nkolban / esp32-snippets

Sample ESP32 snippets and code fragments
https://leanpub.com/kolban-ESP32
Apache License 2.0
2.33k stars 709 forks source link

Firmware crash when sending a char string over BLE to my ESP32 S3 device. #1162

Open aeonSolutions opened 1 year ago

aeonSolutions commented 1 year ago

Hi everyone, I'm getting the following firmware crash when sending a char string over BLE to my ESP32 S3 device. I'm using Arduino Studio 2.1 and esptool 4.5.1

Guru Meditation Error: Core  0 panic'ed (Unhandled debug exception). 
Debug exception reason: Stack canary watchpoint triggered (BTC_TASK) 
Core  0 register dump:
PC      : 0x4037974f  PS      : 0x00060636  A0      : 0x00060630  A1      : 0x3fcecdd0  
A2      : 0x00000000  A3      : 0x00002000  A4      : 0x0000a000  A5      : 0x00002000  
A6      : 0x00000075  A7      : 0xff000000  A8      : 0x20000000  A9      : 0x00000000  
A10     : 0x0000001c  A11     : 0xa0000000  A12     : 0x90000000  A13     : 0x00010000  
A14     : 0x00000056  A15     : 0x00000054  SAR     : 0x00000004  EXCCAUSE: 0x00000001  
EXCVADDR: 0x00000000  LBEG    : 0x400556d5  LEND    : 0x400556e5  LCOUNT  : 0xffffffff  

Backtrace:0x4037974c:0x3fcecdd00x0006062d:0x3fceceb0  |<-CORRUPTED

Bellow is the Class callbacks I'm using to handle BLE messages

class MyServerCallbacks: public BLEServerCallbacks {
    void onConnect(BLEServer* pServer) {
      interface->BLE_IS_DEVICE_CONNECTED = true;
      deviceDisconnected_BLE_callback=false;
      interface->onBoardLED->led[0] = interface->onBoardLED->LED_BLUE;
      interface->onBoardLED->statusLED(100, 1);
    };

    void onDisconnect(BLEServer* pServer) {
      interface->BLE_IS_DEVICE_CONNECTED = false;
      interface->onBoardLED->led[0] = interface->onBoardLED->LED_BLUE;
      interface->onBoardLED->statusLED(100, 0.5);
      interface->onBoardLED->led[0] = interface->onBoardLED->LED_RED;
      interface->onBoardLED->statusLED(100, 0.5);
      interface->onBoardLED->led[0] = interface->onBoardLED->LED_BLUE;
      interface->onBoardLED->statusLED(100, 0.5);
      pServer->getAdvertising()->start();
    }
};

class pCharacteristicTX_Callbacks: public BLECharacteristicCallbacks {
    void onWrite(BLECharacteristic *pCharacteristic) {
      std::string rxValue = pCharacteristic->getValue();

      if (rxValue.length() > 0) {
        String msg="";
        mserial->printStrln("*********");
        mserial->printStr("Received Value: ");
        for (int i = 0; i < rxValue.length(); i++) {
           msg=msg+String(rxValue[i]);
           mserial->printStr(String(rxValue[i])); 
        } 

        mserial->printStrln(""); 
        mserial->printStrln("*********");

        //valueReceived=msg;
      } 
    }

    void onRead(BLECharacteristic *pCharacteristic) {
      mserial->printStrln("*********");
      mserial->printStr("onRead...");    
      pCharacteristic->setValue("OK");
    }

  }; 

class pCharacteristicRX_Callbacks: public BLECharacteristicCallbacks {
    void onWrite(BLECharacteristic *pCharacteristic) {
      std::string rxValue = pCharacteristic->getValue();

      mserial->ble=false;

      if (rxValue.length() > 0) {
        String msg="";
        mserial->printStr("Received Value: ");
        for (int i = 0; i < rxValue.length(); i++) {
           msg=msg+String(rxValue[i]);
           mserial->printStr(String(rxValue[i])); 
        } 

        msg.trim();
        $BLE_CMD=msg;
        mserial->ble=true;
        newCMDarrived=true;
      }
    } 

    void onRead(BLECharacteristic *pCharacteristic) {
      mserial->printStrln("*********");
      mserial->printStr("onRead...");    
      pCharacteristic->setValue("OK");
    }

  }; 

//------------------------------------------------------------------
unstopp commented 10 months ago

Same issue, happens only in some cases, not on all setValue calls