diff options
author | combolek <4743344+combolek@users.noreply.github.com> | 2020-06-23 07:52:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-23 10:52:15 -0400 |
commit | 7cab732ae9baf5cf6da716f06dc82942426a1712 (patch) | |
tree | ab3f2fbd5ab1613f26c32008590796bb7ca72ef7 /src | |
parent | a4c31bafb0c86b679c591fc0ab693b4fdef6114e (diff) | |
download | kutter-7cab732ae9baf5cf6da716f06dc82942426a1712.tar.gz kutter-7cab732ae9baf5cf6da716f06dc82942426a1712.tar.xz kutter-7cab732ae9baf5cf6da716f06dc82942426a1712.zip |
stm32: Initial support for stm32f2 (#3001)
Initial support for stm32f2 in general and STM32F207 in particular.
Boots up and communicates on STM32F207VC.
Signed-off-by: Boleslaw Ciesielski <combolek@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/stm32/Kconfig | 17 | ||||
-rw-r--r-- | src/stm32/Makefile | 5 | ||||
-rw-r--r-- | src/stm32/internal.h | 2 | ||||
-rw-r--r-- | src/stm32/stm32f4.c | 28 |
4 files changed, 46 insertions, 6 deletions
diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig index 4e02798f..5d6ef82b 100644 --- a/src/stm32/Kconfig +++ b/src/stm32/Kconfig @@ -22,6 +22,9 @@ choice config MACH_STM32F103 bool "STM32F103" select MACH_STM32F1 + config MACH_STM32F207 + bool "STM32F207" + select MACH_STM32F2 config MACH_STM32F405 bool "STM32F405" select MACH_STM32F4 @@ -43,6 +46,8 @@ config MACH_STM32F0 bool config MACH_STM32F1 bool +config MACH_STM32F2 + bool config MACH_STM32F4 bool config HAVE_STM32_USBFS @@ -51,7 +56,7 @@ config HAVE_STM32_USBFS default n config HAVE_STM32_USBOTG bool - default y if MACH_STM32F4 + default y if MACH_STM32F2 || MACH_STM32F4 default n config MCU @@ -59,6 +64,7 @@ config MCU default "stm32f042x6" if MACH_STM32F042 default "stm32f070xb" if MACH_STM32F070 default "stm32f103xe" if MACH_STM32F103 + default "stm32f207xx" if MACH_STM32F207 default "stm32f405xx" if MACH_STM32F405 default "stm32f407xx" if MACH_STM32F407 default "stm32f446xx" if MACH_STM32F446 @@ -68,6 +74,7 @@ config CLOCK_FREQ default 48000000 if MACH_STM32F0 default 64000000 if MACH_STM32F103 && STM32_CLOCK_REF_INTERNAL default 72000000 if MACH_STM32F103 + default 120000000 if MACH_STM32F207 default 168000000 if MACH_STM32F405 || MACH_STM32F407 default 180000000 if MACH_STM32F446 @@ -76,6 +83,7 @@ config FLASH_SIZE default 0x8000 if MACH_STM32F042 default 0x20000 if MACH_STM32F070 default 0x10000 if MACH_STM32F103 # Flash size of stm32f103x8 (64KiB) + default 0x40000 if MACH_STM32F2 default 0x80000 if MACH_STM32F4 config RAM_START @@ -87,6 +95,7 @@ config RAM_SIZE default 0x1800 if MACH_STM32F042 default 0x4000 if MACH_STM32F070 default 0x5000 if MACH_STM32F103 # Ram size of stm32f103x8 (20KiB) + default 0x20000 if MACH_STM32F207 default 0x20000 if MACH_STM32F4 config STACK_SIZE @@ -94,19 +103,19 @@ config STACK_SIZE default 512 choice - prompt "Bootloader offset" if MACH_STM32F407 || MACH_STM32F405 || MACH_STM32F103 || MACH_STM32F070 + prompt "Bootloader offset" if MACH_STM32F207 || MACH_STM32F407 || MACH_STM32F405 || MACH_STM32F103 || MACH_STM32F070 config STM32_FLASH_START_800 bool "2KiB bootloader (HID Bootloader)" if MACH_STM32F103 config STM32_FLASH_START_2000 bool "8KiB bootloader (stm32duino)" if MACH_STM32F103 || MACH_STM32F070 config STM32_FLASH_START_4000 - bool "16KiB bootloader (HID Bootloader)" if MACH_STM32F405 || MACH_STM32F407 + bool "16KiB bootloader (HID Bootloader)" if MACH_STM32F207 || MACH_STM32F405 || MACH_STM32F407 config STM32_FLASH_START_5000 bool "20KiB bootloader" if MACH_STM32F103 config STM32_FLASH_START_7000 bool "28KiB bootloader" if MACH_STM32F103 config STM32_FLASH_START_8000 - bool "32KiB bootloader (SKR-PRO)" if MACH_STM32F407 + bool "32KiB bootloader (SKR-PRO or TFT35-V3.0)" if MACH_STM32F207 || MACH_STM32F407 config STM32_FLASH_START_10000 bool "64KiB bootloader (Alfawise)" if MACH_STM32F103 config STM32_FLASH_START_0000 diff --git a/src/stm32/Makefile b/src/stm32/Makefile index dc8768a2..98b52e4c 100644 --- a/src/stm32/Makefile +++ b/src/stm32/Makefile @@ -6,6 +6,7 @@ CROSS_PREFIX=arm-none-eabi- dirs-y += src/stm32 src/generic dirs-$(CONFIG_MACH_STM32F0) += lib/stm32f0 dirs-$(CONFIG_MACH_STM32F1) += lib/stm32f1 +dirs-$(CONFIG_MACH_STM32F2) += lib/stm32f2 dirs-$(CONFIG_MACH_STM32F4) += lib/stm32f4 MCU := $(shell echo $(CONFIG_MCU)) @@ -13,6 +14,7 @@ MCU_UPPER := $(shell echo $(CONFIG_MCU) | tr a-z A-Z | tr X x) CFLAGS-$(CONFIG_MACH_STM32F0) += -mcpu=cortex-m0 -Ilib/stm32f0/include CFLAGS-$(CONFIG_MACH_STM32F1) += -mcpu=cortex-m3 -Ilib/stm32f1/include +CFLAGS-$(CONFIG_MACH_STM32F2) += -mcpu=cortex-m3 -Ilib/stm32f2/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 @@ -31,6 +33,9 @@ src-$(CONFIG_MACH_STM32F0) += stm32/stm32f0_i2c.c src-$(CONFIG_MACH_STM32F1) += ../lib/stm32f1/system_stm32f1xx.c src-$(CONFIG_MACH_STM32F1) += stm32/stm32f1.c generic/armcm_timer.c src-$(CONFIG_MACH_STM32F1) += stm32/adc.c stm32/i2c.c +src-$(CONFIG_MACH_STM32F2) += ../lib/stm32f2/system_stm32f2xx.c +src-$(CONFIG_MACH_STM32F2) += stm32/stm32f4.c generic/armcm_timer.c +src-$(CONFIG_MACH_STM32F2) += stm32/adc.c stm32/i2c.c src-$(CONFIG_MACH_STM32F4) += ../lib/stm32f4/system_stm32f4xx.c src-$(CONFIG_MACH_STM32F4) += stm32/stm32f4.c generic/armcm_timer.c src-$(CONFIG_MACH_STM32F4) += stm32/adc.c stm32/i2c.c diff --git a/src/stm32/internal.h b/src/stm32/internal.h index abe879c1..2538bbaa 100644 --- a/src/stm32/internal.h +++ b/src/stm32/internal.h @@ -8,6 +8,8 @@ #include "stm32f0xx.h" #elif CONFIG_MACH_STM32F1 #include "stm32f1xx.h" +#elif CONFIG_MACH_STM32F2 +#include "stm32f2xx.h" #elif CONFIG_MACH_STM32F4 #include "stm32f4xx.h" #endif diff --git a/src/stm32/stm32f4.c b/src/stm32/stm32f4.c index 9b5433af..bc8d0eb2 100644 --- a/src/stm32/stm32f4.c +++ b/src/stm32/stm32f4.c @@ -1,4 +1,4 @@ -// Code to setup clocks and gpio on stm32f4 +// Code to setup clocks and gpio on stm32f2/stm32f4 // // Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net> // @@ -119,6 +119,28 @@ DECL_CONSTANT_STR("RESERVE_PINS_crystal", "PH0,PH1"); // Clock configuration static void +enable_clock_stm32f20x(void) +{ +#if CONFIG_MACH_STM32F207 + uint32_t pll_base = 1000000, pll_freq = CONFIG_CLOCK_FREQ * 2, pllcfgr; + if (!CONFIG_STM32_CLOCK_REF_INTERNAL) { + // Configure 120Mhz PLL from external crystal (HSE) + uint32_t div = CONFIG_CLOCK_REF_FREQ / pll_base; + RCC->CR |= RCC_CR_HSEON; + pllcfgr = RCC_PLLCFGR_PLLSRC_HSE | (div << RCC_PLLCFGR_PLLM_Pos); + } else { + // Configure 120Mhz PLL from internal 16Mhz oscillator (HSI) + uint32_t div = 16000000 / pll_base; + pllcfgr = RCC_PLLCFGR_PLLSRC_HSI | (div << RCC_PLLCFGR_PLLM_Pos); + } + RCC->PLLCFGR = (pllcfgr | ((pll_freq/pll_base) << RCC_PLLCFGR_PLLN_Pos) + | (0 << RCC_PLLCFGR_PLLP_Pos) + | ((pll_freq/FREQ_USB) << RCC_PLLCFGR_PLLQ_Pos)); + RCC->CR |= RCC_CR_PLLON; +#endif +} + +static void enable_clock_stm32f40x(void) { #if CONFIG_MACH_STM32F405 || CONFIG_MACH_STM32F407 @@ -194,7 +216,9 @@ static void clock_setup(void) { // Configure and enable PLL - if (CONFIG_MACH_STM32F405 || CONFIG_MACH_STM32F407) + if (CONFIG_MACH_STM32F207) + enable_clock_stm32f20x(); + else if (CONFIG_MACH_STM32F405 || CONFIG_MACH_STM32F407) enable_clock_stm32f40x(); else enable_clock_stm32f446(); |