Skip to content

Commit 8ec2d6c

Browse files
authored
Merge pull request #2007 from hierophect/F4xx-port-setup
Add STM32 Discovery F412ZG and F411RE support
2 parents f39a6f4 + 295afaa commit 8ec2d6c

Some content is hidden

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

75 files changed

+8090
-27
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,6 @@
9595
[submodule "frozen/circuitpython-stage"]
9696
path = frozen/circuitpython-stage
9797
url = https://github.com/python-ugame/circuitpython-stage.git
98+
[submodule "ports/stm32f4/stm32f4"]
99+
path = ports/stm32f4/stm32f4
100+
url = https://github.com/adafruit/stm32f4.git

conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@
122122
"ports/nrf/nrfx",
123123
"ports/nrf/peripherals",
124124
"ports/nrf/usb",
125+
"ports/stm32f4/stm32f4",
126+
"ports/stm32f4/peripherals",
127+
"ports/stm32f4/ref",
128+
"ports/stm32f4/README.md",
125129
"ports/pic16bit",
126130
"ports/qemu-arm",
127131
"ports/stm32",

main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
#include "background.h"
4747
#include "mpconfigboard.h"
48-
#include "shared-module/displayio/__init__.h"
4948
#include "supervisor/cpu.h"
5049
#include "supervisor/memory.h"
5150
#include "supervisor/port.h"
@@ -58,6 +57,10 @@
5857
#include "supervisor/shared/stack.h"
5958
#include "supervisor/serial.h"
6059

60+
#if CIRCUITPY_DISPLAYIO
61+
#include "shared-module/displayio/__init__.h"
62+
#endif
63+
6164
#if CIRCUITPY_NETWORK
6265
#include "shared-module/network/__init__.h"
6366
#endif
@@ -187,7 +190,9 @@ void cleanup_after_vm(supervisor_allocation* heap) {
187190
supervisor_move_memory();
188191

189192
reset_port();
193+
#if CIRCUITPY_BOARD
190194
reset_board_busses();
195+
#endif
191196
reset_board();
192197
reset_status_led();
193198
}

