cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure 4-bit SDIO with DMA using STM32CubeMX?

ard33
Associate

How to configure 4-bit SDIO with DMA using STM32CubeMX, to write to an SD card?

FW is running on an STM32F103.

I am trying to set up an SDIO interface with DMA for an SD card using STM32CubeMX.

The issue I am having is that I am unable to write to the SD card.

I can read from it just fine, but trying to write to it always fails.

Not quite sure what the issue is but here is some more information:

  • I've found that a Transmit-FIFO-underrun flag is set when attempting to write.
    • Could be related to the clock settings. The MCU is running at 8MHz, and the SDIO line is at 4MHz (divide bypass disabled and divide factor set to 0).
    • Could be due to priority settings for DMA and SDIO. Tried setting the SDIO priority is set to 0, and the DMA channel to high, but that did not help. There is another high-priority DMA channel in the system, used by an ADC.

  • The processor I'm using is the STM32F103, for which CubeMX only gives me one DMA channel as an option, which I've set to be Peripheral to Memory (the other options being Memory to Peripheral and Memory to Memory). Not sure whether that has anything to do with it. Setting it as Memory to Peripheral right before a write seems to fail as well.

Any help would be greatly appreciated.

-Best

2 REPLIES 2
Amel NASRI
ST Employee

Hi @ard33​ ,

I don't have the exact explanation of the problem you are facing but just some recommendation in order to try deeply analyze it:

  • make sure that you are not facing one of the known limitations described on the product errata sheet
  • is it possible for you to use the 1-bit mode? if yes try it and check if it works
  • if no DMA configured, what is the result?

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi, Amel.

Thank you for the help.

  • I did not have any of the issues in the errata regarding SDIO.
  • I could not get it to work in one-bit mode either.
  • Yes, I can get it to work without DMA, but I've had to set the SDIO clock divide factor to 3, for 1-bit mode, and to 18 for 4-bit mode.

Thanks, again.