2025-07-31 8:57 AM - edited 2025-07-31 8:57 AM
void MX_FLASH_Init(void)
{
/* USER CODE BEGIN FLASH_Init 0 */
/* USER CODE END FLASH_Init 0 */
FLASH_OBProgramInitTypeDef pOBInit = {0};
/* USER CODE BEGIN FLASH_Init 1 */
/* USER CODE END FLASH_Init 1 */
if (HAL_FLASH_Unlock() != HAL_OK)
{
Error_Handler();
}
/* Option Bytes settings */
if (HAL_FLASH_OB_Unlock() != HAL_OK)
{
Error_Handler();
}
pOBInit.OptionType = OPTIONBYTE_EDATA;
pOBInit.Banks = FLASH_BANK_2;
pOBInit.EDATASize = 2;
if (HAL_FLASHEx_OBProgram(&pOBInit) != HAL_OK)
{
Error_Handler();
}
if (HAL_FLASH_OB_Lock() != HAL_OK)
{
Error_Handler();
}
if (HAL_FLASH_Lock() != HAL_OK)
{
Error_Handler();
}
/* Launch Option Bytes Loading */
/*HAL_FLASH_OB_Launch(); */
/* USER CODE BEGIN FLASH_Init 2 */
/* USER CODE END FLASH_Init 2 */
}
2025-08-27 7:52 AM - edited 2025-08-27 7:53 AM
Hello @continuum;
Could you please try with sequence and let me know if the issue is solved or not?
if (HAL_FLASHEx_OBProgram(&FLASH_OBInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Start option byte load operation after successful programming operation */
HAL_FLASH_OB_Launch();
/* Lock the Flash to disable the flash control register access (recommended
to protect the FLASH memory against possible unwanted operation)
*/
HAL_FLASH_Lock();
/* Lock the Flash control option to restrict register access */
HAL_FLASH_OB_Lock();
Also, I recommend you to look at STM32CubeH5/Projects/NUCLEO-H563ZI/Examples/FLASH/FLASH_EDATA_EraseProgram at main · STMicroelectronics/STM32CubeH5 · GitHub example may help you to check your code.
I hope this help you.
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.