This document explains how you can debug the FRDM-K22F board with the Segger J-Link OpenSDAv2.1 Firmware and the Kinetis Design Studio V1.1.0.
Applicable to:
The FRDM-K22F board (FRDM-K22F|Freedom Development Board|Kinetis|Freescale) comes with OpenSDAv2.1 programmed on it, and has the CMSIS-DAP debug firmware on it by default.
(see 'Technical Details' at the end about the OpenSDA differences)
OpenOCD with CMSIS-DAP for FRDM-K22F is not supported in KDS V1.1.0. Trying to debug the FRDM-K22F board with KDS V1.1.0 and OpenOCD/CMSIS-DAP results in an error in the Console View and is currently not possible, until OpenSDA gets updated (see Kinetis Design Studio V1.1.0: Release Notes and News).
One solution is to use the Segger J-Link OpenSDAv2.1 firmware to debug the board.
(Another solution is to use the P&E Multilink OpenSDAv2.1 firmware, see FRDM-K22F: Debugging with P&E OpenSDAv2.1 Firmware)
You need to install the Segger J-Link OpenSDAv2.1 firmware on the board, and you only need to do this once (unless you change the firmware again).
Create a new debug/launch configuration: Select your project, then use the menu Run > Debug Configurations.
Use the 'new' Icon to create a new configuration for your application and project (Main tab):
Specify MK22FN512xxx12 as your device name, and make sure 'SWD' is selected:
Have SWO disabled:
That's it. Now you can debug your application with Segger J-Link OpenSDA V2.1 firmware on the board :-).
You can use the 'Debug' button in the launch configuration:
Or use the debug icon drop-down list:
Happy Debugging :-)
There are so far three versions of the OpenSDA available:
The debug circuit on the board is the same for all OpenSDA versions (Kinetis K20 microcontroller): the difference is what bootloader is programmed on the K20: the bootloader on the OpenSDAv1.0 cannot be erased/changed. The bootloader on OpenSDAv2.x can be erased/changed, and the difference between the OpenSDAv2.0 and v2.1 is the address where the debug application starts: for OpenSDAv2.0 it expects the application at address 0x5000, while OpenSDAv2.1 expects the application to start at address 0x8000.
See also: OpenSDAv2
Thanks for your information.
I have compared the differences between V1 and V2 of OpenSDA. I found its hardware is different at following points:
Changes from V1 to V2
Therefore, the biggest difference is control logic of SDA_SWD_EN and SDA_SWD_OE from P16/P20.
Please kindly correct me if I am wrong.
I can find the schematics documents in K22F package at FRDM-K22F|Freedom Development Board|Kinetis|Freescale
The FRDMK22FUG.pdf has part of the schematics. But it isn't complete.
Thanks for the information. I upgraded to Segger J-Link OpenSDAv2.1 Firmware but when the program starts it seems sort of like the base addresses of the program are off. Could KDS with its toolchain be making the executable for the incorrect base address? Is there a setting somewhere I should check? Or is the the code relocatable and this just a loader detail thing?
readelf -h -l mbed_22blinky.elf (output below)
I think this, particularly the .isr_vector being at 0x8000, tells me this elf file is incompatible with OpenSDA 2.1 (should be 0x5000 as I read the original post). Now to find where to tweak that setting. Thinking it might be buried in mbed somewhere since I can't find it in the kds settings anywhere. Will import mbed from source rather than a .o export (would be good to do for other reasons).
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x199
Start of program headers: 52 (bytes into file)
Start of section headers: 142632 (bytes into file)
Flags: 0x5000002, has entry point, Version5 EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 5
Size of section headers: 40 (bytes)
Number of section headers: 22
Section header string table index: 19
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
EXIDX 0x011b80 0x00009b80 0x00009b80 0x00390 0x00390 R 0x4
LOAD 0x008000 0x00000000 0x00000000 0x001f0 0x001f0 R E 0x8000
LOAD 0x008400 0x00000400 0x00000400 0x00010 0x00010 R 0x8000
LOAD 0x008410 0x00000410 0x00000410 0x09b00 0x09b00 R E 0x8000
LOAD 0x018400 0x1fff0400 0x00009f10 0x002c8 0x00cac RW 0x8000
Section to Segment mapping:
Segment Sections...
00 .ARM.exidx
01 .isr_vector
02 .flash_protect
03 .text .ARM.extab .ARM.exidx
04 .data .bss
My bad. My issues were some combination of getting the wrong segger boot loader and not noticing the pin names changed between a FRDM-K64F and FRDM-K22F. Fixed those things and now everything is working.
OpenSDA 2.1 start address is 0x8000 which is reflected in the ELF headers (although I am curious where the build gets this value from).