Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32F1/F4/L0/L4: flash loader run error #607

Closed
dougyeager opened this issue Jun 20, 2017 · 52 comments · Fixed by #1113
Closed

STM32F1/F4/L0/L4: flash loader run error #607

dougyeager opened this issue Jun 20, 2017 · 52 comments · Fixed by #1113

Comments

@dougyeager
Copy link

NOTICE: The issue may be closed without notice when not enough information is provided!

Thank you for giving feedback to the stlink project. Take some time to fill out
check boxes with a X in the following items so developers and other people can try to
to find out what is going on. And add/remove what is appropriate to your problem.

When submitting a feature request, try to reuse the list and add/remove what is appropriate.
Place a X between the brackets [X] to mark the list item.

  • [stlink/v2 ] Programmer/board type: e.g Stlink/v1, Stlink/v2, Stlink/v2-onboard
  • [lastest from ST ] Programmer firmware version: e.g STSW-LINK007 2.27.15
  • [ mac] Operating system: e.g Linux, Mac OS X, Windows (with specific version)
  • [today ] Stlink tools version and/or git commit hash: e.g v1.1.0/git-c722056
  • [ st-flash] Stlink commandline tool name: e.g st-info, st-flash, st-util
  • [ STM32F446x] Target chip (and optional board): e.g STM32F402VG (STM32Fxxx Discovery)

A as-detailed description possible of the problem with debug output when available.

Output:
Dougs-MacBook-Pro:bin dyeager$ ./st-flash write out.bin 0x8000000
st-flash 1.3.0
2017-06-20T18:28:52 INFO /Users/jerry/Downloads/stlink-master/src/common.c: Loading device parameters....
2017-06-20T18:28:52 INFO /Users/jerry/Downloads/stlink-master/src/common.c: Device connected is: F446 device, id 0x10006421
2017-06-20T18:28:52 INFO /Users/jerry/Downloads/stlink-master/src/common.c: SRAM size: 0x20000 bytes (128 KiB), Flash: 0x80000 bytes (512 KiB) in pages of 131072 bytes
2017-06-20T18:28:52 INFO /Users/jerry/Downloads/stlink-master/src/common.c: Attempting to write 16536 (0x4098) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08004000 erasedEraseFlash - Sector:0x1 Size:0x4000
2017-06-20T18:28:53 INFO /Users/jerry/Downloads/stlink-master/src/common.c: Finished erasing 2 pages of 16384 (0x4000) bytes
2017-06-20T18:28:53 INFO /Users/jerry/Downloads/stlink-master/src/common.c: Starting Flash write for F2/F4/L4
2017-06-20T18:28:53 INFO /Users/jerry/Downloads/stlink-master/src/flash_loader.c: Successfully loaded flash loader in sram
enabling 32-bit flash writes
size: 16536
2017-06-20T18:28:57 ERROR /Users/jerry/Downloads/stlink-master/src/flash_loader.c: flash loader run error
2017-06-20T18:28:57 ERROR /Users/jerry/Downloads/stlink-master/src/common.c: stlink_flash_loader_run(0x8000000) failed! == -1
stlink_fwrite_flash() == -1

OUTPUT/ERROR of the commandline tool(s)

Expected/description:
short description of the expected value

Thank you,
The stlink project maintainers

@dougyeager
Copy link
Author

i meant to add that this is repeatable. it happens every time when i program (not sometimes). read and erase seem to work ok. when in debug mode, i get this for a long time and then the timeout happens and error's out. i'm not sure why my core is not going to HALT state. i don't think it is the reset line hardware as some have suggested, but i suppose it could be...:
2017-06-20T17:14:57 DEBUG /Users/jerry/Downloads/stlink-master/src/common.c: core status: running
2017-06-20T17:14:57 DEBUG /Users/jerry/Downloads/stlink-master/src/common.c: *** stlink_status ***
2017-06-20T17:14:57 DEBUG /Users/jerry/Downloads/stlink-master/src/common.c: core status: running
2017-06-20T17:14:57 DEBUG /Users/jerry/Downloads/stlink-master/src/common.c: *** stlink_status ***
2017-06-20T17:14:57 DEBUG /Users/jerry/Downloads/stlink-master/src/common.c: core status: running

@xor-gate xor-gate added this to the Unplanned (Contributions Welcome) milestone Jul 1, 2017
@LightningStalker
Copy link

I'm getting the exact same behavior on my Ugly board.

