野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7556|回复: 3

fatfs移植 f_mount提示底层io代码出错,求大佬帮忙看看那里错了!!!

[复制链接]
发表于 2019-6-18 17:43:38 | 显示全部楼层 |阅读模式
在调用挂在函数f_mount时,返回值是  FR_DISK_ERR,                        /* (1) A hard error occurred in the low level disk I/O layer */
所以应该是底层函数挂了,spi_flash的函数都是正常的,测试过。求大佬帮忙看看是哪儿出错了!!!!

我的底层函数如下:
[mw_shl_code=c,true]DSTATUS disk_status (
        BYTE pdrv                /* Physical drive nmuber to identify the drive */
)
{
       
        uint32_t result;

        switch (pdrv) {
        case SD_CARD:
//                result = ATA_disk_status();

                // translate the reslut code here

               


        case FLASH_MEMORY:
//                result = MMC_disk_status();
                result = SPI_FLASH_ReadId();
                // translate the reslut code here
                if(result == 0xef4017)
                {
                        return 0;
                }
                else
                {
                        return STA_NOINIT;
                }
               

        default:
                return STA_NOINIT;

        }
       
}



/*-----------------------------------------------------------------------*/
/* Inidialize a Drive                                                    */
/*-----------------------------------------------------------------------*/

DSTATUS disk_initialize (
        BYTE pdrv                                /* Physical drive nmuber to identify the drive */
)
{
       

        switch (pdrv) {
        case SD_CARD:
//                result = ATA_disk_initialize();

                // translate the reslut code here

               


        case FLASH_MEMORY:
//                result = MMC_disk_initialize();

                // translate the reslut code here

                SPI_FALSH_GPIO_Config();
                SPI_FLASH_Config();
                SPI_Flash_WAKEUP();
               
                return disk_status(FLASH_MEMORY);

        default:
                return STA_NOINIT;

        }
       
}



/*-----------------------------------------------------------------------*/
/* Read Sector(s)                                                        */
/*-----------------------------------------------------------------------*/

DRESULT disk_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 */
)
{
        DRESULT res;


        switch (pdrv) {
        case SD_CARD:
                // translate the arguments here

//                result = ATA_disk_read(buff, sector, count);

                // translate the reslut code here

               

        case FLASH_MEMORY:
                // translate the arguments here

//                result = MMC_disk_read(buff, sector, count);

                // translate the reslut code here
                SPI_FLASH_ReadByte(sector << 12, buff, count << 12);
                res = RES_OK;
                return res;
        default :
                        return RES_PARERR;
       
        }


}



/*-----------------------------------------------------------------------*/
/* Write Sector(s)                                                       */
/*-----------------------------------------------------------------------*/

#if _USE_WRITE
DRESULT disk_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 */
)
{
        DRESULT res;


        switch (pdrv) {
        case SD_CARD :
                // translate the arguments here

//                result = ATA_disk_write(buff, sector, count);

                // translate the reslut code here

                return res;

        case FLASH_MEMORY :
                // translate the arguments here

//                result = MMC_disk_write(buff, sector, count);

                // translate the reslut code here
                SPI_FALSH_Erase_Sector(sector<< 12);
                SPI_FLASH_WritBytes(sector<< 12, (uint8_t*)buff, count<< 12);
                res = RES_OK;
                return res;
        default :
                return RES_PARERR;
       
        }

       
}
#endif


/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions                                               */
/*-----------------------------------------------------------------------*/

#if _USE_IOCTL
DRESULT disk_ioctl (
        BYTE pdrv,                /* Physical drive nmuber (0..) */
        BYTE cmd,                /* Control code */
        void *buff                /* Buffer to send/receive control data */
)
{
        DRESULT res;
       

        switch (pdrv) {
        case SD_CARD :

                // Process of the command for the ATA drive

                return res;

        case FLASH_MEMORY :

                // Process of the command for the MMC/SD card
                switch(cmd)
                {
                        case GET_SECTOR_COUNT:
                                *(DWORD* )buff = 2048;
                                break;
                        case GET_SECTOR_SIZE:
                                *(WORD*)buff = 4096;
                                break;
                        case GET_BLOCK_SIZE:
                                *(DWORD* )buff = 1;
                                break;
                }

                return res;

        default :
                return RES_PARERR;
        }


}
#endif[/mw_shl_code]


回复

使用道具 举报

发表于 2019-6-19 15:08:14 | 显示全部楼层
还要看看你ioctl函数是怎么写的
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-6-30 20:42:25 | 显示全部楼层
过了好多天才上来看,对不住楼上大佬
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-6-30 20:43:15 | 显示全部楼层
改成每个函数只有一个return 后可以使用了,应该是某处逻辑错误
回复 支持 反对

使用道具 举报

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

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-4-25 06:17 , Processed in 0.028737 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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