Building for STM32 on Linux

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
philcl
Posts: 4
Joined: Sun Jun 17, 2018 2:35 pm

Building for STM32 on Linux

Post by philcl » Sun Jun 17, 2018 3:41 pm

Hi, So I'm new to micropython and was wondering exactly what I need to do to set up a build system on Linux to build firmware for STM32.

I want to set up a VirtualBox Linux guest OS on a Windows 10 host and was wondering what the easiest Linux distribution to work with would be? Does it need to be 32bit, 64bit or does it not matter?

Much of the (terse) documentation on the subject seems to be out of date (still referring to the stmhal directory when this has been moved and renamed ports\stm32 in the latest source).

Exactly which toolchains are needed to accomplish this?

Any advice would be much appreciated!

Phil

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

Re: Building for STM32 on Linux

Post by dhylands » Sun Jun 17, 2018 6:24 pm

It should work under either 32-bit or 64-bit, although recent distros are typically only offered in 64-bit. I use 64-bit native.

I use the launchpad gcc from here: https://launchpad.net/gcc-arm-embedded
Any version should work. I tend to use am older version and Damien tends to use a really new version.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Building for STM32 on Linux

Post by pythoncoder » Mon Jun 18, 2018 8:33 am

For an easy Linux distro I recommend (and currently use) Mint 64 bit.
Peter Hinch
Index to my micropython libraries.

philcl
Posts: 4
Joined: Sun Jun 17, 2018 2:35 pm

Re: Building for STM32 on Linux

Post by philcl » Mon Jun 18, 2018 3:07 pm

Hi All

Thankyou so much for your support, it is much appreciated!

For the record, I have this building now. This is what I did, in baby steps, just in case anyone else wants to tread a similar path!

Installed Oracle VM VirtualBox 5.2.12 on Windows 10

Installed Raspberry Pi Desktop (32-bit Debian 9 (Stretch) with Pixel)
into a new virtual machine with 2Gb RAM and 32Gb Disk

( !!! git clone https://github.com/micropython/micropython.git does NOT work for me !!! --
LWIP folder seems to be empty)

downloaded micropython-1.9.4.tar.xz from https://micropython.org/download using Ras Pi web browser

open terminal session:

cd /home/pi/Downloads

uncompress using:

tar xf micropython-1.9.4.tar.xz

using Ras Pi file manager:

move micropython-1.9.4 from /home/pi/Downloads to /home/pi

in terminal session:

cd /home/pi

rename the micropython folder:

mv micropython-1.9.4 micropython

install the toolchain:

sudo apt-get install gcc-arm-none-eabi

try to build micropython cross-compiler tools:

cd /home/pi/micropython/mpy-cross

make

try to build micropython for ST32F4DISC board:

cd /home/pi/micropython/ports/stm32

make BOARD=STM32F4DISC

output is in /home/pi/micropython/ports/stm32/build-STM32F4DISC and is called firmware.hex

Best Regards

philcl

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

Re: Building for STM32 on Linux

Post by dhylands » Mon Jun 18, 2018 6:59 pm

philcl wrote:
Mon Jun 18, 2018 3:07 pm
( !!! git clone https://github.com/micropython/micropython.git does NOT work for me !!! --
LWIP folder seems to be empty)
That's because the lwip directory is actually from another git repository.

When you execute this command:

Code: Select all

git submodule update --init
then it will populate all of the submodules. This shows all of the directories which come from other repositories:

Code: Select all

$ git submodule status
 43a6e6bd3bbc03dc501e16b89fba0ef042ed3ea0 lib/axtls (remotes/origin/micropython-2.1.3)
 35aaec4418ad78628a3b935885dd189d41ce779b lib/berkeley-db-1.xx (remotes/origin/embedded)
 e9de7e35f2339598b16cbb375f9992643ed81209 lib/libffi (v3.2.1-146-ge9de7e3)
 92f23d6ca0971a32f2085b9480e738d34174417b lib/lwip (STABLE-2_0_3_RELEASE)
 1fe30d1446f2eba3730dc4b05e9ac0cf03bcf9bf lib/stm32lib (F0-1.9.0+F4-1.16.0+F7-1.7.0+H7-1.2.0+L4-1.8.1-10-g1fe30d1)

philcl
Posts: 4
Joined: Sun Jun 17, 2018 2:35 pm

Re: Building for STM32 on Linux

Post by philcl » Tue Jun 19, 2018 9:09 am

Thanks for clearing that mystery up Dave, I'll give it another try when I get a minute!

Best Regards

Phil

philcl
Posts: 4
Joined: Sun Jun 17, 2018 2:35 pm

Re: Building for STM32 on Linux

Post by philcl » Tue Jun 19, 2018 10:38 am

This is all working as advertised now, thanks again.

Now, time to dig in and get to grips with MicroPython properly!

Best Regards

Phil :D

grail
Posts: 2
Joined: Fri Oct 12, 2018 7:07 am

Re: Building for STM32 on Linux

Post by grail » Fri Oct 12, 2018 7:47 am

I think these are better than the launchpad cross compilers : https://developer.arm.com/open-source/g ... /downloads

Then set the CROSS_COMPILE variable :

make BOARD=B_L475E_IOT01A CROSS_COMPILE=mumble/gcc-arm-none-eabi-7-2018-q2-update/bin/arm-none-eabi-

tuckata
Posts: 2
Joined: Sun Sep 19, 2021 1:17 pm

Re: Building for STM32 on Linux

Post by tuckata » Sun Sep 19, 2021 5:34 pm

Hi, I am also a newbie in MicroPython and I am wondering do you know what IDE can I use to compile and debug MicroPython for STM32, for instance Visual Studio Code? Can use the IDE also for debugging (I have ST-LINK v2 and BMP probes)?

Thank you in advance for any help

Tuckata

CarlFK
Posts: 11
Joined: Sun Aug 16, 2020 6:18 am

Re: Building for STM32 on Linux

Post by CarlFK » Sat Sep 25, 2021 11:53 pm

about a year ago we got mPy to build on Windows using the WSL - which gets you a Linux compatible shell where you can then follow the instructions for building on Linux.

I have also vetted some docs for building things (FPGA tools) using native windows tools, I can see the advantages, but it was way more effort to gather all the pieces in place.

installing WSL is well documented and pretty easy, and then the "build mPy on Linux" is also well documented and somewhat straight forward. I think you will get more help with this path than trying to use native Windows tools.

Post Reply