Electronics project notes/STM32 notes

From Helpful
Revision as of 23:11, 21 April 2024 by Helpful (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

⚠ This is for beginners and very much by a beginner / hobbyist

It's intended to get an intuitive overview for hobbyist needs. It may get you started, but to be able to do anything remotely clever, follow a proper course or read a good book.

Some basics and reference: Volts, amps, energy, power · batteries · resistors · transistors · fuses · diodes · capacitors · inductors and transformers · ground

Slightly less basic: amplifier notes · varistors · changing voltage · baluns · frequency generation · Transmission lines · skin effect

And some more applied stuff:

IO: Input and output pins · wired local IO · wired local-ish IO · ·  Various wireless · 802.11 (WiFi) · cell phone

Sensors: General sensor notes, voltage and current sensing · Knobs and dials · Pressure sensing · Temperature sensing · humidity sensing · Light sensing · Movement sensing · Capacitive sensing · Touch screen notes

Actuators: General actuator notes, circuit protection · Motors and servos · Solenoids

Noise stuff: Stray signals and noise · sound-related noise names · electronic non-coupled noise names · electronic coupled noise · ground loop · strategies to avoid coupled noise · Sampling, reproduction, and transmission distortions

Audio and video notes: See avnotes

Platform specific

Arduino and AVR notes · (Ethernet)
Microcontroller and computer platforms ··· ESP series notes · STM32 series notes

Less sorted: Ground · device voltage and impedance (+ audio-specific) · electricity and humans · Common terms, useful basics, soldering · landline phones · pulse modulation · signal reflection · Project boxes · resource metering · SDR · PLL · vacuum tubes · Multimeter notes Unsorted stuff

Some stuff I've messed with: Avrusb500v2 · GPS · Hilo GPRS · JY-MCU · DMX · Thermal printer ·

See also Category:Electronics.

For STM in the context of other DIY chips, see Electronics_project_notes/Microcontroller_and_computer_platforms#STM32

Voltage and current

This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

Regularly run at 3.3V (down to 2V), generally considered a 3.3V device.

A subset of pins are 5V tolerant (when you disable pullup/pulldown), others are not, so don't assume this.

As to power draw, maybe run STM32CubeMX - it's to generate the boilerplate code to enable/disable specific peripherals at boot (and configure CPU idle rates), but in the process is pretty good at estimating the resulting current.

Models and boards

Starting to understand STM32 model codes
This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

1 letter: Type/market

F - Foundation / general purpose (probably the most common?)
L - Low-power
G - Mainstream
H - High performance
W - Wireless

1 digit: Core

0 - Cortex M0
1 - Cortex M3
2 - Cortex M3
3 - Cortex M4
4 - Cortex M4
7 - Cortex M7

(These two combine as a series. Not all exist, see series list below)

2 digits: Product line within the series - so the meaning varies per series

e.g. for F1
00 - 24MHz, motor control
01 - 36MHz
02 - 48MHz, USB
03 - 72MHz, USB, CAN, motor control
05, 07 - 72MHz, Ethernet, CAN, USB OTG
e.g. for F4 (most have USB, many have crypto and rng) (verify) TODO: finish this list
01 - 84MHz
05/15 - 168MHz, 2 DACs,
07/17 - 168MHz, 2 DACs, Ethernet, camera interface
10 - 100MHz, DAC
11 - 100MHz, 5 SPI
12 - 100MHz,
13/23 - 100MHz, more serial ports than most
27/37 - 180MHz, memory controller
29/39 - 180MHz, memory controller
46 - 180MHz, memory controller
69/79 - 180MHz, LCD-TFT and MPI-DSI

1 letter: pin count (will roughly correlate with package type), e.g.

C - 48 (or 49)
R - 64 (or 66)
V - 100
O - 90
Z - 144
(the list is longer, omitted for brevity)

1 letter/number: Flash size (within a line this is strongly correlated to RAM(verify)), e.g.

4 - 16KiB Flash (RAM e.g. 6KiB for F1)
6 - 32KiB Flash (RAM e.g. 10KiB for F1)
8 - 64KiB Flash (RAM e.g. 20KiB for F1)
B - 128KiB Flash (RAM e.g. 20KiB for F1, 64KiB for F4)
C - 256KiB Flash (RAM e.g. 48KiB for F1, 64KiB for F4)
D - 384KiB Flash (RAM e.g. 96KiB for F4)
E - 512KiB Flash (RAM e.g. 96KiB for F4)
F - 768KiB Flash
G - 1024KiB Flash (RAM e.g. 96KiB for F4)
H - 1536KiB Flash
I - 2048KiB Flash
(the list is longer, omitted for brevity)

1 letter: Package, e.g.

(the list is longer, omitted for brevity)

1 number: Temperature

6 - -40C to 85C
7 - -40C to 105C

See also:

It seems the series that exist are currently:

F1 series (launched 2007), Cortex-M3
F2 series (launched 2010), Cortex-M3
L1 series (launched 2010), Cortex-M3
F4 series (launched 2011), Cortex-M4F
F3 series (launched 2012), Cortex-M4F
F0 series (launched 2012), Cortex-M0
F7 series (launched 2014), Cortex-M7F (pin compatible with F4, faster)
L0 series (launched 2014), Cortex-M0+
L4 series (launched 2015), Cortex-M4F
L4+ series (launched 2016)
H7 series (launched 2017), Cortex-M7F
L5 series (launched 2018), Cortex-M33F
G0 series (launched 2018), lower-power variants of L0 (Cortex-M0+)


WB series
WL series

For example:


The first three are F1 series and all F103 line.

The last four are F4 series, and four different lines (F405, F407, F401, F411).

IO featureset will vary between distinct lines, but also note that fewer-pin versions within a line can omit things because they don't have enough pins to expose them, so consult the datasheet.

Datasheets will often be for a line, part of a line , or group a few similar-enough lines basically varying with how similar their features are.

Blue pill notes
This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

Blue Pill boards are typically based on the STM32F103C8T6 (Cortex-M3, STM32F1 series - 72MHz, 64KiB Flash, 20KiB SRAM)

If USB doesn't work:

  • R10 problem: R10 on the board is the USB's D+ line pullup, which should be 1.5k -- but is higher on many older blue pill boards
there's a hack in putting something in parallel on external pins (e.g. if the resistor is 10k, adding ~1.8k should work)
  • Many boards do not come with a USB-capable firmware/bootloader(verify)
you will need to flash one over serial
Note that USB code takes ~20KB, so if you don't need it, you may want to skip that
(that said, most people don't need a huge amount of code, so USB is just nice to have)
   0     x    on-board flash (the firmware you wrote)
   1     0    system ROM (mostly for programming mode, see ST AN2606)
   1     1    SRAM (certain debugging, sometimes being controlled by something else)

...so most of us only care to set BOOT0, to switch between low=flashing and high=operating (on many versions that't the top jumper left and right, respectively)

Black pill (Blue Pill 2) notes

Black Pill boards are typically based on the STM32F401CCU6 or STM32F411CEU6 (Cortex-M4F, STM32F4 series)

Compared to blue pill, these will have

higher clock speed (84 and 100MHz)
256 or 512KB flash
64 or 128KB SRAM
USB-C port
a few more IO options (but how much is exposed)

They cost maybe twice as much, which is still not much






This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

Serial ports

Some series have up to 5 hardware serial ports, but most DIY boards have only three.

Note they share pins with other functions (like ADC, PWM, I2C)

The USB can be used to talk serial, but details vary a little with the firmware being used.





In Arduino:


5V tolerance

A number of pins seem to have what amounts to level shifters, so can talk 5V (when powered by 5V?).

You may be best off looking at a pinout.

Though note:

  • this doesn't apply when using pullup (/pulldown(verify)) because it's to a different voltage(verify)
  • that circuit it doesn't work when powered off(verify)

For voltage levels, see 6.3.14, but basically, they are compliant to both CMOS and TTL levels (and the precise voltage behaviour differs slightly between regular and 5V tolerant pins).


ADC and DAC notes

Many have (12-bit(verify)) ADCs (some multiple)

Some have (12-bit) DACs (max speed in the megasample range, varying with series)

Sound output

Choose between the DAC and I2S

internal DAC is cheaper, and arguably simpler, but is available in fewer STM32 models
is available in more (but not all) STM32 models than the DAC
means using an external I2S DAC - a little more work, yet gives you a choice of DAC to use

In theory you can also use PWM, because there a whole bunch of timers, but one of the above options is usually just a few bucks more and gives better quality and gives you more CPU to spend on what you want to generate.

Setup and programming

This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

STM32Cube is a group of applications intended to combine to be a complete toolset.

It includes things like

  • STM32CubeMX [1]
win, lin, osx
"initialization code generator"
generates a code to initialize the parts you want, for any known board - basically a template with all the hardware init, and an empty main()
(and does things like calculating power use)
You can then move to STM32CubeIDE, or other IDE/toolchain
  • STM32CubeIDE [2]
win, lin, osx
  • STM32CubeProgrammer [3]
  • STM32CubeMonitor [4]
run-time monitoring
groups some more specific things (verify)


STM32 Arduino
This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

There are a handful of cores you can use, but mostly it's the following two:

  • Arduino STM32
since 2011 or so,
STM32F1(03?) only, later also added STM32F4(verify)
based on maple code (see also maple mini), not STM's code (because that wasn't released until years later), meaning new features take more work to add
  • STM Core boards
from STM, but came years later (2016, 2017ish)

It seems that since the release of the latter, the former isn't really maintained anymore(verify), and since a number of things differ, it's probably a good idea to choose the latter unless a specific codebase is easier to make work on the former.

There are others, but most were more specific than Arduino STM32

See also:

Firmware flashing
This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.