Help me with USB hub layout - Page 1
Forum section: electronics / projects

author: roli
author_rank: Regular Contributor
timestamp: March 24, 2020, 08:27:53 pm
content: Hi!Not too long ago I got this brilliant idea that I want to make a custom mechanical keyboard. And of course that idea is now pretty much close to reality with one issue hanging there. I want my dream keyboard to include a USB hub. Nothing fancy - USB 2.0 - mostly used to plug in a mouse receiver or a USB key here and there.I have some minor experience drawing PCB boards and soldering them together, but I am still just a hobbyist. So I never dealt with differential pairs and high speeds before.After a bit of searching here and there I decided to go with the USB2514 USB hub controller from Microchip. I managed to find a working design somewhere, so I more or less copied the schematic from that. Sadly the layout is a different story. Included in the PDF is the schematic and the current board layout that I came up with. The hub is located in the upper right corner of the PCB. It has a micro USB connector for input and two standard USB A outputs, plus another output that goes to the main keyboard controller. So three outputs together.I will use elecrow or JLCPB to manufacture the board, and it's gonna be a standard 1.6mm 2 layer board with 1oz copper. The USB lines here are 30mil wide with 5.3mil spacing. Except where possible - near the chips and micro USB connectors it tapers down to 10/15mil (as was suggested by the application note for the USB hub chipset). According to some online calculators the differential pair impedance for this board should be roughly 100 ohms. Now, I know that for USB you need 90, but I don't think I can get that here.Can somebody please look this over and tell me if it is going to work or not? And if possible... how can I improve this to give it a higher chance that it will work?

author: Yansi
author_rank: Super Contributor
timestamp: March 24, 2020, 10:07:24 pm
content: I would highly suggest to not use the twists in the high speed bus pairs. Go around the connector, instead of placing a via in just one of the traces. Make sure the impedance is correct (guessing a 2l board hence they are that thicc) and they are length matched according to the specification.Either use vias in both highspeed traces similarly (to introduce similar/same signaly delays/distortion in both lines) or just don't use them.Swapping the pins using a via for the USB lines to the MCU, I wouldn't care much, it is just 12mbps data. Slow noncritical stuff. You would likely get away even with much higher impedance traces there.Haven't checked anything further, I guess you have done your homework in that area.//EDIT: Also, as a side note: Your USB hub is already USB non-compliant, due to not providing downstream power supply switching and overcurrent protection. Adding it is easy and beneficial. Stuff like STMPS2141 is dirt cheap and easy to use.

author: roli
author_rank: Regular Contributor
timestamp: March 25, 2020, 06:37:15 am
content: Awesome, thank you.I will try to get rid of the twists by going around the connectors as suggested. Not sure what to do with the micro-usb input one though. No easy way of going around it there. So, next best thing is just placing vias that don't go anywhere just to get that symmetry?As for power switching... didn't know it needs that. Especially since it's powered by the host only (no external power supply). One thing that I was debating though is wether or not I should place a schottky diode on the power input or not.

