8 years, 1 month ago.

hang on write() EP_PENDING forever

did some debugging with LPCExpresso and the mbed gets stuck randomly in an infinite loop on

usbdevice.cpp: USBDevice::write()

    /* Send report */
    result = endpointWrite(endpoint, buffer, size);

    if (result != EP_PENDING)
    {
        return false;
    }

    /* Wait for completion */
    do {
        result = endpointWriteResult(endpoint);
    } while ((result == EP_PENDING) && configured());

It waits with EP_PENDING forever.

Only way to exit from this is restart mbed from watchdog at the moment.

This happens randomly, usually around the time of a read interrupt event. I am using 2 interrupt endpoints: In and Out @ 1ms rate and 64byte packets.

Question relating to:

USB device stack device, USB

2 Answers

7 years, 3 months ago.

We have same problem with STM32F4 device. Have you found any solution to this problem yet?

I would believe it is some mess-up with interrupts as well. We're in progress of investigating the USBDevice code for solution.

my solution was to put writeNB in SOF() event, I believe writeNB cannot be in a loop because it could try to write during a read, so putting it in SOF() keeps it in sync, meaning read/write is always performed sequentially rather than simultaneously.

posted by Michael Wiernicki 09 Mar 2017

This is a very interesting topic! I tried USBMSD_SD on mbed. No go. Exported it to CoIDE and built and tested. In the end Windows would recognise it as USB Mass Storage Device but after 20 secs windows timed out with the yellow exclaimation mark and code 10 (Device could not start). Checked it with Message Analyser and discovered that it fails after windows sends the SCSI Inquiry command. My device gets the CBW inquiry command but when it tries to send the result it ends up in an endless loop with EP_PENDING. Windows waits and finally times out with BULK_IN_TRANSFER CANCELLED in Message Analyser.

How did you code it to put the writeNB() in the SOF() event. Can you explain the sequence ?

posted by Bob Kendrick 13 Mar 2017
7 years, 3 months ago.

i get the same problem. stm32f407.

bool USBDevice::writeNB(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize) { EP_STATUS result;

if (size > maxSize) { return false; }

if(!configured()) { return false; }

/* Send report */ result = endpointWrite(endpoint, buffer, size);

if (result != EP_PENDING) { return false; }

result = endpointWriteResult(endpoint);

printf("USB Device write %d \r",result);

return (result == EP_COMPLETED); }

the result : 1