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

Calling NimBLEDevice::deinit before NimBLEDevice::init causes core panic #203

Open
jefflongo opened this issue Oct 2, 2024 · 1 comment

Comments

@jefflongo
Copy link
Contributor

#include "Arduino.h"
#include "NimBLEDevice.h"

extern "C" void app_main()
{
  initArduino();

  Serial.begin(115200);
  while(!Serial)
    ; 

  NimBLEDevice::deinit(true);

  while(1)
    ;
}

With this basic program, the device will continuously crash and reset. It could be argued that calling a "deinit" function before "init" function is undefined behavior, but I don't think a crash is acceptable.

SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5820,len:0x1204
load:0x403cc710,len:0x770
load:0x403ce710,len:0x2d1c
entry 0x403cc710
Guru Meditation Error: Core  0 panic'ed (Load access fault). Exception was unhandled.

Core  0 register dump:
--- Stack dump detected
MEPC    : 0x4200febc  RA      : 0x420086f2  SP      : 0x3fc93510  GP      : 0x3fc8e000  
--- 0x4200febc: ble_npl_sem_init at /redacted/esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h:246
 (inlined by) nimble_port_stop at /redacted/esp-idf/components/bt/host/nimble/nimble/porting/nimble/src/nimble_port.c:239
0x420086f2: NimBLEDevice::deinit(bool) at /redacted/components/esp-nimble-cpp/src/NimBLEDevice.cpp:954

TP      : 0x3fc7ed4c  T0      : 0x4005890e  T1      : 0x1313bff8  T2      : 0xffffffff  
S0/FP   : 0x3fc8fbe4  S1      : 0x00000000  A0      : 0x00000000  A1      : 0x00000000  
A2      : 0x00000000  A3      : 0x00000001  A4      : 0x00000000  A5      : 0x00000000  
A6      : 0x3fc8dac8  A7      : 0x00000000  S2      : 0x00000000  S3      : 0x00000000  
S4      : 0x00000000  S5      : 0x00000000  S6      : 0x00000000  S7      : 0x00000000  
--- 0x4005890e: memset in ROM

S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000  
T3      : 0xe5b6385f  T4      : 0x80064205  T5      : 0xffffffff  T6      : 0xffffffff  
MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000005  MTVAL   : 0x0000004c  
--- 0x40380001: _vector_table at ??:?

MHARTID : 0x00000000  


--- Backtrace:


0x4200febc in ble_npl_sem_init (tokens=0, sem=0x3fc902cc <ble_hs_stop_sem>) at /redacted/esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h:246
246        return npl_funcs->p_ble_npl_sem_init(sem, tokens);
#0  0x4200febc in ble_npl_sem_init (tokens=0, sem=0x3fc902cc <ble_hs_stop_sem>) at /redacted/esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h:246
#1  nimble_port_stop () at /redacted/esp-idf/components/bt/host/nimble/nimble/porting/nimble/src/nimble_port.c:239
#2  0x420086f2 in NimBLEDevice::deinit (clearAll=clearAll@entry=true) at /redacted/components/esp-nimble-cpp/src/NimBLEDevice.cpp:953
#3  0x42008410 in app_main () at /redacted/main/main.cpp:16
#4  0x420368bc in main_task (args=<error reading variable: value has been optimized out>) at /redacted/esp-idf/components/freertos/app_startup.c:208
#5  0x40388a08 in vPortTaskWrapper (pxCode=<optimized out>, pvParameters=<optimized out>) at /redacted/esp-idf/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:202



ELF file SHA256: 8c2c157ba3d1c1bc
@h2zero
Copy link
Owner

h2zero commented Oct 2, 2024

Nice catch, thanks. Amazing that this has never been mentioned before. I'll fix this in the currently open PR.

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

2 participants