- Sketch core-dumps in infinite loop on the first
m_sampler->read(m_sample_buffer, WINDOW_SIZE)
call with the following output:
ELF file SHA256: e1628abd6cce84a4
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13104
load:0x40080400,len:3036
entry 0x400805e4
[ 51][E][esp32-hal-gpio.c:102] __pinMode(): Invalid pin selected
E (32) gpio: gpio_set_level(226): GPIO output gpio_num error
Display is 240 x 135
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x400d9f34 PS : 0x00060030 A0 : 0x800d53a4 A1 : 0x3ffd6750
A2 : 0x00000000 A3 : 0x3ffb93b8 A4 : 0x00000400 A5 : 0x3ffd679c
A6 : 0xffffffff A7 : 0x3ffc2858 A8 : 0x00000000 A9 : 0x3ffbea9c
A10 : 0x3ffc2c90 A11 : 0x3ffc2c90 A12 : 0x3ffc2c90 A13 : 0x00060023
A14 : 0x00060021 A15 : 0x00000001 SAR : 0x00000000 EXCCAUSE: 0x0000001c
EXCVADDR: 0x0000001c LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
Backtrace: 0x400d9f31:0x3ffd6750 0x400d53a1:0x3ffd6790 0x400d1af1:0x3ffd67c0 0x400d1b0d:0x3ffd67e0
#0 0x400d9f31:0x3ffd6750 in i2s_read at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/driver/i2s.c:2264 (discriminator 2)
#1 0x400d53a1:0x3ffd6790 in ADCSampler::read(short*, int) at lib/audio_input/src/ADCSampler.cpp:41
#2 0x400d1af1:0x3ffd67c0 in Application::process_samples() at src/application.cpp:50
#3 0x400d1b0d:0x3ffd67e0 in processing_task(void*) at src/application.cpp:17 (discriminator 1)
Apparently, processing_task
(and attempts to read samples) starts before i2s driver is initialized.
It happens because of race conditions in
void Application::begin()
asynchronous processing task is created before i2s is initialized:
xTaskCreatePinnedToCore(processing_task, "Processing Task", 4096, this, 2, &processing_task_handle, 0);
...
m_sampler->start(); //here i2s driver is initizlied
so processing task might already call i2s_read
which would cause abort.
The fix would be to call
m_sampler->start();
first in the void Application::begin()
and only then call
xTaskCreatePinnedToCore(processing_task, "Processing Task", 4096, this, 2, &processing_task_handle, 0);
After fixing the problem above, I've got another:
2. Sketch is running, but from time to time is aborts and restarts with the following output:
E (30476) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (30476) task_wdt: - IDLE (CPU 0)
E (30476) task_wdt: Tasks currently running:
E (30476) task_wdt: CPU 0: Processing Task
E (30476) task_wdt: CPU 1: Drawing Task
E (30476) task_wdt: Aborting.
abort() was called at PC 0x400e04f5 on core 0
Backtrace: 0x40083729:0x3ffbea2c |<-CORRUPTED
#0 0x40083729:0x3ffbea2c in panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c:402
This happens because all the tasks runs infinitely, but FreeRTOS wants at least some yeld for its housekeeping.
Fix is to add vTaskDelay(1);
inside the loop in the processing_task
function