Skip to content

ESP32 is crashing when WiFi is connecting / BLE is initializing #6541

Closed
@umerm64

Description

@umerm64

Board

ESP32 DEVKIT C

Device Description

I am using simple ESP32 module and there is no external device attached to it.

Hardware Configuration

I don't have any external device connected to it.
I am using the WLED project from here: https://github.com/Aircoookie/WLED
Only the GPIO pins used by this project are used.

Version

v2.0.2

IDE Name

Platform IO

Operating System

Windows 10

Flash frequency

40MHz

PSRAM enabled

no

Upload speed

115200

Description

I am using the WLED project here: https://github.com/Aircoookie/WLED
I am trying to add BLE support to this project.
For that, I am using partitions based on the huge_app.csv file
Currently, I am facing an exception at run time when using BLE as well as WiFi in this.
Basically when I am initializing BLE first then the exception occurs when connecting to the WiFi network.
Similarly when I am connecting to WiFi network then an exception occurs at the BLE initializing.
I am attaching the trace for both in this ticket.

I have also uploaded the code from the usermod.cpp file where I am initializing BLE server, its basically the code taken from BLE example given in the ESP32.

Sketch

#include "wled.h"
/*
 * This v1 usermod file allows you to add own functionality to WLED more easily
 * See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality
 * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in const.h)
 * If you just need 8 bytes, use 2551-2559 (you do not need to increase EEPSIZE)
 *
 * Consider the v2 usermod API if you need a more advanced feature set!
 */

//Use userVar0 and userVar1 (API calls &U0=,&U1=, uint16_t)

#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>

#define SERVICE_UUID           "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" // UART service UUID
#define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"

static BLEServer *pServer = NULL;
static BLECharacteristic * pTxCharacteristic;
static bool deviceConnected = false;
static bool oldDeviceConnected = false;
static uint8_t txValue = 0;

class MyServerCallbacks: public BLEServerCallbacks {
    void onConnect(BLEServer* pServer) {
      deviceConnected = true;
    };

    void onDisconnect(BLEServer* pServer) {
      deviceConnected = false;
    }
};

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

      if (rxValue.length() > 0) {
        Serial.println("*********");
        Serial.print("Received Value: ");
        for (int i = 0; i < rxValue.length(); i++)
          Serial.print(rxValue[i]);

        Serial.println();
        Serial.println("*********");
      }
    }
};

void ble_init()
{
  // Create the BLE Device
  BLEDevice::init("wled ble Service");
  Serial.println("BLE init called");
  // delay(2000);

  // Create the BLE Server
  pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());

  // Create the BLE Service
  BLEService *pService = pServer->createService(SERVICE_UUID);

  // Create a BLE Characteristic
  pTxCharacteristic = pService->createCharacteristic(
										CHARACTERISTIC_UUID_TX,
										BLECharacteristic::PROPERTY_NOTIFY
									);

  pTxCharacteristic->addDescriptor(new BLE2902());

  BLECharacteristic * pRxCharacteristic = pService->createCharacteristic(
											 CHARACTERISTIC_UUID_RX,
											BLECharacteristic::PROPERTY_WRITE
										);

  pRxCharacteristic->setCallbacks(new MyCallbacks());

  // Start the service
  pService->start();

  // Start advertising
  pServer->getAdvertising()->start();
  Serial.println("Waiting a client connection to notify...");
  // delay(2000);
}

void handle_ble_connection()
{
  if (deviceConnected) {
    pTxCharacteristic->setValue(&txValue, 1);
    pTxCharacteristic->notify();
    txValue++;
		delay(100); // bluetooth stack will go into congestion, if too many packets are sent
	}
  // disconnecting
  if (!deviceConnected && oldDeviceConnected) {
    delay(500); // give the bluetooth stack the chance to get things ready
    pServer->startAdvertising(); // restart advertising
    Serial.println("start advertising");
    oldDeviceConnected = deviceConnected;
  }
  // connecting
  if (deviceConnected && !oldDeviceConnected) {
    // do stuff here on connecting
    oldDeviceConnected = deviceConnected;
  }
}

//gets called once at boot. Do all initialization that doesn't depend on network here
void userSetup()
{
  Serial.println("going to init ble");
  ble_init();
}

//gets called every time WiFi is (re-)connected. Initialize own network interfaces here
void userConnected()
{

}

//loop. You can use "if (WLED_CONNECTED)" to check for successful connection
void userLoop()
{
  // handle_ble_connection();
}

Debug Message



####When BLE is initialized first:

