187521db1SMatthias Ringwald# BTstack Port for Zephyr RTOS 2277e512cSDirk Helbig 3277e512cSDirk Helbig## Overview 4277e512cSDirk Helbig 587521db1SMatthias RingwaldThis port targets any platform supported by Zephyr that either contains a built-in Bluetooth Controller 687521db1SMatthias Ringwaldor is connected to an external Controller via one of the supported Zephyr HCI Transports drivers (see `zephyr/drivers/bluetooth/hci`) 7277e512cSDirk Helbig 887521db1SMatthias Ringwald## Status 9277e512cSDirk Helbig 10*a0047cddSDirk HelbigTested with nRF52 DK (PCA10040), nRF52840 DK (PC10056) and nRF5340 DK (PCA10095) boards only. It uses the fixed static random BD ADDR stored in NRF_FICR/NRF_FICR_S, which will not compile on non nRF SoCs. 1187521db1SMatthias Ringwald 12*a0047cddSDirk Helbig## Build Environment 1387521db1SMatthias RingwaldThe first step needs to done once. Step two is needed every time to setup the environment. 14277e512cSDirk Helbig 1587521db1SMatthias Ringwald### 1. Build Environment Preconditions 1687521db1SMatthias Ringwald 17277e512cSDirk HelbigFollow the getting started [guide](https://docs.zephyrproject.org/latest/develop/getting_started/index.html) 1887521db1SMatthias Ringwalduntil you are able to build an example. 1987521db1SMatthias Ringwald 2087521db1SMatthias RingwaldThen update the `ZEPHYR_ROOT` variable in `env.sh` to point to your `zephyrproject`. Defaults to `~/zephyrproject` 2187521db1SMatthias Ringwald 22277e512cSDirk Helbig 23277e512cSDirk Helbig### 2. Prepare the build environmet 2487521db1SMatthias Ringwald 2587521db1SMatthias RingwaldTo setup your environment to build a BTstack example, run the provided setup in `env.sh`. 2687521db1SMatthias Ringwald 27277e512cSDirk Helbig```sh 28277e512cSDirk Helbigsource env.sh 29277e512cSDirk Helbig``` 30277e512cSDirk Helbig 31*a0047cddSDirk Helbig## Building and Running on nRF52840 32*a0047cddSDirk Helbig 3387521db1SMatthias Ringwald### 3. Build Example 3487521db1SMatthias Ringwald 3587521db1SMatthias RingwaldYou can build an example using: 36277e512cSDirk Helbig```sh 37277e512cSDirk Helbigwest build -b nrf52840dk_nrf52840 38277e512cSDirk Helbig``` 3987521db1SMatthias Ringwald 4087521db1SMatthias Ringwald`nrf52840dk_nrf52840` selected the Nordic nRF52840 DK. For the older nRF52 DK with nRF52832, you can specify nrf52dk_nrf52832. 4187521db1SMatthias RingwaldTo get a list of all supported Zephyr targets, run `west boards` 4287521db1SMatthias Ringwald 4387521db1SMatthias RingwaldTo change zephyr platform settings use: 44277e512cSDirk Helbig```sh 45277e512cSDirk Helbigwest build -b nrf52840dk_nrf52840 -t menuconfig 46277e512cSDirk Helbig``` 4787521db1SMatthias Ringwald 4887521db1SMatthias RingwaldTo build a different example, e.g. the `gatt_streamer_server`, set the EXAMPLE environment variable: 49277e512cSDirk Helbig```sh 50277e512cSDirk HelbigEXAMPLE=gatt_streamer_server west build -b nrf52840dk_nrf52840 51277e512cSDirk Helbig``` 5287521db1SMatthias Ringwald 5387521db1SMatthias Ringwald### 4. Flash Example 5487521db1SMatthias Ringwald 5587521db1SMatthias RingwaldTo flash a connected board: 5687521db1SMatthias Ringwald```sh 5787521db1SMatthias Ringwaldwest flash 5887521db1SMatthias Ringwald``` 5987521db1SMatthias Ringwald 60*a0047cddSDirk Helbig## Buiding and Running on nRF5340 61*a0047cddSDirk Helbig 62*a0047cddSDirk HelbigThe nrf5340 is a dual core SOC, where one core is used for Bluetooth HCI functionality and 63*a0047cddSDirk Helbigthe other for the high level application logic. So both cores need to be programmed separately. 64*a0047cddSDirk HelbigUsing the nRF5340-DK for example allowes debug output on both cores to separate UART ports. 65*a0047cddSDirk Helbig 66*a0047cddSDirk Helbig### Building the application 67*a0047cddSDirk Helbigbuild using: 68*a0047cddSDirk Helbig```sh 69*a0047cddSDirk Helbigwest build -b nrf5340dk_nrf5340_cpuapp 70*a0047cddSDirk Helbig``` 71*a0047cddSDirk Helbigwith debug: 72*a0047cddSDirk Helbig```sh 73*a0047cddSDirk Helbigwest build -b nrf5340dk_nrf5340_cpuapp -- -DOVERLAY_CONFIG=debug_overlay.conf 74*a0047cddSDirk Helbig``` 75*a0047cddSDirk Helbig 76*a0047cddSDirk Helbig### Using zephyr network core image 77*a0047cddSDirk Helbigthe `hci_rgmsg` application needs to be loaded first to the network core 78*a0047cddSDirk Helbig```sh 79*a0047cddSDirk Helbigwest build -b nrf5340dk_nrf5340_cpunet 80*a0047cddSDirk Helbigwest flash 81*a0047cddSDirk Helbig``` 82*a0047cddSDirk Helbig 83*a0047cddSDirk Helbig### Using Packetcraft binary network core image 84*a0047cddSDirk Helbigfor nrf5340 the latest netcore firmware is located at [sdk-nrf](https://github.com/nrfconnect/sdk-nrf/tree/main/lib/bin/bt_ll_acs_nrf53/bin) 85*a0047cddSDirk Helbigto program it: 86*a0047cddSDirk Helbig```sh 87*a0047cddSDirk Helbignrfjprog --program ble5-ctr-rpmsg_<version number>.hex --chiperase --coprocessor CP_NETWORK -r 88*a0047cddSDirk Helbig``` 8987521db1SMatthias Ringwald 9087521db1SMatthias Ringwald## TODO 9187521db1SMatthias Ringwald 9287521db1SMatthias Ringwald- Allow/document use of Zephyr HCI Drivers 9387521db1SMatthias Ringwald 9487521db1SMatthias Ringwald 95