Please critique my STM32 board - Page 1
Forum section: electronics / projects

author: hendrix
author_rank: Contributor
timestamp: November 26, 2022, 10:54:55 am
content: Hello,I'm an industrial designer by trade, which means I'm a complete novice in electronics. Although I do basic electronic boards from time to time, I have never made an STM32 board before, so, any insight on what I should change would be appreciated.The board is designed to enable the gathering of multiple NTC thermistor data from drivers and motors of a 3D printer and report them to Klipper software via CAN bus. The board is a OSHW and aimed to have the following features:- STM32F103RBT6 MCU- USB port for DFU and to enable USB protocol rather than CAN bus if need be (It's USB C because I have a lot more of these cables now)- USB power jumper to enable programming without giving the board VDD- CAN ports for CAN bus protocol (supported by Klipper)- 120R CAN termination jumper to finalize CAN bus- SWD port- USART port- Boot push switch and Reset push switch to ease going into the programming state- 2 x LEDs, one for POWER state, one for SWD state- 16 x ADC points to attach 16 x NTC thermistorsThank you.Kicad V6 files are attached.Edit: Realized I forgot to add pin names for USART and SWD, updated.

author: ataradov
author_rank: Super Contributor
timestamp: November 26, 2022, 06:33:56 pm
content: You need 5.1K pull-down resistors on the CCx pins of the USB connector.I would also use external pull-up on the reset, since you decided to add the capacitor. Internal pull-up value is relatively high and variable, might lead to unexpected differences in behavior between the devices.

author: Martinn
author_rank: Frequent Contributor
timestamp: November 26, 2022, 07:18:23 pm
content: Consider attaching a PDF schematic (not everyone will have KiCad installed)Some subjective points:Consider a more modern STM32 variant (G0, G4) instead of this dinosaurAdd a 14 pin 50 mil STDC connector for STLINK V3 interfacingAdd TraceSWO (for SWO printf)Add UART RX/TX to STLINK connector (STLINK V3 has a virtual com port integrated, which you can use for debugging/printf in addition to SWO)Add test points (I use a mix of 1.6 mm Keystone 5009 and 1 mm SMD pads), at least for GNDAdd 1 mm test points to (some) unused STM32 pins - avoids having to solder wires to QFP pins in case you forgot somethingGround plane is pretty much cut in half, poor GND connection on decoupling pin 47/48Mounting holes are unconnected (is this intentional)?

author: Doctorandus_P
author_rank: Super Contributor
timestamp: November 26, 2022, 09:45:26 pm
content: Some short notes (Not a full review).Personally I don't like the boxes drawn around schematic sections. They do not add useful information and they cost time to maintain. A bit of whitespace between sections is perfectly adequate for separating parts.I do like the use of bigger texts to identify sections. Making the text bold makes it easier to read when the schematic is zoomed out far.You've drawn everything as "loose sections", which makes it more difficult to get an overview. I tend to keep the schematic layout in a functional order. For example: Power input, Voltage regulators, Power distribution and decoupling caps, drawn from left to right. I would for example also mirror the section around FB1 to keep with the logical flow of "signals and power go from left to right".You've copied the thermistor interface 16 times. With KiCad you can put one of such sections on a hierarchical sheet, and then include that sheet 16 times. This way you only have to draw the circuit once. You probably copied that section, but with hierarchical sheets they are all changed at once when you modify that sheet. With a hierarchical design you can also make use of theReplicate LayoutPlugin that helps with both footprint placement and laying of tracks on the PCB.If there is any chance that boards are added or removed on a "live" system, then a pullup or pull down resistor on the can transceiver can prevent data corruption while the uC is still in reset or initializing.There are a few wide tracks cutting through the GND plane on the bottom, and this is not very good. It's always a struggle to get a good GND plane on a 2 layer PCB, but you can quite easily move much more of the tracks from the bottom to the top. I'm not sure what the resolution of your thermistors is, but connecting 16 of them to a single +3.3V track may introduce a bit of voltage dropWhen I run DRC on the PCB, I see a few warnings about net names that do not match the names in the schematic in theSchematic Parity[/] Tab.But overall, it looks quite good for a first design. You've clearly put some effort into this.

author: hendrix
author_rank: Contributor
timestamp: November 27, 2022, 09:58:43 am
content: Thanks for the reply guys,I have some questions:Dear Alex,Quote from: ataradov on November 26, 2022, 06:33:56 pmIs this good practice or a necessity? Other examples that use USB-C connections for FS USB don't have anything attached to CCx, please elaborate.Dear Martinn,- According to pricing, STM32F is almost half the price of the G series, am I missing an advantage that the G series provides?- I designed the interface to be used with STLINK V2-1, don't have a V3 so didn't consider that.- I didn't put GND connection to mounting pads to prevent ground loops, was aiming for a single point ground from CAN Bus, is that bad practice?Dear Doctrorandus_P- I know my schematic is probably a mess to a PRO but, I read so many different views on a schematic design that I have no idea which is better:/ I will try to organize the layout as you state.- It's my first time using Kicad, still learning, didn't know that replicate layout was a thing, that's great.- The CAN bus for this board was not designed to be a hot-plug type of thing, so didn't even consider that, that's a great idea though.- I will definitely fix the GND plane, not happy with that either.- Do you think local LDO (I think it's called PoL Dc-Dc conversion) would help with the voltage drop issue? Like placing something similar to a TPS70933 before each thermistor and feeding with the 24V from CAN bus connection? I see some boards doing that.- The schematic Parity is something I didn't know, is this a problem or just good practice to fix this?

