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

st-flash run_flash_loader(0x08000000) failed #356

Closed
Almaz1c opened this issue Dec 9, 2015 · 40 comments · Fixed by #1113
Closed

st-flash run_flash_loader(0x08000000) failed #356

Almaz1c opened this issue Dec 9, 2015 · 40 comments · Fixed by #1113

Comments

@Almaz1c
Copy link

Almaz1c commented Dec 9, 2015

Hello. I try to load firmare in STM32F103CBT6 using compiled st-flash.exe utility under windows 8.1.

There is used command:
st-flash.exe write ${project_name}.bin 0x08000000

Here is result:

Flash page at addr: 0x08000000 erased
Flash page at addr: 0x08000400 erased
Flash page at addr: 0x08000800 erased
Flash page at addr: 0x08000c00 erased
Flash page at addr: 0x08001000 erased
Flash page at addr: 0x08001400 erased
Flash page at addr: 0x08001800 erased
Flash page at addr: 0x08001c00 erased
Flash page at addr: 0x08002000 erased
Flash page at addr: 0x08002400 erased
Flash page at addr: 0x08002800 erased
Flash page at addr: 0x08002c00 erased
Flash page at addr: 0x08003000 erased
Flash page at addr: 0x08003400 erased
Flash page at addr: 0x08003800 erased
Flash page at addr: 0x08003c00 erased
Flash page at addr: 0x08004000 erased
Flash page at addr: 0x08004400 erased
Flash page at addr: 0x08004800 erased
Flash page at addr: 0x08004c00 erased
Flash page at addr: 0x08005000 erased
Flash page at addr: 0x08005400 erased
Flash page at addr: 0x08005800 erased
Flash page at addr: 0x08005c00 erased
Flash page at addr: 0x08006000 erased
Flash page at addr: 0x08006400 erased
Flash page at addr: 0x08006800 erased
Flash page at addr: 0x08006c00 erased
Flash page at addr: 0x08007000 erased
Flash page at addr: 0x08007400 erased
Flash page at addr: 0x08007800 erased
Flash page at addr: 0x08007c00 erased
Flash page at addr: 0x08008000 erased
Flash page at addr: 0x08008400 erased
Flash page at addr: 0x08008800 erased
Flash page at addr: 0x08008c00 erased
Flash page at addr: 0x08009000 erased
Flash page at addr: 0x08009400 erased
Flash page at addr: 0x08009800 erased
Flash page at addr: 0x08009c00 erased
Flash page at addr: 0x0800a000 erased
Flash page at addr: 0x0800a400 erased
stlink_fwrite_flash() == -1
2015-12-09T22:01:57 INFO src/stlink-common.c: Loading device parameters....
2015-12-09T22:01:57 INFO src/stlink-common.c: Device connected is: F1 Medium-density device, id 0x20036410
2015-12-09T22:01:57 INFO src/stlink-common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0xb4a000 bytes (11560 KiB) in pages of 1024 bytes
2015-12-09T22:01:57 INFO src/stlink-common.c: Attempting to write 42368 (0xa580) bytes to stm32 address: 134217728 (0x8000000)
2015-12-09T22:01:57 INFO src/stlink-common.c: Finished erasing 42 pages of 1024 (0x400) bytes
2015-12-09T22:01:57 INFO src/stlink-common.c: Starting Flash write for VL/F0/F3 core id
2015-12-09T22:01:57 INFO src/stlink-common.c: Successfully loaded flash loader in sram
2015-12-09T22:02:18 ERROR src/stlink-common.c: flash loader run error
2015-12-09T22:02:18 ERROR src/stlink-common.c: run_flash_loader(0x8000000) failed! == -1

What is the issue? Thank you)

@xor-gate
Copy link
Member

@Almaz1c could you test with v1.2.0 or master, and see if the problem still exists?

@vladiks
Copy link

vladiks commented May 26, 2016

I can confirm this bug, but I get it only occasionally - sometimes it passes, sometimes it fails.

  • using the same command and params
  • Running on raspberry Pi 2, using Linux raspberrypi 4.1.7+, armv6l
  • chip STM32F091RCT6

I am using latest version, compiled yesterday. My output:

