cancel
Showing results for 
Search instead for 
Did you mean: 

FATFS f_mount problem

Joseph5241
Associate II

Hi,

I am trying to program on keil based on sdio with STM32H753ZI MCU.

I am able to successfully initialize the sdcard FATFS_LinkDriver(&SD_Driver, SDPath),

and I use HAL_SD_Erase() to erase ,itˊs successful ,

but when i use f_mount() function it stuck in the disk_read() and doesnˊt return.

Here are the steps of these function:

f_mount()->find_volume()->chech_fs()->move_window()->disk_read().

here are my sd init parameters

Joseph5241_1-1716369138524.png

Joseph5241_2-1716369634059.png

What should I do to solve this problem,

Thanks!

 

6 REPLIES 6
AScha.3
Chief

Hi,

>HAL_SD_Erase() to erase ,itˊs successful   (How you know this ?)

+

> but when i use f_mount() function it stuck in the disk_read() 

 

So you at first try to destroy the filesystem on sdcard , and then -big surprise- you cannot mount ? 🙂

1. use a working card with fatfs (check in your PC first )

2. never write or format card, until mount and read is working fine .

3. try mount - until success, then go on...

fresult = f_mount(&SDfs, (TCHAR const*)SDPath, 1);			// SD card mount NOW

 

If you feel a post has answered your question, please click "Accept as Solution".
urbito
Senior

As  @AScha.3 stated, you should not "erase" the SDCard. If you do that, then you have to call f_mkfs.

 

You only "erase" the full media one time, says at the first time you use it, but not when using an SDCard. You usually format a Flash Memory, like a NAND or NOR Flash... Then you do f_mkfs to format the drive/memory and then you call f_mount to actually use the drive/flash.

 

If you erase the SDCard, basically when you put it back on windows, you may get a "corrupted" msg from windows in order to format the SDCard.

Thanks,Ascha.3

Sorry,my description is not detailed enough.

I use SDFormatter.exe to format SD card on PC,after I use HAL_SD_Erase() to erase,

so when I use f_mount(),SD card is still fine.

Then I  want to use f_mount() to mount the sd card, 

the problem I mentioned occurred.(stuck in the disk_read() and doesnˊt return)

Thanks,urbito

Sorry,my description is not detailed enough.

I use SDFormatter.exe to format SD card on PC,after I use HAL_SD_Erase() to erase,

so when I use f_mount(),SD card is still fine.

Then I  want to use f_mount() to mount the sd card, 

the problem I mentioned occurred.(stuck in the disk_read() and doesnˊt return)

I still do not understand why you use the Erase function at the begining, after formating the SD card, why dont you just use the f_mount without the "erase" and then use the disk_read

SHs
ST Employee

Hello @Joseph5241 ,

Using HAL_SD_Erase() refers to wiping data from the card, which can include removing the file system structure. Formatting on the other hand, usually involves creating a new file system on the card. It gets prepared to store data in a way that the operating system can manage. f_mount() mounts the file system and makes it available for operations such as reading and writing files. If you have erased the SD card and not created a new file system, f_mount() will not be able to mount the card, as there is no file system to mount. Typically, you do not need to erase an SD card before use. SD cards usually come pre-formatted with a file system, and you can directly mount and use them with f_mount(). If you need to clear the data, you would format the card, not erase it.

Please mark my answer as best by clicking on the “Accept as solution" button if it fully answered your question. This will help other users find this solution faster.

Thanks for your contribution.