cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB55 - Change RDP level without POR

sstel.1
Associate II

Hi,

I am currently trying to change RDP level via firmware without a power reset (POR) on a NUCLEO-WB55RG (STM32WB55). 

I am facing the problem that after changing the RDP level a power reset is necessary. Without a power reset the device seems to get stuck/frozen. I tried to upgrade the RDP level 0->1 and downgrade 1->0 but both did not work without a power reset.

I found a youtube guide how RDP level can be changed without POR but it was addressed to STML4 family:

https://www.youtube.com/watch?v=f7vs0NwZPFo&ab_channel=STMicroelectronics

I tried to adapt the code for STM32WB55 but without success:

void ChangeRDPLevel()

{

  FLASH_OBProgramInitTypeDef tFLASH_OB = { 0x00 };

  // Check if flash is unprotected

  if ((FLASH->OPTR & FLASH_OPTR_RDP) == OB_RDP_LEVEL_0)

  {

    // Unlock the FLASH control register access

    HAL_FLASH_Unlock();

    // Unlock the option bytes block access

    HAL_FLASH_OB_Unlock();

    // Read option bytes

    HAL_FLASHEx_OBGetConfig(&tFLASH_OB);

    // Set RDP level

    tFLASH_OB.OptionType = OPTIONBYTE_RDP;

    tFLASH_OB.RDPLevel = OB_RDP_LEVEL_1;

    // Set PRCROP_RDP bit (needed when RDP level set to 1)

    // Bit ensures, that flash is cleared when RDP level is decreased

    tFLASH_OB.OptionType |= OPTIONBYTE_PCROP;

    tFLASH_OB.PCROPConfig = OB_PCROP_RDP_ERASE;

    // Program option bytes

    HAL_FLASHEx_OBProgram(&tFLASH_OB);

    // Launch the option byte loading

    //HAL_FLASH_OB_Launch(); -> do NOT use launch because a power reset is necessary after RDP level change

    HAL_SuspendTick();

    HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);

    /*## Clear all related wakeup flags ########################################*/

    /* Clear PWR wake up Flag */

    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

    /* Clear RTC Wake Up timer Flag */

    __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);

    /*## Setting the Wake up time ##############################################*/

    HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 2000, RTC_WAKEUPCLOCK_RTCCLK_DIV16);

    Activate_RDP_1_Go_to_Standby();

    /**********************************************************************/

    // *** DEVICE SHOULD RESET HERE **** //

    /**********************************************************************/

    // Locks the option bytes block access

    HAL_FLASH_OB_Lock();

    // Lock the FLASH control register access

    HAL_FLASH_Lock();

  }

}

__RAM_FUNC void Activate_RDP_1_Go_to_Standby(void)

{

  // HAL_FLASH_OB_Launch();

  SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH);

  //HAL_PWR_EnterSTANDBYMode;

  MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_LOWPOWERMODE_STANDBY);

  /* Set SLEEPDEEP bit of Cortex System Control Register */

  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));

  /* This option is used to ensure that store operations are completed */

  /* Request Wait For Interrupt */

  __WFI();

}

Any ideas how i can change RDP level without POR?

Thanks!

3 REPLIES 3
Bubbles
ST Employee

Hi @sstel.1​,

is the debug probe attached while you are doing this?

Since the RDP affects the debug interface and the debug interface is active even during reset, the MCU needs POR to change the RDP. If you try without debugger attached, normal reset (OBL_LAUNCH) should be fine.

BR,

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

sstel.1
Associate II

Hi @JHOUD​ 

Yes, I have also tried it without a debug probe attached but the result was identical. Without a power reset the device was not answering anymore after changing RDP level.

With "no debug probe" I mean that I have changed JP1 (open: USB_STL, close: USB_MCU) and powered the device via USB_USER instead of USB_STLINK.

Bubbles
ST Employee

There may also be a dependency on the CPU2 FW installed. How is the second core provisioned in your application?

BR,

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.