NXP OpenSDA

Overview

OpenSDA is a serial and debug adapter that is built into several NXP evaluation boards. It provides a bridge between your computer (or other USB host) and the embedded target processor, which can be used for debugging, flash programming, and serial communication, all over a simple USB cable.

The OpenSDA hardware features a Kinetis K2x microcontroller with an integrated USB controller. On the software side, it implements a mass storage device bootloader which offers a quick and easy way to load OpenSDA applications such as flash programmers, run-control debug interfaces, serial to USB converters, and more.

Zephyr supports the following debug tools through OpenSDA:

Program the Firmware

Once you’ve selected which debug tool you wish to use, you need to program the associated OpenSDA firmware application to the OpenSDA adapter.

Put the OpenSDA adapter into bootloader mode by holding the reset button while you power on the board. After you power on the board, release the reset button and a USB mass storage device called BOOTLOADER or MAINTENANCE will enumerate. Copy the OpenSDA firmware application binary to the USB mass storage device. Power cycle the board, this time without holding the reset button.

pyOCD

pyOCD is an Open Source python 2.7 based library for programming and debugging ARM Cortex-M microcontrollers using CMSIS-DAP.

Host Tools and Firmware

Follow the instructions in pyOCD Installation to install the pyOCD flash tool and GDB server for your host computer.

Select your board in OpenSDA and download the latest DAPLink firmware application binary. Program the Firmware with this application.

Flashing

Use the make flash build target to build your Zephyr application, invoke the pyOCD flash tool and program your Zephyr application to flash.

$ make FLASH_SCRIPT=pyocd.sh flash
Using /home/maureen/zephyr/boards/arm/frdm_k64f/frdm_k64f_defconfig as base
Merging /home/maureen/zephyr/tests/include/test.config
Merging /home/maureen/zephyr/kernel/configs/kernel.config
Merging prj.conf
#
# configuration written to .config
#
make[1]: Entering directory '/home/maureen/zephyr'
make[2]: Entering directory '/home/maureen/zephyr/samples/hello_world/outdir/frdm_k64f'
  GEN     ./Makefile
scripts/kconfig/conf --silentoldconfig Kconfig
  Using /home/maureen/zephyr as source for kernel
  GEN     ./Makefile
  CHK     include/generated/version.h
  UPD     include/generated/version.h
  DTC     dts/arm/frdm_k64f.dts_compiled
  CHK     include/generated/generated_dts_board.h
  UPD     include/generated/generated_dts_board.h
  CHK     misc/generated/configs.c
  UPD     misc/generated/configs.c
  CHK     include/generated/offsets.h
  UPD     include/generated/offsets.h
  CC      lib/libc/minimal/source/stdlib/strtol.o

<snip>

  CC      kernel/work_q.o
  AR      kernel/lib.a
  CC      src/main.o
  LD      src/built-in.o
  AR      libzephyr.a
  LINK    zephyr.lnk
  IRQ     isr_tables.c
  CC      isr_tables.o
  LINK    zephyr.elf
  BIN     zephyr.bin
Flashing frdm_k64f
Flashing Target Device
INFO:root:DAP SWD MODE initialised
INFO:root:K64F not in secure state
INFO:root:ROM table #0 @ 0xe00ff000 cidr=b105100d pidr=4000bb4c4
INFO:root:[0]<e000e000:SCS-M4 cidr=b105e00d, pidr=4000bb00c, class=14>
WARNING:root:Invalid coresight component, cidr=0x0
INFO:root:[1]<e0001000: cidr=0, pidr=0, component invalid>
INFO:root:[2]<e0002000:FPB cidr=b105e00d, pidr=4002bb003, class=14>
WARNING:root:Invalid coresight component, cidr=0x1010101
INFO:root:[3]<e0000000: cidr=1010101, pidr=101010101010101, component invalid>
WARNING:root:Invalid coresight component, cidr=0x0
INFO:root:[4]<e0040000: cidr=0, pidr=0, component invalid>
INFO:root:[5]<e0041000:ETM-M4 cidr=b105900d, pidr=4000bb925, class=9, devtype=13, devid=0>
INFO:root:[6]<e0042000:ETB cidr=b105900d, pidr=4003bb907, class=9, devtype=21, devid=0>
INFO:root:[7]<e0043000:CSTF cidr=b105900d, pidr=4001bb908, class=9, devtype=12, devid=28>
INFO:root:CPU core is Cortex-M4
INFO:root:FPU present
INFO:root:6 hardware breakpoints, 4 literal comparators
INFO:root:4 hardware watchpoints
[====================] 100%
INFO:root:Programmed 12288 bytes (3 pages) at 10.57 kB/s
make[2]: Leaving directory '/home/maureen/zephyr/samples/hello_world/outdir/frdm_k64f'
make[1]: Leaving directory '/home/maureen/zephyr'

