USB device stack

Dependents:   mbed-mX-USB-TEST1 USBMSD_SD_HID_HelloWorld HidTest MIDI_usb_bridge ... more

Issue: USBSerial freezes with Nucleo F401RE

I'm using a Nucleo F401RE board to help me debug a problem with the USBSerial library and this micro.

I've attached a USB connector to PA12 (D+), PA11 (D-), GND, and PA9 (+5V). The board is powered from the embedded STLINK USB and the clock is configured by default (board revision C-03) to use the MCO from ST-LINK.

The library works well for simple reads and writes. However, when I stress it a little it freezes. Here is a simple program that hangs the board when more than 64 bytes are transferred from the PC to the board in a single shot (tried with the Arduino console).

#include "mbed.h"
#include "USBSerial.h"

USBSerial serial;

void readISR() {
	while(serial.readable()) {
		serial._getc();
	}
}

int main(void) {
    serial.attach(readISR);
    while(1)
    {
    	for(int i=0; i<100; i++) {
    		if(serial.writeable()) {
    			serial._putc('.');
    		}
    	}
    	wait_ms(5);
    	if(serial.writeable()) {
    	    serial._putc('\n');
    	}	
    }
}

I've debugged it a little bit, and it is stucked here:

bool USBDevice::write(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize)
{
[...]
    /* Wait for completion */
    do {
        result = endpointWriteResult(endpoint);
    } while ((result == EP_PENDING) && configured());

For some reason epComplete flag is not changed by the USB ISR inside USBHAL_STM32F4.cpp