STM32 storage allocation problem

Publisher:温暖的微风Latest update time:2018-06-07 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

After keil compilation, the following information is generated:
Program Size: Code=37970 RO-data=7598 RW-data=212 ZI-data=12340  What do code ro-data rw-data zi-data mean respectively
?

Answer:
Code segment + initialized data segment = FLASH, data segment + 0 initialized data segment = RAM; 


RO, RW and ZI DATA segments in ARM compilation
ARM program (referring to the program being executed in the ARM system, not the bin file saved in ROM) composition
An ARM program contains 3 parts: RO segment, RW segment and ZI segment
RO is the instruction and constant in the program
RW is the initialized variable in the program
ZI is the uninitialized variable in the program
The above 3 points can be understood as:
RO is readonly,
RW is read/write,
ZI is zero
Composition of ARM image file
The so-called ARM image file refers to the bin file burned into ROM, also known as image file. It is called Image file below.
Image file contains RO and RW data.
The reason why Image file does not contain ZI data is that ZI data is all 0, so it is not necessary to include it. Just clear the area where ZI data is before running the program. Including it will waste storage space.

Q: Why must RO and RW be included in the Image?
A: Because the instructions and constants in RO and the variables initialized in RW cannot be created out of nothing like ZI. From the above two points, we can know that
the execution process of the ARM program
is not exactly the same as the image file burned into the ROM and the ARM program in actual operation. Therefore, it is necessary to understand how the ARM program reaches the actual running state from the image in the ROM.
In fact, the instructions in RO should at least have the following functions:
1. Move RW from ROM to RAM, because RW is a variable and variables cannot exist in ROM.
2. Clear all RAM areas where ZI is located, because the ZI area is not in the Image, so the program needs to clear the corresponding RAM area according to the ZI address and size given by the compiler. ZI is also a variable. Similarly: variables cannot exist in ROM. In the
initial stage of program operation, the C program can access variables normally only after the instructions in RO complete these two tasks. Otherwise, only code without variables can be run.
After all the above, you may still be confused. What are RO, RW and ZI? Below I will give a few examples to explain what RO, RW and ZI mean in C. 
1; RO
Look at the following two programs. There is a statement between them, which is to declare a character constant. Therefore, according to what we said before, there should only be one byte difference in RO data (character constant is 1 byte).
Prog1:
#include 
void main(void)
{
;
}
Prog2:
#include 

const char a = 5;
void main(void)
{
;
}
The compiled information of Prog1 is as follows:
======================================================================================
Code RO Data RW Data ZI Data Debug
948 60 0 96 0 Grand Totals
=======================================================================================================
Total RO Size(Code + RO Data) 1008 ( 0.98kB)
Total RW Size(RW Data + ZI Data) 96 ( 0.09kB)
Total ROM Size(Code + RO Data + RW Data) 1008 ( 0.98kB)
==========================================================================================
The information after Prog2 compiles is as follows:
===================================================================================================
Code RO Data RW Data ZI Data Debug
948 61 0 96 0 Grand Totals
==================================================================================
Total RO Size(Code + RO Data) 1009 (0.99kB)
Total RW Size(RW Data + ZI Data) 96 (0.09kB)

Total ROM Size(Code + RO Data + RW Data) 1009 ( 0.99kB )
=== ... Prog3: #include  void main(void) { ; } Prog4: #include  char a = 5; void main(void) { ; }



















The information after Prog3 compiles is as follows:
=================================================================================
Code RO Data RW Data ZI Data Debug
948 60 0 96 0 Grand Totals
=======================================================================================================
Total RO Size(Code + RO Data) 1008 ( 0.98kB)
Total RW Size(RW Data + ZI Data) 96 ( 0.09kB)
Total ROM Size(Code + RO Data + RW Data) 1008 ( 0.98kB)
==============================================================================================
The information compiled by Prog4 is as follows:
========================================================================================================
Code RO Data RW Data ZI Data Debug
948 60 1 96 0 Grand Totals
================================================================================
Total RO Size(Code + RO Data) 1008 (0.98kB)
Total RW Size(RW Data + ZI Data) 97 (0.09kB)
Total ROM Size(Code + RO Data + RW Data) 1009 (0.99kB)
===
...




