USBCDC on NucleoL152 not running

Hi, how do I get USBCDC running on STM32L152 Nucleo?
my program:
#include “mbed.h”
#include “USBCDC.h”

USBCDC cdc;

int main(void)
{

while (1) {
    char msg[] = "Hello world\r\n";
    cdc.send((uint8_t *)msg, strlen(msg));
    HAL_Delay(1000);
}

}
I get the following Errormessage:
++ MbedOS Error Info ++
Error Status: 0x80FF0100 Code: 256 Module: 255
Error Message: Fatal Run-time error
Location: 0x8002897
Error Value: 0x0
Current Thread: main Id: 0x20001E20 Entry: 0x8006875 StackSize: 0x1000 StackMem: 0x20000450 SP: 0x2000138C
For more info, visit: mbedos-error
– MbedOS Error Info –
This board does not have a hardware USB driver

But STM32-L152 has USB-hardware
Greetings
Joerg

Hello,

do you have the USBDEVICE in mbed_app.json like bellow?

{
    "target_overrides": {
        "*": {
            "target.device_has_add": ["USBDEVICE"]
        }
    }
}

BR, Jan

Hello Jan,
yes I have.
BR Joerg

I’m sorry, I copied and wrote the wrong template above.
The USBDEVICE is from device_has so in the mbed_app.json must be device_has_add and not commponent_add.
Tested with Nucleo-L152RE, MbedOS 6.15.1 and Online compiler and it is working (DTR signal ON in PC terminal app).

Another possible reason of your crash can be Keil Studio online, if you use it. It seems like it ignores mbed_app.json configuration sometimes. I tried same code with Keil Studio and result is the crash.
KeilStudio should trigger clean build with every change in mbed_app.json, but it doesn’t behave that way.

BR, Jan

Hello Jan,
great!! It works!! Thank You a lot
BR Joerg

You are welcome.

BR, Jan