Skip to content

Commit c4db8b8

Browse files
committed
Add F7 and H7 Support to the STM32 port
Restructures the STM port of Circuitpython to be more generic about the STM32 chip lines to support the F7 and H7 series of chips. Adds the new Packages directory to organize different chip layouts between lines. Makes general changes to the Makefile to condense board-level flags to the minimum and support the new chip series. Adds the new chip line to the Peripherals directory, along with new python tools used to generate peripheral text automatically in the tools/ directory.
1 parent bb3ed3a commit c4db8b8

Some content is hidden

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

95 files changed

+4672
-1298
lines changed

ports/stm/Makefile

Lines changed: 80 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2323
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
# THE SOFTWARE.
25-
# DEBUG = 1
2625

2726
# Select the board to build for.
2827
ifeq ($(BOARD),)
@@ -58,21 +57,23 @@ include $(TOP)/py/circuitpy_defns.mk
5857

5958
CROSS_COMPILE = arm-none-eabi-
6059

61-
#######################################
62-
# CFLAGS
63-
#######################################
60+
MCU_SERIES_LOWER = $(shell echo $(MCU_SERIES) | tr '[:upper:]' '[:lower:]')
61+
MCU_VARIANT_LOWER = $(shell echo $(MCU_VARIANT) | tr '[:upper:]' '[:lower:]')
62+
63+
HAL_DIR=st_driver/STM32$(MCU_SERIES)xx_HAL_Driver
6464

6565
INC += -I.
6666
INC += -I../..
6767
INC += -I$(BUILD)
6868
INC += -I$(BUILD)/genhdr
69-
INC += -I./st_driver/STM32F4xx_HAL_Driver/Inc
70-
INC += -I./st_driver/STM32F4xx_HAL_Driver/Inc/Legacy
71-
INC += -I./st_driver/CMSIS/Device/ST/STM32F4xx/Include
69+
INC += -I./$(HAL_DIR)/Inc
70+
INC += -I./$(HAL_DIR)/Inc/Legacy
71+
INC += -I./st_driver/CMSIS/Device/ST/STM32$(MCU_SERIES)xx/Include
7272
INC += -I./st_driver/CMSIS/Include
7373
INC += -I./boards
7474
INC += -I./boards/$(BOARD)
7575
INC += -I./peripherals
76+
INC += -I./packages
7677
INC += -I../../lib/mp-readline
7778
INC += -I../../lib/tinyusb/src
7879
INC += -I../../supervisor/shared/usb
@@ -87,11 +88,11 @@ else
8788
CFLAGS += -Os -DNDEBUG
8889
CFLAGS += -ggdb
8990
# TODO: Test with -flto
90-
### CFLAGS += -flto
91+
# CFLAGS += -flto
9192
endif
9293

93-
94-
C_DEFS = -DMCU_PACKAGE=$(MCU_PACKAGE) -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -D$(CMSIS_MCU)
94+
# MCU Series is defined by the HAL package and doesn't need to be specified here
95+
C_DEFS = -D$(MCU_PACKAGE) -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -D$(MCU_VARIANT)
9596

9697
CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
9798

@@ -102,17 +103,24 @@ CFLAGS += -Wno-undef
102103
# STM32 might do casts that increase alignment requirements.
103104
CFLAGS += -Wno-cast-align
104105

105-
CFLAGS += \
106-
-mthumb \
107-
-mabi=aapcs-linux \
108-
-mfloat-abi=hard \
109-
-mcpu=cortex-m4 \
110-
-mfpu=fpv4-sp-d16
106+
CFLAGS += -mthumb -mabi=aapcs-linux
111107

112-
# TODO: check this
113-
CFLAGS += -D__START=main
108+
# Arm core selection
109+
MCU_FLAGS_F4 = -mtune=cortex-m4 -mcpu=cortex-m4
110+
MCU_FLAGS_F7 = -mtune=cortex-m7 -mcpu=cortex-m7
111+
MCU_FLAGS_H7 = -mtune=cortex-m7 -mcpu=cortex-m7
112+
CFLAGS += $(MCU_FLAGS_$(MCU_SERIES))
114113

115-
#need both command and valid file to use uf2 bootloader
114+
CFLAGS += -DSTM32_HAL_H='<stm32$(MCU_SERIES_LOWER)xx_hal.h>'
115+
116+
# Floating point settings
117+
ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32F765xx STM32F767xx STM32F769xx STM32H743xx))
118+
CFLAGS += -mfpu=fpv5-d16 -mfloat-abi=hard
119+
else
120+
CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard
121+
endif
122+
123+
# Need both command and valid file to use uf2 bootloader
116124
ifndef LD_FILE
117125
ifneq ($(and $(UF2_BOOTLOADER),$(LD_BOOT)),)
118126
LD_FILE = $(LD_BOOT)
@@ -131,63 +139,60 @@ endif
131139
LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
132140
LIBS := -lgcc -lc
133141

134-
LDFLAGS += -mthumb -mcpu=cortex-m4
142+
LDFLAGS += -mthumb $(MCU_FLAGS_$(MCU_SERIES))
135143

136144
# Use toolchain libm if we're not using our own.
137145
ifndef INTERNAL_LIBM
138146
LIBS += -lm
139147
endif
140148

