11 years, 7 months ago.

Saving state on a kl25z between power cycles

I understand it lacks a filesystem but it is possible to write to an area of static ram so that the code I am running can save state (just a few bytes is all I need) ?

[ Also.. I cannot believe this thing has 2 usb connectors, an input area, tricolor leds etc for the price. Let alone all the other gubbins ... Incredible. ]

3 Answers

11 years, 7 months ago.

Short of writing to the flash itself (using the flash controller), there's no way to have your data survive power outages.

There's no library support as yet for writing to the internal flash.

See chapter 27 in the reference manual (KL25P80M48SF0RM.pdf) for more about the Flash Memory Module (FTFA).

You can erase the flash in 1K blocks, and write the flash in 4 byte blocks.

One important catch is that if you want to erase or write to the flash, you have to do so from code that is running from the SRAM. Which means that you'd have to convince the linker to compile your flash writing routines so that they can be copied from flash to RAM, or ensure that your code is position-independent so you could do that.

Another strategy might be to implement a very low power sleep mode (VLPS, LLS, or VLLS3) which will maintain SRAM contents but reduce power consumption far enough to allow backup with the coin cell (you'll have to add a coin cell holder for this).

Accepted Answer

Hi Ned. Thanks for this - that was a very complete answer. I am looking to write to flash as opposed to a low power sleep mode as I want to ship the units in the mail, store them safely for months at a time etc etc (the idea being that the unit itself will generate private keys via some user-generated entropy, store them safely and use these keys for message signing). I know that these aren't hardware safe (ie if someone has the unit itself, then they can probably extract the flash and read from it) but the cost of those efforts would be > the value of the data, so it's safe enough.

Now .. how do I get to the flash ? Excuse my ignorance, but is the client mbed app written to flash upon upload? Also - if the app was small enough - would there not be some flash available for storage? Have also noted that there is a write-once location which would be interesting to use as well.

Is library support for flash writing on the roadmap yet?

posted by Richard Green 15 May 2013

Yes, the client app is written to flash on upload. There is a Kinetis K20 processor (more powerful than the target KL25 processor!) that is connected to the SDA USB port. It programs the target KL25 via its SWD/JTAG pins. There are 64 bytes available in the FTFA, it seems. You may be able to use these. You can probably lock the flash and the FTFA bytes against being read via JTAG as well (which you will need, because it's trivial to read the data via the OpenSDA port.

posted by Ned Konz 18 May 2013
11 years, 4 months ago.

I am also interested in code to write to the KL25Z flash. Sounds like a small blob of position independent code needs to be loaded into sram for the actual write to flash.

11 years, 4 months ago.

You might consider using either an SD card or a flash memory (for which there are a variety of user libraries on mbed).