Zephyr KNoT SDK provides libraries, tools and samples to make a KNoT application for Zephyr environment.
The actual version of KNoT Zephyr SDK is only available for Linux based systems. You may consider using a Virtual Machine running a Linux distribution on other systems.
KNoT uses a fork of Zephyr repository.
-
Set up a Zephyr development environment by following these instructions.
-
Program the
$HOME/.profile
to always set ZEPHYR_TOOLCHAIN_VARIANT and ZEPHYR_SDK_INSTALL_DIR.$ echo "export ZEPHYR_TOOLCHAIN_VARIANT=zephyr" >> $HOME/.profile $ echo "export ZEPHYR_SDK_INSTALL_DIR=`readlink -f <SDK-INSTALLATION-DIRECTORY>`" >> $HOME/.profile
Replace
<SDK-INSTALLATION-DIRECTORY>
by the actual Zephyr SDK install path -
Install the west binary and bootstrapper
$ pip3 install --user west
-
Create an enclosing folder and change directory
$ mkdir zephyrproject $ cd zephyrproject
-
Clone KNoT Zephyr fork
$ git clone -b zephyr-knot-v1.14.0 https://github.com/CESARBR/zephyr.git
-
Initialize west. Inside zephyrproject directory run:
$ west init -l zephyr/ $ west update
If the system can't find west, try logging out and in again.
-
Set up zephyr environment variables
$ source zephyr/zephyr-env.sh
-
Program the
$HOME/.profile
to always source zephyr-env.sh when you log in.$ echo "source $ZEPHYR_BASE/zephyr-env.sh" >> $HOME/.profile
If you skip this step, it will be necessary to manually source zephyr-env.sh every time a new terminal is opened.
-
Download and install nrfjprog and mergehex cli applications at nRF5 Command Line Tools.
-
Add the nrfjprog and mergehex executables to the
~/.local/bin/
folder.$ ln -s `readlink -f <MERGEHEX-PATH>` >> $HOME/.local/bin/mergehex $ ln -s `readlink -f <NRFJPROG-PATH>` >> $HOME/.local/bin/nrfjprog
Replace
<MERGEHEX-PATH>
and<NRFJPROG-PATH>
by path to the downloaded apps
This is only necessary if you're going to use the DK board.
- Download the appropriate package from the J-Link Software and install it.
-
Download the zephyr-knot-sdk repository to a folder you prefer.
$ git clone https://github.com/cesarbr/zephyr-knot-sdk/
-
The environment configuration file is used to set up KNOT_BASE path.
$ source zephyr-knot-sdk/knot-env.sh
-
Program the
$HOME/.profile
to always source knot-env.sh when you log in.$ echo "source $KNOT_BASE/knot-env.sh" >> $HOME/.profile
-
Add cli.py to the path files.
$ ln -s $KNOT_BASE/scripts/cli.py $HOME/.local/bin/knot
This will allow you to call the knot command line interface from any folder.
-
Use pip to install cli requirements
$ pip3 install --user -r ${KNOT_BASE}/scripts/requirements.txt
If you skip this step, it will be necessary to manually source knot-env.sh every time a new terminal is opened.
- Follow the instructions to install the KNoT protocol library.
- Add your user to the dialout group.
$ sudo usermod -a -G dialout `whoami`
- In order to apply the changes to your user, you must log out and log in again.
Make sure that you have sourced the knot-env.sh, zephyr-env.sh and defined the values for ZEPHYR_SDK_INSTALL_DIR and ZEPHYR_TOOLCHAIN_VARIANT.
You may be using one of the two supported boards: DK (nrf52840_pca10056) or Dongle (nrf52840_pca10059).
-
If using the DK:
- Connect the board to a USB port
- Set the DK as the default target board
$ knot board dk
-
If using the Dongle:
- Connect the board to a USB port
- Press the reset button. The red led will blink.
- Set the Dongle as the default target board
$ knot board dongle
-
Go to the KNoT App file.
$ cd <path-to-app>
If you don't have an app, you may use the example at $KNOT_BASE/apps/hello
-
Build and flash apps
$ knot make --mcuboot
The option 'mcuboot' flashes the compiled program and the mcuboot booloader at the end of building.
You can use minicom or any other serial port reader to monitor the app output.
-
Install minicom
You can install minicom on debian based systems by using:
$ sudo apt-get install minicom
$ minicom -D <your-device>
If you are using debian the device usually is something like /dev/ttyACM0.
There are many commands that you can call when using the knot script (cli.py). Some of their functions are:
- You can set the default target board with the command:
Where
$ knot board <BOARD>
<BOARD>
can be 'dk' or 'dongle'
To avoid downloading the OpenThread repo on every new build, set an external path:
-
Clone Openthread Github repository:
$ git clone https://github.com/openthread/openthread.git
-
Checkout to the compatible hash and set it as default
$ cd openthread $ git checkout -b knot_hash f9d757a161fea4775d033a1ce88cf7962fe24a93 $ knot ot-path `pwd`
The user can delete old building files before compiling again:
This is especially useful when the project had important changes like different target board or dependency repository.
- Clear old files before compiling:
$ knot make --clean
The user can flash the board just after building it:
- Flash board after building:
$ knot make --flash
This option also flashes the bootloader when targeting the Dongle.
When using the DK, it's possible for the board to be flashed without the bootloader. To fix that, the user should flash it separately.
- Flash bootloader to board.
$ knot mcuboot
This option also erases the main app when targeting the Dongle.
These and the other commands are described when using the command:
- Read help
$ knot --help