Hello everyone!
I am trying to bundle my python code files into a MicroPython UF2 build.
Reason for this is that I'd love to be able to flash the UF2 file directly onto my RP2040 and have a fresh MicroPython build as well as all my python files up and running without having to send the files to the device after flashing MP.
My current approach is to put my boot.py, main.py and all the other files files into the ports/rp2/modules directory.
I am a little unclear about the MICROPY_MODULE_FROZEN macro.
If I understand things correctly I this should be defined and then pyexec_file_if_exists() within the main.c file should find my boot.py and main.py files and start executing, right?
So my question is, is that the best approach for this?
Thanks in advance!
Cheers,
Robin
Bundle python files into the compiled firmware
Re: Bundle python files into the compiled firmware
Just puttign them into the modules directory is not sufficient. You have to re-build the firmware to freeze the code into the image. But then pyexec_file_if_exists() should find it.
Re: Bundle python files into the compiled firmware
Oh my text was probably misleading.
I did mean putting the files into the modules dir before actually building MicroPython.
But that's good news that it will autodetect the main.py and boot.py in that folder.
I'll give it a try later today.
Thanks!
I did mean putting the files into the modules dir before actually building MicroPython.
But that's good news that it will autodetect the main.py and boot.py in that folder.
I'll give it a try later today.
Thanks!
Re: Bundle python files into the compiled firmware
This works just perfect!
Here's a quick tutorial for all that see this post.
I'm running those commands inside an Ubuntu 20.04 image in a VirtualBox.
Now put all your python files like main.py, boot.py, ... inside the ports/rp2/modules directory.
When finished build this micropython port as shown here:
You should now have the output files within ports/rp2/build-PICO
Especially helpful is the UF2 file which you can drag and drop onto a Pico while it is booted into its built-in bootloader.
This UF2 file now contains MicroPython and all your files frozen into it and your ready 🥳
Here's a quick tutorial for all that see this post.
I'm running those commands inside an Ubuntu 20.04 image in a VirtualBox.
Code: Select all
sudo apt-get install git
sudo apt-get install gcc-arm-none-eabi libnewlib-arm-none-eabi
sudo apt-get install build-essential
sudo apt-get install cmake
git clone git@github.com:micropython/micropython.git
cd micropython/mp-cross
make
cd ..
git submodule update --init lib/pico-sdk lib/tinyusb
When finished build this micropython port as shown here:
Code: Select all
cd ports/rp2
make
Especially helpful is the UF2 file which you can drag and drop onto a Pico while it is booted into its built-in bootloader.
This UF2 file now contains MicroPython and all your files frozen into it and your ready 🥳
-
- Posts: 1
- Joined: Thu Jun 09, 2022 11:21 am
Re: Bundle python files into the compiled firmware
Hi, This is really cool have you seen anything like this for windows?
Re: Bundle python files into the compiled firmware
I had the same question yesterday. So i try another aproach with docker dektop for windows. And it worked. See here
viewtopic.php?f=21&t=12559#p68049
viewtopic.php?f=21&t=12559#p68049