Debugging

Use the make debug build target to build your Zephyr application, invoke the pyOCD GDB server, attach a GDB client, and program your Zephyr application to flash. It will leave you at a gdb prompt.

$ make DEBUG_SCRIPT=pyocd.sh debug
Using /home/maureen/zephyr/boards/arm/frdm_k64f/frdm_k64f_defconfig as base
Merging /home/maureen/zephyr/tests/include/test.config
Merging /home/maureen/zephyr/kernel/configs/kernel.config
Merging prj.conf
#
# configuration written to .config
#
make[1]: Entering directory '/home/maureen/zephyr'
make[2]: Entering directory '/home/maureen/zephyr/samples/hello_world/outdir/frdm_k64f'
  GEN     ./Makefile
scripts/kconfig/conf --silentoldconfig Kconfig
  Using /home/maureen/zephyr as source for kernel
  GEN     ./Makefile
  CHK     include/generated/version.h
  UPD     include/generated/version.h
  DTC     dts/arm/frdm_k64f.dts_compiled
  CHK     include/generated/generated_dts_board.h
  UPD     include/generated/generated_dts_board.h
  CHK     misc/generated/configs.c
  UPD     misc/generated/configs.c
  CHK     include/generated/offsets.h
  UPD     include/generated/offsets.h
  CC      lib/libc/minimal/source/stdlib/strtol.o

<snip>

  CC      kernel/work_q.o
  AR      kernel/lib.a
  CC      src/main.o
  LD      src/built-in.o
  AR      libzephyr.a
  LINK    zephyr.lnk
  IRQ     isr_tables.c
  CC      isr_tables.o
  LINK    zephyr.elf
  BIN     zephyr.bin
pyOCD GDB server running on port 3333
GNU gdb (GDB) 7.11.0.20160511-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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-pokysdk-linux --target=arm-zephyr-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/maureen/zephyr/samples/hello_world/outdir/frdm_k64f/zephyr.elf...done.
INFO:root:DAP SWD MODE initialised
INFO:root:K64F not in secure state
INFO:root:ROM table #0 @ 0xe00ff000 cidr=b105100d pidr=4000bb4c4
INFO:root:[0]<e000e000:SCS-M4 cidr=b105e00d, pidr=4000bb00c, class=14>
WARNING:root:Invalid coresight component, cidr=0x0
INFO:root:[1]<e0001000: cidr=0, pidr=0, component invalid>
INFO:root:[2]<e0002000:FPB cidr=b105e00d, pidr=4002bb003, class=14>
WARNING:root:Invalid coresight component, cidr=0x1010101
INFO:root:[3]<e0000000: cidr=1010101, pidr=101010101010101, component invalid>
WARNING:root:Invalid coresight component, cidr=0x0
INFO:root:[4]<e0040000: cidr=0, pidr=0, component invalid>
INFO:root:[5]<e0041000:ETM-M4 cidr=b105900d, pidr=4000bb925, class=9, devtype=13, devid=0>
INFO:root:[6]<e0042000:ETB cidr=b105900d, pidr=4003bb907, class=9, devtype=21, devid=0>
INFO:root:[7]<e0043000:CSTF cidr=b105900d, pidr=4001bb908, class=9, devtype=12, devid=28>
INFO:root:CPU core is Cortex-M4
INFO:root:FPU present
INFO:root:6 hardware breakpoints, 4 literal comparators
INFO:root:4 hardware watchpoints
INFO:root:Telnet: server started on port 4444
INFO:root:GDB server started at port:3333
Remote debugging using :3333
INFO:root:One client connected!
k_cpu_idle () at /home/maureen/zephyr/arch/arm/core/cpu_idle.S:135
135                bx lr
Loading section text, size 0x233e lma 0x0
Loading section devconfig, size 0xa8 lma 0x2340
Loading section rodata, size 0x5d4 lma 0x23e8
Loading section datas, size 0x14 lma 0x29bc
Loading section initlevel, size 0xa8 lma 0x29d0
[====================] 100%
INFO:root:Programmed 45056 bytes (3 pages) at 38.21 kB/s
Start address 0x1b64, load size 10870
Transfer rate: 9 KB/sec, 1207 bytes/write.
(gdb)