2025-01-02 5:03 AM - last edited on 2025-01-03 2:23 AM by mƎALLEm
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.
2025-05-09 4:05 AM
Hi @sivani
If still having the same issue, update latest version of CubeMX and Cube FW H7.
Changing features involves modifying the USB device descriptor. Each time we change the device descriptor, we may need to reinstall the USB device : uninstall the USB device from the Windows Device Manager and re-plug the USB cable. During this operation, the USB host keeps new information in its registry. Also, changing PID can solve such issue.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.