Cannot use custom pins for SPI on esp32-pico-v3

brahmajit
Posts: 24
Joined: Wed Sep 08, 2021 10:31 am

Cannot use custom pins for SPI on esp32-pico-v3

Postby brahmajit » Wed Sep 08, 2021 10:39 am

I'm trying to use custom pins for SPI (the multiple SPI example). But getting the `Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.` error. I have decoded the backtrace. Any help would be appreciated.

My sketch
  1.  
  2. /* The ESP32 has four SPi buses, however as of right now only two of
  3.  * them are available to use, HSPI and VSPI. Simply using the SPI API
  4.  * as illustrated in Arduino examples will use VSPI, leaving HSPI unused.
  5.  *
  6.  * However if we simply intialise two instance of the SPI class for both
  7.  * of these buses both can be used. However when just using these the Arduino
  8.  * way only will actually be outputting at a time.
  9.  *
  10.  * Logic analyser capture is in the same folder as this example as
  11.  * "multiple_bus_output.png"
  12.  *
  13.  * created 30/04/2018 by Alistair Symonds
  14.  */
  15. #include <SPI.h>
  16.  
  17. // Define ALTERNATE_PINS to use non-standard GPIO pins for SPI bus
  18.  
  19. #ifdef ALTERNATE_PINS
  20.   #define VSPI_MISO   2
  21.   #define VSPI_MOSI   4
  22.   #define VSPI_SCLK   0
  23.   #define VSPI_SS     33
  24.  
  25.   #define HSPI_MISO   26
  26.   #define HSPI_MOSI   27
  27.   #define HSPI_SCLK   25
  28.   #define HSPI_SS     32
  29. #else
  30.   #define VSPI_MISO   MISO
  31.   #define VSPI_MOSI   MOSI
  32.   #define VSPI_SCLK   SCK
  33.   #define VSPI_SS     SS
  34.  
  35.   #define HSPI_MISO   12
  36.   #define HSPI_MOSI   13
  37.   #define HSPI_SCLK   14
  38.   #define HSPI_SS     15
  39. #endif
  40.  
  41. static const int spiClk = 1000000; // 1 MHz
  42.  
  43. //uninitalised pointers to SPI objects
  44. SPIClass * vspi = NULL;
  45. SPIClass * hspi = NULL;
  46.  
  47. void setup() {
  48.   //initialise two instances of the SPIClass attached to VSPI and HSPI respectively
  49.   vspi = new SPIClass(VSPI);
  50.   hspi = new SPIClass(HSPI);
  51.  
  52.   //clock miso mosi ss
  53.  
  54. #ifndef ALTERNATE_PINS
  55.   //initialise vspi with default pins
  56.   //SCLK = 18, MISO = 19, MOSI = 23, SS = 5
  57.   vspi->begin();
  58. #else
  59.   //alternatively route through GPIO pins of your choice
  60.   vspi->begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS); //SCLK, MISO, MOSI, SS
  61. #endif
  62.  
  63. #ifndef ALTERNATE_PINS
  64.   //initialise hspi with default pins
  65.   //SCLK = 14, MISO = 12, MOSI = 13, SS = 15
  66.   hspi->begin();
  67. #else
  68.   //alternatively route through GPIO pins
  69.   hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS); //SCLK, MISO, MOSI, SS
  70. #endif
  71.  
  72.   //set up slave select pins as outputs as the Arduino API
  73.   //doesn't handle automatically pulling SS low
  74.   pinMode(VSPI_SS, OUTPUT); //VSPI SS
  75.   pinMode(HSPI_SS, OUTPUT); //HSPI SS
  76.  
  77. }
  78.  
  79. // the loop function runs over and over again until power down or reset
  80. void loop() {
  81.   //use the SPI buses
  82.   vspiCommand();
  83.   hspiCommand();
  84.   delay(100);
  85. }
  86.  
  87. void vspiCommand() {
  88.   byte data = 0b01010101; // junk data to illustrate usage
  89.  
  90.   //use it as you would the regular arduino SPI API
  91.   vspi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
  92.   digitalWrite(VSPI_SS, LOW); //pull SS slow to prep other end for transfer
  93.   vspi->transfer(data);  
  94.   digitalWrite(VSPI_SS, HIGH); //pull ss high to signify end of data transfer
  95.   vspi->endTransaction();
  96. }
  97.  
  98. void hspiCommand() {
  99.   byte stuff = 0b11001100;
  100.  
  101.   hspi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
  102.   digitalWrite(HSPI_SS, LOW);
  103.   hspi->transfer(stuff);
  104.   digitalWrite(HSPI_SS, HIGH);
  105.   hspi->endTransaction();
  106. }
Output from serial monitor

Code: Select all

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 271414342, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5856
entry 0x400806a8
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x40080f31  PS      : 0x00060730  A0      : 0x800d0f3d  A1      : 0x3ffb1f30
A2      : 0x0000000e  A3      : 0x00000002  A4      : 0x3ffb8364  A5      : 0x00000001
A6      : 0x00000000  A7      : 0x00000004  A8      : 0x3f400674  A9      : 0xaaaaaaaa
A10     : 0xaaaaaaaa  A11     : 0x00000030  A12     : 0x3ffb82cc  A13     : 0x00000000
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x00000009  EXCCAUSE: 0x0000001c
EXCVADDR: 0xaaaaaaaa  LBEG    : 0x400d1258  LEND    : 0x400d1265  LCOUNT  : 0x00000000

ELF file SHA256: 0000000000000000

Backtrace: 0x40080f31:0x3ffb1f30 0x400d0f3a:0x3ffb1f50 0x400d0db2:0x3ffb1f70 0x400d0c2b:0x3ffb1f90 0x400d190a:0x3ffb1fb0 0x40085fa5:0x3ffb1fd0

Rebooting...
ets Jul 29 2019 12:21:46
The decoded backtrace

Code: Select all

0x40080f31: __pinMode at C:\Users\newto\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.5\cores\esp32\esp32-hal-gpio.c line 115
0x400d0f3a: spiAttachSCK at C:\Users\newto\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.5\cores\esp32\esp32-hal-spi.c line 87
0x400d0db2: SPIClass::begin(signed char, signed char, signed char, signed char) at C:\Users\newto\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.5\libraries\SPI\src\SPI.cpp line 57
0x400d0c2b: setup() at C:\Users\newto\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.5\libraries\SPI\examples\SPI_Multiple_Buses/SPI_Multiple_Buses.ino line 67
0x400d190a: loopTask(void*) at C:\Users\newto\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.5\cores\esp32\main.cpp line 32
0x40085fa5: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: Cannot use custom pins for SPI on esp32-pico-v3

Postby ESP_Sprite » Thu Sep 09, 2021 1:35 am

From the pico-v3 datasheet:
None of the embedded flash data pins are connected externally on ESP32-PICO-V3. These are connected internally to GPIO16, GPIO17, GPIO18, and GPIO23.
MOSI on Arduino is defined to 23, making the example try to reconfigure a pin the SoC needs for flash access. Suggest you change that to something else.

Who is online

Users browsing this forum: No registered users and 104 guests