We've got a project that was originally based on the MK22FN1M0AVLK12, but that we've backed out to the MK21DN512VLK5 because that was the only socket-compatible device we could find in inventory anywhere. The MCUXpresso toolkit only has an SDK for the MK21DN512AVLK5 (not the MK21DN512VLK5), so we rebuilt the project with that SDK, and after some debugging got it running properly.
On our first production build, we've discovered that about 10% of the units are unable to write the flash memory under program control (we can load the program to flash just fine via JTAG). When we step through the code on a failing unit, we see the calls to FLASH_Erase() and FLASH_Program() both returning kStatus_FLASH_Success, but examining the written sector (either via the emulator or program read) shows all FF's - no write occurred.
Note that on 90% of the units, we are able to reliably and repeatably write the flash - we've never observed a failure.
A review of the data sheet did not reveal any sector-locking features, or at least if they're in there I did not see them. Is there any configuration of the device that can inhibit write?
BTW - We checked the power supply - solid, clean 3.3V with plenty of bypass caps close to the device.
Any suggestions of where to look next would be welcome!
-lr