+
+ return ftfl_submit_cmd();
+}
+
+int flash_program_section_phrases( uintptr_t addr, size_t num_phrases )
+{
+ FTFL.fccob.program_section.fcmd = FTFL_FCMD_PROGRAM_SECTION;
+ FTFL.fccob.program_section.addr = addr;
+ FTFL.fccob.program_section.num_words = num_phrases;
+
+ return ftfl_submit_cmd();
+}
+
+int flash_program_sector( uintptr_t addr, size_t len )
+{
+ if ( len != FLASH_SECTOR_SIZE )
+ return 1;
+
+#if defined(_mk20dx128vlf5_)
+ // Check if this is the beginning of a sector
+ // Only erase if necessary
+ if ( (addr & (FLASH_SECTOR_SIZE - 1)) == 0
+ && flash_read_1s_sector( addr, FLASH_SECTOR_SIZE / 4 )
+ && flash_erase_sector( addr ) )
+ return 1;
+
+ // Program sector
+ return flash_program_section_longwords( addr, FLASH_SECTOR_SIZE / 4 );
+#elif defined(_mk20dx256vlh7_)
+ // Check if beginning of sector and erase if not empty
+ // Each sector is 2 kB in length, but we can only write to half a sector at a time
+ // We can only erase an entire sector at a time
+ if ( (addr & (FLASH_SECTOR_SIZE - 1)) == 0
+ && flash_read_1s_sector( addr, FLASH_SECTOR_SIZE / 8 )
+ && flash_erase_sector( addr ) )
+ return 1;
+
+ // Program half-sector
+ return flash_program_section_phrases( addr, FLASH_SECTOR_SIZE / 16 );
+#endif