PCB

Prerequisite: Analog Electronics 模擬電路, Digital Electronics 數字電路

One thing to keep in mind is that unlike software learning where you can just watch Youtube videos online and code along it, the learning method is different for hardware. You will find yourself reading text documentations and product specifications, protocol standards, measuring voltage, and asking people in the community a lot. To learn this skill, watch Hardware Wallet Research Series: #1, #2, #3, #4, #5, #6, #7

Totorial Series:

Basics of Circuit

Units:

Concepts: PCB Basics

Simple Electronics Basics Series

What are the meaning of Vdd and Vss? Vcc and Vee?? GND? https://miscircuitos.com/what-are-the-meaning-of-vdd-vss-vcc-vee-and-gnd/

What are the meaning of Vdd and Vss? Vcc and Vee?? GND? https://miscircuitos.com/what-are-the-meaning-of-vdd-vss-vcc-vee-and-gnd/

PCB Structure

PCB Layers

PCB Layers

PCB has layers:

Resistor Size

Resistor Size

PCB封装欣赏了解之旅(上篇)—— 常用元器件 https://blog.csdn.net/Mculover666/article/details/104226477

PCB封装欣赏了解之旅(上篇)—— 常用元器件 https://blog.csdn.net/Mculover666/article/details/104226477

PCB封装欣赏了解之旅(下篇)—— 常用集成电路 https://blog.csdn.net/Mculover666/article/details/104244912

PCB封装欣赏了解之旅(下篇)—— 常用集成电路 https://blog.csdn.net/Mculover666/article/details/104244912

Capacitor Arrays

Why too many capacitors in parallel for Vdd supply net? Can't we just add all to replace with one big capacitor?

Why too many capacitors in parallel for Vdd supply net? Can't we just add all to replace with one big capacitor?

Q: Why are there so many capacitors added in parallel rather than just one big capacitor?

A: Caps are located close to each digital IC, or small set of such ICs, to act as local reservoirs to smooth out the rapidly fluctuating current demands of such ICs. This prevents those rapidly fluctuating currents from causing fluctuating voltages on longer supply wires (PCB traces) and possibly disrupting other chips connected to those supply wires.

In some instances you will also see a large cap parallel with a small cap right next to it. The large cap provides a large reservoir, but has a significant internal resistance, so doesn't respond as quickly as a small cap can. So together the two caps can respond quickly and provide a large reservoir.

Real capacitors have both some internal resistance and inductance in series with their "ideal" capacitance. The effects are larger with larger-value capacitors, and vary with capacitor material and construction. For the current discussion, both these non-ideal characteristics act to slow the speed with which the capacitor can respond.

A: These caps are used as "decoupling" capacitors. Even though they appear like they're all next to each other, they will be located (often in pairs) on the circuit board next to power pins of digital IC's.

Unlike analog circuitry, a digital circuit uses power in short, fast bursts. All traces or wires have some inductance, which prevents the current from changing as quickly as the IC needs it. This causes two problems: The voltage fluctuates at the input pin, and the rapidly-changing current causes the traces to radiate electrical noise.

A decoupling capacitor provides two main functions: 1. The first function is to prevent these two problems. It acts as a small power buffer right at the IC, and can provide the necessary rapidly-fluctuating currents. Since they are located right next to the IC's, there are no long traces to act as noise generators. 2. The second function is to act as a filter, dampening noise seen from the outside of the chip. This is where the multiple values of capacitors come into play. The capacitors have some small parasitic inductance, also. Each capacitor you add creates an LC filter. Each different capacitor value, combined with the parasitic inductance, filters a different range of frequencies. It is common to see a 100pF next to a 0.1uF cap at each power pin. This combination has a favorable filtering bandwidth.

So, even though you could use one large capacitor to match the nominal bus capacitance, you would lose the decoupling benefits.

USB Connections

USB Versions

USB Versions

USB Versions (Graphical)

USB Versions (Graphical)

