2019-06-27 05:03 AM
Hello.
Short Story:
I'm doing a little project that has to write some sensor data to an SD-Card.
After setting up with CubeMX, I found this (well-known) example of "kiwih" (https://github.com/kiwih/cubemx-mmc-sd-card?fbclid=IwAR1JE_SkRHDFSikRvwptlszMZUA-ZmuBhtI3UJPCThuC68mt_NsgG7M5qTE).
Everything is working perfect and I can do f_mount, f_open, etc ...
So far so good.
Problem:
To facilitate the connection of the SD-Card I used a uSD extension so I can not use the "card dettect" pin.
Sometimes the system boots and no card is present. So when I do f_mount I check if the answer is "FR_OK".
After that I wait to introduce the uSD and try "f_mount" again.
The problem is that as long as I do not reset the MCU, the response from f_mount (already with the card inserted) is always "FR_DISK_ERR".
I have already tried restart the SPI, the FATFS, clean the FATFS object, etc ...
But all my attempts were unsuccessful.
In this case, having to reset the MCU is not a solution for me.
Does anyone have any ideas that can help me?
Thank you!
Solved! Go to Solution.
2019-06-27 01:17 PM
Hello.
In my case, this pin has a pull-up (I put pull-up resistors on all pins of the SD card). I did not want to remove it from the PCBs.
It would also have the drawback that after saving and removing the card it would never recover.
After analyse the problem, I discovered the following solution.
Edit the fatfs.c file with the following
And, of course, declare the function in fatfs.h
My code to mount the SD card looks something like this:
Problem solved.
I hope this can help someone.
Thank you!
2019-06-27 09:05 AM
You should be able to read the pin state via GPIOC->IDR to see if a card is present, seem to recall at least one of the pins of the card should be "CD" in the SPI sense.
If I were debugging this I'd probably dig down and understand specifically which commands or functionality to the card were actually failing. At the top level FATFS the failure is far too non-specific.
The SDIO layers should have a DeInit, static structures Cube/HAL use are not cleaned post startup.
The cards themselves should have an 80 clock cycle trick to pull them out of odd states.
2019-06-27 09:51 AM
Hello Clive.
Thanks for the answer.
I do not have access to the card detect pin. The extension is always placed in the socket.
I'll analyze it better and I'll put here the place where I get the error.
2019-06-27 10:14 AM
>>I do not have access to the card detect pin. The extension is always placed in the socket.
You'll need to reparse what I said. The CARD has a pin typically usable for this purpose, not just the SOCKET one you're focusing on.
CD/CMD3
2019-06-27 01:17 PM
Hello.
In my case, this pin has a pull-up (I put pull-up resistors on all pins of the SD card). I did not want to remove it from the PCBs.
It would also have the drawback that after saving and removing the card it would never recover.
After analyse the problem, I discovered the following solution.
Edit the fatfs.c file with the following
And, of course, declare the function in fatfs.h
My code to mount the SD card looks something like this:
Problem solved.
I hope this can help someone.
Thank you!
2023-08-23 03:57 AM
Clive do you have sample source code to share on how to do the 80 clock cycle trick