Implementing Kinetis Flash "SWAP" in MQX

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

Implementing Kinetis Flash "SWAP" in MQX

1,382 Views
myke_predko
Senior Contributor III

I just wanted to make a comment regarding implementing Flash SWAP in MQX - I was able to do it using the code kindly given by David White in the discussion: Using flashx io_ioctl FLASH_IOCTL_SWAP_FLASH_AND_RESET for bootloader

However, if you want to write to the Flash after the swap, you cannot write to the last sector of Flash in each block (in a 512k part these sectors are at 0x3F800-0x3FFFF and 0x7F800-0x7FFFF). 

As I have implemented a file system in my application, I treat these sectors as they are defective so there are no attempts to write/read to them. 

This is documented in the Kinetis documentation and David's code adds the functionality needed for implementing the SWAP, but, as noted, if you want to write to the Kinetis Flash afterwards you need to avoid the sectors listed above. 

myke

Tags (4)
7 Replies

488 Views
RadekS
NXP Employee
NXP Employee

Just note:

SWAP solution in incoming MQX4.1 will also use last sectors as Flash swap indicators. So result will be the same = last sectors cannot be used for user data/code.

0 Kudos

488 Views
thiagow
Contributor III

Could say what is the size of these "Last Sectors" on K64 ?        I'm doing a solution that stores some useful data at the end of each bank<0-3>       . Calling ioctl with FLASH_IOCTL_SWAP_FLASH_AND_RESET    will  erase the of my data that I stored at the end of each bank?

0 Kudos

488 Views
RadekS
NXP Employee
NXP Employee

Hi thiagow,

Sector size at Kinetis MK64FN1M0 is 4 Kbytes.

So, sectors at 0x7F000-0x7FFFF and 0xFF000-0xFFFFF will be reserved for Flash swap indicators when we want use flash swap function.

Yes, if swap functionality is used first time, last sector is erased and protected against any write, except next swap...

Note: Theoretically we could choose different flash sectors (macro BSPCFG_SWAP_INDICATOR_ADDR is defined in <your_BSP>.h file) for Flash swap indicators. However last sectors at every flash block is most reasonable option for these data.

Note: Flash swap functionality is not available at MK64FX512 derivative.


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

488 Views
thiagow
Contributor III

Is flash swap funcionality avaliable on MQX 4.1.1  for K64FN1M0M12 ?

For example the K64FN1M0M12 have 4 flash banks of 256 kB each. If my code have for example 400 kB , I will use full size of bank0 and a part of bank1,  when I call FLASH_IOCTL_SWAP_FLASH_AND_RESET , will I lose the code of the end of bank0? Or I will lose only the end of bank1 ?

0 Kudos

488 Views
RadekS
NXP Employee
NXP Employee

Hi thiagow,

Yes, flash swap functionality is available on MQX 4.1.1 for K64FN1M0M12.

This is just misunderstanding. You are right K64FN1M0M12 have physically 4 flash banks of 256 kB each.

Flash swap will cause switching two halves of program flash in memory map. So, after swap, banks 0 and 1 will be located at address 0x80000 and banks 2 and 3 will be located at address 0x00000.

So, data in bank 1 will stay untouched except last sector.

For proper functionality of flash swap (This swap feature enables the lower half of the program flash space to be operational while the upper half is being updated for future use.), you code have to fit inside 508kB = 1024kB/2 - 4k(for Flash swap indicator).


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

488 Views
thiagow
Contributor III

Thats ok, I understood now.

Thanks.

0 Kudos

488 Views
DavidS
NXP Employee
NXP Employee

Hi Myke,

Our MQX4.1 will have inherent support for the flash swap.

I will help verify its operation before we make public.

The formal release is targeted for early March.  I'll update this post once I verify that.

Regards,

David

0 Kudos