# [KiCad STM32 Hardware Design - An Overview in 20 Minutes - Phil's Lab #15](https://youtu.be/wLwKgMBWhpY) STM32 breakout board in KiCAD Programmed via USB Design Files online at https://github.com/pms67/STM32F1-Breakout-Board Phil's Lab #15 - KiCad STM32 Hardware Design - An Overview in 20 Minutes ### Part Selection Basic STM32 - `STM32F103` - Has a USB interface Regulator - `XC6206` - Drops 5V down to 3.3V - Since the board will be powered via USB ### Schematic Overview Three Sections: 1. USB and Regulator 2. STM32F1 Microcontroller 3. GPIO Headers ### USB and Regulator ![[Pasted image 20241209081930.png]] USB Input -> LDO -> 3.3V Rail with Status LED - USB-B Micro Input: - VBUS - D+ - D- - GND - ID - Shield VBUS is a noisy power source, especially when powered by a laptop. A 100Ω Ferrite Bead and a 1uF RC Low Pass Filter can reduce the noise at the input to the LDO. Regulator `XC6206P332MR` is small and simple. Stable with 1uF input and output capacitors. These are on the smaller end for a regulator. LED is Green, with 1.5kΩ on the 3.3V (2.2mA). He prefers to run the LED's fairly dim around 1-2mA. #protip/kicad By applying net labels to D+ and D- as `USB_D+` and `USB_D-` during Schematic creation, KiCAD will recognize the terminating +/- on otherwise identically named nets and flag them as a Differential Pair. This will come in handy later during layout when routing tracks. The USB-B device has a shield pin. If you had a metal enclosure, you would tie them together. In this case we have no metal enclosure for the device, so we leave it open. Typically, USB is tied to ground on the host-side. ### STM32F1 Microcontroller ![[Pasted image 20241209082722.png]] He recommends installing the **STM32 Cube IDE**. This allows you program the device, as well as set all the pin assignments. You can right click each pin and see what its capable of doing. `STM32F103C8T6` symbol in KiCAD. Always Include: **PD0 and PD1** - Connect an external crystal oscillator **PA13 and PA14** - Serial Wire Debug pins. Allows us to interface with the chip, debug, and upload firmware. **PA11 and PA12** - USB_DM - Data Differential Pair ### STM32 Decoupling Capacitors Pin Banks A, B, C, D - PA0, PB0, PC0, PD0, etc. Starting with the Power Pins Typically tied to the system voltage - VDD, VBATT, VDDA For the main power pins you want - 1 bulk decoupling capacitor - 1x100nF per VDD pin, placed as close as possible to the power pins in layout The VDDA pin acts as the power source for all Analog sections of the microcontroller. It's wise to set up some additional low-pass filtering on the 3.3V rail/VDD to produce VDDA. ### NRST and BOOT0 Pins ![[Pasted image 20241210051422.png]] Pins - N-Reset - Pull it low, and then set it high again to reset the uC. - This pin has an internal pullup, so you don't have to add your own external pullup - Boot-Zero - Determines whether the bootloader will run when the uC is reset. - HIGH - Bootloader - LOW - Run as normal - When Low, we can program the device normally via Serial Wire Debug - When High, Starts in Bootloader Mode - Can be programmed via UART or sometimes USB - Typically just give it a pull-down resistor, and then provide a solder pad jumper connected to VDD so you can short them together when you want to manually enable bootloader. ### Crystal Oscillator (HSE) - PD0 and PD1 - High Speed Crystal IO - Crystals, in general, always require loading capacitors. - 30pF in this case, but easy to approximate. - Crystal datasheet will provide an example Load Capacitance **Weird Load Capacitance Trick:** `CL = 2 * (C_load - C_stray)` Measure a stray capacitance due to pins/traces. Get the datasheet's recommended Load Capacitance for the crystal oscillator. Double their difference, and use that value for your actual load capacitor on the board. e.g. 20pF spec, 5pF stray: 2 x (20-5) = 30 pF ### USB Data Pins (+External Pullup) Remember to tell KiCAD they're a differential pair by labeling the nets with `USB_D+` and `USB_D-`. Some STM32 Microcontrollers will include all the Series Termination and Pullup Resistor parts, but not always. Double check the datasheet to see what you have to include yourself. In this case, the `STM32F103C8T6` requires an external 1k5 pullup resistor on the D+ line. ### Serial Wire Debug (SWD) Pins - SWDIO (PA13) - SWCLK (PA14) Baked in LED on PA1 with 1k5 resistor. Add Net Labels to every pin on the uC even if you're not using it. It's very useful for setting up GPIO headers. ![[Pasted image 20241210052246.png]] Ideally, you would add a Ground or Power pin in between each signal pin. This helps with EMI and signal integrity. But for general purpose boards like this it's not important. It's also worthwhile to add decoupling capacitors between the GPIO header power pins 3.3V/GND, etc. ### Annotation and ERC Typical KiCAD Workflow: - KiCAD Annotator with Reference Designators, etc. - Run ERC, check for and address errors. - Then Assign PCB Footprints to Symbols. ### Footprint Selection 0603 or 0805 - Power Components 0402 - Small Decoupling Capacitors Be sure to check manufacturer stock ### PCB Layout and Sectioning ![[Pasted image 20241210052652.png]] 2 Layer Board Signal Plane Ground Plane GPIO Headers on Top and Bottom uC in the center Crystal on the left Regulator and USB input on the right Power Regulator Put bypass and decoupling capacitors very very close to the pins. Resistor and Power indicator LED right next to the power is common sense Thick 3.3V trace snaking around the board to feed into everything. STM32 Microcontroller Small decoupling capacitors as close as possible to the uC's power pins. Design for Manufacturability though, don't make them too close. If it's too close you won't be able to solder it. Load capacitors nice and close to the crystal. After routing important stuff like power, the decoupling capacitors, and the crystal, You can worry about NRST and BOOT0 and other indicator LEDs. When the bottom layer is fill ground, all your ground connections are made via drop-through vias. You can have Vias under the uC. Don't put the Vias in the pad, but right next to it. Connect with thick traces to ensure a low impedance path. Last priority is for connecting all the GPIO headers. For the D+ and D- USB Data differential pair, you can go up to `Route -> Differential Pair` then click D+ or D- and it'll find the partner and route them together. USB Traces should have a characteristic impedance of 90Ω. Running at USB full speed, 12 MBits/s. Trace impedance doesn't matter here. Note the cool branch style for the USB D+ pullup resistor. ### Silkscreen Add Logo Description Component Designators, nice and neat Zoning - POWER Indicate which are Power and Ground Maybe Serial Wire, etc. Silkscreen next to GPIO is an option as well, but not necessary if you're lazy. Good practice to indicate where pin 1 is with a silkscreen dot for the chips/uC. For Diodes and LEDs, it's good to mark there the positive side is. You can hide the silkscreen of the uC part number by putting it in the square so it gets obscured by the chip body. ### Generate Gerbers You can generate pick and place files as you wish as well. --- [[STM32F - Research Topics]] [[STM32F - Walkthrough Notes]]