Getting Started with the Black Pill
Contents
Installing MicroPython
This series of articles on the WeAct Studio Black Pill promote the use of MicroPython as the language of choice to using this board as an educational resource.
The board doesn't come preloaded with the MicroPython firmware. You must flash this to the STM32F411CEU6. Don't despair as this is a relatively simple task!
Our advice is to read through the rest of this introductory article then follow the instructions here, Installing MicroPython, to flash MicroPython on your board.
After MicroPython is installed an IDE (Integrated Development Environment) is required to write and send MicroPython programs to the Black Pill. We use and recommend the industry standard Thonny IDE. This article discusses Thonny and how to use it with the Black Pill; The Thonny IDE
A Brief History
It was around 2020 that WeAct Studio released it's Black Pill board based on the STM32F411. It was introduced as a lighter more compact variant of the Pyboard. With it's Cortex-M4 CPU core, reasonable clock speed, breadboard friendliness, (usually) more flash memory, excellent price point and high availability it has become the preferred development board for many.
Additionally, WeAct Studio is a well respected Chinese electronics manufacturer that produces quality products. It was never involved in the cloning/counterfeiting Blue Pill market and is known to only use genuine STM32 chips. And the Black Pill is an excellent target for MicroPython programming!
Black Pill Versions
The Black Pill comes in two main versions, based on different STM32 microcontrollers:
- STM32F401CCU6: Clock speed 84MHz, flash memory 256 KB, SRAM 64KB.
- STM32F411CEU6: Clock speed 96MHz, flash memory 512 KB, SRAM 128KB.
Look for the board versions containing the STM32F411CEU6 microcontroller. The Black Pill V3.1 is recommended as it also comes with 8MB SPI flash. All of the MicroPython scripts in this web series on the Black Pill have been tested with this version of the board.
Powering the Black Pill
There are two recommended ways that the board can be powered:
- USB connector: This is the most common method i.e. via a computer's USB port.
- 5V pin: A 3.6V to 5.25V supply applied to the 5V pin is regulated to 3.3V by the board's LDO (AP7343D-33FS4-7B voltage regulator).
Note: The 3.3 V pins are output only i.e. they are for supplying power to low power peripherals from the Black Pill. Under no circumstance should these pins be used to power the Black Pill.
Pinout
The Black Pill (STM32411) pinout is straight forward.
Click the image above to see a larger high resolution image.
The STM32F411CEU6 Microcontroller
The Black Pill V3.1 uses the STM32F411CEU6 Microcontroller. The name can be broken down:
- STM32: Family of 32-bit microcontrollers from STMicroelectronics.
- F: Identifies the specific series within the family, F = General Purpose.
- 4: Cortex-M4 core (with FPU).
- 11: Product line within the F4 series.
- C: Indicates the pin count i.e. a 48-pin device.
- E: Specifies the amount of Flash memory i.e. 512 KB of flash memory.
- U: Indicates the package type i.e. UFQFPN 48-pin package.
- 6: Denotes the operating temperature range i.e. -40°C to +85°C.
As noted above the STM32F411CEU6 CPU core is the 32‑bit ARM Cortex‑M4 operating at a maximum 100 MHz clock speed. However if a USB port is present (as on the Black Pill) the maximum processor speed is 96 MHz to facilitate a precise requirement of 48 MHz for the USB bus.
With its onboard memory ( and especially if optional SPI flash is available) these specifications are more than adequate to support the MicroPython compiler and runtime system.
Not all of the pins, communication buses, timers, etc that are available on the STM32F411CEU6 MCU are exposed on the Black Pill board. Some are designed for other uses that the user should't have access to and the board size is also a limitation.
GPIO Pins
There are ample GPIO pins exposed on the Black Pill for all but the most demanding project.
Digital pins
All up, the board has 34 digital pins. Of these, there are 21 pins that are 'anytime' available;
- A1, A2, A3, A8, A13, A14, A15
- B0, B1, B3..B10, B12..B15
Pins C14 and C15 are supplied through the power switch. Since the switch only sinks a limited amount of current (3mA), the use of these two pins in output mode is limited:
- The speed should not exceed 2 MHz with a maximum load of 30 pF.
- These I/Os must not be used as a current source (e.g. to drive an LED).
The remaining digital pins are connected to peripherals on the Black Bill board and shouldn't be interfered with.
Details on the board's digital pins and how to use them can be found in this MicroPython pyb.Pin class article.
Analog pins
Of the 23 user-accessible digital pins, 5 of these can also be used as 12-bit analog pins. This board provides only ADC (Analog-to-Digital Converter) pins: A1, A2, A3, B0, B1.
Details on the board's analog pins and how to use them can be found in this MicroPython pyb.ADC class article.
Serial Communications
The Black Pill has a selection of UART, I2C and SPI serial ports.
UART
The Black Pill has only one hardware UART available to the user:
- UART(2): Pins A2, A3
UART(1) on Pins A9, A10 will interfere with the function of the USB port if used.
Details on the board's UART and how to use it can be found in this MicroPython pyb.UART class article.
I2C
The Black Pill has three hardware I2C interfaces:
- i2c(1): Pins B6, B7
- i2c(2): Pins B10, B9
- i2c(3): Pins A8, B8
The MicroPython pyb module, specific to STM32 microcontroller with MicroPython firmware, provides an I2C class but this is now considered legacy.
Instead the MicroPython machine module contains an I2C class that provides much more control over the I2C interface. When dealing with some slave devices this extra level of control is required.
Details on the board's I2C interfaces and how to use them can be found in these MicroPython machine.I2C class and MicroPython pyb.I2C class articles.
SPI
The Black Pill has two separate hardware SPI interfaces available to the user:
- SPI(2): Pins B13, B14, B15
- SPI(3): Pins B3, B4, B5
SPI(1) on Pins A7, A6, A5 is used by the external SPI flash.
Details on the board's SPI interfaces and how to use them can be found in these articles: MicroPython pyb.SPI class and MicroPython machine.SPI class.
Timers
The Black Pill has 11 timers of which eight are available for general purpose use. They are referred to as TIM(1)..TIM(5) and TIM(9)..TIM(11).
The timers generally count down at a configured frequency from a given value to 0. The execution of a MicroPython function is triggered at the end of the count down.
The counters are also used to provision PWM (pulse width modulation) on digital pins.
Details on the board's timers and how to use them can be found in this MicroPython pyb.Timer class article.
Real-Time Clock
The STM32F411CEU6 has a full-featured calendar (seconds, minutes, hours, day, date, month, and year), a programmable alarm, and a periodic wake-up unit. It also has backup battery capability that retains the correct time/date when the microcontroller is powered down.
Details on the board's RTC and how to use it can be found in this MicroPython pyb.RTC class article.
External Interrupts
Hardware interrupts are specialized electrical signals that allow external or internal hardware events to immediately pause a microcontroller's main program and execute a dedicated task. A common signal that triggers a hardware interrupt occurs when a given digital pin changes value.
The WeAct Black Pill has 16 external hardware interrupts (labelled 0 through to 15) that can be used to respond to falling edge, rising edge or either on the board's digital pins.
When the condition occurs on the digital pin the main program is halted and an interrupt service routine ("callback function") is invoked. This allows actions to be taken as a result of an external happening.
Details on the board's external interrupts and how to use them can be found in this MicroPython pyb.ExtInt Class article.
Additional Hardware
Separate to the microcontroller the Black Pill has some additional hardware that might be useful in MicroPython programs. This hardware includes:
- LED: There is a blue user-controllable LED.
- Switch: A pushbutton switch labelled KEY; a MicroPython program can detect whether this switch has been pushed.
The following articles discuss in detail how to use these items: MicroPython pyb.LED class and MicroPython pyb.Switch class.
The Black Pill board doesn't come with a microSD card slot. However it's easy to add this as an expansion board to the Black Pill to provide removable file storage. How to add and use a microSD card with the Black Pill is discussed in this article.