Connecting to WFH...
abort() was called at PC 0x401f8477 on core 0

ELF file SHA256: 0000000000000000

Backtrace: 0x40090370:0x3fff0580 0x400906cd:0x3fff05a0 0x401f8477:0x3fff05c0 0x401d7ca0:0x3fff05e0 0x401d6fde:0x3fff0600 0x401fb012:0x3fff0620 0x4009217a:0x3fff0650
  #0  0x40090370:0x3fff0580 in invoke_abort at /home/cschwinne/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:648
  #1  0x400906cd:0x3fff05a0 in abort at /home/cschwinne/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:648
  #2  0x401f8477:0x3fff05c0 in pm_set_sleep_type at ??:?
  #3  0x401d7ca0:0x3fff05e0 in wifi_set_ps_process at ??:?
  #4  0x401d6fde:0x3fff0600 in ieee80211_ioctl_process at ??:?
  #5  0x401fb012:0x3fff0620 in ppTask at ??:?
  #6  0x4009217a:0x3fff0650 in vPortTaskWrapper at /home/cschwinne/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)

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:DOUT, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1084
load:0x40078000,len:11220
load:0x40080400,len:5360
entry 0x4008067c










#### When WiFi is connected first and then BLE is connected:

Connecting to WFH...

Connected! IP address: 192.168.10.21
Init STA interfaces
mDNS started
going to init ble
abort() was called at PC 0x401a8332 on core 1

ELF file SHA256: 0000000000000000

Backtrace: 0x40090370:0x3ffd3170 0x400906cd:0x3ffd3190 0x401a8332:0x3ffd31b0 0x401aca70:0x3ffd31d0 0x401acc4a:0x3ffd31f0 0x4011905a:0x3ffd3220 0x40114ae2:0x3ffd3240 0x4010d711:0x3ffd3280 0x400f55a2:0x3ffd32b0 0x400f56a4:0x3ffd32f0 0x400f6b03:0x3ffd3310 0x400f6b4a:0x3ffd33d0 0x400f6f62:0x3ffd3410 0x40116e2c:0x3ffd3430 0x4009217a:0x3ffd3450
  #0  0x40090370:0x3ffd3170 in invoke_abort at /home/cschwinne/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:648
  #1  0x400906cd:0x3ffd3190 in abort at /home/cschwinne/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:648
  #2  0x401a8332:0x3ffd31b0 in coex_init at ??:?
  #3  0x401aca70:0x3ffd31d0 in esp_phy_rf_init at /home/cschwinne/esp32-arduino-lib-builder/esp-idf/components/esp32/phy_init.c:524
  #4  0x401acc4a:0x3ffd31f0 in esp_phy_load_cal_and_init at /home/cschwinne/esp32-arduino-lib-builder/esp-idf/components/esp32/phy_init.c:673
  #5  0x4011905a:0x3ffd3220 in esp_bt_controller_enable at /home/cschwinne/esp32-arduino-lib-builder/esp-idf/components/bt/bt.c:1704
  #6  0x40114ae2:0x3ffd3240 in btStart at C:\Users\umer.arshad\.platformio\packages\framework-arduinoespressif32\cores\esp32/esp32-hal-bt.c:45
  #7  0x4010d711:0x3ffd3280 in BLEDevice::init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) at C:/Users/umer.arshad/.platformio/packages/framework-arduinoespressif32@src-e9b1fbd6563a55e19ddae15e1fc09589/libraries/BLE/src/BLEDevice.cpp:591
  #8  0x400f55a2:0x3ffd32b0 in ble_init() at wled00/usermod.cpp:110
  #9  0x400f56a4:0x3ffd32f0 in userConnected() at wled00/usermod.cpp:123
  #10 0x400f6b03:0x3ffd3310 in WLED::handleConnection() at wled00/bus_manager.h:149
  #11 0x400f6b4a:0x3ffd33d0 in WLED::loop() at wled00/bus_manager.h:149
  #12 0x400f6f62:0x3ffd3410 in loop() at D:/MyStuff/WattsLights/WLED/wled00/wled00.ino:20
  #13 0x40116e2c:0x3ffd3430 in loopTask(void*) at C:\Users\umer.arshad\.platformio\packages\framework-arduinoespressif32\cores\esp32/main.cpp:23
  #14 0x4009217a:0x3ffd3450 in vPortTaskWrapper at /home/cschwinne/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)

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:DOUT, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1084
load:0x40078000,len:11220
load:0x40080400,len:5360
entry 0x4008067c

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions