[STM32H7/Linux] Can micropython be installed with linux OS on this microcontroller ?

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
Clancys
Posts: 3
Joined: Tue Jun 11, 2019 9:13 am

[STM32H7/Linux] Can micropython be installed with linux OS on this microcontroller ?

Post by Clancys » Tue Jun 11, 2019 9:26 am

Hello,

First, i hope that this question hasn't been already posted somewhere, i searched a lot about it and i haven't found anything.

I want to set MicroPython as an interpreter so that i can write script that can be launched from a C application on the linux on my board. However, i don't know if this is possible.

Can MicroPython be installed on a microcontroller with an OS (Linux) ?
If yes, can MicroPython be installed on a microcontroller without a MMU (Memory Management Unit) ?

Ask if you need any more precisions on my problem :)

Sincerely,
Clancys.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: [STM32H7/Linux] Can micropython be installed with linux OS on this microcontroller ?

Post by Roberthh » Tue Jun 11, 2019 10:06 am

Since there is a Linux port, the question is more, whether Linux is available for your Micro. You will have to re-compile the Linux Port of Micropython for your target platform. There was some discussion about compiling it for Raspberry Pi/Raspbian. You may find traces of that also in the Github repository: https://github.com/micropython/micropython

Edit: For verification, I just have built microypthon on a Raspberry Pi, and it worked well. After compiling micropython, one has to install micropython-lib too for the standard libraries.

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

Re: [STM32H7/Linux] Can micropython be installed with linux OS on this microcontroller ?

Post by jimmo » Tue Jun 11, 2019 1:34 pm

Clancys wrote:
Tue Jun 11, 2019 9:26 am
Can MicroPython be installed on a microcontroller with an OS (Linux) ?
Yes, this is exactly the Unix port, as roberthh has already described.

but... this is a bit different to running it on your PC or a RPi...
Clancys wrote:
Tue Jun 11, 2019 9:26 am
If yes, can MicroPython be installed on a microcontroller without a MMU (Memory Management Unit) ?
This is a bit more tricky. You're talking about the STM32H7 which is big by STM32 standards but tiny by Linux standards. You'll likely run into some issues with the Unix port. For example, the default heap size is likely to be too big, and it pulls in some dependencies by default (e.g. axtls). You might want to start with the "minimal" target (i.e. "make minimal") to help with the latter, and you can adjust the heap size manually.

Clancys
Posts: 3
Joined: Tue Jun 11, 2019 9:13 am

Re: [STM32H7/Linux] Can micropython be installed with linux OS on this microcontroller ?

Post by Clancys » Mon Jun 17, 2019 3:13 pm

Hello,

Thank you for your responses, the idea of implementing python on a Linux OS on an STM32H7 is gone.
However, i have more questions :

Is it possible to add the bare-metal micro-python library in the userspace of Linux as an application ?
Will we need to make some changes to the library to allow it to access the kernel functions ?

Sincerely,
Clancys.

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

Re: [STM32H7/Linux] Can micropython be installed with linux OS on this microcontroller ?

Post by jimmo » Mon Jun 17, 2019 9:59 pm

Clancys wrote:
Mon Jun 17, 2019 3:13 pm
Is it possible to add the bare-metal micro-python library in the userspace of Linux as an application ?
Will we need to make some changes to the library to allow it to access the kernel functions ?
Yep! That's pretty much what the Unix port doesz but there's also an embedding example https://github.com/micropython/micropyt ... /embedding

Clancys
Posts: 3
Joined: Tue Jun 11, 2019 9:13 am

Re: [STM32H7/Linux] Can micropython be installed with linux OS on this microcontroller ?

Post by Clancys » Tue Jun 18, 2019 7:19 am

I'm so sorry, i messed up my question... Let me reformulate :

Linux can probably be set on a lot of micro-controller accepting some limits for example lack of MMU, not enough RAM and so on.

Because the unix port of micropython will not work without MMU, I would like to know if it is possible to compile micropython as a userspace application (by using the "micropython for STM32" sources and adapting the access to low level STM32 functionality by calling API provided by the OS) ?
Does my microcontroller need any specific resources (e.g. MMU, certain amount of RAM or flash, specific library from linux, ...) ?
Will i have to change some low-level micropython functions to make it work if i am missing some of these resources ?

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

Re: [STM32H7/Linux] Can micropython be installed with linux OS on this microcontroller ?

Post by jimmo » Tue Jun 18, 2019 7:52 am

MicroPython (just the compiler/VM/standard library) part doesn't need anything special from the hardware. If you have a C compiler, then you should be good.

The only reason you can't use the Unix port directly isn't because of the MMU, it's just that it makes some assumptions that it's running on a regular sized Unix machine (i.e. the default heap size). You might find that you can get it working quite easily by adjusting some things.

But if you just want to test out the concept, I'd start simple with the embedding example I linked to -- it makes a simple userspace application that embeds MicroPython with a tiny 16kiB heap and a basic REPL, and only the minimum of MicroPython functionality. Once you have Linux running on your board, you should try building this example. Then you can incrementally turn on additional functionality with mpconfigport.h etc.

This is in comparison to starting with the STM32 port, which I don't think is a good option (even though it will ultimately be running on an STM32 chip, your hardware API is the kernel, not the STMHAL).

When it comes to accessing hardware, you'll need to essentially write an equivalent implementation of modmachine.c, etc that knows how to access GPIO / SPI / etc through the Linux kernel. This would potentially be a really useful thing. This forum thread viewtopic.php?t=6327 has an example of someone making a start on this for Raspberry Pi but unfortuantely the GitHub link is broken (was https://github.com/hacksterous/micropyt ... /mpbcm2835 )

Post Reply