Create a RAM Function

From SEGGER Wiki
Revision as of 14:32, 24 May 2023 by Oliver (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

For some situations it may be beneficial or even necessary to place a function in RAM instead of flash. This for example is needed in case a bootloader (that runs from flash) shall update a firmware (running from the same flash but different sectors). As the flash is not accessible for read accesses while it is programmed, the flash programming routines itself need to run from RAM.

In order to put a function into RAM, it needs to be placed into the .fast section and should also be prevented from being inlined into code in flash. This is done as follows:

__attribute__ ((section(".fast"), noinline))  // Place the following function in RAM and prevent it from being inlined into flash routines
void _Delay(void) {
  [...]
}