Compile and Flash Micropython Firmware on STM32F7
Essentially documenting this for myself, perhaps it will show up on Google. Micropython has lacking documentation and it's all over the place - Github wiki, Github readmes, pybd.io and read the docs somewhere. I am writing to consolidate everything specifically needed for flashing a Pyboard D from scratch except for mboot
bootloader in this blog post.
Pyboard D - SF3W Model
Specs: Link
Schematics: PDF
User Manual: Link
3D Model: Zip File
Firmware Download (official builds): Link
Building Firmware
- Clone micropython repository:
git@github.com:micropython/micropython.git
to~/Dev/micropython
folder such that the repository's .git folder lives under~/Dev/micropython/micropython/.git
. You can choose to clone wherever. - Navigate to cd
micropython/ports/stm32
and rungit submodule update --init
. It is going to clone and update all submodules in this folder. - Download ARM GCC toolkit: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
- It will, on macOS install under
/Applications/ARM/bin
. - Add ARM GCC compiler to path in the
.bash_profile
, add the following line to the end of the file:export PATH=$PATH:/Applications/ARM/bin
. - Restart terminal or run
source ~/.bash_profile
. - Check if ARM GCC compiler is in path by running:
arm-none-eabi-gcc
in the terminal. It should print (this is normal):
♦ stm32 / ➞ arm-none-eabi-gcc
arm-none-eabi-gcc: fatal error: no input files
compilation terminated.
- Navigate to
/micropython/mpy-cross
and runmake -j10
.-j10
flag should be the number of cores on your system, or omit it for single threaded build. It should output the following at the end of the build process.
LINK mpy-cross
__TEXT __DATA __OBJC others dec hex
307200 4096 0 4295000052 4295311348 100053ff4
- Navigate back to
/micropython/ports/stm32
and runmake -j10 BOARD=PYBD_SF3
.
It should result in the following output at the end of the build process:
LINK build-PYBD_SF3/firmware.elf
text data bss dec hex filename
1001712 352 76756 1078820 107624 build-PYBD_SF3/firmware.elf
INFO: this build requires mboot to be installed first
INFO: this build places firmware in external QSPI flash
GEN build-PYBD_SF3/firmware.dfu
GEN build-PYBD_SF3/firmware.hex
Firmware that we just built is located at /micropython/ports/stm32/build-PYBD_SF3/firmware.dfu
. In the next section, we'll go over how to flash this on the Pyboard D.
DFU Mode
- Hold the
USR
button - Press and release
RST
button while still holding theUSR
button. - RGB LED will flash different colors. When its white, let go of the
USR
button. It window to let go is terribly small. - A flashing red LED confirms DFU mode.
Flashing the Firmware
To flash the firmware located at /micropython/ports/stm32/build-PYBD_SF3/firmware.dfu
:
- Download dfu-utils. On macOS, just run
brew install dfu-util
. - Make sure the Pyboard is connected to the PC via USB cable and verify if
dfu-util
can detect it by runningdfu-util -l
. It should list our board as:
♦ stm32 / ➞ dfu-util -l
dfu-util 0.9
Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/
Found DFU: [0483:df11] ver=2200, devnum=35, cfg=1, intf=0, path="20-4",
alt=0, name="@Internal Flash /0x08000000/04*016Kg,01*064Kg,07*128Kg
/0x80000000/64*32Kg/0x90000000/64*32Kg", serial="356431583037"
- Navigate to
/micropython/ports/stm32/build-PYBD_SF3
- Run
dfu-util -a 0 -d 0483:df11 -D build-PYBV11/firmware.dfu