Hi
Here's one method for calling the Flash routine from RAM
// This routine runs from SRAM - the reason why the pointer is passed is to avoid the routine taking it from a const value in FLASH, which is then not code location dependent//static void fnFlashRoutine(volatile unsigned char *ptrFTFL_BLOCK){ *ptrFTFL_BLOCK = FTFL_STAT_CCIF; // launch the command - this clears the FTFL_STAT_CCIF flag (register is FTFL_FSTAT) while (!(*ptrFTFL_BLOCK & FTFL_STAT_CCIF)) {} // wait for the command to terminate}static void fnConfigFlashRam(void){ static void (*fnRAM_code)(volatile unsigned char *) = 0; #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]; // 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);}
call fnFlashRoutine() using;
fnRAM_code((volatile unsigned char *)FTFL_BLOCK); // execute the command from SRAM
Also block interrupts when the routine is called if interrupt handlers are in FLASH.
Regards
Mark