3
\$\begingroup\$

I have STM32f107 MCU soldered on custom board. I would like to use USB peripheral in CDC mode. I connected pins PA11 (D-), PA12 (D+) and GND directly to a USB CDC cable which leads to the computer. The device is self-powered, thus I don't use VDD pin.

In STM32Cube I created a new project, configured only USB_OTG_FS device and USB_DEVICE in middleware section. Also I configured High-Speed Clock in RCC section so that USB peripheral has 48 MHz clock.

Then I generated the program skeleton and uploaded it to the MCU. Unfortunately it does not work. I think the main problem is that there is no voltage on D+ pin so that the computer is not able to recognize a new device. When I execute the CDC_Transmit_FS function, the processor falls into the Hard fault.

The strangest thing is that when I configure STM32F429 MCU on Discovery kit in the similar way, the USB works out of the box. I tried to diff the source code, but I haven't found any crucial difference (except the STMF4 MCU uses USB High speed OTG in full speed mode).

Please does anybody have some experience on using USB with STM32F107 and STM32CubeMX program skeleton?

EDIT: When I run the MCU in bootloader mode, the D+ line is pulled to 3V3 - therefore I think the MCU really does not need any external pull-up (also datasheet says this).

EDIT2: Does anybody know what Activate VBUS option in CubeMX exactly do? I can understand it in Host mode, but what does it do in Device-Only mode?

\$\endgroup\$
2
  • \$\begingroup\$ With ST parts you typically need the pullup resistor on a USB data line that indicates the device speed to be external - the usually do not include it within the chip. \$\endgroup\$ Commented Aug 11, 2016 at 17:39
  • 1
    \$\begingroup\$ @ChrisStratton Other ST parts may require this, but not this specific microcontroller. I have a working project with this IC and no data pullups. \$\endgroup\$
    – bitsmack
    Commented Aug 11, 2016 at 18:04

5 Answers 5

3
\$\begingroup\$

Even though the device is self-powered, you still need to connect the USB's Vbus (pin 1) to the microcontroller's OTG_FS_VBUS (pin PA9).

This isn't to provide power, but to allow the microcontroller to know when to start up the USB subsystem.

\$\endgroup\$
2
  • \$\begingroup\$ Are you sure? I tried the 3-wire connection on STMF429I Discovery kit (I bypassed the official microUSB connector and connected USB cable directly to appropriate MCU pins) and it worked without problems. I think the most important thing is that D+ data line is pulled to 3V3 and this is signal for the computer to start USB communication. \$\endgroup\$ Commented Aug 12, 2016 at 7:29
  • \$\begingroup\$ @klasyc I see by your answer that Vbus sensing is required in Device mode, but can be disabled in Host mode. Thanks for coming back and letting us know! \$\endgroup\$
    – bitsmack
    Commented Aug 12, 2016 at 19:05
1
\$\begingroup\$

