Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. How to reduce program size

How to reduce program size

Scheduled Pinned Locked Moved Development
8 Posts 5 Posters 1.6k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • rozpruwaczR Offline
    rozpruwaczR Offline
    rozpruwacz
    wrote on last edited by
    #1

    Hi
    I want to include signing into my project but it makes my program too big to fit into atmega328p ... What I found is that the "super duper" arduino ide is just compiling all the libraries from the libraries directory as they would be a part of the project, not as a real libraries. So the linker pulls all the functions from those "libraries" into the resulting binary together with not used functions. So they are sitting there doing nothing taking the space out of my binary :( Is there an easy way to fix that problem ? I can only think of writing a proper makefile to build my project but this will take some time to get it right ...

    T 1 Reply Last reply
    0
    • rozpruwaczR Offline
      rozpruwaczR Offline
      rozpruwacz
      wrote on last edited by
      #2

      hmm, I think that the arduino strips unused functions by using -fprogram-sections and -Wl,--gc-sections, and those functions I thought that are not use are actually used.

      AnticimexA 1 Reply Last reply
      0
      • rozpruwaczR rozpruwacz

        hmm, I think that the arduino strips unused functions by using -fprogram-sections and -Wl,--gc-sections, and those functions I thought that are not use are actually used.

        AnticimexA Offline
        AnticimexA Offline
        Anticimex
        Contest Winner
        wrote on last edited by
        #3

        @rozpruwacz What happens if you just remove the unused libraries from the folder? If the compiler fails, they are used in one way or another.

        Do you feel secure today? No? Start requiring some signatures and feel better tomorrow ;)

        1 Reply Last reply
        0
        • mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #4

          Unused functions are not included in the binary.

          https://www.mysensors.org/apidocs/group__memorysavings.html#gacaf8e04fb48965a06beea8842bb8466f might help a bit to reduce the footprint.

          1 Reply Last reply
          0
          • rozpruwaczR rozpruwacz

            Hi
            I want to include signing into my project but it makes my program too big to fit into atmega328p ... What I found is that the "super duper" arduino ide is just compiling all the libraries from the libraries directory as they would be a part of the project, not as a real libraries. So the linker pulls all the functions from those "libraries" into the resulting binary together with not used functions. So they are sitting there doing nothing taking the space out of my binary :( Is there an easy way to fix that problem ? I can only think of writing a proper makefile to build my project but this will take some time to get it right ...

            T Offline
            T Offline
            tochinet
            wrote on last edited by
            #5

            @rozpruwacz I can guarantee you that the IDE will NOT link all the libraries in every project. I have many, and they would never fit in one 328P memory. Even the parts of libraries that are not used do not get in.

            That said, there are many "memory eaters" in libraries, so you should only consider using one if you really need it.

            A second point of attention is using floats. They are deadly for memory, because the 328p is not able to calculate with floats natively. Division is already huge, but if you use any sin or tan, kB are used.

            A third eater is ... objects. When you create an object (from a library), every part of it is created. So if it done according to the good old rules, it starts bay uselessly copying the parameters of the constructor into its internal variables ... that maybe won't ever change.

            Strings are also eating a lot of memory. Both in creation and in manipulation.

            To see what eats your memory, start from an empty sketch setup+loop, and add each part of your sketch (in a compilable way) step by step. You could be surprised of where the biggest memory eaters are.

            1 Reply Last reply
            1
            • mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by
              #6

              avr-size and readelf might help you track what's using up the space. Some details in https://forum.mysensors.org/post/46683 (focused on ram usage, but the same tools can show information about the flash usage)

              1 Reply Last reply
              0
              • brendanlB Offline
                brendanlB Offline
                brendanl
                wrote on last edited by
                #7

                Maybe this could help?
                https://forum.mysensors.org/topic/4077/gatewayw5100mqttclient-my_signing_soft-development-branch-atmega328-nano-sketch-too-large

                1 Reply Last reply
                0
                • rozpruwaczR Offline
                  rozpruwaczR Offline
                  rozpruwacz
                  wrote on last edited by
                  #8

                  wow, didn't expect such a response :) thanks.
                  every think is working as expected. I was mislead by some functions from the APDS9930 library that I was not using, but the library was using them in its init function. I solved my problem by reducing size of my code and additionally I removed some functions from the APDS9930 library.

                  So, bottom line. The Arduino IDE uses -fprogram-sections and -Wl,--gc-sections switches during compilation. Those switches remove the unused parts of the compiled objects from the resulting binary.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  18

                  Online

                  11.7k

                  Users

                  11.2k

                  Topics

                  113.1k

                  Posts


                  Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • MySensors
                  • OpenHardware.io
                  • Categories
                  • Recent
                  • Tags
                  • Popular