Author Topic: STM32F103 usb problems  (Read 6606 times)

0 Members and 1 Guest are viewing this topic.

Offline HackedTopic starter

  • Contributor
  • Posts: 36
  • Country: hr
STM32F103 usb problems
« on: June 13, 2023, 09:07:41 pm »
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.
 

Offline GromBeestje

  • Frequent Contributor
  • **
  • Posts: 310
  • Country: nl
Re: STM32F103 usb problems
« Reply #1 on: June 13, 2023, 09:15:58 pm »
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.
 

Online thm_w

  • Super Contributor
  • ***
  • Posts: 9877
  • Country: ca
  • Non-expert
Re: STM32F103 usb problems
« Reply #2 on: June 13, 2023, 09:18:47 pm »
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.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline HackedTopic starter

  • Contributor
  • Posts: 36
  • Country: hr
Re: STM32F103 usb problems
« Reply #3 on: June 13, 2023, 09:36:49 pm »
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.

Damn 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-?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12495
  • Country: us
    • Personal site
Re: STM32F103 usb problems
« Reply #4 on: June 13, 2023, 10:12:59 pm »
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.
« Last Edit: June 13, 2023, 10:16:56 pm by ataradov »
Alex
 

Offline wraper

  • Supporter
  • ****
  • Posts: 19517
  • Country: lv
Re: STM32F103 usb problems
« Reply #5 on: June 13, 2023, 10:44:55 pm »
AMS1117 is not supposed to be used with a ceramic cap on its output and may oscillate.
 
The following users thanked this post: elecdonia

Offline HackedTopic starter

  • Contributor
  • Posts: 36
  • Country: hr
Re: STM32F103 usb problems
« Reply #6 on: June 14, 2023, 12:08:41 pm »
AMS1117 is not supposed to be used with a ceramic cap on its output and may oscillate.

Missed that part in datasheet  :palm:
Although voltage is ok, not oscillating, checked with oscilloscope, but good to know, thanks.
 


Online thm_w

  • Super Contributor
  • ***
  • Posts: 9877
  • Country: ca
  • Non-expert
Re: STM32F103 usb problems
« Reply #8 on: June 14, 2023, 09:44:04 pm »
there was this problem too on bluepill

http://amitesh-singh.github.io/stm32/2017/05/27/Overcoming-wrong-pullup-in-blue-pill.html

https://stm32duinoforum.com/forum/wiki_subdomain/index_title_Blue_Pill.html#Known_issues

Yes 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.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline HackedTopic starter

  • Contributor
  • Posts: 36
  • Country: hr
Re: STM32F103 usb problems
« Reply #9 on: June 18, 2023, 12:16:46 pm »
Hey, again me :)
After 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.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12495
  • Country: us
    • Personal site
Re: STM32F103 usb problems
« Reply #10 on: June 18, 2023, 03:52:19 pm »
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.
« Last Edit: June 18, 2023, 04:11:08 pm by ataradov »
Alex
 
The following users thanked this post: thm_w

Offline wraper

  • Supporter
  • ****
  • Posts: 19517
  • Country: lv
Re: STM32F103 usb problems
« Reply #11 on: June 18, 2023, 05:20:09 pm »
Capacitors won't change anything. While it theoretically can oscillate, it is not that easy to actually make it oscillate, you are fine.
Rigol 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.
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 5829
  • Country: dk
Re: STM32F103 usb problems
« Reply #12 on: June 18, 2023, 07:35:12 pm »
Capacitors won't change anything. While it theoretically can oscillate, it is not that easy to actually make it oscillate, you are fine.
Rigol 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.

remember 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
 

Offline HackedTopic starter

  • Contributor
  • Posts: 36
  • Country: hr
Re: STM32F103 usb problems
« Reply #13 on: June 18, 2023, 09:35:24 pm »

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 use HAL drivers for USB, but I don't have any debug message, on blue pill code works perfect.

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.

Will check both tommorow.
Thanks on help.
 

Offline HackedTopic starter

  • Contributor
  • Posts: 36
  • Country: hr
Re: STM32F103 usb problems
« Reply #14 on: June 18, 2023, 09:36:29 pm »
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.

What voltage regulators would you recommend?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12495
  • Country: us
    • Personal site
Re: STM32F103 usb problems
« Reply #15 on: June 18, 2023, 09:54:11 pm »
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.
« Last Edit: June 18, 2023, 09:56:54 pm by ataradov »
Alex
 

Offline HackedTopic starter

  • Contributor
  • Posts: 36
  • Country: hr
Re: STM32F103 usb problems
« Reply #16 on: June 21, 2023, 07:52:28 pm »
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?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12495
  • Country: us
    • Personal site
Re: STM32F103 usb problems
« Reply #17 on: June 21, 2023, 08:03:57 pm »
Your oscillator may not start correctly or fast enough, for example.
Alex
 

Offline sd

  • Supporter
  • ****
  • Posts: 51
  • Country: ro
Re: STM32F103 usb problems
« Reply #18 on: June 21, 2023, 08:14:04 pm »
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.
« Last Edit: June 21, 2023, 08:17:45 pm by sd »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12495
  • Country: us
    • Personal site
Re: STM32F103 usb problems
« Reply #19 on: June 21, 2023, 08:38:51 pm »
Edit: C2 and C3 should be connected to GND.
Well, this would certainly make the clock not work reliably.
Alex
 

Offline HackedTopic starter

  • Contributor
  • Posts: 36
  • Country: hr
Re: STM32F103 usb problems
« Reply #20 on: June 21, 2023, 08:46:57 pm »
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.

H2 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?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12495
  • Country: us
    • Personal site
Re: STM32F103 usb problems
« Reply #21 on: June 21, 2023, 08:52:27 pm »
According to datasheet: 12pF,20pF,or specify, I choose 20pF.
This 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.

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.
What specific schematic did you use? There are a lot of them floating around.

Is that the problem?
Yes.
« Last Edit: June 21, 2023, 08:55:17 pm by ataradov »
Alex
 

Offline HackedTopic starter

  • Contributor
  • Posts: 36
  • Country: hr
Re: STM32F103 usb problems
« Reply #22 on: June 21, 2023, 09:02:13 pm »
According to datasheet: 12pF,20pF,or specify, I choose 20pF.
This 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.

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.
What specific schematic did you use? There are a lot of them floating around.

Is that the problem?
Yes.

I used schematic from here https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill.html
Ok. I will ground them, hope that solves my usb problems.
Thanks ataradov and sd for help :)

 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12495
  • Country: us
    • Personal site
Re: STM32F103 usb problems
« Reply #23 on: June 21, 2023, 09:18:25 pm »
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.
Alex
 

Offline HackedTopic starter

  • Contributor
  • Posts: 36
  • Country: hr
Re: STM32F103 usb problems
« Reply #24 on: June 21, 2023, 09:26:33 pm »
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?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->