STM32u585- RDP Regression in software from RDP level 1 to RDP level 0 not working
Hello all,
Kindly guide us how to resolve the following issue or share the sample code,
We are using MCU STM32U585QII6QTR. In this TrustZone is not enabled.
We are trying to change the RDP level from 0 to level 1 and from level 1 to level 0 from software.
We are successfully able to change from RDP level 0 to RDP level 1 in software. But when we try to change the RDP level from level 1 to level 0 the regression is not happening.
The regression is not working with and without RDP regression password(OEM1KEY).
RDP level 0 to level 1 change code:
void ChangeRDPLevel(FLASH_OBProgramInitTypeDef *pOptionsBytesStruct)
{
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
pOptionsBytesStruct->OptionType = OPTIONBYTE_USER | OPTIONBYTE_RDP ; //Configure USER and RDP
// pOptionsBytesStruct->USERType = OB_USER_nBOOT0;
// pOptionsBytesStruct->USERConfig = OB_BOOT0_FROM_PIN;//Set to boot from pin (UART)
pOptionsBytesStruct->RDPLevel = 0xDC;
while(HAL_FLASHEx_OBProgram(pOptionsBytesStruct) != HAL_OK)
{
;
}
SET_BIT(FLASH->NSCR, FLASH_NSCR_OPTSTRT);
while((FLASH->NSSR & FLASH_NSSR_BSY) != 0)
{
;
}
// MX_WWDG_Init();
while(HAL_FLASH_OB_Launch()!= HAL_OK)
{
;
}
}
RDP level 1 to RDP level 0 change regression code:
void __attribute__((long_call, __section__(".RamFunc"))) RDP_Regression(void)
{
__disable_irq();
printf("\n\r Mass Erase Start \r\n");
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
while((FLASH->NSSR & FLASH_NSSR_BSY) != 0)
{
;
}
FLASH->NSKEYR = FLASH_KEY1;
FLASH->NSKEYR = FLASH_KEY2;
FLASH->OPTKEYR = FLASH_OPTKEY1;
FLASH->OPTKEYR = FLASH_OPTKEY2;
/* Force readout protection level 0 */
FLASH->OPTR |= 0xAA;
FLASH->NSCR |= FLASH_NSCR_OPTSTRT;
while((FLASH->NSSR & FLASH_NSSR_BSY) != 0)
{
;
}
printf("\n\r Force OB Load \r\n");
/* Force OB Load */
FLASH->NSCR |= FLASH_NSCR_OBL_LAUNCH;
printf("\n\r Regression Complete \r\n");
}
Thanks in Advance.
