S32 SDK
Flash Memory (Flash)

Detailed Description

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.

  1. Program flash memory for vector space and code store.
  2. 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.
  3. 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.

flash_EEPROM_architecture.jpg
Figure 1. EEPROM Architecture

To handle with various customer's requirements, the FlexRAM and FlexNVM blocks can be split into partitions:

  1. 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.
  2. 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.
  3. 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:

/* Provide information about the flash blocks. */
const flash_user_config_t flashUserConfig =
{
0x00000000u, /* Base address of Program Flash block */
FEATURE_FLS_PF_BLOCK_SIZE, /* Size of Program Flash block */
FEATURE_FLS_DF_START_ADDRESS, /* Base address of Data Flash block */
FEATURE_FLS_FLEX_RAM_START_ADDRESS, /* Base address of FlexRAM block */
NULL_CALLBACK /* Pointer to callback function */
};
/* Declare a FLASH configuration structure which is initialized by FlashInit, and will be used by all flash APIs */
flash_ssd_config_t flashSSDConfig;
/* Always initialize the driver before calling other functions */
ret = FLASH_DRV_Init(&flashUserConfig, &flashSSDConfig);
if (ret != STATUS_SUCCESS)
{
return ret;
}
#if ((FEATURE_FLS_HAS_FLEX_NVM == 1u) & (FEATURE_FLS_HAS_FLEX_RAM == 1u))
/* Configure FlexRAM as EEPROM if it is currently used as traditional RAM */
if (flashSSDConfig.EEESize == 0u)
{
/* Configure FlexRAM as EEPROM and FlexNVM as EEPROM backup region,
DEFlashPartition will be failed if the IFR region isn't blank.
Refer to the device document for valid EEPROM Data Size Code
and FlexNVM Partition Code. For example on S32K144:
- EEEDataSizeCode = 0x02u: EEPROM size = 4 Kbytes
- DEPartitionCode = 0x08u: EEPROM backup size = 64 Kbytes */
ret = FLASH_DRV_DEFlashPartition(&flashSSDConfig, 0x02u, 0x08u, 0x0, false);
if (ret != STATUS_SUCCESS)
{
return ret;
}
else
{
/* Re-initialize the driver to update the new EEPROM configuration */
ret = FLASH_DRV_Init(&flashUserConfig, &flashSSDConfig);
if (ret != STATUS_SUCCESS)
{
return ret;
}
/* Make FlexRAM available for EEPROM */
ret = FLASH_DRV_SetFlexRamFunction(&flashSSDConfig, EEE_ENABLE, 0x0u, NULL);
if (ret != STATUS_SUCCESS)
{
return ret;
}
}
}
else /* FLexRAM is already configured as EEPROM */
{
/* Make FlexRAM available for EEPROM, make sure that FlexNVM and FlexRAM
are already partitioned successfully before */
ret = FLASH_DRV_SetFlexRamFunction(&flashSSDConfig, EEE_ENABLE, 0x0u, NULL);
if (ret != STATUS_SUCCESS)
{
return ret;
}
}
#endif

Important Note

  1. 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.
  2. 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.
  3. 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.
  4. To guarantee the correct execution of this driver, the Flash cache in the Flash memory controller module should be disabled before invoking any API.
  5. Partitioning FlexNVM and FlexRAM for EEPROM usage shall be executed only once in the lifetime of the device.
  6. After successfully partitioning FlexNVM and FlexRAM for EEPROM usage, user needs to call FLASH_DRV_Init to update memory information in global structure.

Modules

 Flash Memory (Flash)