Timer interrupt and reading/writing flash memory causes a crash
Posted: Thu Jun 28, 2018 5:35 pm
I can read and write to the flash memory without problems in the main program. Doing the same in a timer interrupt routine (watchdog) causes a crash. The objective is to save some status values when the watchdog gets triggered.
I thought it might be a timing issue, but increasing the watchdog timeout from 300 to 900ms does not help.
I thought it might be a timing issue, but increasing the watchdog timeout from 300 to 900ms does not help.
Code: Select all
hw_timer_t *timer = NULL;
void IRAM_ATTR resetModule() {
int32_t tempValue = 0;
nvs_handle my_handle;
esp_err_t err;
ESP_ERROR_CHECK(nvs_open("storage", NVS_READWRITE, &my_handle));
ets_printf("**** Program will crash now: ****\n");
err = nvs_get_i32(my_handle, "TEST", &tempValue);
ets_printf("value read\n"); // never reaches that point
esp_restart();
}
void initWatchdog(int wdtTimeout)
{
timer = timerBegin(0, 80, true); //timer 0, div 80
timerAttachInterrupt(timer, &resetModule, true); //attach callback
timerAlarmWrite(timer, wdtTimeout * 1000 * 1000, false); //set time in us
timerAlarmEnable(timer);
timerWrite(timer, 0);
}
void app_main()
{
initWatchdog(2);
while(1){
vTaskDelay(50000 / portTICK_RATE_MS); //
printf("...\n");
}
}
Code: Select all
**** Program will crash now: ****
Guru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0)
Core 0 register dump:
PC : 0x40086542 PS : 0x00060034 A0 : 0x8008594e A1 : 0x3ffb02e0
0x40086542: vListInsert at /Users/spadmin/esp/esp-idf/components/freertos/list.c:188 (discriminator 1)
A2 : 0x3ffafcf8 A3 : 0x3ffb4df4 A4 : 0x00060021 A5 : 0x00000001
A6 : 0x00060021 A7 : 0x3ffb04a4 A8 : 0x3ffb4df4 A9 : 0x3ffb4df4
A10 : 0x00000019 A11 : 0x00000019 A12 : 0x3ffb04a4 A13 : 0x00000001
A14 : 0x00060023 A15 : 0xff000000 SAR : 0x0000001e EXCCAUSE: 0x00000005
EXCVADDR: 0x00000000 LBEG : 0x40001609 LEND : 0x4000160d LCOUNT : 0x00000000
Core 0 was running in ISR context:
EPC1 : 0x40084493 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x40086542
0x40084493: xQueueGenericSend at /Users/spadmin/esp/esp-idf/components/freertos/queue.c:2037
0x40086542: vListInsert at /Users/spadmin/esp/esp-idf/components/freertos/list.c:188 (discriminator 1)
Backtrace: 0x40086542:0x3ffb02e0 0x4008594b:0x3ffb0300 0x4008482c:0x3ffb0320 0x400d1490:0x3ffb0360 0x400d1532:0x3ffb0380 0x40083108:0x3ffb03a0 0x400835c6:0x3ffb03c0 0x400e0631:0x3ffb0430 0x400e09a7:0x3ffb0450 0x400e0a6d:0x3ffb04a0 0x400dfee3:0x3ffb0510 0x400df8d9:0x3ffb0560 0x400dfacd:0x3ffb05a0 0x40082aa0:0x3ffb05c0 0x40083e9d:0x3ffb05f0 0x400823b5:0x3ffb0610 0x400d1c2b:0x00000000
0x40086542: vListInsert at /Users/spadmin/esp/esp-idf/components/freertos/list.c:188 (discriminator 1)