Skip to content

Commit aec10aa

Browse files
authored
bsp: gd32470z-lckfb: 增加 SPI Flash 支持及使用说明 (#10347)
1 parent 7568ec9 commit aec10aa

File tree

4 files changed

+129
-62
lines changed

4 files changed

+129
-62
lines changed

MAINTAINERS

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ tag: bsp_cvitek
4949
path: bsp/cvitek
5050
owners: Chen Wang(unicornx)<[email protected]>
5151

52+
tag: bsp_gd32470z-lckfb
53+
path: bsp/gd32/arm/gd32470z-lckfb
54+
owners: Wu Ying Xiang(godmial)<[email protected]>
55+
5256
tag: bsp_k230
5357
path: bsp/k230
5458
owners: Chen Wang(unicornx)<[email protected]>
@@ -79,10 +83,6 @@ tag: workflow
7983
path: .github
8084
owners: supper thomas(supperthomas)<[email protected]>, Bingru Zhang(Rbb666)<[email protected]>, Yuqiang Wang(kurisaW)<[email protected]>
8185

82-
tag: gd32470z-lckfb-lcd
83-
path: bsp/gd32/arm/gd32470z-lckfb/board/ports
84-
owners: Wu Ying Xiang(godmial)<[email protected]>
85-
8686
tag: bsp_ultrarisc
8787
path: bsp/ultrarisc/ur_dp1000_evb
88-
owners: Zhang Jing(zhangjing0303)<[email protected]>
88+
owners: Zhang Jing(zhangjing0303)<[email protected]>

bsp/gd32/arm/gd32470z-lckfb/README.md

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ GD32470Z-LCKFB梁山派是立创开发板推出的一款GD32F470系列的开发
1313
- GD32F470ZGT6,主频 240MHz,CPU内核:ARM Cortex-M4,1024KB FLASH ,512KB RAM
1414
- 常用外设
1515

16-
- 用户LED :4个,LED1 (PE3),LED2(PD7),LED3(PG3),LED4(PA5)
16+
- 用户LED :4个,LED1PE3),LED2(PD7),LED3(PG3),LED4(PA5)
1717
- 电源指示灯:一个红色LED
1818
- 按键:3个,KEY_UP(PA0),RESET(NRST),BOOT0(PB2)
1919
- General TM * 10、Advanced TM * 2、Basic TM * 2
@@ -44,14 +44,18 @@ GD32470Z-LCKFB梁山派是立创开发板推出的一款GD32F470系列的开发
4444

4545
## 外设支持
4646

47-
本 BSP 目前对外设的支持情况如下:
4847

4948
| **片上外设** | **支持情况** | **备注** |
50-
|:-------- |:--------:|:-------------------------------- |
51-
| GPIO | 支持 | PA0, PA1... ---> PIN: 0, 1...113 |
52-
| UART | 支持 | UART0 - UART7 |
53-
| **扩展模块** | **支持情况** | **备注** |
54-
| LCD+触摸屏 | 支持 | 暂不支持中文显示(因 Keil5 编码限制),使用方法请查看bsp\gd32\arm\gd32470z-lckfb\board\ports\README.md |
49+
|:------------|:------------:|:----------------------------------|
50+
| GPIO | 支持 | PA0, PA1... ---> PIN: 0, 1...113 |
51+
| UART | 支持 | UART0 - UART7 |
52+
| SPI | 支持 | 支持 SPI0 ~ SPI4,可配置多个总线 |
53+
| **扩展模块** | **支持情况** | **备注** |
54+
| LCD+触摸屏 | 支持 | 暂不支持中文显示(因 Keil5 编码限制),使用方法请查看bsp\gd32\arm\gd32470z-lckfb\board\ports\README.md |
55+
| **板载外设** | **支持情况** | **备注** |
56+
| SPI Flash | 支持 | 板载 W25Q64,挂载在 SPI4,总线名:spi4,设备名:spi40 |
57+
58+
5559

5660
## 使用说明
5761

@@ -107,10 +111,27 @@ msh />
107111

108112
## 注意事项
109113

