Hello,
Based on AN-4329, I assembled a test project (attached) for the FRDM-K64F which attempts to copy a function to RAM and run it, but I am getting a fault when attempting to call the function. The Source and Destiny variables seem to be in the correct ranges in copyToMyRam, but the call fails.
Note changes in the ProcessorExpert.ld file, and main.c
Any advice is appreciated! It seems very close.
Thanks,
Jake
Original Attachment has been moved to: test-run-from-memory-frdm-k64f.zip
I got things working and wrote up a summary here:
Jacob Jennings Tech • Leverage the GNU ARM linker to relocate and...
Hi
Make sure that you are creating a thumb-comform copy of the code in SRAM since if it i not correctly aligned it will fail.
Below is an example where fnFlashRoutine() is a small subroutine to be copied to SRAM and later executed by calling fnRAM_code()
Regards
Mark
#define PROG_WORD_SIZE 30 | // adequate space for the small program | |
int i = 0; | ||
unsigned char *ptrThumb2 = (unsigned char *)fnFlashRoutine; | ||
static unsigned short usProgSpace[PROG_WORD_SIZE] = {0}; | // make space for the routine on stack (this will have an even boundary) |
ptrThumb2 = (unsigned char *)(((CAST_POINTER_ARITHMETIC)ptrThumb2) & ~0x1); // thumb 2 address | ||
while (i < PROG_WORD_SIZE) { | // copy program to SRAM | |
usProgSpace[i++] = *(unsigned short *)ptrThumb2; | ||
ptrThumb2 += sizeof (unsigned short); | ||
} | ||
ptrThumb2 = (unsigned char *)usProgSpace; | ||
ptrThumb2++; | // create a thumb 2 call | |
fnRAM_code = (void(*)(volatile unsigned char *))(ptrThumb2); |