我手上有几个项目因为要使用到在SDRAM中建立FatFS,首先在SPI FLASH中的文件拷贝到SDRAM中的FatFS,因为数据操作特别频繁,因此设定在一定时间段后将SDRAM中的文件拷贝到SPI Flash。
测试环境:STM32F429IGT6+W9825G6KH的SDRAM
软件环境:STM32CubeMX 1.8
单独测试429驱动SDRAM都是一切正常的,在加载FatFS文件系统以后,执行以下操作就出现代码标注红 {MOD}地方:
打开文件就一直提示的是没有文件系统,而我在初始化FatFS之后,去观察我SDRAM首地址0xC0000000之后的512个字节,所有数据全部为0,目前不知道问题出在哪里,恳请大家帮忙分析分析?
printf("
****** FatFs Example ******
");
/*##-1- Register the file system object to the FatFs module ##############*/
retSD = f_mount(&fs, "0:", 0);
if(retSD)
{
printf(" f_mount error : %d
",retSD);
Error_Handler() ;
}
else
{
printf(" mount sucess!!!
");
}
retSD = f_fdisk(0,plist,work) ;
if( retSD )
{
printf(" f_fdisk error : %d
",retSD);
Error_Handler() ;
}
else
{
printf(" f_fdisk sucess!!!
");
}
retSD = f_mkfs("0:",FM_ANY,2048,work,sizeof work) ;
if(retSD)
{
printf(" mkfs error : %d
",retSD);
Error_Handler() ;
}
else
{
printf(" mkfs sucess!!!
");
}
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
",retSD);
}
else
{
printf(" open file sucess!!!
");
}
/*##-3- Write data to the text files ###############################*/
retSD = f_write(&fil, wtext, sizeof(wtext), (void *)&byteswritten);
if(retSD)
{
printf(" write file error : %d
",retSD);
}
else
{
printf(" write file sucess!!!
");
printf(" write Data : %s
",wtext);
}
/*##-4- Close the open text files ################################*/
retSD = f_close(&fil);
if(retSD)
{
printf(" close error : %d
",retSD);
}
else
{
printf(" close sucess!!!
");
}
/*##-5- Open the text files object with read access ##############*/
retSD = f_open(&fil, filename, FA_READ);
if(retSD)
{
printf(" open file error : %d
",retSD);
}
else
{
printf(" open file sucess!!!
");
}
/*##-6- Read data from the text files ##########################*/
retSD = f_read(&fil, rtext, sizeof(rtext), (UINT*)&bytesread);
if(retSD)
{
printf(" read error!!! %d
",retSD);
}
else
{
printf(" read sucess!!!
");
printf(" read Data : %s
",rtext);
}
/*##-7- Close the open text files ############################*/
retSD = f_close(&fil);
if(retSD)
{
printf(" close error!!! %d
",retSD);
}
else
{
printf(" close sucess!!!
");
}
/*##-8- Compare read data with the expected data ############*/
if(bytesread == byteswritten)
{
printf(" FatFs is working well!!!
");
}
retSD=f_mount(0, "0", 0);
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
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);
一周热门 更多>