cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L433RCTx USB MSC Read/write failure, GetCapacityFS working

PGrun.1
Associate

Hello, i would like to build a SD Card Reader from my STM32L433RCTx. The SD Card is connected via SDMMC 1 SD 4 bits Wide bus. The USB_DEVICE is activated and set to Mass Sorage Class.

When i connect to the computer a Storage device is shown but windows wants to format it. It is however not able to format the card. It shows the correct size of the SD Card. My most important functions are:

int8_t STORAGE_GetCapacity_FS(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
{
  /* USER CODE BEGIN 3 */
  HAL_SD_GetCardInfo(&hsd1, &SDCardInfo);
  *block_size = BLOCK_SIZE;
  *block_num = SDCardInfo.BlockNbr;
  return (USBD_OK);
  /* USER CODE END 3 */
}

I suppose this one is working properly, as the Size of the SD Card is correct.

But Read and Write does not work.

int8_t STORAGE_Read_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
{
  /* USER CODE BEGIN 6 */
    HAL_SD_ReadBlocks(&hsd1, buf, blk_addr, (uint32_t) blk_len, 10);
    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 */
HAL_SD_WriteBlocks(&hsd1, buf, blk_addr, (uint32_t) blk_len, 10);
return (USBD_OK);
  /* USER CODE END 7 */
}

Questions:

  1. Is it possible to make this work without using FATFS or do i need to first connect the SD Card with FATFS to the MCU and then pass this information within the USB Driver?
  2. What are the right read and write functions?

Thank you very much!

0 REPLIES 0