[bsp][nuvoton_m487]Add SPI drive
This commit is contained in:
parent
adc6dd5dbe
commit
3ac00d4c02
|
@ -7,6 +7,8 @@
|
|||
# RT-Thread Kernel
|
||||
#
|
||||
CONFIG_RT_NAME_MAX=8
|
||||
# CONFIG_RT_USING_ARCH_DATA_TYPE is not set
|
||||
# CONFIG_RT_USING_SMP is not set
|
||||
CONFIG_RT_ALIGN_SIZE=4
|
||||
# CONFIG_RT_THREAD_PRIORITY_8 is not set
|
||||
CONFIG_RT_THREAD_PRIORITY_32=y
|
||||
|
@ -62,6 +64,7 @@ CONFIG_RT_USING_DEVICE=y
|
|||
CONFIG_RT_USING_CONSOLE=y
|
||||
CONFIG_RT_CONSOLEBUF_SIZE=128
|
||||
CONFIG_RT_CONSOLE_DEVICE_NAME="uart0"
|
||||
CONFIG_RT_VER_NUM=0x40001
|
||||
# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
|
||||
|
||||
#
|
||||
|
@ -88,7 +91,7 @@ CONFIG_FINSH_USING_SYMTAB=y
|
|||
CONFIG_FINSH_USING_DESCRIPTION=y
|
||||
# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
|
||||
CONFIG_FINSH_THREAD_PRIORITY=20
|
||||
CONFIG_FINSH_THREAD_STACK_SIZE=1024
|
||||
CONFIG_FINSH_THREAD_STACK_SIZE=2048
|
||||
CONFIG_FINSH_CMD_SIZE=80
|
||||
# CONFIG_FINSH_USING_AUTH is not set
|
||||
CONFIG_FINSH_USING_MSH=y
|
||||
|
@ -100,12 +103,28 @@ CONFIG_FINSH_ARG_MAX=10
|
|||
# Device virtual file system
|
||||
#
|
||||
CONFIG_RT_USING_DFS=y
|
||||
# CONFIG_DFS_USING_WORKDIR is not set
|
||||
CONFIG_DFS_FILESYSTEMS_MAX=1
|
||||
CONFIG_DFS_USING_WORKDIR=y
|
||||
CONFIG_DFS_FILESYSTEMS_MAX=2
|
||||
CONFIG_DFS_FILESYSTEM_TYPES_MAX=2
|
||||
CONFIG_DFS_FD_MAX=32
|
||||
# CONFIG_RT_USING_DFS_MNTTABLE is not set
|
||||
# CONFIG_RT_USING_DFS_ELMFAT is not set
|
||||
CONFIG_RT_USING_DFS_ELMFAT=y
|
||||
|
||||
#
|
||||
# elm-chan's FatFs, Generic FAT Filesystem Module
|
||||
#
|
||||
CONFIG_RT_DFS_ELM_CODE_PAGE=437
|
||||
CONFIG_RT_DFS_ELM_WORD_ACCESS=y
|
||||
# CONFIG_RT_DFS_ELM_USE_LFN_0 is not set
|
||||
# CONFIG_RT_DFS_ELM_USE_LFN_1 is not set
|
||||
# CONFIG_RT_DFS_ELM_USE_LFN_2 is not set
|
||||
CONFIG_RT_DFS_ELM_USE_LFN_3=y
|
||||
CONFIG_RT_DFS_ELM_USE_LFN=3
|
||||
CONFIG_RT_DFS_ELM_MAX_LFN=255
|
||||
CONFIG_RT_DFS_ELM_DRIVES=2
|
||||
CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=4096
|
||||
# CONFIG_RT_DFS_ELM_USE_ERASE is not set
|
||||
CONFIG_RT_DFS_ELM_REENTRANT=y
|
||||
CONFIG_RT_USING_DFS_DEVFS=y
|
||||
# CONFIG_RT_USING_DFS_ROMFS is not set
|
||||
# CONFIG_RT_USING_DFS_RAMFS is not set
|
||||
|
@ -120,11 +139,13 @@ CONFIG_RT_USING_DEVICE_IPC=y
|
|||
CONFIG_RT_PIPE_BUFSZ=64
|
||||
CONFIG_RT_USING_SERIAL=y
|
||||
CONFIG_RT_SERIAL_USING_DMA=y
|
||||
CONFIG_RT_SERIAL_RB_BUFSZ=64
|
||||
# CONFIG_RT_USING_CAN is not set
|
||||
# CONFIG_RT_USING_HWTIMER is not set
|
||||
# CONFIG_RT_USING_CPUTIME is not set
|
||||
# CONFIG_RT_USING_I2C is not set
|
||||
# CONFIG_RT_USING_PIN is not set
|
||||
# CONFIG_RT_USING_ADC is not set
|
||||
# CONFIG_RT_USING_PWM is not set
|
||||
# CONFIG_RT_USING_MTD_NOR is not set
|
||||
# CONFIG_RT_USING_MTD_NAND is not set
|
||||
|
@ -132,9 +153,17 @@ CONFIG_RT_SERIAL_USING_DMA=y
|
|||
# CONFIG_RT_USING_PM is not set
|
||||
# CONFIG_RT_USING_RTC is not set
|
||||
# CONFIG_RT_USING_SDIO is not set
|
||||
# CONFIG_RT_USING_SPI is not set
|
||||
CONFIG_RT_USING_SPI=y
|
||||
# CONFIG_RT_USING_QSPI is not set
|
||||
# CONFIG_RT_USING_SPI_MSD is not set
|
||||
# CONFIG_RT_USING_SFUD is not set
|
||||
CONFIG_RT_USING_W25QXX=y
|
||||
# CONFIG_RT_USING_GD is not set
|
||||
# CONFIG_RT_USING_ENC28J60 is not set
|
||||
# CONFIG_RT_USING_SPI_WIFI is not set
|
||||
# CONFIG_RT_USING_WDT is not set
|
||||
# CONFIG_RT_USING_AUDIO is not set
|
||||
# CONFIG_RT_USING_SENSOR is not set
|
||||
|
||||
#
|
||||
# Using WiFi
|
||||
|
@ -218,6 +247,7 @@ CONFIG_LWIP_SO_RCVBUF=1
|
|||
# CONFIG_RT_LWIP_NETIF_LOOPBACK is not set
|
||||
CONFIG_LWIP_NETIF_LOOPBACK=0
|
||||
# CONFIG_RT_LWIP_STATS is not set
|
||||
# CONFIG_RT_LWIP_USING_HW_CHECKSUM is not set
|
||||
# CONFIG_RT_LWIP_DEBUG is not set
|
||||
|
||||
#
|
||||
|
@ -242,36 +272,26 @@ CONFIG_LWIP_NETIF_LOOPBACK=0
|
|||
# CONFIG_RT_USING_LOGTRACE is not set
|
||||
# CONFIG_RT_USING_RYM is not set
|
||||
# CONFIG_RT_USING_ULOG is not set
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
|
||||
#
|
||||
# RT-Thread online packages
|
||||
#
|
||||
|
||||
#
|
||||
# system packages
|
||||
#
|
||||
|
||||
#
|
||||
# RT-Thread GUI Engine
|
||||
#
|
||||
# CONFIG_PKG_USING_GUIENGINE is not set
|
||||
# CONFIG_PKG_USING_LWEXT4 is not set
|
||||
# CONFIG_PKG_USING_PARTITION is not set
|
||||
# CONFIG_PKG_USING_SQLITE is not set
|
||||
# CONFIG_PKG_USING_RTI is not set
|
||||
|
||||
#
|
||||
# IoT - internet of things
|
||||
#
|
||||
# CONFIG_PKG_USING_PAHOMQTT is not set
|
||||
# CONFIG_PKG_USING_WEBCLIENT is not set
|
||||
# CONFIG_PKG_USING_WEBNET is not set
|
||||
# CONFIG_PKG_USING_MONGOOSE is not set
|
||||
# CONFIG_PKG_USING_WEBTERMINAL is not set
|
||||
# CONFIG_PKG_USING_CJSON is not set
|
||||
# CONFIG_PKG_USING_JSMN is not set
|
||||
# CONFIG_PKG_USING_LIBMODBUS is not set
|
||||
# CONFIG_PKG_USING_LJSON is not set
|
||||
# CONFIG_PKG_USING_EZXML is not set
|
||||
# CONFIG_PKG_USING_NANOPB is not set
|
||||
# CONFIG_PKG_USING_GAGENT_CLOUD is not set
|
||||
|
||||
#
|
||||
# Wi-Fi
|
||||
|
@ -286,9 +306,23 @@ CONFIG_LWIP_NETIF_LOOPBACK=0
|
|||
# Wiced WiFi
|
||||
#
|
||||
# CONFIG_PKG_USING_WLAN_WICED is not set
|
||||
# CONFIG_PKG_USING_RW007 is not set
|
||||
# CONFIG_PKG_USING_COAP is not set
|
||||
# CONFIG_PKG_USING_NOPOLL is not set
|
||||
# CONFIG_PKG_USING_NETUTILS is not set
|
||||
# CONFIG_PKG_USING_AT_DEVICE is not set
|
||||
# CONFIG_PKG_USING_WIZNET is not set
|
||||
|
||||
#
|
||||
# IoT Cloud
|
||||
#
|
||||
# CONFIG_PKG_USING_ONENET is not set
|
||||
# CONFIG_PKG_USING_GAGENT_CLOUD is not set
|
||||
# CONFIG_PKG_USING_ALI_IOTKIT is not set
|
||||
# CONFIG_PKG_USING_AZURE is not set
|
||||
# CONFIG_PKG_USING_TENCENT_IOTKIT is not set
|
||||
# CONFIG_PKG_USING_NIMBLE is not set
|
||||
# CONFIG_PKG_USING_OTA_DOWNLOADER is not set
|
||||
|
||||
#
|
||||
# security packages
|
||||
|
@ -300,6 +334,7 @@ CONFIG_LWIP_NETIF_LOOPBACK=0
|
|||
#
|
||||
# language packages
|
||||
#
|
||||
# CONFIG_PKG_USING_LUA is not set
|
||||
# CONFIG_PKG_USING_JERRYSCRIPT is not set
|
||||
# CONFIG_PKG_USING_MICROPYTHON is not set
|
||||
|
||||
|
@ -307,24 +342,86 @@ CONFIG_LWIP_NETIF_LOOPBACK=0
|
|||
# multimedia packages
|
||||
#
|
||||
# CONFIG_PKG_USING_OPENMV is not set
|
||||
# CONFIG_PKG_USING_MUPDF is not set
|
||||
|
||||
#
|
||||
# tools packages
|
||||
#
|
||||
# CONFIG_PKG_USING_CMBACKTRACE is not set
|
||||
# CONFIG_PKG_USING_EASYFLASH is not set
|
||||
# CONFIG_PKG_USING_EASYLOGGER is not set
|
||||
# CONFIG_PKG_USING_SYSTEMVIEW is not set
|
||||
# CONFIG_PKG_USING_IPERF is not set
|
||||
# CONFIG_PKG_USING_RDB is not set
|
||||
# CONFIG_PKG_USING_QRCODE is not set
|
||||
# CONFIG_PKG_USING_ULOG_EASYFLASH is not set
|
||||
# CONFIG_PKG_USING_ADBD is not set
|
||||
|
||||
#
|
||||
# system packages
|
||||
#
|
||||
# CONFIG_PKG_USING_GUIENGINE is not set
|
||||
# CONFIG_PKG_USING_CAIRO is not set
|
||||
# CONFIG_PKG_USING_PIXMAN is not set
|
||||
# CONFIG_PKG_USING_LWEXT4 is not set
|
||||
# CONFIG_PKG_USING_PARTITION is not set
|
||||
# CONFIG_PKG_USING_FAL is not set
|
||||
# CONFIG_PKG_USING_SQLITE is not set
|
||||
# CONFIG_PKG_USING_RTI is not set
|
||||
# CONFIG_PKG_USING_LITTLEVGL2RTT is not set
|
||||
# CONFIG_PKG_USING_CMSIS is not set
|
||||
# CONFIG_PKG_USING_DFS_YAFFS is not set
|
||||
# CONFIG_PKG_USING_LITTLEFS is not set
|
||||
|
||||
#
|
||||
# peripheral libraries and drivers
|
||||
#
|
||||
|
||||
#
|
||||
# sensors drivers
|
||||
#
|
||||
# CONFIG_PKG_USING_LSM6DSL is not set
|
||||
# CONFIG_PKG_USING_LPS22HB is not set
|
||||
# CONFIG_PKG_USING_HTS221 is not set
|
||||
# CONFIG_PKG_USING_LSM303AGR is not set
|
||||
# CONFIG_PKG_USING_BME280 is not set
|
||||
# CONFIG_PKG_USING_BMA400 is not set
|
||||
# CONFIG_PKG_USING_BMI160_BMX160 is not set
|
||||
# CONFIG_PKG_USING_SPL0601 is not set
|
||||
# CONFIG_PKG_USING_REALTEK_AMEBA is not set
|
||||
# CONFIG_PKG_USING_SHT2X is not set
|
||||
# CONFIG_PKG_USING_AHT10 is not set
|
||||
# CONFIG_PKG_USING_AP3216C is not set
|
||||
# CONFIG_PKG_USING_STM32_SDIO is not set
|
||||
# CONFIG_PKG_USING_ICM20608 is not set
|
||||
# CONFIG_PKG_USING_U8G2 is not set
|
||||
# CONFIG_PKG_USING_BUTTON is not set
|
||||
# CONFIG_PKG_USING_MPU6XXX is not set
|
||||
# CONFIG_PKG_USING_PCF8574 is not set
|
||||
# CONFIG_PKG_USING_SX12XX is not set
|
||||
# CONFIG_PKG_USING_SIGNAL_LED is not set
|
||||
# CONFIG_PKG_USING_KENDRYTE_SDK is not set
|
||||
|
||||
#
|
||||
# miscellaneous packages
|
||||
#
|
||||
# CONFIG_PKG_USING_LIBCSV is not set
|
||||
# CONFIG_PKG_USING_OPTPARSE is not set
|
||||
# CONFIG_PKG_USING_FASTLZ is not set
|
||||
# CONFIG_PKG_USING_MINILZO is not set
|
||||
# CONFIG_PKG_USING_QUICKLZ is not set
|
||||
# CONFIG_PKG_USING_MULTIBUTTON is not set
|
||||
# CONFIG_PKG_USING_CANFESTIVAL is not set
|
||||
# CONFIG_PKG_USING_ZLIB is not set
|
||||
# CONFIG_PKG_USING_DSTR is not set
|
||||
# CONFIG_PKG_USING_TINYFRAME is not set
|
||||
# CONFIG_PKG_USING_KENDRYTE_DEMO is not set
|
||||
|
||||
#
|
||||
# example package: hello
|
||||
# samples: kernel and components samples
|
||||
#
|
||||
# CONFIG_PKG_USING_KERNEL_SAMPLES is not set
|
||||
# CONFIG_PKG_USING_FILESYSTEM_SAMPLES is not set
|
||||
# CONFIG_PKG_USING_NETWORK_SAMPLES is not set
|
||||
# CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set
|
||||
# CONFIG_PKG_USING_HELLO is not set
|
||||
# CONFIG_PKG_USING_VI is not set
|
||||
|
|
|
@ -31,11 +31,13 @@
|
|||
|
||||
连接好串口,可以使用115200-N-8-1的配置方式连接到设备上。设备使用的串口引脚是:`[Tx:PB13 Rx:PB12]`
|
||||
|
||||
当正确编译产生出rtthread.bin映像文件后,可以使用NU-link或者JLINK下载
|
||||
当正确编译产生出rtthread.bin映像文件后,可以使用Nu-link或者JLINK下载
|
||||
|
||||
### 3.1 运行结果
|
||||
|
||||
如果编译 & 烧写无误,当复位设备后,会在串口上看到RT-Thread的启动logo信息:
|
||||
如果编译 & 烧写无误,当复位设备后,会在串口上看到RT-Thread的启动logo信息
|
||||
|
||||
如挂载根目录失败,需要格式化SPI FLASH,请输入`mkfs -t elm flash0`
|
||||
|
||||
## 4. 驱动支持情况及计划
|
||||
|
||||
|
@ -43,6 +45,9 @@
|
|||
| ------ | ---- | :------: |
|
||||
| UART | 支持 | UART0|
|
||||
| EMAC | 支持 | EH0|
|
||||
| QSPI | 支持 | QSPI0|
|
||||
| SPIFLASH | 支持 | W25Q32 |
|
||||
|
||||
|
||||
### 4.1 IO在板级支持包中的映射情况
|
||||
|
||||
|
|
|
@ -9,10 +9,19 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <dfs_fs.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
printf("Hello RT-Thread!\n");
|
||||
|
||||
return 0;
|
||||
#ifdef RT_USING_DFS
|
||||
if(dfs_mount("flash0", "/", "efm", 0, 0) == 0)
|
||||
{
|
||||
rt_kprintf("mount efm ok\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("mount efm fail\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ src = Split('''
|
|||
board.c
|
||||
drv_uart.c
|
||||
drv_emac.c
|
||||
drv_qspi.c
|
||||
drv_spiflash.c
|
||||
''')
|
||||
CPPPATH = [cwd]
|
||||
|
||||
|
|
|
@ -0,0 +1,270 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-3-30 bluebear233 first version
|
||||
*/
|
||||
|
||||
|
||||
#include "NuMicro.h"
|
||||
#include <rtdevice.h>
|
||||
#ifdef RT_USING_SPI
|
||||
|
||||
/* Private Define ---------------------------------------------------------------*/
|
||||
#define USEING_QSPI0
|
||||
|
||||
/* Private Typedef --------------------------------------------------------------*/
|
||||
struct m487_qspi
|
||||
{
|
||||
struct rt_spi_bus dev;
|
||||
struct rt_spi_configuration configuration;
|
||||
QSPI_T *spi_base;
|
||||
rt_uint8_t init_gpio:1;
|
||||
};
|
||||
|
||||
/* Private functions ------------------------------------------------------------*/
|
||||
static rt_err_t m487_qspi_bus_configure(struct rt_spi_device *device,
|
||||
struct rt_spi_configuration *configuration);
|
||||
static rt_uint32_t m487_qspi_bus_xfer(struct rt_spi_device *device,
|
||||
struct rt_spi_message *message);
|
||||
|
||||
/* Private Variables ------------------------------------------------------------*/
|
||||
struct rt_spi_ops m487_spi_poll_ops =
|
||||
{
|
||||
.configure = m487_qspi_bus_configure,
|
||||
.xfer = m487_qspi_bus_xfer,
|
||||
};
|
||||
|
||||
#ifdef USEING_QSPI0
|
||||
static struct m487_qspi qspi0 =
|
||||
{
|
||||
.spi_base = QSPI0,
|
||||
};
|
||||
#endif
|
||||
|
||||
static rt_err_t m487_qspi_bus_configure(struct rt_spi_device *device,
|
||||
struct rt_spi_configuration *configuration) {
|
||||
|
||||
struct m487_qspi *spi;
|
||||
uint32_t u32QSPIMode;
|
||||
uint32_t u32BusClock;
|
||||
rt_uint8_t init_bus;
|
||||
|
||||
spi = (struct m487_qspi *) device->bus;
|
||||
init_bus = 0;
|
||||
|
||||
if (!spi->init_gpio)
|
||||
{
|
||||
spi->init_gpio = 1;
|
||||
init_bus = 1;
|
||||
|
||||
if(spi->spi_base == QSPI0)
|
||||
{
|
||||
/* Select PCLK0 as the clock source of QSPI0 */
|
||||
CLK_SetModuleClock(QSPI0_MODULE, CLK_CLKSEL2_QSPI0SEL_PLL,
|
||||
MODULE_NoMsk);
|
||||
|
||||
/* Enable QSPI0 peripheral clock */
|
||||
CLK_EnableModuleClock(QSPI0_MODULE);
|
||||
|
||||
/* Setup QSPI0 multi-function pins */
|
||||
SYS->GPC_MFPL &= ~(SYS_GPC_MFPL_PC0MFP_Msk | SYS_GPC_MFPL_PC1MFP_Msk
|
||||
| SYS_GPC_MFPL_PC2MFP_Msk | SYS_GPC_MFPL_PC3MFP_Msk);
|
||||
SYS->GPC_MFPL |= SYS_GPC_MFPL_PC0MFP_QSPI0_MOSI0 | SYS_GPC_MFPL_PC1MFP_QSPI0_MISO0
|
||||
| SYS_GPC_MFPL_PC2MFP_QSPI0_CLK | SYS_GPC_MFPL_PC3MFP_QSPI0_SS;
|
||||
|
||||
/* Enable SPI0 clock pin (PC2) schmitt trigger */
|
||||
PC->SMTEN |= GPIO_SMTEN_SMTEN2_Msk;
|
||||
}
|
||||
}
|
||||
|
||||
if(rt_memcmp(configuration, &spi->configuration, sizeof(*configuration)) != 0)
|
||||
{
|
||||
rt_memcpy(&spi->configuration, configuration, sizeof(*configuration));
|
||||
init_bus = 1;
|
||||
}
|
||||
|
||||
if(init_bus)
|
||||
{
|
||||
switch(configuration->mode & RT_SPI_MODE_3)
|
||||
{
|
||||
case RT_SPI_MODE_0:u32QSPIMode = QSPI_MODE_0;break;
|
||||
case RT_SPI_MODE_1:u32QSPIMode = QSPI_MODE_1;break;
|
||||
case RT_SPI_MODE_2:u32QSPIMode = QSPI_MODE_2;break;
|
||||
case RT_SPI_MODE_3:u32QSPIMode = QSPI_MODE_3;break;
|
||||
default:RT_ASSERT(0);
|
||||
}
|
||||
|
||||
u32BusClock = configuration->max_hz;
|
||||
if(u32BusClock > 50*1000*1000)
|
||||
{
|
||||
u32BusClock = 50*1000*1000;
|
||||
}
|
||||
|
||||
QSPI_Open(spi->spi_base, QSPI_MASTER, u32QSPIMode, configuration->data_width, u32BusClock);
|
||||
|
||||
QSPI_EnableAutoSS(spi->spi_base, QSPI_SS, QSPI_SS_ACTIVE_LOW);
|
||||
|
||||
if(configuration->mode & RT_SPI_MSB)
|
||||
{
|
||||
QSPI_SET_MSB_FIRST(spi->spi_base);
|
||||
}
|
||||
else
|
||||
{
|
||||
QSPI_SET_LSB_FIRST(spi->spi_base);
|
||||
}
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI bus 轮询
|
||||
* @param dev : SPI总线设备结构体指针
|
||||
* @param send_addr : 发送缓冲区地址
|
||||
* @param recv_addr : 接收缓冲区地址
|
||||
* @param length : 数据长度
|
||||
*/
|
||||
static void qspi_transmission_with_poll(struct m487_qspi *spi_bus,
|
||||
const uint8_t *send_addr, uint8_t *recv_addr, int length)
|
||||
{
|
||||
QSPI_T *spi_base = spi_bus->spi_base;
|
||||
|
||||
// 写
|
||||
if (send_addr != RT_NULL && recv_addr == RT_NULL)
|
||||
{
|
||||
while (length--)
|
||||
{
|
||||
// 等待TX FIFO 为空
|
||||
while(QSPI_GET_TX_FIFO_FULL_FLAG(spi_base));
|
||||
|
||||
// 输入数据
|
||||
QSPI_WRITE_TX(spi_base, *send_addr++);
|
||||
}
|
||||
|
||||
// 等待SPI空闲
|
||||
while(QSPI_IS_BUSY(spi_base));
|
||||
}
|
||||
// 读写
|
||||
else if (send_addr != RT_NULL && recv_addr != RT_NULL)
|
||||
{
|
||||
// 清空读FIFO
|
||||
if(!QSPI_GET_RX_FIFO_EMPTY_FLAG(spi_base))
|
||||
{
|
||||
QSPI_ClearRxFIFO(spi_base);
|
||||
while(!QSPI_GET_RX_FIFO_EMPTY_FLAG(spi_base));
|
||||
}
|
||||
|
||||
while (length--)
|
||||
{
|
||||
// 等待TX FIFO 为空
|
||||
while(QSPI_GET_TX_FIFO_FULL_FLAG(spi_base));
|
||||
|
||||
// 输入数据
|
||||
QSPI_WRITE_TX(spi_base, *send_addr++);
|
||||
|
||||
// 读取RX FIFO
|
||||
while(!QSPI_GET_RX_FIFO_EMPTY_FLAG(spi_base))
|
||||
{
|
||||
*recv_addr++ = QSPI_READ_RX(spi_base);
|
||||
}
|
||||
}
|
||||
|
||||
// 等待SPI空闲
|
||||
while(QSPI_IS_BUSY(spi_base))
|
||||
{
|
||||
while(!QSPI_GET_RX_FIFO_EMPTY_FLAG(spi_base))
|
||||
{
|
||||
*recv_addr++ = QSPI_READ_RX(spi_base);
|
||||
}
|
||||
}
|
||||
}
|
||||
//读
|
||||
else
|
||||
{
|
||||
// 清空读FIFO
|
||||
if(!QSPI_GET_RX_FIFO_EMPTY_FLAG(spi_base))
|
||||
{
|
||||
QSPI_ClearRxFIFO(spi_base);
|
||||
while(!QSPI_GET_RX_FIFO_EMPTY_FLAG(spi_base));
|
||||
}
|
||||
|
||||
while (length--)
|
||||
{
|
||||
// 等待TX FIFO 为空
|
||||
while(QSPI_GET_TX_FIFO_FULL_FLAG(spi_base));
|
||||
|
||||
// 输入数据
|
||||
QSPI_WRITE_TX(spi_base, 0x00);
|
||||
|
||||
// 读取RX FIFO
|
||||
while(!QSPI_GET_RX_FIFO_EMPTY_FLAG(spi_base))
|
||||
{
|
||||
*recv_addr++ = QSPI_READ_RX(spi_base);
|
||||
}
|
||||
}
|
||||
|
||||
// 等待SPI空闲
|
||||
while(QSPI_IS_BUSY(spi_base))
|
||||
{
|
||||
while(!QSPI_GET_RX_FIFO_EMPTY_FLAG(spi_base))
|
||||
{
|
||||
*recv_addr++ = QSPI_READ_RX(spi_base);
|
||||
}
|
||||
}
|
||||
|
||||
while(!QSPI_GET_RX_FIFO_EMPTY_FLAG(spi_base))
|
||||
{
|
||||
*recv_addr++ = QSPI_READ_RX(spi_base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static rt_uint32_t m487_qspi_bus_xfer(struct rt_spi_device *device, struct rt_spi_message *message)
|
||||
{
|
||||
struct m487_qspi *spi;
|
||||
|
||||
spi = (struct m487_qspi *) device->bus;
|
||||
|
||||
if (message->cs_take)
|
||||
{
|
||||
QSPI_SET_SS_LOW(spi->spi_base);
|
||||
}
|
||||
|
||||
if (message->length > 0)
|
||||
{
|
||||
qspi_transmission_with_poll(spi, message->send_buf,
|
||||
message->recv_buf, message->length);
|
||||
}
|
||||
|
||||
if (message->cs_release)
|
||||
{
|
||||
QSPI_SET_SS_HIGH(spi->spi_base);
|
||||
}
|
||||
|
||||
return message->length;
|
||||
}
|
||||
|
||||
static int m487_qspi_register_bus(struct m487_qspi *spi_bus, const char *name)
|
||||
{
|
||||
return rt_spi_bus_register(&spi_bus->dev, name, &m487_spi_poll_ops);
|
||||
}
|
||||
|
||||
/**
|
||||
* 硬件QSPI注册
|
||||
*/
|
||||
static int rt_hw_qspi_init(void)
|
||||
{
|
||||
#ifdef USEING_QSPI0
|
||||
m487_qspi_register_bus(&qspi0, "qspi0");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
INIT_DEVICE_EXPORT(rt_hw_qspi_init);
|
||||
#endif
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-3-30 bluebear233 first version
|
||||
*/
|
||||
|
||||
#include <rtdevice.h>
|
||||
|
||||
#ifdef RT_USING_SPI
|
||||
#if defined(RT_USING_W25QXX) || defined(RT_USING_SFUD)
|
||||
static struct rt_spi_device spi_device;
|
||||
#ifdef RT_USING_W25QXX
|
||||
#include "spi_flash_w25qxx.h"
|
||||
#elif defined(RT_USING_SFUD)
|
||||
#include "spi_flash.h"
|
||||
#include "spi_flash_sfud.h"
|
||||
#endif
|
||||
|
||||
|
||||
static int rt_hw_spi_flash_init(void)
|
||||
{
|
||||
rt_spi_bus_attach_device(&spi_device, "qspi01", "qspi0", RT_NULL);
|
||||
|
||||
#ifdef RT_USING_W25QXX
|
||||
|
||||
return w25qxx_init("flash0", "qspi01");
|
||||
|
||||
#elif defined(RT_USING_SFUD)
|
||||
|
||||
if (rt_sfud_flash_probe("flash0", "qspi01") == RT_NULL)
|
||||
{
|
||||
return -RT_ERROR;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -26,8 +26,6 @@ struct usart
|
|||
typedef struct usart* usart_t;
|
||||
|
||||
/* Private functions ------------------------------------------------------------*/
|
||||
|
||||
|
||||
static rt_err_t usart_gpio_configure(struct rt_serial_device *serial);
|
||||
static rt_err_t usart_configure(struct rt_serial_device *serial, struct serial_configure *cfg);
|
||||
static rt_err_t usart_control(struct rt_serial_device *serial, int cmd, void *arg);
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*
|
||||
* @copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
|
||||
*****************************************************************************/
|
||||
#ifndef __SPI_H__
|
||||
#define __SPI_H__
|
||||
#ifndef ___SPI_H__
|
||||
#define ___SPI_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
#define RT_USING_CONSOLE
|
||||
#define RT_CONSOLEBUF_SIZE 128
|
||||
#define RT_CONSOLE_DEVICE_NAME "uart0"
|
||||
#define RT_VER_NUM 0x40000
|
||||
#define RT_VER_NUM 0x40001
|
||||
|
||||
/* RT-Thread Components */
|
||||
|
||||
|
@ -58,7 +58,7 @@
|
|||
#define FINSH_USING_SYMTAB
|
||||
#define FINSH_USING_DESCRIPTION
|
||||
#define FINSH_THREAD_PRIORITY 20
|
||||
#define FINSH_THREAD_STACK_SIZE 1024
|
||||
#define FINSH_THREAD_STACK_SIZE 2048
|
||||
#define FINSH_CMD_SIZE 80
|
||||
#define FINSH_USING_MSH
|
||||
#define FINSH_USING_MSH_DEFAULT
|
||||
|
@ -67,9 +67,22 @@
|
|||
/* Device virtual file system */
|
||||
|
||||
#define RT_USING_DFS
|
||||
#define DFS_FILESYSTEMS_MAX 1
|
||||
#define DFS_USING_WORKDIR
|
||||
#define DFS_FILESYSTEMS_MAX 2
|
||||
#define DFS_FILESYSTEM_TYPES_MAX 2
|
||||
#define DFS_FD_MAX 32
|
||||
#define RT_USING_DFS_ELMFAT
|
||||
|
||||
/* elm-chan's FatFs, Generic FAT Filesystem Module */
|
||||
|
||||
#define RT_DFS_ELM_CODE_PAGE 437
|
||||
#define RT_DFS_ELM_WORD_ACCESS
|
||||
#define RT_DFS_ELM_USE_LFN_3
|
||||
#define RT_DFS_ELM_USE_LFN 3
|
||||
#define RT_DFS_ELM_MAX_LFN 255
|
||||
#define RT_DFS_ELM_DRIVES 2
|
||||
#define RT_DFS_ELM_MAX_SECTOR_SIZE 4096
|
||||
#define RT_DFS_ELM_REENTRANT
|
||||
#define RT_USING_DFS_DEVFS
|
||||
|
||||
/* Device Drivers */
|
||||
|
@ -78,6 +91,9 @@
|
|||
#define RT_PIPE_BUFSZ 64
|
||||
#define RT_USING_SERIAL
|
||||
#define RT_SERIAL_USING_DMA
|
||||
#define RT_SERIAL_RB_BUFSZ 64
|
||||
#define RT_USING_SPI
|
||||
#define RT_USING_W25QXX
|
||||
|
||||
/* Using WiFi */
|
||||
|
||||
|
@ -180,6 +196,8 @@
|
|||
|
||||
/* peripheral libraries and drivers */
|
||||
|
||||
/* sensors drivers */
|
||||
|
||||
|
||||
/* miscellaneous packages */
|
||||
|
||||
|
|
Loading…
Reference in New Issue