I have a weird issue.
I am using SPI to read out some temperature sensors. The code I have to do this runs fine on one ESP32, but crashes on another ESP32. Both hardware are the same.
To give some idea, here is my code to init SPI:
Code: Select all
spi_device_handle_t SPI_init(void)
{
ESP_LOGD(tag, ">> test_spi_task");
spi_bus_config_t bus_config {};
bus_config.sclk_io_num = PIN_NUM_CLK; // CLK
bus_config.mosi_io_num = PIN_NUM_MOSI; // MOSI
bus_config.miso_io_num = PIN_NUM_MISO; // MISO
bus_config.quadwp_io_num = -1; // Not used
bus_config.quadhd_io_num = -1; // Not used
ESP_LOGI(tag, "... Initializing bus.");
ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &bus_config, 1));
spi_device_handle_t handle;
spi_device_interface_config_t dev_config {};
dev_config.address_bits = 0;
dev_config.command_bits = 0;
dev_config.dummy_bits = 0;
dev_config.mode = 0;
dev_config.duty_cycle_pos = 0;
dev_config.cs_ena_posttrans = 0;
dev_config.cs_ena_pretrans = 0;
dev_config.clock_speed_hz = 20000;
dev_config.spics_io_num = PIN_NUM_CS;
dev_config.flags = 0;
dev_config.queue_size = 1;
dev_config.pre_cb = NULL;
dev_config.post_cb = NULL;
ESP_LOGI(tag, "... Adding device bus.");
ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &dev_config, &handle));
return handle;
}
Code: Select all
uint32_t spi_tranfer_for_result(spi_device_handle_t spi, const uint8_t *data)
{
spi_transaction_t t;
memset(&t, 0, sizeof(t));
t.length = 8 * 3;
t.flags = SPI_TRANS_USE_RXDATA;
t.user = (void*)1;
t.tx_buffer = data;
esp_err_t ret = spi_device_transmit(spi, &t);
assert(ret == ESP_OK);
// cast to uint32
uint32_t rx_data = t.rx_data[0] | ( (uint32_t)t.rx_data[1] << 8 ) | ( (uint32_t)t.rx_data[2] << 16 ) | ( (uint32_t)t.rx_data[3] << 24 );
return rx_data;
}
On another ESP32, I instantly get a Guru Meditation error as soon as I call the function "spi_device_transmit(spi, &t);" like so:
Code: Select all
Guru Meditation Error: Core 0 panic'ed (IllegalInstruction). Exception was unhandled.
Core 0 register dump:
PC : 0x400d31bc PS : 0x00060430 A0 : 0x8008d20a A1 : 0x3ffc7a60
0x400d31bc: idle_hook_cb at /home/peter/esp/esp-idf-v3.1/components/esp32/task_wdt.c:76
A2 : 0x00000000 A3 : 0x00000000 A4 : 0x3ffb44f0 A5 : 0x3ffb1078
A6 : 0x3ffb4814 A7 : 0x3ffb45bc A8 : 0x800d3628 A9 : 0x3ffc7a40
A10 : 0x400d31bc A11 : 0x40082c10 A12 : 0x00060020 A13 : 0x00000001
0x400d31bc: idle_hook_cb at /home/peter/esp/esp-idf-v3.1/components/esp32/task_wdt.c:76
0x40082c10: _free_r at /home/peter/esp/esp-idf-v3.1/components/newlib/syscalls.c:41
A14 : 0x0000cdcd A15 : 0x00060a23 SAR : 0x00000000 EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
Backtrace: 0x400d31bc:0x3ffc7a60 0x4008d207:0x3ffc7a80
0x400d31bc: idle_hook_cb at /home/peter/esp/esp-idf-v3.1/components/esp32/task_wdt.c:76
0x4008d207: prvIdleTask at /home/peter/esp/esp-idf-v3.1/components/freertos/tasks.c:5112
E (1178) spi_flash: Bad write at offset 0x114284 expected 0x00000000 readback 0x00000002
E (1178) spi_flash: Bad write at offset 0x3b305b4b expected 0x0000000c readback 0x00000001
E (1178) spi_flash: Bad write at offset 0x3b305b4f expected 0x00000001 readback 0x3ffc6330
E (1178) spi_flash: Bad write at offset 0x3b305b53 expected 0x00000000 readback 0x6e69616d
E (1178) spi_flash: Bad write at offset 0x3b305b57 expected 0x800835d1 readback 0xda796000
Now the weirdest part: The SPI does work on the ESP32 where it normally doesn't if I remove all code that has something to do with the UART or the Ethernet part.
And the location/reason of the Guru Meditation error is random.
Mostly it is one of:
- LoadProhibited
- StoreProhibited (0x401771ce: esp_vApplicationWaitiHook at /home/peter/esp/esp-idf-v3.1/components/esp32/freertos_hooks.c:66)
- IllegalInstruction (0x401771cb: esp_vApplicationWaitiHook at /home/peter/esp/esp-idf-v3.1/components/esp32/freertos_hooks.c:66)
- IllegalInstruction (0x401771df: LevelSwitch::initSetpDev(variable*, unsigned short, unsigned short, bool) at /home/peter/esp/WTW_controller/main/AOS/AOS_system.cpp:462)
Any thoughts of what this might be?