cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 SDMMC Command Timeout

ChrisH
Associate III
Posted on July 05, 2017 at 10:53

While using SDMMC with FatFS to interface with SDCards occasionally I get Command Timeout when issuing:

SDMMC_CmdReadSingleBlock

This is when using new 1.7.0 drivers. Did anyone experience similar issue?

29 REPLIES 29
Posted on August 29, 2017 at 18:15

Currently I resolved problems in my code by using following approach:

1) using two HAL callbacks for SDIO RX complete and TX complete:

2) after callback waiting for HAL_SD_CARD_TRANSFER.

__IO uint8_t nowRxSd=0;
__IO uint8_t nowTxSd=0;
void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)
{
if (hsd->Instance==SDIO)
 {
nowRxSd=0;
}

}
void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)
{
if (hsd->Instance==SDIO)
 {
nowTxSd=0;
}

}
...
reading:
nowRxSd=1;
HAL_SD_ReadBlocks_DMA(&hsd, (uint8_t*)&tmpBuffer, sdaddr, 32);
while (nowRxSd==1) {}
while (1)
{
ch=HAL_SD_GetCardState(&hsd);
if (ch==HAL_SD_CARD_TRANSFER) break;
}
writing:
nowTxSd=1;
ch1=HAL_SD_WriteBlocks_DMA(&hsd, (uint8_t*)&adcBuffer, address, 32);
while (nowTxSd==1) {}
while (1)
{
ch=HAL_SD_GetCardState(&hsd);
if (ch==HAL_SD_CARD_TRANSFER) break;
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Posted on August 29, 2017 at 18:39

Georgy, your solution wont solve timeouts on ReadBlocksDMA function. But its proper Flow to read and write with when using dma

Nesrine M_O
Lead II
Posted on October 03, 2017 at 17:53

Hi,

Thanks for highlighting this issue!

I will check it  with our development team & come back to you ASAP.Sorry for the inconvenience it may bring.

-Nesrine-

vladimir boretsky
Associate II
Posted on October 18, 2017 at 12:26

Hi friends!

Do anybody have working project for STM32L476 for READ WRITE files with DMA mode using by FatFs?

Could you send me this project?

mailto:boretskyv@gmail.com

Best regards. 

Posted on October 19, 2017 at 15:44

This worked. Similar situation with heavily loaded stm32F401.

Thanks Chris,

Tony

Posted on October 30, 2017 at 08:28

Hi Nesrine,

Any updates on this - will there be a fix when the next versions are released? The initial problem was reported for L4, but it's the same issue of F7.

Posted on November 16, 2017 at 03:01

I can also confirm it is the same case with the F4 library, and

Moshkin.Georgy

's fix works.

Posted on November 16, 2017 at 16:24

Thank you for mentioning that. I used similar approach with callbacks not only for SDIO but also for SPI with the newest libraries around August.  Wiznet chip Ethernet, AX1 software tool loopback works with DMA near full theoretical MBPS speed limit without errors. Had no problems with SD cards yet, although I use only old 2gb cards which are slow, and no fat FS. But setup is pretty heavy, Simultaneously working: SPI+DMA, sdio+DMA writing to SD card, i2s 4 channels + interrupts, UART+interrupts, signal processing, all on F4. I did not used DMA everywhere just because there are no more free DMA channels left, because there is also DAC-dma and some other stuff.

Here is email I sent to someone interested in solving similar problem:

Unfortunately I did not used FatFS in my projects.

Although someone mentioned that

'Georgy, your solution wont solve timeouts on ReadBlocksDMA function. But its proper Flow to read and write with when using dma',I think it will probably solve the problem.Main idea is to wait for HAL_SD_RxCpltCallback before calling any other SDIO functions. I did not traced the problem, but if HAL_SD_ReadBlocks_DMA is followed by any SDIO calls (reading SDIO status/etc.) then reading did not work properly. Note that problems with FatFS appear on newer HAL firmware libraries.

I use SPI for WizNet Ethernet chip and SDIO for SD card, both in DMA modes.I had similar problems with SPI dma reading (latest HAL firmware). For example, random Ethernet exchange errors on high data rates. Problem solved in similar way: waiting for reading/writing CPLT callback.

Although this approach is blocking execution until CPLT callback is called:

HAL_SD_ReadBlocks_DMA

blocking execution, waiting  for HAL_SD_RxCpltCallbackit may be improved: for example set flag in read CPLT callback. Check this flag before reading.

default value of flag is 1 (CPLT is called)

reading operation:

on program execution flag is initialized to 1, as if CPLT callback is already called.

check if flag is 1

SDIO read, set flag=0

do not wait, continue execution

if later another read operation is performed:

check if flag is 1

SDIO read, set flag=0

do not wait, continue execution

Hope it helps.

Georgy.

Posted on November 17, 2017 at 02:36

The HAL library is a great work. However, it does needs some touch to work reliably. Thanks to this forum, I also solved a DMA FIFO error problem for SDRAM to SPI transfer the other day. 

BTW, after your fix my FAT on TF card works so far so good. In my system, there are RTOS, and quite a few DMA, including 4 SPI, SDIO, DAC, timer for pulse sequence, and USB. 

PS. a little off-topic, are you also aware some glitch with the USB library? maybe the USB HAL as well. As some of my USB stick does not work properly with the recent HAL, but it worked ok with the HAL some time last year.

Posted on November 29, 2017 at 11:20

Hi Nesrine,

When can we expect an official patch to SD timeout issue? It takes too much time in my opinion.