diff --git a/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/autogen_board_info.toml b/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/autogen_board_info.toml index 133f753c715..de07ed9ce1a 100644 --- a/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/autogen_board_info.toml +++ b/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/autogen_board_info.toml @@ -3,7 +3,7 @@ name = "Raspberry Pi Foundation Raspberry Pi Pico 2" [modules] __future__ = true -_bleio = false +_bleio = true # Zephyr board has _bleio _eve = false _pew = false _pixelmap = false diff --git a/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/board.conf b/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/board.conf index 8fcc1c0b9ae..81b1f87c4d2 100644 --- a/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/board.conf +++ b/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/board.conf @@ -18,3 +18,20 @@ CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y CONFIG_MBEDTLS_CIPHERSUITE_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256=y CONFIG_MBEDTLS_ENTROPY_C=y CONFIG_MBEDTLS_CTR_DRBG_C=y + +# Bluetooth over the shared gSPI bus (CONFIG_BT itself comes from the +# zephyr,bt-hci chosen node in the overlay). +# +# The WHD WiFi, cybt BT and coexistence call chains are deeper than the +# defaults in ../prj.conf; the Cortex-M33 MPU catches an overflow cleanly +# instead of silently corrupting neighbouring stacks. +CONFIG_HW_STACK_PROTECTION=y +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 + +# The CYW43439's BT controller firmware (CYW4343A2_001.003.016.0065.0000) does +# not implement the Bluetooth 5 extended advertising/scanning commands: it +# rejects LE Set Extended Scan Parameters (0x2041) with status 0x01 "Unknown +# HCI Command", so scanning fails with -EIO. The port defaults BT_EXT_ADV on, +# so turn it off here to make the host use the legacy 0x200B/0x200C scan and +# legacy advertising commands instead. +CONFIG_BT_EXT_ADV=n diff --git a/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/board.overlay b/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/board.overlay index aaaa51c2e0e..573792beb9d 100644 --- a/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/board.overlay +++ b/ports/zephyr-cp/boards/raspberrypi/rpi_pico2_w_zephyr/board.overlay @@ -1,3 +1,57 @@ /* Partition layout is owned by the mcuboot fork (dts/raspberrypi/rpi_pico2.dtsi) * and applied to this image by sysbuild. This overlay only adds board/app config. */ + +/* + * Settings partition: one exception to the layout above. sysbuild prepends the + * adaboot layout (dts/raspberrypi/rpi_pico2_w.dtsi) to this overlay, so what + * is set here wins. + * + * The settings partition backs Bluetooth bond keys via NVS, so it must be + * erase-sector aligned and hold at least two of the RP2350's 4K sectors. + * The layout gives it one (0x17f000, 4K); nvs_mount() rejects a single sector + * with -EINVAL, which makes bt_enable() fail before ever opening the HCI + * driver and surfaces as a bare OSError from "import _bleio". + * + * nvm and the filesystem must stay where ports/raspberrypi puts them + * (cptools/check_partitions.py enforces this), so the second sector comes out + * of the code partition, not out of the CIRCUITPY drive. + */ +&code_partition { + reg = <0x0 0x17e000>; +}; + +/delete-node/ &storage_partition; + +&flash0 { + partitions { + storage_partition: partition@17e000 { + compatible = "zephyr,mapped-partition"; + label = "storage"; + reg = <0x17e000 0x2000>; + }; + }; +}; + +/* + * Bluetooth. The CYW43439's HCI is not on a UART here — it shares the WiFi + * gSPI bus — so hang the shared-bus HCI transport off the board's stock + * infineon,airoc-wifi node and point the host at it. CONFIG_BT then turns + * itself on via the zephyr,bt-hci chosen (see + * ../../../internal-modules/circuitpython-kconfig/Kconfig). + */ +&pio0_spi0 { + airoc-wifi@0 { + cyw43_bt_hci: cyw43_bt_hci { + compatible = "infineon,cyw43-bt-hci"; + status = "okay"; + }; + }; +}; + +/ { + chosen { + zephyr,bt-hci = &cyw43_bt_hci; + }; +}; + #include "../../../app.overlay" diff --git a/ports/zephyr-cp/cptools/compat2driver.py b/ports/zephyr-cp/cptools/compat2driver.py index 8cd3c248265..27f890ff926 100644 --- a/ports/zephyr-cp/cptools/compat2driver.py +++ b/ports/zephyr-cp/cptools/compat2driver.py @@ -166,6 +166,7 @@ "infineon_bless_hci": "bluetooth/hci", "infineon_bt_hci_uart": "bluetooth/hci", "infineon_cyw208xx_hci": "bluetooth/hci", + "infineon_cyw43_bt_hci": "bluetooth/hci", "nxp_bt_hci_uart": "bluetooth/hci", "nxp_hci_ble": "bluetooth/hci", "renesas_bt_hci_da1453x": "bluetooth/hci", diff --git a/ports/zephyr-cp/debug.conf b/ports/zephyr-cp/debug.conf index 21e82985247..1e9c2dfbb76 100644 --- a/ports/zephyr-cp/debug.conf +++ b/ports/zephyr-cp/debug.conf @@ -51,3 +51,10 @@ CONFIG_IDLE_STACK_SIZE=1024 # haven't overflowed — left at their defaults.) CONFIG_BT_RX_STACK_SIZE=4096 CONFIG_BT_LONG_WQ_STACK_SIZE=4096 + +# Bluetooth HCI: driver + host-core debug logging. The CYW43 shared-bus +# transport logs its patchram download and bring-up at INF/DBG, and the host +# core logs the command/event exchange — both invisible at the default +# LOG_MAX_LEVEL. Needed to see how far controller bring-up gets when it fails. +CONFIG_BT_HCI_DRIVER_LOG_LEVEL_DBG=y +CONFIG_BT_HCI_CORE_LOG_LEVEL_DBG=y diff --git a/ports/zephyr-cp/prj.conf b/ports/zephyr-cp/prj.conf index f3a9da38e96..be6e22c8fa8 100644 --- a/ports/zephyr-cp/prj.conf +++ b/ports/zephyr-cp/prj.conf @@ -109,3 +109,11 @@ CONFIG_BT_MAX_CONN=5 # evicts the BLE workflow's bond (BT_KEYS_OVERWRITE_OLDEST). 3 matches # espressif's NimBLE default; nordic keeps dozens. CONFIG_BT_MAX_PAIRED=3 + +# A board upgraded from a layout without a settings partition (or one that +# moved) has whatever the previous image left in those sectors. NVS reads that +# as "all sectors closed" and refuses to mount with -EDEADLK, which surfaces as +# bt_enable() failing before the HCI driver is ever opened. Let it reclaim a +# region it does not recognise instead, so first boot after a layout change +# recovers on its own rather than needing a manual erase. +CONFIG_NVS_INIT_BAD_MEMORY_REGION=y