USBSerial freezes on Nucleo F401RE

29 Jun 2016

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 approximately 300 bytes are transferred from the PC to the board in a single shot.

#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');
    	}	
    }
}