• Menu
  • Product
  • Email
  • PDF
  • Order now
  • Emulate EEPROM With Flash (Type A)

    • SLAAEN2A February   2025  – August 2025 MSPM0C1103 , MSPM0C1103-Q1 , MSPM0C1104 , MSPM0C1104-Q1 , MSPM0C1106 , MSPM0C1106-Q1 , MSPM0G1105 , MSPM0G1106 , MSPM0G1107 , MSPM0G1505 , MSPM0G1506 , MSPM0G1507 , MSPM0G1518 , MSPM0G1519 , MSPM0G3105 , MSPM0G3105-Q1 , MSPM0G3106 , MSPM0G3106-Q1 , MSPM0G3107 , MSPM0G3107-Q1 , MSPM0G3505 , MSPM0G3505-Q1 , MSPM0G3506 , MSPM0G3506-Q1 , MSPM0G3507 , MSPM0G3507-Q1 , MSPM0G3518 , MSPM0G3518-Q1 , MSPM0G3519 , MSPM0G3519-Q1 , MSPM0H3216 , MSPM0H3216-Q1 , MSPM0L1105 , MSPM0L1106 , MSPM0L1117 , MSPM0L1227 , MSPM0L1227-Q1 , MSPM0L1228 , MSPM0L1228-Q1 , MSPM0L1303 , MSPM0L1304 , MSPM0L1304-Q1 , MSPM0L1305 , MSPM0L1305-Q1 , MSPM0L1306 , MSPM0L1306-Q1 , MSPM0L1343 , MSPM0L1344 , MSPM0L1345 , MSPM0L1346 , MSPM0L2227 , MSPM0L2227-Q1 , MSPM0L2228 , MSPM0L2228-Q1

       

  • CONTENTS
  • SEARCH
  • Emulate EEPROM With Flash (Type A)
  1.   1
  2. 1Description
  3. 2Required Peripherals
  4. 3Design Steps
  5. 4Design Considerations
  6. 5Software Flow Chart
  7. 6Application Code
  8. 7Additional Resources
  9. 8Revision History
  10.   Trademarks
  11. IMPORTANT NOTICE
search No matches found.
  • Full reading width
    • Full reading width
    • Comfortable reading width
    • Expanded reading width
  • Card for each section
  • Card with all content

 

Subsystem Design

Emulate EEPROM With Flash (Type A)

1 Description

This subsystem demonstrates how to implement Electrically Erasable Programmable Read-Only Memory (EEPROM) emulation (Type A) in the application. EEPROM emulation allows a device to emulate EEPROM in Flash memory, and make an equivalent durability similar to EEPROM. The following features are available using Flash memory:

  • Data retention after unexpected power loss
  • Flexible structure for different applications
  • User-configured erase operation

Download the code for this example.

There are two types of EEPROM emulation libraries for MSPM0. Type A is to store one large block of data (64 bytes, 128 bytes or 256 bytes) with a Static Random Access Memory (SRAM) buffer. See the EEPROM Emulation Type A Design application note for details of the library. Type B is to store many small data items (16bit or 32bit) with item identifiers. See also the EEPROM Emulation Type B Design application note for details of the library.

This subsystem shows the usage of Type A. For the Type B subsystem, see the Emulate EEPROM With Flash (Type B) subsystem design.

Figure 1-1 shows a functional diagram of this subsystem.

MSPM0L1306, MSPM0G3507, MSPM0C1104 Subsystem Functional Block
                    Diagram Figure 1-1 Subsystem Functional Block Diagram

2 Required Peripherals

This application requires Flash.

Table 2-1 Required Peripherals
Subblock Functionality Peripheral Use Notes
Flash API (1 ×) Flash Called FLASHCTL in code

3 Design Steps

  1. Add the EEPROM emulation library. The MSPM0 software development kit (SDK) includes the EEPROM emulation library.
    Note: The EEPROM emulation library is based on the Flash API so the drivelib from SDK is also required.
    For Type A, the following files are needed:
    1. eeprom_emulation_type_a.c
    2. eeprom_emulation_type_a.h
    MSPM0L1306, MSPM0G3507, MSPM0C1104 EEPROM Emulation
                            Files Figure 3-1 EEPROM Emulation Files
  2. Add the include path in the code for eeprom_emulation_type_a.h. MSPM0L1306, MSPM0G3507, MSPM0C1104

    Users can modify the start address, the number of sectors to use, and the record size in eeprom_emulation_type_a.h. The default Flash address used for EEPROM emulation is 0x00001000, and 2 sectors are used by default, so 0x00001000-0x000017ff is occupied. Additionally, the default size of the emulated EEPROM is 128 bytes.

    1. #define EEPROM_EMULATION_ADDRESS (0x00001000)
    2. #define EEPROM_EMULATION_SECTOR_ACCOUNT (2)
    3. #define EEPROM_EMULATION_RECORD_SIZE (128)
  3. Define a global array as a buffer in random-access memory (RAM). Every time the system powers on, the data of the emulated EEPROM is loaded from Flash to this buffer using the initialize function. The size of array ought to be equal to the record size in step 2.
    • uint32_t EEPROMEmulationBuffer[EEPROM_EMULATION_DATA_SIZE / sizeof(uint32_t)];
  4. Add the initialize function at the beginning of main(), typically after SYSCFG_DL_init(). This action allows the relevant Flash areas to be formatted correctly and global variables to be allocated correctly. The initialize function EEPROM_TypeA_init() also searches the active record and loads the data from Flash to the buffer in step 3.
    • EEPROM_TypeA_init(&EEPROMEmulationBuffer[0]);
    MSPM0L1306, MSPM0G3507, MSPM0C1104 EEPROM
                            Initialization Figure 3-2 EEPROM Initialization
  5. Users can read or modify the buffer in RAM, as needed, after initialization. When the data from the buffer to Flash need to be stored, call EEPROM_TypeA_writeData() to create a new record in Flash.
    Note: After power down, the data in RAM is lost. To implement data storage after power loss, execute this function at least once.
    • EEPROM_TypeA_writeData(&EEPROMEmulationBuffer[0]);
    MSPM0L1306, MSPM0G3507, MSPM0C1104 EEPROM Write Figure 3-3 EEPROM Write
  6. Add the erase function according to the gEEPROMTypeAEraseFlag. Flash needs to be erased before writing data again and the smallest unit of erasure is sector. For EEPROM emulation, after one sector is full, gEEPROMTypeAEraseFlag is set. Users can call EEPROM_TypeA_eraseLastSector() according to the flag. For example, add the following code after EEPROM_TypeA_writeData() from step 5. Users can also choose an appropriate timepoint to erase the full sector, as needed.
    • EEPROM_TypeA_eraseLastSector();
    MSPM0L1306, MSPM0G3507, MSPM0C1104 EEPROM Erase Figure 3-4 EEPROM Erase

After steps 1 through 6, the EEPROM emulation Type A is implemented in the application. See Section 5 for the flow.

 

Texas Instruments

© Copyright 1995-2025 Texas Instruments Incorporated. All rights reserved.
Submit documentation feedback | IMPORTANT NOTICE | Trademarks | Privacy policy | Cookie policy | Terms of use | Terms of sale