cancel
Showing results for 
Search instead for 
Did you mean: 

How to use STM32 as a USB host and mount USB device??

jsoda.1
Associate III
/* USER CODE END Header */
 
/* Includes ------------------------------------------------------------------*/
 
#include "usb_host.h"
#include "usbh_core.h"
#include "usbh_msc.h"
 
/* USER CODE BEGIN Includes */
#include "ff.h"
/* USER CODE END Includes */
 
/* USER CODE BEGIN PV */
/* Private variables ----------------------------
 * -----------------------------*/
FATFS USBH_fatfs;
FIL MyFile;
FRESULT res;
uint8_t oktext = "USB mounted !";
uint8_t text = "USB not mounted !";
extern char USBHpath[];
extern UART_HandleTypeDef huart3;
/* USER CODE END PV */
 
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
 
/* USER CODE END PFP */
 
/* USB Host core handle declaration */
USBH_HandleTypeDef hUsbHostFS;
ApplicationTypeDef Appli_state = APPLICATION_IDLE;
 
/*
 * -- Insert your variables declaration here --
 */
/* USER CODE BEGIN 0 */
void UserPr(void)
{
    if(f_mount(&USBH_fatfs, USBHpath, 1) != FR_OK)
    {
    	HAL_UART_Transmit(&huart3, text, sizeof(text), 100);
    }
    else
    {
    	HAL_UART_Transmit(&huart3, oktext, sizeof(oktext), 100);
    }
}
/* USER CODE END 0 */

Hii there, I am using STM32g0c1 and I am trying to mount USB pendrive. I followed some online tutorials but still I am not able to mount USB pendrive.

  • I am using 32Gb pendrive using FAT32 format.
  • Heap size is 2000.
  • I connected DP and DM pins directly to USB A type connector.
  • DISKIO.C file looks fine.

When I try to mount USB device it shows FR_DISK_ERR. Also, when I use f_mkfs it shows FR_NOT_ENABLED.

Can I get example code/project ?? It will be a good help.

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @jsoda.1​ 

You can refer to the following example provided under the G0 Firmware Package:

  • Path: Projects\STM32G0C1E-EV\Applications\USB_Host\MSC_Standalone

I hope this helps.

BeST Regards,

Walid

View solution in original post

2 REPLIES 2
KnarfB
Principal III

Hello @jsoda.1​ 

You can refer to the following example provided under the G0 Firmware Package:

  • Path: Projects\STM32G0C1E-EV\Applications\USB_Host\MSC_Standalone

I hope this helps.

BeST Regards,

Walid