2021-05-23 12:06 AM
Hi,
Trying to turn on RDP just before I get a product out to market. Can unlock and erase Option RDP bits to 0xFFFF but cannot seem to write the option bit to set RDP byte to 0x00FF. This leaves the devices bricked on the next reboot. Can't erase debug or program with SWD.
I have looked at app notes on website and followed the instructions on the RDP programming but not sure where to go from here, I can't afford to brick any more as we are all aware that I cannot source anymore processors until Q1 2022. See code below. The last lines doesn't work?
if((FLASH->OBR & FLASH_OBR_RDPRT_Msk) == 0) //Flash RDP not set
{
FLASH->KEYR = FLASH_OPTKEY1;
FLASH->KEYR = FLASH_OPTKEY2;
FLASH->OPTKEYR = FLASH_OPTKEY1;
FLASH->OPTKEYR = FLASH_OPTKEY2;
if(FLASH->CR & FLASH_CR_OPTWRE_Msk) //Check to see if option write protect off
{
FLASH->CR |= FLASH_CR_OPTER;
FLASH->CR |= FLASH_CR_STRT;
while(FLASH->SR & FLASH_SR_BSY) {;}
FLASH->CR &= ~FLASH_CR_OPTER;
FLASH->CR |= FLASH_CR_OPTPG;
OB->RDP = 0x00FF;
}
}
2021-05-23 07:37 AM
Look at and copy the logic within HAL_FLASHEx_OBProgram/FLASH_OB_RDP_LevelConfig.