@LightningStalker
Copy link

Ok get this
I did a cold reset on the ST-LINK and the Ugly by unplugging both from USB and now it works. ¯_(ツ)_/¯

@ARizzo35
Copy link

I'm seeing this pretty regularly with STLinkv2. Steps to reproduce:

Disconnect target and try to flash; flash will fail.
Reconnect target.
Attempt to flash; flash will fail with error:

2018-06-29T11:27:50 ERROR flash_loader.c: flash loader run error
2018-06-29T11:27:50 ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1
stlink_fwrite_flash() == -1

Disconnecting STLinkv2 from USB and reconnecting, essentially doing a power cycle, resolves the issue.

@PDAJ-MM
Copy link

PDAJ-MM commented Jul 16, 2018

I also have the same problem.

2018-07-16T19:24:46 ERROR flash_loader.c: flash loader run error
2018-07-16T19:24:46 ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1
Flash page at addr: 0x08051000 erased
size: 32768
stlink_fwrite_flash() == -1
make: *** [stflash] Error 255

I can resolve it by unplugging/replugging the usb cable of the st-link, but that isn't really a solution

@pascal-niklaus
Copy link

I experience the very same issue with an ST-LINK (part of a "discovery" board). Connected to it is a RobotDyn STM32 mini. Flashing works the first time, but the second time it fails:

(...)
2018-08-25T23:43:57 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2018-08-25T23:43:57 INFO flash_loader.c: Successfully loaded flash loader in sram
15/15 pages written
2018-08-25T23:43:58 INFO common.c: Starting verification of write complete
2018-08-25T23:43:58 INFO common.c: Flash written and verified! jolly good!

$ st-flash --reset --format ihex write somefile.hex
st-flash 1.4.0-47-gae717b9
2018-08-25T23:46:08 INFO common.c: Loading device parameters....
2018-08-25T23:46:08 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2018-08-25T23:46:08 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
2018-08-25T23:46:08 INFO common.c: Attempting to write 14932 (0x3a54) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08003800 erased
2018-08-25T23:46:09 INFO common.c: Finished erasing 15 pages of 1024 (0x400) bytes
2018-08-25T23:46:09 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2018-08-25T23:46:09 INFO flash_loader.c: Successfully loaded flash loader in sram
2018-08-25T23:46:12 ERROR flash_loader.c: flash loader run error
2018-08-25T23:46:12 ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1
stlink_fwrite_flash() == -1

Unplugging and re-plugging the device fixes the issue, but just for a single time.

The hardware is fine, at least it works without the "unplugging" fix with ST-Link running in a VirtualBox VM with WIn7.

@gustawdaniel
Copy link

I am too interested in reason of this problem. As @PDAJ-MM noticed - unplug and plug works as temporary solution.

@brad-natelborg
Copy link
Contributor

Same here for me.

@rvowles
Copy link

rvowles commented Jan 11, 2019

mine:

2019-01-11T18:03:23 DEBUG common.c: stlink current mode: mass
2019-01-11T18:03:23 DEBUG common.c: stlink current mode: mass
2019-01-11T18:03:23 DEBUG common.c: *** stlink_enter_swd_mode ***
2019-01-11T18:03:23 DEBUG common.c: *** looking up stlink version
2019-01-11T18:03:23 DEBUG common.c: st vid = 0x0483 (expect 0x0483)
2019-01-11T18:03:23 DEBUG common.c: stlink pid = 0x3748
2019-01-11T18:03:23 DEBUG common.c: stlink version = 0x2
2019-01-11T18:03:23 DEBUG common.c: jtag version = 0x11
2019-01-11T18:03:23 DEBUG common.c: swim version = 0x4
2019-01-11T18:03:23 DEBUG common.c: *** stlink_jtag_reset ***
2019-01-11T18:03:23 DEBUG common.c: *** stlink_reset ***
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 5fa0004 to 0xe000ed0c
2019-01-11T18:03:23 INFO common.c: Loading device parameters....
2019-01-11T18:03:23 DEBUG common.c: *** stlink_core_id ***
2019-01-11T18:03:23 DEBUG common.c: core_id = 0x2ba01477
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 20036410 is 0xe0042000
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 ffff0080 is 0x1ffff7e0
2019-01-11T18:03:23 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2019-01-11T18:03:23 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x20000 bytes (128 KiB) in pages of 1024 bytes
2019-01-11T18:03:23 DEBUG common.c: *** set_swdclk ***
2019-01-11T18:03:23 DEBUG common.c: stlink current mode: debug (jtag or swd)
2019-01-11T18:03:23 DEBUG common.c: stlink current mode: debug (jtag or swd)
2019-01-11T18:03:23 DEBUG common.c: *** stlink_force_debug_mode ***
2019-01-11T18:03:23 DEBUG common.c: *** stlink_status ***
2019-01-11T18:03:23 DEBUG common.c: core status: halted
2019-01-11T18:03:23 INFO common.c: Attempting to write 14292 (0x37d4) bytes to stm32 address: 134231040 (0x8003400)
2019-01-11T18:03:23 DEBUG common.c: *** stlink_core_id ***
2019-01-11T18:03:23 DEBUG common.c: core_id = 0x2ba01477
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 0 is 0x4002200c
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 80 is 0x40022010
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 45670123 to 0x40022004
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 cdef89ab to 0x40022004
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 0 is 0x40022010
2019-01-11T18:03:23 DEBUG common.c: Successfully unlocked flash
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 2 to 0x40022010
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 8003400 to 0x40022014
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 2 is 0x40022010
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 42 to 0x40022010
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 10 is 0x4002200c
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 2 is 0x40022010
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 82 to 0x40022010
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 10 is 0x4002200c
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 82 is 0x40022010
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 45670123 to 0x40022004
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 cdef89ab to 0x40022004
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 2 is 0x40022010
2019-01-11T18:03:23 DEBUG common.c: Successfully unlocked flash