author: TheUnnamedNewbie
author_rank: Super Contributor
timestamp: March 25, 2020, 08:29:13 am
content: Quote from: roli on March 25, 2020, 06:37:15 amA think I seem to remember seeing done is to simply send both traces to the bottom layer. Then, when you get back to the MCU, you can simply have one switch to top before the other to do the crossing. This way, the length remains matched, and if you do it right, the length difference will also not be too big.(but hey, I am not a baseband PCB designer so don't quote me on this)

author: Yansi
author_rank: Super Contributor
timestamp: March 25, 2020, 08:39:04 am
content: Quote from: roli on March 25, 2020, 06:37:15 amNo! Vias in the signal have to be symmetrical in both lines. If the DP line has two vias in it, DM line should have also two and go through them. Do not create stubs.Schottky in series? No. USB has a rather tight spec on power supply voltage range. One diode drop lower and you are almost out of spec even if you get 5V input exactly.Not sure if the power switching isrequiredby the spec (never done any USB hubs), but it helps at least as an overload/short protection. Otherwise one faulty device plugged to the hub will likely bring the whole hub down, due to the upstream port going into overload.The USB spec is available for free, download it and have a read or two in there.https://www.usb.org/document-library/usb-20-specification(top right link)

author: roli
author_rank: Regular Contributor
timestamp: March 25, 2020, 04:34:36 pm
content: Ok, so I've implemented the changes discussed. Is this better?Length vise the max difference between the lines is now 32mil... that should be fine, right?I also checked the USB spec regarding the power switching... apparently it's the other way around from what I expected. A self powered hub doesn't require switching, while a host powered one does. Seeing how this is not something that I will be making commercially - I'll live with it. Although I know that with my current mac keyboard the computer shuts down power to the whole port when something plugged into the keyboard gets a short.One more question... if this hub fails to work at USB 2.0 speeds (let's say because of impedance issues)... will it drop to say USB 1.1 speeds, or simply not work? Just wondering how fault tolerant this is. I've added some test pads in the new design so I can just leave the hub components off and jumper the USB lines from the micro to the input port... just in case. I can live with the hub not working, but I would rather have a working keyboard in the end.

author: Yansi
author_rank: Super Contributor
timestamp: March 25, 2020, 06:23:37 pm
content: Better, but the diffpair to the MCU is now more uglyfied. But should not be that much of a problem. 32mil difference should likely pass.Now looking at it second time, being more familiar with it, I see number of more issues:a) no ESD protection of power supply input and all outputs?b) just a ceramic cap on power supply input is a big no. Voltage overshoot due to inrush current may damage the circuit. Check this for exampelhttps://www.analog.com/media/en/technical-documentation/application-notes/an88f.pdffor more details.c) decoupling caps for the hub shall be placed better. As close as possible. Remember, this is a device supposed to work at 480 megabits. Very very fast signal transitions. I would swap for a smaller size caps (this ain't 0603 right? Would not use any bigger). For example, rotate C14 horizontal and place directly near the power supply pads. C17(can't see it clearly) for example lacks a decent low impedance path to the ground plane below. Place closer, use at least two vias near the GND pad of the cap. I would add a bit of bulk capacitance (20-47uF electrolytic or tantalum) to both the input and output side of the LDO.d) if not using current limited power switches, use at least one polyfuse (polyswitch) on the input (upstream USB port) as a "last resort" protection against rough overload (short). Add the TVS behing it.e) NRST pin shall have a 100nF cap to ground.f) I suggest adding a 10k pulldown to SWDCLK and 10k pullup to SWDIO.g) a pro tip: Use a dual diode with a common cathode in a SOT23 instead of discrete 4148 diodes. Will get you 25% joints less to solder. Likely also cheaper, as only half the device count required.Regarding the hub behavior: No, it won't likely fall down to USB 1 speed, it won't likely work much at all, especially with windows, if there will be any signal integrity issues. Windows have some annoying device management, that simply disconnects any HW that malfunctions few times in a row. I am not even sure if the hub can work with USB 1 low speed (1.5mbps). I would guess it can't. Communication will be initialized at USB 2.0 FS (full speed, 12mbps) and then negotiated to HS mode. Not sure what happens if the HS mode fails due to signal integrity issues - likely device will not be recognized and blocked.Also, the STM32 does not support USB 1 mode either. Only 2.0 FS.

author: roli
author_rank: Regular Contributor
timestamp: March 26, 2020, 06:45:42 am
content: Awesome, thanks for feedback.a) So, can I just add the same ESD protection diodes as I have on the data lines?b) Interesting. Will add some electrolytic caps there then.c) You are right, these are 0805s. I was thinking about using 0402s but I didn't want to complicate the design too much by using two different sizes. But it is an easy swap since I have some 0402s laying around from another project.d) I'll look into it. I'll probably place the pads there, but leave it off for now... I don't plan on ordering any components before I start assembling this, so I'll add it latere, f) Did not know that this was necessary/suggested. I've made quite a few boards with both STM32 and Nordic NRF51 chips and never added any resistors or capacitors to the SWD/RST lines.

author: Yansi
author_rank: Super Contributor
timestamp: March 26, 2020, 08:47:16 am
content: I do not know about Nordic, but ST's datasheet clearly suggest you should place a 100n cap to the NRST and ideally NO pullup resistor. The NRST pulldown transistor is not specified for pulling any additional external load. Putting a tight external NRST pullup resistor can even prevent correct working of the reset circuitry. The cap to ground is required as a filter (there is only internal weak pullup). Without the cap, you may see spurious resets, due to EMI (caused by rapid load switching nearby, ESD events, etc..).Same with the pull-up (SWDIO) / down (SWCLK) resistors. If you plan to leave the SWD activated in your product, you better not rely on the internal weak pull- resistors. Spurious signals may cause undefined behavior. If you plan to disable SWD in your final product, then it is likely just fine to leave it as is.For Nordic NRST pin related stuff, consult the appropriate manual of the Nordic chip you have. They may have a completely different reccomendations and very different implementation in the chip itself.I wouldn't use the flimsy small signal ESD diodes on the power supply. I'd use something way beefier there.My defacto standard for USB ESD protection is USBLC6-2SC6. Although this part is specified for USB HS (480mbps), I mostly work with only USB FS. This is a SOT23-6 packaged well known part, including clamping diodes and a TVS across the supply pins. This one should work even in your HS application. But I do not have any experience with it.

author: roli
author_rank: Regular Contributor
timestamp: March 26, 2020, 09:52:39 am
content: Ok. Will play around with it in the afternoon and fix/improve some of the stuff as suggested.Just remember here that this is just an afternoon project for me, not something that I plan on selling or something. I may make one or two more for a friend, but that's it.The USBLC6-2SC6 looks interesting, and I will keep it in mind for future designs/improvements.

author: roli
author_rank: Regular Contributor
timestamp: March 26, 2020, 05:42:38 pm
content: And here it is with the latest fixes. I replaced the 0805 caps with 0402 and moved them closer. Also added one. And added the cap to the NRST line. Plus added two electrolytics to the power supply (forgot to mark the value correctly on the schematic though).If anybody sees anything that will definitely not work... let me know. If not... I'll probably send it off tomorrow and see how it goes.