2025-01-02 05:03 AM - last edited on 2025-01-03 02:23 AM by SofLit
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
SDMMC CLK
RCC
SDMMC
USB_OTG_FS configuration
in middle firmware
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
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
Please provide a solution for this issue. I have also attached the relevant firmware configurations for reference.