Learn

STM32 Blue Pill pinout: every pin, and which ones take 5 V

Beginner

Or see every lesson.

  • 505parts on the bench
  • 45boards running now
  • 1.00xreal time, on every board
Blue Pill: the LED on PC13live0.000 s 0.00x
Click to open it in the editor
PC13 sinks the board’s LED and a lamp wired from 3.3 V, so the two light together when the pin is LOW.

The Blue Pill is an STM32F103C8, a Cortex-M3 at 72 MHz, on a board 53 by 23 mm with twenty pins down each side, two jumpers and a micro-USB socket. Its pins are named by port and number, so the one marked A5 is PA5 in code. This page lists every pin with whether it takes 5 V, what it can do and what to watch for, then the power pins, the LED that lights on LOW, the BOOT jumpers and the pins the debug port holds.

The circuit above is a Blue Pill in Mokxi blinking its own LED on PC13 and a lamp on the breadboard wired the way the board’s is, from 3.3 V to the pin, so both light when PC13 goes LOW. The table is read from the same board model the simulator runs, and where Mokxi does less than the chip, the row says so.

Every pin, and which are 5 V tolerant

With the USB socket at the top, the left header reads VB, C13, C14, C15, A0 to A7, B0, B1, B10, B11, R, 3.3, G and 5V. The right header reads G, G, 3.3, then B12 to B15, A8 to A12, A15 and B3 to B9. The silkscreen leaves off the P, so C13 is PC13, and in code a pin is written in full: digitalWrite(PC13, LOW).

The second column is the one people come for. ST’s datasheet marks the pins that take 5 V on an input as FT, and on this header they are PA8 to PA12, PA15, PB3, PB4 and PB6 to PB15. PA0 to PA7, PB0, PB1, PB5 and PC13 to PC15 are 3.3 V only, and that includes every analog pin. An FT pin takes 5 V only while it is a digital pin, and its own output still goes no higher than 3.3 V. Mokxi does not model the difference: any pin takes 5 V here without harm, so check this column before you wire a 5 V signal on a desk.

STM32 Blue Pill: the left header top to bottom, then the right, USB at the top
Pin5 V tolerantWhat it can doWatch out for
VBAT-Backup supply for the clock and the backup registers, from a coin cell.Not a GPIO. Mokxi ignores it.
PC13NoDigital. The green LED, lit when LOW.Sinks 3 mA at most, shared with PC14 and PC15.
PC14NoDigital. OSC32_IN on the chip.Sinks 3 mA at most; most boards wire it to a 32.768 kHz crystal.
PC15NoDigital. OSC32_OUT on the chip.Sinks 3 mA at most; most boards wire it to a 32.768 kHz crystal.
PA0NoAnalog in, ADC channel 0. TIM2 channel 1 on the chip.analogWrite does nothing here in Mokxi: TIM2 runs micros().
PA1NoAnalog in, ADC channel 1. TIM2 channel 2 on the chip.analogWrite does nothing here in Mokxi: TIM2 runs micros().
PA2NoAnalog in, ADC channel 2. USART2 TX on the chip (its bytes reach no pin in Mokxi).-
PA3NoAnalog in, ADC channel 3. USART2 RX on the chip (its bytes reach no pin in Mokxi).-
PA4NoAnalog in, ADC channel 4. SPI SS (default).-
PA5NoAnalog in, ADC channel 5. SPI SCK (default).-
PA6NoAnalog in, ADC channel 6. PWM on TIM3 channel 1. SPI MISO (default).-
PA7NoAnalog in, ADC channel 7. PWM on TIM3 channel 2. SPI MOSI (default).-
PB0NoAnalog in, ADC channel 8. PWM on TIM3 channel 3.-
PB1NoAnalog in, ADC channel 9. PWM on TIM3 channel 4.-
PB10YesDigital. I2C2 SCL and USART3 TX on the chip (not modeled).-
PB11YesDigital. I2C2 SDA and USART3 RX on the chip (not modeled).-
NRST-Reset, printed R: low restarts the chip, as the button does.Not a GPIO.
3V3-The regulator’s 3.3 V output. Two pins.Not a GPIO.
GND-Ground. Three pins.-
5V-USB 5 V with a cable in; put 5 V here to run the board without one.Not a GPIO.
PB12YesDigital. SPI2 NSS on the chip (not modeled).-
PB13YesDigital. SPI2 SCK on the chip (not modeled).-
PB14YesDigital. SPI2 MISO on the chip (not modeled).-
PB15YesDigital. SPI2 MOSI on the chip (not modeled).-
PA8YesPWM on TIM1 channel 1.-
PA9YesTX: Serial, on USART1.The serial bootloader uploads through it.
PA10YesRX: Serial, on USART1.The serial bootloader uploads through it.
PA11YesPWM on TIM1 channel 4. USB D- on a real board.Drive it and the USB socket stops working.
PA12YesDigital. USB D+ on a real board.Carries the board’s USB pull-up resistor.
PA15YesDigital. JTAG’s JTDI out of reset.Held by the debug port until the sketch releases it.
PB3YesDigital. JTAG’s JTDO out of reset.Held by the debug port until the sketch releases it.
PB4YesDigital. JTAG’s NJTRST out of reset.Held by the debug port until the sketch releases it.
PB5NoDigital.The one pin from PB3 to PB15 that is 3.3 V only.
PB6YesPWM on TIM4 channel 1. I2C SCL (default).-
PB7YesPWM on TIM4 channel 2. I2C SDA (default).-
PB8YesPWM on TIM4 channel 3. I2C SCL with Wire.setSCL(PB8).-
PB9YesPWM on TIM4 channel 4. I2C SDA with Wire.setSDA(PB9).-

