ZYNQ系统中实现FAT32文件系统的SD卡读写之三 SDK编程调试


导入到SDK后直接模板生成一个HELLO WORLD项目,之后在XILINX TOOLS-》BOARD SUPPORT PACKAGE SETTING里面设置选择XILFFS。

ZYNQ系统中实现FAT32文件系统的SD卡读写之三 SDK编程调试_第1张图片





XILFFS各项可以设置参数按照默认,如下图:



ZYNQ系统中实现FAT32文件系统的SD卡读写之三 SDK编程调试_第2张图片


之后修改main函数所在文件,直接拷贝一下内容覆盖原文件 : 

#include "platform.h"
#include "xparameters.h"
#include "xil_printf.h"
#include "ff.h"
#include "xdevcfg.h"


static FATFS fatfs;


int SD_Init()
{
FRESULT rc;
rc = f_mount(&fatfs,"",0);
if(rc)
{
xil_printf("ERROR : f_mount returned %d\r\n",rc);
return XST_FAILURE;
}
return XST_SUCCESS;
}


int SD_Transfer_read(char *FileName,u32 DestinationAddress,u32 ByteLength)
{
FIL fil;
FRESULT rc;
UINT br;


rc = f_open(&fil,FileName,FA_READ);
if(rc)
{
xil_printf("ERROR : f_open returned %d\r\n",rc);
return XST_FAILURE;
}
rc = f_lseek(&fil, 0);
if(rc)
{
xil_printf("ERROR : f_lseek returned %d\r\n",rc);
return XST_FAILURE;
}
rc = f_read(&fil, (void*)DestinationAddress,ByteLength,&br);
if(rc)
{
xil_printf("ERROR : f_read returned %d\r\n",rc);
return XST_FAILURE;
}
rc = f_close(&fil);
if(rc)
{
xil_printf(" ERROR : f_close returned %d\r\n", rc);
return XST_FAILURE;
}
return XST_SUCCESS;
}


int SD_Transfer_write(char *FileName,u32 SourceAddress,u32 ByteLength)
{
FIL fil;
FRESULT rc;
UINT bw;

rc = f_open(&fil,FileName,FA_CREATE_ALWAYS | FA_WRITE);
if(rc)
{
xil_printf("ERROR : f_open returned %d\r\n",rc);
return XST_FAILURE;
}
rc = f_lseek(&fil, 0);
if(rc)
{
xil_printf("ERROR : f_lseek returned %d\r\n",rc);
return XST_FAILURE;
}
rc = f_write(&fil,(void*) SourceAddress,ByteLength,&bw);
printf("SD_Transfer_write -> f_write result len is %d \n\r" ,bw );
if(rc)
{
xil_printf("ERROR : f_write returned %d\r\n", rc);
return XST_FAILURE;
}
rc = f_close(&fil);
if(rc){
xil_printf("ERROR : f_close returned %d\r\n",rc);
return XST_FAILURE;
}
return XST_SUCCESS;
}


#define FILE "test123.txt"


#define MAX_LEN 1024*1024*200

static  char src_str[MAX_LEN] = { 0 } ;
static  char dst_str[MAX_LEN] = { 0 } ;

int main()
{
	int i,r;
init_platform();

u32 len = strlen(src_str);


r  = SD_Init();
if ( XST_SUCCESS != r ){

	printf("fail to open SD1\n\r");
	return 1 ;
}

for(i=0;i dst %d  \n\r",i,src_str[i],dst_str[i]);

}

print("SD write and read over!\r\n");

cleanup_platform();
return 0;
}





之后链接JTAG直接下载到板子上在线运行,注意可以不少些PL部分,因为这里仅仅是PS程序。



下一篇我重点分析一下这个代码,介绍一下注意事项。




你可能感兴趣的:(FPGA,ZEDBOARD,ZYNQ7)