cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f407VG SD card and USB Mass Storage using stmcubemx version 4.21.0

ESami
Associate II

Hi Guys,

I want to see the content of my SD card in pc using USB mass storage. I implement my project using stmcubemx version 4.21.0. The SD card works meaning that I can create a .txt file and write something into it. When I put the SD card into adapter and connect to PC, I can also see its contents, as expected.

However, i can not see its contents using USB mass storage! In usbd_storage_if.c file, there is a STORAGE_READ_FS function to read SD card contents using USB. SInce it is originally empty, I modify it as follows:

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(&hsd, buf, blk_addr, blk_len, 10);

HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);  //Orange LED);  

 return (USBD_OK);

However, it doesn't work! Moreover, I cannot watch buf, blk_addr, blk_len in live watch to see what such arguments contain!

It really blocks me for a while! Do you guys face such issue? or have any suggestions ?

Infinite thanks in advance!

Cheers

Edmond

2 REPLIES 2

Perhaps look at the MSC examples under the F4 HAL tree in the repository.

Check the units for the parameters, check ST isn't using byte address rather the block addresses and count.

Check the timeout is realistic.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks Clive for your comment,

Couldn't find similar example(s) for STM32f407vgt! There are some examples for other discovery boards which have an integrated SD slot! For others, I found "FatFs_USBDisk" but it is used in host not device mass storage.

However, I just see this post: https://community.st.com/s/question/0D50X00009XkWt5SAF/solution-to-fix-stm32f4xxx-stmcubemx-firmware-v118-sdio-fatfs-dma-not-working-issue

I am using stmcubemx version 4.21.0. Do you think such a problem has been already solved in this version or it is good to try with another version? If so, which version you suggest?