usb_serial stops working after reset

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

Re: usb_serial stops working after reset

Post by alexblack »

Hi,
Giovanni wrote:The STM32F3-Discovery is unable to control the USB pull-up resistor that allows to detect the device, it is always ON. After restarting an application or resetting the board is mandatory to disconnect the USB cable and connect it again or the host cannot detect the board again.
This is a problem specific to this board only.
Giovanni

There is no problem. To disconnect from USB simpy pull down USBD+ USBD- pins and then release them after 1 sec pause.

Code: Select all

void usb_lld_disconnect_bus(USBDriver *usbp)
{
  palClearPort(USB_GPIO_PORT, (1<<USBDM_BIT) | (1<<USBDP_BIT));
  palSetPadMode(USB_GPIO_PORT, USBDM_BIT, PAL_MODE_OUTPUT_PUSHPULL);
  palSetPadMode(USB_GPIO_PORT, USBDP_BIT, PAL_MODE_OUTPUT_PUSHPULL);
}

void usb_lld_connect_bus(USBDriver *usbp)
{
  palClearPort(USB_GPIO_PORT, (1<<USBDM_BIT) | (1<<USBDP_BIT));
  palSetPadMode(USB_GPIO_PORT, USBDM_BIT, PAL_MODE_INPUT);
  palSetPadMode(USB_GPIO_PORT, USBDM_BIT, PAL_MODE_INPUT);
}

I tested this on STM32F103, STM32F205/207 and STM32F407 with Windows XP host - all works fine.
alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

Re: usb_serial stops working after reset

Post by alexblack »

One remark: for STM32F4 (and possible for F3) you must configure USB pins in "Alternate IN" mode in usb_lld_connect_bus().
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: usb_serial stops working after reset

Post by Giovanni »

Thanks for that code, I will update the board files.

Still, the problem is present in current code for that board.

Giovanni
User avatar
part1zan_
Posts: 44
Joined: Sun Sep 08, 2013 9:04 pm

Re: usb_serial stops working after reset

Post by part1zan_ »

I tried using the above code, and after a while I made it work. Here is what I came to:

Code: Select all

#define USB_GPIO_PORT GPIOA
#define USBDM_BIT GPIOA_USB_DM
#define USBDP_BIT GPIOA_USB_DP

void usb_lld_disconnect_bus(USBDriver *usbp)
{
  palClearPort(USB_GPIO_PORT, (1<<USBDM_BIT) | (1<<USBDP_BIT));
  palSetPadMode(USB_GPIO_PORT, USBDM_BIT, PAL_MODE_OUTPUT_PUSHPULL);
  palSetPadMode(USB_GPIO_PORT, USBDP_BIT, PAL_MODE_OUTPUT_PUSHPULL);
}

void usb_lld_connect_bus(USBDriver *usbp)
{
  palClearPort(USB_GPIO_PORT, (1<<USBDM_BIT) | (1<<USBDP_BIT));
  palSetPadMode(USB_GPIO_PORT, USBDM_BIT, PAL_MODE_ALTERNATE(14));
  palSetPadMode(USB_GPIO_PORT, USBDP_BIT, PAL_MODE_ALTERNATE(14));
}

Yep, that's exactly what alexblack said. Thank you very much, alexblack.
enly1
Posts: 38
Joined: Wed Oct 09, 2013 10:21 pm

Re: usb_serial stops working after reset

Post by enly1 »

Hi,

Just working on this board and came across the very thing this morning.

Not aware enough of the ChibiOS file layout yet to know where to put this code / replace this code.

Could you advise which board file / how to replace what is needed please or supply a new board file privately ?

Thanks

Simon
enly1
Posts: 38
Joined: Wed Oct 09, 2013 10:21 pm

Re: usb_serial stops working after reset

Post by enly1 »

Not sure if i've got this right, but it appears that post reset, the com port dissapears, a second later re-appears, but still won't let me reconnect to the com port until I pull the cable again.

So not sure what is going on here and if I'm doing it correctly.

PS - Windows 7.
User avatar
part1zan_
Posts: 44
Joined: Sun Sep 08, 2013 9:04 pm

Re: usb_serial stops working after reset

Post by part1zan_ »

I just put it into main.c of my project (I know it's an ugly hack, but it works), into main() where I initialize USB. Didn't test it on windows, though
enly1
Posts: 38
Joined: Wed Oct 09, 2013 10:21 pm

Re: usb_serial stops working after reset

Post by enly1 »

Right - worked it out.

There are a couple of issues at play on windows 7.

1. You definitely need the extra code to handle the reset and bounce the USB lines. This works as expected (when you test correctly - see point 2) If you don't have it, MCU reset means no com port.
2. In windows, if you have the com port open when you reset the MCU, it will not reconnect until USB disconnected or another MCU reset.

Point 2 is the reason I didn't believe it was working correctly.

The test I was doing was to view the virtual com port output, hit reset, attempt to reconnect to com port and failed.
Had I reset again after the failed attempt, it would have connected fine.

If you repeat the process and reset while the com port isn't active, it works 100% of the time.
So assuming this is some weird windows / USB issue and not one linked to the device.

Anyway, its working now and I know what is going on.

Now all this has been done because it annoyed me. I'm not going to use the virt com port for any diagnostics output, i'll hook up a usart connector that never drops and I don't have to worry about swapping over USB cables and all that ... but good to know.
Post Reply