Get and compile a Zephyr firmware

 

Difficulty: Medium

 Duration: 20 minutes

Prerequisites: Configure SSH Access

Description: Zephyr is a real-time operating system designed for the Internet of Things (IoT). The aim of this tutorial is to understand how to setup your environment and how to compile a Zephyr firmware. Note that Zephyr can be used with the following IoT-LAB nodes: nRF52DK, nRF52840DK, nRF51DK, BBC micro:bit, FRDM-KW41Z, Arduino Zero, ST B-L072Z-LRWAN1, ST B-L475E-IOT01A.
The Zephyr SDK, which is required to build the firmwares, is provided by the SSH frontend of each IoT-LAB site.

  1. Setup your environment by cloning the iot-lab repository from GitHub
    ssh <login>@saclay;.iot-lab.info
    <login>@saclay~$ git clone https://github.com/iot-lab/iot-lab.git
    Cloning into 'iot-lab'...
    ...
    <login>@saclay~$ cd iot-lab
    <login>@saclay:~/iot-lab$ make
    
      Welcome to the IoT-LAB development environment setup.
    
      targets:
    	setup-aggregation-tools
    	setup-cli-tools
    	setup-contiki
    	setup-iot-lab.wiki
    	setup-oml-plot-tools
    	setup-openlab
    	setup-riot
    	setup-wsn430
    	setup-zephyr
    
    
    	pull
  2. Setup Zephyr target
    <login>@saclay:~/iot-lab$ make setup-zephyr
    make setup-zephyr
    git clone --depth https://github.com/zephyrproject-rtos/zephyr.git parts/zephyr
    Cloning into 'parts/zephyr'...
    ...
    <login>@saclay:~/iot-lab$ cd parts/zephyr
  3. Setup the environment variables required to use the Zephyr SDK:
    <login>@saclay:~/iot-lab/parts/zephyr$ source /opt/zephyr.source

    This must be done in each new shell. To have the SDK setup everytime, the command above can be added at the end of your ~/.bashrc file.

  4. Setup the ZEPHYR_BASE environment variable:
    <login>@saclay:~/iot-lab/parts/zephyr$ source zephyr-env.sh

    This must be done in each new shell. To have ZEPHYR_BASE correctly setup everytime, the command above can be added at the end of your ~/.bashrc file (use an absolute path to zephyr-env.sh).

  5. Now that everything is in place, let’s build our first hello_world firmware. This firmware is based on the sample provided in parts/zephyr/samples/hello_world. The sample will be built for the nRF52DK node, which corresponds to the board nrf52_pca10040 in Zephyr.
    <login>@saclay:~/iot-lab/parts/zephyr$ cd samples/hello_world
    <login>@saclay:~/iot-lab/parts/zephyr/samples/hello_world$ mkdir build-nrf52
    <login>@saclay:~/iot-lab/parts/zephyr/samples/hello_world$ cd build-nrf52
    <login>@saclay:~/iot-lab/parts/zephyr/samples/hello_world/build-nrf52$ cmake -DBOARD=nrf52_pca10040 ..
    <login>@saclay:~/iot-lab/parts/zephyr/samples/hello_world/build-nrf52$ make
  6. The generated firmware is located in the zephyr/samples/hello_world/build-nrf52/zephyr directory:
    <login>@saclay:~/iot-lab/parts/zephyr/samples/hello_world/build-nrf52$ ls zephyr/zephyr.{hex,bin,elf}
    zephyr/zephyr.bin  zephyr/zephyr.elf  zephyr/zephyr.hex
    

    Use the *.elf file to flash the nodes using the IoT-LAB tools (webportal or cli-tools)

  7. Here is a table containing the mapping between node names with IoT-LAB names and Zephyr names:
    Node name IoT-LAB name Zephyr name
    nRF52DK nrf52dk nrf52dk_pca10040
    nRF52840DK nrf52840dk nrf52840_pca10056
    nRF51DK nrf51dk nrf51_pca10028
    BBC micro:bit microbit bbc_microbit
    NXP FRDM-KW41Z frdm-kw41z frdm_kw41z
    Arduino Zero arduino-zero arduino_zero
    ST B-L072Z-LRWAN1 st-lrwan1 b_l072z_lrwan1
    ST B-L475E-IOT01A st-iotnode disco_l475_iot1
  8. Build the hello_world firmware for each of the nodes listed above.

Congratulations, you have completed the tutorial!