2023-12-13 04:45 AM
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.
Solved! Go to Solution.
2023-12-15 05:58 AM
Hello @Surya S ,
first, there is no need to execute regression from RAM.
Secondly, in your regression function you first call
unlock functions and then do the same by writing directly in registers: This will put flash in a state where you cannot to anything. Only one unlock is required.
Best regards
Jocelyn
2023-12-15 05:58 AM
Hello @Surya S ,
first, there is no need to execute regression from RAM.
Secondly, in your regression function you first call
unlock functions and then do the same by writing directly in registers: This will put flash in a state where you cannot to anything. Only one unlock is required.
Best regards
Jocelyn
2023-12-15 06:28 AM
Hello @Surya S and welcome to ST Community ,
Note that unlocking the device with a password is only possible once per power cycle.
more details can be found on this in this article and this presentation .
BR
2023-12-15 05:33 PM
Your article link doesn't work...
2023-12-20 06:53 AM
Hello @Piranha ,
Indeed the link does not work because it's under maintenance here's the block diagram that i wanted to refer to :
the same information could be found in details in RM 0456 section 3.10.1 Life-cycle management with readout protection (RDP).
BR