Skip to content

bus710/zephyr-rtos-development-in-linux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 

Repository files navigation

Zephyr RTOS Development in Linux

Zephyr is an RTOS for IoT projects.
This repo is a walkthrough to prepare Zephyr development environment for nRF52 devices in Ubuntu.



Index

  • Prerequisites
  • Reference
  • Contents
    1. Linux dependencies
    2. Get JLink package
    3. Get zephyr source code and tools
    4. Get zephyr SDK
    5. Build the blinky application for nRF52832-DK
    6. Debug the blinky app in VSCODE
  • What's next



Prerequisites

  • nRF52832-DK board
  • Ubuntu 19.10 or newer version on a PC



Reference




1. Linux dependencies

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 



2. Get JLink package

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:

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)



3. Get zephyr source code and tools

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



4. Get zephyr SDK

Check the latest stable SDK version first:

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



5. Build the blinky application

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



6. Debug the blinky app in VSCODE

First, install VSCODE:

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



6.1 For Jlink GDB host and the on board probe

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.



6.2 For Openocd GDB host and the on board probe

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.




What's next

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!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages