Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion cpu/esp32/bootloader/sdkconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,25 @@ extern "C" {
* Bootloader output baudrate, defined by the app settings as BAUD or
* BOOTLOADER_BAUD.
*/
#define CONFIG_ESP_CONSOLE_UART_BAUDRATE (RIOT_BOOTLOADER_BAUD)
#define CONFIG_ESP_CONSOLE_UART_BAUDRATE (RIOT_BOOTLOADER_BAUD)

/*
* If custom TX and RX are defined, use custom UART configuration for 2nd stage
* bootloader.
*/
#if defined(CONFIG_CONSOLE_UART_RX) && defined(CONFIG_CONSOLE_UART_RX)
#define CONFIG_ESP_CONSOLE_UART_CUSTOM 1
#define CONFIG_ESP_CONSOLE_UART_TX_GPIO CONFIG_CONSOLE_UART_TX
#define CONFIG_ESP_CONSOLE_UART_RX_GPIO CONFIG_CONSOLE_UART_RX
#else
#define CONFIG_ESP_CONSOLE_UART_DEFAULT 1
#endif

#if defined(CONFIG_CONSOLE_UART_NUM)
#define CONFIG_ESP_CONSOLE_UART_NUM CONFIG_CONSOLE_UART_NUM
#else
#define CONFIG_ESP_CONSOLE_UART_NUM 0
#endif

#ifdef __cplusplus
}
Expand Down
5 changes: 0 additions & 5 deletions cpu/esp32/bootloader/sdkconfig_default_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ extern "C" {
#define CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT 1

#define CONFIG_ESP_CONSOLE_UART 1
#define CONFIG_ESP_CONSOLE_UART_DEFAULT 1
#define CONFIG_ESP_CONSOLE_UART_NUM 0

#define CONFIG_CONSOLE_UART_NUM CONFIG_ESP_CONSOLE_UART_NUM
#define CONFIG_CONSOLE_UART_DEFAULT CONFIG_ESP_CONSOLE_UART_DEFAULT

#define CONFIG_LOG_DEFAULT_LEVEL 3
#define CONFIG_LOG_TIMESTAMP_SOURCE_RTOS 1
Expand Down
5 changes: 5 additions & 0 deletions cpu/esp32/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
extern "C" {
#endif

/**
* @brief UART device used for STDIO
*/
#define STDIO_UART_DEV CONFIG_ESP_CONSOLE_UART_NUM

/**
* @name Power management configuration
* @{
Expand Down
12 changes: 6 additions & 6 deletions cpu/esp32/include/sdkconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
/**
* Default console configuration
*
* STDIO_UART_BAUDRATE is used as CONFIG_CONSOLE_UART_BAUDRATE and
* STDIO_UART_BAUDRATE is used as CONFIG_ESP_CONSOLE_UART_BAUDRATE and
* can be overridden by an application specific configuration.
*/
#define CONFIG_CONSOLE_UART_NUM 0
#define CONFIG_ESP_CONSOLE_UART_NUM CONFIG_CONSOLE_UART_NUM

#ifndef CONFIG_CONSOLE_UART_BAUDRATE
#define CONFIG_CONSOLE_UART_BAUDRATE STDIO_UART_BAUDRATE
#ifdef CONFIG_CONSOLE_UART_NUM
#define CONFIG_ESP_CONSOLE_UART_NUM CONFIG_CONSOLE_UART_NUM
#else
#define CONFIG_ESP_CONSOLE_UART_NUM 0
#endif
#define CONFIG_ESP_CONSOLE_UART_BAUDRATE STDIO_UART_BAUDRATE

/**
* Log output configuration (DO NOT CHANGE)
Expand Down
4 changes: 2 additions & 2 deletions cpu/esp32/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static NORETURN void IRAM system_startup_cpu0(void)
#endif

/* initialize stdio */
esp_rom_uart_tx_wait_idle(CONFIG_CONSOLE_UART_NUM);
esp_rom_uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
stdio_init();

RESET_REASON reset_reason = rtc_get_reset_reason(PRO_CPU_NUM);
Expand Down Expand Up @@ -315,7 +315,7 @@ static NORETURN void IRAM system_init (void)
/* starting RIOT */
#if IS_USED(MODULE_ESP_LOG_STARTUP)
LOG_STARTUP("Starting RIOT kernel on PRO cpu\n");
esp_rom_uart_tx_wait_idle(CONFIG_CONSOLE_UART_NUM);
esp_rom_uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
#else
puts("");
#endif
Expand Down
67 changes: 24 additions & 43 deletions cpu/esp_common/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

#else /* defined(MCU_ESP8266) */

#include "esp_rom_gpio.h"
#include "hal/interrupt_controller_types.h"
#include "hal/interrupt_controller_ll.h"
#include "soc/gpio_reg.h"
Expand Down Expand Up @@ -164,53 +165,33 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
assert(uart < UART_NUMOF_MAX);
assert(uart < UART_NUMOF);

/* UART1 and UART2 have configurable pins */
if ((UART_NUMOF > 1 && uart == UART_DEV(1)) ||
(UART_NUMOF > 2 && uart == UART_DEV(2))) {

/* reset the pins 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);
}
if (gpio_get_pin_usage(uart_config[uart].rxd) == _UART) {
gpio_set_pin_usage(uart_config[uart].rxd, _GPIO);
}

/* try to initialize the pins as GPIOs first */
if ((uart_config[uart].txd != GPIO_UNDEF &&
gpio_init(uart_config[uart].txd, GPIO_OUT)) ||
(uart_config[uart].rxd != GPIO_UNDEF &&
gpio_init(uart_config[uart].rxd, GPIO_IN))) {
return -1;
}
#ifndef MCU_ESP8266
/* reset the pins 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);
}
if (gpio_get_pin_usage(uart_config[uart].rxd) == _UART) {
gpio_set_pin_usage(uart_config[uart].rxd, _GPIO);
}

/* store the usage type in GPIO table */
gpio_set_pin_usage(uart_config[uart].txd, _UART);
gpio_set_pin_usage(uart_config[uart].rxd, _UART);
/* try to initialize the pins as GPIOs first */
if ((uart_config[uart].txd != GPIO_UNDEF &&
gpio_init(uart_config[uart].txd, GPIO_OUT)) ||
(uart_config[uart].rxd != GPIO_UNDEF &&
gpio_init(uart_config[uart].rxd, GPIO_IN_PU))) {
return -1;
}

#ifdef MCU_ESP8266
if (uart_config[uart].txd != GPIO_UNDEF) {
uint8_t mux = _gpio_to_iomux[uart_config[uart].txd];
IOMUX.PIN[mux] = (IOMUX.PIN[mux] & ~IOMUX_PIN_FUNC_MASK) |
IOMUX_FUNC(uart_config[uart].txd == GPIO2 ? 2 : 4);
}
if (uart_config[uart].rxd != GPIO_UNDEF) {
/* There's really only GPIO8 / FUNC(4) for this, but it is normally
* unusable because it is used by the internal flash. */
uint8_t mux = _gpio_to_iomux[uart_config[uart].rxd];
IOMUX.PIN[mux] = (IOMUX.PIN[mux] & ~IOMUX_PIN_FUNC_MASK) |
IOMUX_FUNC(4);
}
#else /* MCU_ESP8266 */
/* connect TxD pin to the TxD output signal through the GPIO matrix */
GPIO.func_out_sel_cfg[uart_config[uart].txd].func_sel = _uarts[uart].signal_txd;
/* store the usage type in GPIO table */
gpio_set_pin_usage(uart_config[uart].txd, _UART);
gpio_set_pin_usage(uart_config[uart].rxd, _UART);

/* connect RxD input signal to the RxD pin through the GPIO matrix */
GPIO.func_in_sel_cfg[_uarts[uart].signal_rxd].sig_in_sel = 1;
GPIO.func_in_sel_cfg[_uarts[uart].signal_rxd].sig_in_inv = 0;
GPIO.func_in_sel_cfg[_uarts[uart].signal_rxd].func_sel = uart_config[uart].rxd;
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,
_uarts[uart].signal_rxd, false);
#endif /* MCU_ESP8266 */
}

_uarts[uart].baudrate = baudrate;

/* register interrupt context */
Expand Down