Skip to main content
Associate III
November 30, 2023
Solved

STM32H5 HAL_FLASHEx_OBGetConfig gives incorrect EDATASize

  • November 30, 2023
  • 1 reply
  • 1815 views

When I configure 8 EDATA sectors with

FLASH_OBInitStruct.OptionType = OPTIONBYTE_EDATA;
FLASH_OBInitStruct.Banks = FLASH_BANK_1;
FLASH_OBInitStruct.EDATASize = 8;
HAL_FLASHEx_OBProgram(&FLASH_OBInitStruct);

 

and then I read the result:

 

FLASH_OBInitStruct.Banks = FLASH_BANK_1;
HAL_FLASHEx_OBGetConfig(&FLASH_OBInitStruct);

The FLASH_OBInitStruct.EDATASize member has the value 3.

 

This is caused by two issues:

In CMSIS/Device/stm32h563xx.h (and 562xx, 573xx and 503xx as well)

#define FLASH_EDATAR_EDATA_STRT_Msk (0x3UL << FLASH_EDATAR_EDATA_STRT_Pos) /*!< 0x00000003 */

while according to the datasheets this field is 3 bits wide:

PieterG_0-1701332072748.png

I've changed the mask to 0x7.

Now when I read EDATASize, I get the value of 7 (instead of 8).

This is because FLASH_OB_EDATAConfig uses EDATASize - 1, but FLASH_OB_EDATAConfig fails to add 1 to the result.

I've modified FLASH_OB_GetEDATA to add 1 to EDATASize, and also made a check on FLASH_EDATAR_EDATA_EN to avoid that zero FLASH_EDATAR_EDATA_STRT would result in EDATASize being 1:

/* Get configuration of secure area */
if (regvalue & FLASH_EDATAR_EDATA_EN)
{
  *EDATASize = (regvalue & FLASH_EDATAR_EDATA_STRT) + 1;
}

instead of what is currently used:

/* Get configuration of secure area */
*EDATASize = (regvalue & FLASH_EDATAR_EDATA_STRT);

 

Do you think these changes are correct, and if so, could you please apply them to STM32CubeH5?

This topic has been closed for replies.
Best answer by FBL

Hello @PieterG 


Thank you to bring this issue to our attention. An internal ticket 167670 is submitted to update CubeH5.  

1 reply

FBLBest answer
Technical Moderator
November 30, 2023

Hello @PieterG 


Thank you to bring this issue to our attention. An internal ticket 167670 is submitted to update CubeH5.  

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL