Kinetis K20 support in OpenOCD

Hi everyone,

I’m trying to get OpenOCD and GDB working with a K20-based dev board (TWR-K20D50M) from freescale. The board uses a P&E Micro USB debug interface, which I believe is supported in OpenOCD (using interface/osbdm.cfg).

Here is the openocd.cfg file I’m using:


source [find interface/osbdm.cfg]

gdb_memory_map disable

gdb_flash_program enable

source [find board/twr-k60f120m.cfg]


I seem to be able to examine memory using GDBs x command, but when I try and load a binary I always get “Load failed”.

Has anyone had success with this chip?

Thanks!

Marlon

When you say load a binary do you mean using the gdb load cmd?

To use that feature you will need to make sure the following are enabled, which is the default anyway.

gdb_memory_map enable

gdb_flash_program enable

Spen

Thanks ntfreak, that got me one step further. Now when I attempt a load with gdb, I get these errors in my openOCD terminal:

Warn : flash configuration field erased, please reset the device

Error: gdb requested a non-existing register

Info : dropped ‘gdb’ connection

I think it could be the way I’m defining the flash banks in openOCD; I really don’t know what I’m doing in that area.

flash bank pflash.0 kinetis 0x00000000 0x40000 0 4 $_TARGETNAME

flash bank pflash.1 kinetis 0x00040000 0x40000 0 4 $_TARGETNAME

flash bank pflash.2 kinetis 0x00080000 0x40000 0 4 $_TARGETNAME

flash bank pflash.3 kinetis 0x000c0000 0x40000 0 4 $_TARGETNAME

If I include just the first two lines, I get the error I mentioned above. If I use all four lines, I get another error from openOCD before I can even attempt a load:

Info : Probing flash info for bank 0

Info : Probing flash info for bank 1

Info : Probing flash info for bank 2

Error: FlexRAM support not yet implemented

Error: auto_probe failed

Can anyone point me in the right direction to fix this problem?

Thanks!

Marlon

Looking through my chip’s datasheet, I think there is just one bank of 128Kb of flash. I changed the configuration in openOCD so that there’s just one bank like this:

flash bank pflash.0 kinetis 0x00000000 0x20000 0 4 $_TARGETNAME

And I can erase the flash using:

monitor flash erase_address 0x0 0x20000

But still when I attempt to load my .elf file I get:

target halted due to debug-request, current mode: Thread

xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc

Warn : flash configuration field erased, please reset the device

Error: gdb requested a non-existing register

Info : dropped ‘gdb’ connection

And if I examine the memory using gdb it’s all set to 0xff.

I got it working! Apparently using arm-eabi-gdb instead of just gdb made the difference.

That would help quite a bit :slight_smile:

Ok so I’ve got it sort of working, but it’s very flaky and I can’t seem to get my code to run properly.

I get tons of these errors from OpenOCD:

Error: JTAG-DP STICKY ERROR

Error: MEM_AP_CSW 0x23000042, MEM_AP_TAR 0xe000edf0

Polling target failed, GDB will be halted. Polling again in 300ms

Do you guys have any thoughts on that? I’ve been spending a lot of time trying to get this going…

Thanks

Marlon

Firstly try slowing down the JTAG speed.

Looking in osbdm.cfg, it seems like the JTAG speed can’t be controlled…

Ah, seems the interface has no support for changing the speed :frowning:

Afraid not sure what to suggest as I have never used the osbdm before.

Perhaps worth sending an email to the OpenOCD mailing list.

Spen

Thanks for the help so far guys, I really appreciate it. I’m getting a new error now when I try to load code with gdb:

Error: ftfx command failed FSTAT: 00 W0: 0B003000 W1: 01000000 W2: 00000000

Error: error writing to flash at address 0x00000000 at offset 0x00003000

Any idea what could be causing that?

(In case anyone was wondering, my previous problem was caused by the security bits being set incorrectly in the K20’s flash).