# Unable to program STM32F1x with OpenOCD/ST-link

**URL:** <https://community.sparkfun.com/t/unable-to-program-stm32f1x-with-openocd-st-link/28060>\
**Category:** MicroMod\
**Tags:** arm-lpc\
**Created:** [January 9, 2014, 12:32pm UTC](https://community.sparkfun.com/t/unable-to-program-stm32f1x-with-openocd-st-link/28060 "2014-01-09T12:32:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evert](https://avatars.discourse-cdn.com/v4/letter/e/e99b99/32.png) [@Evert](https://community.sparkfun.com/u/Evert)\
**Post date:** [January 9, 2014, 12:32pm UTC](https://community.sparkfun.com/t/unable-to-program-stm32f1x-with-openocd-st-link/28060/1 "2014-01-09T12:32:45Z")

</div>

Hello,

I like to program my STM32F103 with the ST-link/V2 device by using openOCD.

However I got next message:

Error: flash write failed at address 0x80016f8

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

By using the ST-link Utility, it works fine with the same programmer.

I am using the stm32f1x\_stlink.cfg target script and next openocd script for writing:

I call this script from my makefile (IMGFILE is my binary)

roc stm\_flash {IMGFILE} {

reset halt

sleep 10

wait\_halt 2

flash write\_image erase $IMGFILE 0x08008000

sleep 10

verify\_image $IMGFILE 0x08008000

sleep 10

reset run

}

Does anyone has an idea what is going on?

Regards Evert Huijben

Here is the complete logging:

make program

Open On-Chip Debugger 0.6.1 (2014-01-08-11:14)

Licensed under GNU GPL v2

For bug reports, read

[http://openocd.sourceforge.net/doc/doxygen/bugs.html](http://openocd.sourceforge.net/doc/doxygen/bugs.html)

adapter speed: 1000 kHz

srst\_only separate srst\_nogate srst\_open\_drain

Info : clock speed 1000 kHz

Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints

stm\_erase

target state: halted

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

xPSR: 0x01000000 pc: 0x08000160 msp: 0x20000400

auto erase enabled

Info : device id = 0x20036410

Info : flash size = 128kbytes

Error: flash write algorithm aborted by target

target state: halted

target halted due to breakpoint, current mode: Thread

xPSR: 0x01000000 pc: 0x08000160 msp: 0x20000400

Error: flash write failed at address 0x80016f8

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

Runtime Error: /home/evert/sandbox/multi\_IO/projects/chibiOs/make/…/…/…/boards/multiIo/stm32f1-openocd.cfg:12:

in procedure ‘stm\_flash’

in procedure ‘flash’ called at file “/home/evert/sandbox/multi\_IO/projects/chibiOs/make/…/…/…/boards/multiIo/stm32f1-openocd.cfg”, line 12

make: Nothing to be done for `program’.
