From 9c82ad06c376485408d42a22c048eb796ad8a14f Mon Sep 17 00:00:00 2001 From: "sonika.rathi" Date: Wed, 19 Jul 2023 12:28:39 +0200 Subject: [PATCH] fix(vfs/uart): add UART VFS select callback in IRAM UART VFS select callback is placed in IRAM when CONFIG_UART_ISR_IN_IRAM is enabled --- components/driver/uart/Kconfig.uart | 1 + components/lwip/linker.lf | 2 ++ components/vfs/CMakeLists.txt | 1 + components/vfs/Kconfig | 7 +++++++ components/vfs/linker.lf | 6 ++++++ components/vfs/test_apps/pytest_vfs.py | 2 +- components/vfs/test_apps/sdkconfig.ci.iram | 1 + components/vfs/vfs.c | 1 + 8 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 components/vfs/linker.lf create mode 100644 components/vfs/test_apps/sdkconfig.ci.iram diff --git a/components/driver/uart/Kconfig.uart b/components/driver/uart/Kconfig.uart index 96ea2571de..4272cb290f 100644 --- a/components/driver/uart/Kconfig.uart +++ b/components/driver/uart/Kconfig.uart @@ -3,6 +3,7 @@ menu "UART Configuration" config UART_ISR_IN_IRAM bool "Place UART ISR function into IRAM" depends on !RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH + select VFS_SELECT_IN_RAM if VFS_SUPPORT_SELECT default n help If this option is not selected, UART interrupt will be disabled for a long time and diff --git a/components/lwip/linker.lf b/components/lwip/linker.lf index 055b2fc55b..97e60e2d69 100644 --- a/components/lwip/linker.lf +++ b/components/lwip/linker.lf @@ -134,3 +134,5 @@ entries: memp:do_memp_malloc_pool (noflash_text) if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: * (extram_bss) + if VFS_SELECT_IN_RAM = y: + vfs_lwip:lwip_stop_socket_select_isr (noflash) diff --git a/components/vfs/CMakeLists.txt b/components/vfs/CMakeLists.txt index 8ac55d67c1..d056cd8b0d 100644 --- a/components/vfs/CMakeLists.txt +++ b/components/vfs/CMakeLists.txt @@ -14,6 +14,7 @@ list(APPEND pr driver esp_timer) idf_component_register(SRCS ${sources} + LDFRAGMENTS "linker.lf" INCLUDE_DIRS include PRIV_INCLUDE_DIRS private_include PRIV_REQUIRES ${pr}) diff --git a/components/vfs/Kconfig b/components/vfs/Kconfig index 0c7b2ce972..1665898e9d 100644 --- a/components/vfs/Kconfig +++ b/components/vfs/Kconfig @@ -63,6 +63,13 @@ menu "Virtual file system" It is possible to suppress these debug outputs by enabling this option. + config VFS_SELECT_IN_RAM + bool "Make VFS driver select() callbacks IRAM-safe" + default n + depends on VFS_SUPPORT_SELECT + help + If enabled, VFS driver select() callback function will be placed in IRAM. + config VFS_SUPPORT_TERMIOS bool "Provide termios.h functions" default y diff --git a/components/vfs/linker.lf b/components/vfs/linker.lf new file mode 100644 index 0000000000..9c8e69b5f7 --- /dev/null +++ b/components/vfs/linker.lf @@ -0,0 +1,6 @@ +[mapping:vfs] +archive: libvfs.a +entries: + if VFS_SELECT_IN_RAM = y: + vfs:esp_vfs_select_triggered_isr (noflash) + vfs_uart:select_notif_callback_isr (noflash) diff --git a/components/vfs/test_apps/pytest_vfs.py b/components/vfs/test_apps/pytest_vfs.py index d2e7d97f31..92c19370a3 100644 --- a/components/vfs/test_apps/pytest_vfs.py +++ b/components/vfs/test_apps/pytest_vfs.py @@ -11,7 +11,7 @@ from pytest_embedded import Dut @pytest.mark.esp32h2 @pytest.mark.generic @pytest.mark.parametrize('config', [ - 'default', + 'default', 'iram', ], indirect=True) def test_vfs_default(dut: Dut) -> None: dut.run_all_single_board_cases() diff --git a/components/vfs/test_apps/sdkconfig.ci.iram b/components/vfs/test_apps/sdkconfig.ci.iram new file mode 100644 index 0000000000..328d7f113c --- /dev/null +++ b/components/vfs/test_apps/sdkconfig.ci.iram @@ -0,0 +1 @@ +CONFIG_UART_ISR_IN_IRAM=y diff --git a/components/vfs/vfs.c b/components/vfs/vfs.c index d68699af05..9b2c7887c8 100644 --- a/components/vfs/vfs.c +++ b/components/vfs/vfs.c @@ -1194,6 +1194,7 @@ void esp_vfs_select_triggered_isr(esp_vfs_select_sem_t sem, BaseType_t *woken) // matter here stop_socket_select() will be called for only valid VFS drivers. const vfs_entry_t *vfs = s_vfs[i]; if (vfs != NULL && vfs->vfs.stop_socket_select_isr != NULL) { + // Note: If the UART ISR resides in IRAM, the function referenced by stop_socket_select_isr should also be placed in IRAM. vfs->vfs.stop_socket_select_isr(sem.sem, woken); break; }