Skip to main content
Associate III
June 15, 2026
Question

STM32U5 WRP2AR register value resets to default value and write protect is disabled

  • June 15, 2026
  • 1 reply
  • 51 views

Hi

I am implemented flash write protect on STM32U5 using option byte register FLASH_WRP2AR.
Following these steps to write protect page 0x4C and 0x4D page in Bank 2
- Unlock flash 
- Unlock Flash option register(FLASH_OPTR)
- Unlock flash page by setting UNLOCK bit(31) in FLASH_WRP2AR
- Write WRP2A_PSTRT[6:0] of  FLASH_WRP2AR with value 0x4C
- Write WRP2A_PEND[[6:0] of  FLASH_WRP2AR with value 0x4D
- Lock flash page by clearing UNLOCK bit(31) in FLASH_WRP2AR 
- Initiate option byte programming by setting OPTSTRT bit FLASH_NSCR register 
- Wait for flash operation to complete 
- Lock FLASH_OPTR register 
- Lock Flash

This sequence works some times , however most of the time  after option byte programming FLASH_WRP2AR value resets to following value and write protect is disabled.
 - WRP2A_PSTRT[6:0]: 0x7F
 - WRP2A_PEND[[6:0]: 0x00

OPTWERR bit sets in FLASH_NSSR indicating that invalid configuration, however configuration looks right.

Regards,
Hareesha 

1 reply

Jocelyn RICARD
ST Employee
June 16, 2026

Hello ​@harisuvarna ;

The unlock bit in write protection registers is not made to allow changing the configuration as you seem to use it. This bit is used to lock the configuration. You cannot unlock it like this.

First to be able to program the WRP sectors, the bit 31 should be 1. If unlock bit is 0 it means write protection is locked. To be able to change this bit back to 1 you must go through a RDP regression.

This is described in “Write protection lock” part of paragraph 7..6.1 of the reference manual RM0456 rev 7.

So, I would advise first to make sure this bit is set to 1.

Then in your code, you can first make tests without changing this bit.

Then if you want to use this unlock bit to lock the write protection in production, you can set it to 0 at the end of your programming sequence.

Best regards

Jocelyn