author: Martinn
author_rank: Frequent Contributor
timestamp: November 27, 2022, 04:20:51 pm
content: Quote from: hendrix on November 27, 2022, 09:58:43 amIs cost relevant for a 1-off design? Probably it's fine to use older parts when they do their job. Some points however:- The F103 has been pirated to death. Make sure to purchase a genuine one or you could run into trouble.- With my personal designs, I'd like to establish a basis I can build on later, so I'd rather use something modern like a G4, which has much more features I might use later. Changing the MCU is not a big thing however.- STLINK V2 can also handle TraceSWO IIRC (check SWO printf, data watchpoints etc)- GND: It seems you have a ground concept, which is a good thing. Don't know CAN, so I can't give you an advice here.I noted you used a crystal: Those are rather difficult to properly verify and personally I'd try to avoid the verification procedure by using a crystal oscillator.For a DIY project likely this will work just fine, but as you seem to care about details be aware that properly designing crystal oscillators for production is not trivial. Seehttps://www.st.com/resource/en/application_note/cd00221665-oscillator-design-guide-for-stm8afals-stm32-mcus-and-mpus-stmicroelectronics.pdfThe DC/DC converter layout is so-so. Read the layout hints (datasheet p. 21). Note that the data sheet example requires a mid layer switch node connection. As the switch node is by far the worst EMI source, it must be kept as short as possible. So in your case I'd modify the datasheet example and have the inductor as close to the switch pin as possible (as you have two layers only).Anyway those are details. Except for the cut in half ground plane your design looks fine!

author: ataradov
author_rank: Super Contributor
timestamp: November 27, 2022, 06:05:11 pm
content: Quote from: hendrix on November 27, 2022, 09:58:43 amIt is necessary. You may not notice that something is wrong if you use USB-A plug on the host side, but if you use USB-C to USB-C cable, some hosts will refuse to enumerate the device.Quote from: hendrix on November 27, 2022, 09:58:43 amFor what it is worth, I agree. Those small boxes within the schematic add nothing useful and make it harder to read.Quote from: hendrix on November 27, 2022, 09:58:43 amIt is not a problem on its own, but it would make maintenance much harder in the future.

author: hendrix
author_rank: Contributor
timestamp: December 02, 2022, 07:52:32 pm
content: Hey,Tried to make the necessary changes to make it better. Hope its better.- Tried to create a better schematic, without the borders and also with multiple sheets- GND plane should be better- Tried to fix voltage drop issue by giving each thermistor its own LDO, this was quite important as the number of used thermistors will change from person to person and that might have created problems- Added caps for USB-C- Tried to match the DC-DC suggested layout by Texas Ins. (included in the attachments) without the inner layer- Got rid of the CAN ports on each side of the board, it was mostly for esthetic purposes anyway, brought them side by side and this seems much more functional- For now, I have omitted the SWO printf- I have also included a PDF schematic this time around

