cancel
Showing results for 
Search instead for 
Did you mean: 

Does the HAL support MMC?

vrouesnel
Associate II
Posted on May 12, 2015 at 01:12

So in `SD_PowerON` there is a comment at the bottom that says `/* else MMC Card */`. `hsd->CardType` is never set to `MULTIMEDIA_CARD` which is defined in `stm32f4xx_hal_sd.h`, and read in `HAL_SD_WideBusOperation_Config`.  I have generated a project in the Cube and changed the `Mode` of `SDIO` to `eMMC 4 bits wide`, but it doesn't seem any different to the SD version.  Here is the function for reference:-  /**
* @brief Enquires cards about their operating voltage and configures clock
* controls and stores SD information that will be needed in future
* in the SD handle.
* @param hsd: SD handle
* @retval SD Card error state
*/
static HAL_SD_ErrorTypedef SD_PowerON(SD_HandleTypeDef *hsd)
{
SDIO_CmdInitTypeDef sdio_cmdinitstructure; 
__IO HAL_SD_ErrorTypedef errorstate = SD_OK; 
uint32_t response = 0, count = 0, validvoltage = 0;
uint32_t sdtype = SD_STD_CAPACITY;
/* Power ON Sequence -------------------------------------------------------*/
/* Disable SDIO Clock */
__HAL_SD_SDIO_DISABLE(); 
/* Set Power State to ON */
SDIO_PowerState_ON(hsd->Instance);
/* 1ms: required power up waiting time before starting the SD initialization 
sequence */
HAL_Delay(1);
/* Enable SDIO Clock */
__HAL_SD_SDIO_ENABLE();
/* CMD0: GO_IDLE_STATE -----------------------------------------------------*/
/* No CMD response required */
sdio_cmdinitstructure.Argument = 0;
sdio_cmdinitstructure.CmdIndex = SD_CMD_GO_IDLE_STATE;
sdio_cmdinitstructure.Response = SDIO_RESPONSE_NO;
sdio_cmdinitstructure.WaitForInterrupt = SDIO_WAIT_NO;
sdio_cmdinitstructure.CPSM = SDIO_CPSM_ENABLE;
SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
/* Check for error conditions */
errorstate = SD_CmdError(hsd);
if(errorstate != SD_OK)
{
/* CMD Response Timeout (wait for CMDSENT flag) */
return errorstate;
}
/* CMD8: SEND_IF_COND ------------------------------------------------------*/
/* Send CMD8 to verify SD card interface operating condition */
/* Argument: - [31:12]: Reserved (shall be set to '0')
- [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V)
- [7:0]: Check Pattern (recommended 0xAA) */
/* CMD Response: R7 */
sdio_cmdinitstructure.Argument = SD_CHECK_PATTERN;
sdio_cmdinitstructure.CmdIndex = SD_SDIO_SEND_IF_COND;
sdio_cmdinitstructure.Response = SDIO_RESPONSE_SHORT;
SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
/* Check for error conditions */ 
errorstate = SD_CmdResp7Error(hsd);
if (errorstate == SD_OK)
{
/* SD Card 2.0 */
hsd->CardType = STD_CAPACITY_SD_CARD_V2_0; 
sdtype = SD_HIGH_CAPACITY;
}
/* Send CMD55 */
sdio_cmdinitstructure.Argument = 0;
sdio_cmdinitstructure.CmdIndex = SD_CMD_APP_CMD;
SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
/* Check for error conditions */
errorstate = SD_CmdResp1Error(hsd, SD_CMD_APP_CMD);
/* If errorstate is Command Timeout, it is a MMC card */
/* If errorstate is SD_OK it is a SD card: SD card 2.0 (voltage range mismatch)
or SD card 1.x */
if(errorstate == SD_OK)
{
/* SD CARD */
/* Send ACMD41 SD_APP_OP_COND with Argument 0x80100000 */
while((!validvoltage) && (count < 
SD_MAX_VOLT_TRIAL
))
{
/* SEND CMD55 APP_CMD with RCA as 0 */
sdio_cmdinitstructure.Argument
= 
0
;
sdio_cmdinitstructure.CmdIndex
= 
SD_CMD_APP_CMD
;
sdio_cmdinitstructure.Response
= 
SDIO_RESPONSE_SHORT
;
sdio_cmdinitstructure.WaitForInterrupt
= 
SDIO_WAIT_NO
;
sdio_cmdinitstructure.CPSM
= 
SDIO_CPSM_ENABLE
;
SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
/* Check for error conditions */
errorstate = SD_CmdResp1Error(hsd, SD_CMD_APP_CMD);
if(errorstate != SD_OK)
{
return errorstate;
}
/* Send CMD41 */
sdio_cmdinitstructure.Argument = SD_VOLTAGE_WINDOW_SD | sdtype;
sdio_cmdinitstructure.CmdIndex = SD_CMD_SD_APP_OP_COND;
sdio_cmdinitstructure.Response = SDIO_RESPONSE_SHORT;
sdio_cmdinitstructure.WaitForInterrupt = SDIO_WAIT_NO;
sdio_cmdinitstructure.CPSM = SDIO_CPSM_ENABLE;
SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
/* Check for error conditions */
errorstate = SD_CmdResp3Error(hsd);
if(errorstate != SD_OK)
{
return errorstate;
}
/* Get command response */
response = SDIO_GetResponse(SDIO_RESP1);
/* Get operating voltage*/
validvoltage = (((response >> 31) == 1) ? 1 : 0);
count++;
}
if(count >= SD_MAX_VOLT_TRIAL)
{
errorstate = SD_INVALID_VOLTRANGE;
return errorstate;
}
if((response & SD_HIGH_CAPACITY) == SD_HIGH_CAPACITY) /* (response &= SD_HIGH_CAPACITY) */
{
hsd->CardType = HIGH_CAPACITY_SD_CARD;
}
} /* else MMC Card */
return errorstate;
}

