Detailed explanation of MCU memory allocation

Publisher:冰山火影1977Latest update time:2020-06-03 Source: elecfansKeywords: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:

Detailed explanation of MCU memory allocation

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.

Keywords:MCU Reference address:Detailed explanation of MCU memory allocation

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

Talking about the automated testing in single chip microcomputer programs
Testing, I believe that every programmer will be familiar with it, and we will think of a series of terms such as unit testing, integration testing, release testing, black box testing, white box testing, etc. But in the field of single-chip microcomputers, more functional testing is done. After trying the product, tes
[Microcontroller]
Design of Portable Digital Blood Pressure Monitor Based on AT89C51 Single Chip Microcomputer
 1 Introduction   At present, due to unscientific eating habits and unhealthy living habits, people are prone to various diseases, and hypertension, as one of the diseases, has seriously threatened the health of modern people. How to detect hypertension as early as possible has become the primary issue for people to
[Medical Electronics]
Design of Portable Digital Blood Pressure Monitor Based on AT89C51 Single Chip Microcomputer
GigaDevice Launches GD32A490 Series Automotive-Grade MCUs
GigaDevice (stock code 603986), an industry-leading semiconductor device supplier, announced today the official launch of the new GD32A490 series of high-performance automotive-grade MCUs. With its advantages such as high main frequency, large capacity, high integration and high reliability, it closely meets th
[Automotive Electronics]
Winbond launches new memory products and wins order for Qualcomm IoT modems
According to the Liberty Times, memory manufacturer Winbond Electronics announced today that it has launched QspiNAND Flash with new functions. The product has been adopted by Qualcomm's IoT modem, a major US IC design company. Winbond Electronics said it has introduced the industry’s first 1.8V 512Mb (64MB) QspiNAN
[Mobile phone portable]
Multifunctional electronic clock design based on 51 microcontroller
Design tasks: 1. Design task: Use microcontroller, clock chip DS1302, temperature sensor DS18B20, 1602 LCD, etc. to realize the display of date, time and temperature, which is a simple perpetual calendar. 2. Design requirements (1) Accurate timing can be achieved through DS1302, the time is adjustable and displayed on
[Microcontroller]
Multifunctional electronic clock design based on 51 microcontroller
iPhone 14 series configuration parameters decrypted: all series have 6G memory, and the Pro version is the real iterative product
Recently, TrendForce, a Taiwan-based consultancy, said in a research report that due to the continued hot sales of the iPhone 13 series and the support of the new iPhone SE3, iPhone sales in the first quarter of 2022 reached 60 million units, an excellent year-on-year performance, with an annual growth rate of 11.1%.
[Mobile phone portable]
iPhone 14 series configuration parameters decrypted: all series have 6G memory, and the Pro version is the real iterative product
Starting from 1199 yuan, Honor Play6T series is officially released: equipped with Dimensity chip, standard 8GB memory
According to Jiwei.com, this evening, Honor officially released the Honor Play6T series, which includes two mobile phones, Honor Play6T Pro and Honor Play6T. All series are equipped with 8GB of large RAM as standard. It is the first to configure a 256GB ultra-large memory version in a new phone priced between 1,000 an
[Mobile phone portable]
Starting from 1199 yuan, Honor Play6T series is officially released: equipped with Dimensity chip, standard 8GB memory
Several methods of writing delay programs for microcontrollers
1) No-operation delay (12MHz)   void delay10us() {    _NOP_();    _NOP_();    _NOP_();    _NOP_();    _NOP_();    _NOP_(); } 2) Loop delay (12MHz) Void delay500ms() { unsigned char i,j,k; for(i=15;i 0;i--)      for(j=202;j 0;j--)          for (k=81;k 0;k--); } Total delay time= *i+5 k*2+3=165 us 165*j+3=33333 us 3
[Microcontroller]
Several methods of writing delay programs for microcontrollers
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号