cancel
Showing results for 
Search instead for 
Did you mean: 

Getting TXUNDERR while writing data to eMMC

Srikanth1
Senior

Hello 

-> We are using a custom board with STM32H745 controller and 8GB eMMC communicated with sdmmc. 

-> getting SDMMC_FLAG_TXUNDERR bit after writing 64 bytes to eMMC. But i am giving 1k buffer array to write. 

-> eMMC initialization, reading logic blocks and erase command all are working and getting HAL_OK status. 

-> We tried SDMMC clock with 500KHz to 45 MHz.

-> We are generated code from CubeMX(latest version) and running in CubeIDE (latest version)

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

for(int i=0;i<1024;i++)     { 

      eMMCWriteBuf[i] = 0x53; 

    } 

    StatusTx = HAL_MMC_Erase(&hmmc2,0x00,0x2000); / / erase 16 blocks 

    HAL_Delay (1000); 

   HAL_Delay (1000); 

   HAL_Delay (1000); 

    StatusTx = HAL_MMC_WriteBlocks(&hmmc2, eMMCWriteBuf, 12, 2, 0xFFFF);  

  HAL_Delay (1000); 

  HAL_Delay (1000); 

  while(1) 

  { 

  StatusRx = HAL_MMC_ReadBlocks(&hmmc2, eMMCReadBuf, 12, 2, 0xFFFF); 

  HAL_Delay (1000); 

  HAL_Delay (1000); 

  } 

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

can anyone help mw in this regards , it urgent.

thank you in advance

 

regards

srikanth

 

 

 

2 REPLIES 2

Arbitrary delays are just bad practice, you're supposed to pace by what the card/chip wants, not what's convenient for you.

errorState = HAL_MMC_WriteBlocks(&hmmc1, wData, blockAdd, numberOfBlocks, timeout);
while (HAL_MMC_GetCardState(&hmmc1) != HAL_MMC_CARD_TRANSFER) { // need timeout on this
HAL_Delay(1);
}

Be aware that SD/MMC has zero tolerance for you wandering off-task during data transfers, there is a FIFO, but it's not very deep, and if you call slow/blocking functions in interrupt handlers or callbacks, it's likely to fail.

Consider using DMA, it's more complicate on CM7 parts due to coherency issues, and expectations of buffer alignment, but ultimately worth it if speed is important / critical.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thank you for reply,

   We checked and got card status as HAL_MMC_CARD_TRANSFER. But after writing 64 bytes in FIFO getting SDMMC_FLAG_TXUNDERR bit is set. we checked with all speeds and got same error. 

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

for(int i=0;i<1024;i++)
{
eMMCWriteBuf[i] = 0x78;
}

StatusTx = HAL_MMC_Erase(&hmmc2,0x00,0x2000);

// check card status
while (HAL_MMC_GetCardState(&hmmc2) != HAL_MMC_CARD_TRANSFER) {
HAL_Delay(1);
}

StatusTx = HAL_MMC_WriteBlocks(&hmmc2, eMMCWriteBuf, 12, 2, 0xfff);

// check card status
while (HAL_MMC_GetCardState(&hmmc2) != HAL_MMC_CARD_TRANSFER) {
HAL_Delay(1);
}

while(1)
{
StatusRx = HAL_MMC_ReadBlocks(&hmmc2, eMMCReadBuf, 12, 2, 0xFFFF);

// check card status
while (HAL_MMC_GetCardState(&hmmc2) != HAL_MMC_CARD_TRANSFER) {
HAL_Delay(1);
}

}

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

After writing 64 bytes getting 0x00045010 in Status register after clearing SDMMC_FLAG_TXUNDERR  this bit 

getting 0x00045000 in Status register. But not getting HAL_MMC_CARD_TRANSFER this state after writing.

So, what was the issue and how to solve?