​ 

}
;
}
Prog4:
#include 
char a;
void main(void)
}
;
}
The compiled information of Prog3 is as follows:
=========================================================================================
Code RO Data RW Data ZI Data Debug
948 60 0 96 0 Grand Totals
==============================================================================================================
Total RO Size(Code + RO Data) 1008 ( 0.98kB)
Total RW Size(RW Data + ZI Data) 96 ( 0.09kB)
Total ROM Size(Code + RO Data + RW Data) 1008 ( 0.98kB)
===========================================================================================
The information compiled by Prog4 is as follows:
=====================================================================================================
Code RO Data RW Data ZI Data Debug
948 60 0 97 0 Grand Totals
==========================================================================
Total RO Size(Code + RO Data) 1008 ( 0.98kB)
Total RW Size(RW Data + ZI Data) 97 ( 0.09kB)
Total ROM Size(Code + RO Data + RW Data ) 1008 ( 0.98kB)
===
...






Appendix:
Program compilation command (assuming the C program is named tst.c):
armcc -c -o tst.o tst.c
armlink -noremove -elf -nodebug -info totals -info sizes -map -list aa.map -o tst.elf
The compiled information of tst.o is in the aa.map file.
ROM mainly refers to: NAND Flash, Nor Flash
RAM mainly refers to: PSRAM, SDRAM, SRAM, DDRAM


Keywords:STM32 Reference address:STM32 storage allocation problem

Previous article:Understanding of program memory in stm32 and solutions to some problems
Next article:Detailed explanation of STM32 bitband operation

Recommended ReadingLatest update time:2024-11-17 00:49

stm32ADC非DMA mode的多时间的时间与可以时间的时间
The first one is a DMA mode of multiple channel acquisition void ADC_DMA_Config(void)  { ADC_InitTypeDef ADC_InitStructure; RCC_HSICmd(ENABLE); while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);   RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); ADC_DeInit(ADC1); ADC_StructInit(&ADC_InitStructure); ADC_InitStru
[Microcontroller]
How to define variables in flash in stm32
Purpose: Define variables in flash Actually, writing this is just a record. Suddenly, I was working on the font display problem. I thought that if the font data is put in the memory, it will inevitably cause problems. It is better to put it in the flash so that it does not need to be changed. int a; a in memory cons
[Microcontroller]
Solve the problem that STM32 J-FLASH cannot read RAM download
I made two ARM-OB downloaders and STLINK downloaders in the afternoon. I thought it would be done quickly, but the following problems occurred in the last step: - ERROR: RAM check failed @ address 0x20000000. - ERROR: Write: 0xE7FEBE00 E07CE062        - ERROR: Read: 0x0000000 000000000        - ERROR: (0 bytes of
[Microcontroller]
Solve the problem that STM32 J-FLASH cannot read RAM download
STM32 Study Notes - PWM Waveform Output
Debug chip: STM32F103C8T6 External crystal: 8MHz Function introduction: Use Timer3 to realize two (or four) PWM waveform outputs code show as below: Initialization: system clock initialization, GPIO port initialization, Timer initialization System clock initialization:   /* Configure the system clock to
[Microcontroller]
STM32 hardware SPI driver LCD example
Preface: Every time I learn a new knowledge, I will make a lot of mistakes. I can't find it even on Baidu, which takes a lot of time. The main reason is that I don't understand the underlying principles, don't have much time to understand, and am under pressure. As for SPI, everyone knows what it is used for. I don't
[Microcontroller]
STM32 SWD download mode
I have been using JTAG downloading before, and recently I used SWD mode. SW mode uses 5 pins, NRST: reset SWCLK: serial line clock SWDIO: serial line debug data input/output, and the others are GND and VCC Advantages of SWD mode: SWD mode is more reliable than JTAG in high-speed mode. JTAG download program will f
[Microcontroller]
STM32 SWD download mode
Introduction to STM32 series processors
Application Background If you are having a hard time choosing a processor for your project: on the one hand, you are complaining about the limited instructions and performance of 16-bit microcontrollers, and on the other hand, you are complaining about the high cost and high power consumption of 32-bit processors. The
[Microcontroller]
Portable human-machine interface system based on STM32
In the process of total station measurement applied to aircraft, calculations are often involved to meet different application environments and measurement requirements. In the past, the post-measurement editing software was implemented on the computer. Modern measurement urgently needs a portable handheld computing sy
[Microcontroller]
Portable human-machine interface system based on STM32
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号