
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 am using is the STM32F103C8T6, which has a program memory (flash) of only 64K.
From the image above, it can be seen that the hex file is 128K.
I have two questions:
1. It’s just a very simple balance car program, does it really need 128K? Is it that big?
2. Even if it’s 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 part:
Many friends probably see this interface and only care about two points:
First, whether the program they wrote correctly generated the hex file!
Second, whether their program has errors or warnings!
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, all global constant data and strings defined in the program are located here. RW-data: indicates initialized read-write data, all global variables and static variables defined and initialized in the program are located here. ZI-data: indicates uninitialized read-write data, all 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’s 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, this is another very interesting question, and friends who are interested can discuss it together.
Finally, it seems that the resources of the C8T6 chip have been nearly exhausted, and I need to consider changing the chip.
Author: Zhang Qiaolong, Source: Dayu Robot
Statement: This article is authorized and reprinted from the “Dayu Robot” public account. Reprinting is for learning reference only and does not represent the views of this account. This account does not bear any infringement responsibility for its content, text, or images.
1. I stepped on a landmine again! More than 1,000 sets of boards need to be reworked, so much to say it’s tears!
2. The working circuit of a Bluetooth chip so simple it’s astonishing, let’s take a look together
3. How I converted 51 code to STM32 driver code