Skip to main content
Explorer
May 11, 2022
Question

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

  • May 11, 2022
  • 3 replies
  • 2393 views

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

    This topic has been closed for replies.

    3 replies

    Graduate II
    May 11, 2022

    0693W00000NpnHjQAJ.pngIf your USB connection is as above, I recommend that you find the MX_DriverVbusFS function in the usbh_platform.c file and make its content compatible with your power switch IC.

    https://www.st.com/resource/en/application_note/dm00296349-usb-hardware-and-pcb-guidelines-using-stm32-mcus-stmicroelectronics.pdf

    jsoda.1Author
    Explorer
    May 12, 2022

    Hiii, thank you so much for suggestion. Is it necessary to set USB connection as you showed in image??

    I​ didn't make any connection like that. I just connected USB connector pin to STM32's A9 pin.

    Graduate II
    May 12, 2022

    A couple of times I accidentaly swapped USB DATA+ and DATA- Lines, double check you didnt do the same.

    https://www.youtube.com/watch?v=vwlXUOY7KY0&list=PLnMKNibPkDnFFRBVD206EfnnHhQZI4Hxa&index=7&ab_channel=STMicroelectronics

    Graduate II
    May 12, 2022

    Leave a link to the youtube tutorial youre trying to follow and maybe some pictures of your hardware

    jsoda.1Author
    Explorer
    May 12, 2022

    Hi, thank you so much for reply. No, I made sure that I don't interchange DP and DM lines. Both connections are correct..Here is link of the video I am following:

    https://www.youtube.com/watch?v=dC0d8CVEPrQ&list=PLnMKNibPkDnFFRBVD206EfnnHhQZI4Hxa&index=20

    Sorry but I can't get picture of hardware. Do I need to use "Current limiter power switch"??

    When I run program FRESULT shows FR_DISK_ERR. what does that mean?

    0693W00000NpqstQAB.png

    Graduate II
    May 12, 2022

    >>When I run program FRESULT shows FR_DISK_ERR. what does that mean?

    Means your DISKIO layer isn't working, fix that first.

    Graduate II
    May 12, 2022

    You can use STMPS2141 as switch. I also recommend adding a protection element such as USBLC6-2SC6 to the USB data line.​

    jsoda.1Author
    Explorer
    May 15, 2022

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

    Graduate II
    May 16, 2022

    >>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)