mbed:使用 USBDevice 库编译导致错误

mbed: compiling with USBDevice library results in error

我一直在尝试为我的 STM32 Nucleo F303K8 编译 USB 键盘的简单示例(我一直在关注 https://os.mbed.com/handbook/USBKeyboard and https://www.hackerspace-ntnu.no/wiki/tutorials/mbed/mbed-keyboard-en/ 中的示例)

基本上我的整个main.cpp是:

#include "mbed.h"
#include "USBKeyboard.h"

USBKeyboard keyboard;

int main(void) {

    while (1) {
        wait(1);
        keyboard.printf("Test");
    }
}

但是在编译时,我被告知

Error: Identifier "PCD_HandleTypeDef" is undefined in "USBDevice/USBDevice/USBHAL.h", Line: 134, Col: 6

该特定错误是从我在 https://os.mbed.com/compiler 上的项目复制而来的 - 我还尝试从 VSCode 中的本地项目构建(使用 PlatformIO 插件),但我遇到了同样的问题。没有 mbed 的 USBDevice 库,我可以从两个 IDE 编译。

有谁知道为什么会这样?我需要导入其他东西吗?

您遇到此错误是因为 USBDevice 库不支持 NUCLEO_F303K8 目标。对于 Mbed 2,您可以看到没有可用于 F303K8 in this directory here, and for Mbed OS 5 you can see that the F303K8 target is not supported according to the USBHAL_STM32.h 文件的文件夹。