The names are confusing:

USB Port Colorcode

USB Port Colorcode

Before USB Type C, all connectors has a host end and a client end, which lead to the design of different type of connector on different end to avoid confusion. However, both side Type C can either be host or client (dual role), therefore Type C is commonly made with Type C on both side.

Don't confuse USB protocols (like 2.0 and 3.0) with USB connector (USB-C, USB-A). But USB-C has protocol: 3A, 60W, dual role. Knowing a physical wire has a USB-C connector doesn't tell you what protocol the physical wire supports. A full-featured USB-C should support USB 3.1 Gen 2 and compatible with USB 2.0.

Voltage of Type-C. For more, read specification: https://www.usb.org/sites/default/files/USB%20Type-C%20Spec%20R2.0%20-%20August%202019.pdf

Voltage of Type-C. For more, read specification: https://www.usb.org/sites/default/files/USB%20Type-C%20Spec%20R2.0%20-%20August%202019.pdf

Power Delivery (PD): support 5A, 100W when the device requires it. Note that not all USB-C support PD.

Alt Mode: Alternate Mode is a mechanism that uses a USB Type-C shape port and cable to send a signal of another specification. This allows people to make different flavors of USB-C cable and port to send non-USB signal as well as USB-signal through USB-signal. Only USB-C can potentially support an Alt Mode and one USB-C cable or port is limited to have one of the "flavor". You can think of a port or a cable having one of the "flavor". A "flavor" can also be thought as a bundle of supporting protocols. For example, a cable with the Thunderbolt "flavor", which bundles USB, DisplayPort, Thunderbolt protocol, can be plugged into ports with original USB flavor, or DisplayPort flavor, or Thunderbolt flavor. The cable also has type Passive or Active.

While each protocol have their native cable (for example: USB 3.2 protocol uses USB-C, display port protocol uses display port), Thunderbolt protocol's native cable uses USB-C exclusively. Thunderbolt 3-port cable is "one of many variations of USB Type-C port cables"

Alt Mode Flavor

Alt Mode Flavor

Note that all Thunderbolt Alt Mode support DisplayPort Alt Mode (except for DisplayPort 2.0) as shown in chart above.

The chart shows 5 original flavored Type-C cable's connection with different Alt Mode port. For example, it is fine to use a DisplayPort cable to connect Thunderbolt Alt Mode Type-C port. https://en.wikipedia.org/wiki/USB-C

The chart shows 5 original flavored Type-C cable's connection with different Alt Mode port. For example, it is fine to use a DisplayPort cable to connect Thunderbolt Alt Mode Type-C port. https://en.wikipedia.org/wiki/USB-C

"VBUS" is the USB bus voltage. It's nominally 5V (give or take 5%). You can connect it to the VCC on a 5V tolerant device. Sprinkle some decoupling capacitors (to filter signal) around it and your project can be bus powered. If you're self-powered, there's no need to connect VBUS to anything. Does your device has a use case where it's powered but not plugged into USB? If not, I'd put a weak pull-down on reset# and have a stronger pull-up tied to VBUS. That way the device gets a reset when it's plugged in. https://www.reddit.com/r/AskElectronics/comments/5dn0nf/what_is_vbus_in_this_diagram/

There are various symbol in the library for USB-C. For example TYPE-C-31-M-12 refers to Type-C male port (maybe 31 means with USB 3.1 protocol) and 12 ports.

USB Type-C Protocol

How USB Discovery Work

USB Charging Protocol

USB-C Pin Definition

USB-C Pin Definition

USB-C Receptacle

USB-C Receptacle

Host and Peripheral: by determine with of CC1 or CC2 is pulled low, the host can determine peripheral's orientation. (3A and 5V case, otherwisde watch https://www.youtube.com/watch?v=V1OiQoyjDOo)

Host and Peripheral: by determine with of CC1 or CC2 is pulled low, the host can determine peripheral's orientation. (3A and 5V case, otherwisde watch https://www.youtube.com/watch?v=V1OiQoyjDOo)

