cancel
Showing results for 
Search instead for 
Did you mean: 

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

DLim.16
Associate II

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.

18 REPLIES 18
dbgarasiya
Senior II

I am attaching my sd card project with you ,

dbgarasiya
Senior II

sorry to forgot,

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

ALL the best

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 II

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

confused why that is not working

dbgarasiya
Senior II

advice to make it sort ,

Mhoyl.1
Associate

I have the same problem does anyone have a working example?

Hi Dbgarasiya,

What do you mean by make it sort?

Thanks.

Fasdf.4
Associate

Looks like I can most effective pick to both use SDIO or SDIO RX & TX but no longer all 3 of them, in any other case I get an error say "No to be had DMA requests for this peripheral".

TJack.2
Associate III

I've been struggling with similar problems with the STM32F407 and FATFS on SD card.

Firstly, to answer some of the points that have come up here and elsewhere.

  • No, you don't have to use DMA or interrupt, it is perfectly OK to use the SD card in polled mode as long as you are prepared for your program to wait while the SD transfer completes. DMA and/or interrupt are there to allow the SD transfers to happen in the background while the program proceeds with something else, e.g. real-time work.
  • The code CubeID generates for initialising the SD interface looks strange. the procedure MX_SDIO_SD_Init creates a structure to initialise the SDIO clock register, but doesn't actually do it. This is correct, as the SD card setup procedure first starts the interface with a default set of parameters to initialise the card, before switching to the IDE specified mode in SD_InitCard, after a labyrinthine series of procedure calls.
  • Some have talked about playing with the clock settings, but if it fails to identify the card (in SD_PowerON), that won't do anything because the initial setup is done in low-speed mode anyway.
  • By default the IDE doesn't turn on the pull-up resistors on the data, command and clock circuits. These are essential, unless your board has external pull-ups ( the 407 Discovery does).
  • If you remove and replace the card 'hot' the supplied code can't cope. Obviously, FATFS being a foreground program, it can't monitor the SD-NCD (insertion switch) signal, so you have to do that yourself. Then you need to un-mount the no longer inserted card (f_mount(0,...) and to rerun MX_FATFS_Init to make it forget that the card was initialised. And some more that I haven't worked out yet.
  • If you reset the processor you lose access to the card until it has been removed and replaced, or the power cycled. No problem in service, but a pain when debugging.
  • I find that if the card has been idle for a while, the next command often gets a checksum error. I presume this is due to occasional random noise bits getting into the command shift register. Modifying the read/write blocks procedures (override e.g. BSP_SD_ReadBlocks) to retry just once seems to solve this.

Despite all this I still get a lot of random write errors. Writing a file of a few kB sometimes completes but usually gets a write error partway through, at random locations. I'm using an existing 407 board (and SD HC card) that work fine with software written under the old Standard Peripheral library, these problems (except the last one) only happen with Cube. Albeit the older software wasn't very demanding on the SD card, but it happily read and wrote small files without problem and has been released to customers for some years. No way the Cube-generated software gets anywhere near a customer yet. Incidentally, I'm using the FATFS API for I/O (f_read, f_write), haven't got around to connecting up stream I/O yet.