STM32U595 - Option Bytes not being Set after STANDBY or SHUTDOWN mode
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-29 1:01 AM - edited ‎2024-05-29 4:45 AM
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
Solved! Go to Solution.
- Labels:
-
STM32 Security
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-29 2:44 PM
Hello @KaiS_ ,
I have checked it is working fine.
What you need to make sure is that you don't have a debugger feature activated that prevents from really entering in standby mode.
This can happen if you download your code with debugger for instance.
You can check DBGMCU register for that
Best regards
Jocelyn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-29 1:57 AM
Btw. I also tried
HAL_PWR_EnterSTANDBYMode();
Instead of
HAL_PWREx_EnterSHUTDOWNMode();
but it was showing the same behaviour.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-29 2:44 PM
Hello @KaiS_ ,
I have checked it is working fine.
What you need to make sure is that you don't have a debugger feature activated that prevents from really entering in standby mode.
This can happen if you download your code with debugger for instance.
You can check DBGMCU register for that
Best regards
Jocelyn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-31 3:12 AM
Hi Jocelyn,
Thank you very much, setting
DBGMCU->CR = 0x0;
before going to STANDBY/SHUTDOWN mode actually did the trick.
Best regards