If a cable only support UBS2, not beyond 5V and not beyond 3A, then it may not be electronically marked. Otherwise, all cable need to be electronically marked.

An Electronically Marked Cable Assembly (EMCA) is a USB Type-C cable that uses a marker chip to provide the cable’s characteristics to the DFP. The electronic marking is accomplished by embedding a USB PD controller chip into the plug at one or both ends of the cable. These marker chips operate from VCONN power (or VBUS power as per the cable design). VCONN is a low voltage rail operating between 2.7 Volts and 5.5 Volts but is limited to 1 Watt of power. VBUS can be a high voltage rail up to 20 Volts. While marker chips operating off of VBUS can take advantage of more power a high voltage marker chip can also be more expensive. For this reason, most marker chips are powered by VCONN.

USB-C with Cable

USB-C with Cable

For legacy device using USB2.0, the following connection should be made.

Source to Legacy Device Port Functional Model. Note the value for Rd can be found in Table 4-25 at https://www.usb.org/sites/default/files/USB%20Type-C%20Spec%20R2.0%20-%20August%202019.pdf

Source to Legacy Device Port Functional Model. Note the value for Rd can be found in Table 4-25 at https://www.usb.org/sites/default/files/USB%20Type-C%20Spec%20R2.0%20-%20August%202019.pdf

UBS connection needs impedance matching and sometimes 1.5k Resistor for indicate full-speed device. However, these two are incorporated in most STM32 chips.

Surface Mounting Technology (SMT)

封装 尺寸 功率 电阻耐压值 V
0201 1/20W 25 P2P
0402 1.0mmx0.5mm 1/16W 50
0603 1.6mmx0.8mm 1/10W 50
0805 2.0mmx1.2mm 1/8W 150
1206 3.2mmx1.6mm 1/4W 200
1210 3.2mmx2.5mm 1/3W 200
1812 4.5mmx3.2mm 1/2W 200
2225 5.6mmx6.5mm

Soldering

Soldering is to make connections by melting the right amount of solder to make bound with copper.

Flux: Flux is to remove oxidized layer of copper wire so that solder can directly bound with copper instead of staying on the surface of oxidized layer. The remaining flux can be removed from PCB by washing with Isopropine alcohol.

Solder: thin solder is good as it gives you more control of amount of solder you are applying. Typically solder comes with flux inside the wire.

Cleaning:

Temperature: 316~343 Celsius for lead-based solder and 343~371 Celsius for lead-free solder

Protection: leave some solder on the tip if you are not using the tip for a while

Other stuff you might (or might not) need: insulator heat shrink, plate holder, wire cutter or striper, soldering breadboard.

Technique:

If you prefer unnecessarily long video, watch this (Part 1) and (Part 2)

For more, it is good if you can read The Ultimate Guide to Soldering

If you have multiple PCB boards, you can order a solder paste stencil to help you mount the components on PCB quickly. You must order the stencil with the PCB as the height and holes must match.

There are also machines in CMU TechSpark (and courses) that can mount components for you

51 Chip

Preperation:

MCU: Micro Controller Unit, including CPU, RAM, ROM, click, ...

8051: The Intel MCS-51 (commonly termed 8051, typically pronounced eight-oh-five-one) is a single chip microcontroller (MCU) series developed by Intel in 1980 for use in embedded systems. So any chip support MCS-51 instruction set is 51-MCU.

STC89 Nomenclature

STC89 Nomenclature

Different IC Package

Different IC Package

STC98C51RC/RD+ Block Diagram from http://www.stcmcudata.com/datasheet/stc/STC-AD-PDF/STC89C51RC-english.pdf

STC98C51RC/RD+ Block Diagram from http://www.stcmcudata.com/datasheet/stc/STC-AD-PDF/STC89C51RC-english.pdf

