Previously, I wrote an article on an Introduction to Zephyr, a popular RTOS (the most popular RTOS?) in the embedded systems space today, and how industry leaders like Intel and Google see Zephyr as a future standard for PC Embedded Controllers (ECs).  In the spirit of diving deeper, this article continues the thread on Zephyr, this time building a "hello, world"-style application and testing it out.

Hardware

For our investigation into Zephyr, we're going to use actual hardware, the Adafruit Feather M0 Basic Proto, a microcontroller prototyping board based on the Atmel/Microchip ATSAMD21G18 ARM Cortex M0 SoC. The Feather M0 is both Arduino-compatible and natively supported by Zephyr.  Its Zephyr-compatibility, plus low cost (only $19.95 at time of writing) make this board a good candidate for exploring Zephyr.

Furthermore, we'll need a USB to TTL Serial Cable so we can connect to the serial interface on the Feather M0.  There are numerous choices, but I like this one:  DSD TECH SH-U09G.

It's not necessary to buy this hardware in order to derive value from this article, but I'm providing these links in case you would like to work alongside me for the duration of this series of articles on Zephyr.

Building Zephyr for the Feather M0

In my previous Introduction article, I simply built Zephyr, and did it in Ubuntu v22.  This time around, we're going to use Windows, mainly because we need to flash real hardware, and flashing the Feather M0 from Windows Services for Linux (WSL) is currently not supported.  So, to help out the greatest number of people, we'll use Windows.

Following are the steps I took to download the source, build it, flash it on the Feather M0, and run the "hello, world" sample application.  For reference, I used the following guides:

Step-by-step:

  1. Install chocolatey, then run the following 3 commands from an Admin cmd.exe
    1. choco feature enable -n allowGlobalConfirmation
    2. choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
    3. choco install ninja gperf python311 git dtc-msys2 wget 7zip
    4. <close Admin cmd.exe; use normal cmd.exe for remaining steps>
  2. cd %HOMEPATH% (this can be any path where you want the source to reside)
  3. python -m venv zephyrproject\.venv
  4. zephyrproject\.venv\Scripts\activate.bat
  5. pip install west
  6. west init zephyrproject
  7. cd zephyrproject
  8. west update
  9. west zephyr-export
  10. west packages pip --install
  11. cd %HOMEPATH%\zephyrproject\zephyr (or wherever you cloned the source in Step #2)
  12. west sdk install
  13. west build -b adafruit_feather_m0_basic_proto samples/hello_world
  14. Download and install BOSSA:  https://github.com/shumatech/BOSSA
  15. Connect your computer to the Feather M0 via its Micro-USB connector
  16. Double-tap the Feather M0's button to place the board in programming mode; the red LED should start "breathing"
  17. Check Device Manager under Ports (COM & LPT) to see which COM port got assigned, e.g. COM6
  18. Flash Feather M0:  bossac --port=COM6 -R -e -w -v -b %HOMEPATH%\zephyrproject\zephyr\build\zephyr\zephyr.bin -o 8192
  19. Insert USB to TTL Serial Cable, check Device Manager under Ports (COM & LPT) to see which COM port got assigned to the Serial Cable, e.g. COM10
  20. Connect the USB to TTL Serial Cable to the Feather M0:
    • VCC/Red to 3.3V
    • GND/Black to GND
    • TXD to Rx
    • RXD to Tx

    21. Connect a terminal program, like PuTTY to the USB Serial Port owned by the USB to TTL Serial Cable (COM10, in example above)

Press the button once to reboot the Feather M0.  If all goes well, you should see:

Congratulations, that was a lot of work.

A Note on Alternate Zephyr SDK Locations

In Step-by-step above, I ran the command west sdk install to install the Zephyr SDK.  In truth, to "install" the SDK you just download it and unzip it, and it can be put anyplace you like.  You can alternatively just use wget, like:

wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.0/zephyr-sdk-0.17.0_windows-x86_64.7z

If you opt to put the SDK in a custom location, just set the Zephyr-sdk_DIR environment variable:

set Zephyr-sdk_DIR=c:\Users\WilliamLeara\<my custom path>\zephyr-sdk-0.17.0

Before your first build, run the setup.cmd batch file, located in the SDK root; this only needs to be done once after initial install.

A Note on Python Virtual Environments

Working with Zephyr, both installing it and building Zephyr applications, makes use of a Python technology called Python Virtual Environments.  Take a look at the preceding link if you want to learn more, but suffice it to say that before working with Zephyr you should activate the virtual environment by running the command zephyrproject\.venv\Scripts\activate.bat, and in order to exit the virtual environment, run the command deactivate.

Moving Forward

So, now that we've got a foundation of 1) the Zephyr source, 2) Zephyr SDK, and 3) compatible hardware all connected and ready to go, we can explore more sophisticated Zephyr features.  We will use this link to group all Zephyr-related articles:

https://www.basicinputoutput.com/search/label/Zephyr?&max-results=5

Stay tuned!

Next
This is the most recent post.
Previous
Older Post

Post a Comment

Be sure to select an account profile (e.g. Google, OpenID, etc.) before typing your comment!