Hello Mark,
Thank you very much. I was able to compile the code without any errors by doing the above suggestions.
I was able to port the code from the uTasker project to my project which uses K22FN1M0 device.
I had to replace FTFL used in uTasker project with FTFE memory configuration as my device references are using FTFE. I verified the addresses for FTFL and FTFE used in my project and they are same.
my flash size if 0x100000 which is 1MB
swap indicator address is 0 + (0x100000/2) - 0x1000 ( 4KB sector size)
so last sector of the first swap block is used for swap indicator address.
1) Initially for just testing purposes at bootup i run the function fnHandleSwap(1).
2) After this is called then fnSwapMemory(1) is called
3) Then fnFlashNow is called which returns (FTFE_FSTAT & (FTFE_STAT_ACCERR | FTFE_STAT_FPVIOL | FTFE_STAT_MGSTAT0)); // if there was an error this will be non-zero
the FTFE_FSTAT is 0xa0 which indicates ACCERR error as per datasheet.
Can you please let me know the cause for this ACCERR errror?
Attached is my flash swap code.
Also I had one query regarding swap.
As per the link which you have sharedhttps://community.nxp.com/thread/379755?commentID=587268#comment-587268
swap by default works on half area of flash. i.e. if 1MB flash is present then lower 512K and upper 512K will be swapped. In our application we are using a bootloader which will be at address 0 in flash. Application will start at address 0x4000 for ex. in this case how will the flash swap work?
Can we specify flash swap starting address as 0x4000 so that only the application area is swapped?
If not then i think bootloader should be included in the image which is going to be downloaded OTA and then swap is initiated.
Can you please confirm whether flash swap always acts on 2 half areas of flash and there is no way to change the start address from which swap will work.
Regards,
Anuj