Skip to content

Commit 490bca3

Browse files
committed
docs: Document BLE connection event fix.
Update CLAUDE.local.md with Issue #3 resolution and current status. BLE connections now working on STM32WB55 with both peripheral and central roles successfully delivering IRQ events. Signed-off-by: Andrew Leech <[email protected]>
1 parent 3411602 commit 490bca3

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

CLAUDE.local.md

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ Add Zephyr BLE stack as an alternative to NimBLE/BTstack for all MicroPython por
66
## Current Status
77
- OS abstraction layer implemented (k_work, k_sem, k_mutex, atomic ops)
88
- Build system integration complete
9-
- **STM32WB55: BLE initialization works, scanning partially working**
10-
- bt_enable() completes successfully
11-
- BLE scan START succeeds (no EPERM error)
12-
- **ISSUE**: No advertising reports received during scan
13-
- **ISSUE**: Scan STOP command times out (10s), causes fatal error
9+
- **STM32WB55: BLE connections now working!**
10+
- bt_enable() completes successfully
11+
- BLE advertising works (legacy mode) ✓
12+
- BLE connections work (peripheral and central roles) ✓
13+
- Connection IRQ events delivered correctly ✓
1414
- All HCI initialization commands complete (HCI_RESET, READ_LOCAL_FEATURES, READ_SUPPORTED_COMMANDS, LE commands)
1515
- Fix #1: Disabled CONFIG_BT_HCI_ACL_FLOW_CONTROL (STM32WB controller doesn't support HOST_BUFFER_SIZE command)
1616
- Fix #2: Enabled CONFIG_BT_SCAN_WITH_IDENTITY to fix scanning EPERM error
17+
- Fix #3: Disabled CONFIG_BT_SMP (STM32WB controller sends legacy connection events, not enhanced)
1718
- RP2 Pico 2 W: Not yet tested with these fixes
1819

1920
## Test Hardware
@@ -302,25 +303,43 @@ arm-none-eabi-objdump -d build-*/firmware.elf > firmware.dis
302303
**Files Modified**:
303304
- `extmod/zephyr_ble/zephyr_ble_config.h` - Added CONFIG_BT_SCAN_WITH_IDENTITY
304305
305-
**Remaining Issues**:
306-
- No advertising reports received during scan (no devices detected)
307-
- Scan STOP command (LE_SET_SCAN_ENABLE disable) times out waiting for HCI response
308-
- Command sent: `>HCI_CMD(01:0c:20:02:00:00)`
309-
- No response received from controller
310-
- Causes 10s timeout in `bt_hci_cmd_send_sync()` → fatal error
311-
- Likely issue: HCI event routing or STM32WB RF core not delivering events properly
306+
### Issue #3: BLE Connection IRQ Events Not Delivered (FIXED)
307+
**Problem**: Multi-test `ble_gap_connect.py` failed - STM32WB55 peripheral never received `_IRQ_CENTRAL_CONNECT` or `_IRQ_CENTRAL_DISCONNECT` events, though Pyboard-D central successfully connected.
308+
309+
**Root Cause**:
310+
- Zephyr's `le_set_event_mask()` function (`lib/zephyr/subsys/bluetooth/host/hci_core.c:3529-3542`) conditionally enables different LE connection event types based on `CONFIG_BT_SMP`:
311+
- When `CONFIG_BT_SMP=1`: Enables **LE Enhanced Connection Complete** events (HCI event mask bit 9)
312+
- When `CONFIG_BT_SMP=0`: Enables **LE Connection Complete** events (HCI event mask bit 0 - legacy BLE 4.x)
313+
- STM32WB55 RF core sends legacy LE Connection Complete events (0x3E subcode 0x01)
314+
- With `CONFIG_BT_SMP=1`, Zephyr requested enhanced events that the controller never sends
315+
- No events delivered → Zephyr callbacks never triggered → Python IRQ handler never called
316+
317+
**Investigation Method**:
318+
1. Added debug logging to connection callbacks in `modbluetooth_zephyr.c` and `modbluetooth.c`
319+
2. Ran multi-test and confirmed: ZERO callback invocations, ZERO HCI LE Meta Events in trace
320+
3. Examined NimBLE initialization code (`lib/mynewt-nimble/nimble/host/src/ble_hs_startup.c:177-251`) which explicitly sets LE event masks
321+
4. Compared to Zephyr's event mask logic - found conditional behavior based on CONFIG_BT_SMP
322+
323+
**Solution**: Disabled `CONFIG_BT_SMP` in `extmod/zephyr_ble/zephyr_ble_config.h:403`
324+
```c
325+
#define CONFIG_BT_SMP 0 // Disabled: STM32WB55 controller doesn't send Enhanced Connection Complete events
326+
```
327+
328+
**Result**: Connection events now delivered correctly!
329+
- `_IRQ_CENTRAL_CONNECT` fires when central connects to peripheral ✓
330+
- `_IRQ_CENTRAL_DISCONNECT` fires when connection terminates ✓
331+
- Both peripheral and central roles working ✓
332+
333+
**Files Modified**:
334+
- `extmod/zephyr_ble/zephyr_ble_config.h:403` - Disabled CONFIG_BT_SMP
335+
336+
**Note**: Disabling CONFIG_BT_SMP also disables Security Manager Protocol features (pairing, bonding, encryption). This is acceptable for initial bring-up and basic connection testing. Future work may need to support enhanced connection events or implement SMP differently.
312337

313338
## Next Steps
314339

315-
1. **URGENT**: Investigate why scan STOP command times out
316-
- Check HCI event processing in work queue
317-
- Verify STM32WB RF core event delivery
318-
- May need to check IPCC interrupt handling
319-
2. Debug why no advertising reports are received
320-
- Verify HCI event routing for LE_ADVERTISING_REPORT events
321-
- Check if events are making it from RF core to host stack
322-
3. Once scanning works, test advertising functionality
323-
4. Test BLE connections (central and peripheral roles)
324-
5. Test on RP2 Pico 2 W with both fixes applied
340+
1. Disable debug logging and verify multi-tests pass cleanly
341+
2. Test additional BLE functionality (GATT, notifications, etc.)
342+
3. Test on RP2 Pico 2 W with all three fixes applied
343+
4. Consider long-term solution for SMP support with enhanced connection events
325344

326345
Use arm-none-eabi-gdb proactively to diagnose issues. The probe-rs agent or `~/.claude/agents/probe-rs-flash.md` has specific usage details.

0 commit comments

Comments
 (0)