cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407VG + 4 bit SDIO + DMA does not work probably

JulianH
Associate II
Posted on April 27, 2018 at 19:33

Hi,

I am using the STM32F407VG and try to read an SD Card over SDIO in 4 bit mode.

I have downloaded the fatfs driver from this site:

https://community.st.com/external-link.jspa?url=http%3A%2F%2Fstm32f4-discovery.net%2F2015%2F08%2Fhal-library-20-fatfs-for-stm32fxxx%2F

The initialization works absolutely fine until the second invocation of check_fs in line 3008 of ff.c 'fmt = bsect ? check_fs(fs, bsect) : 3; /* Check the partition */'

(Note: The first invocation of check_fs in line 2998 'fmt = check_fs(fs, bsect);' returns the correct value (2))

Where it sticks after the check_fs invocation is in the interrupt of the DMA RX interrupt callback:

static void SD_DMA_RxCplt(DMA_HandleTypeDef *hdma)
{
 SD_HandleTypeDef *hsd = (SD_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
 /* DMA transfer is complete */
 hsd->DmaTransferCplt = 1U;
 /* Wait until SD transfer is complete */
 while(hsd->SdTransferCplt == 0U)
 {
 }
 /* Disable the DMA channel */
 HAL_DMA_Abort(hdma);
 /* Transfer complete user callback */
 HAL_SD_DMA_RxCpltCallback(hsd->hdmarx); 
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

line 9 ('while(hsd->SdTransferCplt == 0U)).

Any ideas what is going wrong?

3 REPLIES 3
Posted on April 27, 2018 at 23:36

The DISKIO or SDIO layer isn't working properly or returning inconsistent data.

Review current HAL examples. 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 09, 2018 at 12:16

Now I figured out, the second check_fs-call isn't working because theHAL_SD_IRQHandler-interrupt-function isn't setting the hsd->SdTransferCplt = 1U; due to a CRC error. So the SD_DMA_RxCplt-interrupt-functionends up in the infinite while loopwhile(hsd->SdTransferCplt == 0U).

So my questions changed to: Why I am getting a CRC-error in the second invocation of the check_fs-function (always in the second)?

The CRC-error check happens here:

void HAL_SD_IRQHandler(SD_HandleTypeDef *hsd)
{ 
 /* Check for SDIO interrupt flags */
 if (__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_IT_DATAEND))
 {
 __HAL_SD_SDIO_CLEAR_FLAG(hsd, SDIO_IT_DATAEND); 
 
 /* SD transfer is complete */
 hsd->SdTransferCplt = 1U;
 /* No transfer error */ 
 hsd->SdTransferErr = SD_OK;
 HAL_SD_XferCpltCallback(hsd); 
 } 
 --------> else if (__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_IT_DCRCFAIL))
 {
 __HAL_SD_SDIO_CLEAR_FLAG(hsd, SDIO_FLAG_DCRCFAIL);
 
 hsd->SdTransferErr = SD_DATA_CRC_FAIL;
 
 HAL_SD_XferErrorCallback(hsd);
 
 }
 else if (__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_IT_DTIMEOUT))
 {�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

So the execution never reaches

hsd->SdTransferCplt = 1U; and is ending up in the endless while loop.

Posted on May 18, 2018 at 15:29

I attached a minimal project of my problem. May be someone can take a look over it.

________________

Attachments :

sdio_test.rar : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxb1&d=%2Fa%2F0X0000000b08%2F8lobDjfF.aLy9ggNKwDEv.43.r5iLWiTdrl2mS8iWDM&asPdf=false