cancel
Showing results for 
Search instead for 
Did you mean: 

Enable eMMC on STM32H743, get multiple block writing failed

CChen.4
Associate

Hi ST Community:

I'm appling STM32H743 with eMMC card in my project. I call function "HAL_MMC_WriteBlocks" for block writing. The problem is when I write one block every time, the write operation is ok. When write more than one blocks, it get failed. I use the newest FW(STM32Cube_FW_H7_V1.5.0). I have no idea about how to modify the HAL driver, could you please offer some help? Thank you.

/**********************

Here is initial code of SDMMC:

HmsUint8 Hms_SDMMC1_MMC_Init(HmsUint32 print)

{

 HmsUint8 ret = HAL_OK;

 static HmsUint8 InitFlag = 0;

 if(InitFlag)

  return HAL_OK;

 hmmc1.Instance = SDMMC1;

 hmmc1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;

 hmmc1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;

 hmmc1.Init.BusWide = SDMMC_BUS_WIDE_1B;

 hmmc1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;

 hmmc1.Init.ClockDiv = 3;

 //printf("start HAL_MMC_Init...\r\n");

 if (HAL_MMC_Init(&hmmc1) != HAL_OK)

 {

  ret= HAL_ERROR;

  printf("HAL_MMC_Init Error!!!\r\n");

 }

 if (HAL_MMC_ConfigWideBusOperation(&hmmc1, SDMMC_BUS_WIDE_8B) != HAL_OK)

 {

  ret= HAL_ERROR;

   printf("HAL_MMC_ConfigWideBusOperation Error!!!\r\n");

 }

}

void HAL_MMC_MspInit(MMC_HandleTypeDef* hmmc)

{

 GPIO_InitTypeDef GPIO_InitStruct;

 if(hmmc->Instance==SDMMC1)

 {

 /* USER CODE BEGIN SDMMC1_MspInit 0 */

 /* USER CODE END SDMMC1_MspInit 0 */

   /* Peripheral clock enable */

   __HAL_RCC_SDMMC1_CLK_ENABLE();

   /**SDMMC1 GPIO Configuration   

   PC6    ------> SDMMC1_D6

   PC7    ------> SDMMC1_D7

   PC8    ------> SDMMC1_D0

   PC9    ------> SDMMC1_D1

   PC10    ------> SDMMC1_D2

   PC11    ------> SDMMC1_D3

   PC12    ------> SDMMC1_CK

   PD2    ------> SDMMC1_CMD

   PB8    ------> SDMMC1_D4

   PB9    ------> SDMMC1_D5

   */

   GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9

                         |GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;

   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

   GPIO_InitStruct.Pull = GPIO_NOPULL;

   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

   GPIO_InitStruct.Alternate = GPIO_AF12_SDIO1;

   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

   GPIO_InitStruct.Pin = GPIO_PIN_2;

   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

   GPIO_InitStruct.Pull = GPIO_NOPULL;

   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

   GPIO_InitStruct.Alternate = GPIO_AF12_SDIO1;

   HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

   GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;

   GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

   GPIO_InitStruct.Pull = GPIO_NOPULL;

   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

   GPIO_InitStruct.Alternate = GPIO_AF12_SDIO1;

   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

 }

}

/*****************

The following is the test log:

***************************MMC Card info***************************

CardType:1

Class:245

RelCardAdd:0

BlockNbr:62128128

BlockSize:512

Card state:1

Card CID:fe014e4d-4d433332-4740e106-ff2972c4

Card CSD:d04f0132-0f5913ff-ffffffff-8a4000de

*******************************************************************

CMMC_CLKCR:8003

task:Hms_TaskStart...

Hms_eMMC_R_W_Test start...

Write Block 0,1

eMMC-STAR:0,ICR:0

Write Block 1,1

eMMC-STAR:0,ICR:0

Write Block 2,1

eMMC-STAR:0,ICR:0

Write Block 3,1

eMMC-STAR:0,ICR:0

Write Block 4,1

eMMC-STAR:0,ICR:0

Write Block 5,1

eMMC-STAR:0,ICR:0

Write Block 6,1

eMMC-STAR:0,ICR:0

Write Block 7,1

eMMC-STAR:0,ICR:0

Write Block 8,1

eMMC-STAR:0,ICR:0

Write Block 9,1

eMMC-STAR:0,ICR:0

Write Block 10,1

eMMC-STAR:0,ICR:0

Write Block 11,2  //start to write 2 blocks every time

eMMC-STAR:101000,ICR:0 //Write get pass.read STAR after write operation finished, Bit12=1:DPSM is active, Bit20=1:SDMMC_D0 is busy

Write Block 13,2

eMMC-STAR:0,ICR:0

Write Failed 3,MMC State 4 !!! //Write get failed.3:write operation timeout.4 is return of “HAL_MMC_GetCardState�?

Write Block 15,2

eMMC-STAR:101000,ICR:0

Write Block 17,2

eMMC-STAR:101000,ICR:0

Write Failed 1,MMC State 6 !!!

Write Block 19,2

eMMC-STAR:2000,ICR:0

Write Failed 1,MMC State 4 !!!

Write Block 21,2

eMMC-STAR:0,ICR:0

Write Failed 3,MMC State 4 !!!

Write Block 23,2

eMMC-STAR:101000,ICR:0

Write Block 25,2

eMMC-STAR:0,ICR:0

Write Failed 3,MMC State 4 !!!

Write Block 27,2

eMMC-STAR:101000,ICR:0

Write Block 29,2

1 REPLY 1
CChen.4
Associate

It's down by switch to DMA read and write operation. If your use DMA for read and write, you need to pay attantiion to cache, because DMA makes the data not match between RAM and Cache.