QUERY · ISSUE
ESP32: BLE.config('mac') causes crash if BLE not active
port-esp32proposed-close
Hello,
calling config('mac') cause reset with latest esp-idf-v3
MicroPython` v1.12-233-ga01757670 on 2020-03-10; ESP32 module with ESP32
Type "help()" for more information.
>>> import bluetooth
>>> ble=bluetooth.BLE()
>>> ble.config('mac')
assertion "mu->handle" failed: file "/home/micropython/esp-idf-v3/components/nimble/nimble/porting/npl/freertos/src/npl_os_freertos.c", line 185, function: npl_freertos_mutex_pend
abort() was called at PC 0x40167b2b on core 1
ELF file SHA256: 0000000000000000000000000000000000000000000000000000000000000000
Backtrace: 0x40091bdf:0x3ffd0390 0x40091efd:0x3ffd03b0 0x40167b2b:0x3ffd03d0 0x4015bcfb:0x3ffd0400 0x4015cb58:0x3ffd0420 0x4015cb6f:0x3ffd0440 0x401581e7:0x3ffd0460 0x40102595:0x3ffd0490 0x400f1911:0x3ffd04b0 0x400e3581:0x3ffd04f0 0x400df729:0x3ffd0520 0x400df849:0x3ffd0540 0x400eccd5:0x3ffd0560 0x400e3648:0x3ffd0600 0x400df729:0x3ffd0670 0x400df752:0x3ffd0690 0x401037ab:0x3ffd06b0 0x4010389d:0x3ffd0740 0x400f5391:0x3ffd0770 0x40097331:0x3ffd07a0
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:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:5008
ho 0 tail 12 room 4
load:0x40078000,len:10600
ho 0 tail 12 room 4
load:0x40080400,len:5684
entry 0x400806bc
I (531) cpu_start: Pro cpu up.
I (531) cpu_start: Application information:
I (531) cpu_start: Compile time: Mar 10 2020 12:41:25
I (534) cpu_start: ELF file SHA256: 0000000000000000...
I (540) cpu_start: ESP-IDF: v3.3.1
I (545) cpu_start: Starting app cpu, entry point is 0x400836ec
I (535) cpu_start: App cpu up.
I (556) heap_init: Initializing. RAM available for dynamic allocation:
I (563) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (569) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (575) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (581) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM
I (587) heap_init: At 3FFCC810 len 000137F0 (77 KiB): DRAM
I (593) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (599) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (606) heap_init: At 40099A80 len 00006580 (25 KiB): IRAM
I (612) cpu_start: Pro cpu start user code
I (295) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
MicroPython v1.12-233-ga01757670 on 2020-03-10; ESP32 module with ESP32
Type "help()" for more information.
CANDIDATE · PULL REQUEST
extmod/modbluetooth.c: Catch uninitialized BLE use.
extmod
This avoids MicroPython crashes like the following:
>>> ble = ubluetooth.BLE()
>>> ble.config('mac')
assertion "mu->handle" failed: file "/esp-idf-4.0/components/bt/host/nimble/nimble/porting/npl/freertos/src/npl_os_freertos.c", line 185, function: npl_freertos_mutex_pend
abort() was called at PC 0x4016a0c3 on core 1
After this change:
>>> import ubluetooth
>>> ble = ubluetooth.BLE()
>>> ble.config('rxbuf')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: BLE not active
>>>
Basic regression check:
>>> import ubluetooth
>>> ble = ubluetooth.BLE()
>>> ble.active(1)
I (37700) BTDM_INIT: BT controller compile version [a482cda]
I (50155) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
W (50165) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration
I (50305) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 2
GAP procedure initiated: stop advertising.
True
>>> ble.config('rxbuf')
128
>>>