... skip similar:

2019-01-11T18:03:23 DEBUG common.c: Successfully unlocked flash
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 2 to 0x40022010
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 8006800 to 0x40022014
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 2 is 0x40022010
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 42 to 0x40022010
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 10 is 0x4002200c
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 2 is 0x40022010
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 82 to 0x40022010
2019-01-11T18:03:23 INFO common.c: Finished erasing 14 pages of 1024 (0x400) bytes
2019-01-11T18:03:23 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_mem32 40 bytes to 0x20000000
2019-01-11T18:03:23 INFO flash_loader.c: Successfully loaded flash loader in sram
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 82 is 0x40022010
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 45670123 to 0x40022004
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 cdef89ab to 0x40022004
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 2 is 0x40022010
2019-01-11T18:03:23 DEBUG common.c: Successfully unlocked flash
2019-01-11T18:03:23 DEBUG common.c: *** stlink_read_debug32 2 is 0x40022010
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_debug32 1 to 0x40022010
2019-01-11T18:03:23 DEBUG common.c: Finished unlocking flash, running loader!
2019-01-11T18:03:23 DEBUG flash_loader.c: Running flash loader, write address:0x8003400, size: 1024
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_mem32 1024 bytes to 0x20000028
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_reg
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_reg
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_reg
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_reg
2019-01-11T18:03:23 DEBUG common.c: *** stlink_write_reg
2019-01-11T18:03:23 DEBUG common.c: *** stlink_run ***
2019-01-11T18:03:23 DEBUG common.c: *** stlink_status ***
2019-01-11T18:03:23 DEBUG common.c: core status: running
2019-01-11T18:03:23 DEBUG common.c: *** stlink_status ***
2019-01-11T18:03:23 DEBUG common.c: core status: running
2019-01-11T18:03:23 DEBUG common.c: *** stlink_status ***
2019-01-11T18:03:23 DEBUG common.c: core status: running

that loops a fair few times:

2019-01-11T18:03:26 DEBUG common.c: *** stlink_status ***
2019-01-11T18:03:26 DEBUG common.c: core status: running
2019-01-11T18:03:26 DEBUG common.c: *** stlink_status ***
2019-01-11T18:03:26 DEBUG common.c: core status: running
2019-01-11T18:03:26 ERROR flash_loader.c: flash loader run error
2019-01-11T18:03:26 ERROR common.c: stlink_flash_loader_run(0x8003400) failed! == -1
2019-01-11T18:03:26 DEBUG common.c: *** stlink_read_debug32 0 is 0x8003400
2019-01-11T18:03:26 DEBUG common.c: *** stlink_write_reg
2019-01-11T18:03:26 DEBUG common.c: *** stlink_read_debug32 0 is 0x8003404
2019-01-11T18:03:26 DEBUG common.c: *** stlink_write_reg
2019-01-11T18:03:26 DEBUG common.c: *** stlink_run ***
2019-01-11T18:03:26 DEBUG common.c: *** stlink_exit_debug_mode ***
2019-01-11T18:03:26 DEBUG common.c: *** stlink_write_debug32 a05f0000 to 0xe000edf0
2019-01-11T18:03:26 DEBUG common.c: *** stlink_close ***

