Hi roymessinger,
About the kinetis K series flash swap, you can refer to our application note:
http://cache.nxp.com/assets/documents/data/en/application-notes/AN4533.pdf?fsrch=1&sr=1&pageNum=1
This application note have the detail description.
The according software can be downloaded from this link:
http://cache.nxp.com/assets/documents/data/en/application-notes-software/AN4533SW.zip
Wish it helps you!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
So why does it take me an hour of searching to find what has to be one of the most important app notes for the K60 series?
Has anyone ever considered organizing information into some logical structure, e.g. a wiki on each chip family, so that users don't have to waste time sorting through forums postings, which contain a great deal of duplicate and out of date information?
The Kinetis seem like decent products, but every time I go to find information, it is hugely frustrating and time consuming. Really sad.
Hi E Engineer,
Actually, you can input the keyword in the search from our nxp website, for example, you want to get the flash swap an.
You can find the first one is what you need.
Wish it helps you!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Roy
There is an application note using the swap block here:
http://cache.nxp.com/assets/document3s/data/en/application-notes/AN4533.pdf?fsrch=1&sr=1&pageNum=1
There is a working example at http://www.utasker.com/kinetis/FRDM-K64F.html#SWAP
The K64 user manual more or less explains how to do it.
There is full code in the links that I have shown you before (enable with define SUPPORT_SWAP_BLOCK to activate the driver).
Using VisualStudio and the K64 simulator the Flash swap block operation is emulated so that you can step through the complete procedure to see how it works. Essentially the code below handles it.
Regards
Mark
Professional support for Kinetis: http://www.utasker.com/index.html
Remote desktop one-on-one coaching: http://www.utasker.com/services.html
Getting started to expert videos: https://www.youtube.com/results?search_query=utasker+shorts
extern int fnSwapMemory(int iCheck)
{
#define FLASH_SWAP_INDICATOR_ADDRESS ((FLASH_START_ADDRESS + (SIZE_OF_FLASH/2)) - 32) // final sector in the first half of flash memory used as flash swap indicator
unsigned long ulCommand;
while (1) {
ulCommand = ((SWAP_CONTROL_CODE_REPORT_SWAP_STATUS << 24) | 0x00ffffff); // note that the unused bytes in the command are set to 0xff so that it is clear whether they are changed by the operation (failed operations may otherwise not be detectable)
if (fnFlashNow(FCMD_SWAP, (unsigned long *)FLASH_SWAP_INDICATOR_ADDRESS, &ulCommand) != 0) { // get the swap state
return SWAP_COMMAND_FAILURE; // error
}
//fnDebugHex(ulCommand, (WITH_LEADIN | WITH_CR_LF | sizeof(ulCommand)));
switch ((unsigned char)(ulCommand >> 16)) { // switch on current swap mode
case CURRENT_SWAP_MODE_UNINITIALISED:
{
int iPhrases = 0;
unsigned long *ptrSwapIndicator = (unsigned long *)FLASH_SWAP_INDICATOR_ADDRESS;
if (iCheck != 0) { // if checking present state
return SWAP_STATE_UNINITIALISED; // uninitialised
}
while (iPhrases++ < ((FLASH_ROW_SIZE/sizeof(unsigned long)) * 2)) { // for each of the two phrases of each block containing the swap indicator
if (*(unsigned long *)fnGetFlashAdd((unsigned char *)ptrSwapIndicator) != 0xffffffff) {
fnDebugMsg("Cleaning swap indicator sector\r\n");
if ((fnFlashNow(FCMD_ERASE_FLASH_SECTOR, ptrSwapIndicator, (unsigned long)0)) != 0) { // erase the sector
return SWAP_ERASE_FAILURE;
}
}
if (iPhrases == (FLASH_ROW_SIZE/sizeof(unsigned long))) { // after checking the two phrases in the first block move to the second block
ptrSwapIndicator = (unsigned long *)(FLASH_SWAP_INDICATOR_ADDRESS + (SIZE_OF_FLASH/2)); // location in the second block
}
else {
ptrSwapIndicator++; // move to the next long word
}
}
ulCommand = ((SWAP_CONTROL_CODE_INITIALISE_SWAP_SYSTEM << 24) | 0x00ffffff); // set the flash swap indicator address to initialise the swap mechanism (this address is programmed to IFR swap memory and 0xff00 programmed to the swap indicator address in the first block)
if (fnFlashNow(FCMD_SWAP, (unsigned long *)FLASH_SWAP_INDICATOR_ADDRESS, &ulCommand) != 0) { // start by initialising the swap process
return SWAP_COMMAND_FAILURE;
}
while (FTFL_FCCOB5 == CURRENT_SWAP_MODE_UNINITIALISED) {}// the current swap mode may take a little time to complete so wait until the new state is indicated
}
break;
case CURRENT_SWAP_MODE_READY:
ulCommand = ((SWAP_CONTROL_CODE_SET_SWAP_IN_UPDATE_STATE << 24) | 0x00ffffff);
if (fnFlashNow(FCMD_SWAP, (unsigned long *)FLASH_SWAP_INDICATOR_ADDRESS, &ulCommand) != 0) {
return SWAP_COMMAND_FAILURE; // error
}
while (FTFL_FCCOB5 == CURRENT_SWAP_MODE_READY) {} // the current swap mode may take a little time to complete so wait until the new state is indicated
break;
case CURRENT_SWAP_MODE_UPDATE:
if (iCheck != 0) { // checking and not swapping
if ((unsigned char)(ulCommand >> 8) != 0) { // check the active block
return SWAP_STATE_USING_1; // block 1 is being used
}
else {
return SWAP_STATE_USING_0; // block 0 is being used
}
}
else {
// We are performing a swap from one active block to another
// - this requires erasing the swap indicator of the non-active block
//
if ((fnFlashNow(FCMD_ERASE_FLASH_SECTOR, (unsigned long *)(FLASH_SWAP_INDICATOR_ADDRESS + (SIZE_OF_FLASH/2)), (unsigned long)0)) != 0) { // erase the sector
return SWAP_ERASE_FAILURE;
}
}
// Fall through intentionally
//
case CURRENT_SWAP_MODE_UPDATE_ERASED:
ulCommand = ((SWAP_CONTROL_CODE_SET_SWAP_IN_COMPLETE_STATE << 24) | 0x00ffffff);
if (fnFlashNow(FCMD_SWAP, (unsigned long *)FLASH_SWAP_INDICATOR_ADDRESS, &ulCommand) != 0) {
return SWAP_COMMAND_FAILURE;
}
while (FTFL_FCCOB5 != CURRENT_SWAP_MODE_COMPLETE) {} // the current swap mode may take a little time to complete so wait until the new state is indicated
// Fall through intentionally
//
case CURRENT_SWAP_MODE_COMPLETE:
return SWAP_STATE_SWAPPED; // swap has completed - a reset is required to effect the new operation
default:
break; // unexpected - continue until a valid state is returned
}
}
return 0;
}