Save important informations on power fail on MK22FX512VLH12

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

Save important informations on power fail on MK22FX512VLH12

Jump to solution
1,400 Views
ralf1694
Contributor III

Hi. I want to store important information on power fail on the internal flash (from MK22).

I detect the power fail, but how I must write my data on internal flash. I read something about FLEX RAM?

Have anybody an example or idea for me?

Thanks.

Labels (1)
1 Solution
1,204 Views
egoodii
Senior Contributor III

Just one quick operational note from me:

Make SURE you will have enough power-supply holdup time to COMPLETE the (erase?) phrase-write cycle.  If the entire cell-write process does NOT complete before Vdd falls out of spec, you risk getting hard-faults when you attempt to read said corrupt phrase on the next power-up.

View solution in original post

11 Replies
1,204 Views
ralf1694
Contributor III

Hi Earl and jeremyzhou. Thanks for your reply! I have an capacitor on my hardware. But what happened when the power goes down within an phrase write? When I am start the software and I want to read this data Earl said I get an hard fault. Can I intercept this, so that my software do not hanging in the hard fault? And when this is possible, how I com back from the hardfault to my software without reading the corrupt phrase?

Thanks.

0 Kudos
1,204 Views
ralf1694
Contributor III

I am reading the interrupts and the cache must be disable when write to the internal flash? Is this correct? I know that an ISR can interrupt the write cycle and maybe the time is to short to write the whole data on flash. Thanks.

0 Kudos
1,204 Views
ralf1694
Contributor III

I write now some data to the flash and I think I have the problem which Earl said. I can not read the data on the next power on.

I see in the Memory window that not all data are written. If I read the data in line 948 with a normal pointer I get an Hard Fault conj an Bus Fault and from Bus Fault to Hard Fault. But this happened sporadic. I write 1000 times to the flash and only once the error occurs. In the followning 2 screenshots from the issue. I can not make the capacitor bigger. Is there a chance to spring from the Hard Fualt back to my software and read other data from flash when which are ok? Thanks.

Note: The pointer is 0x10004210 and the flash addresses from 0x10004210 to 0x10004217 on memory window should be 0x00 but the addresses are not 0x00? In this area I get the hardfault.

error1.PNG

0 Kudos
1,204 Views
egoodii
Senior Contributor III

The hard-fault is, of course, just a vectored-interrupt, and you can put anything you like in the 'handler'.  I have NOT confirmed if there is any 'obvious' indication in the ARM fault-registers that would tell you said fault was a flash-access-read-error (like DFSR ending in 0x18 or 0x19?), you might look into that.  OR look into the stacked 'return address' pointing to the fault-location, and recognize that as your read-function -- and in that way 'discard' this 'latest' record and restore from a previous, known-good set of info.

1,204 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Oliver,

I'd like to range of flash area you choose to save the data, and I'm afraid that you can't  should use the pointer to write or read flash, you should use the flash command to do flash operations.

Hope it helps.
Have a great day,
Ping

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

0 Kudos
1,204 Views
ralf1694
Contributor III

I use the FlashProgram command to write to flash, but an simple pointer to read them. I try to use the flash command to read the flash. I found two read functions. FlashReadResource() and FlashReadOnce(). I think I need the FlashReadresource function? I see this function have the return value OK and FTFx_ERR_ACCERR. If I read the faulty flash area with this function and the return value is FTFx_ERR_ACCERR, would I jump to the Hard Fault ISR or not. And how can I recreate this error without writting 1000 times or often to the flash because the issue is sporadic? Can I write the same flash area 2 times to get the same issue?

0 Kudos
1,204 Views
ralf1694
Contributor III

I try to use the FlashReadresource function but I get always an ACCERR. I found this post:

I was trying for several hours to read program flash using the FlashReadResource() function.  After reading this post I tried the READ32() macro, and it just worked.  Yay!

 

Sidenote:

It's strange to me that the C90TFS library has 2 functions to read the P-Flash IFR(FlashReadResource, and ReadOnce), but neither can read the basic program flash.  If you try to pass in an absolute address, e.g. 0x7E000 for a 512KB MKW2x chip, the FlashReadResource function will return an access error (ACCERR).  After lots of reading I realized that the access error is because these functions are only supposed to access IFR memory (see Table 35-44 of the MKW2x reference manual for valid local address ranges). 

So my question. Which Flash read function do you mean jeremyzhou?

0 Kudos
1,203 Views
ralf1694
Contributor III

error2.PNG

0 Kudos
1,205 Views
egoodii
Senior Contributor III

Just one quick operational note from me:

Make SURE you will have enough power-supply holdup time to COMPLETE the (erase?) phrase-write cycle.  If the entire cell-write process does NOT complete before Vdd falls out of spec, you risk getting hard-faults when you attempt to read said corrupt phrase on the next power-up.

1,203 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Oliver Schmid,

As EARL GOODRICH mentioned above, it's the key to save the completely important information before the power supply drop out.

So I'd highly recommend that you can adapt the power supply circuit which can provide an backup power supply such as LI-lon battery instead of the original one.

Hope it helps.
Have a great day,
Ping

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

1,204 Views
egoodii
Senior Contributor III

Or maybe 'one step down' from a full battery, in the form of a supercapacitor.

0 Kudos