MCU memory allocation

Publisher:闪耀之星Latest update time:2014-12-12 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

   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.

Keywords:MCU Reference address:MCU memory allocation

Previous article:Keil optimization level setting
Next article:Nuvoton NuMicro M051 Timer 1 Test Program

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号