cancel
Showing results for 
Search instead for 
Did you mean: 

Hello guys, I am working with STM32G0C1RET6. I want to use STM32 as a USB host and want to save data on USB flash stick. I followed some tutorial from ST microcontroller's youtube channel but I am still not able to mount my USB device. what should I do?

jsoda.1
Associate III

Here are details about my project:

  • I have connected my USB_DM and USB_DP pin directly to USB connector.
  • I enable A9 and selected as a GPIO output using VBUS setting in CUBEIDE. Which is providing me 3.3V
  • I read that there is inbuilt pull up resistor in STM32G0C1RET6. So, I connected USB connector directly to pins
  • I used "f_mount" function to mount my usb device.

My USB device is using FAT32 format. I AM SORRY if I made some dumb mistake; I am newbie

12 REPLIES 12

@Community member​ @Javier Muñoz​ 

Sorry for bothering you guys again. I have tried to solve DISKIO error but everything is working fine. There are no errors. Can low heap size cause FR_DISK_ERR??

I am posting the code I wrote in "USB_host.c" and my settings which I am using:

0693W00000NpyZjQAJ.png0693W00000NpyZeQAJ.png0693W00000NpyZZQAZ.png

/* 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 */

>>Can low heap size cause FR_DISK_ERR??

Generally speaking GNU/GCC hides a lot of potential size issues with heap/stack

Some of the USB Driver Stack for devices used the heap.

FATFS can use the heap for things like long filenames, etc, check ff_conf.h

It can also use the stack for auto/local variables, I'd typical look for at least 1 or 2 KB

Suggest the following syntax for the output

uint8_t text[] = "USB not mounted !";

HAL_UART_Transmit(&huart3, text, sizeof(text)-1, 100); // or strlen(text)

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

Thank you so much, I have tried everything by fat but I am still not able to mount my USB device, I am using 32GB pendrive; Is that a problem?

I am still getting FR_DISK_ERR. Can you guys post your settings and code?? So I cam identify problem