implement EEPROM emulation
This commit is contained in:
+837
-1533
File diff suppressed because it is too large
Load Diff
@@ -23,29 +23,23 @@
|
||||
#define __EEPROM_EMUL_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define __IO volatile
|
||||
#define __weak __attribute__((weak))
|
||||
|
||||
#include "eeprom_emul_conf.h"
|
||||
#include "eeprom_emul_types.h"
|
||||
#include "flash_interface.h"
|
||||
|
||||
/** @addtogroup EEPROM_Emulation
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/** @defgroup EEPROM_Private_Constants EEPROM Private Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup Private_Other_Constants Private Other Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Page definitions */
|
||||
#define PAGE_SIZE FLASH_PAGE_SIZE /*!< Page size */
|
||||
#define PAGE_HEADER_SIZE EE_ELEMENT_SIZE * 4U /*!< Page Header is 4 elements to save page state */
|
||||
#define PAGE_HEADER_SIZE (EE_ELEMENT_SIZE * 4U) /*!< Page Header is 4 elements to save page state */
|
||||
#define NB_MAX_ELEMENTS_BY_PAGE ((PAGE_SIZE - PAGE_HEADER_SIZE) / EE_ELEMENT_SIZE) /*!< Max number of elements by page */
|
||||
#define PAGES_NUMBER (((((NB_OF_VARIABLES + NB_MAX_ELEMENTS_BY_PAGE) / NB_MAX_ELEMENTS_BY_PAGE) * 2U) * CYCLES_NUMBER) + GUARD_PAGES_NUMBER)
|
||||
/*!< Number of consecutives pages used by the application */
|
||||
/*!< Number of consecutives pages used by the application */
|
||||
#define NB_MAX_WRITTEN_ELEMENTS ((NB_MAX_ELEMENTS_BY_PAGE * PAGES_NUMBER) / 2U) /*!< Max number of elements written before triggering pages transfer */
|
||||
#define START_PAGE PAGE(START_PAGE_ADDRESS) /*!< Page index of the 1st page used for EEPROM emul, in the bank */
|
||||
#define END_EEPROM_ADDRESS (START_PAGE_ADDRESS + (PAGES_NUMBER * FLASH_PAGE_SIZE) - 1) /*!< Last address of EEPROM emulation flash pages */
|
||||
@@ -53,89 +47,44 @@
|
||||
/* No page define */
|
||||
#define EE_NO_PAGE_FOUND ((uint32_t)0xFFFFFFFFU)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/** @defgroup EEPROM_Private_Macros EEPROM Private Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup Macros_Pages Macros to manipulate pages
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Macros to manipulate pages */
|
||||
#ifdef SECURE_FEATURES
|
||||
#define PAGE_ADDRESS(__PAGE__) (uint32_t)(FLASH_BASE_NS + (__PAGE__) * PAGE_SIZE + ((START_PAGE_ADDRESS - FLASH_BASE_NS) / BANK_SIZE) * BANK_SIZE) /*!< Get page address from page index */
|
||||
#define PAGE(__ADDRESS__) (uint32_t)((((__ADDRESS__) - FLASH_BASE_NS) % BANK_SIZE) / FLASH_PAGE_SIZE) /*!< Get page index from page address */
|
||||
#else
|
||||
#define PAGE_ADDRESS(__PAGE__) (uint32_t)(FLASH_BASE + (__PAGE__) * PAGE_SIZE + ((START_PAGE_ADDRESS - FLASH_BASE) / BANK_SIZE) * BANK_SIZE) /*!< Get page address from page index */
|
||||
#define PAGE(__ADDRESS__) (uint32_t)((((__ADDRESS__) - FLASH_BASE) % BANK_SIZE) / FLASH_PAGE_SIZE) /*!< Get page index from page address */
|
||||
#endif
|
||||
#define PAGE_ADDRESS(__PAGE__) (uint32_t)(FLASH_BASE + (__PAGE__) * PAGE_SIZE + ((START_PAGE_ADDRESS - FLASH_BASE) / BANK_SIZE) * BANK_SIZE) /*!< Get page address from page index */
|
||||
#define PAGE(__ADDRESS__) (uint32_t)((((__ADDRESS__) - FLASH_BASE) % BANK_SIZE) / FLASH_PAGE_SIZE) /*!< Get page index from page address */
|
||||
#define PREVIOUS_PAGE(__PAGE__) (uint32_t)((((__PAGE__) - START_PAGE - 1U + PAGES_NUMBER) % PAGES_NUMBER) + START_PAGE) /*!< Get page index of previous page, among circular page list */
|
||||
#define FOLLOWING_PAGE(__PAGE__) (uint32_t)((((__PAGE__) - START_PAGE + 1U) % PAGES_NUMBER) + START_PAGE) /*!< Get page index of following page, among circular page list */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup Macros_Elements Macros to manipulate elements
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Macros to manipulate elements */
|
||||
#define EE_VIRTUALADDRESS_VALUE(__ELEMENT__) (EE_VIRTUALADDRESS_TYPE)((__ELEMENT__) & EE_MASK_VIRTUALADDRESS) /*!< Get virtual address value from element value */
|
||||
#define EE_DATA_VALUE(__ELEMENT__) (EE_DATA_TYPE)(((__ELEMENT__) & EE_MASK_DATA) >> EE_DATA_SHIFT) /*!< Get Data value from element value */
|
||||
#define EE_CRC_VALUE(__ELEMENT__) (EE_CRC_TYPE)(((__ELEMENT__) & EE_MASK_CRC) >> EE_CRC_SHIFT) /*!< Get Crc value from element value */
|
||||
#define EE_ELEMENT_VALUE(__VIRTADDR__,__DATA__,__CRC__) (((EE_ELEMENT_TYPE)(__DATA__) << EE_DATA_SHIFT) | (__CRC__) << EE_CRC_SHIFT | (__VIRTADDR__)) /*!< Get element value from virtual addr, data and crc values */
|
||||
#define EE_ELEMENT_VALUE(__VIRTADDR__, __DATA__, __CRC__) (((EE_ELEMENT_TYPE)(__DATA__) << EE_DATA_SHIFT) | (__CRC__) << EE_CRC_SHIFT | (__VIRTADDR__)) /*!< Get element value from virtual addr, data and crc values */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
/** @defgroup EEPROM_Exported_Functions EEPROM Exported Functions
|
||||
* @{
|
||||
*/
|
||||
EE_Status EE_Format(EE_Erase_type EraseType);
|
||||
|
||||
EE_Status EE_Init(EE_Erase_type EraseType);
|
||||
#if defined(EE_ACCESS_32BITS)
|
||||
EE_Status EE_ReadVariable32bits(uint16_t VirtAddress, uint32_t* pData);
|
||||
|
||||
EE_Status EE_ReadVariable32bits(uint16_t VirtAddress, uint32_t *pData);
|
||||
|
||||
EE_Status EE_WriteVariable32bits(uint16_t VirtAddress, uint32_t Data);
|
||||
#endif
|
||||
#if defined(FLASH_LINES_128B)
|
||||
EE_Status EE_ReadVariable96bits(uint16_t VirtAddress, uint64_t* pData);
|
||||
EE_Status EE_WriteVariable96bits(uint16_t VirtAddress, uint64_t* Data);
|
||||
#endif
|
||||
EE_Status EE_ReadVariable16bits(uint16_t VirtAddress, uint16_t* pData);
|
||||
|
||||
EE_Status EE_ReadVariable16bits(uint16_t VirtAddress, uint16_t *pData);
|
||||
|
||||
EE_Status EE_WriteVariable16bits(uint16_t VirtAddress, uint16_t Data);
|
||||
EE_Status EE_ReadVariable8bits(uint16_t VirtAddress, uint8_t* pData);
|
||||
|
||||
EE_Status EE_ReadVariable8bits(uint16_t VirtAddress, uint8_t *pData);
|
||||
|
||||
EE_Status EE_WriteVariable8bits(uint16_t VirtAddress, uint8_t Data);
|
||||
|
||||
EE_Status EE_CleanUp(void);
|
||||
EE_Status EE_CleanUp_IT(void);
|
||||
|
||||
EE_Status EE_DeleteCorruptedFlashAddress(uint32_t Address);
|
||||
void EE_EndOfCleanup_UserCallback(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
* Callback from NMI.
|
||||
*
|
||||
* @return true if handled by this library
|
||||
*/
|
||||
bool EE_NMI_Callback();
|
||||
|
||||
#endif /* __EEPROM_EMUL_H */
|
||||
|
||||
|
||||
+3
-50
@@ -27,64 +27,17 @@
|
||||
#ifndef __EEPROM_EMUL_CONF_H
|
||||
#define __EEPROM_EMUL_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/** @addtogroup EEPROM_Private_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup Private_Configuration_Constants Private Configuration Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Configuration of eeprom emulation in flash, can be custom */
|
||||
#define START_PAGE_ADDRESS 0x08080000U /*!< Start address of the 1st page in flash, for EEPROM emulation */
|
||||
#define START_PAGE_ADDRESS 0x800E000U /*!< 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 2U /*!< 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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/** @defgroup EEPROM_Exported_Constants EEPROM Exported Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup Exported_Configuration_Constants Exported Configuration Constants
|
||||
* @{
|
||||
*/
|
||||
#define NB_OF_VARIABLES 1000U /*!< Number of variables to handle in eeprom */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __EEPROM_EMUL_CONF_H */
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __EEPROM_EMUL_TYPES_H
|
||||
#define __EEPROM_EMUL_TYPES_H
|
||||
@@ -67,7 +67,7 @@ typedef enum {
|
||||
|
||||
/* External return code : action required */
|
||||
EE_CLEANUP_REQUIRED = 0x100U,
|
||||
|
||||
|
||||
#ifdef DUALCORE_FLASH_SHARING
|
||||
/* Value returned when a program or erase operation is requested but
|
||||
* the flash is already used by CPU2 */
|
||||
|
||||
Reference in New Issue
Block a user