cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H563 EDATA Size - Code Generation Issue

lpfeiffer
Associate

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;
    }
  }
}

 

2 REPLIES 2
STea
ST Employee

Hello @lpfeiffer ,

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

BR 

In order 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.
STea
ST Employee

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 

In order 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.