Question
USB library stalls while waiting for response
Posted on July 21, 2014 at 20:25
Hello,
I'm currently working with an STM32F215 mcu and I'm attempting to write a test program with the USB-Host-Device Library V.2.1.0. The goal of this test project is to program the STM32F215 as a host controller, and when an MSC USB Device is connected, download the contents and transmit over UART. Inside usbh_usr.c I have written the following code:
int
USBH_USR_MSC_Application(
void
)
{
switch
(msc_state)
{
case
MSC_INIT:
{
printf
(
''Starting download...\r\n''
);
msc_state = MSC_READ;
}
break
;
case
MSC_IDLE:
{
}
break
;
case
MSC_READ:
{
uint32_t sectors_read = 0;
uint8_t buffer[64];
/* Download every available sector */
if
(sectors_read < USBH_MSC_Param.MSCapacity)
{
/* Check if there's enough room in uart buffer */
if
(dl_uart_count() < (BUFFER_SIZE - 64))
{
uint8_t status = USBH_MSC_OK;
/* Queue read command */
status = USBH_MSC_Read10(&USB_OTG_Core,
buffer,
sectors_read,
64);
if
(status == USBH_MSC_OK)
{
printf
(
''Downloaded sector %lu of %lu\r\n''
, sectors_read, USBH_MSC_Param.MSCapacity);
/* Write data to usart */
dl_uart_write(buffer, 64);
/* Set next sector to be read */
sectors_read++;
}
else
if
(status == USBH_MSC_FAIL || status == USBH_MSC_PHASE_ERROR)
{
msc_state = MSC_ERROR;
}
}
}
else
{
printf
(
''Download complete\r\n''
);
msc_state = MSC_IDLE;
}
}
break
;
case
MSC_WRITE:
break
;
case
MSC_ERROR:
printf
(
''Error detected\r\n''
);
msc_state = MSC_IDLE;
break
;
default
:
break
;
}
return
(0);
}
The trouble is, the download never starts, and USBH_MSC_Read10 repeatedly returns USBH_MSC_BUSY. Based on my debugger, it seems like the parameter USBH_MSC_BOTXferParam.CmdStateMachine is constantly stuck at CMD_WAIT_STATUS. I've been reading the documentation as well as digging into the usb 2.0 specification document, but neither seem to be helping much. Is there a delay I need to put in after I queue up the read command? Or an additional command? I've checked the examples and they don't seem to help much either.
Additionally, the code's comments/documentation has been confusing, so I'm not totally sure what the parameters of USBH_MSC_Read10 should be. The first two are self-explanatory, but afterward, is the address the actual address, and is it in terms of bytes or sectors? Also, how can USBH_MSC_Read10 support values larger than wMaxPacketSize if it's using bulk transfers?
#usbhost #stm32 #stm32f3