Getting started with Zephyr: a developer’s guide to your first project
Zephyr OS is integrated within the nRF Connect SDK together with a selection of code examples, application protocols, protocol stacks, libraries, and hardware drivers. Your first Zephyr project An established way of confirming you can connect to and flash a development board is by blinking an on-board LED or displaying ‘Hello, world’ on the system console. The Zephyr SDK provides code samples for these popular tasks in addition to many others. A comprehensive list is available here, divided into functional and sub-system categories. Clicking on each example provides more detailed information, including functional requirements, command line instructions, and board constraints. Before commencing to try a code sample, it is necessary to determine the development board’s identity according to Zephyr’s supported board list . For our first project, we’ll use the nRF9160-DK development board highlighted above. To blink an LED on the board we must ascertain how the physical LED is mapped into Zephyr OS. The devicetree node label table – see Figure 3 – provides the definitions for the board’s LEDs, buttons, and switches. A readable text file of a board’s devicetree has a file extension .dts. The devicetree source file for the nRF9160 highlights the mapping and routing
of board features.
The Blinky code sample uses Zephyr’s GPIO API to configure the required LED using the devicetree and, when executed, will continuously toggle the required LED. You can access the c source code files on the Zephyr GitHub repository – see Figure 4. Use the Zephyr command line tool west, to build and flash the Blinky example to your nRF9160-DK development board. west build -b nrf9160dk_nrf52840 samples/basic/blinky west flash During execution, the LED flashes and a system console displays the current LED state, either ON or OFF. If you encounter a build error that points to the struct gpio_dt_spec LED variable, it is likely that you either have an unsupported board or an incorrect LED assignment. Another test is to use the Hello World example. Since the nRF9160-DK does not have any on-board display, you must use a terminal program to access the board’s system console output. For example, using the minicom terminal program from a Linux command line shell, the syntax is -
dev/ttyACM1 or /dev/ttyACM0 for the nRF9160. You can then proceed to build and flash the sample code, using west from the root directory of the Zephyr respository. west build -b nrf9160dk_nrf52840 samples/hello_world west flash
Another sensor example is using the popular Bosch BME280 environmental device that measures temperature, humidity and air pressure. Equipped with both SPI and I2C interfaces, the BMS280 is available as an add- on shield or Click board for many embedded development boards. Zephyr – the proven, open- source RTOS for embedded developers Zephyr OS offers a stepping- stone for embedded developers who wish to advance their skills from single loop-based applications to real-time, thread- based designs. Supporting all popular microcontroller and microprocessor architectures, and over 500+ development boards, Zephyr is accessible and well- documented. Start your journey into RTOS development today with Zephyr.
Next steps in Zephyr development
Once you have successfully connected to the board and run one or both of the above examples, why not explore more functionality of your chosen development board with one of the more advanced Zephyr code samples? For example, if you choose an STMicro STM32F3 Discovery board as your development platform, you could access its onboard LSM303DLHC 6-axis accelerometer and magnetometer using this code sample.
$ minicom -D <tty_device> -b 115200
Figure 4: The source code of the Zephyr Blinky example Image source: Zephyr
<tty_device> defines the port that the nRF52480 is connected to. In most cases using Linux, it will be /
we get technical
66
67
Powered by FlippingBook