diff --git a/src/Kconfig b/src/Kconfig index 2d238c50..d065bc26 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -19,12 +19,10 @@ choice bool "SAMD21/SAMD51" config MACH_LPC176X bool "LPC176x (Smoothieboard)" + config MACH_STM32 + bool "STMicroelectronics STM32F1/F4" config MACH_STM32F0 bool "STMicroelectronics STM32F042" - config MACH_STM32F1 - bool "STMicroelectronics STM32F103" - config MACH_STM32F4 - bool "STMicroelectronics STM32F4" config MACH_PRU bool "Beaglebone PRU" config MACH_LINUX @@ -37,9 +35,8 @@ source "src/avr/Kconfig" source "src/atsam/Kconfig" source "src/atsamd/Kconfig" source "src/lpc176x/Kconfig" +source "src/stm32/Kconfig" source "src/stm32f0/Kconfig" -source "src/stm32f1/Kconfig" -source "src/stm32f4/Kconfig" source "src/pru/Kconfig" source "src/linux/Kconfig" source "src/simulator/Kconfig" diff --git a/src/stm32f4/Kconfig b/src/stm32/Kconfig similarity index 90% rename from src/stm32f4/Kconfig rename to src/stm32/Kconfig index de60e4fa..707215ec 100644 --- a/src/stm32f4/Kconfig +++ b/src/stm32/Kconfig @@ -1,8 +1,8 @@ -# Kconfig settings for STM32F4 processors +# Kconfig settings for STM32 processors -if MACH_STM32F4 +if MACH_STM32 -config STM32F4_SELECT +config STM32_SELECT bool default y select HAVE_GPIO @@ -12,28 +12,28 @@ config STM32F4_SELECT config BOARD_DIRECTORY string - default "stm32f4" + default "stm32" choice prompt "Processor model" config MACH_STM32F103 bool "STM32F103" - select MACH_STM32F1xx + select MACH_STM32F1 select HAVE_STM32_USBFS config MACH_STM32F405 bool "STM32F405" - select MACH_STM32F4xx + select MACH_STM32F4 config MACH_STM32F407 bool "STM32F407" - select MACH_STM32F4xx + select MACH_STM32F4 config MACH_STM32F446 bool "STM32F446" - select MACH_STM32F4xx + select MACH_STM32F4 endchoice -config MACH_STM32F1xx +config MACH_STM32F1 bool -config MACH_STM32F4xx +config MACH_STM32F4 bool config HAVE_STM32_USBFS bool diff --git a/src/stm32/Makefile b/src/stm32/Makefile new file mode 100644 index 00000000..24c60c58 --- /dev/null +++ b/src/stm32/Makefile @@ -0,0 +1,63 @@ +# Additional STM32 build rules + +# Setup the toolchain +CROSS_PREFIX=arm-none-eabi- + +dirs-y += src/stm32 src/generic +dirs-$(CONFIG_MACH_STM32F1) += lib/stm32f1 lib/stm32f1/gcc +dirs-$(CONFIG_MACH_STM32F4) += lib/stm32f4 lib/stm32f4/gcc + +MCU := $(shell echo $(CONFIG_MCU)) +MCU_UPPER := $(shell echo $(CONFIG_MCU) | tr a-z A-Z | tr X x) + +CFLAGS-$(CONFIG_MACH_STM32F1) += -mcpu=cortex-m3 -Ilib/stm32f1/include +CFLAGS-$(CONFIG_MACH_STM32F4) += -mcpu=cortex-m4 -Ilib/stm32f4/include +CFLAGS-$(CONFIG_MACH_STM32F4) += -mfpu=fpv4-sp-d16 -mfloat-abi=hard + +CFLAGS += $(CFLAGS-y) -D$(MCU_UPPER) -mthumb -Ilib/cmsis-core +CFLAGS_klipper.elf += -T $(OUT)stm32.ld --specs=nano.specs --specs=nosys.specs + +# Add source files +src-y += stm32/main.c stm32/watchdog.c stm32/gpio.c +src-y += generic/crc16_ccitt.c generic/armcm_irq.c generic/armcm_timer.c +src-$(CONFIG_MACH_STM32F1) += ../lib/stm32f1/system_stm32f1xx.c +src-$(CONFIG_MACH_STM32F1) += stm32/stm32f1.c +src-$(CONFIG_MACH_STM32F4) += ../lib/stm32f4/system_stm32f4xx.c +src-$(CONFIG_MACH_STM32F4) += stm32/clock.c +src-$(CONFIG_HAVE_GPIO_ADC) += stm32/adc.c +src-$(CONFIG_HAVE_GPIO_SPI) += stm32/spi.c +src-$(CONFIG_USBSERIAL) += stm32/usbfs.c generic/usb_cdc.c +src-$(CONFIG_SERIAL) += stm32/serial.c generic/serial_irq.c + +# Add assembler build rules +$(OUT)%.o: %.s $(OUT)autoconf.h $(OUT)board-link + @echo " Assembling $@" + $(Q)$(AS) $< -o $@ + +asmsrc-$(CONFIG_MACH_STM32F1) := ../lib/stm32f1/gcc/startup_$(MCU).s +asmsrc-$(CONFIG_MACH_STM32F4) := ../lib/stm32f4/gcc/startup_$(MCU).s +OBJS_klipper.elf += $(patsubst %.s, $(OUT)src/%.o,$(asmsrc-y)) + +# Build the linker script +$(OUT)stm32.ld: src/stm32/stm32.lds.S $(OUT)board-link + @echo " Preprocessing $@" + $(Q)$(CPP) -I$(OUT) -P -MD -MT $@ $< -o $@ +$(OUT)klipper.elf: $(OUT)stm32.ld + +# Binary output file rules +target-y += $(OUT)klipper.bin + +$(OUT)klipper.bin: $(OUT)klipper.elf + @echo " Creating hex file $@" + $(Q)$(OBJCOPY) -O binary $< $@ + +FLASH_TYPE-$(CONFIG_MACH_STM32F1) := stm32f1 +FLASH_TYPE-$(CONFIG_MACH_STM32F4) := stm32f4 + +flash: $(OUT)klipper.bin + @echo " Flashing $< to $(FLASH_DEVICE)" + $(Q)$(PYTHON) ./scripts/flash_usb.py -t $(FLASH_TYPE-y) -d "$(FLASH_DEVICE)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.bin + +serialflash: $(OUT)klipper.bin + @echo " Flashing $< to $(FLASH_DEVICE) via stm32flash" + $(Q)stm32flash -w $< -v -g 0 $(FLASH_DEVICE) diff --git a/src/stm32f4/adc.c b/src/stm32/adc.c similarity index 97% rename from src/stm32f4/adc.c rename to src/stm32/adc.c index 8cd50b48..b24b9e06 100644 --- a/src/stm32f4/adc.c +++ b/src/stm32/adc.c @@ -1,4 +1,4 @@ -// ADC functions on STM32F4 +// ADC functions on STM32 // // Copyright (C) 2019 Kevin O'Connor // @@ -22,7 +22,7 @@ static const uint8_t adc_pins[] = { GPIO('C', 2), GPIO('C', 3), GPIO('C', 4), GPIO('C', 5) }; -#if CONFIG_MACH_STM32F1xx +#if CONFIG_MACH_STM32F1 #define CR2_FLAGS (ADC_CR2_ADON | (7 << ADC_CR2_EXTSEL_Pos) | ADC_CR2_EXTTRIG) #else #define CR2_FLAGS ADC_CR2_ADON @@ -52,7 +52,7 @@ gpio_adc_setup(uint32_t pin) | (aticks << 21) | (aticks << 24) | (aticks << 27)); ADC1->CR2 = CR2_FLAGS; -#if CONFIG_MACH_STM32F1xx +#if CONFIG_MACH_STM32F1 // Perform calibration udelay(timer_from_us(1)); ADC1->CR2 = ADC_CR2_CAL | CR2_FLAGS; diff --git a/src/stm32f4/clock.c b/src/stm32/clock.c similarity index 100% rename from src/stm32f4/clock.c rename to src/stm32/clock.c diff --git a/src/stm32f4/gpio.c b/src/stm32/gpio.c similarity index 100% rename from src/stm32f4/gpio.c rename to src/stm32/gpio.c diff --git a/src/stm32f4/gpio.h b/src/stm32/gpio.h similarity index 95% rename from src/stm32f4/gpio.h rename to src/stm32/gpio.h index 01c01a1e..c7602504 100644 --- a/src/stm32f4/gpio.h +++ b/src/stm32/gpio.h @@ -1,5 +1,5 @@ -#ifndef __STM32F4_GPIO_H -#define __STM32F4_GPIO_H +#ifndef __STM32_GPIO_H +#define __STM32_GPIO_H #include // uint32_t diff --git a/src/stm32f4/internal.h b/src/stm32/internal.h similarity index 77% rename from src/stm32f4/internal.h rename to src/stm32/internal.h index d19a0b98..0edfefe5 100644 --- a/src/stm32f4/internal.h +++ b/src/stm32/internal.h @@ -1,10 +1,10 @@ -#ifndef __STM32F4_INTERNAL_H -#define __STM32F4_INTERNAL_H -// Local definitions for STM32F4 code +#ifndef __STM32_INTERNAL_H +#define __STM32_INTERNAL_H +// Local definitions for STM32 code -#include "autoconf.h" // CONFIG_MACH_STM32F1xx +#include "autoconf.h" // CONFIG_MACH_STM32F1 -#if CONFIG_MACH_STM32F1xx +#if CONFIG_MACH_STM32F1 #include "stm32f1xx.h" #else #include "stm32f4xx.h" diff --git a/src/stm32f4/main.c b/src/stm32/main.c similarity index 95% rename from src/stm32f4/main.c rename to src/stm32/main.c index 4f4867a6..20549799 100644 --- a/src/stm32f4/main.c +++ b/src/stm32/main.c @@ -1,4 +1,4 @@ -// Main starting point for STM32F4 boards. +// Main starting point for STM32 boards. // // Copyright (C) 2019 Kevin O'Connor // diff --git a/src/stm32f4/serial.c b/src/stm32/serial.c similarity index 99% rename from src/stm32f4/serial.c rename to src/stm32/serial.c index 786b27ae..0142aaa6 100644 --- a/src/stm32f4/serial.c +++ b/src/stm32/serial.c @@ -1,4 +1,4 @@ -// STM32F4 serial +// STM32 serial // // Copyright (C) 2019 Kevin O'Connor // diff --git a/src/stm32f4/spi.c b/src/stm32/spi.c similarity index 98% rename from src/stm32f4/spi.c rename to src/stm32/spi.c index f8852be9..77072958 100644 --- a/src/stm32f4/spi.c +++ b/src/stm32/spi.c @@ -1,4 +1,4 @@ -// SPI functions on STM32F4 +// SPI functions on STM32 // // Copyright (C) 2019 Kevin O'Connor // diff --git a/src/stm32f4/stm32f4.lds.S b/src/stm32/stm32.lds.S similarity index 100% rename from src/stm32f4/stm32f4.lds.S rename to src/stm32/stm32.lds.S diff --git a/src/stm32f4/stm32f1.c b/src/stm32/stm32f1.c similarity index 100% rename from src/stm32f4/stm32f1.c rename to src/stm32/stm32f1.c diff --git a/src/stm32f4/usbfs.c b/src/stm32/usbfs.c similarity index 100% rename from src/stm32f4/usbfs.c rename to src/stm32/usbfs.c diff --git a/src/stm32f4/watchdog.c b/src/stm32/watchdog.c similarity index 93% rename from src/stm32f4/watchdog.c rename to src/stm32/watchdog.c index 2851560a..696d64d6 100644 --- a/src/stm32f4/watchdog.c +++ b/src/stm32/watchdog.c @@ -1,4 +1,4 @@ -// Watchdog handler on STM32F4 +// Watchdog handler on STM32 // // Copyright (C) 2019 Kevin O'Connor // diff --git a/src/stm32f4/Makefile b/src/stm32f4/Makefile deleted file mode 100644 index e39574b2..00000000 --- a/src/stm32f4/Makefile +++ /dev/null @@ -1,63 +0,0 @@ -# Additional STM32F4 build rules - -# Setup the toolchain -CROSS_PREFIX=arm-none-eabi- - -dirs-y += src/stm32f4 src/generic -dirs-$(CONFIG_MACH_STM32F1xx) += lib/stm32f1 lib/stm32f1/gcc -dirs-$(CONFIG_MACH_STM32F4xx) += lib/stm32f4 lib/stm32f4/gcc - -MCU := $(shell echo $(CONFIG_MCU)) -MCU_UPPER := $(shell echo $(CONFIG_MCU) | tr a-z A-Z | tr X x) - -CFLAGS-$(CONFIG_MACH_STM32F1xx) += -mcpu=cortex-m3 -Ilib/stm32f1/include -CFLAGS-$(CONFIG_MACH_STM32F4xx) += -mcpu=cortex-m4 -Ilib/stm32f4/include -CFLAGS-$(CONFIG_MACH_STM32F4xx) += -mfpu=fpv4-sp-d16 -mfloat-abi=hard - -CFLAGS += $(CFLAGS-y) -D$(MCU_UPPER) -mthumb -Ilib/cmsis-core -CFLAGS_klipper.elf += -T $(OUT)stm32f4.ld --specs=nano.specs --specs=nosys.specs - -# Add source files -src-y += stm32f4/main.c stm32f4/watchdog.c stm32f4/gpio.c -src-y += generic/crc16_ccitt.c generic/armcm_irq.c generic/armcm_timer.c -src-$(CONFIG_MACH_STM32F1xx) += ../lib/stm32f1/system_stm32f1xx.c -src-$(CONFIG_MACH_STM32F1xx) += stm32f4/stm32f1.c -src-$(CONFIG_MACH_STM32F4xx) += ../lib/stm32f4/system_stm32f4xx.c -src-$(CONFIG_MACH_STM32F4xx) += stm32f4/clock.c -src-$(CONFIG_HAVE_GPIO_ADC) += stm32f4/adc.c -src-$(CONFIG_HAVE_GPIO_SPI) += stm32f4/spi.c -src-$(CONFIG_USBSERIAL) += stm32f4/usbfs.c generic/usb_cdc.c -src-$(CONFIG_SERIAL) += stm32f4/serial.c generic/serial_irq.c - -# Add assembler build rules -$(OUT)%.o: %.s $(OUT)autoconf.h $(OUT)board-link - @echo " Assembling $@" - $(Q)$(AS) $< -o $@ - -asmsrc-$(CONFIG_MACH_STM32F1xx) := ../lib/stm32f1/gcc/startup_$(MCU).s -asmsrc-$(CONFIG_MACH_STM32F4xx) := ../lib/stm32f4/gcc/startup_$(MCU).s -OBJS_klipper.elf += $(patsubst %.s, $(OUT)src/%.o,$(asmsrc-y)) - -# Build the linker script -$(OUT)stm32f4.ld: src/stm32f4/stm32f4.lds.S $(OUT)board-link - @echo " Preprocessing $@" - $(Q)$(CPP) -I$(OUT) -P -MD -MT $@ $< -o $@ -$(OUT)klipper.elf: $(OUT)stm32f4.ld - -# Binary output file rules -target-y += $(OUT)klipper.bin - -$(OUT)klipper.bin: $(OUT)klipper.elf - @echo " Creating hex file $@" - $(Q)$(OBJCOPY) -O binary $< $@ - -FLASH_TYPE-$(CONFIG_MACH_STM32F1xx) := stm32f1 -FLASH_TYPE-$(CONFIG_MACH_STM32F4xx) := stm32f4 - -flash: $(OUT)klipper.bin - @echo " Flashing $< to $(FLASH_DEVICE)" - $(Q)$(PYTHON) ./scripts/flash_usb.py -t $(FLASH_TYPE-y) -d "$(FLASH_DEVICE)" $(if $(NOSUDO),--no-sudo) $(OUT)klipper.bin - -serialflash: $(OUT)klipper.bin - @echo " Flashing $< to $(FLASH_DEVICE) via stm32flash" - $(Q)stm32flash -w $< -v -g 0 $(FLASH_DEVICE) diff --git a/test/configs/stm32f1.config b/test/configs/stm32f1.config index b8b38826..9170fb06 100644 --- a/test/configs/stm32f1.config +++ b/test/configs/stm32f1.config @@ -1,2 +1,3 @@ # Base config file for STM32F1 ARM processor -CONFIG_MACH_STM32F1=y +CONFIG_MACH_STM32=y +CONFIG_MACH_STM32F103=y