Seek to particular position in Sd card
응답
19. 7. 23 오후 4:08

hello,

 can anyone help on how to seek to particular location in Sd card.

I am using ff.h APIs. In my case i want to read lets say only last 5 chars stored in a particular file.

I tried to implement it with below code but its throwing an error.

#include "ff.h"

........

        f_open(&fileObject, filename, FA_OPEN_EXISTING | FA_READ);
        f_lseek(&fileObject, f_size(&fileObject) - 4);
        //printf("%d",f_size(&fileObject));                              // just to see what its getting
        fileSystemResult = f_read(&fileObject, ramBufferRead,  3,
                &bytesRead);

.......

 

Also is there any better way to handle Sd card ?

Thank you

0 (0 투표)
RE: Seek to particular position in Sd card
응답
19. 7. 24 오전 7:44 as a reply to Hiren Patel.

Hello Hiren,

Please use the below code to read last 5 characters with fatfs library.

FIL f;
FIL * fp = &f;
uint8_t ramBufferRead[BUFFER_SIZE];
uint32_t bytesRead;
uint32_t Offset = 0;
FILINFO fileInfo;

fres = f_open(fp, filename, FA_OPEN_EXISTING | FA_READ);
if (fres == FR_OK)
{
	fres = f_stat(filename, &fileInfo);
}
if (fres == FR_OK)
{
        Offset = fileInfo.fsize - 5;
	fres = f_lseek(fp, Offset);
}
if (fres == FR_OK)
{
	fres = f_read(fp, ramBufferRead,  BUFFER_SIZE,&bytesRead);
}

 

 

0 (0 투표)