Reducing Code Size with gcc and EWL

If you have not noticed: the final CodeWarrior for MCU10.3 has been released on the Freescale web :-).

It comes with a few changes compared to the 10.3beta release, and one is about the library configuration. I noticed that new projects created with the wizard are around 4 KByte larger than I expect them to be. For example my rather simple application below uses 8 KByte of code, where my expectation would be in the range of around 4 KByte:

   text       data        bss        dec        hex    filename
   8644         24       1108       9776       2630    Freedom_2x16_HTA.elf

💡 See this post how to show the code/data size after the link phase.

Maybe you remember my trick I have published here around the __pformatter symbols. The good news is: that trick is not needed any more. The not so good news is: it requires a different setting to get rid of the not needed printf() support.

The 💡 trick is to use the right library option.

By default the project wizard sets up the project to use EWL (Embedded Warrior Library) to use ‘ewl with int’ for GNU gcc:

Librarian Option with EWL

Librarian Option with EWL

Compared to normal GNU gcc libraries, EWL is better suited for embedded systems. However, EWL still comes with too much overhead in my view for true embedded projects. And even if I do *not* use any printf() or scanf() in my application, the above settings are adding a huge (in my view) overhead to my code.

The good news is: it is very easy to get rid of that overhead: Simply configure it to use EWL with ‘ewl_noio’:

Librarian with ewl_noio

Librarian with ewl_noio

With this option set, I’m back to what I expect: 4 Kbyte of code:

   text       data        bss        dec        hex    filename
   4168         24       1108       5300       14b4    Freedom_2x16_HTA.elf

Happy Reducing 🙂

Advertisements

14 thoughts on “Reducing Code Size with gcc and EWL

  1. Pingback: Optimizing the Kinetis gcc Startup | MCU on Eclipse

  2. Did reduce my file size.
    But also killed many, many hours of work in MCUInit in my interrupt handlers! Seems to have erased all the code I placed in after the comment, “/* Write your interrupt code here … */”

    Fortunately, using “undo typing” recovered most of my routines. Whew!

    Be very careful when using this. Back everything up first.

    Like

    • Hi Brad,
      Maybe the right time to consider using a version control system like SVN in 2013 ;-)? Seriously, what have you done? This post is about changing the library option, and does not impact Processor Expert code generation at all.

      Like

    • Hi Marc,
      thanks 🙂
      About SUPPORT_ROM_TO_RAM: if you disable that, then your RAM variables will not be initialized with the constant values (e.g. like for static int i=37;) If you do not need, or if you know that your code does not use that: fine. But many applications I have seen are depending on that,so switching this off might not work for every application. You might try it out and verify with your application.

      Like

      • yes I did see that, another great article. With CW10.4 the startup code looks a bit different – they have ifdef’d out a lot of the stuff you were taking out manually, but for some odd reason they unconditionally keep in the CPP initialization. Thanks to that article I was able to find that and get rid of it.

        The other thing that saves space is disabling PE methods and events you don’t need. Also, for example, BitIO_LDD by itself takes less code space than BitIO or LED methods, for tiny processors it’s something that might have to be jettisoned.

        Like

  3. Thanks thanks thanks Erich !
    It was 4 A.M., I was coding and suddenly ! Out of .text memory !!
    I remembered the title of this post, I searched it and in less than 10 minutes I recovered 4Kb !!
    Again, Thanks thanks thanks !
    Now, I’m going to sleep, and happy 🙂

    Like

  4. Hey Erich.
    I am using Kinetis Design Studio 2.0. There is no option called LIBRARIAN in it. What is the procedure to reduce the code size in KDS (Version 2.0 to be specific ) ?
    Thanks
    Ganesh

    Like

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s