Tutorial: How to Design Your Own Custom STM32 Microcontroller Board – Part 2

A circuit board Description generated with high confidence

Article Technical Rating: 7 out of 10

In this tutorial you’re going to continue learning how to design your own custom 32-bit microcontroller board based on an Arm Cortex-M0 STM32 from ST Microelectronics.

In part 1 of this tutorial we covered how to design the system level block diagram, select all of the critical components, design the full schematic circuit diagram, and run schematic verifications.

In part 2 you’re going to learn how to turn the schematic diagram into a real-world PCB layout which can then be sent to a manufacturer for prototyping or mass production.

Once the schematic design is completed, it’s time to design the Printed Circuit Board. Begin by inserting all of the components into the PCB layout. In DipTrace, you can use the “Convert to PCB” function in the schematic to automatically create the PCB with all of the components inserted.

NOTE: This is a long, very detailed tutorial so here's a free PDF version of the full tutorial (part 1 and 2).



Component Placement

Although all of the components have been inserted, it’s your job to determine exactly where each component is placed on the PCB.

Most PCB design software packages include an auto-placement feature that places components with the goal of minimizing routing lengths. But I never use it, and it’s almost necessary to manually place the components in the best layout.

For our initial tutorial circuit, the component placement is pretty simple. Place the microUSB connector next to the linear regulator with its output as close as possible to the input supply pins (VDD) on the microcontroller. Finally, place the programming connector anywhere that is convenient.


Figure 1 – Placement of the critical components in this initial design: the microcontroller (U1), the regulator (U2), the micro USB connector (J1), and the programming connector (JTAG-1).


Once all of the core components are properly placed, your next step is placing all of the passive components (resistors, capacitors, and inductors). For this initial design the only passive components are capacitors.

One key aspect of designing electronics that you need to learn is the concept of parasitics. Parasitics are passive components (resistors, capacitors, and inductors) that you don’t intentionally design into your circuit. But, nonetheless, they are there and impact performance.

For example, although a signal trace is intended to be a perfect short, it in fact has some finite resistance, capacitance, and inductance all of which become more significant as the trace length increases, and as the number of bends and vias increase.


Figure 2 – Placement of all critical components (U1, U2, J1, and JTAG-1) and passive components (capacitors).


So this means that if a voltage source is located far away from the load, which is the STM32 microcontroller in this case, there is essentially a resistor between the load and the source (neglecting any capacitance and inductance).

If the microcontroller all of a sudden requires a fast spike of current then it will cause a voltage drop across this trace resistor.

So even though the voltage regulator’s output may be a perfect 3.30V, the voltage at the microcontroller pin will be lower during this current surge. Decoupling capacitors are used to solve this problem.

Remember, capacitors are like little batteries that store electrical charge. Placing them right at the microcontroller’s supply pins allows them to supply any fast, transient current needs of the microcontroller.

Once the transient load disappears the capacitors are recharged by the power supply so they are ready for the next transient increase in load current.

PCB Layer Stack

A printed circuit board is made up of stacked layers. Conducting layers are separated by insulating layers. The minimum number of conducting layers is two. This means the top layer and the bottom layer can be used for routing signals, and these two layers are separated by an internal insulating layer.

For this tutorial we’ll start with a 2-layer board to keep things simple. But as the circuit complexity increases you’ll find it necessary to add additional layers.

The number of conducting layers is always an even number, so you can have a board with 2,4,6,8,10,12 conducting layers. Most designs will require 4-6 layers, and more advanced designs may require 8 or more layers.


Once all of the components have been properly placed it’s now time to perform the necessary routing. There are two options for routing: manual and automatic.

For auto-routing in DipTrace you simply select Route -> Run Autorouter and the software will automatically do all of the routing.

Unfortunately, auto-routers in general do a horrible job, and in almost all cases you will need to manually do all of the routing. For this tutorial we will be doing all of the routing manually.


Figure 3 – Routing the PCB (black traces on the top layer, gray traces on the bottom layer)


When routing on a PCB you want to minimize the length of each trace as much as possible. You also want to minimize the number of vias and avoid any 90 degree bends in the traces. These recommendations are especially critical for high power traces and high speed signals.

A via is a hole between layers with conducting material that allows you to connect together two traces on different layers. Most vias are what are known as through vias which means the via tunnels through all layers of the board.

Through vias are the simplest type to manufacture because they can be drilled after the entire PCB layer stack-up is assembled.


Figure 4 – Via #1 is a classic through via, via #2 is a blind via, and via #3 is a buried via.