@dientc
Copy link

dientc commented Feb 1, 2019

I also got this problem on STM32F4 Discovery board. But plugging/unplugging does not solve. Hardware runs well on Windows with stlink v2 utility. :|

@ceciliacsilva
Copy link

Same here. (STM32L052). Works after plugging/unplugging.

@cdrews
Copy link

cdrews commented Feb 7, 2019

I got the same behavior as @rvowles under ubuntu linux with the stm32f4 discover board and st-flash

@dhylands
Copy link
Contributor

dhylands commented Feb 7, 2019

The F4 flashing is currently broken. See #766

@VladimirGaristov
Copy link

VladimirGaristov commented Feb 8, 2019

Seems that L4 flashing is broken as well.
I get the same error when attempting to flash STM32L496AGI6 on a Discovery kit board. Plugging / unplugging the board doesn't help. Flashing the same binary to a F7 chip works fine (STM32F767ZIT6).
My OS is Linux Mint 18 64-bit.

st-flash write original_demo.bin.bkp 0x08000000
st-flash 1.5.1
2019-02-08T01:49:01 INFO common.c: Loading device parameters....
2019-02-08T01:49:01 INFO common.c: Device connected is: L496x/L4A6x device, id 0x20006461
2019-02-08T01:49:01 INFO common.c: SRAM size: 0x40000 bytes (256 KiB), Flash: 0x100000 bytes (1024 KiB) in pages of 2048 bytes
2019-02-08T01:49:01 INFO common.c: Ignoring 488 bytes of 0xff at end of file
2019-02-08T01:49:01 INFO common.c: Attempting to write 1048088 (0xffe18) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x080ff800 erasedEraseFlash - Page:0x1ff Size:0x800
2019-02-08T01:49:15 INFO common.c: Finished erasing 512 pages of 2048 (0x800) bytes
2019-02-08T01:49:15 INFO common.c: Starting Flash write for F2/F4/L4
2019-02-08T01:49:15 INFO flash_loader.c: Successfully loaded flash loader in sram
size: 32768
2019-02-08T01:49:19 ERROR flash_loader.c: flash loader run error
2019-02-08T01:49:19 ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1
stlink_fwrite_flash() == -1

@cdrews
Copy link

cdrews commented Feb 8, 2019

I was able to compile and use an older version until this bug is fixed. 1.4.0 seems to work fine.
Here is how to build it if you are under ubuntu and were able to build the currently broken version:

cd ~/stlink # or wherever your stlink clone sits
git checkout 1.4.0-53-ga201d3e
make
cd build/Release
sudo make install

@peterremote1980
Copy link

not working with latest stlink and latest mac. Same problem still exists.

@xor-gate
Copy link
Member

xor-gate commented Feb 9, 2019

We should continue in #761 for issues with latest master version. This issue is really old. Closing this for not recycling this inappropriate. Thanks all for the comments.

@chris1seto
Copy link

chris1seto commented Oct 10, 2020

I'm also getting this with an Stm32 NulceoF767ZI:

Of note, I am also using a Raspi4 like an earlier comment.

pi@raspberrypi:~ $ st-flash --reset  --format=ihex write fw.hex
st-flash 1.6.1-98-gd819a4a
2020-10-10T03:17:45 INFO common.c: F76xxx: 512 KiB SRAM, 2048 KiB flash in at least 2 KiB pages.
2020-10-10T03:17:45 INFO common.c: Attempting to write 255304 (0x3e548) bytes to stm32 address: 134217728 (0x8000000)
EraseFlash - Sector:0x0 Size:0x8000 2020-10-10T03:17:45 INFO common.c: Flash page at addr: 0x08000000 erased
EraseFlash - Sector:0x1 Size:0x8000 2020-10-10T03:17:45 INFO common.c: Flash page at addr: 0x08008000 erased
EraseFlash - Sector:0x2 Size:0x8000 2020-10-10T03:17:46 INFO common.c: Flash page at addr: 0x08010000 erased
EraseFlash - Sector:0x3 Size:0x8000 2020-10-10T03:17:46 INFO common.c: Flash page at addr: 0x08018000 erased
EraseFlash - Sector:0x4 Size:0x20000 2020-10-10T03:17:47 INFO common.c: Flash page at addr: 0x08020000 erased
2020-10-10T03:17:47 INFO common.c: Finished erasing 5 pages of 131072 (0x20000) bytes
2020-10-10T03:17:47 INFO common.c: Starting Flash write for F2/F4/F7/L4
2020-10-10T03:17:47 INFO flash_loader.c: Successfully loaded flash loader in sram
enabling 32-bit flash writes
size: 32768
2020-10-10T03:17:48 ERROR flash_loader.c: flash loader run error
2020-10-10T03:17:48 ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1
stlink_fwrite_flash() == -1

