SLAAE58 april   2023 MSPM0C1105 , MSPM0C1106 , MSPM0G1105 , MSPM0G1106 , MSPM0G1107 , MSPM0G1505 , MSPM0G1506 , MSPM0G1507 , MSPM0G1518 , MSPM0G1519 , MSPM0G3105 , MSPM0G3106 , MSPM0G3106-Q1 , MSPM0G3107 , MSPM0G3107-Q1 , MSPM0G3505 , MSPM0G3506 , MSPM0G3506-Q1 , MSPM0G3507 , MSPM0G3507-Q1 , MSPM0G3518 , MSPM0G3518-Q1 , MSPM0G3519 , MSPM0G3519-Q1 , MSPM0H3216 , MSPM0L1105 , MSPM0L1106 , MSPM0L1303 , MSPM0L1304 , MSPM0L1304-Q1 , MSPM0L1305 , MSPM0L1305-Q1 , MSPM0L1306 , MSPM0L1306-Q1 , MSPM0L1343 , MSPM0L1344 , MSPM0L1345 , MSPM0L1346

 

  1.   1
  2.   Abstract
  3.   Trademarks
  4. 1Introduction
  5. 2Implementation
  6. 3Software Description
  7. 4Application Aspects
  8. 5References

Software Description

This software provides basic EEPROM functionality. At least 2 sectors are used to emulate the EEPROM. These sectors are broken into several records each containing header to determine the validity of the data as described above. To reduce the number of flash operations, a buffer in RAM of the same size as virtual EEPROM is used to copy data from active record. Besides, 4 global variables are used to trace the active record and 3 global variables are used for flags.

Software functionality and flow

In total, only three functions are called directly by the user.

  • EEPROM_TypeA_init
  • EEPROM_TypeA_writeData
  • EEPROM_TypeA_eraseLastSector

The high-level software flow is shown in Figure 3-1. The device should first go through the initialization code. By calling EEPROM_TypeA_init, it will search active record and check the format of Flash. If active record exists, the data of active will be copied to the buffer in RAM. If format is not correct, the format will be repaired. After initialization, there will be a properly formatted flash area for EEPROM emulation, several global variables tracing the active record, and a buffer in RAM which has copied the active record’s data.

In the application, user can directly read or edit buffer in RAM. Only when EEPROM_TypeA_writeData is called, the buffer is stored into flash to be a new active record. EEPROM_TypeA_writeData will also set the erase flag when the sector is full. In the flow, EEPROM_TypeA_eraseLastSector is called immediately when the erase flag is set. According to the application, users can select the appropriate point in time to erase.

GUID-20230417-SS0I-L2MC-1PJM-5X5LDS177VBS-low.svg Figure 3-1 High-Level Software Flow

EEPROM Functions

To implement this functionality, six functions are required. In addition to the three functions mentioned above, the remaining three functions are called primarily by EEPROM_TypeA_init.

  • EEPROM_TypeA_init
  • EEPROM_TypeA_writeData
  • EEPROM_TypeA_eraseLastSector
  • EEPROM_TypeA_readData
  • EEPROM_TypeA_searchCheck
  • EEPROM_TypeA_repairFormat

Besides, 7 global variables are used to record the status of the EEPROM emulation. 4 global variables are used to trace the active record.

  • uint32_t gActiveRecordAddress;
  • uint32_t gNextRecordAddress;
  • uint16_t gActiveRecordNum;
  • uint16_t gActiveSectorNum;

gActiveRecordAddress and gNextRecordAddress are used to store the address about active record.

gActiveRecordNum and gActiveSectorNum are used to trace the position of active record.

3 global variables are used for flags.

  • bool gEEPROMTypeASearchFlag;
  • bool gEEPROMTypeAEraseFlag;
  • bool gEEPROMTypeAFormatErrorFlag;

gEEPROMTypeASearchFlag is set when the active record exists.

gEEPROMTypeAEraseFlag is set when the sector is full and needs to be erased.

gEEPROMTypeAFormatErrorFlag is set When format error is found.

EEPROM_TypeA_init

The function is used to initialize the EEPROM emulation. Through this function, user’s data is restored and active record in Flash is tracked. The function includes the following features:

  • active record search and format check
  • read active record to buffer in RAM
  • format repair if necessary, by calling EEPROM_TypeA_repairFormat

The software flow is shown in Figure 3-2. Firstly, it searches the active record and checks the format by calling EEPROM_TypeA_searchCheck. According to the flag set by EEPROM_TypeA_searchCheck, it can be determined whether active record exists or is format correct. If active record exists, the data of active record will be copied to the buffer in RAM by calling EEPROM_TypeA_readData, and the pointer is set to the active record. If active record does not exist, all sectors are erased and the pointer is set to the beginning of the first sector.

If format is not correct, format will be repaired by calling EEPROM_TypeA_repairFormat. After format repair, all sectors are erased and the active record is restored. Flash area comparison before and after EEPROM_TypeA_init is shown in Figure 3-3 and Figure 3-4.

The input of the function is the address of the buffer in RAM. The output of the function is the operation states. Besides, all 7 global variables are updated in the function.

  • Input: &buffer[0]
  • Output: operation state
GUID-20230417-SS0I-8L3C-XPZD-3FJ2SWR2LXCL-low.svg Figure 3-2 Software Flow of EEPROM_TypeA_init
GUID-20230417-SS0I-GZV8-S5Q6-C6P7XBK0HR9W-low.png Figure 3-3 EEPROM_TypeA_init for the Normal Scene
GUID-20230417-SS0I-GVCJ-WZR9-5FVJR19DGDHT-low.png Figure 3-4 EEPROM_TypeA_init for the Abnormal Scene

