1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:52:44 +01:00

cpu/esp32: improve initialization of UART pins

Since PR #19100 it is possible to define:
- other pins for `UART_DEV(0)` than the default pins
- different `UART_DEV(0)` pins for the bootloader and RIOT
To allow correct reinitialization of the UART pins used by the bootloader as well as their usage for other purposes, the pin usage for the default UART0 pins and the UART pins used by the bootloader are reset to `_GPIO`. This is done in `uart_system_init` which has to be called earlier in the startup procedure.
This commit is contained in:
Gunar Schorcht 2023-01-14 13:54:16 +01:00
parent 9004867fe0
commit fe21e82079
2 changed files with 23 additions and 5 deletions

View File

@ -150,6 +150,10 @@ static NORETURN void IRAM system_startup_cpu0(void)
/* initialize system call tables of ESP32x rom and newlib */
syscalls_init();
/* systemwide UART initialization */
extern void uart_system_init (void);
uart_system_init();
/* initialize stdio */
esp_rom_uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
early_init();
@ -234,10 +238,6 @@ static NORETURN void IRAM system_init (void)
/* install exception handlers */
init_exceptions();
/* systemwide UART initialization */
extern void uart_system_init (void);
uart_system_init();
/* set log levels for SDK library outputs */
extern void esp_log_level_set(const char* tag, esp_log_level_t level);
esp_log_level_set("wifi", LOG_DEBUG);

View File

@ -60,6 +60,7 @@
#else /* defined(MCU_ESP8266) */
#include "esp_rom_gpio.h"
#include "esp_rom_uart.h"
#include "hal/interrupt_controller_types.h"
#include "hal/interrupt_controller_ll.h"
#include "soc/gpio_reg.h"
@ -68,6 +69,7 @@
#include "soc/periph_defs.h"
#include "soc/rtc.h"
#include "soc/soc_caps.h"
#include "soc/uart_pins.h"
#include "soc/uart_reg.h"
#include "soc/uart_struct.h"
@ -166,7 +168,10 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
assert(uart < UART_NUMOF);
#ifndef MCU_ESP8266
/* reset the pins when they were already used as UART pins */
assert(uart_config[uart].txd != GPIO_UNDEF);
assert(uart_config[uart].rxd != GPIO_UNDEF);
/* reset the pin usage when they were already used as UART pins */
if (gpio_get_pin_usage(uart_config[uart].txd) == _UART) {
gpio_set_pin_usage(uart_config[uart].txd, _GPIO);
}
@ -186,6 +191,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
gpio_set_pin_usage(uart_config[uart].txd, _UART);
gpio_set_pin_usage(uart_config[uart].rxd, _UART);
esp_rom_uart_tx_wait_idle(uart);
esp_rom_gpio_connect_out_signal(uart_config[uart].txd,
_uarts[uart].signal_txd, false, false);
esp_rom_gpio_connect_in_signal(uart_config[uart].rxd,
@ -247,6 +253,18 @@ void uart_system_init(void)
/* reset all UART interrupt status registers */
_uarts[uart].regs->int_clr.val = ~0;
}
#ifndef MCU_ESP8266
/* reset the pin usage of the default UART0 pins to GPIO to allow
* reinitialization and usage for other purposes */
gpio_set_pin_usage(U0TXD_GPIO_NUM, _GPIO);
gpio_set_pin_usage(U0RXD_GPIO_NUM, _GPIO);
#if defined(CONFIG_CONSOLE_UART_TX) && defined(CONFIG_CONSOLE_UART_TX)
/* reset the pin usage of the UART pins used by the bootloader to
* _GPIO to be able to use them later for other purposes */
gpio_set_pin_usage(CONFIG_CONSOLE_UART_TX, _GPIO);
gpio_set_pin_usage(CONFIG_CONSOLE_UART_RX, _GPIO);
#endif
#endif
}
void uart_print_config(void)