@chris1seto
Copy link

For what it's worth going to tag v1.6.0 results in a working config on an Stm32F767zi Nucleo with a Raspi4

@ploedige
Copy link

ploedige commented Dec 18, 2020

st-flash 1.6.1 with STM32F373CCTx:
command:

st-flash --reset write <folderPath>/Drivecontroller/MainController/build/MainController.bin 0x8000000

output:

st-flash 1.6.1
2020-12-18T14:38:38 INFO common.c: F3xx: 40 KiB SRAM, 256 KiB flash in at least 2 KiB pages.
file <folderPath>/MainController/build/MainController.bin md5 checksum: 9f5e7fe1c654e9183f3e116cd745ea12, stlink checksum: 0x0004f76c
2020-12-18T14:38:38 INFO common.c: Attempting to write 3372 (0xd2c) bytes to stm32 address: 134217728 (0x8000000)
2020-12-18T14:38:38 INFO common.c: Flash page at addr: 0x08000000 erased
2020-12-18T14:38:38 INFO common.c: Flash page at addr: 0x08000800 erased
2020-12-18T14:38:38 INFO common.c: Finished erasing 2 pages of 2048 (0x800) bytes
2020-12-18T14:38:38 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2020-12-18T14:38:38 INFO flash_loader.c: Successfully loaded flash loader in sram
2020-12-18T14:38:38 ERROR flash_loader.c: flash loader run error
2020-12-18T14:38:38 ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1
stlink_fwrite_flash() == -1
The terminal process "/bin/bash '-c', 'st-flash write <folderPath>/MainController/build/MainController.bin 0x8000000'" terminated with exit code: 255.

It works on every second run


Hint: replaced the real path with <folderPath>

@Ant-ON
Copy link
Collaborator

Ant-ON commented Dec 18, 2020

@ploedige Can you try st-flash built from the develop branch?

@ploedige
Copy link

I'm not very familiar with the st-link utility, yet. What develop branch are you referring to?

@ploedige
Copy link

Sorry. I think I know what you mean.
The develop branch has the same problem:

st-flash 1.6.1-194-ga66557a
2020-12-18T17:04:20 INFO common.c: F3xx: 40 KiB SRAM, 256 KiB flash in at least 2 KiB pages.
<folderPath>/MainController/build/MainController.bin md5 checksum: 9f5e7fe1c654e9183f3e116cd745ea12, stlink checksum: 0x0004f76c
2020-12-18T17:04:21 INFO common.c: Attempting to write 3372 (0xd2c) bytes to stm32 address: 134217728 (0x8000000)
2020-12-18T17:04:21 INFO common.c: Flash page at addr: 0x08000000 erased
2020-12-18T17:04:21 INFO common.c: Flash page at addr: 0x08000800 erased
2020-12-18T17:04:21 INFO common.c: Finished erasing 2 pages of 2048 (0x800) bytes
2020-12-18T17:04:21 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL
2020-12-18T17:04:21 INFO flash_loader.c: Successfully loaded flash loader in sram
2020-12-18T17:04:21 ERROR flash_loader.c: Flash loader run error (R2 0x41000000 R15 0x41000000 DHCSR 0x01090001 DFSR 0x00000009)
2020-12-18T17:04:21 ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1
2020-12-18T17:04:21 INFO common.c: Go to Thumb mode
stlink_fwrite_flash() == -1
The terminal process "/bin/bash '-c', 'st-flash --reset write <folderPath>/MainController/build/MainController.bin 0x8000000'" terminated with exit code: 255.

@Ant-ON
Copy link
Collaborator

Ant-ON commented Dec 21, 2020

