I have always been curious about a question: every time I finish writing a microcontroller program and use the burning software to upload it, I can see the size of the burning file, which is the hex file size:

The microcontroller chip I use is STM32F103C8T6, and the program memory (flash) is only 64K.
From the above image, we can see that the hex file is 128K.
I have two questions:
1. It is just a simple balance car program, how can it be 128K? Is that really that big?
2. Even if it is 128K, can it be downloaded to a microcontroller with only 64K capacity?
This might be a tricky question!
Now let’s start our exploration journey, taking STM32 development as an example.
After compiling the program in Keil, in the interface:
Many friends probably see this interface and only care about two points:
First, whether the program they wrote correctly generated the hex!
Second, whether there are errors or warnings in the program they wrote!
In the red line part of the image:
There are four: Code, RO-data, RW-data, ZI-data. Code: indicates the executable code, all functions in the program are located here. RO-data: indicates read-only data, global constant data and strings defined in the program are located here. RW-data: indicates initialized read-write data, global variables and static variables defined and initialized in the program are located here. ZI-data: indicates uninitialized read-write data, global variables and static variables defined in the program but not initialized are located here.
From the description, we can conclude:
1. The program downloaded to the microcontroller FLASH is: Code + RO-data + RW-data (the data in the above image is in bytes, kb = byte/1024);
hex = (39546 + 5862 + 12428) / 1024 = 56.48
2. The data running in RAM is: RW-data + ZI-data;
It turns out that the hex size displayed in Windows is not the same as the hex size we download to the microcontroller.
As for why the display is different, that is another interesting question, and friends who are interested can discuss it together.
In the end, it seems that the resources of the C8T6 chip have been nearly exhausted, and it is time to consider changing the chip.
-END-
Who understands you better, is it your girlfriend? No, it’s these recommendation algorithms.
Why we should support Huawei
Crystal oscillator, the heart of digital circuits~
If you think the article is good, please share, it is also our motivation to continue updating.
5T Resource Giveaway! Including but not limited to: C/C++, Linux, Python, Java, PHP, Artificial Intelligence, PCB, FPGA, DSP, LabVIEW, Microcontrollers, etc.!
Reply “More Resources” in the public account to get it for free, looking forward to your attention~
Long press to recognize the QR code in the image to follow