I have been keeping track of my flash and RAM usage since I know I'm getting close to filling up my STM32F030R8T6 microcontroller. Mostly I'm running out of Flash, but RAM is getting full too.
From lots of form posts, I'm pretty confident that my flash usage is Code + RO-data + RW-data, and that makes sense to me. But today I compiled and linked successfully, even though they add up to more flash space than my micro has.
linking...Program Size: Code=49516 RO-data=13604 RW-data=3304 ZI-data=3544 FromELF: creating hex file...
linking...
Program Size: Code=49516 RO-data=13604 RW-data=3304 ZI-data=3544
FromELF: creating hex file...
So this would be 49516 + 13604 + 3304 = 66424 bytes. This is larger than the 64K (65536 bytes) available on the Flash. I am running my target device and everything is working fine.
So my question is, am I misinterpreting the Program Size readout as it pertains to flash space, or am I misinterpreting the datasheet for the STM32F030R8T6 flash size?
Two possibilities come to mind right away:
1) you didn't inform the tools that you only have internal flash, and/or its exact size
2) you underestimate the cleverness of the tools. The master copy of the RW data may be kept in a (slightly) compressed form, allowing it to use less than those 3304 bytes.For the full story, you'll have to look deeper into the linker's work output than that summary line, i.e. the actual map file.
I agree with both of the above. You should specify region sizes to ensure you do not overflow.
https://developer.arm.com/documentation/101754/0624/armlink-Reference/Scatter-loading-Features/The-scatter-loading-mechanism/Scatter-loading-images-with-a-simple-memory-map
Assuming you have done this, data compression is almost certainly the reason.
The report from the MDK IDE shows the uncompressed values, for example 2572 bytes below:
Program Size: Code=6284 RO-data=536 RW-data=2572 ZI-data=5204
However if you look at the generated .map file (and assuming Totals Info is enabled in the Target Option > Listing tab), you will see the compressed value:
Code (inc. data) RO Data RW Data ZI Data Debug 6284 310 536 2572 5204 214117 Grand Totals 6284 310 536 428 5204 214117 ELF Image Totals (compressed) 6284 310 536 428 0 0 ROM Totals ============================================================================== Total RO Size (Code + RO Data) 6820 ( 6.66kB) Total RW Size (RW Data + ZI Data) 7776 ( 7.59kB) Total ROM Size (Code + RO Data + RW Data) 7248 ( 7.08kB) ==============================================================================
In this example the "Total ROM Size" uses the compressed data size (428 bytes), but the RW size uses the uncompressed size.
See also:https://developer.arm.com/documentation/101754/0624/armlink-Reference/armlink-Command-line-Options/--datacompressor-opt
https://developer.arm.com/documentation/100748/0624/Getting-Image-Details/Example-of-using-the---info-linker-option