When we talk about memory, we will think of PC. There is also memory for microcontrollers or ARMs. The simple understanding is: memory is a place to store things, but this thing is data. Well, let's focus on MCU. For an MCU, the capacity of SRAM and flash will be told in the performance description. For beginners, they will not consider and care about these things. They just use them when they get them. In fact, these quantities are very important. Think carefully, why can the code run, how much code is there, how the defined int, short and other types of variables are allocated and stored, these problems are all related to memory.
First of all, the memory of the microcontroller can be divided into RAM and ROM in size. The difference between RAM and ROM will not be explained here. We can equate them to flash and sram. According to the definition of flash and sram, the data in flash can be saved when power is off, but the data in sram cannot. However, the execution speed of sram is faster than flash. The program of the microcontroller can be divided into code (code storage area), RO-data (read-only data storage area), RW-data (read-write data storage area) and ZI-data (zero-initialized data area). Under the MDK compiler, the values of these four quantities in the code can be observed, as shown in Figure 1 below:
Code and RO-data are stored in flash, so the sum of the two is the size of the space that needs to be allocated to them in the microcontroller flash (and is equal to the size of the .bin file generated by the code). In addition, RW-data and ZI-data are stored in sram, and the sum of the two is the size of the space that needs to be allocated to them in the microcontroller sram.
In addition, we will inevitably think of the relationship between the stack area (stack), heap area (heap), global area (static area), text constant area and program code area and the code, RO-data, etc. introduced above.
1. Stack area: automatically allocated and released by the compiler, storing function parameter values, local variable values, etc. Its operation is similar to the stack in the data structure. These values are readable and writable, so the stack should be included in the RW-data (read-write data storage area), that is, the sram of the microcontroller.
2. Heap: Generally allocated and released by the programmer. If the programmer does not release it, it may be reclaimed by the OS when the program ends. It can be understood that these are also included in the sram of the microcontroller.
3. Global area (static area) (static): The storage of global variables and static variables is placed together. Initialized global variables and static variables are in one area, and uninitialized global variables and uninitialized static variables are in another adjacent area. They are released by the system after the program ends. These data are also readable and writable, and are contained in sram like stack and heap.
4. Text constant area: Constant strings are placed here. These data are read-only and are allocated in RO-data (read-only data storage area), which is included in the flash.
5. Program code area: The binary code of the function body is stored. It can be imagined that it is also included in the flash. Because for the MCU, when it is powered on again, the code will continue to run and will not disappear, so it is stored in the flash.
In summary, the memory allocation of MCU is basically like this. The flash and sram addresses corresponding to the storage space are not mentioned. These will be discussed later! If there are any mistakes, please correct them.
Previous article:Why does a microcontroller need a crystal oscillator? Can the value of the external crystal be chosen at will?
Next article:What is the function of pull-up and pull-down resistors in microcontrollers?
Recommended ReadingLatest update time:2024-11-16 11:39
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Is this the worst impedance processing you have ever encountered?
- PCB panelization
- RPG game ported using RP2040 and MicroPython
- For large project files containing nios, timing constraints, and layout and routing, modify the internal module names and some variable names.
- What is output impedance? What is impedance matching?
- High-frequency transformer sandwich winding method: primary wrapped in secondary? Or secondary wrapped in primary?
- Detailed description of I2C bus protocol and timing, getting started is no longer difficult
- Send a WDS configuration software for SI4463
- LM1875 Op Amp
- OpenBLT is an open source bootloader with comprehensive functional information, supporting USB, CAN, 232 and TCP/IP