platformio / platform-espressif32

Espressif 32: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/espressif32
Apache License 2.0
901 stars 607 forks source link

Core panic when using with PXMatrix #1369

Closed radical-las closed 4 months ago

radical-las commented 4 months ago

Module: ESP-WROOM-32 DevKit v1 Platform version: 6.6.0 Framework: Arduino IDE: VS Code + PlatformIO All libs are up to date

When using libraries WiFi and PxMatrix at the same time, program crashes. If init WiFi before display, and connection attempt was successful - program is stable. Separately both libs causes no problems.

My test program:

#include <Arduino.h>
#include <PxMatrix.h>
#include <WiFi.h>

const char *ssid = "ssid";
const char *password = "password";

#define P_LAT 22
#define P_A 19
#define P_B 23
#define P_C 18
#define P_D 5
#define P_OE 16
#define MATRIX_WIDTH 64
#define MATRIX_HEIGHT 32
#define PxMATRIX_double_buffer true
PxMATRIX display(MATRIX_WIDTH, MATRIX_HEIGHT, P_LAT, P_OE, P_A, P_B, P_C, P_D);

uint8_t display_draw_time = 5;
hw_timer_t *timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

void IRAM_ATTR display_updater() {
  // Increment the counter and set the time of ISR
  portENTER_CRITICAL_ISR(&timerMux);
  display.display(display_draw_time);
  portEXIT_CRITICAL_ISR(&timerMux);
}

void display_update_enable(bool is_enable) {
  if (is_enable) {
    timer = timerBegin(0, 80, true);
    timerAttachInterrupt(timer, &display_updater, true);
    timerAlarmWrite(timer, 2000, true);
    timerAlarmEnable(timer);
  } else {
    timerDetachInterrupt(timer);
    timerAlarmDisable(timer);
  }
}

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

  WiFi.begin(ssid, password);

  int attemptCounter = 0;
  while (WiFi.status() != WL_CONNECTED && attemptCounter <= 10) {
    attemptCounter++;
    delay(1000);
  }

  display.begin(16);
  display.setMuxPattern(SHIFTREG_ABC_BIN_DE);
  display.setFastUpdate(true);
  display.setTextWrap(false);
  display.clearDisplay();
  display_update_enable(true);
  display.showBuffer();

  Serial.println("END OF INIT");
}

void loop() {
  delay(1000);
}

Error log:

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13232
load:0x40080400,len:3028
entry 0x400805e4

assert failed: xQueueSemaphoreTake queue.c:1554 (!( ( xTaskGetSchedulerState() == ( ( BaseType_t ) 0 ) ) && ( xTicksToWait != 0 ) ))

Backtrace: 0x40083b91:0x3ffbf38c |<-CORRUPTED

  #0  0x40083b91:0x3ffbf38c in panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c:408

Ways to reproduce the error:

1) Init display before WiFi - crashes always

void setup()
{
  display.begin(16);
  display.setMuxPattern(SHIFTREG_ABC_BIN_DE);
  display.setFastUpdate(true);
  display.setTextWrap(false);
  display.setFont(&CyrMono);
  display.clearDisplay();
  display_update_enable(true);
  display.showBuffer();

  WiFi.begin(ssid, password);
}

2) Init display after WiFi, after unsuccessful connection attempt - crashes always, but it takes some time (without counting attempts time)

void setup()
{
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED && attemptCounter <= 10)
  {
    attemptCounter++;
    Delay(1000);
  }

  display.begin(16);
  display.setMuxPattern(SHIFTREG_ABC_BIN_DE);
  display.setFastUpdate(true);
  display.setTextWrap(false);
  display.setFont(&CyrMono);
  display.clearDisplay();
  display_update_enable(true);
  display.showBuffer();
}

3) When trying to refer to WiFi instance - crashes always

void setup()
{
  display.begin(16);
  display.setMuxPattern(SHIFTREG_ABC_BIN_DE);
  display.setFastUpdate(true);
  display.setTextWrap(false);
  display.setFont(&CyrMono);
  display.clearDisplay();
  display_update_enable(true);
  display.showBuffer();

  WiFi.mode(WIFI_STA);
}
valeros commented 4 months ago

Hi @radical-las, could you please try the same code in Arduino IDE?

radical-las commented 4 months ago

Hi @valeros! Thank you for responding! I tried Arduino IDE it kinda work on platform version 1.0.6, but after update to platform version 2.0.11 same problem - core panic.

valeros commented 4 months ago

but after update to platform version 2.0.11 same problem - core panic.

Then you'd better forward the issue to https://github.com/espressif/arduino-esp32