Skip to main content
Visitor II
April 5, 2024
Question

f_lseek returning FR_INT_ERROR in stm FATFS

  • April 5, 2024
  • 2 replies
  • 6269 views

Hello,

I am trying to interface the sdcard FAT32 based on SPI with STM32F429ZI MCU. I am using the FATFS library (R0.12c) provided in the stmcube ide.

I am able to successfully initialize the sdcard using f_mount() function.

I want to implement the below mentioned code. f_open is sending the FR_OK response that means file is opened successfully but f_lseek command is not responding correctly.

fres = f_open(&fil,"HEADER.TXT", FA_READ | FA_OPEN_EXISTING);
if(fres == FR_OK)
{
fres = f_lseek(&fil,2);
fres = f_read(&fil,&temp,3, &ptr);
fres = f_close(&fil);
}

It is also came to my notice that when I send the command fres = f_lseek(&fil,0); then it responds FR_OK. Any non zero value in f_lseek function responds to the FR_INIT_ERROR.

 

During Debugging:  in my case ofs =2

bcs = (DWORD)fs->csize * SS(fs); /* Cluster size (byte) */ --> this line results in bcs= 0 since the fs_csize is 0

ofs -= bcs; fp->fptr += bcs; --> Due to bcs=0 this line does not have any effect

clst = get_fat(&fp->obj, clst); --> this function return 0, here clst is passed as 24

if (clst <= 1 || clst >= fs->n_fatent) ABORT(fs, FR_INT_ERR); --> since clst = 0 it result in FR_INIT_ERROR

 

I am not able the infer the error from this debugging process. Please help me to find the issue and solution to resolve the issue.

I am attaching the I/O level implementation files and middleware is same as provided by stmcube ide while building the code using .ioc file.

    This topic has been closed for replies.

    2 replies

    Graduate II
    April 5, 2024

    So an Internal Error.

    I'd suggest migrating to a more current version of the FatFs implementation. 

    You should check the file size before seeking. 

    shefuAuthor
    Visitor II
    April 8, 2024

    I am using the code generation from the CUBEMX and in the FATFS implementation library involved is by default version (R0.12c). Can you suggest me how can I use the Newest version of the FATFS library in my project?

     

    Graduate II
    April 8, 2024

    You'll need to do it manually.

    Visitor II
    October 10, 2024

    Hi!
    I have the same problem and I just migrated to the latest v0.15 as well.
    Did you find out what the problem was?

    Many thanks! 

    shefuAuthor
    Visitor II
    October 10, 2024

    Hello,

    I do not remember the exact solution but it is working now. From one my comments I have found that It was issue during the Mounting of the sdcard (f_mount function).

    The card was detected as FAT12 instead of FAT32 file system due to which the problem was coming.

    You should check and debug your f_mount function, it should be implemented correctly.