|
|
|
@ -22,15 +22,14 @@
|
|
|
|
|
# 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)
|
|
|
|
|
$(error You must provide a BOARD parameter)
|
|
|
|
|
else
|
|
|
|
|
ifeq ($(wildcard boards/$(BOARD)/.),)
|
|
|
|
|
$(error Invalid BOARD specified)
|
|
|
|
|
endif
|
|
|
|
|
ifeq ($(wildcard boards/$(BOARD)/.),)
|
|
|
|
|
$(error Invalid BOARD specified)
|
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
# If the build directory is not given, make it reflect the board name.
|
|
|
|
@ -58,26 +57,27 @@ include $(TOP)/py/circuitpy_defns.mk
|
|
|
|
|
|
|
|
|
|
CROSS_COMPILE = arm-none-eabi-
|
|
|
|
|
|
|
|
|
|
#######################################
|
|
|
|
|
# CFLAGS
|
|
|
|
|
#######################################
|
|
|
|
|
MCU_SERIES_LOWER = $(shell echo $(MCU_SERIES) | tr '[:upper:]' '[:lower:]')
|
|
|
|
|
MCU_VARIANT_LOWER = $(shell echo $(MCU_VARIANT) | tr '[:upper:]' '[:lower:]')
|
|
|
|
|
|
|
|
|
|
HAL_DIR=st_driver/STM32$(MCU_SERIES)xx_HAL_Driver
|
|
|
|
|
|
|
|
|
|
INC += -I.
|
|
|
|
|
INC += -I../..
|
|
|
|
|
INC += -I$(BUILD)
|
|
|
|
|
INC += -I$(BUILD)/genhdr
|
|
|
|
|
INC += -I./st_driver/STM32F4xx_HAL_Driver/Inc
|
|
|
|
|
INC += -I./st_driver/STM32F4xx_HAL_Driver/Inc/Legacy
|
|
|
|
|
INC += -I./st_driver/CMSIS/Device/ST/STM32F4xx/Include
|
|
|
|
|
INC += -I./$(HAL_DIR)/Inc
|
|
|
|
|
INC += -I./$(HAL_DIR)/Inc/Legacy
|
|
|
|
|
INC += -I./st_driver/CMSIS/Device/ST/STM32$(MCU_SERIES)xx/Include
|
|
|
|
|
INC += -I./st_driver/CMSIS/Include
|
|
|
|
|
INC += -I./boards
|
|
|
|
|
INC += -I./boards/$(BOARD)
|
|
|
|
|
INC += -I./peripherals
|
|
|
|
|
INC += -I./packages
|
|
|
|
|
INC += -I../../lib/mp-readline
|
|
|
|
|
INC += -I../../lib/tinyusb/src
|
|
|
|
|
INC += -I../../supervisor/shared/usb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Debugging/Optimization
|
|
|
|
|
ifeq ($(DEBUG), 1)
|
|
|
|
|
CFLAGS += -ggdb
|
|
|
|
@ -87,32 +87,37 @@ else
|
|
|
|
|
CFLAGS += -Os -DNDEBUG
|
|
|
|
|
CFLAGS += -ggdb
|
|
|
|
|
# TODO: Test with -flto
|
|
|
|
|
### CFLAGS += -flto
|
|
|
|
|
# CFLAGS += -flto
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
# MCU Series is defined by the HAL package and doesn't need to be specified here
|
|
|
|
|
C_DEFS = -D$(MCU_PACKAGE) -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -D$(MCU_VARIANT)
|
|
|
|
|
|
|
|
|
|
C_DEFS = -DMCU_PACKAGE=$(MCU_PACKAGE) -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -D$(CMSIS_MCU)
|
|
|
|
|
|
|
|
|
|
CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
|
|
|
|
|
CFLAGS += $(INC) -Werror -Wall -std=gnu11 $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT) -nostdlib -nostartfiles
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
# STM32 HAL uses undefined preprocessor variables, shadowed variables, casts that change alignment reqs
|
|
|
|
|
CFLAGS += -Wno-undef -Wno-shadow -Wno-cast-align
|
|
|
|
|
|
|
|
|
|
CFLAGS += \
|
|
|
|
|
-mthumb \
|
|
|
|
|
-mabi=aapcs-linux \
|
|
|
|
|
-mfloat-abi=hard \
|
|
|
|
|
-mcpu=cortex-m4 \
|
|
|
|
|
-mfpu=fpv4-sp-d16
|
|
|
|
|
CFLAGS += -mthumb -mabi=aapcs-linux
|
|
|
|
|
|
|
|
|
|
# Arm core selection
|
|
|
|
|
MCU_FLAGS_F4 = -mcpu=cortex-m4
|
|
|
|
|
MCU_FLAGS_F7 = -mcpu=cortex-m7
|
|
|
|
|
MCU_FLAGS_H7 = -mcpu=cortex-m7
|
|
|
|
|
CFLAGS += $(MCU_FLAGS_$(MCU_SERIES))
|
|
|
|
|
|
|
|
|
|
# Select HAL file for distribution via mpconfigport
|
|
|
|
|
CFLAGS += -DSTM32_HAL_H='<stm32$(MCU_SERIES_LOWER)xx_hal.h>'
|
|
|
|
|
|
|
|
|
|
# TODO: check this
|
|
|
|
|
CFLAGS += -D__START=main
|
|
|
|
|
# Floating point settings
|
|
|
|
|
ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32F765xx STM32F767xx STM32F769xx STM32H743xx))
|
|
|
|
|
CFLAGS += -mfpu=fpv5-d16 -mfloat-abi=hard
|
|
|
|
|
else
|
|
|
|
|
CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
#need both command and valid file to use uf2 bootloader
|
|
|
|
|
# Need both command and valid file to use uf2 bootloader
|
|
|
|
|
ifndef LD_FILE
|
|
|
|
|
ifneq ($(and $(UF2_BOOTLOADER),$(LD_BOOT)),)
|
|
|
|
|
LD_FILE = $(LD_BOOT)
|
|
|
|
@ -128,66 +133,70 @@ ifndef BOOTLOADER_OFFSET
|
|
|
|
|
BOOTLOADER_OFFSET := 0x8000000
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
|
|
|
|
|
LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-T,$(LD_COMMON) -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 = \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dac.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dac_ex.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_qspi.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc_ex.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_usart.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_gpio.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_adc.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fsmc.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_i2c.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_dma.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usart.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_rcc.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_utils.c \
|
|
|
|
|
st_driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_exti.c \
|
|
|
|
|
system_stm32f4xx.c
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
SRC_STM32 = $(addprefix $(HAL_DIR)/Src/stm32$(MCU_SERIES_LOWER)xx_,\
|
|
|
|
|
hal_adc.c \
|
|
|
|
|
hal_adc_ex.c \
|
|
|
|
|
hal_dac.c \
|
|
|
|
|
hal_dac_ex.c \
|
|
|
|
|
hal_i2c.c \
|
|
|
|
|
hal_i2c_ex.c \
|
|
|
|
|
hal_qspi.c \
|
|
|
|
|
hal_rng.c \
|
|
|
|
|
hal_rtc.c \
|
|
|
|
|
hal_rtc_ex.c \
|
|
|
|
|
hal_spi.c \
|
|
|
|
|
hal_tim.c \
|
|
|
|
|
hal_tim_ex.c \
|
|
|
|
|
hal_uart.c \
|
|
|
|
|
hal_usart.c \
|
|
|
|
|
hal_rcc.c \
|
|
|
|
|
hal_rcc_ex.c \
|
|
|
|
|
hal_flash.c \
|
|
|
|
|
hal_flash_ex.c \
|
|
|
|
|
hal_gpio.c \
|
|
|
|
|
hal_dma_ex.c \
|
|
|
|
|
hal_dma.c \
|
|
|
|
|
hal_pwr.c \
|
|
|
|
|
hal_pwr_ex.c \
|
|
|
|
|
hal_cortex.c \
|
|
|
|
|
hal.c \
|
|
|
|
|
hal_exti.c \
|
|
|
|
|
hal_sd.c \
|
|
|
|
|
ll_gpio.c \
|
|
|
|
|
ll_adc.c \
|
|
|
|
|
ll_i2c.c \
|
|
|
|
|
ll_dma.c \
|
|
|
|
|
ll_sdmmc.c \
|
|
|
|
|
ll_usart.c \
|
|
|
|
|
ll_rcc.c \
|
|
|
|
|
ll_utils.c \
|
|
|
|
|
ll_exti.c \
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Need this to avoid UART linker problems. TODO: rewrite to use registered callbacks.
|
|
|
|
|
# Does not exist for F4 and lower
|
|
|
|
|
ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32F765xx STM32F767xx STM32F769xx STM32H743xx))
|
|
|
|
|
SRC_STM32 += $(HAL_DIR)/Src/stm32$(MCU_SERIES_LOWER)xx_hal_uart_ex.c
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
SRC_STM32 += boards/system_stm32$(MCU_SERIES_LOWER)xx.c
|
|
|
|
|
|
|
|
|
|
SRC_C += \
|
|
|
|
|
background.c \
|
|
|
|
@ -196,10 +205,11 @@ SRC_C += \
|
|
|
|
|
tick.c \
|
|
|
|
|
boards/$(BOARD)/board.c \
|
|
|
|
|
boards/$(BOARD)/pins.c \
|
|
|
|
|
peripherals/stm32f4/$(MCU_SUB_VARIANT)/pins.c \
|
|
|
|
|
peripherals/stm32f4/$(MCU_SUB_VARIANT)/clocks.c \
|
|
|
|
|
peripherals/stm32f4/$(MCU_SUB_VARIANT)/gpio.c \
|
|
|
|
|
peripherals/stm32f4/$(MCU_SUB_VARIANT)/periph.c \
|
|
|
|
|
peripherals/stm32$(MCU_SERIES_LOWER)/$(MCU_VARIANT_LOWER)/pins.c \
|
|
|
|
|
peripherals/stm32$(MCU_SERIES_LOWER)/$(MCU_VARIANT_LOWER)/clocks.c \
|
|
|
|
|
peripherals/stm32$(MCU_SERIES_LOWER)/$(MCU_VARIANT_LOWER)/gpio.c \
|
|
|
|
|
peripherals/stm32$(MCU_SERIES_LOWER)/$(MCU_VARIANT_LOWER)/periph.c \
|
|
|
|
|
packages/$(MCU_PACKAGE).c\
|
|
|
|
|
lib/libc/string0.c \
|
|
|
|
|
lib/mp-readline/readline.c \
|
|
|
|
|
lib/oofatfs/ff.c \
|
|
|
|
@ -219,7 +229,7 @@ endif
|
|
|
|
|
|
|
|
|
|
SRC_S = \
|
|
|
|
|
supervisor/cpu.s \
|
|
|
|
|
boards/startup_$(MCU_SUB_VARIANT).s
|
|
|
|
|
st_driver/CMSIS/Device/ST/STM32$(MCU_SERIES)xx/Source/Templates/gcc/startup_$(MCU_VARIANT_LOWER).s
|
|
|
|
|
|
|
|
|
|
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
|
|
|
|
|
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
|
|
|
|
@ -253,6 +263,12 @@ SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_COMMON_HAL_EXPANDED) $(S
|
|
|
|
|
# Sources that only hold QSTRs after pre-processing.
|
|
|
|
|
SRC_QSTR_PREPROCESSOR +=
|
|
|
|
|
|
|
|
|
|
# Bin section settings specific to the STM32H7
|
|
|
|
|
ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32H743xx))
|
|
|
|
|
MCU_SECTIONS = -j .isr_vector -j .text -j .data -j .itcm -j .dtcm_data $^ $@
|
|
|
|
|
else
|
|
|
|
|
MCU_SECTIONS = $^ $@
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2
|
|
|
|
|
|
|
|
|
@ -263,13 +279,11 @@ $(BUILD)/firmware.elf: $(OBJ)
|
|
|
|
|
|
|
|
|
|
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
|
|
|
|
|
$(STEPECHO) "Create $@"
|
|
|
|
|
$(Q)$(OBJCOPY) -O binary $^ $@
|
|
|
|
|
# $(Q)$(OBJCOPY) -O binary -j .vectors -j .text -j .data $^ $@
|
|
|
|
|
$(Q)$(OBJCOPY) -O binary $(MCU_SECTIONS)
|
|
|
|
|
|
|
|
|
|
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
|
|
|
|
|
$(STEPECHO) "Create $@"
|
|
|
|
|
$(Q)$(OBJCOPY) -O ihex $^ $@
|
|
|
|
|
# $(Q)$(OBJCOPY) -O ihex -j .vectors -j .text -j .data $^ $@
|
|
|
|
|
$(Q)$(OBJCOPY) -O ihex $(MCU_SECTIONS)
|
|
|
|
|
|
|
|
|
|
$(BUILD)/firmware.uf2: $(BUILD)/firmware.hex
|
|
|
|
|
$(ECHO) "Create $@"
|
|
|
|
|