Skip to content

Commit 2fb53c8

Browse files
authored
[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的依赖关系
1 parent 75d6c1c commit 2fb53c8

File tree

4 files changed

+81
-8
lines changed

4 files changed

+81
-8
lines changed

bsp/gd32/arm/gd32470z-lckfb/.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ CONFIG_BSP_USING_SERIAL_V1=y
14471447
CONFIG_BSP_USING_UART0=y
14481448
CONFIG_BSP_UART0_TX_PIN="PA9"
14491449
CONFIG_BSP_UART0_RX_PIN="PA10"
1450-
CONFIG_BSP_UART0_AFIO="AF1"
1450+
CONFIG_BSP_UART0_AFIO="AF7"
14511451
# CONFIG_BSP_USING_UART1 is not set
14521452
# CONFIG_BSP_USING_UART2 is not set
14531453
# CONFIG_BSP_USING_UART3 is not set

bsp/gd32/arm/gd32470z-lckfb/board/Kconfig

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ menu "On-chip Peripheral Drivers"
5353

5454
config BSP_UART0_AFIO
5555
string "UART0 alternate function, such as AF7"
56-
default "AF1"
56+
default "AF7"
5757

5858
if BSP_USING_SERIAL_V2
5959
config BSP_UART0_RX_USING_DMA
@@ -254,6 +254,61 @@ menu "On-chip Peripheral Drivers"
254254
depends on BSP_USING_SPI4
255255
select BSP_SPI4_TX_USING_DMA
256256
default n
257+
258+
menuconfig BSP_USING_SPI_FLASH
259+
bool "Enable SPI Flash auto initialization"
260+
depends on RT_USING_SPI
261+
default n
262+
help
263+
Enable automatic SPI Flash initialization on selected SPI buses.
264+
Note: Only enable this for SPI buses that are actually connected to SPI Flash.
265+
If a SPI bus is used for other devices (e.g., OLED, WIFI), do not enable flash initialization for it.
266+
Note: This feature can work with or without SFUD. If you want to use SFUD, enable it in SPI driver menu.
267+
268+
if BSP_USING_SPI_FLASH
269+
270+
config BSP_USING_SPI0_FLASH
271+
bool "Enable SPI Flash on SPI0"
272+
depends on BSP_USING_SPI0
273+
default n
274+
help
275+
Enable SPI Flash initialization on SPI0 bus.
276+
277+
config BSP_USING_SPI1_FLASH
278+
bool "Enable SPI Flash on SPI1"
279+
depends on BSP_USING_SPI1
280+
default n
281+
help
282+
Enable SPI Flash initialization on SPI1 bus.
283+
284+
config BSP_USING_SPI2_FLASH
285+
bool "Enable SPI Flash on SPI2"
286+
depends on BSP_USING_SPI2
287+
default n
288+
help
289+
Enable SPI Flash initialization on SPI2 bus.
290+
291+
config BSP_USING_SPI3_FLASH
292+
bool "Enable SPI Flash on SPI3"
293+
depends on BSP_USING_SPI3
294+
default n
295+
help
296+
Enable SPI Flash initialization on SPI3 bus.
297+
298+
config BSP_USING_SPI4_FLASH
299+
bool "Enable SPI Flash on SPI4"
300+
depends on BSP_USING_SPI4
301+
default n
302+
help
303+
Enable SPI Flash initialization on SPI4 bus.
304+
305+
config BSP_USING_SPI5_FLASH
306+
bool "Enable SPI Flash on SPI5"
307+
depends on BSP_USING_SPI5
308+
default n
309+
help
310+
Enable SPI Flash initialization on SPI5 bus.
311+
endif
257312
endif
258313

259314
menuconfig BSP_USING_ADC

bsp/gd32/arm/gd32470z-lckfb/rtconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@
428428
#define BSP_USING_UART0
429429
#define BSP_UART0_TX_PIN "PA9"
430430
#define BSP_UART0_RX_PIN "PA10"
431-
#define BSP_UART0_AFIO "AF1"
431+
#define BSP_UART0_AFIO "AF7"
432432
#define BSP_USING_GD_DBG
433433
/* end of On-chip Peripheral Drivers */
434434

bsp/gd32/arm/libraries/gd32_drivers/drv_spi_flash.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
* 2021-12-31 BruceOu first implementation
99
* 2023-06-03 CX fixed sf probe error bug
1010
* 2024-05-30 godmial refactor driver for multi-SPI bus auto-mount
11+
* 2025-11-28 godmial add configurable SPI Flash initialization
12+
* Only initialize flash on SPI buses explicitly configured
13+
* via BSP_USING_SPIx_FLASH options to avoid conflicts
14+
* with other SPI devices (e.g., OLED, WIFI)
1115
*/
1216
#include <board.h>
1317
#include "drv_spi.h"
@@ -34,7 +38,7 @@ struct spi_flash_config
3438

3539
static const struct spi_flash_config flash_configs[] =
3640
{
37-
#ifdef BSP_USING_SPI0
41+
#if defined(BSP_USING_SPI0) && defined(BSP_USING_SPI0_FLASH)
3842
{
3943
.bus_name = "spi0",
4044
.device_name = "spi00",
@@ -43,7 +47,7 @@ static const struct spi_flash_config flash_configs[] =
4347
},
4448
#endif
4549

46-
#ifdef BSP_USING_SPI1
50+
#if defined(BSP_USING_SPI1) && defined(BSP_USING_SPI1_FLASH)
4751
{
4852
.bus_name = "spi1",
4953
.device_name = "spi10",
@@ -52,7 +56,7 @@ static const struct spi_flash_config flash_configs[] =
5256
},
5357
#endif
5458

55-
#ifdef BSP_USING_SPI2
59+
#if defined(BSP_USING_SPI2) && defined(BSP_USING_SPI2_FLASH)
5660
{
5761
.bus_name = "spi2",
5862
.device_name = "spi20",
@@ -61,7 +65,7 @@ static const struct spi_flash_config flash_configs[] =
6165
},
6266
#endif
6367

64-
#ifdef BSP_USING_SPI3
68+
#if defined(BSP_USING_SPI3) && defined(BSP_USING_SPI3_FLASH)
6569
{
6670
.bus_name = "spi3",
6771
.device_name = "spi30",
@@ -70,19 +74,29 @@ static const struct spi_flash_config flash_configs[] =
7074
},
7175
#endif
7276

73-
#ifdef BSP_USING_SPI4
77+
#if defined(BSP_USING_SPI4) && defined(BSP_USING_SPI4_FLASH)
7478
{
7579
.bus_name = "spi4",
7680
.device_name = "spi40",
7781
.flash_name = "gd25q_spi4",
7882
.cs_pin = GET_PIN(F, 6),
7983
},
8084
#endif
85+
86+
#if defined(BSP_USING_SPI5) && defined(BSP_USING_SPI5_FLASH)
87+
{
88+
.bus_name = "spi5",
89+
.device_name = "spi50",
90+
.flash_name = "gd25q_spi5",
91+
.cs_pin = GET_PIN(F, 6), /* Note: Update CS pin according to actual hardware */
92+
},
93+
#endif
8194
};
8295

8396

8497
static int spi_flash_init(void)
8598
{
99+
#ifdef BSP_USING_SPI_FLASH
86100
int result = RT_EOK;
87101

88102
for (size_t i = 0; i < sizeof(flash_configs) / sizeof(flash_configs[0]); i++)
@@ -106,5 +120,9 @@ static int spi_flash_init(void)
106120
}
107121

108122
return result;
123+
#else
124+
/* SPI Flash auto-initialization is disabled. User should initialize SPI Flash manually in board code. */
125+
return RT_EOK;
126+
#endif
109127
}
110128
INIT_COMPONENT_EXPORT(spi_flash_init);

0 commit comments

Comments
 (0)