Where is the Flash Swap Indicator located?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Where is the Flash Swap Indicator located?

898 Views
aberger
Contributor V

I am using an MK64FN1M and would like to program some data into the unused Program Flash block. Currently, my entire program fits well within pFlash block 0, so I would like to write these data to block 1 in order to avoid any read-while-write violations. I am closely following the pflash example project from SDK_2.3.0_TWR_K64F120M.

In this example, there are some preprocessor directives to handle the block swap functionality (copied below):

/* In case of the protected sectors at the end of the pFlash just select
the block from the end of pFlash to be used for operations
SECTOR_INDEX_FROM_END = 1 means the last sector,
SECTOR_INDEX_FROM_END = 2 means (the last sector - 1) ...
in case of FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP it is
SECTOR_INDEX_FROM_END = 1 means the last 2 sectors with width of 2 sectors,
SECTOR_INDEX_FROM_END = 2 means the last 4 sectors back
with width of 2 sectors ...
*/
#ifndef SECTOR_INDEX_FROM_END
#define SECTOR_INDEX_FROM_END 1U
#endif

/* Erase a sector from destAdrss. */
#if defined(FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP) && FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP
/* Note: we should make sure that the sector shouldn't be swap indicator sector*/
destAdrss = pflashBlockBase + (pflashTotalSize - (SECTOR_INDEX_FROM_END * pflashSectorSize * 2));
#else
destAdrss = pflashBlockBase + (pflashTotalSize - (SECTOR_INDEX_FROM_END * pflashSectorSize));
#endif

This implies that the flash swap indicator is stored in the last sector of each pFlash block (in my case 0x7_FFFF - 0x1000 = 0x7_EFFF). However, I have been unable to verify this by examining either the source code or the K64 Reference Manual. And in AN4533, it states that "the system programmer specifies where the flash swap indicators are to be located." This same app note states that "The address of the flash swap indicators (offset address from the base of each block) is stored in an area of flash called the program flash block 1 IFR." I have also been unable to find this register. 

I want to be sure that when erasing and programming the flash, I do not inadvertently overwrite the flash swap indicator. How do I determine it's memory location?

Labels (1)
0 Kudos
Reply
1 Reply

767 Views
mjbcswitzerland
Specialist V

Hi

The flash indicator is used by the flash swap mechanism and is located any where in the the final sector. For exampe, the uTasker project uses the last 32 bytes, which makes more sense that having it at the beginning of the sector and blocking the sector from other use:

#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

However, if you are not actually using the swap feature (as you won't be when using Block 1 for other purposes) you don't need to worry about this in any way - you can therefore have code or other data there as you wish.

Regards

Mark

0 Kudos
Reply