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
Posted on May 12, 2015 at 01:19

You have a very old

http://en.wikipedia.org/wiki/MultiMediaCard

card or something else?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
vrouesnel
Associate II
Posted on May 12, 2015 at 02:28

We are currently using SD card, and we are moving to eMMC in the next hardware. I don't have the new hardware yet, so just wanted to see if there was anything I need to do to get it to work.

Lori B.
Associate III
Posted on January 12, 2016 at 14:57

I have the same exact question as pinkman.

I'm working on integrating an eMMC, but I can't event make it through the HAL_SD_Init() since, from the code above, HAL libraries don't seem to fully implement it!

I can't understand how I am supposed to build my eMMC app over HAL, since getting a ''errorstate = Command Timeout'' leads nowhere!
scottmorgan
Associate II
Posted on January 12, 2016 at 17:10

Exact same problem here.  I connect an eMMC and I see the errorState returned by SD_PowerON() is SD_CMD_RSP_TIMEOUT.  The function HAL_SD_Init() returns that error and so there is no further initialization.  In the case of an SD card that function proceeds with a cal to SD_Initialize_Cards() but there is nothing there for an MMC card.

scottmorgan
Associate II
Posted on January 12, 2016 at 17:20

pinkman, how did you end up solving this problem? 

Posted on January 13, 2016 at 01:59

Dear all, MMC initialize command(CMD1) fully lacks since Standard Peripheral Library.

In addition, currently HAL Drivers(F4,F7 and other) cannot initialize not only MMC but also SDv1 Cards!!.

I'll report this bug on ''STM32 Software Tools and Firmware'' forum.

Attachment file shows my test code for F4(confirmed SDv1,MMCv3 soon).

Although still I'm using with SPL,but you can easily migrate to HAL.

edited:20161026

I confirmed my FatFs project to work 2GB MMCplus(MMCv4.1) and very older 128MB MMC(MMCv3) cards.

Also 8GB eMMC v5(confirmed currently upto 4-bitmode).

Here is my achievement for now.

STM32F7-Discovery:

http://nemuisan.blog.bai.ne.jp/?eid=192848#STM32F7

STM32F407ZGT(should edit makefile to use SDIO):

http://nemuisan.blog.bai.ne.jp/?eid=192848#STM32F4

STM32Primer2(STM32F103ZET6):

https://github.com/nemuisan/STM32Primer2_GPS_Tracker

See also related article(pls use google-translation)

http://nemuisan.blog.bai.ne.jp/?eid=218492

Cheers,

Nemui.

Lori B.
Associate III
Posted on January 13, 2016 at 09:29

Thanks for the support!

Anyway that's a complete non-sense from ST! In the STM32F2 Reference Manual they explicitly say to support MMCs and then they don't release a low level driver regarding it!

Amel NASRI
ST Employee
Posted on January 13, 2016 at 09:51

Hi,

The SDMMC driver is available in STM32CubeF2/STM32CubeF4/STM32CubeF7.

In F4 case, it is stm32f4xx_ll_sdmmc.c located under STM32Cube_FW_F4_V1.10.0\Drivers\STM32F4xx_HAL_Driver\Src.

As stated in this file:

The SDIO features include the following:

         (+) Full compliance with MultiMedia Card System Specification Version 4.2. Card support for three different databus modes: 1-bit (default), 4-bit and 8-bit

         (+) Full compatibility with previous versions of MultiMedia Cards (forward compatibility)

         (+) Full compliance with SD Memory Card Specifications Version 2.0

         (+) Full compliance with SD I/O Card Specification Version 2.0: card support for two different data bus modes: 1-bit (default) and 4-bit

         (+) Full support of the CE-ATA features (full compliance with CE-ATA digital protocol Rev1.1)

         (+) Data transfer up to 48 MHz for the 8 bit mode

         (+) Data and command output enable signals to control external bidirectional drivers.

So I recommend you to review this driver.

If we are speaking about different things, please correct me.

If the issue is in CubeMX side, Yes I confirm that SDMMC is not yet supported even if you can select it in the Pinout wizard.

-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.

Lori B.
Associate III
Posted on January 13, 2016 at 10:04

Hi Mayla! Thanks for replying!

So, are we supposed to use the ''stm32f2xx_ll_sdmmc'' driver instead of the ''stm32f2xx_hal_sd'' when dealing with MMCs?

I looked at the ''stm32f2xx_ll_sdmmc'' but it looks so poor compared to the second one, looking at its functions. For example it doesn't have ''ReadBlocks'' or ''WriteBlocks'' functions, it doesn't have DMA, etc.

How are we supposed to use it, compared to using an SD card?