Simvik

Blue Pill (STM32F103C8) pinout

The Blue Pill (STM32F103C8) (STM32F103C8) pinout: what each pin does, from GPIO, analog inputs and PWM to UART, I2C and SPI, with the notes that catch people…

The board

  • Microcontroller: STM32F103C8T6, 32-bit Arm Cortex-M3
  • Clock: 72 MHz (the 8 MHz crystal × 9 through the PLL)
  • Flash / SRAM: 64 KB / 20 KB
  • Logic level: 3.3 V; the pins marked 5 V tolerant take 5 V signals
  • Analog inputs: 10 channels (PA0–PA7, PB0, PB1), 12-bit
  • PWM: Timer channels TIM1–TIM4: 1 kHz by default
  • Serial: USART1 on PA9/PA10 (Serial); USART2 on PA2/PA3; USART3 on PB10/PB11
  • I2C: I2C1: SDA PB7, SCL PB6 (Wire); I2C2: SDA PB11, SCL PB10
  • SPI: SPI1: SCK PA5, MISO PA6, MOSI PA7, NSS PA4; SPI2 on PB12–PB15
  • External interrupts: Any pin: EXTI line n takes pin n of one port
  • On-board LED: PC13 (LED_BUILTIN), lit LOW

Pins

PinFunctionsNotes
B12PB12, EXTI12, SPI2 NSSSPI2 chip select. External interrupt on EXTI line 12: attachInterrupt(digitalPinToInterrupt(PB12), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
B13PB13, EXTI13, SPI2 SCK, TIM1_CH1N, ~PWMSPI2 clock. analogWrite() PWM from TIM1_CH1N, 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 13: attachInterrupt(digitalPinToInterrupt(PB13), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
B14PB14, EXTI14, SPI2 MISO, TIM1_CH2N, ~PWMSPI2 data in. analogWrite() PWM from TIM1_CH2N, 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 14: attachInterrupt(digitalPinToInterrupt(PB14), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
B15PB15, EXTI15, SPI2 MOSI, TIM1_CH3N, ~PWMSPI2 data out. analogWrite() PWM from TIM1_CH3N, 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 15: attachInterrupt(digitalPinToInterrupt(PB15), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
A8PA8, EXTI8, TIM1_CH1, MCO, ~PWManalogWrite() PWM from TIM1_CH1, 1 kHz by default (analogWriteFrequency()). Can output a clock (MCO). External interrupt on EXTI line 8: attachInterrupt(digitalPinToInterrupt(PA8), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
A9PA9, EXTI9, USART1 TX, TIM1_CH2, ~PWMUSART1 transmit: Serial, which the Serial Monitor shows. analogWrite() PWM from TIM1_CH2, 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 9: attachInterrupt(digitalPinToInterrupt(PA9), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
A10PA10, EXTI10, USART1 RX, TIM1_CH3, ~PWMUSART1 receive: what the Serial Monitor sends. analogWrite() PWM from TIM1_CH3, 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 10: attachInterrupt(digitalPinToInterrupt(PA10), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
A11PA11, EXTI11, TIM1_CH4, USB D-, ~PWManalogWrite() PWM from TIM1_CH4, 1 kHz by default (analogWriteFrequency()). USB D- (with usb=none, as the simulator builds, a plain GPIO). External interrupt on EXTI line 11: attachInterrupt(digitalPinToInterrupt(PA11), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
A12PA12, EXTI12, USB D+USB D+, pulled up by a resistor on the board (1.5 kΩ on a good one). External interrupt on EXTI line 12: attachInterrupt(digitalPinToInterrupt(PA12), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
A15PA15, EXTI15, JTDI, TIM2_CH1, ~PWMJTAG at reset: a GPIO once JTAG is off (the core turns it off when the sketch uses the pin). analogWrite() PWM from TIM2_CH1 (remapped by AFIO, which the core does for you), 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 15: attachInterrupt(digitalPinToInterrupt(PA15), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
B3PB3, EXTI3, JTDO, TIM2_CH2, ~PWMJTAG at reset: a GPIO once JTAG is off. analogWrite() PWM from TIM2_CH2 (remapped by AFIO, which the core does for you), 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 3: attachInterrupt(digitalPinToInterrupt(PB3), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
B4PB4, EXTI4, NJTRST, TIM3_CH1, ~PWMJTAG at reset: a GPIO once JTAG is off. analogWrite() PWM from TIM3_CH1 (remapped by AFIO, which the core does for you), 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 4: attachInterrupt(digitalPinToInterrupt(PB4), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
B5PB5, EXTI5, TIM3_CH2, ~PWManalogWrite() PWM from TIM3_CH2 (remapped by AFIO, which the core does for you), 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 5: attachInterrupt(digitalPinToInterrupt(PB5), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
B6PB6, EXTI6, I2C1 SCL, TIM4_CH1, ~PWMI2C1 clock for Wire. analogWrite() PWM from TIM4_CH1, 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 6: attachInterrupt(digitalPinToInterrupt(PB6), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
B7PB7, EXTI7, I2C1 SDA, TIM4_CH2, ~PWMI2C1 data for Wire. analogWrite() PWM from TIM4_CH2, 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 7: attachInterrupt(digitalPinToInterrupt(PB7), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
B8PB8, EXTI8, TIM4_CH3, ~PWManalogWrite() PWM from TIM4_CH3, 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 8: attachInterrupt(digitalPinToInterrupt(PB8), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
B9PB9, EXTI9, TIM4_CH4, ~PWManalogWrite() PWM from TIM4_CH4, 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 9: attachInterrupt(digitalPinToInterrupt(PB9), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
B11PB11, EXTI11, USART3 RX, I2C2 SDA, TIM2_CH4, ~PWMUSART3 receive. I2C2 data. analogWrite() PWM from TIM2_CH4 (remapped by AFIO, which the core does for you), 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 11: attachInterrupt(digitalPinToInterrupt(PB11), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
B10PB10, EXTI10, USART3 TX, I2C2 SCL, TIM2_CH3, ~PWMUSART3 transmit: HardwareSerial Serial3(PB11, PB10). I2C2 clock: TwoWire Wire2(PB11, PB10). analogWrite() PWM from TIM2_CH3 (remapped by AFIO, which the core does for you), 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 10: attachInterrupt(digitalPinToInterrupt(PB10), handler, mode). 5 V tolerant (FT): a 5 V input is safe.
B1PB1, EXTI1, ADC9, TIM3_CH4, ~PWMAnalog input: analogRead() reads ADC channel 9 (12-bit; the core returns 10 bits unless analogReadResolution(12)). analogWrite() PWM from TIM3_CH4, 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 1: attachInterrupt(digitalPinToInterrupt(PB1), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
B0PB0, EXTI0, ADC8, TIM3_CH3, ~PWMAnalog input: analogRead() reads ADC channel 8 (12-bit; the core returns 10 bits unless analogReadResolution(12)). analogWrite() PWM from TIM3_CH3, 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 0: attachInterrupt(digitalPinToInterrupt(PB0), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
A7PA7, EXTI7, ADC7, TIM3_CH2, SPI1 MOSI, ~PWMAnalog input: analogRead() reads ADC channel 7 (12-bit; the core returns 10 bits unless analogReadResolution(12)). analogWrite() PWM from TIM3_CH2, 1 kHz by default (analogWriteFrequency()). SPI1 data out for the SPI library. External interrupt on EXTI line 7: attachInterrupt(digitalPinToInterrupt(PA7), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
A6PA6, EXTI6, ADC6, TIM3_CH1, SPI1 MISO, ~PWMAnalog input: analogRead() reads ADC channel 6 (12-bit; the core returns 10 bits unless analogReadResolution(12)). analogWrite() PWM from TIM3_CH1, 1 kHz by default (analogWriteFrequency()). SPI1 data in for the SPI library. External interrupt on EXTI line 6: attachInterrupt(digitalPinToInterrupt(PA6), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
A5PA5, EXTI5, ADC5, SPI1 SCKAnalog input: analogRead() reads ADC channel 5 (12-bit; the core returns 10 bits unless analogReadResolution(12)). SPI1 clock for the SPI library. External interrupt on EXTI line 5: attachInterrupt(digitalPinToInterrupt(PA5), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
A4PA4, EXTI4, ADC4, SPI1 NSSAnalog input: analogRead() reads ADC channel 4 (12-bit; the core returns 10 bits unless analogReadResolution(12)). SPI1 chip select (the SPI library's SS). External interrupt on EXTI line 4: attachInterrupt(digitalPinToInterrupt(PA4), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
A3PA3, EXTI3, ADC3, TIM2_CH4, USART2 RX, ~PWMAnalog input: analogRead() reads ADC channel 3 (12-bit; the core returns 10 bits unless analogReadResolution(12)). analogWrite() PWM from TIM2_CH4, 1 kHz by default (analogWriteFrequency()). USART2 receive. External interrupt on EXTI line 3: attachInterrupt(digitalPinToInterrupt(PA3), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
A2PA2, EXTI2, ADC2, TIM2_CH3, USART2 TX, ~PWMAnalog input: analogRead() reads ADC channel 2 (12-bit; the core returns 10 bits unless analogReadResolution(12)). analogWrite() PWM from TIM2_CH3, 1 kHz by default (analogWriteFrequency()). USART2 transmit: HardwareSerial Serial2(PA3, PA2). External interrupt on EXTI line 2: attachInterrupt(digitalPinToInterrupt(PA2), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
A1PA1, EXTI1, ADC1, TIM2_CH2, ~PWMAnalog input: analogRead() reads ADC channel 1 (12-bit; the core returns 10 bits unless analogReadResolution(12)). analogWrite() PWM from TIM2_CH2, 1 kHz by default (analogWriteFrequency()). External interrupt on EXTI line 1: attachInterrupt(digitalPinToInterrupt(PA1), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
A0PA0, EXTI0, ADC0, TIM2_CH1, WKUP, ~PWMAnalog input: analogRead() reads ADC channel 0 (12-bit; the core returns 10 bits unless analogReadResolution(12)). analogWrite() PWM from TIM2_CH1, 1 kHz by default (analogWriteFrequency()). Wakes the chip from Standby on a rising edge. External interrupt on EXTI line 0: attachInterrupt(digitalPinToInterrupt(PA0), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
C15PC15, EXTI15, OSC32_OUTThe 32.768 kHz crystal's other side; as a GPIO it sinks 3 mA at most. External interrupt on EXTI line 15: attachInterrupt(digitalPinToInterrupt(PC15), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
C14PC14, EXTI14, OSC32_INThe 32.768 kHz crystal for the RTC sits here on the board; as a GPIO it sinks 3 mA at most. External interrupt on EXTI line 14: attachInterrupt(digitalPinToInterrupt(PC14), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
C13PC13, EXTI13, LEDThe on-board LED, wired to 3.3 V: digitalWrite(PC13, LOW) lights it. It can sink only 3 mA, so drive nothing else from it. External interrupt on EXTI line 13: attachInterrupt(digitalPinToInterrupt(PC13), handler, mode). Not 5 V tolerant: keep it at 3.3 V or below.
5V5V5 V supply: from USB, or from the regulator when the board is powered through VIN.
GNDGNDGround (0 V).
3V33V33.3 V supply from the on-board regulator. Keep the load small.
GNDGNDGround (0 V).
GNDGNDGround (0 V).
3V33V33.3 V supply from the on-board regulator. Keep the load small.

Good to know

  • Pins are named by port and bit in code too: pinMode(PB12, INPUT_PULLUP), digitalWrite(PC13, LOW).
  • Register by register: turn a peripheral's clock on first (RCC->APB2ENR |= RCC_APB2ENR_IOPBEN), then set the pin's four bits in GPIOx->CRL (pins 0–7) or CRH (8–15), and drive it with GPIOx->BSRR or ODR.
  • The pins run at 3.3 V. The 5 V tolerant ones (PA8–PA15, PB2–PB4, PB6–PB15) can take a 5 V input; the others cannot. Each sinks or sources up to 25 mA, PC13–PC15 only 3 mA.
  • EXTI line n serves pin n of one port at a time: PA3 and PB3 cannot both interrupt.
  • JTAG holds PA15, PB3 and PB4 after reset; the core frees them when the sketch uses them. PA13 and PA14 are the SWD programming pins.
  • In the simulator, VBAT and R (reset) connect to nothing.