Building libs for MCUs

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
mooreaa
Posts: 1
Joined: Sat Mar 14, 2020 12:06 am

Building libs for MCUs

Post by mooreaa » Mon Mar 23, 2020 3:05 am

Hi all,

I've got what is probably a newbie question on how to build/install libraries for micropython when the target is a MCU.

Specifically, I'd like to install the uasyncio lib to play with on my STM32 dev board (NUCLEO). I've build micropython and have that working, but would now like to install the uasyncio lib and build that in (frozen, i think is the right term so that it is more efficient).

I belive it has something to do with specifying FROZEN_MPY_DIR= , but what do i point this to? How and where do I specify which libs I want frozen into the micropython firmware? I am lost on how to do this as most of the methods refer to using upip to install which I cannot do on the MCU. Can someone help me out or point me to the right resource?

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

Re: Building libs for MCUs

Post by jimmo » Mon Mar 23, 2020 3:19 am

Hi,

Depending on how much flash you have, you can just copy the Python files to the device filesystem (in the same way you would copy main.py, etc).

However, you're right, freezing is a much more efficient way to put library code onto the device, especially if you're already set up to compile the firmware.

Have a look at ports/stm32/boards/manifest.py -- is used by the build to specify which Python files are frozen into the build. And have a look at stm32/boards/PYBD_SF2/manifest.py to see how a board definition can extend the base manifest. (See stm32/boards/PYBD_SF2/mpconfigboard.mk which sets the FROZEN_MANIFEST variable). You could do this for your Nucleo board's config.

You can also set FROZEN_MANIFEST on the make command line if you want to just use an abritrary manifest.py anywhere on your filesystem.

To see how to add uasyncio to manifest.py, look at ports/esp8266/manifest_release.py (note the way the destination paths work).

Because you asked -- FROZEN_MPY_DIR is the old way to do this where there was just a directory of Python files that would be frozen. It still works, but the manifest is easier to maintain.

Post Reply