Skip to content

Commit 8978e3e

Browse files
committed
- (build): Added tinyUSB src/inc, DMA & RTC from MSDK.
- (build): added hex & bin targets for executable. - (build): temporarily modified .ld due to issue exiting MAX32 ROM code - (flash): added flash target for jlink & msdk, along with helper files under tools/ - Reorganized mpconfigport.mk for clarity - Moved flash driver & LED/PB definitions to board files (mpconfigboard._)
1 parent e8528fa commit 8978e3e

13 files changed

Lines changed: 191 additions & 115 deletions

File tree

ports/analog/Makefile

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ INC += \
7676
-I$(ADI_PERIPH)/Include/$(MCU_VARIANT_UPPER) \
7777
-I$(PERIPH_SRC)/SYS \
7878
-I$(PERIPH_SRC)/CTB \
79+
-I$(PERIPH_SRC)/DMA \
7980
-I$(PERIPH_SRC)/FLC \
8081
-I$(PERIPH_SRC)/GPIO \
8182
-I$(PERIPH_SRC)/ICC \
83+
-I$(PERIPH_SRC)/TMR \
8284
-I$(PERIPH_SRC)/RTC \
8385
-I$(PERIPH_SRC)/UART \
8486

@@ -96,6 +98,9 @@ SRC_MAX32 += \
9698
$(PERIPH_SRC)/CTB/ctb_$(DIE_TYPE).c \
9799
$(PERIPH_SRC)/CTB/ctb_reva.c \
98100
$(PERIPH_SRC)/CTB/ctb_common.c \
101+
$(PERIPH_SRC)/DMA/dma_reva.c \
102+
$(PERIPH_SRC)/DMA/dma_revb.c \
103+
$(PERIPH_SRC)/DMA/dma_$(DIE_TYPE).c \
99104
$(PERIPH_SRC)/FLC/flc_common.c \
100105
$(PERIPH_SRC)/FLC/flc_$(DIE_TYPE).c \
101106
$(PERIPH_SRC)/FLC/flc_reva.c \
@@ -106,6 +111,9 @@ SRC_MAX32 += \
106111
$(PERIPH_SRC)/ICC/icc_reva.c \
107112
$(PERIPH_SRC)/RTC/rtc_$(DIE_TYPE).c \
108113
$(PERIPH_SRC)/RTC/rtc_reva.c \
114+
$(PERIPH_SRC)/TMR/tmr_common.c \
115+
$(PERIPH_SRC)/TMR/tmr_revb.c \
116+
$(PERIPH_SRC)/TMR/tmr_$(DIE_TYPE).c \
109117
$(PERIPH_SRC)/UART/uart_common.c \
110118
$(PERIPH_SRC)/UART/uart_$(DIE_TYPE).c \
111119
$(PERIPH_SRC)/UART/uart_revb.c \
@@ -126,7 +134,7 @@ STARTUPFILE = $(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC/startup
126134

127135
# CircuitPython custom linkerfile (necessary for build steps & filesystems)
128136
LINKERFILE = linking/$(MCU_VARIANT_LOWER)_cktpy.ld
129-
LDFLAGS += -nostartfiles -specs=nosys.specs -specs=nano.specs
137+
LDFLAGS += -nostartfiles -specs=nano.specs
130138
endif
131139

132140
SRC_S += supervisor/cpu.s \
@@ -137,13 +145,14 @@ CFLAGS += -D$(MCU_VARIANT_UPPER) \
137145
-DTARGET_REV=0x4131 \
138146
-DTARGET=$(MCU_VARIANT_UPPER) \
139147
-DIAR_PRAGMAS=0 \
148+
-DRISCV_LOAD=0 \
140149
# -DFLASH_ORIGIN=0x10000000 \
141150
# -DFLASH_SIZE=0x340000 \
142151
# -DSRAM_ORIGIN=0x20000000 \
143152
# -DSRAM_SIZE=0x100000 \
144153
145154
CPU_CORE=cortex-m4
146-
CFLAGS += -mthumb -mcpu=$(CPU_CORE) -mfloat-abi=hard -mfpu=fpv4-sp-d16
155+
CFLAGS += -mthumb -mcpu=$(CPU_CORE) -mfloat-abi=softfp -mfpu=fpv4-sp-d16
147156

148157
# NOTE: Start with DEBUG ONLY settings for now
149158
ifeq ($(DEBUG),)
@@ -154,7 +163,7 @@ ifeq ($(DEBUG),1)
154163
CFLAGS += -ggdb3
155164
COPT = -Og
156165
else
157-
COPT += -O2
166+
COPT += -O0 #opt completely off to start
158167
endif
159168

160169

@@ -165,9 +174,9 @@ CFLAGS += \
165174

166175
# TODO: Add for TinyUSB once our PR goes through for MAX32 devices
167176
# Add TinyUSB
168-
# INC += -I../../lib/tinyusb/src
169-
# INC += -I../../supervisor/shared/usb
170-
# SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c
177+
INC += -I../../lib/tinyusb/src
178+
INC += -I../../supervisor/shared/usb
179+
SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c
171180

172181
SRC_C += \
173182
boards/$(BOARD)/board.c \
@@ -182,13 +191,14 @@ CFLAGS += -Wno-error=unused-parameter \
182191
-Wno-error=sign-compare \
183192
-Wno-error=strict-prototypes \
184193
-Wno-error=cast-qual \
185-
-Wno-unused-variable \
186-
-Wno-lto-type-mismatch \
187-
-Wno-cast-align \
188-
-Wno-nested-externs \
189-
-Wno-sign-compare
194+
-Wno-error=unused-variable \
195+
-Wno-error=lto-type-mismatch \
196+
-Wno-error=cast-align \
197+
-Wno-error=nested-externs \
198+
-Wno-error=sign-compare \
190199

191-
LDFLAGS += $(CFLAGS) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections
200+
ENTRY = Reset_Handler
201+
LDFLAGS += $(CFLAGS) --entry $(ENTRY) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections
192202
LIBS := -lgcc -lc
193203

194204
# If not using CKTPY mathlib, use toolchain mathlib
@@ -234,7 +244,7 @@ SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_CIRCUITPY_COMMON) \
234244
SRC_QSTR_PREPROCESSOR +=
235245

