cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 VS Code Extension – How To Prevent Compiling Unused Functions

Ricko
Senior III

Hi,

I would appreciate any guidance or best practices for minimizing code size by eliminating unused functions when using the STM32 extension for VS Code with CubeMX generated code (bare metal) as some code I'm writing has become very large.

What is the recommended way to configure the compile/build process so that unused functions are not compiled or linked into the final image flashed to the microcontroller, in order to save flash space?

I am not familiar with CMake, so if this can be achieved without using CMake, that would be preferred.

If custom configuration text is required (for example Makefile edits or similar), could you please outline them in detail and whether these changes are generally safe, or if they require careful consideration.

Any clarification on the recommended approach would be greatly appreciated.

Thank you

1 REPLY 1
gbm
Principal

Normally the unused functions and data are eliminated automatically during linking. This behavior is controlled by compiler options -fdata-sections and -ffunction-sections, which are turned on by default under CubeIDE.

You may verify that these options are turned on in your project's config files.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice