diff --git a/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/autogen_board_info.toml b/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/autogen_board_info.toml index 321aa7a01f6..012cc8c2dc9 100644 --- a/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/autogen_board_info.toml +++ b/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/autogen_board_info.toml @@ -3,7 +3,7 @@ name = "Raspberry Pi Foundation Raspberry Pi Pico" [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_pico_w_zephyr/board.conf b/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/board.conf index 1e2d7ae1cd2..84002ed1f05 100644 --- a/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/board.conf +++ b/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/board.conf @@ -20,3 +20,19 @@ CONFIG_MBEDTLS_ENTROPY_C=y CONFIG_MBEDTLS_CTR_DRBG_C=y CONFIG_TEST_RANDOM_GENERATOR=y + +# Bluetooth over the shared gSPI bus (CONFIG_BT itself comes from the +# zephyr,bt-hci chosen node in the overlay). +# +# The CYW43439's BT controller firmware does not implement the Bluetooth 5 +# extended advertising/scanning commands, and the port defaults BT_EXT_ADV on, +# so turn it off here and let the host use the legacy 0x200B/0x200C commands. +CONFIG_BT_EXT_ADV=n +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 + +# Connections. prj.conf allows 5 on every board, and every connection reserves +# its buffers and state in static RAM up front. The Pico W's 264 KB is mostly +# spoken for by the WiFi and BT stacks already: with 5, the CircuitPython heap +# left over came to ~16.5 KB, too little for adafruit_ble plus a program. Two +# still covers the BLE workflow plus one more central. +CONFIG_BT_MAX_CONN=2 diff --git a/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/board.overlay b/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/board.overlay index f8f00f5cb37..2a2ca56d9ec 100644 --- a/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/board.overlay +++ b/ports/zephyr-cp/boards/raspberrypi/rpi_pico_w_zephyr/board.overlay @@ -1,3 +1,58 @@ /* Partition layout is owned by the mcuboot fork (dts/raspberrypi/rpi_pico.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_pico_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 RP2040'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. The code partition + * still starts at 0x100, after the second stage bootloader. + */ +&code_partition { + reg = <0x100 (0x17e000 - 0x100)>; +}; + +/delete-node/ &storage_partition; + +&flash0 { + partitions { + storage_partition: partition@17e000 { + compatible = "zephyr,mapped-partition"; + label = "storage"; + reg = <0x17e000 0x2000>; + }; + }; +}; + +/* + * Bluetooth. Same CYW43439 as the Pico 2 W: HCI is not on a UART, 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 + * enables itself 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"