Vias that only tunnel through a subset of layers are known as buried and blind vias. Blind vias connect an external layer to an internal layer (so one end is hidden inside the PCB stack-up). Buried vias connect two internal layers and are completely hidden on the assembled PCB.

Blind and buried vias allow you to pack a design more tightly. This is because they don’t take up space on the layers not using them. Through vias on the other hand consume space on all layers.

However, be aware that blind and buried vias drastically increase the prototype cost for your board. In most situations you should restrict yourself to only using through vias. Only exceptionally complex designs, that must fit in an exceptionally small space, should likely ever require these more advanced via types.

When routing any high current power lines you need to ensure the trace width is capable of carrying the necessary current. If you run too much current through a PCB trace it will overheat and melt causing the board to become defective.

To determine the necessary trace width I like to use a PCB trace width calculator. To determine the required trace width you need to first know the trace thickness for your specific PCB process.

PCB manufacturers allow you to select various conducting layer thicknesses, usually measured in ounces per square foot (oz/ft2) but also measured in mils (a mil is one thousandth of an inch) or millimeters.

A common conducting layer thickness is 1 oz/ft2. In this tutorial I’ve made the power supply lines 10 mils wide. Using the calculator linked to above shows that a 1 oz/ft2 trace measuring 10 mils wide can actually carry almost 900mA of current.

This is obviously much more than we’ll need, and I could have easily made the supply lines much more narrow. In the first tutorial I showed that the absolute maximum current required by the STM32F042 is 120mA. Perhaps surprisingly, to handle 120mA we only need a trace width of 0.635 mils!

The minimum trace width allowed by most processes is 4-6 mils. The minimum width traces can be easily used for the supply lines in this design. That being said, the wider the trace the less the resistance and the more stable the supply voltage at each component.

Unless space is extremely tight you should always over design the power supply traces. In fact, in many cases you’ll want the power supply routing on its own layer so you can maximize the routing width.

Finally, in the calculator you’ll notice the requirements are different for internal layers versus external layers. For this simple, 2-layer design both layers are external so the “Results for External Layers in Air” is what we need to use.

Internal layers can carry much less current because they don’t get the cooling effect of being exposed to air so the traces will overheat with much less current.


Figure 5 – The completed Printed Circuit Board (PCB) layout for this initial tutorial.



Once all of the routing is done it’s time to perform verifications to ensure everything is correct. This is where automation really works well and any PCB design tool will offer automatic verification features.

There are broadly two types of verification: design rules check (DRC) and schematic comparison.

The DRC verifies that all PCB process design rules have been followed. This includes rules such as the minimum allowed trace width, the minimum spacing allowed between traces, the minimum spacing between a trace and the board edge, and so on.

In order to run a DRC verification its necessary that you first obtain all of the design rules for the specific PCB process you will be using.

Each PCB prototyping process has slightly different rules so you must have the correct rules before proceeding. You can get the design rules for your specific process from your PCB prototype supplier.

In DipTrace, you define the design rules by selecting Verification->Design Rules. Once all rules have been correctly defined, you can run the DRC by selecting Verification->Check Design Rules.

After you have verified that your PCB layout adheres to all of the process design rules, it’s now time to verify that your PCB design matches your schematic diagram. To do this in DipTrace you simply select Verification->Compare to Schematic.

In future tutorials, I’ll show you various types of DRC and schematic comparison errors, and how to fix them.

Generating Gerbers

Once you have verified the design adheres to the process design rules and matches the schematic diagram, it’s time to order your PCB prototypes.

In order to do this you’ll need to convert your PCB layout design (which is currently stored in a proprietary file format) into the industry standard file format known as Gerber.

The Gerber format outputs each layer of your PCB design as a separate file. The generated layers are much more than just the conducting layers of your board. Some of those layers include:

1) Silk layers – Includes the text and component designators.

2) Assembly layers – Similar to silk layers but with specific assembly instructions.

3) Solder mask layers – Indicates the green stuff on a PCB that covers up any conductors that you don’t want to solder to. This prevents accidental shorts during soldering.

4) Solder paste layers – Used to precisely place solder paste where soldering will occur.

You will also need to generate what is known as a Pick-and-Place file which includes the coordinates and orientation for all of the components. This file is used by the manufacturer’s automatic component placement machines.

Finally, you need to output a drill file that provides the exact location and size of any holes such as vias and mounting holes.

Once you have the Gerbers, the Pick-and-Place file, and the drill file you can send those files to any prototype shop or manufacturer for production of your board.


