KSDK 2.0 Flash Programm is not working

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

KSDK 2.0 Flash Programm is not working

1,958件の閲覧回数
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,827件の閲覧回数
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,827件の閲覧回数
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,827件の閲覧回数
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,827件の閲覧回数
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 件の賞賛
返信