From dd77dbd4f72734da2b11ff52c553d636d1eee614 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Fri, 24 Jun 2022 12:04:47 +1000 Subject: [PATCH] stm32/boards: Enable LTO by default on boards with smaller flash size. Signed-off-by: Angus Gratton --- ports/stm32/README.md | 17 +++++++++++++++++ .../boards/B_L072Z_LRWAN1/mpconfigboard.mk | 3 +++ .../stm32/boards/NUCLEO_F091RC/mpconfigboard.mk | 3 +++ .../stm32/boards/NUCLEO_G0B1RE/mpconfigboard.mk | 3 +++ .../stm32/boards/NUCLEO_L073RZ/mpconfigboard.mk | 3 +++ .../stm32/boards/NUCLEO_L432KC/mpconfigboard.mk | 3 +++ 6 files changed, 32 insertions(+) diff --git a/ports/stm32/README.md b/ports/stm32/README.md index 6b5f096d73..15025c5ae1 100644 --- a/ports/stm32/README.md +++ b/ports/stm32/README.md @@ -68,6 +68,23 @@ can be built via: For more information about mboot see mboot/README.md. +### Link Time Optimization + +Link Time Optimization (LTO) reduces the firmware binary size when enabled +(typically 2-3% smaller). However it may make build time longer, particularly on +older GCC versions. + +Currently LTO is enabled by default for some smaller STM32 boards with less +flash, but disabled on other boards. + +To enable LTO, pass `LTO=1` on the command line: + + $ make BOARD=boardname LTO=1 + +To disable LTO, pass `LTO=0` in the same way. + +Note that `make clean BOARD=boardname` will be needed before changing the `LTO` +setting of a firmware that is already built. ### Flashing the Firmware using DFU mode diff --git a/ports/stm32/boards/B_L072Z_LRWAN1/mpconfigboard.mk b/ports/stm32/boards/B_L072Z_LRWAN1/mpconfigboard.mk index 03561f90ad..708c3cf133 100644 --- a/ports/stm32/boards/B_L072Z_LRWAN1/mpconfigboard.mk +++ b/ports/stm32/boards/B_L072Z_LRWAN1/mpconfigboard.mk @@ -9,3 +9,6 @@ MICROPY_VFS_FAT = 0 # Don't include default frozen modules because MCU is tight on flash space FROZEN_MANIFEST ?= + +# LTO reduces final binary size, may be slower to build depending on gcc version and hardware +LTO ?= 1 diff --git a/ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.mk index 4416188816..bb7142d1b3 100644 --- a/ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.mk +++ b/ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.mk @@ -9,3 +9,6 @@ MICROPY_VFS_LFS1 ?= 1 # Don't include default frozen modules because MCU is tight on flash space FROZEN_MANIFEST ?= + +# LTO reduces final binary size, may be slower to build depending on gcc version and hardware +LTO ?= 1 diff --git a/ports/stm32/boards/NUCLEO_G0B1RE/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_G0B1RE/mpconfigboard.mk index 371e10d154..b8bbfb4534 100644 --- a/ports/stm32/boards/NUCLEO_G0B1RE/mpconfigboard.mk +++ b/ports/stm32/boards/NUCLEO_G0B1RE/mpconfigboard.mk @@ -2,3 +2,6 @@ MCU_SERIES = g0 CMSIS_MCU = STM32G0B1xx AF_FILE = boards/stm32g0b1_af.csv LD_FILES = boards/stm32g0b1xe.ld boards/common_basic.ld + +# LTO reduces final binary size, may be slower to build depending on gcc version and hardware +LTO ?= 1 diff --git a/ports/stm32/boards/NUCLEO_L073RZ/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_L073RZ/mpconfigboard.mk index f3673f0060..72b13a70b2 100644 --- a/ports/stm32/boards/NUCLEO_L073RZ/mpconfigboard.mk +++ b/ports/stm32/boards/NUCLEO_L073RZ/mpconfigboard.mk @@ -8,3 +8,6 @@ MICROPY_VFS_FAT = 0 # Don't include default frozen modules because MCU is tight on flash space FROZEN_MANIFEST ?= + +# LTO reduces final binary size, may be slower to build depending on gcc version and hardware +LTO ?= 1 diff --git a/ports/stm32/boards/NUCLEO_L432KC/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_L432KC/mpconfigboard.mk index a87b4710e7..c3fff81002 100644 --- a/ports/stm32/boards/NUCLEO_L432KC/mpconfigboard.mk +++ b/ports/stm32/boards/NUCLEO_L432KC/mpconfigboard.mk @@ -10,3 +10,6 @@ MICROPY_VFS_LFS1 ?= 1 # Don't include default frozen modules because MCU is tight on flash space FROZEN_MANIFEST ?= + +# LTO reduces final binary size, may be slower to build depending on gcc version and hardware +LTO ?= 1