Skip to content

Commit 0374e99

Browse files
U-ANALOG\BHurstBrandon-Hurst
U-ANALOG\BHurst
authored andcommitted
Initial commit for ADI MAX32690 support. Still many modules to implement/unstub, but builds clean.
1 parent 72f6deb commit 0374e99

33 files changed

+2278
-0
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,6 @@
407407
[submodule "frozen/Adafruit_CircuitPython_Wiznet5k"]
408408
path = frozen/Adafruit_CircuitPython_Wiznet5k
409409
url = https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k
410+
[submodule "ports/analog/msdk"]
411+
path = ports/analog/msdk
412+
url = https://github.com/analogdevicesinc/msdk.git

ports/analog/Makefile

+261
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
# This file is part of the CircuitPython project: https://circuitpython.org
2+
#
3+
# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
4+
#
5+
# SPDX-License-Identifier: MIT
6+
7+
# Includes mpconfigboard.mk & mpconfigport.mk,
8+
# along with numerous other shared environment makefiles.
9+
include ../../py/circuitpy_mkenv.mk
10+
11+
CROSS_COMPILE = arm-none-eabi-
12+
13+
# MCU_SERIES e.g. "max32"
14+
# MCU_VARIANT e.g. "max32690"
15+
# defined in mpconfigboard.mk
16+
MCU_SERIES_LOWER := $(shell echo $(MCU_SERIES) | tr '[:upper:]' '[:lower:]')
17+
MCU_SERIES_UPPER := $(shell echo $(MCU_SERIES) | tr '[:lower:]' '[:upper:]')
18+
MCU_VARIANT_LOWER := $(shell echo $(MCU_VARIANT) | tr '[:upper:]' '[:lower:]')
19+
MCU_VARIANT_UPPER := $(shell echo $(MCU_VARIANT) | tr '[:lower:]' '[:upper:]')
20+
21+
# *******************************************************************************
22+
#### MSDK INCLUDES ####
23+
# Necessary for msdk makefiles
24+
TARGET := $(MCU_VARIANT_UPPER)
25+
TARGET_UC := $(MCU_VARIANT_UPPER)
26+
TARGET_LC := $(MCU_VARIANT_LOWER)
27+
28+
MSDK_ROOT = ./msdk
29+
MSDK_LIBS = $(MSDK_ROOT)/Libraries
30+
CMSIS_ROOT = $(MSDK_LIBS)/CMSIS
31+
ADI_PERIPH = $(MSDK_ROOT)/Libraries/PeriphDrivers
32+
ADI_MISC_DRIVERS_DIR ?= $(MSDK_LIBS)/MiscDrivers
33+
ADI_BOARD_DIR = $(MSDK_LIBS)/Boards/$(MCU_VARIANT_UPPER)/$(BOARD)
34+
35+
# For debugging the build
36+
ifneq ($(BUILD_VERBOSE),"")
37+
$(info MSDK_ROOT is $(MSDK_ROOT))
38+
$(info MSDK_LIBS is $(MSDK_LIBS))
39+
$(info CMSIS_ROOT is $(CMSIS_ROOT))
40+
$(info ADI_PERIPH is $(ADI_PERIPH))
41+
$(info ADI_MISC_DRIVERS_DIR is $(ADI_MISC_DRIVERS_DIR))
42+
$(info ADI_BOARD_DIR is $(ADI_BOARD_DIR))
43+
$(info MAXIM_PATH is $(MAXIM_PATH))
44+
endif
45+
46+
# -----------------
47+
# Sources & Include
48+
# -----------------
49+
# Define max32 die type for PeriphDriver Includes
50+
# default to me18 for max32690
51+
# more info:
52+
# https://analogdevicesinc.github.io/msdk//USERGUIDE/#die-types-to-part-numbers
53+
ifeq ($(MCU_VARIANT_LOWER), "max32690")
54+
DIE_TYPE=me18
55+
else
56+
DIE_TYPE=me18
57+
endif
58+
59+
PERIPH_SRC = $(ADI_PERIPH)/Source
60+
61+
INC += -I.
62+
INC += -I../..
63+
INC += -I$(BUILD)
64+
INC += -I$(BUILD)/genhdr
65+
INC += -I./../../lib/cmsis/inc
66+
INC += -I./boards/
67+
INC += -I./boards/$(BOARD)
68+
INC += -I./peripherals/
69+
INC += -I../../lib/mp-readline
70+
71+
INC += \
72+
-I$(TOP)/$(BOARD_PATH) \
73+
-I$(TOP)/lib/cmsis/inc \
74+
-I$(CMSIS_ROOT)/Include \
75+
-I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Include \
76+
-I$(ADI_PERIPH)/Include/$(MCU_VARIANT_UPPER) \
77+
-I$(PERIPH_SRC)/SYS \
78+
-I$(PERIPH_SRC)/GPIO \
79+
-I$(PERIPH_SRC)/CTB \
80+
-I$(PERIPH_SRC)/ICC \
81+
-I$(PERIPH_SRC)/FLC \
82+
-I$(PERIPH_SRC)/UART \
83+
84+
INC += -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC
85+
86+
SRC_MAX32 += \
87+
$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/heap.c \
88+
$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/system_$(MCU_VARIANT_LOWER).c \
89+
$(PERIPH_SRC)/SYS/mxc_assert.c \
90+
$(PERIPH_SRC)/SYS/mxc_delay.c \
91+
$(PERIPH_SRC)/SYS/mxc_lock.c \
92+
$(PERIPH_SRC)/SYS/nvic_table.c \
93+
$(PERIPH_SRC)/SYS/pins_$(DIE_TYPE).c \
94+
$(PERIPH_SRC)/SYS/sys_$(DIE_TYPE).c \
95+
$(PERIPH_SRC)/CTB/ctb_$(DIE_TYPE).c \
96+
$(PERIPH_SRC)/CTB/ctb_reva.c \
97+
$(PERIPH_SRC)/CTB/ctb_common.c \
98+
$(PERIPH_SRC)/FLC/flc_common.c \
99+
$(PERIPH_SRC)/FLC/flc_$(DIE_TYPE).c \
100+
$(PERIPH_SRC)/FLC/flc_reva.c \
101+
$(PERIPH_SRC)/GPIO/gpio_common.c \
102+
$(PERIPH_SRC)/GPIO/gpio_$(DIE_TYPE).c \
103+
$(PERIPH_SRC)/GPIO/gpio_reva.c \
104+
$(PERIPH_SRC)/ICC/icc_$(DIE_TYPE).c \
105+
$(PERIPH_SRC)/ICC/icc_reva.c \
106+
$(PERIPH_SRC)/UART/uart_common.c \
107+
$(PERIPH_SRC)/UART/uart_$(DIE_TYPE).c \
108+
$(PERIPH_SRC)/UART/uart_revb.c \
109+
110+
SRC_C += $(SRC_MAX32) \
111+
boards/$(BOARD)/board.c \
112+
boards/$(BOARD)/pins.c \
113+
peripherals/$(MCU_VARIANT_LOWER)/pins.c \
114+
115+
# *******************************************************************************
116+
### Compiler & Linker Flags ###
117+
COMPILER ?= GCC
118+
119+
ifeq ($(COMPILER), GCC)
120+
121+
STARTUPFILE = $(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC/startup_$(MCU_VARIANT_LOWER).s
122+
# STARTUPFILE = $(ADI_BOARD_DIR)/Source/startup_$(MCU_VARIANT_LOWER).s
123+
124+
# CircuitPython custom linkerfile (necessary for build steps & filesystems)
125+
LINKERFILE = linking/$(MCU_VARIANT_LOWER)_cktpy.ld
126+
LDFLAGS += -nostartfiles -specs=nosys.specs -specs=nano.specs
127+
endif
128+
129+
SRC_S += supervisor/cpu.s \
130+
$(STARTUPFILE)
131+
132+
# Needed to compile some MAX32 headers
133+
CFLAGS += -D$(MCU_VARIANT_UPPER) \
134+
-DTARGET_REV=0x4131 \
135+
-DTARGET=$(MCU_VARIANT_UPPER) \
136+
-DIAR_PRAGMAS=0 \
137+
# -DFLASH_ORIGIN=0x10000000 \
138+
# -DFLASH_SIZE=0x340000 \
139+
# -DSRAM_ORIGIN=0x20000000 \
140+
# -DSRAM_SIZE=0x100000 \
141+
142+
CPU_CORE=cortex-m4
143+
CFLAGS += -mthumb -mcpu=$(CPU_CORE) -mfloat-abi=hard -mfpu=fpv4-sp-d16
144+
145+
# NOTE: Start with DEBUG ONLY settings for now
146+
ifeq ($(DEBUG),)
147+
DEBUG ?= 1
148+
endif
149+
150+
ifeq ($(DEBUG),1)
151+
CFLAGS += -ggdb3
152+
COPT = -Og
153+
else
154+
COPT += -O2
155+
endif
156+
157+
158+
# TinyUSB CFLAGS
159+
CFLAGS += \
160+
-DCFG_TUSB_MCU=OPT_MCU_$(MCU_VARIANT_UPPER) \
161+
-DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED \
162+
163+
# TODO: Add for TinyUSB once our PR goes through for MAX32 devices
164+
# Add TinyUSB
165+
# INC += -I../../lib/tinyusb/src
166+
# INC += -I../../supervisor/shared/usb
167+
# SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c
168+
169+
SRC_C += \
170+
boards/$(BOARD)/board.c \
171+
background.c \
172+
mphalport.c \
173+
174+
CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostartfiles $(BASE_CFLAGS) $(COPT)
175+
176+
# Suppress some warnings for MSDK
177+
CFLAGS += -Wno-error=unused-parameter \
178+
-Wno-error=old-style-declaration \
179+
-Wno-error=sign-compare \
180+
-Wno-error=strict-prototypes \
181+
-Wno-error=cast-qual \
182+
-Wno-unused-variable \
183+
-Wno-lto-type-mismatch \
184+
-Wno-cast-align \
185+
-Wno-nested-externs \
186+
-Wno-sign-compare
187+
188+
LDFLAGS += $(CFLAGS) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections
189+
LIBS := -lgcc -lc
190+
191+
# If not using CKTPY mathlib, use toolchain mathlib
192+
ifndef INTERNAL_LIBM
193+
LIBS += -lm
194+
endif
195+
196+
# *******************************************************************************
197+
### PORT-DEFINED BUILD RULES ###
198+
# This section attempts to build the Python core, the supervisor, and any
199+
# port-provided source code.
200+
#
201+
# QSTR sources are provided for the initial build step, which generates
202+
# Python constants to represent C data which gets passed into the GC.
203+
204+
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
205+
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
206+
$(addprefix common-hal/, $(SRC_COMMON_HAL))
207+
208+
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
209+
$(addprefix shared-module/, $(SRC_SHARED_MODULE)) \
210+
$(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL))
211+
212+
# There are duplicates between SRC_COMMON_HAL_EXPANDED and SRC_SHARED_MODULE_EXPANDED,
213+
# because a few modules have files both in common-hal/ and shared-module/.
214+
# Doing a $(sort ...) removes duplicates as part of sorting.
215+
SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED))
216+
217+
# OBJ includes
218+
OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
219+
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o))
220+
ifeq ($(INTERNAL_LIBM),1)
221+
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
222+
endif
223+
OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o))
224+
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
225+
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
226+
227+
# List of sources for qstr extraction
228+
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_CIRCUITPY_COMMON) \
229+
$(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED) $(SRC_MOD)
230+
# Sources that only hold QSTRs after pre-processing.
231+
SRC_QSTR_PREPROCESSOR +=
232+
233+
# Default build target
234+
all: $(BUILD)/firmware.elf
235+
236+
clean-max32:
237+
rm -rf build-*
238+
239+
# Optional flash option when running within an installed MSDK to use OpenOCD
240+
# Mainline OpenOCD does not yet have the MAX32's flash algorithm integrated.
241+
# If the MSDK is installed, flash-msdk can be run to utilize the the modified
242+
# openocd with the algorithms
243+
MAXIM_PATH := $(subst \,/,$(MAXIM_PATH))
244+
flash-msdk:
245+
$(MAXIM_PATH)/Tools/OpenOCD/openocd -s $(MAXIM_PATH)/Tools/OpenOCD/scripts \
246+
-f interface/cmsis-dap.cfg -f target/$(MCU_VARIANT_LOWER).cfg \
247+
-c "program $(BUILD)/$(PROJECT).elf verify; init; reset; exit"
248+
249+
# flash target using JLink
250+
JLINK_DEVICE = $(MCU_VARIANT_LOWER)
251+
flash: flash-jlink
252+
253+
$(BUILD)/firmware.elf: $(OBJ) $(LINKERFILE)
254+
$(STEPECHO) "LINK $@"
255+
$(Q)echo $(OBJ) > $(BUILD)/firmware.objs
256+
$(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--print-memory-usage -Wl,--start-group $(LIBS) -Wl,--end-group
257+
$(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(LINKERFILE) $(BUILD)
258+
259+
# *******************************************************************************
260+
### CKTPY BUILD RULES ###
261+
include $(TOP)/py/mkrules.mk

ports/analog/README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Analog Devices "MAX32" MCUs
2+
3+
This port brings CircuitPython to ADI's "MAX32" series of microcontrollers. These devices are mostly ARM Cortex-M4-based and focus on delivering performance at low-power levels. Currently this port only supports MAX32690.
4+
5+
### Structure of this port
6+
7+
- **`boards/:`** Board-specific definitions including pins, board initialization, etc.
8+
- **`common-hal/:`** Port-specific implementations of CircuitPython common-hal APIs. When a new module is enabled, this is often where the implementation is found. Expected functions for modules in `common-hal` are usually found in `shared-bindings/` or `shared-module/` in the CircuitPy root directory.
9+
- **`linking/:`** Linkerfiles customized for CircuitPython. These are distinct from the linkerfiles used in MSDK as they adopt the structure required by CircuitPython. They may also omit unused features and memory sections, e.g. Mailboxes, RISC-V Flash, & Hyperbus RAM for MAX32690.
10+
- **`msdk:/`** SDK for MAX32 devices. More info on our GitHub: [Analog Devices MSDK GitHub](https://github.com/analogdevicesinc/msdk)
11+
- **`peripherals:/`** Helper files for peripherals such as clocks, gpio, etc. These files tend to be specific to vendor SDKs and provide some useful functions for the common-hal interfaces.
12+
- **`supervisor/:`** Implementation files for the CircuitPython supervisor. This includes port setup, usb, and a filesystem on a storage medium such as SD Card/eMMC, QSPI Flash, or internal flash memory. Currently the internal flash is used.
13+
14+
- `. :` Build system and high-level interface to the CircuitPython core for the ADI port.
15+
16+
### Building for MAX32 devices
17+
18+
Ensure CircuitPython dependencies are up-to-date by following the CircuitPython introduction on Adafruit's Website: [Building CircuitPython - Introduction](https://learn.adafruit.com/building-circuitpython/introduction). In particular, it is necessary to fetch all submodules (including the ARM Toolchain inside MSDK) and build the `mpy-cross` compiler.
19+
20+
Ensure the MSDK's ARM toolchain is contained on your PATH. This can be done in MinGW or WSL by exporting a prefix to the PATH variable:
21+
22+
$ export MSDK_GNU_PATH=<CircuitPy_Path>/ports/analog/msdk/Tools/GNUTools/10.3/bin
23+
$ export PATH=$MSDK_GNU_PATH:$PATH
24+
25+
This needs to be done each time you open a command environment to build CircuitPython.
26+
27+
Once you have built `mpy-cross` and set up your build system for CircuitPython, you can build for MAX32 devices using the following commands:
28+
29+
$ cd ports/analog
30+
$ make BOARD=<board from boards/ directory>
31+
32+
Be aware the build may take a long time without parallelizing via the `-jN` flag, where N is the # of cores on your machine.
33+
34+
### Flashing the board
35+
36+
Universal instructions on flashing MAX32 devices this project can be found in the **[MSDK User Guide](https://analogdevicesinc.github.io/msdk/USERGUIDE/)**.
37+
38+
In addition, a user may flash the device by calling `make` with the `flash-msdk` target from within the `ports/analog` directory, as below:
39+
40+
$ make BOARD=<target board> flash-msdk
41+
42+
This requires the following:
43+
- A MAX32625PICO is connected to the PC via USB
44+
- The PICO board shows up as a "DAPLINK" drive which implements the CMSIS-DAP interface.
45+
- The PICO board is connected to the target board via a 10-pin SWD ribbon cable.
46+
- If SWD connectors are not keyed, the P1 indicator (red line) on the SWD ribbon cable should match the P1 indicator on the board silkscreen near the 10-pin SWD connector.
47+
48+
[**Section in Progress.**]
49+
50+
### Using the REPL
51+
52+
[**Section in Progress. Review & Testing are needed.**]

ports/analog/background.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "py/runtime.h"
8+
#include "supervisor/filesystem.h"
9+
#include "supervisor/usb.h"
10+
#include "supervisor/shared/stack.h"
11+
12+
//TODO: IMPLEMENT
13+
14+
void port_background_task(void) {
15+
return;
16+
}
17+
18+
void port_background_tick(void) {
19+
return;
20+
}
21+
22+
void port_start_background_tick(void) {
23+
return;
24+
}
25+
26+
void port_finish_background_tick(void) {
27+
return;
28+
}

ports/analog/background.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2019 Dan Halbert for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#ifndef MICROPY_INCLUDED_BACKGROUND_H
8+
#define MICROPY_INCLUDED_BACKGROUND_H
9+
10+
#endif // MICROPY_INCLUDED_BACKGROUND_H

ports/analog/boards/APARD/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# AD-APARD32690-SL
2+
3+
This board features the MAX32690, a dual-core ARM Cortex-M4/RISC-V MCU with 3MiB Flash, 1MiB SRAM. The board also has support for 10BASE-T1L Ethernet, Wifi, Bluetooth, USB, and Security via MAXQ1065. However, most of these features are not yet available for this CircuitPython port (USB will be added soon; others are currently unplanned).
4+
5+
### Onboard connectors & peripherals
6+
7+
This board comes in a form-factor similar to an Arduino Mega, enabling Arduino-style shield boards to be plugged in and evaluated with the MAX32690. This vastly opens up the options for easily plugging peripherals into the board, especially when combined with the two Pmod:tm: connectors, P8 (SPI) and P13 (I2C).
8+
9+
### Product Resources
10+
11+
For more info about AD-APARD32690-SL, visit our product webpages for datasheets, User Guides, Software, and Design Documents:
12+
13+
[AD-APARD32690-SL Product Webpage](https://www.analog.com/en/resources/evaluation-hardware-and-software/evaluation-boards-kits/ad-apard32690-sl.html)
14+
[AD-APARD32690-SL User Guide](https://wiki.analog.com/resources/eval/user-guides/ad-apard32690-sl)

ports/analog/boards/APARD/board.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "supervisor/board.h"
8+
9+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

0 commit comments

Comments
 (0)