3

I'm on Micropython 1.9.3. I know how to use mpy-cross to turn a .py into a compiled python .mpy that can be executed by the Micropython virtual machine.

The problem is that if I try to compile using @micropython.native i.e. compile the Python script to native code instead of bytecode, I get an error:

../../mpy-cross/mpy-cross -o build/frozen_mpy/./frozentest.mpy -s frozentest.py  frozentest.py

ValueError: can only save bytecode

On the following .py

@micropython.native
def native_add(a,b):
    return (a+b)

c = native_add(2342,4542)

QUESTION

Is it not possible to embed native code in .mpy format? Did I miss some option in mpy-cross/mpconfigport.h?

Only thing I changed is:

#define MICROPY_EMIT_THUMB (0) // changed it to 1

dda
  • 6,030
  • 2
  • 25
  • 34
Bob
  • 4,576
  • 7
  • 39
  • 107

1 Answers1

1

I got the answer from someone on micropython forum:

You cannot. It is an TODO item. If you want to put it into flash memory, you can embed it as frozen source code in some ports. Just put these files in a subdirectory called scripts, like esp8266/scripts or stm32/scripts. But it will still be compiled at import time and consume RAM. Typically, that should not hurt, when this variant of coding is used only for small, time-critical sections of the code.

Bob
  • 4,576
  • 7
  • 39
  • 107