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

[STM32F205]: st-flash broken due to introduced bug in stlink-lib/usb.c #1451

Open
1 of 6 tasks
cdhooper opened this issue Feb 3, 2025 · 0 comments
Open
1 of 6 tasks

Comments

@cdhooper
Copy link

cdhooper commented Feb 3, 2025

Thank you for giving feedback to the stlink project.



  • I made serious effort to avoid creating duplicate or nearly similar issue

In order to allow developers to isolate and target your respective issue, please take some time to select the check boxes below and fill out each of the following items appropriate to your specific problem.

  • Programmer/board type: STM32F4-Discovery onboard st-link, programming an external target.
  • Operating system an version: Linux Fedora 41
  • stlink tools version and/or git commit hash: commit eecfe05
  • stlink commandline tool name: st-flash
  • Target chip (and board, if applicable): [enter here] (e.g STM32F205RET6 (Custom board)

Commandline output:

stutils/build/Release/bin/st-flash  --reset write objs/fw.bin 0x08000000
st-flash 1.8.0-90-geecfe05
2025-02-03T00:37:14 INFO common_legacy.c: STM32F2xx: 128 KiB SRAM, 512 KiB flash in at least 128 KiB pages.
file objs/fw.bin md5 checksum: 3de9c24d5e6066922a7d1de95ba83724, stlink checksum: 0x007ae944
2025-02-03T00:37:14 INFO common_flash.c: Attempting to write 84720 (0x14af0) bytes to stm32 address: 134217728 (0x8000000)
EraseFlash - Sector:0x0 Size:0x4000 -> Flash page at 0x8000000 erased (size: 0x4000)
EraseFlash - Sector:0x1 Size:0x4000 -> Flash page at 0x8004000 erased (size: 0x4000)
EraseFlash - Sector:0x2 Size:0x4000 -> Flash page at 0x8008000 erased (size: 0x4000)
EraseFlash - Sector:0x3 Size:0x4000 -> Flash page at 0x800c000 erased (size: 0x4000)
EraseFlash - Sector:0x4 Size:0x10000 -> Flash page at 0x8010000 erased (size: 0x10000)

2025-02-03T00:37:15 INFO flash_loader.c: Starting Flash write for F2/F4/F7/L4
2025-02-03T00:37:15 INFO flash_loader.c: Successfully loaded flash loader in sram
2025-02-03T00:37:15 INFO flash_loader.c: Clear DFSR
2025-02-03T00:37:15 INFO flash_loader.c: Clear CFSR
2025-02-03T00:37:15 INFO flash_loader.c: Clear HFSR
2025-02-03T00:37:15 INFO flash_loader.c: enabling 32-bit flash writes
2025-02-03T00:37:15 INFO common_legacy.c: Go to Thumb mode
2025-02-03T00:37:16 ERROR flash_loader.c: Flash loader write error
2025-02-03T00:37:16 WARN flash_loader.c: Loader state: R2 0x0 R15 0x20000024
2025-02-03T00:37:16 WARN flash_loader.c: MCU state: DHCSR 0x3000B DFSR 0x2 CFSR 0x0 HFSR 0x0
2025-02-03T00:37:16 ERROR flash_loader.c: stlink_flash_loader_run(0x8000000) failed! == -1
2025-02-03T00:37:16 INFO common_legacy.c: Go to Thumb mode
stlink_fwrite_flash() == -1
make: *** [Makefile:325: just-flash] Error 255

Expected/description:

Due to a recent change in src/stlink-lib/usb.c, register reads are attempted as register writes.

The following patch should resolve the issue:

diff --git a/src/stlink-lib/usb.c b/src/stlink-lib/usb.c
index 8ad6cdd..3685e92 100644
--- a/src/stlink-lib/usb.c
+++ b/src/stlink-lib/usb.c
@@ -808,12 +808,12 @@ int32_t _stlink_usb_read_reg(stlink_t *sl, int32_t r_idx, struct stlink_reg *reg
     cmd[i++] = STLINK_DEBUG_COMMAND;
 
     if(sl->version.jtag_api == STLINK_JTAG_API_V1) {
-        cmd[i++] = STLINK_DEBUG_APIV1_WRITEREG;
+        cmd[i++] = STLINK_DEBUG_APIV1_READREG;
     } else if(sl->version.jtag_api == STLINK_JTAG_API_V2) {
-        cmd[i++] = STLINK_DEBUG_APIV2_WRITEREG;
+        cmd[i++] = STLINK_DEBUG_APIV2_READREG;
     } else {
         // STLINK_JTAG_API_V3
-        cmd[i++] = STLINK_DEBUG_APIV2_WRITEREG;
+        cmd[i++] = STLINK_DEBUG_APIV2_READREG;
     }
 
     cmd[i++] = (uint8_t) r_idx;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant