Store data on internal non Volatile Memory

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Store data on internal non Volatile Memory

Jump to solution
5,717 Views
sebasira
Senior Contributor I

Hello to you all!

I'm new at Kinetis MCUs... Rigth now, we're no using any RTOS, just bare-metal projects. I have a PC application that communicate with the TWRK60 using the uart.

The idea of the PC app is to program some parameters of the firmware. Before Kinetis, on HCS12 and CFv1 MCUs I stored this data into internal FLASH or EEPROM. Rigth now, I'm confused about this and the FlexMem.

Does anyone know about a simple way to store data (non-volatile data) in the K60 internal memory? I've downloaded C90TFS driver but it seem way too complex.

I'm using IAR IDE.

Thanks!! Best Regards!

SebaS

Labels (1)
Tags (3)
0 Kudos
1 Solution
1,848 Views
Paul_Tian
NXP Employee
NXP Employee


Hi, Sebas

Attached is a sample code of Kinetis flex memory operation. It is from C90TS but not so complex. It is for your reference.

Hope my reply can help you.

Best Regards

Paul

View solution in original post

0 Kudos
11 Replies
1,848 Views
stefano_conegia
Contributor I

Hi All,

I am using a Freescale K60DN512 and MQX4.1 .

Also I need to store some data on NVM memory. I followed the example flash_demo.c and it works fine. My problem is that if I re-flash the program (for example for an update of FW) I lose my previous data stored into NVM memory.

Is there a way to preserve my NVM data after a reload of FLASH memory ? What is my mystake? Thanks all,

Stefano

0 Kudos
1,849 Views
Paul_Tian
NXP Employee
NXP Employee


Hi, Sebas

Attached is a sample code of Kinetis flex memory operation. It is from C90TS but not so complex. It is for your reference.

Hope my reply can help you.

Best Regards

Paul

0 Kudos
1,848 Views
keithkolmos
Contributor I

Am I missing something?  But in your flexmem_demo.c snippet it includes flexmem_demo.h.  I can't seem to find that file (and I've downloaded the C90 driver and the app note code referenced above)?

I have a K10  MK10DX256ZVLQ10 micro.  I just want to set up a small area to save the state of 10 bytes of data.  I realize that I have to erase / write by sectors which is fine.

Any help here?


Keith

0 Kudos
1,848 Views
jonathanscott
Contributor III

Hi Keith,

Do you have your project working?  I am using the MK10DX128, and I'm having a heck of a time storing to NVM and then reading it back.  I have EEPROM defined from 0x14000000 to 0x140003FF and from 0x14000400 to 0x140007FF.  Ultimately, I'm just trying to read a word back from 0x14000040. I'm in debug mode.

Writing like this seems to work: 

#define WORD_VALUE_ADDR 0x14000040

EEEWrite(address, 0x02, value);

 

But everything I've tried to read data back seems to give me a hard fault: 

value = READ8(0x14000040); --> FAULT

value = *((unsigned char *)0x14000040); --> FAULT

value = *((unsigned char *)WORD_VALUE_ADDR ); --> FAULT

value = *((uint16 *)WORD_VALUE_ADDR ); --> FAULT 

Where can I find a simple EEERead(address, size)???


Let me know if you've figured this out.

Thanks,

Jonathan

0 Kudos
1,848 Views
sebasira
Senior Contributor I

Hi Paul!

Thanks for your quick reply!!

I just replace your file for the "main.c" inside my project. It compiles fine but when I run it, it get stuck inside EEEWrite, waiting for the EEERDY bit to be set.

Here's a portion of the code where it gets stuck:

void EEEWrite(unsigned long destination,unsigned long size,unsigned long source){

    /* Check if EEE is enabled */

    if(REG_READ(FTFL_FCNFG & 0x01)){

            while(size > 0){

                while(0 == (FTFL_FCNFG & 0x01)){

                   HERE IS WHERE IT GETS STUCK /* wait till EEERDY bit is set */

                }

                WRITE8(destination,READ8(source));

Hope you can help me!

Thanks again!

Best Regards

SebaS

0 Kudos
1,848 Views
sebasira
Senior Contributor I

I've read in another post that: "The K60 MCU on the TWR-K60N512 doesn't have any NVM. It's a flash only part. The N in the K60 part number signifies a flash only part. You would need an X in that position to signify a part with NVM."

If that's true, does it mean I can not write non volatile data on that chip?

0 Kudos
1,848 Views
Paul_Tian
NXP Employee
NXP Employee

Hi, Sebasria

You can use function FlashProgramLongword in my sample code to write data to flash.

Hope my reply can help you.

Best Regards

Paul

0 Kudos
1,848 Views
sebasira
Senior Contributor I

Oh, sorry I miss that routine!

I would like to ask you some more question. I'm used to work with .LCF and .PRM files, where the segments are defined. Now I can't find the equivalent for the Kinetis. I'm using IAR Workbench.

- How can I tell where does the FLASH begins/ends? Where can I modify that?

- What's the samallest partion that I can erase(1kb?) and How can I do that? I mean, I've seen the "FlashEraseAllBlock" rotuine but I guess that erase ALL the flash

- And the last question is about the "flow". Why I need to init flash and then re-init it? What about the unsecure_key? and can you explain me what's DEFlashPartition for?

Thank you very much. You're helping me a lot!

Best Regards!

SebaS

0 Kudos
1,848 Views
Paul_Tian
NXP Employee
NXP Employee

Hi, Sebasria

1. For flash memory, you can reference this picture.
memory map.bmp

2. Yes, it is 1K. I will provide a simple sector erase function "FlashEraseSector" for your reference as attached.

3. If you did flexNVM partition operation, you need to re-init flash. If you do not do this operation, of course, you need not.

4. If you are interest in FlexNVM operation, you can reference an application note http://cache.freescale.com/files/32bit/doc/app_note/AN4282.pdf?fsrch=1&sr=24

Hope my reply can help you.

Best Regards

Paul

1,848 Views
sebasira
Senior Contributor I

One more time, thank you for your reply!

I'm experiencing some troubles with this. For example, it only "works" if I run it as DEBUG. If I do it in RELEASE, it gets stuck inside EraseAllBlock (I can't tell where, because it's the release version and it doesn't accept breakpoints or halt).

And when in DEBUG, it only works (writes the flash) if I put a breakpoint after the ProgramLongword routine and then reset the MCU. At that point is where I can see the data written (in Memory windows). If I do not do so, then it does not write. I can tell this not only because I can't see it on the Memory Windows, but also I print it out via UART and there are all 0xFF

Hope you can help me here!

Best Regards,

SebaS

0 Kudos
1,848 Views
sebasira
Senior Contributor I

Paul!

I've solve the problem!!

It was due to the fact that ("I guess") I was trying to re-program an address where the firmware reside. And that's why it hangs in the release version.

Now, I've change that address to be 0x7F800 ( the last 2KB of PFLASH) and I have no problem with it and works like a charm!

Now I've got a final question.

Where and How can I defined the code sections and nonVolatileData section?

For example I want the code to reside from 0x00000000 to 0x0007F7FF and also NVMdata from 0x0007F800 to 0x0007FFFF

THANK YOU!!

SebaS

0 Kudos