Power pins and their limits

5V is the USB rail when a cable is plugged in, and the regulator’s input when one is not: put 5 V on it to run the board from a supply. 3V3, on two pins, is the regulator’s output, for the chip and a sensor or two. The three GND pins are one ground. VBAT keeps the real-time clock and the backup registers alive from a coin cell while the rest is off; Mokxi ignores it.

ST gives a pin 25 mA at most and the whole chip 150 mA. PC13, PC14 and PC15 are on the backup domain and can sink only 3 mA between them, enough for an indicator and no more. Clone boards often carry the wrong regulator, which is a fault nothing in Mokxi can show you: here 3V3 and 5V are ideal rails that cannot sag.

The LED on PC13 lights on LOW

The green LED is on PC13, with its anode to 3.3 V through 1 k and its cathode on the pin, so it lights when PC13 is driven LOW. LED_BUILTIN is PC13, and digitalWrite(LED_BUILTIN, HIGH) turns it off. An LED copied from an Uno sketch, pin to resistor to LED to ground, lights when the board’s goes out; wired from 3.3 V to the pin, as above, the two agree.

The red LED is the power light. There is no user button: the one button is RESET, so a sketch that wants a button needs one on the breadboard.

BOOT0 and BOOT1: the two jumpers

The two jumpers at the top set BOOT0 and BOOT1, which the chip reads as it comes out of reset. With BOOT0 at 0 it runs the program in flash, which is the setting to leave it in. With BOOT0 at 1 and BOOT1 at 0 it starts ST’s serial bootloader, built into the chip, which takes a new program over USART1 on PA9 and PA10 from a USB-serial adapter. BOOT1 is PB2, which is why PB2 is not on the header.

The micro-USB socket does not upload anything unless a USB bootloader has been flashed onto the chip first; most people program a Blue Pill with an ST-Link on the SWD pins instead. Mokxi does not model the jumpers. The model boots from flash, as with BOOT0 at 0, and a program is loaded by pressing Run.

Pins the debug port and the USB hold

PA13 and PA14 are SWD, on the four-pin header at the end of the board, which is where an ST-Link connects. PA15, PB3 and PB4 are on the main header but belong to the JTAG port out of reset: PA15 and PB4 pulled up, PB3 floating. Write SWJ_CFG in AFIO_MAPR once in setup() and they are ordinary pins. This is the most common surprise on the board, and Mokxi reproduces it rather than hiding it.

PA11 and PA12 are the USB socket’s D- and D+ on a real board, and PA12 carries the board’s USB pull-up resistor. Mokxi does not model the USB and leaves both as plain pins.

Analog, PWM, I2C, SPI and Serial

ADC1 reads twelve bits, 0 to 4095 across 0 to 3.3 V, on ten pins: PA0 to PA7, PB0 and PB1. analogRead returns all twelve, not the ten an Uno gives, and Mokxi models the converter. analogWrite drives PWM at 488 Hz on ten pins, from TIM3, TIM4 and TIM1: PA6, PA7, PB0, PB1, PB6 to PB9, PA8 and PA11. PA0 to PA3 are TIM2’s channels on the chip, but Mokxi’s runtime keeps TIM2 for micros(), so analogWrite does nothing there.

Wire.begin() puts I2C on PB7 for SDA and PB6 for SCL, and Wire.setSDA(PB9) and Wire.setSCL(PB8) before it move the bus to the other pair. SPI is PA5, PA6, PA7 and PA4 for SCK, MISO, MOSI and SS. In Mokxi both buses run in software on those pins, because the chip’s I2C and SPI blocks are not modeled. Serial is USART1 on PA9 and PA10; USART2 and USART3 exist in the model, and their bytes reach no pin.

Open this circuit in the editor. Blue Pill: the LED on PC13, wired as it runs at the top of this page. Change a part or a value and run it again.

Open the circuit

Questions

Which STM32 Blue Pill pins are 5 V tolerant?

PA8 to PA12, PA15, PB3, PB4 and PB6 to PB15 on the header. Every analog pin, PB5 and PC13 to PC15 are 3.3 V only.

Why is the Blue Pill LED backwards?

It is wired from 3.3 V to PC13, so the pin sinks its current and it lights when PC13 is LOW. `digitalWrite(PC13, LOW)` turns it on.

What are the Blue Pill I2C pins?

SDA is PB7 and SCL is PB6 by default, or PB9 and PB8 with `Wire.setSDA` and `Wire.setSCL`. The chip’s second I2C bus is on PB11 and PB10.

Which Blue Pill pins are analog?

PA0 to PA7, PB0 and PB1, ADC channels 0 to 9. Keep the signal between 0 and 3.3 V: none of them is 5 V tolerant.

How do I upload to a Blue Pill?

With an ST-Link on the SWD pins, or with a USB-serial adapter on PA9 and PA10 and BOOT0 set to 1. The micro-USB socket uploads only once a USB bootloader has been flashed.

Why can my sketch not drive PA15, PB3 or PB4?

The debug port holds them out of reset. Release them with `SWJ_CFG` in `AFIO_MAPR`, or pick another pin.

Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.