fix(console): fixed secondary console not working on all chips without VFS

This commit is contained in:
Marius Vikhammer
2025-03-04 10:26:31 +08:00
parent 7f88aa2621
commit 12e9d6514a
30 changed files with 178 additions and 9 deletions

View File

@@ -75,6 +75,10 @@ if(CONFIG_ESP_ROM_HAS_CACHE_WRITEBACK_BUG)
list(APPEND sources "patches/esp_rom_cache_writeback_esp32s3.S")
endif()
if(CONFIG_ESP_ROM_NO_USB_SERIAL_OUTPUT_API)
list(APPEND sources "patches/esp_rom_usb_serial.c")
endif()
idf_component_register(SRCS ${sources}
INCLUDE_DIRS ${include_dirs}
PRIV_REQUIRES ${private_required_comp}

View File

@@ -98,3 +98,7 @@ config ESP_ROM_HAS_VPRINTF_FUNC
config ESP_ROM_HAS_OUTPUT_PUTC_FUNC
bool
default y
config ESP_ROM_CONSOLE_OUTPUT_SECONDARY
bool
default y

View File

@@ -30,3 +30,4 @@
#define ESP_ROM_HAS_VERSION (1) // ROM has version/eco information
#define ESP_ROM_HAS_VPRINTF_FUNC (1) // ROM has ets_vprintf
#define ESP_ROM_HAS_OUTPUT_PUTC_FUNC (1) // ROM has esp_rom_output_putc (or ets_write_char_uart)
#define ESP_ROM_CONSOLE_OUTPUT_SECONDARY (1) // The console output functions will also output to the USB-serial secondary console

View File

@@ -94,3 +94,7 @@ config ESP_ROM_HAS_VERSION
config ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB
bool
default y
config ESP_ROM_CONSOLE_OUTPUT_SECONDARY
bool
default y

View File

@@ -29,3 +29,4 @@
#define ESP_ROM_USB_OTG_NUM (-1) // No USB_OTG CDC in the ROM, set -1 for Kconfig usage.
#define ESP_ROM_HAS_VERSION (1) // ROM has version/eco information
#define ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB (1) // ROM supports the HP core to jump to the RTC memory to execute stub code after waking up from deepsleep.
#define ESP_ROM_CONSOLE_OUTPUT_SECONDARY (1) // The console output functions will also output to the USB-serial secondary console

View File

@@ -31,6 +31,8 @@ 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_usb_serial_putc = uart_tx_one_char3 );
PROVIDE ( esp_rom_output_flush_tx = uart_tx_flush );
PROVIDE ( esp_rom_output_tx_one_char = uart_tx_one_char );
PROVIDE ( esp_rom_output_tx_wait_idle = uart_tx_wait_idle );

View File

@@ -110,3 +110,7 @@ config ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB
config ESP_ROM_HAS_OUTPUT_PUTC_FUNC
bool
default y
config ESP_ROM_NO_USB_SERIAL_OUTPUT_API
bool
default y

View File

@@ -33,3 +33,4 @@
#define ESP_ROM_HAS_VERSION (1) // ROM has version/eco information
#define ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB (1) // ROM supports the HP core to jump to the RTC memory to execute stub code after waking up from deepsleep.
#define ESP_ROM_HAS_OUTPUT_PUTC_FUNC (1) // ROM has esp_rom_output_putc (or ets_write_char_uart)
#define ESP_ROM_NO_USB_SERIAL_OUTPUT_API (1) // ROM does not export the usb-serial-jtag write char function

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -272,6 +272,16 @@ int ets_jtag_enable_temporarily(const uint8_t *jtag_hmac_key, ets_efuse_block_t
*/
unsigned char esp_crc8(unsigned char const *p, unsigned int len);
/**
* @brief Read if usb print in ROM disabled by efuse
*
*
* @return
* - 0 for enable.
* - 1 for disable.
*/
uint32_t ets_efuse_usb_print_is_disabled(void);
/**
* @}
*/

View File

@@ -29,6 +29,8 @@ 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_usb_serial_putc = uart_tx_one_char3 );
PROVIDE ( esp_rom_output_flush_tx = uart_tx_flush );
PROVIDE ( esp_rom_output_tx_one_char = uart_tx_one_char );
PROVIDE ( esp_rom_output_tx_wait_idle = uart_tx_wait_idle );

View File

@@ -102,3 +102,7 @@ config ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB
config ESP_ROM_HAS_OUTPUT_PUTC_FUNC
bool
default y
config ESP_ROM_NO_USB_SERIAL_OUTPUT_API
bool
default y

