2025-11-26 2:36 PM - edited 2025-11-26 2:37 PM
Hello,
STM32L4+, CubeProgrammer 2.21, ST-Link V2, Windows 10
I need to do:
* Full flash erase
* Write Application image (.hex or .bin)
* Write Bootloader image (.hex or .bin)
* Set RDP level 1
* Start the application at the Bootloader start address.
-
I am successfully doing this with the CubeProgrammer GUI, but I fail to get it to work with CLI.
The "-e all" command works and says "Mass erase successfully achieved":
C:\"Program Files"\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe -c port=SWD ap=0 -e all
-
However, I have tried numerous variants of the following command (and its separate parts alone) without success:
C:\"Program Files"\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe -c port=SWD freq=3900 ap=0 -e all -w C:\SVN\Path\More_path\hex\Application.elf -w C:\SVN\Path\More_path\hex\Bootloader.hex -ob rdp=0xBB -s 0x08000000
I have also tried with .bin files and their respective start addresses.
The only response I get is the header:
-------------------------------------------------------------------
STM32CubeProgrammer v2.21.0
-------------------------------------------------------------------
-
The command "-c port=SWD freq=3900 ap=0 -s 0x08000000" gives a complete (failure) response:
-------------------------------------------------------------------
STM32CubeProgrammer v2.21.0
-------------------------------------------------------------------
ST-LINK SN : 36FF6C064D59303612251543
ST-LINK FW : V2J46S7
Board : --
Voltage : 3.17V
SWD freq : 1800 KHz
Connect mode: Normal
Reset mode : Software reset
Device ID : 0x470
Revision ID : Rev V
Device name : STM32L4Rxxx/STM32L4Sxxx
Flash size : 2 MBytes
Device type : MCU
Device CPU : Cortex-M4
BL Version : 0x95
Debug in Low Power mode enabled
RUNNING Program ...
Address: : 0x8000000
Warning: failed to run application!
Warning: The core is kept under Reset!
Error: Start operation failed
-
I have tried to find a tutorial or a list of CLI command examples but um2237 is a wee bit brief and I haven't found much on the internet.
Grateful for your input.
BR
Niclas
2026-01-25 10:52 PM
Well, ELF files are a bit different, and more complex.
I don't think they can be merged so easily, and by hand.
If ou look at a SREC (a.k.a. S19) file OTOH, they are quite simple and line-based.
For me (us), both use cases are relevent. We publish the application alone for device updates, and a bootloader / application merge file for the PCB manufacturer.
BTW, there is even a nice tool available to do a merge from commandline, e.g. from a batch / script file : https://srecord.sourceforge.net/
2026-01-26 2:14 AM
Hi Aziz,
I'm afraid your CLI commands don't work for me. The problem is the same as described above.
---
#Erase all works (like before):
C:\"Program Files"\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe -c port=SWD -e all
-------------------------------------------------------------------
STM32CubeProgrammer v2.21.0
-------------------------------------------------------------------
ST-LINK SN : 36FF6C064D59303612251543
ST-LINK FW : V2J46S7
Board : --
Voltage : 2.93V
SWD freq : 4000 KHz
Connect mode: Normal
Reset mode : Software reset
Device ID : 0x470
Revision ID : Rev V
Device name : STM32L4Rxxx/STM32L4Sxxx
Flash size : 2 MBytes
Device type : MCU
Device CPU : Cortex-M4
BL Version : 0x95
Debug in Low Power mode enabled
Mass erase ...
Mass erase successfully achieved
----
#Program application binary doesn't work (and neither does its bootloader counterpart:
C:\"Program Files"\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe -c port=SWD mode=hotplug -w C:\SVN\XXXXX\Xxxxx_3\SW\Xxxxx3_ws\Application\Debug\Application.elf
-------------------------------------------------------------------
STM32CubeProgrammer v2.21.0
-------------------------------------------------------------------
That's all it outputs. I have also tried this with J-Link (-c port=JLINK) with the same output (which for erase is less verbose with J-Link).
===
It appears this is a bug or lack of support in STM32CubeProgrammer.
Based on previous experience:
Up until a few versions ago of CubeIDE, Debug probe ST-LINK GDB server didn't work with my flash layout. At that time I didn't have a J-Link so I don't know if that was supported and worked, but ST-LINK OpenOCD worked. At some point ST-LINK GDB server was fixed/improved, so now all three Debug probe options work.
My guess is that CubeProgrammer needs the same fix/improvement as ST-LINK GDB server.
I cannot send you our .elf files, but your colleague M B has my contact details for collaboration on further investigation and testing.
Best regards
Niclas
2026-01-26 3:30 AM
I mean CubeProgrammer _CLI_ needs the same fix/improvement as ST-LINK GDB server. _GUI_ works.
2026-01-26 7:11 AM - edited 2026-01-26 7:12 AM
Hi @NArnd,
I don't think this is a bug, I think it's just a path parsing issue.
To prove this, try running the following:
C:\"Program Files"\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe
You won't have any output because STM32_Programmer_CLI won't be properly parsed by Windows. It's a good practice to wrap the whole path containing spaces with quotes, the whole CLI becomes:
"C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe" -c port=SWD mode=hotplug -w C:\SVN\XXXXX\Xxxxx_3\SW\Xxxxx3_ws\Application\Debug\Application.elf
Let me know if this solves the issue,
Aziz
2026-01-26 7:29 AM
Hi Aziz,
This is not a parsing error.
As I wrote at the beginning of my previous post, the erase command works:
#Erase all works (like before):
C:\"Program Files"\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe -c port=SWD -e all
-
Also, had it been a parsing error, STM32_Programmer_CLI.exe wouldn't respond with
-------------------------------------------------------------------
STM32CubeProgrammer v2.21.0
-------------------------------------------------------------------
-
To humour you, I have tested
C:\"Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe" -c port=SWD mode=hotplug -w C:\SVN\SWEMA\Swema_3\SW\Swema3_ws\Application\Debug\Application.elf
and it behaves exactly like the previous syntax.
2026-01-26 7:36 AM
Hi Niclas,
Please include the C:\ in the quotes and get back to me. Or simply copy this to a CMD window and screenshot the result.
"C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe" -c port=SWD mode=hotplug -w C:\SVN\XXXXX\Xxxxx_3\SW\Xxxxx3_ws\Application\Debug\Application.elf
Thanks,
Aziz
2026-01-26 7:51 AM
FYI: To prove further that it's a parsing issue, you can test your original scripts (Without my suggested modification) in PowerShell and not Windows CMD, the CLIs will run as expected.
PowerShell
Windows CMD
Looking forward to your reply !
Aziz
2026-01-26 8:23 AM
Hi Aziz,
You are correct. This is a parsing error. Weird that the erase command was parsed correctly but not the program commands.
These commands do almost what I need:
#Erase all
"C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe" -c port=SWD -e all
#Program application binary
"C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe" -c port=SWD mode=hotplug -w C:\SVN\XXXXX\Xxxxx_3\SW\Xxxxx3_ws\Application\Debug\Application.elf
#Program bootloader binary
"C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe" -c port=SWD mode=hotplug -w C:\SVN\XXXXX\Xxxxx_3\SW\Xxxxx3_ws\Bootloader\Debug\Bootloader.elf
#Start execution
"C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe" -c port=SWD mode=hotplug -s 0x08000000The command to set RDP level to 1 (0xBB) doesn't play well with others:
#Set RDP to 1
"C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe" -c port=SWD mode=hotplug -ob RDP=0xBBI would like to set RDP to 1 and then start execution (reset). Is this combination not possible?
Are the only options to power cycle the device (unplug - replug) or to press a reset button (that is currently not in our PCB design)?
We are writing HW & identity information to the MCU OTP flash via a Java application immediately after running the above commands.
Thank you and best regards
Niclas
2026-01-26 9:11 AM
One wonders what sort of tomfoolery is going on inside STM32CubeProgrammer that it fails to parse this correctly. Is it reconstructing the path and then trying to re-parse it to get the parameters?
It is a parsing issue, but not a Windows command line parsing issue. That part works.
2026-01-26 12:56 PM
Thank you TDK,
Windows Command Prompt syntax has never been one of my areas of interest, so I was thinking maybe I had made a mistake. What an unnecessary waste of customer time...
So, now we know that it can be done and that ST is aware of their parser error. Hopefully this means that they will also fix it. (?)
-
Regarding the suspected issue with resetting the MCU after RDP is set to 1:
I'll try the following:
With my ST-Link V2 I use an Olimex adapter board to connect to the 10-pin Cortex M debug pin header on the device:
https://www.olimex.com/Products/ARM/JTAG/ARM-JTAG-20-10/
Rev C of this board has a footprint for a tactile reset switch. The Olimex product page has a photo of Rev A, but I attach a photo of Rev C.
Here is a link to a document from ARM (?) that present the various ARM-standard headers:
https://documentation-service.arm.com/static/5fce6c49e167456a35b36af1
The tactile switch is an 1185AU2 J-bent:
http://www.ilswitch.com/pdf/Tact/1185.pdf
The closest I have found that I can buy are these two (CIT CS1213BJF160 / CS1213BJF260):
https://www.digikey.se/sv/products/detail/cit-relay-and-switch/CS1213BJF160/16607697
https://www.digikey.se/sv/products/detail/cit-relay-and-switch/CS1213BJF260/16607813
I hope this will help others in a similar situation.