Ok, I have done a little reading and discovered:
The (somewhat oddly named) text section (segment) usually contains the compiled binary code, as you suspect. An executable often contains other types of data besides the code, like initialized variable values, resources, debug information, relocation data, and so on, which are placed in sections with other names.Dec 13, 2014
So this means that my discovery that the compiler thinks that my program code is too large to fit in memory not just the ascii text found in sprintf statements (although that’s one thing that’s contributing of course).
In a way, that makes my job to fix this issue a little easier. In fact the amount of reduction I might gain by simply removing the debug is quite small; whereas I am seeking a reduction of the order 30 kbytes I think.
So I am looking for BIG things to remove not little things.
My mind turns to the fact that the current code base is designed to support a myriad of sensors and groups of sensors dating back to the beginning of the Smart Citizen project. But many of the ‘legacy’ sensors are no longer used; and many also are only used when the user opts to attach things like GPS, OLED etc
The libraries for these devices are quite sizeable.
This issue is akin to what we see happening with Microsoft Windows. It has grown and grown over the years always betting bigger never smaller; and every of user pays for it in terms of needing to have pc’s with ever increasing resource requirements.
But Smart Citizen Data board resources are strictly limited to the amount of Flash available on the SAMD21G MCU. Sooner or later either we need a different MCU with more resource; OR we need to put the firmware on a diet and send it to the gym.
In fact there is a case for upgrading the Data Board and Urban boards firstly to get more resources and secondly to replace sensors that are proving troublesome. But that is a digression…
So I am thinking that it may be possible to fabricate a mechanism to optionally include/exclude support for certain devices from a final object code build.
It would mean making a different “build” for each combination of supported devices.
The broad structure of the proposed mechanism:
A header file “build.h” might contains a number of #define macro variables; and it is included in all the other header files so the macro switches are visible in all parts of the code.
A given switch would be used to “wrap” sections of code in a “IFDEF” type arrangement. It would need to be carefully crafted not to create broken dependencies all over the place.
Looking at the code base here (below) are my targets for running an experiment to see how viable this proposed mechanism might be.
Targets for this treatment
- SCK Gases pro board ( this early version of gas sensor board is not often found)
- Battery ( might be difficult as it’s intertwined in a lot of places)
- GPS ( there are 3 different devices supported, each with their own library)
- OLED (the ug8 library is HUUGE)
- Atlas
- Aux (all of it, not used in SCK 2.1 systems; only in SCS)
- ….
So this proposal has ramifications of course. It would become necessary to distribute different versions of compiled firmware files. It would also make testing of the firmware into a nightmare.
Finally I have to think whether my own code changes have caused this.
I have added blocks of code for:
(a) support for SCD41. It’s a clone of SCD30 with slight alterations.
(b) support for I2C mux. It became necessary due to the attachment of 10 devices to the Aux bus; with disparate treatment of I2C pull-ups. It’s a necessity if you want to use sensors from different vendors instead of designing your own boards to match the system.
(c) support for a second Pm board. It’s a clone of the code for PM board 1 and “slim” because the attached sensors are fairly simple. It is needed because SAMD21G has only 6 UART devices available and PMB#1 has used them up for PM sensors …
All together I’m thinking my code additions couldn’t amount to 30 kbytes worth off code; ( Surely not ?!) but I can verify that by running the “Inspect” command against the current 0.9.8 baseline code from GitHub and comparing the memory map for the two versions. Something I will do a bit later.
For now I will prune off some excessive debug statements and see if the firmware can become passably stable.