USBSerial compilation error

I am trying to compile an example code as below for DISCO-L053C8 on mbed-os 5.15.6 on Mbed Studio. The code is:

#include “mbed.h”
#include “USBSerial.h”
//Virtual serial port over USB
USBSerial serial;
//USBSerial ser (true, 0x1f00, 0x2012, 0x0001);
int main(void) {
serial.printf(“I am a virtual serial port\n”);

However it shows the below errors:
[Error] @0,0: L6218E: Undefined symbol USBSerial::USBSerial(bool, unsigned short, unsigned short, unsigned short) (referred from BUILD/DISCO_L053C8/ARMC6/main.o).
[Error] @0,0: L6218E: Undefined symbol USBSerial::~USBSerial() (referred from BUILD/DISCO_L053C8/ARMC6/main.o).

What is missing?


the USB feature was probably not supported/implemented on this target
In the targets.json is missing USBDEVICE. That can be enabled but also in STM32L0 HAL drivers are not any USB drivers, so it seems to be pointless.

BR, Jan

Don’t know where the mistake is. The users are not supposed to read the entire code before selecting the device and start using it.

The PinNames.h file shows the USB pins: mbed-dev - mbed library sources. Supersedes mbed-src. | Mbed

The PeripheralPins.c file shows USB pins: mbed-dev - mbed library sources. Supersedes mbed-src. | Mbed

The system_clock.c file shows clock selection for USB.


above you wrote about MbedOS 5.15 and now you poste some links to mbed-dev, which is Mbed2.
And of course there are pins for the USB because the board DISCO-L053C8 | Mbed has USB 2.0 full speed on-chip interface. But unfortunately the USB driver for STM32L0 was not implemented under Mbed - STM32L0 HAL drivers.

You can try to do what I mentioned in this topic but because your board is low memory target you also need additional setting for activate USB under bare metal.

Probably something like this.

    "requires": ["bare-metal", "events","drivers-usb"],
    "target_overrides": {
        "*": {
            "target.device_has_add": ["USBDEVICE"]

But from me point of view after you will enable all necessary things then you will see this Error

– MbedOS Error Info –
This board does not have a hardware USB driver

Ok, the setting for bare metal above is for MbedOS6+ but not for MbedOS5. The USB API of MbedOS5 was probably not supported under bare metal.

BR, Jan

Thank you. When I tried, it generated lots of errors. Where can I get the files, PinNames.h, PeripheralPins.c and system_clock.c for mbed-os 5.15.6 for this device?

On github repository - TARGET_DISCO_L053C8 at mbed-os-5.15.6

BR, Jan

Oh! Wonderful! Many thanks. I was always searching on the mbed site.

Also when you use Mbed Studio, how you wrote above, you not need visit the github repo.
Just follow same path in project tree: YOUR_PROJECT/mbed-os/targets/TARGET_STM/TARGET_STM32L0/TARGET_STM32L053x8/TARGET_DISCO_L053C8/

BR, Jan

Thank you Jan. How do I quickly know which peripherals on the controller are supported by mBed? I thought whatever is available in the PeripheralPins.c is all supported.

Maybe I miss something but from my point of view there is no official quick way, especially for USB.

  1. you need to check the board page (or user manual) if your target has requested feature
  2. you can check targets.json if that feature is enabled or not.
  3. you can check if the folder of STM32L0 family contain USB drivers

And it still not enough.

I would like to say here Development boards | Mbed but I do not think so. Support of boards/ targets are usually added by Mbed partners like are NXP, ST etc.
When you check the list above, it seems all use different rules.

  • The ST probably add all boards with physical on-board USB conector. F446RE is not on the list because it not have on-board USB connector probably but I tried USBSerial API on F446RE and seems be OK.
  • The NXP not care of that or not interested (I do not know right word) but how you can see both boards (FRDM-K64F | Mbed and also FRDM-KL46Z | Mbed) have on-board USB port and are not in the list.

BR, Jan

here is another tool for finding boards with particular hardware, written by an user from this forum:

Good point, it is good work from Jamie as usual. But I not mentioned it because it is similar situation (because it is based on targets.json), like I descripted above. Furthermore it is a parser of the master branch of MbedOS repo, I think. So that not contain MbedOS 5.15 and therefore does not contain STM32L053.

Only my opinion.

BR, Jan

I believe the developers prefer Mbed because you get all the drivers and libraries ready. You need to just write the application specific code. You don’t have to worry about the start-up code and the drivers for the peripherals. However what I have observed is the developers need to struggle to find out what is available and what is not. Perhaps finally you spend almost the same time as you would on the target specific environment like STMCubeMX. This is because on Mbed you spend time on searching and trying to find what is available. I believe there should be a clear list for each target about the availability of the supported features for all supported OS versions.