AnsweredAssumed Answered

STM32F4-Disco USB MSC HOST

Question asked by Majerle.Tilen on Aug 5, 2014
Latest reply on Jan 12, 2017 by Imen D
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:

01./* Init Host Library */
02.USBH_Init(  &USB_OTG_Core,
03.        #ifdef USE_USB_OTG_FS
04.            USB_OTG_FS_CORE_ID,
05.        #else
06.            USB_OTG_HS_CORE_ID,
07.        #endif
08.            &USB_Host,
09.            &USBH_MSC_cb,
10.            &USR_Callbacks);
11. 
12.while (1) {
13.    /* Host Task handler */
14.    USBH_Process(&USB_OTG_Core, &USB_Host);
     /* Device connected ? */
15.    if (HCD_IsDeviceConnected(&USB_OTG_Core)) {
16.        //USBH_deviceOk = 0;
17.        TM_DISCO_LedOff(LED_RED);
18.        if (i > 0xFF) {
19.            /* Turn off LED */
20.            TM_DISCO_LedOff(LED_GREEN);
21.        }
22.        /* Some counter */
23.        if (i > 0x7FFFF/* && write*/) {
24.            i = 0;
25.            /* Try to mount */
26.            if (f_mount(&fs, "", 1) == FR_OK) {
27.            //if (f_mount(0, &fs) == FR_OK) {
28.                err = f_open(&fil, "test_file.txt", FA_READ | FA_WRITE | FA_OPEN_ALWAYS);
29.                 
30.                if (err == FR_OK) {
31.                    /* Append file */
32.                    f_lseek(&fil, f_size(&fil));
33.                    /* Put data */
34.                    f_puts("test string\n", &fil);
35.                     
36.                    TM_DISCO_LedOn(LED_GREEN);
37.                } else {
38.                    sprintf(str, "Error code: %d\n", err);
39.                    TM_USART_Puts(USART6, str);
40.                    TM_DISCO_LedOff(LED_GREEN);
41.                }
42.                if (write == 1) {
43.                    // Get volume information and free clusters of drive
44.                    err = f_getfree("0:", &fre_clust, &fss);
45.                    if (err == FR_OK) {
46.                        // Get total sectors and free sectors
47.                        total = (fs.n_fatent - 2) * fs.csize / 2;
48.                        free = fre_clust * fs.csize / 2;
49.                         
50.                        sprintf(str, "----------\nTOTAL: %d\nFREE:  %d\n----------\n", total, free);
51.                        TM_USART_Puts(USART6, str);
52.                         
53.                        write = 0;
54.                    }
55.                }
56.                /* Close file */
57.                f_close(&fil);
58.            }
59.            /* Unmount */
60.            f_mount(0, "", 1);
61.            //f_mount(0, 0);
62.        } else {
63.        }
64.        i++;
65.    } else {
66.        /* Not inserted, turn on RED */
67.        TM_DISCO_LedOn(LED_RED);
68.        TM_DISCO_LedOff(LED_GREEN);
69.        
70.        write = 1;
71.    }
72.}

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?

Outcomes