Use OpenOCD and an FTDI Mini Module as a Kinetis K22 Debugger

We review the steps and connections necessary to use both OpenOCD and an FTDI Mini-module as a JTAG debugger for a Kinetis K22 embedded on an FRDM-K22 board. Also, we build OpenOCD from source using the Git repo and run it on an Ubuntu 16.04 system.

advertisement

Overview

We utilize an NXP Kinetis K22 microcontroller on Private Island (our open source network security project). The system has on-board debug support utilizing an FTDI FT2232H device as a USB-based JTAG controller and UART. This article briefly describes how we prototyped & tested OpenOCD debug operation utilizing an FT2232H Mini-Module and an NXP FRDM-K22 board via JTAG. Note that working with the OpenOCD project and the K22 is an ongoing process to ensure each open source developer working with Private Island has the best experience possible.

OpenOCD (On-Chip Debugger) is an open source, community project for debugging and programming of embedded processors and FPGAs.

The FT2232H is a USB 2.0 Hi-Speed (480Mb/s) to UART/FIFO/JTAG device. It has the capability of being configured in a variety of industry standard serial or parallel interfaces, and we use it on Private Island as a combination JTAG controller and UART for the on-board NXP K22 and Lattice ECP5UM FPGA

The NXP Kinetis K22 integrates an ARM Cortex M4 (ARMv7). Our Integrated Development Environment (IDE) of choice for code development and debugging is Kinetis Development Studio. Although this ships with built in OpenOCD support (older version), we will be testing with the master branch of OpenOCD via the Git Repository. Note that we are using an Ubuntu 16.04 System on a x86_64 machine.

JTAG is a 4-wire protocol defined by the IEEE (Std 1149.1-2013). The signals that comprise the Test Access Port (TAP) are TCK, TMS, TDI, and TDO. Various implementations also make use of additional pins for test and programming (i.e., TRST). Support of these additional signals can be accomplished with the FT2232 device through general purpose I/Os.

Before we go further, a disclaimer / warning: use these instructions and the development hardware with care and at your own risk. We have been using the FTDI Mini-module for programming various devices for a long time. However, there are associated risks, such as having the un-enclosed Mini-module short against something, wiring it improperly, using a faulty card, etc. However, if you exercise caution, review the data sheets, and double check your connections, you should be fine.

Build OpenOCD from Source / Git Repo

We're using our Ubuntu 16.04, x86_64 build machine. We build our projects at '/build':

$ cd /build
$ git clone https://git.code.sf.net/p/openocd/code  openocd
Cloning into 'openocd'...
remote: Counting objects: 56333, done.
remote: Compressing objects: 100% (20689/20689), done.
remote: Total 56333 (delta 46326), reused 43111 (delta 35495)
Receiving objects: 100% (56333/56333), 12.59 MiB | 2.77 MiB/s, done.
Resolving deltas: 100% (46326/46326), done.
Checking connectivity... done.

$ cd openocd
$ git log
commit 0e02fe40c64ad7488aeb351641723e1eb9ae49cb
Author: Peter Griffin
Date:   Mon Jun 12 16:28:03 2017 +0100
...

Normally, we would checkout the latest stable release / tag ( v0.10.0 ), but let's work with the bleeding edge in this instance. If we find strange bugs, we can backtrack.

Let's build OpenOCD in it's own directory. Some of the prerequisite Ubuntu packages include libtool, automake, autoconf, libusb-1.0, and libhidapi-dev, so you may need to install these before either bootstrap or configure will complete.

$ cd /build/openocd/
$ ./bootstrap
...

$ mkdir build
$ cd build
$ ../configure --enable-ftdi --enable-cmsis-dap
...
OpenOCD configuration summary
--------------------------------------------------
MPSSE mode of FTDI based devices        yes
ST-Link JTAG Programmer                 yes (auto)
TI ICDI JTAG Programmer                 yes (auto)
Keil ULINK JTAG Programmer              yes (auto)
Altera USB-Blaster II Compatible        yes (auto)
Versaloon-Link JTAG Programmer          yes (auto)
OSBDM (JTAG only) Programmer            yes (auto)
eStick/opendous JTAG Programmer         yes (auto)
Andes JTAG Programmer                   yes (auto)
USBProg JTAG Programmer                 no
Raisonance RLink JTAG Programmer        no
Olimex ARM-JTAG-EW Programmer           no
CMSIS-DAP Compliant Debugger            yes
Cypress KitProg Programmer              yes (auto)
Altera USB-Blaster Compatible           no
ASIX Presto Adapter                     no
OpenJTAG Adapter                        no
SEGGER J-Link Programmer                yes (auto)