ports/nrf/common-hal/microcontroller/Pin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void reset_pin_number(uint8_t pin_number) {
105105
#ifdef SPEAKER_ENABLE_PIN
106106
if (pin_number == SPEAKER_ENABLE_PIN->number) {
107107
speaker_enable_in_use = false;
108-
common_hal_digitalio_digitalinout_switch_to_output(
108+
common_hal_digitalio_digitalinout_switch_to_output(SPEAKER_ENABLE_PIN, true, DRIVE_MODE_PUSH_PULL);
109109
nrf_gpio_pin_dir_set(pin_number, NRF_GPIO_PIN_DIR_OUTPUT);
110110
nrf_gpio_pin_write(pin_number, false);
111111
}

ports/stm32f4/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Build files
2+
#####################
3+
build-*/
4+
5+
# Reference files
6+
#####################
7+
ref/
8+
9+
.gdb_history

ports/stm32f4/Makefile

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
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+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
DEBUG = 1
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+
44+
# CircuitPython-specific
45+
include $(TOP)/py/circuitpy_mpconfig.mk
46+
47+
# qstr definitions (must come before including py.mk)
48+
QSTR_DEFS = qstrdefsport.h
49+
50+
# include py core make definitions
51+
include $(TOP)/py/py.mk
52+
53+
include $(TOP)/supervisor/supervisor.mk
54+
55+
# Include make rules and variables common across CircuitPython builds.
56+
include $(TOP)/py/circuitpy_defns.mk
57+
58+
CROSS_COMPILE = arm-none-eabi-
59+
60+
#######################################
61+
# CFLAGS
62+
#######################################
63+
64+
INC += -I.
65+
INC += -I../..
66+
INC += -I$(BUILD)
67+
INC += -I$(BUILD)/genhdr
68+
INC += -I./stm32f4/STM32F4xx_HAL_Driver/Inc
69+
INC += -I./stm32f4/STM32F4xx_HAL_Driver/Inc/Legacy
70+
INC += -I./stm32f4/CMSIS/Device/ST/STM32F4xx/Include
71+
INC += -I./stm32f4/CMSIS/Include
72+
INC += -I./boards
73+
INC += -I./boards/$(BOARD)
74+
INC += -I./peripherals
75+
INC += -I../../lib/mp-readline
76+
INC += -I../../lib/tinyusb/src
77+
INC += -I../../supervisor/shared/usb
78+
79+
80+
#Debugging/Optimization
81+
ifeq ($(DEBUG), 1)
82+
CFLAGS += -ggdb
83+
# You may want to enable these flags to make setting breakpoints easier.
84+
CFLAGS += -fno-inline -fno-ipa-sra
85+
else
86+
CFLAGS += -Os -DNDEBUG
87+
# TODO: Test with -flto
88+
### CFLAGS += -flto
89+
endif
90+
91+
# C defines and other board specifics
92+
ifeq ($(MCU_SUB_VARIANT), stm32f412zx)
93+
C_DEFS = \
94+
-DUSE_FULL_LL_DRIVER \
95+
-DUSE_HAL_DRIVER \
96+
-DSTM32F412Zx
97+
endif
98+
99+
ifeq ($(MCU_SUB_VARIANT), stm32f411xe)
100+
C_DEFS = \
101+
-DUSE_HAL_DRIVER \
102+
-DSTM32F411xE
103+
endif
104+
105+
#TODO: Add ASM Flags? -Werror
106+
CFLAGS += $(INC) -Wall -std=gnu11 -nostdlib $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
107+
108+
# Undo some warnings.
109+
# STM32 apparently also uses undefined preprocessor variables quite casually,
110+
# so we can't do warning checks for these.
111+
CFLAGS += -Wno-undef
112+
# STM32 might do casts that increase alignment requirements.
113+
CFLAGS += -Wno-cast-align
114+
115+
CFLAGS += \
116+
-mthumb \
117+
-mabi=aapcs-linux \
118+
-mfloat-abi=hard \
119+
-mcpu=cortex-m4 \
120+
-mfpu=fpv4-sp-d16
121+
122+
# TODO: check this
123+
CFLAGS += -D__START=main
124+
125+
LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
126+
LIBS := -lgcc -lc
127+
128+
LDFLAGS += -mthumb -mcpu=cortex-m4
129+
130+
# Use toolchain libm if we're not using our own.
131+
ifndef INTERNAL_LIBM
132+
LIBS += -lm
133+
endif
134+
135+
# TinyUSB defines
136+
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_STM32F4 -DCFG_TUD_CDC_RX_BUFSIZE=1024 -DCFG_TUD_CDC_TX_BUFSIZE=1024 -DCFG_TUD_MSC_BUFSIZE=4096 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_MIDI_TX_BUFSIZE=128
137+
138+
139+
######################################
140+
# source
141+
######################################
142+
143+
SRC_STM32 = \
144+
boards/$(BOARD)/stm32f4xx_hal_msp.c \
145+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_gpio.c \
146+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c \
147+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c \
148+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c \
149+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fsmc.c \
150+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c \
151+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_i2c.c \
152+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_dma.c \
153+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s.c \
154+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s_ex.c \
155+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_qspi.c \
156+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c \
157+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c \
158+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c \
159+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \
160+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usart.c \
161+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_rcc.c \
162+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_utils.c \
163+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_exti.c \
164+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c \
165+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \
166+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c \
167+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c \
168+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c \
169+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c \
170+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \
171+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c \
172+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \
173+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c \
174+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c \
175+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \
176+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \
177+
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c \
178+
system_stm32f4xx.c
179+
180+
SRC_C += \
181+
background.c \
182+
fatfs_port.c \
183+
mphalport.c \
184+
tick.c \
185+
boards/$(BOARD)/board.c \
186+
peripherals/stm32f4/$(MCU_SUB_VARIANT)/clocks.c \
187+
peripherals/stm32f4/$(MCU_SUB_VARIANT)/gpio.c \
188+
lib/libc/string0.c \
189+
lib/mp-readline/readline.c \
190+
lib/oofatfs/ff.c \
191+
lib/oofatfs/option/ccsbcs.c \
192+
lib/timeutils/timeutils.c \
193+
lib/utils/buffer_helper.c \
194+
lib/utils/context_manager_helpers.c \
195+
lib/utils/interrupt_char.c \
196+
lib/utils/pyexec.c \
197+
lib/utils/stdout_helpers.c \
198+
lib/utils/sys_stdio_mphal.c \
199+
supervisor/shared/memory.c
200+
201+
ifneq ($(USB),FALSE)
202+
SRC_C += lib/tinyusb/src/portable/st/stm32f4/dcd_stm32f4.c
203+
endif
204+
205+
ifeq ($(MCU_SUB_VARIANT), stm32f412zx)
206+
SRC_C += peripherals/stm32f4/stm32f412zx/pins.c
207+
SRC_C += boards/$(BOARD)/pins.c
208+
endif
209+
210+
SRC_S = \
211+
supervisor/cpu.s \
212+
boards/startup_$(MCU_SUB_VARIANT).s
213+
214+
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
215+
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
216+
$(addprefix common-hal/, $(SRC_COMMON_HAL))
217+
218+
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
219+
$(addprefix shared-module/, $(SRC_SHARED_MODULE))
220+
221+
222+
223+
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
224+
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
225+
226+
OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
227+
OBJ += $(addprefix $(BUILD)/, $(SRC_STM32:.c=.o))
228+
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
229+
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
230+
ifeq ($(INTERNAL_LIBM),1)
231+
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
232+
endif
233+
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
234+
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
235+
236+
$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
237+
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os
238+
239+
# List of sources for qstr extraction
240+
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
241+
# Sources that only hold QSTRs after pre-processing.
242+
SRC_QSTR_PREPROCESSOR +=
243+
244+
245+
all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2
246+
247+
$(BUILD)/firmware.elf: $(OBJ)
248+
$(STEPECHO) "LINK $@"
249+
$(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
250+
$(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(LD_FILE)
251+
252+
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
253+
$(STEPECHO) "Create $@"
254+
$(Q)$(OBJCOPY) -O binary $^ $@
255+
# $(Q)$(OBJCOPY) -O binary -j .vectors -j .text -j .data $^ $@
256+
257+
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
258+
$(STEPECHO) "Create $@"
259+
$(Q)$(OBJCOPY) -O ihex $^ $@
260+
# $(Q)$(OBJCOPY) -O ihex -j .vectors -j .text -j .data $^ $@
261+
262+
$(BUILD)/firmware.uf2: $(BUILD)/firmware.hex
263+
$(ECHO) "Create $@"
264+
$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xADA52840 -c -o "$(BUILD)/firmware.uf2" $^
265+
266+
include $(TOP)/py/mkrules.mk
267+
268+
# Print out the value of a make variable.
269+
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
270+
print-%:
271+
@echo $* = $($*)

ports/stm32f4/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 ST Microelectronics STM32F4 Series
2+
3+
This is a port of CircuitPython to the STM32F4 series of chips.

0 commit comments

Comments
 (0)