OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 6706|回复: 8

使用FATFS挂载SD卡使,读取容量,返回 FR_NO_FILESYSTEM;

[复制链接]

6

主题

23

帖子

0

精华

初级会员

Rank: 2

积分
55
金钱
55
注册时间
2016-4-23
在线时间
15 小时
发表于 2016-4-26 14:01:20 | 显示全部楼层 |阅读模式
1金钱
void LCD_OD_Test(void)
{             /*!<Flash picture number initial value*/   
  uint8_t KeyInfoTmp;                 /*!<KeyInfo temporary data*/
uint8_t *ptr1=0;
uint8_t *ptr2=0;
uint8_t ptraddr[18];
uint16_t i=0;
uint8_t usage=0;
  uint32_t total=0,free=0;
uint8_t status1=0;
  uint8_t status2=0;
LCD_Init();/*!<LCM&SSD282X Init*/
  MemoryInit();
  while(SD_Init()!=SD_OK)
  {
   StringDisplay(5,52,"SD_Init Fail",RED);
   StringDisplay(5,69,"pleas check",RED);
   Delay_ms(500);
   LED_Toggle(LED2);
  }
  ShowSDCardInfo();
  sprintf((char*)ptraddr,"SD_Size:%dMB",SDCardInfo.CardCapacity>>20);
  StringDisplay(5,52,"SD Successful",GREEN);
  StringDisplay(5,69,ptraddr,GREEN);
  
  while(extraFunctionInit())
  {
   printf("\r\n please check.....");
   Delay_ms(500);
  }
       printf("\r\n after malloc (3)fs1=%p",fs1);
       printf("\r\n after malloc (3)&fs1%d",&fs1);   
  status1=f_mount(0,fs1);
  printf("\r\nResult from f_mount is:%d",status1);
  
  status2=capacityGet(0,&total,&free);
  printf("\r\nResult from FATFS is:%d",status2);
  while(status2)
  {
     StringDisplay(5,86,"SD FATFS FAIL",RED);   
     StringDisplay(5,103,"Check!!",RED);   
  }
   StringDisplay(5,120,"By FATFAS READ",GREEN);
   StringDisplay(5,137,"Total:",GREEN);
   ValueDisplay(102,137,total,GREEN);  
   StringDisplay(5,154,"Free:",GREEN);  
   ValueDisplay(102,154,free,GREEN);
  while(1);


通过串口信息追踪,直接操作SD读取容量,读取里面文件信息也是成功的;
调用malloc分配供FATFS使用的空间也是OK的;
使用f_mount()注册磁盘,返回也是OK的;
然后在通过FATFS获取容量是,返回 FR_NO_FILESYSTEM;
然后通过不停的插入printf,capacityGet()调用f_getfree(),然后f_getfree调用chk_mounted(),
错误发生在chk_mounted()中。如下加粗斜体文字部分,fmt返回值为2,然后就返回了 FR_NO_FILESYSTEM;
串口信息如图片,请教下各位是哪里出问题了、、、、。完全懵逼了。

    fmt = check_fs(fs, bsect = 0);        /* Load sector 0 and check if it is an FAT-VBR (in SFD) */
   printf("\r\n Error test: check_fs(fs, bsect = 0)=fmt =%d",fmt);   
    if (LD2PT(vol) && !fmt) fmt = 1;    /* Force non-SFD if the volume is forced partition */
     printf("\r\n (2)fmt =%d",fmt);  
    if (fmt == 1) {                        /* Not an FAT-VBR, the physical drive can be partitioned */
        /* Check the partition listed in the partition table */
        pi = LD2PT(vol);
        if (pi) pi--;
        tbl = &fs->win[MBR_Table + pi * SZ_PTE];/* Partition table */
        if (tbl[4]) {                        /* Is the partition existing? */
            bsect = LD_DWORD(&tbl[8]);        /* Partition offset in LBA */
            fmt = check_fs(fs, bsect);        /* Check the partition */
        }
    }
printf("\r\n (3)fmt =%d",fmt);    if (fmt == 3) return FR_DISK_ERR;
    if (fmt) return FR_NO_FILESYSTEM;        /* No FAT volume is found */
2016-04-26_140049.jpg

最佳答案

查看完整内容[请看2#楼]

多谢原子哥。搞定了。。。一个问题还是DMA传输的问题。。 文件容量读取出错是变量类型的问题,忘了设成long long了
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

6

主题

23

帖子

0

精华

初级会员

Rank: 2

积分
55
金钱
55
注册时间
2016-4-23
在线时间
15 小时
 楼主| 发表于 2016-4-26 14:01:21 | 显示全部楼层
正点原子 发表于 2016-5-1 12:07
这个提示说明你的文件系统有问题,格式化SD卡,重新试试

多谢原子哥。搞定了。。。一个问题还是DMA传输的问题。。
文件容量读取出错是变量类型的问题,忘了设成long long了
回复

使用道具 举报

6

主题

23

帖子

0

精华

初级会员

Rank: 2

积分
55
金钱
55
注册时间
2016-4-23
在线时间
15 小时
 楼主| 发表于 2016-4-26 14:02:21 | 显示全部楼层
另外。。弱弱的问下,为了使贴上来的代码看起来没那么乱,我在发帖的时候选择添加代码,点击了没用。。这个怎么弄啊?
回复

使用道具 举报

6

主题

23

帖子

0

精华

初级会员

Rank: 2

积分
55
金钱
55
注册时间
2016-4-23
在线时间
15 小时
 楼主| 发表于 2016-4-26 16:13:07 | 显示全部楼层
更新下新状况。。完全懵逼了。我单步Debug code。。运行就是正常的。求助各位大神。截图如下:
2016-04-26_161047.jpg
2016-04-26_161151.jpg
回复

使用道具 举报

6

主题

23

帖子

0

精华

初级会员

Rank: 2

积分
55
金钱
55
注册时间
2016-4-23
在线时间
15 小时
 楼主| 发表于 2016-4-26 16:16:20 | 显示全部楼层
而且读取出来的。应该是KB。换算成MB。也不等于调用ShowSDCardInfo()得出来的,3324MB。。。
回复

使用道具 举报

6

主题

23

帖子

0

精华

初级会员

Rank: 2

积分
55
金钱
55
注册时间
2016-4-23
在线时间
15 小时
 楼主| 发表于 2016-4-27 10:07:02 | 显示全部楼层
跪求大神。。。想到单步运行跟直接运行唯一的区别是时间问题,我在程序里试了个遍,在disk_read加上至少800us的延时就能正常读取。
可是想不明白为什么。。
[mw_shl_code=c,true]DRESULT disk_read (
    BYTE drv,        /* Physical drive nmuber (0..) */
    BYTE *buff,        /* Data buffer to store read data */
    DWORD sector,    /* Sector address (LBA) */
    BYTE count        /* Number of sectors to read (1..255) */
)
{
       
        uint8_t status=0;
       
    if(((uint32_t)buff&(uint32_t)0x1)!=0)
        printf("\r\n disk_read error:data is not aligned!buff is %x,count is %d",buff,count);
   
    if (count > 1)
    {
                                status=SDRead(buff,sector,count);
                          Delay_ms(5);                               
    }
    else
    {
                         status=SDRead(buff,sector,count);   
                         Delay_ms(1);               
    }
                //printf("\r\n In disread  status=%d",status);
   if(status==0x00) return RES_OK;
                else return RES_ERROR;
               
}[/mw_shl_code]
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165377
金钱
165377
注册时间
2010-12-1
在线时间
2111 小时
发表于 2016-5-1 12:07:14 | 显示全部楼层
这个提示说明你的文件系统有问题,格式化SD卡,重新试试
回复

使用道具 举报

4

主题

33

帖子

0

精华

高级会员

Rank: 4

积分
552
金钱
552
注册时间
2016-4-10
在线时间
100 小时
发表于 2016-7-22 16:11:06 | 显示全部楼层
正点原子 发表于 2016-5-1 12:07
这个提示说明你的文件系统有问题,格式化SD卡,重新试试

格式化就可以了,搞死我了。。。。
回复

使用道具 举报

13

主题

65

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
403
金钱
403
注册时间
2016-2-2
在线时间
66 小时
发表于 2016-7-24 15:01:07 | 显示全部楼层
最好格式化一下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-2-27 20:41

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表