STM32F103 usb problems - Page 1
Forum section: electronics / general

author: Hacked
author_rank: Contributor
timestamp: June 13, 2023, 09:07:41 pm
content: Hello all,I made a pcb design of button plate for sim racing, just a few buttons and encoders with usb. I test the program on blue pill and it all works, but when i try on my pcb from JLC i get "unknown usb device descriptor request failed" in windows.To be honest when I made design where I didn't bother to calculate exact trace width for usb traces for impedance matching because I read that for 12mbit speed it doesn't matter. my trace width is 0.254mm and lenght is 9mm for both D+ and D- (differential routing).Is that maybe a issue or something else?Pictures of schematic and pcb are in attachement.Any help would be appreciated.

author: GromBeestje
author_rank: Frequent Contributor
timestamp: June 13, 2023, 09:15:58 pm
content: The 20 Ohm resistors R2 and R3 are not needed for an STM32F1 design as those impedance matching resistors are built in the microcontroller.However, I'm note sure if placing them would cause such a failure though, but you could try replacing them with 0 Ohms to see what happens.

author: thm_w
author_rank: Super Contributor
timestamp: June 13, 2023, 09:18:47 pm
content: As Grom says 20 ohm isn't needed but they are present on the bluepill and works there.The traces you have are fine for low speed USB.Your green and white D+/D- wires are backwards, you can try flipping those.

author: Hacked
author_rank: Contributor
timestamp: June 13, 2023, 09:36:49 pm
content: Quote from: thm_w on June 13, 2023, 09:18:47 pmDamn it works when I change the wires, but I need to unplug/plug usb cable 10 times to be recognized, probably due to bad soldering. Isn't D+ DP and DM is D-?

author: ataradov
author_rank: Super Contributor
timestamp: June 13, 2023, 10:12:59 pm
content: In the cables D+ is green and D- is white. Your picture shows them reversed, assuming you are using a standard cable.Note that quick google search pulls an incorrect image. It actually finds the same exact picture marked both ways.

author: wraper
author_rank: Unknown
timestamp: June 13, 2023, 10:44:55 pm
content: AMS1117 is not supposed to be used with a ceramic cap on its output and may oscillate.

author: Hacked
author_rank: Contributor
timestamp: June 14, 2023, 12:08:41 pm
content: Quote from: wraper on June 13, 2023, 10:44:55 pmMissed that part in datasheetAlthough voltage is ok, not oscillating, checked with oscilloscope, but good to know, thanks.

author: coromonadalix
author_rank: Super Contributor
timestamp: June 14, 2023, 04:05:01 pm
content: there was this problem too on bluepillhttp://amitesh-singh.github.io/stm32/2017/05/27/Overcoming-wrong-pullup-in-blue-pill.htmlhttps://stm32duinoforum.com/forum/wiki_subdomain/index_title_Blue_Pill.html#Known_issues

author: thm_w
author_rank: Super Contributor
timestamp: June 14, 2023, 09:44:04 pm
content: Quote from: coromonadalix on June 14, 2023, 04:05:01 pmYes but OP has used the correct pullup in their schematic.So its kinda odd it would work reliably on bluepill but not their PCB, but we don't know which version they have.

author: Hacked
author_rank: Contributor
timestamp: June 18, 2023, 12:16:46 pm
content: Hey, again meAfter changing green and white wires it works, but now have another issue. If I disconnected and connect the usb cable 10 times, only 5 times it will be recognized as USB HID device, the other 5 times I get "unknown usb device descriptor request failed" in device manager. Why is that happening?In attachements are corrected schematic and pcb design (I removed series resistor to DP and DM).I connected oscilloscope to 3.3V to check if I have oscillations because I used ceramic capacitor on AMS1117 output but there is none, at least I didn't saw them.PCB has 4 layers, inner layers are Vcc(3.3V output from AMS1117) and GND.If I remove series 20ohm resistors and if I change ceramic capacitor to tantalum, will that solve my problem?Is directly soldering wires to usb pins like I did bad practice? Is it better to use some kind of connector (usb micro or JST 4 pin connector?Any help would be appreciated before I order new batch from JLCPCB.

author: ataradov
author_rank: Super Contributor
timestamp: June 18, 2023, 03:52:19 pm
content: Capacitors won't change anything. While it theoretically can oscillate, it is not that easy to actually make it oscillate, you are fine. Just use better voltage regulators next time, there are lots of them that are stable with ceramic capacitors.Resistors while not necessary, are not likely to be the issue. But replace them with 0 Ohm for all future experiments.Direct soldering is also fine.The issue is likely on the firmware side. With a fixed pull-up resistor on D+, host will start enumeration process right after the device plugged in. Your initialization can't take too long, if you print some debug messages at the beginning or something like that, it might be the reason.I would look at the DM/DP signals on the scope to check that they are visually correct - no noise, no weird glitches.And check that your clock is starting in time and is stable.And do not re-order boards until you debug this one. You will be just be wasting time and money. Your current board is good enough for debugging.

author: wraper
author_rank: Unknown
timestamp: June 18, 2023, 05:20:09 pm
content: Quote from: ataradov on June 18, 2023, 03:52:19 pmRigol engineers achieved that in DS-2000 oscilloscope series on multiple power rails, although it happened not in all oscilloscopes due to different 1117 vendors used.

