mimxrt/Makefile: Refactor Makefile and divide it into sections.

Reworks grouping of Makefile variables and reorders variable values in
alphabetic order.
This commit is contained in:
Philipp Ebensberger 2022-06-19 23:00:38 +02:00 committed by Damien George
parent db7682e02d
commit fbc50196ad
1 changed files with 227 additions and 138 deletions

View File

@ -1,72 +1,61 @@
# =============================================================================
# Parameter Configuration
# =============================================================================
BOARD ?= TEENSY40
BOARD_DIR ?= boards/$(BOARD)
BUILD ?= build-$(BOARD)
PORT ?= /dev/ttyACM0
CROSS_COMPILE ?= arm-none-eabi-
ifeq ($(wildcard $(BOARD_DIR)/.),)
$(error Invalid BOARD specified: $(BOARD_DIR))
endif
include ../../py/mkenv.mk
include $(BOARD_DIR)/mpconfigboard.mk
LD_MEMORY_CONFIG_DEFINES += \
MICROPY_HW_FLASH_TYPE=$(MICROPY_HW_FLASH_TYPE) \
MICROPY_HW_FLASH_SIZE=$(MICROPY_HW_FLASH_SIZE)
ifdef MICROPY_HW_FLASH_RESERVED
LD_MEMORY_CONFIG_DEFINES += MICROPY_HW_FLASH_RESERVED=$(MICROPY_HW_FLASH_RESERVED)
endif
ifdef MICROPY_HW_SDRAM_AVAIL
CFLAGS += \
-DMICROPY_HW_SDRAM_AVAIL=$(MICROPY_HW_SDRAM_AVAIL) \
-DMICROPY_HW_SDRAM_SIZE=$(MICROPY_HW_SDRAM_SIZE)
LD_MEMORY_CONFIG_DEFINES += \
MICROPY_HW_SDRAM_AVAIL=$(MICROPY_HW_SDRAM_AVAIL) \
MICROPY_HW_SDRAM_SIZE=$(MICROPY_HW_SDRAM_SIZE)
endif
# Qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h
QSTR_GLOBAL_DEPENDENCIES = $(BOARD_DIR)/mpconfigboard.h
GIT_SUBMODULES = lib/tinyusb lib/nxp_driver lib/lwip lib/mbedtls
# MicroPython feature configurations
FROZEN_MANIFEST ?= boards/manifest.py
MICROPY_VFS_LFS2 ?= 1
MICROPY_VFS_FAT ?= 1
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h
QSTR_GLOBAL_DEPENDENCIES = $(BOARD_DIR)/mpconfigboard.h
# Generation scripts
MAKE_PINS = boards/make-pins.py
MAKE_FLEXRAM_LD = boards/make-flexram-config.py
# Include py make environment
include ../../py/mkenv.mk
# Include micropython configuration board makefile
ifeq ($(wildcard $(BOARD_DIR)/.),)
$(error Invalid BOARD specified: $(BOARD_DIR))
endif
include $(BOARD_DIR)/mpconfigboard.mk
# Include py core make definitions
include $(TOP)/py/py.mk
include $(TOP)/extmod/extmod.mk
GIT_SUBMODULES = lib/tinyusb lib/nxp_driver lib/lwip lib/mbedtls
# Set SDK directory based on MCU_SERIES
MCU_DIR = lib/nxp_driver/sdk/devices/$(MCU_SERIES)
# Select linker scripts based on MCU_SERIES
LD_FILES = boards/$(MCU_SERIES).ld boards/common.ld
MAKE_PINS = boards/make-pins.py
MAKE_FLEXRAM_LD = boards/make-flexram-config.py
BOARD_PINS = $(BOARD_DIR)/pins.csv
# Parameter configurations for generation
AF_FILE = boards/$(MCU_SERIES)_af.csv
BOARD_PINS = $(BOARD_DIR)/pins.csv
PREFIX_FILE = boards/mimxrt_prefix.c
GEN_PINS_SRC = $(BUILD)/pins_gen.c
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
GEN_PINS_QSTR = $(BUILD)/pins_qstr.h
GEN_FLEXRAM_CONFIG_SRC = $(BUILD)/flexram_config.s
GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h
GEN_PINS_AF_PY = $(BUILD)/pins_af.py
GEN_FLEXRAM_CONFIG_SRC = $(BUILD)/flexram_config.s
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
GEN_PINS_QSTR = $(BUILD)/pins_qstr.h
GEN_PINS_SRC = $(BUILD)/pins_gen.c
# mcu driver cause following warnings
#CFLAGS += -Wno-error=float-equal -Wno-error=nested-externs
CFLAGS += -Wno-error=unused-parameter
# =============================================================================
# Includes
# =============================================================================
INC += -I.
INC += -Ihal
INC += -I$(BOARD_DIR)
INC += -I$(BUILD)
INC += -I$(TOP)
@ -77,90 +66,19 @@ INC += -I$(TOP)/lib/oofatfs
INC += -I$(TOP)/lib/tinyusb/hw
INC += -I$(TOP)/lib/tinyusb/hw/bsp/teensy_40
INC += -I$(TOP)/lib/tinyusb/src
CFLAGS_MCU = -mtune=cortex-m7 -mcpu=cortex-m7
CFLAGS += $(INC) -Wall -Werror -Wdouble-promotion -Wfloat-conversion -std=c99 -nostdlib -mthumb $(CFLAGS_MCU)
CFLAGS += -DCPU_$(MCU_SERIES) -DCPU_$(MCU_VARIANT) -DBOARD_$(BOARD)
CFLAGS += -DXIP_EXTERNAL_FLASH=1 \
-DXIP_BOOT_HEADER_ENABLE=1 \
-DFSL_SDK_ENABLE_DRIVER_CACHE_CONTROL=1 \
-DCFG_TUSB_MCU=OPT_MCU_MIMXRT10XX \
-D__STARTUP_CLEAR_BSS \
-D__STARTUP_INITIALIZE_RAMFUNCTION \
-D__START=main \
-DCPU_HEADER_H='<$(MCU_SERIES).h>' \
-DCLOCK_CONFIG_H='<boards/$(MCU_SERIES)_clock_config.h>' \
-DBOARD_FLASH_SIZE=$(MICROPY_HW_FLASH_SIZE) \
-DMICROPY_HW_FLASH_SIZE=$(MICROPY_HW_FLASH_SIZE) \
CFLAGS += -DI2C_RETRY_TIMES=1000000 -DSPI_RETRY_TIMES=1000000 -DUART_RETRY_TIMES=1000000
ifeq ($(MICROPY_PY_MACHINE_SDCARD),1)
CFLAGS += -DMICROPY_PY_MACHINE_SDCARD=1
endif
CFLAGS += $(CFLAGS_MOD) $(CFLAGS_EXTRA)
# Configure floating point support
ifeq ($(MICROPY_FLOAT_IMPL),double)
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_DOUBLE
CFLAGS_MCU += -mfloat-abi=hard -mfpu=fpv5-d16
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
CFLAGS_MCU += -mfloat-abi=softfp -mfpu=fpv5-sp-d16
endif
endif
SUPPORTS_HARDWARE_FP_SINGLE = 0
SUPPORTS_HARDWARE_FP_DOUBLE = 0
LDFLAGS = -Map=$@.map --cref --print-memory-usage
LDDEFINES = $(addprefix -D, $(LD_MEMORY_CONFIG_DEFINES))
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
# Tune for Debugging or Optimization
ifeq ($(DEBUG),1)
CFLAGS += -Og -ggdb
LDFLAGS += --gc-sections
CFLAGS += -fdata-sections -ffunction-sections
else
CFLAGS += -Os -DNDEBUG
LDFLAGS += --gc-sections
CFLAGS += -fdata-sections -ffunction-sections
endif
INC += -I.
INC += -Ihal
# All settings for Ethernet support are controller by the value of MICROPY_PY_LWIP
ifeq ($(MICROPY_PY_LWIP), 1)
INC += -Ilwip_inc
INC += -Ihal/phy
SRC_MOD := $(filter-out %/mbedtls/library/error.c, $(SRC_MOD))
SRC_ETH_C += \
hal/phy/mdio/enet/fsl_enet_mdio.c \
hal/phy/device/phydp83825/fsl_phydp83825.c \
hal/phy/device/phydp83848/fsl_phydp83848.c \
hal/phy/device/phyksz8081/fsl_phyksz8081.c \
hal/phy/device/phylan8720/fsl_phylan8720.c \
lib/mbedtls_errors/mp_mbedtls_errors.c \
$(MCU_DIR)/drivers/fsl_enet.c \
SRC_QSTR += \
extmod/modnetwork.c \
extmod/moduwebsocket.c \
extmod/modusocket.c \
network_lan.c \
CFLAGS += -DFSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE=1 \
-DMBEDTLS_CONFIG_FILE='"mbedtls/mbedtls_config.h"'
endif
# =============================================================================
# Sources
# =============================================================================
# TinyUSB Stack source
SRC_TINYUSB_C += \
lib/tinyusb/src/class/cdc/cdc_device.c \
@ -176,6 +94,20 @@ SRC_TINYUSB_C += \
lib/tinyusb/src/portable/nxp/transdimension/dcd_transdimension.c \
lib/tinyusb/src/tusb.c
# All settings for Ethernet support are controller by the value of MICROPY_PY_LWIP
ifeq ($(MICROPY_PY_LWIP), 1)
SRC_MOD := $(filter-out %/mbedtls/library/error.c, $(SRC_MOD))
SRC_ETH_C += \
$(MCU_DIR)/drivers/fsl_enet.c \
hal/phy/device/phydp83825/fsl_phydp83825.c \
hal/phy/device/phydp83848/fsl_phydp83848.c \
hal/phy/device/phyksz8081/fsl_phyksz8081.c \
hal/phy/device/phylan8720/fsl_phylan8720.c \
hal/phy/mdio/enet/fsl_enet_mdio.c \
lib/mbedtls_errors/mp_mbedtls_errors.c
endif
# NXP SDK sources
SRC_HAL_IMX_C += \
$(MCU_DIR)/drivers/fsl_adc.c \
$(MCU_DIR)/drivers/fsl_cache.c \
@ -213,6 +145,7 @@ SRC_HAL_IMX_C += \
$(MCU_DIR)/drivers/fsl_qtmr.c
endif
# C source files
SRC_C += \
board_init.c \
boards/$(MCU_SERIES)_clock_config.c \
@ -254,9 +187,9 @@ SRC_C += \
sdcard.c \
shared/libc/printf.c \
shared/libc/string0.c \
shared/netutils/dhcpserver.c \
shared/netutils/netutils.c \
shared/netutils/trace.c \
shared/netutils/dhcpserver.c \
shared/readline/readline.c \
shared/runtime/gchelper_native.c \
shared/runtime/interrupt_char.c \
@ -273,33 +206,28 @@ SRC_C += \
$(SRC_ETH_C) \
ifeq ($(MICROPY_HW_FLASH_TYPE), qspi_nor)
CFLAGS += -DBOARD_FLASH_OPS_HEADER_H=\"hal/flexspi_nor_flash.h\"
SRC_C += hal/flexspi_nor_flash.c
ifeq ($(MICROPY_HW_BOARD_FLASH_FILES), 1)
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"$(BOARD)_flexspi_flash_config.h\"
SRC_C += $(BOARD_DIR)/qspi_nor_flash_config.c
else
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"hal/flexspi_flash_config.h\"
SRC_C += hal/qspi_nor_flash_config.c
endif
endif # qspi_nor
#
else ifeq ($(MICROPY_HW_FLASH_TYPE), hyperflash)
CFLAGS += -DBOARD_FLASH_OPS_HEADER_H=\"hal/flexspi_hyper_flash.h\"
SRC_C += hal/flexspi_hyper_flash.c
ifeq ($(MICROPY_HW_BOARD_FLASH_FILES), 1)
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"$(BOARD)_flexspi_flash_config.h\"
SRC_C += $(BOARD_DIR)/qspi_hyper_flash_config.c
else
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"hal/flexspi_flash_config.h\"
SRC_C += hal/qspi_hyper_flash_config.c
endif
endif # hyperflash
#
else
$(error Error: Unknown board flash type $(MICROPY_HW_FLASH_TYPE))
endif
# Math library source files
ifeq ($(MICROPY_FLOAT_IMPL),double)
LIBM_SRC_C += $(addprefix lib/libm_dbl/,\
__cos.c \
@ -386,19 +314,31 @@ 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
# Reset variables
SUPPORTS_HARDWARE_FP_SINGLE = 0
SUPPORTS_HARDWARE_FP_DOUBLE = 0
# Assembly source files
SRC_SS = \
$(MCU_DIR)/gcc/startup_$(MCU_SERIES).S \
hal/resethandler_MIMXRT10xx.S
SRC_S += shared/runtime/gchelper_m3.s \
# =============================================================================
# QSTR Sources
# =============================================================================
# All settings for Ethernet support are controller by the value of MICROPY_PY_LWIP
ifeq ($(MICROPY_PY_LWIP), 1)
SRC_QSTR += \
extmod/modlwip.c \
extmod/modnetwork.c \
extmod/modusocket.c \
extmod/moduwebsocket.c \
network_lan.c
endif
# List of sources for qstr extraction
SRC_QSTR += \
extmod/modonewire.c \
@ -421,7 +361,150 @@ SRC_QSTR += \
pin.c \
shared/runtime/mpirq.c \
shared/runtime/sys_stdio_mphal.c \
$(GEN_PINS_SRC) \
$(GEN_PINS_SRC)
# =============================================================================
# Compiler Flags
# =============================================================================
ifeq ($(DEBUG),1)
CFLAGS += -Og -ggdb
else
CFLAGS += -Os -DNDEBUG
endif
# Configure default compiler flags
CFLAGS += \
$(INC) \
-D__START=main \
-D__STARTUP_CLEAR_BSS \
-D__STARTUP_INITIALIZE_RAMFUNCTION \
-DBOARD_$(BOARD) \
-DBOARD_FLASH_SIZE=$(MICROPY_HW_FLASH_SIZE) \
-DCFG_TUSB_MCU=OPT_MCU_MIMXRT10XX \
-DCLOCK_CONFIG_H='<boards/$(MCU_SERIES)_clock_config.h>' \
-DCPU_$(MCU_SERIES) \
-DCPU_$(MCU_VARIANT) \
-DCPU_HEADER_H='<$(MCU_SERIES).h>' \
-DFSL_SDK_ENABLE_DRIVER_CACHE_CONTROL=1 \
-DI2C_RETRY_TIMES=1000000 \
-DMICROPY_HW_FLASH_SIZE=$(MICROPY_HW_FLASH_SIZE) \
-DSPI_RETRY_TIMES=1000000 \
-DUART_RETRY_TIMES=1000000 \
-DXIP_BOOT_HEADER_ENABLE=1 \
-DXIP_EXTERNAL_FLASH=1 \
-fdata-sections \
-ffunction-sections \
-mcpu=cortex-m7 \
-mthumb \
-mtune=cortex-m7 \
-nostdlib \
-std=c99 \
-Wall \
-Wdouble-promotion \
-Werror \
-Wfloat-conversion \
-Wno-error=unused-parameter
ifeq ($(MICROPY_HW_FLASH_TYPE), qspi_nor)
CFLAGS += -DBOARD_FLASH_OPS_HEADER_H=\"hal/flexspi_nor_flash.h\"
ifeq ($(MICROPY_HW_BOARD_FLASH_FILES), 1)
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"$(BOARD)_flexspi_flash_config.h\"
else
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"hal/flexspi_flash_config.h\"
endif # qspi_nor
#
else ifeq ($(MICROPY_HW_FLASH_TYPE), hyperflash)
CFLAGS += -DBOARD_FLASH_OPS_HEADER_H=\"hal/flexspi_hyper_flash.h\"
ifeq ($(MICROPY_HW_BOARD_FLASH_FILES), 1)
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"$(BOARD)_flexspi_flash_config.h\"
else
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"hal/flexspi_flash_config.h\"
endif # hyperflash
#
else
$(error Error: Unknown board flash type $(MICROPY_HW_FLASH_TYPE))
endif
# Configure floating point support
ifeq ($(MICROPY_FLOAT_IMPL),double)
CFLAGS += \
-DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_DOUBLE \
-mfloat-abi=hard \
-mfpu=fpv5-d16
else
ifeq ($(MICROPY_FLOAT_IMPL),none)
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_NONE
else
CFLAGS += \
-DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_FLOAT \
-fsingle-precision-constant \
-mfloat-abi=softfp \
-mfpu=fpv5-sp-d16
endif
endif
# Configure feature specific compiler flags
ifeq ($(MICROPY_PY_MACHINE_SDCARD),1)
CFLAGS += -DMICROPY_PY_MACHINE_SDCARD=1
endif
# All settings for Ethernet support are controller by the value of MICROPY_PY_LWIP
ifeq ($(MICROPY_PY_LWIP), 1)
CFLAGS += \
-DFSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE=1 \
-DMBEDTLS_CONFIG_FILE='"mbedtls/mbedtls_config.h"'
endif
ifdef MICROPY_HW_SDRAM_AVAIL
CFLAGS += \
-DMICROPY_HW_SDRAM_AVAIL=$(MICROPY_HW_SDRAM_AVAIL) \
-DMICROPY_HW_SDRAM_SIZE=$(MICROPY_HW_SDRAM_SIZE)
endif
CFLAGS += $(CFLAGS_MOD) $(CFLAGS_EXTRA)
# =============================================================================
# Linker Flags
# =============================================================================
LDFLAGS = \
--cref \
--gc-sections \
--print-memory-usage \
-Map=$@.map
# LDDEFINES are used for link time adaptation of linker scripts, utilizing
# the C preprocessor. Therefore keep LDDEFINES separated from LDFLAGS!
LDDEFINES = \
-DMICROPY_HW_FLASH_TYPE=$(MICROPY_HW_FLASH_TYPE) \
-DMICROPY_HW_FLASH_SIZE=$(MICROPY_HW_FLASH_SIZE)
ifdef MICROPY_HW_FLASH_RESERVED
LDDEFINES += -DMICROPY_HW_FLASH_RESERVED=$(MICROPY_HW_FLASH_RESERVED)
endif
ifdef MICROPY_HW_SDRAM_AVAIL
LDDEFINES += \
-DMICROPY_HW_SDRAM_AVAIL=$(MICROPY_HW_SDRAM_AVAIL) \
-DMICROPY_HW_SDRAM_SIZE=$(MICROPY_HW_SDRAM_SIZE)
endif
# =============================================================================
# Library and Object files
# =============================================================================
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
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
OBJ += $(PY_O)
OBJ += $(LIBM_O)
@ -434,8 +517,14 @@ OBJ += $(BUILD)/pins_gen.o
# Workaround for bug in older gcc, warning on "static usbd_device_t _usbd_dev = { 0 };"
$(BUILD)/lib/tinyusb/src/device/usbd.o: CFLAGS += -Wno-missing-braces
# =============================================================================
# Build targets
# =============================================================================
all: $(BUILD)/firmware.hex $(BUILD)/firmware.bin
# Process linker scripts with C preprocessor to exchange LDDEFINES and
# aggregate output of preprocessor in a single linker script `link.ld`
$(BUILD)/firmware.elf: $(OBJ)
$(ECHO) "PREPROCESS LINK $@"
$(Q)$(CC) -E -x c $(LDDEFINES) $(LD_FILES) | grep -v '^#' > $(BUILD)/link.ld