In this tutorial you’ve learned how to design a system-level block diagram, select all of the critical components, design the full schematic circuit diagram, design the Printed Circuit Board (PCB) layout, and order prototypes of your completed microcontroller PCB design.

This tutorial has purposefully kept the circuit itself rather simple so as to not overwhelm you with circuit complexity. That being said, a microcontroller without any additional functionality isn’t very useful.

In future tutorials we’ll greatly expand on this circuit by adding lots of additional features including battery charging, a display, Bluetooth, WiFi, GPS, USB, and various sensors.

Are you ready to discover the smart way to develop a new electronic hardware product? If so then check out the Predictable Hardware Report.

Leave a Reply 22 comments

Qandeel Sheikh Reply

I am waiting for the next part of the tutorial. Please let me know if you have posted the tutorial already but I am missing it?

    John Teel Reply

    It will be coming soon and you haven’t missed it. Be sure to join my email list so you don’t miss it. Thanks for the comment.


Richard Salazar Reply

Great tutorial! I can’t wait to see your succeeding tutorials and learn a lot more in terms of using the STM series micro controllers. Any idea as to when these might come out?

Shine Reply

Thank you for this article. I look forward to your next articles in this series.
Is there a free opensource equivalent to DipTrace?

    John Teel Reply

    Thank you Shine. I’m not familiar with an opensource equivalent to Diptrace. There are several free design tools available but they restrict you to only one PCB vendor. Diptrace does have a free version available for smaller designs.


Cannot wait to see next part !

Pachito Marco Calabrese Reply

Really good set of articles, thank you

Qandeel Sheikh Reply

Nice article !

Stevie Reply

Sir Teel I know you love the stm32 microcontroller but I am wondering if in future you could do a tutorial on AVR microcontroller (more specific ATmega 48) just like the one you are presently doing on the stm32…

    John Teel Reply

    Hi Stevie,

    Yes, definitely! The STM32 isn’t always to best solution for every project. Since the AVR microcontrollers are so popular with makers I think a tutorial on the microcontroller is a great idea. Thanks for the recommendation.


Mbavhalelo Neron Maano Reply

Reviewing datasheets is absolutely a critical skill to learn for every Electronic Designer as it may not be possible to successfully design for microchips without understanding your datasheets. So, that’ll be much appreciated! I look forward to your series!

Mbavhalelo Neron Maano Reply

I’d like to say that I really appreciate this series of tutorials. What makes me appreciate them the most is the fact that you’ll be adding advanced features such as a rechargeable battery, a display, Bluetooth, WiFi, USB data, GPS, and an accelerometer because it is true that a MCU board without any additional functionality isn’t really that useful. I’d like to see how the MCU board connects with a rechargeable battery, a display, Bluetooth, WiFi, USB data, GPS, and an accelerometer.

I’m starting to think that this series will help my upcoming projects become a reality and I’ll have you to thank for that. So once again, thank you very much for this series! I look forward to your future tutorials of this series!

    John Teel Reply

    Thank you Mbavhalelo! That is really awesome to hear and I’m happy you are finding it helpful. I will be creating add-on tutorials soon that will expand the capabilities of the circuit like you mention.

    I’m also planning a series of tutorials where I review various component datasheets. When designing electronics you will spend a lot of time reviewing datasheets so I felt this is a critical skill to learn.

    Thanks again for the great feedback!


Mark Jones Reply

Great stuff! Keep up the good work.

abba Reply

thanks alot it cleared most of my doubt about mcu prog.
can we use arduino language to program the chip?

Abba Reply

thanks alot. it was very useful to mcu starters like me. which assembler is suitable for STM and cortex-m types mcu?

Santosh Sonar Reply

Thanks, John. I am deliberately waiting for future mail from predictable design.

Andreas Reply

Thank you for this article. I wish I had stumbled upon your website much earlier in my startup process. I look forward to your next articles in this series!

    John Teel Reply

    Thank you Andreas! I wish you had as well, but it’s never too late to learn more.

Nicholas Wani Reply

Great Work John!
keep up, I learnt a lot from this article

    John Teel Reply

    Thank you Nicholas! I’m excited that you learned a lot.

Leave a Reply:

Predictable Designs LLC, 10645 N. Oracle Rd, Suite 121-117, Oro Valley, AZ 85737 USA
[email protected], Phone: (520) 261-1844 (for fastest repsponse please email instead of call)
Copyright 2018 by Predictable Designs LLC

This website uses cookies. By continuing you consent to the use of cookies and the collection of your IP address. See our privacy policy for more information.