USBDevice support for STM32F3


I am currently trying to use the USB capability on a custom board using an STM32F303RD (RE was out of stock when I purchased, and the reduced ROM size should not be a problem). I use a custom board config based on the NUCLEO F303RE available in the mbed sources.

I just need a simple virtual serial port, but I cannot make it work using mbed (6.2.0 via platformio) and an example as simple as something like :

#include "mbed.h"
#include "USBSerial.h"
USBSerial serial;
int main(void)
    while (1) {
        serial.printf("I am a virtual serial port\r\n");

Does not work: it compiles ok, but the USB port is not recognized by my laptop (With errors in my syslog like “Device not responding to setup address.”)

The DFU works fine and I have been able to execute a basic test built from STM32Cube (based on the USB CDC tutorial), so the HW should be ok (I am using an external 8MHz crystal).

Now looking in the targets/TARGET_STM/TARGET_STM32F3/ directory, it seems there is very few code dedicated to USB FS handling.

So my question is: did I missed something or is the USB FS on the STM32F3 family actually not supported by mbed 6?



Hello David,

Usually, the USB is supported only on boards what have a onboard USB connector and then also boards what not have onboard connector but use same/similar chip (USB interface).
How you can see here is no F3XX target with USB tag and also in the folder of F3xx targets are missing USB HAL Drivers.

So I think I can say - NO, the USB feature is not supported on STM32F3XX targets for now.

BR, Jan

USB Code should be in /TARGET_STM/ root folder for STM devices. Generally, it should be supported.

Did you define your own custom target, and in that target setup USB use? Or did you just port Nucleo board files?

Thanks Jan,

Ok but unless I’m wrong the NUCLEO_F303ZE do have a USB connector (directly connected to the MCU I mean, in addition to the ST-Link one on the F103).

So I would have expected for the mbed USB stack to be implemented on the STM32F3 family.

Note that I have almost no knowledge of the mbed internals, I’ve started using mbed for a few nucleo based pet projects. This one is my first custom board.

Also, on here the F303ZE is listed with “USB 2.0 full-speed” which is a bit misleading (I get why it is like that, I guess, still make it easy to get confused).

So I’ll have to wait until the USB stack is implemented (/ ported from ST Cube?) I guess to implement my serial based feature.


Hi Ante,

I’ve used nucleo f303re’s definition from target/target.json as base, and I made a (partial) copy of targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/TARGET_NUCLEO_F303RE/, but it looks there is no much more help in the NUCLEO_F303ZE (unless I’m mistaken).

Yes, you are right but I also wrote “usually” :slight_smile: And the description on board’s page is a summary of what the board can do not what is supported on Mbed, it is confusing.

Just for clarification. The work around board’s page and and its porting to Mbed is responsibility of Board Partner, in this case ST.
So you can try to contact ST’s employe @jeromecoutant. He can lead you where you can start.

You can also check an old USB library for inspiration.

BR, Jan

Thanks Jan, I’ll ask Jerome about heir plan on this, and give a look at this library, just in case. (and yes there is some confusion on between board, MCU and mbed abilities… not to mention mbed versions, and the gazillion examples and discussions actually referring to mbed 2 or 5 :slight_smile:


I think adding USB support for NUCLEO_F303ZE should be possible since

has been merged

Thanks for the response, but the clock is already set up properly for the STM32F3 target (which the main part of this PR, if I understand the code right) eg. in system_clock.c (for the F303RE) or system_clock.c (F303ZE), especially in the case of an external 8MHz crystal is used.

However, I see a lot of USB related low level code in TARGET_STM32F1 (especially in the HAL code from STM32Cube in STM32Cube_FW for which I see no equivalent in nor any other subdir of TARGET_STM32F3.

So my guess is that the LL/HAL code from STM32Cube for the STM32F3 family in mbed 6 should be updated.

Or did I miss something?



So my guess is that the LL/HAL code from STM32Cube for the STM32F3 family in mbed 6 should be updated.

Please check



1 Like

Wonderful, thanks a lot!