2023-11-07 02:45 PM
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.
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;
}
}
}
Solved! Go to Solution.
2024-07-19 04:44 AM
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
2023-11-10 01:27 AM
Hello @lpfeiffer ,
I will start investigation on this matter and get to you as soon as possible.
BR
2023-11-10 05:23 AM
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
2024-07-18 11:30 AM
Hello,
This appears to still be an issue. Is there a fix for this coming?
2024-07-19 04:44 AM
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
2024-07-19 08:27 AM
Thank you for the reply.
I am using CubeMX version 6.11.1, and the information text when selecting the "Size" field of the EDATA section (in FLASH > Flash data sectors > Activate BankX EDATA) is as follows.
Parameter Description:
Bit 2:0 EDATA1_STRT[2:0]: EDATA1_STRT contains the start sectors of the Flash high-cycle data area in Bank 1.
There is no hardware effect to those bits. They shall be managed by ST tools in Flasher.
0:000: The last sector of the Bank 1 is reserved for Flash high-cycle data
1:001: The two last sectors of the Bank 1 are reserved for Flash high-cycle data
2:010: The three last sectors of the Bank 1 are reserved for Flash high-cycle data ...
7:111: The eight last sectors of the Bank 1 are reserved for Flash high-cycle data
Note: Bit 2 is reserved on 512-Kbyte product configuration
Glad to hear that this should be addressed though.