MicroPython on STM32 – old Nucleo STM32-F401RE and STM32F4DISC with F407VG

As the title says – the sheer hilarity of trying to have fun with uPython on Nucleo.

First of all, a disclaimer – I am in my Unreal Engine phase, so I tried to have it working on Windows 10. Sorry for that.

Images are on https://micropython.org/download/stm32/, download one of them and download STM32CubeProgrammer https://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-programmers/stm32cubeprog.html (may require providing name/email upon downloading).

1. connect the board
2. it shouts at me that my st-link is outdated, so in my naive state of mind I click upgrade and …

19:57:02 : STM32CubeProgrammer API v2.7.0
  19:58:50 : Error: No debug probe detected.
  19:58:54 : Error: Establishing connection with device failed
  19:58:58 : Error: No debug probe detected.
  19:59:36 : Error: No debug probe detected.

… dead? No, it still shows up as a USB mass storage properly, so kinda working. Suddenly, I realised – it’s OLD, and I connected it to the mobo with usb 3.0. I grabbed another usb cable and connected it like PC -> old 24 inch HP LCD usb 2.0 hub -> Nucleo, and …

  20:00:58 : Warning: Device changed, refreshing...
  20:00:58 : ST-LINK error (DEV_CONNECT_ERR)
  20:00:58 : ST-LINK SN  : 066DFF575056805087082357
  20:00:58 : ST-LINK FW  : V2J37M27
  20:00:58 : Board       : --
  20:00:58 : Voltage     : 3.24V
  20:00:58 : SWD freq    : 4000 KHz
  20:00:58 : Connect mode: Normal
  20:00:58 : Reset mode  : Software reset
  20:00:58 : Device ID   : 0x433
  20:00:58 : Revision ID : Rev A
  20:00:58 :   Bank          : 0x00
  20:00:58 :   Address       : 0x40023c14
  20:00:58 :   Size          : 8 Bytes
  20:00:58 : UPLOADING ...
  20:00:58 :   Size          : 1024 Bytes
  20:00:58 :   Address       : 0x8000000
  20:00:58 : Read progress:
  20:00:58 : Data read successfully
  20:00:58 : Time elapsed during the read operation is: 00:00:00.006

And now the biggest SNAFU: you can’t upload .dfu when you don’t have a second usb on board that easily. So I need to compile. FML, let me start WSL Ubuntu for that (I’m hell bent on doing that within the limits of win10).

Gonna go through https://docs.micropython.org/en/latest/develop/gettingstarted.html with slight upgrades to commands, so that it is 20.04-compatible

git clone https://github.com/micropython/micropython
sudo apt-get install build-essential libffi-dev git pkg-config

now install arm libs:
go to https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
for me this one looks sexy: gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 150MB

wget "https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2"

(rename the result if it looks weird)

sudo tar xjf gcc-arm-none-eabi-*.bz2 -C /usr/share/
sudo ln -s /usr/share/gcc-arm-none-eabi-*/bin/arm-none-eabi-gcc /usr/bin/arm-none-eabi-gcc 
sudo ln -s /usr/share/gcc-arm-none-eabi-*/bin/arm-none-eabi-g++ /usr/bin/arm-none-eabi-g++
sudo ln -s /usr/share/gcc-arm-none-eabi-*/bin/arm-none-eabi-gdb /usr/bin/arm-none-eabi-gdb
sudo ln -s /usr/share/gcc-arm-none-eabi-*/bin/arm-none-eabi-size /usr/bin/arm-none-eabi-size
sudo ln -s /usr/share/gcc-arm-none-eabi-*/bin/arm-none-eabi-as /usr/bin/arm-none-eabi-as
sudo ln -s /usr/share/gcc-arm-none-eabi-*/bin/arm-none-eabi-ld /usr/bin/arm-none-eabi-ld
sudo ln -s /usr/share/gcc-arm-none-eabi-*/bin/arm-none-eabi-objcopy /usr/bin/arm-none-eabi-objcopy
sudo apt install libncurses-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libncurses.so.6 /usr/lib/x86_64-linux-gnu/libncurses.so.5
sudo ln -s /usr/lib/x86_64-linux-gnu/libtinfo.so.6 /usr/lib/x86_64-linux-gnu/libtinfo.so.5
cd micropython/mpy-cross
cd ../ports/stm32
make submodules

After that grab the file from the subdirectory, you are looking for a .hex one, and upload using STM32CubeProgrammer.

Then install putty for serial console on Windows10 and “pip install adafruit-ampy” for file management.

Now the Discovery board with STM32-F407: take a look at https://micropython.org/download/stm32/ again, the board is listed under STM32F4DISC name and appears in the repo under https://github.com/micropython/micropython/tree/master/ports/stm32/boards/STM32F4DISC, so the make command would be:


And if your board is blinking red on the ST-Link part: grab a proper driver: