AnsweredAssumed Answered

USB library stalls while waiting for response

Question asked by mex1 on Jul 21, 2014
Latest reply on Jul 21, 2014 by Clive One
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:

01.int USBH_USR_MSC_Application(void)
02.{
03.    switch (msc_state)
04.    {
05.        case MSC_INIT:
06.            {
07.                printf("Starting download...\r\n");
08.                msc_state = MSC_READ;
09.            }
10.            break;
11.        case MSC_IDLE:
12.            {
13.            }
14.            break;
15.        case MSC_READ:
16.            {
17.                uint32_t sectors_read = 0;
18.                uint8_t buffer[64];
19. 
20.                /* Download every available sector */
21.                if (sectors_read < USBH_MSC_Param.MSCapacity)
22.                {
23.                    /* Check if there's enough room in uart buffer */
24.                    if (dl_uart_count() < (BUFFER_SIZE - 64))
25.                    {
26.                        uint8_t status = USBH_MSC_OK;
27.                        /* Queue read command */
28.                        status = USBH_MSC_Read10(&USB_OTG_Core,
29.                                                 buffer,
30.                                                 sectors_read,
31.                                                 64);
32. 
33.                        if (status == USBH_MSC_OK)
34.                        {
35.                            printf("Downloaded sector %lu of %lu\r\n", sectors_read, USBH_MSC_Param.MSCapacity);
36.                            /* Write data to usart */
37.                            dl_uart_write(buffer, 64);
38. 
39.                            /* Set next sector to be read */
40.                            sectors_read++;
41.                        }
42.                        else if (status == USBH_MSC_FAIL || status == USBH_MSC_PHASE_ERROR)
43.                        {
44.                            msc_state = MSC_ERROR;
45.                        }
46.                    }
47.                }
48.                else
49.                {
50.                    printf("Download complete\r\n");
51.                    msc_state = MSC_IDLE;
52.                }
53.            }
54.            break;
55.        case MSC_WRITE:
56.            break;
57.        case MSC_ERROR:
58.            printf("Error detected\r\n");
59.            msc_state = MSC_IDLE;
60.            break;
61.        default:
62.            break;
63.    }
64.    return(0);
65.}

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?

Outcomes