Flash Memory Module provides the general flash APIs.
Flash memory is ideal for single-supply applications, permitting in-the-field erase and reprogramming operations without the need for any external high voltage power sources. The flash module includes a memory controller that executes commands to modify flash memory contents. An erased bit reads '1' and a programmed bit reads '0'. The programming operation is unidirectional; it can only move bits from the '1' state (erased) to the '0' state (programmed). Only the erase operation restores bits from '0' to '1'; bits cannot be programmed from a '0' to a '1'.
C90TFS Flash Driver
The C90TFS flash module includes the following accessible memory regions.
- Program flash memory for vector space and code store.
- FlexNVM for data store, additional code store and also non-volatile storage for the EEPROM filing system representing data written to the FlexRAM requiring highest endurance.
- FlexRAM for high-endurance EEPROM data store or traditional RAM.
Some platforms may be designed to have only program flash memory or all of them.
The S32 SDK provides the C90TFS Flash driver of S32K platforms. The driver includes general APIs to handle specific operations on C90TFS Flash module. The user can use those APIs directly in the application.
EEPROM feature
For platforms with FlexNVM, the flash module provides a built-in hardware emulation scheme to emulate the characteristics of an EEPROM by effectively providing a high-endurance, byte write-able NVM. The EEPROM system is shown in the following figure.
Figure 1. EEPROM Architecture To handle with various customer's requirements, the FlexRAM and FlexNVM blocks can be split into partitions:
- EEPROM partition(EEESIZE) — The amount of FlexRAM used for EEPROM can be set from 0 Bytes (no EEPROM) to the maximum FlexRAM size. The remainder of the FlexRAM not used for EEPROM is not accessible while the FlexRAM is configured for EEPROM.The EEPROM partition grows upward from the bottom of the FlexRAM address space.
- Data flash partition(DEPART) — The amount of FlexNVM memory used for data flash can be programmed from 0 bytes (all of the FlexNVM block is available for EEPROM backup) to the maximum size of the FlexNVM block.
- FlexNVM EEPROM partition — The amount of FlexNVM memory used for EEPROM backup, which is equal to the FlexNVM block size minus the data flash memory partition size. The EEPROM backup size must be at least 16 times the EEPROM partition size in FlexRAM.
The partition information (EEESIZE, DEPART) is programmed using the FLASH_DRV_DEFlashPartition API.
The function of FlexRAM can be changed from EEPROM usage to traditional RAM for accelerate programming in FLASH_DRV_ProgramSection API and vice versa by FLASH_DRV_SetFlexRamFunction API.
This is example code of EEE usage sequence:
{
0x00000000u,
};
{
return ret;
}
#if ((FEATURE_FLS_HAS_FLEX_NVM == 1u) & (FEATURE_FLS_HAS_FLEX_RAM == 1u))
{
{
return ret;
}
else
{
{
return ret;
}
{
return ret;
}
}
}
else
{
{
return ret;
}
}
#endif
Important Note
- If using callback in the application, any code reachable from this function must not be placed in a Flash block targeted for a program/erase operation to avoid the RWW error. Functions can be placed in RAM section by using the START/END_FUNCTION_DEFINITION/DECLARATION_RAMSECTION macros.
- To suspend the sector erase operation for a simple method, invoke the FLASH_DRV_EraseSuspend function within callback of FLASH_DRV_EraseSector. In this case, the FLASH_DRV_EraseSuspend must not be placed in the same block in which the Flash erase sector command is going on.
- FLASH_DRV_CommandSequence, FLASH_DRV_EraseSuspend and FLASH_DRV_EraseResume should be executed from RAM or different Flash blocks which are targeted for writing to avoid the RWW error. FLASH_DRV_EraseSuspend and FLASH_DRV_EraseResume functions should be called in pairs.
- To guarantee the correct execution of this driver, the Flash cache in the Flash memory controller module should be disabled before invoking any API.
- Partitioning FlexNVM and FlexRAM for EEPROM usage shall be executed only once in the lifetime of the device.
- After successfully partitioning FlexNVM and FlexRAM for EEPROM usage, user needs to call FLASH_DRV_Init to update memory information in global structure.