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

  1. 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.
  2. Navigate to cd micropython/ports/stm32 and run git submodule update --init. It is going to clone and update all submodules in this folder.
  3. Download ARM GCC toolkit: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
  4. It will, on macOS install under /Applications/ARM/bin.
  5. 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.
  6. Restart terminal or run source ~/.bash_profile.
  7. 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.
  1. Navigate to /micropython/mpy-cross and run make -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
  1. Navigate back to /micropython/ports/stm32 and run 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.

DFU Mode

  1. Hold the USR button
  2. Press and release RST button while still holding the USR button.
  3. RGB LED will flash different colors. When its white, let go of the USR button. It window to let go is terribly small.
  4. A flashing red LED confirms DFU mode.

Flashing the Firmware

To flash the firmware located at /micropython/ports/stm32/build-PYBD_SF3/firmware.dfu :

  1. Download dfu-utils. On macOS, just run brew install dfu-util.
  2. Make sure the Pyboard is connected to the PC via USB cable and verify if dfu-util can 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"
  1. Navigate to /micropython/ports/stm32/build-PYBD_SF3
  2. Run dfu-util -a 0 -d 0483:df11 -D build-PYBV11/firmware.dfu

← Back to Home