View File

@@ -31,3 +31,4 @@
#define ESP_ROM_HAS_VERSION (1) // ROM has version/eco information
#define ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB (1) // ROM supports the HP core to jump to the RTC memory to execute stub code after waking up from deepsleep.
#define ESP_ROM_HAS_OUTPUT_PUTC_FUNC (1) // ROM has esp_rom_output_putc (or ets_write_char_uart)
#define ESP_ROM_NO_USB_SERIAL_OUTPUT_API (1) // ROM does not export the usb-serial-jtag write char function

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -273,6 +273,17 @@ int ets_jtag_enable_temporarily(const uint8_t *jtag_hmac_key, ets_efuse_block_t
*/
unsigned char esp_crc8(unsigned char const *p, unsigned int len);
/**
* @brief Read if usb print in ROM disabled by efuse
*
*
* @return
* - 0 for enable.
* - 1 for disable.
*/
uint32_t ets_efuse_usb_print_is_disabled(void);
/**
* @}
*/

View File

@@ -29,6 +29,8 @@ 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_usb_serial_putc = uart_tx_one_char3 );
PROVIDE ( esp_rom_output_flush_tx = uart_tx_flush );
PROVIDE ( esp_rom_output_tx_one_char = uart_tx_one_char );
PROVIDE ( esp_rom_output_tx_wait_idle = uart_tx_wait_idle );

View File

@@ -31,6 +31,8 @@ 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_usb_serial_putc = uart_tx_one_char3 );
PROVIDE ( esp_rom_output_flush_tx = uart_tx_flush );
PROVIDE ( esp_rom_output_tx_one_char = uart_tx_one_char );
PROVIDE ( esp_rom_output_tx_wait_idle = uart_tx_wait_idle );

View File

@@ -31,6 +31,8 @@ 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_usb_serial_putc = uart_tx_one_char3 );
PROVIDE ( esp_rom_output_flush_tx = uart_tx_flush );
PROVIDE ( esp_rom_output_tx_one_char = uart_tx_one_char );
PROVIDE ( esp_rom_output_tx_wait_idle = uart_tx_wait_idle );

View File

@@ -66,3 +66,7 @@ config ESP_ROM_HAS_OUTPUT_TO_CHANNELS_FUNC
config ESP_ROM_HAS_OUTPUT_PUTC_FUNC
bool
default y
config ESP_ROM_CONSOLE_OUTPUT_SECONDARY
bool
default y

View File

@@ -22,3 +22,4 @@
#define ESP_ROM_HAS_VPRINTF_FUNC (1) // ROM has ets_vprintf
#define ESP_ROM_HAS_OUTPUT_TO_CHANNELS_FUNC (1) // ROM has ets_write_char, alias is esp_rom_output_to_channels
#define ESP_ROM_HAS_OUTPUT_PUTC_FUNC (1) // ROM has esp_rom_output_putc (or ets_write_char_uart)
#define ESP_ROM_CONSOLE_OUTPUT_SECONDARY (1) // The console output functions will also output to the USB-serial secondary console

View File

@@ -114,3 +114,7 @@ config ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB
config ESP_ROM_HAS_OUTPUT_PUTC_FUNC
bool
default y
config ESP_ROM_CONSOLE_OUTPUT_SECONDARY
bool
default y

View File

@@ -34,3 +34,4 @@
#define ESP_ROM_HAS_VERSION (1) // ROM has version/eco information
#define ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB (1) // ROM supports the HP core to jump to the RTC memory to execute stub code after waking up from deepsleep.
#define ESP_ROM_HAS_OUTPUT_PUTC_FUNC (1) // ROM has esp_rom_output_putc (or ets_write_char_uart)
#define ESP_ROM_CONSOLE_OUTPUT_SECONDARY (1) // The console output functions will also output to the USB-serial secondary console

View File

@@ -0,0 +1,21 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Output a char over usb-serial if printing has not been disabled
*
* @param c the char to output
*/
void esp_rom_usb_serial_putc(char c);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,23 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_rom_usb_serial.h"
#include <stdint.h>
#include "rom/ets_sys.h"
#include "rom/efuse.h"
extern ETS_STATUS usb_serial_device_tx_one_char(uint8_t TxChar);
extern void usb_serial_device_tx_flush(void);
void esp_rom_usb_serial_putc(char c)
{
uint32_t print_enabled = !ets_efuse_usb_print_is_disabled();
if (print_enabled) {
usb_serial_device_tx_one_char(c);
if (c == '\n') {
usb_serial_device_tx_flush();
}
}
}

View File

