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.
Code
/opt/SEGGER/JLink_Linux_V700_x86_64/JLinkGDBServerCLExe -singlerun -strict -timeout 0 -nogui -speed 1000 -ir -endian little -vd -device STM32L433CC -if swd
SEGGER J-Link GDB Server V7.00 Command Line Version
JLinkARM.dll V7.00 (DLL compiled Apr 8 2021 14:33:43)
Command line: -singlerun -strict -timeout 0 -nogui -speed 1000 -ir -endian little -vd -device STM32L433CC -if swd
-----GDB Server start settings-----
GDBInit file: none
GDB Server Listening port: 2331
SWO raw output listening port: 2332
Terminal I/O port: 2333
Accept remote connection: yes
Generate logfile: on
Verify download: on
Init regs on start: on
Silent mode: off
Single run mode: on
Target connection timeout: 0 ms
------J-Link related settings------
J-Link Host interface: USB
J-Link script: none
J-Link settings file: none
------Target related settings------
Target device: STM32L433CC
Target interface: SWD
Target interface speed: 1000kHz
Target endian: little
Connecting to J-Link...
J-Link is connected.
Firmware: J-Link Pro V4 compiled Feb 16 2021 10:07:18
Hardware: V4.00
S/N: 174505557
Feature(s): RDI, FlashBP, FlashDL, JFlash, GDB
Checking target voltage...
Target voltage: 3.30 V
Listening on TCP/IP port 2331
Connecting to target...
Error during pretty printers setup: Undefined info command: "pretty-printer". Try "help info".
Some features and performance optimizations will not be available.
Connected to target
Waiting for GDB connection...Connected to 127.0.0.1
Reading all registers
Read 2 bytes @ address 0x08013C10 (Data = 0x4B02)
Read 2 bytes @ address 0x08001198 (Data = 0x4770)
Read 4 bytes @ address 0x00000000 (Data = 0x20010000)
Read 2 bytes @ address 0x00000000 (Data = 0x0000)
Downloading 400 bytes @ address 0x08000000 - Verified OK
Downloading 16112 bytes @ address 0x08000190 - Verified OK
Downloading 16048 bytes @ address 0x08004080 - Verified OK
Downloading 16160 bytes @ address 0x08007F30 - Verified OK
Downloading 15984 bytes @ address 0x0800BE50 - Verified OK
Downloading 16080 bytes @ address 0x0800FCC0 - Verified OK
Downloading 15984 bytes @ address 0x08013B90 - Verified OK
Downloading 7464 bytes @ address 0x08017A00 - Verified OK
Downloading 6856 bytes @ address 0x08019728 - Verified OK
Downloading 1680 bytes @ address 0x0801B1F0 - Verified OK
Downloading 1512 bytes @ address 0x0801B880 - Verified OK
Downloading 40 bytes @ address 0x0801BE68 - Verified OK
Downloading 8 bytes @ address 0x0801BE90 - Verified OK
Downloading 632 bytes @ address 0x0801BE98 - Verified OK
Comparing flash [....................] Done.
Erasing flash [....................] Done.
ERROR: Failed to erase sectors 0 @ address 0x08000000 (Algo87: Unspecified error #1)
Failed to erase sectors.
Writing register (PC = 0x 800f0dc)
Read 2 bytes @ address 0x08013C10 (Data = 0x4B02)
Read 2 bytes @ address 0x08001198 (Data = 0x4770)
Debugger connected to localhost:2331
Starting target CPU...
Display More