cancel
Showing results for 
Search instead for 
Did you mean: 

STM32h745i-DISCO USB with MMC windows was unable to complete the format

sivani
Associate

Hi, 

We are working on MMC with USB on the STM32H745I-Disco board but are unable to format the disk. 

using STM32CubeIDE version is  1.16.1

System Clock Configuration

  • HSE Clock Source
    • CM7 Core: 400 MHz
    • CM4 Core: 200 MHz
  • USB Frequency
    • RC48 Clock: 48 MHz

SDMMC CLK

sivani_1-1735819714232.png

 

RCC

sivani_0-1735819631276.png

SDMMC 

sivani_2-1735819814038.png  

sivani_3-1735819843558.png 

sivani_4-1735819869605.png

 

USB_OTG_FS configuration

sivani_5-1735819920330.png

in middle firmware

sivani_6-1735819984456.png

All these configurations were applied in the CM7 core.

And the location D:\ Mass_storage\CM7\USB_DEVICE\App\usbd_storage_if.c  we added  below function

 

int8_t STORAGE_GetCapacity_FS(uint8_t lun, uint32_t *block_num, uint16_t *block_size)

{

  /* USER CODE BEGIN 3 */

//  UNUSED(lun);

//  *block_num  = STORAGE_BLK_NBR;

//  *block_size = STORAGE_BLK_SIZ;

                  HAL_MMC_CardInfoTypeDef hmmcInfo;

                  if(HAL_MMC_GetCardInfo(&hmmc1, &hmmcInfo) != HAL_OK)

                  {  return (USBD_FAIL);

                  }

                  *block_num  = hmmcInfo.LogBlockNbr - 1;

                  *block_size = hmmcInfo.LogBlockSize;

                  return (USBD_OK);

  /* USER CODE END 3 */                          

    } 

 

When we attempt to format the disk from the host system (e.g., Windows), the operation fails with an error

sivani_7-1735820127174.png

 

sivani_8-1735820204618.png 

 

After that in same location .c  file  we added read and write function

 

int8_t STORAGE_Read_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)

{

  /* USER CODE BEGIN 6 */

 // UNUSED(lun);

 // UNUSED(buf);

//  UNUSED(blk_addr);

//  UNUSED(blk_len);

                if(HAL_MMC_ReadBlocks(&hmmc1, buf, blk_addr, blk_len, HAL_MAX_DELAY) != HAL_OK)

                {

                                return (USBD_FAIL);

//            }

                uint32_t timestart = 100000;

                while ((HAL_MMC_GetCardState(&hmmc1) != HAL_MMC_CARD_TRANSFER))

                {

                                if ((HAL_GetTick() - timestart) >=  SDMMC_DATATIMEOUT)

                                    {

                                      return (USBD_FAIL);

                                    }

                }

return (USBD_OK);

  /* USER CODE END 6 */

}

int8_t STORAGE_Write_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)

{

  /* USER CODE BEGIN 7 */

  //UNUSED(lun);

  //UNUSED(buf);

 // UNUSED(blk_addr);

  //UNUSED(blk_len);

                if(HAL_MMC_WriteBlocks(&hmmc1, buf, blk_addr, blk_len, HAL_MAX_DELAY) != HAL_OK)

                {

                                return (USBD_FAIL);

                }

                uint32_t timestart = 100000;

                while ((HAL_MMC_GetCardState(&hmmc1) != HAL_MMC_CARD_TRANSFER))

                {

                                if ((HAL_GetTick() - timestart) >=  SDMMC_DATATIMEOUT)

                                    {

                                      return (USBD_FAIL);

                                    }

                }

return (USBD_OK);

  /* USER CODE END 7 */

} 

 

If we added these two function the disk not showing the PC we are getting like this

sivani_9-1735822863667.png

 

Please provide a solution for this issue. I have also attached the relevant firmware configurations for reference.

0 REPLIES 0