From cdb5b56911737d31ec8fa21b58a940ea4753ea59 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 16 May 2025 17:56:34 -0400 Subject: [PATCH] stm32: Add support for stm32g431 chips Signed-off-by: Kevin O'Connor --- src/stm32/Kconfig | 4 ++-- src/stm32/Makefile | 4 ++++ src/stm32/flash.c | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/stm32/Kconfig b/src/stm32/Kconfig index a3cd0ea..b6baf1a 100644 --- a/src/stm32/Kconfig +++ b/src/stm32/Kconfig @@ -73,7 +73,7 @@ choice select MACH_STM32G0 select MACH_STM32G0Bx config MACH_STM32G431 - bool "STM32G431" if 0 + bool "STM32G431" select MACH_STM32G4 config MACH_STM32H723 bool "STM32H723" @@ -498,7 +498,7 @@ choice config STM32_APP_START_4000 bool "16KiB offset" if MACH_STM32F2 || MACH_STM32F4 config STM32_APP_START_2000 - bool "8KiB offset" if MACH_STM32F0 || MACH_STM32F1 || MACH_STM32G0 + bool "8KiB offset" if MACH_STM32F0 || MACH_STM32F1 || MACH_STM32G0 || MACH_STM32G4 config STM32_APP_START_1000 bool "4KiB offset" if MACH_STM32F0 || MACH_STM32F1 || MACH_STM32G0 endchoice diff --git a/src/stm32/Makefile b/src/stm32/Makefile index 057761a..bd95028 100644 --- a/src/stm32/Makefile +++ b/src/stm32/Makefile @@ -9,6 +9,7 @@ dirs-$(CONFIG_MACH_STM32F1) += lib/stm32f1 dirs-$(CONFIG_MACH_STM32F2) += lib/stm32f2 dirs-$(CONFIG_MACH_STM32F4) += lib/stm32f4 dirs-$(CONFIG_MACH_STM32G0) += lib/stm32g0 +dirs-$(CONFIG_MACH_STM32G4) += lib/stm32g4 dirs-$(CONFIG_MACH_STM32H7) += lib/stm32h7 MCU := $(shell echo $(CONFIG_MCU)) @@ -19,6 +20,7 @@ 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_STM32G0) += -mcpu=cortex-m0plus -Ilib/stm32g0/include +CFLAGS-$(CONFIG_MACH_STM32G4) += -mcpu=cortex-m4 -Ilib/stm32g4/include CFLAGS-$(CONFIG_MACH_STM32H7) += -mcpu=cortex-m7 -Ilib/stm32h7/include CFLAGS += $(CFLAGS-y) -D$(MCU_UPPER) -mthumb -Ilib/cmsis-core -Ilib/fast-hash @@ -34,6 +36,7 @@ src-$(CONFIG_MACH_STM32F1) += stm32/stm32f1.c ../lib/stm32f1/system_stm32f1xx.c src-$(CONFIG_MACH_STM32F2) += stm32/stm32f4.c ../lib/stm32f2/system_stm32f2xx.c src-$(CONFIG_MACH_STM32F4) += stm32/stm32f4.c ../lib/stm32f4/system_stm32f4xx.c src-$(CONFIG_MACH_STM32G0) += stm32/stm32g0.c +src-$(CONFIG_MACH_STM32G4) += stm32/stm32g4.c ../lib/stm32g4/system_stm32g4xx.c src-$(CONFIG_MACH_STM32H7) += stm32/stm32h7.c ../lib/stm32h7/system_stm32h7xx.c timer-src-y := generic/armcm_timer.c timer-src-$(CONFIG_MACH_STM32F0) := generic/timer_irq.c stm32/stm32f0_timer.c @@ -44,6 +47,7 @@ src-y += $(timer-src-y) $(gpio-src-y) serial-src-y := stm32/serial.c serial-src-$(CONFIG_MACH_STM32F0) := stm32/stm32f0_serial.c serial-src-$(CONFIG_MACH_STM32G0) := stm32/stm32f0_serial.c +serial-src-$(CONFIG_MACH_STM32G4) := stm32/stm32f0_serial.c serial-src-$(CONFIG_MACH_STM32H7) := stm32/stm32f0_serial.c src-$(CONFIG_SERIAL) += $(serial-src-y) generic/serial_irq.c usb-src-$(CONFIG_HAVE_STM32_USBFS) := stm32/usbfs.c diff --git a/src/stm32/flash.c b/src/stm32/flash.c index 50332ee..229aa34 100644 --- a/src/stm32/flash.c +++ b/src/stm32/flash.c @@ -32,7 +32,7 @@ flash_get_page_size(uint32_t addr) return 2 * 1024; uint16_t *flash_size = (void*)FLASHSIZE_BASE; return *flash_size <= 64 ? 1024 : 2 * 1024; - } else if (CONFIG_MACH_STM32G0) { + } else if (CONFIG_MACH_STM32G0 || CONFIG_MACH_STM32G4) { return 2 * 1024; } else if (CONFIG_MACH_STM32H7) { return 128 * 1024; @@ -110,7 +110,7 @@ erase_page(uint32_t page_address) FLASH->CR = FLASH_CR_PER; FLASH->AR = page_address; FLASH->CR = FLASH_CR_PER | FLASH_CR_STRT; -#elif CONFIG_MACH_STM32G0 +#elif CONFIG_MACH_STM32G0 || CONFIG_MACH_STM32G4 uint32_t pidx = (page_address - 0x08000000) / (2 * 1024); if (pidx >= 64) { uint16_t *flash_size = (void*)FLASHSIZE_BASE; @@ -150,7 +150,7 @@ write_block(uint32_t block_address, uint32_t *data) writew(&page[i], data16[i]); wait_flash(); } -#elif CONFIG_MACH_STM32G0 +#elif CONFIG_MACH_STM32G0 || CONFIG_MACH_STM32G4 uint32_t *page = (void*)block_address; FLASH->CR = FLASH_CR_PG; for (int i = 0; i < CONFIG_BLOCK_SIZE / 8; i++) {