Skip to content

Commit e574f68

Browse files
robert-hhdpgeorge
authored andcommitted
mimxrt: Add support for a UF2 bootloader.
Allowing to use e.g. the Adafruit bootloaders with MicroPython. The .uf2 file is created in addition to the .bin and .hex files allowing to use the latter ones without the bootloader for debugging and testing. Changes: - Set the location of the ISR Vector and .text segment to 0x6000C000 and 0x6000C400. - Reserve an area at the start of ITCM for a copy of the interrupt vector table and copy the table on reset to this place. - Extend `machine.bootloader()` by setting the magic number to enable the bootloader on reset. - Create a .uf2 file which skips the segments below 0x6000C000. The bootloader has to be installed as a preparation step using the board specific methods, but then the firmware's .uf2 file version can be installed using the bootloader. The bootloader can be invoked with: - double reset - calling machine.bootloader() - Using the touch1200 method Double reset is hard to achieve on MIMXRT boards, since there is no clean reset pin. Some MIMXRT boards provide it by switching the power. Some boards are excluded from the .uf2 build: - MIMXRT1050_EVK: The uf2 bootloader is built for the QSPI version of the board. MicroPython supports the Hyperflash version. - MIMXRT1176_EVK: No support for this board yet, but it should be possible. Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent b2ce9b6 commit e574f68

File tree

22 files changed

+87
-20
lines changed

22 files changed

+87
-20
lines changed

ports/mimxrt/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ BUILD ?= build-$(BOARD)
2121
PORT ?= /dev/ttyACM0
2222
CROSS_COMPILE ?= arm-none-eabi-
2323
GIT_SUBMODULES += lib/tinyusb lib/nxp_driver
24+
UF2CONV ?= $(TOP)/tools/uf2conv.py
2425

2526
# MicroPython feature configurations
2627
MICROPY_VFS_LFS2 ?= 1
@@ -162,6 +163,13 @@ SRC_HAL_IMX_C += \
162163
$(MCU_DIR)/drivers/fsl_romapi.c
163164
endif
164165

166+
# If not empty, then it is 10xx.
167+
ifneq ($(findstring MIMXRT10, $(MCU_SERIES)),)
168+
APPLICATION_ADDR := 0x6000C000
169+
else
170+
APPLICATION_ADDR := 0x3000C000
171+
endif
172+
165173
ifeq ($(MCU_SERIES), MIMXRT1176)
166174
INC += -I$(TOP)/$(MCU_DIR)/drivers/cm7
167175

@@ -253,6 +261,11 @@ else
253261
$(error Error: Unknown board flash type $(MICROPY_HW_FLASH_TYPE))
254262
endif
255263

264+
# Set a flag if the UF2 bootloader is used
265+
ifeq ($(USE_UF2_BOOTLOADER),1)
266+
CFLAGS += -DMICROPY_MACHINE_UF2_BOOTLOADER=1
267+
endif
268+
256269
# Add sources for respective board flash type
257270
# Add hal/flexspi_nor_flash.c or hal/flashspi_hyper_flash.c respectively
258271
SRC_HAL_C += hal/flexspi_$(subst qspi_,,$(FLEXSPI_FLASH_TYPE)).c
@@ -470,7 +483,11 @@ $(BUILD)/lib/tinyusb/src/device/usbd.o: CFLAGS += -Wno-missing-braces
470483
# Build targets
471484
# =============================================================================
472485

486+
ifeq ($(USE_UF2_BOOTLOADER),1)
487+
all: $(BUILD)/firmware.hex $(BUILD)/firmware.bin $(BUILD)/firmware.uf2
488+
else
473489
all: $(BUILD)/firmware.hex $(BUILD)/firmware.bin
490+
endif
474491

475492
# Process linker scripts with C preprocessor to exchange LDDEFINES and
476493
# aggregate output of preprocessor in a single linker script `link.ld`
@@ -487,6 +504,10 @@ $(BUILD)/firmware.bin: $(BUILD)/firmware.elf
487504
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
488505
$(Q)$(OBJCOPY) -O ihex -R .eeprom $< $@
489506

507+
$(BUILD)/firmware.uf2: $(BUILD)/firmware.elf
508+
$(Q)$(OBJCOPY) -O binary -R .stack -R .ivt -R .flash_config $^ $@-binpart
509+
$(Q)$(PYTHON) $(UF2CONV) -b $(APPLICATION_ADDR) -f MIMXRT10XX -c -o $@ $@-binpart
510+
490511
# Making OBJ use an order-only dependency on the generated pins.h file
491512
# has the side effect of making the pins.h file before we actually compile
492513
# any of the objects. The normal dependency generation will deal with the

