Skip to main content
longchair
Associate III
October 24, 2012
Question

USB D+ Pullup with gpio

  • October 24, 2012
  • 24 replies
  • 8972 views
Posted on October 24, 2012 at 17:13

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.

    This topic has been closed for replies.

    24 replies

    longchair
    longchairAuthor
    Associate III
    October 26, 2012
    Posted on October 26, 2012 at 14:59

    Okay, I have followed my investigations.

    I decided to use only My Olimex H103 Board and wire on a prototyping board the circuit which is on my PCB. The board has an embedded USB connector on which my code works, but all the pins are available on the board connection as well.

    the board schematics is here :

    https://www.olimex.com/Products/ARM/ST/STM32-H103/resources/STM32-H103-sch.gif

    I have cut an usb cable and connected :

    - the USB 5V to Vin pin of the board (EXT2-26)

    - the USB GND to board GND (EXT2-25)

    - The D- to USBDM pin (EXT1-1)

    - The D+ to USBDP pin (EXT1-3)

    - the PC11 (which is the pin used to drive the usb_disconnect on the board) to D+ through a 1K5 resistor.

    This will give me a failure when i reset the board in this configuration (Device is detected but as unknown device). What I can see is that I will get a reset event in this configuration, but it will not go further.

    If I use the H103 board connector with an USB cable it works just fine and is detected 100%.

    The only obvious difference I can see between my ''external'' setup and the board internal setup is the transisitors used in the usb disconnect line. I do'nt understand how this could give a different behaviour, but it does.

    I guess all I have to try is to reproduce the transistor setup on my prototyping board to see if it changes anything, but it just doesn't make sense to me :)

    Any enlighting is welcome ;)

    Lionel.
    tsuneo
    Associate II
    October 26, 2012
    Posted on October 26, 2012 at 16:44

    > - the PC11 (which is the pin used to drive the usb_disconnect on the board) to D+ through a 1K5 resistor.

    Try another port pin, which has no extra circuit on the board.

    On the Olimex board, PC11 connects to a transistor / resistors circuit for the original pull-up. It should affect to the behavior.

    Tsuneo

    longchair
    longchairAuthor
    Associate III
    October 26, 2012
    Posted on October 26, 2012 at 17:11

    Well I have also tried with PC10 which is not connected to anything, and it still gives the same result :(

    tsuneo
    Associate II
    October 26, 2012
    Posted on October 26, 2012 at 22:17

    > Well I have also tried with PC10 which is not connected to anything, and it still gives the same result :(

    Heh, on my side, it works well. At last, I found my Olimex H103 board out of piled-up closet ;) Attached a 1k5 resistor across EXT1-3 (USBDP) - EXT1-8 (PC10) Modified ''Virtual_COM_Port'' example, as follows,

    STM32_USB-FS-Device_Lib_V3.4.0\Project\Virtual_COM_Port\src\hw_config.c
    void Set_System(void)
    {
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
    }
    void USB_Cable_Config (FunctionalState NewState)
    {
    // for PC10 
    uint32_t tmpreg = GPIOC->CRH & 0xFFFFF0FF; // clear pin 10 MODE/CNF
    if (NewState != DISABLE)
    {
    GPIOC->BSRR = GPIO_Pin_10; // set pin 10
    GPIOC->CRH = tmpreg | 0x00000200; // GPIO OUT, push-pull
    }
    else
    {
    GPIOC->CRH = tmpreg | 0x00000400; // floating input
    }
    }

    Windows recognized the board without any problem. Tsuneo
    longchair
    longchairAuthor
    Associate III
    October 27, 2012
    Posted on October 27, 2012 at 21:26

    Hello,

    First of all I wanted to thank you for the time you spent trying to help me to sort this out :)

    OK, In order to make sure that i didn't change anything wrong in the USB library I re downloaded it, and tried to have the Vcom sample work again.

    I selected the STM3210B-EVAL config.

    I changed in platformconfig the port definition as follows :

    #define USB_DISCONNECT GPIOC

    #define USB_DISCONNECT_PIN GPIO_Pin_10

    #define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOC

    Then I replaced both functions with the code you pasted in previous post.

    When i run the code I still have the exact same problem.

    Here is a picture of my setup :

    http://i44.photobucket.com/albums/f8/LongChair/photo.jpg

    the wires on the bottom left of the picture come from the USB plug connected to my PC.

    Then I have

    VUSB from cable (red) connected to EXT2-26 (VIN) with a red wire

    USB Gnd from cable (black) connected to EXT2-25 (GND) with a black wire

    USB D- from cable (green) connected to USB DM (EXT1-1) with a green wire

    USB D+ from cable(white) connected to USB DP (EXT1-3) with a Yellow wire.

    PC10 on the board (EXT1-8) connected to USBDP through a 1K5 resistor with a red wire.

    I still have the same issue. Have you been testing in the same conditions ? :)

    By the way I am running Win 7 - 64 bits.

    I have the 64 bit driver installed and it will work fine with a USB connector connected on the board USB port.

    Thanks.

    tsuneo
    Associate II
    October 28, 2012
    Posted on October 28, 2012 at 02:02

    On your picture, the connection of D+/D- line of the cut-out USB cable is swapped.

    Typical cable coloring, defined on the USB spec,

    VBUS : Red

    D-   : White

    D+   : Green

    GND  : Black

    Tsuneo

    longchair
    longchairAuthor
    Associate III
    October 28, 2012
    Posted on October 28, 2012 at 09:13

    Hi Tsuneo,

    Well you are 100% right. That is wierd.You check and recheck things and still it's under your eyes and cannot see it :)

    OK so I have swapped the D+ / D- wires and tried your code -> Works

    Now Try My code in the same configuration -> Works.

    Now try my new PCB in the PB4 Configuration (after remap) and this doesn't work.

    I have rechecked the D+ / D- Data lines to make sure and didn't find any inversion.

    I have attached some screenshot of my eagle PCB hightlighting the D+ / D- lines just in case you see anything :

    this is the D- Line path :

    http://i44.photobucket.com/albums/f8/LongChair/Divers/D-.jpg

    This is the D+ line path from STM to USB connector:

    http://i44.photobucket.com/albums/f8/LongChair/Divers/D_1.jpg

    This is the D+ line pullup connected to PB4:

    http://i44.photobucket.com/albums/f8/LongChair/Divers/D_2.jpg

    When the line is pulled up I can measure The 3.3V (3.254) aobe the pullup resistor, so I assume there is no specific problem with PB4. I'll try to solder some wire on PC10 which is not connected on my board but soldering wires on stm32 pins is tricky :p

    When i look at the olimex board, I can see some other components on the line which I don't have :

    - The U3 (diode bridge) but when I wire the USB externally as on my pciture, that shouldn't make a diff

    - The 22 ohm in line resitors, but that the same, when wiring externally that should not make a difference.

    I also have seen that there is another Quartz on the Olimex board (Q2) which is located between PC13 / PC14. From what I have read this is used for RTC clock ... but i'm not sure if this would be used for USB.

    My only track at the moment is to try to use PC10 on my board, but I am quite pessimistic about the fact that it will fix it. I'll try it and report here anyways ;)

    If you have any other idea ... they will be more than welcome :)

    Lionel.

    zzdz2
    Associate
    October 28, 2012
    Posted on October 28, 2012 at 13:09

    Just swap D+/D- and see if it works, you can solder USB wires directly to the board and bypass the socket.

    longchair
    longchairAuthor
    Associate III
    October 28, 2012
    Posted on October 28, 2012 at 18:07

    I cut an usb cable and inserted pins on the two halves in order to be able to cross the wires with jumper cable

    Wether I cross D-/D+ or not i get the same result -> unknown device.

    zzdz2
    Associate
    October 29, 2012
    Posted on October 29, 2012 at 08:47

    I'm out of ideas, i only found one thing that may be applicable:

    http://www.usb.org/developers/usbfaq#sig6