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
User Manual: Link
3D Model: Zip File
Firmware Download (official builds): Link
- Clone micropython repository:
~/Dev/micropythonfolder such that the repository's .git folder lives under
~/Dev/micropython/micropython/.git. You can choose to clone wherever.
- Navigate to cd
git 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
- Add ARM GCC compiler to path in the
.bash_profile, add the following line to the end of the file:
- Restart terminal or run
- Check if ARM GCC compiler is in path by running:
arm-none-eabi-gccin 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
-j10flag 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
make -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.
- Hold the
- Press and release
RSTbutton while still holding the
- RGB LED will flash different colors. When its white, let go of the
USRbutton. It window to let go is terribly small.
- A flashing red LED confirms DFU mode.
Flashing the Firmware
To flash the firmware located at
- 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-utilcan detect it by running
dfu-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
dfu-util -a 0 -d 0483:df11 -D build-PYBV11/firmware.dfu