Skip to content

Commit 817c4af

Browse files
authored
Merge pull request adafruit#2456 from arturo182/mimxrt10xx
Add initial MIMXRT10XX port implementation
2 parents 866ac13 + cc7b57c commit 817c4af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+8187
-3
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,16 @@ jobs:
102102
- "feather_m0_rfm9x"
103103
- "feather_m0_supersized"
104104
- "feather_m4_express"
105+
- "feather_mimxrt1011"
106+
- "feather_mimxrt1062"
105107
- "feather_nrf52840_express"
106108
- "feather_radiofruit_zigbee"
107109
- "feather_stm32f405_express"
108110
- "gemma_m0"
109111
- "grandcentral_m4_express"
110112
- "hallowing_m0_express"
111113
- "hallowing_m4_express"
114+
- "imxrt1010_evk"
112115
- "itsybitsy_m0_express"
113116
- "itsybitsy_m4_express"
114117
- "itsybitsy_nrf52840_express"

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,6 @@
108108
[submodule "lib/mp3"]
109109
path = lib/mp3
110110
url = https://github.com/adafruit/Adafruit_MP3
111+
[submodule "ports/mimxrt10xx/sdk"]
112+
path = ports/mimxrt10xx/sdk
113+
url = https://github.com/arturo182/MIMXRT10xx_SDK

conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@
131131
"ports/esp8266/common-hal",
132132
"ports/esp8266/modules",
133133
"ports/minimal",
134+
"ports/mimxrt10xx/peripherals",
135+
"ports/mimxrt10xx/sdk",
134136
"ports/nrf/device",
135137
"ports/nrf/bluetooth",
136138
"ports/nrf/modules",

docs/shared_bindings_matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import re
2727

2828

29-
SUPPORTED_PORTS = ["atmel-samd", "nrf"]
29+
SUPPORTED_PORTS = ["atmel-samd", "nrf", "mimxrt10xx"]
3030

3131

3232
def parse_port_config(contents, chip_keyword=None):

docs/supported_ports.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and ESP8266.
88
:maxdepth: 2
99

1010
../ports/atmel-samd/README
11+
../ports/mimxrt10xx/README
1112
../ports/nrf/README
1213
../ports/stm32f4/README
1314
../ports/cxd56/README

ports/mimxrt10xx/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build-*/

ports/mimxrt10xx/Makefile

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
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 $* = $($*)

ports/mimxrt10xx/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# CircuitPython Port To The NXP i.MX RT10xx Series
2+
3+
This is a port of CircuitPython to the i.MX RT10xx series of chips.

ports/mimxrt10xx/background.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
7+
* Copyright (c) 2019 Artur Pacholec
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
#include "background.h"
28+
29+
//#include "audio_dma.h"
30+
#include "tick.h"
31+
#include "supervisor/filesystem.h"
32+
#include "supervisor/shared/tick.h"
33+
#include "supervisor/usb.h"
34+
35+
#include "py/runtime.h"
36+
#include "shared-module/network/__init__.h"
37+
#include "supervisor/shared/stack.h"
38+
39+
// TODO
40+
#ifdef CIRCUITPY_DISPLAYIO
41+
//#include "shared-module/displayio/__init__.h"
42+
#endif
43+
44+
volatile uint64_t last_finished_tick = 0;
45+
46+
bool stack_ok_so_far = true;
47+
48+
static bool running_background_tasks = false;
49+
50+
void background_tasks_reset(void) {
51+
running_background_tasks = false;
52+
}
53+
54+
void run_background_tasks(void) {
55+
// Don't call ourselves recursively.
56+
if (running_background_tasks) {
57+
return;
58+
}
59+
assert_heap_ok();
60+
running_background_tasks = true;
61+
62+
#if CIRCUITPY_AUDIOIO || CIRCUITPY_AUDIOBUSIO
63+
audio_dma_background();
64+
#endif
65+
#if CIRCUITPY_DISPLAYIO
66+
displayio_background();
67+
#endif
68+
69+
#if CIRCUITPY_NETWORK
70+
network_module_background();
71+
#endif
72+
filesystem_background();
73+
usb_background();
74+
running_background_tasks = false;
75+
assert_heap_ok();
76+
77+
last_finished_tick = supervisor_ticks_ms64();
78+
}
79+
80+
bool background_tasks_ok(void) {
81+
return supervisor_ticks_ms64() - last_finished_tick < 1000;
82+
}

0 commit comments

Comments
 (0)