STm32F205RBt6 as USB Host, interfacing code for pen drive

Discussion in 'Embedded Systems and Microcontrollers' started by Vindhyachal Takniki, Dec 7, 2017.

  1. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    419
    14
    1. Need to interface pen drive with stm32f205rbt6 for logging data in text file in pen drive.

    2. Generated code from stm32cube & link for total code is here: https://drive.google.com/open?id=1oJSXOmWXzn_xduLmcJWXdiNxtMTpdmtP

    3. Made changes in fatfs.c file generated as below.

    4. Problem is code always struk in if(FR_OK != res) & return disk_error always. What error I am doing.

    5. is there any example code for STM32F2 using pen drive for storage purpose to see exactly where changes are to be made.



    Code (Text):
    1. #include "fatfs.h"
    2.  
    3. uint8_t retUSBH;    /* Return value for USBH */
    4. char USBHPath[4];   /* USBH logical drive path */
    5. FATFS USBHFatFS;    /* File system object for USBH logical drive */
    6. FIL USBHFile;       /* File object for USBH */
    7. FRESULT res;
    8.  
    9. /* USER CODE BEGIN Variables */
    10.  
    11. /* USER CODE END Variables */  
    12.  
    13. void MX_FATFS_Init(void)
    14. {
    15.   /*## FatFS: Link the USBH driver ###########################*/
    16.   retUSBH = FATFS_LinkDriver(&USBH_Driver, USBHPath);
    17.  
    18.   /* USER CODE BEGIN Init */
    19.   /* additional user code for init */    
    20.   /* USER CODE END Init */
    21.    
    22.     res = f_mount(&USBHFatFS , USBHPath ,0U);
    23.     if(FR_OK != res)
    24.     {
    25.             while(1);
    26.     }
    27.        
    28.     res = f_setlabel("DATA DISK");
    29.     if(FR_OK != res)
    30.     {
    31.             while(1);
    32.     }            
    33.        
    34.     res = f_open(&USBHFile, "/_SERIAL.txt", FA_OPEN_ALWAYS);
    35.     if(FR_OK != res)
    36.     {
    37.         while(1);              
    38.     }  
    39.    
    40. }
    41.  
    42. /**
    43.   * @brief  Gets Time from RTC
    44.   * @param  None
    45.   * @retval Time in DWORD
    46.   */
    47. DWORD get_fattime(void)
    48. {
    49.   /* USER CODE BEGIN get_fattime */
    50.   return 0;
    51.   /* USER CODE END get_fattime */
    52. }
     
Loading...