I got this eval board from freescale: TWR-K20D72M because I like the features of the K20 - especially the built-in 2-channel 16-bit ADC.
I’m using a bleeding edge version of openocd:
0.7.0-dev-00228-g2cb4862-dirty (2013-04-17-21:23)
I tried release 0.6.1 but I couldn’t get past opening osbdm device with that.
I’m on a mac (64-bit x86 Lion) and I use macports to install all the dependencies, mainly just libusb I think.
Here’s the configure command I used to build:
env CC=gcc CPPFLAGS="-I/opt/local/include" LDFLAGS="-L/opt/local/lib" ./configure --enable-osbdm --enable-maintainer-mode
I had to add entries in the osdbm.c for the vendor ID and product ID for the USB device on the eval board. Here are the lines with the entries added:
/* Lists of valid VID/PID pairs
*/
static const uint16_t osbdm_vid[] = { 0x15a2, 0x15a2, 0x15a2, 0 };
static const uint16_t osbdm_pid[] = { 0x0042, 0x0058, 0x005e, 0 };
Once I did that, it looks like it is mostly working, but it gives me an error when I try to load my program.
Here is the .cfg file I use (all combined into one for debugging):
#source [find interface/osbdm.cfg]
#
# P&E Micro OSBDM (aka OSJTAG) interface
#
# http://pemicro.com/osbdm/
#
interface osbdm
reset_config srst_only
#source [find board/twr-k20d72m.cfg]
#
# Freescale TWR-K20D72M development board
#
#source [find target/k20.cfg]
#
# Freescale Kinetis K20 devices
#
#
# K20 devices support both JTAG and SWD transports.
#
source [find target/swj-dp.tcl]
if { [info exists CHIPNAME] } {
set _CHIPNAME $CHIPNAME
} else {
set _CHIPNAME k20
}
if { [info exists ENDIAN] } {
set _ENDIAN $ENDIAN
} else {
set _ENDIAN little
}
if { [info exists CPUTAPID] } {
set _CPUTAPID $CPUTAPID
} else {
set _CPUTAPID 0x4ba00477
}
set _TARGETNAME $_CHIPNAME.cpu
swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
target create $_TARGETNAME cortex_m3 -chain-position $_CHIPNAME.cpu
$_CHIPNAME.cpu configure -event examine-start { puts "START..." ; }
$_CHIPNAME.cpu configure -event examine-end { puts "END..." ; }
# if srst is not fitted use SYSRESETREQ to
# perform a soft reset
cortex_m3 reset_config sysresetreq
$_TARGETNAME configure -event reset-init {
puts "-event reset-init occured"
}
proc my_attach_proc { } {
echo "Reset..."
reset halt
}
$_TARGETNAME configure -event gdb-attach my_attach_proc
$_TARGETNAME configure -event gdb-attach {
echo "Reset..."
# To make flash probe and gdb load to flash work we need a reset init.
reset init
}
# 32K SRAM for work area
$_TARGETNAME configure -work-area-phys 0x1fff8000 -work-area-size 0x8000
#
# Bank definition for the 'program flash' (instructions and/or data)
#
# flash bank name driver base size chip_width bus_width target
flash bank pflash.0 kinetis 0x00000000 0x40000 0 4 $_TARGETNAME
scan_chain
gdb_memory_map disable
Problems I see:
- Sometimes before I enter any debug commands, openocd repeats the following:
Polling target k20.cpu succeeded again
Error: JTAG-DP STICKY ERROR
Error: MEM_AP_CSW 0x23000042, MEM_AP_TAR 0xe000edf0
Polling target k20.cpu failed, GDB will be halted. Polling again in 100ms
Polling target k20.cpu succeeded again
- Sometimes I can program flash and sometimes not. Tried to reproduce some errors for this post and of course it worked! So, here’s what it looks like when it seems to work:
Open On-Chip Debugger
> program /Users/roger/Dev/kinetis/getting_started/Debug/getting_started
JTAG tap: k20.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
** Programming Started **
auto erase enabled
Probing flash info for bank 0
Padding image section 0 with 1988 bytes
wrote 4096 bytes from file /Users/roger/Dev/kinetis/getting_started/Debug/getting_started in 21.725399s (0.184 KiB/s)
** Programming Finished **
shutdown command invoked
> Connection closed by foreign host.
- Then when I try to load it to debug it, it has never worked. Here’s the output of openocd:
Open On-Chip Debugger 0.7.0-dev-00228-g2cb4862-dirty (2013-04-17-21:23)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst
cortex_m3 reset_config sysresetreq
Info : add flash_bank kinetis pflash.0
TapName Enabled IdCode Expected IrLen IrCap IrMask
-- ------------------- -------- ---------- ---------- ----- ----- ------
0 k20.cpu Y 0x00000000 0x4ba00477 4 0x01 0x0f
Info : OSBDM has opened
Info : This adapter doesn't support configurable speed
Info : JTAG tap: k20.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
START...
Info : k20.cpu: hardware has 6 breakpoints, 4 watchpoints
END...
Info : accepting 'gdb' connection from 3333
Reset...
Info : JTAG tap: k20.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
START...
END...
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
-event reset-init occured
Warn : acknowledgment received, but no packet pending
Error: address + size wrapped(0xfffffffe, 0x00000004)
Error: JTAG-DP STICKY ERROR
Error: MEM_AP_CSW 0x23000052, MEM_AP_TAR 0x4
Error: JTAG-DP STICKY ERROR
Error: MEM_AP_CSW 0x23000052, MEM_AP_TAR 0x4
Warn : Block write error address 0x0, wcount 0xf
Error: JTAG-DP STICKY ERROR
Error: MEM_AP_CSW 0x23000052, MEM_AP_TAR 0x804
Error: JTAG-DP STICKY ERROR
Error: MEM_AP_CSW 0x23000052, MEM_AP_TAR 0x804
Warn : Block write error address 0x800, wcount 0x192
Info : dropped 'gdb' connection
All that to say… does anyone know how to decode those register values MEM_AP_CSW and TAR to try to figure out what is wrong?
Please help me get this new target supported by openocd so I don’t have to admit defeat.
Thanks,
Roger