|
| 1 | +# This file is part of the MicroPython project, http://micropython.org/ |
| 2 | +# |
| 3 | +# The MIT License (MIT) |
| 4 | +# |
| 5 | +# Copyright (c) 2019 Dan Halbert for Adafruit Industries |
| 6 | +# Copyright (c) 2019 Artur Pacholec |
| 7 | +# |
| 8 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | +# of this software and associated documentation files (the "Software"), to deal |
| 10 | +# in the Software without restriction, including without limitation the rights |
| 11 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | +# copies of the Software, and to permit persons to whom the Software is |
| 13 | +# furnished to do so, subject to the following conditions: |
| 14 | +# |
| 15 | +# The above copyright notice and this permission notice shall be included in |
| 16 | +# all copies or substantial portions of the Software. |
| 17 | +# |
| 18 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | +# THE SOFTWARE. |
| 25 | + |
| 26 | +# Select the board to build for. |
| 27 | +ifeq ($(BOARD),) |
| 28 | + $(error You must provide a BOARD parameter) |
| 29 | +else |
| 30 | + ifeq ($(wildcard boards/$(BOARD)/.),) |
| 31 | + $(error Invalid BOARD specified) |
| 32 | + endif |
| 33 | +endif |
| 34 | + |
| 35 | +# If the build directory is not given, make it reflect the board name. |
| 36 | +BUILD ?= build-$(BOARD) |
| 37 | + |
| 38 | +include ../../py/mkenv.mk |
| 39 | +# Board-specific |
| 40 | +include boards/$(BOARD)/mpconfigboard.mk |
| 41 | +# Port-specific |
| 42 | +include mpconfigport.mk |
| 43 | +# CircuitPython-specific |
| 44 | +include $(TOP)/py/circuitpy_mpconfig.mk |
| 45 | + |
| 46 | +# qstr definitions (must come before including py.mk) |
| 47 | +QSTR_DEFS = qstrdefsport.h |
| 48 | + |
| 49 | +# include py core make definitions |
| 50 | +include $(TOP)/py/py.mk |
| 51 | + |
| 52 | +include $(TOP)/supervisor/supervisor.mk |
| 53 | + |
| 54 | +# Include make rules and variables common across CircuitPython builds. |
| 55 | +include $(TOP)/py/circuitpy_defns.mk |
| 56 | + |
| 57 | +CROSS_COMPILE = arm-none-eabi- |
| 58 | + |
| 59 | +INC += \ |
| 60 | + -I. \ |
| 61 | + -I../.. \ |
| 62 | + -I../lib/mp-readline \ |
| 63 | + -I../lib/timeutils \ |
| 64 | + -I../../lib/tinyusb/src \ |
| 65 | + -I../../supervisor/shared/usb \ |
| 66 | + -I$(BUILD) \ |
| 67 | + -Iboards/ \ |
| 68 | + -Iboards/$(BOARD) \ |
| 69 | + -Iperipherals/ \ |
| 70 | + -Iperipherals/mimxrt10xx/ \ |
| 71 | + -Isdk/CMSIS/Include \ |
| 72 | + -Isdk/devices/$(CHIP_FAMILY) \ |
| 73 | + -Isdk/devices/$(CHIP_FAMILY)/drivers \ |
| 74 | + |
| 75 | +# NDEBUG disables assert() statements. This reduces code size pretty dramatically, per tannewt. |
| 76 | + |
| 77 | +CFLAGS += -Os -DNDEBUG |
| 78 | + |
| 79 | +# TinyUSB defines |
| 80 | +CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_MIMXRT10XX -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 |
| 81 | + |
| 82 | +#Debugging/Optimization |
| 83 | +ifeq ($(DEBUG), 1) |
| 84 | + CFLAGS += -ggdb |
| 85 | + # You may want to disable -flto if it interferes with debugging. |
| 86 | + #CFLAGS += -flto -flto-partition=none |
| 87 | + # You may want to enable these flags to make setting breakpoints easier. |
| 88 | + CFLAGS += -fno-inline -fno-ipa-sra |
| 89 | +else |
| 90 | + # -finline-limit can shrink the image size. |
| 91 | + # -finline-limit=80 or so is similar to not having it on. |
| 92 | + # There is no simple default value, though. |
| 93 | + |
| 94 | + # Do a default shrink for small builds. |
| 95 | + ifndef CFLAGS_INLINE_LIMIT |
| 96 | + ifeq ($(CIRCUITPY_SMALL_BUILD),1) |
| 97 | + CFLAGS_INLINE_LIMIT = 50 |
| 98 | + endif |
| 99 | + endif |
| 100 | + |
| 101 | + ifdef CFLAGS_INLINE_LIMIT |
| 102 | + CFLAGS += -finline-limit=$(CFLAGS_INLINE_LIMIT) |
| 103 | + endif |
| 104 | + #CFLAGS += -flto -flto-partition=none |
| 105 | +endif |
| 106 | + |
| 107 | +CFLAGS += $(INC) -Wall -Wno-cast-align -std=gnu11 -nostdlib $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) |
| 108 | + |
| 109 | +CFLAGS += \ |
| 110 | + -mthumb \ |
| 111 | + -mapcs \ |
| 112 | + -mcpu=cortex-m7 \ |
| 113 | + -mfloat-abi=hard \ |
| 114 | + -mfpu=fpv5-sp-d16 \ |
| 115 | + -DCPU_$(CHIP_VARIANT) \ |
| 116 | + -DDEBUG \ |
| 117 | + -DXIP_EXTERNAL_FLASH=1 \ |
| 118 | + -DXIP_BOOT_HEADER_ENABLE=1 \ |
| 119 | + -D__START=main \ |
| 120 | + -Os -g3 -Wno-unused-parameter \ |
| 121 | + -ffunction-sections -fdata-sections -fstack-usage \ |
| 122 | + -D__STARTUP_CLEAR_BSS |
| 123 | + |
| 124 | +LDFLAGS = $(CFLAGS) -nostartfiles -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs |
| 125 | +LIBS := -lgcc -lc -lnosys -lm |
| 126 | + |
| 127 | +# Use toolchain libm if we're not using our own. |
| 128 | +ifndef INTERNAL_LIBM |
| 129 | +LIBS += -lm |
| 130 | +endif |
| 131 | + |
| 132 | +LDFLAGS += -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -mthumb -mapcs |
| 133 | +BOOTLOADER_SIZE := 0x6000C000 |
| 134 | + |
| 135 | +SRC_SDK := \ |
| 136 | + drivers/fsl_adc.c \ |
| 137 | + drivers/fsl_cache.c \ |
| 138 | + drivers/fsl_clock.c \ |
| 139 | + drivers/fsl_common.c \ |
| 140 | + drivers/fsl_flexspi.c \ |
| 141 | + drivers/fsl_gpio.c \ |
| 142 | + drivers/fsl_lpi2c.c \ |
| 143 | + drivers/fsl_lpspi.c \ |
| 144 | + drivers/fsl_lpuart.c \ |
| 145 | + drivers/fsl_ocotp.c \ |
| 146 | + drivers/fsl_pwm.c \ |
| 147 | + drivers/fsl_snvs_hp.c \ |
| 148 | + drivers/fsl_tempmon.c \ |
| 149 | + drivers/fsl_trng.c \ |
| 150 | + system_$(CHIP_FAMILY).c \ |
| 151 | + |
| 152 | +SRC_SDK := $(addprefix sdk/devices/$(CHIP_FAMILY)/, $(SRC_SDK)) |
| 153 | + |
| 154 | +SRC_C = \ |
| 155 | + background.c \ |
| 156 | + boards/$(BOARD)/board.c \ |
| 157 | + boards/$(BOARD)/pins.c \ |
| 158 | + fatfs_port.c \ |
| 159 | + lib/mp-readline/readline.c \ |
| 160 | + lib/oofatfs/ff.c \ |
| 161 | + lib/oofatfs/option/ccsbcs.c \ |
| 162 | + lib/timeutils/timeutils.c \ |
| 163 | + lib/utils/buffer_helper.c \ |
| 164 | + lib/utils/context_manager_helpers.c \ |
| 165 | + lib/utils/interrupt_char.c \ |
| 166 | + lib/utils/pyexec.c \ |
| 167 | + lib/utils/stdout_helpers.c \ |
| 168 | + lib/utils/sys_stdio_mphal.c \ |
| 169 | + lib/tinyusb/src/portable/nxp/transdimension/dcd_transdimension.c \ |
| 170 | + mphalport.c \ |
| 171 | + peripherals/mimxrt10xx/$(CHIP_FAMILY)/clocks.c \ |
| 172 | + peripherals/mimxrt10xx/$(CHIP_FAMILY)/periph.c \ |
| 173 | + peripherals/mimxrt10xx/$(CHIP_FAMILY)/pins.c \ |
| 174 | + reset.c \ |
| 175 | + supervisor/flexspi_nor_flash_ops.c \ |
| 176 | + supervisor/shared/memory.c \ |
| 177 | + tick.c |
| 178 | + |
| 179 | +ifeq ($(CIRCUITPY_NETWORK),1) |
| 180 | +CFLAGS += -DMICROPY_PY_NETWORK=1 |
| 181 | + |
| 182 | +SRC_MOD += lib/netutils/netutils.c |
| 183 | + |
| 184 | +ifneq ($(MICROPY_PY_WIZNET5K),0) |
| 185 | +WIZNET5K_DIR=drivers/wiznet5k |
| 186 | +INC += -I$(TOP)/$(WIZNET5K_DIR) |
| 187 | +CFLAGS_MOD += -DMICROPY_PY_WIZNET5K=$(MICROPY_PY_WIZNET5K) -D_WIZCHIP_=$(MICROPY_PY_WIZNET5K) |
| 188 | +SRC_MOD += $(addprefix $(WIZNET5K_DIR)/,\ |
| 189 | + ethernet/w$(MICROPY_PY_WIZNET5K)/w$(MICROPY_PY_WIZNET5K).c \ |
| 190 | + ethernet/wizchip_conf.c \ |
| 191 | + ethernet/socket.c \ |
| 192 | + internet/dns/dns.c \ |
| 193 | + internet/dhcp/dhcp.c \ |
| 194 | + ) |
| 195 | + |
| 196 | +endif # MICROPY_PY_WIZNET5K |
| 197 | +endif # CIRCUITPY_NETWORK |
| 198 | + |
| 199 | +ifeq ($(CIRCUITPY_NETWORK),1) |
| 200 | +ifneq ($(MICROPY_PY_WIZNET5K),0) |
| 201 | +SRC_SHARED_MODULE += wiznet/__init__.c wiznet/wiznet5k.c |
| 202 | +endif |
| 203 | +endif |
| 204 | + |
| 205 | +# TODO |
| 206 | +#ifeq ($(CIRCUITPY_AUDIOBUSIO),1) |
| 207 | +#SRC_C += peripherals/samd/i2s.c peripherals/samd/$(CHIP_FAMILY)/i2s.c |
| 208 | +#endif |
| 209 | +# |
| 210 | +SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ |
| 211 | + $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ |
| 212 | + $(addprefix common-hal/, $(SRC_COMMON_HAL)) |
| 213 | + |
| 214 | +SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \ |
| 215 | + $(addprefix shared-module/, $(SRC_SHARED_MODULE)) \ |
| 216 | + $(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL)) |
| 217 | + |
| 218 | +SRC_S = \ |
| 219 | + sdk/devices/$(CHIP_FAMILY)/gcc/startup_$(CHIP_FAMILY).S \ |
| 220 | + supervisor/cpu.S |
| 221 | + |
| 222 | +OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) |
| 223 | +OBJ += $(addprefix $(BUILD)/, $(SRC_SDK:.c=.o)) |
| 224 | +OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o)) |
| 225 | +OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o)) |
| 226 | +ifeq ($(INTERNAL_LIBM),1) |
| 227 | +OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o)) |
| 228 | +endif |
| 229 | +OBJ += $(addprefix $(BUILD)/, $(SRC_S:.S=.o)) |
| 230 | +OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o)) |
| 231 | + |
| 232 | +SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) |
| 233 | + |
| 234 | +all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2 |
| 235 | + |
| 236 | +$(BUILD)/firmware.elf: $(LD_FILE) $(OBJ) |
| 237 | + $(STEPECHO) "LINK $@" |
| 238 | + $(Q)$(CC) -o $@ $(LDFLAGS) $(filter-out $<,$^) -Wl,--start-group $(LIBS) -Wl,--end-group |
| 239 | + |
| 240 | +$(BUILD)/firmware.bin: $(BUILD)/firmware.elf |
| 241 | + $(STEPECHO) "Create $@" |
| 242 | + $(Q)$(OBJCOPY) -O binary -j .interrupts -j .text -j .ARM.exidx -j .data $^ $@ |
| 243 | + |
| 244 | +$(BUILD)/firmware.uf2: $(BUILD)/firmware.bin |
| 245 | + $(STEPECHO) "Create $@" |
| 246 | + $(Q)$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -b $(BOOTLOADER_SIZE) -f MIMXRT10XX -c -o $@ $^ |
| 247 | + |
| 248 | +include $(TOP)/py/mkrules.mk |
| 249 | + |
| 250 | +# Print out the value of a make variable. |
| 251 | +# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile |
| 252 | +print-%: |
| 253 | + @echo $* = $($*) |
0 commit comments