新手上路
- 积分
- 46
- 金钱
- 46
- 注册时间
- 2019-12-4
- 在线时间
- 25 小时
|
50金钱
定义如下
- #define FLASH_SECTOR_SIZE 512
- #define FLASH_SECTOR_COUNT 8 * 1024 * 2// 8M的spiflash
- #define FLASH_BLOCK_SIZE 8 //每个BLOCK有8个扇区
复制代码 我自己写了flash 读写函数,在格式化spi flash 的时候,代码如下
- void w25qxxtestfunction(void* parameter)
- {
- rt_kprintf("w25qxx running\n");
- FATFS exfalsh ={0};
- uint8_t res = 0 ;
- // QspiFlash_Erase4KbSector(0);
- res = f_mount(&exfalsh,"0:",1);
- BYTE work[FF_MAX_SS];
- MKFS_PARM opt = {0};
- opt.fmt = 1 ;
- opt.n_fat = 1 ;
- opt.align = 4096 ;
- opt.n_root = 0 ;
- opt.au_size = 0 ;
- if(res == 0x0d)
- {
- res = f_mkfs("0:",&opt,work,sizeof(work));
- if(res == 0)
- {
- res = f_mount(&exfalsh,"0:",1);
- }
- }
- printf("flash mount state:%d\r\n",res);
- while(1)
- {
-
- rt_thread_delay(3000);
- }
- }
复制代码- DRESULT disk_read (
- BYTE pdrv, /* Physical drive nmuber to identify the drive */
- BYTE *buff, /* Data buffer to store read data */
- LBA_t sector, /* Start sector in LBA */
- UINT count /* Number of sectors to read */
- )
- {
- // DRESULT res;
- int result;
- switch (pdrv) {
- case W25QXX :
- // translate the arguments here
-
-
- // result = flashfatfsread(buff, sector * FATFS_SECTOR_SIZE, count * FATFS_SECTOR_SIZE);
- result = w25qxxread(buff, sector * FATFS_SECTOR_SIZE, count * FATFS_SECTOR_SIZE);
- // translate the reslut code here
- return (DRESULT)result;
- }
- return RES_PARERR;
- }
复制代码- DRESULT disk_write (
- BYTE pdrv, /* Physical drive nmuber to identify the drive */
- const BYTE *buff, /* Data to be written */
- LBA_t sector, /* Start sector in LBA */
- UINT count /* Number of sectors to write */
- )
- {
- //DRESULT res;
- int result;
- switch (pdrv) {
- case W25QXX :
- // result = flashfatfswrite((uint8_t *)buff,sector * FATFS_SECTOR_SIZE,count * FATFS_SECTOR_SIZE);
- result = w25qxxwrite((uint8_t *)&buff, sector * FATFS_SECTOR_SIZE, count * FATFS_SECTOR_SIZE);
- return (DRESULT)result;
- }
- return RES_PARERR;
- }
复制代码
等了很久后,格式化返回的是0,再次挂载,还是会返回13,搞了好几天了头大,写入和读出函数已经验证过了,是完全正常的.完全没有头绪了,有经验的大佬能讲讲,我是不是还缺少什么环节啊
|
最佳答案
查看完整内容[请看2#楼]
正常来说,擦除后,重新格式化SPI FLASH会比较快实现。
具体实现代码,你可以参考下我们的例程,我们的fatfs支持访问SPI FLASH
|