Nimble crash/panic after calling nimble_port_stop()

felixcollins
Posts: 125
Joined: Fri May 24, 2019 2:02 am

Nimble crash/panic after calling nimble_port_stop()

Postby felixcollins » Thu Jul 27, 2023 12:31 am

In my system I have a situation where BLE may need to be shut down very soon after starting (a low power scenario).

The first log output below is from my code just before I call nimble_port_stop().

The stack trace shows a crash from within the nimble port task, nimble_port_run().

Is it not allowed to call nimble_port_stop() at any time? Do I need to check a condition first?

Thanks,
Felix

Code: Select all

I (2089) BLE_SPP: Disabling BLE
E (2089) NimBLE: Host not enabled. Dropping the packet!
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x4008542a  PS      : 0x00060c30  A0      : 0x800e45c8  A1      : 0x3ffd7140
0x4008542a: npl_freertos_callout_is_active at C:/Users/felix/esp5/esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/src/npl_os_freertos.c:856

A2      : 0x3ffd2038  A3      : 0x3ffd7178  A4      : 0x3ffc296c  A5      : 0x3ffd2418
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3ffd7120
A10     : 0x000053e8  A11     : 0x00000000  A12     : 0x0000ef00  A13     : 0x00000000
A14     : 0x00000000  A15     : 0x00002001  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff


Backtrace: 0x40085427:0x3ffd7140 0x400e45c5:0x3ffd7160 0x400e4662:0x3ffd7180 0x400e4803:0x3ffd71a0 0x400e480b:0x3ffd71c0 0x40092d2d:0x3ffd71e0 0x400847d9:0x3ffd7200 0x400dbba0:0x3ffd7220
0x40085427: npl_freertos_callout_is_active at C:/Users/felix/esp5/esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/src/npl_os_freertos.c:854

0x400e45c5: ble_npl_callout_is_active at C:/Users/felix/esp5/esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h:300
 (inlined by) ble_hs_timer_sched at C:/Users/felix/esp5/esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_hs.c:488

0x400e4662: ble_hs_sync at C:/Users/felix/esp5/esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_hs.c:367

0x400e4803: ble_hs_start at C:/Users/felix/esp5/esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_hs.c:696

0x400e480b: ble_hs_event_start_stage2 at C:/Users/felix/esp5/esp-idf/components/bt/host/nimble/nimble/nimble/host/src/ble_hs.c:596

0x40092d2d: npl_freertos_event_run at C:/Users/felix/esp5/esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/src/npl_os_freertos.c:450

0x400847d9: ble_npl_event_run at C:/Users/felix/esp5/esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h:185
 (inlined by) nimble_port_run at C:/Users/felix/esp5/esp-idf/components/bt/host/nimble/nimble/porting/nimble/src/nimble_port.c:255

0x400dbba0: ble_spp_server_host_task at C:/Users/felix/source/Thor/fw-sensor-hub/main/gl_ble_spp_server.c:521 (discriminator 2)


MicroController
Posts: 1705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Nimble crash/panic after calling nimble_port_stop()

Postby MicroController » Thu Jul 27, 2023 10:37 am

I didn't experience such an issue. I have a task which initializes (Nim)BLE, starts time-limited advertising, waits on a semaphore, and then tears down (Nim)BLE again. I send a signal to the semaphore upon receiving the ADV_COMPLETE event in the BLE callback.
This seems to work in a loop without issues. Maybe it's because this way the BLE stack is always "idle" when I stop it.
Last edited by MicroController on Thu Jul 27, 2023 11:13 pm, edited 1 time in total.

felixcollins
Posts: 125
Joined: Fri May 24, 2019 2:02 am

Re: Nimble crash/panic after calling nimble_port_stop()

Postby felixcollins » Thu Jul 27, 2023 9:53 pm

@MicroController I think you may be correct. I found all sorts of fragile assumptions in the esp nimble port. I am however starting and stopping successfully elsewhere under user control. Is there a simple way to determine whether it is idle and therefore safe to shut down? I would prefer if it was more robustly implemented but we take what we can get!

DrMickeyLauer
Posts: 168
Joined: Sun May 22, 2022 2:42 pm

Re: Nimble crash/panic after calling nimble_port_stop()

Postby DrMickeyLauer » Wed May 15, 2024 2:44 pm

The upstream Nimble folks seem to be quite cooperative. I'm sure they accept patches. I'm working on a pull request right now to stop leaking L2CAP servers when you shut down and restart them.

Who is online

Users browsing this forum: Bing [Bot] and 77 guests