Introduction
When learning STM32, many developers focus on software and overlook the hardware aspects. This often means they are comfortable using development boards but struggle when it comes to designing their own custom STM32 system. This article provides a guide to designing a minimal system for an STM32 microcontroller.
Components of an STM32 Minimal System
Overview
An STM32 minimal system consists of the essential components required for the microcontroller to operate correctly. It provides the necessary environment for the STM32 MCU to run. The main parts of an STM32 minimal system are:
- Power supply circuit
- Clock circuit
- Programming and debug circuit
- Reset circuit
- Boot mode selection
Since the STM32 MCU has an internal clock, it can technically function with only a power supply and a reset circuit. However, in practical applications, other circuits are needed to ensure the system is flexible, stable, immune to interference, and debuggable. The minimal system described here is based on the STM32F103RCT6.
Power Supply Circuit
When designing the power supply, the first step is to determine the input voltage. This design uses a 5V USB power source. Since the microcontroller's operating voltage is 3.3V, a voltage regulator is needed. We use the AMS1117-3.3 chip to step down the 5V input to 3.3V for the MCU.
In applications requiring a high signal-to-noise ratio, it's important to separate the analog and digital signals to prevent mutual interference. VDDA is the power supply for the ADC and DAC modules. VREF+ is the positive voltage reference input pin, and VREF- is the negative. VREF+ should be connected to VDDA, and VREF- to VSSA.
Generally, a simple low-pass filter (such as an RC or Pi filter) between the digital power supply (VDD) and the analog power supply (VDDA) is sufficient. The digital and analog grounds can be isolated with a 0Ω resistor or a ferrite bead. In less demanding applications, they can be connected directly to a common ground plane.
Clock Circuit
According to the official STM32 datasheet, the high-speed external clock (HSE) can be driven by a 4MHz to 16MHz crystal. An 8MHz crystal is commonly used, as it can be easily multiplied by the Phase-Locked Loop (PLL) to generate higher frequencies for various peripherals. The clock circuit consists of a crystal, load capacitors, and an optional feedback resistor (in the MΩ range). If an external high-speed clock is not used, the OSC_IN pin should be grounded, and the OSC_OUT pin should be left floating.
The low-speed external clock (LSE) uses a 32.768kHz crystal to provide a clock source for the Real-Time Clock (RTC). Since 2^15 = 32768, this frequency can be easily divided down in a register to produce a precise 1Hz signal, which is ideal for timing applications like a perpetual calendar.
Crystal Oscillators vs. Crystal Resonators:
- Passive Crystal (Resonator): Flexible, typically offers sufficient precision, low cost, and requires external load capacitors.
- Active Crystal (Oscillator): More stable, requires an external power supply, and does not need external support circuitry.
Reset Circuit
A reset circuit is essential for ensuring the stable and reliable operation of the STM32 system. It allows the MCU to be returned to its initial state, which is crucial for recovering from program faults and preparing the system to receive new instructions.
Boot Mode Selection
STM32 microcontrollers use the BOOT0 and BOOT1.
- Main Flash memory: Executes the user application.
- System memory (Bootloader): Executes the built-in bootloader for serial programming.
- Embedded SRAM: Executes code loaded into SRAM.
Appendix
STM32 Chip Selection
When starting an STM32 project, select a chip based on the functional requirements. After defining the project's needs, you can use ST's official selection manuals or download datasheets to find a suitable chip.
Chip Pin Functions
During system design, you must consult the chip's datasheet to confirm the functions of the pins you intend to use. For example, if you need to connect an external low-speed crystal, you must find the corresponding pins in the datasheet. This article uses the STM32F103RCT6, a 64-pin package. The pins for the external crystal are PC14 and PC15. This information is then used to connect the external circuitry in the schematic.