Unable to reprogram STM32 flash without full erase

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Unable to reprogram STM32 flash without full erase

      I am unable to reprogram an STM32 microcontroller unless I perform a full erase before programming. The below code uses CLion, but the same error also happens using the command line version of arm-none-eabi-gdb and JLinkGDBServer.
      GDB: arm-none-eabi-gdb (also occurs with CLion's bundled GDB)
      Compiler: arm-none-eabi-gcc and arm-none-eabi-g++
      Microcontroller: STM32L433CC (also happens with STM32F411RC)
      I am using USB for this. When I use ethernet, I get an error like "Failed to download RAMCode")

      The error is below. The program still starts, but with the previous code. If I attempt to flash it one more time, the flash is corrupted until I perform a full erase.

      Brainfuck Source Code

      1. /opt/SEGGER/JLink_Linux_V700_x86_64/JLinkGDBServerCLExe -singlerun -strict -timeout 0 -nogui -speed 1000 -ir -endian little -vd -device STM32L433CC -if swd
      2. SEGGER J-Link GDB Server V7.00 Command Line Version
      3. JLinkARM.dll V7.00 (DLL compiled Apr 8 2021 14:33:43)
      4. Command line: -singlerun -strict -timeout 0 -nogui -speed 1000 -ir -endian little -vd -device STM32L433CC -if swd
      5. -----GDB Server start settings-----
      6. GDBInit file: none
      7. GDB Server Listening port: 2331
      8. SWO raw output listening port: 2332
      9. Terminal I/O port: 2333
      10. Accept remote connection: yes
      11. Generate logfile: on
      12. Verify download: on
      13. Init regs on start: on
      14. Silent mode: off
      15. Single run mode: on
      16. Target connection timeout: 0 ms
      17. ------J-Link related settings------
      18. J-Link Host interface: USB
      19. J-Link script: none
      20. J-Link settings file: none
      21. ------Target related settings------
      22. Target device: STM32L433CC
      23. Target interface: SWD
      24. Target interface speed: 1000kHz
      25. Target endian: little
      26. Connecting to J-Link...
      27. J-Link is connected.
      28. Firmware: J-Link Pro V4 compiled Feb 16 2021 10:07:18
      29. Hardware: V4.00
      30. S/N: 174505557
      31. Feature(s): RDI, FlashBP, FlashDL, JFlash, GDB
      32. Checking target voltage...
      33. Target voltage: 3.30 V
      34. Listening on TCP/IP port 2331
      35. Connecting to target...
      36. Error during pretty printers setup: Undefined info command: "pretty-printer". Try "help info".
      37. Some features and performance optimizations will not be available.
      38. Connected to target
      39. Waiting for GDB connection...Connected to 127.0.0.1
      40. Reading all registers
      41. Read 2 bytes @ address 0x08013C10 (Data = 0x4B02)
      42. Read 2 bytes @ address 0x08001198 (Data = 0x4770)
      43. Read 4 bytes @ address 0x00000000 (Data = 0x20010000)
      44. Read 2 bytes @ address 0x00000000 (Data = 0x0000)
      45. Downloading 400 bytes @ address 0x08000000 - Verified OK
      46. Downloading 16112 bytes @ address 0x08000190 - Verified OK
      47. Downloading 16048 bytes @ address 0x08004080 - Verified OK
      48. Downloading 16160 bytes @ address 0x08007F30 - Verified OK
      49. Downloading 15984 bytes @ address 0x0800BE50 - Verified OK
      50. Downloading 16080 bytes @ address 0x0800FCC0 - Verified OK
      51. Downloading 15984 bytes @ address 0x08013B90 - Verified OK
      52. Downloading 7464 bytes @ address 0x08017A00 - Verified OK
      53. Downloading 6856 bytes @ address 0x08019728 - Verified OK
      54. Downloading 1680 bytes @ address 0x0801B1F0 - Verified OK
      55. Downloading 1512 bytes @ address 0x0801B880 - Verified OK
      56. Downloading 40 bytes @ address 0x0801BE68 - Verified OK
      57. Downloading 8 bytes @ address 0x0801BE90 - Verified OK
      58. Downloading 632 bytes @ address 0x0801BE98 - Verified OK
      59. Comparing flash [....................] Done.
      60. Erasing flash [....................] Done.
      61. ERROR: Failed to erase sectors 0 @ address 0x08000000 (Algo87: Unspecified error #1)
      62. Failed to erase sectors.
      63. Writing register (PC = 0x 800f0dc)
      64. Read 2 bytes @ address 0x08013C10 (Data = 0x4B02)
      65. Read 2 bytes @ address 0x08001198 (Data = 0x4770)
      66. Debugger connected to localhost:2331
      67. Starting target CPU...
      Display All