f_mount()返回FA_DISK_ERR [英] f_mount() returns FA_DISK_ERR

查看:928
本文介绍了f_mount()返回FA_DISK_ERR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人都提出了建议后,我对源代码进行了一些更改.为了将FATFS API与SPI接口连接,我遵循了此代码.

I have made few changes in my source code after suggestion form everyone.For connecting FATFS API with SPI interface i have followed this code..

https://github.com/eziya/STM32_SPI_SDCARD/blob/master/Src/fatfs_sd.c

,并相应地更改了我的user_diskio.c.

and changed my user_diskio.c accordingly.

完成所有这些操作之后,我的SD卡也会返回FA_DISK_ERROR.

After doing all those things then also my SD Card returns FA_DISK_ERROR.

我更改了SD卡插槽以及SD卡.但是什么都没改变.

I have changed SD Card slot as well as SD Card. But nothing Changed.

我的user_diskio.c看起来像这样:

#include <string.h>
#include "ff_gen_drv.h"
#include "fatfs_sd.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/
/* Disk status */
static volatile DSTATUS Stat = STA_NOINIT;

/* USER CODE END DECL */

/* Private function prototypes -----------------------------------------------*/
DSTATUS USER_initialize (BYTE pdrv);
DSTATUS USER_status (BYTE pdrv);
DRESULT USER_read (BYTE pdrv, BYTE *buff, DWORD sector, UINT count);
#if _USE_WRITE == 1
  DRESULT USER_write (BYTE pdrv, const BYTE *buff, DWORD sector, UINT count);  
#endif /* _USE_WRITE == 1 */
#if _USE_IOCTL == 1
  DRESULT USER_ioctl (BYTE pdrv, BYTE cmd, void *buff);
#endif /* _USE_IOCTL == 1 */

Diskio_drvTypeDef  USER_Driver =
{
  USER_initialize,
  USER_status,
  USER_read, 
#if  _USE_WRITE
  USER_write,
#endif  /* _USE_WRITE == 1 */  
#if  _USE_IOCTL == 1
  USER_ioctl,
#endif /* _USE_IOCTL == 1 */
};

/* Private functions ---------------------------------------------------------*/

/**
  * @brief  Initializes a Drive
  * @param  pdrv: Physical drive number (0..)
  * @retval DSTATUS: Operation status
  */
DSTATUS USER_initialize (
    BYTE pdrv           /* Physical drive nmuber to identify the drive */
)
{
  /* USER CODE BEGIN INIT */
    return SD_disk_initialize(pdrv);
  /* USER CODE END INIT */
}

/**
  * @brief  Gets Disk Status 
  * @param  pdrv: Physical drive number (0..)
  * @retval DSTATUS: Operation status
  */
DSTATUS USER_status (
    BYTE pdrv       /* Physical drive number to identify the drive */
)
{
  /* USER CODE BEGIN STATUS */
    return SD_disk_status(pdrv);
  /* USER CODE END STATUS */
}

/**
  * @brief  Reads Sector(s) 
  * @param  pdrv: Physical drive number (0..)
  * @param  *buff: Data buffer to store read data
  * @param  sector: Sector address (LBA)
  * @param  count: Number of sectors to read (1..128)
  * @retval DRESULT: Operation result
  */
DRESULT USER_read (
    BYTE pdrv,      /* Physical drive nmuber to identify the drive */
    BYTE *buff,     /* Data buffer to store read data */
    DWORD sector,   /* Sector address in LBA */
    UINT count      /* Number of sectors to read */
)
{
  /* USER CODE BEGIN READ */
    return SD_disk_read(pdrv, buff, sector, count);
  /* USER CODE END READ */
}

/**
  * @brief  Writes Sector(s)  
  * @param  pdrv: Physical drive number (0..)
  * @param  *buff: Data to be written
  * @param  sector: Sector address (LBA)
  * @param  count: Number of sectors to write (1..128)
  * @retval DRESULT: Operation result
  */
#if _USE_WRITE == 1
DRESULT USER_write (
    BYTE pdrv,          /* Physical drive nmuber to identify the drive */
    const BYTE *buff,   /* Data to be written */
    DWORD sector,       /* Sector address in LBA */
    UINT count          /* Number of sectors to write */
)
{ 
  /* USER CODE BEGIN WRITE */
  /* USER CODE HERE */
    return SD_disk_write(pdrv, buff, sector, count);
  /* USER CODE END WRITE */
}
#endif /* _USE_WRITE == 1 */

/**
  * @brief  I/O control operation  
  * @param  pdrv: Physical drive number (0..)
  * @param  cmd: Control code
  * @param  *buff: Buffer to send/receive control data
  * @retval DRESULT: Operation result
  */
#if _USE_IOCTL == 1
DRESULT USER_ioctl (
    BYTE pdrv,      /* Physical drive nmuber (0..) */
    BYTE cmd,       /* Control code */
    void *buff      /* Buffer to send/receive control data */
)
{
  /* USER CODE BEGIN IOCTL */
    return SD_disk_ioctl(pdrv, cmd, buff);
  /* USER CODE END IOCTL */
}
#endif /* _USE_IOCTL == 1 */

fatfs_sd.c看起来像这样:

转到上面的GITHUB链接

GO TO THE ABOVE GITHUB LINK

不知道我要去哪里错了.

Have no idea where i am going wrong.

有关此主题的任何内容都会有所帮助.

Anything on this topic will be helpful.

先谢谢了.

推荐答案

我以前使用stm32f7芯片为FatFS编写了自己的驱动程序,并认为我可能知道发生了什么事情.我的猜测是,您可能忘记了为diskio.h中的disk_writedisk_read函数附加实现.如果不这样做,FatFS库就不知道如何与SD卡实际接口.

I've written my own driver using an stm32f7 chip for FatFS before and think I might know what's going on. My guess is that you likely forgot to attach implementations for the disk_write and disk_read functions in diskio.h. Without doing that, the FatFS library has no clue on how to actually interface with the SD card.

您可以将FatFS文档/手册作为常规资源查看:此处

You could check out the FatFS documentation/manual as a general resource: here

非常非常重视必需的功能";此应用笔记中的部分:此处

像您的示例项目,但适用于STM32F4:

An example project like yours but for STM32F4: here

这篇关于f_mount()返回FA_DISK_ERR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