@@ -31,6 +31,7 @@ else()
list(APPEND srcs "crosscore_int.c"
"esp_ipc.c"
"esp_err.c"
"esp_system_console.c"
"freertos_hooks.c"
"int_wdt.c"
"panic.c"

View File

@@ -0,0 +1,18 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_system_console.h"
#include "sdkconfig.h"
#include "esp_rom_uart.h"
#include "esp_rom_usb_serial.h"
#include "esp_rom_caps.h"
void esp_system_console_put_char(char c)
{
esp_rom_output_tx_one_char(c);
#if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG && !ESP_ROM_CONSOLE_OUTPUT_SECONDARY
esp_rom_usb_serial_putc(c);
#endif // CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG && !ESP_ROM_CONSOLE_OUTPUT_SECONDARY
}

View File

@@ -0,0 +1,21 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Outputs a char to the configured primary and secondary console
*
* @param c char to output
*/
void esp_system_console_put_char(char c);
#ifdef __cplusplus
}
#endif

View File

@@ -8,6 +8,7 @@ components/esp_system/test_apps/console:
disable:
- if: CONFIG_NAME == "serial_jtag_only" and SOC_USB_SERIAL_JTAG_SUPPORTED != 1
- if: CONFIG_NAME == "serial_jtag_only_no_vfs" and SOC_USB_SERIAL_JTAG_SUPPORTED != 1
- if: CONFIG_NAME == "console_no_vfs" and SOC_USB_SERIAL_JTAG_SUPPORTED != 1
disable_test:
- if: CONFIG_NAME == "simple" and IDF_TARGET != "esp32"

View File

@@ -19,7 +19,9 @@ JTAG_SERIAL_MARKS = [
pytest.mark.esp32s3,
pytest.mark.esp32c2,
pytest.mark.esp32c3,
pytest.mark.esp32c5,
pytest.mark.esp32c6,
pytest.mark.esp32c61,
pytest.mark.esp32h2,
]
@@ -56,6 +58,18 @@ def test_esp_system_console_only_serial_jtag_no_vfs(dut: Dut) -> None:
dut.expect('Hello World')
@pytest.mark.usb_serial_jtag
@idf_parametrize('config', ['console_no_vfs'], indirect=['config'])
@idf_parametrize('flash_port', ['/dev/serial_ports/ttyUSB-esp32'], indirect=['flash_port'])
@idf_parametrize('port', ['/dev/serial_ports/ttyACM-esp32'], indirect=['port'])
@idf_parametrize(
'target', ['esp32c2', 'esp32c3', 'esp32c5', 'esp32c6', 'esp32c61', 'esp32h2', 'esp32s3'], indirect=['target']
)
def test_esp_system_console_secondary_serial_jtag(dut: Dut) -> None:
dut.expect('2nd stage bootloader')
dut.expect('Hello World')
@pytest.mark.generic
@idf_parametrize('config', ['simple'], indirect=['config'])
@idf_parametrize('target', ['supported_targets'], indirect=['target'])

View File

@@ -0,0 +1,3 @@
CONFIG_VFS_SUPPORT_IO=n
CONFIG_ESP_CONSOLE_UART_DEFAULT=y
CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -15,6 +15,7 @@
#include <sys/fcntl.h>
#include "sdkconfig.h"
#include "esp_rom_uart.h"
#include "esp_system_console.h"
static int syscall_not_implemented(struct _reent *r, ...)
{
@@ -34,9 +35,9 @@ ssize_t _write_r_console(struct _reent *r, int fd, const void * data, size_t siz
if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
for (size_t i = 0; i < size; ++i) {
if (cdata[i] == '\n') {
esp_rom_output_tx_one_char('\r');
esp_system_console_put_char('\r');
}
esp_rom_output_tx_one_char(cdata[i]);
esp_system_console_put_char(cdata[i]);
}
return size;
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2016-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -9,6 +9,7 @@
#include "sdkconfig.h"
#include "esp_cpu.h"
#include "esp_rom_uart.h"
#include "esp_system_console.h"
#include "esp_private/esp_clk.h"
static uint32_t s_test_start, s_test_stop;
@@ -16,11 +17,11 @@ static uint32_t s_test_start, s_test_stop;
void unity_putc(int c)
{
if (c == '\n') {
esp_rom_output_tx_one_char('\r');
esp_rom_output_tx_one_char('\n');
esp_system_console_put_char('\r');
esp_system_console_put_char('\n');
} else if (c == '\r') {
} else {
esp_rom_output_tx_one_char(c);
esp_system_console_put_char(c);
}
}