STC98C51RC/RD+ Minimum Application System. The white arrow means positive and the dashed arrow means negative. The two capacitors are for electronic filters and 18/19 pins are for CPU clock. Pin 9 is reset button

STC98C51RC/RD+ Minimum Application System. The white arrow means positive and the dashed arrow means negative. The two capacitors are for electronic filters and 18/19 pins are for CPU clock. Pin 9 is reset button

HC6800-ES

HC6800-ES

A bar on the top of a port means low voltage enabling.

VCC (Volt Current Condenser): 电路的供电电压

GND (COM): Ground CE(OE): Chip Enable, 使能. 芯片的開關.

LED and Buttons

When we press a button, a raw voltage is sent to a port. Usually, we make the port output 0 on some port and connect LED with the port and GND to light up the LED. The same goes for LED arrays.

按鍵消抖: we can do hardware or software based signal filter to clean up the in-coming signal.

按鍵消抖: we can do hardware or software based signal filter to clean up the in-coming signal.

There are two types of connection for LED arrays, we can either share common anode or common cathode (GND).

Common Cathode and Common Anode in LED arrays

Common Cathode and Common Anode in LED arrays

For display matrix, the circuit is arranged in the following manner (similar to keyboards)

LED Numeric Display Circuit Diagram

LED Numeric Display Circuit Diagram

LED Numeric Display Circuit Diagram on 51 MCU where 'COM' means common port, most likely negative.

LED Numeric Display Circuit Diagram on 51 MCU where 'COM' means common port, most likely negative.

When there is lack of pins to accurately identify the LED or input button, we can scan the port (only detecting or outputing a certain row or column)

掃描: 減少 I/O

How I/O port works, 弱上拉模式 - 強 GND, 弱 VCC

How I/O port works, 弱上拉模式 - 強 GND, 弱 VCC

Clocks and Interuption

STC89C52 has built-in internal clocks (T0, T1, T2) where T0 and T1 clocks are in all traditional 8052 and T2 is specific to STC89C52.

Clock: clock is counter, you can command the clock to interupt after some time.

There are 4 modes for STC89C523 T0 and T1 clocks:

How clocks work in hardware: SySclik (晶振週期) provide clock pulse to clock and is received by two counters. One counter count the number of low voltage and the other count the number of high voltage. They share a number of bits (16 in Mode 1). When the counters overflow, interrupt is triggered. When the input is connected to port instead of SySclik, then the clock becomes a counter.

How clocks work in hardware. T0 Pin here is a port to use it as a counter (if C/T is 0, then it listen from system clock, otherwise from pin T0). 12 T mode takes the input frequency and divide by 12. If 12 T mode is used, a klzzwxh:0059 CPU clock will become klzzwxh:0060.

How clocks work in hardware. T0 Pin here is a port to use it as a counter (if C/T is 0, then it listen from system clock, otherwise from pin T0). 12 T mode takes the input frequency and divide by 12. If 12 T mode is used, a 12 Hz CPU clock will become 1 Hz.

If the CPU clock is 1 Hz, then the voltage go high and low for 1000000 times.

There are limited amount of interuption hardware in STC89C523 (OutsideInterrupt0, ClockInterrupt0, OutsideInterrupt1, ClockInterrupt1, SerialPortInterrupt, OutsideInterrupt2, OutsideInterrupt3) where the last two are not common in typical 8051. There are also limited number of priority int.

Clock Wires are Controlled by Setting Bits in Memory

Clock Wires are Controlled by Setting Bits in Memory

Pull-up Resistors

This article: 上拉电阻, 下拉电阻, 强上拉, 弱上拉, 强下拉, 弱下拉 and this article explains the concept.

Strong pull-Up is the action of increasing the voltage of a point by connecting the point with higher voltage through a low resistor. This way, the voltage of the point is nearly identical as the voltage of the added voltage. Weak pull-up is the action of increasing the voltage of a point by connecting the point with higher voltage through a high resistor. This way, the voltage of the point is only increased a bit. Pull-down shares the same idea as pull-up but for the purpose of decreasing the voltage of a point.

