通过下面代码
#include <rtthread.h>
#include "spi_flash.h"
#include "spi_flash_sfud.h"
#include "drv_spi.h"
#if defined(BSP_USING_SPI_FLASH)
static int rt_hw_spi_flash_init(void)
{
__HAL_RCC_GPIOB_CLK_ENABLE();
rt_hw_spi_device_attach("spi2", "spi20", GPIOB, GPIO_PIN_9);
if (RT_NULL == rt_sfud_flash_probe("W25Q64", "spi20"))
{
return -RT_ERROR;
}
return RT_EOK;
}
INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init);
#endif
开启SPI Flash功能支持后
还需要在menucofig
开启自动挂载表功能
-*- Using device virtual file system
[*] Using working directory
(2) The maximal number of mounted file system
(2) The maximal number of file system type
(16) The maximal number of opened files
[*] Using mount table for file system
[*] Enable elm-chan fatfs
elm-chan's FatFs, Generic FAT Filesystem Module --->
-*- Using devfs for device objects
[ ] Enable ReadOnly file system on flash
[ ] Enable RAM file system
[ ] Enable UFFS file system: Ultra-low-cost Flash File System
[ ] Enable JFFS2 file system
[ ] Using NFS v3 client file system
开启这个功能后,在shell终端需要用SF Probe 命令后才能用ls列表出来,不然调到芯片状态查询死循环出不来。