UART and LittleFS crash when used together

HighVoltage
Posts: 52
Joined: Mon Oct 24, 2022 9:37 pm

UART and LittleFS crash when used together

Postby HighVoltage » Fri Dec 01, 2023 7:29 am

I am running my application on ESP32E, 4MB, with IDFv4.4.6.

I updated to the latest esp_littlefs from https://github.com/joltwallet/esp_littl ... master/src and am using LittleFS from arduino component.

My applicatioin is structured with below two tasks running on Core 0.
SerialReceiverTask, priority 2, uses interrupts to read from UART2, and passes data to queue.
WebServerTask, priority 1, serves HTTP requests, some of which use LittleFS

There is a constant stream of data coming in on UART2. But there's still plenty of time to respond to HTTP requests. Requests that don't use LittleFS respond fine, regardless if there is incoming data on the UART or not.

The request that accesses LittleFS also work fine when I disconnect the serial line so there's no incoming data on the UART. However, if there is incoming data, and I make the request, it consistently crashes as below. The first 3 lines only show up on the console, not in the decoded hex backtrace. I'd appreciate any insights on the problem.
0x4011bff8: uart_clear_intr_status at C:/exp/frameworks/esp-idf-v4.4.6/components/driver/uart.c:364
0x40082f50: _xt_lowint1 at C:/exp/frameworks/esp-idf-v4.4.6/components/freertos/port/xtensa/xtensa_vectors.S:1114
0x40089d56: _frxt_int_enter at C:/exp/frameworks/esp-idf-v4.4.6/components/freertos/port/xtensa/portasm.S:119
0x4011bff5: uart_set_line_inverse at C:/exp/frameworks/esp-idf-v4.4.6/components/driver/uart.c:324
0x40082f4d: _xt_lowint1 at C:/exp/frameworks/esp-idf-v4.4.6/components/freertos/port/xtensa/xtensa_vectors.S:1114
0x4008db1e: spi_flash_ll_set_command at C:/exp/frameworks/esp-idf-v4.4.6/components/hal/esp32/include/hal/spi_flash_ll.h:329
(inlined by) spi_flash_hal_configure_host_io_mode at C:/exp/frameworks/esp-idf-v4.4.6/components/hal/spi_flash_hal_common.inc:120
0x40095691: spi_flash_chip_generic_config_host_io_mode at C:/exp/frameworks/esp-idf-v4.4.6/components/spi_flash/spi_flash_chip_generic.c:531
0x400956fe: spi_flash_chip_generic_read at C:/exp/frameworks/esp-idf-v4.4.6/components/spi_flash/spi_flash_chip_generic.c:229
0x40084d07: esp_flash_read at C:/exp/frameworks/esp-idf-v4.4.6/components/spi_flash/esp_flash_api.c:852 (discriminator 4)
0x4011f965: esp_partition_read at C:/exp/frameworks/esp-idf-v4.4.6/components/spi_flash/partition.c:424
0x4011227f: littlefs_api_read at C:/exp/frameworks/esp-idf-v4.4.6/components/esp_littlefs/src/littlefs_api.c:21
0x401126af: lfs_bd_read at C:/exp/frameworks/esp-idf-v4.4.6/components/esp_littlefs/src/littlefs/lfs.c:116
0x401132a6: lfs_dir_getslice at C:/exp/frameworks/esp-idf-v4.4.6/components/esp_littlefs/src/littlefs/lfs.c:704
0x401133a3: lfs_dir_get at C:/exp/frameworks/esp-idf-v4.4.6/components/esp_littlefs/src/littlefs/lfs.c:750
0x401169b0: lfs_dir_getinfo at C:/exp/frameworks/esp-idf-v4.4.6/components/esp_littlefs/src/littlefs/lfs.c:1386
0x40116ab1: lfs_dir_rawread at C:/exp/frameworks/esp-idf-v4.4.6/components/esp_littlefs/src/littlefs/lfs.c:2744
0x40116dc9: lfs_dir_read at C:/exp/frameworks/esp-idf-v4.4.6/components/esp_littlefs/src/littlefs/lfs.c:6160
0x4010eb41: vfs_littlefs_readdir_r at C:/exp/frameworks/esp-idf-v4.4.6/components/esp_littlefs/src/esp_littlefs.c:1789 (discriminator 4)
0x4010ec69: vfs_littlefs_readdir at C:/exp/frameworks/esp-idf-v4.4.6/components/esp_littlefs/src/esp_littlefs.c:1774
0x400d43df: esp_vfs_readdir at C:/exp/frameworks/esp-idf-v4.4.6/components/vfs/vfs.c:675 (discriminator 3)
0x4010d441: VFSFileImpl::openNextFile(char const*) at C:/exp/frameworks/esp-idf-v4.4.6/components/arduino/libraries/FS/src/vfs_api.cpp:483
0x4010546e: fs::File::openNextFile(char const*) at C:/exp/frameworks/esp-idf-v4.4.6/components/arduino/libraries/FS/src/FS.cpp:187
0x400dc47a: handleConfig() at C:/exp/dmcs/main/Aardvark.cpp:4678
0x401b1ba5: std::_Function_handler<void (), void (*)()>::_M_invoke(std::_Any_data const&) at c:\exp\tools\xtensa-esp32-elf\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:297
0x401036ed: std::function<void ()>::operator()() const at c:\exp\tools\xtensa-esp32-elf\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:687
0x40106f71: FunctionRequestHandler::handle(WebServer&, http_method, String) at C:/exp/frameworks/esp-idf-v4.4.6/components/arduino/libraries/WebServer/src/detail/RequestHandlersImpl.h:45
0x40106fcf: WebServer::_handleRequest() at C:/exp/frameworks/esp-idf-v4.4.6/components/arduino/libraries/WebServer/src/WebServer.cpp:651
0x40107113: WebServer::handleClient() at C:/exp/frameworks/esp-idf-v4.4.6/components/arduino/libraries/WebServer/src/WebServer.cpp:318
0x400e6628: wifiServer(void*) at C:/exp/dmcs/main/Aardvark.cpp:3535
0x4008d349: vPortTaskWrapper at C:/exp/frameworks/esp-idf-v4.4.6/components/freertos/port/xtensa/port.c:142

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: UART and LittleFS crash when used together

Postby MicroController » Fri Dec 01, 2023 10:30 pm

Make sure (menuconfig) that either the UART ISR and IDF ring buffer code are placed in IRAM, or that you do not use ESP_INTR_FLAG_IRAM when installing the UART driver.

HighVoltage
Posts: 52
Joined: Mon Oct 24, 2022 9:37 pm

Re: UART and LittleFS crash when used together

Postby HighVoltage » Sat Dec 02, 2023 4:31 am

MicroController wrote:
Fri Dec 01, 2023 10:30 pm
Make sure (menuconfig) that either the UART ISR and IDF ring buffer code are placed in IRAM, or that you do not use ESP_INTR_FLAG_IRAM when installing the UART driver.
Yes, specifying IRAM for UART ISR in menuconfig fixed it! Thanks! I did have that FLAG_IRAM setting, which I followed from an example.

Could you give some details about using IRAM vs not? Maybe this is documented somewhere, I will poke around.

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: UART and LittleFS crash when used together

Postby MicroController » Sat Dec 02, 2023 7:15 am

HighVoltage wrote:
Sat Dec 02, 2023 4:31 am
Could you give some details about using IRAM vs not? Maybe this is documented somewhere, I will poke around.
See e.g. https://docs.espressif.com/projects/esp ... rency.html

Who is online

Users browsing this forum: Google [Bot], ignisuti and 128 guests