MCU analog EEPROM basic function

Source: Internet
Author: User
Tags reset valid blank page

MCU analog EEPROM basic function

If your MCU's flash is large enough. And your MCU provides self-programmed flash instructions. You can simulate an EEPROM area via Flash. Used to store data.
This document refers to the St company's AN2594 documentation. Use the examples provided by St. Designed to learn how to simulate a piece of EEPROM using Flash.






By the table we get a comparison of erase times. The internal simulation is obviously faster. However, I would like to remind you that the data stored in the analog EEPROM needs to be changed frequently. The frequent point here is that time is less than the page erase time. Since the simulated EEPROM is flash-only, the entire page can be erased. Therefore, it is recommended that the frequently modified data do not use simulated EEPROM. However, if you simply store the data before the electricity or 1s clock record a piece of data can be considered. This can save the cost of external EEPROM.




The above figure we get the example provided by St company is using two-page flash to simulate. Why use two pages? If I only use one page, I think about it. Because there is only one page. The data can only be written down. There will be a full time. And after you change the data. The previous data will not be erased. When one of the pages is full. The data from the page will be moved to the second page, and the first page erased.


This picture is the most critical one. Helps to understand how to store data and read data. The simulated EEPROM is composed of two parts. are virtual addresses and data, respectively. Are 16bit. The virtual address exists at a high level. There is a low data level.
For example, at the beginning of the virtual address 0x7777h write Data 0x1232h. The data is stored as shown in the figure. If another number is written to the same address, the data exists in the next location. But the previous data will not be erased immediately. If you want to use ST's function at this time to read the 0x7777h virtual address of the data. So the reading is 0x1245h, not 0x1232h. Because reading is read from bottom to top. Read to the first data that matches that address. That would be a good understanding.
When the data is full. The new data being written will be present in the second page. The function is automatically called to copy the first page of data that is not duplicated to the second page. such as our virtual address 0x7777h and 0x5555h data. As shown in the figure. Then erase the first page. Two-page alternate use. Speaking of which, you may understand why the frequently modified data is not suitable for the presence of simulated EEPROM. If modified frequently. So soon a page is full. Then you need to erase this page. Requires 20ms. You understand what's going on behind you.
Because of my limited knowledge, I can only understand so much. If you want to port the program to another microcontroller. You can refer to this way of thinking. Oh.

Here is a little learning experience.
Note by Chenfen
/*
1. Use STM32 internal flash analog EEPROM to read and write, define two-page flash for PAGE0 Page1
The start address of the flash simulation is modified to eeprom_start_address in eeprom.h
2. Modify the number of storage variables required to implement the Numbofvar in the eeprom.h file
3. Modify Virtaddvartab[numbofvar] To make changes to the virtual address
4. Write data written immediately after write to virtual address Virtaddvartab (0<=i<numbofvar)
5. The first address of each page is written to the page state (Earse,reveice,vild)
6. When the same address is written again, it will not erase the last write, but in the analog EEPROM area at the end of the non-written place again write data, virtual address,
Reading is the beginning of the tail to match the address, that is, read the last write content.
7. The simulated EEPROM area is divided into 2 pages, if one page is full to erase the data that is not duplicated in this page after copying to another page, 2 pages are used interchangeably.
8. Add a string storage function to change the 8bit ASCII code to store two-bit strings for 1 16bit addresses

STM32 's Application manual AN2594 provides an internal flash analog EEPROM method that can be applied to external flash other MCUs with internal flash.

the difference between 1.Flash and EEPROM

eeprom:electrically erasable programmable read-only memory, electrically erasable programmable read-only memory-a memory chip with no loss of data after power-down.

Flash: Flash, it combines the advantages of ROM and RAM, not only the performance of EEPROM, but also the ability to quickly read data (the advantages of NVRAM), so that the data will not be lost due to power loss.

EEPROM needs more components and silicon, in order to reduce the system cost, more MCU use flash instead of EEPROM storage code and data.

Eeprom FLASH
Write Time

A few milliseconds.

Random bytes: 5-10ms

Page: Character/100us (5-10ms/page)

Word Programming Time: 20US
Erase time No Page/Piece Erase time: 20ms
How to Write

Once activated, no CPU interference is required

Only need power

Once started, CPU interference is required
Read access

Serial: 100US

Random Word: 92us

Page: Byte/2.25us

Parallel: 100ns

Word/Several CPU cycles

Access time: 35ns

Write/Erase

Cycle

10k-1000k Cycle 10k-100k Cycle
Flash Write access speed, external serial EEPROM write is not affected by the CPU reset, the appropriate decoupling capacitor can maintain the completion of the write, EEPROM does not need to erase, flash erase takes time, Flash software design needs to fully consider the reset and interrupt situation;

2. Implement EEPROM simulation

You need at least two pages of the same size: one provides verbatim programming and the other provides the data to receive the front page. When one of the pages is full. The data from the page will be moved to the second page, and the first page erased. The first 16 characters of each page mark the page status.

Page has three states: erase: blank page; receive data: Receive data from other full pages; Effective page: Contains valid data, knowing that all valid data is transferred to other pages to change state;

Each variable element contains a virtual address and data for searching and updating. When the data is modified, the modified virtual address and data are saved in a new location, and the last value is returned when the data is taken.

Learn how to store data and read data from the above image. The simulated EEPROM has two parts, namely virtual address and data, all of which are 16bit. The virtual address exists at a high level and the data is low.

For example, at the beginning of the virtual address 0x7777h write Data 0x1232h. The data is stored as shown in the figure. If another number is written to the same address, the data exists in the next location. But the previous data will not be erased immediately. If you want to read the data for the 0x7777h virtual address at this time. So the reading is 0x1245h, not 0x1232h. Because reading is read from bottom to top. Read to the first data that matches that address.

When the data is full. The new data being written will be present in the second page. This will automatically copy the first page of data that is not duplicated to the second page. For example, our virtual address 0x7777h and 0x5555h corresponding data, immediately after 0x6666h. As shown in the figure. Then erase the first page. Two-page alternate use. The process of writing the data determines whether the page is full, searches from top to bottom, and finds FFFF, which can be written directly. If you search the full page, there is no FFFF, indicating that the page is full, you need to write to the next page, and perform a move and erase operation.

The data needs to change frequently, and it is not recommended to use secondary methods.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.