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..806989c9abf 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,61 @@ 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 + 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 + 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..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,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 + * 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) */ #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);