110-
暂无
114+
115+
- 目前DFS支持有问题,若需使用板载 SPI Flash,请在 `menuconfig` 中启用以下配置:
116+
117+
```
118+
RT-Thread Components --->
119+
DFS: device virtual file system --->
120+
[ ] DFS: device virtual file system (RT_USING_DFS) 关闭DFS
121+
Device Drivers --->
122+
[*] Enable SPI BUS support (RT_USING_SPI)
123+
[*] Enable SFUD for SPI Flash (RT_USING_SFUD)
124+
125+
Hardware Drivers Config --->
126+
On-chip Peripheral Drivers --->
127+
[*] Enable SPI BUS (BSP_USING_SPI)
128+
[*] Enable SPI4 BUS (BSP_USING_SPI4)
129+
```
130+
111131

112132
## 联系人信息
113133

114134
维护人:
115135

136+
- [godmial](https://github.com/godmial), 邮箱:<[email protected]>
116137
- [yuanzihao](https://github.com/zihao-yuan/), 邮箱:<[email protected]>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,21 @@ menu "On-chip Peripheral Drivers"
319319
depends on BSP_USING_SPI1
320320
select BSP_SPI1_TX_USING_DMA
321321
default n
322+
323+
config BSP_USING_SPI4
324+
bool "Enable SPI4 BUS"
325+
default n
326+
327+
config BSP_SPI4_TX_USING_DMA
328+
bool "Enable SPI4 TX DMA"
329+
depends on BSP_USING_SPI4
330+
default n
331+
332+
config BSP_SPI4_RX_USING_DMA
333+
bool "Enable SPI4 RX DMA"
334+
depends on BSP_USING_SPI4
335+
select BSP_SPI4_TX_USING_DMA
336+
default n
322337
endif
323338

324339
menuconfig BSP_USING_I2C1

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

Lines changed: 80 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Date Author Notes
88
* 2021-12-31 BruceOu first implementation
99
* 2023-06-03 CX fixed sf probe error bug
10+
* 2024-05-30 godmial refactor driver for multi-SPI bus auto-mount
1011
*/
1112
#include <board.h>
1213
#include "drv_spi.h"
@@ -19,72 +20,102 @@
1920
#include <rthw.h>
2021
#include <finsh.h>
2122

22-
#define SPI_BUS_NAME "spi0"
23-
#define SPI_DEVICE_NAME "spi01"
24-
#define SPI_FLASH_DEVICE_NAME "gd25q"
23+
#ifdef RT_USING_DFS
24+
#include <dfs_fs.h>
25+
#endif
2526

26-
#define GD25Q_SPI_CS_GPIOX_CLK RCU_GPIOE
27-
#define GD25Q_SPI_CS_GPIOX GPIOE
28-
#define GD25Q_SPI_CS_GPIOX_PIN_X GPIO_PIN_3
27+
struct spi_flash_config
28+
{
29+
const char *bus_name;
30+
const char *device_name;
31+
const char *flash_name;
32+
rt_base_t cs_pin;
33+
};
2934

30-
static int rt_hw_spi_flash_init(void)
35+
static const struct spi_flash_config flash_configs[] =
3136
{
32-
rt_err_t res;
33-
static struct rt_spi_device spi_dev_gd25q; /* SPI device */
34-
static struct gd32_spi_cs spi_cs;
35-
spi_cs.GPIOx = GD25Q_SPI_CS_GPIOX;
36-
spi_cs.GPIO_Pin = GD25Q_SPI_CS_GPIOX_PIN_X;
37+
#ifdef BSP_USING_SPI0
38+
{
39+
.bus_name = "spi0",
40+
.device_name = "spi00",
41+
.flash_name = "gd25q_spi0",
42+
.cs_pin = GET_PIN(A, 4),
43+
},
44+
#endif
3745

38-
rcu_periph_clock_enable(GD25Q_SPI_CS_GPIOX_CLK);
39-
#if defined SOC_SERIES_GD32F4xx
40-
gpio_mode_set(spi_cs.GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, spi_cs.GPIO_Pin);
41-
gpio_output_options_set(spi_cs.GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, spi_cs.GPIO_Pin);
46+
#ifdef BSP_USING_SPI1
47+
{
48+
.bus_name = "spi1",
49+
.device_name = "spi10",
50+
.flash_name = "gd25q_spi1",
51+
.cs_pin = GET_PIN(B, 9),
52+
},
53+
#endif
4254

43-
gpio_bit_set(spi_cs.GPIOx, spi_cs.GPIO_Pin);
44-
#else
45-
gpio_init(spi_cs.GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, spi_cs.GPIO_Pin);
55+
#ifdef BSP_USING_SPI2
56+
{
57+
.bus_name = "spi2",
58+
.device_name = "spi20",
59+
.flash_name = "gd25q_spi2",
60+
.cs_pin = GET_PIN(B, 12),
61+
},
62+
#endif
4663

64+
#ifdef BSP_USING_SPI3
65+
{
66+
.bus_name = "spi3",
67+
.device_name = "spi30",
68+
.flash_name = "gd25q_spi3",
69+
.cs_pin = GET_PIN(E, 4),
70+
},
4771
#endif
48-
res = rt_spi_bus_attach_device(&spi_dev_gd25q, SPI_FLASH_DEVICE_NAME, SPI_BUS_NAME, (void*)&spi_cs);
4972

50-
if (res != RT_EOK)
73+
#ifdef BSP_USING_SPI4
5174
{
52-
rt_kprintf("rt_spi_bus_attach_device() run failed!\n");
53-
return res;
54-
}
75+
.bus_name = "spi4",
76+
.device_name = "spi40",
77+
.flash_name = "gd25q_spi4",
78+
.cs_pin = GET_PIN(F, 6),
79+
},
80+
#endif
81+
};
5582

56-
return RT_EOK;
57-
}
58-
INIT_DEVICE_EXPORT(rt_hw_spi_flash_init);
5983

