I'm trying to add some libraries to my firmware-combined.bin so that I can access them from my code.
I'm not sure of the proper procedure. I've been copying files from micropython-lib into the scripts directory. I'm not sure what to copy, just the libraryname.py file? The whole directory?
Some libraries have sublibraries like urllib. If I just want the functions in urllib.parse, do I need urllib as well?
I also got this error:
xtensa-lx106-elf-ld: build/firmware.elf section `.irom0.text' will not fit in region `irom0_0_seg'
xtensa-lx106-elf-ld: region `irom0_0_seg' overflowed by 34020 bytes
make: *** [build/firmware.elf] Error 1
Is the space available for libraries really limited?
Is there a tutorial on this that I could read somewhere?
Adding libraries to the binary image
Re: Adding libraries to the binary image
I think I have it figured out now.
Modules consisting of a single .py file I just put in the scripts directory. Modules with submodules, like urllib.urequest I put in a subdirectory like urllib/urequest.py.
I still can't get urllib.parse to work, but I suspect that library is not working yet.
Thanks for reading.
Modules consisting of a single .py file I just put in the scripts directory. Modules with submodules, like urllib.urequest I put in a subdirectory like urllib/urequest.py.
I still can't get urllib.parse to work, but I suspect that library is not working yet.
Thanks for reading.
Re: Adding libraries to the binary image
Instead of the scripts directory, you can also create a modules directory and place your files there. The difference is, that Python scripts in the modules directory will be pre-compiled at image build time and then executed from flash, saving RAM during both loading and execution. I do that with scripts which are otherwise too large for parsing or execution. Whether this also works for scripts in subdirectories has to be tested.
-
- Posts: 35
- Joined: Tue Aug 09, 2016 6:56 pm
Re: Adding libraries to the binary image
I have just tested out of curiosity and sub-directories in modules seems to work too.
More info:
I have created sub-folder inside modules with following files:
The init file is empty and I didn't test omitting it, but compiled it only has 48 bytes. The test file has following code:
The code compiled successfully so I flashed the new firmware like usual and connected to the device. Below is the output from UART:
Edit: The __init__.py file can be omitted without problems. Saved 48 bytes per module, yay!
More info:
I have created sub-folder inside modules with following files:
Code: Select all
modules/sub/__init__.py
modules/sub/test.py
Code: Select all
class Test:
def __init__(self):
print("Test from subfolder")
Code: Select all
>>>from sub.test import Test
>>> t = Test()
Test from subfolder
>>>
Re: Adding libraries to the binary image
If you have your files in the modules directory, you do not need them in the scripts directory. Otherwise they would be stored twice in flash.
Re: Adding libraries to the binary image
Question : in the modules directory, do I need to put all the files for the micropython-lin I wants to freezes ?
For exemple I wants to freeze the upip in my pyboardv11 firmware, should I pout all the upip forlder in the submodules folder I create in ports/stm32 folder ?
For exemple I wants to freeze the upip in my pyboardv11 firmware, should I pout all the upip forlder in the submodules folder I create in ports/stm32 folder ?
Re: Adding libraries to the binary image
This thread (from 2016) is a bit out of date. The way freezing works has been updated since then to use the new "frozen manifest" feature, which allows you to extend from the default configuration in your own board configuration.
Probably the best example is to look at ports/esp32/boards/TINYPICO which adds additional modules over the default ones (this is for esp32, but the same process applies to esp8266).
So you could do the same thing for your board. Note on esp8266 you might want to extend from manifest_release.py.
There's been a few forum threads discussing this, search for "manifest.py" for more info.
Probably the best example is to look at ports/esp32/boards/TINYPICO which adds additional modules over the default ones (this is for esp32, but the same process applies to esp8266).
Code: Select all
cd ports/esp32
make BOARD=TINYPICO
There's been a few forum threads discussing this, search for "manifest.py" for more info.