Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash/reboot in writing to SPI?! #125

Open
stapelberg opened this issue May 24, 2021 · 0 comments
Open

crash/reboot in writing to SPI?! #125

stapelberg opened this issue May 24, 2021 · 0 comments

Comments

@stapelberg
Copy link

Sometimes (haven’t figured out when or why exactly), my M5ez-based UI crashes/reboots with the following backtrace:

Backtrace: 0x4008ce58:0x3ffbe170 0x4008d089:0x3ffbe190 0x400ee51b:0x3ffbe1b0 0x40085161:0x3ffbe1d0 0x400e2329:0x3ffce600 0x400e2535:0x3ffce620 0x400d710e:0x3ffce650 0x400d1886:0x3ffce670 0x400d199e:0x3ffce6a0 0x401693db:0x3ffce6c0 0x400e871e:0x3ffce6e0 0x400d1612:0x3ffce720 0x4008956d:0x3ffce740

GDB says:

(gdb) l *0x4008ce58
0x4008ce58 is in invoke_abort (/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:155).
(gdb) l *0x4008d089
0x4008d089 is in abort (/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:170).
(gdb) l *0x400ee51b
0x400ee51b is in task_wdt_isr (/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/task_wdt.c:174).
(gdb) l *0x40085161
0x40085161 is at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/xtensa_vectors.S:1154.
(gdb) l *0x400e2329
0x400e2329 is in writeBlock(unsigned short, unsigned int) (/home/michael/Arduino/libraries/M5Stack/src/utility/In_eSPI.cpp:5316).
5311	  if (repeat > 31) // Revert legacy toggle buffer change
5312	  {
5313	    WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), 511);
5314	    while(repeat>31)
5315	    {
5316	      while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT))&SPI_USR);
5317	      WRITE_PERI_REG(SPI_W0_REG(SPI_PORT), color32);
5318	      WRITE_PERI_REG(SPI_W1_REG(SPI_PORT), color32);
5319	      WRITE_PERI_REG(SPI_W2_REG(SPI_PORT), color32);
5320	      WRITE_PERI_REG(SPI_W3_REG(SPI_PORT), color32);
(gdb) l *0x400e2535
0x400e2535 is in TFT_eSPI::fillRect(int, int, int, int, unsigned int) (/home/michael/Arduino/libraries/M5Stack/src/utility/In_eSPI.cpp:3951).
3946	    else
3947	    {
3948	      while (n--) {tft_Write_16(color);}
3949	    }
3950	  #else
3951	    writeBlock(color, n);
3952	  #endif
3953	#endif
3954	
3955	  spi_end();
(gdb) l *0x400d710e
0x400d710e is in ezHeader::show(String) (/home/michael/Arduino/libraries/M5ez/src/M5ez.cpp:191).
186	}
187	
188	void ezHeader::show(String t /* = "" */) {
189		_shown = true;
190		if (t != "") _title = t;											// only change title if provided
191		m5.lcd.fillRect(0, 0, TFT_W, ez.theme->header_height, ez.theme->header_bgcolor);	// Clear header area
192		for (uint8_t n = 0; n < _widgets.size(); n++) {
193			(_widgets[n].function)(_widgets[n].x, _widgets[n].w);		// Tell all header widgets to draw
194		}
195		ez.canvas.top(ez.theme->header_height);
(gdb) l *0x400d1886
0x400d1886 is in redraw() (/home/michael/Arduino/scan2drive-ui-m5stack/scan2drive-ui-m5stack.ino:113).
108	
109	void redraw(void) {
110	  //ez.screen.clear();
111	  ez.canvas.reset();
112	
113	  ez.header.show("scan2drive");
114	  ez.buttons.show("Lea # Michael # source");
115	
116	  ez.canvas.lmargin(10);

Any idea what I’m doing wrong, or whether this is a bug in M5ez?

I’m using M5ez 2.3.0 on an M5Stack Basic with the following sketch:

#include <M5ez.h>
#include <WiFi.h>
#include <PubSubClient.h>

WiFiClient wificlient;
PubSubClient client(wificlient);

void redraw(void);

void connectToWiFi(void) {
  Serial.println("WiFi: configuring");
  WiFi.mode(WIFI_STA);
  // required to set hostname properly:
  // https://github.com/espressif/arduino-esp32/issues/3438#issuecomment-721428310
  WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
  WiFi.setHostname("uiscan2drive");
  WiFi.begin("secret", "secret");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.println("WiFi: connecting...");
    delay(100);
  }
  Serial.print("WiFi: connected: mac=");
  Serial.print(WiFi.macAddress());
  Serial.print(" ip=");
  Serial.print(WiFi.localIP());
  Serial.println("");
}

void taskmqtt(void *pvParameters) {
  for (;;) {
    if (!client.connected()) {
      client.connect("ui_scan2drive" /* clientid */);
      client.subscribe("scan2drive/ui/status");
      client.subscribe("scan2drive/ui/user");
    }

    // Poll PubSubClient for new messages and invoke the callback.
    // Should be called as infrequent as one is willing to delay
    // reacting to MQTT messages.
    // Should not be called too frequently to avoid strain on
    // the network hardware:
    // https://github.com/knolleary/pubsubclient/issues/756#issuecomment-654335096
    client.loop();
    vTaskDelay(pdMS_TO_TICKS(100));
  }
}

// Size determined by how much space we have on the LCD display.
// m5ez does line wrapping for us.
char statusbuffer[140] = {'\0'};

void callback(char* topic, byte* payload, unsigned int length) {
#if 0
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
#endif

  if (strcmp(topic, "scan2drive/ui/status") == 0) {
    int len = length;
    if (len > sizeof(statusbuffer)) {
      len = sizeof(statusbuffer) - 1;
    }
    strncpy(statusbuffer, (const char*)payload, len);
    statusbuffer[len] = '\0';
    if (strcmp(statusbuffer, "powersave") == 0) {
      m5.lcd.setBrightness(0);
    } else {
      m5.lcd.setBrightness(100);
    }
    redraw();
  }
}

void setup() {
  Serial.begin(115200);
  Serial.println("setup");
#include <themes/default.h>
#include <themes/dark.h>
  ezt::setDebug(INFO);
  // ez.begin() calls m5.begin() under the covers:
  ez.begin();
  redraw();

  connectToWiFi();

  client.setServer("dr.lan", 1883);
  client.setCallback(callback);

  xTaskCreatePinnedToCore(taskmqtt, "MQTT", 2048, NULL, 1, NULL, PRO_CPU_NUM);

}

int source = 0;
const char *sourceIdentifiers[] = {
  "usb",
  "airscan",
};
const char *sourceLabels[] = {
  "Fujitsu ScanSnap",
  "Brother (AirScan)",
};

void redraw(void) {
  //ez.screen.clear();
  ez.canvas.reset();

  ez.header.show("scan2drive");
  ez.buttons.show("Lea # Michael # source");

  ez.canvas.lmargin(10);

  ez.canvas.println("");
  ez.canvas.font(&FreeSansBold12pt7b);
  ez.canvas.printf("Source: ");
  ez.canvas.font(&FreeSans12pt7b);
  ez.canvas.println(sourceLabels[source]);

  ez.canvas.font(&FreeSansBold12pt7b);
  ez.canvas.printf("Status: ");
  ez.canvas.font(&FreeSans12pt7b);
  ez.canvas.println(statusbuffer);

  ez.redraw();
}

void loop() {
  String buttonName = ez.buttons.poll();
  if (buttonName == "source") {
    source = (source + 1) % 2;
    redraw();
    return;
  }
  if (buttonName == "Lea" || buttonName == "Michael") {
    String payload = String("{\"user\":\"") +
                     buttonName +
                     String("\", \"source\": \"") +
                     String(sourceIdentifiers[source]) +
                     String("\"}");
    client.publish("scan2drive/cmd/scan", payload.c_str());
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant