
I have always been curious about a question: after writing a microcontroller program, when I use the programming software to upload it, I can see the size of the programming file, which is the hex file size:

The microcontroller chip I am using is STM32F103C8T6, with a program memory (flash) of only 64K.
From the above image, we can see that the hex file is 128K.
I have two questions:
1. It is just a very simple balance car program, does it really take up 128K?
2. Even if it is 128K, can it be downloaded to a microcontroller with only 64K capacity?
This might be a trick question!
Now, let’s start our exploration journey, taking STM32 development as an example.
After compiling the program in Keil, the interface shows:
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 any 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: represents the code to be executed, all functions in the program are located here. RO-data: represents read-only data, all global constant data and strings defined in the program are located here. RW-data: represents initialized read-write data, global variables and static variables defined and initialized in the program are located here. ZI-data: represents 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 figure 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 hex size we download to the microcontroller.
About why the display is different, that’s another interesting question, and interested friends can discuss this together.
Finally, it seems that the resources of the C8T6 chip are almost exhausted, and I need to consider changing the chip.
Author: Zhang Qiaolong, Source: Dayu Robot
Disclaimer: This article is reprinted with permission from the “Dayu Robot” public account. The reprint is for learning reference only and does not represent this account’s endorsement of its views, nor does this account bear any infringement liability for its content, text, and images.
♥Click 👇 the business card, follow me♥
1. I stepped on a landmine again! More than 1000 sets of boards need to be reworked in bulk, it’s all tears!
2. The Bluetooth chip with a circuit so simple it’s shocking, let’s take a look together
3. How I converted 51 code to STM32 driver code