Skip to main content
Associate
October 10, 2023
Question

HAL_FLASH_OB_Launch causes hang and needs power cycle to accept option bytes

  • October 10, 2023
  • 4 replies
  • 4193 views

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?

This topic has been closed for replies.

4 replies

TDK
October 10, 2023

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""."
Associate
October 11, 2023

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
Principal III
October 11, 2023

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 Technical Moderator
October 13, 2023

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 "Best answer" on the reply which solved your issue or answered your question.