KSDK 2.0 Flash Programm is not working

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

KSDK 2.0 Flash Programm is not working

1,967 次查看
nobodyKnows
Contributor III

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

标签 (1)
0 项奖励
回复
4 回复数

1,836 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Maximilian,

Frankly speaking, I do not know if the line is correct or not:


 uint32_t 

result = FLASH_Erase(&s_flashDriver, devSettings, 1024, kFLASH_ApiEras);
pls have a try.
BR
Xiangjun Rong
0 项奖励
回复

1,836 次查看
nobodyKnows
Contributor III

Hello,

thank you for your quick responds.I double checked the adresses. Everything seems to be ok. I tried your modification with the same result.

Yes it is possible to to directly set an absolute located variable. I think this is a special IAR specific syntax but it works flawlessly. I also checked this with the debugger.

IAR Absolute located variable 

Best regards,

Maximilian

0 项奖励
回复

1,836 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Can you use the example in SDK2.0?

C:\Freescale\SDK2.1_Frdm_KL27Z\boards\frdmkl27z\driver_examples\flash\pflash\kds

BR

XiangJun Rong

0 项奖励
回复

1,836 次查看
nobodyKnows
Contributor III

The Demo works perfectly. However I found something really strange. If I set the __no_init flag on the devSettings constant than it works with my code too.

__root __no_init const deviceSettings_t devSettings  @ 0x0003fc00;

Is there some protection if I initialise the constant in c code?

0 项奖励
回复