From 64552a3b9a05b2dac116008fa61d1842651ffa85 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Fri, 27 Mar 2020 02:30:11 +0100 Subject: [PATCH 1/2] cpu/cortexm_common: Move common modules to Makefile.dep This moves the following modules to a architecture-specific Makefile.dep file: - cortexm_common - cortexm_common_periph - newlib - newlib_nano - periph --- cpu/cc2538/Makefile.dep | 2 ++ cpu/cc26xx_cc13xx/Makefile.dep | 2 ++ cpu/cortexm_common/Makefile.dep | 14 ++++++++++++++ cpu/efm32/Makefile.dep | 2 ++ cpu/ezr32wg/Makefile.dep | 1 + cpu/kinetis/Makefile.dep | 2 ++ cpu/lm4f120/Makefile.dep | 1 + cpu/lpc1768/Makefile.dep | 2 ++ cpu/nrf51/Makefile.dep | 1 + cpu/nrf52/Makefile.dep | 1 + cpu/sam0_common/Makefile.dep | 2 ++ cpu/sam3/Makefile.dep | 1 + cpu/stm32_common/Makefile.dep | 2 ++ makefiles/arch/cortexm.inc.mk | 14 -------------- 14 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 cpu/cortexm_common/Makefile.dep create mode 100644 cpu/ezr32wg/Makefile.dep create mode 100644 cpu/lm4f120/Makefile.dep create mode 100644 cpu/sam3/Makefile.dep diff --git a/cpu/cc2538/Makefile.dep b/cpu/cc2538/Makefile.dep index b9e01ef586..6006861140 100644 --- a/cpu/cc2538/Makefile.dep +++ b/cpu/cc2538/Makefile.dep @@ -8,3 +8,5 @@ ifneq (,$(filter periph_rtc,$(USEMODULE))) endif USEMODULE += pm_layered + +include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/cc26xx_cc13xx/Makefile.dep b/cpu/cc26xx_cc13xx/Makefile.dep index c9dafe0dfb..4a55cc2938 100644 --- a/cpu/cc26xx_cc13xx/Makefile.dep +++ b/cpu/cc26xx_cc13xx/Makefile.dep @@ -1 +1,3 @@ USEMODULE += periph_common cc26xx_cc13xx_periph + +include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/cortexm_common/Makefile.dep b/cpu/cortexm_common/Makefile.dep new file mode 100644 index 0000000000..d2f428394b --- /dev/null +++ b/cpu/cortexm_common/Makefile.dep @@ -0,0 +1,14 @@ +# Tell the build system that the CPU depends on the Cortex-M common files: +USEMODULE += cortexm_common + +# include common periph code +USEMODULE += cortexm_common_periph + +# all cortex MCU's use newlib as libc +USEMODULE += newlib + +# use the nano-specs of Newlib when available +USEMODULE += newlib_nano + +# Export the peripheral drivers to be linked into the final binary: +USEMODULE += periph diff --git a/cpu/efm32/Makefile.dep b/cpu/efm32/Makefile.dep index 23e6f7fe6a..20ee155ce0 100644 --- a/cpu/efm32/Makefile.dep +++ b/cpu/efm32/Makefile.dep @@ -19,3 +19,5 @@ endif # include CPU family module USEMODULE += cpu_$(CPU_FAM) + +include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/ezr32wg/Makefile.dep b/cpu/ezr32wg/Makefile.dep new file mode 100644 index 0000000000..849cc8d116 --- /dev/null +++ b/cpu/ezr32wg/Makefile.dep @@ -0,0 +1 @@ +include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/kinetis/Makefile.dep b/cpu/kinetis/Makefile.dep index 663a24209f..4e73ff1d08 100644 --- a/cpu/kinetis/Makefile.dep +++ b/cpu/kinetis/Makefile.dep @@ -4,3 +4,5 @@ endif ifneq (,$(filter periph_i2c,$(USEMODULE))) USEMODULE += core_thread_flags endif + +include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/lm4f120/Makefile.dep b/cpu/lm4f120/Makefile.dep new file mode 100644 index 0000000000..849cc8d116 --- /dev/null +++ b/cpu/lm4f120/Makefile.dep @@ -0,0 +1 @@ +include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/lpc1768/Makefile.dep b/cpu/lpc1768/Makefile.dep index d626e716f1..f0a929e7f1 100644 --- a/cpu/lpc1768/Makefile.dep +++ b/cpu/lpc1768/Makefile.dep @@ -1 +1,3 @@ USEMODULE += pm_layered + +include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/nrf51/Makefile.dep b/cpu/nrf51/Makefile.dep index 56c2263f7e..7ea56ff04b 100644 --- a/cpu/nrf51/Makefile.dep +++ b/cpu/nrf51/Makefile.dep @@ -1 +1,2 @@ include $(RIOTCPU)/nrf5x_common/Makefile.dep +include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/nrf52/Makefile.dep b/cpu/nrf52/Makefile.dep index cbf9f0708b..ebf5dff9fe 100644 --- a/cpu/nrf52/Makefile.dep +++ b/cpu/nrf52/Makefile.dep @@ -6,3 +6,4 @@ ifneq (,$(filter nrf802154,$(USEMODULE))) endif include $(RIOTCPU)/nrf5x_common/Makefile.dep +include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/sam0_common/Makefile.dep b/cpu/sam0_common/Makefile.dep index a87db0f10c..b286abfdfa 100644 --- a/cpu/sam0_common/Makefile.dep +++ b/cpu/sam0_common/Makefile.dep @@ -7,3 +7,5 @@ USEMODULE += pm_layered # include sam0 common periph drivers USEMODULE += sam0_common_periph + +include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/sam3/Makefile.dep b/cpu/sam3/Makefile.dep new file mode 100644 index 0000000000..849cc8d116 --- /dev/null +++ b/cpu/sam3/Makefile.dep @@ -0,0 +1 @@ +include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/stm32_common/Makefile.dep b/cpu/stm32_common/Makefile.dep index 2a2c82fa34..fb87e48809 100644 --- a/cpu/stm32_common/Makefile.dep +++ b/cpu/stm32_common/Makefile.dep @@ -7,3 +7,5 @@ USEMODULE += stm32_common stm32_common_periph ifneq (,$(filter periph_usbdev,$(FEATURES_USED))) USEMODULE += xtimer endif + +include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/makefiles/arch/cortexm.inc.mk b/makefiles/arch/cortexm.inc.mk index 2e4284802e..e158e83fee 100644 --- a/makefiles/arch/cortexm.inc.mk +++ b/makefiles/arch/cortexm.inc.mk @@ -33,17 +33,6 @@ LINKFLAGS += -T$(LINKER_SCRIPT) -Wl,--fatal-warnings LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) -static -lgcc -nostartfiles LINKFLAGS += -Wl,--gc-sections -# Tell the build system that the CPU depends on the Cortex-M common files: -USEMODULE += cortexm_common -# Export the peripheral drivers to be linked into the final binary: -USEMODULE += periph -# include common periph code -USEMODULE += cortexm_common_periph - -# all cortex MCU's use newlib as libc -USEMODULE += newlib - - # extract version inside the first parentheses ARM_GCC_VERSION = $(shell $(TARGET_ARCH)-gcc --version | sed -n '1 s/[^(]*(\([^\)]*\)).*/\1/p') @@ -126,9 +115,6 @@ endif # CPU depends on the cortex-m common module, so include it: include $(RIOTCPU)/cortexm_common/Makefile.include -# use the nano-specs of Newlib when available -USEMODULE += newlib_nano - # Avoid overriding the default rule: all: From ea2f963302728a195c37096449d6a2b27512db75 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Fri, 27 Mar 2020 13:17:52 +0100 Subject: [PATCH 2/2] cpu/cortexm: Add 'cortexm_fpu' as a DEFAULT_MODULE if possible This adds cortexm_fpu to the DEFAULT_MODULE list when the feature cortexm_fpu is provided by the architecture. It also moves the dependency resolution of this module to the architecture-specific Makefile.dep file. --- cpu/cortexm_common/Makefile.dep | 6 ++++++ cpu/cortexm_common/Makefile.features | 5 +++++ makefiles/arch/cortexm.inc.mk | 24 +++++++++--------------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/cpu/cortexm_common/Makefile.dep b/cpu/cortexm_common/Makefile.dep index d2f428394b..3b3c0bc9fe 100644 --- a/cpu/cortexm_common/Makefile.dep +++ b/cpu/cortexm_common/Makefile.dep @@ -12,3 +12,9 @@ USEMODULE += newlib_nano # Export the peripheral drivers to be linked into the final binary: USEMODULE += periph + +# Use Hardware FPU by default if present +FEATURES_OPTIONAL += cortexm_fpu +ifneq (,$(filter cortexm_fpu,$(FEATURES_USED))) + DEFAULT_MODULE += cortexm_fpu +endif diff --git a/cpu/cortexm_common/Makefile.features b/cpu/cortexm_common/Makefile.features index 74b9888ac1..1ddbe4e896 100644 --- a/cpu/cortexm_common/Makefile.features +++ b/cpu/cortexm_common/Makefile.features @@ -5,3 +5,8 @@ FEATURES_PROVIDED += periph_pm FEATURES_PROVIDED += cpp FEATURES_PROVIDED += cpu_check_address FEATURES_PROVIDED += ssp + +# cortex-m4f and cortex-m7 provide FPU support +ifneq (,$(filter $(CPU_ARCH),cortex-m4f cortex-m7)) + FEATURES_PROVIDED += cortexm_fpu +endif diff --git a/makefiles/arch/cortexm.inc.mk b/makefiles/arch/cortexm.inc.mk index e158e83fee..2305ed4cc5 100644 --- a/makefiles/arch/cortexm.inc.mk +++ b/makefiles/arch/cortexm.inc.mk @@ -60,24 +60,18 @@ endif # BUILD_IN_DOCKER CFLAGS += -DCPU_MODEL_$(call uppercase_and_underscore,$(CPU_MODEL)) CFLAGS += -DCPU_ARCH_$(call uppercase_and_underscore,$(CPU_ARCH)) -# set the compiler specific CPU and FPU options -ifneq (,$(filter $(CPU_ARCH),cortex-m4f cortex-m7)) - ifneq (,$(filter cortexm_fpu,$(DISABLE_MODULE))) - CFLAGS_FPU ?= -mfloat-abi=soft +# Add corresponding FPU CFLAGS +# clang assumes there is an FPU, no CFLAGS necessary +ifneq (llvm, $(TOOLCHAIN)) + ifeq ($(CPU_ARCH),cortex-m7) + _CORTEX_HW_FPU_CFLAGS = -mfloat-abi=hard -mfpu=fpv5-sp-d16 else - USEMODULE += cortexm_fpu - # clang assumes there is an FPU - ifneq (llvm,$(TOOLCHAIN)) - ifeq ($(CPU_ARCH),cortex-m7) - CFLAGS_FPU ?= -mfloat-abi=hard -mfpu=fpv5-sp-d16 - else - CFLAGS_FPU ?= -mfloat-abi=hard -mfpu=fpv4-sp-d16 - endif - endif + _CORTEX_HW_FPU_CFLAGS = -mfloat-abi=hard -mfpu=fpv4-sp-d16 endif -else - CFLAGS_FPU ?= -mfloat-abi=soft endif +# Add soft or hard FPU CFLAGS depending on the module +# NOTE: This can be turned into normal conditional syntax once #9913 is fixed +CFLAGS_FPU ?= $(if $(filter cortexm_fpu,$(USEMODULE)),$(_CORTEX_HW_FPU_CFLAGS),-mfloat-abi=soft) ifeq ($(CPU_ARCH),cortex-m4f) MCPU = cortex-m4