Working with Zephyr — The RTOS

Milind Deore
Pune Smart City Hackathon
4 min readJun 19, 2016

--

Linux foundation’s Zephyr is going to go long way for Wireless Sensor Nodes (WSN) and IoT gateways. This is one of the OS which linux community drives and many potential semiconductor vendors, the possibility of this being rock star soon is inevitable.

Start contributing to Zephyr

Contributing to open source project is rewarding experience and appreciated by the community too. To save yourself from flames and to adjust to the community standards quickly, i would highly recommend to learn the standards first hand, yes i am talking about coding standards and good practices. As you becoming the part of already established community, take it easy and slowly, may be start with code review, update documents etc. I tried by first stint with Zephyr around the same lines. Written a library form of HD44780 LCD controller sample code. This falls in the testing region of Zephyr codebase and not integral part of the kernel, at the same time if someone would like to use it in their project can use it as part of library with fever changes in the code structure.

I will walk you through …

Step 1 : Read coding standards

Reiterating the same that i mentioned before, because its most important for any FOSS (Free and Open Source Software).

“Smart people ask less question and often intelligent ones !”

Step 2 : Create Linux Foundation ID

Follow the Linux Foundation account creation process on following this page.

Create a key-pair using command

ssh-keygen -t rsa -C “Milind D milind.d@example.com

The generated key can be found in: ~/.ssh/id_rsa (private key) and ~/.ssh/id_rsa.pub (public key). Add private key to key-ring.

It is also necessary that you should have 600 permission set for private key. We need to protect our private key.

You might face issue with SSH sometimes because when it is not added to the ssh agent (use ‘ssh-add’ to verify “ssh-add -L” should give you keys of all identity) or for other reasons. Follow the steps given here and using troubleshooting to understand real problem area (if any).

ssh -v -p 29418 sshusername@hostname

‘-v’ option potentially point you to the real problem area so do not forget to use it. If you get “Welcome …” message, you are all good to go!

Step 3: Time to clone the repository

Following command would use you ssh key to create git clone:

git clone ssh://<LFID>@gerrit.zephyrproject.org:29418/zephyr zephyr-project

Step 4 : Your patch goes in here !

The patch you want to introduce will go in here but before that there are quite a few due diligence required on your part. Follow coding guidelines and run readymade scripts (under ./zephyr-project/scripts/)to make sure you are in good shape. If you avoid this step, CI will catch and mark your patch invalid which is also visible in Gerrit, i am sure you do not want this? Only when CI approves the patch, it will be code-reviewed by community. Find out who is the right person who can review your code, otherwise maintainer would add few folks. Submitting your patch for code review via Gerrit is simple but has some process.

Due diligence is not just about the process but also make it easy for community to review your code. You can help in various ways:

Commenting : This is one of the most important part that gives idea about the patch in quick glance. Example you patch comment should start with the component name(s) example: ‘kernel’ OR ‘sample : gpio : lcd’. A decently detailed comment give huge help, please follow the the guide here.

‘change-id’ and ‘signed-off-by’ : Should have ‘change-id’ and ‘signed-off-by’ at the end of the commit. change-id is added automatically but ‘signed-off-id’ needs to be added by the user. After commit make sure these fields are set properly and are in place.

Step 5 : Review comments (Optional)

If you got review comments, then you do not have to create new change-id because Gerrit track changes based on change-id. Hence amend the commit rather then creating a new one.

NOTE: DO NOT CREATE A NEW COMMIT, RATHER AMEND THE OLD COMMIT.

Use following command to amend the existing changes:

git commit --amend

Say by mistake you have created multiple commits and want to rebase them, this guide would really help.

Step 6: Flashing image to Arduino Due (Optional)

This step is optional and completely based on the single-board-computer you have. I have Arduino Due and hence i will write this section considering the same.

  1. Hope you have exported path and other zephyr related variables, if not run ‘source zephyr-env.sh’ from home directory.
  2. Pick any project, let me pick the one that i created :
$ cd ./zephyr-project/samples/drivers/lcd_hd44780$ vim ./prj.conf ---> make changes here based on your configuration.
CONFIG_GPIO=y
CONFIG_NANO_TIMERS=y
CONFIG_NANO_TIMEOUTS=y
$ make ---> cross compile your code based on inputs provided.
KERNEL_TYPE = nano
BOARD = arduino_due
CONF_FILE = prj.conf

3. ‘make’ command will cross compile the code based on the board and kernel you provided.

4. If the code compiles successfully, it will create ‘outdir’ directory that will have compiled binary (by name zephyr.bin) that you can flash to your board.

5. Before you flash make sure you erase the existing image from your arduino. This is important.

6. I am using BOSSA utility to flash my image to Arduino Due using USB port on my MAC. BOSSA works for FTDI bashed USB controllers and the same is there on my Arduino board, its basically UDOO Dual board.

$ ./bossac -p cu.SLAB_USBtoUART -e -w -v -b zephyr-project/samples/drivers/lcd_hd44780/outdir/zephyr.bin

6. Use external USB monitoring tool to Arudino to enjoy serial print output. OR in this project we have compiled LCD HD44780 program, so if you have once this display and enjoy the output.

Happy coding!

--

--