author: ataradov
author_rank: Super Contributor
timestamp: December 03, 2022, 12:16:57 am
content: It looks fine. No need to overthink it too much. At this stage it is easier to just order the boards.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: December 03, 2022, 05:14:32 am
content: I had a short peek at your modifications and it looks quite good.Have you looked into the pullup resistor for the Reset as ataradov mentioned?Shorting C21 to GND could also be a minor issue even though C21 is only 100nF, ceramic capacitors can deliver high enough peak currents to damage switches, but this is mainly a long term issue and probably irellevant for an ocasional reset.A note for your next project, use:PCB Editor / File / Board Setup / Design Rules / Net ClassesWith net classes you can divide your nets into groups and assign default copper track widths to those groups.

author: hendrix
author_rank: Contributor
timestamp: December 03, 2022, 07:31:26 am
content: Thank you for the replies.I am having a hard time understanding the need for that resistor. If possible please explain why I need that? The reason that I am asking is I can't find information on the need for it, the datasheet shows the following:Thank you.

author: ataradov
author_rank: Super Contributor
timestamp: December 03, 2022, 07:59:45 am
content: It is just a good practice. Internal resistor has a very high and variable value. Without a strong pull-up your circuit may be susceptible to noise and EMI.It costs nothing to place a footprint. If you determine you don't need it - don't populate it. It is far worse to find out that you need it and not have a way to populate it.

author: hendrix
author_rank: Contributor
timestamp: December 03, 2022, 08:51:00 am
content: Ok, that makes sense. I added something like the following:

