USB CDC fails at reconnect

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Captain
Posts: 12
Joined: Sat Dec 19, 2015 3:21 pm

USB CDC fails at reconnect

Post by Captain »

Hello.
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.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: USB CDC fails at reconnect

Post by Giovanni »

Hi,

Try changing port or (not) go through a USB HUB ands see if it makes a difference.

Our and ST code are entirely different so it is unlikely it is a SW issue.

Giovanni
Captain
Posts: 12
Joined: Sat Dec 19, 2015 3:21 pm

Re: USB CDC fails at reconnect

Post by Captain »

Our and ST code are entirely different so it is unlikely it is a SW issue.

That seems so, but the same code flashed into stm32f407 discovery board works ok. The bug also appears on reset, so it is unlike to be a slow power up issue.. Changing port/pc (Win8.1 x64/Win10 x64)/hub does not help. Everything works perfectly, when connected to macbook (tty.usbmodem is available each time I connect it). I wonder if there might be a piece of code in stm32f0 usb driver which can cause windows drivers to fail on enumeration? Maybe anyone here does have the stm32f072 discovery board to check on the code?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: USB CDC fails at reconnect

Post by Giovanni »

Hi,

I tested the USB demo for the STM32F072 earlier today, it worked as expected.

Giovanni
Captain
Posts: 12
Joined: Sat Dec 19, 2015 3:21 pm

Re: USB CDC fails at reconnect

Post by Captain »

Finally... The os tick rate was set to 100kHz, after lowering down to 10kHz it works like a charm.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: USB CDC fails at reconnect

Post by Giovanni »

In tickless mode the tickrate should not affect much, strange.

Could you try to restore it at 100kHz and increase delta instead? (try 10)

Giovanni
Captain
Posts: 12
Joined: Sat Dec 19, 2015 3:21 pm

Re: USB CDC fails at reconnect

Post by Captain »

Ayeah, it worked ok in tickless (delta=4) :) But due to the lack of timers, I've decided to disable the tickless mode but missed the tick rate.
Post Reply