Skip to main content
Visitor II
July 5, 2022
Question

The function f_open() never return when the SD card is empty.

  • July 5, 2022
  • 2 replies
  • 1005 views

Hello,

I have a problem of f_read in the example project FatFS_uSD_Standalone that the function has never been return when trying to read an empty SD cards.

The following Pseudocode can access sd successfully in the example project FatFS_uSD_Standalone:

f_mkfs

f_open(FA_CREATE_ALWAYS | FA_WRITE)

f_write

f_close

f_open(FA_READ)

f_read

f_close

Need to check the SD card first to see if it is empty or not:

f_open(FA_READ)

if(ok)

{

f_read

f_close

}

else

{

f_open(FA_CREATE_ALWAYS | FA_WRITE)

f_write

f_close

}

- f_open(FA_READ) never return if no file exist.

I appreciated that if you provide any suggestion regarding this issue.

Thanks,

    This topic has been closed for replies.

    2 replies

    Graduate II
    July 5, 2022

    Assume you'll need to instrument and debug your implementation.

    Make sure stack and heap are adequate.

    Media Empty or No Media in Socket?

    Media Empty or Doesn't have one specific file you're looking for?

    Is the media formatted?

    What error/status is returned in the NOT(ok) path?

    What board/STM32 are we talking about here.

    Super User
    July 5, 2022

    "the function has never been return when trying to read an empty SD cards."

    How, exactly, do you determine that?

    Have you tried using the debugger to step through the code, and see where it gets stuck?

    0693W000008xsqBQAQ.png

    (including pseudo code)