Serial Port

Serial Port is a port to transmit byte information between two device.

The serial port looks like VGA port but it only has 9 pins. Do not confuse it with VGA. Many old computers have this port. There are serial port to usb or even bluetooth adaptor.

The easiest connector with serial port only involves 4 pins. VCC, TXD, RXD, GND for device 1 and VCC, TXD, RXD, GND for device 2. Note that we cross connect TXD and RXD. (Be careful on PCB schemetic) The TXD stands for Transmit Exchange Data and RXD stands for Receive Exchange Data.

Serial Port DB9 male

Serial Port DB9 male

We could ignore one of TXD, RXD connection if the data flow is one directional.

There are multiple protocol we can use

The reason we use Differential Signalling is that it can transmit beyond 10 meters or wire and possibly 1000 meters without much disturbance. This protocol is commonly used in USB.

Other pins like DTR and RTS are pins that control data flow (not supported by 8051)

Half Duplex: can send and receive, but not at the same time. Usually 1 pin. Full Duplex: can send and receive at the same time. Usually 2 pins. Single Duplex: only one way transmission by 1 pin (or bluetooth wireless etc...)

Async: both device obey their own transmission rate Sync: both device obey the same clock cycle, usually needs a clock pin.

There are a few more protocols: and also CAN(in cars), USB

Name Pins Transmission Comments
UART TXD, RXD Full Duplex, Async Point to Point Transmission
PC SCL, SDA Half Duplex, Sync Multiple Device attach on Main Line
SPI SCLK, MOSI, MISO, CS Full Duplex, Sync Multiple Device attach on Main Line
1-Wire DQ Half Duplex, Async Multiple Device attach on Main Line

UART is serial port // QUESTION

STC89C52 has 4 modes for UART:

Bit Orders of Transmission on 9 bit UART

Bit Orders of Transmission on 9 bit UART

Baud Bit: the rate of transmission sampling Verify Bit: Hamming Code Stop Bit: divide byte to byte

I/O Extension

We can use chips like 74HC695 to extend the number of IO ports. It is esstentally a register that take sequential input and converted to synchronous signal.

74HC595

74HC595

The way it works is that we send bit information to one port and then move the all information by one slot (and reset). Once all data is there, we batch send them.

STM32

STM32 MCUs

STM32 MCUs

STM32 Nomenclature

STM32 Nomenclature

There are following peripherals on the chip:

STM32F103C8T6 Pin Defintion. Blue is minimal circuit while red is related to power. klzzwxh:0096 means power. klzzwxh:0097 means 5V, otherwise 3V. Re-definition allows us to re-define a pin for other usage.

STM32F103C8T6 Pin Defintion. Blue is minimal circuit while red is related to power. S means power. FT means 5V, otherwise 3V. Re-definition allows us to re-define a pin for other usage.

Some images and text are from STM32固件库(标准外设库)入门学习 第一章 STM32简介

Pin Definitions #1

Pin Definitions #1

Pin Definitions #2

Pin Definitions #2

Boot Loader Guiding Pins. klzzwxh:0101为最常用的, 默认的启动方式. klzzwxh:0102, 这个模式主要用来做串口下载用, 系统存储器存的是STM32中的一段 BootLoader 程序, 该程序的作用就是接收串口的数据, 然后刷新到主闪存中,这样就可以使用串口下载程序了, 一般使用串口下载程序会配置到这个模式. 当 klzzwxh:0103 串口引脚都被配置 IO 口, 程序不能下载, 此时若想使用出串口下载, klzzwxh:0104 为 0, klzzwxh:0105 为 1。若无 ST-LINK 也没有 J-LINK, 也可以使用串口来进行下载程序,这样多了一种下载程序. klzzwxh:0106 主要用于程序调试.

