Embedded Design Handbook

ID 683689
Date 8/28/2023
Public
Document Table of Contents

7.2.4.2. Reducing the Code Footprint

The following methods help you to reduce your code footprint:

  • Compiler options—Setting the -Os flag for the GCC causes the compiler to apply size optimizations for code size reduction. Use the hal.make.bsp_cflags_optimization BSP setting to set this flag.
  • Reducing the HAL footprint—Use the HAL BSP library configuration settings to reduce the size of the HAL component of your BSP library file. However, enabling the size-reduction settings for the HAL BSP library often impacts the flexibility and performance of the system.

    The table below lists the configuration settings for size optimization. Use as many of these settings as possible with your system to reduce the size of BSP library file.

    Table 54.  BSP Settings to Reduce Library Size
    BSP Setting Name Value
    hal.max_file_descriptors 4
    hal.enable_small_c_library True
    hal.sys_clk_timer None
    hal.timestamp_timer None
    hal.enable_exit False
    hal.enable_c_plus_plus False
    hal.enable_lightweight_device_driver_api True
    hal.enable_clean_exit False
    hal.enable_sim_optimize False
    hal.enable_reduced_device_drivers True
    hal.make.bsp_cflags_optimization \"-Os\"

    You can reduce the HAL footprint by adjusting BSP settings as shown in the table.

  • Removing unused HAL device drivers—Configure the HAL with support only for system peripherals your application uses.
    • By default, the HAL configuration mechanism includes device driver support for all system peripherals present. If you do not plan on accessing all of these peripherals using the HAL device drivers, you can elect to have them omitted during configuration of the HAL BSP library by using the set_driver command when you configure the BSP project.
    • The HAL can be configured to include various software modules, such as the NicheStack networking stack and the read-only zip file system, whose presence increases the overall footprint of the application. However, the HAL does not enable these modules by default.