2015-05-11 04:12 PM
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.
2016-10-11 08:45 AM
Hi Craig,
thank you for your contribution. I'm trying to use an eMMC with the STM32F7 using your method but I'm not able to found your modifications to stm32f4xx_hal_sd.c (there is no ''for eMMC'' results in the attached file). Did you attached the correct version? Thank you!2017-01-19 05:13 PM
Dear all,
I found MMC(and eMMC) support added on newest CubeF7V1.6.0!
http://www.st.com/en/embedded-software/stm32cubef7.html
And sdcard HAL driver was revised overall from former one.
2017-02-03 04:09 AM
Dear All,
I'm just getting into this problem too as I need to support an eMMC with the STM32F7. What I have found so far:
1. The drivers in STM32CubeF7 1.6.0 seem to be the same as what is in STM32CubeMX 4.19.0
2. There is a HAL 'driver' for MMC in those libraries, but you cannot enable it in the GUI.
3. There is no user level layers between the HAL MMC driver and FATfs, i.e. no 'bsp_driver_mmc.c' or 'mmc_diskio.c'.
4. The HAL driver for MMC does not support memories over 2GB.
5. The HAL driver for MMC may not ever have been used or even compiled, as it has inconsistencies in function names.
I am currently working my way through all this. I have had some success by writing the missing bits, but still have some issues to fix. Card initialisation seems to work stepping through with the debugger but fails at full speed, and I also get errors when trying to write a file.
2017-02-03 07:04 AM
Dear Gideon Riddell,
Because of 1~5 reasons you suggest(especially 4!) ,I dare to use old v1.5.0 SD HAL driver.
For detail, see this entry.https://community.st.com/0D50X00009Xkh8DSAR
Best Regards,
Nemui.2017-02-03 07:21 AM
Hi Nemui,
Thanks for the tip.
Did you use it with an SDcard or eMMC?
Regards,
Gideon
2017-02-04 01:27 AM
Dear Gideon Riddell,
I confirmed many SDCards and some MMC&eMMCv5 on the STM32F746G/769I-Discoveries.
Nomal size standard SD was confirmed with SD->MicroSD Aadapter.
http://www.hwtools.net/ExtenderBoard/EXTF.html
eMMC was confirmed with Odroid's eMMC to MicroSD Adapter(up to 4bit,8bit cannot applicable).
http://www.hardkernel.com/main/products/prdt_info.php?g_code=G145628097465
Best Regards,
Nemui.2018-05-11 07:49 AM
Hi
Riddell.Gideon
I know this is an old topic, but did you by any chance solve the problems you are describing? I have come to the exact same conclusions, even though over a year passed since your post.
2018-05-21 04:50 AM
Nemui Trinomius is the only code I found that works. There is hope that the STM32H7 supporting eMMC 4.5 will result in improvements to the HAL library and CubeMX.
2018-05-21 10:25 AM
https://community.st.com/0D50X00009XkhQ7SAJ
I'm working on getting the H7 MMC driver working, in the mean time I do have the F4 stuff working having implemented the CMD1/CMD2/CMD3 startup, and CMD7/CMD8 EXTCSD capacity detection. The regular CSD reports 1GB media with the Samsung 16GB and 32GB modules and this needs to be replaced with the values from the EXDCSD. There is a bunch of wrong headed code in ST's implementation which breaks the block addressing for cards it believes are 2GB or less.
I have furnished
Przenioslo.Lukasz
with the modified files I'm working with on the STM32F412G-DISCO board, along with the ODROID modules and adapters.The 32GB Samsung is eMMC 5.1
http://www.samsung.com/semiconductor/estorage/emmc/KLMBG2JENB-B041/
If someone wants to sponsor some 64GB and 128GB ODROID cards I will test those.
FatFs Testing (68300)
00200000 2097152 1.00 GB GetCardCSD 03A3E000 12 GB 54 GB EXTCSD READ 0 1 00000000 : FA B8 00 10 8E D0 BC 00-B0 B8 00 00 8E D8 8E C0 ................ 00000010 : FB BE 00 7C BF 00 06 B9-00 02 F3 A4 EA 21 06 00 ...|.........!.. 00000020 : 00 BE BE 07 38 04 75 0B-83 C6 10 81 FE FE 07 75 ....8.u........u 00000030 : F3 EB 16 B4 02 B0 01 BB-00 7C B2 80 8A 74 01 8B .........|...t.. 00000040 : 4C 02 CD 13 EA 00 7C 00-00 EB FE 00 00 00 00 00 L.....|......... 00000050 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000060 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000070 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000080 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000090 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000000A0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000000B0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000000C0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000000D0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000000E0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000000F0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000100 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000110 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000120 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000130 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000140 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000150 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000160 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000170 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000180 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000190 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000001A0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000001B0 : 00 00 00 00 00 00 00 00-53 FD ED 3C 00 00 00 20 ........S..<... 000001C0 : 21 00 0C 71 21 10 00 08-00 00 00 00 04 00 00 00 !..q!........... 000001D0 : 01 20 83 98 8B CD 00 08-04 00 00 E0 AB 00 00 00 . .............. 000001E0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000001F0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA ..............U. READ 2048 1 00000000 : EB 3C 90 6D 6B 66 73 2E-66 61 74 00 02 04 01 00 .<.mkfs.fat..... 00000010 : 02 00 02 00 00 F8 00 01-3F 00 FF 00 00 00 00 00 ........?....... 00000020 : 00 00 04 00 80 00 29 67-68 AA 52 62 6F 6F 74 20 ......)gh.Rboot 00000030 : 20 20 20 20 20 20 46 41-54 31 36 20 20 20 0E 1F FAT16 .. 00000040 : BE 5B 7C AC 22 C0 74 0B-56 B4 0E BB 07 00 CD 10 .[|.'.t.V....... 00000050 : 5E EB F0 32 E4 CD 16 CD-19 EB FE 54 68 69 73 20 ^..2.......This 00000060 : 69 73 20 6E 6F 74 20 61-20 62 6F 6F 74 61 62 6C is not a bootabl 00000070 : 65 20 64 69 73 6B 2E 20-20 50 6C 65 61 73 65 20 e disk. Please 00000080 : 69 6E 73 65 72 74 20 61-20 62 6F 6F 74 61 62 6C insert a bootabl 00000090 : 65 20 66 6C 6F 70 70 79-20 61 6E 64 0D 0A 70 72 e floppy and..pr 000000A0 : 65 73 73 20 61 6E 79 20-6B 65 79 20 74 6F 20 74 ess any key to t 000000B0 : 72 79 20 61 67 61 69 6E-20 2E 2E 2E 20 0D 0A 00 ry again ... ... 000000C0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000000D0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000000E0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000000F0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000100 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000110 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000120 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000130 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000140 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000150 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000160 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000170 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000180 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00000190 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000001A0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000001B0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000001C0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000001D0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000001E0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 000001F0 : 00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA ..............U. FAT168 MB total drive space
9 MB available 9 MB used Display Directory ---- 62844 /exynos5422-odroidxu3.dtb ---- 10288963 /uInitrd ---- 5744416 /zImage ---- 9642 /boot.ini ---- 62739 /exynos5422-odroidxu4.dtb ---- 62093 /exynos5422-odroidxu3-lite.dtb ---- 753 /boot.ini.defaultNeed to reformat/repartition
2018-05-21 10:47 AM
Sounds like you are making good progress. I tried going down that route but eventually decided it was too much effort and instead imported Nemui's code on top of the F7 HAL library. It works with both eMMC (we made a SDcard containing an eMMC*) and SDCards of a variety of sizes. It does not use DMA, as that does not seem to work.
*Crazy, I know, but necessary for our application.