2023-05-29 11:43 PM
Hi,
I was trying to convert a code written in HAL to baremetal for reducing the size. The code in HAL has 90KB file size when build in Debug mode and has 50KB file size in Release mode. In case of baremetal 73KB and 63KB respectively for Debug and Release modes. How can I reduce the file size of baremetal code than the HAL Release mode.
Solved! Go to Solution.
2023-05-31 12:20 AM
Perhaps review .MAP and .LST, look at what's eating the most memory.
If there's repetitive stuff that could be a subroutine or otherwise factored.
Compilers are not good with intent or identifying algorithms.
A lot of register code is very inefficient, using a lot of individual RMW code that the compiler can't fold due to the volatile and in-order expectations constraining it. Understand the load-store architecture and use your overview to decide what can be folded and where the order is or is not critical.
2023-05-30 01:43 AM
Try to set compiler optimization to "Optimize for size"
2023-05-30 05:10 AM
Compiler optimization is already in Optimize for size
2023-05-30 05:52 AM
It is hard to say. If the bare metal code is larger than the HAL, then the code is inefficient. Try using the LL code instead. If that doesn't help either, the easiest way is to use an MCU with more flash memory. The last option is to limit the scope (and functionality) of the code.
2023-05-30 06:48 AM
If u r using custom linker script, first you must check it.
2023-05-30 07:13 AM
Not using custom linker script
2023-05-30 07:15 AM
But in Debug mode I got less build size. Could you please tell me what will be causing the size variation.
2023-05-30 08:22 AM
Can we be precise in the question please ?
Bare Metal xor RTOS based code. It has nothing to relate to LL or HAL.
Second, when you build and you look at the code size, does the code WORK ?
Debug and Release is just an artifact to have 2 set of project compiler properties. It's about compiler optimisation levels, linker file settings, etc...
The non HAL LL encoded application resulting memory footprint will mostly depend on the coder's skill and write C "ASM in mind". So in short, if the code sizes don't make sense, it's probably because something is not mastered.
2023-05-30 10:47 PM
yes the code works fine in alll cases. So could you please give me some suggestions improve the code size.
2023-05-30 11:38 PM
There are many options.
Your link map would tell you how much size you need to reduce and indicate some places you might reduce the size most easily.