mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-05 13:33:51 +00:00
[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的依赖关系
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user