1*cfb92d14SAndroid Build Coastguard Worker# OpenThread POSIX app 2*cfb92d14SAndroid Build Coastguard Worker 3*cfb92d14SAndroid Build Coastguard WorkerOpenThread supports running its core on POSIX and transmits radio frames through a radio transceiver. 4*cfb92d14SAndroid Build Coastguard Worker 5*cfb92d14SAndroid Build Coastguard WorkerCurrently most platforms in [examples/platforms](../../examples/platforms) support transceiver mode. 6*cfb92d14SAndroid Build Coastguard Worker 7*cfb92d14SAndroid Build Coastguard WorkerThe figure below shows the architecture of OpenThread running in transceiver mode. 8*cfb92d14SAndroid Build Coastguard Worker 9*cfb92d14SAndroid Build Coastguard Worker``` 10*cfb92d14SAndroid Build Coastguard Worker+-------------------------+ 11*cfb92d14SAndroid Build Coastguard Worker| MLE TMF UDP IP | 12*cfb92d14SAndroid Build Coastguard Worker| MeshForwarder 6LoWPAN | 13*cfb92d14SAndroid Build Coastguard Worker| _ _ _ _ _ _ _ _ _ _ _ _ | spinel +------------------+ 14*cfb92d14SAndroid Build Coastguard Worker| OpenThread Core | <----------------> | OpenThread Radio | 15*cfb92d14SAndroid Build Coastguard Worker+-------------------------+ UART|SPI +------------------+ 16*cfb92d14SAndroid Build Coastguard Worker POSIX Chip 17*cfb92d14SAndroid Build Coastguard Worker``` 18*cfb92d14SAndroid Build Coastguard Worker 19*cfb92d14SAndroid Build Coastguard Worker## Build POSIX CLI 20*cfb92d14SAndroid Build Coastguard Worker 21*cfb92d14SAndroid Build Coastguard Worker```sh 22*cfb92d14SAndroid Build Coastguard Worker./script/cmake-build posix 23*cfb92d14SAndroid Build Coastguard Worker``` 24*cfb92d14SAndroid Build Coastguard Worker 25*cfb92d14SAndroid Build Coastguard WorkerIf built successfully, the binary should be found at: `build/posix/src/posix/ot-cli`. 26*cfb92d14SAndroid Build Coastguard Worker 27*cfb92d14SAndroid Build Coastguard Worker## Transceivers on different platforms 28*cfb92d14SAndroid Build Coastguard Worker 29*cfb92d14SAndroid Build Coastguard Worker### Simulation 30*cfb92d14SAndroid Build Coastguard Worker 31*cfb92d14SAndroid Build Coastguard WorkerOpenThread provides an implementation on the simulation platform which enables running a simulated transceiver on the host. 32*cfb92d14SAndroid Build Coastguard Worker 33*cfb92d14SAndroid Build Coastguard Worker#### Build 34*cfb92d14SAndroid Build Coastguard Worker 35*cfb92d14SAndroid Build Coastguard Worker```sh 36*cfb92d14SAndroid Build Coastguard Worker# Only build RCP so that it goes faster 37*cfb92d14SAndroid Build Coastguard Worker./script/cmake-build simulation -DOT_APP_CLI=OFF -DOT_APP_NCP=OFF -DOT_FTD=OFF -DOT_MTD=OFF 38*cfb92d14SAndroid Build Coastguard Worker``` 39*cfb92d14SAndroid Build Coastguard Worker 40*cfb92d14SAndroid Build Coastguard Worker#### Run 41*cfb92d14SAndroid Build Coastguard Worker 42*cfb92d14SAndroid Build Coastguard Worker**NOTE** Assuming the build system is 64bit Linux, you can use the normal OpenThread CLI as described in the [command line document](../../src/cli/README.md). You can also perform radio diagnostics using the command [diag](../../src/core/diags/README.md). 43*cfb92d14SAndroid Build Coastguard Worker 44*cfb92d14SAndroid Build Coastguard Worker```sh 45*cfb92d14SAndroid Build Coastguard Worker./build/posix/src/posix/ot-cli 'spinel+hdlc+forkpty://build/simulation/examples/apps/ncp/ot-rcp?forkpty-arg=1' 46*cfb92d14SAndroid Build Coastguard Worker``` 47*cfb92d14SAndroid Build Coastguard Worker 48*cfb92d14SAndroid Build Coastguard Worker### Nordic Semiconductor nRF52840 49*cfb92d14SAndroid Build Coastguard Worker 50*cfb92d14SAndroid Build Coastguard WorkerThe nRF example platform driver can be found in the [ot-nrf528xx](https://github.com/openthread/ot-nrf528xx) repo. 51*cfb92d14SAndroid Build Coastguard Worker 52*cfb92d14SAndroid Build Coastguard Worker#### Build 53*cfb92d14SAndroid Build Coastguard Worker 54*cfb92d14SAndroid Build Coastguard WorkerTo build and program the device with RCP application, complete the following steps: 55*cfb92d14SAndroid Build Coastguard Worker 56*cfb92d14SAndroid Build Coastguard Worker1. Clone the OpenThread nRF528xx platform repository into the current directory: 57*cfb92d14SAndroid Build Coastguard Worker 58*cfb92d14SAndroid Build Coastguard Worker ```sh 59*cfb92d14SAndroid Build Coastguard Worker git clone --recursive https://github.com/openthread/ot-nrf528xx.git 60*cfb92d14SAndroid Build Coastguard Worker ``` 61*cfb92d14SAndroid Build Coastguard Worker 62*cfb92d14SAndroid Build Coastguard Worker2. Enter the `ot-nrf528xx` directory: 63*cfb92d14SAndroid Build Coastguard Worker 64*cfb92d14SAndroid Build Coastguard Worker ```sh 65*cfb92d14SAndroid Build Coastguard Worker cd ot-nrf528xx 66*cfb92d14SAndroid Build Coastguard Worker ``` 67*cfb92d14SAndroid Build Coastguard Worker 68*cfb92d14SAndroid Build Coastguard Worker3. Install the OpenThread dependencies: 69*cfb92d14SAndroid Build Coastguard Worker 70*cfb92d14SAndroid Build Coastguard Worker ```sh 71*cfb92d14SAndroid Build Coastguard Worker ./script/bootstrap 72*cfb92d14SAndroid Build Coastguard Worker ``` 73*cfb92d14SAndroid Build Coastguard Worker 74*cfb92d14SAndroid Build Coastguard Worker4. Build the RCP example for the hardware platform and the transport of your choice: 75*cfb92d14SAndroid Build Coastguard Worker 76*cfb92d14SAndroid Build Coastguard Worker a. nRF52840 Dongle (USB transport) 77*cfb92d14SAndroid Build Coastguard Worker 78*cfb92d14SAndroid Build Coastguard Worker ```sh 79*cfb92d14SAndroid Build Coastguard Worker rm -rf build 80*cfb92d14SAndroid Build Coastguard Worker script/build nrf52840 USB_trans -DOT_BOOTLOADER=USB 81*cfb92d14SAndroid Build Coastguard Worker ``` 82*cfb92d14SAndroid Build Coastguard Worker 83*cfb92d14SAndroid Build Coastguard Worker b. For nRF52840 Development Kit 84*cfb92d14SAndroid Build Coastguard Worker 85*cfb92d14SAndroid Build Coastguard Worker ```sh 86*cfb92d14SAndroid Build Coastguard Worker rm -rf build 87*cfb92d14SAndroid Build Coastguard Worker script/build nrf52840 UART_trans 88*cfb92d14SAndroid Build Coastguard Worker ``` 89*cfb92d14SAndroid Build Coastguard Worker 90*cfb92d14SAndroid Build Coastguard Worker This creates an RCP image at `build/bin/ot-rcp`. 91*cfb92d14SAndroid Build Coastguard Worker 92*cfb92d14SAndroid Build Coastguard Worker5. Generate the HEX image: 93*cfb92d14SAndroid Build Coastguard Worker 94*cfb92d14SAndroid Build Coastguard Worker ```sh 95*cfb92d14SAndroid Build Coastguard Worker arm-none-eabi-objcopy -O ihex build/bin/ot-rcp build/bin/ot-rcp.hex 96*cfb92d14SAndroid Build Coastguard Worker ``` 97*cfb92d14SAndroid Build Coastguard Worker 98*cfb92d14SAndroid Build Coastguard Worker6. Depending on the hardware platform, complete the following steps to program the device: 99*cfb92d14SAndroid Build Coastguard Worker 100*cfb92d14SAndroid Build Coastguard Worker a. nRF52840 Dongle (USB transport) 101*cfb92d14SAndroid Build Coastguard Worker 102*cfb92d14SAndroid Build Coastguard Worker ```sh 103*cfb92d14SAndroid Build Coastguard Worker # Install nRF Util: 104*cfb92d14SAndroid Build Coastguard Worker python3 -m pip install -U nrfutil 105*cfb92d14SAndroid Build Coastguard Worker 106*cfb92d14SAndroid Build Coastguard Worker # Generate the RCP firmware package: 107*cfb92d14SAndroid Build Coastguard Worker nrfutil pkg generate --hw-version 52 --sd-req=0x00 \ 108*cfb92d14SAndroid Build Coastguard Worker --application build/bin/ot-rcp.hex --application-version 1 build/bin/ot-rcp.zip 109*cfb92d14SAndroid Build Coastguard Worker ``` 110*cfb92d14SAndroid Build Coastguard Worker 111*cfb92d14SAndroid Build Coastguard Worker Connect the nRF52840 Dongle to the USB port and press the **RESET** button on the dongle to put it into the DFU mode. The LED on the dongle starts blinking red. 112*cfb92d14SAndroid Build Coastguard Worker 113*cfb92d14SAndroid Build Coastguard Worker ```sh 114*cfb92d14SAndroid Build Coastguard Worker # Install the RCP firmware package onto the dongle 115*cfb92d14SAndroid Build Coastguard Worker nrfutil dfu usb-serial -pkg build/bin/ot-rcp.zip -p /dev/ttyACM0 116*cfb92d14SAndroid Build Coastguard Worker ``` 117*cfb92d14SAndroid Build Coastguard Worker 118*cfb92d14SAndroid Build Coastguard Worker b. nRF52840 Development Kit 119*cfb92d14SAndroid Build Coastguard Worker 120*cfb92d14SAndroid Build Coastguard Worker ```sh 121*cfb92d14SAndroid Build Coastguard Worker # Program the image using the nrfjprog utility. 122*cfb92d14SAndroid Build Coastguard Worker nrfjprog -f nrf52 --chiperase --program build/bin/ot-rcp.hex --reset 123*cfb92d14SAndroid Build Coastguard Worker ``` 124*cfb92d14SAndroid Build Coastguard Worker 125*cfb92d14SAndroid Build Coastguard Worker Disable the Mass Storage feature on the device, so that it does not interfere with the core RCP functionalities: 126*cfb92d14SAndroid Build Coastguard Worker 127*cfb92d14SAndroid Build Coastguard Worker ```sh 128*cfb92d14SAndroid Build Coastguard Worker JLinkExe -device NRF52840_XXAA -if SWD -speed 4000 -autoconnect 1 129*cfb92d14SAndroid Build Coastguard Worker J-Link>MSDDisable 130*cfb92d14SAndroid Build Coastguard Worker Probe configured successfully. 131*cfb92d14SAndroid Build Coastguard Worker J-Link>exit 132*cfb92d14SAndroid Build Coastguard Worker ``` 133*cfb92d14SAndroid Build Coastguard Worker 134*cfb92d14SAndroid Build Coastguard Worker Power-cycle the device to apply the changes. 135*cfb92d14SAndroid Build Coastguard Worker 136*cfb92d14SAndroid Build Coastguard Worker#### Run 137*cfb92d14SAndroid Build Coastguard Worker 138*cfb92d14SAndroid Build Coastguard Worker```sh 139*cfb92d14SAndroid Build Coastguard Worker./build/posix/src/posix/ot-cli 'spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=115200' 140*cfb92d14SAndroid Build Coastguard Worker``` 141*cfb92d14SAndroid Build Coastguard Worker 142*cfb92d14SAndroid Build Coastguard Worker## Daemon Mode 143*cfb92d14SAndroid Build Coastguard Worker 144*cfb92d14SAndroid Build Coastguard WorkerOpenThread Posix Daemon mode uses a unix socket as input and output, so that OpenThread core can run as a service. And a client can communicate with it by connecting to the socket. The protocol is OpenThread CLI. 145*cfb92d14SAndroid Build Coastguard Worker 146*cfb92d14SAndroid Build Coastguard Worker``` 147*cfb92d14SAndroid Build Coastguard Worker# build daemon mode core stack for POSIX 148*cfb92d14SAndroid Build Coastguard Worker./script/cmake-build posix -DOT_DAEMON=ON 149*cfb92d14SAndroid Build Coastguard Worker# Daemon with simulation 150*cfb92d14SAndroid Build Coastguard Worker./build/posix/src/posix/ot-daemon 'spinel+hdlc+forkpty://build/simulation/examples/apps/ncp/ot-rcp?forkpty-arg=1' 151*cfb92d14SAndroid Build Coastguard Worker# Daemon with real device 152*cfb92d14SAndroid Build Coastguard Worker./build/posix/src/posix/ot-daemon 'spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=115200' 153*cfb92d14SAndroid Build Coastguard Worker# Built-in controller 154*cfb92d14SAndroid Build Coastguard Worker./build/posix/src/posix/ot-ctl 155*cfb92d14SAndroid Build Coastguard Worker``` 156