From a40e1473dc5a399d2586da32c3abb96413b5463c Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 26 May 2021 11:29:34 +0200 Subject: [PATCH] mimxrt: Add floating point support. Since not all boards support double fp, all board specific .mk files are affected too. --- ports/mimxrt/Makefile | 109 ++++++++++++++++++ .../boards/MIMXRT1010_EVK/mpconfigboard.mk | 2 + .../boards/MIMXRT1020_EVK/mpconfigboard.mk | 2 + .../boards/MIMXRT1050_EVK/mpconfigboard.mk | 2 + .../boards/MIMXRT1060_EVK/mpconfigboard.mk | 2 + .../boards/MIMXRT1064_EVK/mpconfigboard.mk | 2 + ports/mimxrt/boards/TEENSY40/mpconfigboard.mk | 2 + 7 files changed, 121 insertions(+) diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index 732485edd9..141bc2c49b 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -67,6 +67,21 @@ CFLAGS += -DXIP_EXTERNAL_FLASH=1 \ -DCPU_HEADER_H='<$(MCU_SERIES).h>' CFLAGS += $(CFLAGS_MOD) $(CFLAGS_EXTRA) +# Configure floating point support +ifeq ($(MICROPY_FLOAT_IMPL),double) +CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_DOUBLE +else +ifeq ($(MICROPY_FLOAT_IMPL),none) +CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_NONE +else +CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_FLOAT +CFLAGS += -fsingle-precision-constant +endif +endif + +SUPPORTS_HARDWARE_FP_SINGLE = 0 +SUPPORTS_HARDWARE_FP_DOUBLE = 0 + LDFLAGS = $(addprefix -T,$(LD_FILES)) -Map=$@.map --cref --print-memory-usage LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name) @@ -140,6 +155,99 @@ SRC_C = \ $(SRC_TINYUSB_C) \ $(SRC_TINYUSB_IMX_C) \ +ifeq ($(MICROPY_FLOAT_IMPL),double) +LIBM_SRC_C += $(addprefix lib/libm_dbl/,\ + __cos.c \ + __expo2.c \ + __fpclassify.c \ + __rem_pio2.c \ + __rem_pio2_large.c \ + __signbit.c \ + __sin.c \ + __tan.c \ + acos.c \ + acosh.c \ + asin.c \ + asinh.c \ + atan.c \ + atan2.c \ + atanh.c \ + ceil.c \ + cos.c \ + cosh.c \ + copysign.c \ + erf.c \ + exp.c \ + expm1.c \ + floor.c \ + fmod.c \ + frexp.c \ + ldexp.c \ + lgamma.c \ + log.c \ + log10.c \ + log1p.c \ + modf.c \ + nearbyint.c \ + pow.c \ + rint.c \ + round.c \ + scalbn.c \ + sin.c \ + sinh.c \ + tan.c \ + tanh.c \ + tgamma.c \ + trunc.c \ + ) +ifeq ($(SUPPORTS_HARDWARE_FP_DOUBLE),1) +LIBM_SRC_C += lib/libm_dbl/thumb_vfp_sqrt.c +else +LIBM_SRC_C += lib/libm_dbl/sqrt.c +endif +else +LIBM_SRC_C += $(addprefix lib/libm/,\ + math.c \ + acoshf.c \ + asinfacosf.c \ + asinhf.c \ + atan2f.c \ + atanf.c \ + atanhf.c \ + ef_rem_pio2.c \ + erf_lgamma.c \ + fmodf.c \ + kf_cos.c \ + kf_rem_pio2.c \ + kf_sin.c \ + kf_tan.c \ + log1pf.c \ + nearbyintf.c \ + roundf.c \ + sf_cos.c \ + sf_erf.c \ + sf_frexp.c \ + sf_ldexp.c \ + sf_modf.c \ + sf_sin.c \ + sf_tan.c \ + wf_lgamma.c \ + wf_tgamma.c \ + ) +ifeq ($(SUPPORTS_HARDWARE_FP_SINGLE),1) +LIBM_SRC_C += lib/libm/thumb_vfp_sqrtf.c +else +LIBM_SRC_C += lib/libm/ef_sqrt.c +endif +endif + +LIBM_O = $(addprefix $(BUILD)/, $(LIBM_SRC_C:.c=.o)) + +# Too many warnings in libm_dbl, disable for now. +ifeq ($(MICROPY_FLOAT_IMPL),double) +$(LIBM_O): CFLAGS := $(filter-out -Wdouble-promotion -Wfloat-conversion, $(CFLAGS)) +endif + SRC_SS = $(MCU_DIR)/gcc/startup_$(MCU_SERIES).S SRC_S = lib/utils/gchelper_m3.s \ @@ -160,6 +268,7 @@ SRC_QSTR += \ $(GEN_PINS_SRC) \ OBJ += $(PY_O) +OBJ += $(LIBM_O) OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_SS:.S=.o)) diff --git a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk index c5b5055324..ca8efcd5bf 100644 --- a/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk @@ -1,6 +1,8 @@ MCU_SERIES = MIMXRT1011 MCU_VARIANT = MIMXRT1011DAE5A +MICROPY_FLOAT_IMPL = single + JLINK_PATH = /media/RT1010-EVK/ JLINK_COMMANDER_SCRIPT = $(BUILD)/script.jlink diff --git a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk index 0f5bb967af..b0bbd705cb 100644 --- a/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk @@ -1,6 +1,8 @@ MCU_SERIES = MIMXRT1021 MCU_VARIANT = MIMXRT1021DAG5A +MICROPY_FLOAT_IMPL = double + JLINK_PATH ?= /media/RT1020-EVK/ JLINK_COMMANDER_SCRIPT = $(BUILD)/script.jlink diff --git a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk index 61cca4d63f..e338ec6cf8 100644 --- a/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1050_EVK/mpconfigboard.mk @@ -1,6 +1,8 @@ MCU_SERIES = MIMXRT1052 MCU_VARIANT = MIMXRT1052DVL6B +MICROPY_FLOAT_IMPL = double + JLINK_PATH ?= /media/RT1050-EVK/ deploy: $(BUILD)/firmware.bin diff --git a/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk index 32f87046b8..b7ea5fcbe1 100644 --- a/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk @@ -1,6 +1,8 @@ MCU_SERIES = MIMXRT1062 MCU_VARIANT = MIMXRT1062DVJ6A +MICROPY_FLOAT_IMPL = double + JLINK_PATH ?= /media/RT1060-EVK/ JLINK_COMMANDER_SCRIPT = $(BUILD)/script.jlink diff --git a/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk index 7009889191..bd4c496416 100644 --- a/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk +++ b/ports/mimxrt/boards/MIMXRT1064_EVK/mpconfigboard.mk @@ -1,6 +1,8 @@ MCU_SERIES = MIMXRT1064 MCU_VARIANT = MIMXRT1064DVL6A +MICROPY_FLOAT_IMPL = double + JLINK_PATH ?= /media/RT1064-EVK/ CFLAGS += -DBOARD_FLASH_SIZE=0x400000 diff --git a/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk b/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk index 79365d0da8..0f818af42c 100644 --- a/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk +++ b/ports/mimxrt/boards/TEENSY40/mpconfigboard.mk @@ -1,6 +1,8 @@ MCU_SERIES = MIMXRT1062 MCU_VARIANT = MIMXRT1062DVJ6A +MICROPY_FLOAT_IMPL = double + deploy: $(BUILD)/firmware.hex teensy_loader_cli --mcu=imxrt1062 -v -w $< sleep 1