Hello, I am using TRK - KEA128 board debugging Flash, debug mode can run normally, but in normal mode, the Flash will not erase and write properly, the program runs in a Flash, whether need before erasing and writing the code loaded into RAM?If so, what should I do?
Hi,
Yes,when executes Flash programming we need copy Flash programming routine from Flash to RAM then execute it from RAM. The reason is that when writing MCU Flash, program is also reading instruction from same Flash, but Flash can’t perform reading and writing parallel. So executing the flash programming routine from RAM can avoid Flash read/write conflict.
Thank you. About this point, I would like to ask, how should the copy program execute to RAM and jump to RAM?
Hi
If you download the free uTasker open source project from GitHub you will have all code.
Here is a snippet to show you how a thumb 2 call can be created in SRAM to execute a routine (here fnFlashRotine())
static void (*fnRAM_code)(void) = 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] = {0}; // make space for the routine in static memory (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(*)(void))(ptrThumb2);
and then can be executed with
fnRAM_code(); // execute the command in SRAM
Regards
Mark
Hi
You need to execute Flash routines from SRAM.
If you have difficulties just use the uTasker open source project (including TRK-KEA128 support) since it solves all such complications.
Regards
Mark
Kinetis: http://www.utasker.com/kinetis.html
Kinetis KEA128:
- http://www.utasker.com/kinetis/TRK-KEA128.html
- http://www.utasker.com/kinetis/FRDM-KEAZ128Q80.html