nvm module provides a non-volatile memory for the data by using an external
EEPROM with integrated transparent hardware error correcting code (ECC). It
handles the backup and recovery features between the participating submodules
and depends on the implementation (EEPROM, BKSSRAM or SRAM). The user has to
group the data in channels which are taped with a checksum and handled as one
entity. Usually, the data are first written into the SRAM (or BKPSRAM if
available) and then backed up into the EEPROM. Alternatively, the data can be
written directly into the EEPROM without a buffer. When a buffer is used, it
can be located in SRAM or in BKPSRAM (Backup SRAM) with following different
- no data loss in case of any kind of reset (button cell buffered SRAM)
- SRAM (cleared memory section):
- data loss in case of any kind of reset
- SRAM (non-cleared memory section):
- data loss only in case of power down, no data loss in case of software reset or warm startup
6.18.1. Module Files¶
- Driver Configuration:
6.18.2. Data Management¶
188.8.131.52. Data Structure¶
The data storage of the EEPROM is organized in coherent data entities called channels. Each channel has its own storage area reserved in the EEPROM. EEPROM channels can be used as a non-volatile backup for corresponding BKPSRAM channels. Furthermore, every channel has a checksum, an ID, and optionally a software write protection and a pointer to the location of the corresponding channel in the SRAM or BKPSRAM. Additionally, every channel has a dirty flag, which is set to indicate a modification of data to initiate a backup process to the EEPROM. EEPROM channels can be configured to be updated automatically during startup, if data is not up-to-date or in case it is corrupted.
Example: EEPROM-channels A, B and C have coherent BKPSRAM channels. E has a coherent SRAM channel. D does not have a coherent channel: the data are written directly into this channel.
184.108.40.206. Statemachine of the EEPROM Driver¶
The statemachine is capable of handling the requests to write, read or to go into an idle mode. The states of the statemachine are:
||Initial state at startup|
||First state which will be entered after startup: the initialization sequence is started here|
||Checking of EEPROM availability and actual initialization|
||Idle mode, ready to receive commands|
||Start of write process|
||Activation and verification of the write mode of the EEPROM|
||Page length and timers are set, actual write command is being sent|
||Verification of the write process|
||Page length and timers are set, read command is being sent|
||Verification of the write process|
||Checksum verification of the written/read data|
Handling of an initialization error
Handling of read errors
Handling of write errors
Before any data can be written or read, the EEPROM is being initialized by sending the request to go to idle. If the initialization was successful, the version number of the software and the EEPROM Header Information is checked, to ensure an equal memory layout software and NVM. Afterwards the data channels will be initialized.
220.127.116.11. Channel Initialization¶
During the initialization, the driver will check and update the data of the selected channels as shown in Fig. 6.28. The specific control mechanisms to identify corrupt data are:
- Hardware-Check of Brownout Reset (BOR)
- Software-Check of BKPSRAM checksum
- Software-Check of EEPROM checksum
6.18.3. NVM Configuration¶
18.104.22.168. Channel Configuration¶
Users can create new channels by declaring them in the array
When creating channels, attention should be paid to the following aspects:
- It is advisable to create a structure to work with the correct data format.
- When creating the structure, users have to pay attention to the correct data alignment. Data should be stored in blocks of 4 byte (32 bit) to avoid errors when reading or writing data. Example: Do not store a 32 bit number directly behind a 16 bit number. Instead, insert a 16 bit dummy in between.
- Make sure channels do not overlap.
- The checksum must always be stored in the last 4 bytes of the channel.
- Make sure that the channel ID matches the position in the array.
- Setting the write protection is optional and should only be set if the channel data in the EEPROM does not have to be changed during the runtime.
- Setting the pointer to the location of the corresponding channel (BKPSRAM or SRAM) is also optional, but necessary if an automatic update of the data should be done during the initialization.
- To support the automatic update function, the user has to make two function
calls in the function
EEPR_InitChannelData(), just like the other channels that are handled there.
- In the function
EEPR_SetDefaultValue(EEPR_CHANNEL_ID_TYPE_e eepr_channel)the default values of the new channel must be set.
- It is advisable to implement a GET and SET function for the new channel in
bkpsram_cfg.c, similar to the implemented examples, to ensure data consistency.
22.214.171.124. Write and Read during Runtime¶
To write or read an EEPROM channel during runtime, the user should use the
EEPR_SetChannelData(EEPR_CHANNEL_ID_TYPE_e eepr_channel, uint8_t *dest_ptr)
EEPR_GetChannelData(EEPR_CHANNEL_ID_TYPE_e eepr_channel, uint8_t *dest_ptr)
and trigger the state machine until it is either in the idle mode again or in
an error state. To use the BKPSRAM pointer defined in the channel config, the
source/destination pointer can be declared to be a NULL-pointer. To write or
read the data of a BKPSRAM channel, the implemented GET and SET functions can
The EEPROM can be initialized manually, by setting the request to go to IDLE
and triggering the state machine until the desired state is reached.
Alternatively, the EEPROM can be initialized automatically by calling the
EEPR_ERRORTYPES_e EEPR_Init(void), which will initialize the
EEPROM first and the channels afterwards. The BKPSRAM module can be
initialized by calling
126.96.36.199. Usage during runtime¶
During runtime a datahandler will manage the write and read process of the
channels. It continuously checks if there is a read request or a write request
for every channel.
The read/write requests can be set with
void EEPR_SetChReadReqFlag(EEPR_CHANNEL_ID_TYPE_e eepr_channel) for read
void EEPR_SetChDirtyFlag(EEPR_CHANNEL_ID_TYPE_e eepr_channel)
for write requests.
Afterwards the datahandler will take care of the write-process itself. How the
write/read-process works can be seen in Fig. 6.29.
After the write/read process is complete, the datahandler will diagnose the
188.8.131.52. Other Functions¶
void EEPR_Trigger(void) triggers the statemachine of the EEPROM.
EEPR_RETURNTYPE_e EEPR_SetStateRequest(EEPR_STATE_e state_req,
EEPR_CHANNEL_ID_TYPE_e channel, uint8_t* ramaddress) is used to request the
desired state and returns if the request was accepted.
EEPR_ERRORTYPES_e EEPR_Init(void) initializes the EEPROM.