cancel
Showing results for 
Search instead for 
Did you mean: 

RDP erase bricking STM32F103, can't keep testing because I can't get more processors, help?

AThom.3
Associate

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;

}

}

1 REPLY 1
TDK
Guru

Look at and copy the logic within HAL_FLASHEx_OBProgram/FLASH_OB_RDP_LevelConfig.

https://github.com/STMicroelectronics/STM32CubeF1/blob/f5aaa9b45492d70585ade1dac4d1e33d5531c171/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c#L886

If you feel a post has answered your question, please click "Accept as Solution".