Zephyr is an RTOS for IoT projects.
This repo is a walkthrough to prepare Zephyr development environment for nRF52 devices in Ubuntu.
- Prerequisites
- Reference
- Contents
- Linux dependencies
- Get JLink package
- Get zephyr source code and tools
- Get zephyr SDK
- Build the blinky application for nRF52832-DK
- Debug the blinky app in VSCODE
- What's next
- nRF52832-DK board
- Ubuntu 19.10 or newer version on a PC
- nRF development in linux
- Home page
- Documents
- Introduction
- Downloads
- Linux dependencies
- Getting started
- Beyond the getting started
- West - zephyr meta tool
- Samples and demos
- Application development
- Overview: nRF52832 + zephyr
- JLink for nRF52
- Nice explanation for debuggers
- nRF52 development with VSCODE/Cortex-debug
Install some packages:
$ sudo apt update
$ sudo apt install build-essential \
git \
openocd \
libncurses5 \
gdb-multiarch \
gcc-arm-none-eabi
$ sudo apt-get install --no-install-recommends \
git cmake ninja-build gperf \
ccache dfu-util device-tree-compiler wget \
python3-pip python3-setuptools python3-tk python3-wheel \
xz-utils file make gcc gcc-multilib
Check the versions (should be newer than these):
$ arm-none-eabi-gcc -v
gcc version 7.3.1 20180622 ...
$ openocd
Open On-Chip Debugger 0.10.0
$ cmake --version
cmake version 3.13.4
$ dtc --version
Version: DTC 1.4.7
$ pip3 --version
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)
Get west:
$ pip3 install --user -U west
$ echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc
$ source ~/.bashrc
$ west --version
West version: v0.6.3
(Optional) Do this if ncurses installation shows some error:
$ sudo apt --fix-broken install
We can download some software tools from Nordic semiconductor:
- JLinkExe is required to use JLink
- nrfjprog is specifically requried to work with nRF chips
Download nRF5x-Command-Line-Tools for Linux 64 bit from:
- https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Command-Line-Tools/Download#infotabs
- (if the above link doesn't work) https://www.nordicsemi.com > Software and Tools > Development tools > nRF command line tools. Please pick the OS (Linux 64) and download.
Run these commands to install the tools:
$ tar xvf nRF-Command-Line-Tools_10_4_1_Linux-amd64.tar.gz
$ sudo dpkg -i JLink_Linux_V650b_x86_64.deb
$ sudo dpkg -i nRF-Command-Line-Tools_10_4_1_Linux-amd64.deb
To check the version of installed tools:
$ nrfjprog -v
nrfjprog version: 10.4.1
JLinkARM.dll version: 6.50b
$ mergehex -v
mergehex version: 10.4.1
$ JLinkExe -v
SEGGER J-Link Commander V6.50b (Compiled Sep 6 2019 17:46:52)
DLL version V6.50b, compiled Sep 6 2019 17:46:40
Unknown command line option -h. (<= Don't worry about this)
Here each step downloads many files from the internet:
- the source code in west initializing is about 600~700MB
- the objects in west updating is about 300MB
- the packages in pip3 installing is about 100MB
$ cd ~
$ west init zephyrproject
$ cd zephyrproject
$ west update
$ pip3 install --user -r ~/zephyrproject/zephyr/scripts/requirements.txt
Check the latest stable SDK version first:
- https://www.zephyrproject.org/developers (just to see news)
- https://github.com/zephyrproject-rtos/sdk-ng/releases (to see the SDK version)
- 0.10.3 is the latest as of today
- The size is about 1.1GB
Download it:
$ wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.10.3/zephyr-sdk-0.10.3-setup.run
Run the SDK installer:
$ chmod 744 zephyr-sdk-0.10.3-setup.run
$ ./zephyr-sdk-0.10.3-setup.run -- -d ~/zephyr-sdk-0.10.3
...
Success installing SDK. SDK is ready to be used.
Since the extracted files are stored in ~/zephyr-sdk-0.10.3, put these in bashrc or so:
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=$HOME/zephyr-sdk-0.10.3
To apply the variables:
$ source ~/.bashrc
Get an udev rule file for openocd:
$ sudo cp ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
$ sudo udevadm control --reload
Add this to bashrc:
source ~/zephyrproject/zephyr/zephyr-env.sh
Apply the variables:
$ source ~/.bashrc
Then build the project:
- the result as bin and elf files will be created in:
- ~/zephyrproject/zephyr/samples/basic/blinky/build/zephyr
- run this one time and use the flash sub command for short
$ cd ~/zephyrproject/zephyr/samples/basic/blinky
$ west build -p auto -b nrf52_pca10040 .
To flash the generated image to a connected board:
$ west flash
...
-- runners.nrfjprog: Board with serial number 682347313 flashed successfully.
(Option) To clean the built images:
$ west build -b nrf52_pca10040 -t clean
(Option) To erase the flash memory (+UICR) of the target:
$ west flash --erase
First, install VSCODE:
- https://code.visualstudio.com/download
- Don't forget to install Cortex-Debug and C/C++ extension
Open the blinky app in VSCODE:
$ cd ~/zephyrproject/zephyr/samples/basic/blinky
$ code .
To create the launch.json file in VSCODE,
- press CTRL + SHIFT + P
- use the Debug: Open launch.json
- choose the Cortex-Debug
- follow one of the below options
Paste this for the launch.json for Cortex-Debug extension:
{
"version": "0.2.0",
"configurations": [
{
"name": "Zephyr nRF52832",
"cwd": "${workspaceRoot}",
"executable": "build/zephyr/zephyr.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"device": "nrf52832_xxaa",
"targetId": "nrf52",
"boardId": "",
"armToolchainPath": "${HOME}/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin",
"interface": "swd",
"gdbpath": "/usr/bin/gdb-multiarch",
},
]
}
To start debugging, press the F5 key twice.
However, this may not support RTOS-awareness.
Paste this for the launch.json for Cortex-Debug extension:
{
"version": "0.2.0",
"configurations": [
{
"name": "Zephyr nRF52832 openocd",
"cwd": "${workspaceRoot}",
"executable": "build/zephyr/zephyr.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "nrf52832_xxaa",
"targetId": "nrf52",
"boardId": "",
"armToolchainPath": "${HOME}/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin",
"interface": "swd",
"gdbpath": "/usr/bin/gdb-multiarch",
"configFiles": [
"/usr/share/openocd/scripts/board/nordic_nrf52_dk.cfg"
]
},
]
}
To start debugging, press the F5 key twice.
The application doc introduces the basic work flow:
In the same doc, there is a section that describes to make a custom system:
Also, there are tips in the user and developer guide:
Good luck!