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.
2025-09-12 8:19 AM
Hello @continuum ;
Any update about the issue?
If your issue is solved, please click on Accept as Solution on the reply which solved your issue.
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.
2025-09-29 5:31 AM
Hi @KDJEM.1
Your solution probably works. I had it already figured out. My problem is how CubeMX generates the code. The commented out line with
HAL_FLASH_OB_Launch
suggests that uncommenting this should apply option bytes which is not the case. Also, there is no user code block before HAL_FLASH_Lock where the user can place this line.
2025-09-29 6:29 AM
Hello @continuum ;
I reported the STM32CubeMX issue internally for checking and fixing.
Internal ticket number is reported : 218539 (This is an internal tracking number and is not accessible or usable by customers).
Thank you for reporting this issue and for your contribution in STCommunity.
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.