flash:W25Q16DV
代码:
#include "drv_spi.h"
#include <rtdevice.h>
#include "spi_flash_sfud.h"
#define SPI_NAME "spi1" //spi 接口名
#define CS_GPIO GPIOB //片选GPIO组 stn32
#define CS_PIN GPIO_PIN_14 //片选GPIO脚 stm32
#define SPI_DEV_NAME "spi10" //挂在在spi总线上的设备名
#define FLASE_NAME "W25Q16" //flash设备名
#define FS_NAME "elm" //文件系统
#define ROOT_PATH "/flash1" //文件系统的根目录
int w25q_init(void){
rt_hw_spi_device_attach(SPI_NAME, SPI_DEV_NAME, CS_GPIO, CS_PIN);
rt_hw_us_delay(100);
if(rt_sfud_flash_probe(FLASE_NAME, SPI_DEV_NAME)){
rt_kprintf("sfud flash probe success\n");
return RT_EOK;
}
else{
rt_kprintf("sfud flash probe fail\n");
return RT_ERROR;
}
}
INIT_COMPONENT_EXPORT(w25q_init);
int dfs_mount_init(void){
dfs_mkfs(FS_NAME, FLASE_NAME);
if(dfs_mount(FLASE_NAME, ROOT_PATH, FS_NAME, 0, 0) == 0){
rt_kprintf("dfs_mount success\n");
return RT_EOK;
}
else{
rt_kprintf("dfs_mount fail\n");
return RT_ERROR;
}
}
INIT_COMPONENT_EXPORT(dfs_mount_init);
输出:
[I/SFUD] Warning: Read SFDP parameter header information failed. The W25Q16 is not support JEDEC SFDP.
[I/SFUD] Find a Winbond W25Q16BV flash chip. Size is 2097152 bytes.
[I/SFUD] W25Q16 flash device is initialize success.
[I/SFUD] Probe SPI flash W25Q16 by SPI device spi10 success.
sfud flash probe success
[I/SFUD] Error: Can't enable write status.
format error, result=1
dfs_mount fail
我不使用代号,使用sf工具操作flash,读是没有问题的,但是写和删除有问题,问题时好时坏,就像github上说的可能是读切换日佥楽题
msh />sf read 0 64
Read the sf_cmd flash data success. Start from 0x00000000, size is 64. The data is:
Offset (h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
[00000000] 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
[00000010] 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
[00000020] 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
[00000030] 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
msh />sf ser
msh />sf era
msh />sf erase 0 8194
[I/SFUD] Error: Can't disable write status.
Erase the sf_cmd flash data success. Start from 0x00000000, size is 8194.
msh />sf write 1000 1 2 3 4 5 #这里写入成功
Write the sf_cmd flash data success. Start from 0x000003E8, size is 5.
Write data: 1 2 3 4 5 .
msh />sf erase 0 8194
[I/SFUD] Error: Can't enable write status.
This flash operate has an error. Error code: 2.
msh />sf erase 0 8194
[I/SFUD] Error: Can't disable write status.
Erase the sf_cmd flash data success. Start from 0x00000000, size is 8194.
msh />sf read 1000 5
Read the sf_cmd flash data success. Start from 0x000003E8, size is 5. The data is:
Offset (h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
[000003E8] 02 02 02 02 02 .....
msh />sf write 0 1 2 3 4 5
[I/SFUD] Error: Can't disable write status.
Write the sf_cmd flash data success. Start from 0x00000000, size is 5.
Write data: 1 2 3 4 5 .
msh />sf write 0 1 2 3 4 5
[I/SFUD] Error: Can't disable write status.
Write the sf_cmd flash data success. Start from 0x00000000, size is 5.
Write data: 1 2 3 4 5 .
msh />sf write 500 1 2 3 4 5
[I/SFUD] Error: Can't disable write status.
Write the sf_cmd flash data success. Start from 0x000001F4, size is 5.
Write data: 1 2 3 4 5 .
msh />sf erase 0 8194
[I/SFUD] Error: Can't disable write status.
Erase the sf_cmd flash data success. Start from 0x00000000, size is 8194.
msh />sf status
The sf_cmd flash status register current value is 0xFF.
msh />sf status
The sf_cmd flash status register current value is 0x02.
msh />
msh />sf status
The sf_cmd flash status register current value is 0x02.
msh />sf status
The sf_cmd flash status register current value is 0x02.
msh />sf write 500 1 2 3 4 5
Write the sf_cmd flash data success. Start from 0x000001F4, size is 5.
Write data: 1 2 3 4 5 .
msh />sf status
The sf_cmd flash status register current value is 0x02.
msh />sf erase 0 8194
[I/SFUD] Error: Can't enable write status.
This flash operate has an error. Error code: 2.
msh />
功能:spi驱动flash挂载文件系统