Skip to main content
DLim.16
Associate III
January 16, 2020
Question

Need help configuring SDIO to read SD card on STM32F405 using STM32CubeIDE.

  • January 16, 2020
  • 13 replies
  • 6577 views

Hi,

I am trying to use the STM32F405 microcontroller to log data into an SD card using STM32CubeIDE. Specifically, this MCU from adafruit: https://www.adafruit.com/product/4382?gclid=EAIaIQobChMI3qONnpCJ5wIVD_DACh2XCQY7EAAYASAAEgL4QvD_BwE

I found a few resources online and integrated that into the my source code, which can be found in "main.zip". My SDIO and FATFS configurations are shown in the attached figures. I did not change anything under 'Set Defines'.

Regardless of whether I have an SD card in the MCU or not, the results are the same: the program doesn't go beyond the line of code that calls "f_mkfs". I would appreciate it if someone could help me troubleshoot this.

Thanks.

This topic has been closed for replies.

13 replies

Tesla DeLorean
Guru
January 16, 2020

Formatted cards should not need MKFS, one should avoid using it at all until DISKIO layer read function is fully tested/validated.

Unfortunately I lack the will to trawl through broken code, especially from Cube.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
DLim.16
DLim.16Author
Associate III
January 17, 2020

Hi clive1,

Thank you for your answer!

I removed "f_mkfs" and my program gets stuck in the next line of code, which is 'f_open'. It fails to open/create a file.

Also, what did you mean by "until DISKIO layer read function is fully tested/validated"? How can I test/validate that function?

Thanks.

dbgarasiya
Senior
January 18, 2020

you are missing sd card initializartion and configuring of bus width functin missing in you project

and according to @Community member​  , you do not need to use f_mkfs

DLim.16
DLim.16Author
Associate III
January 20, 2020

Hi Dbgarasiya,

I thought the IDE already initialized the module after configuring it using the GUI in Device Configuration Tool. It even created a function call: 'MX_SDIO_SD_Init'.

Do you think maybe the module wasn't initialized properly? If so, what are the right function calls I should be using?

Thanks.

dbgarasiya
Senior
January 21, 2020

BSP_SD_Init()

dbgarasiya
Senior
January 21, 2020

bsp_driver_sd.c in this file

DLim.16
DLim.16Author
Associate III
January 21, 2020

Hi Dbgarasiya,

I added that, but I am still getting the same result. Am I missing something else?

Thanks.

dbgarasiya
Senior
January 22, 2020

you have not enable DMA, for rx and tx also

then try

DLim.16
DLim.16Author
Associate III
January 22, 2020

Hi Dbgarasiya,

Looks like I can only choose to either use SDIO or SDIO RX & TX but not all three of them, otherwise I get an error say "No available DMA requests for this peripheral".

Was DMA required? I enabled both variations i.e. only SDIO and then only SDIO RX & TX, nothing worked. Let me know if I'm doing something wrong.

Thanks.

dbgarasiya
Senior
January 23, 2020

I am attaching my sd card project with you ,

dbgarasiya
Senior
January 23, 2020

sorry to forgot,

I have done it for STM32F779BI contoller ,you could poet it for your controller

ALL the best

DLim.16
DLim.16Author
Associate III
January 24, 2020

Hi Dbgarasiya,

Thanks a lot for your help so far! I have also found another useful resource for this particular MCU:

https://www.digikey.com/en/maker/projects/making-a-temperature-logger-with-the-adafruit-feather-stm32f405-express/11ea860d54074a19bb75cb6425e6d0b0

I think with all the resources, we are getting close to a solution. Currently, the error I'm seeing is :'FR_NO_FILESYSTEM' whenever 'f_open' is called.

I've reformatted my sdcard multiple times to all kinds of allocation unit settings, that didn't help. Although, when I used 'f_mks', it seemed like it worked, but there was no way of confirming it because when I tried to read the sd card on my PC, the sd card was corrupted and had to be reformatted everytime.

I don't think my sd card is bad because I can actually log data to the it, following the ArduinoIDE instructions by adafruit. So, this implies that something is still wrong/missing with my configurations in STM32CubeIDE.

I have attached my latest version of project. I'd appreciate it if anyone could help troubleshoot.

Thanks.

dbgarasiya
Senior
January 27, 2020

just make sort as possible , i am not geting any of issue your code

confused why that is not working

dbgarasiya
Senior
January 27, 2020

advice to make it sort ,

DLim.16
DLim.16Author
Associate III
January 27, 2020

Hi Dbgarasiya,

What do you mean by make it sort?

Thanks.