kiwih / cubeide-sd-card

CubeIDE/CubeMX compatible MMC/SD memory card FatFs driver
Other
103 stars 59 forks source link

f_mount error (3) when not setting internal pullups on SPI pins #2

Closed midasgossye closed 3 years ago

midasgossye commented 3 years ago

First of all, thanks for the well written how-to guide and blog post! Thanks to your explanation and code I managed to read and write to a MicroSD card using a custom STM32F4 dev board 😃 However, it didn't work first-go and I had to spend a couple of hours to figure out what the issue was...

I have the microSD card directly connected to the SPI2 interface pins on a STM32F405RGT6, like so: microSD_card_connections

I altered and uploaded the code and it refused to work, it always gave me a f_mount error (3) error... I hooked up an SD card interface module (like the one you used in your blogpost) to the same SPI pins, and it started working! After some probing I noticed that the SD card interface module has pullup resistors on all of the data lines. After enabling the internal pullups of the SPI interface using the STM32CubeIDE configurator it suddenly started to work! pullups_cubeIDE

This was definitely a goof up on my part, but it would be nice to add a note on your blogpost or code to enable the internal pullups if someone is directly connecting the SD card pins to the STM32. Hopefully, it can save some other people some time so they don't have to go troubleshooting like I did 😅

kiwih commented 3 years ago

This is great to know. I have added a note to the blog and README.

zharfanw commented 3 years ago

I had the same problem too, but it was solved. I was using NUCLEO-64 STM32F446RE, with the same sd card module, and using SD Card Sandisk 16GB.

I did the same thing with blog instruction and I got error (3). And I solved it with all the SPI2 pins(MOSI, MISO, SCK, and CS) are switched to Pull-Down. Actually, I don't know why? but it's work for me.

Thanks for your code and blog post. it's helpful. I leave a comment here to share my experience with the troubles, but the code it's fine for this far.

zharfanw commented 3 years ago

I had the same problem too, but it was solved. I was using NUCLEO-64 STM32F446RE, with the same sd card module, and using SD Card Sandisk 16GB.

I did the same thing with blog instruction and I got error (3). And I solved it with all the SPI2 pins(MOSI, MISO, SCK, and CS) are switched to Pull-Down. Actually, I don't know why? but it's work for me.

Thanks for your code and blog post. it's helpful. I leave a comment here to share my experience with the troubles, but the code it's fine for this far.

Screenshot 2021-04-16 165444 Screenshot 2021-04-16 165606

lakshminarayanaks79 commented 3 years ago

Hi this lakshminarayana KS i am trying to integrate SD card with SPI over STM32f469I discovery board but i always get the same problem that f_mount error (3) i followed to blog and also made changed specified here but nothing has worked for me till now. could be able to help with latest STM32Cube id

Thanks in advance

With Regards Lakshminarayana KS

kiwih commented 3 years ago

Also try changing your SD card @lakshminarayanaks79 , as noted in the blog, not every SD card likes talking SPI.

thibeaux commented 3 years ago

I fixed this problem by following the steps in this tutorial by Kiwih, https://01001000.xyz/2020-08-09-Tutorial-STM32CubeIDE-SD-card/

You have to make sure you edit the user_diskio.c file adding in the appropriate user code that returns the SPI commands that is used in user_disk_spi.h. This returned the size of my drive being printed into my UART terminal.

I'm using a SANDISK ULTRA 32GB Micro SD Card, HW-125 SD card SPI adapter for my Nucleo-F446RE.

Thanks to you guys! Also I'm using pull-ups on all 4 of my SPI1 pins including the CS. Also I am setting my prescaler to 256.

MAXH20 commented 2 years ago

Set FS_TINY Enabled will make the trick