|
| 1 | +# Vendor Command Investigation - HYPOTHESIS DISPROVEN |
| 2 | + |
| 3 | +## Hypothesis |
| 4 | +STM32WB controller requires vendor-specific HCI commands (0xfc66, 0xfc73, 0xfc0c) that Zephyr BLE might not be sending, causing LE Meta Event delivery failure. |
| 5 | + |
| 6 | +## Investigation Method |
| 7 | +1. Identified vendor commands in NimBLE HCI trace |
| 8 | +2. Located vendor command definitions in `rfcore.c` |
| 9 | +3. Traced call path from both stacks to `rfcore_ble_init()` |
| 10 | +4. Enabled HCI_TRACE in rfcore.c |
| 11 | +5. Captured full Zephyr initialization sequence |
| 12 | + |
| 13 | +## Vendor Commands Identified |
| 14 | + |
| 15 | +**From `ports/stm32/rfcore.c:72-77`:** |
| 16 | +- **0xfc66** = `OCF_BLE_INIT` - Initialize BLE controller with configuration parameters |
| 17 | +- **0xfc73** = `OCF_C2_SET_FLASH_ACTIVITY_CONTROL` - Flash activity control |
| 18 | +- **0xfc0c** = `OCF_WRITE_CONFIG` - Write BD address configuration |
| 19 | + |
| 20 | +## Shared rfcore.c Layer |
| 21 | + |
| 22 | +Both NimBLE and Zephyr BLE use the **same** `rfcore.c` implementation for IPCC transport: |
| 23 | + |
| 24 | +**Initialization Path (Both Stacks):** |
| 25 | +``` |
| 26 | +bt_hci_transport_setup() (mpzephyrport.c:512) |
| 27 | + └→ mp_bluetooth_hci_uart_init() (mpbthciport.c:103) |
| 28 | + └→ rfcore_ble_init() (rfcore.c:609) |
| 29 | + ├→ rfcore_ble_reset() (rfcore.c:628) |
| 30 | + │ ├→ Vendor 0xfc66 (BLE_INIT) |
| 31 | + │ └→ HCI_RESET (first) |
| 32 | + └→ Vendor 0xfc73 (FLASH_ACTIVITY) |
| 33 | +``` |
| 34 | + |
| 35 | +**BD Address Config Path (Both Stacks):** |
| 36 | +``` |
| 37 | +rfcore_ble_check_msg() (rfcore.c:695) |
| 38 | + └→ Intercepts HCI_Reset response (rfcore.c:700-711) |
| 39 | + └→ Sends Vendor 0xfc0c (WRITE_CONFIG) with BD address |
| 40 | +``` |
| 41 | + |
| 42 | +## Test Results: Zephyr Sends ALL Vendor Commands |
| 43 | + |
| 44 | +**HCI Trace from `zephyr_hci_trace_full.txt`:** |
| 45 | + |
| 46 | +``` |
| 47 | +[ 10445] >HCI(:10:66:fc:24:00:00:00:00:...) ← Vendor BLE_INIT |
| 48 | +[ 10460] <VEND_RESP(11:0e:04:01:66:fc:00) ← Success |
| 49 | +
|
| 50 | +[ 10464] >HCI(:01:03:0c:00) ← HCI_RESET (first) |
| 51 | +[ 10468] <HCI_EVT(04:0e:04:01:03:0c:00) ← Success |
| 52 | +
|
| 53 | +[ 10472] >HCI(:10:73:fc:01:00) ← Vendor FLASH_ACTIVITY |
| 54 | +[ 10475] <VEND_RESP(11:0e:04:01:73:fc:00) ← Success |
| 55 | +
|
| 56 | +[ 10513] >HCI_CMD(01:03:0c:00) ← HCI_RESET (second, from Zephyr) |
| 57 | +[ 10523] <HCI_EVT(04:0e:04:01:03:0c:00) (reset) ← Success |
| 58 | +
|
| 59 | +[ 10528] >HCI(:01:0c:fc:08:00:06:d2:30:5d:13:09:02) ← Vendor WRITE_CONFIG (BD addr) |
| 60 | +[ 10534] <HCI_EVT(04:0e:04:01:0c:fc:00) ← Success |
| 61 | +``` |
| 62 | + |
| 63 | +**Event Mask Configuration:** |
| 64 | +``` |
| 65 | +[ 11522] >HCI_CMD(01:01:0c:08:10:88:00:02:00:00:00:20) ← SET_EVENT_MASK |
| 66 | + mask=0x2000000002008810, Bit 61 (LE_META_EVENT)=1 |
| 67 | +[ 11542] <HCI_EVT(04:0e:04:01:01:0c:00) ← Success (status=0) |
| 68 | +
|
| 69 | +[ 11655] >HCI_CMD(01:01:20:08:0f:00:00:00:00:00:00:00) ← LE_SET_EVENT_MASK |
| 70 | + mask=0x0F, Bit 0 (LE_CONN_COMPLETE)=1 |
| 71 | +[ 11674] <HCI_EVT(04:0e:04:01:01:20:00) ← Success (status=0) |
| 72 | +``` |
| 73 | + |
| 74 | +## Conclusion: HYPOTHESIS DISPROVEN - Zephyr BLE Now WORKING |
| 75 | + |
| 76 | +**Zephyr BLE sends IDENTICAL initialization sequence to NimBLE:** |
| 77 | + |
| 78 | +✓ Vendor command 0xfc66 (BLE_INIT) sent and acknowledged |
| 79 | +✓ Vendor command 0xfc73 (FLASH_ACTIVITY) sent and acknowledged |
| 80 | +✓ Vendor command 0xfc0c (WRITE_CONFIG) sent and acknowledged |
| 81 | +✓ Both HCI_RESET commands sent successfully |
| 82 | +✓ Event masks configured correctly (bit 61 enabled) |
| 83 | +✓ All commands return status=0 (success) |
| 84 | + |
| 85 | +**And LE Meta Events (0x3E) ARE NOW being delivered successfully!** |
| 86 | + |
| 87 | +**Test Results - Scanning Works:** |
| 88 | +``` |
| 89 | +[88871] >HCI_CMD(01:0c:20:02:01:00) ← LE_SET_SCAN_ENABLE (start scan) |
| 90 | +[88888] <HCI_EVT(04:0e:04:01:0c:20:00) ← Success |
| 91 | +[88921] <HCI_EVT(04:3e:1a:02:01:00:00:...) ← LE Meta Event 0x3E, subevent 0x02 (Advertising Report) |
| 92 | +>>> HCI EVT: LE Meta Event detected! |
| 93 | +>>> HCI EVT: LE Meta subevent=0x02 |
| 94 | +``` |
| 95 | + |
| 96 | +The root cause was NOT missing vendor commands. Both stacks use the same rfcore.c IPCC transport layer. |
| 97 | + |
| 98 | +## Actual Root Cause (Previously Fixed) |
| 99 | + |
| 100 | +The LE Meta Event delivery failure documented in earlier investigation files was caused by **missing IPCC memory sections in linker script** (Fix #4, commit 7f8ea29497). |
| 101 | + |
| 102 | +STM32WB55 RF coprocessor requires buffers in specific RAM regions: |
| 103 | +- RAM2A (0x20030000): IPCC tables and metadata |
| 104 | +- RAM2B (0x20038000): IPCC data buffers |
| 105 | + |
| 106 | +When these sections were removed (commit 5d69f18330), RF core couldn't access buffers, preventing event delivery. |
| 107 | + |
| 108 | +Restoring the IPCC SECTIONS in `ports/stm32/boards/stm32wb55xg.ld` fixed both: |
| 109 | +- NimBLE BLE activation (was broken) |
| 110 | +- Zephyr BLE event delivery (was broken) |
| 111 | + |
| 112 | +## Current Status |
| 113 | + |
| 114 | +✓ Zephyr BLE fully functional on STM32WB55 |
| 115 | +✓ BLE initialization, advertising, scanning, connections all working |
| 116 | +✓ LE Meta Events delivered correctly |
| 117 | +⚠ Detection rate: ~30% of NimBLE (69 vs 227 devices in 5s scan) |
| 118 | + - Likely work queue processing throughput limitation |
| 119 | + - Acceptable for most use cases |
| 120 | + |
| 121 | +## Files Modified |
| 122 | +- `ports/stm32/rfcore.c:61` - Enabled HCI_TRACE (1) |
| 123 | + |
| 124 | +## Test Artifacts |
| 125 | +- Full HCI trace: `zephyr_hci_trace_full.txt` |
| 126 | +- NimBLE reference: `nimble_scan_hci_trace.txt` |
| 127 | +- Investigation docs: |
| 128 | + - `EVENT_MASK_ORDER_TEST_RESULTS.md` |
| 129 | + - `HCI_EVENT_MASK_INVESTIGATION.md` |
| 130 | + - `CONNECTION_EVENT_INVESTIGATION.md` |
0 commit comments