cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_FLASH_OB_Launch causes hang and needs power cycle to accept option bytes

nick_stoughton
Associate

We want to be able to set the RDP bytes to level 1 (read protect, but fallback allowed) via software for production. The device in question is based on an STMF723 and will be battery powered and fully assembled at the point where this protection needs to be applied on the production line.

I have the following function to set the option bytes:

    HAL_FLASH_Unlock();
    HAL_FLASH_OB_Unlock();
    watchdog_feed();
    HAL_FLASHEx_OBGetConfig(&flash_init);
    // 0 for no lock, 1 for upgradeable lock, 2 for permanent lock
    flash_init.RDPLevel = OB_RDP_LEVEL_1;
    HAL_FLASHEx_OBProgram(&flash_init);

    HAL_FLASH_OB_Launch();
    // the Launch function will cause a reset if it works
    // if we get here, it failed

    HAL_FLASH_OB_Lock();
    HAL_FLASH_Lock()

However, at the point where I "launch", the chip hangs and must be fully power cycled. At that point the read protect has worked, but this is not a possible step in production. Is there any way to set the RDP level without requiring a power cycle?

4 REPLIES 4
TDK
Guru

You can set RDP without resetting the chip. Also note that HAL_FLASH_OB_Launch doesn't reset the chip if it works. The watchdog may be complicating things here. I'd disable it until you get the code working.

See this example code for most of what you're trying to do:

https://github.com/STMicroelectronics/STM32CubeF7/blob/043626d52e34ee8146588bae597513398683e329/Projects/STM32F723E-Discovery/Examples/FLASH/FLASH_PcropProtection/Src/main.c#L125

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

Thanks @TDK . I figured out in the end that if there is a debugger (ST-Link) attached the chip will hang until power cycle. In fact, you have to remove the debugger and power cycle, then everything worked as expected.

Piranha
Chief II

In some scenarios it's better to enter Standby or Shutdown mode than executing the option byte "launch". And in some other cases one can implement this workaround:

https://community.st.com/t5/stm32-mcus-products/stm32h7-rdp-without-por/td-p/581180

KDJEM.1
ST Employee

Hello @nick_stoughton ,

This  is caused by an set one internal flag to one indicating that debugging link was uses. If you are in RDP level 1 and this flag is set, the flash is locked.

In this case, this flag is unfortunately only reset by power on Reset or transition from standby state. To solve the issue please replace the HAL_FLASH_OB_Launch by a transition from standby. Please take a look to this video  .

Thank you.

Kaouthar

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.