Serial interrupts and LittlsFS together
Posted: Thu Feb 12, 2026 3:03 am
by grunnels@gmail.com
Is there a way to use LittleFS and not drop any serial data? I'm capturing about 8k of serial data per minute and writing to a littleFS file. When the file write happens, interrupts are disabled and I lose serial data. Hardware is an ESP32-S3. Serial is read over GPIO 4 & 5.
Re: Serial interrupts and LittlsFS together
Posted: Thu Feb 12, 2026 1:21 pm
by adokitkat
Hello. You should be able to do so by putting the ISR handler function into IRAM and registering it under the IRAM interrupt flag:
Code: Select all
void IRAM_ATTR my_critical_isr_handler(void *arg) {
// This ISR can run even during flash operations
// BUT: it must NOT access any data in flash either!
// Any function this function calls also HAS to be in IRAM
// Any data this function access has to be placed in DRAM (DRAM_ATTR), e.g.: `static const uint8_t DRAM_ATTR lookup[] = {0, 1, 2, 3};`
}
//...
esp_err_t ret = esp_intr_alloc(ETS_GPIO_INTR_SOURCE,
ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LEVEL1,
my_critical_isr_handler,
NULL,
NULL);
This is more advanced feature so please read the documentation thoroughly.
https://docs.espressif.com/projects/esp ... t-handlers
https://docs.espressif.com/projects/esp ... uction-ram
https://docs.espressif.com/projects/esp ... io_isr_tPv
https://docs.espressif.com/projects/esp ... nc-in-iram
What: In Flash (Default) -> Move to IRAM
- Functions: Regular functions -> IRAM_ATTR
- Called sub-functions: Normal calls -> Must also be IRAM_ATTR
- Const data / tables: const, static const -> DRAM_ATTR
- String literals: "hello" -> Use DRAM_ATTR char arrays
- Logging: ESP_LOGx() -> esp_rom_printf()
- GPIO control: gpio_set_level() -> Direct register access or place GPIO function into IRAM (CONFIG_GPIO_CTRL_FUNC_IN_IRAM)