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:
Figure 1:
Among them, code and RO-data are stored in flash, so the sum of the two is the size of the space that flash in the microcontroller needs to allocate to them (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 sram in the microcontroller needs to allocate to them.
In addition, we will inevitably think of the relationship between the stack area, heap area, global area (static area), text constant area and program code area and the code, RO-data, etc. introduced above.
1. Stack area (stack): automatically allocated and released by the compiler, storing function parameter values, local variable values, etc. Its operation method is similar to the stack in the data structure. These values are readable and writable, so the stack should be included in RW-data (read-write data storage area), that is, the sram of the microcontroller.
2. Heap area (heap): generally allocated and released by the programmer. If the programmer does not release it, it may be recovered 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): 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 contained in flash. 5.
Program code area: The binary code of the function body is stored. It can be imagined that it is also contained in flash, because for MCU, when it is powered on again, the code will continue to run and will not disappear, so it is stored in 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, which will be discussed later! If there are any errors, please correct them.
Previous article:Keil optimization level setting
Next article:Nuvoton NuMicro M051 Timer 1 Test Program
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Introduction to wiring arrangement between printed circuit board components
- Sensitivity of automotive electronic logos in high and low temperature environments
- When BLE meets MEMS——DIY Bluetooth somatosensory controller (demonstration)
- Should OPC abandon the pit?
- Video signal detection
- Temperature and humidity monitoring system based on ZigBee-WSN
- Ultra-wideband is really popular. Let’s discuss it together.
- 【AD21】How to set the spacing between multiple traces to be consistent
- 【CC1352P review】——by cruelfox
- Do I need to add a pull-down resistor to the GPIO of STM32?