cancel
Showing results for 
Search instead for 
Did you mean: 

Virtual COM Port demo in USB Dev kit

spencer
Associate II
Posted on April 29, 2008 at 21:24

Virtual COM Port demo in USB Dev kit

10 REPLIES 10
spencer
Associate II
Posted on May 17, 2011 at 12:28

Here are some lines from the Set_System() function called from main.c in the Virtual COM Port demo bundled in the USB Developer Kit:

/* PD.09 used as USB pull-up */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;

GPIO_Init(GPIOD, &GPIO_InitStructure);

What does PD.09 have to do with USB? Does this demo firmware work anywhere?

USBDP and USBDM map to PA11 and PA12 on this chip. Why is the demo coded this way?

lanchon
Associate III
Posted on May 17, 2011 at 12:28

you may want the USB device to disconnect from and reconnect to the host in order to cause reenumeration (to switch the device ''personality'', for instance), and you may not want the user to have to physically perform the action. I think you can do this by gating the the pullup to the USB data+ line. check out the DISC line in

http://www.olimex.com/dev/images/ARM/ST/STM32-H103-sch.gif

(it should be driven open drain, or else too much current will flow through R27 into Q3).

also, when the stm32 is powered externally (not from USB) you might want to detect the USB power bus (see the USB_P signal).

spencer
Associate II
Posted on May 17, 2011 at 12:28

Thank you for the reply, lanchon, and I will save this circuit diagram for future reference.

When I disconnect and reconnect the USB connector, I believe that the only thing that happens is that the PC detects a voltage change. It is not getting any information about the type of device, and so it says ''Unknown Device.''

I don't think that my STM32 is receiving anything from the PC, even though I know the PC is transmitting because I can see well-formed data with the oscilloscope when I plug in the connector.

Whatever else is going on, the code has to be wrong. It is doing things to PD.09, which doesn't exist on this chip.

[ This message was edited by: spencer1 on 03-04-2008 02:00 ]

lanchon
Associate III
Posted on May 17, 2011 at 12:28

what I meant was that that software was probably written for a board that has a circuit similar to the one I pointed you to. since it's using PD9 it must be a 100 pin package, so I guess it's probably for the ST eval board. check that schematic. it wouldn't surprise me if olimex just copied the USB part from ST's board.

spencer
Associate II
Posted on May 17, 2011 at 12:28

That's exactly how this is playing out.

I just downloaded the CD-ROM files for the STM32-Primer, and found these extra lines in hw_config.c in the Virtual COM Port project:

/* Configure USART1 Rx (PA.10) as input floating */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Configure USART1 Tx (PA.09) as alternate function push-pull */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOA, &GPIO_InitStructure);

They weren't there in the first version I got.

But there is still this:

/* PD.09 used as USB pull-up */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;

GPIO_Init(GPIOD, &GPIO_InitStructure);

Obviously PD.09 isn't the right pin, but what is the right pin for this?

I don't know what ''USB pull-up'' they mean. Back to the manual I go...

lanchon
Associate III
Posted on May 17, 2011 at 12:28

ok, I looked at ST's eval schematic. sure enough PD9 is connected via JP1 to a USB pull-up circuit. when PD9 is driven low, the pull-up on DATA+ is activated. PD9 shouldn't be driven high (must be configured as open drain). JP1 can be set to activate the pull-up all the time and free PD9.

> I don't know what ''USB pull-up'' they mean

a USB device is detected when it pulls up the DATA+ line. if it doesn't, the host thinks the USB socket is empty.

> Obviously PD.09 isn't the right pin, but what is the right pin for this?

there's no right pin. you either pull the line up continuously with a resistor for instance, or via a circuit that the STM32 controls. it's your choice. look at the circuit you're using to see what -if anything- you need to do.

> I just downloaded the CD-ROM files for the STM32-Primer

just checked the primer. PB12 is used to gate the pull-up, but differently: you have to ground the pin to turn off the pull-up, otherwise it's on. (never drive high the pin, use open drain.) this means that if you do nothing, USB will work on the primer. (that's why the code works.) use of the PD9 in the primer is a mistake (with no consequences).

spencer
Associate II
Posted on May 17, 2011 at 12:28

Aren't pullup and pulldowns done internally on the STM32F103RBT?

I am looking at the STM32F101xx and 103xx Tech Ref Manual RM0008 page 75.

http://www.st.com/mcu/familiesdocs-110.html#Reference%20Manual

How are the GPIO registers supposed to be set for transmitting and receiving? Doesn't the STM32F103xxx have its own pullups and pulldowns? How does that relate to the USB 2.0 Spec (Figure 7-1 on page 120)?

Do you know of USB firmware anywhere that is proven to work on this chip?

I should add that I am not using the STM32-Primer. I am using the Reva motherboard with STM32F103B daughterboard.

[ This message was edited by: spencer1 on 04-04-2008 00:41 ]

bob239955
Associate II
Posted on May 17, 2011 at 12:28

If anyone can post a link to STs Eval Schematic that would be greatly appreciated.

lanchon
Associate III