Is there any way to reduce the consumption of ROM resources under the GCC compilation platform?

Due to the allocation of Flash resources, only 100KB ROM for the app, and if we use Keil, we will have about 20KB of margin for additional code development, but we have to abandon Keil for the sake of the compilation platform.

Is there any way to optimize the program's ROM usage? Our code is very timing-sensitive, and if we change it directly from O3 to Os, we will get obvious ROM benefits, but our program execution will start to get messy.

I tried to analyze the map file and found that the main extra ROM resource consumption came from the referenced Mbedtls library and some C libraries.But I didn't have a better way to replace them, and because we were short on RAM, I had to turn on the MBEDTLS_AES_ROM_TABLES in the Mbedtls library.

Parents
  • Hi,

     

    Is there any way to optimize the program's ROM usage? Our code is very timing-sensitive, and if we change it directly from O3 to Os, we will get obvious ROM benefits, but our program execution will start to get messy.

    If there are certain functions which require another optimization level, you can use the gcc #pragma directive to change optimization:

    #pragma GCC push_options
    #pragma GCC optimize ("O3")
    
    ...functions to optimize with -O3..
    
    #pragma GCC pop_options

      

    Then you can keep the rest of your firmware on "-Os" to allow for a lower ROM footprint.

     

    Kind regards,

    Håkon

  • Hi,

    Are there any other alternatives? Using this approach makes my code less generic and requires extra time to think about which functions really need to be optimized separately.

Reply Children
Related