OpenEdv-开源电子网

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

关于FatFS移植到SDRAM的疑问

[复制链接]

76

主题

88

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
264
金钱
264
注册时间
2017-10-26
在线时间
12 小时
发表于 2017-11-17 14:57:04 | 显示全部楼层 |阅读模式
1金钱
我手上有几个项目因为要使用到在SDRAM中建立FatFS,首先在SPI FLASH中的文件拷贝到SDRAM中的FatFS,因为数据操作特别频繁,因此设定在一定时间段后将SDRAM中的文件拷贝到SPI Flash。

测试环境:STM32F429IGT6+W9825G6KH的SDRAM
软件环境:STM32CubeMX 1.8

单独测试429驱动SDRAM都是一切正常的,在加载FatFS文件系统以后,执行以下操作就出现代码标注红色地方:
打开文件就一直提示的是没有文件系统,而我在初始化FatFS之后,去观察我SDRAM首地址0xC0000000之后的512个字节,所有数据全部为0,目前不知道问题出在哪里,恳请大家帮忙分析分析?

printf("\r\n ****** FatFs Example ******\r\n\r\n");
    /*##-1- Register the file system object to the FatFs module ##############*/
                retSD = f_mount(&fs, "0:", 0);
    if(retSD)
                {
        printf(" f_mount error : %d \r\n",retSD);        
                        Error_Handler() ;
    }
    else
                {
        printf(" mount sucess!!! \r\n");
                }
                retSD = f_fdisk(0,plist,work) ;
                if( retSD )
                {
                        printf(" f_fdisk error : %d \r\n",retSD);        
                        Error_Handler() ;
                }
                else
                {
                        printf(" f_fdisk sucess!!! \r\n");
                }
                retSD = f_mkfs("0:",FM_ANY,2048,work,sizeof work) ;
                if(retSD)
                {
        printf(" mkfs error : %d \r\n",retSD);        
                        Error_Handler() ;
    }
    else
                {
        printf(" mkfs sucess!!! \r\n");
                }  
                retSD = f_mount(NULL, "0:", 1);
               
                retSD = f_mount(&fs, "0:", 1);
               
    /*##-2- Create and Open new text file objects with write access ######*/
    retSD = f_open(&fil, filename, FA_CREATE_NEW | FA_WRITE | FA_READ );  //在这里就提示没有文件系统,而我调试观测SDRAM的首地址,发现在首地址这里之后的512字节的数据全是0x00.
    if(retSD)
                {
        printf(" open file error : %d\r\n",retSD);
                }
    else
                {
        printf(" open file sucess!!! \r\n");
                }

    /*##-3- Write data to the text files ###############################*/

    retSD = f_write(&fil, wtext, sizeof(wtext), (void *)&byteswritten);

    if(retSD)
                {
        printf(" write file error : %d\r\n",retSD);
                }
    else
    {
        printf(" write file sucess!!! \r\n");
        printf(" write Data : %s\r\n",wtext);
    }

    /*##-4- Close the open text files ################################*/
    retSD = f_close(&fil);
    if(retSD)
                {
        printf(" close error : %d\r\n",retSD);
                }
    else
                {
        printf(" close sucess!!! \r\n");
                }
    /*##-5- Open the text files object with read access ##############*/
    retSD = f_open(&fil, filename, FA_READ);
    if(retSD)
                {
        printf(" open file error : %d\r\n",retSD);
                }
    else
                {
        printf(" open file sucess!!! \r\n");
                }
    /*##-6- Read data from the text files ##########################*/
    retSD = f_read(&fil, rtext, sizeof(rtext), (UINT*)&bytesread);
    if(retSD)
                {
        printf(" read error!!! %d\r\n",retSD);
                }
    else
    {
        printf(" read sucess!!! \r\n");
        printf(" read Data : %s\r\n",rtext);
    }
    /*##-7- Close the open text files ############################*/
    retSD = f_close(&fil);
    if(retSD)
                {
        printf(" close error!!! %d\r\n",retSD);
                }
    else
                {
        printf(" close sucess!!! \r\n");
                }
    /*##-8- Compare read data with the expected data ############*/
    if(bytesread == byteswritten)
    {
        printf(" FatFs is working well!!!\r\n");
    }
                retSD=f_mount(0, "0", 0);  

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

使用道具 举报

68

主题

165

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
388
金钱
388
注册时间
2017-3-2
在线时间
156 小时
发表于 2017-11-17 15:45:14 | 显示全部楼层
把你驱动移植的部分贴出来,移植部分对接的没问题吗?
回复

使用道具 举报

76

主题

88

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
264
金钱
264
注册时间
2017-10-26
在线时间
12 小时
 楼主| 发表于 2017-11-17 17:08:25 | 显示全部楼层
驱动移植部分采用的是STM32CubeMX自动生成的!
回复

使用道具 举报

68

主题

165

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
388
金钱
388
注册时间
2017-3-2
在线时间
156 小时
发表于 2017-11-18 08:29:05 | 显示全部楼层
我觉得是你 驱动移植部分和SDRAM读写对接有问题,你可以看看移植的那几个函数怎么实现的,就是下面这个 5个函数:

DSTATUS disk_initialize (BYTE pdrv);
DSTATUS disk_status (BYTE pdrv);
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
回复

使用道具 举报

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

本版积分规则



关闭

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

正点原子公众号

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

GMT+8, 2025-5-19 04:02

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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