cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with fmount / SD Card / SPI (Any help would be appreciated)

JayDev
Senior II

I've been looking through forums, posts, youtube videos, etc and I'm still having trouble getting my card to mount correctly.

The code I'm having trouble with is this:

	FRESULT fresult;  // result
	FATFS fs;  // file system
 
	HAL_Delay (500);
 
	fresult = f_mount(&fs, "/", 1);
	if(fresult != FR_OK)
	{
		debugPrintln(&huart1, "ERROR!!! in mounting SD CARD...\n\n");
	}
	else
	{
		debugPrintln(&huart1, "SD CARD mounted successfully...\n\n");
	}

I've seen some people use "1" in the fmount command (mount immediately) and some use a 0 (delayed mount). The problem I'm having is when I use a 1, I get the error "FR_DISK_ERR". When I use a 0, I get FR_OK.

So, naturally, I would think, "no problem, I'll just use 1 since that seems to work". However, when I have the SD card removed, it ALSO works using 1, which doesn't make sense to me.

So, I have a few potential problems:

1) I have a hardware problem and it's not seeing the SD card

2) I have a SW setup issue with the drivers

The problem is I don't fully understand what this is doing, to be honest. I'm not sure if it's testing software settings or if it's actually trying to communicate to hardware. I'm expecting it to do so over SPI pins but maybe I don't have it linked to the SPI bus? I have a scope probe on the clock line and I'm not seeing any signals, so that seems like a big red flag that it's not doing what it's supposed to (that said, I don't see in the code where it would actually try to communicate to the SD card via SPI).

Can anyone explain to me what I might be seeing, what I should expect, where I can look, etc? I'm racking my brain, scouring the internet trying to understand the problem and I just don't. I've been at it for much longer than I care to admit and I should've stopped for lunch about 2-3 hours ago . . . heh.

Anyway, thought I'd throw this out there in case someone else can shed some light on this. Thanks!

4 REPLIES 4

Review/instrument the functions in the DISKIO.C layer, it sits on top of the code you should have interfacing with the SPI and SD Card support.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Prove that you can initialize the card interface, and read sectors (blocks) from the block storage device. If it can't read data consistently/correctly any file system built on top will fail.

Generally FR_DISK_ERR comes from a fail of the read or write to the media, best to prove the thing works properly in READ ONLY mode before trashing the media with broken writes. Things like FR_NOT_READY would typically occur if the media sense / switch on socket flags the card is not present.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Well, it sounds consistent with me not having something setup correctly with the SPI so it's getting no communication. If that's the case, it makes sense it would have the same response whether the SD card is in or out, it's not seeing anything.

I'll see if I can dig deeper on what it's SUPPOSED to do during an f_mount and see where it's going wrong. I definitely expected to see some clock signals going to the SD card. Maybe there's some linkage that's missing in my project file. Not sure where to look but it's time to start digging deeper.

Thanks for the advice!

hMasg.1
Associate

i had almost the same prblm; in fact i m trying to read and write data on SD card through an adpter using FREERTOS ,spi and fatfs .I m using stm32F767ZIT6

the debugger return FR_OK for f_mount when it s put with 0 option and not working for 1 option

the prblms is that even when i try to take the SD card from the adpter it returns the same thing for f_mount (FR_OK) and for the functions after it ;they are not working for exemple: f_open always return FR_NOT_READY

so i dont know if it s hardware prblm or something with the drivers !!

i m even doubting a clock prblm but i couldn 't fix it and really don t know why ( i m just adding that there's no prblm with the adapter because i tried it with an arduino program and it s working to say that i found the file opened and written )

so i m stuck trying to find the prblm :(