Build firmware with python drivers.

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
MyUsername
Posts: 5
Joined: Mon Jan 02, 2017 4:06 pm

Build firmware with python drivers.

Postby MyUsername » Mon Jan 02, 2017 4:11 pm

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.

User avatar
deshipu
Posts: 937
Joined: Thu May 28, 2015 5:54 pm

Re: Build firmware with python drivers.

Postby deshipu » Mon Jan 02, 2017 5:41 pm

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).

User avatar
pythoncoder
Posts: 1392
Joined: Fri Jul 18, 2014 8:01 am

Re: Build firmware with python drivers.

Postby pythoncoder » Tue Jan 03, 2017 9:16 am

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.
Peter Hinch

v923z
Posts: 23
Joined: Mon Dec 28, 2015 6:19 pm

Re: Build firmware with python drivers.

Postby v923z » Tue Jan 03, 2017 10:05 pm

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?

User avatar
dhylands
Posts: 2264
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: Build firmware with python drivers.

Postby dhylands » Tue Jan 03, 2017 11:43 pm

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.


Return to “Development of MicroPython”

Who is online

Users browsing this forum: No registered users and 1 guest