Bare STM32 as USB Host always disconnects - Page 1
Forum section: electronics / projects

author: mortrek
author_rank: Contributor
timestamp: July 31, 2020, 12:40:06 am
content: I have an STM32L496RET bare chip on a Schmartboard QFP->DIP breakout put into a breadboard, with all the VDDs (inc VDDUSB) connected to the + source, which is currently the ST-Link V2 at ~3.3V, and they are all bypassed with 100nf caps. There is one bulk tantalum on the power rail as required in the datasheet. I'm using a TSX 10ppm 8.000MHz crystal for the HSE, with a PLL set up to 48MHz for the main clock and peripherals, including USB. The crystal is bypassed by two 20pf caps. The USB port is a type-A breakout that's connected to the respective DP and DM pins through series 22ohm resistors and bypassed w/47pf caps as per the MapleMini schematics, and an independent 5V PSU is being used to supply + and GND on the port. A voltage divider brings the 5V supply back to the PA9 VBUS sensing pin to ~3.3V when on. From what I can tell, and from the research that I've done, it's all connected properly but I could of course be totally wrong.I'm using STM32CubeIDE and autogenerating the USB_OTG_FS comm library and the USB_HOST library set for MTP (although I tested with mass storage and got the same results). When I run or debug the code w/ breakpoints on the autogenerated USBH_UserProcess switch cases, and then insert any camera or USB device, it always triggers on HOST_USER_DISCONNECTION. Obviously the chip sees something on the bus but is unable to properly connect.What are likely issues? Do you need photos? Screenshots of the clock config? I can try to mock up the circuit in a CAD program if needed, but it's pretty simple so far. Do all of the USB lines prior to the breakout need to be super short? Or maybe the crystal is too far from the chip since it's on a breakout, or 20pF is not the right cap value for stable operation? I've tried USB FS and LS and they both behave the same way. Is a breadboard not going to work for a USB host? I'm getting pretty frustrated at this point.Thank you for any suggestions.

author: MosherIV
author_rank: Super Contributor
timestamp: July 31, 2020, 07:53:51 am
content: Schematic and photos would help.QuoteNot a good idea. The usb lines are transmission lines, so perf board is going to ruin the line characteristics.QuoteI have never tried such a bare bones approach to usb interface.Most design I have worked with use a dedicated usb buffer chip.I am not sure the stm32 peripheral is capable of driving usb lines, as far as I am aware the peripheral requires an external usb buffer device to drive the D+ D- lines.I believe that is what most ST app notes show.In addition, USB is electrically 0V and 5V differential lines. The stm32 only provides 3.3V (or what ever the supply voltage is ) on the gpio lines, that includes all the perpherals. So the usb peripheral is not providing the correct voltages to drive the D+ D- lines. Some stm32 are 5V tolerant on the gpio pin, that means you can put 5V into the micro pin, it does NOT mean they will output 5V

author: Saimoun
author_rank: Frequent Contributor
timestamp: July 31, 2020, 08:36:15 am
content: I experienced a few times strange behavior with breadboards, especially if the metal clamps on the breadboard are a bit old/damaged.So I would definitely say try to solder a few cables - at least for the USB lines - and see if it makes any difference.About the way to connect the USB port I would not know if you did anything wrong but you might want to look at the schematics for some of their demo boards - for example the Disco-F4 board:https://www.st.com/en/evaluation-tools/stm32f4discovery.html#resourceAlso it would help if you showed the CubeMX configuration (a few screenshots) - in case there is something wrong there?

author: Saimoun
author_rank: Frequent Contributor
timestamp: July 31, 2020, 08:40:14 am
content: Quote from: MosherIV on July 31, 2020, 07:53:51 amIt definitely is possible to do USB directly with an STM32 since they do it themselves on their demo boards, but it's an interesting point about the 3.3V... I do not see any signal level shifter on their demo boards... I guess they just run at 3.3V?

author: mortrek
author_rank: Contributor
timestamp: July 31, 2020, 01:58:27 pm
content: I thought USB 1 and 2 used 3.3V or lower on data lines. Is the answer to this post herehttps://electronics.stackexchange.com/questions/190592/why-does-usb-have-vcc-5v-and-high-3-3vincorrect?Also the discovery board does not have a buffer or level shifter as far as I can see. The port goes almost direct to the pins. That's the same for every STM32 USB implementation I've seen so far.Do I need to pull up the D+ line like on the Discovery schematic? I'm looking at the one posted by simonlasnier. I've had trouble finding the info in the STM32L496 USB datasheets for *exactly* how to connect things, but I'll look again.I'll rereadhttps://www.st.com/resource/en/application_note/dm00296349-usb-hardware-and-pcb-guidelines-using-stm32-mcus-stmicroelectronics.pdfand to see if I got it all wrong.edit: Also part of why I chose this particular chip was that it had an on-chip USB FS PHYSedit2: So part of the problem is that the USB documentation mostly talks about acting as a USB device and covers little about being a USB Host. I've had to piece a lot together from other sites and from schematics... also my chip has the embedded pullup w/VBUS detection so I do not need to use an external resistor.

author: mortrek
author_rank: Contributor
timestamp: July 31, 2020, 03:16:28 pm
content: Here's my clocks. Probably all messed up...