Skip to main content
Graduate
February 24, 2025
Question

STM32U575 flash write often fails due to OPTWERR but I'm not writing the option bytes.

  • February 24, 2025
  • 1 reply
  • 407 views

The memory I'm writing is 16-byte aligned (both flash destination and RAM source) and a multiple of 16 bytes in length. Using HAL to write the flash. Writing the first quadword fails with the error OPTWERR. This is quite unexpected since I am not, as far as I know, doing anything with option bytes.

The data a sizeable chunk of just over 2KB (falling within an 8KB page), but it fails on the first quadword anyway. The context is storing a user-modifiable look up table to support a UI. We use two pages as a simulated EEPROM.

The code is basically just __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS), HAL_FLASH_Unlock(), HAL_FLASH_Program() in a loop, HAL_FLASH_Lock().  Inside HAL_FLASH_Program(), there are calls to FLASH_WaitForLastOperation(), FLASH_Program_QuadWord(), FLASH_WaitForLastOperation() - again. The second call to FLASH_WaitForLastOperation() is where the OPTWERR bit is set for some reason.

Any insight would be greatly appreciated.

    This topic has been closed for replies.

    1 reply

    Graduate
    February 24, 2025

    Ah. I minuderstood. That isn't the error. I'll investigate further.