Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
16ba035
first commit, very crude
hierophect Jun 28, 2019
caed59e
name change
hierophect Jun 28, 2019
b93f93f
name change but actually
hierophect Jun 28, 2019
04a9bc0
case changes
hierophect Jun 28, 2019
94a2eff
remove build, fix link issues)
hierophect Jun 28, 2019
040acc3
remove dependencies for stable build
hierophect Jul 1, 2019
7742a97
Add STM32F412-DISCO support, cleanup
hierophect Jul 9, 2019
a0e6975
Add some usb reference material, non functional
hierophect Jul 10, 2019
f31a0d9
Serial REPL support
hierophect Jul 11, 2019
c588cc6
first pass of DigitalIO
hierophect Jul 17, 2019
45e73c4
fix gitignore
hierophect Jul 17, 2019
43e8a41
Add missing files for DigitalIO
hierophect Jul 17, 2019
755b86e
Deinit-capable USB on 411
hierophect Jul 18, 2019
734012a
Makefile cleanup
hierophect Jul 18, 2019
10b9ca5
pin selection cleanup, tinyUSB update
hierophect Jul 19, 2019
58630a8
Add feature conditionals and clean up
hierophect Jul 22, 2019
f65404c
Cleanup missed items
hierophect Jul 22, 2019
ee75f1a
Fix LED misuse interfering with atmel builds
hierophect Jul 22, 2019
10aac2b
Switch to SAMD compatible tinyusb commit
hierophect Jul 22, 2019
9c1487c
Python doc generator fixes
hierophect Jul 23, 2019
5cfde7b
Switch to submodule for cube files
hierophect Jul 23, 2019
5ee5c35
Doc error caused by submodule, misc cleanup
hierophect Jul 23, 2019
172ab19
Revert tinyUSB issue
hierophect Jul 23, 2019
a63df51
Requested changes, general cleanup
hierophect Jul 24, 2019
295afaa
Update SystemCoreClock macro
hierophect Jul 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@
[submodule "frozen/circuitpython-stage"]
path = frozen/circuitpython-stage
url = https://github.com/python-ugame/circuitpython-stage.git
[submodule "ports/stm32f4/stm32f4"]
path = ports/stm32f4/stm32f4
url = https://github.com/adafruit/stm32f4.git
4 changes: 4 additions & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
"ports/nrf/nrfx",
"ports/nrf/peripherals",
"ports/nrf/usb",
"ports/stm32f4/stm32f4",
"ports/stm32f4/peripherals",
"ports/stm32f4/ref",
"ports/stm32f4/README.md",
"ports/pic16bit",
"ports/qemu-arm",
"ports/stm32",
Expand Down
7 changes: 6 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@

#include "background.h"
#include "mpconfigboard.h"
#include "shared-module/displayio/__init__.h"
#include "supervisor/cpu.h"
#include "supervisor/memory.h"
#include "supervisor/port.h"
Expand All @@ -58,6 +57,10 @@
#include "supervisor/shared/stack.h"
#include "supervisor/serial.h"

#if CIRCUITPY_DISPLAYIO
#include "shared-module/displayio/__init__.h"
#endif

