cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f405RG eeprom emulation

TCash.1
Associate III

Hello All,

I am trying to get eeprom emulation working on a stm32f405RG**.

I created a new simple project in STM32CubeIde using the eeprom code from the stm32f4cubeide packages. specifically I am using the code from STM32Cube_FW_F4_V1.25.0\Projects\STM32F401RE-Nucleo\Applications\EEPROM\EEPROM_Emulation

however I keep getting an error from the EE_Init() function below:

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
  /* Unlock the Flash Program Erase controller */
 HAL_FLASH_Unlock();
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  //MX_SPI2_Init();
  //MX_TIM3_Init();
  //MX_SPI3_Init();
  //MX_TIM4_Init();
  //MX_TIM5_Init();
  //MX_TIM8_Init();
  //MX_USART3_UART_Init();
  //MX_TIM2_Init();
  //MX_ADC1_Init();
  //MX_USART1_UART_Init();
  /* USER CODE BEGIN 2 */
 
 
  /* EEPROM Init */
  if( EE_Init() != EE_OK)
  {
    Error_Handler();
  }

I setup my virtual addresses the same as in the example:

uint16_t VirtAddVarTab[NB_OF_VAR] = {0x5555, 0x6666, 0x7777};
uint16_t VarDataTab[NB_OF_VAR] = {0, 0, 0};
uint16_t VarValue,VarDataTmp = 0;

I suspect it could be a problem because the code was made for STM32F401RE. But I think it should be similar....

Any Ideas or help would be appreciated.

Thanks,

Trevor

4 REPLIES 4
KnarfB
Principal III

What is the error code? If you debug-step into EE_Init(), do you see what causes the error? When you ported to the other chip: did you check RAM+Flash sizes and layout in the linker file?

TCash.1
Associate III

Hi KnarfB,

Here is my linker file MEMORY layout (STM32F405RGTX_FLASH.ld):

MEMORY
{
  RAM (xrw)               : ORIGIN = 0x20000000, LENGTH = 128K
  CCMRAM (rw)             : ORIGIN = 0x10000000, LENGTH = 64K
  FLASH_BOOT (rx)         : ORIGIN = 0x8000000, LENGTH = 32k
  EMULATED_EEPROM (rwx)   : ORIGIN = ORIGIN(FLASH_BOOT) + LENGTH(FLASH_BOOT), LENGTH = 32k
  FLASH (rx)              : ORIGIN = ORIGIN(EMULATED_EEPROM) + LENGTH(EMULATED_EEPROM), LENGTH = 1024k - LENGTH(FLASH_BOOT) - LENGTH(EMULATED_EEPROM)
}

EE_Init() is returning 128(dec) (PAGE_FULL), line 22 in the below snippit:

else /* Page0 valid, Page1 receive */
      {
        /* Transfer data from Page0 to Page1 */
        for (VarIdx = 0; VarIdx < NB_OF_VAR; VarIdx++)
        {
          if ((*(__IO uint16_t*)(PAGE1_BASE_ADDRESS + 6)) == VirtAddVarTab[VarIdx])
          {
            x = VarIdx;
          }
          if (VarIdx != x)
          {
            /* Read the last variables' updates */
            ReadStatus = EE_ReadVariable(VirtAddVarTab[VarIdx], &DataVar);
            /* In case variable corresponding to the virtual address was found */
            if (ReadStatus != 0x1)
            {
              /* Transfer the variable to the Page1 */
              EepromStatus = EE_VerifyPageFullWriteVariable(VirtAddVarTab[VarIdx], DataVar);
              /* If program operation was failed, a Flash error code is returned */
              if (EepromStatus != HAL_OK)
              {
                return EepromStatus;
              }
            }
          }
        }

In main.c, flashunlock is HAL_OK. which seems to mean the flash is unlocked.

int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
  /* Unlock the Flash Program Erase controller */
  HAL_StatusTypeDef flashunlock = HAL_FLASH_Unlock();
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  //MX_SPI2_Init();

TCash.1
Associate III

It looks like I was using to large of values (from the example 0x5555, 0x6666, 0x7777) for the virtual addresses. using virtual address 0x0,0x1,0x2, etc seems to be working for me.

TCash.1
Associate III

UPDATE: The Above is really not the correct solution to the problem. I believe I am still getting errors.

To be clear I am trying to get eeprom emulation working on the both the f4 (above) and a stm32H7. right now I am working with the H7 again and am having trouble with the EE_VerifyPageFullWriteVariable function:

/* Check each active page address starting from begining */
  while (Address < PageEndAddress)
  {
 
    /* Verify if Address and Address+2 contents are 0xFFFFFFFF */
	__IO uint32_t* addressAsPointer = Address;
	uint32_t addressValue = (*addressAsPointer);
 
 
    if (addressValue == 0xFFFFFFFF)
    {
      /* Set variable data */
      FlashStatus = HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, Address, ((uint32_t)data32));
   
      /* If program operation was failed, a Flash error code is returned */
      if (FlashStatus != HAL_OK)
      {
        return FlashStatus;
      }
      /* Set variable virtual address */
      FlashStatus = HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, Address + 32, ((uint32_t)VirtAddress1));
 
      /* Return program operation status */
     return FlashStatus;
    }
    else
    {

 I get a hardfault when dereferencing the addressAsPointer variable. the address seems valid (its in flash range 0x81cb680) and the value is even extracted into the addressValue variable. non-theless I get a hardfault