Skip to main content
tm3341
Associate III
August 5, 2014
Question

STM32F4-Disco USB MSC HOST

  • August 5, 2014
  • 2 replies
  • 895 views
Posted on August 05, 2014 at 18:51

Hello everyone.

I have a strange problem. Downloaded USB-Host-Device v2.1.0 library. I then started an example, set correct pinout for VBUS on F4-Discovery (PC0). USB MSC host works in FS mode. Everything is the same as in example, just FatFS by Chan is version 0.10b and pins are different. Then my example going like that:


/* Init Host Library */

USBH_Init( &USB_OTG_Core,

#ifdef USE_USB_OTG_FS

USB_OTG_FS_CORE_ID,

#else

USB_OTG_HS_CORE_ID,

#endif

&USB_Host,

&USBH_MSC_cb, 

&USR_Callbacks);


while
(1) {

/* Host Task handler */

USBH_Process(&USB_OTG_Core, &USB_Host);
 /* Device connected ? */

if
(HCD_IsDeviceConnected(&USB_OTG_Core)) {

//USBH_deviceOk = 0;

TM_DISCO_LedOff(LED_RED);

if
(i > 0xFF) {

/* Turn off LED */

TM_DISCO_LedOff(LED_GREEN);

}

/* Some counter */

if
(i > 0x7FFFF
/* && write*/
) {

i = 0;

/* Try to mount */

if
(f_mount(&fs, 
''''
, 1) == FR_OK) {

//if (f_mount(0, &fs) == FR_OK) {

err = f_open(&fil, 
''test_file.txt''
, FA_READ | FA_WRITE | FA_OPEN_ALWAYS);


if
(err == FR_OK) {

/* Append file */

f_lseek(&fil, f_size(&fil));

/* Put data */

f_puts(
''test string\n''
, &fil);


TM_DISCO_LedOn(LED_GREEN);

} 
else
{

sprintf(str, 
''Error code: %d\n''
, err);

TM_USART_Puts(USART6, str);

TM_DISCO_LedOff(LED_GREEN);

}

if
(write == 1) {

// Get volume information and free clusters of drive

err = f_getfree(
''0:''
, &fre_clust, &fss);

if
(err == FR_OK) {

// Get total sectors and free sectors

total = (fs.n_fatent - 2) * fs.csize / 2;

free = fre_clust * fs.csize / 2;


sprintf(str, 
''----------\nTOTAL: %d\nFREE: %d\n----------\n''
, total, free);

TM_USART_Puts(USART6, str);


write = 0;

}

}

/* Close file */

f_close(&fil);

}

/* Unmount */

f_mount(0, 
''''
, 1);

//f_mount(0, 0);

} 
else
{

}

i++;

} 
else
{

/* Not inserted, turn on RED */

TM_DISCO_LedOn(LED_RED);

TM_DISCO_LedOff(LED_GREEN);


write = 1;

} 

}

The problem is, that every USB stick is detected as inserted, but from my USBs the results are like that: USB 1: works always USB 2: works always USB 3: works only first write, then stop USB 4: sometimes recognized but could not open and mount. USB 4: sometime not recognized USB 4: sometimes recognized and worked I realize, that problem is in disk_read and disk_write of fatfs, because BUSY flag on read never stop. Do you know why is that?
    This topic has been closed for replies.

    2 replies

    daynial
    Associate II
    January 11, 2017
    Posted on January 11, 2017 at 10:58

    Can you please send me the complete project ? or send me the link 

    ST Technical Moderator
    January 12, 2017
    Posted on January 12, 2017 at 10:40

    Hi

    khan.daynial

    ,

    This is a very old thread. It should be better to start a new discussion for new request even if the topic is the same.This will be more easy for user forum to help/answer you.

    So, I invite user forum to putting responses in your proper

    https://community.st.com/0D50X00009XkfMvSAJ

    .

    Thanks

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks