打印

SD卡FATS系统失败,请求解决

[复制链接]
227|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
丑帅丑帅的|  楼主 | 2019-11-13 17:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近刚学习FATS,但是将程序下进板中 无法得到程序应有的效果(程序为板子配套的代码,而且sd卡驱动能够正常运行)。
经过检查FATS调用函数的返回值,发现如下
res=f_mount(0,&fs);——————0————FR_OK
res = f_open(&fnew, "0:newfile.txt", FA_CREATE_ALWAYS | FA_WRITE );_______13________FR_NO_FILESYSTEM,  /* (13) There is no valid FAT volume */
res = f_read(&fnew, buffer, sizeof(buffer), &br); ________9___________FR_INVALID_OBJECT,  /* (9) The file/directory object is invalid */






请问下,该如何解决这个问题啊???小弟,拜谢了






下面的是主函数的代码


FIL fnew;             /* file objects */
FATFS fs;             /* Work area (file system object) for logical drives */
FRESULT res;
UINT br, bw;                 /* File R/W count */
BYTE buffer[4096]={0};           /* file copy buffer */
BYTE textFileBuffer[] = "Welcome to use Wildfire iso stm32 Development Board today is a good day";
int main(void)
{
   /* USART1 config */
  USART1_Config();
  printf("\r\n this is a fatfs test demo \r\n");

  /* Sdio Interrupt Config */
  NVIC_Configuration();

  /* Register work area for each volume (Always succeeds regardless of disk status) */
  res=f_mount(0,&fs);
  printf("1___%d   ",res);

//  f_mkdir("sub");
//  f_mkdir("sub/sub1");
  /* function disk_initialize() has been called in f_open */

  /* Create new file on the drive 0 */
  res = f_open(&fnew, "0:newfile.txt", FA_CREATE_ALWAYS | FA_WRITE );
   printf("2___%d   ",res);
  if ( res == FR_OK )
  {
   res = f_write(&fnew, textFileBuffer, sizeof(textFileBuffer), &bw);
   printf("3__%d   ",res);
   f_close(&fnew);      
  }
  res = f_open(&fnew, "0:newfile.txt", FA_OPEN_EXISTING | FA_READ);
  printf("4__%d    ",res);
  res = f_read(&fnew, buffer, sizeof(buffer), &br);
  printf("5__%d    ",res);
  printf("\r\n %s ", buffer);
  
  /* Close open files */
  f_close(&fnew);                                       
   
    /* Unregister work area prior to discard it */
    f_mount(0, NULL);
  
  while(1);
}

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

741

主题

742

帖子

0

粉丝