1 year ago.

F401 Nucleo using USB from Controller via PA11 / PA12


new to mbed i try to connect my NucleoF401RE via his internal USB ( not via ST-Link ) to my PC to use it as CDC to get the highest possible Speed.

d+ and d- are connected via 22Ohm Resistors to PA11/PA12. USB Ground ist connected to Nucleo Ground.

I try several examples, a.e. the USBDeviceLibs but dont get sucsess.

Has someone a Project which i can use "out of the Box" or can explain which Lib´s to use / which way to go ?

Serial Communication via ST-Link is working. But "only" changing the Pin´s

Serial USB(PA_11, PA_12, 256000); tx, rx

is not enough :-)

Windows is telling me "Device not recognized"

Comment on this question

1 Answer

1 year ago.

Hi Guido,
I just modified original program and issued as follow.

Import programSTM32_USBDevice_Serial

check program for USB Serial

Modify: (1) Change mbed-os2 to mbed-os5 (2) Add time measurement (3) Compare with pc.printf

This program works well on F401 board.
You need to connect USB cable after program run.
If you connect USB cable then RESET, system doesn't work.

Thanks, will test it tomorrow and send Feedback. Maybe we find a way that the chronology of plugging in Power / USB doesent matter. Maybe initalizing USB only / first if 5V DC from USB is connected to a Portpin ?

Edit 04/17/2018

Your changes are working perfect. Comport is generated. Win10 is istalling a matching Driver automaticly. Also it is possible to plug in USB first and then Power up the Device.

Parts of Code:

Serial pc(USBTX, USBRX, 9600); Baudrate doesnt matter. Speed is the same from 9600 to XXXXXX

int main(void) { Interrupt Handler usb_serial.attach(&Rx_interrupt); usb_serial.printf("I am a virtual serial port..."); usb_serial.putc(0x03);

while(1) { if (ETX_received){ usb_serial.putc(0x02); usb_serial.printf("Serial Data %d Bytes received\r\n",readindex); usb_serial.putc(0x03); readindex=0; ETX_received=false; led = !led; } } }

void Rx_interrupt() { led=1; char c; while (usb_serial.readable() ){

rx_buffer[readindex] = usb_serial.getc();

if (rx_buffer[readindex]==0x02){ readindex=0; return; }

if (rx_buffer[readindex]==0x03){ ETX_received=true; return; }

readindex++; if ( readindex>buffer_size) readindex=buffer_size; } led=0; return; }

Explaining: I use a PC Test-Tool to send / receive Data.RX RX Interrupt is counting the incomming Bytes. If 0x02(STX) is received the Counter is set to 0. If 0x03 (ETX) is received a flag is set and the MainLoop is sending an Answer back to the PC.

There i measure the Time, starting with sending 0x02 (STX) which is Clearing the In-Counter and ending with ETX received from the Board.

The Communication Looks slow in my Eyes. 8 Blocks of 1Kb e.a. need about 320ms.

posted by Guido Jaeger 16 Apr 2018

To post an answer, please log in.