Skip to main content
Graduate II
March 10, 2025
Solved

Save flash when using printf and floating-point on STM32F0

  • March 10, 2025
  • 2 replies
  • 1705 views

Originally a reply to this thread:

https://community.st.com/t5/stm32-mcus-embedded-software/how-generate-hex-file-without-link-files-hal-drivers/td-p/723141

Split as it seems to be a different issue.


Hi,

I have same issue too

I am using STM32F051R8 with STM32CubeIDE Version: 1.18.0

There is limited Flash memory. So when I am checking the memory I found some library names etc definition strings on my hex file. I tried to change some setting according to topics above but no success at all

Please let me know which settings is this. Also I am using optimization "Optimize for size -s"

Regards

Murat

    This topic has been closed for replies.
    Best answer by Andrew Neil

    @istepne wrote:

    if it possible to remove this textures (sic?) from flash makes more space for me.


    You mean text ?

    As @KnarfB said, the space taken by the text is insignificant - it's the use of floating-point and printf that's really eating the flash space!

     


    @istepne wrote:

    This is an old project and old electronic board desing.


    So why are you adding floating-point at this late stage?

    2 replies

    Super User
    March 10, 2025

    @istepne wrote:

    Please let me know which settings is this. 


    This one:

    https://community.st.com/t5/stm32-mcus-embedded-software/how-generate-hex-file-without-link-files-hal-drivers/m-p/723990/highlight/true#M55354

     

    PS:

    It will be in your stm32xxxx_hal_conf.h file:

     

    /* ########################## Assert Selection ############################## */
    /**
     * @brief Uncomment the line below to expanse the "assert_param" macro in the
     * HAL drivers code
     */
    /* #define USE_FULL_ASSERT 1U */

     

    As shown above, it is not defined.

    istepneAuthor
    Graduate II
    March 11, 2025

    @Andrew Neilthank you for the answer.

    I realized that it comes from the floating library. I need to use printf with floating point operations enabled.

    I made a new project and just compiled it, it tooks 2,99 kbyte memory. After than I enabled the floating feature on settings and compiled again (either debug or release mode) . Then it tooks 23,52kbyte (huge increase). I see the texture on the hex file again with a blank project.

    I need Flash memory space on this the older board (can not change the MCU). 
    Is there a way to disable this strings from hex file to get more space?

    Or any other solution like lightweight floating point library etc

    Regards

    Murat

    Super User
    March 11, 2025

    This doesn't sound like the same problem as the OP - which was solved as described.

    Edit: So split to a separate thread.

     


    @istepne wrote:

    I see the texture on the hex file again with a blank project


    What, exactly, do you mean by that?  How are you viewing it?

    Please give full details of the tools & procedures used, and show what you're seeing.

     


    @istepne wrote:

    I need (sic?) to use printf with floating point operations enabled.


    Do you really need to?

    Both Floating Point and printf can use a lot of flash - so, when flash space is limited, maybe try to avoid both?

    Super User
    March 11, 2025

    Look into alternative printf implementations like GitHub - charlesnicholson/nanoprintf: The smallest public printf implementation for its feature set. and avoid using the printf provided in newlib.

    hth

    KnarfB