pi@raspberrypi ~/Desktop/Tester $ sudo st-flash write fw_v13.bin 0x08000000
2016-05-26T10:23:34 INFO src/common.c: Loading device parameters....
2016-05-26T10:23:34 INFO src/common.c: Device connected is: F09X device, id 0x10006442
2016-05-26T10:23:34 INFO src/common.c: SRAM size: 0x8000 bytes (32 KiB), Flash: 0x40000 bytes (256 KiB) in pages of 2048 bytes
2016-05-26T10:23:34 INFO src/common.c: Attempting to write 196964 (0x30164) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08030000 erased
2016-05-26T10:23:37 INFO src/common.c: Finished erasing 97 pages of 2048 (0x800) bytes
2016-05-26T10:23:37 INFO src/common.c: Starting Flash write for VL/F0/F3 core id
2016-05-26T10:23:37 INFO src/flash_loader.c: Successfully loaded flash loader in sram
2016-05-26T10:23:47 ERROR src/flash_loader.c: flash loader run error
2016-05-26T10:23:47 ERROR src/common.c: stlink_flash_loader_run(0x8000000) failed! == -1
stlink_fwrite_flash() == -1

@xor-gate
Copy link
Member

xor-gate commented May 26, 2016

@vladiks which version/git tag do you use of the st-flash tool?

@xor-gate
Copy link
Member

Current version is unable to compile with visual studio, probably it should work under MinGW but I have not tested this.

@vladiks
Copy link

vladiks commented May 26, 2016

@xor-gate I'm sorry, but I don't know how to find out the git tag. I've downloaded master as zip and copied it to raspberry. I am retty sure it's 1.2.0, there are also news for 1.2.0 in changelog.

I've avoided the issue by erasing memory by separate command before flashing it again - the problem now disappeared.

@xor-gate
Copy link
Member

xor-gate commented May 26, 2016

@vladiks when you downloaded zipfile for master you running latest version (beyond 1.2.0). I have seen an exact issue where people erase the flash (mass erase/full?) and then it worked. This is a problem which I saw some other people have but have not confirmed and seen this myself. In the upcoming time I will prepare a continues hardware/stlink testing setup at Dual Inventive and hopefully I will catch this nasty bug.

This needs some documentation somewhere if people tried to (mass)erased and then flashed and the problem resolved. I will keep this issue open until I have documented/noted it somewhere.

@vladiks
Copy link

vladiks commented May 26, 2016

Good luck and many thanks for your work on this utility.

xor-gate added a commit that referenced this issue May 26, 2016
Related to #356
@xor-gate
Copy link
Member

I have put it in the README.md. So people will see it 👍. Thanks all for the feedback, feel free to open a issue when something is not working as expected!

@zokl
Copy link

zokl commented Sep 9, 2016

Hello I have the same problem with STML0xx. This error occurs only with st-link utility in linux and mac os X. Utility from STM works fine.

@Ant-ON
Copy link
Collaborator

Ant-ON commented Mar 19, 2021

@Nightwalker-87
Copy link
Member

Yes, I will soon. Thx for the note.

@Nightwalker-87
Copy link
Member

@Ant-ON Unfortunately it doesn't make a difference. 😕

@Ant-ON
Copy link
Collaborator

Ant-ON commented Mar 21, 2021

@Nightwalker-87 Do you use --reset option? Can you upload firmware for bluepill? I will test it

@Nightwalker-87
Copy link
Member

Nightwalker-87 commented Mar 21, 2021

No, but I retried and again there was no difference. The first attempt fails, the second one works, the next one fails and so on...
So in consequence one can upload firmware under these circumstances.

I've done some more tests with --connect-under-reset instead of --reset. The result is interesting:
After plugging in the programmer, the first attempt fails:

2021-03-21T11:22:29 INFO common.c: Attempting to write 3520 (0xdc0) bytes to stm32 address: 134217728 (0x8000000)
2021-03-21T11:22:29 INFO common.c: Flash page at addr: 0x08000000 erased
2021-03-21T11:22:29 INFO common.c: Flash page at addr: 0x08000400 erased
2021-03-21T11:22:29 INFO common.c: Flash page at addr: 0x08000800 erased
2021-03-21T11:22:29 INFO common.c: Flash page at addr: 0x08000c00 erased
2021-03-21T11:22:29 INFO common.c: Finished erasing 4 pages of 1024 (0x400) bytes
2021-03-21T11:22:29 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL
2021-03-21T11:22:29 INFO flash_loader.c: Successfully loaded flash loader in sram
2021-03-21T11:22:30 ERROR flash_loader.c: Flash loader run error (R2 0x00000000 R15 0x00000000 DHCSR 0x01090001 DFSR 0x00000001)
2021-03-21T11:22:30 ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1
2021-03-21T11:22:30 INFO common.c: Go to Thumb mode
stlink_fwrite_flash() == -1

