I am writing am embedded program for a Cortex M0, compiled with GCC. For power reasons, the main program loop is kept in RAM and the flash is turned off after setup.
We have a section declared in the Linker script called ramfunc which puts the specified functions into ram. Our "ram functions" have the follow attributes on their prototypes:
__attribute__((section(".ramfunc")));
However, I am now trying to include the SEGGER JLink RTT library into the program. SEGGER provides a header file, SEGGER_RTT.h, which is #included where we use it. However, because the Linker isn't moving the library functions into ramfunc, the program crashes when they're called after the flash is powered off.
From what I understand there are two ways to move functions in the ramfunc section:
- using the
__attribute__
macro. - specifying the object file and section in the linker script.
I want to do it using the attribute macro, since I don't have much experience with linker scripts, and I don't know if it's good to have it in there when production builds won't use the library.
To try this, I added this line to a header file and included it where we use this function:
unsigned SEGGER_RTT_WriteString(unsigned BufferIndex, const char* s) __attribute__((section(".ramfunc")));
However, the program still crashes when the WriteString function is called.
I suspect perhaps the reason this isn't working is because the SEGGER_RTT.c file is #including the header file that doesn't have these attributes set, but I'm not sure.