Boot Loader Guiding Pins. X0为最常用的, 默认的启动方式. 01, 这个模式主要用来做串口下载用, 系统存储器存的是STM32中的一段 BootLoader 程序, 该程序的作用就是接收串口的数据, 然后刷新到主闪存中,这样就可以使用串口下载程序了, 一般使用串口下载程序会配置到这个模式. 当 34, 37, 38, 39, 40 串口引脚都被配置 IO 口, 程序不能下载, 此时若想使用出串口下载, 就需要配置BOOT1 为 0, BOOT0 为 1。若无 ST-LINK 也没有 J-LINK, 也可以使用串口来进行下载程序,这样多了一种下载程序. 11 主要用于程序调试.

Note the Capacitor between GND and 3.3V is for stablizing voltage. VBAT can be connected to a backup Button Battery (not necessary, can connect to 3.3V or nothing).

Note the Capacitor between GND and 3.3V is for stablizing voltage. VBAT can be connected to a backup Button Battery (not necessary, can connect to 3.3V or nothing).

供电电路: 在3.3V和GND之间有滤波电容C4、C5、C6、C7,这个电容可保证供电电压的稳定,在设计电路的时候,只要有供电,都会习惯加上几个滤波电容。 晶振电路: 8MHz晶振接到5、6号引脚,还需要接两个20pF的电容,作为启振电容,电容另一端接地。

若需要RTC实时时钟功能,还需要接一个32.768kHz的晶振,电路与此图一样,接在3号(PC14)、4号(PC15)引脚。32768是2的15次方,内部RTC电路经过2的15次方分频,就可以生成1秒的时间信号。

若需要RTC实时时钟功能,还需要接一个32.768kHz的晶振,电路与此图一样,接在3号(PC14)、4号(PC15)引脚。32768是2的15次方,内部RTC电路经过2的15次方分频,就可以生成1秒的时间信号。

复位电路: 复位电路是一个10k的电阻和0.1uF的电容组成,用来给单片机提供复位信号,接7号引脚,NRST为低电平复位的,复位电路在上电的瞬间,电容是没有电的,电源通过电阻开始向电容充电,并且此时电容呈现的是短路状态,NRST引脚为低电平,当电容逐渐充满电时,电容就相当于断路,此时NRST就会被上拉为高电平。上电顺间的波形就是先低电平,然后逐渐高电平。电路左端有K1按键,提供一个手动复位,按下K1电容被放电,并且NRST引脚也通过按键被直接接地了,相当于手动产生了低电平复位信号。按键松手后,NRST又回归高电平,此时单片机就从复位状态转为工作状态。平时在电子设备上也会看到这个,一般是一个小孔,当设备死机并且不方便断电重启时,就可以拿一个针去戳一下,就可以使设备复位了。

启动配置电路: H1相当于开关的作用,拨动开关就可让BOOT引脚选3.3V还是GND,在最小系统板上使用的是跳线帽充当开关的功能,当跳线帽在左边两个引脚时,就相当于接GND,插在右边两个引脚时,就相当于接3.3V。这样就可以配置BOOT的高低电平。自己设计电路时,可以接一个拨码开关。

下载端口电路: 若采用ST-LINK需要把SWDIO和SWCLK这两个引脚引出方便接线,另外还需要把3.3V和GND引出来,这个GND是必须引出的,3.3V板子有供电的话可以不引。有时候也会在供电处加一个电源滤波,作用就是稳定供电。

下载端口电路: 若采用ST-LINK需要把SWDIO和SWCLK这两个引脚引出方便接线,另外还需要把3.3V和GND引出来,这个GND是必须引出的,3.3V板子有供电的话可以不引。有时候也会在供电处加一个电源滤波,作用就是稳定供电。

测试用LED电路: 上面为电源指示灯,另一个接PC13,这是一个IO口的测试灯。

测试用LED电路: 上面为电源指示灯,另一个接PC13,这是一个IO口的测试灯。

