Skip to main content
Visitor II
April 20, 2024
Question

stm32h563 edata Code Generation issue

  • April 20, 2024
  • 1 reply
  • 1991 views

Hello,

On flash option byte I need to use only one sector. Only Edata bank1 is activate. No other option bytes are required.

CubeMx generate MX_FLASH_Init with Edata configuration commented. What other option byte is necessary to select to use Edata on bank1?

Can you help me?

target: STM32H563ZI

stm32CubeMx 6.11.0

stm32Cube MCU Package STM32H5 1.2.0

 

Regards 

1 reply

Chaima_M
ST Employee
May 3, 2024

Hello @BenoitS ,

Did you try to check the EDATA1_EN option byte using STM3CubeProgrammer?

CMAHM1_0-1714727150181.png

Associate II
May 7, 2024

Hi @Chaima_M

I have the similar question. My board is STM32H573I-DK. EData seems not be enabled after MX_FLASH_Init().

Here is the code generated by CubeMX.

 

static 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_BOTH;
 pOBInit.EDATASize = 1;
 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 */

}

 

 

I tried to access 0x0900A800 by CubeProgrammer but it showed Data read failed. 

But if checked the EDATA1_EN option by CubeProgrammer. It worked.

Is there any bug or what I missed?

P.S. I also uncommented  

/*HAL_FLASH_OB_Launch(); */

but still not worked.

Associate II
July 31, 2025

I don't know if you resolved your issue but for anyone struggling with this, the problem is that HAL_FLASH_OB_Launch() won't work after HAL_FLASH_OB_Lock(). I resolved it by adding the following function:

void USER_FLASH_LaunchOB(void)
{
 if (HAL_FLASH_Unlock() != HAL_OK)
 {
 Error_Handler();
 }
 if (HAL_FLASH_OB_Unlock() != HAL_OK)
 {
 Error_Handler();
 }
 if (HAL_FLASH_OB_Launch() != HAL_OK)
 {
 Error_Handler();
 }
 if (HAL_FLASH_OB_Lock() != HAL_OK)
 {
 Error_Handler();
 }
 if (HAL_FLASH_Lock() != HAL_OK)
 {
 Error_Handler();
 }
}

and running it after MX_FLASH_Init()