60-
#ifdef RT_USING_SFUD
61-
static int rt_hw_spi_flash_with_sfud_init(void)
84+
static int spi_flash_init(void)
6285
{
63-
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_DEVICE_NAME, SPI_DEVICE_NAME))
86+
int result = RT_EOK;
87+
88+
for (size_t i = 0; i < sizeof(flash_configs) / sizeof(flash_configs[0]); i++)
6489
{
65-
return -RT_ERROR;
66-
};
90+
const struct spi_flash_config *cfg = &flash_configs[i];
6791

68-
return RT_EOK;
69-
}
70-
INIT_COMPONENT_EXPORT(rt_hw_spi_flash_with_sfud_init);
92+
result = rt_hw_spi_device_attach(cfg->bus_name, cfg->device_name, cfg->cs_pin);
93+
if (result != RT_EOK)
94+
{
95+
rt_kprintf("Failed to attach device %s on bus %s\n", cfg->device_name, cfg->bus_name);
96+
continue;
97+
}
98+
99+
#ifdef RT_USING_SFUD
100+
if (RT_NULL == rt_sfud_flash_probe(cfg->flash_name, cfg->device_name))
101+
{
102+
rt_kprintf("SFUD probe failed: %s\n", cfg->flash_name);
103+
continue;
104+
}
71105
#endif
72106

73107
#ifdef RT_USING_DFS
74-
#include <dfs_fs.h>
75-
76-
int mnt_init(void)
77-
{
78-
if (dfs_mount(SPI_FLASH_DEVICE_NAME, "/", "elm", 0, 0) == 0)
79-
{
80-
rt_kprintf("spi flash mount success !\n");
81-
}
82-
else
83-
{
84-
rt_kprintf("spi flash mount failed!\n");
108+
if (dfs_mount(cfg->flash_name, "/", "elm", 0, 0) == RT_EOK)
109+
{
110+
rt_kprintf("SPI flash %s mount success!\n", cfg->flash_name);
111+
}
112+
else
113+
{
114+
rt_kprintf("SPI flash %s mount failed!\n", cfg->flash_name);
115+
}
116+
#endif
85117
}
86118

87-
return 0;
119+
return result;
88120
}
89-
MSH_CMD_EXPORT(mnt_init, mount spi flash to file system);
90-
#endif
121+
INIT_COMPONENT_EXPORT(spi_flash_init);

0 commit comments

Comments
 (0)