Build firmware with python drivers.
-
- Posts: 5
- Joined: Mon Jan 02, 2017 4:06 pm
Build firmware with python drivers.
How can I attach drivers written in python to build? For instance, there is a driver for nrf24l01. I have tried to add it like any other c driver to Makefile but it can't help.
Re: Build firmware with python drivers.
You copy the python file eitehr to the "scripts" or "modules" directories (the first just includes the python code in the firmware, the second byte-compiles it first).
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Build firmware with python drivers.
It depends on your target hardware. If you're using a Pyboard V1.1 you put the Python code in a directory (lets assume it's stmhal/modules) and build with:
On the ESP8266 you copy the code to esp8266/modules and build in the usual way.
The aim here is to save RAM. If this isn't an issue you can, of course, just copy the driver to the filesystem on your target and execute it from there.
Code: Select all
make BOARD=PYBV11 FROZEN_MPY_DIR=modules
The aim here is to save RAM. If this isn't an issue you can, of course, just copy the driver to the filesystem on your target and execute it from there.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Build firmware with python drivers.
There might be other reasons for compiling the code. E.g., if you don't want to make it readable. But this is, perhaps, more like a question: can a python module compiled in this way be read out and reverse engineered later?pythoncoder wrote: The aim here is to save RAM. If this isn't an issue you can, of course, just copy the driver to the filesystem on your target and execute it from there.
Re: Build firmware with python drivers.
Sure. Currently I don't think that anybody has written a de-compiler (there is a byte-code disassembler), however, given that there are decompilers already that can take asm code and decompile into C source, I don't see that it would be too much of a stretch to take bytecodes and reverse them into python source (or any other language for that matter).
There are bits in the MCU that can be programmed so that you can't download the firmware over DFU (so even if you disable USB, I can still grab everything from the internal filesystem and the firmware itself by using DFU).
If you lock the chip, then you need to perform a chip erase before you can unlock it (and while locked, DFU/JTAG can't read anything).
You can see more by looking for RDP (Read protect) in the datasheet.
There are bits in the MCU that can be programmed so that you can't download the firmware over DFU (so even if you disable USB, I can still grab everything from the internal filesystem and the firmware itself by using DFU).
If you lock the chip, then you need to perform a chip erase before you can unlock it (and while locked, DFU/JTAG can't read anything).
You can see more by looking for RDP (Read protect) in the datasheet.