but all following attempts succeed:

2021-03-21T11:26:52 INFO common.c: Attempting to write 3520 (0xdc0) bytes to stm32 address: 134217728 (0x8000000)
2021-03-21T11:26:52 INFO common.c: Flash page at addr: 0x08000000 erased
2021-03-21T11:26:52 INFO common.c: Flash page at addr: 0x08000400 erased
2021-03-21T11:26:52 INFO common.c: Flash page at addr: 0x08000800 erased
2021-03-21T11:26:52 INFO common.c: Flash page at addr: 0x08000c00 erased
2021-03-21T11:26:52 INFO common.c: Finished erasing 4 pages of 1024 (0x400) bytes
2021-03-21T11:26:52 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL
2021-03-21T11:26:52 INFO flash_loader.c: Successfully loaded flash loader in sram
  4/  4 pages written
2021-03-21T11:26:52 INFO common.c: Starting verification of write complete
2021-03-21T11:26:52 INFO common.c: Flash written and verified! jolly good!

@Ant-ON
Copy link
Collaborator

Ant-ON commented Mar 21, 2021

The problem is in setup which the MCU firmware do, if the firmware goes once every other time. It is necessary to determine what exactly needs to be turned off.
The most easy option is to reboot the MCU after erasing, but this is not the best option.

@Nightwalker-87
Copy link
Member

Hm, ok - Well there is no guarantee that the process is currently implemented well...
Should you find any flaws, just get rid of them if a reasonable alternative comes to you mind.

I'm still busy reviewing tickets and identifying already solved issues.
Nevertheless I can test things with my Bluepill or a Discovery VL board anytime. Just let me know. 😉

@Ant-ON
Copy link
Collaborator

Ant-ON commented Mar 22, 2021

@Nightwalker-87 I have looked at the logs from #356 (comment). You use develop branch of main repo. Can you try with st-flash from my fork https://github.com/Ant-ON/stlink/tree/flash_loader_rework?

@Nightwalker-87
Copy link
Member

No, I haven't: git checkout flash_loader_rework (commit: bc9062c)
My command was st-flash --reset write /[...]/Blinker.bin 0x8000000, as requested.

Still can't report anything else. 😕

@Ant-ON
Copy link
Collaborator

Ant-ON commented Mar 22, 2021

@Nightwalker-87 I fixed the problem on the flash_loader_rework baranch of my fork. I want to make sure that the problem was solved not only for me.
But the --connect-under-reset results were interesting. The error says that the MCU is a sleep...

@Nightwalker-87
Copy link
Member

Yeah, well, nobody claimed this would be easy to solve. 😒

@Ant-ON
Copy link
Collaborator

Ant-ON commented Mar 22, 2021

@Nightwalker-87
The flash_loader_rework branch

anton@vivobook:~/stlink/build/Release/bin$ ./st-flash --reset --format ihex write ./STM32F103_Nucleo_Demo.hex 
st-flash 1.6.1-229-gbc9062c-dirty
2021-03-22T19:22:48 WARN usb.c: NRST is not connected
2021-03-22T19:22:48 INFO common.c: F1xx Medium-density: 20 KiB SRAM, 64 KiB flash in at least 1 KiB pages.
2021-03-22T19:22:48 WARN usb.c: NRST is not connected
2021-03-22T19:22:48 INFO common.c: Attempting to write 19328 (0x4b80) bytes to stm32 address: 134217728 (0x8000000)
2021-03-22T19:22:48 INFO common.c: Flash page at addr: 0x08000000 erased
...
2021-03-22T19:22:49 INFO common.c: Flash page at addr: 0x08004800 erased
2021-03-22T19:22:49 INFO common.c: Finished erasing 19 pages of 1024 (0x400) bytes
2021-03-22T19:22:49 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL
2021-03-22T19:22:49 INFO flash_loader.c: Successfully loaded flash loader in sram
 19/ 19 pages written