#if CIRCUITPY_NETWORK
#include "shared-module/network/__init__.h"
#endif
Expand Down Expand Up @@ -187,7 +190,9 @@ void cleanup_after_vm(supervisor_allocation* heap) {
supervisor_move_memory();

reset_port();
#if CIRCUITPY_BOARD
reset_board_busses();
#endif
reset_board();
reset_status_led();
}
Expand Down
2 changes: 1 addition & 1 deletion ports/nrf/common-hal/microcontroller/Pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void reset_pin_number(uint8_t pin_number) {
#ifdef SPEAKER_ENABLE_PIN
if (pin_number == SPEAKER_ENABLE_PIN->number) {
speaker_enable_in_use = false;
common_hal_digitalio_digitalinout_switch_to_output(
common_hal_digitalio_digitalinout_switch_to_output(SPEAKER_ENABLE_PIN, true, DRIVE_MODE_PUSH_PULL);
nrf_gpio_pin_dir_set(pin_number, NRF_GPIO_PIN_DIR_OUTPUT);
nrf_gpio_pin_write(pin_number, false);
}
Expand Down
9 changes: 9 additions & 0 deletions ports/stm32f4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Build files
#####################
build-*/

# Reference files
#####################
ref/

.gdb_history
271 changes: 271 additions & 0 deletions ports/stm32f4/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
# This file is part of the MicroPython project, http://micropython.org/
#
# The MIT License (MIT)
#
# Copyright (c) 2019 Dan Halbert for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
DEBUG = 1

# Select the board to build for.
ifeq ($(BOARD),)
$(error You must provide a BOARD parameter)
else
ifeq ($(wildcard boards/$(BOARD)/.),)
$(error Invalid BOARD specified)
endif
endif

# If the build directory is not given, make it reflect the board name.
BUILD ?= build-$(BOARD)

include ../../py/mkenv.mk
# Board-specific
include boards/$(BOARD)/mpconfigboard.mk
# Port-specific
include mpconfigport.mk

# CircuitPython-specific
include $(TOP)/py/circuitpy_mpconfig.mk

# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h

# include py core make definitions
include $(TOP)/py/py.mk

include $(TOP)/supervisor/supervisor.mk

# Include make rules and variables common across CircuitPython builds.
include $(TOP)/py/circuitpy_defns.mk

CROSS_COMPILE = arm-none-eabi-

#######################################
# CFLAGS
#######################################

INC += -I.
INC += -I../..
INC += -I$(BUILD)
INC += -I$(BUILD)/genhdr
INC += -I./stm32f4/STM32F4xx_HAL_Driver/Inc
INC += -I./stm32f4/STM32F4xx_HAL_Driver/Inc/Legacy
INC += -I./stm32f4/CMSIS/Device/ST/STM32F4xx/Include
INC += -I./stm32f4/CMSIS/Include
INC += -I./boards
INC += -I./boards/$(BOARD)
INC += -I./peripherals
INC += -I../../lib/mp-readline
INC += -I../../lib/tinyusb/src
INC += -I../../supervisor/shared/usb


#Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -ggdb
# You may want to enable these flags to make setting breakpoints easier.
CFLAGS += -fno-inline -fno-ipa-sra
else
CFLAGS += -Os -DNDEBUG
# TODO: Test with -flto
### CFLAGS += -flto
endif

# C defines and other board specifics
ifeq ($(MCU_SUB_VARIANT), stm32f412zx)
C_DEFS = \
-DUSE_FULL_LL_DRIVER \
-DUSE_HAL_DRIVER \
-DSTM32F412Zx
endif

ifeq ($(MCU_SUB_VARIANT), stm32f411xe)
C_DEFS = \
-DUSE_HAL_DRIVER \
-DSTM32F411xE
endif

#TODO: Add ASM Flags? -Werror
CFLAGS += $(INC) -Wall -std=gnu11 -nostdlib $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)

# Undo some warnings.
# STM32 apparently also uses undefined preprocessor variables quite casually,
# so we can't do warning checks for these.
CFLAGS += -Wno-undef
# STM32 might do casts that increase alignment requirements.
CFLAGS += -Wno-cast-align

CFLAGS += \
-mthumb \
-mabi=aapcs-linux \
-mfloat-abi=hard \
-mcpu=cortex-m4 \
-mfpu=fpv4-sp-d16

# TODO: check this
CFLAGS += -D__START=main

LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
LIBS := -lgcc -lc

LDFLAGS += -mthumb -mcpu=cortex-m4

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

# TinyUSB defines
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


######################################
# source
######################################

SRC_STM32 = \
boards/$(BOARD)/stm32f4xx_hal_msp.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_gpio.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fsmc.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_i2c.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_dma.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s_ex.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_qspi.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usart.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_rcc.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_utils.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_exti.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c \
system_stm32f4xx.c

SRC_C += \
background.c \
fatfs_port.c \
mphalport.c \
tick.c \
boards/$(BOARD)/board.c \
peripherals/stm32f4/$(MCU_SUB_VARIANT)/clocks.c \
peripherals/stm32f4/$(MCU_SUB_VARIANT)/gpio.c \
lib/libc/string0.c \
lib/mp-readline/readline.c \
lib/oofatfs/ff.c \
lib/oofatfs/option/ccsbcs.c \
lib/timeutils/timeutils.c \
lib/utils/buffer_helper.c \
lib/utils/context_manager_helpers.c \
lib/utils/interrupt_char.c \
lib/utils/pyexec.c \
lib/utils/stdout_helpers.c \
lib/utils/sys_stdio_mphal.c \
supervisor/shared/memory.c

ifneq ($(USB),FALSE)
SRC_C += lib/tinyusb/src/portable/st/stm32f4/dcd_stm32f4.c
endif

ifeq ($(MCU_SUB_VARIANT), stm32f412zx)
SRC_C += peripherals/stm32f4/stm32f412zx/pins.c
SRC_C += boards/$(BOARD)/pins.c
endif

SRC_S = \
supervisor/cpu.s \
boards/startup_$(MCU_SUB_VARIANT).s

SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
$(addprefix common-hal/, $(SRC_COMMON_HAL))

SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
$(addprefix shared-module/, $(SRC_SHARED_MODULE))



FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))

OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_STM32:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
ifeq ($(INTERNAL_LIBM),1)
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
endif
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))

$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os

# List of sources for qstr extraction
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
# Sources that only hold QSTRs after pre-processing.
SRC_QSTR_PREPROCESSOR +=


all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2

$(BUILD)/firmware.elf: $(OBJ)
$(STEPECHO) "LINK $@"
$(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
$(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(LD_FILE)

$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
$(STEPECHO) "Create $@"
$(Q)$(OBJCOPY) -O binary $^ $@
# $(Q)$(OBJCOPY) -O binary -j .vectors -j .text -j .data $^ $@

$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
$(STEPECHO) "Create $@"
$(Q)$(OBJCOPY) -O ihex $^ $@
# $(Q)$(OBJCOPY) -O ihex -j .vectors -j .text -j .data $^ $@

$(BUILD)/firmware.uf2: $(BUILD)/firmware.hex
$(ECHO) "Create $@"
$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xADA52840 -c -o "$(BUILD)/firmware.uf2" $^

include $(TOP)/py/mkrules.mk

# Print out the value of a make variable.
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
print-%:
@echo $* = $($*)
3 changes: 3 additions & 0 deletions ports/stm32f4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CircuitPython Port To The ST Microelectronics STM32F4 Series

This is a port of CircuitPython to the STM32F4 series of chips.
Loading