From e35d8a25d36521a1f026d0e3042a4dc20ca62f1b Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Mon, 18 Feb 2019 16:11:38 +0100 Subject: [PATCH] Allow files to compiled without optimization. This is required when trying to see what the optimizer is doing to the assembly or in aiding debugging CPU IMPRECISE bus fault errors. --- Makefile | 35 +++++++++++++++++++++++++---------- make/source.mk | 4 ++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 78d4e775d..06cc03788 100644 --- a/Makefile +++ b/Makefile @@ -211,6 +211,7 @@ CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT) CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT) CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED) CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE) +CC_NO_OPTIMISATION := CFLAGS += $(ARCH_FLAGS) \ $(addprefix -D,$(OPTIONS)) \ @@ -310,19 +311,33 @@ $(TARGET_ELF): $(TARGET_OBJS) ifeq ($(DEBUG),GDB) $(OBJECT_DIR)/$(TARGET)/%.o: %.c $(V1) mkdir -p $(dir $@) - $(V1) echo "%% (debug) $(notdir $<)" "$(STDOUT)" && \ - $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEBUG_OPTIMISATION) $< + $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \ + echo "%% (not optimised) $<" "$(STDOUT)" && \ + $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_NO_OPTIMISATION) $< \ + , \ + echo "%% (debug) $<" "$(STDOUT)" && \ + $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEBUG_OPTIMISATION) $< \ + ) else $(OBJECT_DIR)/$(TARGET)/%.o: %.c $(V1) mkdir -p $(dir $@) - $(V1) $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \ - echo "%% (speed optimised) $(notdir $<)" "$(STDOUT)" && \ - $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SPEED_OPTIMISATION) $<, \ - $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \ - echo "%% (size optimised) $(notdir $<)" "$(STDOUT)" && \ - $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SIZE_OPTIMISATION) $<, \ - echo "%% $(notdir $<)" "$(STDOUT)" && \ - $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEFAULT_OPTIMISATION) $<)) + $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \ + echo "%% (not optimised) $<" "$(STDOUT)" && \ + $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_NO_OPTIMISATION) $< \ + , \ + $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \ + echo "%% (speed optimised) $<" "$(STDOUT)" && \ + $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SPEED_OPTIMISATION) $< \ + , \ + $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \ + echo "%% (size optimised) $<" "$(STDOUT)" && \ + $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SIZE_OPTIMISATION) $< \ + , \ + echo "%% (optimised) $<" "$(STDOUT)" && \ + $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEFAULT_OPTIMISATION) $< \ + ) \ + ) \ + ) endif # Assemble diff --git a/make/source.mk b/make/source.mk index dd974bab9..57200ec79 100644 --- a/make/source.mk +++ b/make/source.mk @@ -333,6 +333,10 @@ endif #!F1 # check if target.mk supplied SRC := $(STARTUP_SRC) $(MCU_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC) +# Files that should not be optimized, useful for debugging IMPRECISE cpu faults. +# Specify FULL PATH, e.g. "./lib/main/STM32F7/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_sdmmc.c" +NOT_OPTIMISED_SRC := $(NOT_OPTIMISED_SRC) \ + ifneq ($(DSP_LIB),) INCLUDE_DIRS += $(DSP_LIB)/Include