author: mariush
author_rank: Super Contributor
timestamp: December 03, 2022, 10:04:51 am
content: Strictly looking at the picture of the board :* I'd move L1, C15 and C16 more inside the board, let's say ABOVE the line of headers* Consider moving the BOOT and RESET buttons to the right of the USART header ( or at least on the same horizontal line and with the text in the same orientation)* CAN_ something header is the only header that's oriented differently ( well, perpendicular to the closest edge, all the other headers close to edge are horizontal ). Also maybe it would make more sense to be to the right of CAN PORT 2 header, to be easily accessible like the other headers?* the thick trace on the right edge seems a bit close to the mounting hole (top right corner) but it's probably fine.* you have A LOT of empty space on the left side of the board. For example, you could easily move the microcontroller an inch or so / couple cm to the left (in the picture) and that would allow all the stuff to the right of the controller to be arranged nicer way.* don't really see any particular reason why the chip has to be oriented at 45 degrees. Seems like you have plenty of space to arrange traces and it's not like you need to have matched lengths of traces* Consider changing to a smaller font for all the components around the 16 headers. That whole area is filled with nearly pointless text... almost feels like you're messing the layout because you have to squeeze the text somehow on the board.* I'd think about designing this board to allow for a right angle header version (if those headers are available in right angle version as well) - basically, some may want a low profile / low height version of this board, where the bundles of wires going up could be an inconvenience.If you change to be right angle headers, then the headers at the edges would not be very accessible due to the screw holes (the screw could block entry of connector into the header, or put unneeded pressure/bend on the plug or wires) so in that case maybe see if it's possible to redesign the board to have all the headers within the mounting holes?On the schematicBuck regulator :You really don't need to do it exactly like the reference design.* you can tweak the R2 and R4 values (for enable). See 7.3.5 in datasheet for formulas. But I think you'd probably be fine with 100K instead of 105K for R4 (because you have another 100K in R5) so reduce you BOM list. You could probably be just fine with 510K resistor for R2, as 510K is E24 value unlike 511K ( you could probably also have a 470K + a 47K in series to get 517K, if you use these values somewhere else on the board, so you don't have to order a single 510K or 511K resistor)* The 49.9 ohm resistor (R3) is not needed - the datasheet says it's there just to make it easy to debug, to check for stability (basically to desolder it and solder wires or other values there to test)* YourR6 value is incorrect in the schematic, it's set at 120 ohm. Should be 13.3K as the datasheet recommends, for 5v output.The formula is Vout = Vref x [(R5 + optional R3)/R6 +1] where Vref = ~0.596 ... in this case (100k / 13.3K +1 ) x 0.596 = ~ 5.07vAgain, 13.3k is recommended, but I don't think you have to be that exact. Could probably be fine with a E12 value like 12K or a E24 value like 13K and just recalculate the other resistor. 100K and 13K will give you around 5.2v output voltage, which will be fine, considering the voltage drop on the traces to components, and considering most components will go up to 5.5v just fine.For the 16 thermistor circuits ...For the TPS70933 check datasheet,seems the EN pin voltage must be below 6.5v- so you'd need at least a voltage divider or to bring 5v to the enable pins ... see datasheet at page 3, pin functions:https://www.ti.com/lit/ds/symlink/tps709.pdfSeems downright silly to use 16 linear regulators, one for each thermistor, especially when that regulator costs around $1.25 (if you buy 100)I guess it costs that much because it supports 24v input. BUT you have space on the board to add another 24v to 5v regulator (if needed) and then you could use cheaper ldos to do 5v to 3.3v for each thermistor, or use regulators with multiple independent outputs if you insist on that.You also have regulator ICs with 2 independent outputs, or 4 independent outputs and they're cheap...ex.0.72$ each, 0.5$ per 100 : TLV7113333 (max 5.5v input, 2 x 3.3v 200mA outputs 6WSON) :https://www.digikey.com/en/products/detail/texas-instruments/TLV7113333DDSER/26964141.26$ each, 1.0$ per 100 : MIC5330 (max 5.5v input, 2 x 3.3v 300mA outputs 8MLF, ultra low output noise 30uVrms ) :https://www.digikey.com/en/products/detail/microchip-technology/MIC5330-SSYML-TR/16171370.49$ each, 0.36$ per 100 : MIC5380 (max 5.5v input, 2 x 3.3v 150mA 6-TMLF - very tiny, noisier i guess compared to mic5330) :https://www.digikey.com/en/products/detail/microchip-technology/MIC5380-SSYFT-TR/2048505You may want to consider using separate diodes instead of BAT54S simply because you'd save space and maybe do better layout, and you may actually get better pricing.You probably get BAT54S for 10 cents if you buy 100, but you can get 1000 single diodes for around 4 cents each.For example :4.5 cents @ 500 , 3 cents each @ 1000 RB520S30T5Ghttps://www.digikey.com/en/products/detail/onsemi/RB520S30T5G/2797277DO you really need 2.37K resistors? Will this work with 2.35K resistors or is that critical? If the circuit will work with 2.35K resistors, then you could just reduce your bom by paralleling 2 4.7K resistors to get your 2.35KAs you would now have 5 resistors (2 pairs of 4.7K for the 2.35K resistors + the 4.7K resistor) you could even consider using a resistor array instead of 5 separate resistors, to save PCB space, even if you're gonna use only 5 out of the 7-8 resistors in the packageFor example :11 cents @ 100, 6.6 cents @ 500 EXB-2HV472JV8x4.7k Ohm ±5% 62.5mW Power Per Element Isolated 8 Resistor Network/Array ±200ppm/°C 1506, Convex, Long Side Terminalshttps://www.digikey.com/en/products/detail/panasonic-electronic-components/EXB-2HV472JV/28532714 cents @100, 10 cents @ 500 741X163472JP8x4.7k Ohm ±5% 63mW Power Per Element Isolated 8 Resistor Network/Array ±200ppm/°C 1506, Convex, Long Side Terminalshttps://www.digikey.com/en/products/detail/cts-resistor-products/741X163472JP/112443116 headers , 5 resistors per header = 80 resistors , so 10 such resistor arrays would do. But for easier layout maybe you'd want to do 3 resistor networks per group of 4 headers (20 resistors out of 24 available used), so you end up with 12 such resistor networks.

