TMS320F2812 FatFs f_write 返回 FR_DISK_ERR [英] TMS320F2812 FatFs f_write returns FR_DISK_ERR

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

问题描述

我的 SD 卡有问题.我正在使用版本 R0.10b 的 FatFs 库来访问 SD 卡.

I have problem with an SD card. I'm using the FatFs library ver R0.10b to access the SD card.

我的代码:

    // .... //
    FATFS fatfs;
    FIL plik;
    FRESULT fresult,res1,res2,res3,res4,res5;
    UINT zapisanych_bajtow = 0 , br;
    UINT zapianie_bajtow = 0;
    char * buffor = "123456789abcdef\r\n";
    unsigned short int i;

    void main(void) {

    // ... //

       res1 = f_mount(0,&fatfs); // returns FA_OK
        res2 = f_open( &plik, "f721.txt", FA_OPEN_ALWAYS | FA_WRITE ); // returns FA_OK
        if( res2 == FR_OK )
        {
                res3 = f_write( &plik, ( const void * ) buffor, 17, &zapisanych_bajtow ); // returns FR_DISK_ERR
        }

        res4 = f_close( &plik );// returns FR_DISK_ERR

        for(;;)
        {

        }
}

知道哪里出了问题吗?

推荐答案

我遇到了类似的错误,只有一处不同.我尝试使用 f_write 函数一次写入 4096 字节.它总是返回 FR_DISK_ERR.这是因为我试图在 FatFS(在 ff.h 中定义)的 FIL 结构中写入更多的 IO 缓冲区大小.

I had similar error with just one difference. I tried to write 4096bytes with f_write function at once. And it always returned FR_DISK_ERR. And this was caused because I tried to write more then is size of IO buffer in FIL structure in FatFS (defined in ff.h).

typedef struct {
    FATFS*  fs;             /* Pointer to the related file system object (**do not change order**) */
    WORD    id;             /* Owner file system mount ID (**do not change order**) */
    BYTE    flag;           /* Status flags */
    BYTE    err;            /* Abort flag (error code) */
    DWORD   fptr;           /* File read/write pointer (Zeroed on file open) */
    DWORD   fsize;          /* File size */
    DWORD   sclust;         /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */
    DWORD   clust;          /* Current cluster of fpter (not valid when fprt is 0) */
    DWORD   dsect;          /* Sector number appearing in buf[] (0:invalid) */
    DWORD   dir_sect;       /* Sector number containing the directory entry */
    BYTE*   dir_ptr;        /* Pointer to the directory entry in the win[] */
    DWORD*  cltbl;          /* Pointer to the cluster link map table (Nulled on file open) */
    UINT    lockid;         /* File lock ID origin from 1 (index of file semaphore table Files[]) */
    BYTE    buf[_MAX_SS];   /* File private data read/write window */
} FIL;

最后一个数组 buf[_MAX_SS] 是文件 IO 缓冲区.但是 _MAX_SS 是用户定义的参数(在 ff.h 中定义),因此您可以减少一次写入的字节数或最终更改 _MAX_SS 值.

The last array buf[_MAX_SS] is the file IO buffer. But _MAX_SS is user defined parameter (defined in ff.h) so you can decrease the amount of bytes written at once or eventually change the _MAX_SS value.

我知道这不是您的情况,因为您一次只能写入 17 个字节,但这对其他人可能会有所帮助.

I know this is not your case because you only write 17 bytes at once, but this can be helpful for others.

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

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