@ploedige The ARM core in lockup state. Most likely the bootloader (or the core of some reason before bootloader runs) falls into the hardfault.
Based on current information, it is difficult to say why this is happening. You may extend information in src/stlink-lib/flash_loader.c by cheinging stlink_flash_loader_run:

    uint32_t dhcsr, dfsr;

change to

    uint32_t dhcsr, dfsr, cfsr, hfsr;

and

    dhcsr = dfsr = 0;
    stlink_read_debug32(sl, STLINK_REG_DHCSR, &dhcsr);
    stlink_read_debug32(sl, STLINK_REG_DFSR, &dfsr);

change to

    dhcsr = dfsr = cfsr = hfsr = 0;
    stlink_read_debug32(sl, STLINK_REG_DHCSR, &dhcsr);
    stlink_read_debug32(sl, STLINK_REG_DFSR, &dfsr);
    stlink_read_debug32(sl, 0xE000ED28, &cfsr);
    stlink_read_debug32(sl, 0xE000ED2C, &hfsr);
    ELOG("CFSR 0x%08X HFSR 0x%08X\n", cfsr, hfsr);

@jakub-michalik-proemion
Copy link

jakub-michalik-proemion commented Jan 8, 2021

Instruction (Ubuntu 20.04) to avoid the error:

First, we are going to install the necessary libraries and build tools:

sudo apt-get install git make cmake libusb-1.0-0-dev
sudo apt-get install gcc build-essential
Now, we will download and build the ST-Link utilities:

cd ~myusername
mkdir stm32
cd stm32
git clone https://github.com/stlink-org/stlink
git checkout v1.6.1
cd stlink
cmake .
make

Now we copy the built binaries to their place:

cd bin
sudo cp st-* /usr/local/bin
cd ../lib
sudo cp .so /lib32

then udev rules:

sudo cp stlink/config/udev/rules.d/49-stlinkv* /etc/udev/rules.d/

@Nightwalker-87
Copy link
Member

Nightwalker-87 commented Jan 8, 2021

❗ No, this is no good approach, one should not manually copy files to other locations.
This also breaks the implemented uninstall routine.
Use sudo make install for correct installation to the appropriate paths or follow our compilation tutorial.

@iFreilicht
Copy link

I'm having the same issue, even with v1.6.1, and power cycling does not fix it.

$ st-flash --reset --format ihex write test_app_v1_00.hex   
st-flash 1.6.1
2021-01-12T13:25:30 INFO common.c: F4xx: 192 KiB SRAM, 1024 KiB flash in at least 16 KiB pages.
2021-01-12T13:25:30 INFO common.c: Attempting to write 32528 (0x7f10) bytes to stm32 address: 134217728 (0x8000000)
EraseFlash - Sector:0x0 Size:0x4000 2021-01-12T13:25:30 INFO common.c: Flash page at addr: 0x08000000 erased
EraseFlash - Sector:0x1 Size:0x4000 2021-01-12T13:25:30 INFO common.c: Flash page at addr: 0x08004000 erased
2021-01-12T13:25:30 INFO common.c: Finished erasing 2 pages of 16384 (0x4000) bytes
2021-01-12T13:25:30 INFO common.c: Starting Flash write for F2/F4/L4
2021-01-12T13:25:30 INFO flash_loader.c: Successfully loaded flash loader in sram
enabling 32-bit flash writes
size: 32528
2021-01-12T13:25:31 ERROR flash_loader.c: flash loader run error
2021-01-12T13:25:31 ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1
stlink_fwrite_flash() == -1

@iFreilicht
Copy link

Ok, so I actually found a fix in my situation. Turns out the write protection was activated on part of the flash. Unfortunately, setting option bytes via st-flash is not supported for the STM32F4, but using the STM32CubeProgrammer, I managed to completely erase everything on the flash:

./STM32_Programmer.sh -c port=SWD -ob WRP0=1 WRP1=1 WRP2=1 WRP3=1 -e all

After this, flashing with st-flash worked again!

@Nightwalker-87
Copy link
Member

Yes, that may be, but does not help us to fix the problem properly in this toolset. 😕

@iFreilicht
Copy link

Yeah, I guess it's impossible to do unless writing to the option bytes area is supported, see #458.

@Nightwalker-87
Copy link
Member

Nightwalker-87 commented Mar 9, 2021

Feel free to check the known good commits listed in #356 on the reported bugs you have faced within this topic, but report the results here. Please avoid cross-posting between issues.
We need to distinguish different outputs of "flash loader run errors" precisely as they are likely to have several causes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.