How to write a mbed_app.json file for adding feature USBDEVICE

keyword:
mbed-os5.15.0, Nucleo-F446RE, USBDevice, On-line compiler, json

I made a USB Serial(USBDevice) program on mbed-os5.15.0.

#include "mbed.h"
#include "USBSerial.h"

Serial pc(USBTX, USBRX, 115200);
USBSerial usb_serial;

int main(void){
    uint32_t num = 0;
    while(true) {
        usb_serial.printf("I am a USB virtual serial port: %d\r\n", num++);
        pc.printf("I am a ST-Link virtual serial port: %d\r\n", num + 10000);
    }
}

I ran the program on Nucleo-F446RE board then error was appear as follows.

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

BTW I ran the program on Nucleo-F446ZE (not R but Z) board and the program is fine as expect.
After that I wrote mbed_app.json for adding USBDEVICE feature for F446RE.

{
    "config": {
        "usb_speed": {
            "help": "USE_USB_OTG_FS or USE_USB_OTG_HS or USE_USB_HS_IN_FS",
            "value": "USE_USB_OTG_FS"
        }
    },
    "target_overrides": {
        "*": {
            "target.components_add": ["SD"],
            "target.components_add": ["USBDEVICE"]
        }
    }
}

This json file does Not have an compile error but same run time error message was appeared.
Please give me an advice how to write json file to enable USBDEVICE feature.

In addtion, I imported mbed-os5.15.0 souce files into my online environment and modified target.json file as follows.

    "NUCLEO_F446RE": {
        "inherits": ["FAMILY_STM32"],
        "supported_form_factors": ["ARDUINO", "MORPHO"],
        "core": "Cortex-M4F",
        "extra_labels_add": ["STM32F4", "STM32F446xE", "STM32F446RE"],
        "config": {
            "clock_source": {
                "help": "Mask value : USE_PLL_HSE_EXTC | USE_PLL_HSE_XTAL (need HW patch) | USE_PLL_HSI",
                "value": "USE_PLL_HSE_EXTC|USE_PLL_HSI",
                "macro_name": "CLOCK_SOURCE"
            },
            "usb_speed": {
                "help": "USE_USB_OTG_FS or USE_USB_OTG_HS or USE_USB_HS_IN_FS",
                "value": "USE_USB_OTG_FS"
            }
        },
        "detect_code": ["0777"],
        "device_has_add": [
            "ANALOGOUT",
            "CAN",
            "SERIAL_ASYNCH",
            "FLASH",
            "MPU",
            "USBDEVICE"
        ],
        "release_versions": ["2", "5"],
        "device_name": "STM32F446RE",
        "bootloader_supported": true
    },

It works fine.

1 Like

hi @kenji_tokyo
Please note that USBDEVICE is a device, not a comopnent.
Please try changing "target.components_add": ["USBDEVICE"] to "target.device_has_add": ["USBDEVICE"]
Regards,
Mbed Support
Ron

Hi Ron,
Thank you for your support.
I modified the json file accordingly your advice and worked well on Nucleo-F446RE board + USB handmade circuit.
Thanks again,
Kenji

I’m having a similar difficulty with a LPC4088 Quickstart board trying to use one of it’s other USB ports as an alternative serial output.

My mbed_app.json looks like this:

{
    "config": {
        "usb_speed": {
            "help": "USE_USB_OTG_FS or USE_USB_OTG_HS or USE_USB_HS_IN_FS",
            "value": "USE_USB_OTG_FS"
        }
    },
    "target_overrides": {
        "*": {
            "platform.stdio-convert-newlines": true,
            "target.device_has_add": ["USBDEVICE"]
        }
    }
}

and I get the following compiler output (I’m using Mbed Studio 0.81 with MbedOS 5.15.1):

[Error] @0,0: L6218E: Undefined symbol get_usb_phy() (referred from BUILD/LPC4088/ARMC6/mbed-os/drivers/source/usb/USBAudio.o).
Error: L6218E: Undefined symbol get_usb_phy() (referred from BUILD/LPC4088/ARMC6/mbed-os/drivers/source/usb/USBAudio.o).
Error: L6218E: Undefined symbol get_usb_phy() (referred from BUILD/LPC4088/ARMC6/mbed-os/drivers/source/usb/USBAudio.o).

I seems as if it’s trying to add the USBDEVICE as an audio interface rather than serial - is there a way to override this?

Any attempt to modify targets.json causes Mbed Studio to refuse to build with a message about ‘please select valid target’ even though the board is plugged in and recognised.

Any assistance appreciated.