author: hendrix
author_rank: Contributor
timestamp: December 03, 2022, 01:36:18 pm
content: Thank you for the detailed reply. I have some questions and comments about your suggestions.Quote from: mariush on December 03, 2022, 10:04:51 amThats actually a CAN termination jumper header. I wanted to place it in that way because a jumper is placed on it if this device is the last in line on a CAN bus.Quote from: mariush on December 03, 2022, 10:04:51 amI don't really have a problem with the size of the PCB, making it smaller is an option with a little bit of an arrangement like you state. However, I don't see a problem with the 45-degree angle of the STM32, what would be the advantage of not angling the STM32?Quote from: mariush on December 03, 2022, 10:04:51 amIn its current state, the height of the text is about 1mm. Wouldn't it be very difficult to read if it's smaller?Quote from: mariush on December 03, 2022, 10:04:51 amIf I angle the headers, I would not be able to plug into the headers on the second row because of the SMD components, or did you mean something else?The comments you made on the schematic are great, thank you, I think I will integrate everything you said except the resistor network as that might make the routing more challenging.In terms of the LDO from 5V to 3V3, don't you think its better to convert from 24V to 3V3 or from 5V to 3V3 in terms of regulating or controlling voltage drop out when attaching 16 thermistors?Thanks.

author: mariush
author_rank: Super Contributor
timestamp: December 03, 2022, 04:24:42 pm
content: There's no benefit to the microcontroller being at an angle... at least I don't see one.You'll have shorter traces to the usb connectorYou'll have the C5,C6, R1 and D1 nicely placed above the headerYou'll have shorter traces to RX and TXYou'll have shorter traces from the controller to U5The crystal could also be placed closer to the pins and have those traces more equal (though it doesn't matter)The reset button could be easier moved near the boot button (could do a via to the bottom to go around the traces for the crystal instead of going around it)For a version with right angle headers, you could bring the 8 headers closer together leaving maybe 1mm instead of 3 or whatever you have now, and then they would all fit between the two screw holes.Shouldn't be a problem to have the other 8 in two groups of 4 on each side of the pcb - basically a U shape of headers. If this board is screwed inside a case, the cables for 4 thermistors could be easily bundled together and routed outside, without issues.I don't know how much current these thermistors would consume, but I don't think it's more than a few mA at best so not sure why you need one regulator per thermistor in the first placeBut if you want independent 3.3v outputs for each, then I would say implement a 24v -> 5v regulator (could probably be a sot-223 linear regulator or similar if the current is low)At least the regulators with 2 outputs would bring the cost down.One other comment I'd add is that I see you used in lots of places 0.3mm traces ... it's fine I guess, but not really needed. 0.25mm (10mil) works better in some places (ex decoupling capacitors, on the usb connector etc) and for very short connections it's perfectly fine. PCB manufacturers can handle even thinner traces ex jlcpcb can do 5mil / 0.125mm traces on 2 layer, and 8 mil / 0.2mm on 2oz boardsIt also makes it easier to route traces out of pads in a nicer way, with a 45 degree bend instead of coming at an angle directly from the pad

author: hendrix
author_rank: Contributor
timestamp: December 07, 2022, 03:23:24 pm
content: OK, I have to admit it looks better this time, hopefully, I didn't create significant problems while trying to fix things.Some notes:- The DC 24V to 5V that I use supplies 2A and that should be enough to power everything (the thermistors use a max. of 15mA),- Changed to dual output LDO for 5V to 3V3,- Examined the possibility of angled connectors but, for my purposes and generally in the 3D printers, the space towards the top of the board is less critical than towards the sides. For this reason, kept the vertical connectors,- Got rid of the angled MCU and generally made the board smaller, it's actually quite a bit smaller,- Corrected some mistakes with wrong/unnecessary resistors thatmariushmentioned,- the BAT54 that is used is $0.0121 a piece, so didn't change those,- I couldn't find enough information about the 2K37 resistors that are recommended for the thermistors. However, I am able to source these very cheaply, so didn't change those,- I changed to a resonator, according to STM application notes, it should be fine (?)I hope you guys comment, thank you.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: December 07, 2022, 11:25:32 pm
content: It's probably a good idea to add some extra mounting holes in between the thermistor plugs.Ceramic capacitors are very brittle and they can break and cause shorts if the PCB is being bent during insertion of those connectors.