Page 2 of 2

Re: usb_serial stops working after reset

Posted: Fri Oct 18, 2013 9:31 am
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.

Re: usb_serial stops working after reset

Posted: Fri Oct 18, 2013 9:43 am
by alexblack
One remark: for STM32F4 (and possible for F3) you must configure USB pins in "Alternate IN" mode in usb_lld_connect_bus().

Re: usb_serial stops working after reset

Posted: Fri Oct 18, 2013 9:59 am
by Giovanni
Thanks for that code, I will update the board files.

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

Giovanni

Re: usb_serial stops working after reset

Posted: Wed Oct 23, 2013 12:20 am
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.

Re: usb_serial stops working after reset

Posted: Wed Oct 30, 2013 9:24 pm
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

Re: usb_serial stops working after reset

Posted: Wed Oct 30, 2013 11:20 pm
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.

Re: usb_serial stops working after reset

Posted: Fri Nov 01, 2013 8:29 pm
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

Re: usb_serial stops working after reset

Posted: Fri Nov 01, 2013 10:53 pm
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.