Stlink: STM32F103 won't flash

Created on 25 Jan 2017  ·  11Comments  ·  Source: stlink-org/stlink

Hello,

i'm trying to flash an STM32F103 Board via SWD with an STM32F407 Discovery Board. Unfortunately it does not work only with STM32F103 Board.

  • [x] Programmer/board type: Stlink/v2
  • [x] Operating system: Mac OS X
  • [x] Stlink tools version stlink: stable 1.2.0 (bottled), HEAD, Poured from bottle on 2015-10-04
  • [x] Stlink commandline tool name: st-flash
  • [x] Target chip (and optional board): e.g STM32F103C

Output:

st-flash write prog.bin 0x8000000
2017-01-24T18:44:14 INFO src/stlink-common.c: Loading device parameters....
2017-01-24T18:44:14 INFO src/stlink-common.c: Device connected is: F1 High-density device, id 0x10036414
2017-01-24T18:44:14 INFO src/stlink-common.c: SRAM size: 0x10000 bytes (64 KiB), Flash: 0 bytes (0 KiB) in pages of 2048 bytes

As you can see, it gives out something unexpected like
Flash: 0 bytes (0 KiB) in pages of 2048 bytes

st-info --probe
Found 1 stlink programmers
 serial: 303030303030303030303031
openocd: "\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x31"
  flash: 0 (pagesize: 2048)
   sram: 65536
 chipid: 0x0414
  descr: F1 High-density device

Does anyone know how to solve it.
Thank you in advance.

generadocumention omacOS programmestlinkv2 staturesolved targestm32f1

Most helpful comment

Hi , I had success unlocking stm32 bluepills using the following commands on openocd terminal session:

reset halt
flash banks
stm32f1x mass_erase 0
stm32f1x unlock 0

After that, the device was ready to be programmed again.

All 11 comments

Solved with ST Link Utility.

the board was _write protected_

Thanks for your report, I think I will add this to the docs so other people will not fail with this.

Hi, can you help me on that? How can I disable the write protection? I am using Mac OSX. The official St-link utility tool is for windows only, right?

You probably could mass erase first and I thought write protection is cleared then. Or with some openocd commands (it has more features then texane/stlink).

Thank you for your rapid answer. I've tried erasing the flash, it worked. However, the issue remains. I will try to use some windows computer to see what happen. :\

Have you seen this in the README?
https://github.com/texane/stlink/commit/0f9e4990ba0cdc295875b219b354fdf42f30a9aa

When using OpenOCD you could probably invoke monitor stm32f1x unlock 0 commands (untested). See http://openocd.org/doc/html/Flash-Commands.html.

I've run the ST-LINK Utility (on windows) and I went to Target > Option Bytes... > Disable Read Out Protection (combo box). Done, issue solved.

I could find clue on disabling the Read Out Protection using openOCD following this link: http://www.openstm32.org/forumthread562. I am using the Blue Pill Stm32F103c8t6 a Chinese board. It is just necessary to add the "monitor flash protect 0 0 11 off" line to the init script of openOCD. [Untested]

Hi , I had success unlocking stm32 bluepills using the following commands on openocd terminal session:

reset halt
flash banks
stm32f1x mass_erase 0
stm32f1x unlock 0

After that, the device was ready to be programmed again.

@jeroavf Thanks! This worked for me and --probe now returns 65536 (looks like I got one of the few 64kb models) as well as flashing correctly.

Fun bit, when doing the mass_erase step it even thinks it is 128kb, but nevermind.

STM32 flash size failed, probe inaccurate - assuming 128k flash
flash size = 128kbytes

Thanks, I was able to unbrick some STM32F437 with a full chip erase with the windows ST-Link utility, now this is working again on linux st-link :-)

Was this page helpful?
0 / 5 - 0 ratings