Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bsp/gd32/arm/gd32470z-lckfb/.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 56 additions & 1 deletion bsp/gd32/arm/gd32470z-lckfb/board/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bsp/gd32/arm/gd32470z-lckfb/rtconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
28 changes: 23 additions & 5 deletions bsp/gd32/arm/libraries/gd32_drivers/drv_spi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -70,19 +74,29 @@ 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",
.flash_name = "gd25q_spi4",
.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++)
Expand All @@ -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);