2018-05-14 11:27 AM
Hi all,
I'm trying to get ROP enabled by my bootloader.
This function is run first up by main().
I'm finding that it get stuck in a loop, as ROP never seems to become enabled (always reads back as being set at level 0).
Any ideas what im doing wrong here?
Thanks.
void BL_ROPL1(){ FLASH_OBProgramInitTypeDef OBInit; //check ROP status HAL_FLASHEx_OBGetConfig(&OBInit); if (OBInit.RDPLevel == OB_RDP_LEVEL_0) { //no read out protection is active, enable it OBInit.OptionType = OPTIONBYTE_RDP; OBInit.RDPLevel = OB_RDP_LEVEL_1;HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock(); HAL_FLASHEx_OBProgram(&OBInit); HAL_FLASH_OB_Lock(); HAL_FLASH_OB_Launch(); NVIC_SystemReset(); //shouldnt get to here }}#rop #security #stm32 #stm32f401 #protection2018-05-14 11:39 AM
You should perhaps unlock the Flash/OB first, and pay attention to status returned.
2018-05-15 10:27 AM
Okay, here is the full thing.
All i ever see is a flickering green LED (flickering due to the boot loop).
Never a red LED indicating an issue.
void
BL_Flash_Protect() {#ifndef BL_DONT_PROTECT
FLASH_OBProgramInitTypeDef OBInit;//get ROP status
if
(HAL_FLASH_Unlock() != HAL_OK)goto
ferror;if
(HAL_FLASH_OB_Unlock() != HAL_OK)goto
ferror; HAL_FLASHEx_OBGetConfig(&OBInit);if
(OBInit.RDPLevel == OB_RDP_LEVEL_0) {//no read out protection is active
//disable flash read out to external devices
LL_GPIO_SetOutputPin(LED3_GRN_PIN); OBInit.OptionType = OPTIONBYTE_RDP; OBInit.RDPLevel = OB_RDP_LEVEL_1;if
(HAL_FLASHEx_OBProgram(&OBInit) != HAL_OK)goto
ferror; HAL_FLASH_OB_Lock(); HAL_FLASH_Lock(); HAL_FLASH_OB_Launch();//restarts
NVIC_SystemReset();//shouldnt get to here
} HAL_FLASH_OB_Lock(); HAL_FLASH_Lock();return
; ferror:while
(1) { LL_GPIO_SetOutputPin(LED3_RED_PIN); __BKPT(0); }#endif
}2018-05-15 12:06 PM
Solved!
I misunderstood the function of HAL_FLASH_OB_Launch().
The correct working order is:
HAL_FLASHEx_OBGetConfig(&OBInit);
OBInit.OptionType = OPTIONBYTE_RDP;
OBInit.RDPLevel = OB_RDP_LEVEL_1;HAL_FLASH_OB_Unlock();
HAL_FLASH_Unlock();
HAL_FLASHEx_OBProgram(&OBInit);
HAL_FLASH_OB_Launch();
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();NVIC_SystemReset();