mirror of https://github.com/RT-Thread/rt-thread
bsp: gd32470z-lckfb: 增加 SPI Flash 支持及使用说明 (#10347)
This commit is contained in:
parent
7568ec9618
commit
aec10aa0a8
10
MAINTAINERS
10
MAINTAINERS
|
@ -49,6 +49,10 @@ tag: bsp_cvitek
|
|||
path: bsp/cvitek
|
||||
owners: Chen Wang(unicornx)<unicorn_wang@outlook.com>
|
||||
|
||||
tag: bsp_gd32470z-lckfb
|
||||
path: bsp/gd32/arm/gd32470z-lckfb
|
||||
owners: Wu Ying Xiang(godmial)<2633967641@qq.com>
|
||||
|
||||
tag: bsp_k230
|
||||
path: bsp/k230
|
||||
owners: Chen Wang(unicornx)<unicorn_wang@outlook.com>
|
||||
|
@ -79,10 +83,6 @@ tag: workflow
|
|||
path: .github
|
||||
owners: supper thomas(supperthomas)<78900636@qq.com>, Bingru Zhang(Rbb666)<751061401@qq.com>, Yuqiang Wang(kurisaW)<2053731441@qq.com>
|
||||
|
||||
tag: gd32470z-lckfb-lcd
|
||||
path: bsp/gd32/arm/gd32470z-lckfb/board/ports
|
||||
owners: Wu Ying Xiang(godmial)<2633967641@qq.com>
|
||||
|
||||
tag: bsp_ultrarisc
|
||||
path: bsp/ultrarisc/ur_dp1000_evb
|
||||
owners: Zhang Jing(zhangjing0303)<zhangjing@ultrarisc.com>
|
||||
owners: Zhang Jing(zhangjing0303)<zhangjing@ultrarisc.com>
|
|
@ -13,7 +13,7 @@ GD32470Z-LCKFB梁山派是立创开发板推出的一款GD32F470系列的开发
|
|||
- GD32F470ZGT6,主频 240MHz,CPU内核:ARM Cortex-M4,1024KB FLASH ,512KB RAM
|
||||
- 常用外设
|
||||
|
||||
- 用户LED :4个,LED1 (PE3),LED2(PD7),LED3(PG3),LED4(PA5)
|
||||
- 用户LED :4个,LED1(PE3),LED2(PD7),LED3(PG3),LED4(PA5)
|
||||
- 电源指示灯:一个红色LED
|
||||
- 按键:3个,KEY_UP(PA0),RESET(NRST),BOOT0(PB2)
|
||||
- General TM * 10、Advanced TM * 2、Basic TM * 2
|
||||
|
@ -44,14 +44,18 @@ GD32470Z-LCKFB梁山派是立创开发板推出的一款GD32F470系列的开发
|
|||
|
||||
## 外设支持
|
||||
|
||||
本 BSP 目前对外设的支持情况如下:
|
||||
|
||||
| **片上外设** | **支持情况** | **备注** |
|
||||
|:-------- |:--------:|:-------------------------------- |
|
||||
| GPIO | 支持 | PA0, PA1... ---> PIN: 0, 1...113 |
|
||||
| UART | 支持 | UART0 - UART7 |
|
||||
| **扩展模块** | **支持情况** | **备注** |
|
||||
| LCD+触摸屏 | 支持 | 暂不支持中文显示(因 Keil5 编码限制),使用方法请查看bsp\gd32\arm\gd32470z-lckfb\board\ports\README.md |
|
||||
|:------------|:------------:|:----------------------------------|
|
||||
| GPIO | 支持 | PA0, PA1... ---> PIN: 0, 1...113 |
|
||||
| UART | 支持 | UART0 - UART7 |
|
||||
| SPI | 支持 | 支持 SPI0 ~ SPI4,可配置多个总线 |
|
||||
| **扩展模块** | **支持情况** | **备注** |
|
||||
| LCD+触摸屏 | 支持 | 暂不支持中文显示(因 Keil5 编码限制),使用方法请查看bsp\gd32\arm\gd32470z-lckfb\board\ports\README.md |
|
||||
| **板载外设** | **支持情况** | **备注** |
|
||||
| SPI Flash | 支持 | 板载 W25Q64,挂载在 SPI4,总线名:spi4,设备名:spi40 |
|
||||
|
||||
|
||||
|
||||
## 使用说明
|
||||
|
||||
|
@ -107,10 +111,27 @@ msh />
|
|||
|
||||
## 注意事项
|
||||
|
||||
暂无
|
||||
|
||||
- 目前DFS支持有问题,若需使用板载 SPI Flash,请在 `menuconfig` 中启用以下配置:
|
||||
|
||||
```
|
||||
RT-Thread Components --->
|
||||
DFS: device virtual file system --->
|
||||
[ ] DFS: device virtual file system (RT_USING_DFS) 关闭DFS
|
||||
Device Drivers --->
|
||||
[*] Enable SPI BUS support (RT_USING_SPI)
|
||||
[*] Enable SFUD for SPI Flash (RT_USING_SFUD)
|
||||
|
||||
Hardware Drivers Config --->
|
||||
On-chip Peripheral Drivers --->
|
||||
[*] Enable SPI BUS (BSP_USING_SPI)
|
||||
[*] Enable SPI4 BUS (BSP_USING_SPI4)
|
||||
```
|
||||
|
||||
|
||||
## 联系人信息
|
||||
|
||||
维护人:
|
||||
|
||||
- [godmial](https://github.com/godmial), 邮箱:<2633967641@qq.com>
|
||||
- [yuanzihao](https://github.com/zihao-yuan/), 邮箱:<y@yzh.email>
|
||||
|
|
|
@ -319,6 +319,21 @@ menu "On-chip Peripheral Drivers"
|
|||
depends on BSP_USING_SPI1
|
||||
select BSP_SPI1_TX_USING_DMA
|
||||
default n
|
||||
|
||||
config BSP_USING_SPI4
|
||||
bool "Enable SPI4 BUS"
|
||||
default n
|
||||
|
||||
config BSP_SPI4_TX_USING_DMA
|
||||
bool "Enable SPI4 TX DMA"
|
||||
depends on BSP_USING_SPI4
|
||||
default n
|
||||
|
||||
config BSP_SPI4_RX_USING_DMA
|
||||
bool "Enable SPI4 RX DMA"
|
||||
depends on BSP_USING_SPI4
|
||||
select BSP_SPI4_TX_USING_DMA
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_I2C1
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* Date Author Notes
|
||||
* 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
|
||||
*/
|
||||
#include <board.h>
|
||||
#include "drv_spi.h"
|
||||
|
@ -19,72 +20,102 @@
|
|||
#include <rthw.h>
|
||||
#include <finsh.h>
|
||||
|
||||
#define SPI_BUS_NAME "spi0"
|
||||
#define SPI_DEVICE_NAME "spi01"
|
||||
#define SPI_FLASH_DEVICE_NAME "gd25q"
|
||||
|
||||
#define GD25Q_SPI_CS_GPIOX_CLK RCU_GPIOE
|
||||
#define GD25Q_SPI_CS_GPIOX GPIOE
|
||||
#define GD25Q_SPI_CS_GPIOX_PIN_X GPIO_PIN_3
|
||||
|
||||
static int rt_hw_spi_flash_init(void)
|
||||
{
|
||||
rt_err_t res;
|
||||
static struct rt_spi_device spi_dev_gd25q; /* SPI device */
|
||||
static struct gd32_spi_cs spi_cs;
|
||||
spi_cs.GPIOx = GD25Q_SPI_CS_GPIOX;
|
||||
spi_cs.GPIO_Pin = GD25Q_SPI_CS_GPIOX_PIN_X;
|
||||
|
||||
rcu_periph_clock_enable(GD25Q_SPI_CS_GPIOX_CLK);
|
||||
#if defined SOC_SERIES_GD32F4xx
|
||||
gpio_mode_set(spi_cs.GPIOx, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, spi_cs.GPIO_Pin);
|
||||
gpio_output_options_set(spi_cs.GPIOx, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, spi_cs.GPIO_Pin);
|
||||
|
||||
gpio_bit_set(spi_cs.GPIOx, spi_cs.GPIO_Pin);
|
||||
#else
|
||||
gpio_init(spi_cs.GPIOx, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, spi_cs.GPIO_Pin);
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
#include <dfs_fs.h>
|
||||
#endif
|
||||
res = rt_spi_bus_attach_device(&spi_dev_gd25q, SPI_FLASH_DEVICE_NAME, SPI_BUS_NAME, (void*)&spi_cs);
|
||||
|
||||
if (res != RT_EOK)
|
||||
struct spi_flash_config
|
||||
{
|
||||
const char *bus_name;
|
||||
const char *device_name;
|
||||
const char *flash_name;
|
||||
rt_base_t cs_pin;
|
||||
};
|
||||
|
||||
static const struct spi_flash_config flash_configs[] =
|
||||
{
|
||||
#ifdef BSP_USING_SPI0
|
||||
{
|
||||
rt_kprintf("rt_spi_bus_attach_device() run failed!\n");
|
||||
return res;
|
||||
}
|
||||
.bus_name = "spi0",
|
||||
.device_name = "spi00",
|
||||
.flash_name = "gd25q_spi0",
|
||||
.cs_pin = GET_PIN(A, 4),
|
||||
},
|
||||
#endif
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_DEVICE_EXPORT(rt_hw_spi_flash_init);
|
||||
#ifdef BSP_USING_SPI1
|
||||
{
|
||||
.bus_name = "spi1",
|
||||
.device_name = "spi10",
|
||||
.flash_name = "gd25q_spi1",
|
||||
.cs_pin = GET_PIN(B, 9),
|
||||
},
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_SPI2
|
||||
{
|
||||
.bus_name = "spi2",
|
||||
.device_name = "spi20",
|
||||
.flash_name = "gd25q_spi2",
|
||||
.cs_pin = GET_PIN(B, 12),
|
||||
},
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_SPI3
|
||||
{
|
||||
.bus_name = "spi3",
|
||||
.device_name = "spi30",
|
||||
.flash_name = "gd25q_spi3",
|
||||
.cs_pin = GET_PIN(E, 4),
|
||||
},
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_SPI4
|
||||
{
|
||||
.bus_name = "spi4",
|
||||
.device_name = "spi40",
|
||||
.flash_name = "gd25q_spi4",
|
||||
.cs_pin = GET_PIN(F, 6),
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
static int spi_flash_init(void)
|
||||
{
|
||||
int result = RT_EOK;
|
||||
|
||||
for (size_t i = 0; i < sizeof(flash_configs) / sizeof(flash_configs[0]); i++)
|
||||
{
|
||||
const struct spi_flash_config *cfg = &flash_configs[i];
|
||||
|
||||
result = rt_hw_spi_device_attach(cfg->bus_name, cfg->device_name, cfg->cs_pin);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
rt_kprintf("Failed to attach device %s on bus %s\n", cfg->device_name, cfg->bus_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_SFUD
|
||||
static int rt_hw_spi_flash_with_sfud_init(void)
|
||||
{
|
||||
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_DEVICE_NAME, SPI_DEVICE_NAME))
|
||||
{
|
||||
return -RT_ERROR;
|
||||
};
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_COMPONENT_EXPORT(rt_hw_spi_flash_with_sfud_init);
|
||||
if (RT_NULL == rt_sfud_flash_probe(cfg->flash_name, cfg->device_name))
|
||||
{
|
||||
rt_kprintf("SFUD probe failed: %s\n", cfg->flash_name);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
#include <dfs_fs.h>
|
||||
|
||||
int mnt_init(void)
|
||||
{
|
||||
if (dfs_mount(SPI_FLASH_DEVICE_NAME, "/", "elm", 0, 0) == 0)
|
||||
{
|
||||
rt_kprintf("spi flash mount success !\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("spi flash mount failed!\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
MSH_CMD_EXPORT(mnt_init, mount spi flash to file system);
|
||||
if (dfs_mount(cfg->flash_name, "/", "elm", 0, 0) == RT_EOK)
|
||||
{
|
||||
rt_kprintf("SPI flash %s mount success!\n", cfg->flash_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("SPI flash %s mount failed!\n", cfg->flash_name);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
INIT_COMPONENT_EXPORT(spi_flash_init);
|
||||
|
|
Loading…
Reference in New Issue