Thank you for both answers, you are right. To sum it up I will make another answer. I hope someone will find this useful.

  • USB connection requires GND, D+ and D- lines. VBUS is used only for USB cable detection.
  • VBUS sensing can be disabled at least on some MCUs. In this case, VUSB wire is not necessary.
  • When you enable USB OTG peripheral in CubeMX, it does not light up the VBUS pin even it is necessary (unless you check the Activate VBUS checkbox).
  • I cannot say what does Activate VBUS option do in Device mode. I tried to generate sources both with and without this option and both projects required VBUS line to make USB working.
  • When you generate code from CubeMX (I am using HAL version 1.31) with USB CDC in Device mode, the generated code really works on both stm32f1 and stm32f4 cores out of the box. Even if you don't implement send/receive handlers, the MCU is still recognized as VCP.
  • I wanted to disable VBUS sensing on STM32F107 by writting zero to VBUSBSEN bit in GCCFG register, but I didn't succeed or the value has been overwritten
    by the usb library (the library is quite complicated, thus I don't know where exactly put the register assignment). Also it is interesting that reference manual on the page 926, section 28.17.3 says that in Device mode the VBUS sensing must be on.
  • STM32F107 MCU does not require any pull-up resistor to make the USB working.

If I have stated anything incorrect, please correct me in the comments.

Klasyc

\$\endgroup\$
1
\$\begingroup\$

One way to register a high level on the VBUS pin (PA9) in software (or without a physical connection), is to uncheck the "Activate_VBUS" checkbox in CubeMx and make PA9 a GPIO output, with the default level being high. This worked for me with a STM32F105 which has the same USB_OTG_FS Stack as the F107. CubeMx will highlight a warning, but this can be ignored. The device enumerates as it should.

\$\endgroup\$
1
  • \$\begingroup\$ oh wow! that helped! \$\endgroup\$
    – viteo
    Commented Feb 26 at 13:22
0
\$\begingroup\$

That pull-up R on D+ (or D-) is used to indicate the USB speed of the device. While host can detect the plugged device by this pull-up, in your case your have USB Device (Slave). And since it is self powered, as @bitsmack answered it shall detect connection by monitoring VBUS and start USB operation.

If you configured USB peripheral as dual role/OTG, you have to also connect USB_OTG_xx_ID pin to ID/OTG pin in your micro-USB connector.

For CDC, in CubeMX you can configure your device as Device_Only, connect VBUS (connector <-> MCU). If using micro USB connector then also wire connectors ID/OTG <-> GND.

\$\endgroup\$
5
  • \$\begingroup\$ I still cannot figure out why STM32F429 works without VBUS wire and STM32F107 not. Do you think it is a hardware difference of both MCUs? \$\endgroup\$ Commented Aug 12, 2016 at 8:33
  • \$\begingroup\$ You didn't mentioned your USB connector type. If yours is USB micro then you have to ground ID/OTG pin. STMF4 board surely handles ID/OTG pin correctly by software. Regarding VBUS, in STMF4 it is already connected, somehow it 'thinks' that device is connected, even if you using other 3 pins. Maybe you can turn off VBUS detection in software. \$\endgroup\$
    – Flanker
    Commented Aug 12, 2016 at 9:38
  • \$\begingroup\$ I use USB A connector connected to the computer and on the other side I connect the white, green and black wire directly to the discovery kit's pins (the same circuit as for stm32f107). Therefore I think the VBUS pin is not necessary. \$\endgroup\$ Commented Aug 12, 2016 at 9:42
  • \$\begingroup\$ Since you didn't have VBUS connected, you have to disable VBUS sensing: electronics.stackexchange.com/questions/124063/… \$\endgroup\$
    – Flanker
    Commented Aug 12, 2016 at 9:53
  • \$\begingroup\$ I haven't succeeded in disabling VBUS sensing, but connecting VBUS pin really helped. Since I have to much observations, I wrote them in separate answer. Thank you for your assistance. \$\endgroup\$ Commented Aug 12, 2016 at 11:54
0
\$\begingroup\$

VBUS sensing is mandatory for self-powered devices (slaves). USB specification demands that a device can't source power to D lines in the absence of VBUS. A self-powered device must disconnect the pull-up resistor as soon as VBUS disappears.

For example, a self-powered device may be physically connected to a PC which is powered down. As the device still has power, it sources power to D line unless it can detect the absence of VBUS.

I'm not sure what happens if you fail to satisfy this requirement. I guess your device may work well with some hosts but not with others. Or it works most of the time but may cause some strange host behavior sometimes. It's best to follow the USB specification and not take risks.

VBUS sensing is not required for bus-powered devices, as there is no risk of driving D lines when the VBUS is gone. When VBUS is gone, the device will be unpowered too, obviously.

OTG_FS hardware of STM32 manages its internal pull-up resistor automatically, if VBUS sensing is activated. The other USB_Device hardware, which is present in some other STM32 microcontrollers, doesn't have this feature and needs additional software and external pull-up.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.