cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G030 and X-CUBE-EEPROM

Lgarb.1
Associate II

Hi, I'm trying to use https://www.st.com/en/embedded-software/x-cube-eeprom.html on my custom stm32g030 board.

Following the examples I write this code:

 

 

  HAL_FLASH_Unlock();

  ee_status = EE_Init(EE_FORCED_ERASE);
  if(ee_status != EE_OK) {
	  Error_Handler();
  }


  VarValue = 3;
  for (Index = 1; Index < NB_OF_VARIABLES+1; Index++)
  {
	  ee_status = EE_WriteVariable32bits(Index, Index*VarValue);
	  /* Start cleanup polling mode, if cleanup is needed */
	  if ((ee_status & EE_STATUSMASK_CLEANUP) == EE_STATUSMASK_CLEANUP) {ErasingOnGoing = 0;ee_status|= EE_CleanUp();}
	  if ((ee_status & EE_STATUSMASK_ERROR) == EE_STATUSMASK_ERROR) {Error_Handler();}
  }

  for (uint8_t idx = 0; idx < NB_OF_VARIABLES; idx++)
  {
	  // Virtual address arranca en 1
	  ee_status = EE_ReadVariable32bits(idx+1, &VarValue);
	  if (ee_status != EE_OK) {Error_Handler();}
  }

  /* Lock the Flash Program Erase controller */
  HAL_FLASH_Lock();

 

 

I unlock the flash, the Init the EE emulation, write 10 variables (check if a cleanup is required), then read back the values.

This works ok. After running this code a couple of time I get:

Lgarb1_0-1735511572087.png

I'm not sure why I have 4*32 bits with 0xFFFFFFFF on 0x08007810.

Then I get 16 bits VA (0001) 16 bits CRC (80E01) and 32 bits value 00000003.

Then I want to try to read data after power off. So I comment back writing operations, flash the code and connect with STM32 Programmer to read the data. I get the following:

Lgarb1_1-1735512281721.png

each time I re-connect the programmer (and so a reset is made) 2x32 bits 0's are written into the flash. It's come from ee_status = EE_Init(EE_FORCED_ERASE); calling that is forcing the write of those 0's. I've tried with EE_CONDITIONAL_ERASE but the same happens.

My configuration is as follow:

 

 

/* Configuration of eeprom emulation in flash, can be custom */
#define START_PAGE_ADDRESS      (FLASH_BASE + (14 * FLASH_PAGE_SIZE)) //0x08080000U /*!< Start address of the 1st page in flash, for EEPROM emulation */
#define CYCLES_NUMBER           1U   /*!< Number of 10Kcycles requested, minimum 1 for 10Kcycles (default),
                                        for instance 10 to reach 100Kcycles. This factor will increase
                                        pages number */
#define GUARD_PAGES_NUMBER      0U   /*!< Number of guard pages avoiding frequent transfers (must be multiple of 2): 0,2,4.. */

/* Configuration of crc calculation for eeprom emulation in flash */
#define CRC_POLYNOMIAL_LENGTH   LL_CRC_POLYLENGTH_16B /* CRC polynomial lenght 16 bits */
#define CRC_POLYNOMIAL_VALUE    0x8005U /* Polynomial to use for CRC calculation */

 

 

Any help will be appreciated.

0 REPLIES 0