Electronics project notes/STM32 notes: Difference between revisions

From Helpful
Jump to navigation Jump to search
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
#REDIRECT [[Electronics project notes/Microcontroller and computer platforms#STM32]]
{{electronics notes}}
 
 
For STM in the context of other DIY chips, see [[Electronics_project_notes/Microcontroller_and_computer_platforms#STM32]]
 
 
 
 
 
====Voltage and current====
{{stub}}
 
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 [https://www.st.com/en/development-tools/stm32cubemx.html 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=====
{{stub}}
 
'''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:
: [https://www.st.com/en/microcontrollers-microprocessors/stm32f1-series.html F1 series] (launched 2007), Cortex-M3
: [https://www.st.com/en/microcontrollers-microprocessors/stm32f2-series.html F2 series] (launched 2010), Cortex-M3
: [https://www.st.com/en/microcontrollers-microprocessors/stm32l1-series.html L1 series] (launched 2010), Cortex-M3
: [https://www.st.com/en/microcontrollers-microprocessors/stm32f4-series.html F4 series] (launched 2011), Cortex-M4F
: [https://www.st.com/en/microcontrollers-microprocessors/stm32f3-series.html F3 series] (launched 2012), Cortex-M4F
: [https://www.st.com/en/microcontrollers-microprocessors/stm32f0-series.html F0 series] (launched 2012), Cortex-M0
: [https://www.st.com/en/microcontrollers-microprocessors/stm32f7-series.html F7 series] (launched 2014), Cortex-M7F (pin compatible with F4, faster)
: [https://www.st.com/en/microcontrollers-microprocessors/stm32l0-series.html L0 series] (launched 2014), Cortex-M0+
: [https://www.st.com/en/microcontrollers-microprocessors/stm32l4-series.html L4 series] (launched 2015), Cortex-M4F
: [https://www.st.com/en/microcontrollers-microprocessors/stm32l4-plus-series.html L4+ series] (launched 2016)
: [https://www.st.com/en/microcontrollers-microprocessors/stm32h7-series.html H7 series] (launched 2017), Cortex-M7F
: [https://www.st.com/en/microcontrollers-microprocessors/stm32l5-series.html L5 series] (launched 2018), Cortex-M33F
: [https://www.st.com/en/microcontrollers-microprocessors/stm32g0-series.html G0 series] (launched 2018), lower-power variants of L0 (Cortex-M0+)
Also:
: [https://www.st.com/en/microcontrollers-microprocessors/stm32wb-series.html WB series]
: [https://www.st.com/en/microcontrollers-microprocessors/stm32wl-series.html WL series]
 
 
 
 
'''For example:'''
: STM32F103C8T6
: STM32F103RBT6
: STM32F103RCT6
: STM32F405RGT6
: STM32F407VGT6
: STM32F401CEU6
: STM32F411CEU6
 
The first three are [https://www.st.com/en/microcontrollers-microprocessors/stm32f1-series.html F1 series] and all [https://www.st.com/en/microcontrollers-microprocessors/stm32f103.html F103] line.
The last four are [https://www.st.com/en/microcontrollers-microprocessors/stm32f4-series.html F4 series], and four different lines ([https://www.st.com/en/microcontrollers-microprocessors/stm32f405-415.html F405], [https://www.st.com/en/microcontrollers-microprocessors/stm32f407-417.html F407], [https://www.st.com/en/microcontrollers-microprocessors/stm32f401.html F401], [https://www.st.com/en/microcontrollers-microprocessors/stm32f411.html 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 <!--(e.g. {{search|STM32F103x8
STM32F103xB filetype:pdf}})-->, or group a few similar-enough lines <!--(e.g. {{search|STM32F405xx STM32F407xx filetype:pdf|STM32F405xx STM32F407xx])--> basically varying with how similar their features are.
 
<!--
E.g. figuring out how many SPI ports
STM32F103C8T6,
STM32F103RBT6,
STM32F103RCT6
have takes some digging through the datasheets.
 
There are further patterns you would care about, like that I2S is only usable on the not-first SPI port.
 
-->
 
=====Blue pill notes=====
{{stub}}
 
Blue Pill boards are typically based on the STM32F103C8T6 {{comment|(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 [https://www.st.com/content/ccc/resource/technical/document/application_note/b9/9b/16/3a/12/1e/40/0c/CD00167594.pdf/files/CD00167594.pdf/jcr:content/translations/en.CD00167594.pdf 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=====
{{stub}}
 
'''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:
: https://github.com/stm32duino/wiki/wiki/API#hardwareserial
 
 
 
'''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)
 
<!--
STM32F103C8 (e.g. blue pill) have an 12-bit (SAR) ADC
 
 
https://deepbluembedded.com/stm32-adc-tutorial-complete-guide-with-examples/
 
https://www.st.com/resource/en/application_note/cd00211314-how-to-get-the-best-adc-accuracy-in-stm32-microcontrollers-stmicroelectronics.pdf
-->
 
 
 
'''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.
 
 
<!--
 
'''Timer/PWM notes'''
 
We have a bunch of timers, some usable as PWM{{verify}}.
Others have more dedicated PWM (e.g. with dead time / phase control generator){{verify}}.
 
http://www.emcu.eu/stm32-basic-timer/
 
 
16-bit prescaler
16-bit timer
 
One PWM counter can be used with four comparisons, so same speed, different duty cycle
 
 
https://deepbluembedded.com/stm32-timers-tutorial-hardware-timers-explained/
 
http://www.micromouseonline.com/2016/02/06/pwm-basics-on-the-stm32-general-purpose-timers/
 
-->
 
====Setup and programming====
<!--
If going the Arduino route, you gets its hardware abstraction layer bolted on top of the STM32, and probably want to stick with that.
 
If not (and probably go with STM32Cube), you get more control, but more work.
-->
 
<!--
 
CMSIS (Cortex Microcontroller Software Interface Standard) is basically a layer over the HAL (Hardware Abstraction Layer), making boilerplate faster, and portability a little better.
 
https://www.keil.com/pack/doc/CMSIS/General/html/index.html
-->
 
 
 
======STM32Cube======
{{stub}}
 
[https://www.st.com/content/st_com/en/stm32cube-ecosystem.html STM32Cube] is a group of applications intended to combine to be a complete toolset.
 
It includes things like
* '''STM32CubeMX''' [https://www.st.com/en/development-tools/stm32cubemx.html]
: 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''' [https://www.st.com/en/development-tools/stm32cubeide.html]
: win, lin, osx
 
* '''STM32CubeProgrammer''' [https://www.st.com/en/development-tools/stm32cubeprog.html]
: flashing
 
* '''STM32CubeMonitor''' [https://www.st.com/en/development-tools/stm32cubemonitor.html]
: run-time monitoring
:: groups some more specific things {{verify}}
 
<!--
* '''STM32Cube MCU & MPU packages'''  - specifics per STM32 series [https://www.st.com/en/embedded-software/stm32cube-mcu-mpu-packages.html]
: ?
-->
 
 
https://www.youtube.com/watch?v=hyZS2p1tW-g
 
======STM32 Arduino======
{{stub}}
 
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 {{search|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
<!--
* MakerLabMe
* Koduino
* STM32 GENERIC
-->
 
 
See also:
* https://stm32duinoforum.com/forum/viewtopic_f_42_t_97.html#p617
 
======PlatformIO======
<!--
 
You can do live debugging (SWD)
 
-->
 
=====Firmware flashing=====
{{stub}}
<!--
If not choosing to use this thing from an Arduino environment, then you'll often be using [https://www.st.com/en/development-tools/stm-studio-stm32.html STM Studio], and probably want an ST-link V2 because of its convenience, allowing not only flashing but also realtime debug ([[SWD]]/[[JTAG]]).
 
 
As to flashing:
* '''invoke the STM's ROM bootloader''', often with a jumper, sometimes a button
: Connection: 4 pins: Gnd, 3.3V, RX, TX (A9/A10 on blue pills)
: It speaks {{search|AN3155 USART protocol used in the STM32 bootloader|a specific protocol}} over RS232.
: ...which is why it's called "serial" in some tools
: On 3.3V:
:: if your USB-serial board outputs 3.3V on its Vcc (or can be jumpered to) connect it to 3.3V
:: if your USB-serial board outputs 5V on its Vcc, connect it to 5V
:: the often-simpler option is to also plug in the board's USB (yes, the one that without firmware may not communicate)
: Roughly: Set BOOT0 to 1, BOOT1 to 0 (system ROM), press reset, run the flasher, Set BOOT0 to 0, BOOT1 to 0 (user flash), unplug (also for the implied reset)
 
* '''Flash via DFU'''[https://en.wikipedia.org/wiki/USB#Device_Firmware_Upgrade]
: Connection: USB
: Part of the ROM bootloader - only in some STM32 series
:: See {{search|AN3156}} - USB DFU protocol used in the STM32 bootloader
: means you need to jumper to get the ROM bootloader
 
 
* '''flash it via [[SWD]]''', with an ST-LINK or similar
: Connection: 4 pins: Gnd, DCLK, DIO, 3.3V
: (hardware-wise, look at ST-LINK/V2, Black Magic Probe, J-Link (SWD))
: faster than serial
: SWD allows runtime debugging  (note: Arduino IDE doesn't do this)
: Software: supplied with some, [https://github.com/stlink-org/stlink st-flash], though I had more luck with [https://www.st.com/en/development-tools/stm32cubeprog.html STM32CubProgrammer].
: This is independent of the ROM bootloader (so always works)
 
 
* '''Install a bootloader in Flash''' (using one of the above)
: ...that ''then'' can update the rest of flash, from Arduino (STM32Duino or HID Bootloader{{verify}})
: Connection: USB
: ...but that bootloader needs to be installed first, using one of the above
 
 
 
 
HID Bootloader
: USB
: initially built to avoid needing serial
: you need to flash [https://github.com/Serasidis/STM32_HID_Bootloader this bootloader] first, once
: smaller than STM32Duino
: not on all STM32 boards {{verify}}
 
 
STM32Duino bootloader
: USB(-serial)
: you need to flash [https://github.com/rogerclarkmelbourne/STM32duino-bootloader this bootloader]{{verify}} first, once
: and install [https://github.com/rogerclarkmelbourne/Arduino_STM32/tree/master/drivers/win this driver]{{verify}} to then recognize that as a serial port
: https://github.com/stm32duino/Arduino_Core_STM32#Introduction
: https://github.com/rogerclarkmelbourne/Arduino_STM32/
 
 
 
DFU Bootloeader
: am unsure about the details right now
 
 
From the Arduino IDE's point of view, we have
: STM32Duino bootloader
: Serial (ROM bootloader with jumper)
: STLink (specific SWD hardware)
: Black Magic Probe (specific SWD hardware)
: Jlink (specific SWD hardware)
: HID Bootloader
 
 
-->

Revision as of 12:21, 17 September 2023

⚠ 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 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 · power supply considerations · 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.

T - LQFP
(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+)

Also:

WB series
WL series



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
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)
 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
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.

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:

https://github.com/stm32duino/wiki/wiki/API#hardwareserial


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
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]
flashing
  • STM32CubeMonitor [4]
run-time monitoring
groups some more specific things (verify)


https://www.youtube.com/watch?v=hyZS2p1tW-g

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
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:

PlatformIO
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.