stm32: Add support for stm32g431 chips

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2025-05-16 17:56:34 -04:00 committed by Eric Callahan
parent dd69900b99
commit cdb5b56911
3 changed files with 9 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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++) {