Mbed OS 6.14 include USBSerial

How should I include the USBSerial using the new mbed CLI 2? I get the error the compiler cannot find the header file.

Steps to reproduce:
mbed-tools new .
mbed-tools configure -t GCC_ARM -m DISCO_L476VG
code .

After that the VScode window is opened. I configure the CMake kit to the ARM embedded toolchain and configure it to debug. Then after modifying main.cpp to include USBSerial.h I build the project and get the error.

I tried to fiddle around with the Cmake files, but I do not know much about Cmake. I eventually got stuck on the CMakeLists.txt inside mbed-os where it does have add_subdirectory() on lin e178. But I can’t actually use the USB driver…

Hi,

Your CMakeLists.txt should have mbed-usb library as below.

target_link_libraries(${APP_TARGET}
    PRIVATE
        mbed-os
        mbed-usb
        mbed-events
)