141149
# TinyUSB defines
142-
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
143-
144-
145-
######################################
146-
# source
147-
######################################
148-
149-
SRC_STM32 = \
150-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c \
151-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c \
152-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dac.c \
153-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dac_ex.c \
154-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c \
155-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c \
156-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_qspi.c \
157-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.c \
158-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc.c \
159-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc_ex.c \
160-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c \
161-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c \
162-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \
163-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c \
164-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_usart.c \
165-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \
166-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c \
167-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c \
168-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c \
169-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c \
170-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \
171-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c \
172-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \
173-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c \
174-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c \
175-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \
176-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \
177-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c \
178-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c \
179-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_gpio.c \
180-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_adc.c \
181-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fsmc.c \
182-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_i2c.c \
183-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_dma.c \
184-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c \
185-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usart.c \
186-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_rcc.c \
187-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_utils.c \
188-
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_exti.c \
189-
system_stm32f4xx.c
190-
150+
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_STM32$(MCU_SERIES) -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
151+
152+
SRC_STM32 = $(addprefix $(HAL_DIR)/Src/stm32$(MCU_SERIES_LOWER)xx_,\
153+
hal_adc.c \
154+
hal_adc_ex.c \
155+
hal_dac.c \
156+
hal_dac_ex.c \
157+
hal_i2c.c \
158+
hal_i2c_ex.c \
159+
hal_qspi.c \
160+
hal_rng.c \
161+
hal_rtc.c \
162+
hal_rtc_ex.c \
163+
hal_spi.c \
164+
hal_tim.c \
165+
hal_tim_ex.c \
166+
hal_uart.c \
167+
hal_usart.c \
168+
hal_rcc.c \
169+
hal_rcc_ex.c \
170+
hal_flash.c \
171+
hal_flash_ex.c \
172+
hal_gpio.c \
173+
hal_dma_ex.c \
174+
hal_dma.c \
175+
hal_pwr.c \
176+
hal_pwr_ex.c \
177+
hal_cortex.c \
178+
hal.c \
179+
hal_exti.c \
180+
hal_sd.c \
181+
ll_gpio.c \
182+
ll_adc.c \
183+
ll_i2c.c \
184+
ll_dma.c \
185+
ll_sdmmc.c \
186+
ll_usart.c \
187+
ll_rcc.c \
188+
ll_utils.c \
189+
ll_exti.c \
190+
)
191+
#removed:
192+
# hal_flash_ramfunc.c \
193+
# ll_fsmc.c \
194+
195+
SRC_STM32 += system_stm32$(MCU_SERIES_LOWER)xx.c
191196

192197
SRC_C += \
193198
background.c \
@@ -196,10 +201,11 @@ SRC_C += \
196201
tick.c \
197202
boards/$(BOARD)/board.c \
198203
boards/$(BOARD)/pins.c \
199-
peripherals/stm32f4/$(MCU_SUB_VARIANT)/pins.c \
200-
peripherals/stm32f4/$(MCU_SUB_VARIANT)/clocks.c \
201-
peripherals/stm32f4/$(MCU_SUB_VARIANT)/gpio.c \
202-
peripherals/stm32f4/$(MCU_SUB_VARIANT)/periph.c \
204+
peripherals/stm32$(MCU_SERIES_LOWER)/$(MCU_VARIANT_LOWER)/pins.c \
205+
peripherals/stm32$(MCU_SERIES_LOWER)/$(MCU_VARIANT_LOWER)/clocks.c \
206+
peripherals/stm32$(MCU_SERIES_LOWER)/$(MCU_VARIANT_LOWER)/gpio.c \
207+
peripherals/stm32$(MCU_SERIES_LOWER)/$(MCU_VARIANT_LOWER)/periph.c \
208+
packages/$(MCU_PACKAGE).c\
203209
lib/libc/string0.c \
204210
lib/mp-readline/readline.c \
205211
lib/oofatfs/ff.c \
@@ -219,7 +225,7 @@ endif
219225

220226
SRC_S = \
221227
supervisor/cpu.s \
222-
boards/startup_$(MCU_SUB_VARIANT).s
228+
boards/startup_$(MCU_VARIANT_LOWER).s
223229

224230
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
225231
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \

ports/stm/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# CircuitPython Port To The ST Microelectronics STM32F4 Series
1+
# CircuitPython Port To The ST Microelectronics STM32 Series
22

3-
This is a port of CircuitPython to the STM32F4 series of chips.
3+
This is a port of CircuitPython to the STM32 series of chips.

ports/stm/background.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_STM32F4_BACKGROUND_H
28-
#define MICROPY_INCLUDED_STM32F4_BACKGROUND_H
27+
#ifndef MICROPY_INCLUDED_STM32_BACKGROUND_H
28+
#define MICROPY_INCLUDED_STM32_BACKGROUND_H
2929

3030
#include <stdbool.h>
3131

3232
void background_tasks_reset(void);
3333
void run_background_tasks(void);
3434

35-
#endif // MICROPY_INCLUDED_STM32F4_BACKGROUND_H
35+
#endif // MICROPY_INCLUDED_STM32_BACKGROUND_H

0 commit comments

Comments
 (0)