From b8803c3ab79a696bb192802b836ebe6fc3db9f64 Mon Sep 17 00:00:00 2001 From: godmial Date: Fri, 28 Nov 2025 15:41:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(gd32):=20=E4=BC=98=E5=8C=96GD32F470=20?= =?UTF-8?q?SPI=20Flash=E5=88=9D=E5=A7=8B=E5=8C=96=E5=92=8CUART0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 主要修改: 1. SPI Flash初始化优化 - 添加可配置的SPI Flash自动初始化选项(BSP_USING_SPI_FLASH) - 支持按SPI总线独立配置Flash初始化(BSP_USING_SPIx_FLASH) - 避免SPI Flash初始化与其他SPI设备(如OLED、WIFI)冲突 - 添加SPI5 Flash支持 - 修改drv_spi_flash.c,仅在明确配置的SPI总线上初始化Flash 2. UART0配置修复 - 将UART0的AFIO默认值从AF1改为AF7 - 修复串口无响应问题 这些修改使得用户可以更灵活地配置SPI Flash初始化,避免自动初始化导致的设备冲突问题。 --- bsp/gd32/arm/gd32470z-lckfb/.config | 2 +- bsp/gd32/arm/gd32470z-lckfb/board/Kconfig | 56 ++++++++++++++++++- bsp/gd32/arm/gd32470z-lckfb/rtconfig.h | 2 +- .../libraries/gd32_drivers/drv_spi_flash.c | 28 ++++++++-- 4 files changed, 80 insertions(+), 8 deletions(-) diff --git a/bsp/gd32/arm/gd32470z-lckfb/.config b/bsp/gd32/arm/gd32470z-lckfb/.config index 62ab51945f6..0798ecfb021 100644 --- a/bsp/gd32/arm/gd32470z-lckfb/.config +++ b/bsp/gd32/arm/gd32470z-lckfb/.config @@ -1447,7 +1447,7 @@ CONFIG_BSP_USING_SERIAL_V1=y CONFIG_BSP_USING_UART0=y CONFIG_BSP_UART0_TX_PIN="PA9" CONFIG_BSP_UART0_RX_PIN="PA10" -CONFIG_BSP_UART0_AFIO="AF1" +CONFIG_BSP_UART0_AFIO="AF7" # CONFIG_BSP_USING_UART1 is not set # CONFIG_BSP_USING_UART2 is not set # CONFIG_BSP_USING_UART3 is not set diff --git a/bsp/gd32/arm/gd32470z-lckfb/board/Kconfig b/bsp/gd32/arm/gd32470z-lckfb/board/Kconfig index 2cf71f29b7c..c152c757198 100644 --- a/bsp/gd32/arm/gd32470z-lckfb/board/Kconfig +++ b/bsp/gd32/arm/gd32470z-lckfb/board/Kconfig @@ -53,7 +53,7 @@ menu "On-chip Peripheral Drivers" config BSP_UART0_AFIO string "UART0 alternate function, such as AF7" - default "AF1" + default "AF7" if BSP_USING_SERIAL_V2 config BSP_UART0_RX_USING_DMA @@ -254,6 +254,60 @@ menu "On-chip Peripheral Drivers" depends on BSP_USING_SPI4 select BSP_SPI4_TX_USING_DMA default n + + menuconfig BSP_USING_SPI_FLASH + bool "Enable SPI Flash auto initialization" + depends on RT_USING_SPI + select RT_USING_SFUD + default n + help + Enable automatic SPI Flash initialization on selected SPI buses. + Note: Only enable this for SPI buses that are actually connected to SPI Flash. + If a SPI bus is used for other devices (e.g., OLED, WIFI), do not enable flash initialization for it. + + if BSP_USING_SPI_FLASH + config BSP_USING_SPI0_FLASH + bool "Enable SPI Flash on SPI0" + depends on BSP_USING_SPI0 + default n + help + Enable SPI Flash initialization on SPI0 bus. + + config BSP_USING_SPI1_FLASH + bool "Enable SPI Flash on SPI1" + depends on BSP_USING_SPI1 + default n + help + Enable SPI Flash initialization on SPI1 bus. + + config BSP_USING_SPI2_FLASH + bool "Enable SPI Flash on SPI2" + depends on BSP_USING_SPI2 + default n + help + Enable SPI Flash initialization on SPI2 bus. + + config BSP_USING_SPI3_FLASH + bool "Enable SPI Flash on SPI3" + depends on BSP_USING_SPI3 + default n + help + Enable SPI Flash initialization on SPI3 bus. + + config BSP_USING_SPI4_FLASH + bool "Enable SPI Flash on SPI4" + depends on BSP_USING_SPI4 + default n + help + Enable SPI Flash initialization on SPI4 bus. + + config BSP_USING_SPI5_FLASH + bool "Enable SPI Flash on SPI5" + depends on BSP_USING_SPI5 + default n + help + Enable SPI Flash initialization on SPI5 bus. + endif endif menuconfig BSP_USING_ADC diff --git a/bsp/gd32/arm/gd32470z-lckfb/rtconfig.h b/bsp/gd32/arm/gd32470z-lckfb/rtconfig.h index bad10a43fb1..60c60a7a4d4 100644 --- a/bsp/gd32/arm/gd32470z-lckfb/rtconfig.h +++ b/bsp/gd32/arm/gd32470z-lckfb/rtconfig.h @@ -428,7 +428,7 @@ #define BSP_USING_UART0 #define BSP_UART0_TX_PIN "PA9" #define BSP_UART0_RX_PIN "PA10" -#define BSP_UART0_AFIO "AF1" +#define BSP_UART0_AFIO "AF7" #define BSP_USING_GD_DBG /* end of On-chip Peripheral Drivers */ diff --git a/bsp/gd32/arm/libraries/gd32_drivers/drv_spi_flash.c b/bsp/gd32/arm/libraries/gd32_drivers/drv_spi_flash.c index b61d42f0f4c..d58ff053af9 100644 --- a/bsp/gd32/arm/libraries/gd32_drivers/drv_spi_flash.c +++ b/bsp/gd32/arm/libraries/gd32_drivers/drv_spi_flash.c @@ -8,6 +8,10 @@ * 2021-12-31 BruceOu first implementation * 2023-06-03 CX fixed sf probe error bug * 2024-05-30 godmial refactor driver for multi-SPI bus auto-mount + * 2024-12-XX godmial add configurable SPI Flash initialization + * Only initialize flash on SPI buses explicitly configured + * via BSP_USING_SPIx_FLASH options to avoid conflicts + * with other SPI devices (e.g., OLED, WIFI) */ #include #include "drv_spi.h" @@ -34,7 +38,7 @@ struct spi_flash_config static const struct spi_flash_config flash_configs[] = { -#ifdef BSP_USING_SPI0 +#if defined(BSP_USING_SPI0) && defined(BSP_USING_SPI0_FLASH) { .bus_name = "spi0", .device_name = "spi00", @@ -43,7 +47,7 @@ static const struct spi_flash_config flash_configs[] = }, #endif -#ifdef BSP_USING_SPI1 +#if defined(BSP_USING_SPI1) && defined(BSP_USING_SPI1_FLASH) { .bus_name = "spi1", .device_name = "spi10", @@ -52,7 +56,7 @@ static const struct spi_flash_config flash_configs[] = }, #endif -#ifdef BSP_USING_SPI2 +#if defined(BSP_USING_SPI2) && defined(BSP_USING_SPI2_FLASH) { .bus_name = "spi2", .device_name = "spi20", @@ -61,7 +65,7 @@ static const struct spi_flash_config flash_configs[] = }, #endif -#ifdef BSP_USING_SPI3 +#if defined(BSP_USING_SPI3) && defined(BSP_USING_SPI3_FLASH) { .bus_name = "spi3", .device_name = "spi30", @@ -70,7 +74,7 @@ static const struct spi_flash_config flash_configs[] = }, #endif -#ifdef BSP_USING_SPI4 +#if defined(BSP_USING_SPI4) && defined(BSP_USING_SPI4_FLASH) { .bus_name = "spi4", .device_name = "spi40", @@ -78,11 +82,21 @@ static const struct spi_flash_config flash_configs[] = .cs_pin = GET_PIN(F, 6), }, #endif + +#if defined(BSP_USING_SPI5) && defined(BSP_USING_SPI5_FLASH) + { + .bus_name = "spi5", + .device_name = "spi50", + .flash_name = "gd25q_spi5", + .cs_pin = GET_PIN(F, 6), /* Note: Update CS pin according to actual hardware */ + }, +#endif }; static int spi_flash_init(void) { +#ifdef BSP_USING_SPI_FLASH int result = RT_EOK; for (size_t i = 0; i < sizeof(flash_configs) / sizeof(flash_configs[0]); i++) @@ -106,5 +120,9 @@ static int spi_flash_init(void) } return result; +#else + /* SPI Flash auto-initialization is disabled. User should initialize SPI Flash manually in board code. */ + return RT_EOK; +#endif } INIT_COMPONENT_EXPORT(spi_flash_init); From 251b417d6df93941727a49295aeb71492d8b4df5 Mon Sep 17 00:00:00 2001 From: godmial Date: Mon, 1 Dec 2025 11:57:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat(gd32):=20=E8=A7=A3=E8=80=A6SPI=20Flash?= =?UTF-8?q?=E4=B8=8ESFUD=E7=9A=84=E4=BE=9D=E8=B5=96=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/gd32/arm/gd32470z-lckfb/board/Kconfig | 3 ++- bsp/gd32/arm/libraries/gd32_drivers/drv_spi_flash.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bsp/gd32/arm/gd32470z-lckfb/board/Kconfig b/bsp/gd32/arm/gd32470z-lckfb/board/Kconfig index c152c757198..806989c9abf 100644 --- a/bsp/gd32/arm/gd32470z-lckfb/board/Kconfig +++ b/bsp/gd32/arm/gd32470z-lckfb/board/Kconfig @@ -258,14 +258,15 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_SPI_FLASH bool "Enable SPI Flash auto initialization" depends on RT_USING_SPI - select RT_USING_SFUD default n help Enable automatic SPI Flash initialization on selected SPI buses. Note: Only enable this for SPI buses that are actually connected to SPI Flash. If a SPI bus is used for other devices (e.g., OLED, WIFI), do not enable flash initialization for it. + Note: This feature can work with or without SFUD. If you want to use SFUD, enable it in SPI driver menu. if BSP_USING_SPI_FLASH + config BSP_USING_SPI0_FLASH bool "Enable SPI Flash on SPI0" depends on BSP_USING_SPI0 diff --git a/bsp/gd32/arm/libraries/gd32_drivers/drv_spi_flash.c b/bsp/gd32/arm/libraries/gd32_drivers/drv_spi_flash.c index d58ff053af9..99f36c81d96 100644 --- a/bsp/gd32/arm/libraries/gd32_drivers/drv_spi_flash.c +++ b/bsp/gd32/arm/libraries/gd32_drivers/drv_spi_flash.c @@ -8,7 +8,7 @@ * 2021-12-31 BruceOu first implementation * 2023-06-03 CX fixed sf probe error bug * 2024-05-30 godmial refactor driver for multi-SPI bus auto-mount - * 2024-12-XX godmial add configurable SPI Flash initialization + * 2025-11-28 godmial add configurable SPI Flash initialization * Only initialize flash on SPI buses explicitly configured * via BSP_USING_SPIx_FLASH options to avoid conflicts * with other SPI devices (e.g., OLED, WIFI)