SparkFun Forums 

Where electronics enthusiasts find answers.

Open source ARM Debugger
By champro
#162816
Hi,

After some initial struggling I managed to get OpenOCD 0.6.1 (and now upgraded to 0.7) running on OSX and programming my custom Freescale k20 based boards using JTAG and a bus blaster. On a fresh chip I would have to take the reset pin to GND to be able to halt the chip, but after the initial erase everything worked very well. I could halt the chip and flash program fine after that. I'm using .elf files compiled out of the teensy 3.0 variant of arduino since its the same chip.

Now I've added in the EEPROM library which uses the FlexRAM on the k20 chip to emulate EEPROM and while the code works fine, whenever I go to flash fresh code on I get a fault partway through the write. Then the chip is unresponsive and I have to again take the Reset pin low to halt it, so I can get code on once more. Its obviously killing my workflow.

I'm pretty sure the problem is with openOCD trying to write fresh code into the FlexRAM, but the Flex is either protected or the partition bit that says whether the flex is program memory vs. eeprom is causing issues. I know the teensy itself issues the chip's flash controller's "Erase All Blocks" (command 0x44) when it writes fresh code. Ideally I could get openOCD to do this or to otherwise overwrite everything so that fresh code would go on fine. Here is the log of a successful flash write and then a bad one after trying to write to a chip that is configured to use EEPROM

> flash write_image erase programs/PX2_077.cpp.elf 0 elf
auto erase enabled
flash configuration field erased, please reset the device
wrote 35840 bytes from file programs/PX2_077.cpp.elf in 3.216008s (10.883 KiB/s)

Then a bad write:

> flash write_image erase programs/PX2_077a.cpp.elf 0 elf
auto erase enabled
flash configuration field erased, please reset the device
JTAG-DP STICKY ERROR
MEM_AP_CSW 0x23000052, MEM_AP_TAR 0x14000018
JTAG-DP STICKY ERROR
MEM_AP_CSW 0x23000052, MEM_AP_TAR 0x1400001c
Block write error address 0x14000000, wcount 0x100
target_write_memory failed
error writing to flash at address 0x00000000 at offset 0x00000000
in procedure 'flash'


FlashRam starts at 0x14000000, anyone who can shed some light on this, it would be greatly appreciated.
By champro
#162830
I'll fire this over to the mailing list today. As a side note is there a way to use the chip specific commands that are in the kinetis.c file

These flash commander commands are defined

-#define FTFx_CMD_BLOCKSTAT 0x00
-#define FTFx_CMD_SECTSTAT 0x01
-#define FTFx_CMD_LWORDPROG 0x06
-#define FTFx_CMD_SECTERASE 0x09
-#define FTFx_CMD_SECTWRITE 0x0b
+#define FTFx_CMD_BLOCKSTAT 0x00
+#define FTFx_CMD_SECTSTAT 0x01
+#define FTFx_CMD_LWORDPROG 0x06
+#define FTFx_CMD_SECTERASE 0x09
+#define FTFx_CMD_SECTWRITE 0x0b
#define FTFx_CMD_SETFLEXRAM 0x81
+#define FTFx_CMD_MASSERASE 0x44

can they be called from the openocd command line somehow? maybe "kinetis_mass_erase"
By champro
#162835
Yea, I just spent the last hour or so trying to figure the best way to get that patch into my current openOCD install. Have to say my terminal package building knowledge is woefully incomplete. I installed using macports which is pretty simple, but then leaves me a little lost when trying to add the patch in. Any good tutorials or readme files for patching a current install or rebuilding to incorporate a patch in osx.
User avatar
By ntfreak
#162836
The patch guidelines give you the flow:
http://openocd.sourceforge.net/doc/doxy ... guide.html
Code: Select all
# checkout code from OpenOCD master branch
git clone git://git.code.sf.net/p/openocd/code openocd

# apply patch, this info is given on the gerrit page for the patch.
git fetch http://openocd.zylin.com/openocd refs/changes/08/1508/1 && git checkout FETCH_HEAD

./bootstrap
./configure ...
make
and your done

Cheers
Spen
By priestnot
#191546
I am trying to program a Freescale Kinetis MK20DX128 using a Olimex ARM-USB-OCD-H with Open OCD.
I am on a ubuntu 14.04 system.

I have followed this steps:
Code: Select all
# checkout code from OpenOCD master branch via http mirror
git clone http://repo.or.cz/openocd.git

# apply patch, this info is given on the gerrit page for the patch.
git fetch http://openocd.zylin.com/openocd refs/changes/08/1508/1 && git checkout FETCH_HEAD

./bootstrap
./configure --enable ftdi-ftdi
make
make install
I am using the following command to flash the uC:
Code: Select all
openocd -f openocd.cfg -c "program firmware.hex verify reset"
The openocd.cfg is like this:
Code: Select all
source [find interface/ftdi/olimex-arm-usb-ocd-h.cfg]

# Freescale Kinetis K20 device. Should be compatible with K40,
# just set a custom name.
set CHIPNAME k20
source [find target/k40.cfg]

adapter_khz 1000
reset_config srst_only

# Scratch RAM for verify
# XXX: This verify method is broken due to a problem with reset?
# k20.cpu configure -work-area-phys 0x1FFFE000 -work-area-size 16384

# One 128K flash bank
flash bank pflash.0 kinetis 0x00000000 0x20000 0 4 $_TARGETNAME

But it gives me the following output:
Code: Select all
openocd -f openocd.cfg -c "program fc-boot.hex verify reset"
Open On-Chip Debugger 0.8.0-dev-00079-g650904c (2016-09-05-11:56)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
cortex_m3 reset_config sysresetreq
adapter speed: 1000 kHz
srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst
Info : add flash_bank kinetis pflash.0
Info : clock speed 1000 kHz
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 : 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: 0x000000f8 msp: 0x20001ffc
** Programming Started **
auto erase enabled
Info : Probing flash info for bank 0
Error: ftfx command failed FSTAT: 90 FCCOB: 09000000 00000000 00000000
Warn : erase sector 0 failed
Error: failed erasing sectors 0 to 3
** Programming Failed **
shutdown command invoked
What am I doing wrong?