Skip to content

Commit b8803c3

Browse files
committed
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初始化,避免自动初始化导致的设备冲突问题。
1 parent 2fcdd86 commit b8803c3

File tree

4 files changed

+80
-8
lines changed

4 files changed

+80
-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: 55 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,60 @@ 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+
select RT_USING_SFUD
262+
default n
263+
help
264+
Enable automatic SPI Flash initialization on selected SPI buses.
265+
Note: Only enable this for SPI buses that are actually connected to SPI Flash.
266+
If a SPI bus is used for other devices (e.g., OLED, WIFI), do not enable flash initialization for it.
267+
268+
if BSP_USING_SPI_FLASH
269+
config BSP_USING_SPI0_FLASH
270+
bool "Enable SPI Flash on SPI0"
271+
depends on BSP_USING_SPI0
272+
default n
273+
help
274+
Enable SPI Flash initialization on SPI0 bus.
275+
276+
config BSP_USING_SPI1_FLASH
277+
bool "Enable SPI Flash on SPI1"
278+
depends on BSP_USING_SPI1
279+
default n
280+
help
281+
Enable SPI Flash initialization on SPI1 bus.
282+
283+
config BSP_USING_SPI2_FLASH
284+
bool "Enable SPI Flash on SPI2"
285+
depends on BSP_USING_SPI2
286+
default n
287+
help
288+
Enable SPI Flash initialization on SPI2 bus.
289+
290+
config BSP_USING_SPI3_FLASH
291+
bool "Enable SPI Flash on SPI3"
292+
depends on BSP_USING_SPI3
293+
default n
294+
help
295+
Enable SPI Flash initialization on SPI3 bus.
296+
297+
config BSP_USING_SPI4_FLASH
298+
bool "Enable SPI Flash on SPI4"
299+
depends on BSP_USING_SPI4
300+
default n
301+
help
302+
Enable SPI Flash initialization on SPI4 bus.
303+
304+
config BSP_USING_SPI5_FLASH
305+
bool "Enable SPI Flash on SPI5"
306+
depends on BSP_USING_SPI5
307+
default n
308+
help
309+
Enable SPI Flash initialization on SPI5 bus.
310+
endif
257311
endif
258312

259313
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+
* 2024-12-XX 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)