2022-08-15 01:16 PM
I’ve been struggling with setting up RDP Level 1 on my STM32G473CBT6.
This project does not use the system bootloader. The BOOT0 pin is held low and it boots from FLASH using our own bootloader.
I have code in place to accept a command to program RDP Level 1. It is fairly simple:
if(HAL_FLASH_Unlock() != HAL_OK){
return;
}
if(HAL_FLASH_OB_Unlock() != HAL_OK){
HAL_FLASH_Lock();
return;
}
FLASH_OBProgramInitTypeDef ob_prog = {.OptionType = OPTIONBYTE_RDP, .RDPLevel = OB_RDP_LEVEL1};
HAL_FLASHEx_OBProgram(&ob_prog);
/* This call should reset the MCU. */
(void)HAL_FLASH_OB_Launch();
The problem is the MCU is non-functional after performing this operation. I have no way to know what is going on because I can’t debug at RDP Level 1. I have confirmed the Option Bytes are set as expected using STM32CubeProgrammer (RDP Level 1 is set). Power cycling and unplugging the ST-LINK does not work. The only recovery is to revert to Level 0 via ST-LINK and re-flash.
To eliminate the possibility of my code being the problem, I have programmed RDP Level 1 via ST-LINK and got the same results. The other Option Bytes are at their default values.
2022-08-16 12:35 PM
You may need to resort to classic debugging techniques: Toggle GPIOs, output to UART, etc. Specially in your bootloader so you can follow its progress.
Might also try CubeProgrammer instead of STLink.
2022-08-16 03:15 PM
Without being able to get BOOT0 HIGH, you're not going to be able to walk it out via a USART and the ROM Based System Loader..
Segger / J-Link may offer more options/recovery methods, although not used in some time, and not for G4's
Should probably practice on a NUCLEO, or some other board that's actually accessible when tinkering with such functionality initially.
2022-08-16 03:36 PM
It is simple enough to recover from the error state. Since I'm only setting RDP Level 1, it is still possible to connect via ST-LINK with the STM32CubeProgrammer. I can reprogram the Option Bytes and re-flash.
Just not sure where the processor goes. I'll see if I can reproduce on a NUCLEO.
I've been through this with an H7. Completely different animal (but works as expected).
2022-08-16 03:47 PM
My expectation is that you'd need to cycle power after setting in this mode.
Perhaps add code in Reset Handler to toggle GPIO's or output to a UART, confirming some level of life.