cancel
Showing results for 
Search instead for 
Did you mean: 

USB Disk with CubeMX and STM32F4-Discovery

evenlund
Associate III
Posted on October 04, 2016 at 22:01

I have been struggling to set up CubeMX to be able to read and write to a USB memory stick for STM32F4-Discovery board, similarly to what is done in the example from the repository (Repository\STM32Cube_FW_F4_V1.13.0\Projects\STM32F4-Discovery\Applications\FatFs\FatFs_USBDisk). This example from ST is working perfectly.

My setup procedure is as follows:

  • Set RCC to High Speed Clock (HSE) with Crystal/Ceramic resonator
  • Change the clock configuration to HSE, M=4,N=x168,P=2, Q=7, so that PLL clock is 48 MHz
  • Set USB_OTG_FS to Host_Only with Activate_VBUS
  • Set USB_Host to Mass Storage Host Class
  • Set FATFS to USB Disc
  • Set USB_Host configuration, Platform settings MSC_FS, Drive_VBUS_FS to GPIO:Output through PC0.

After generating the code I &sharpinclude the fatfs.h in usb_host.c in order to be able to use the functions defined, similarly to what is done in main.c for the original example. Next the private variables (FATFS USBDISKFatFs etc) and the ''MSC_Application'' function is added to the code. I call this function in USBH_UserProcess for the case HOST_USER_CONNECTION. Last I add the red LED to be activated in USB_Error_Handler.

What am I doing wrong? Am I missing any additional settings or code? Please help, as I would like to base most of my upcoming work on the use of CubeMX.

#!cubemx #!usb-msc #!stm32f4discovery
1 ACCEPTED SOLUTION

Accepted Solutions
evenlund
Associate III
Posted on October 13, 2016 at 09:23

I finally figured out how to set up the USB for STM32F4 Discovery in CubeMX for reading and writing to a memory stick. I made a

http://evenlund.blogspot.no/2016/10/usb-storage-with-stm32f4-discovery-and_58.html

if anyone else would be interested to know.

My only challenge now is to be able to call the reading and writing operations originally called from usb_host.c on demand from main.c. CubeMX is calling MX_USB_Host_Process() in the main while loop, and I guess if I fill up a global variable wtext and only call MX_USB_Host_Process() when this is ready I will be able to achieve this. Are there any more elegant ways to do this?

View solution in original post

4 REPLIES 4
Amel NASRI
ST Employee
Posted on October 10, 2016 at 18:04

Hi Even,

Could you please share more details regarding the issue you are facing after generating the Cube_MX project and updating it? When debugging, where are you struggling compared to the Cube example?

-Mayla- 

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.

Nor Sch
Associate III
Posted on October 11, 2016 at 12:32

I'm not sure, how the Code for the F4 is generated. But for the L4 the Implementation in the sd_diskio.c is a ''fill-in-the-blank text''. You have to copy /adjust this File from the Examples ...

evenlund
Associate III
Posted on October 13, 2016 at 09:23

I finally figured out how to set up the USB for STM32F4 Discovery in CubeMX for reading and writing to a memory stick. I made a

http://evenlund.blogspot.no/2016/10/usb-storage-with-stm32f4-discovery-and_58.html

if anyone else would be interested to know.

My only challenge now is to be able to call the reading and writing operations originally called from usb_host.c on demand from main.c. CubeMX is calling MX_USB_Host_Process() in the main while loop, and I guess if I fill up a global variable wtext and only call MX_USB_Host_Process() when this is ready I will be able to achieve this. Are there any more elegant ways to do this?

Nor Sch
Associate III
Posted on October 17, 2016 at 09:11

I took a short look over your Blogpost and what I have seen is not the Code for a USB MassStorageDevice. You have only implemented the FatFS-Demo-Code. Somehow you do not have the needed FATFS_LinkDriver() called (or it's somewhere else?), but you do the unlink at the End. I think this works only by Chance.

Anyway, for the USB MSD you have to look into your sd_diskio.c as I wrote above ...