cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743VI USB mass storage device and uSD card

RPuccio
Visitor

Hello everyone, and thank you in advance for chiming in on this topic !

 

I'm having trouble getting an STM32H743VI pass a 32GB uSD-Card to my computer through USB_OTG_FS. Please consider me a noob at embedded system.

I'm following Phil's Lab video (https://www.youtube.com/watch?v=aEwwQMdKd-c) which uses the same family of microcontrollers and manages to get his SD card recognized by his computer, with write and read working. I'm following the same steps, but when I connect the board to my computer, no available space is shown and double clicking on the listed USB device prompt me to format it (even though trying to format it doesn't work that way).

The project I'm working need wave file transfer between a computer and the STM32 so that the STM can read it later on and use them for real-time audio processing. In order to achieve that, I have enabled FatFS, SDMMC1, USB_OTG_FS and USB_DEVICE. I already have some code running the real-time audio processing part, but I disabled it just for testing.

I've used some default FatFS examples to try to write to the SD card and can confirm that I've been able to format it and write some text files that can properly be read on my computer. It leads me to believe that the STM32 and the uSD connection is working, so hardware should be alright.

IDE version : 1.18.1
STM32H7 firmware version : 1.12.1

As per the video, I've added a couple lines to the usbd_storage_if.c file :

#define SD_CARD_TIMEOUT_MS 5000
extern SD_HandleTypeDef hsd1;

And modified the STORAGE_GetCapacity_FS function :

int8_t STORAGE_GetCapacity_FS(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
{
  /* USER CODE BEGIN 3 */
  HAL_SD_CardInfoTypeDef sdInfo;
  if(HAL_SD_GetCardInfo(&hsd1, &sdInfo) != HAL_OK){
    return (USBD_FAIL);
  }
  *block_num = sdInfo.LogBlockNbr - 1;
  *block_size = sdInfo.LogBlockSize;
  return (USBD_OK);
  /* USER CODE END 3 */
}

 

Read and Write functions have also been modified to match what's written in the video, but just going through debug and adding a breakpoint on the line "return (USBD_OK);" is enough to see that the HAL_SD_GetCardInfo gets properly triggered, but *block_num = -1 and *block_size = 0.

Clock configuration seems ok to me, I've tried the same settings as in the video and the ones attached in the files below and the issue remains. Please note that I am using HSI instead of an external oscillator. Here are the other important info not shown in the screenshots :

SDMMC1 :
- Tried either Very High and Low output speed with no luck.
- Global interrupt are enabled.

SDMMC1.png

USB_OTG_FS :
- All interrupts enabled

USB_OTG_FS.png

USB_DEVICE :
- Device descriptor has not been changed

USB_DEVICE.png

FatFS :
- SD card is the only option checked
- "Set Defines" is left at default values
- "Use dma template" is Enabled
- "Platform settings" Detect_SDIO pin is properly set, with voltage measuring 3.3V (pull-up) without SD card and 0V with the SD card inserted.

I'm not sure where to look, as it seems the STM32 can talk both to the computer (otherwise it wouldn't been displayed as a USB mass storage device) and to the SD card (or I wouldn't be able to write on it at all with the FatFS basic example). I feel like something is wrong and that the STM32 can't get the proper values for the block_num and block_size parameters.

I'm sure I'm missing some point here, and I've never went so deep in embedded systems before so bare with my *** questions. At this point, any help is appreciated !

Thanks in advance,
Best regards,
Rodolphe

 

0 REPLIES 0