USBDevice support for STM32F3

Hi,

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");
        ThisThread::sleep_for(1000);
    }
}

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?

Thanks,

David

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.

David

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:

David

Hi
I think adding USB support for NUCLEO_F303ZE should be possible since

has been merged
Regards,

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 https://github.com/ARMmbed/mbed-os/tree/master/targets/TARGET_STM/TARGET_STM32F3/device 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?

Thanks,
David

Hi

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

Please check

Regards,

Jerome

1 Like

Wonderful, thanks a lot!