cancel
Showing results for 
Search instead for 
Did you mean: 

Removing dead code from HAL Library and optimising for size breaks functionality

B Zikhali
Associate III
Posted on July 15, 2016 at 11:47

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
3 REPLIES 3
Rosiney Silva
Associate II
Posted on July 15, 2016 at 18:41

If you use gcc, there is an

option

of compilation (-flto) you should do what you want without having to change

the code

. The option of compilation -flto, performs a blobal optimization. Below is the result (in bytes) of compilation of 3 code examples

:

        | p1-avr | p2-stm32f1 | p3-stm32f4 |

--------|--------|------------|------------|

Os      |  23911 |    34180   |    75384   |

Os-flto |  21015 |    11552   |    33036   |

O3      |  27219 |    43708   |    93416   |

O3-flto |  29813 |    13416   |    41460   |

--------|--------|------------|------------|

matic
Associate III
Posted on July 16, 2016 at 00:52

For the highest speed performance and smallest code size I suggest to not use any libraries. Program with registers directly. When I remove from our project all HAL functions (which were used for peripheral initialisation only), the code size goes from 32kB to around 18 kB.

B Zikhali
Associate III
Posted on July 18, 2016 at 11:03

Thank you Silva for the suggestion to use Link Time Optimisation; it does actually reduce code size and increase the speed of my application. Unfortunately the disassembly of the LTO'd code removes comments and I can't verify if the 'useless' code is actually removed. And also out of curiosity, I would still like to know why removing dead code would break the code when optimised for size and work with every other optimisation level.