cancel
Showing results for 
Search instead for 
Did you mean: 

EEPROM Emulator in STM32L053

joaoleao
Associate II

Hello everyone,

I known that isn't normal to use EEPROM emulator on a STM32L053, because it has is own EEPROM, but nowadays with the chip shortage, i was forcedto use an alternative MCU (STM32L053R8T6) instead of the "original design" (STM32F030C8T6), so i want to use the same code for both MCU, so the EEPROM emulator on the STM32L053R8T6.

But i'm having some difficulty using the EEPROM emulator on the STM32L053, the compiler didn't give any error, and the code run normmally, but didn't save any value to the EEPROM.

Header File:

```

#define ADDR_FLASH_PAGE_60  ((uint32_t)0x0800F000) /* Base @ of Page 60, 1 Kbytes */

#define ADDR_FLASH_PAGE_61  ((uint32_t)0x0800F400) /* Base @ of Page 61, 1 Kbytes */

#define ADDR_FLASH_PAGE_62  ((uint32_t)0x0800F800) /* Base @ of Page 62, 1 Kbytes */

/* Define the size of the sectors to be used */

#define PAGE_SIZE        (uint32_t) FLASH_PAGE_SIZE /* Page size */

/* EEPROM start address in Flash */

#define EEPROM_START_ADDRESS ((uint32_t) ADDR_FLASH_PAGE_60) /* EEPROM emulation start address */

/* Pages 0 and 1 base and end addresses */

#define PAGE0_BASE_ADDRESS  ((uint32_t)(EEPROM_START_ADDRESS + 0x0000))

#define PAGE0_END_ADDRESS   ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))

#define PAGE1_BASE_ADDRESS  ((uint32_t)(ADDR_FLASH_PAGE_61))

#define PAGE1_END_ADDRESS   ((uint32_t)(ADDR_FLASH_PAGE_61 + PAGE_SIZE - 1))

/* Used Flash pages for EEPROM emulation */

#define PAGE0         ((uint16_t) 0x0000)

#define PAGE1         ((uint16_t)((PAGE1_BASE_ADDRESS-PAGE0_BASE_ADDRESS)/PAGE_SIZE)) /* Virtual page nb between PAGE0_BASE_ADDRESS & PAGE1_BASE_ADDRESS*/

/* No valid page define */

#define NO_VALID_PAGE     ((uint16_t)0x00AB)

/* Page status definitions */

#define ERASED        ((uint16_t)0xFFFF)   /* Page is empty */

#define RECEIVE_DATA     ((uint16_t)0xEEEE)   /* Page is marked to receive data */

#define VALID_PAGE      ((uint16_t)0x0000)   /* Page containing valid data */

/* Valid pages in read and write defines */

#define READ_FROM_VALID_PAGE ((uint8_t)0x00)

#define WRITE_IN_VALID_PAGE  ((uint8_t)0x01)

/* Page full define */

#define PAGE_FULL       ((uint8_t)0x80)

void EE_ReadData(void);

uint16_t EE_Init(void);

uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);

uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);

#endif /* __EEPROM_H */

```

EEPROM Write Variable Function:

```

uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data)

{

uint16_t Status = 0;

/* Write the variable virtual address and value in the EEPROM */

Status = EE_VerifyPageFullWriteVariable(VirtAddress, Data);

/* In case the EEPROM active page is full */

if (Status == PAGE_FULL)

{

/* Perform Page transfer */

Status = EE_PageTransfer(VirtAddress, Data);

}

/* Return last operation status */

return Status;

}

```

3 REPLIES 3

> #define ERASED        ((uint16_t)0xFFFF)   /* Page is empty */

Note, that the FLASH in 'L0, very untypically, erases to zeros.

I don't use the EEPROM emulation library, but I would not expect that it is enough to change this macro.

Also note, that FLASH in 'L0 has ECC.

JW

Chloe Meunier
ST Employee

Hello

did you try to first erase your flash memory ?

#define ERASED        ((uint16_t)0xFFFF)   /* Page is empty */ is a marker : if it is written 0xFFFF in the beginning of a page, so page status is "erased", so I don't think that comes from this macro..

Chloé

joaoleao
Associate II

Hello,

Yes i do a EEProm_Init, where i erase the flash.