How to build and run MicroPython on STM32F7-Disco board

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
JF002
Posts: 6
Joined: Sat Nov 05, 2016 6:23 pm
Contact:

How to build and run MicroPython on STM32F7-Disco board

Post by JF002 » Sat Nov 05, 2016 7:11 pm

Hi!

I recently discovered the MicroPython project, and I wanted to give it a try. After some research, I found out that MicroPython is ported to the STM32F7 microcontroller, and the STM32F7-Disco board. Nice, I have one laying around!

I did not find complete documentation about building and running MicroPython on this board, but after some tries and errors, I managed to build and run it on my board! Here is what I did.

First, my setup : I mainly work on Windows 10, but I have a Debian virtual machine (VirtualBox).
I used the Debian virtual machine as most of the documentation about building MicroPython is related to Linux (and that's a very good point!).

First, get the source using git:
$ git clone https://github.com/micropython/micropython.git
This will download the source to the directory ./micropython

You can build the Unix version of MicroPython if you want. For that, you need to install some dependancies:
$ apt-get install build-essential libffi-dev pkg-config

Then go into the Unix folder:
$ cd micropython/unix

And build MicroPython for Unix:
$ make

You can then run the interpreter :
$ ./micropython

Now, let's build MicroPython for our STM32F7DISCO board. We need a toolchain (compiler and other tools) to cross-compile micropython. Indeed, my computer is running a 64bits Intel Processor, and we need to build MicroPython to run on an ARM Cortex M7 microcontroller.
There is a package in Debian named 'gcc-arm-none-eabi' which should do the job, except that this is an old version (4.8) of GCC that has no knowledge of the Cortex-M7 architecture.
We'll need to find another compiler. I found useful information about this on this page : http://gnuarmeclipse.github.io/toolchain/install/

First, download the toolchain (GCC ARM Embedded) : https://launchpad.net/gcc-arm-embedded/+download. You'll want the 'Linux installation tarball'.
Download it and uncompress it on your local hard-drive.
As this toolchain is built for 32bits Linux and as I use a 64bits Debian, I needed to install extra packages :
$ apt-get -y install lib32z1 lib32ncurses5

Then, go to the micropython directory and start the compilation:
$ cd ~/micropython
$ cd stmhal
$ make BOARD=STM32F7DISC CROSS_COMPILE=<Path where you uncompressed the toolchain>/bin/arm-none-eabi-

This will build Micropython into the folder build-STM32F7DISC. Just look for the files firmware.dfu, firmware.hex,...

Next, we need to flash the board with this binary file. It is easily done using the STLINK USB interface of the board.
I did this step in Windows, as I never used the STLINK on Linux.
Download STLINK drivers and utility from this page : http://www.st.com/en/development-tools/st-link-v2.html

Connect a mini-USB cable between the board and your computer. Windows should detect the STLINK interface and a new COM port (it'll be used as the REPL port once the firmware will be uploaded).
Start the STM32 ST-Link Utility, and open (File->Open File) the file 'firmware.hex' that was created before.
Screenshot : https://pydio.codingfield.com/data/public/2c7c2d--en
Then, connect to the target (Target->Connect) and upload the file (Target->Program).
Screenshot : https://pydio.codingfield.com/data/public/4813f5--en

I use Putty as a serial terminal (just open a connection on COMx, 115200 bauds). After the uploading of the firmware, the board reset and... the Python interpreter appeard on the screen!
Screenshot : https://pydio.codingfield.com/data/public/715c4a--en
How is that possible? MicroPython is configured to use the UART1 of the µC as the REPL port. It is connected to the STLINK device on the board, and the USB interface of the STLINK exposes this UART as a USB-serial port to Windows.

And I've just discovered that the micro-USB port on the right of the STLINK port is seen by windows as a USB storage, which is used by MicroPython to store your .py files.

Now, I'm ready to play with MicroPython :-)
Pictures : https://pydio.codingfield.com/data/public/362b88--en and https://pydio.codingfield.com/data/public/e27154--en

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: How to build and run MicroPython on STM32F7-Disco board

Post by dhylands » Sun Nov 06, 2016 2:03 am

The normal build instructions for micropython are found on the main README.md file in the github repository:
https://github.com/micropython/micropyt ... tm-version

If you put arm-none-eabi-gcc into your PATH then you don't need to use CROSS_COMPILE

The remaining instructions can be found here:
https://github.com/micropython/micropyt ... -Discovery

Since those instructions were written there is now a deploy-stlink rule which will program any of the STM32 boards that have the builtin stlink hardware.
You'll need to install stlink (under linux) from: https://github.com/texane/stlink to use the deploy-stlink target.

JF002
Posts: 6
Joined: Sat Nov 05, 2016 6:23 pm
Contact:

Re: How to build and run MicroPython on STM32F7-Disco board

Post by JF002 » Sun Nov 06, 2016 4:08 pm

You're right, all the information were already available...
But I spent some time to put them together, and I thought it would be useful for anyone who wants to start micropython on is STM32F4 disco board :)

Btw, thanks for the links!

aronno
Posts: 1
Joined: Sun Jan 08, 2017 11:40 am

Re: How to build and run MicroPython on STM32F7-Disco board

Post by aronno » Wed Jan 18, 2017 6:04 pm

Thanks very much for the post. I just applied your steps and success. I want to add a note that, I inserted a Micro SDCard when powering up the board, The board did not respond. Then I removed the Micro SDCard and repower the board. Then the board started to respond and MicroPython prompt appeared on both port.

blipton
Posts: 8
Joined: Mon Dec 15, 2014 3:11 am

Re: How to build and run MicroPython on STM32F7-Disco board

Post by blipton » Sat Jan 20, 2018 5:48 am

Is this only for the STM32F769 DISCovery board? The other STM32F7 based boards (ex. STM32F746G-DISCO, NUCLEO-F746ZG) would require additional work?

BTW, does micropython support an interactive shell via the SWD console? Keil's uVision has a debug (printf) console but seems to require a compatible debugger.. not sure if the cheapy $3 st-link v2 will work!
https://www.silabs.com/community/mcu/32 ... print-Ly1m

[Update] Regarding SWV and St-Link, it seems according to this, that it should work:
https://maketips.net/tip/120/enable-pri ... -for-stm32

User avatar
ta1db
Posts: 53
Joined: Mon Sep 02, 2019 12:05 pm
Contact:

Re: How to build and run MicroPython on STM32F7-Disco board

Post by ta1db » Fri Sep 20, 2019 8:35 am

JF002 wrote:
Sun Nov 06, 2016 4:08 pm
.. and I thought it would be useful for anyone who wants to start micropython on is STM32F4 disco board :)

Btw, thanks for the links!
You're right, your descriptions are useful, thanks.

HollowHead
Posts: 10
Joined: Sun Nov 10, 2019 10:30 pm

Re: How to build and run MicroPython on STM32F7-Disco board

Post by HollowHead » Mon Nov 11, 2019 11:45 pm

Hello JF002,

I am trying your instructions to build and run micropython on a NUCLEO STM32L476GT6 ;

git clone https://github.com/micropython/micropython.git Worked!

apt-get install build-essential libffi-dev pkg-config Worked!

cd micropython/unix There is no unix folder within the micropython folder????

Thanks Mike

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: How to build and run MicroPython on STM32F7-Disco board

Post by jimmo » Tue Nov 12, 2019 2:16 am

hi Mike,

See my reply on your other thread. Since this post was written, the ports have moved into the "ports" directory (i.e. ports/stm32 and ports/unix).

Also you don't have to build the unix port, that's just an example. Also since this post was written, you need to build mpy-cross, and also fetch the submodules (run the steps in my other reply which will do all that).

Post Reply