$ make

$ sudo make install

$ which openocd
/usr/local/bin/openocd

Note that in the configure step above, we added cmsis-dap because this is the adapter we use when interfacing with the K20 on the FRDM-K22 board. However, we won't be using it in this article. In fact, we'll take steps to disconnect the K20 from the K22 below.

Connect the Mini-module to the FRDM-K22

Shown below is a picture of our Mini-module connected to the FRDM-K22 on our lab bench.

Figure 1. Mini-module connected to FRDM-K22
mini module conntected to FRDM-K22 board

We need to disconnect the K20 from the K22 on the FRDM-K22. Note that before doing this, we flashed the K22 using Kinetis Design Studio to configure the JTAG I/O as dedicated JTAG pins. We also removed the RGB LED (D14) and current limiting resistors (R91:R93). Neither of these latter two steps may have been necessary.

  • Remove J10 jumper (SWD_CLK_TGTMCU)
  • Remove J13 jumper (SWD_DIO_TGTMCU)
  • Move J9 jumper from 1-2 to 2-3, so we can independtly use SW1 to reset the K22

Inter-board Connections*

MM Pin # MM Pin Name MM JTAG Function FRDM-K22 I/O FRDM-K22 I/O Name
CN2-7 AD0 TCK J10.1 SWD_CLK_TGTMCU
CN2-10 AD1 TDI J2.4 PTA1
CN2-9 AD2 TDO J1.8 PTA2
CN2-12 AD3 TMS J13.1 SWD_DIO_TGTMCU
CN2-2 GND - J25-14 GND

*Connection Notes:

  • Power (3.3V) is not connected between the target board and Mini-module.
  • For our testing, we powered the FRDM-K22 board via USB connector J5. There are multiple ways to power the board (see the FRDM-K22 documentation).
  • Additional intra-board connections for the Mini-module follow FTDI's USB-bus powered guidelines in the Mini-module datasheet:
    • CN3-1 is connected to CN3-3, which connects USB power to FTDI voltage regulator input.
    • CN2-1 is connected to CN2-11, which ties V3V3 to VIO on FTDI device.

Test OpenOCD with our System

Before we can sucessfully connect to our FTDI mini-module with Ubuntu Linux, we need to properly configure permissions so we don't have to run as root. Note that we are using the Mini-module as shipped by FTDI. In other words, it still has the default vendor and product ID.

Add the following to /etc/udev/rules.d/usb.rules and then restart udev:

ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", GROUP="usb"
$ sudo service udev restart

Now, we're ready to connect our target system with OpenOCD. Run the following from our openocd source directory:

$ openocd -f tcl/interface/ftdi/minimodule.cfg -f tcl/target/kx.cfg

Open On-Chip Debugger 0.10.0+dev-00198-g0e02fe4 (2017-10-16-19:32)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Info : add flash_bank kinetis kx.pflash
adapter speed: 1000 kHz
none separate
cortex_m reset_config sysresetreq
Info : clock speed 1000 kHz
Info : JTAG tap: kx.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Info : kx.cpu: hardware has 6 breakpoints, 4 watchpoints

As you can see above, we have now connected to our K22 via the FTDI Mini-module using JTAG!

Next, we'll create an example project using Kinetis Design Studio (KDS). In our case, we verified operation using the i2c polling example in SDK2. Note that we no longer have the I/O facility provided by the CMSIS-DAP K20 debugger, so we will verify proper operation using breakpoints. The creation of an example project is outside the scope of this article, so please refer to the NXP Kinetis SDK documentation for instructions on how to do this if needed.

Before testing our I2C example project with KDS, we create a debug configuration that makes use of our OpenOCD target that we previously started. Refer to the dialog box below:

