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 with ESP32 when wifi enabled. #39

Closed
fanfanlatulipe26 opened this issue Jun 30, 2023 · 3 comments
Closed

Crash with ESP32 when wifi enabled. #39

fanfanlatulipe26 opened this issue Jun 30, 2023 · 3 comments

Comments

@fanfanlatulipe26
Copy link

When a webserver is used the ESP32 crash with default iBus config.
It runs OK if IBUSBM_NOTIMER is used with explicit call to .loop()
This problem may be linked to issue #33
Configuration: ESP32 Dev Kit board
Arduino IDE 1.8.19
ESP32 package2.0.9

Small test case:

#include <WiFi.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <IBusBM.h>

const char* ssid = "..........";
const char* password = "............................";
uint8_t rpmSens;
IBusBM IBus;
WebServer server(80);
uint16_t speed = 0;
void handleRoot() {
  server.send(200, "text/plain", "hello from esp32!");
}

void setup(void) {
  IBus.begin(Serial2);  //  crash ............
//  IBus.begin(Serial2, IBUSBM_NOTIMER); // OK
  rpmSens =  IBus.addSensor(IBUSS_RPM);

  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("esp32")) {
    Serial.println("MDNS responder started for esp32.local");
  }
  server.on("/", handleRoot);
  server.begin();
  Serial.println("HTTP server started");
}

void loop(void) {
//  IBus.loop();
  IBus.setSensorMeasurement(rpmSens, speed);
  speed += 1;
  server.handleClient();
  delay(2);//allow the cpu to switch to other tasks
}

The crash:

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

rst:0xc (SW_CPU_RESET),boot:0x17 (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:1
load:0x3fff0030,len:1344
load:0x40078000,len:13924
ho 0 tail 12 room 4
load:0x40080400,len:3600
entry 0x400805f0

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


Backtrace: 0x40083731:0x3ffbf32c |<-CORRUPTED




ELF file SHA256: 9faf0afb38fda9e7

Rebooting...
@fanfanlatulipe26
Copy link
Author

Same problem if we use timer 1 or 2 or 3 instead of the default timer 0.
Some times, after several crashes the Wifi get connected and the web server is OK.
Some time the system freeze .

@fanfanlatulipe26
Copy link
Author

The test case run OK if we perform the init of the ibus stuff at the end of the setup() ..., after all others init for the wifi. Not sure if this workarround does'nt give others problems ...
May be the best in this context is to use the IBUSBM_NOTIMER.
Anyhow the problem doesn't seem to really come from the IbusBM libray and I close this issue.

@fanfanlatulipe26
Copy link
Author

At least in the ARDUINO ESP32 context it is strongly advised in the documentation to not used Serial in ISR.
Even just the first test in the ISR uses available(...) that uses uartAvailable(...) that uses soon the macro UART_MUTEX_LOCK making a call to xSemaphoreTake(uart->lock, portMAX_DELAY) != pdPASS.
This macro must not be called from an ISR: documented in https://www.freertos.org/a00122.html)

So really better to not use the timer / ISR at least in the context ARDUINO/ESP32 and use the option IBUSBM_NOTIMER and call directly iBus.loop();

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