After compiling the code with Keil, compilation information is generated



(1) Code(Inc.Data) : contains two parts, namely Code and Data

– code: indicates the program code

– Inline data. For example, literal pools, and short strings, etc. This is generally ignored, please pay attention!!

– Code snippet, the part of code that stores the program.

(2) RO Data: read-only Data

Shows how many bytes are occupied by read-only data. This is in addition to the inline data included in the Code (inc. data) column. All read-only data except inline data.

Read-only data segment that holds constants defined in the program.

(3) RW Data: read write Data

Shows how many bytes are occupied by read-write data.

Read and write data segments that hold global variables initialized to non-zero values.

(4) ZI Data: Zero initialized Data, a zero initialized read-write variable

Shows how many bytes are occupied by zero-initialized data.

0 data segment, storing uninitialized global variables and variables initialized to 0.

Storage Size:

RO size: Code + RO_data: indicates the Flash space occupied by the program.

RW size: RW_data + ZI_data, which indicates the RAM size occupied during running.

ROM (minimum) size = Code + RO_data + RW_data

Total ROM Size (Code + RO Data + RW Data) Total ROM Size (Code + RO Data + RW Data) Total ROM Size (Code + RO Data + RW Data) The data in RAM is reassigned every time it is powered on. Each time these fixed values are stored in Rom. Why not include ZI segment? As long as the area where ZI data is located is cleared before the program runs. Including it wastes storage space. RAM equals memory, Flash equals hard drive.

RAM size: RW Data + ZI Data (i.e. the amount of RAM used when the program is running)

From the above information, we can see that the total size of the current compiled code is: 16088+372+204=16664 bytes

16664/1024 = 16.2734375 K

View the compiled binary size



It shows that the theoretical calculation is consistent with the practice.

After the microcontroller is powered on, it starts from Flash by default. After the microcontroller starts, it carries RW-data (initialized global variable) in RW segment to RAM, but does not carry RO segment, that is, the executing code of CPU reads from Flash. In addition, it allocates ZI segment according to ZI address and size given by compiler, and the RAM region is cleared to 0.

The dynamic memory heap is the unused RAM space from which blocks of memory are applied and released by applications.

#include"The main. H"
const staic int ADDR = 0x000000FF;		// store in RO
int num;								// store in ZI
int s = 100;							// store in RW segment

void main (void)
{... }Copy the code

Alternatively, you can view it directly in the keil-generated project file *.map.

To do this, compile the entire project once in KEil.



Then double-click on the project file name to open a map file



Drag the right scroll bar all the way to the bottom.



Memory usage is also displayed at the bottom of the file. Scroll up a bit to see the memory usage details.



The report generated by the compiler gives you a clearer view of the memory usage of each file.

If it is difficult to open this file in the project, you can also directly go to the project folder to open this file, find a file with the suffix map, and open it in text format.







Drag the scrollbar to the bottom to see the details of the code footprint.