cancel
Showing results for 
Search instead for 
Did you mean: 

No interrupt in SDcard with DMA on STM32L476 and CubeMX

MarcoM
Associate II

Hi, I have an unsolved issue with SDcard.

The project is based on STM32L476, the IDE is Atollic and configuration is made by STM32CucbeMX (as I do with all my designs).

Without DMA (no DMA template in FATFS and no configured DMA channels) the SDcard works. When I use the DMA (see screenshot), the very first read operation stucks and after the 30s timeout I get an error.

0693W00000D0ny7QAB.png 

I have investigated inside the code and I have the evidence that there is not any interrupt after the HAL_SD_ReadBlocks_DMA(). This is the cause of the timeout. The function itself returns no error, so it believes the data transfer is running, but it is not.

The interrupts are so configured:

0693W00000D0ntHQAR.pngThe CubeMX is version 6.2.1. and the STM32L4 packages are updated.

My opinion is that there is some error in libraries or in the Cube generated code. I have seen other (rare) posts about a similar issue suspecting a libray error.

This is very imbarassing for me because I have an important design that is waiting for the SD card working at full speed.

Without DMA, as I told, the SDcard works but the writing speed is too low and I must run the interface at very low frequency to avoid writing errors. I suppose that read/write operations via DMA will give me the needed speed, but this interrupt problem keeps all the things in stall.

Is there some idea about the non-working interrupt?

Thank you very much

9 REPLIES 9
Haithem Rahmani
ST Employee

Hi @MarcoM​ 

is it possible for you to share the .ioc file generated by the STM32CubeMX, this would help us analyzing the issue?

regards

haithem.

MarcoM
Associate II

Sorry for the big delay.

Yes, here is the .ioc file

MarcoM
Associate II

Is there someone ftom ST that could have an idea about the missing interrupt in using SDcard with DMA?

Do you need other informations?

Thank you.

Haithem Rahmani
ST Employee

Hi @MarcoM​ 

Sorry for the delay, I were in vacation.

could you please enable the following option in the STM32CubeMX, regenerate your project and retest?

regards

Haithem.

Haithem Rahmani
ST Employee

0693W00000Dli93QAB.png

MarcoM
Associate II

Hi @Haithem Rahmani​,

I have enabled the option, regenerated and retested. The result is still the same: I get the 30s timeout after HAL_SD_ReadBlocks_DMA() and the SD_read() returns RES_ERROR.

I have done the test only now because in the last weeks I developed a temporary version that reads audio from an USB pendrive instead of the SD card. This is a temporary solution for the customer, but I now need again to find the way to read/write the SD using DMA because I need the full speed access to SD card.

There must be a missing initialization about something, I suppose. What could I try now?

Thank you

MarcoM
Associate II

Update: I have found that the ISR is called during the DMA transfer from SD card to memory, but the ISR finds that flag RXOVERR in SDMMC status register (SDMMC_STA) in set, so it disables the DMA and the whole process stops waiting for the 30s timeout.

I don't know the reason of RXOVERR. It seems like that the DMA doesn't take away the bytes in the FIFO, until an Overrun.

MarcoM
Associate II

Update: dear @Haithem Rahmani​ ,

after many tests the situation is this:

Using DMA2 Channel 5 in TX and DMA2 Channel 4 in RX, as the configuration I have shown, the software doesn't read the SD and (as told) I get a timeout error when it tries to read the first SD sector. Whan this happens, the SDMMC controller have the RX OVERRUN flag set.

Swapping the two DMA channels (channel 4 in TX and channel 5 in RX) the read operations works without any problem at any SD clock speed, even at the maximum speed. But the write operations always fails, and this happens because the DMA2 Channel 4 interrupt is never called.

If I debug in single-step until SDMMC_CmdWriteSingleBlock(), and than I manually modify by the debugger the value of hdma_sdmmc1_tx->Instance, so it points to Channel 5 instead of Channel 4, the IRQ handler of the Channel 5 is called. Of course this handler is not the right one, because it is for read operations, anyway this prove that DMA2 Channel 5 makes its job and than it calls the IRQ.

All this seems to indicate that the DMA2 Channel 5 works correctly with SDMMC controller, while DMA2 Channel 4 never works.

CubeMX doesn't allow me to configure the software for using only the DMA Channel 5 (the only one that works) for both read and write operations.

What could be the cause of the failure of DMA2 Channel 4? This is the very important point because this failure makes impossible to uso the SD card with DMA data transfer.

I will appreciate very much any useful suggestions, because the software of this project is now in a complete deadlock.

Thank you in advance

RobGeografo
Associate II

Hi,

I have the exact same problem, with the same STM32L476 chip.

Does anyone have any update on this or a workaround?

I have tried all the solutions on this topic on other similar posts, however, none of them helped so far.

Thanks in advance