Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save 6952 bytes of RAM #2881

Merged
merged 6 commits into from
Mar 7, 2018

Conversation

fiam
Copy link
Member

@fiam fiam commented Mar 6, 2018

Make CMS use a separate static array for keeping track of the items that need redrawing rather than modifying each OSD_Entry_t item. This lets us move all items and most menus to flash (the SA menu uses dynamic entries, so it needs to stay in ram). Note that text increases by 6728 bytes due to these changes, but even F3 still has ~31K free.

Also, a bunch of macros have been added to CMS to make both the code cleaner and changes like this one easier. Please, try to use them in the future when adding new menus.

Before:

Linking OMNIBUS
arm-none-eabi-size ./obj/main/inav_OMNIBUS.elf
   text	   data	    bss	    dec	    hex	filename
 218430	  10136	  37900	 266466	  410e2	./obj/main/inav_OMNIBUS.elf

After:

arm-none-eabi-size ./obj/main/inav_OMNIBUS.elf
   text	   data	    bss	    dec	    hex	filename
 225158	   3224	  37860	 266242	  41002	./obj/main/inav_OMNIBUS.elf

fiam added 6 commits March 6, 2018 10:49
Will make future changes cleaner
This will make the transition to using const values where possible
much easier and cleaner.
Use a global array in cms.c to keep track of the dirty elements
that need redrawing. This lets us avoid modifying the entry flags
to keep track of it, so they can now be completely read only. This
in turn lets us also move all the menus to the text section.

This commit saves 6112 bytes of RAM in F3, so we have some room
to play again without resorting to disabling features.
Instead, change the OSD configuration directly. This saves 2 bytes
per OSD element now and for all the future ones, which translates
to -80 bytes from BSS in this commit.
Add support for direct pointers to readonly values rather than using
intermediate OSD_XXX_t types.
Use direct pointers on all readonly values.
Make sure all intermediate value/step holders are in flash rather
than ram, since they're never modified.

This saves another 352 bytes of RAM (mostly on data, a few on bss).
Make sure all of them are declared as const, since they hold a
pointer to the actual value as well as the min/max/step, hence
they are never changed.

This saves another 408 bytes of ram, by moving them to text
@digitalentity digitalentity added this to the 1.9.1 milestone Mar 6, 2018
@fiam
Copy link
Member Author

fiam commented Mar 6, 2018

Just checked how much VTX control takes with these changes. Now it takes ~8K of flash and ~500 bytes of RAM, which are way more palatable values. The VTX control CMS code could still be optimised a bit more by avoiding duplication of a bunch of values in BSS (~30 bytes or so), but since I don't have any SA VTX to test and the remaining potential savings aren't that big I'm not touching it anymore for now.

@digitalentity digitalentity merged commit 4d44954 into development Mar 7, 2018
@digitalentity digitalentity deleted the agh_make_free_ram_on_f3_great_again branch March 7, 2018 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants