Getting Started with NuttX -- FreeScale / NXP Kinetis Tower K64F120M (Arch Linux)

Here we will try to set up a functional Nuttx environment on a TWR-K64F120M Tower evaluation board, combined with the TWR-SER for Ethernet access on Arch Linux OS.

This may be applicable to other Linux distributions as well.

We will install the required software components, configure the board with the following configurations:

  • nsh: uses the main board only. nsh prompt will be available on OpenSDA serial bridge. SDHC card is automounted in /mnt/sdcard
  • netnsh: uses main board coupled with TWR-SER board. nsh prompt will be available on both OpenSDA serial bridge and Ethernet
Installing the ARM tool chain

See “Getting Started with NuttX – Nucleo STM32F303 (Arch Linux)” page for instructions.

Install Nuttx
$ mkdir twr-k64f120m; cd twr-k64f120m
$ git clone
$ git clone

$ cd nuttx
$ tools/ twr-k64f120m/nsh
$ tools/ twr-k64f120m/netnsh

Now compile Nuttx (output truncated):

$ make
LD: nuttx
make[1]: Leaving directory '/home/myhome/projets/twr-k64f120m/nuttx/arch/arm/src'
CP: nuttx.hex

One can see the firmware nuttx.hex has been successfully generated.

Flash & debug with JLInk OpenSDA and gdb

Should you not have a JTAG probe, JLink is kindly providing a proprietary OpenSDA V2 firmware which will allow to flash and debug with JLink software trhoug the USB link, while still keeping the serial bridge feature.

So please install this firwmare on your tower kit. See for instructions

The JLink software is available on Arch AUR: jlink-software-and-documentation. Please install it.

In the nuttx directory, you may prepare a .gdbinit file with:

target remote localhost:2331
monitor reset

It will allow gdb to automatically connect to the JLink server.

udev rules:

JLink package comes with a 99-jlink.rules already installed in /etc/udev/rules.d, so nothing special should be done her.

Make sure your OpenSDA serial is recognized properly. Plug your TWR-K64F120M to the USB connector (Power/OpenSDA Mini-USB).

Check that your board is detected properly:

ls -l /dev/ttyA*
crw-rw-rw- 1 root uucp 166, 0 25 oct.  08:11 /dev/ttyACM0

let's try to connect to OpenSDA

While your TWR-K64F120M is connected with the USB cable, start JLink server:

$ JLinkGDBServer -device MK64FN1M0xxx12 -if SWD -speed 4000 -endian little -vd
SEGGER J-Link GDB Server V5.12 Command Line Version

JLinkARM.dll V5.12 (DLL compiled Mar 30 2016 17:29:06)

-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     2331
SWO raw output listening port: 2332
Terminal I/O port:             2333
Accept remote connection:      yes
Generate logfile:              off
Verify download:               on
Init regs on start:            off
Silent mode:                   off
Single run mode:               off
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 MK64FN1M0xxx12
Target interface:              SWD
Target interface speed:        4000kHz
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link OpenSDA compiled Jan  4 2017 16:04:51
Hardware: V1.00
S/N: 621000000
Checking target voltage...
Target voltage: 3.30 V
Listening on TCP/IP port 2331
Connecting to target...Connected to target
Waiting for GDB connection...

So far so good, in an other dedicated terminal session (cd in nuttx before), start gdb. It should automatically connect to JLink server:

$ arm-none-eabi-gdb nuttx
GNU gdb (GDB) 7.12.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
Find the GDB manual and other documentation resources online at:
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from nuttx...done.
__start () at chip/kinetis_start.c:273
273	{
Resetting target

Now load the firmware into the TWR-K64F120M MCU. In gdb type:

(gdb) load
Loading section .vectors, size 0x198 lma 0x0
Loading section .cfmprotect, size 0x10 lma 0x400
Loading section .text, size 0x32079 lma 0x800
Loading section .ARM.exidx, size 0x8 lma 0x3287c
Loading section .data, size 0x1dc lma 0x32884
Loading section .ramfunc, size 0x6c lma 0x32a60
Start address 0xb3c, load size 205937
Transfer rate: 40222 KB/sec, 11440 bytes/write.

Run the code. In gdb type:

(gdb) mon reset
Resetting target
(gdb) c

The Green LED should be ON on the TWR-K64F120M board. Orange and Red leds should flash faintly according to IRQ and SIGNAL activity.

To stop the code, press Ctlrl+C

For more information on openSDA: and for GNU gdb:

GNU Make doc may be also valuable:

Connect to the OpenSDA serial console

Open a new terminal and run the minterm:

$ --filter direct /dev/ttyACM0 115200 /dev/ttyACM0 115200
--- Miniterm on /dev/ttyACM0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

Press the RESET button on the TWR-K64120M board, one should see the following in the terminal window:

__start: Reset status: 00:00
Mounting procfs to /proc
Successfully bound SDHC to the MMC/SD driver
fat_checkbootrecord: ERROR: Signature: aa55 FS sectorsize: 0 HW sectorsize: 512

NuttShell (NSH)

At this stage the SD card (if any) should be automatically mounted on /mnt/sdcard

Congratulation ! You are started with Nuttx !