Note: this post was migrated and contained many threaded conversations, some content may be missing.
37 REPLIES 37
scottmorgan
Associate II
Posted on January 26, 2016 at 21:51

This answer from Mayla is indeed very troubling.  I have no doubt that the low-level code in stm32f4xx_ll_sdmmc.c is to be used with an SD card and an MMC card.  When I try to use stm32f4xx_hal_sd.c with an MMC card it uses those very functions however as has been stated above it simply returns an error which leads me to believe that ST has never tested with an MMC card or has never published a software solution for using one.  The function SD_PowerON() in stm32f24xx_hal_sd.c does not set hsd->CardType = MULTIMEDIA_CARD, HIGH_SPEED_MULTIMEDIA_CARD or HIGH_CAPACITY_MMC_CARD even though the file stm32f4xx_hal_sd.h indicates that these are all supported SD Memory Cards.  When does ST plan to publish a version of stm32f4xx_hal_sd.c that has been tested with MMC cards?

I modified SD_PowerON() as follows:

  } /* else MMC Card */

  else

  {

    hsd->CardType = MULTIMEDIA_CARD;

    errorstate = SD_OK;

  }  

I would like to make use of a Kingston EMMC04G-S100 that has 4GB Capacity via an adapter that interfaces it to a microSD slot in an SD adapter that's connected to my ST eval board.  That part is compliant with eMMC standard 5.0.

I am able to reliably use high capacity microSD cards in that slot with FatFs when I modify sd_diskio.c so that the SD_write() function makes use of BSP_SD_WriteBlocks_DMA() and the SD_read() function makes use of BSP_SD_ReadBlocks_DMA() since I founds that the non-DMA versions of those functions are unreliable and produce FIFO underrun errors as other people have reported on this forum.

Amel NASRI
ST Employee
Posted on February 23, 2016 at 15:50

Hi Scott & all,

To answer the initial question: ''does HAL support MMC?'':

Now there is no MMC driver available. But it will be there in a coming release of the yCube FW packages. When deployed, you will be able to select MMC as SDIO mode from CubeMX interface.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

craig2399
Associate II
Posted on June 20, 2016 at 23:48

Mayla, 

Can you give us an update on MMC support?  I have the latest CubeMX(4.15.0) and it seems like no support has been added since your last post several months ago.  Like others, I am hoping to add eMMC support to my project and would really like to see proper configuration in CubeMX for this functionality.

Thanks,

Craig

Lori B.
Associate III
Posted on June 29, 2016 at 08:39

It would be great to have at least an update on this..

Posted on June 29, 2016 at 13:48

Given how half baked these solutions have been over the years, I think the guiding philosophy should be that you can develop code for the parts you have chosen to use, or modify what is available to suit.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
craig2399
Associate II
Posted on June 29, 2016 at 19:49

I certainly understand that sentiment Clive.  However, in this case the CubeMX software allows you to do the initial configuration of MMC support by giving you the option within the SDIO config.  Unfortunately, they have really only stubbed it out and what you end up with is just the GPIO pins configured and none of the other SDIO configuration code.  You can understand that having Mayla indicate that support was forthcoming, it would be nice to use their offering.  I have enough other things to work on so that I could wait a bit for a new version of CubeMX with MMC support, but without any idea how long that will be, I will likely need to figure it out myself.  That would likely be pretty time consuming.

