Question
STM32F4-Disco USB MSC HOST
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?