AnsweredAssumed Answered

KSDK 2.0 Flash Programm is not working

Question asked by Maximilian Niedernhuber on Feb 15, 2017
Latest reply on Feb 16, 2017 by Maximilian Niedernhuber

Hello,

I wrote a small function to write a struct to the internal flash of the KL26Z256. Everythings seems great, no function throw an error. But the flash page was not deleted and the new data was not written. Can somebody help me with this issue. I dont know what is going wrong.

 

const deviceSettings_t devSettings @ 0x0003fc00;


void updateDeviceSettings ( deviceSettings_t *devs ) {
  flash_config_t s_flashDriver;
  status_t result;
  flash_security_state_t securityStatus = kFLASH_SecurityStateNotSecure;
  uint32_t failAddr, failDat;
  memset(&s_flashDriver, 0, sizeof(flash_config_t));

  result = FLASH_Init(&s_flashDriver); 
  if (kStatus_FLASH_Success != result)
    __asm("BKPT #0\n");
 
  result = FLASH_GetSecurityState(&s_flashDriver, &securityStatus);
 
  if(kStatus_FLASH_Success != result)
    __asm("BKPT #0\n");
 
  result = FLASH_Erase(&s_flashDriver, (uint32_t) &devSettings, 1024, kFLASH_ApiEraseKey);
  if (kStatus_FLASH_Success != result)
    __asm("BKPT #0\n");
 
  result = FLASH_VerifyErase(&s_flashDriver, (uint32_t) &devSettings, 1024, kFLASH_MarginValueUser);
  if (kStatus_FLASH_Success != result)
    __asm("BKPT #0\n");
 
  result = FLASH_Program(&s_flashDriver, (uint32_t) &devSettings, (uint32_t*)devs, sizeof(devSettings));
  if (kStatus_FLASH_Success != result)
    __asm("BKPT #0\n");
   
  result = FLASH_VerifyProgram(&s_flashDriver, (uint32_t) &devSettings, sizeof(devSettings), (uint32_t*)devs, kFLASH_MarginValueUser,
                                     &failAddr, &failDat);
  if (kStatus_FLASH_Success != result)
    __asm("BKPT #0\n");
 
  uint8_t* ptrA = (uint8_t*) &devSettings;
  uint8_t* ptrB = (uint8_t*) &devs;
 
  for(int i=0;i<1024;i++){
    uint8_t* ptr = (uint8_t*) &devSettings;
   
    if(ptrA[i] != ptrB[i])
      __asm("BKPT #0\n");   //fails here at the first byte.
  }
 
}

 

Thanks a lot and best regards,

 

Maximilian

Outcomes