ports/stm32: Add Zephyr BLE support for WB55 and PYBD.#20
Draft
andrewleech wants to merge 21 commits intopr/zephyr-ble-corefrom
Draft
ports/stm32: Add Zephyr BLE support for WB55 and PYBD.#20andrewleech wants to merge 21 commits intopr/zephyr-ble-corefrom
andrewleech wants to merge 21 commits intopr/zephyr-ble-corefrom
Conversation
9a8ad56 to
6c8c6df
Compare
ba9ebb7 to
86b9e6a
Compare
6c8c6df to
24302ac
Compare
86b9e6a to
123460b
Compare
24302ac to
59ff3cf
Compare
123460b to
8e853d6
Compare
59ff3cf to
372dab7
Compare
8e853d6 to
7e0b581
Compare
372dab7 to
39ec763
Compare
7e0b581 to
86dba95
Compare
39ec763 to
a78beb8
Compare
86dba95 to
edf2fd6
Compare
a78beb8 to
9555510
Compare
edf2fd6 to
c408c95
Compare
9555510 to
c383dbe
Compare
c408c95 to
7dfdb11
Compare
c383dbe to
4f9cb08
Compare
50639b0 to
c11d224
Compare
577fa84 to
eb4a81a
Compare
Owner
Author
|
/review |
|
Review failed. Retry with |
eb4a81a to
fedbc7f
Compare
c11d224 to
3450a55
Compare
fedbc7f to
ffe840c
Compare
3450a55 to
1ca3fe5
Compare
ffe840c to
673bd99
Compare
1ca3fe5 to
09ee309
Compare
0c5c401 to
f18c8ac
Compare
b3df7e5 to
c197acc
Compare
Extends the Zephyr BLE HAL layer to support running the BLE controller on-core alongside the host stack. All changes are guarded by MICROPY_BLUETOOTH_ZEPHYR_CONTROLLER so host-only ports are unaffected. New files provide IRQ management (NVIC wrappers), ISR dispatch table, clock control (HFCLK/LFCLK), and controller kernel stubs (k_poll, k_thread_create). Existing shims are updated to use real PRIMASK-based interrupt control and IPSR-based ISR detection when the controller is active. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Adds Zephyr BLE controller source files (ULL, LLL, ticker, HAL) to zephyr_ble.mk under MICROPY_BLUETOOTH_ZEPHYR_CONTROLLER=1 guard. Adds controller configuration defines (CONFIG_BT_CTLR_*, CONFIG_SOC_*, ticker, LLCP) and header stubs needed by controller code (devicetree, IRQ, entropy, version). Also enables L2CAP dynamic channels (COC) in the shared build flags and adds LTO type-mismatch warning suppression for stub declarations that intentionally differ from Zephyr internals. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Add 1kHz SysTick handler with millisecond counter (uwTick), PendSV dispatch mechanism for deferred soft timer processing, and SysTick init function. Enable SEVONPEND so WFE wakes on SysTick interrupts. Also unconditionally enable the MicroPython scheduler (previously gated behind MICROPY_HW_ENABLE_USBDEV) since BLE event processing requires mp_sched_schedule_node(). Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Add Makefile integration, linker script extensions, and board variant configurations (PCA10056, PCA10059) for building the nRF port with Zephyr BLE. Includes PCA10059 DAPLink variant and hci_driver_poll_rx support for the on-core controller. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Add mpzephyrport_nrf.c with on-core BLE controller initialization, LFXO startup, cooperative HCI polling, and scheduler node callback handling. Includes NULL callback guard for safe deinit during scheduler node draining. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Extend the bt_disable deinit path to the nRF port's on-core controller. The controller is shut down via ll_deinit() called from bt_disable(), with proper LFXO re-start on next init. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Add work processing interleaving to the nRF port's controller polling loop. Each HCI packet is followed by a work_process() call to ensure connection events are handled before subsequent packets. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Move the remaining two Zephyr submodule patches (HCI driver, quirk reset) into wrapper files, eliminating all custom patches from the lib/zephyr submodule. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Add mp_bluetooth_zephyr_l2cap_flush_recv_notify() call to port_run_task and re-entrancy guard to prevent recursive port_run_task execution. Update lib/zephyr submodule with LLL preempt ticker fix — ticker_stop(TICKER_ID_LLL_PREEMPT) in init_reset() prevents ll_deinit assertion on second bt_disable/bt_enable cycle. Run codeformat.py on nRF port files and hci_driver_wrapper.c. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Use ZEPHYR_BLE_POLL_INTERVAL_MS for poll timer values. Enable CONFIG_BT_AUTO_DATA_LEN_UPDATE for PCA10056 and PCA10059 on-core controller variants. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
New Unix variant `zephyr_ble` that provides: - Pthread-based soft timer backend for machine.Timer - Linux HCI_CHANNEL_USER socket transport for USB BT adapters - Zephyr BLE stack using RP2 cooperative polling pattern The HCI socket driver uses AF_BLUETOOTH/BTPROTO_HCI with HCI_CHANNEL_USER for exclusive raw access to a USB Bluetooth adapter. Device selection via MICROPYBTHCI env var with auto-detection fallback. Non-blocking socket reads in port_run_task driven by the soft timer. Build: make -C ports/unix VARIANT=zephyr_ble Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
- Replace softtimer_unix.c with version that has proper deinit, SIGUSR1 main-thread wakeup, and GC marking integration. - Add soft_timer_init/deinit calls to main.c, GC marking to gccollect.c. - Add MICROPY_SCHED_HOOK_SCHEDULED to wake main thread from blocking syscalls when timer callbacks are scheduled. - Enable L2CAP channels and pairing/bonding by default in modbluetooth.h (all stacks support these features). - Guard le_dbg variable with ZEPHYR_BLE_DEBUG in l2cap_disconnected_cb. - Document HCI TX buffer size bounds. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Add Zephyr BLE variant configuration for PYBD_SF6 board, with HCI UART readpacket support for bulk reading from the BT coprocessor. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Update mp_handle_pending() calls to use the mp_handle_pending_behaviour_t enum instead of bool, matching the current signature in py/scheduler.c. Add mp_bluetooth_zephyr_l2cap_flush_recv_notify() call to port_run_task, consistent with RP2 and nRF ports. Without this, deferred L2CAP recv notifications were never delivered to Python. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Use ZEPHYR_BLE_POLL_INTERVAL_MS for poll timer values. Enable CONFIG_BT_AUTO_DATA_LEN_UPDATE for NUCLEO_WB55. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Replace NUM_COMPLETED_PACKETS-based ACL flow control with direct IPCC channel flag polling. The IPCC flag clears when M0+ consumes the shared SRAM2B buffer, which is much faster than waiting for the radio round-trip needed by NUM_COMPLETED_PACKETS. Debug instrumentation confirmed the IPCC flag always clears before the next ACL send attempt, so the timeout path is defensive only. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
f18c8ac to
bc161f6
Compare
c197acc to
795da9c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Zephyr BLE integration for the STM32 port, targeting the NUCLEO_WB55 and PYBD_SF6 boards. The WB55's BLE controller runs on the M0+ coprocessor (CPU2) and communicates with the M4 host via IPCC mailbox — the HCI driver in
mpzephyrport.cbridges this to the Zephyr BLE host's H4 transport.The IPCC/rfcore integration required careful handling of the CPU2 lifecycle: HCI_Reset must not be sent to CPU2 as it corrupts all 192KB of SRAM1. This is prevented by a
drv_quirk_no_reset()hook in the Zephyr host'shci_core.c.Build variants:
NUCLEO_WB55 BOARD_VARIANT=zephyr_bleandPYBD_SF6 BOARD_VARIANT=zephyr_ble.Depends on #19.
Testing
11/11 BLE multitests passing on WB55 with nRF52840 DK as peripheral. PYBD variant builds but has not been tested with Zephyr BLE (PYBD is primarily used as a NimBLE reference central).
Trade-offs and Alternatives
The STM32 integration touches several files beyond the BLE-specific code (linker scripts, FreeRTOS hooks, system_stm32 changes) because the WB55's dual-core architecture and IPCC memory layout require careful memory section placement. These changes are guarded by
MICROPY_BLUETOOTH_ZEPHYRdefines where possible.Generative AI
I used generative AI tools when creating this PR, but a human has checked the code and is responsible for the description above.