2016-04-19 09:00 AM
Hi,
I'm using an STm32F107 and I trie to configure the USB interface as host to access to an key.
This is the initialization code :
MX_USB_HOST_Init();
MX_FATFS_Init();
with :
void MX_USB_HOST_Init(void)
{
/* Init Host Library,Add Supported Class and Start the library*/
USBH_Init(&hUsbHostFS, USBH_UserProcess, HOST_FS);
USBH_RegisterClass(&hUsbHostFS, USBH_MSC_CLASS);
USBH_Start(&hUsbHostFS);
}
and :
void MX_FATFS_Init(void)
{
/*## FatFS: Link the USBH driver ###########################*/
retUSBH = FATFS_LinkDriver(&USBH_Driver, USBH_Path);
/* USER CODE BEGIN Init */
/* additional user code for init */
if (retUSBH == 0)
{
HAL_GPIO_WritePin(GPIOD, LED1_Pin, GPIO_PIN_SET);//Succes
}
else
{
HAL_GPIO_WritePin(GPIOD, LED3_Pin, GPIO_PIN_SET);//Error
}
/* USER CODE END Init */
}
After execute, the led1 is on.
A try to access to
/* Register the file system object to the FatFs module */
if (f_mount(&USBH_fatfs, '''', 0) != FR_OK)
{
/* ERROR : Cannot Initialize FatFs. */
...
}
This call to function ''
f_mount()''
always returns FR_OK but after :while (1)
{
/* USER CODE END WHILE */
MX_USB_HOST_Process();
/* USER CODE BEGIN 3 */
HAL_Delay(500);
res = f_open(&MyFile, ''0:USBHost.txt'', FA_CREATE_ALWAYS | FA_WRITE);
if (res != FR_OK)
{
// Error
// ...
}
...
}
Here, the function ''
f_open()''
never returnsFR_OK.
Is there someone who can give me some explanation of this behaviour ? Thank you very much. Bernard. #stm32-usb-otg-msc2016-04-19 09:59 AM
What result code does it return? That might provide additional insight into where things are failing.
If it is with the diskio layer, you might want to instrument that to see where it fails.2016-04-21 10:01 AM
Hi Clive, thank you for your response.
Thefunction ''
f_open()'' always
returns
FR_DISK_ERR.
I've observed that this happens because the USB host handle takes the following states :gstate : HOST_IDLE, HOST_DEV_ATTACHED and then HOST_ENUMERATIONEnumState : ENUM_IDLERequestState : CMD_IDLE, CMD_SEND and then CMD_WAITwith/* USB Host handle structure */typedef struct _USBH_HandleTypeDef{ __IO HOST_StateTypeDef gState; /* Host State Machine Value */ ENUM_StateTypeDef EnumState; /* Enumeration state Machine */ CMD_StateTypeDef RequestState; USBH_CtrlTypeDef Control; USBH_DeviceTypeDef device; USBH_ClassTypeDef* pClass[USBH_MAX_NUM_SUPPORTED_CLASS]; USBH_ClassTypeDef* pActiveClass; uint32_t ClassNumber; uint32_t Pipes[15]; __IO uint32_t Timer; uint8_t id; void* pData; void (* pUser )(struct _USBH_HandleTypeDef *pHandle, uint8_t id); #if (USBH_USE_OS == 1) osMessageQId os_event; osThreadId thread; #endif } USBH_HandleTypeDef;I guess there is something missing in the initialization phase, but I cannot find what !Do you have a track ?Thank you for yor help.Bernard.2016-07-29 01:38 AM
Looks like you are trying to use MSC + FatFs locally at the same time.
I found this thread while trying (and failing) to do the same.After some researches I found this:http://stackoverflow.com/questions/19974503/fatfs-on-st32-with-device-configured-as-usb-driveIt seems it is impossible to achive that..2016-07-29 07:39 AM
Looks like you are trying to use MSC + FatFs locally at the same time.
The OP is *HOSTING*, ie user plugs Flash Drive into STM32, which then accesses it.It seems it is impossible to achieve that..The coherency issues are intractable for a PC and STM32 to be able to access the same media together.