OpenEdv-开源电子网

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

FATFS文件系统问题,无法进行创建文件,写入数据

[复制链接]

15

主题

53

帖子

0

精华

新手入门

积分
8
金钱
8
注册时间
2018-8-16
在线时间
26 小时
发表于 2019-4-27 20:11:13 | 显示全部楼层 |阅读模式
27金钱
本帖最后由 Solace1123 于 2019-4-27 20:10 编辑

用的是micro SD卡,不知道是挂载不上还是怎么样,程序跑到创建文本文件的那一句就卡死了,求助!!!换了两张卡还是不行SD卡用的是别人的SDIO库
这是diskio.c,

[mw_shl_code=c,true]/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2007        */
/*-----------------------------------------------------------------------*/
/* This is a stub disk I/O module that acts as front end of the existing */
/* disk I/O modules and attach it to FatFs module with common interface. */
/*-----------------------------------------------------------------------*/

#include "diskio.h"
#include "stm32f10x.h"
#include "sdio_sdcard.h"

#define BLOCK_SIZE            512 /* Block Size in Bytes */



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

DSTATUS disk_initialize (
        BYTE drv                                /* Physical drive nmuber (0..) */
)
{
        SD_Error  Status;
        /* Supports only single drive */
        if (drv)
        {
                return STA_NOINIT;
        }
/*-------------------------- SD Init ----------------------------- */
  Status = SD_Init();
        if (Status!=SD_OK )
        {
                return STA_NOINIT;
        }
        else
        {
                return RES_OK;
        }

}



/*-----------------------------------------------------------------------*/
/* Return Disk Status                                                    */

DSTATUS disk_status (
        BYTE drv                /* Physical drive nmuber (0..) */
)
{
        return RES_OK;
}



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

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) */
)
{

        if (count > 1)
        {
                SD_ReadMultiBlocks(buff, sector*BLOCK_SIZE, BLOCK_SIZE, count);
        
                          /* Check if the Transfer is finished */
             SD_WaitReadOperation();  //Ñ-»·2éÑˉdma′«êäêÇ·ñ½áêø
        
            /* Wait until end of DMA transfer */
            while(SD_GetStatus() != SD_TRANSFER_OK);

        }
        else
        {
               
                SD_ReadBlock(buff, sector*BLOCK_SIZE, BLOCK_SIZE);

                          /* Check if the Transfer is finished */
             SD_WaitReadOperation();  //Ñ-»·2éÑˉdma′«êäêÇ·ñ½áêø
        
            /* Wait until end of DMA transfer */
            while(SD_GetStatus() != SD_TRANSFER_OK);

        }
        return RES_OK;
}



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

#if _READONLY == 0
DRESULT disk_write (
        BYTE drv,                        /* Physical drive nmuber (0..) */
        const BYTE *buff,        /* Data to be written */
        DWORD sector,                /* Sector address (LBA) */
        BYTE count                        /* Number of sectors to write (1..255) */
)
{

        if (count > 1)
        {
                SD_WriteMultiBlocks((uint8_t *)buff, sector*BLOCK_SIZE, BLOCK_SIZE, count);
               
                  /* Check if the Transfer is finished */
                   SD_WaitWriteOperation();           //μè′ydma′«êä½áêø
            while(SD_GetStatus() != SD_TRANSFER_OK); //μè′ysdioμ½sd¿¨′«êä½áêø
        }
        else
        {
                SD_WriteBlock((uint8_t *)buff,sector*BLOCK_SIZE, BLOCK_SIZE);
               
                  /* Check if the Transfer is finished */
                           SD_WaitWriteOperation();           //μè′ydma′«êä½áêø
            while(SD_GetStatus() != SD_TRANSFER_OK); //μè′ysdioμ½sd¿¨′«êä½áêø
        }
        return RES_OK;
}
#endif /* _READONLY */




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

DRESULT disk_ioctl (
        BYTE drv,                /* Physical drive nmuber (0..) */
        BYTE ctrl,                /* Control code */
        void *buff                /* Buffer to send/receive control data */
)
{
        return RES_OK;
}
                                                         
/*-----------------------------------------------------------------------*/
/* Get current time                                                      */
/*-----------------------------------------------------------------------*/
DWORD get_fattime(void)
{

         return 0;

}
[/mw_shl_code]




正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

15

主题

53

帖子

0

精华

新手入门

积分
8
金钱
8
注册时间
2018-8-16
在线时间
26 小时
 楼主| 发表于 2019-4-27 20:21:10 | 显示全部楼层
仿真点运行的话,就会跑飞到下面这个地方 直接跑卡死在这.png
回复

使用道具 举报

31

主题

2183

帖子

0

精华

资深版主

Rank: 8Rank: 8

积分
14433
金钱
14433
注册时间
2018-8-3
在线时间
1157 小时
发表于 2019-4-27 20:36:42 | 显示全部楼层
挂在SD卡时返回什么 看返回的错误指令找问题
回复

使用道具 举报

15

主题

53

帖子

0

精华

新手入门

积分
8
金钱
8
注册时间
2018-8-16
在线时间
26 小时
 楼主| 发表于 2019-4-27 20:46:10 | 显示全部楼层
本帖最后由 Solace1123 于 2019-4-27 20:47 编辑
翼行园子 发表于 2019-4-27 20:36
挂在SD卡时返回什么 看返回的错误指令找问题

res=f_mount(0,&fs);
res返回值是0;后面写了个:
res=f_open (&fil,"0:/mese.txt", FA_OPEN_ALWAYS);       
无法获得返回值,程序这里直接就卡死了

回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2019-4-28 00:44:17 | 显示全部楼层
Solace1123 发表于 2019-4-27 20:46
res=f_mount(0,&fs);
res返回值是0;后面写了个:
res=f_open (&fil,"0:/mese.txt", FA_OPEN_ALWAYS);         ...

仿真进去,看死在哪里了?
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

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

本版积分规则



关闭

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

正点原子公众号

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

GMT+8, 2025-6-21 05:50

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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