Skip to content

Commit ccc5935

Browse files
committed
alif: Add initial port to Alif Ensemble MCUs.
This commit adds the beginning of a new alif port with support for Alif Ensemble MCUs. See https://alifsemi.com/ Supported features of this port added by this commit: - UART REPL. - TinyUSB support, for REPL and MSC. - Octal SPI flash support, for filesystem. - machine.Pin support. General notes about the port: - It uses make, similar to other bare-metal ports here. - The toolchain is the standard arm-none-eabi- toolchain. - Flashing a board can be done using either the built-in serial bootloader, or JLink (both supported here). - There are two required submodules (one for drivers/SDK, one for security tools), both of which are open source and on GitHub. - No special hardware or software is needed for development, just a board connected over USB. OpenMV have generously sponsored the development of this port. Signed-off-by: Damien George <damien@micropython.org> Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent b8a9cdf commit ccc5935

31 files changed

Lines changed: 2740 additions & 0 deletions

ports/alif/Makefile

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
################################################################################
2+
# Initial setup of Makefile environment
3+
4+
BOARD ?= ALIF_ENSEMBLE
5+
BOARD_DIR ?= boards/$(BOARD)
6+
BUILD ?= build-$(BOARD)
7+
8+
ifeq ($(wildcard $(BOARD_DIR)/.),)
9+
$(error Invalid BOARD specified: $(BOARD_DIR))
10+
endif
11+
12+
include ../../py/mkenv.mk
13+
include mpconfigport.mk
14+
include $(BOARD_DIR)/mpconfigboard.mk
15+
16+
# qstr definitions (must come before including py.mk)
17+
QSTR_DEFS += qstrdefsport.h
18+
19+
# include py core make definitions
20+
include $(TOP)/py/py.mk
21+
include $(TOP)/extmod/extmod.mk
22+
23+
################################################################################
24+
# Project specific settings and compiler/linker flags
25+
26+
CROSS_COMPILE ?= arm-none-eabi-
27+
GIT_SUBMODULES += lib/tinyusb lib/alif_ensemble-cmsis-dfp lib/alif-security-toolkit
28+
PORT ?= /dev/ttyACM0
29+
30+
ALIF_TOOLS ?= ../../lib/alif-security-toolkit/toolkit
31+
ALIF_DFP_REL_TOP ?= lib/alif_ensemble-cmsis-dfp
32+
ALIF_DFP_REL_HERE ?= $(TOP)/lib/alif_ensemble-cmsis-dfp
33+
CMSIS_DIR ?= $(TOP)/lib/cmsis/inc
34+
35+
MCU_CORE ?= M55_HP
36+
ALIF_CONFIG ?= mcu/$(MCU_CORE)_cfg.json
37+
LD_FILE ?= mcu/ensemble.ld.S
38+
39+
INC += -I.
40+
INC += -I$(TOP)
41+
INC += -I$(BUILD)
42+
INC += -I$(BOARD_DIR)
43+
INC += -I$(CMSIS_DIR)
44+
INC += -I$(ALIF_DFP_REL_HERE)/drivers/include/
45+
INC += -I$(ALIF_DFP_REL_HERE)/ospi_xip/source/ospi
46+
INC += -I$(ALIF_DFP_REL_HERE)/Device/common/config/
47+
INC += -I$(ALIF_DFP_REL_HERE)/Device/common/include/
48+
INC += -I$(ALIF_DFP_REL_HERE)/Device/core/$(MCU_CORE)/config/
49+
INC += -I$(ALIF_DFP_REL_HERE)/Device/core/$(MCU_CORE)/include/
50+
INC += -I$(ALIF_DFP_REL_HERE)/Device/$(MCU_SERIES)/$(MCU_VARIANT)/
51+
INC += -I$(TOP)/lib/tinyusb/src
52+
INC += -Itinyusb_port
53+
54+
GEN_PIN_MKPINS = mcu/make-pins.py
55+
GEN_PIN_PREFIX = mcu/pins_prefix.c
56+
GEN_PINS_BOARD_CSV = $(BOARD_DIR)/pins.csv
57+
GEN_PINS_SRC = $(BUILD)/pins_board.c
58+
GEN_PINS_HDR = $(HEADER_BUILD)/pins_board.h
59+
60+
CFLAGS_FPU += -mfloat-abi=hard -mfpu=fpv5-d16
61+
CFLAGS_CORTEX_M55 += -mthumb -mcpu=cortex-m55 -mtune=cortex-m55 $(CFLAGS_FPU)
62+
63+
CFLAGS += $(INC) -Wall -Werror -std=c99 $(CFLAGS_CORTEX_M55) -nostdlib
64+
CFLAGS += -Wdouble-promotion -Wfloat-conversion
65+
CFLAGS += -fdata-sections -ffunction-sections
66+
CFLAGS += -D$(MCU_CORE) -DCORE_$(MCU_CORE) -DALIF_CMSIS_H="\"$(MCU_CORE).h\""
67+
68+
ifeq ($(MICROPY_FLOAT_IMPL),float)
69+
CFLAGS += -fsingle-precision-constant
70+
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_FLOAT
71+
else
72+
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_DOUBLE
73+
endif
74+
75+
AFLAGS = -mthumb -march=armv8.1-m.main $(CFLAGS_FPU)
76+
77+
LDFLAGS += -nostdlib
78+
LDFLAGS += -T$(BUILD)/ensemble.ld -Map=$@.map --cref --gc-sections
79+
LDFLAGS += --wrap=dcd_event_handler
80+
81+
# Tune for Debugging or Optimization
82+
ifeq ($(DEBUG), 1)
83+
CFLAGS += -Og -ggdb3
84+
# Disable text compression in debug builds
85+
MICROPY_ROM_TEXT_COMPRESSION = 0
86+
else
87+
CFLAGS += -O2 -DNDEBUG
88+
endif
89+
90+
LIBS += "$(shell $(CC) $(CFLAGS) -print-libgcc-file-name)"
91+
92+
JLINK_CMD = '\
93+
ExitOnError 1\n\
94+
Device $(JLINK_DEV)\n\
95+
SelectInterface SWD\n\
96+
Speed auto\n\
97+
Connect\n\
98+
Reset\n\
99+
ShowHWStatus\n\
100+
LoadFile "$(BUILD)/firmware_toc.bin",0x8057f1c0\n\
101+
LoadFile "$(BUILD)/firmware.bin",0x80000000\n\
102+
Reset\n\
103+
Exit'
104+
105+
################################################################################
106+
# Source files and libraries
107+
108+
SRC_O += \
109+
shared/runtime/gchelper_thumb2.o
110+
111+
SRC_C = \
112+
alif_flash.c \
113+
fatfs_port.c \
114+
machine_pin.c \
115+
main.c \
116+
modalif.c \
117+
mphalport.c \
118+
mpuart.c \
119+
msc_disk.c \
120+
ospi_flash.c \
121+
pendsv.c \
122+
usbd.c \
123+
$(wildcard $(BOARD_DIR)/*.c)
124+
125+
ifeq ($(MICROPY_FLOAT_IMPL),float)
126+
LIBM_SRC_C += $(SRC_LIB_LIBM_C)
127+
LIBM_SRC_C += $(SRC_LIB_LIBM_SQRT_HW_C)
128+
$(BUILD)/lib/libm/%.o: CFLAGS += -Wno-maybe-uninitialized
129+
else
130+
LIBM_SRC_C += $(SRC_LIB_LIBM_DBL_C)
131+
LIBM_SRC_C += $(SRC_LIB_LIBM_DBL_SQRT_HW_C)
132+
$(BUILD)/lib/libm_dbl/%.o: CFLAGS += -Wno-maybe-uninitialized
133+
endif
134+
135+
SHARED_SRC_C += $(addprefix shared/,\
136+
libc/string0.c \
137+
netutils/dhcpserver.c \
138+
netutils/netutils.c \
139+
netutils/trace.c \
140+
readline/readline.c \
141+
runtime/gchelper_native.c \
142+
runtime/interrupt_char.c \
143+
runtime/mpirq.c \
144+
runtime/pyexec.c \
145+
runtime/softtimer.c \
146+
runtime/stdout_helpers.c \
147+
runtime/sys_stdio_mphal.c \
148+
timeutils/timeutils.c \
149+
tinyusb/mp_usbd.c \
150+
tinyusb/mp_usbd_cdc.c \
151+
tinyusb/mp_usbd_descriptor.c \
152+
)
153+
154+
DRIVERS_SRC_C += $(addprefix drivers/,\
155+
bus/softspi.c \
156+
bus/softqspi.c \
157+
memory/spiflash.c \
158+
dht/dht.c \
159+
)
160+
161+
TINYUSB_SRC_C += \
162+
lib/tinyusb/src/tusb.c \
163+
lib/tinyusb/src/class/cdc/cdc_device.c \
164+
lib/tinyusb/src/class/msc/msc_device.c \
165+
lib/tinyusb/src/common/tusb_fifo.c \
166+
lib/tinyusb/src/device/usbd.c \
167+
lib/tinyusb/src/device/usbd_control.c \
168+
tinyusb_port/tusb_alif_dcd.c \
169+
170+
ALIF_SRC_C += $(addprefix $(ALIF_DFP_REL_TOP)/,\
171+
Device/common/source/clk.c \
172+
Device/common/source/mpu_M55.c \
173+
Device/common/source/system_M55.c \
174+
Device/common/source/system_utils.c \
175+
Device/core/$(MCU_CORE)/source/startup_$(MCU_CORE).c \
176+
drivers/source/pinconf.c \
177+
drivers/source/uart.c \
178+
ospi_xip/source/ospi/ospi_drv.c \
179+
)
180+
181+
$(BUILD)/tinyusb_port/tusb_alif_dcd.o: CFLAGS += -Wno-unused-variable -DTUSB_ALIF_NO_IRQ_CFG=1
182+
183+
# List of sources for qstr extraction
184+
SRC_QSTR += $(SRC_C) $(SHARED_SRC_C) $(GEN_PINS_SRC)
185+
186+
OBJ += $(PY_O)
187+
OBJ += $(addprefix $(BUILD)/, $(SRC_O))
188+
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
189+
OBJ += $(addprefix $(BUILD)/, $(LIBM_SRC_C:.c=.o))
190+
OBJ += $(addprefix $(BUILD)/, $(SHARED_SRC_C:.c=.o))
191+
OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o))
192+
OBJ += $(addprefix $(BUILD)/, $(TINYUSB_SRC_C:.c=.o))
193+
OBJ += $(addprefix $(BUILD)/, $(ALIF_SRC_C:.c=.o))
194+
OBJ += $(GEN_PINS_SRC:.c=.o)
195+
196+
################################################################################
197+
# Main targets
198+
199+
.DELETE_ON_ERROR:
200+
201+
.PHONY: all
202+
all: $(BUILD)/firmware_toc.bin
203+
204+
$(BUILD)/ensemble.ld: $(LD_FILE)
205+
$(ECHO) "Preprocess linker script $@"
206+
$(Q)$(CPP) -P -E $(CFLAGS) $^ > $@
207+
208+
$(BUILD)/firmware.elf: $(OBJ) $(BUILD)/ensemble.ld
209+
$(ECHO) "Link $@"
210+
$(Q)$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
211+
$(Q)$(SIZE) $@
212+
213+
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
214+
$(Q)$(OBJCOPY) -Obinary $^ $(BUILD)/firmware.bin
215+
216+
$(BUILD)/firmware_toc.bin: $(BUILD)/firmware.bin
217+
$(Q)python $(ALIF_TOOLS)/app-gen-toc.py \
218+
--filename $(abspath $(BUILD)/$(ALIF_TOC_CONFIG)) \
219+
--output-dir $(BUILD) \
220+
--firmware-dir $(BUILD) \
221+
--output $@
222+
223+
.PHONY: deploy
224+
deploy: $(BUILD)/firmware_toc.bin
225+
$(ECHO) "Writing $< to the board"
226+
$(Q)python $(ALIF_TOOLS)/app-write-mram.py \
227+
--cfg-part $(ALIF_TOOLKIT_CFG_PART) \
228+
--port $(PORT) \
229+
--pad \
230+
--images file:$(BUILD)/application_package.ds
231+
232+
.PHONY: deploy-jlink
233+
deploy-jlink: $(BUILD)/firmware_toc.bin
234+
$(Q)echo -e $(JLINK_CMD) | $(JLINK_EXE)
235+
236+
.PHONY: maintenance
237+
maintenance:
238+
$(Q)python $(ALIF_TOOLS)/maintenance.py \
239+
--cfg-part $(ALIF_TOOLKIT_CFG_PART) \
240+
--port $(PORT)
241+
242+
.PHONY: update-system-package
243+
update-system-package:
244+
$(Q)python $(ALIF_TOOLS)/updateSystemPackage.py \
245+
--cfg-part $(ALIF_TOOLKIT_CFG_PART) \
246+
--port $(PORT)
247+
248+
################################################################################
249+
# Remaining make rules
250+
251+
# Use a pattern rule here so that make will only call make-pins.py once to make
252+
# both pins_board.c and pins_board.h
253+
$(BUILD)/%_board.c $(HEADER_BUILD)/%_board.h: $(BOARD_DIR)/%.csv $(GEN_PIN_MKPINS) $(GEN_PIN_PREFIX) | $(HEADER_BUILD)
254+
$(ECHO) "GEN $@"
255+
$(Q)$(PYTHON) $(GEN_PIN_MKPINS) \
256+
--board-csv $(GEN_PINS_BOARD_CSV) \
257+
--prefix $(GEN_PIN_PREFIX) \
258+
--output-source $(GEN_PINS_SRC) \
259+
--output-header $(GEN_PINS_HDR)
260+
261+
include $(TOP)/py/mkrules.mk

ports/alif/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MicroPython port to Alif Ensemble MCUs
2+
======================================
3+
4+
This is a port of MicroPython to the Alif Ensemble series of microcontrollers.
5+
6+
Initial development of this Alif port was sponsored by OpenMV LLC.
7+
8+
Features currently supported:
9+
- UART REPL.
10+
- TinyUSB with CDC and MSC device support.
11+
- Octal SPI flash with XIP mode.
12+
- machine.Pin support with named pins.
13+
- machine.UART, machine.SPI, machine.I2C, machine.RTC peripherals.
14+
- WiFi and Bluetooth using cyw43.
15+
- Dual core support of the HE and HP cores using Open-AMP.
16+
- Low power modes.
17+
18+
The following more advanced features will follow later:
19+
- Ethernet support.
20+
- SDRAM support.
21+
- Other machine modules.

0 commit comments

Comments
 (0)