Yes, I am aware of the code that you have written and I can see that it was helpful to many people. Thank you for your contribution to the community 
However, I cannot implement your code. When I write below code, in debugger it goes into an endless loop.
#define PROG_WORD_SIZE 30 // adequate space for the small program
#define CAST_POINTER_ARITHMETIC unsigned long // Kinetis uses 32 bit pointers
#define FTFL_BLOCK 0x40020000 // Flash Memory Module
static unsigned short fnFlashRoutine[] =
{ 0x2180, 0x7001, 0x7801, 0x0609, 0xd5fc, 0x4770 };
void FLASH_program(void)
{
static void (*fnRAM_code)(volatile unsigned char *) = 0;
if (!fnRAM_code)
{
// the first time this is used it will load the program to SRAM
int i = 0;
unsigned char *ptrThumb2 = (unsigned char *) fnFlashRoutine;
static unsigned short usProgSpace[PROG_WORD_SIZE]; // make space for the routine on stack (this will have an even boundary)
ptrThumb2 = (unsigned char *) (((CAST_POINTER_ARITHMETIC) ptrThumb2)
& ~0x1); // thumb 2 address
while (i < PROG_WORD_SIZE)
{ // copy program to SRAM
usProgSpace[i++] = *(unsigned short *) ptrThumb2;
ptrThumb2 += sizeof(unsigned short);
}
ptrThumb2 = (unsigned char *) usProgSpace;
ptrThumb2++; // create a thumb 2 call
fnRAM_code = (void (*)(volatile unsigned char *)) (ptrThumb2);
}
// Read FCLKDIV register
if (FTMRE_FCLKDIV != 0x17)
{
// If FCLKDIV register not correct,
// Wait for any flash command in progress.
while ((FTMRE_FSTAT & FTMRE_FSTAT_CCIF_MASK) == 0x00)
;
// Write FLCKDIV register
FTMRE_FCLKDIV = FTMRE_FCLKDIV_FDIV(0x17);
}
else
{
// If FCLKDIV register is correct,
// Wait for any flash command in progress.
while ((FTMRE_FSTAT & FTMRE_FSTAT_CCIF_MASK) == 0x00)
;
}
// Access Error and or Protection Violation Check
if (((FTMRE_FSTAT & FTMRE_FSTAT_ACCERR_MASK) == 1)
|| ((FTMRE_FSTAT & FTMRE_FSTAT_FPVIOL_MASK) == 1))
{
// Write: FSTAT register: Clear ACCERR and FPVIOL
FTMRE_FSTAT = 0x30;
}
// Write to FCCOBIX register to identify specific command parameter to load
FTMRE_FCCOBIX = 0x00;
// Write to FCCOB register to load required command parameter
FTMRE_FCCOBHI = 0x06; // Program flash command code
FTMRE_FCCOBLO = 0x00; // Global address [23:16] to identify flash block
FTMRE_FCCOBIX = 0x01;
FTMRE_FCCOBHI = 0x1E; // Global address [15:0] of longwords location to be programmed
FTMRE_FCCOBLO = 0x00; // Global address [1:0] must be 0x00
FTMRE_FCCOBIX = 0x02;
FTMRE_FCCOBHI = 0x00; // Word 0 (longword 0) program value
FTMRE_FCCOBLO = 0x00; // (unsigned char) (PWM_duty_H1);
FTMRE_FCCOBIX = 0x03;
FTMRE_FCCOBHI = 0x00; // Word 1 (longword 0) program value
FTMRE_FCCOBLO = 0x00; // (unsigned char) (PWM_duty_H2);
FTMRE_FCCOBIX = 0x04;
FTMRE_FCCOBHI = 0x00; // (unsigned char) (current_limit_FW >> 8); // Word 2 (long3word 1) program value
FTMRE_FCCOBLO = 0x00; // (unsigned char) (current_limit_FW);
FTMRE_FCCOBIX = 0x05;
FTMRE_FCCOBHI = 0x00; // (unsigned char) (current_limit_BW >> 8); // Word 3 (longword 1) program value
FTMRE_FCCOBLO = 0x00; // (unsigned char) (current_limit_BW);
// Write: FSTAT register to launch command
//FTMRE_FSTAT = 0x80;
fnRAM_code((volatile unsigned char *) FTFL_BLOCK); // execute the command from SRAM
// Wait for the flash command in progress.
while ((FTMRE_FSTAT & FTMRE_FSTAT_CCIF_MASK) == 0x00);
}