236246
# Default build target
237-
all: $(BUILD)/firmware.elf
247+
all: $(BUILD)/firmware.elf $(BUILD)/firmware.hex $(BUILD)/firmware.bin
238248

239249
clean-max32:
240250
rm -rf build-*
@@ -247,18 +257,32 @@ MAXIM_PATH := $(subst \,/,$(MAXIM_PATH))
247257
flash-msdk:
248258
$(MAXIM_PATH)/Tools/OpenOCD/openocd -s $(MAXIM_PATH)/Tools/OpenOCD/scripts \
249259
-f interface/cmsis-dap.cfg -f target/$(MCU_VARIANT_LOWER).cfg \
250-
-c "program $(BUILD)/$(PROJECT).elf verify; init; reset; exit"
260+
-c "program $(BUILD)/firmware.elf verify; init; reset; exit"
251261

252262
# flash target using JLink
253263
JLINK_DEVICE = $(MCU_VARIANT_LOWER)
254-
flash: flash-jlink
255264

256-
$(BUILD)/firmware.elf: $(OBJ) $(LINKERFILE)
265+
JLINKEXE ?= JLink.exe
266+
JLINKEXE += -if SWD -device ${JLINK_DEVICE} -speed 10000
267+
COMMAND_FILE := tools/flash_max32.jlink
268+
269+
flash-jlink: $(BUILD)/firmware.bin
270+
@$(JLINKEXE) -device $(MCU_VARIANT_UPPER) -NoGui 1 -CommandFile ${COMMAND_FILE}
271+
272+
$(BUILD)/firmware.elf: $(OBJ)
257273
$(STEPECHO) "LINK $@"
258-
$(Q)echo $(OBJ) > $(BUILD)/firmware.objs
274+
$(Q)echo $^ > $(BUILD)/firmware.objs
259275
$(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--print-memory-usage -Wl,--start-group $(LIBS) -Wl,--end-group
260276
$(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(LINKERFILE) $(BUILD)
261277

278+
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
279+
$(STEPECHO) "Create $@"
280+
$(Q)$(OBJCOPY) -O ihex $^ $@
281+
282+
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
283+
$(STEPECHO) "Create $@"
284+
$(Q)$(OBJCOPY) -O binary $^ $@
285+
262286
# *******************************************************************************
263287
### CKTPY BUILD RULES ###
264288
include $(TOP)/py/mkrules.mk

ports/analog/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ This requires the following:
4545
- The PICO board is connected to the target board via a 10-pin SWD ribbon cable.
4646
- 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.
4747

48-
[**Section in Progress.**]
49-
5048
### Using the REPL
5149

52-
[**Section in Progress. Review & Testing are needed.**]
50+
[**Section in Progress. USB support needs implementation & test.**]

ports/analog/background.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
#include "supervisor/usb.h"
1010
#include "supervisor/shared/stack.h"
1111

12-
#include "supervisor/max32_port.h"
12+
#include "max32_port.h"
13+
14+
// From boards/$(BOARD)/board.c
15+
extern const mxc_gpio_cfg_t pb_pin[];
16+
extern const int num_pbs;
17+
extern const mxc_gpio_cfg_t led_pin[];
18+
extern const int num_leds;
1319

1420
/** NOTE: ALL "ticks" refer to a 1/1024 s period */
1521
static int status_led_ticks=0;
1622

17-
extern mxc_gpio_cfg_t led_pin[];
18-
extern const unsigned int num_leds;
19-
20-
extern mxc_gpio_cfg_t pb_pin[];
21-
extern const unsigned int num_pbs;
22-
2323
// This function is where port-specific background
2424
// tasks should be performed
2525
// Execute port specific actions during background tick. Only if ticks are enabled.
@@ -29,7 +29,7 @@ void port_background_tick(void) {
2929
// Set an LED approx. 1/s
3030
if (status_led_ticks > 1024)
3131
{
32-
MXC_GPIO_OutToggle(led_pin[0].port, led_pin[0].mask);
32+
MXC_GPIO_OutToggle(led_pin[2].port, led_pin[2].mask);
3333
status_led_ticks = 0;
3434
}
3535
}

ports/analog/boards/APARD/mpconfigboard.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@
2222

2323
#define BOARD_HAS_CRYSTAL 1
2424

25-
// todo: figure out a way to smartly set this up based on storage considerations
25+
#define NUM_GPIO_PORTS 4
26+
2627
#if INTERNAL_FLASH_FILESYSTEM
27-
#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x10032000) // for MAX32690
28+
#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x102FC000) // for MAX32690
2829
#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (64 * 1024) // 64K
30+
31+
#define MAX32_FLASH_SIZE 0x300000 // 3 MiB
32+
#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x10000 // 64KiB
33+
#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x102FC000 // Load into the last MiB of code/data storage
34+
2935
#else
3036
#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0)
3137
#endif

ports/analog/linking/max32690_cktpy.ld

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,51 @@
11
MEMORY {
22
ROM (rx) : ORIGIN = 0x00000000, LENGTH = 128K
33
FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 3M
4-
FLASH_ISR (rx) : ORIGIN = 0x10000000, LENGTH = 16K
5-
FLASH_FS (rw) : ORIGIN = 0x10004000, LENGTH = 64K
6-
FLASH_FIRMWARE (rx) : ORIGIN = 0x10014000, LENGTH = 0x10030000 - 80K
7-
RAM (rwx): ORIGIN = 0x20000000, LENGTH = 1M
4+
FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 2992K
5+
FLASH_ISR (rx) : ORIGIN = 0x102EC000, LENGTH = 16K
6+
FLASH_FS (rx) : ORIGIN = 0x102FC000, LENGTH = 64K
7+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 1M
88
}
9-
/* FLASH FIRMWARE: 0x10300000 (end) - 0x10042000 = 0x002BE000 */
10-
11-
ENTRY(Reset_Handler)
9+
/* Minimum flash page is 16K */
10+
/* FLASH FIRMWARE: 3072K [3MB] - 16K - 64K = 2992K */
1211

1312
SECTIONS {
1413
.rom :
1514
{
16-
KEEP(*(.rom_vector))
17-
*(.rom_handlers*)
15+
KEEP(*(.rom_vector*))
16+
KEEP(*(.rom_handlers*))
1817
} > ROM
1918

19+
20+
/** FIXME: can't place this in its own section for some reason
21+
* system doesn't exit ROM code unless *(.isr_vector)
22+
* is placed in the beginning of .text,
23+
* even if .text is moved upward and *(.isr_vector) is
24+
* placed at 0x10000000.
25+
**/
26+
2027
/* Place ISR vector in a separate flash section */
21-
.isr_vector :
22-
{
23-
. = ALIGN(4);
24-
/* Startup code */
25-
KEEP(*(.isr_vector*))
26-
} >FLASH_ISR
28+
/* .isr_vector : */
29+
/* { */
30+
/* ISR Vector beginning of .text */
31+
/* KEEP(*(.isr_vector)) */
32+
/* KEEP(*(.isr_vector*)) */
33+
/* } > FLASH_ISR */
2734

2835
.text :
2936
{
3037
. = ALIGN(4);
3138
_text = .;
3239

33-
/* program code, exclude RISCV code */
34-
EXCLUDE_FILE (*riscv.o) *(.text*)
40+
/* ISR Vector beginning of .text */
41+
/** fixme: may want to move this to FLASH_ISR long-term */
42+
KEEP(*(.isr_vector))
43+
KEEP(*(.isr_vector*))
44+
45+
. = ALIGN(4);
3546

47+
/* program code; exclude RISCV code */
48+
EXCLUDE_FILE (*riscv.o) *(.text*)
3649
*(.rodata*) /* read-only data: "const" */
3750

3851
KEEP(*(.init))
@@ -146,21 +159,21 @@ SECTIONS {
146159
* size of stack_dummy section */
147160
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
148161
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
162+
163+
_stack = __StackTop;
149164
_estack = __StackLimit; /* Provide _estack for CktPython */
150165

151166
.heap (COPY):
152167
{
153168
. = ALIGN(4);
154-
__heap = .;
169+
_heap = .;
155170
PROVIDE ( end = . );
156171
PROVIDE ( _end = . );
157172
*(.heap*)
158173
__HeapLimit = ABSOLUTE(__StackLimit);
159174
} > RAM
160175

161-
__eheap = __HeapLimit;
162-
163-
PROVIDE(__stack = __StackTop);
176+
_eheap = __HeapLimit;
164177

165178
/* Check if data + heap + stack exceeds RAM limit */
166179
ASSERT(__StackLimit >= _ebss, "region RAM overflowed with stack")

ports/analog/mpconfigport.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
#define MICROPY_PY_FUNCTION_ATTRS (1)
1313
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
1414

15-
16-
// 24kiB stack
15+
// 24KiB stack
1716
#define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000
18-
// uint8_t _ld_default_stack_size;
19-
// #define CIRCUITPY_DEFAULT_STACK_SIZE ((uint32_t)&_ld_default_stack_size)
2017

2118
// Also includes mpconfigboard.h
2219
#include "py/circuitpy_mpconfig.h"

0 commit comments

Comments
 (0)