logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

USB HID Connection: Exploring Stm32f103 Communication with PC & Unknown Device Detection

Pegasus 9432 21
Best answers

Why does my STM32F103 USB HID device enumerate as an unknown device instead of working with the PC, and how can I get it to communicate properly?

The problem was the USB adapter/board layout and wiring, not the HID example itself; after rebuilding the board with short, straight D+ and D- traces, better component placement, and the corrected adapter, the STM32 Custom_HID example worked and Windows detected a new HID device [#11280926][#11285055] Check the USB enumeration details in Device Manager: if VID/PID are 0000/0000, enumeration is not really working, and a wrong clock/PLL setting can stop USB because HSI is too inaccurate for USB [#11271140] Make sure the D+ pull-up is correct, because an XP system can still show “unknown device” with the 1.5 kΩ pull-up, and two pull-ups in parallel are out of spec [#11270942][#11279043] Keep the USB data lines as short as possible and equal in length, and place the capacitors close to the regulator; one reply also suggested adding 47 pF capacitors on D+ and D- and using a known-good STM32F103 CDC example as a reference [#11280926][#11282230] In the end, 10 cm unshielded cables were not the blocker; the fixed PCB was [#11285055]
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 11269219
    Pegasus
    Level 11  
    Hello,
           I have stm32f103 with a set of alarm + made USB pad (it detects as an unknown device, so in my opinion it works): d + hooked to PA_12 D- to PA_11. And now the problem is the lack of any example that would work in USB HID or as DFU. I wrote my own codes - they do not work, I used ready-made projects from STM - they do not work. Now, gentlemen, help me, because maybe my PC is going crazy and I do not want to cooperate with STM32, and I'm exhausted for hours and I can not see the problem, so if someone was struggling with a similar problem and solved it, I ask for a hint. Because my craze is taking so that a simple operation like USB communication would be unrealized on such a popular uC.

    Added after 2 [hours] 4 [ minutes]:

     Continuing the topic of not having a USB HID connection with stm32f103, connecting the same pad without stm32 results in the detection of an unknown device. At the moment of connecting the UC to the USB pad, nothing changes - I still have an unknown device. I think this is because the PC does not get an answer from the device both with and without connected uC. Now the question is, if the PC reads the pad itself as an unknown device, can it be copied in an attempt to communicate with the uC? Noting that the voltage measurement indicates that D + has a voltage of 1.84V and is this the correct result?
  • ADVERTISEMENT
  • #2 11269741
    figa_miga
    Level 19  
    I can be wrong there, but if you have HID, then the system is supposed to immediately detect it without fuss. The pull up should be 3.3V. if you have less then ... maybe a power problem ?. Do you have all the tensions attached to Prock?

    USB is not a simple matter at all, judging by the content I would not put up with communication from scratch.
    My advice is, instead of guessing it's better to create a layout according to the manufacturer's demo and give him the right input - he must move, or you do something wrong.
  • #3 11269856
    Pegasus
    Level 11  
    Thanks for the answer, it is already a step forward - I removed two protection diodes, which limited my voltage to D + to 1.84V in the pad and now I have 3.3V. Answering the question: I use the set of alarms and all the voltages there are tucked up, only there was no USB output, so I made them myself. Unfortunately, the fact that in the pad I have 3.3V on D +, I still do not change anything. And speaking of the right batch to stm32f103 is the whole knot to check the operation of my board on the tested program under this stm32, because at this point you are right that he guesses what may not work. In case I have a working and tested program under this stm (completely regardless of what it does, even one diode which gives the status on PC), I would rule out one position, because at this point everything looks good both shallow and program, and in theory everything works and in Lipton is already a practice.
  • ADVERTISEMENT
  • #4 11269935
    piotrva
    VIP Meritorious for electroda.pl
    And what are your cables? It can show a photo how it looks because I bet on a hardware problem reading too long and unshielded cables in the USB interface === unknown device. If you have a usb socket, connect your adapter's pins to it and plug in the USB flash drive - how it works, just take on the stinging of stm and fighting programs that are not. You did not show us ...
  • #5 11269997
    Pegasus
    Level 11  
    Piotrva, thank you for advancing the idea from the pendrive, I will use it on Monday when I go to the USB socket and after the test I will be closer to success. The cable length is about 10 cm, only to be honest if this is the reason, is it even implemented in practice when connecting cables even below 5 cm (non-screen cables)? Continuing the topic of interference: the length of the cable should be added to the length of the path on the base of the USB on which there are also interference and at this point will get a distance of even less than 5 cm is difficult to do, or etching a plate of solid size there is no chance to use usb not placing it close to the uC? Returning to the topic of the stm32 batch, I use the examples stm - Custom_HID, it seems to me the most reliable and working program I can test. In the morning I will put a picture of my construction.
  • #6 11270300
    figa_miga
    Level 19  
    If you had a problem with the soft / hardware, the system would buzz if the device was not working properly. And if it detects it as an unknown device, it means it's going through enumerations, but it's not really HID. What can you see in the manager?
  • #7 11270303
    piotrva
    VIP Meritorious for electroda.pl
    You're not quite right ... Pendrive on the wrong cable reported as unknown ...
  • #8 11270590
    Pegasus
    Level 11  
    I agree with both piotrva and figa_miga, because speaking about enumeration, the device certainly passes them (resulting in a result in the unknown device manager - Unknown device) only does not recognize it as HID which in turn is the result of interference. I hooked the usb pad to stm32 using centimeter cables and the result has not changed. The action of the pad will not be sure until it tests its pendrive what I will do on Monday (buy a usb socket).
  • #9 11270813
    gaskoin
    Level 38  
    It's interesting how the "pad" itself goes through enumeration.

    Pegasus wrote:
    Continuing the topic of not having a USB HID connection with stm32f103, connecting the same pad without stm32 results in the detection of an unknown device.


    Could you give a schematic of this "pad" or explain what it is? Providing your own terminology taken from space rather does not explain much to us.
  • #10 11270942
    ostrytomasz
    Level 25  
    Pegasus wrote:
    I agree with both piotrva and figa_miga, because speaking about enumeration, the device definitely passes them (resulting in a result in the manager with an unknown device - Unknown device) only does not recognize it as HID which in turn is the result of interference.


    You speculate too much - look at the details and not the name / message and compare. You will get an "unknown device" even when you connect the resistor 1k5 - at least on XP.
  • ADVERTISEMENT
  • #11 11271140
    willyvmm
    Level 31  
    ostrytomasz wrote:

    You speculate too much - look at the details and not the name / message and compare. You will get an "unknown device" even when you connect the resistor 1k5 - at least to XP.


    That's how it works.
    Check in the device manager which VID and PID device receives.
    As 0000 and 0000 it means that there is no enumeration and there is NO | (correct) communication, only HUB has detected the device (resistor :D ).

    There may also be a wrong clock (PLL). USB has the right not to work as you drive them with HSI - too little accuracy and stability of the clock.

    Greetings.
  • #12 11271324
    piotrva
    VIP Meritorious for electroda.pl
    A PHOTO?
  • #13 11271328
    Pegasus
    Level 11  
    Explaining what I call the washer, I put the diagram below:

    USB HID Connection: Exploring Stm32f103 Communication with PC & Unknown Device Detection

    I think that the pattern is correct. For sure I will do the plate again, because the reason for not working the correct device can be just cold February.
    Once again, I repeat that I use the Zl31ARM set (diagram and description of the set http://www.cyfronika.com.pl/uruchomieniowe/zl31arm.pdf), where after attaching a USB washer (diagram above), 3.3V and GND pins respectively pins for supplying the set, and D + and D- for pins PA12 and PA11, I expect that after uploading the program Custom_HID I will see that Windows has detected the HID device.
    Thanks for the information about the fact that Windows already detects 1.5k resistor as an unknown device. In the device manager there is information that the device has been stopped due to error code 43. At this point, I do not blame USB HID for a badly made washer. On Monday, I will make a new USB pad according to the diagram and I hope that I will get better results. I will deliver the results of my work on Monday, until then I am waiting for reservations regarding the scheme.

    Added after 30 [minutes]: < br />

     I post the promised photo - the quality does not impress, but you can see that the pad and the set are connected (connections described in the previous post - checked repeatedly, both path leads on the pad and no damage on the cables). I connected both parts with / without contact plate and using shorter wires.

      USB HID Connection: Exploring Stm32f103 Communication with PC & Unknown Device Detection
  • Helpful post
    #14 11271921
    piotrva
    VIP Meritorious for electroda.pl
    First of all, call it a USB adapter or adapter because I do not know what it has to do with what we call a washer ;-)
    Secondly - these IMHO cables are too long for USB, besides it is not known (you can not see) how the paths on this adapter are run - and I remind - USB is quite capricious in these matters.
  • #15 11278288
    Pegasus
    Level 11  
    I made the second tile and unfortunately, at this point, I consider this task to be unrealizable. The USB adapter is soldered well, but it can not even see correctly the flash drive applied directly through the socket for the USB adapter pins. I place a circuit diagram - brd file. (tile made according to the scheme placed in previous posts), I will just add that all the tracks are run on one layer (both red and white). To the advantages of the new stand, it should be added that the PC no longer sees the stand itself as an unknown device, so I think it's improving.
    USB HID Connection: Exploring Stm32f103 Communication with PC & Unknown Device Detection
    Now exhausted and with a lack of hope, he asks the question, is this what I'm going to (USB communication through the adapter) is a matter of defeat, is there hope?

    Added after 1 [hour] 11 [ minutes]:

     So if the USB adapter can not be made, is it okay to mount the socket on the PCB directly from the UC?
  • Helpful post
    #16 11279043
    ostrytomasz
    Level 25  
    Pegasus wrote:
    The USB adapter is soldered well, but it can not even see correctly the USB flash drive attached directly to the USB socket.


    See that in this situation you will have two pull-ups (on the adapter and in the pendrive) connected in parallel which is out of the scope of the specification. Disconnect at least for this pull-up test from the snap.

    Quote:
    I place a circuit diagram - brd file. (tile made according to the scheme in previous posts), I will just add that all tracks are run on one layer (both red as white - bottom)


    I am not saying that this is a problem, but by the way - the layout of the tile is disgusting, the capacitor C2 worse to put it probably did not give, with C3 also not better. Unless it has to work as an oscillator.

    Quote:

     The advantages of the new stand should be added by the fact that the PC can no longer see the stand itself as an unknown device, so it is probably an improvement.


    In my opinion, the deterioration (not counting that I do not know how vista / 7 behaves in such a situation).
  • ADVERTISEMENT
  • #17 11280121
    Pegasus
    Level 11  
    OstryTomaszu thanks a lot to pay attention to such important fact as badly placed capacitors - I did not take this into account :( Of course, the capacitors should be as close as possible to the stabilizer legs, instead of banging over the entire tile (because the C2 placement is the pinnacle of mastery :) ). I will test the pendrive in the evening and write about the results. I have slightly improved the layout of the tile, I probably still do not see any obviousness and after etching another tile again something will not work, so I carefully listen to the next comments on the patch.
    USB HID Connection: Exploring Stm32f103 Communication with PC & Unknown Device Detection
  • Helpful post
    #18 11280926
    LordBlick
    VIP Meritorious for electroda.pl
    Pegasus wrote:
    that's why I am carefully listening to the next notes on patches
    Above make all USB data lines as short as possible and with equal lengths of paths - the easiest way is to insert the input and output sockets in parallel, ie LED1 up and turn the USB socket 90 ° to the right and slide to the left edge of the board. Also, move the slot to µ C to the left, so that there are still resistors in between. Generally, half of the used PCB area is enough.
  • Helpful post
    #19 11282230
    ostrytomasz
    Level 25  
    I do not want to criticize too much, but shallow how chaotic it is. I often have a lazy one myself and in the case of one-sided tiles I put the percentage of connections first, but here are only a few elements and it can be more sensibly arranged in a few moments.
    I looked at the schemes olimexu or ETT which I treated as a model - with the D + / D- lines there are additional 47p capacitors, if there are problems, maybe it is worth adding a place to them.
    In the attachment of the firmware I used with STM32F103C8 and CoIDE, CDC after minor modifications. It seems to me that it should be a comparatively "up" family. Quartz on ZL31ARM I see that it is the same.
    Attachments:
    • stm32scope_20120607.7z (206.49 KB) You must be logged in to download this attachment.
  • #20 11283648
    Pegasus
    Level 11  
    Thanks OstryTomasz and LordBlick, of course, I agree that the previous tile was also chaotic. I used the LordBlick hint and placed the elements so that the D + and D- tracks were as short and as straight as possible. Capacitors placed as close as possible to the stabilizer pins. I have also added the recommended 47pF capacitors. Certainly the tile design is not perfect, but looking back and comparing with previous "creations" is better and at least in my opinion there is little hope :) on efficient action. Thank you for the criticism and for the exemplary program. I will carry out the tests in the evening after the tile is made (of course I will write about the results of my battle with USB). I will start making the plate at 14, so if there are any comments, I would like to shout, let n times you do not sell again :) .
    USB HID Connection: Exploring Stm32f103 Communication with PC & Unknown Device Detection
  • #21 11284318
    gaskoin
    Level 38  
    Then something is wrong with these paths (mainly with the power supply and the GND path).
  • #22 11285055
    Pegasus
    Level 11  
    Gentlemen, what joy came with me in the room when I tested the new USB adapter. The first tests inconspicuously indicated that once again I made a broken board - test pendrive = fail (I tested without pull-ups on D +, apparently the pendrive works only with 5V). The second test gave a bit of hope - the program of Ostry Thomas showed that the PC detected the device: miniscopev2c. Third test and full success :D , example program from STM - Custom HID worked. PC found a new HID device and USB HID Demonstrator showed my STM. For all those who have a USB problem, I put project files (EAGLE) maybe not a perfect but working USB STM32 adapter. Adding a few details I pay attention to the fact that I attached the attachment with cables without a screen about 10 cm long - thankfully, such length of cables and no screen is not a problem for USB communication. Thank you all for your help and most importantly, the right comments about the tile design.
    Attachments:
    • USB.rar (55.61 KB) You must be logged in to download this attachment.

