Search code examples
cavr

Insert machine code into C code at runtime


I am currently building some stuff with an Arduino Uno/Nano using the C language, and I need to insert some already compiled code from outside into the executable at runtime.

I want to be able to use it like a dynamically linked library, that I can exchange within the program.

Here is some code to show what I mean:

int external_code(int); // the external code needs to be called some way
void set_external_code(char*); // set the external code that gets executed

Solution

  • If you intend to load extra program code over serial, you can't do that.

    From the Arduino docs:

    Note: Flash (PROGMEM) memory can only be populated at program burn time. You can’t change the values in the flash after the program has started running.

    AVR stores programs in separate physical memory (Flash). You can read from it, but can't write at runtime unlike RAM and EEPROM.