How can i store some data into flexNVM or flash memory ?

cancel
Showing results for 
Search instead for 
Did you mean: 

How can i store some data into flexNVM or flash memory ?

Jump to solution
1,042 Views
josol
Contributor III

Hi.

settitng :

I am using MK64FN1M0VLL12 MCU  , KDS 3.0.0,  MQX V 1.1.1


Question :

I want to store some data into NVM or flash before Power down.

and right after Power on again , I want to read the data.

but I dont know how edit the ProcessorExpert.pe and etc...

the data I want to store is just 12byte. so can i get a manual or advice about processing a components

93161_93161.pngpastedImage_4.png

Thank you

Tags (1)
1 Solution
269 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Jo Sol:

I am sorry for the troubles you've had so far. I will explain the issues and attached you can find an example project similar to your code but with corrections.

- First the hardfault you observed was most probably because of over programming the same phrase (8-bytes) without a previous erase. I think this is a bug in the FLASH_LDD component which allows over programming, as discussed in the next thread: What are the rules for random writes to Flash? (K64)

- Luiz is correct about the conditional OR operator (| |).

- The information about the parameters in the _Erase() function is misleading. I noticed that FromAddress must be aligned to the start of a flash sector and Size must be a multiple of the sector size. The K64 has a sector size of 4096 Bytes (4 KB). In your example you need to write to address 0xFFFFA, so you have to erase the last flash sector, from 0xFF000 to 0xFFFFF.

In the example project I enabled Auto initialization from the FLASH_LDD component settings so you don't have to call the _Init() function. Just notice that the first parameter for the APIs would be FLASH1_DeviceData.

I have already reported the issues with the component to the Processor Expert team.

Regards!
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------

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

-----------------------------------------------------------------------------------------------------------------------

View solution in original post

7 Replies
269 Views
lfschrickte
Contributor IV

Hi,

First of all, the MK64FN1M0VLL12 MCU has no FlexNVM as far as I know.

Second, you don't need to edit the ProcessorExpert.pe directly! Just add the Flash1 component through Processor Expert interface and configure it according to your needs (define some memory region for data in your MCU memory).

After that you may use Flash1 Methods and Events (I've used FLASH1_Write, FLASH1_GetOperationStatusFLASH1_OnOperationComplete and FLASH1_Main for instance) to do what you want - it is pretty straight forward!

In order to read the data, instead of using the Flash1 Read function,  you can simply create a pointer to the flash address and read for it that it will work fine, like:

data = *((flash_data *)DATA_FLASH_START);

Regards

269 Views
josol
Contributor III

Thank you for kind reply.

I am trying to write or read the data. and i added component successfully

and i found a useful post -> Re: Erasing Flash sectors in KL25 on the Freedom Board.

and i successfully write and read a data at first time. but it didn't work at second time

while debugging, i found that in UnhandledInterrupt, the process stoped.

can i get a answer about this problem? it's my code, and debugging window. 

thank you very much

------------------------------------------------------------------------------------------------------------------------------------------------------

uint8 FromPtr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

uint8 ToPtr[6];

int OpStatus;

LDD_TError OpStatus;

LDD_TDeviceData* FLASH1Pointer;

FXAS2100X_calib(I2C_DeviceData);

FLASH1_Erase(FLASH1Pointer, 0xFFFFA, 0x6);  //erase

  do {

  FLASH1_Main(FLASH1Pointer);

  OpStatus = FLASH1_GetOperationStatus(FLASH1Pointer);

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

  FLASH1_Write(FLASH1Pointer, FromPtr, 0xFFFFA, 0x6);  //write

  do {

  FLASH1_Main(FLASH1Pointer);

  OpStatus = FLASH1_GetOperationStatus(FLASH1Pointer);

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

  FLASH1_Read(FLASH1Pointer,0xFFFFA, ToPtr, 0x6);  //read

  do {

  FLASH1_Main(FLASH1Pointer);

  OpStatus = FLASH1_GetOperationStatus(FLASH1Pointer);

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

------------------------------------------------------------------------------------------------------------------------------------------------------

pastedImage_0.png

0 Kudos
269 Views
lfschrickte
Contributor IV

Dear Jo,

Do you have a call like this somewhere?

FLASH1Pointer = FLASH1_Init(NULL);

You need to this before the other FLASH1 calls!

Other things I noticed is your condition checking:

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

The '|' operator is the bitwise OR, but what you want in there is the conditional OR, which is represented by two bars: '||'

Other tip: put some other pattern in your FromPtr array - 0xFF may get you confused as this is what happens to this flash memory when you erase it...

Another hint: use 4 bytes multiple array sizes - this may save you from some future alignment trouble.

Regards

Luiz

0 Kudos
269 Views
josol
Contributor III

Thank you for friendly answer.

i tried all method you suggeted, but Unfortunately it doesn't work to my board.

so I find the post that someone has a same problem with me

-> K60N512 Memory

and the answer is that this was happening because the sector that i was trying to write to was not erased. the PE generated code does not erase the sector for me prior to writing to it, and i have to erase it myself

so i don't know how can i erase the sector.... I would appreciate your help... Thank you

(perhaps, it may beproblem with MQX, so i will post same content to MQX community)

0 Kudos
270 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Jo Sol:

I am sorry for the troubles you've had so far. I will explain the issues and attached you can find an example project similar to your code but with corrections.

- First the hardfault you observed was most probably because of over programming the same phrase (8-bytes) without a previous erase. I think this is a bug in the FLASH_LDD component which allows over programming, as discussed in the next thread: What are the rules for random writes to Flash? (K64)

- Luiz is correct about the conditional OR operator (| |).

- The information about the parameters in the _Erase() function is misleading. I noticed that FromAddress must be aligned to the start of a flash sector and Size must be a multiple of the sector size. The K64 has a sector size of 4096 Bytes (4 KB). In your example you need to write to address 0xFFFFA, so you have to erase the last flash sector, from 0xFF000 to 0xFFFFF.

In the example project I enabled Auto initialization from the FLASH_LDD component settings so you don't have to call the _Init() function. Just notice that the first parameter for the APIs would be FLASH1_DeviceData.

I have already reported the issues with the component to the Processor Expert team.

Regards!
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------

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

-----------------------------------------------------------------------------------------------------------------------

View solution in original post

269 Views
psjhawer
Contributor II

Hi Jorge,

I might sound a bit unreasonable here... I have been trying to add the flexNVM feature of reading and writing data between power cycles for some time now with no success what so ever.... Can you please help me with a similar project u created here...?? I'm working on a bare board project on MK10DX128VLH5 and need to save a structure of an unsigned char and 4 unsigned into variables on the flash data which can be read between power cycles... Your help on this would be of great great help for as I'm almost on my submission date here and this flexNVM is about to kill me.... :smileysad:

Regards,

Prafful

0 Kudos
269 Views
josol
Contributor III

Dear Luiz , Jorge

I tried to erase 0xFF000~0xFFFFF again and now it work well 

without your help, i can not figure it out.

Thank you very much , Have a nice day!~!:smileyhappy: