Skip to main content
Visitor II
November 7, 2023
Solved

STM32H563 EDATA Size - Code Generation Issue

  • November 7, 2023
  • 2 replies
  • 2369 views

Hello,

I am using the Cube Code Generator, within the STM32CubeIDE (version 1.13.1) for an STM32H563, and have configured the Flash Data Sectors to use the maximum 8 sectors per bank for EDATA. The valid range for the EDATA sector size is 0 - 7, as shown below. I believe there is a bug within the generated code for the EDATA sector size.

STM32CubeIDE Code Generation EDATA Size RangeSTM32CubeIDE Code Generation EDATA Size Range

When I choose the maximum value of 7, and follow it through the generated MX_FLASH_Init() function, I am finding that the resulting sector size that is written to the FLASH->EDATA1R_PRG and FLASH->EDATA2R_PRG registers is 1 less than what I would expect. This is because the FLASH_OB_EDATAConfig() function subtracts 1 from the EDATASize that is passed in. I have temporarily patched this by adding 1 to the EDATASize generated in MX_FLASH_Init().

 

Code snippets added below for context.

Generated MX_FLASH_Init function:

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 = 7;
 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 */

}

 

FLASH_OB_EDATAConfig function within the STM32H5xx HAL library:

/**
 * @brief Configure the Flash high-cycle area.
 *
 * @PAram Banks specifies the bank where to apply Flash high-cycle data area
 * This parameter can be one of the following values:
 * @arg FLASH_BANK_1: configure Flash high-cycle area on bank1
 * @arg FLASH_BANK_2: configure Flash high-cycle area on bank2
 * @arg FLASH_BANK_BOTH: configure Flash high-cycle area on both bank1 and bank2
 *
 * @PAram EDATASize specifies the size (in sectors) of the Flash high-cycle data area
 * This parameter can be sectors number between 0 and 8
 *
 * @retval None
 */
static void FLASH_OB_EDATAConfig(uint32_t Banks, uint32_t EDATASize)
{
 /* Check the parameters */
 assert_param(IS_FLASH_BANK(Banks));
 assert_param(IS_FLASH_EDATA_SIZE(EDATASize));

 if (EDATASize != 0U)
 {
 /* Write EDATA registers */
 if ((Banks & FLASH_BANK_1) == FLASH_BANK_1)
 {
 /* Configure Flash high-cycle data for bank 1 */
 FLASH->EDATA1R_PRG = (FLASH_EDATAR_EDATA_EN | (EDATASize - 1U));
 }

 if ((Banks & FLASH_BANK_2) == FLASH_BANK_2)
 {
 /* Configure Flash high-cycle data for bank 2 */
 FLASH->EDATA2R_PRG = (FLASH_EDATAR_EDATA_EN | (EDATASize - 1U));
 }
 }
 else
 {
 /* Write EDATA registers */
 if ((Banks & FLASH_BANK_1) == FLASH_BANK_1)
 {
 /* de-activate Flash high-cycle data for bank 1 */
 FLASH->EDATA1R_PRG = 0U;
 }

 if ((Banks & FLASH_BANK_2) == FLASH_BANK_2)
 {
 /* de-activate Flash high-cycle data for bank 2 */
 FLASH->EDATA2R_PRG = 0U;
 }
 }
}

 

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

    Hello @skygreenslade ,

    this was fixed by adding a note in CubeMX version 6.11 by adding the following note in the description :

    0: Disable all EDATA sectors.
    1: The last sector is reserved for flash high-cycle data.
    2: The two last sectors are reserved for flash high-cycle data.
    3: The three last sectors are reserved for flash high-cycle data
    4: The four last sectors is reserved for flash high-cycle data.
    5: The five last sectors are reserved for flash high-cycle data.
    6: The six last sectors are reserved for flash high-cycle data.
    7: The seven last sectors are reserved for flash high-cycle data.
    8: The eight last sectors are reserved for flash high-cycle data.

    Regards

     

    2 replies

    ST Employee
    November 10, 2023

    Hello @lpfeiffer ,

    I will start investigation on this matter and get to you as soon as possible.

    BR 

    ST Employee
    November 10, 2023

    Hello @lpfeiffer ,

    i confirm this issue, the HAL function

    FLASH_OB_EDATAConfig

    is not aligned with the CubeMX HAL option bytes settings this has been reported  internally. 

    Internal ticket number: 166051 (This is an internal tracking number and is not accessible or usable by customers).

    BR 

    Visitor II
    July 18, 2024

    Hello,

    This appears to still be an issue. Is there a fix for this coming?

     

    STeaAnswer
    ST Employee
    July 19, 2024

    Hello @skygreenslade ,

    this was fixed by adding a note in CubeMX version 6.11 by adding the following note in the description :

    0: Disable all EDATA sectors.
    1: The last sector is reserved for flash high-cycle data.
    2: The two last sectors are reserved for flash high-cycle data.
    3: The three last sectors are reserved for flash high-cycle data
    4: The four last sectors is reserved for flash high-cycle data.
    5: The five last sectors are reserved for flash high-cycle data.
    6: The six last sectors are reserved for flash high-cycle data.
    7: The seven last sectors are reserved for flash high-cycle data.
    8: The eight last sectors are reserved for flash high-cycle data.

    Regards