Use flash and eerom]

Source: Internet
Author: User

Recently, when I was reading the code, I encountered a situation where I used flash to simulate the EEPROM. I was blind to seeing this, for a person who sometimes cannot even distinguish flash and EEPROM, how can he read and use flash to simulate EEPROM? This program is really like browsing tianshu. I used to check the internet. So I made up my mind to understand the two paper tigers.

EEPROM

 

1. What is flash? What is EEPROM?

The full name of EEPROM is "Electro-erasable programmable read-only memory", that is, electrically erasable programmable read-only memory. Well, in other words, EEPROM is a memory that can be used to store programs and data. At the beginning, there was no such EEPROM. At the beginning, he used his grandfather, Rom, but Rom, which could not be programmed. When leaving the factory, what content would always be what content, not flexible. Later, when the prom appeared, you could write it once by yourself, but if you write an error, you could only change one piece. So if the programmer found that he forgot to write a semicolon, then ....... With the advancement of science and technology and the development of socialism, an EPROM that can be wiped multiple times has finally emerged. However, you have to take the chip to the ultraviolet rays, if the error rate of writing code is as high as mine, it is estimated that the UV lamp can be damaged, so it is not convenient. Finally, the eeprom appeared, saving a large number of programmers and finally modifying the program in the ROM conveniently. Mom no longer has to worry about my learning! The eeprom mentioned now is in a narrow sense. This rom features random access and modification of any byte, and can be written to each bit as 0 or 1. This is the most traditional type of EEPROM. After power loss, data is not lost. It can be saved on July 15, and can be erased for times. High reliability, but complex circuits/high costs. Therefore, the current EEPROM is composed of dozens of thousands of bytes to hundreds of thousands of bytes, with a minimum of over kb.

The Flash we mentioned belongs to the EEPROM in a broad sense. They used to be one of them, because it is also an electrically erasable Rom. We call it flash to distinguish the General bytes-based EEPROM.

2. But why should we be separated as a family? Is it just to differentiate the write-erase mode?

Generally, flash in the single chip microcomputer is used to store the Running code, which cannot be changed during the running process. The EEPROM is used to save user data and can be changed during the running process, for example, the initialization time of a clock is set to, and then changed to during running. This is saved in the EEPROM and is not afraid of power loss. Even if it is powered on again, it does not need to be adjusted.

But the biggest difference is that flash is operated by sector, while EEPROM is operated by byte. The addressing methods are different, the storage unit structure is also different, and the flash circuit structure is relatively simple, the same capacity accounts for a small chip area, and the cost is naturally lower than that of the EEPROM, so it is suitable for use as program memory, while the EEPROM is more used as non-easy data storage. Of course, Flash is also used for data storage, but the operation is much more troublesome than EEPROM, so the more user-friendly MCU design will integrate flash and EEPROM two non-volatile memory, the low-cost design often only involves flash, while the early electroerasable mcu was in the eeprm structure, which has basically been discontinued. In the internal circuit of the chip, flash and EEPROM have different circuits and address spaces, and their operation methods and commands are naturally different, regardless of the Von noiman structure or Harvard structure. Technically, both program memory and non-easy-to-lose data storage can only use the falsh or EEPROM structure, or even simulate the "Data Storage zone" in the program storage area using "flexible" technical means ", even so, the two are still different in concept, which is a basic knowledge problem.

3. Why use flash to simulate EEPROM

In many application scenarios, you need to use EEPROM to store non-volatile data. However, in order to control costs, the Italian semiconductor has not integrated the EEPROM in the stm32f10x series chip, therefore, we need to use its internal integrated flash to simulate the eeprom through software to achieve the same effect. This is a sentence borrowed from others' blogs. In fact, I refused at first, but this is the case. To be honest, I really don't like the terms they use. What is non-volatile data? Can you speak people? We have to go through these tips again. When the computer is suddenly powered off or accidentally shut down, data will not be accidentally lost. It is called non-volatile data!

To sum up,Both EEPROM and flash belong to Rom. Later, they are separated for different purposes. Flash stores user code, and EEPROM is used to store user data. Some chips are integrated with flash and EEPROM, but some are not integrated with EEPROM. They need to be connected outside the chip. In order to save costs, they sometimes use flash to simulate EEPROM. Use space to change the time.

The flash of stm32 is divided into primary storage blocks and information blocks. The primary storage block is used to save specific program code and user data. The information block is used to store 2 kb of boot loader and B of user configuration information zone at the factory of stm32. The primary storage block is divided by pages. The size of a page is 1 kb. The value range is within kb starting from 0x08000000.

When we select a single-chip microcomputer, the flash capacity in the single-chip microcomputer is a common parameter, but how do we determine whether the program we write meets the flash capacity of the single-chip microcomputer? After checking on the internet, when we use keil5 to write a program, we can see the following information in the build output box after the compilation is completed:

Code: The Flash size occupied by the Program (flash ).
Ro-data: Read Only-data, which indicates the constants defined by the program, such as the const type (flash ).
RW-data: Read Write-data, indicating the initialized global variable (SRAM)
Zi-data: Zero init-data, indicating the uninitialized global variable (SRAM)
With this, you can know the size of flash and SRAM you are currently using. Therefore, you must note that the size of the program is not large or small. the size of the Hex file, but the sum of the compiled code and Ro-data. Unit: bit. So the size of our program is

34074 + 798 = 34872bit = 34.1kb

Use flash and eerom]

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.