Report
11 months, 1 week ago.

Nucleo-F103RB USBHID not working?

I am trying USB HID on Nucleo-F103RB. The program I am trying is trivial. However the program crashes. The program only instantiates USBHID class. This should be enough for USB host (running in the PC) to enumerate. The while loop in the main is a blinky program which is just an indicator if program is running or crashed. When I comment out USBHID instantiation, blinky works.

Note following: 1. The program works on FRDM-KL25Z. And PC identifies it as a USB device and provides information like PID and VID etc. 2. The USBHAL_IP_DEVICE.h file tells me that you need to connected a pull-up on D+ line. I did it, however no improvement.

So following is the simple program.

Program starts

  1. include "mbed.h"
  2. include "USBHID.h"

USBHID hid(8, 8);

DigitalOut led1(LED1);

int main(void) { led1 = 0;

while (true) { Thread::wait(500); led1 = !led1;

} } program ends

Comment on this question

1 Answer

11 months, 1 week ago.

Hello Hemant,

  • To assure correct format after pasting your program code here please surround it with markup tags (each on separate line) as below:
<<code>>
your code
<</code>>


  • To make your program work try to add a new mbed_app.json file to your project with the content as below and then compile.

{
    "target_overrides": {
        "NUCLEO_F103RB": {
            "target.clock_source_usb": "1"
        }
    }
}

Thanks Zoltan. Next time will mark my code.

Yesterday I already figured out this. But it took couple of hours to know that the online build and hence default configuration won't work for USB. Also added following into the json file, because HSI is not recommended for USB. <<code>> "target.clock_source": "USE_PLL_HSE_XTAL" <<code>>

Yet to try offline. Is it possible to use mbed_app.json with online build?

I would appreciate if the fact is prominently ("The online compilation and hence default configuration won't work for USB on Nucleo targets") documented.

Thanks again, Hemant

posted by Hemant Joshi 22 Jul 2018

Verified that mbed_app.json works with online compiler. The USB HID too worked. My USB host could enumerate the custom device.

posted by Hemant Joshi 22 Jul 2018

To post an answer, please log in.