cancel
Showing results for 
Search instead for 
Did you mean: 

How do I zise optimize ST firmware library functions?

sima
Associate II
Posted on March 28, 2009 at 09:11

How do I zise optimize ST firmware library functions?

4 REPLIES 4
sima
Associate II
Posted on May 17, 2011 at 13:07

How do I size optimize functions from the ST firmware library?

I have deselected DEBUG and selected optimization towards small size.

I have pointed all unused interrupt vectors to the same dummy function (in stm32f10x_vector.c).

What more can I do?

Any more suggestions?

andreas2
Associate II
Posted on May 17, 2011 at 13:07

What compiler are you using?

sima
Associate II
Posted on May 17, 2011 at 13:07

I'm using Ride7.

andreas2
Associate II
Posted on May 17, 2011 at 13:07

You mean GCC, Ride7 is not a compiler...

One of the shortcomings of GCC when it comes to embedded code is its lack of link time optimization. Which means that if you have a library archive, like what the stm32 fwlib is probably is shipped as with Ride, it contains a bunch of object files. When your application uses a function in the library, the entire object file containing that function must be linked into your binary, including all the unused functions.

There are several solutions to this problem.

Split all the library source files into smaller units, ideally with one function per c-file. The GCC C library is organized this way for this very reason.

Combine all the library c-files into one, copy it to your project and comment out all the functions you do not use. Gives much better optimization possibilities than the first method, but it's not really practical.

Pass the ''-combine -fwhole-program'' flags to the compiler. This requires you to specify on the command line all the c-files which will make up the binary. For example

''gcc $(CFLAGS) -Os -combine -fwhole-program $(LDFLAGS) -o your_app.elf your_src/*.c fwlib/*.c''

GCC will then compile, optimize and link your program as a single unit, and consider all functions static so that they will be dropped if unused. The result is much the same as LTO could have produced. Unfortunately it seems that many GCC versions have problems with these flags in combination with some code constructs, which will cause the compiler to crash. But if it works for your code, its the best solution.