The Emulated EEPROM (Em_EEPROM) middleware emulates an EEPROM storage in PSoC's internal flash memory or in XMC7xxx and T2G-B-H internal Work flash memory. The Em_EEPROM middleware operates on the top of the flash driver included in the Peripheral Driver Library (mtb-pdl-cat1 or mtb-pdl-cat2).
Use the Em_EEPROM to store non-volatile data on a target device when increasing flash memory endurance and restoring corrupted data from a redundant copy is required.
Features:
Include cy_em_eeprom.h to get access to all functions and other declarations in this library. See the Quick Start Guide to start using the Em_EEPROM.
Refer to the Supported Software and Tools section for compatibility information.
Refer to the Changelog section for differences between Em_EEPROM versions. The Changelog section also describes the impact of the changes to your code.
Em_EEPROM operates on the top of the flash driver. The flash driver has some prerequisites for proper operation. Refer to the "Flash (Flash System Routine)" section of the Peripheral Driver Library API Reference Manual. Also, refer to the Limitations and Restrictions section for the different Em_EEPROM middleware restrictions and limitations.
The Em_EEPROM middleware can operate in various modes:
There are several use cases depending on where you store your Em_EEPROM data:
Note: refer to device capabilities for supported storage location for EM_EEPROM data.
The Configuration Considerations section provides the guidance for all these operation modes and use cases. You may also want to migrate from PSoC Creator to ModusToolbox or other environment to simply use the Em_EEPROM middleware APIs. Refer to the Migration from PSoC Creator section.
The Quick Start Guide section highlights the use case, when the Em_EEPROM data is located in the application flash, and the Em_EEPROM is configured to increase the flash endurance (the wearLevelingFactor parameter is turned on).
XMC7xxx and T2G-B-H based devices support Em_EEPROM Data only in "Work Flash". The "Work Flash" provides sectors with 2 sizes namely: Large (2 kbytes) and Small (128 bytes). The user should select which type of Work FLash region will be used for Em_EEPROM storage. The default assumes use of small sector work flash. To use large sector work flash, the user can use EEPROM personality or edit application Makefile.
Using EEPROM Personality: The EEPROM personality has checkbox for: "Work Flash Sector Selection default Small Sector" which is "checked" by default. To use Large sector work flash, uncheck this box.
Using application Makefile: To use large sector work flash add "EEPROM_LARGE_SECTOR_WFLASH" to DEFINES in application Makefile as shown below.
DEFINES=EEPROM_LARGE_SECTOR_WFLASH
Em_EEPROM middleware can be used in various Development Environments such as ModusToolbox, Mbed OS, etc. Refer to the Supported Software and Tools section.
The below steps describe the simplest way of enabling the Em_EEPROM middleware with placing EEPROM memory into the application flash.
This section consists of different guides and instruction of how to enable, configure, and use the Emulated EEPROM Middleware in a design. As you can see from the Quick Start Guide section, the settings of the Em_EEPROM middleware are controlled with the cy_stc_eeprom_config_t structure. Please see its description to learn about the parameters and values.
Now we will describe the most common use cases along with the configuration structure examples and code snippets. The list of sections under Configuration Considerations:
Also refer to the Limitations and Restrictions for the existing restrictions.
The settings of the Em_EEPROM middleware are controlled by the cy_stc_eeprom_config_t structure. See its description to learn about the parameters and values.
Depending on whether you want to increase the flash memory endurance or not, enable or disable the wear leveling. The higher the value is, the more flash is used, but a higher number of erase/write cycles can be done on Em_EEPROM. Multiply this number by the datasheet write endurance spec to determine the max of write cycles.
The amount of wear leveling from 1 to 10. 1 means no wear leveling is used.
To configure the wear leveling just set the WEAR_LEVELING macro value from (1u) to (10u) in step #4 in the Quick Start Guide section:
Depending on how critical for you is recovering information, configure the redundant copy feature. If enabled (1 - enabled, 0 - disabled), a checksum (stored in a row) is calculated on each row of data, while a redundant copy of Em_EEPROM is stored in another location. When data is read, first the checksum is checked. If that checksum is bad, and the redundant copy's checksum is good, the copy is restored.
To configure the redundant copy just set the REDUNDANT_COPY macro value to (1u) or (0u) in step #4 in the Quick Start Guide section:
Simple mode, when enabled (1 - enabled, 0 - disabled), means no additional service information is stored by the Em_EEPROM middleware like checksums, headers, a number of writes, etc. Data is stored directly by the specified address. The size of Em_EEPROM storage is equal to the number of byte specified in the eepromSize parameter rounded up to a full row size CY_EM_EEPROM_FLASH_SIZEOF_ROW. The wear leveling and redundant copy features are disabled, i.e. wearLevelingFactor and redundantCopy parameters are ignored.
To configure Simple mode just set the SIMPLE_MODE macro value to (1u) or (0u) in step #4 in the Quick Start Guide section:
The user is responsible for allocating space in flash for Em_EEPROM (further the Em_EEPROM storage).
For PSoC 6 the Em_EEPROM storage can be placed:
Additionally, the storage can be placed at a fixed address in the application flash.
For PSoC 4 the Em_EEPROM storage can be placed:
Additionally, the storage can be placed at a fixed address in the application flash.
For XMC7xxx and T2G-B-H the Em_EEPROM storage can be placed:
The storage location must be aligned to CY_EM_EEPROM_FLASH_SIZEOF_ROW.
The storage size depends on other configuration parameters and is calculated using the following equation:
Simple mode is turned on. It means the direct mapping of the user data in the Em_EEPROM storage:
storageSize = eepromSize
where:
eepromSize the number of bytes to store in the Em_EEPROM storage rounded up to a full row size CY_EM_EEPROM_FLASH_SIZEOF_ROW. The row size is specific for a device family. Refer to the specific PSoC device datasheet.
Simple mode is turned off. It means the Em_EEPROM middleware stores service information about number of writes, checksums, etc.
storageSize = eepromSize * 2 * wearLevelingFactor * (1 + redundantCopy)
where:
eepromSize the number of bytes to store in the Em_EEPROM storage rounded up to the half of a row size (CY_EM_EEPROM_FLASH_SIZEOF_ROW / 2u). The row size is specific for a device family. Refer to the specific PSoC device datasheet.
Use the CY_EM_EEPROM_GET_PHYSICAL_SIZE() macro to get the needed storage size depending on the configuration.
The below example shows placing the Em_EEPROM storage in the application flash for GCC, ARMCC, and IAR compilers:
where STORAGE_SIZE is the size of the Em_EEPROM storage. Refer to the Em_EEPROM Storage Variable Location and Size section for size calculation equations. For convenience, use the CY_EM_EEPROM_GET_PHYSICAL_SIZE macro to get the needed Em_EEPROM storage size depending on the configuration.
Writes to rows affect the endurance of other rows in the same sector. We recommend using the auxiliary flash for frequently-updated data. The below example shows placing the Em_EEPROM storage in the auxiliary flash (section .cy_em_eeprom) for GCC, ARMCC, and IAR compilers.
where STORAGE_SIZE is the size of the storage. Refer to the Em_EEPROM Storage Variable Location and Size section for size calculation equations. For convenience, use the CY_EM_EEPROM_GET_PHYSICAL_SIZE macro to get the needed Em_EEPROM storage size depending on the configuration.
To allocate the Em_EEPROM storage at a fixed address in the application flash, modify the linker control file (linker script). This requires fundamental knowledge of the linker control file, because there is a risk of receiving a linker error while building the project if you make some improper modifications.
This approach demonstrates adding the storage reservation in the application flash after the application. You must calculate the application end address and select the address of the Em_EEPROM storage so that the memory spaces of the storage and the application do not overlap. You might also add some offset between the application end address and the Em_EEPROM storage start address to ensure there is extra space in case the project code grows.
This section helps migrate your project from PSoC Creator with the Em_EEPROM component to ModusToolbox or other software environment using the Em_EEPROM middleware.
The migration consists of three steps:
The PSoC Creator Em_EEPROM component has parameter "Use Emulated EEPROM". It defines where the Em_EEPROM storage is located.
Allocate memory for Em_EEPROM context and configuration structures, and initialize the configuration structure per the Em_EEPROM component configuration:
where the right side of initialization is the Em_EEPROM Component customizer parameters and "emEepromStorage" is the name of the storage.
Now, after the storage and configuration are defined, change the names of the functions used in the PSoC Creator project per the following table:
PSoC Creator Em_EEPROM Component | ModusToolbox Em_EEPROM Middleware |
---|---|
EEPROM_Init(X) | Cy_Em_EEPROM_Init(&eepromConfig, &eepromContext) |
EEPROM_Write(X1, X2, X3) | Cy_Em_EEPROM_Write(X1, X2, X3, &eepromContext) |
EEPROM_Read(X1, X2, X3) | Cy_Em_EEPROM_Read(X1, X2, X3, &eepromContext) |
EEPROM_Erase() | Cy_Em_EEPROM_Erase(&eepromContext) |
EEPROM_NumWrites() | Cy_Em_EEPROM_NumWrites(&eepromContext) |
Note The above table shows the function names with an assumption that the PSoC Creator component name is EEPROM.
This version of the Em_EEPROM Middleware was validated for the compatibility with the following software and tools:
Software and Tools | Version |
---|---|
ModusToolbox Software Environment | 3.0 |
CAT1 Peripheral Driver Library (mtb-pdl-cat1) | 3.0.0 |
CAT2 Peripheral Driver Library (mtb-pdl-cat2) | 2.0.0 |
GCC Compiler | 10.3.1 |
IAR Compiler | 9.30.1 |
Arm Compiler 6 | 6.16 |
Mbed OS | 5.13.1 |
FreeRTOS | 10.4.3 |
There are no high or medium severity compliance issues for this asset. Listed below are the deviations for minor issues.
The Cy_Em_EEPROM library's specific deviations:
MISRA Rule | Rule Class (Required/Advisory) | Rule Description | Description of Deviation(s) |
---|---|---|---|
5.9 | A | Static Identifiers should be unique. | Following naming convention for static functions. |
11.5 | A | Typecast of void pointer should be avoided. | The cast is used intentionally for the performance reason. |
Version | Changes | Reason for Change |
---|---|---|
2.20 | The Em_EEPROM 2.20 adds support for XMC 7xxx and T2G-B-H devices. | |
Updated major and minor version defines | Follow naming convention | |
Updated documentation | ||
2.10 | The Em_EEPROM 2.10 adds support for PSoC 4 devices. | |
Updated major and minor version defines | Follow naming convention | |
Updated documentation | User experience improvement and Logo update | |
Fixed MISRA violations | Improved the middleware robustness | |
2.00 | The Em_EEPROM 2.0 is not backward compatible with the previous version. It was significantly rewritten with changing the behavior of operation, adding many improvements and fixing defects. However, the application programming interface (API) contains only single change and you can seamlessly migrate to 2.0 version. This change is consist in adding the Simple Mode. | |
Updated major and minor version defines | Follow naming convention | |
Updated documentation | User experience improvement | |
Changed the CY_EM_EEPROM_EEPROM_DATA_LEN macro by adding the simpleMode parameter | Added new mode when wear leveling and redundant copy features are disabled | |
Fixed MISRA violations | Improved the middleware robustness | |
Fixed the defect of the Cy_Em_EEPROM_Read() function when Emulated EEPROM data corruption in some cases caused infinite loop | Fixed Defect | |
Fixed the defect of the Cy_Em_EEPROM_Read() function when the function returns incorrect data after restoring data from the redundant copy | Fixed Defect | |
Added the mechanism to restore the corrupted redundant copy from the main data copy | Improved the Em_EEPROM data reliability | |
Revised the operation of Cy_Em_EEPROM_Read() and Cy_Em_EEPROM_Init() functions by removing the write operation. | Improved the Em_EEPROM functionality | |
Expanded the checksum verification to the entire row. | Improved the Em_EEPROM data reliability | |
1.10 | Flattened the organization of the driver source code into a single source directory and a single include directory | Simplified the Driver library directory-structure |
1.0.1 | Added the Em_EEPROM storage allocation note to the Configuration Considerations | Documentation update and clarification |
1.0 | Initial Version |
For more information, refer to the following documents: