diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index eedcc94a92..25ab2c4aa7 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -87,25 +87,28 @@ INC += -I. \ ifeq ($(CHIP_FAMILY), samd21) PERIPHERALS_CHIP_FAMILY=samd21 -CFLAGS += -Os -DNDEBUG +OPTIMIZATION_FLAGS ?= -Os # TinyUSB defines CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAMD21 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=128 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=128 -DCFG_TUD_MSC_BUFSIZE=512 endif ifeq ($(CHIP_FAMILY), samd51) PERIPHERALS_CHIP_FAMILY=sam_d5x_e5x -CFLAGS += -Os -DNDEBUG +OPTIMIZATION_FLAGS ?= -O2 # TinyUSB defines CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAMD51 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024 endif ifeq ($(CHIP_FAMILY), same54) PERIPHERALS_CHIP_FAMILY=sam_d5x_e5x -CFLAGS += -Os -DNDEBUG +OPTIMIZATION_FLAGS ?= -O2 # TinyUSB defines CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAMD51 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024 endif +# option to override default optimization level, set in boards/$(BOARD)/mpconfigboard.mk +CFLAGS += $(OPTIMIZATION_FLAGS) -DNDEBUG + $(echo PERIPHERALS_CHIP_FAMILY=$(PERIPHERALS_CHIP_FAMILY)) #Debugging/Optimization ifeq ($(DEBUG), 1) diff --git a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk index 9c7fe3398a..18cef738e8 100644 --- a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk +++ b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk @@ -18,3 +18,6 @@ CIRCUITPY_PS2IO = 0 CIRCUITPY_AUDIOMP3 = 0 CIRCUITPY_ULAB = 0 + +# Override optimization to keep binary small +OPTIMIZATION_FLAGS = -Os diff --git a/ports/atmel-samd/boards/loc_ber_m4_base_board/mpconfigboard.mk b/ports/atmel-samd/boards/loc_ber_m4_base_board/mpconfigboard.mk index 55d6fa78e6..3c407f5306 100644 --- a/ports/atmel-samd/boards/loc_ber_m4_base_board/mpconfigboard.mk +++ b/ports/atmel-samd/boards/loc_ber_m4_base_board/mpconfigboard.mk @@ -15,3 +15,5 @@ LONGINT_IMPL = MPZ CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_BITBANG_APA102 = 1 +# Override optimization to keep binary small +OPTIMIZATION_FLAGS = -Os diff --git a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk index e0adc11b06..1ea4a7601f 100644 --- a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk @@ -46,3 +46,5 @@ CFLAGS_INLINE_LIMIT = 45 else CFLAGS_INLINE_LIMIT = 70 endif +# Override optimization to keep binary small +OPTIMIZATION_FLAGS = -Os diff --git a/ports/cxd56/Makefile b/ports/cxd56/Makefile index 3766d42228..b3e104e1ea 100644 --- a/ports/cxd56/Makefile +++ b/ports/cxd56/Makefile @@ -107,7 +107,6 @@ CFLAGS += \ -Dmain=spresense_main \ -D_estack=__stack \ -c \ - -Os \ -pipe \ -std=gnu11 \ -mcpu=cortex-m4 \ @@ -123,6 +122,12 @@ CFLAGS += \ -fdata-sections \ -Wall \ +OPTIMIZATION_FLAGS ?= -O2 + +# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk +CFLAGS += $(OPTIMIZATION_FLAGS) + + LIBM = "${shell "$(CC)" $(CFLAGS) -print-file-name=libm.a}" LIBGCC = "${shell "$(CC)" $(CFLAGS) -print-libgcc-file-name}" diff --git a/ports/esp32s2/Makefile b/ports/esp32s2/Makefile index 401a06a847..55db73604c 100644 --- a/ports/esp32s2/Makefile +++ b/ports/esp32s2/Makefile @@ -101,14 +101,19 @@ CFLAGS += -DSTACK_CANARY_VALUE=0xa5a5a5a5 #Debugging/Optimization ifeq ($(DEBUG), 1) CFLAGS += -ggdb + OPTIMIZATION_FLAGS ?= -Og # You may want to enable these flags to make setting breakpoints easier. # CFLAGS += -fno-inline -fno-ipa-sra else - CFLAGS += -Os -DNDEBUG -ggdb3 + CFLAGS += -DNDEBUG -ggdb3 + OPTIMIZATION_FLAGS ?= -O2 # TODO: Test with -flto ### CFLAGS += -flto endif +# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk +CFLAGS += $(OPTIMIZATION_FLAGS) + CFLAGS += $(INC) -Werror -Wall -mlongcalls -std=gnu11 -Wl,--gc-sections $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT) LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-Map=$@.map -Wl,-cref diff --git a/ports/litex/Makefile b/ports/litex/Makefile index 29149942c9..612953daaf 100644 --- a/ports/litex/Makefile +++ b/ports/litex/Makefile @@ -77,12 +77,17 @@ ifeq ($(DEBUG), 1) CFLAGS += -ggdb # You may want to enable these flags to make setting breakpoints easier. CFLAGS += -fno-inline -fno-ipa-sra + OPTIMIZATION_FLAGS ?= -Og else - CFLAGS += -Os -DNDEBUG -ggdb3 + CFLAGS += -DNDEBUG -ggdb3 + OPTIMIZATION_FLAGS ?= -O2 # TODO: Test with -flto ### CFLAGS += -flto endif +# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk +CFLAGS += $(OPTIMIZATION_FLAGS) + CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT) # TODO: check this diff --git a/ports/mimxrt10xx/Makefile b/ports/mimxrt10xx/Makefile index d82b625e74..9177188100 100644 --- a/ports/mimxrt10xx/Makefile +++ b/ports/mimxrt10xx/Makefile @@ -105,9 +105,14 @@ CFLAGS += \ -DCPU_$(CHIP_VARIANT) \ -DDEBUG \ -DIMXRT10XX \ - -Os -g3 -Wno-unused-parameter \ + -g3 -Wno-unused-parameter \ -ffunction-sections -fdata-sections -fstack-usage +OPTIMIZATION_FLAGS ?= -O2 + +# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk +CFLAGS += $(OPTIMIZATION_FLAGS) + LD_FILES = $(wildcard boards/$(BOARD)/*.ld) $(addprefix linking/, flash/$(FLASH).ld chip_family/$(CHIP_FAMILY).ld common.ld) LD_SCRIPT_FLAG := -Wl,-T, diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index e1d86f7bc1..13a148df3b 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -86,12 +86,16 @@ INC += -I../../supervisor/shared/usb #Debugging/Optimization ifeq ($(DEBUG), 1) - CFLAGS += -ggdb3 -Og + CFLAGS += -ggdb3 + OPTIMIZATION_FLAGS = -Og else - CFLAGS += -Os -DNDEBUG -ggdb3 + OPTIMIZATION_FLAGS ?= -O2 + CFLAGS += -DNDEBUG -ggdb3 CFLAGS += -flto -flto-partition=none endif +# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk +CFLAGS += $(OPTIMIZATION_FLAGS) CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) diff --git a/ports/nrf/boards/pca10100/mpconfigboard.mk b/ports/nrf/boards/pca10100/mpconfigboard.mk index 318bc02065..e15bf3a67c 100644 --- a/ports/nrf/boards/pca10100/mpconfigboard.mk +++ b/ports/nrf/boards/pca10100/mpconfigboard.mk @@ -30,3 +30,6 @@ SUPEROPT_GC = 0 # These defines must be overridden before mpconfigboard.h is included, which is # why they are passed on the command line. CFLAGS += -DSPIM3_BUFFER_SIZE=0 -DSOFTDEVICE_RAM_SIZE='(32*1024)' + +# Override optimization to keep binary small +OPTIMIZATION_FLAGS = -Os diff --git a/ports/nrf/boards/simmel/mpconfigboard.mk b/ports/nrf/boards/simmel/mpconfigboard.mk index 2bca2492fc..8dd284d578 100644 --- a/ports/nrf/boards/simmel/mpconfigboard.mk +++ b/ports/nrf/boards/simmel/mpconfigboard.mk @@ -32,3 +32,6 @@ CIRCUITPY_WATCHDOG = 1 # These defines must be overridden before mpconfigboard.h is included, which is # why they are passed on the command line. CFLAGS += -DSPIM3_BUFFER_SIZE=0 -DSOFTDEVICE_RAM_SIZE='(32*1024)' -DNRFX_SPIM3_ENABLED=0 + +# Override optimization to keep binary small +OPTIMIZATION_FLAGS = -Os diff --git a/ports/stm/Makefile b/ports/stm/Makefile index 7fce260349..dccc749ed8 100755 --- a/ports/stm/Makefile +++ b/ports/stm/Makefile @@ -85,12 +85,16 @@ ifeq ($(DEBUG), 1) # You may want to enable these flags to make setting breakpoints easier. CFLAGS += -fno-inline -fno-ipa-sra else - CFLAGS += -Os -DNDEBUG + CFLAGS += -DNDEBUG + OPTIMIZATION_FLAGS ?= -O2 CFLAGS += -ggdb3 # TODO: Test with -flto # CFLAGS += -flto endif +# to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk +CFLAGS += $(OPTIMIZATION_FLAGS) + # MCU Series is defined by the HAL package and doesn't need to be specified here C_DEFS = -D$(MCU_PACKAGE) -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -D$(MCU_VARIANT)