cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX USB Mass Storage template

iw2lsi
Associate III

Hi all,

I'm trying to set-up a simple USB read/write on our STM32F746G-Disco board using the FullSpeed OTG... but so far it seems that the code generated by CubeMX does not really work...

If I'm not wrong, CubeMX in case of USB MSD enable the DMA template by default, but then it does not copy the usbh_diskio_dma.c and usbh_diskio_dma.h in the project folder.

After disabling the DMA, I can now detect when an USB key is attached and I can see that it is enumerated, but then It fails to open any file after the f_mount() with the error "FR_NOT_ENABLED".

It seems that I'm having the same issue described in: http://www.openstm32.org/forumthread3205

Below is a small log.

Best Regards,

Giampaolo

-----------

System initialized

StartDefaultTask

APPLICATION_START

FatFs initialized!

USB Device Attached

PID: 5571h

VID: 781h

Address (#1) assigned.

Manufacturer : SanDisk

Product : Cruzer Fit

Serial Number : 4C530001010701111474

Enumeration done.

This device has only 1 configuration.

Default configuration set.

Switching to Interface (#0)

Class  : 8h

SubClass : 6h

Protocol : 50h

MSC class started.

APPLICATION_READY

opening file...

Cannot Open 'USBHost.txt' file: FR_NOT_INITIALIZED

3 REPLIES 3
iw2lsi
Associate III

...by the way... we are using STM32CubeMX + Atollic

Did you use delayed initialization with f_mount (at the top of your app, maybe where you reported FatFs initialized!), or forced mount after the USB device was enumerated?

iw2lsi
Associate III

Hello Dave,

I've done various test with both initialization modes (delayed and immediate) but with the same results... but...

yesterday finally I've found the problem and, hopefully, a solution:

In the file usbh_msc.c, the function USBH_MSC_ClassRequest() is calling USBH_MSC_BOT_REQ_GetMaxLUN()... which in my case it was stuck returning USBH_BUSY status.

By changing a single line as suggested here:

https://community.st.com/s/question/0D50X00009q3WzFSAU/usb-host-library-msc-usbhmscbotreqgetmaxlun-no-response

i.e. by changing this line as shown:

if((status == USBH_NOT_SUPPORTED) || (status == USBH_BUSY))

everything is now working as expected, both on a very old 512MB Apacher and on two new 16/32GB SanDisk USB mass storage pen-drive.

thanks for the help,

Giampaolo