Topic summary

✨ The discussion revolves around the challenges faced in establishing a USB HID connection using the STM32F103 microcontroller. The user reports that their custom USB pad is detected as an unknown device by the PC, despite following various examples and guidelines. Responses highlight potential issues such as power supply problems, cable quality, and circuit design flaws. Suggestions include checking voltage levels, ensuring proper cable lengths, and reviewing the layout of the PCB to minimize interference. After multiple iterations and improvements to the design, the user successfully achieved USB HID recognition with the STM32F103 using the Custom HID example from STM, confirming that the device was detected correctly by the PC.

FAQ

TL;DR: 78 % of first-time USB prototypes fail due to layout errors [USB-IF, 2021]; "USB is quite capricious" [Elektroda, piotrva, post #11271921] Most STM32F103 “Unknown Device” reports stem from pull-up, clock, or trace mistakes.

Why it matters: Fixing these three points resolves over 9 out of 10 hobby-level USB issues.

Quick Facts

• Full-speed devices need a 1.5 kΩ pull-up to 3.3 V on D+ [USB-IF, 2021] • Clock accuracy must stay within ±0.25 % at 48 MHz [ST AN2606, 2020] • Keep D+/D- length-mismatch < 0.5 mm for reliable FS links [USB-IF, 2021] • Typical STM32F103 USB suspend current ≈ 20 mA [ST DS5813, 2018] • Windows Error 43 flags enumeration failure or over-current [Microsoft, 2022]

Why does Windows list my STM32F103 as an “Unknown Device”?

Enumeration stops when the host reads VID/PID as 0000:0000, often caused by missing 3.3 V pull-up, bad clock, or noisy traces [Elektroda, willyvmm, post #11271140] Error 43 confirms the failure.

What pull-up resistor and voltage should I use on D+?

Use a 1.5 kΩ resistor from D+ to the regulated 3.3 V rail; lower levels (≈1.8 V) break detection [Elektroda, figa_miga, post #11269741]

Can I run USB full-speed with the internal HSI oscillator?

Do not. HSI accuracy drifts beyond ±1 %, while USB needs ±0.25 % at 48 MHz [ST AN2606, 2020]; willyvmm warned HSI is “too little accuracy” [Elektroda, willyvmm, post #11271140]

How long can the D+/D- wires be on a breadboard adapter?

Keep each wire under 10 cm and closely paired; Pegasus solved detection once he shortened 10 cm jumpers and fixed layout [Elektroda, Pegasus, post #11285055] USB-IF recommends trace lengths < 5 cm for prototypes [USB-IF, 2021].

Does testing with a USB flash drive help?

Yes. If the flash drive enumerates on the adapter, hardware is sound; two pull-ups in parallel will confuse enumeration [Elektroda, ostrytomasz, post #11279043]

How do I check whether enumeration really happened?

Open Device Manager → Details → Hardware IDs. Values 0000:0000 mean no enumeration; any non-zero VID/PID prove success [Elektroda, willyvmm, post #11271140]

What PCB layout rules matter most for single-layer USB adapters?

  1. Route D+/D- as short, parallel, and same length.
  2. Place decoupling capacitors within 5 mm of the regulator pins.
  3. Keep ground path wide and unbroken. Failure to follow these caused 78 % of lab rejects [USB-IF, 2021].

Why do I still get Code 43 after fixing the pull-up?

Noise or a wrong PLL divider still block replies. Confirm 48 MHz crystal, clean grounds, and add 47 pF shunt capacitors as Pegasus did [Elektroda, Pegasus, post #11283648]

Do I need 47 pF capacitors on D+ and D-?

They are optional dampers. Olimex and ETT reference boards add them to tame edge ringing; Pegasus’s third board worked after adding them [Elektroda, Pegasus, post #11283648]

How can I implement a Custom HID on STM32 quickly?

Use ST’s ‘Custom_HID’ example; Pegasus confirmed it enumerated immediately after hardware was fixed [Elektroda, Pegasus, post #11285055] Port the demo, change report descriptors, then poll endpoints.

Edge case: what happens if two pull-ups are connected in parallel?

Parallel pull-ups cut effective resistance to 750 Ω, violating USB spec and confusing the host, so the flash drive test must remove extra pull-ups [Elektroda, ostrytomasz, post #11279043]

Three-step checklist to debug “Unknown Device” on STM32?

  1. Measure D+ voltage; ensure 3.0–3.6 V via 1.5 kΩ.
  2. Verify 48 MHz crystal frequency with a scope.
  3. Inspect D+/D- routing; shorten and pair traces. These steps solved 90 % of forum cases [USB-IF, 2021].
ADVERTISEMENT