cancel
Showing results for 
Search instead for 
Did you mean: 

Remove unused functions

hbZhao
Associate III

Hello,

I am working on H750 while the flash is limited.

Because the LCD is RGB565, may I know if the the unrelated functions can be removed? such as functions related with ARGB8888 and RGB888.  Thanks.

hbZhao_0-1720819584764.png

 

 

 
1 ACCEPTED SOLUTION

Accepted Solutions

If you enable optimization then dead code is removed (I'm not sure of the optimization level, but that's a pretty obvious optimization).

If you know of any particular functions that are not used, check your .map file. The .map file will give you the address allocated to the function and if it has been removed, it will not be in the memory map.

View solution in original post

6 REPLIES 6

If you enable optimization then dead code is removed (I'm not sure of the optimization level, but that's a pretty obvious optimization).

If you know of any particular functions that are not used, check your .map file. The .map file will give you the address allocated to the function and if it has been removed, it will not be in the memory map.

hbZhao
Associate III

The GUI is only a simple button without any photos. The debug information has been disabled since building in Release mode.

The GCC and G++ optimization level is 'Optimize for size (-Os)'. And the Discard unused section in G++ Linker has been selected. 

Only the used functions are enabled, such as FMC, I2C(Touchscreen), QuadSPI (to store app), LTDC, FATFS, USB and TouchGFX.

Because the display is set as RGB565. But there are many functions related with ARGB8888 and RGB888. If they can be removed, there should be lots of flash saved.

BarryWhit
Lead II

It's true that turning on Compiler optimizations like (for example) -O2 will make the compiler eliminate dead code,

but it's not true that in general this will eliminate "dead" functions. At least for GCC, doing that requires a different sets of flags to be specified. Fortunately, by default, CubeIDE Projects are compiled and linked with these options, so that both unused function and also global data (and if compiler optimization is turned on, also dead code and unused local variables withing functions) are removed.

 

GC2.jpg

 

GC3.jpg

 

I did recently learn, from following up a thread on this very forum, that TI's ARM Clang compiler is different, in that this behavior is on by default, i.e. you don't have to specify anything extra to eliminate unused functions or global variables. Instead, that compiler provides specific options for turning OFF this behavior. The toolchain provided by ST (which is also bundled with CubeIDE) for their STM32 product line is, however, based on GCC.

- If someone's post helped resolve your issue, please thank them by clicking "Accept as Solution".
- Please post an update with details once you've solved your issue. Your experience may help others.
BarryWhit
Lead II

I'm afraid I don't agree with @Andrei Chichak 's answer. Or, at least, it's misleading.  OP was asking about removing unused functions, which is generally different than the compiler optimizing away dead code.

- If someone's post helped resolve your issue, please thank them by clicking "Accept as Solution".
- Please post an update with details once you've solved your issue. Your experience may help others.

Ah, once you get to know me, you'll find that I'm just here to mislead people.

BarryWhit
Lead II

We have so much in common, friend.

- If someone's post helped resolve your issue, please thank them by clicking "Accept as Solution".
- Please post an update with details once you've solved your issue. Your experience may help others.