xref: /btstack/port/zephyr/README.md (revision b85834a422e0c837ce972fed74c5a7334e6cbdb8)
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
10a0047cddSDirk 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
12a0047cddSDirk 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
23*b85834a4SDirk Helbig### 2. Prepare the build environment
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
31a0047cddSDirk Helbig## Building and Running on nRF52840
32a0047cddSDirk Helbig
33*b85834a4SDirk Helbig### 1. 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
53*b85834a4SDirk Helbig### 2. Flash Example
5487521db1SMatthias Ringwald
5587521db1SMatthias RingwaldTo flash a connected board:
5687521db1SMatthias Ringwald```sh
5787521db1SMatthias Ringwaldwest flash
5887521db1SMatthias Ringwald```
5987521db1SMatthias Ringwald
60a0047cddSDirk Helbig## Buiding and Running on nRF5340
61a0047cddSDirk Helbig
62*b85834a4SDirk HelbigThe nrf5340 is a dual core SoC, where one core is used for Bluetooth HCI functionality and
63a0047cddSDirk Helbigthe other for the high level application logic. So both cores need to be programmed separately.
64*b85834a4SDirk HelbigUsing the nRF5340-DK for example allows debug output on both cores to separate UART ports.
65*b85834a4SDirk HelbigFor the nRF5340 a network core firmware is required, which one depends on the use-case.
66*b85834a4SDirk HelbigWith 2a and 2b two options are given.
67a0047cddSDirk Helbig
68*b85834a4SDirk Helbig### 1. Building the application
69a0047cddSDirk Helbigbuild using:
70a0047cddSDirk Helbig```sh
71a0047cddSDirk Helbigwest build -b nrf5340dk_nrf5340_cpuapp
72a0047cddSDirk Helbig```
73a0047cddSDirk Helbigwith debug:
74a0047cddSDirk Helbig```sh
75a0047cddSDirk Helbigwest build -b nrf5340dk_nrf5340_cpuapp -- -DOVERLAY_CONFIG=debug_overlay.conf
76a0047cddSDirk Helbig```
77a0047cddSDirk Helbig
78*b85834a4SDirk Helbig### 2a. Using zephyr network core image
79*b85834a4SDirk Helbigthe `hci_rgmsg` application needs to be loaded first to the network core.
80*b85834a4SDirk HelbigConfigure network core by selecting the appropriate config file, for example `nrf5340_cpunet_iso-bt_ll_sw_split.conf`.
81*b85834a4SDirk Helbig```sh
82*b85834a4SDirk Helbigcp nrf5340_cpunet_iso-bt_ll_sw_split.conf prj.conf
83*b85834a4SDirk Helbig```
84*b85834a4SDirk Helbigadditionaly it's required to increase the main stack size from
85*b85834a4SDirk Helbig```sh
86*b85834a4SDirk HelbigCONFIG_MAIN_STACK_SIZE=512
87*b85834a4SDirk Helbig```
88*b85834a4SDirk Helbigto
89*b85834a4SDirk Helbig```sh
90*b85834a4SDirk HelbigCONFIG_MAIN_STACK_SIZE=4096
91*b85834a4SDirk Helbig```
92*b85834a4SDirk Helbigthen the network core image can be compiled and flashed
93a0047cddSDirk Helbig```sh
94a0047cddSDirk Helbigwest build -b nrf5340dk_nrf5340_cpunet
95a0047cddSDirk Helbigwest flash
96a0047cddSDirk Helbig```
97a0047cddSDirk Helbig
98*b85834a4SDirk Helbig### 2b. Using Packetcraft binary network core image
99a0047cddSDirk 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)
100a0047cddSDirk Helbigto program it:
101a0047cddSDirk Helbig```sh
102a0047cddSDirk Helbignrfjprog --program ble5-ctr-rpmsg_<version number>.hex --chiperase --coprocessor CP_NETWORK -r
103a0047cddSDirk Helbig```
10487521db1SMatthias Ringwald
10587521db1SMatthias Ringwald## TODO
10687521db1SMatthias Ringwald
10787521db1SMatthias Ringwald- Allow/document use of Zephyr HCI Drivers
10887521db1SMatthias Ringwald
10987521db1SMatthias Ringwald
110