Hi @Mike1981
Thank you for your reply as well.
Could you try to write only up to 1KB with program section command?
According to below snaps from the MK21 RM, the FlexRAM section program buffer will hold up to 1 KB of data for the program section command. I think that you mentioned that you are trying to write 0x1000 bytes , or 4KB.


I am mentioning this , as I have been running the MCUXpresso SDK pflash demo with specific modifications to pflash.c on my K64F: (as I do not have any MK2x board with me during this Corona virus lock down)
1 Use your address of 0x5000

2 Use the FLASH function for program section command, not program FLASH_Program. If we leave that last one, we can program 4KB. If I am not wrong , that function programs each 8 bytes, using like your current workarround, the program phase command.

3 Play with the length of the dummy buffer that the demo uses for writing in to the flash. As it is expressed in 4 byte words, that 256 corresponds to 1KB.

Below , find my relevant test results:
A) Using 1 KB for buffer length, no errors, see console results:

B) Using more than 1 KB, or 4 KB , we have flash errors

In particular the below error corresponds to when I used a buffer with a length of 4 Kb.
The FTFx_FSTAT_ACCERR_MASK error is raised.

Therefore , my recommendation is to test program section command for 1 KB and check our MCUxpresso SDK pflash examples and use latest MK21 flash driver. This can be found at MCUxpresso SDK builder. I have mentioned the TWR-K21 Plash example as uses a similar MK21.
Let me know your results
Diego.