2021-03-22T19:22:50 INFO common.c: Starting verification of write complete
2021-03-22T19:22:50 INFO common.c: Flash written and verified! jolly good!
2021-03-22T19:22:50 WARN usb.c: NRST is not connected
anton@vivobook:~/stlink/build/Release/bin$ ./st-flash --reset --format ihex write ./STM32F103_Nucleo_Demo.hex 
st-flash 1.6.1-229-gbc9062c-dirty
2021-03-22T19:22:51 WARN usb.c: NRST is not connected
2021-03-22T19:22:51 INFO common.c: F1xx Medium-density: 20 KiB SRAM, 64 KiB flash in at least 1 KiB pages.
2021-03-22T19:22:51 WARN usb.c: NRST is not connected
2021-03-22T19:22:51 INFO common.c: Attempting to write 19328 (0x4b80) bytes to stm32 address: 134217728 (0x8000000)
2021-03-22T19:22:51 INFO common.c: Flash page at addr: 0x08000000 erased
...
2021-03-22T19:22:52 INFO common.c: Flash page at addr: 0x08004800 erased
2021-03-22T19:22:52 INFO common.c: Finished erasing 19 pages of 1024 (0x400) bytes
2021-03-22T19:22:52 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL
2021-03-22T19:22:52 INFO flash_loader.c: Successfully loaded flash loader in sram
 19/ 19 pages written
2021-03-22T19:22:53 INFO common.c: Starting verification of write complete
2021-03-22T19:22:53 INFO common.c: Flash written and verified! jolly good!
2021-03-22T19:22:53 WARN usb.c: NRST is not connected

The develop branch

anton@vivobook:~/stlink/build/Release/bin$ ./st-flash --reset --format ihex write ./STM32F103_Nucleo_Demo.hex 
st-flash 1.6.1-229-gbc9062c-dirty
2021-03-22T19:27:36 WARN usb.c: NRST is not connected
2021-03-22T19:27:36 INFO common.c: F1xx Medium-density: 20 KiB SRAM, 64 KiB flash in at least 1 KiB pages.
2021-03-22T19:27:36 WARN usb.c: NRST is not connected
2021-03-22T19:27:36 INFO common.c: Attempting to write 19328 (0x4b80) bytes to stm32 address: 134217728 (0x8000000)
2021-03-22T19:27:36 INFO common.c: Flash page at addr: 0x08000000 erased
...
2021-03-22T19:27:36 INFO common.c: Flash page at addr: 0x08004800 erased
2021-03-22T19:27:36 INFO common.c: Finished erasing 19 pages of 1024 (0x400) bytes
2021-03-22T19:27:36 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL
2021-03-22T19:27:36 INFO flash_loader.c: Successfully loaded flash loader in sram
2021-03-22T19:27:36 ERROR flash_loader.c: Write error (R2 0x000001F8 R15 0x080049D2 DHCSR 0x00030003 DFSR 0x00000009)
2021-03-22T19:27:36 ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1
stlink_fwrite_flash() == -1
anton@vivobook:~/stlink/build/Release/bin$ ./st-flash --reset --format ihex write ./STM32F103_Nucleo_Demo.hex 
st-flash 1.6.1-229-gbc9062c-dirty
2021-03-22T19:27:38 WARN usb.c: NRST is not connected
2021-03-22T19:27:38 INFO common.c: F1xx Medium-density: 20 KiB SRAM, 64 KiB flash in at least 1 KiB pages.
2021-03-22T19:27:38 WARN usb.c: NRST is not connected
2021-03-22T19:27:38 INFO common.c: Attempting to write 19328 (0x4b80) bytes to stm32 address: 134217728 (0x8000000)
2021-03-22T19:27:38 INFO common.c: Flash page at addr: 0x08000000 erased
...
2021-03-22T19:27:38 INFO common.c: Flash page at addr: 0x08004800 erased
2021-03-22T19:27:38 INFO common.c: Finished erasing 19 pages of 1024 (0x400) bytes
2021-03-22T19:27:38 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL
2021-03-22T19:27:38 INFO flash_loader.c: Successfully loaded flash loader in sram
 19/ 19 pages written
2021-03-22T19:27:39 INFO common.c: Starting verification of write complete
2021-03-22T19:27:40 INFO common.c: Flash written and verified! jolly good!
2021-03-22T19:27:40 WARN usb.c: NRST is not connected

@Nightwalker-87
Copy link
Member

Nightwalker-87 commented Mar 22, 2021

@Ant-ON I can now reproduce after a clean uninstall.
I forgot that I had done a full system install of the develop branch head commit previously.
So of course there were leftovers. 🤦 Sry for that - I should have known better.
The fix obviously solves the issue.
I have also tested a sequence and it really appears to be reproducible.
Using --connect-under-reset also turns out to be flashing reliably.

@Nightwalker-87
Copy link
Member

... so now it's about time to collect all related issues together, I guess. 🥇 🍾

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