稳压电路: 将5V电压降到3.3V,给STM 32供电。稳压芯片估计为XC6204,它是3.3V的稳压芯片,另外还有XC6206、AMS1117等都是常用的稳压芯片,设计电路时可以参考。

稳压电路: 将5V电压降到3.3V,给STM 32供电。稳压芯片估计为XC6204,它是3.3V的稳压芯片,另外还有XC6206、AMS1117等都是常用的稳压芯片,设计电路时可以参考。

USB电路: PA11和PA12是STM32的USB引脚,可进行USB通信,该USB还提供5V供电。

USB电路: PA11和PA12是STM32的USB引脚,可进行USB通信,该USB还提供5V供电。

STM32 Hardware in Practice

Read Manual:

When purchasing parts, go to LCSC-EN as the chinese version sucks.

STM32 Firmware in Practice

Here is a video explaining STM32CubeIDE and you can download it here. You can also thoose STM32CubeMX but it does not have a debian version.

There are a few protocol for between-device communication

Here is a blog post clarify CAN, I2C, JTAG, SPI, SWD, and UART

There isn't a consensus on how to connect SWD pins. You can define how many pins as you want and they are connected by jump wire.

These protocols are used for additional drivers in addition to having one MCU. Usually MCU flash is done with USB DFU protocol used in the STM32 bootloader. DFU stands for Device Firmware Upgrade and it only allows you to flash a new device (Getting started with STM32 built-in USB DFU Bootloader) and cannot be used for debugging purposes. Flashing a device with USB DFU involving set BOOT0 to 1 and flash using USB connection and then set BOOT0 to 0 before RESET. You need to have one of the above protocol (and port) open for debugging purposes as you can't debug with USB DFU. Specific tools like JTAG, ST-Link, or USB-to-UART is needed.

Many keyboards in the QMK Firmware repo are split keyboards. They use two controllers: one plugging into USB, and the second connected by a serial or an I2C connection over a TRRS or similar cable. ARM split supports most QMK subsystems when using the ‘serial’ and ‘serial_usart’ drivers. I2C slave is currently unsupported by QMK. Both sides must use the same MCU family.

If you want to make a split cable, see Required Hardware

For flashing firmware into STM32, see Boot Mode section.

At startup, the boot pin and boot selector option bit are used to select one of the three boot options: - boot from User Flash memory - boot from System Memory - boot from embedded SRAM

The boot loader is located in System Memory. It is used to reprogram the Flash memory by using USART on pins PA14/PA15, or PA9/PA10 or I2C on pins PB6/PB7 or through the USB DFU interface.

Some MCU does not have BOOT1 pins. You might only be able to set BOOT1 using software.

Regulator

Here is a introduction to linear regulator (LDO)

Types of Regulator:

Common LDO:

Sometimes scottky diode (instead of silicon diode as it doesn't impact voltage as much) can be used to prevent backflow of power when user connected to the wrong end. Note that scottky diode might not be able to block all current, 20mA will leak through as compared to silicon diode, but it is sufficient for reverse voltage protection. Absolute maximum rating is normally set as 10V greater than peak reverse voltage, peaking higher voltage rating will sacrefice efficiency.

Power protection (ESD/TVS) and filtering can get very complicated and often involves:

ESD/TVS

Compare ESD and TVS, we know that ESD is protection for human electrical discharge, and TVS is protection for electrical surge. They appear on schemetic as a inverte-connected diode. Such protection is needed at connection to USB since it USB provides both power and signal.

Impedient Matching

Q: So a bit of an odd question, I want to replace all the various bits on a Mysterium with a black pill (sans diodes, switch, etc) If I run lines from PA11, PA12 (Data + and Data -) as well as GND and VCC, and use an external USB port, will I need to add a resistors on the data lines or would that all be handled by the Black pill itself? A: STM32 chips don't need impedance matching resistors on USB data lines, so you should not need to add anything extra (although you may want to add things like a fuse and ESD protection). And if you will be using a Type C port, you will need two 5.1k resistors on CC pins (but they won't be connected to the blackpill).

