Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
flash
SFUD
SPI
15
设备驱动W25Q128,读ID正常,写入读出失败,文件系统挂载失败
发布于 2022-07-04 15:55:27 浏览:1525
订阅该版
没有任何报错的地方,就是写入后,读出来数据是空的。 后来使能了写入,也不行。 读写id都是正常的。 最开始还报了让后我吧系统ticks由100改为1000,目前改为1000了。 换了个电源,提示jedec id不对,flash 是0xef6018,手册上写的,是正确的 ```c [I/SFUD] Error: This reversion(V68.70) JEDEC basic flash parameter header is not supported. [I/SFUD] Warning: Read SFDP parameter header information failed. The w25q128 is not support JEDEC SFDP. [I/SFUD] Warning: This flash device is not found or not support. [I/SFUD] Error: w25q128 flash device is initialize fail. [E/SFUD] ERROR: SPI flash probe failed by SPI device spi1-w25. ``` 另外,那些中间打印信息可以屏蔽么。 代码: ```c #include
#include
#include
//#include "board.h" #include
#include
#include "sfud.h" #include "spi_flash_sfud.h" #include "dfs_fs.h" // Private defines / typedefs --------------------------------------------------- #define EXAMPLES_SPI_BUS_NAME "spi1" #define EXAMPLES_SPI_DEV_NAME "spi1-w25" #define EXAMPLES_SPI_CHIP_NAME "w25q128" #define EXAMPLES_SPI_BUF_LEN 32 #define EXAMPLES_SPI_BUF_STR "This is a spi flash r/w demo." // Private variables ------------------------------------------------------------ int spi_test_count = 0; // Public variables ------------------------------------------------------------- // Private functions prototypes ------------------------------------------------- // Functions -------------------------------------------------------------------- int examples_spi_flash(int argc, char *argv[]) { struct rt_spi_device *spi_dev_w25q128; char name[RT_NAME_MAX]; rt_uint8_t dev_id = 0x90; rt_uint8_t jedec_id = 0x9F; rt_uint8_t id[5] = {0}; rt_err_t res=0; if (spi_test_count == 0) { rt_pin_mode(22, PIN_MODE_OUTPUT); rt_pin_write(22, PIN_HIGH); rt_pin_mode(36, PIN_MODE_OUTPUT); rt_pin_write(36, PIN_HIGH); res = rt_hw_spi_device_attach(EXAMPLES_SPI_BUS_NAME, EXAMPLES_SPI_DEV_NAME, GPIOA, GPIO_PIN_8); rt_kprintf("spi device attach result = %d\r\n", res); spi_test_count = 1; rt_thread_delay(100); } if (argc == 2) { strncpy(name, argv[1], RT_NAME_MAX); } else { strncpy(name, EXAMPLES_SPI_BUS_NAME, RT_NAME_MAX); } /* find spi device */ spi_dev_w25q128 = (struct rt_spi_device *)rt_device_find(EXAMPLES_SPI_DEV_NAME); if (!spi_dev_w25q128) { rt_kprintf("spi sample run failed! can't find %s device!\r\n", name); } else { struct rt_spi_configuration cfg; cfg.data_width = 8; cfg.mode = RT_SPI_MODE_0 | RT_SPI_MSB | RT_SPI_MASTER; /* SPI Compatible Modes 0 and 3 */ cfg.max_hz = 2000000;//66000000; /* Atmel RapidS Serial Interface: 66MHz Maximum Clock Frequency */ res = rt_spi_configure(spi_dev_w25q128, &cfg); rt_kprintf("spi device config result = %d\r\n", res); } //读设备ID 和 JEDEC ID /* 方式1:使用 rt_spi_send_then_recv()发送命令读取ID */ rt_spi_send_then_recv(spi_dev_w25q128, &dev_id, 1, id, 5); rt_kprintf("use rt_spi_send_then_recv() read w25q ID is: 0x%x%x\r\n", id[3], id[4]); rt_spi_send_then_recv(spi_dev_w25q128, &jedec_id, 1, id, 5); rt_kprintf("use rt_spi_send_then_recv() read w25q JEDEC ID is: 0x%x%x%x%x%x\r\n", id[0], id[1], id[2], id[3], id[4]); /* 方式2:使用 rt_spi_transfer_message()发送命令读取ID */ struct rt_spi_message msg1, msg2; msg1.send_buf = &dev_id; msg1.recv_buf = RT_NULL; msg1.length = 1; msg1.cs_take = 1; msg1.cs_release = 0; msg1.next = &msg2; msg2.send_buf = RT_NULL; msg2.recv_buf = id; msg2.length = 5; msg2.cs_take = 0; msg2.cs_release = 1; msg2.next = RT_NULL; rt_spi_transfer_message(spi_dev_w25q128, &msg1); rt_kprintf("use rt_spi_transfer_message() read w25q ID is:%x%x\r\n", id[3], id[4]); msg1.send_buf = &jedec_id; msg1.recv_buf = RT_NULL; msg1.length = 1; msg1.cs_take = 1; msg1.cs_release = 0; msg1.next = &msg2; msg2.send_buf = RT_NULL; msg2.recv_buf = id; msg2.length = 5; msg2.cs_take = 0; msg2.cs_release = 1; msg2.next = RT_NULL; rt_spi_transfer_message(spi_dev_w25q128, &msg1); rt_kprintf("use rt_spi_transfer_message() read w25q JEDEC ID is: 0x%x%x%x%x%x\r\n", id[0], id[1], id[2], id[3], id[4]); //读写数据 uint8_t *read_data = NULL; // 读取到的数据 uint8_t *write_data = NULL; // 将要写入的数据 sfud_flash *sfud_dev = NULL; sfud_err ret; // rt_uint8_t w_enable = 0x06; // struct rt_spi_message msg1; // msg1.send_buf = &w_enable; // msg1.recv_buf = RT_NULL; // msg1.length = 1; // msg1.cs_take = 1; // msg1.cs_release = 0; // msg1.next = RT_NULL; // rt_spi_transfer_message(spi_dev_w25q128, &msg1); // rt_kprintf("write enable\r\n"); // rt_thread_mdelay(1000); if (spi_test_count == 1) { spi_test_count = 2; if (RT_NULL == rt_sfud_flash_probe(EXAMPLES_SPI_CHIP_NAME, EXAMPLES_SPI_DEV_NAME)) { return RT_ERROR; } } sfud_dev = rt_sfud_flash_find(EXAMPLES_SPI_DEV_NAME); // 获取 sfud_dev // sfud_dev = rt_sfud_flash_find_by_dev_name(EXAMPLES_SPI_CHIP_NAME); write_data = rt_malloc(EXAMPLES_SPI_BUF_LEN); rt_memset(write_data, 0, EXAMPLES_SPI_BUF_LEN); rt_strncpy(write_data, EXAMPLES_SPI_BUF_STR, rt_strlen(EXAMPLES_SPI_BUF_STR)); ret = sfud_erase_write(sfud_dev, 0, EXAMPLES_SPI_BUF_LEN, write_data); // 将数据 32 字节的 write_data 从 65535 开始写入 flash if(ret == SFUD_SUCCESS) { rt_kprintf("sfud write data at 0 is: %s\r\n", write_data); } else { rt_kprintf("sfud write data failed\n"); } read_data = rt_malloc(EXAMPLES_SPI_BUF_LEN); rt_memset(read_data, 0, EXAMPLES_SPI_BUF_LEN); ret = sfud_read(sfud_dev, 0, EXAMPLES_SPI_BUF_LEN, read_data); // 读取从 65535 开始的 32 字节,存入 read_data if(ret == SFUD_SUCCESS) { rt_kprintf("sfud read data at 0 is: %s\r\n", read_data); } else { rt_kprintf("sfud read data failed\n"); } dfs_init(); elm_init(); dfs_mkfs(EXAMPLES_SPI_FS_NAME, EXAMPLES_SPI_CHIP_NAME); if(rt_device_find(EXAMPLES_SPI_CHIP_NAME) != RT_NULL) { if(dfs_mount(EXAMPLES_SPI_CHIP_NAME, "/", EXAMPLES_SPI_FS_NAME, 0, 0) == 0) { rt_kprintf("dfs moutn succ\r\n"); } else { rt_kprintf("dfs moutn fail\r\n"); } } return 0; } MSH_CMD_EXPORT(examples_spi_flash, "spi w25q sample"); ``` 运行打印信息: ```c \ | / - RT - Thread Operating System / | \ 3.1.5 build Jul 4 2022 2006 - 2020 Copyright by rt-thread team spi1-w25 attach to spi1 done spi device attach result = 0 msh /> spi device config result = 0 spi1 init done spi1 transfer prepare and start spi1 sendbuf: 20004848, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 20004810, length: 5 spi1 transfer done use rt_spi_send_then_recv() read w25q ID is: 0x00 spi1 transfer prepare and start spi1 sendbuf: 2000484C, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 20004810, length: 5 spi1 transfer done use rt_spi_send_then_recv() read w25q JEDEC ID is: 0xef601800 spi1 transfer prepare and start spi1 sendbuf: 20004848, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 20004810, length: 5 spi1 transfer done use rt_spi_transfer_message() read w25q ID is:17ef spi1 transfer prepare and start spi1 sendbuf: 2000484C, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 20004810, length: 5 spi1 transfer done use rt_spi_transfer_message() read w25q JEDEC ID is: 0xef601800 spi1 init done [W/SFUD] [SFUD] Warning: The OS tick(100) is less than 1000. So the flash write will take more time. spi1 transfer prepare and start spi1 sendbuf: 20004798, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 20004794, length: 3 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 20004774, recvbuf: 0, length: 5 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 20004788, length: 8 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 2000476C, recvbuf: 0, length: 5 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 20004780, length: 8 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 2000474C, recvbuf: 0, length: 5 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 20004760, length: 36 spi1 transfer done [I/SFUD] Find a Winbond flash chip. Size is 16777216 bytes. spi1 transfer prepare and start spi1 sendbuf: 2000478C, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 20004764, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 20004770, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 2000478D, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 20004764, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 20004770, length: 1 spi1 transfer done [I/SFUD] w25q128 flash device is initialize success. [I/SFUD] Probe SPI flash w25q128 by SPI device spi1-w25 success. spi1 transfer prepare and start spi1 sendbuf: 200047A4, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 20004794, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 200047A8, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 200047C4, recvbuf: 0, length: 4 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 2000479C, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 200047A8, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 200047A4, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 20004794, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 200047A8, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 200047AC, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 2000479C, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 200047B0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 200013BC, recvbuf: 0, length: 36 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 200047A4, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 200047B0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 200047AC, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 2000479C, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 200047B0, length: 1 spi1 transfer done sfud write data at 0 is: This is a spi flash r/w demo. spi1 transfer prepare and start spi1 sendbuf: 200047BC, recvbuf: 0, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 200047C8, length: 1 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 200047E4, recvbuf: 0, length: 4 spi1 transfer done spi1 transfer prepare and start spi1 sendbuf: 0, recvbuf: 2000603C, length: 32 spi1 transfer done sfud read data at 0 is: dfs already init. [E/DFS] There is no space to register this file system (elm). [E/DFS] File system (FatFs) was not found. dfs moutn fail ``` ![9.png](https://oss-club.rt-thread.org/uploads/20220704/059d57c3ef49adca67ff5ca2170a19a5.png "9.png") ![8.png](https://oss-club.rt-thread.org/uploads/20220704/ca43c9bf80363c9ec891540471291078.png "8.png") ![7.png](https://oss-club.rt-thread.org/uploads/20220704/f1e9734001fec26343a8658238a46f42.png "7.png")
查看更多
2
个回答
默认排序
按发布时间排序
melody
2022-07-08
世界人民大团结万岁
解决问题后总结: 1. 回复中提到的,RT_SFUD_USING_FLASH_INFO_TABLE不需要打开。 2. 使用Flash时候要注意自己的Flash Jedec ID,我的w25q128 是 0xEF6018。驱动中是0xEF4018。我虽然注意到了这个问题,但是一直没有找到哪里修改。 注意查看:sfud_flash_def.h 里面, SFUD_FLASH_CHIP_TABLE 修改对应的ID就可以。
红枫
认证专家
2022-07-04
这家伙很懒,什么也没写!
#### 文件系统挂载数量配置不够吧! >[E/DFS] There is no space to register this file system (elm).
撰写答案
登录
注册新账号
关注者
0
被浏览
1.5k
关于作者
melody
世界人民大团结万岁
提问
30
回答
6
被采纳
1
关注TA
发私信
相关问题
1
BBB的SPI驱动
2
求个SPI上挂两个或多个设备的使用例子
3
SPI设备有个bug
4
spi flash 的fatfs使用一段时间后读写文件出现故障
5
SPI驱动
6
请教rt_spi_configure函数理解
7
SPI FLASH挂载的问题
8
SPI-FLASH 文件系统 SPIFFS
9
求助一个完整的 spi flash 驱动
10
关于同时使用文件系统与SPI FLASH的问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
2
RT-Thread 发布 EtherKit开源以太网硬件!
3
rt-thread使用cherryusb实现虚拟串口
4
《C++20 图形界面程序:速度与渲染效率的双重优化秘籍》
5
《原子操作:程序世界里的“最小魔法单位”解析》
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
at_device
ulog
C++_cpp
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
a1012112796
13
个答案
2
次被采纳
张世争
9
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
11
个答案
1
次被采纳
本月文章贡献
程序员阿伟
7
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
3
次点赞
ThinkCode
1
篇文章
1
次点赞
Betrayer
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部