2012-10-24 08:13 AM
Hello everyone,
I have been experiencing an issue with USB recently on which I wouls need some tips. I have an Olimex H103 board running a STM32F103 chip. I have been running my code on it and usb works fine. I have made my own board for an application and implemented the USB line slighly differently. In order to make the line pullup, I have used a GPIO line. So in my configuration PB4 is configured as PP output, connected to a 1K5 resistor which is connected to the D+ Line. from the code which is tunning on my olimex board I only had to modify : - The GPIO Output port used for USB DISCONNECT - The State of the IO in USB_Cable_Config function (I need to invert the actuation because I have a PP output instead of OD). When I startup the program, the USB is initilialized, when the pullup is activated, my PC is detecting a device, But I don't get any further, no interruption is coming, and windows will tell that the device is unknown. When I run this same code on olimex, I get interrupts right after the line is pulled up, which are completed the detection process. I have tested the continuity of the 4 pins up to the chip and they all seem ok. I would like to know if this way to pullup the line with a GPIO is valid and if you would have an idea of what might go wrong. Thanks for your suggestions :) Lionel.2012-10-24 09:50 AM
> So in my configuration PB4 is configured as PP output, connected to a 1K5 resistor which is connected to the D+ Line.
Do you see any glitch on a scope, while the ''USB_DISCONNECT'' port is configured to PP? A glitch may cause too early connection, before your firmware calls USB_Cable_Config() Ports come up in floating-input mode, at MCU power up. It's fine for disconnection state of D+ pull-up. To move the port into connection state, - Put '1' to the port with GPIOx_BSRR - Set the port mode to PP at GPIOx_CRL To get back to disconnection state, set the port to floating-input mode. Tsuneo2012-10-24 10:07 AM
Hello,
Well I have removed the GPIO initialization of PB4 which was occuring before the Calble_Config. and modified the cable config function as follows :
if (NewState == DISABLE)
{ GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure); } else { GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure); GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN); }It still shows the same issue, that is windows will show a detection when i Pullup in cable config, but no device will be identified.
On my olimex board, i seem to get some interrupts when the D+ line is pulled, which I don''t get on my own boards and i cannot understand why.
Any other ideas ?
thanks,
Lionel.
> So in my configuration PB4 is configured as PP output, connected to a 1K5 resistor which is connected to the D+ Line.
Do you see any glitch on a scope, while the ''USB_DISCONNECT'' port is configured to PP? A glitch may cause too early connection, before your firmware calls USB_Cable_Config() Ports come up in floating-input mode, at MCU power up. It's fine for disconnection state of D+ pull-up. To move the port into connection state, - Put '1' to the port with GPIOx_BSRR - Set the port mode to PP at GPIOx_CRL To get back to disconnection state, set the port to floating-input mode. Tsuneo2012-10-24 12:48 PM
You've checked the circuit around USB connector.
How about the crystal frequency? Olimex H103 board mounts 8MHz crystal. Tsuneo2012-10-24 01:12 PM
Yes the circuitry is very basic (maybe too much).
Basically USB Gnd goes to board gnd, D- goes directly to USBSM, D+ goes to USBDP, there is only this 1K5 pullup resistor between D+ line and PB4 IO. Vbus is powering my board through a 3.3V regulator. I also have a voltage divider on Vbus in order to detect usb cable connection. I don't use it yet though. I have plugged an USB cable to my board and checked that there was continuity between USBDM DP pins and the cable end D-, D+ lines at the other end of the cable. everything seems Ok. I have solderered another board, thinking that my STM chip was maybe defective, but the other board behaves the same. So either I have a problem in my USB harware implementation, or I am missing something. When you exit the initilialization sequence as it's done in the VCP sample, You are supposed to Get interrupts for negociation or ? the interrupts are configured and nothing comes. That's even more wierd that the same code seems to work on Olimex, except that they don't use the GPIO output directly thru a resistor. They drive some transistors in between. I dunno if this is the problem. I read somewhere else on the forum that this was supposed to work though. I guess anyways that if windows sees the pripheral being connected, the pullup is probably done correctly. I am not sure where to look at regarding what's the next step to look at ;) oh and regarding the crystal, I also have a 8 mhz crystal on my board ;) Lionel.2012-10-24 05:29 PM
I use very similar setup, except with 22 ohm resistors on DP/DM lines, everything works just fine, even with USB extention cable.
My GPIO configuration: GPIO_InitStructure.GPIO_Pin = USB_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(USB_GPIO, &GPIO_InitStructure); and enable/disable function: if (NewState != DISABLE) { GPIO_SetBits(USB_GPIO, USB_PIN); } else { GPIO_ResetBits(USB_GPIO, USB_PIN); } My question: is such pull-up circuit correct? It seems to work just fine, but I've noticed that many projects use additional transistors.2012-10-25 05:10 AM
I use similar circuit but no 22 ohm resistors and it works too.
Measured PP output voltage drop with 1k5 to ground is only about 40 mV, all seems OK.Edit:PB4 is JTAG function after reset, you need to disable jtag alternate function before using this pin. If you use jtag then better use some other pin.2012-10-25 06:51 AM
Yes this is a point I came thru :) At first I didn't even have the USB detection working because of this. Then I remapped JTAG (I am using SWD) and detection started to work.
The initialization seems to run fine as far as I can see, (RCC, GPIO, USB and then pullup). but right after the initiaization, STM will run in the main loop, PC will says that new peripheral has been detected, but nothing happens. I should be getting an interrupt after the line has ben pulled up right ? Lionel.2012-10-25 07:41 AM
> I should be getting an interrupt after the line has ben pulled up right ?
Yes. If everything would be working well, your firmware sees USB interrupt caused by bus reset.When a host (hub) detects voltage change at D+ (or D-) line while the port is disconnected, host puts bus reset after a while (100ms or so). Bus reset is SE0 (Single-Ended zero: both of D+/D- are 0) signaling, which lasts at least 10ms. The USB device engine (SIE) on the STM32F103 detects this signaling, and it raises USB_ISTR.RESET bit, which causes USB interrupt.> PB4 is JTAG function after resetSurely, it may be the cause of the trouble.The port state of JNTRST/PB4 after reset is not well documented on the datasheet/user manual.Try another port pin, which wakes up in GPIO.Tsuneo2012-10-25 08:00 AM
The initialization seems to run fine as far as I can see, (RCC, GPIO, USB and then pullup). but right after the initiaization, STM will run in the main loop, PC will says that new peripheral has been detected, but nothing happens. I should be getting an interrupt after the line has ben pulled up right ?
Right, I use PA13 as pullup, it's also jtag after reset and it works well.Maybe try different supply voltage, better supply capacitors or check if D+/D- is not swapped.