1# BTstack Port for Zephyr RTOS 2 3## Overview 4 5This port targets any platform supported by Zephyr that either contains a built-in Bluetooth Controller 6or is connected to an external Controller via one of the supported Zephyr HCI Transports drivers (see `zephyr/drivers/bluetooth/hci`) 7 8## Status 9 10Tested 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. 11 12## Build Environment 13The first step needs to done once. Step two is needed every time to setup the environment. 14 15### 1. Build Environment Preconditions 16 17Follow the getting started [guide](https://docs.zephyrproject.org/latest/develop/getting_started/index.html) 18until you are able to build an example. 19 20Then update the `ZEPHYR_ROOT` variable in `env.sh` to point to your `zephyrproject`. Defaults to `~/zephyrproject` 21 22 23### 2. Prepare the build environment 24 25To setup your environment to build a BTstack example, run the provided setup in `env.sh`. 26 27```sh 28source env.sh 29``` 30 31## Building and Running on nRF52840 32 33### 1. Build Example 34 35You can build an example using: 36```sh 37west build -b nrf52840dk_nrf52840 38``` 39 40`nrf52840dk_nrf52840` selected the Nordic nRF52840 DK. For the older nRF52 DK with nRF52832, you can specify nrf52dk_nrf52832. 41To get a list of all supported Zephyr targets, run `west boards` 42 43To change zephyr platform settings use: 44```sh 45west build -b nrf52840dk_nrf52840 -t menuconfig 46``` 47 48To build a different example, e.g. the `gatt_streamer_server`, set the EXAMPLE environment variable: 49```sh 50EXAMPLE=gatt_streamer_server west build -b nrf52840dk_nrf52840 51``` 52 53### 2. Flash Example 54 55To flash a connected board: 56```sh 57west flash 58``` 59 60## Buiding and Running on nRF5340 61 62The nrf5340 is a dual core SoC, where one core is used for Bluetooth HCI functionality and 63the other for the high level application logic. So both cores need to be programmed separately. 64Using the nRF5340-DK for example allows debug output on both cores to separate UART ports. 65For the nRF5340 a network core firmware is required, which one depends on the use-case. 66With 2a and 2b two options are given. 67 68### 1. Building the application 69build using: 70```sh 71west build -b nrf5340dk_nrf5340_cpuapp 72``` 73with debug: 74```sh 75west build -b nrf5340dk_nrf5340_cpuapp -- -DOVERLAY_CONFIG=debug_overlay.conf 76``` 77 78### 2a. Using zephyr network core image 79the `hci_rgmsg` application needs to be loaded first to the network core. 80Configure network core by selecting the appropriate config file, for example `nrf5340_cpunet_iso-bt_ll_sw_split.conf`. 81additionally it's required to increase the main stack size from 82```sh 83CONFIG_MAIN_STACK_SIZE=512 84``` 85to 86```sh 87CONFIG_MAIN_STACK_SIZE=4096 88``` 89then the network core image can be compiled and flashed 90```sh 91west build -b nrf5340dk_nrf5340_cpunet -- -DCONF_FILE=nrf5340_cpunet_iso-bt_ll_sw_split.conf 92west flash 93``` 94or with debugging 95```sh 96west build -b nrf5340dk_nrf5340_cpunet -- -DCONF_FILE=nrf5340_cpunet_iso-bt_ll_sw_split.conf -DOVERLAY_CONFIG=debug_overlay.conf 97west flash 98``` 99 100### 2b. Using Packetcraft binary network core image 101for 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) 102to program it: 103```sh 104nrfjprog --program ble5-ctr-rpmsg_<version number>.hex --chiperase --coprocessor CP_NETWORK -r 105``` 106 107## TODO 108 109- Allow/document use of Zephyr HCI Drivers 110 111 112