Skip to content

Commit 24a36e5

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'fix/cdcacm-callback-placement_v5.5' into 'release/v5.5'
fix(esp_vfs_console): Update placement of cdcacm_xx_cb when ETS print enabled (v5.5) See merge request espressif/esp-idf!41330
2 parents d7bdd17 + 175e885 commit 24a36e5

File tree

8 files changed

+71
-12
lines changed

8 files changed

+71
-12
lines changed

components/esp_system/linker.lf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ entries:
5151
if APP_BUILD_TYPE_RAM = n:
5252
image_process (noflash)
5353

54-
[mapping:vfs_cdcacm]
55-
archive: libvfs.a
56-
entries:
57-
if ESP_SYSTEM_IN_IRAM = y:
58-
if ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF:
59-
vfs_cdcacm:cdcacm_tx_cb (noflash)
60-
vfs_cdcacm:cdcacm_rx_cb (noflash)
61-
6254
[mapping:esp_system_hal]
6355
archive: libhal.a
6456
entries:

components/esp_system/port/usb_console.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -494,11 +494,13 @@ void esp_usb_console_write_char(char c)
494494
esp_usb_console_write_buf(&c, 1);
495495
}
496496
}
497-
static inline void write_lock_acquire(void)
497+
498+
static inline __attribute__((always_inline)) void write_lock_acquire(void)
498499
{
499500
portENTER_CRITICAL_SAFE(&s_lock);
500501
}
501-
static inline void write_lock_release(void)
502+
503+
static inline __attribute__((always_inline)) void write_lock_release(void)
502504
{
503505
portEXIT_CRITICAL_SAFE(&s_lock);
504506
}

components/esp_vfs_console/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set(srcs "vfs_console.c")
99
idf_component_register(SRCS ${srcs}
1010
INCLUDE_DIRS include
1111
PRIV_REQUIRES vfs esp_driver_uart esp_driver_usb_serial_jtag
12-
)
12+
LDFRAGMENTS linker.lf)
1313

1414
if(CONFIG_ESP_CONSOLE_USB_CDC)
1515
target_sources(${COMPONENT_LIB} PRIVATE "vfs_cdcacm.c")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[mapping:esp_vfs_console]
2+
archive: libesp_vfs_console.a
3+
entries:
4+
if ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF:
5+
vfs_cdcacm:cdcacm_tx_cb (noflash)
6+
vfs_cdcacm:cdcacm_rx_cb (noflash)

components/esp_vfs_console/test_apps/usb_cdc_vfs/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,17 @@ set(COMPONENTS main)
77

88
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
99
project(usb_cdc_vfs_test)
10+
11+
idf_build_get_property(elf EXECUTABLE)
12+
if(CONFIG_COMPILER_DUMP_RTL_FILES)
13+
add_custom_target(check_test_app_sections ALL
14+
COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py
15+
--rtl-dirs ${CMAKE_BINARY_DIR}/esp-idf/driver/,${CMAKE_BINARY_DIR}/esp-idf/hal/
16+
--elf-file ${CMAKE_BINARY_DIR}/*.elf
17+
find-refs
18+
--from-sections=.iram0.text
19+
--to-sections=.flash.text,.flash.rodata
20+
--exit-code
21+
DEPENDS ${elf}
22+
)
23+
endif()

components/esp_vfs_console/test_apps/usb_cdc_vfs/main/test_app_main.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
#include <fcntl.h>
99
#include <sys/errno.h>
1010
#include "unity.h"
11+
#include "unity_test_utils_cache.h"
1112
#include "esp_private/usb_console.h"
1213
#include "esp_vfs_cdcacm.h"
14+
#include "esp_rom_sys.h"
1315

1416
static void flush_write(void)
1517
{
@@ -263,6 +265,39 @@ static void test_usb_cdc_read_no_exit_on_newline_reception(void)
263265
vTaskDelay(2); // wait for tasks to exit
264266
}
265267

268+
static void IRAM_ATTR test_input_output_post_cache_disable(void *args)
269+
{
270+
static DRAM_ATTR const char test_msg[] = "test_message\n";
271+
esp_rom_printf(test_msg);
272+
}
273+
274+
/**
275+
* @brief Test that the tx and rx cb are placed in IRAM correctly
276+
*/
277+
static void test_usb_cdc_ets_printf_cache_disabled(void)
278+
{
279+
test_setup(__func__, sizeof(__func__));
280+
281+
/* make sure blocking mode is enabled */
282+
int flags = fcntl(STDIN_FILENO, F_GETFL, 0);
283+
fcntl(STDIN_FILENO, F_SETFL, flags & (~O_NONBLOCK));
284+
285+
#if CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF
286+
unity_utils_run_cache_disable_stub(test_input_output_post_cache_disable, NULL);
287+
#else
288+
#error This test must run with CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF enabled
289+
#endif
290+
291+
// send message to the test environment to report successful test
292+
char ready_msg[] = "successful test\n";
293+
write(fileno(stdout), ready_msg, sizeof(ready_msg));
294+
295+
fcntl(STDIN_FILENO, F_SETFL, flags);
296+
esp_vfs_dev_cdcacm_set_rx_line_endings(ESP_LINE_ENDINGS_CRLF);
297+
esp_vfs_dev_cdcacm_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
298+
vTaskDelay(2); // wait for tasks to exit
299+
}
300+
266301
/* Always make sure that the function calling sequence in the main
267302
* function matches the expected order in the pytest function.
268303
*/
@@ -272,4 +307,5 @@ void app_main(void)
272307
test_usb_cdc_read_non_blocking();
273308
test_usb_cdc_read_blocking();
274309
test_usb_cdc_read_no_exit_on_newline_reception();
310+
test_usb_cdc_ets_printf_cache_disabled();
275311
}

components/esp_vfs_console/test_apps/usb_cdc_vfs/pytest_usb_cdc_vfs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ def test_usb_cdc_vfs_default(dut: Dut, test_message: str) -> None:
3636
dut.expect_exact('test_usb_cdc_read_no_exit_on_newline_reception', timeout=2)
3737
dut.expect_exact('ready to receive', timeout=2)
3838
dut.write('!(@*#&(!*@&#((SDasdkjhad\nce')
39+
40+
# test run: test_usb_cdc_ets_printf_cache_disabled
41+
dut.expect_exact('test_usb_cdc_ets_printf_cache_disabled', timeout=2)
42+
dut.expect_exact('test_message', timeout=2)
43+
dut.expect_exact('successful test', timeout=2)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Enable Unity fixture support
22
CONFIG_UNITY_ENABLE_FIXTURE=n
33
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=y
4+
CONFIG_COMPILER_DUMP_RTL_FILES=y
45

56
# Custom partition table for this test app
67
CONFIG_ESP_TASK_WDT_INIT=n
78

89
CONFIG_ESP_CONSOLE_USB_CDC=y
10+
11+
# one test requires this option to be enabled
12+
CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF=y

0 commit comments

Comments
 (0)