9 years, 1 month ago.

Programm hangs without connecting usb

Hello, friends! I wrote a little test program(lpc1768).

#include "mbed.h"
#include "USBMIDI.h"
DigitalOut led(LED1);
USBMIDI midi;
int main()
{             
    while (1)
    {    
        led =! led;
        wait(0.2);    
    }
}

When connected to a computer all is well: LED flashes, midi device is recognized. But if you apply power from an external power supply without having to connect to computers, the program hangs, the LED does not blink.

Please help me how to fix it. Thank U!

UPD: in USBDevice.cpp I blocked line with configured() function. Everything works well! But I think that this is not the right solution.

void USBDevice::connect(void)
{
    /* Connect device */
    USBHAL::connect();
    /* Block if not configured */
    //while (!configured());    //   my red
}

Question relating to:

I cannot make an answer anymore, but you seem to have an old version of USBDevice. Newer versions can connect non-blocking. USBSerial for example can also be constructed non-blocking, USBMidi does not have this yet, but would be easy to add.

posted by Erik - 10 Mar 2015

1 Answer

9 years, 1 month ago.

The other option is to look at the VBUS pin and enumerate once USB is present.

UPD: in USBDevice.cpp I blocked line with configured() function. Everything works well! But I think that this is not the right solution.

Accepted Answer