cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4: HAL_MMC driver - get stuck in MMC_ReadExtCSD()

CZ.4
Associate II

I'm using STM32L4A6 and it's SDMMC peripheral to communicate with an eMMC device.

I found it occasionally get stuck in the MMC_InitCard() call. Further investigation shows it's stuck in the MMC_ReadExtCSD() call, where it utilizes a timeout value of 0x0FFFFFFF in a loop. (stm32l4xx_hal_mmc.c, line 3844). The timeout is measured by tick count. But with such a large number, what ever the unit for the tick is, this basically makes it an infinitive loop.

I experimented with a much smaller value, ie 1000 etc. It does get out of the loop with a timeout error. This triggers subsequent error handling. And once it got out, retry for once or twice usually can get it pass here.

My questions:

  1. What's the likely cause for the failure. The comment in MMC_ReadExtCSD() describes the block of code as 'poll on SDMMC flags'. So something is wrong.
  2. Why such a large value for timeout? Or it mean to be modified by developers? And what value is reasonable?

I'm using STM32 CubeL4 firmware package1.17.0 (and STM32L4xx HAL 1.13.0).

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @CZ.4​ ,

The timeout values highly depend on the SDMMC card (or SDIO device) you're using (Speed Class Rating). The default configuration is set to support a really slow card (lowest common denominator :) ), and if you're sure or are sourcing yourself your SDMMC cards, then you'd need some experimentation to identify the ideal configuration for your project.

The timeout is derived from Systick thour HAL_GetTick(), so expect that the wait will be **at least** the value of timeout (SysTick is generally set to low priority), so if you configure it to 1000ms, it is absolutely normal to find that the real wait is more than that. As for the unit, it depends on the configuration of the SysTick interrupt which is 1ms by default.

Best regards,

@SBEN .2​ 

View solution in original post

5 REPLIES 5
SBEN .2
Senior II

Hello @CZ.4​ ,

The default timeout value is meant to be customized. As for the issue itself, more information is needed (more details about the scenario, the SDMMC card itself, etc...).

Best regards,

@SBEN .2​ 

Thanks for the info. Can you elaborate how to customize this timeout value? Without being an expert on MMC it's hard to guess what value is suitable. In this case I experiment with 1000ms. It seems working ok so far.

I also found these macros regarding timeouts in the stm32l4xx_ll_sdmmc.h:

#define SDMMC_DATATIMEOUT                 ((uint32_t)0xFFFFFFFFU)

#define SDMMC_CMDTIMEOUT                  ((uint32_t)5000U)       /* Command send and response timeout    */

#define SDMMC_MAXERASETIMEOUT             ((uint32_t)63000U)      /* Max erase Timeout 63 s               */

#define SDMMC_STOPTRANSFERTIMEOUT         ((uint32_t)100000000U)  /* Timeout for STOP TRANSMISSION command */

Are these also needs to be customized? Is there any documents or guidance regarding this? Is the time unit to be millisecond?

Thanks!

Hello @CZ.4​ ,

The timeout values highly depend on the SDMMC card (or SDIO device) you're using (Speed Class Rating). The default configuration is set to support a really slow card (lowest common denominator :) ), and if you're sure or are sourcing yourself your SDMMC cards, then you'd need some experimentation to identify the ideal configuration for your project.

The timeout is derived from Systick thour HAL_GetTick(), so expect that the wait will be **at least** the value of timeout (SysTick is generally set to low priority), so if you configure it to 1000ms, it is absolutely normal to find that the real wait is more than that. As for the unit, it depends on the configuration of the SysTick interrupt which is 1ms by default.

Best regards,

@SBEN .2​ 

CZ.4
Associate II

Ok, thanks!

DKapu
Associate II

Hi @SBEN .2​ ,

The problem is that in the driver code the timeout for call to MMC_ReadExtCSD() is not a defined constant but rather hardcoded value of 0x0FFFFFFF which does not look any reasonable.

Do you know why it is not set to the defined constant SDMMC_CMDTIMEOUT ?

Thanks,

Dima.