2019-11-02 11:52:26 -04:00
|
|
|
# This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
#
|
|
|
|
# The MIT License (MIT)
|
|
|
|
#
|
2020-06-03 18:40:05 -04:00
|
|
|
# SPDX-FileCopyrightText: Copyright (c) 2019 Dan Halbert for Adafruit Industries
|
|
|
|
# SPDX-FileCopyrightText: Copyright (c) 2019 Artur Pacholec
|
2019-11-02 11:52:26 -04:00
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
# THE SOFTWARE.
|
|
|
|
|
2022-11-18 12:30:28 -05:00
|
|
|
include ../../py/circuitpy_mkenv.mk
|
2019-11-02 11:52:26 -04:00
|
|
|
|
|
|
|
CROSS_COMPILE = arm-none-eabi-
|
|
|
|
|
|
|
|
INC += \
|
|
|
|
-I. \
|
|
|
|
-I../.. \
|
2023-03-21 19:21:57 -04:00
|
|
|
-I../../lib/cmsis/inc \
|
2019-11-02 11:52:26 -04:00
|
|
|
-I../../lib/tinyusb/src \
|
|
|
|
-I../../supervisor/shared/usb \
|
|
|
|
-I$(BUILD) \
|
|
|
|
-Iboards/ \
|
|
|
|
-Iboards/$(BOARD) \
|
|
|
|
-Iperipherals/ \
|
|
|
|
-Iperipherals/mimxrt10xx/ \
|
|
|
|
-Isdk/CMSIS/Include \
|
|
|
|
-Isdk/devices/$(CHIP_FAMILY) \
|
|
|
|
-Isdk/devices/$(CHIP_FAMILY)/drivers \
|
2023-03-21 19:21:57 -04:00
|
|
|
-Isdk/drivers/common
|
2019-11-02 11:52:26 -04:00
|
|
|
|
|
|
|
# NDEBUG disables assert() statements. This reduces code size pretty dramatically, per tannewt.
|
|
|
|
|
2022-05-27 15:59:54 -04:00
|
|
|
CFLAGS += -ftree-vrp -DNDEBUG
|
2019-11-02 11:52:26 -04:00
|
|
|
|
|
|
|
# TinyUSB defines
|
2023-02-28 18:07:35 -05:00
|
|
|
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_MIMXRT10XX -DCFG_TUD_CDC_RX_BUFSIZE=512 -DCFG_TUD_CDC_TX_BUFSIZE=512
|
|
|
|
ifeq ($(CHIP_FAMILY), MIMXRT1011)
|
|
|
|
CFLAGS += -DCFG_TUD_MIDI_RX_BUFSIZE=64 -DCFG_TUD_MIDI_TX_BUFSIZE=64 -DCFG_TUD_MSC_BUFSIZE=512
|
|
|
|
else
|
|
|
|
CFLAGS += -DCFG_TUD_MIDI_RX_BUFSIZE=512 -DCFG_TUD_MIDI_TX_BUFSIZE=512 -DCFG_TUD_MSC_BUFSIZE=1024
|
|
|
|
endif
|
2019-11-02 11:52:26 -04:00
|
|
|
|
|
|
|
#Debugging/Optimization
|
2021-08-19 15:18:13 -04:00
|
|
|
# Never set -fno-inline because we use inline to move small functions into routines that must be
|
|
|
|
# in RAM. If inlining is disallowed, then we may end up calling a function in flash when we cannot.
|
2019-11-02 11:52:26 -04:00
|
|
|
ifeq ($(DEBUG), 1)
|
|
|
|
# You may want to enable these flags to make setting breakpoints easier.
|
2021-08-19 15:18:13 -04:00
|
|
|
CFLAGS += -fno-ipa-sra
|
2019-11-02 11:52:26 -04:00
|
|
|
endif
|
|
|
|
|
2021-11-12 20:30:24 -05:00
|
|
|
CFLAGS += $(INC) -ggdb -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) -Werror=missing-prototypes
|
2019-11-02 11:52:26 -04:00
|
|
|
|
2020-05-05 12:46:30 -04:00
|
|
|
# TODO: add these when -Werror is applied
|
2020-05-01 10:06:40 -04:00
|
|
|
# Disable some warnings, as do most ports. NXP SDK causes undef, tinyusb causes cast-align
|
2020-05-05 12:46:30 -04:00
|
|
|
# CFLAGS += -Wno-undef -Wno-cast-align
|
2020-05-01 10:06:40 -04:00
|
|
|
|
2019-11-02 11:52:26 -04:00
|
|
|
CFLAGS += \
|
|
|
|
-mthumb \
|
|
|
|
-mapcs \
|
|
|
|
-mcpu=cortex-m7 \
|
|
|
|
-mfloat-abi=hard \
|
|
|
|
-mfpu=fpv5-sp-d16 \
|
|
|
|
-DCPU_$(CHIP_VARIANT) \
|
2020-01-08 23:32:45 -05:00
|
|
|
-DIMXRT10XX \
|
2020-07-23 20:27:02 -04:00
|
|
|
-g3 -Wno-unused-parameter \
|
2020-01-18 14:54:01 -05:00
|
|
|
-ffunction-sections -fdata-sections -fstack-usage
|
2019-11-02 11:52:26 -04:00
|
|
|
|
2023-02-28 18:07:35 -05:00
|
|
|
OPTIMIZATION_FLAGS ?= -O2
|
2020-07-23 20:27:02 -04:00
|
|
|
|
2020-07-22 13:44:41 -04:00
|
|
|
# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk
|
2020-07-23 20:27:02 -04:00
|
|
|
CFLAGS += $(OPTIMIZATION_FLAGS)
|
2020-07-21 11:11:08 -04:00
|
|
|
|
2023-02-28 18:07:35 -05:00
|
|
|
ifeq ($(CIRCUITPY_SWO_TRACE), 1)
|
|
|
|
CFLAGS += -finstrument-functions -finstrument-functions-exclude-file-list=tinyusb -finstrument-functions-exclude-function-list='USB_OTG1_IRQHandler,usb_irq_handler,nlr_push,CLOCK_EnableClock,CLOCK_SetDiv,CLOCK_SetMux,__DMB,__ISB,__DSB,SCB_EnableICache,SCB_EnableDCache,ARM_MPU_Disable,ARM_MPU_Enable,SCB_DisableDCache,SCB_DisableICache,__enable_irq,__disable_irq,__set_MSP,port_get_raw_ticks,supervisor_ticks_ms64'
|
|
|
|
endif
|
|
|
|
|
2020-01-08 23:32:45 -05:00
|
|
|
LD_FILES = $(wildcard boards/$(BOARD)/*.ld) $(addprefix linking/, flash/$(FLASH).ld chip_family/$(CHIP_FAMILY).ld common.ld)
|
|
|
|
|
|
|
|
LD_SCRIPT_FLAG := -Wl,-T,
|
|
|
|
|
2020-05-28 18:43:55 -04:00
|
|
|
LDFLAGS = $(CFLAGS) -nostartfiles -Wl,-nostdlib $(addprefix $(LD_SCRIPT_FLAG), $(LD_FILES)) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
|
2019-11-02 11:52:26 -04:00
|
|
|
LIBS := -lgcc -lc -lnosys -lm
|
|
|
|
|
|
|
|
# Use toolchain libm if we're not using our own.
|
|
|
|
ifndef INTERNAL_LIBM
|
|
|
|
LIBS += -lm
|
|
|
|
endif
|
|
|
|
|
|
|
|
LDFLAGS += -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -mthumb -mapcs
|
|
|
|
BOOTLOADER_SIZE := 0x6000C000
|
|
|
|
|
|
|
|
SRC_SDK := \
|
2023-03-21 19:21:57 -04:00
|
|
|
devices/$(CHIP_FAMILY)/drivers/fsl_clock.c \
|
|
|
|
devices/$(CHIP_FAMILY)/system_$(CHIP_FAMILY).c \
|
|
|
|
devices/$(CHIP_FAMILY)/xip/fsl_flexspi_nor_boot.c \
|
|
|
|
drivers/adc_12b1msps_sar/fsl_adc.c \
|
|
|
|
drivers/cache/armv7-m7/fsl_cache.c \
|
|
|
|
drivers/common/fsl_common_arm.c \
|
|
|
|
drivers/common/fsl_common.c \
|
|
|
|
drivers/flexspi/fsl_flexspi.c \
|
|
|
|
drivers/igpio/fsl_gpio.c \
|
|
|
|
drivers/lpi2c/fsl_lpi2c.c \
|
|
|
|
drivers/lpspi/fsl_lpspi.c \
|
|
|
|
drivers/lpuart/fsl_lpuart.c \
|
|
|
|
drivers/ocotp/fsl_ocotp.c \
|
|
|
|
drivers/pwm/fsl_pwm.c \
|
mimxrt10xx: implement i2sout
tested on metro m7 (green prototype version) with max98357a i2s amplifier and the following test code:
```py
import board
import time
import digitalio
from audiobusio import I2SOut
from audiocore import RawSample
from microcontroller import pin
from ulab import numpy as np
n = np.array(np.sin(np.linspace(0, np.pi*2, 218, endpoint=False)) * 200, dtype=np.int16)
print(n)
r = RawSample(n, sample_rate=8000, channel_count=2)
def main():
with digitalio.DigitalInOut(board.LED) as l:
l.switch_to_output(True)
value = False
while True:
with I2SOut(pin.GPIO_06, pin.GPIO_07, pin.GPIO_04) as i:
time.sleep(.01)
l.value = value = not value
i.play(r, loop=True)
print(i.playing)
time.sleep(.5)
i.stop()
print("STOPPED")
print(i.playing)
time.sleep(.5)
i.play(r, loop=True)
print(i.playing)
print("PLAY AGAIN")
time.sleep(.5)
time.sleep(1)
```
Only stereo, 16-bit, raw samples were tested; the sample rate is actually fixed
at 48kHz in the core right now. There is more to do, but the basics work.
# Conflicts:
# ports/mimxrt10xx/Makefile
# ports/mimxrt10xx/mpconfigport.mk
2023-03-22 13:14:00 -04:00
|
|
|
drivers/sai/fsl_sai.c \
|
2023-03-21 19:21:57 -04:00
|
|
|
drivers/snvs_hp/fsl_snvs_hp.c \
|
|
|
|
drivers/snvs_lp/fsl_snvs_lp.c \
|
|
|
|
drivers/tempmon/fsl_tempmon.c \
|
|
|
|
drivers/trng/fsl_trng.c \
|
|
|
|
|
|
|
|
SRC_SDK := $(addprefix sdk/, $(SRC_SDK))
|
2019-11-02 11:52:26 -04:00
|
|
|
|
2020-10-15 15:24:24 -04:00
|
|
|
SRC_C += \
|
2019-11-02 11:52:26 -04:00
|
|
|
background.c \
|
|
|
|
boards/$(BOARD)/board.c \
|
2020-01-08 23:32:45 -05:00
|
|
|
boards/$(BOARD)/flash_config.c \
|
2019-11-02 11:52:26 -04:00
|
|
|
boards/$(BOARD)/pins.c \
|
2022-01-06 13:24:02 -05:00
|
|
|
lib/tinyusb/src/portable/chipidea/ci_hs/dcd_ci_hs.c \
|
2019-11-02 11:52:26 -04:00
|
|
|
mphalport.c \
|
|
|
|
peripherals/mimxrt10xx/$(CHIP_FAMILY)/clocks.c \
|
|
|
|
peripherals/mimxrt10xx/$(CHIP_FAMILY)/periph.c \
|
|
|
|
peripherals/mimxrt10xx/$(CHIP_FAMILY)/pins.c \
|
2023-03-23 10:28:14 -04:00
|
|
|
peripherals/mimxrt10xx/pins.c \
|
2019-11-02 11:52:26 -04:00
|
|
|
reset.c \
|
2021-04-22 20:55:39 -04:00
|
|
|
supervisor/flexspi_nor_flash_ops.c
|
2020-03-24 18:46:10 -04:00
|
|
|
|
2022-02-18 20:57:54 -05:00
|
|
|
ifeq ($(CIRCUITPY_USB_HOST), 1)
|
|
|
|
SRC_C += \
|
|
|
|
lib/tinyusb/src/portable/chipidea/ci_hs/hcd_ci_hs.c \
|
|
|
|
lib/tinyusb/src/portable/ehci/ehci.c \
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
2019-11-02 11:52:26 -04:00
|
|
|
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
|
|
|
|
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
|
|
|
|
$(addprefix common-hal/, $(SRC_COMMON_HAL))
|
|
|
|
|
|
|
|
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
|
|
|
|
$(addprefix shared-module/, $(SRC_SHARED_MODULE)) \
|
|
|
|
$(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL))
|
|
|
|
|
|
|
|
SRC_S = \
|
|
|
|
sdk/devices/$(CHIP_FAMILY)/gcc/startup_$(CHIP_FAMILY).S \
|
|
|
|
supervisor/cpu.S
|
|
|
|
|
|
|
|
OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_SDK:.c=.o))
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
|
|
|
|
ifeq ($(INTERNAL_LIBM),1)
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
|
|
|
|
endif
|
2021-04-22 20:55:39 -04:00
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o))
|
2019-11-02 11:52:26 -04:00
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.S=.o))
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
|
|
|
|
|
|
|
|
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
|
|
|
|
|
2020-02-12 04:03:11 -05:00
|
|
|
all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2 $(BUILD)/firmware.hex
|
2019-11-02 11:52:26 -04:00
|
|
|
|
2020-01-08 23:32:45 -05:00
|
|
|
$(BUILD)/firmware.elf: $(OBJ) $(LD_FILES)
|
2019-11-02 11:52:26 -04:00
|
|
|
$(STEPECHO) "LINK $@"
|
2023-02-28 18:07:35 -05:00
|
|
|
$(Q)$(CC) -o $@ $(LDFLAGS) $(filter-out %.ld, $^) -Wl,--print-memory-usage -Wl,--start-group $(LIBS) -Wl,--end-group
|
2019-11-02 11:52:26 -04:00
|
|
|
|
2023-03-17 11:49:47 -04:00
|
|
|
# -R excludes sections from the output files.
|
2019-11-02 11:52:26 -04:00
|
|
|
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
|
|
|
|
$(STEPECHO) "Create $@"
|
2023-03-17 11:49:47 -04:00
|
|
|
$(Q)$(OBJCOPY) -O binary -R .stack -R .dtcm_bss $^ $@
|
2019-11-02 11:52:26 -04:00
|
|
|
|
2020-02-12 04:03:11 -05:00
|
|
|
$(BUILD)/firmware.uf2: $(BUILD)/firmware.elf
|
2019-11-02 11:52:26 -04:00
|
|
|
$(STEPECHO) "Create $@"
|
2023-03-17 11:49:47 -04:00
|
|
|
$(Q)$(OBJCOPY) -O binary -R .stack -R .dtcm_bss -R .ivt -R .flash_config $^ $@-binpart
|
2021-10-15 15:59:04 -04:00
|
|
|
$(Q)$(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -b $(BOOTLOADER_SIZE) -f MIMXRT10XX -c -o $@ $@-binpart
|
2023-03-21 19:21:57 -04:00
|
|
|
$(Q)rm $@-binpart
|
2019-11-02 11:52:26 -04:00
|
|
|
|
2020-01-08 23:32:45 -05:00
|
|
|
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
|
2023-03-17 11:49:47 -04:00
|
|
|
$(Q)$(OBJCOPY) -O ihex -R .stack -R .dtcm_bss $< $@
|
2020-01-08 23:32:45 -05:00
|
|
|
|
2019-11-02 11:52:26 -04:00
|
|
|
include $(TOP)/py/mkrules.mk
|
|
|
|
|
|
|
|
# Print out the value of a make variable.
|
|
|
|
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
|
|
|
|
print-%:
|
|
|
|
@echo $* = $($*)
|
2022-02-18 20:57:54 -05:00
|
|
|
|
|
|
|
ifeq ($(CHIP_FAMILY), MIMXRT1062)
|
|
|
|
PYOCD_TARGET = mimxrt1060
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Flash using pyocd
|
|
|
|
PYOCD_OPTION ?=
|
|
|
|
flash: $(BUILD)/firmware.hex
|
|
|
|
pyocd flash -t $(PYOCD_TARGET) $(PYOCD_OPTION) $<
|
|
|
|
pyocd reset -t $(PYOCD_TARGET)
|