ports/mimxrt/boards/ADAFRUIT_METRO_M7/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ MICROPY_HW_FLASH_SIZE ?= 0x800000 # 8MB
88
MICROPY_PY_NETWORK_NINAW10 ?= 1
99
MICROPY_PY_SSL ?= 1
1010
MICROPY_SSL_MBEDTLS ?= 1
11+
12+
USE_UF2_BOOTLOADER = 1

ports/mimxrt/boards/MIMXRT1010_EVK/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ MICROPY_FLOAT_IMPL = single
55
MICROPY_HW_FLASH_TYPE = qspi_nor_flash
66
MICROPY_HW_FLASH_SIZE = 0x1000000 # 16MB
77

8+
USE_UF2_BOOTLOADER = 1
9+
810
JLINK_PATH ?= /media/RT1010-EVK/
911
JLINK_COMMANDER_SCRIPT = $(BUILD)/script.jlink
1012

ports/mimxrt/boards/MIMXRT1011.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ flash_config_start = flash_start + 0x00000400;
1414
flash_config_size = 0x00000C00;
1515
ivt_start = flash_start + 0x00001000;
1616
ivt_size = 0x00001000;
17-
interrupts_start = flash_start + 0x00002000;
17+
interrupts_start = flash_start + 0x0000C000;
1818
interrupts_size = 0x00000400;
19-
text_start = flash_start + 0x00002400;
19+
text_start = flash_start + 0x0000C400;
2020
vfs_start = flash_start + 0x00100000;
2121
text_size = ((vfs_start) - (text_start));
2222
vfs_size = ((flash_end) - (vfs_start));

ports/mimxrt/boards/MIMXRT1015.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ flash_config_start = flash_start;
1414
flash_config_size = 0x00001000;
1515
ivt_start = flash_start + 0x00001000;
1616
ivt_size = 0x00001000;
17-
interrupts_start = flash_start + 0x00002000;
17+
interrupts_start = flash_start + 0x0000C000;
1818
interrupts_size = 0x00000400;
19-
text_start = flash_start + 0x00002400;
19+
text_start = flash_start + 0x0000C400;
2020
vfs_start = flash_start + 0x00100000;
2121
text_size = ((vfs_start) - (text_start));
2222
vfs_size = ((flash_end) - (vfs_start));

ports/mimxrt/boards/MIMXRT1015_EVK/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ MICROPY_HW_FLASH_TYPE = qspi_nor_flash
66
MICROPY_HW_FLASH_SIZE = 0x1000000 # 16MB
77

88
MICROPY_BOOT_BUFFER_SIZE = (32 * 1024)
9+
10+
USE_UF2_BOOTLOADER = 1

ports/mimxrt/boards/MIMXRT1020_EVK/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ MICROPY_PY_LWIP = 1
1212
MICROPY_PY_SSL = 1
1313
MICROPY_SSL_MBEDTLS = 1
1414

15+
USE_UF2_BOOTLOADER = 1
16+
1517
FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py
1618

1719
JLINK_PATH ?= /media/RT1020-EVK/

ports/mimxrt/boards/MIMXRT1021.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ flash_config_start = flash_start;
1414
flash_config_size = 0x00001000;
1515
ivt_start = flash_start + 0x00001000;
1616
ivt_size = 0x00001000;
17-
interrupts_start = flash_start + 0x00002000;
17+
interrupts_start = flash_start + 0x0000C000;
1818
interrupts_size = 0x00000400;
19-
text_start = flash_start + 0x00002400;
19+
text_start = flash_start + 0x0000C400;
2020
vfs_start = flash_start + 0x00100000;
2121
text_size = ((vfs_start) - (text_start));
2222
vfs_size = ((flash_end) - (vfs_start));

ports/mimxrt/boards/MIMXRT1052.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ flash_config_start = flash_start;
1616
flash_config_size = 0x00001000;
1717
ivt_start = flash_start + 0x00001000;
1818
ivt_size = 0x00001000;
19-
interrupts_start = flash_start + 0x00002000;
19+
interrupts_start = flash_start + 0x0000C000;
2020
interrupts_size = 0x00000400;
21-
text_start = flash_start + 0x00002400;
21+
text_start = flash_start + 0x0000C400;
2222
vfs_start = flash_start + 0x00200000;
2323
text_size = ((vfs_start) - (text_start));
2424
vfs_size = ((flash_end) - (vfs_start));

ports/mimxrt/boards/MIMXRT1060_EVK/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ MICROPY_PY_LWIP = 1
1212
MICROPY_PY_SSL = 1
1313
MICROPY_SSL_MBEDTLS = 1
1414

15+
USE_UF2_BOOTLOADER = 1
16+
1517
FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py
1618

1719
JLINK_PATH ?= /media/RT1060-EVK/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy