# openOCD flash write\_image error(-304)

**URL:** <https://community.sparkfun.com/t/openocd-flash-write-image-error-304/21067>\
**Category:** MicroMod\
**Tags:** arm-lpc\
**Created:** [June 22, 2011, 9:10am UTC](https://community.sparkfun.com/t/openocd-flash-write-image-error-304/21067 "2011-06-22T09:10:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kamil51](https://avatars.discourse-cdn.com/v4/letter/k/8491ac/32.png) [@kamil51](https://community.sparkfun.com/u/kamil51)\
**Post date:** [June 22, 2011, 9:10am UTC](https://community.sparkfun.com/t/openocd-flash-write-image-error-304/21067/1 "2011-06-22T09:10:49Z")

</div>

Hello all,

I am using openOCD 0.4.0. The things that I have is below;

Eclipse IDE,(helios)

A lpc2148 cpu board(uni-ds3 board from mikroelektronika),

ARM-USB-OCD (Olimex) JTAG dongle

all the steps like this;

1- First of all the board can be programmed by using openOCD4.0 with the eclipse.

2- And everythins are ok.

3- When the Hex code transferred to the board again, im getting following error from the console in eclipse.

* * *

Open On-Chip Debugger 0.4.0 (2010-02-22-19:05)

Licensed under GNU GPL v2

For bug reports, read

[http://openocd.berlios.de/doc/doxygen/bugs.html](http://openocd.berlios.de/doc/doxygen/bugs.html)

500 kHz

RCLK - adaptive

jtag\_nsrst\_delay: 200

jtag\_ntrst\_delay: 200

trst\_and\_srst srst\_pulls\_trst srst\_gates\_jtag trst\_push\_pull srst\_open\_drain

Info : RCLK (adaptive clock speed) not supported - fallback to 500 kHz

Error: JTAG scan chain interrogation failed: all ones

Error: Check JTAG interface, timings, target power, etc.

error: -100

* * *

And the board can not be programmed again…

If i use openOCD + Telnet ,i am getting error again below;

* * *

Open On-Chip Debugger

> init

> reset

JTAG scan chain interrogation failed: all ones

Check JTAG interface, timings, target power, etc.

error: -100

Command handler execution failed

in procedure ‘reset’ called at file “command.c”, line 650

called at file “command.c”, line 361

> flash protect 0 0 0 off

cleared protection for sectors 0 through 0 on flash bank 0

> flash banks

#0: lpc2000 at 0x00000000, size 0x0007d000, buswidth 0, chipwidth 0

> flash erase\_sector 0 0 0

Target not halted

failed erasing sectors 0 to 0 (-304)

> flash write\_image main.hex 0 ihex

Target not halted

error writing to flash at address 0x00000000 at offset 0x00000000 (-304)

Command handler execution failed

in procedure ‘flash’ called at file “command.c”, line 650

called at file “command.c”, line 361

* * *

The config file is below;

* * *

# 

# Olimex ARM-USB-OCD

# 

# [http://www.olimex.com/dev/arm-usb-ocd.html](http://www.olimex.com/dev/arm-usb-ocd.html)

# 

interface ft2232

ft2232\_device\_desc “Olimex OpenOCD JTAG”

ft2232\_layout olimex-jtag

ft2232\_vid\_pid 0x15ba 0x0003

#daemon configuration

telnet\_port 4444

gdb\_port 3333

# jtag speed

jtag\_khz 500

# Use RCLK. If RCLK is not available fall back to 500kHz.

# 

# Depending on cabling you might be able to eek this up to 2000kHz.

jtag\_rclk 500

if { [info exists CHIPNAME] } {

set \_CHIPNAME $CHIPNAME

} else {

set \_CHIPNAME lpc2148

}

if { [info exists ENDIAN] } {

set \_ENDIAN $ENDIAN

} else {

set \_ENDIAN little

}

if { [info exists CPUTAPID] } {

set \_CPUTAPID $CPUTAPID

} else {

set \_CPUTAPID 0x4f1f0f0f

}

jtag\_nsrst\_delay 200

jtag\_ntrst\_delay 200

# NOTE!!! LPCs need reset pulled while RTCK is low. 0 to activate

# JTAG, power-on reset is not enough, i.e. you need to perform a

# reset before being able to talk to the LPC2148, attach is not possible.

reset\_config trst\_and\_srst srst\_pulls\_trst

jtag newtap $\_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $\_CPUTAPID

set \_TARGETNAME $\_CHIPNAME.cpu

target create $\_TARGETNAME arm7tdmi -endian $\_ENDIAN -chain-position $\_TARGETNAME -variant arm7tdmi-s\_r4

$\_TARGETNAME configure -work-area-phys 0x40000000 -work-area-size 0x4000 -work-area-backup 0

$\_TARGETNAME configure -event reset-init {

# Force target into ARM state

arm core\_state arm

# Do not remap 0x0000-0x0020 to anything but the flash (i.e. select

# “User Flash Mode” where interrupt vectors are _not_ remapped,

# and reside in flash instead).

# 

# See section 7.1 on page 32 (“Memory Mapping control register”) in

# “UM10139: Volume 1: LPC214x User Manual”, Rev. 02 – 25 July 2006.

# [http://www.standardics.nxp.com/support/ … pc2148.pdf](http://www.standardics.nxp.com/support/documents/microcontrollers/pdf/user.manual.lpc2141.lpc2142.lpc2144.lpc2146.lpc2148.pdf)

mwb 0xE01FC040 0x01

# disable watchdog

# mww 0xfffffd44 0x00008000

# enable user reset

# mww 0xfffffd08 0xa5000001

# CKGR\_MOR : enable the main oscillator

# mww 0xfffffc20 0x00000601

# sleep 10

# CKGR\_PLLR: 96.1097 MHz

# mww 0xfffffc2c 0x00481c0e

# sleep 10

# PMC\_MCKR : MCK = PLL / 2 ~= 48 MHz

# mww 0xfffffc30 0x00000007

# sleep 10

# MC\_FMR: flash mode (FWS=1,FMCN=60)

# mww 0xffffff60 0x003c0100

# sleep 100

}

#flash config komutu

# flash bank lpc2000 0 0 \<target#\> [calc\_checksum]

set \_FLASHNAME $\_CHIPNAME.flash

flash bank $\_FLASHNAME lpc2000 0x0 0x7d000 0 0 $\_TARGETNAME lpc2000\_v2 12000 calc\_checksum

init\_reset halt

# write file to flash memory

arm7\_9 dcc\_downloads enable

sleep 10

#start execution of the program just downladed

#reset run

#sleep 10

init

reset halt

#flash write\_image

flash write\_image erase unlock main.hex 0x0 ihex

sleep 10

#exit OpenOCD

shutdown

* * *

Where is the mistake??

Best Regards

kamil
