cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H5 and EEPROM emulation with XCUBE-EEPROM

gh_rcl
Associate II

Hi,

I'd like to have some feedback about the use of XCUBE-EEPROM library on STM32H563.
Is it functionnal and reliable ?

After digging into the code, i have few questions:

 

  • MPU_init()

In the MPU_init() function there's a configuration  with no explanation ?

/********************************************************************************/

** Initializes and configures the Region and the memory to be protected

*/

MPU_InitStruct.Number = MPU_REGION_NUMBER1;

MPU_InitStruct.BaseAddress = 0x08FFF800;

MPU_InitStruct.LimitAddress = 0x08FFF80F;

MPU_InitStruct.AccessPermission = MPU_REGION_ALL_RO;



HAL_MPU_ConfigRegion(&MPU_InitStruct);

/********************************************************************************/

 

  • num_of_edata_page

With the default settings, in the OB_init() function according to me there's a problem with the computation of num_of_edata_page.

Indeed in the code below, after each reset the HAL_FLASHEx_OBProgram() is always called.

 

/********************************************************************************/

num_of_edata_page = ((FLASH_EDATA_BASE + (FLASH_EDATA_SIZE>>1)) - START_PAGE_ADDRESS) / FLASH_PAGE_SIZE;

register_value = FLASH->EDATA2R_CUR;

edata_enable = FLASH_EDATAR_EDATA_EN;



/* If current EDATA configration is different from new configration, Reprogram Option Byte EDATA settings */

if(register_value != (edata_enable | (num_of_edata_page - 1)))

{

/* Variable used for OB Program procedure */

FLASH_OBProgramInitTypeDef FLASH_OBInitStruct;



/* Current EDATA configuration doesn't match with new configuration. */

/* Unlock the Flash option bytes to enable the flash option control register access */

HAL_FLASH_OB_Unlock();



/* Configure 8 sectors for FLASH high-cycle data */

FLASH_OBInitStruct.Banks = bank;

FLASH_OBInitStruct.OptionType = OPTIONBYTE_EDATA;

num_of_edata_page = 1;

FLASH_OBInitStruct.EDATASize = edata_enable | num_of_edata_page;



if(HAL_FLASHEx_OBProgram(&FLASH_OBInitStruct) != HAL_OK)

{

Error_Handler();

}



/* Start option byte load operation after successful programming operation */

HAL_FLASH_OB_Launch();

/********************************************************************************/
  • EDATA settings

When EDATA2_STRT=0 it means that the last sector of Bank2 that is to say

from 0x9016800 to 0x9017FFF is enabled.

 

Thanks in advance for your feedback.

Greg

 

2 REPLIES 2
Florian LR
ST Employee

Hi Greg, 

Yes in some examples coming from cube FW we use that function MPU_Init(), and as described, it configures a certain region to be protected, as RO.
Between 0x08FF F000 and 0x08FF F7FC you have the OTP words, here you're just configuring some of them as read only. Nothing to worry about. 

Regarding the num_of_edata_page, what do you think is the issue ? The page number is equal to the base address of Edata memory + the size of Edata memory - the address of the first page used, which gives you the max address value within the referential of used pages, that you divide by the page size, that gives you the total page number.

"Indeed in the code below, after each reset the HAL_FLASHEx_OBProgram() is always called."
=> This function is called only if the configuration after reset is different from the data retrieved in the registers, containing the edata configuration. So if you don't change the configuration, you don't call HAL_FLASHEx_OBProgram().

Regarding  EDATA2_STRT, it contains the start sectors of the flash high-cycle data area in Bank 2, so yes, according to the reference manual : 000: The last sector of Bank2 is reserved for flash high-cycle data.
Is there any issue there ?

 

Best Regards, 

Florian LR

 

 

Hi,
Thanks for your feedback. I will check the code provided in the X-CUBE-EEPROM library to be sure that the HAL_FLASHEx_OBProgram is called only one time.

Regards,