Skip to content

Commit 53b1544

Browse files
committed
create copy
1 parent d988af0 commit 53b1544

File tree

161 files changed

+19919
-0
lines changed

Some content is hidden

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

161 files changed

+19919
-0
lines changed

ports/stm/.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/stm/Makefile

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

ports/stm/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.

ports/stm/background.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/runtime.h"
28+
#include "supervisor/filesystem.h"
29+
#include "supervisor/usb.h"
30+
#include "supervisor/shared/stack.h"
31+
32+
#if CIRCUITPY_DISPLAYIO
33+
#include "shared-module/displayio/__init__.h"
34+
#endif
35+
36+
static bool running_background_tasks = false;
37+
38+
void background_tasks_reset(void) {
39+
running_background_tasks = false;
40+
}
41+
42+
void run_background_tasks(void) {
43+
// Don't call ourselves recursively.
44+
if (running_background_tasks) {
45+
return;
46+
}
47+
running_background_tasks = true;
48+
filesystem_background();
49+
50+
#if USB_AVAILABLE
51+
usb_background();
52+
#endif
53+
54+
#if CIRCUITPY_DISPLAYIO
55+
displayio_background();
56+
#endif
57+
running_background_tasks = false;
58+
59+
assert_heap_ok();
60+
}

ports/stm/background.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Dan Halbert for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_STM32F4_BACKGROUND_H
28+
#define MICROPY_INCLUDED_STM32F4_BACKGROUND_H
29+
30+
#include <stdbool.h>
31+
32+
void background_tasks_reset(void);
33+
void run_background_tasks(void);
34+
35+
#endif // MICROPY_INCLUDED_STM32F4_BACKGROUND_H

0 commit comments

Comments
 (0)