STM32U595 - Option Bytes not being Set after STANDBY or SHUTDOWN mode
Hello,
I have a use-case with a soldered battery, which I can not power-cycle after programming, however I have to set option bytes to restrict Flash reading.
I found online that going into STANDBY mode or rather, returning from STANDBY mode, would update the option bytes. However, the option bytes are not set. Here is the relevant code block:
#if !defined(BOOTLOADER_DISABLE_AUTOLOCK)
// Auto-enable RDP level 1 (JTAG readout protection)
FLASH_OBProgramInitTypeDef option_bytes;
HAL_FLASHEx_OBGetConfig(&option_bytes);
if (option_bytes.RDPLevel != OB_RDP_LEVEL_1) {
printf("Incorrect RDP level detected, auto locking\n");
if (HAL_FLASH_Unlock() != HAL_OK) {
goto option_byte_panic;
}
if (HAL_FLASH_OB_Unlock() != HAL_OK) {
goto option_byte_panic;
}
option_bytes = (FLASH_OBProgramInitTypeDef) {
.OptionType = OPTIONBYTE_RDP,
.RDPLevel = OB_RDP_LEVEL_1
};
if (HAL_FLASHEx_OBProgram(&option_bytes) != HAL_OK) {
goto option_byte_panic; // Freeze
}
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_CLEAR_FLAG(PWR_WAKEUP_FLAG7);
HAL_PWREx_EnterSHUTDOWNMode();
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
goto option_byte_success;
option_byte_panic:
while(1);
option_byte_success:
}
#endif
. Pressing a button on the device will trigger WKUP7.
I verified that the devices goes to STANDBY and is woken up correctly by pressing the button. However, looking at the device using STM32CubeProgrammer, I can still see the option bytes being set to AA.
How can I resolve this issue?
Best regards
