Can you give a description of the code (and development system) you're using?
I'm using SDK 2.3.1 for the MK22FN1M0Axxx12 and found that you cannot just "write" the Flash, assuming that you are only changing "1"s to "0"s. You need to erase the sector before writing to it, which means that you need to have an image of the sector in SRAM before you erase the sector. My method for writing to a sector (which is effectively the ONLY size unit that you can read and write) is:
uint32_t flashSectorEraseWrite(flash_config_t* flashConfig
, uint32_t sector
, uint32_t* source) {
uint32_t returnValue = FLASH_RESPONSE_NOERROR;
__disable_irq();
if (kStatus_FLASH_Success !=
FLASH_Erase(flashConfig
, sector
, FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE
, kFLASH_ApiEraseKey)) {
returnValue = FLASH_RESPONSE_WRITEFAILURE;
}
__enable_irq();
if (FLASH_RESPONSE_NOERROR == returnValue) {
__disable_irq();
if (kStatus_FLASH_Success !=
FLASH_Program(flashConfig
, sector
, source
, FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE)) {
returnValue = FLASH_RESPONSE_WRITEFAILURE;
}
__enable_irq();
}
return returnValue;
}
Note that you may have to use different APIs depending on the SDK that you are using and select the block (0 or 1) explicitly rather than using the single API that covers either block that I am using.