Flash Zephyr™ OS on target from Mac

In this article, we will dive into the process of flashing Zephyr™OS into the NXP Freedom-K64F (aka FRDM-K64F) board. This board is an ultra low cost development board powered by a Cortex M4 Core and compatible with the Arduino™ R3 pin layout (if you want to add a shield and easily plug sensors).

Environment setup

First of all, go through this first article on how to setup your development environment on your Mac.

Debug Tool

Your Freedom K64F board comes with a serial and debug adapter called OpenSDA. It enables debugging, serial communication and most importantly for flash programming through a USB cable connected from the board to your Mac.

To use OpenSDA, you need to install a debug tool on your Mac, choosen between pyOCD and Segger J-Link.

We will go with pyOCD which is simply installed by using pip

$ pip install — pre -U pyocd

Device connection

Now connect your board to your mac. You should check if the board is found by pyOCD using the following command :

$ pyocd-gdbserver -l
0 => FRDM-K64F [k64f] boardId => 00EDC00fd0000009

If your device does not appear, bear in mind that there are 2 usb sockets on the board. The top left one is OpenSDA enabled.

Build and Flashing

The board is identified as frdm_k64f within Zephyr. We are going to build the hello world sample and flash the connected board

$ cd $ZEPHYR_BASE/samples/hello_world
$ mkdir build && cd build
$ cmake -GNinja -DBOARD=frdm_k64f ..
$ ninja flash

The magic should happen and your board should be correctly flashed. If you encounter some error (mainly board not connected), run the following command :

$ west -v flash

Serial configuration

The hello world sample simply displays Hello World! through the serial port. So first, identify the device created in the /dev folder. It should be something like /dev/tty.usbmodem14521.

Configure your serial console to be as followed :
* Speed: 115200
* Data: 8 bits
* Parity: None
* Stop bits: 1

In my case, I’m using screen to listen to serial port, as follow :

$ screen /dev/tty.usbmodem14521 115200

Going Further

The next step is to use an IDE for compiling, flashing and debugging Zephyr™OS on a target board. If anyone has a feedback, please feel free to reach me.


Zephyr on K64F : http://docs.zephyrproject.org/boards/arm/frdm_k64f/doc/frdm_k64f.html

OpenSDA : http://docs.zephyrproject.org/tools/opensda.html#nxp-opensda