Electronics project notes/STM32 notes
For STM in the context of other DIY chips, see Electronics_project_notes/Microcontroller_and_computer_platforms#STM32
Voltage and current
Regularly run at 3.3V (down to 2V).
A subset of pins may be 5V tolerant (when you disable pullup/pulldown), others are not, so don't assume this -- At a basic level you should consider this a 3.3V device.
As to power draw, consider trying 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
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.
- T - LQFP
- (the list is longer, omitted for brevity)
1 number: Temperature
- 6 - -40C to 85C
- 7 - -40C to 105C
See also:
- https://www.digikey.com/en/maker/blogs/2020/understanding-stm32-naming-conventions
- https://www.st.com/en/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus.html
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+)
Also:
For example:
- STM32F103C8T6
- STM32F103RBT6
- STM32F103RCT6
- STM32F405RGT6
- STM32F407VGT6
- STM32F401CEU6
- STM32F411CEU6
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
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)
BOOT0 BOOT1 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
- FPU
- 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
Nucleo
https://www.st.com/en/evaluation-tools/stm32-nucleo-boards.html
Maple
https://www.leaflabs.com/maple/
Hardware
IO
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.
CDC
https://github.com/stm32duino/wiki/wiki/API#hardwareserial
https://www.stm32duino.com/viewtopic.php?t=291
https://www.stm32duino.com/viewtopic.php?t=269
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).
http://www.emcu.eu/000/STM32_5VtolerantIO.pdf
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
- I2S
- 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
STM32Cube
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]
- flashing
- STM32CubeMonitor [4]
- run-time monitoring
- groups some more specific things (verify)
https://www.youtube.com/watch?v=hyZS2p1tW-g
STM32 Arduino
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
- https://github.com/rogerclarkmelbourne/Arduino_STM32
- STM Core boards
- from STM, but came years later (2016, 2017ish)
- https://github.com/stm32duino
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: