summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgodmial <[email protected]>2025-12-01 14:47:53 +0800
committerGitHub <[email protected]>2025-12-01 14:47:53 +0800
commit2fb53c83c5d41fed43f347071ce189f104b2e5d7 (patch)
tree6e1ec08f7f9984bcc5833d86c975da5e3f3d75f7
parent75d6c1cec580a207e07ce875cfa870b366d3576e (diff)
[bsp][spi flash]: 优化GD32F470 SPI Flash初始化和UART0配置 (#10983)
* feat(gd32): 优化GD32F470 SPI Flash初始化和UART0配置 主要修改: 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初始化,避免自动初始化导致的设备冲突问题。 * feat(gd32): 解耦SPI Flash与SFUD的依赖关系
-rw-r--r--bsp/gd32/arm/gd32470z-lckfb/.config2
-rw-r--r--bsp/gd32/arm/gd32470z-lckfb/board/Kconfig57
-rw-r--r--bsp/gd32/arm/gd32470z-lckfb/rtconfig.h2
-rw-r--r--bsp/gd32/arm/libraries/gd32_drivers/drv_spi_flash.c28
4 files changed, 81 insertions, 8 deletions
diff --git a/bsp/gd32/arm/gd32470z-lckfb/.config b/bsp/gd32/arm/gd32470z-lckfb/.config
index 62ab51945f..0798ecfb02 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 2cf71f29b7..806989c9ab 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 bad10a43fb..60c60a7a4d 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 b61d42f0f4..99f36c81d9 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 <board.h>
#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);