Global SPIClass instance crashes Freenove WROVER

In many examples of using the SPI bus there is code like:

#include <SPI.h>

SPIClass hspi(HSPI);

void setup() {
  Serial.begin(115200);

  Serial.println("Initializing ...");
  hspi.begin();
  // and so on ...

}

void loop() {
  Serial.println("loop");
  delay(1000);
}

but for some reason my Freenove WROVER clone simply freezes and in few seconds gets restarted by the watchdog. After much fiddling with this code I found an alternative that worked just fine:

#include <SPI.h>

SPIClass * hspi = NULL; // don't instantiate just yet

void setup() {
  Serial.begin(115200);

  Serial.println("Initializing ...");
  hspi = new SPIClass(HSPI); // initialize the SPIClass instance here
  hspi->begin();
  // and so on ....
}

void loop() {
  Serial.println("loop");
  delay(1000);
}

I wonder if anyone knows what could be the reason for this? Apparently the board feels bad about instantiating the SPIClass before the setup() but most ESP32 examples have it exactly like this.

Thanks

Not really but i have always used the 2nd method with a pointer to the object.

Is this the same behavior for the older and newer versions of the espressif ESP32 core ?

espressif do appear to have introduced quite a few ‘features’ with recent versions of their core.

I tested your 1st code on a Freenove Wrover (genuine, with CAM) and it worked fine.

  • Platform package: ESP32 by Espressif Systems 3.3.0
  • Board type: "ESP32 Wrover Module" or "ESP32 Dev Module"

In fact, in SPI.cpp, it is defined in the same form as the 1st code.

I also don't understand why the watchdog is firing in core 1...

I was using esp32@3.2.0 and haven’t tried with older versions. But I saw now that there is 3.3.1 and gave that a try … and it worked just fine :blush:

As also pointed to be working by @embeddedkiddie , it must be the 3.3 that has solved it.

Cheers

So by the sound of it a ‘feature’ was introduced in 3.2.0 which needed was fixed by 3.3.1.

ESP32 is becoming a difficult platform to keep up with.

Oh i have to have a look at that to see if they have included something i have been waiting for.