Installing MicroPython on inexpensive STM32F4xx boards
This tutorial will explain step by step how to build and deploy MicroPython on STM32F407xx and STM32F411CEU boards, using both DFU mode over USB, as well as SWD with ST-Link and OpenOCD in case you can't get the board into DFU mode (happened to me with the "black pill").
It should be applicable to other boards, such as the other "black pill" STM32F401, Nucleo boards etc., provided you can find an appropriate board definition to build.
1. clone the MicroPython repo:
git clone https://github.com/micropython/micropython
2. build submodules
in micropython/ports/stm32 folder:
make submodules
(this will take a while, as it will built the necessary STM32 pieces of code)
3. build mpy-cross
in micropython/ folder:
make -C mpy-cross
(this will take a while, as it will build the necessary cross compiler code)
4. clone the board repo:
in micropython/ports/stm32/boards folder:
-
STM32F407xxx 'black tile'
git clone https://github.com/mcauser/BLACK_F407VE.git
-
STM32F411CEx 'black pill'
git clone https://github.com/mcauser/WEACT_F411CEU6.git
5. build uPy for the boards
in micropython/ports/stm32/ folder:
-
STM32F407xxx 'black tile'
make BOARD=BLACK_F407VE
-
STM32F411CEx 'black pill'
make BOARD=WEACT_F411CEU6
6. flash the board
-
using DFU mode: STM32F407xxx 'black tile' example
put the board into the DFU mode, connecting BT0 pin to 3V3 with a jumper as described, then connect the USB cable and do:
make BOARD=BLACK_F407VE deploy
after it's done, unplug the board, connect BT0 to GND with the jumper, and reconnect the board
-
using SWD with ST-Link: STM32F411CEx 'black pill' example
cd micropython/ports/stm32/build-WEACT_F411CEU6
openocd -f interface/stlink-v2.cfg -f target/stm32f0x.cfg
in another terminal window:
telnet localhost 4444
> reset halt
> flash write_image erase build-STM32F4NUCLEO/firmware.elf
7. test the MicroPython installation
rshell -p /dev/ttyACM0 repl