Page 1 of 1

Build firmware with python drivers.

Posted: Mon Jan 02, 2017 4:11 pm
by MyUsername
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.

Posted: Mon Jan 02, 2017 5:41 pm
by deshipu
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).

Re: Build firmware with python drivers.

Posted: Tue Jan 03, 2017 9:16 am
by pythoncoder
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:

Code: Select all

make BOARD=PYBV11 FROZEN_MPY_DIR=modules
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.

Re: Build firmware with python drivers.

Posted: Tue Jan 03, 2017 10:05 pm
by v923z
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.
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?

Re: Build firmware with python drivers.

Posted: Tue Jan 03, 2017 11:43 pm
by dhylands
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.