STM32U5 WRP2AR register value resets to default value and write protect is disabled
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
