EEPROM configuration issue in k20d50 development board

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

EEPROM configuration issue in k20d50 development board

ソリューションへジャンプ
2,298件の閲覧回数
joginderrana
Contributor II

Hello,

I am developing an application using FRDM K20D50 development board. I want a value to be preserved even after the power on reset. To get rid of the problem I am trying to configure EEPROM from the flex memory available in the controller.

I have read the app note AN4282. I got a clear picture of memory divisions but not able to configure the same practically. After defining 512 bytes of EEPROM in CPU settings I am using the code:

/*** Processor Expert internal initialisation. DON'T REMOVE THIS CODE!!! ***/

  PE_low_level_init();

  inc = *(word*)0x14000000;

// uart=AS1_Init(NULL);

  /*** End of Processor Expert internal initialisation.                    ***/

  /* Write your code here */

  for(;;) {

   for(i=0;i<10; i++)

   {

   inc = inc+1;

  *(word*)0x14000000 = inc;

  printf("Data %d \n",  inc);

   }

Since the value of variable "inc" is preserved and returned back after manual cpu reset but it losts after doing power on reset. It seems value is still in flex RAM and not written in the E Flash. Can some one please help me get rid of the issue by providing a right approach to the FLex memory partitioning? I will be fine if there is any certain setting in cw to store data  variables in P Flash memory and to use it after power ON reset.

Attached jpg is CPU memory portioning settings.

ラベル(1)
タグ(4)
0 件の賞賛
返信
1 解決策
1,934件の閲覧回数
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Joginder Rana,

Actaully there is a ready Flash demo for TWR-KL05Z48M, if you installed CW 10.5, you may find it in the folder of something like "D:\CW MCU v10.5\MCU\CodeWarrior_Examples\Processor_Expert\Kinetis\TWR-KL05Z48M\FLASH". Please kindly refer to it for details.

Hope that helps,


Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

元の投稿で解決策を見る

0 件の賞賛
返信
7 返答(返信)
1,934件の閲覧回数
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Joginder Rana,

I think maybe you have to check the EEERDY bit after every write. Please kindly refer to the following for more details.

1.png

Hope that helps,


Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,934件の閲覧回数
joginderrana
Contributor II

Hi Kan,

First, thanks for your support. I tried the process you suggested but it did not work.

And since final application will be developed on the MKL05Z32VLF4 microcontroller, which doesn't have any flex_memory.

So the only option left to preserve data and use after power reset is to store required data into the programming Flash. I have one FLASH_LDD method in CW. I am using that function to read and write the data.

I have done all settings and created "use user memory area" . My test code according to one example code in community is as below:

#define location 0x200

char Data[20] = "Hello";

char Buffer[11] = "           ";

LDD_TError Error;

volatile bool DataWrittenFlg = FALSE;

LDD_FLASH_TOperationStatus  OpStatus;

/* Write your code here */

  for(;;) {

     

  Error =  FLASH1_Write(flash, Data, location, sizeof(Data));

   while (!DataWrittenFlg) {                                                   /* Wait until the data are written */

   }

  DataWrittenFlg = FALSE;

   if (FLASH1_GetOperationStatus(flash) == LDD_FLASH_FAILED) {           /* Check if the operation has successfully ended */

     /* Error state solution */

   }

  Error = FLASH1_Read(flash, location, Buffer, sizeof(Data));

   do {

       FLASH1_Main(flash);

       OpStatus = FLASH1_GetOperationStatus(flash);

     } while (!((OpStatus == LDD_FLASH_IDLE) | (OpStatus == LDD_FLASH_FAILED)));

     if (OpStatus == LDD_FLASH_FAILED) {                                         /* Check if the operation has successfully ended */

       /* Error state solution */

     }

       printf(" Received Data %s \n",  Buffer);

  WAIT1_Waitms(1000);

  }

  /*** Don't write any code pass this line

Even it is not working accordingly. Please help me in preserving the required data in Flash memory either by refining the above code or by providing any alternative option.

Thanks,

Joginder Rana

0 件の賞賛
返信
1,935件の閲覧回数
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Joginder Rana,

Actaully there is a ready Flash demo for TWR-KL05Z48M, if you installed CW 10.5, you may find it in the folder of something like "D:\CW MCU v10.5\MCU\CodeWarrior_Examples\Processor_Expert\Kinetis\TWR-KL05Z48M\FLASH". Please kindly refer to it for details.

Hope that helps,


Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信
1,934件の閲覧回数
joginderrana
Contributor II

HI Kan,

Thanks for referring to demo code. I went through the code you had suggested. I found that the code I sent to you in my last post for verifications is logically same to the one which is given as demo.

Now I am facing following issues:

1) Flash erase function is not working in any of the codes

2) As I need to store run time values in variables in the Flash.  It is still not happening if I am storing a constant value in the flash buffer and reading it, its working fine but cannot store or over write the value of the buffer during run time.

Please help me to make it happen so that controller could access variables from Flash whenever it needs those variables, either to store the value or to read the value.

0 件の賞賛
返信
1,934件の閲覧回数
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Rana,

Have you protected the code section in flash so that flash erase didn't funtion on your side? If you would provide some code snippet for review, that would be fine, and the whole project would be better as I can try to reproduce your issue on my FRDM-K20D50M:smileyhappy:

Thanks for your patience!!


Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信
1,934件の閲覧回数
joginderrana
Contributor II

Hi Kan,

Thanks for your kind support. I did not protect code in flash. I am here by sending my project, Please have a look of it and help me in get rid of the issue in case if I have done some thing wrong in my code and with settings. Please find the attachment.

0 件の賞賛
返信
1,934件の閲覧回数
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Rana,

I just reviewed your code and found some issues in your application:

1. I didn't find any flash erase function called before writing the flash, actaully it is needed for every flash program operation.

2. the location that you want to write and read is at 0x100, where resides in the first sector, and the interrupt vector occupies this place as well, so that is not a good space for flash program on the fly, because flash erase on that sector would also remove the interrupt vector so that the application could not function well.

3. I remember you told me the flash erase would not function well on your side, and after I realised the location is 0x100, I think that might be the cause, you know, K20D50M's inter flash has 1KB sector size, so flash erase should be sector size aligned, so you may input the starting address is at 0x000, 0x400,0x800 or something like that, but if the address to start erase is at 0x100, the flash API would return error with ERR_PARAM_ADDRESS, you may refer to FLASH1_Erase() for more details.

so my recommendation is changing the location to the last sector of the 128KB flash, and please call FLASH1_Erase() before any flash program operation.

Hope that helps,


Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------