AnsweredAssumed Answered

KL02 FLASH_OnOperationComplete() does not happen

Question asked by Benjamin Chang on Mar 26, 2015
Latest reply on May 5, 2015 by Benjamin Chang


We have a long time bootloader works fine for KL25. Now we revise it for KL02.

The same program code is used, with CodeWarrior 10.6 and ProcessorExpert component.


We first tried on FRDM-KL02 (MKL02Z32VFM4), and also works fine.

But after we port it to custom target board (MKL02Z32VFG4), using MultiLink to debug in CW,

The function FLASH_OnOperationComplete() never reach, and it just keep looping and wait for complete

"while(OpStatus != TRUE)" as below code.


With CW debug, the program flash is correctly downloaded.

Please check and comment what might be the reason for this? Or what kind data/action can we check/make?

Next is the part of code:


// in event.c, hook for complete and error

void FLASH_OnOperationComplete(LDD_TUserData *UserDataPtr)


  /* Write your code here ... */

  uint8_t *OpStatus = (LDD_TUserData*) UserDataPtr;

   *OpStatus = TRUE;


void FLASH_OnError(LDD_TUserData *UserDataPtr)


  /* Write your code here ... */

  uint8_t *OpStatus = (LDD_TUserData*) UserDataPtr; // Bj, 140605

   *OpStatus = 8;


// User program file, function to perform flash

bool WriteFlash(LDD_FLASH_TAddress FromAddress, LDD_TData* DataPtr, LDD_FLASH_TDataSize Size)


  LDD_TError Error;

  //*OpStatus = FALSE;

   LDD_TDeviceData *FlashDevData;

  uint8_t OpStatus=FALSE;

   FlashDevData = IntFlash(&OpStatus);

  Error = FLASH_Write(FlashDevData, DataPtr, FromAddress, Size);

  if (Error) {     // no function call error found

    return FALSE;


  while(OpStatus != TRUE)  // as flash never complete, so it keeps looping in this while loop!!

  {/* Wait while operation done , Bj, 0605*/

   if (OpStatus == 8)


    printf ("Wf8");  // on error flag, set in event.c




  return TRUE;


// Reserve 1KB size of data on top of BootLoader as Signature

// main program will try to write a version number to the top of Bootloader for the 1st time (empty sector)

.. ..

if (BootVer1.VerBoot==0xff) { // check empty flag for the very first one

     BootVer1.VerBoot = 3;

     WriteFlash (BL_TOP, &BootVer1.VerBoot, 1); // write a new flag, << this is where the program stuck!!


.. ..

// We also tried to add checking in the loop


OpStatus=FLASH_GetOperationStatus (FlashDevData);

// but OpStatus is always 4 (LDD_FLASH_START)

// 2015/3/29 add:

// Before write Bootloader program, we developed AP program on this target board, and it works fine.

// We developed under CW10.6, using Multilink to download and debug, and running OK.

// The H/W is simple, checked, and nothing wrong can be found.

// We tested two boards, and both have this Flashing problem.

// We tried to revise the sample FLASH program of CW (for KL05), to KL02, only to found Erase is failed.

// Could this be a chip issue? How to identify it?

// Could the flash be locked? But CW downloading is working fine.