ESP32S3 crashes using Arduino_gfx library

Hello, guys.
I'm currently battling a bug using the "Arduino_GFX.h" library from moononournation (GitHub - moononournation/Arduino_GFX: Arduino GFX developing for various color displays and various data bus interfaces). I have implemented my display related code in a disp.h file. Each time I include this file in my main.ino file and call my custom lcdInit() function, the MCU crashes.

I'm currently testing this firmware on ESP32S3-mini-1 dev board.
Arduino version: 2.3.2
I intend to use this firmware on this ESP32S3 dev board: https://s.click.aliexpress.com/e/_EG1ZBqH along with a 2.1Inch TFT display 480x480 which uses st7701 driver.

disp.h

#pragma once
#include "Arduino_GFX.h"
#include <Arduino_GFX_Library.h>


#define HSPI_SPI  2 //Use HSPI for ESP32S3 (https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-spi.h#L31-L43)

//Available spare pins one the dev board: r https://s.click.aliexpress.com/e/_EG1ZBqH

// Un comment if you want to use software based SPI.
// #define USE_SOFTWARE_SPI 


class LCDDisplay{

public:
  LCDDisplay(){
/****************************************************************
* The Pins used in the configuration are all based on the pin information provided by the display driver manufacturer:
* https://s.click.aliexpress.com/e/_EG1ZBqH
****************************************************************/

#ifdef USE_SOFTWARE_SPI
    bus = new Arduino_SWSPI(GFX_NOT_DEFINED /* DC */, 42 /* CS */,
    2 /* SCK */, 1 /* MOSI */, GFX_NOT_DEFINED /* MISO */);
#else
    // Setup SPI bus (used only for sending commands to ST7701)
    bus = new Arduino_ESP32SPI(
        GFX_NOT_DEFINED /* No info from manufacturer about DC */, 42 /* CS */, 2 /* SCK */, 1 /* MOSI */, GFX_NOT_DEFINED, HSPI_SPI
    );
#endif

    // For 2.1" round display: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration (ESP32-S3-RGB)
    rgbpanel = new Arduino_ESP32RGBPanel(
      40 /* DE */, 39 /* VSYNC */, 38 /* HSYNC */, 41 /* PCLK */,
      46 /* R0 */, 3 /* R1 */, 8 /* R2 */, 18 /* R3 */, 17 /* R4 */,
      14 /* G0 */, 13 /* G1 */, 12 /* G2 */, 11 /* G3 */, 10 /* G4 */, 9 /* G5 */,
      5 /* B0 */, 45 /* B1 */, 48 /* B2 */, 47 /* B3 */, 21 /* B4 */,
      1 /* hsync_polarity */, 10 /* hsync_front_porch */, 8 /* hsync_pulse_width */, 50 /* hsync_back_porch */,
      1 /* vsync_polarity */, 10 /* vsync_front_porch */, 8 /* vsync_pulse_width */, 20 /* vsync_back_porch */
    );

    gfx = new Arduino_RGB_Display(
    480 /* width */, 480 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */,
    bus, GFX_NOT_DEFINED /* RST */, st7701_type5_init_operations, sizeof(st7701_type5_init_operations));
      
  }

  void lcdInit(){
    gfx->begin();
  }


private:
Arduino_ESP32RGBPanel *rgbpanel = {nullptr};
Arduino_DataBus *bus = {nullptr};
Arduino_RGB_Display *gfx = {nullptr};
uint16_t color;

};

Here's where I'm using disp.h in main.ino:

#include "disp.h"

LCDDisplay *disp = nullptr;//LCDDisplay();

// the setup function runs once when you press reset or power the board
void setup() {

  disp = new LCDDisplay();
  disp->lcdInit();

}

// the loop function runs over and over again forever
void loop() {}

After flashing this code to the ESP32S3-mini-1 dev board, it throws the crash log:

ELF file SHA256: 50f8e54a0

Rebooting...
��΄(��:�J19�L��!���Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x4037cc89  PS      : 0x00060730  A0      : 0x82004874  A1      : 0x3fca4b00  
A2      : 0x00ffff00  A3      : 0xffffffff  A4      : 0x04c4b400  A5      : 0x00000001  
A6      : 0x02625a00  A7      : 0x02625a00  A8      : 0x82007725  A9      : 0x3fca4af0  
A10     : 0x00000000  A11     : 0x00000001  A12     : 0x0000002b  A13     : 0x000000ff  
A14     : 0x000000ff  A15     : 0x000002a0  SAR     : 0x00000016  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00ffff40  LBEG    : 0x40056f5c  LEND    : 0x40056f72  LCOUNT  : 0xffffffff  


Backtrace: 0x4037cc86:0x3fca4b00 0x42004871:0x3fca4b40 0x42005ed9:0x3fca4b60 0x42002889:0x3fca4b80 0x4200aa92:0x3fca4bb0 0x4037d16e:0x3fca4bd0 

I have gone steps further to investigate the backtrace memory addresses using the xtensa-esp32-elf-addr2line command on my terminal:

/Users/user/Library/Arduino15/packages/esp32/tools/esp-x32/2405/bin/xtensa-esp32s3-elf-addr2line \
  -pfiaC \
  -e /private/var/folders/q9/_c1p3yd166gdhr9586t0tfbr0000gn/T/arduino/sketches/155135A44E6DEF00AC4834AA2FAA2E7F/canTask.ino.elf \
  0x4037cc86 0x42004871 0x42005ed9 0x42002889 0x4200aa92 0x4037d16e

and from the returned diagnose log from the command above:

0x4037cc86: xQueueSemaphoreTake at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/FreeRTOS-Kernel/queue.c:1713 (discriminator 1)
0x42004871: Arduino_ESP32SPI::begin(long, signed char) at /Users/user/Documents/Arduino/libraries/Arduino_GFX-master/src/databus/Arduino_ESP32SPI.cpp:284 (discriminator 1)
0x42005ed9: Arduino_RGB_Display::begin(long) at /Users/user/Documents/Arduino/libraries/Arduino_GFX-master/src/display/Arduino_RGB_Display.cpp:31
0x42002889: LCDDisplay::lcdInit() at /Users/user/Documents/Arduino/canTask/disp.h:57
 (inlined by) setup() at /Users/user/Documents/Arduino/canTask/main.ino:31
0x4200aa92: loopTask(void*) at /Users/user/Library/Arduino15/packages/esp32/hardware/esp32/3.1.2/cores/esp32/main.cpp:59
0x4037d16e: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:139

does anyone understand what the problem is? According to chatgpt: "the addr2line tool shows the panic chain :

lcdInit() → Arduino_RGB_Display::begin() → Arduino_ESP32SPI::begin() → xQueueSemaphoreTake

so the SPI mutex is still 0x00FFFF00 when xQueueSemaphoreTake() runs.
That can only happen if bus->begin() has not executed (or it executed after the first xQueueSemaphoreTake() inside Arduino_ESP32SPI::begin())."

What could be the problem guys? I sure know the problem stems from the lcdInit() function because each time I comment it out, the crashing stops.

Thanks

Hi @techist_avr ,

not sure but should it probably read

*rgbpanel = new Arduino_ESP32RGBPanel( ...)

because it's declared and used as a pointer? If yes it would also apply to the other assignments (bus and gfx)...

ec2021