You should check the manual to see if your chip has integrated impedance matching for USB.

NRST and Boot

advance circuit for reset and boot

advance circuit for reset and boot

Here is an advanced circuit for reset and boot. The circuit make use of MOSFETs to act as a voltage-controlled switch. When the human-controlled botton is pressed, the BOOT pin gets powered, and then once powered, the NRST pin is powered by the internal MCU, therefore disconnect BOOT from 3.3V. Once botton is released, NRST is pulled down by GND and reset the MCU.

PCB Design Rules

Here is a good Routing Tutorial. And here is a tip video for PCB routing

Via Stub

Via Stub

PCB Design Rules

Debugging Hardware

STM32 Nucleo-F446RE Pin Out

STM32 Nucleo-F446RE Pin Out

Instead of buying an ST-Link, we can buy a developmen board.

Follow this guide so that you know to light up LD2, you need to set A5 high. You can use STM32CUBEIDE and run debug configuration. In C/C++ application set your flashing .elf file and hit run to flash your board with ST-LINK S/N enabled and scan automatically.

  1. Create a new project (with the correct processor)
  2. Hit Run
  3. Hit Run Configuration
  4. Double Click STM32 C/C++ Application
  5. Give it a name
  6. At C/C++ Application, give path to your .elf file
  7. In Debugger, Misc -> Log to file, enable and select a log file (otherwise will result in device not found error)
  8. In Debugger, GDB Server Command Line Option -> Interface, check ST-LINK S/N and hit Scan.
  9. Press Run.

Assume you have just purchased ST-Link and soldered your board, here is what you need to do to debug:

  1. Power up your board
  2. Connect ST-Link to your computer
  3. Remove two jumpers to ST-Link if you have purchased NUCLEO-F446RE instead
  4. Connect SWD from ST-Link to your board following this video
  5. Create a project in STM32CUBEIDE, and configure the pins you want to test by clicking the pin and select GPIO_OUTPUT
  6. Configure external crystal setting if you are using one
  7. Save the file and generate the code
  8. In the while loop, add the code that looks like this (names may be different)
  9. Click the debug icon to start debug
  10. The program will pause on default breakpoint, click green arrow to continue
  11. Note that for some reason, you can only configure one debug profile (the second one would not work)
  while (1)
  {
    /* USER CODE END WHILE */
  HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_10);
  HAL_Delay(500);
    /* USER CODE BEGIN 3 */
  }

Impedance Matching

Here are a list of video explaining the concept of impedance matching

Here is a trace impedance calculator for signal and here is a trace width related to current consumption and here is differential impedance calculator (jlc uses 4.5 Dielectric Constant in FR4 with option of standard 1.6mm or 63 mil board and 1oz of copper is 35\mu m thick or 1.4 mils). Note that you should consider manufacturer's capability when using design rules. However, Altium Designer is the only option for calculating trace width for coplanar differential pairs (read article).

For hand-calculation of Edge-coupled coplanar, see this stackoverflow

Coupled Differential Pairs

Coupled Differential Pairs

Final Check

Once you settle down your design, check out this good video as it will run you through the entire process of pcb design with small caution (or nice to have) details like impedance matching and power protection.

Copper Pour

To connect GND together, you fill out copper in all planes. For 4 layers, it is common to have Signal, GND, POW, Signal stackup. However, there isn't a consensus on whether you should pour GND for the top layer in 2-layer PCB.

This is for:

Note that for digital signal, copper pour is good. But it might be bad for analog signal due to electromagnetic coupling. Therefore not all pcb needs copper pour.

There are two ways to do copper pour

Other Stuff

Before Finish Design: - vias in chip for heat dissipation - rounding edge - testing pad with exposed copper - screw holes - pretty drawing and logos - pin labels

Table of Content