So if anyone from ST could provide a timeframe for MMC support, it would be appreciated.  Even without CubeMX support, a simple, but complete code example would go a long way.

Lori B.
Associate III
Posted on July 11, 2016 at 16:48

Apart from this, I would also add that we would have nothing to object to ST, if it wasn't for the fact that they claim the HAL already supports eMMCs, while it clearly doesn't!!

Posted on July 11, 2016 at 17:38

I would suggest you start shaking the tree from the distribution/sales contacts you have with ST, discussing with your FAE, and your eMMC part vendors and their FAEs. The direction of the ship is dictated by large customers, with specific requirements.

Most examples in the storage media space are of the ''tada! look it works! kinda'' category. ST proves a basic level of functionality, will minimal error propagation, and recovery. It doesn't look to me as if these things were written by people with much experience in the storage media space, but rather by people who have access to the protocol documentation and not much else. Being beholden to people with little more experience in the space than anyone else is not a strong position to work from.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Lori B.
Associate III
Posted on July 22, 2016 at 09:52

Hi clive1, thank you for your interest!

Actually I managed to hanve my eMMC working with a lot of code added to the ST HAL SD driver. It also works when used with USB MSC device class.

Unfortunatly I have  some problems with performances since my eMMC file transfer is really slow, but for the moment I'm quite happy with the result.

craig2399
Associate II
Posted on September 15, 2016 at 19:27

Hi All,

I too was able to get my eMMC chip working the FatFs and I would like to provide some details about what I did, so hopefully others might benefit as well. I was able to find what Nemui did and apply it. Thanks Nemui!

Just a quick recap. The basic problem is that the MMC configuration is not yet implemented/provided by CubeMX. You are able to select it, but the result is just the pins being configured and nothing else. What most have found is that basically stm32f4xx_hal_sd.c is missing the necessary code to support MMC. There are comments and various if statements that are in place for some code, but they really just set an error code and return.

I am using a custom board with a STM32F429NGH6 and Micron Tech MTFC2GMDEA (2 gig 8-bit eMMC).

My approach might seem a bit odd, but my goal was to leverage as much of CubeMX’sgenerated code as possible. Additionally, I wanted a very easy path to switch over to thesanctioned implementation once ST adds it to CubeMX. So I actually started by configuring my project for 1-bit SDIO rather than MMC, so that CubeMX would generate all the SDIO initialization code, etc. Then I just manually configured the other 7 SDIO pins in CubeMX (read below).

My steps for getting the FatFs working with eMMC:

  • In CubeMX, add/configure SDIO as“SD 1-bit�? (we will switch to 8-bit after initialization in main.c).
  • Configure the other pins that would normally be used by MMC (8-bit in my case) the same as the SDIO_D0 pin that is configured when you add SDIO 1-bit support. The easiest way to figure out what pins these are is to set the SDIO to 8-bit and look at what pins were configured, then set the SDIO back to 1-bit and manually click on eachof the pins and set them to the correct function (SDIO_D1 through SDIO_D7).
  • In CubeMX, add/configure FatFs using“SD Card�?.
  • Export your project.
  • Modifystm32f4xx_hal_sd.c (see my modified version ATTACHED). **NOTE** remember that CubeMX will overwrite this file every time you regenerate your project so you need to keep it safe. I havethe project under version control, so I can easily spot and discard the subsequently generated file each time I generate from CubeMX.

The result is a project that is ready for file I/O via FatFs. I have attached my main.c with a very simple file test. I tried to keep it assimple as possible, but please note that I have a USART configured for logging. If you are interested to see all themodifications that I made tostm32f4xx_hal_sd.c, open it and search for“for eMMC�?. I believe that I added a comment including that text at thebeginning of every block of modified.

I hope others may find this useful. I am not an expert with SDIO/MMC so I would be happy to hear from anyone with suggested improvements or if there are issues with this code. I’m happy to answer questions as well, but as I said, I’m no expert with this stuff.

Thanks,

Craig

________________

Attachments :

main.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1Gb&d=%2Fa%2F0X0000000bkY%2FCkDZMertvGCSuExA0vZyrILu.6dDd4djJatBiIsAiRM&asPdf=false

stm32f4xx_hal_sd.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1GD&d=%2Fa%2F0X0000000bkU%2F.gQDCN19yjRsq.8rh9F.vU_cGTgw4tke8SpTML8pnLA&asPdf=false