Skip to main content
Associate II
May 29, 2024
Solved

STM32U595 - Option Bytes not being Set after STANDBY or SHUTDOWN mode

  • May 29, 2024
  • 3 replies
  • 1474 views

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

 

Best answer by Jocelyn RICARD

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

 

 

3 replies

KaiS_Author
Associate II
May 29, 2024

Btw. I also tried 

HAL_PWR_EnterSTANDBYMode();

Instead of 

HAL_PWREx_EnterSHUTDOWNMode();

but it was showing the same behaviour.

Jocelyn RICARD
Jocelyn RICARDBest answer
ST Employee
May 29, 2024

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

 

 

KaiS_Author
Associate II
May 31, 2024

Hi Jocelyn,

Thank you very much, setting

DBGMCU->CR = 0x0;

before going to STANDBY/SHUTDOWN mode actually did the trick.

Best regards