Skip to main content
NBrow.1
Associate
March 4, 2021
Question

FW v1.16.1 broke HAL MMC Driver

  • March 4, 2021
  • 4 replies
  • 2219 views

Using a custom board with an STM32F769 I had successfully interfaced to an eMMC with the HAL-MMC driver. The limitations of the driver's ability to query the extended CSD were clearly noted on this forum. I implemented my own routines to retrieve this information and correct the block sizes (after HAL_MMC_Init call). After upgrading to F7 FW v1.16.1 (released mid February) I noticed this functionality had been added to the driver itself so I removed my version.

The out of the box driver fails when calling MMC_ReadExtCSD() from HAL_MMC_GetCardCSD() with a command timeout (CTIMEOUT) error. After quite a bit of debuggin I compared the driver to the STM32L series driver and noticed in that version the SDMMC_CmdSelDesel() call was made prior to HAL_MMC_GetCardCSD(). After making the modification the code runs successfully. I'm by no means an SDMMC expert but I believe this fix needs to be made in the next firmware release. I would appreciate ST/Community confirming the issue. The "fixed" and suspect code is below:

/////// Working Code ////////// 
 /* Select the Card */
 errorstate = SDMMC_CmdSelDesel(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
 if(errorstate != HAL_MMC_ERROR_NONE)
 {
 return errorstate;
 }
 
 /* Get CSD parameters */
 if (HAL_MMC_GetCardCSD(hmmc, &CSD) != HAL_OK)
 {
 return hmmc->ErrorCode;
 }
 /////// Suspect Code //////////
 /* Get CSD parameters */
 if (HAL_MMC_GetCardCSD(hmmc, &CSD) != HAL_OK)
 {
 return hmmc->ErrorCode;
 }
 
 /* Select the Card */
 errorstate = SDMMC_CmdSelDesel(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
 if(errorstate != HAL_MMC_ERROR_NONE)
 {
 return errorstate;
 }

This topic has been closed for replies.

4 replies

Tesla DeLorean
Guru
March 4, 2021

Pretty sure the method that works most robustly is

Get CID from card

Select w/Relative Address Zero

Get RCA from card

Get CSD from card using RCA as parameter

Select w/RCA

if (BlockCount == 0x200000) Get EXTCSD from card

Depends what "HAL_MMC/SD_GetCardCSD()" does, most implementations just decode the CSD into structure variables, they don't actually call anything, but obviously ST continually shuffles things around

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
NBrow.1
NBrow.1Author
Associate
March 4, 2021

Thanks for the info, I'll use that order in my modified driver. The HAL_MMC_GetCardCSD() first decodes the CSD and then midway through actually makes a call to retrieve the extended CSD. It's a bit misleading but at least ST is making progress on the driver.

Tesla DeLorean
Guru
March 4, 2021

>>at least ST is making progress on the driver.

I suppose. Not clear to me why they need an SD and MMC fork, I just merged in a handful of changes to the old SDIO drivers.

The speed and bus-width stuff is still a huge mess.

And the shipping FatFs library is broken.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
MMenz.1
Associate II
September 9, 2022

Safed my day, thanks a lot