author: langwadt
author_rank: Super Contributor
timestamp: June 18, 2023, 07:35:12 pm
content: Quote from: wraper on June 18, 2023, 05:20:09 pmremember working on a RF device many years ago, took while to figure out why the sensitivity was much worse when running on battery than when running on USB, turned out to be the LDO (don't remember if it was an 1117 ) oscillating but only when the input was right at the usual battery voltage

author: Hacked
author_rank: Contributor
timestamp: June 18, 2023, 09:35:24 pm
content: Quote from: ataradov on June 18, 2023, 03:52:19 pmI use HAL drivers for USB, but I don't have any debug message, on blue pill code works perfect.Quote from: ataradov on June 18, 2023, 03:52:19 pmWill check both tommorow.Thanks on help.

author: Hacked
author_rank: Contributor
timestamp: June 18, 2023, 09:36:29 pm
content: Quote from: ataradov on June 18, 2023, 03:52:19 pmWhat voltage regulators would you recommend?

author: ataradov
author_rank: Super Contributor
timestamp: June 18, 2023, 09:54:11 pm
content: For lower currents I usually use MIC5504 or SC662K.SC662K got discontinued recently, but there are many equivalents. XC6206P332MR is one, which has the same top marking. I assume there was some transfer of ownership or something like that.For higher current, there is TLV1117LV, which is a more modern version, which is stable with any capacitors. Note that this is a low input voltage version, but it is ideal for USB-powered designs.

author: Hacked
author_rank: Contributor
timestamp: June 21, 2023, 07:52:28 pm
content: Ok, I inspecteded DP/DM lines as suggested, and when it doesn't get recognized data lines are visible with no glitches, but then after second or two it becomes flat.Although now when I soldered it again it's better but still in 10 times I plug it, 2 or 3 times it doesn't get recognized. If it's firmware related why it works on blue pill?

author: ataradov
author_rank: Super Contributor
timestamp: June 21, 2023, 08:03:57 pm
content: Your oscillator may not start correctly or fast enough, for example.

author: sd
author_rank: Unknown
timestamp: June 21, 2023, 08:14:04 pm
content: Is the H2 jumper installed or BOOT0 is floating?Also, what's the datasheet load capacitance for X1?Edit: C2 and C3 should be connected to GND.

author: ataradov
author_rank: Super Contributor
timestamp: June 21, 2023, 08:38:51 pm
content: Quote from: sd on June 21, 2023, 08:14:04 pmWell, this would certainly make the clock not work reliably.

author: Hacked
author_rank: Contributor
timestamp: June 21, 2023, 08:46:57 pm
content: Quote from: sd on June 21, 2023, 08:14:04 pmH2 jumper is installed on BOOT0 (connected to GND).According to datasheet: 12pF,20pF,or specify, I choose 20pF.You are right, C2 and C3 should be connected to GND, didn't know that, I used blue pill schematic as reference and they didn't connect capacitors to GND, or is schematic is wrong.Is that the problem?

author: ataradov
author_rank: Super Contributor
timestamp: June 21, 2023, 08:52:27 pm
content: Quote from: Hacked on June 21, 2023, 08:46:57 pmThis is the crystal intrinsic parameter. They sell them with 12 pF, 20 pF or any value you specify on a special order. But the load capacitors on the board would not be this value, they would depend on the type of the oscillator and its internal design. Usually the datasheet would have a formula showing how to calculate necessary external capacitors for a given crystal.But it is not that sensitive in practice, so don't change this now, ground them first and see if that works.Quote from: Hacked on June 21, 2023, 08:46:57 pmWhat specific schematic did you use? There are a lot of them floating around.Quote from: Hacked on June 21, 2023, 08:46:57 pmYes.

author: Hacked
author_rank: Contributor
timestamp: June 21, 2023, 09:02:13 pm
content: Quote from: ataradov on June 21, 2023, 08:52:27 pmI used schematic from herehttps://stm32-base.org/boards/STM32F103C8T6-Blue-Pill.htmlOk. I will ground them, hope that solves my usb problems.Thanks ataradov and sd for help

author: ataradov
author_rank: Super Contributor
timestamp: June 21, 2023, 09:18:25 pm
content: Yes, this is either a mistake or an intentional small modification to prevent blind copying. You can see that 32 kHz oscillator is properly grounded. And on the board you can see those capacitors connected to the ground plane.

author: Hacked
author_rank: Contributor
timestamp: June 21, 2023, 09:26:33 pm
content: Just one more question.In attachement you can see part of schematic where RXJXF42001 funky switch is connected. buttons work fine (directions and push), but encoder acts strange.When I rotate it left or right one detent signal stays at Vcc voltage instead of GND (not always, but sometimes), why is that? burns encoder acts as it's supposed so.Did I made mistake in schematic?

author: ataradov
author_rank: Super Contributor
timestamp: June 21, 2023, 09:56:11 pm
content: It is hard to figure out the exact pinout from the Alps document. I see no mistakes in the schematic, but it is hard to verify the pinout.I would take the encoder without the board and measure its behavior using a multimeter.

author: Hacked
author_rank: Contributor
timestamp: July 14, 2023, 06:54:58 am
content: New pcb's arrived yesterday and USB is working without issues.Thank you all