arduinospiarduino-esp32lora

I'm trying to use SPI and LoRa and when I initialize the SPI (with custom pins) I get a crash


I am using an ESP32-WROOM-32E with 2 MB PSRAM. If I comment out the begin of the vspi, the code will not crash. (Any help would really be appreciated!)

vspi = new SPIClass(VSPI);
vspi->setHwCs(false);
DebugPrintln("FREE HEAP: %d", ESP.getFreeHeap()); //  (192.3K)
vspi->begin(MY_SPI_SCK, MY_SPI_MISO, MY_SPI_MOSI,MY_SPI_NSS);
DebugPrintln("FREE HEAP: %d", ESP.getFreeHeap()); //  (192.0K)
LoRa.setSPI(*vspi);
LoRa.setPins(MY_SPI_NSS, MY_LORA_RESET, MY_LORA_DIO0);
DebugPrintln("SPI initialized.");
if (!LoRa.begin(915E6)) {
  DebugPrintln("Starting Long Range failed!");
} else {
  DebugPrintln("Long range initialized!");
}

My SPI pins are as follows:

const int MY_SPI_MOSI = 16; 
const int MY_SPI_MISO = 23; 
const int MY_SPI_SCK  = 14; 
const int MY_SPI_NSS  = 5; 
const int MY_LORA_RESET = 2; 
const int MY_LORA_DIO0  = 26; 

The crash I see is with the hw serial (I am outputting a "." in loop() once a second). loopheap is 78K.

Here is the stack trace on crash:

0x40098cf9: xQueueSemaphoreTake at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/queue.c line 1545
0x4010288d: uart_tx_all at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/driver/uart.c line 1231
0x40103189: uart_write_bytes at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/driver/uart.c line 1284
0x400ffdf9: uartWriteBuf at C:/Users/danie/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-uart.c line 686
0x400fc8f1: HardwareSerial::write(unsigned char const*, unsigned int) at C:/Users/danie/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.cpp line 472
0x400fce87: Print::write(char const*) at C:/Users/danie/.platformio/packages/framework-arduinoespressif32/cores/esp32/Print.h line 67
0x400fcf41: Print::print(char const*) at C:/Users/danie/.platformio/packages/framework-arduinoespressif32/cores/esp32/Print.cpp line 84
0x400da989: loop() at src/main.cpp line 4139
0x401004f5: loopTask(void*) at C:/Users/danie/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp line 50

Line 4139 is Serial.print(".");.

I tried to use custom pins to initialize SPI before using LoRa. I expected the code to run like before I called begin on SPI.


Solution

  • Found it. Two issues. One, I used IO16. It is also used by psram. And two, I was running out of heap.