EEPROM_TypeA_writeData

EEPROM_TypeA_writeData is used to store the data from buffer in RAM to Flash. Through the function, a new active record is added to the Flash.

Users can directly read or edit buffer in RAM. However, only after calling this function, buffer’s data is copied to the new active record. In other words, Flash area is to record/backup the buffer. When power off, all data in RAM is lost, and the active record is used to recover the data.

The software flow is shown in Figure 3-5. Firstly, it checks whether next record is erased. Then it begins storing data to next record. The process follows Figure 2-3:

  1. Set the record’s header to ‘Recording’
  2. Copy the data from buffer in RAM to the record
  3. Set the record’s header to ‘Active’
  4. If last active record exists, set it header to ‘Used’

Finally, it checks whether the sector is full. If so, gEEPROMTypeAEraseFlag will be set. Besides, the global variables about active record are updated. Flash area comparison before and after EEPROM_TypeA_writeData is shown in Figure 3-6.

The input of the function is the address of the buffer in RAM. The output of the function is the operation states.

  • Input: &buffer[0]
  • Output: operation state
GUID-B39C88FD-1E9F-490C-995F-C557D99FC374-low.png Figure 3-5 Software Flow of EEPROM_TypeA_writeData
GUID-44D67BF1-58C1-4C8F-ADF0-373E54609F1F-low.png Figure 3-6 Software Flow of EEPROM_TypeA_writeData

EEPROM_TypeA_eraseLastSector

EEPROM_TypeA_eraseLastSector is used to erase the Flash sector when it is full. While calling EEPROM_TypeA_writeData, gEEPROMTypeAEraseFlag will be set if the sector is full. It is recommended to call the EEPROM_TypeA_eraseLastSector immediately when gEEPROMTypeAEraseFlag is set, as in Figure 3-1. However, users can change the time point to erase the sector by modifying the high-level software flow.

The output of the function is the operation states.

  • Input: void
  • Output: operation state

EEPROM_TypeA_readData

EEPROM_TypeA_readData is used to copy the data from active record in Flash to buffer in RAM. This function is called in EEPROM_TypeA_init. While users can directly read or edit buffer in RAM, EEPROM_TypeA_readData is not usually used directly by users.

The input of the function is the address of the buffer in RAM.

  • Input: &buffer[0]
  • Output: void

EEPROM_TypeA_searchCheck

EEPROM_TypeA_searchCheck is used to search the active record and check the format. The function traverses the headers of all records. If active record is found, search flag will be set, and global variables about active record will be updated. If there is a header of ‘Recording’ or an invalid header or other format-error situation, error flag will be set. The function is called in EEPROM_TypeA_repairFormat. The software flow is shown in Figure 3-7.

The function outputs the result by setting global variables, so both the input and output of the function are void.

  • Input: void
  • Output:void
GUID-2FE5D581-B291-424F-ADC3-CA8C1E8C36F7-low.png Figure 3-7 Software Flow of EEPROM_TypeA_searchCheck

EEPROM_TypeA_repairFormat

EEPROM_TypeA_repairFormat is used to repair the format. Before calling the function, active record should have been read to the buffer in RAM. Through the function, all sectors are erased and the data is copied from buffer in RAM to the new record in Flash. The function is called in EEPROM_TypeA_repairFormat. The software flow is shown in Figure 3-8.

The input of the function is the address of the buffer in RAM. The output of the function is the operation states.

  • Input: &buffer[0]
  • Output:operation state
GUID-47FB536F-D9B0-48D4-A864-9C4500AC1101-low.png Figure 3-8 Software Flow of EEPROM_TypeA_repairFormat

Application Integration

Applications requiring this functionality need to include the eeprom_emulation_type_a.c and eeprom_emulation_type_a.h files provided for MSPM0 MCUs. The Flash API also needs to be included for the specific device. For example, for the MSPM0G3507/MSPM0L1306 the following files are needed:

  • eeprom_emulation_type_a.c
  • eeprom_emulation_type_a.h
  • ti_msp_dl_config.c
  • ti_msp_dl_config.h

EEPROM emulation library has been included in the SDK supporting MSPM0 products.

All Flash API files are also included in the SDK.

GUID-9633C96F-BD9F-496F-B222-94783B7B55CE-low.png Figure 3-9 Files Required by the Software

EEPROM emulation memory footprint

Table 3-2 details the footprint of the EEPROM emulation driver in terms of flash size and RAM size. The table and figure below have been determined using the Code Composer Studio (Version: 11.2.0.00007) with optimization level 2.

Table 3-1 Structure of EEPROM Emulation
Mechanism Minimum Required Code Size (bytes)
Flash SRAM
EEPROM emulation type A with 64 bytes record size 2616 71
EEPROM emulation type A with 128 bytes record size 2616 135
EEPROM emulation type A with 256 bytes record size 2616 273

EEPROM emulation timing

This section describes the timing parameters associated with the EEPROM emulation driver based on two 1KB flash sectors.

All timing measurements are performed with these conditions:

  • MSPM0G3507
  • System clock at 32 MHz
  • With execution from flash
  • At room temperature

The functions are tested with these parameters:

  • Record size: 128 bytes
  • Number of sectors used: 2
  • Sector address: 0x00001000
Table 3-2 Timing of EEPROM Emulation Operations
Operation Typical (µs)
EEPROM_TypeA_init with correct format 80
EEPROM_TypeA_init with format repair 4467
EEPROM_TypeA_writeData 848
EEPROM_TypeA_eraseLastSector 3612