Micropython on STM32F746G Disco
The STM32F746G Discovery board (32F746GDISCOVERY) is one of the more versatile development boards for embedded developers or makers. Not only does it support traditional C/C++ developments, it also supports Micropython with GUI on its 4.3” LCD screen.
In this post we will look at how to set up the Micropython development environment for the STM32F746G Discovery board using LVGL (Light and Versatile Embedded Graphics Library). You can check out its Git repository at LVGL (github.com).
Setting up STM32 Toolchain
You would need to have the gcc-arm-none-eabi toolchain installed. If you have not installed it already, you may download it from: Arm GNU Toolchain Downloads – Arm Developer. We would need the compiler for AArch32 bare-metal target (arm-none-eabi). Select the favor according to your host architecture. For example, we pick that for 64-bit x86 Linux host:
Download the file for 64-bit x86 Linux host named arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi.tar.xz
Decompress the file to a folder with the default name and move the folder to/usr/local. Create a symbolic link to the folder.
tar xvf arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi.tar.xz sudo mv arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi /usr/local ln -s /usr/local/arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi /usr/local/gcc-arm-none-eabi
Add the path /usr/local/gcc-arm-none-eabi to the $PATH environment variable with a shell script named ~/Projects/git/setup.sh, which contains:
export PATH=/usr/local/gcc-arm-none-eabi/bin:$PATH
Run the setup script and verify the compiler versionis correct.
cd ~/Projects/git . ./setup.sh arm-none-eabi-g++ --version
Build Micropython Firmware
You may find detailed instructions at this link:
LVGL’s Micropython binding on STM32F746 Discovery | LVGL’s Blog
Below are the brief instructions that have been tested on an Ubuntu 22 virtual machine and an STM32F746G Discovery board.
First we need to build the Micropython firmware which contains the Micropython interpreter along with all the built-in modules.
Checkout the Micropython source code from git to a local folder. We are going to place it under ~/Projects/git. We then build the Micropython cross-compiler.
cd ~/Projects/git git clone https://github.com/lvgl/lv_micropython.git cd micropython cd lv_micropython git submodule update --init --recursive lib/lv_bindings make -j16 -C mpy-cross
Build firmware for STM32F746G Discovery board.
cd ports/stm32 make submodules make -j16 BOARD=STM32F7DISC MICROPY_PY_LVGL=1
If you see an error message “/bin/sh: 1: arm-none-eabi-gcc: not found”, ensure you have set the $PATH environment variable to include the ARM toolchain path (see previous step).
If the build is successful, you will see the following output. It tells us the output firmware files are located under the subfolder build-STM32F7DISC.
LINK build-STM32F7DISC/firmware.elf text data bss dec hex filename 872616 4128 30680 907424 dd8a0 build-STM32F7DISC/firmware.elf GEN build-STM32F7DISC/firmware0.bin GEN build-STM32F7DISC/firmware1.bin GEN build-STM32F7DISC/firmware.hex GEN build-STM32F7DISC/firmware.dfu
Download Micropython Firmware
The STM32F746G Discovery board supports mbed Flash update. You can simply copy the Micropython firmware hex file (firmware.hex) to the USB mass-storage drive which is automatically mounted to your host machine (Windows or Linux) when the board is plugged in.
The following screenshot shows the file firmware.hex has been copied to the USB drive named DIS_F746NG. Do not unplug the board while the internal Flash is being updated. The board will automatically reboot when the update is completed. The USB drive will be remounted without the file firmware.hex shown anymore.
The update process should not take more than one minute. If the USB drive is not remounted automatically after a minute (i.e. the file firmware.hex remains), please check the ST-Link version of your board by opening the file DETAILS.TXT.This is the version of my board:
Version: V2J40M27 Build: May 5 2022 13:16:48
If the version of your board is lower than this, please upgrade the ST-Link firmware using the ST-Link upgrade utility (STSW-LINK007 – ST-LINK, ST-LINK/V2, ST-LINK/V2-1, STLINK-V3 boards firmware upgrade – STMicroelectronics) or through STM32CubeIDE.
Trying out REPL
After the Micropython firmware has been downloaded to the STM32F746G Discovery board, we can verify it is running normally by trying out the REPL interface (read-evaluate-print-loop).
Using the same USB connection used to download the firmware, we connect to the virtual COM port from a serial terminal program such as minicom.
To allow access to the COM port without root privilege, we need to add the current user to the dialout group:
sudo usermod -a -G dialout $USER
Type “minicom -s” to bring up the setup menu of minicom. Configure it to use “/dev/ttyACM0” as the serial device with the settings of 115200 N81.
Press the reset button of the discovery board, you should see something similar to the following on the terminal:
MicroPython v1.19.1-657-g89c3b3943 on 2022-12-25; F7DISC with STM32F746 Type "help()" for more information. >>>