adafruit / ArduinoCore-samd

115 stars 119 forks source link

Add .ramfunc attribute to flash_with_bootloader.ld to enable keeping functions in RAM #339

Closed yosinski closed 2 months ago

yosinski commented 1 year ago

For some use cases, e.g. re-flashing the Arduino during runtime via OTA updates, it is useful to enable certain functions to be kept in RAM so that the underlying flash memory may be replaced with new firmware while the program is running. An approach to accomplishing this is to prefix function definitions with the .ramfunc attribute:

__attribute__ ((long_call, section (".ramfunc")))

However, to get this to work, we needed to add a section specifying how to handle .ramfunc to the relevant flash_with_bootloader.ld for our hardware.

Is this the correct entry point? If so, is this few line addition appropriate for inclusion in this repository? In this PR, I've only added the line to the feather_m4 variant, though it could also be added for architectures.

drewfish commented 1 year ago

Another possible use for this is interrupt handlers, which could also benefit from being in ram. (Also would be nice to be able to store the interrupt table itself in ram.)

rlcamp commented 2 months ago

Worth pointing out there are some places in neopixel code that need to be in RAM in order to meet their timing requirements if they are the first thing that happens upon wake from sleep. I've worked around it by adding __attribute__((section(".datafunc"))) which gets picked up by the .data* rule in the existing linker script, but this is more of a hack than a proper fix.