STM32 Overview
Why Use STM32?
Prior to the 22-23 competition season, the only microcontrollers used on the car were NERduinos, which utilize Teensy 4.1 (ARM Cortex-M7 at 600 MHz, 7936K Flash, 1024K RAM). While these have served us well, they’re both difficult to acquire and fairly expensive (~$32 apiece). The STM32 series from STMicroelectronics presents a massive array of chips spanning a wide spectrum of cost/performance ratios, meaning that we can almost always find something that matches the task at hand in both price and functionality. The STM32 line includes MCUs ranging from ARM Cortex M0 to Cortex M7, as well as MPUs. They can also support a wide range of peripheral devices (including CAN, which is the most important for us), and all STM32s are supported by the STM32Cube Development Environment, making it very easy to switch between chips and re-use code.
STM32 Features
The following lists include most of the features available through microcontrollers in the STM32 series:
IO Count: 6-140
Program Memory Size: 8KB-2MB
RAM size: 2KB - 640KB
Speed: 24-550MHz
Connectivity: CANbus, EBI/EMI, Ethernet, Memory Card, I²C, IrDA, LINbus, MDIO, MMC/SD/SDIO, QSPI, SAI, SPDIF, SPI, SWPMI, UART/USART, USB OTG
Peripherals: Brown-out Detect/Reset, DMA, I²S, LCD, POR, PWM, WDT Bluetooth, SmartCard
ADC/DAC: up to 42 12-bit ADC channels, 7 12-bit DAC channels
There are also several categories of STM32s, which can be identified from the part numbers. This page from Digikey is a great resource on understanding STM32 part numbers.
STM32 Circuit Design
Before even settling on a particular chip, a good first step is to create a new project in the STM32CubeIDE.
Power
Almost all STM32s require 3.3V (although a few accept 5V). They’re fairly low power (STM32G431C8T6 draws 150mA max, measured as the sum of all currents into VDD pins). The STM32G431C8T6 chip can sink/source 20mA max per GPIO pin, but the total current output or input across all GPIO must remain below 100mA.
SWD pins
Make sure that at minimum the Adafruit 2548 programmer can connect to the SWDIO-JTMS and SWCLK-JTCK pins of the STM32, as well as 3.3V and GND. A PH2-10-UA male header was used for the wheel PCB, but any 0.100"/2.54mm pitch connector should work
Boot pins
Make sure that the boot pins of the chosen STM32 are pulled up/down according to the intended means of programming (see the Boot Modes section of the spec sheet, and/or google the boot pin functions for a given chip).
Decoupling Capacitors
To figure out what arrangement of decoupling caps are required, refer to the Power Supply Scheme section of the spec sheet. Since STM32s have several power pins, make sure to add schematic notes detailing where each capacitor should be placed in the layout.
NRST Button
It’s a good idea to tie the NRST pin to ground through a pushbutton, so that you can reset the chip if needed. A 0.1uF debouncing capacitor should be included in parallel to the pushbutton (see Recommended NRST pin protection in spec sheet).
CAN
If the STM32 will connect to the car’s CAN bus, connect the FDCAN TX pin to the TX/D/Driver pin of a CAN transceiver (SN65HVD231QDRQ1 works well), and connect the FDCAN RX pin to the RX/R/Receiver pin of the transceiver. Although CAN FD (Flexible Data rate) is technically a more complex protocol than CAN2.0B (what we use), it is fully backwards compatible with CAN2.0B and can use the same transceivers.
DO NOT put capacitors on the TX/RX lines, or on the CANH/CANL lines as was done in NERduino and the Steering Wheel PCB. This completely shuts down CAN communication if you put them on the TX/RX lines, and causes significant signal distortion if put on CANH/CANL.
ADC Inputs
An unresolved issue with the Steering Wheel PCB involves variation of the voltage on one ADC pin affecting the reading on an adjacent pin. This seems likely to be a timing issue (switching between ADC channels too quickly with DMA), but this still needs to be ruled out to confirm there isn’t also a hardware issue at play.
Reference boards
The 17D Steering Wheel PCB uses a STM32G431C8T6, and at time of writing is the only completed and tested NER PCB using an STM32. Another good resource is the design files provided by STM32 for all of their Nucleo Dev Boards (You can find the design files for the NUCLEO-G431KB here).
STM32 Layout/PCB Design
Make sure that the decoupling capacitors wind up at the VCC pins they’re supposed to be at.
Design rules will likely need to be modified in order for the chip itself to not throw errors due to close pad spacing.
Programming the STM32
The current strategy for programming STM32s is to use an Adafruit 2548 ST-Link V2 Programmer to program the boards over SWD (ARM Serial Wire Debug) protocol. When connected to the 3.3V rail, this programmer is able to power the STM32, which is handy for board testing without a power supply.
STM32CubeIDE
Learning Resources
The overall best resource I’ve found so far is the STM32 Digikey series by Shawn Hymel:
If you’re looking for a really in-depth walkthrough of the entire Altium design cycle for an STM32 board, this video (along with the rest of his channel) is an excellent resource: