2024-10-23 12:06 PM
I'm trying to flash my custom STM32L152RET6 board using the command-line version of CubeProgrammer. Initially, everything seemed fine, but I wanted to ensure the firmware couldn't be read out. So, I set the option bytes with -ob RDP=1 to enable read protection. However, after doing this, the flashing process failed, and now my program no longer runs.
I was able to flash it again using a Segger debugger, but when I try to run the program, it crashes at startup. The voltages all seem normal, so I don't suspect a hardware issue. Could this be due to some incorrectly set registers or option bytes in the CPU?
Here’s the command I used:
STM32_Programmer_CLI.exe -c port=usb1 -ob RDP=1 -d firmware.hex -v
Any advice would be greatly appreciated!
Solved! Go to Solution.
2024-10-30 11:45 PM
I fixed the broken PCB, when I looked in the Cube programmer GUI the option byte nBFB2 was not set so it would boot from bank2. When enable this option and also did a full chip erase everything was working just fine !
Why I could still flash it with the segger debugger (in bank 1 ?) and the program would still go to the main , but then only crashed when it wanted to init the HAL is still a mystery to me.
2024-10-23 03:04 PM
Your app running on the STM32 should be able to print out content/state of FLASH and/or OB
Check it it write protects the base sectors.
Usually you can clear these with a Mass Erase, or walked in via the UART connection to the System Boot Loader.
As you say Segger also has an un-brick app.
Can you use ST-LINK via SWDIO/SWCLK ? To connect/inspect?
2024-10-24 05:55 AM
Try reverting the RDP level back to RDP=0 (no read protection) and see if your program starts running properly. You can do this by issuing the following command:
STM32_Programmer_CLI.exe -c port=usb1 -ob RDP=0
Look for any unexpected settings, particularly those related to:
2024-10-24 09:48 AM
Yes I can just debug no problem. But when it inits the HAL driver it gives an exception and crashes
2024-10-24 09:51 AM
That is a good one I will try indeed the -ob RDP=0 option !
But what I do not understand is that the Segger SWD can just write new flash code. So its not write protected anymore. Or the Segger ignores the protection bits ?
2024-10-30 11:45 PM
I fixed the broken PCB, when I looked in the Cube programmer GUI the option byte nBFB2 was not set so it would boot from bank2. When enable this option and also did a full chip erase everything was working just fine !
Why I could still flash it with the segger debugger (in bank 1 ?) and the program would still go to the main , but then only crashed when it wanted to init the HAL is still a mystery to me.