I have a fairly large and working C++ code base running on the Teensy 4.1, refered to as firmware in the following, communicating with a number of embedded digital and analog circuitery and primarily communicating over a custom simple remote procedure call procotol over TCP/IP. In order to get rid of Ethernet latencies in certain user-defined cases, I want to make the firmware scriptable, i.e. allow users to send small snippets of code which are put in RAM and callbacked when needed.
I am really open for the technology to realize this. Micropython could be a mature option (https://github.com/orgs/micropython/discussions/9607) but would require me to expose the existing C++ API in the firmware to the mpy runtime. Various existing Lua VMs for microcontrollers go in the same direction.
I wonder if I could not load (cross-)compiled C++ code snippets (i.e. the corresponding bytecode) directly. I understand that this is half the way to Over-The-Air firmware flashing, but hopefully without the pain of replacing the full flash image (and also much faster since I don't even want to write my snippets to flash). If the users have exactly the same codebase in a working platformio installation, cleverly extracting the relevant "user customizable" symbols out of the code and sending them to the teensy should do it, isn't it? Issues are probably with PIC if the usercode is slightly more complex then a single subroutine.
I acknowledge that my proposed method is very hacky by nature and a proper microcontroller OS such as zephyr could provide similar things out of the box (i.e. https://docs.zephyrproject.org/latest/samples/subsys/llext/shell_loader/README.html) or, even simpler, just would allow the execution of suitable programs within the OS. However, I want to avoid using a microcontroller OS at this stage.
So here is my question, does anybody have done similar things on Teensy and can share code snippets, suggestions or useful links?
I am really open for the technology to realize this. Micropython could be a mature option (https://github.com/orgs/micropython/discussions/9607) but would require me to expose the existing C++ API in the firmware to the mpy runtime. Various existing Lua VMs for microcontrollers go in the same direction.
I wonder if I could not load (cross-)compiled C++ code snippets (i.e. the corresponding bytecode) directly. I understand that this is half the way to Over-The-Air firmware flashing, but hopefully without the pain of replacing the full flash image (and also much faster since I don't even want to write my snippets to flash). If the users have exactly the same codebase in a working platformio installation, cleverly extracting the relevant "user customizable" symbols out of the code and sending them to the teensy should do it, isn't it? Issues are probably with PIC if the usercode is slightly more complex then a single subroutine.
I acknowledge that my proposed method is very hacky by nature and a proper microcontroller OS such as zephyr could provide similar things out of the box (i.e. https://docs.zephyrproject.org/latest/samples/subsys/llext/shell_loader/README.html) or, even simpler, just would allow the execution of suitable programs within the OS. However, I want to avoid using a microcontroller OS at this stage.
So here is my question, does anybody have done similar things on Teensy and can share code snippets, suggestions or useful links?