Figure 2. KDS Debug Configuration
debug configuration

After we click "Debug" in the dialog box, we see the following output in our OpenOCD shell and our KDS debugger breaks at the first line in our main() routine.

Info : accepting 'gdb' connection on tcp/3333
Info : Kinetis MK22FN512xxx12 detected: 2 flash blocks
Info : 2 PFlash banks: 512k total
undefined debug reason 7 - target needs reset
Info : JTAG tap: kx.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Info : MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x000004d8 msp: 0x20010000
Info : Disabling Kinetis watchdog (initial WDOG_STCTRLH = 0x01d3)
Info : WDOG_STCTRLH = 0x01d2
semihosting is enabled
Info : JTAG tap: kx.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Info : MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x000004d8 msp: 0x20010000, semihosting
Info : Disabling Kinetis watchdog (initial WDOG_STCTRLH = 0x01d3)
Info : WDOG_STCTRLH = 0x01d2
Info : This device supports Program Longword execution only.
Info : This device supports Program Longword execution only.
Warn : Flash Configuration Field written.
Warn : Reset or power off the device to make settings effective.
Info : This device supports Program Longword execution only.
Info : JTAG tap: kx.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Info : MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x000004d8 msp: 0x20010000, semihosting
Info : JTAG tap: kx.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Info : MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x000004d8 msp: 0x20010000, semihosting
===== arm v7m registers
(0) r0 (/32): 0x00000000
(1) r1 (/32): 0x00000000
(2) r2 (/32): 0x00000000
(3) r3 (/32): 0x00000000
(4) r4 (/32): 0x00000000
(5) r5 (/32): 0x00000000
(6) r6 (/32): 0x00000000
(7) r7 (/32): 0x00000000
(8) r8 (/32): 0x00000000
(9) r9 (/32): 0x00000000
(10) r10 (/32): 0x00000000
(11) r11 (/32): 0x00000000
(12) r12 (/32): 0x00000000
(13) sp (/32): 0x20010000
(14) lr (/32): 0xFFFFFFFF
(15) pc (/32): 0x000004D8
(16) xPSR (/32): 0x01000000
(17) msp (/32): 0x20010000
(18) psp (/32): 0x00000000
(19) primask (/1): 0x00
(20) basepri (/8): 0x00
(21) faultmask (/1): 0x00
(22) control (/2): 0x00
(23) d0 (/64): 0x0000000000000000
(24) d1 (/64): 0x0000000000000000
(25) d2 (/64): 0x0000000000000000
(26) d3 (/64): 0x0000000000000000
(27) d4 (/64): 0x0000000000000000
(28) d5 (/64): 0x0000000000000000
(29) d6 (/64): 0x0000000000000000
(30) d7 (/64): 0x0000000000000000
(31) d8 (/64): 0x0000000000000000
(32) d9 (/64): 0x0000000000000000
(33) d10 (/64): 0x0000000000000000
(34) d11 (/64): 0x0000000000000000
(35) d12 (/64): 0x0000000000000000
(36) d13 (/64): 0x0000000000000000
(37) d14 (/64): 0x0000000000000000
(38) d15 (/64): 0x0000000000000000
(39) fpscr (/32): 0x00000000
===== Cortex-M DWT registers
(40) dwt_ctrl (/32)
(41) dwt_cyccnt (/32)
(42) dwt_0_comp (/32)
(43) dwt_0_mask (/4)
(44) dwt_0_function (/32)
(45) dwt_1_comp (/32)
(46) dwt_1_mask (/4)
(47) dwt_1_function (/32)
(48) dwt_2_comp (/32)
(49) dwt_2_mask (/4)
(50) dwt_2_function (/32)
(51) dwt_3_comp (/32)
(52) dwt_3_mask (/4)
(53) dwt_3_function (/32)

Summary

As of the last update of this article, we continue testing and verifying operation. We found that we can program internal FLAS, set breakpoints, view memory & registers, and step through code easily using OpenOCD and our FTDI-based JTAG debugger. We'll continue to update this page as we continue to test this OpenOCD functionality with the FTDI FT2232H.

Please help us improve this article by adding your comment or question:

email addresses are neither displayed nor shared