Skip to content

Commit

Permalink
Merge branch 'bugfix/2nd_bootloader_custom_uart1_print_issue' into 'm…
Browse files Browse the repository at this point in the history
…aster'

bootloader_support: fix uart1 no printing in the 2nd bootloader stage

See merge request espressif/esp-idf!20935
  • Loading branch information
esp-jiangguangming committed Nov 10, 2022
2 parents ed26b01 + 618dfaa commit 435e055
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/bootloader_support/src/bootloader_console.c
Expand Up @@ -61,6 +61,9 @@ void bootloader_console_init(void)
const int uart_tx_gpio = CONFIG_ESP_CONSOLE_UART_TX_GPIO;
const int uart_rx_gpio = CONFIG_ESP_CONSOLE_UART_RX_GPIO;

// Switch to the new UART (this just changes UART number used for esp_rom_printf in ROM code).
esp_rom_uart_set_as_console(uart_num);

// If console is attached to UART1 or if non-default pins are used,
// need to reconfigure pins using GPIO matrix
if (uart_num != 0 ||
Expand Down
1 change: 1 addition & 0 deletions components/esp_rom/esp32c2/ld/esp32c2.rom.api.ld
Expand Up @@ -28,6 +28,7 @@ PROVIDE ( esp_rom_uart_tx_one_char = uart_tx_one_char );
PROVIDE ( esp_rom_uart_tx_wait_idle = uart_tx_wait_idle );
PROVIDE ( esp_rom_uart_rx_one_char = uart_rx_one_char );
PROVIDE ( esp_rom_uart_rx_string = UartRxString );
PROVIDE ( esp_rom_uart_set_as_console = uart_tx_switch );
PROVIDE ( esp_rom_uart_putc = ets_write_char_uart );

PROVIDE ( esp_rom_mbedtls_md5_starts_ret = mbedtls_md5_starts_ret );
Expand Down
1 change: 1 addition & 0 deletions components/esp_rom/esp32c6/ld/esp32c6.rom.api.ld
Expand Up @@ -28,6 +28,7 @@ PROVIDE ( esp_rom_uart_tx_one_char = uart_tx_one_char );
PROVIDE ( esp_rom_uart_tx_wait_idle = uart_tx_wait_idle );
PROVIDE ( esp_rom_uart_rx_one_char = uart_rx_one_char );
PROVIDE ( esp_rom_uart_rx_string = UartRxString );
PROVIDE ( esp_rom_uart_set_as_console = uart_tx_switch );
PROVIDE ( esp_rom_uart_putc = ets_write_char_uart );

PROVIDE ( esp_rom_md5_init = MD5Init );
Expand Down
1 change: 1 addition & 0 deletions components/esp_rom/esp32h4/ld/rev1/esp32h4.rom.api.ld
Expand Up @@ -30,6 +30,7 @@ PROVIDE ( esp_rom_uart_tx_one_char = uart_tx_one_char );
PROVIDE ( esp_rom_uart_tx_wait_idle = uart_tx_wait_idle );
PROVIDE ( esp_rom_uart_rx_one_char = uart_rx_one_char );
PROVIDE ( esp_rom_uart_rx_string = UartRxString );
PROVIDE ( esp_rom_uart_set_as_console = uart_tx_switch );
PROVIDE ( esp_rom_uart_putc = ets_write_char_uart );


Expand Down
1 change: 1 addition & 0 deletions components/esp_rom/esp32h4/ld/rev2/esp32h4.rom.api.ld
Expand Up @@ -30,6 +30,7 @@ PROVIDE ( esp_rom_uart_tx_one_char = uart_tx_one_char );
PROVIDE ( esp_rom_uart_tx_wait_idle = uart_tx_wait_idle );
PROVIDE ( esp_rom_uart_rx_one_char = uart_rx_one_char );
PROVIDE ( esp_rom_uart_rx_string = UartRxString );
PROVIDE ( esp_rom_uart_set_as_console = uart_tx_switch );
PROVIDE ( esp_rom_uart_putc = ets_write_char_uart );


Expand Down
23 changes: 23 additions & 0 deletions components/esp_rom/patches/esp_rom_uart.c
Expand Up @@ -9,6 +9,7 @@
#include "esp_attr.h"
#include "sdkconfig.h"
#include "hal/uart_ll.h"
#include "hal/efuse_hal.h"

#if CONFIG_IDF_TARGET_ESP32
/**
Expand All @@ -24,3 +25,25 @@ IRAM_ATTR void esp_rom_uart_set_clock_baudrate(uint8_t uart_no, uint32_t clock_h
{
uart_ll_set_baudrate(UART_LL_GET_HW(uart_no), baud_rate, clock_hz);
}

#if CONFIG_IDF_TARGET_ESP32C3
/**
* The ESP32-C3 ROM has released two versions, one is the ECO3 version,
* and the other is the version before ECO3 (include ECO0 ECO1 ECO2).
* These two versions of the ROM code do not list uart_tx_switch wrap
* function in the ROM interface, so here use the uart_tx_switch direct
* address instead.
*/
IRAM_ATTR void esp_rom_uart_set_as_console(uint8_t uart_no)
{
typedef void (*rom_func_t)(uint8_t);
rom_func_t uart_tx_switch = NULL;

if (efuse_hal_chip_revision() < 3) {
uart_tx_switch = (rom_func_t)0x4004b8ca;
} else {
uart_tx_switch = (rom_func_t)0x4004c166;
}
uart_tx_switch(uart_no);
}
#endif

0 comments on commit 435e055

Please sign in to comment.