AN2594: EEPROM emulation in STM32F10x microcontrollers: EEPROM_Emulation

AN2594: EEPROM

EEPROM_Emulation

Functions

void BusFault_Handler (void)
 This function handles Bus Fault exception.
void DebugMon_Handler (void)
 This function handles Debug Monitor exception.
static uint16_t EE_FindValidPage (uint8_t Operation)
 Find valid Page for write or read operation.
static FLASH_Status EE_Format (void)
 Erases PAGE0 and PAGE1 and writes VALID_PAGE header to PAGE0.
uint16_t EE_Init (void)
 Restore the pages to a known good state in case of page's status corruption after a power loss.
static uint16_t EE_PageTransfer (uint16_t VirtAddress, uint16_t Data)
 Transfers last updated variables data from the full Page to an empty one.
uint16_t EE_ReadVariable (uint16_t VirtAddress, uint16_t *Data)
 Returns the last stored variable data, if found, which correspond to the passed virtual address.
static uint16_t EE_VerifyPageFullWriteVariable (uint16_t VirtAddress, uint16_t Data)
 Verify if active page is full and Writes variable in EEPROM.
uint16_t EE_WriteVariable (uint16_t VirtAddress, uint16_t Data)
 Writes/upadtes variable data in EEPROM.
void HardFault_Handler (void)
 This function handles Hard Fault exception.
int main (void)
 Main program.
void MemManage_Handler (void)
 This function handles Memory Manage exception.
void NMI_Handler (void)
 This function handles NMI exception.
void PendSV_Handler (void)
 This function handles PendSVC exception.
void SVC_Handler (void)
 This function handles SVCall exception.
void SysTick_Handler (void)
 This function handles SysTick Handler.
void UsageFault_Handler (void)
 This function handles Usage Fault exception.

Variables

uint16_t DataVar = 0
FLASH_Status FlashStatus
ErrorStatus HSEStartUpStatus
uint16_t VarValue = 0
uint16_t VirtAddVarTab [NumbOfVar] = {0x5555, 0x6666, 0x7777}
uint16_t VirtAddVarTab [NumbOfVar]

Function Documentation

void BusFault_Handler ( void   ) 

This function handles Bus Fault exception.

Parameters:
None 
Return values:
None 

Definition at line 81 of file stm32f10x_it.c.

void DebugMon_Handler ( void   ) 

This function handles Debug Monitor exception.

Parameters:
None 
Return values:
None 

Definition at line 116 of file stm32f10x_it.c.

static uint16_t EE_FindValidPage ( uint8_t  Operation  )  [static]

Find valid Page for write or read operation.

Parameters:
Operation,: operation to achieve on the valid page. This parameter can be one of the following values:
  • READ_FROM_VALID_PAGE: read operation from valid page
  • WRITE_IN_VALID_PAGE: write operation from valid page
Return values:
Valid page number (PAGE0 or PAGE1) or NO_VALID_PAGE in case of no valid page was found

Definition at line 388 of file eeprom.c.

References NO_VALID_PAGE, PAGE0, PAGE0_BASE_ADDRESS, PAGE1, PAGE1_BASE_ADDRESS, READ_FROM_VALID_PAGE, RECEIVE_DATA, VALID_PAGE, and WRITE_IN_VALID_PAGE.

Referenced by EE_PageTransfer(), EE_ReadVariable(), and EE_VerifyPageFullWriteVariable().

static FLASH_Status EE_Format ( void   )  [static]

Erases PAGE0 and PAGE1 and writes VALID_PAGE header to PAGE0.

Parameters:
None 
Return values:
Status of the last operation (Flash write or erase) done during EEPROM formating

Definition at line 350 of file eeprom.c.

References FlashStatus, PAGE0_BASE_ADDRESS, PAGE1_BASE_ADDRESS, and VALID_PAGE.

Referenced by EE_Init().

uint16_t EE_Init ( void   ) 

Restore the pages to a known good state in case of page's status corruption after a power loss.

Parameters:
None. 
Return values:
- Flash error code: on write Flash error
  • FLASH_COMPLETE: on success

Definition at line 52 of file eeprom.c.

References DataVar, EE_Format(), EE_ReadVariable(), EE_VerifyPageFullWriteVariable(), ERASED, FlashStatus, NumbOfVar, PAGE0_BASE_ADDRESS, PAGE1_BASE_ADDRESS, RECEIVE_DATA, VALID_PAGE, and VirtAddVarTab.

Referenced by main().

static uint16_t EE_PageTransfer ( uint16_t  VirtAddress,
uint16_t  Data 
) [static]

Transfers last updated variables data from the full Page to an empty one.

Parameters:
VirtAddress,: 16 bit virtual address of the variable
Data,: 16 bit data to be written as variable value
Return values:
Success or error status:
  • FLASH_COMPLETE: on success
  • PAGE_FULL: if valid page is full
  • NO_VALID_PAGE: if no valid page was found
  • Flash error code: on write Flash error

Definition at line 521 of file eeprom.c.

