diff --git a/components/esp_system/linker.lf b/components/esp_system/linker.lf index 65a6670298..51b6cff9e2 100644 --- a/components/esp_system/linker.lf +++ b/components/esp_system/linker.lf @@ -51,14 +51,6 @@ entries: if APP_BUILD_TYPE_RAM = n: image_process (noflash) -[mapping:vfs_cdcacm] -archive: libvfs.a -entries: - if ESP_SYSTEM_IN_IRAM = y: - if ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF: - vfs_cdcacm:cdcacm_tx_cb (noflash) - vfs_cdcacm:cdcacm_rx_cb (noflash) - [mapping:esp_system_hal] archive: libhal.a entries: diff --git a/components/esp_system/port/usb_console.c b/components/esp_system/port/usb_console.c index 45a3844f87..5f946e1608 100644 --- a/components/esp_system/port/usb_console.c +++ b/components/esp_system/port/usb_console.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -494,11 +494,13 @@ void esp_usb_console_write_char(char c) esp_usb_console_write_buf(&c, 1); } } -static inline void write_lock_acquire(void) + +static inline __attribute__((always_inline)) void write_lock_acquire(void) { portENTER_CRITICAL_SAFE(&s_lock); } -static inline void write_lock_release(void) + +static inline __attribute__((always_inline)) void write_lock_release(void) { portEXIT_CRITICAL_SAFE(&s_lock); } diff --git a/components/esp_vfs_console/CMakeLists.txt b/components/esp_vfs_console/CMakeLists.txt index 50954747a7..b5ee171f5f 100644 --- a/components/esp_vfs_console/CMakeLists.txt +++ b/components/esp_vfs_console/CMakeLists.txt @@ -9,7 +9,7 @@ set(srcs "vfs_console.c") idf_component_register(SRCS ${srcs} INCLUDE_DIRS include PRIV_REQUIRES vfs esp_driver_uart esp_driver_usb_serial_jtag - ) + LDFRAGMENTS linker.lf) if(CONFIG_ESP_CONSOLE_USB_CDC) target_sources(${COMPONENT_LIB} PRIVATE "vfs_cdcacm.c") diff --git a/components/esp_vfs_console/linker.lf b/components/esp_vfs_console/linker.lf new file mode 100644 index 0000000000..e5d817a1e5 --- /dev/null +++ b/components/esp_vfs_console/linker.lf @@ -0,0 +1,6 @@ +[mapping:esp_vfs_console] +archive: libesp_vfs_console.a +entries: + if ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF: + vfs_cdcacm:cdcacm_tx_cb (noflash) + vfs_cdcacm:cdcacm_rx_cb (noflash) diff --git a/components/esp_vfs_console/test_apps/usb_cdc_vfs/CMakeLists.txt b/components/esp_vfs_console/test_apps/usb_cdc_vfs/CMakeLists.txt index 0f63d0caaa..86ac25a3ab 100644 --- a/components/esp_vfs_console/test_apps/usb_cdc_vfs/CMakeLists.txt +++ b/components/esp_vfs_console/test_apps/usb_cdc_vfs/CMakeLists.txt @@ -7,3 +7,17 @@ set(COMPONENTS main) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(usb_cdc_vfs_test) + +idf_build_get_property(elf EXECUTABLE) +if(CONFIG_COMPILER_DUMP_RTL_FILES) + add_custom_target(check_test_app_sections ALL + COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py + --rtl-dirs ${CMAKE_BINARY_DIR}/esp-idf/driver/,${CMAKE_BINARY_DIR}/esp-idf/hal/ + --elf-file ${CMAKE_BINARY_DIR}/*.elf + find-refs + --from-sections=.iram0.text + --to-sections=.flash.text,.flash.rodata + --exit-code + DEPENDS ${elf} + ) +endif() diff --git a/components/esp_vfs_console/test_apps/usb_cdc_vfs/main/test_app_main.c b/components/esp_vfs_console/test_apps/usb_cdc_vfs/main/test_app_main.c index a82a7a6d18..1d14ed505c 100644 --- a/components/esp_vfs_console/test_apps/usb_cdc_vfs/main/test_app_main.c +++ b/components/esp_vfs_console/test_apps/usb_cdc_vfs/main/test_app_main.c @@ -8,8 +8,10 @@ #include #include #include "unity.h" +#include "unity_test_utils_cache.h" #include "esp_private/usb_console.h" #include "esp_vfs_cdcacm.h" +#include "esp_rom_sys.h" static void flush_write(void) { @@ -263,6 +265,39 @@ static void test_usb_cdc_read_no_exit_on_newline_reception(void) vTaskDelay(2); // wait for tasks to exit } +static void IRAM_ATTR test_input_output_post_cache_disable(void *args) +{ + static DRAM_ATTR const char test_msg[] = "test_message\n"; + esp_rom_printf(test_msg); +} + +/** + * @brief Test that the tx and rx cb are placed in IRAM correctly + */ +static void test_usb_cdc_ets_printf_cache_disabled(void) +{ + test_setup(__func__, sizeof(__func__)); + + /* make sure blocking mode is enabled */ + int flags = fcntl(STDIN_FILENO, F_GETFL, 0); + fcntl(STDIN_FILENO, F_SETFL, flags & (~O_NONBLOCK)); + +#if CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF + unity_utils_run_cache_disable_stub(test_input_output_post_cache_disable, NULL); +#else +#error This test must run with CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF enabled +#endif + + // send message to the test environment to report successful test + char ready_msg[] = "successful test\n"; + write(fileno(stdout), ready_msg, sizeof(ready_msg)); + + fcntl(STDIN_FILENO, F_SETFL, flags); + esp_vfs_dev_cdcacm_set_rx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_cdcacm_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + vTaskDelay(2); // wait for tasks to exit +} + /* Always make sure that the function calling sequence in the main * function matches the expected order in the pytest function. */ @@ -272,4 +307,5 @@ void app_main(void) test_usb_cdc_read_non_blocking(); test_usb_cdc_read_blocking(); test_usb_cdc_read_no_exit_on_newline_reception(); + test_usb_cdc_ets_printf_cache_disabled(); } diff --git a/components/esp_vfs_console/test_apps/usb_cdc_vfs/pytest_usb_cdc_vfs.py b/components/esp_vfs_console/test_apps/usb_cdc_vfs/pytest_usb_cdc_vfs.py index 8693a8b0b9..434dfbab77 100644 --- a/components/esp_vfs_console/test_apps/usb_cdc_vfs/pytest_usb_cdc_vfs.py +++ b/components/esp_vfs_console/test_apps/usb_cdc_vfs/pytest_usb_cdc_vfs.py @@ -37,3 +37,8 @@ def test_usb_cdc_vfs_default(dut: Dut) -> None: dut.expect_exact('test_usb_cdc_read_no_exit_on_newline_reception', timeout=2) dut.expect_exact('ready to receive', timeout=2) dut.write('!(@*#&(!*@&#((SDasdkjhad\nce') + + # test run: test_usb_cdc_ets_printf_cache_disabled + dut.expect_exact('test_usb_cdc_ets_printf_cache_disabled', timeout=2) + dut.expect_exact('test_message', timeout=2) + dut.expect_exact('successful test', timeout=2) diff --git a/components/esp_vfs_console/test_apps/usb_cdc_vfs/sdkconfig.defaults b/components/esp_vfs_console/test_apps/usb_cdc_vfs/sdkconfig.defaults index 9f592f7463..308212da84 100644 --- a/components/esp_vfs_console/test_apps/usb_cdc_vfs/sdkconfig.defaults +++ b/components/esp_vfs_console/test_apps/usb_cdc_vfs/sdkconfig.defaults @@ -1,8 +1,12 @@ # Enable Unity fixture support CONFIG_UNITY_ENABLE_FIXTURE=n CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=y +CONFIG_COMPILER_DUMP_RTL_FILES=y # Custom partition table for this test app CONFIG_ESP_TASK_WDT_INIT=n CONFIG_ESP_CONSOLE_USB_CDC=y + +# one test requires this option to be enabled +CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF=y