I need a technique to debug an SPI crash I regularly get.
I'm getting a Panic, LoadProhibited crash in an ESP32 design. I have MJPEG files stored on a NAND/SD card and a 240x240 pixel TFT display. Both are connected to the VSPI. I use GPIO32 for the display and GPIO 4 for the SD. They are tied to the VSPI, GPIO 23 MOSI, GPIO 19 MISO, and GPIO 18 SCK.
I start the TFT on the SPI bus with:
Arduino_DataBus *bus = new Arduino_ESP32SPI(SPI_DisplayDC /* DC */, SPI_DisplayCS /* CS */, SPI_SCK /* SCK */, SPI_MOSI /* MOSI */, SPI_MISO /* MISO */, VSPI /* spi_num */); Arduino_GFX *gfx = new Arduino_GC9A01(bus, SPI_DisplayRST, 2 /* rotation */, false /* IPS */); then I start the SPI:
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI); SPI.setFrequency(4000000); // at 8000000 I get CPU panic reboots and start the SD with:
if ( ! SD.begin(SD_CS) ) I coded an MJPEG decoder that reads data from the SD and sends it to the TFT display. After about 10 seconds of normal play I get this crash:
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled. Core 1 register dump: PC : 0x400d222d PS : 0x00060130 A0 : 0x800d1e60 A1 : 0x3ffb1f20 A2 : 0x00000001 A3 : 0x3ffc1878 A4 : 0x00000000 A5 : 0x3ffc5d78 A6 : 0x3ffb9560 A7 : 0x00000001 A8 : 0x800d2225 A9 : 0x0000001a A10 : 0x3ffb1f68 A11 : 0x3ffb9560 A12 : 0x0000001a A13 : 0x3ffb957a A14 : 0x0000004c A15 : 0x00000061 SAR : 0x00000010 EXCCAUSE: 0x0000001c EXCVADDR: 0x00000024 LBEG : 0x4000c349 LEND : 0x4000c36b LCOUNT : 0x00000000 ELF file SHA256: 0000000000000000 Backtrace: 0x400d222d:0x3ffb1f20 0x400d1e5d:0x3ffb1f50 0x400e1f2c:0x3ffb1fb0 0x400896e2:0x3ffb1fd0 Rebooting... I decode the Backtrace to get:
Decoding stack results 0x400d222d: MjpegClass::readMjpegBuf() at /var/folders/8y/z6t4zfcs2611ddcwsm1cg1080000gn/T/arduino_build_687015/sketch/MjpegClass.cpp line 136 0x400d1e5d: loop() at /Users/frankcohen/Documents/Arduino/13StoryRunner/13StoryRunner.ino line 178 0x400e1f2c: loopTask(void*) at /Users/frankcohen/Documents/Arduino/hardware/espressif/esp32/cores/esp32/main.cpp line 23 0x400896e2: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143 This is the offending line: _buf_read = _input->readBytes(_read_buf + o, READ_BUFFER_SIZE - o); I added debugging around line 136 of MjpegClass.cpp to see if maybe the buffer is corrupt or no longer valid. It looks fine.
I'm seeking advice on where I should look next?
The software repository is here: https://github.com/frankcohen/ReflectionsOS/tree/main/Devices/Sox/Software/13StoryRunner