2023-10-10 06:24 AM
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?
2023-10-10 07:03 AM
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:
2023-10-11 12:52 PM
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.
2023-10-11 02:09 PM
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
2023-10-13 03:32 AM - edited 2023-10-13 03:42 AM
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.