I am facing a weird bug now. The code is very simple:
Code: Select all
int main(void) {
halInit();
chSysInit();
usbDisconnectBus(serusbcfg.usbp);
chThdSleepMilliseconds(1000);
usbStart(serusbcfg.usbp, &usbcfg);
usbConnectBus(serusbcfg.usbp);
sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg);
chThdSleepMilliseconds(2000);
while (true) {
chnWrite(&SDU1, (void *) "123", 3);
chThdSleepMilliseconds(100);
}
}usbcfg.h/.c are those from testhal\STM32\STM32F0xx\USB_CDC. First, when I flash the MCU, it works fine, the terminal window floods up with "123" text. When I disconnect the board from USB (it also supplied from usb power line, so it turns off) and then plug it back in, it fails configurating. From the device manager in Windows I see:
This device cannot start. (Code 10)
{Operation Failed}
The requested operation was unsuccessful.
The only way to make thing work (though not every time) is to Disable the driver end enable it back. I have tried Windows Default driver and STM VCP with the same result. The problem seems to be related with Windows drivers, though I am not sure.