Flashing LM4F with TI ICDI

Has anyone tried to flash a TI LM4F device (specifically I am using an EK-LM4F232 board) using OpenOCD and the TI ICDI interface? When I try it I get the following:

Open On-Chip Debugger 0.7.0-dev-00145-gd631b2e (2013-01-23-09:38)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.sourceforge.net/doc/doxygen/bugs.html
adapter speed: 1000 kHz
Info : clock speed 1000 kHz
Info : ICDI Firmware version: 8790
Info : lmf423x.cpu: hardware has 6 breakpoints, 4 watchpoints
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00000642 msp: 0x20001418
auto erase enabled
Error: timed out while waiting for target halted
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x61000000 pc: 0x20000016 msp: 0x20001418
Error: error waiting for target flash write algorithm

…and I end up needing the ^C to get out. Below is my OpenOCD configuration/command file:

source [find interface/ti-icdi.cfg]
set WORKAREASIZE 0x8000
set CHIPNAME lmf423x
source [find target/stellaris_icdi.cfg]
gdb_port 3332
init
reset halt
flash write_image erase firmware.bin 0
reset
exit

Hello again,

Can you post a full debug log?

For info that board has a proper cfg, eg.

source [find board/ek-lm4f232.cfg]

Cheers

Spen

Thanks, I have updated my OpenOCD script as follow (flash.cfg):

source [find board/ek-lm4f232.cfg]
gdb_port 3332
init
reset halt
flash write_image erase D:/Projects/Stryker/MoonRacer/SW/AuxBus/GIT/template/factory.bin 0
reset
exit

I have attached the debug log output from running this script with the following command:

$ openocd.exe --debug --log_output flash.log -f flash.cfg 

For some reason the flash loader does not appear to be working as expected - i cannot reproduce here though.

The loader is common among all stellaris targets. After failing it is then dropping through to the much slower memory writes.

Do you get the same behaviour if you use the elf to program ?

If you do can you send me a copy of the failing elf or binary.

Sometimes it is easier to split the erase, as it can make debugging issues easier.

flash erase_sector lm4f23x.flash 0 last
flash write_image firmware.bin

For info to quit OpenOCD in your script use ‘shutdown’ not ‘exit’.

Cheers

Spen

Thanks for the information Spen. I have updated my OpenOCD command/configuration files to the following…

erase.cfg:

source [find board/ek-lm4f232.cfg]
init
reset halt
flash erase_sector lm4f23x.flash 0 last
shutdown

flash.cfg:

source [find board/ek-lm4f232.cfg]
init
reset halt
flash write_image FIRMWARE.bin 0 bin
shutdown

I can’t provide the binary that I am using, but what I can tell you is that it DOES WORK if the binary is less than 128k (or, at least I tested up to 127k). At 128k flashing starts to fail. The binary I WAS working with is 152k in size. This device has 256k flash and when I run ‘flash info 0’ I do get 256 flash pages, each 1k in size.

I will try and create a large test binary and see if that fails.

Spen

For actual testing, to determine what size files I could flash, I simply created binary files that where completely zeroed out but of the specified size. I used a simple little Python function:

def gen_file(sz):
    with open('zero-{0}k.bin'.format(sz), 'w') as f:
        f.write('\x00' * 1024 * sz)

With the above function, simply execute gen_file(1) to create a file called ‘zero-1k.bin’ that is 1kbytes in size that is completely zeroed out.

I can reproduce here, very strange.

My original test binary was 256k and that works fine however if I reduce the count by 4 bytes it fails :slight_smile:

I can only think the issue is related to the icdi, if I use another adapter with the same target it works OK.

Need to try a few other things tomorrow before I blame the icdi.

Cheers

Spen

I just tried the 128k binary which failed using OpenOCD with the LM Flash utility from TI and that worked fine.

I pretty much know what is causing the problem, i have emailed my contact at TI to see if he can clarify it.

Will keep you posted.

Cheers

Spen

Thanks so much for your continued effort on this Spen.

ok i have pushed a fix to our review system - http://openocd.zylin.com/1124

If you are able to test that would be great.

Cheers

Spen

Terrific! Looks like it works. Thank you for the fix.