cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 and eMMC memory - EXT_CSD register access

MOndr.1
Associate

Hello, I am a little advanced STM32 user, but I quite struggle with eMMC memory and STM32F7 (on custom board with STM32F756I and Samsung's 32GB eMMC KLMB2G2JENB-041 in the 8-bit MMC interface). Optionally I can solder STM32H753I which is pin-to-pin compatible.

I read many documents (including the JEDEC specs) on the topic but still can't get it to work. I use the CubeIDE generated init code. I slowly stepped into these init methods and there is everything fine, all the initialization steps return OK qnd after it, I can read card info, CSD and CID.

I need to read (and update some data in) the EXT_CSD register (512B data block) and there it is. I wrote this code snippet, which however returns none data:

 SDMMC_CmdInitTypeDef cmd;
 HAL_StatusTypeDef ret1 = HAL_OK;
 uint8_t buf_local[512];
 memset(buf_local, 0, 512);
  
 cmd.CmdIndex = SDMMC_CMD_HS_SEND_EXT_CSD;
 cmd.Argument = 0;
 cmd.Response = SDMMC_RESPONSE_SHORT;
 cmd.WaitForInterrupt = SDMMC_WAIT_NO;
 cmd.CPSM = SDMMC_CPSM_ENABLE;
 ret1 = SDMMC_SendCommand(hmmc1.Instance, &cmd);
 
 uint16_t count = 512;
 while ((__HAL_MMC_GET_FLAG(&hmmc1, SDMMC_FLAG_RXDAVL) && (count)))
 {
	 buf_local[512-count] = SDMMC_ReadFIFO(hmmc1.Instance);
	 count--;
 }

I tested this code with 16GB SD(HC) card on the STM32F769I_DISCOVERY and it reads 28 Bytes of data from the card. I am not quite familiar with the SD JEDEC specs so I don't know if this is correct, but I know that I must read 512 Bytes from the eMMC chip on the custom board (which does not happen)

Unfortunately, there are no test points on the custom board, but the complete init process finishes OK and the CID/CSD data is completely correct so I assume there is no problem with wiring. I tried with multiple CLK speeds, 48MHz with many divider options, still no success.

If someone has an idea how to initialize the eMMC to use, please help. I only need the blocks operations, not all the eMMC 5.1 special features.

Thank you!

I'd appreciate any help, Martin

2 REPLIES 2
TDK
Guru

> while ((__HAL_MMC_GET_FLAG(&hmmc1, SDMMC_FLAG_RXDAVL) && (count)))

This loop will terminate unconditionally if data is not available. Data transfer isn't instant, so it is terminating prematurely.

If you feel a post has answered your question, please click "Accept as Solution".

Thanks for the reply. OK, I tried adding a simple timeout loop right in front of the reception while:

  uint32_t delay = 500000;
  while (delay)
  {
	  if (__HAL_MMC_GET_FLAG(&hmmc1, SDMMC_FLAG_RXDAVL)) break;
	  delay--;
  }

No success, even with this ridiculous timeout. The break never occurs (variable delay is zero) and no data are received afterwards.