Arm Mbed OS support forum

USBKeyboard undefined when compiling for K22F

I’m compiling a very simple mBed OS 6 (bare metal) program that uses USBKeyboard for the FRDM-K22F, but I get this link error:

[Error] @0,0: L6218E: Undefined symbol USBKeyboard::key_code(unsigned char, unsigned char) (referred from BUILD/K22F/ARMC6/main.o).
[Error] @0,0: L6218E: Undefined symbol USBKeyboard::USBKeyboard(bool, unsigned short, unsigned short, unsigned short) (referred from BUILD/K22F/ARMC6/main.o).

Those functions are defined in USBKeyboard.cpp but I’m not sure how to make mBed Studio actually link it. Any ideas?

Ahoj Tim,

if you have in your mbed_app.json file only this content

{
"requires": ["bare-metal"]
}

then you probably need to change it to

{
"requires": ["bare-metal", "events", "drivers-usb"]
}

This seems to be incorrectly documented.

BR, Jan

It worked, thanks! Would be nice if it was documented somewhere (ideally on the USBKeyboard doxygen page!)

You are welcome.

That is not correct place because that was affected by bare metal profil.
But here is full list of all APIs, where is info also about state of all APIs under Bare metal profile. There seems be wrong info about USB APIs, probably missing “(can be manually enabled)”.

You need to visit page about Bare metal profile where is a link -

To enable individual APIs, see the usage instructions.

Then you need to find mbed_lib.json of USB API in its folder.
The events was added because compiler throw error about “Events missing in USB” (something similar).

BR, Jan

Ah yeah I did visit that list of APIs, saw that USB was enabled on bare metal, and then figured it must be a bug. If it had said “can be manually enabled (here’s how)” I think it’s likely I’d have found the solution.

Still I don’t get why you think the API documentation isn’t a reasonable place to put a note like “Note: this API is not enabled for all profiles, see (here) for details.”

In fact even better would be

#ifndef USB_API_ENABLED
#error “You need to do this…”
#endif