References DataVar, EE_FindValidPage(), EE_ReadVariable(), EE_VerifyPageFullWriteVariable(), FlashStatus, NO_VALID_PAGE, NumbOfVar, PAGE0, PAGE0_BASE_ADDRESS, PAGE1, PAGE1_BASE_ADDRESS, READ_FROM_VALID_PAGE, RECEIVE_DATA, VALID_PAGE, and VirtAddVarTab.

Referenced by EE_WriteVariable().

uint16_t EE_ReadVariable ( uint16_t  VirtAddress,
uint16_t *  Data 
)

Returns the last stored variable data, if found, which correspond to the passed virtual address.

Parameters:
VirtAddress,: Variable virtual address
Data,: Global variable contains the read variable value
Return values:
Success or error status:
  • 0: if variable was found
  • 1: if the variable was not found
  • NO_VALID_PAGE: if no valid page was found.

Definition at line 267 of file eeprom.c.

References EE_FindValidPage(), EEPROM_START_ADDRESS, NO_VALID_PAGE, PAGE0, and READ_FROM_VALID_PAGE.

Referenced by EE_Init(), and EE_PageTransfer().

static uint16_t EE_VerifyPageFullWriteVariable ( uint16_t  VirtAddress,
uint16_t  Data 
) [static]

Verify if active page is full and Writes variable in EEPROM.

Parameters:
VirtAddress,: 16 bit virtual address of the variable
Data,: 16 bit data to be written as variable value
Return values:
Success or error status:
  • FLASH_COMPLETE: on success
  • PAGE_FULL: if valid page is full
  • NO_VALID_PAGE: if no valid page was found
  • Flash error code: on write Flash error

Definition at line 460 of file eeprom.c.

References EE_FindValidPage(), EEPROM_START_ADDRESS, FlashStatus, NO_VALID_PAGE, PAGE0, PAGE_FULL, and WRITE_IN_VALID_PAGE.

Referenced by EE_Init(), EE_PageTransfer(), and EE_WriteVariable().

uint16_t EE_WriteVariable ( uint16_t  VirtAddress,
uint16_t  Data 
)

Writes/upadtes variable data in EEPROM.

Parameters:
VirtAddress,: Variable virtual address
Data,: 16 bit data to be written
Return values:
Success or error status:
  • FLASH_COMPLETE: on success
  • PAGE_FULL: if valid page is full
  • NO_VALID_PAGE: if no valid page was found
  • Flash error code: on write Flash error

Definition at line 326 of file eeprom.c.

References EE_PageTransfer(), EE_VerifyPageFullWriteVariable(), and PAGE_FULL.

Referenced by main().

void HardFault_Handler ( void   ) 

This function handles Hard Fault exception.

Parameters:
None 
Return values:
None 

Definition at line 55 of file stm32f10x_it.c.

int main ( void   ) 

Main program.

Parameters:
None 
Return values:
None 

Definition at line 47 of file main.c.

References EE_Init(), EE_WriteVariable(), VarValue, and VirtAddVarTab.

void MemManage_Handler ( void   ) 

This function handles Memory Manage exception.

Parameters:
None 
Return values:
None 

Definition at line 68 of file stm32f10x_it.c.

void NMI_Handler ( void   ) 

This function handles NMI exception.

Parameters:
None 
Return values:
None 

Definition at line 46 of file stm32f10x_it.c.

void PendSV_Handler ( void   ) 

This function handles PendSVC exception.

Parameters:
None 
Return values:
None 

Definition at line 125 of file stm32f10x_it.c.

void SVC_Handler ( void   ) 

This function handles SVCall exception.

Parameters:
None 
Return values:
None 

Definition at line 107 of file stm32f10x_it.c.

void SysTick_Handler ( void   ) 

This function handles SysTick Handler.

Parameters:
None 
Return values:
None 

Definition at line 134 of file stm32f10x_it.c.

void UsageFault_Handler ( void   ) 

This function handles Usage Fault exception.

Parameters:
None 
Return values:
None 

Definition at line 94 of file stm32f10x_it.c.


Variable Documentation

uint16_t DataVar = 0

Definition at line 33 of file eeprom.c.

Referenced by EE_Init(), and EE_PageTransfer().

FLASH_Status FlashStatus

Definition at line 33 of file main.c.

Referenced by EE_Format(), EE_Init(), EE_PageTransfer(), and EE_VerifyPageFullWriteVariable().

ErrorStatus HSEStartUpStatus

Definition at line 32 of file main.c.

uint16_t VarValue = 0

Definition at line 34 of file main.c.

Referenced by main().

uint16_t VirtAddVarTab[NumbOfVar] = {0x5555, 0x6666, 0x7777}

Definition at line 37 of file main.c.

Referenced by EE_Init(), EE_PageTransfer(), and main().

uint16_t VirtAddVarTab[NumbOfVar]

Definition at line 37 of file main.c.

Referenced by EE_Init(), EE_PageTransfer(), and main().

STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit www.st.com/STM32