UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Visitor dannna
Visitor
5,667 Views
Registered: ‎03-04-2015

Writing to SD card using ff.h

Hi,

 

I wrote a simple code that writes data to bin file.

printf returns: NumBytesWritten=800;

 

 

When I open the file in binary viewer the actual size is 768 (which is 3*256) instead of 800 bytes.

The file is cut and I can't figure why.  

 


#include <stdio.h>
#include "xsdps.h" /* SD device driver */
#include "ff.h"
#include "platform.h"
#include "xbasic_types.h"
/************************** Constant Definitions *****************************/
/************************** Variable Definitions *****************************/

volatile u32 FileSize= 800;
static FIL fil; /* File object */
static FATFS fatfs;
static char FileName[32] = "sd_Test.bin";
u32 Platform;
TCHAR *Path = "0:/";
u8 buffer[800]

/*****************************************************************************/
/******************************************************************************/
int main()
{
u32 BuffCnt;
FRESULT Res;
UINT NumBytesWritten;

init_platform();

Res = f_mount(&fatfs, Path, 0);

Res = f_open(&fil, FileName, FA_CREATE_ALWAYS | FA_WRITE);//FA_CREATE_ALWAYS

Res = f_lseek(&fil, 0); // Pointer to beginning of file

for(BuffCnt = 0; BuffCnt < FileSize; BuffCnt++){
buffer[BuffCnt] =5;
}

Res = f_write(&fil, (const void*)buffer, FileSize,&NumBytesWritten);
xil_printf("NumBytesWritten=%d\r\n", NumBytesWritten);

Res = f_close(&fil);

return 0;
}

 

 

Thanks,

 

 

 

0 Kudos
1 Reply
2,071 Views
Registered: ‎05-24-2016

Re: Writing to SD card using ff.h

Did you ever figure this out? I am having the exact same issue on a 7z100 Avnet MMP board

 

Craig

0 Kudos