Bugs in BLE support

Board: STM32 Discovery IOT
Mbed version: 6.15.0

I am having various issues related to the scan function of BLE. My code is based on the BLE_GAP example but with the advertising removed and scanning for 10000ms. Ie: it doesn’t switch between advertising and scanning, just continues to scan.

After a while, the scanning will stop due to the scan being not idle (Line 3759 of GapImpl.cpp) and it will not be possible to restart the scan.
If I set the scan duration to “forever”, the scan will eventually stop, but with no indication as to why.
Depending on how memory is being used, there may also be a HardFault at some stage, with the fault addresses being different more often than not. Currently unable to generate hardfaults again after disabling BLE_FEATURE_PERIODIC_ADVERTISING.

My last HardFault looks like this:

[DBG ][BLCO]: HCI Adv report, data len: 27
[DBG ][BLE ]: stack_handler received DM_SCAN_REPORT_IND
[DBG ][BLGP]: GAP event of type ADVERTISING_REPORT received
[INFO][BLGP]: GAP advertising report received
[DBG ][BLGP]: Advertising 0 - type=ADV_SCAN_IND, address_type=RANDOM_ADDRESS, address=f9:32:26:a8:9c:56, data=1a:ff:4c:00:02:15:50:76:5c:b7:d9:ea:4e:21:99:a4:fa:87:96:13:a4:92:f3:df:75:c6:ce, rssi=-85
[DBG ][BLCO]: HCI Adv report, num reports: 1
[DBG ][BLCO]: HCI Adv report, data len: 0
[DBG ][BLE ]: stack_handler received DM_SCAN_REPORT_IND
[DBG ][BLGP]: GAP event of type ADVERTISING_REPORT received
[INFO][BLGP]: GAP advertising report received
[DBG ][BLGP]: Advertising 0 - type=ADV_NONCONN_IND, address_type=RANDOM_ADDRESS, address=90:2f:78:70:49:04, data=, rssi=-65

++ MbedOS Fault Handler ++

FaultType: HardFault

Context:
R 0: 200079C0
R 1: 00000001
R 2: FF1D1E74
R 3: 00000000
R 4: 200016E8
R 5: 200016E8
R 6: 00000002
R 7: 00000000
R 8: 48001000
R 9: 40010414
R 10: 20001A3C
R 11: 00000001
R 12: FFFFFFFF
SP : 20017FA0
LR : 0803A8C5
PC : FF1D1E74
xPSR : 00000017
PSP : 20008E70
MSP : 20017F80
CPUID: 410FC241
HFSR : 40000000
MMFSR: 00000001
BFSR : 00000000
UFSR : 00000000
DFSR : 00000000
AFSR : 00000000
Mode : Handler
Priv : Privileged
Stack: MSP

– MbedOS Fault Handler –

++ MbedOS Error Info ++
Error Status: 0x80FF013D Code: 317 Module: 255
Error Message: Fault exception
Location: 0xFF1D1E74
Error Value: 0x10000188
Current Thread: application_unnamed_thread Id: 0x2000539C Entry: 0x802D1BD StackSize: 0x1000 StackMem: 0x20007FC0 SP…

For more info, visit: mbedos-error
– MbedOS Error Info –

= System will be rebooted due to a fatal error =
= Reboot count(=16) reached maximum, system will halt after rebooting =