I've an application that needs to count the operating seconds. I have implemented the time already.
Now on low power warning, I'd like to store the operating seconds. I have implemted the recognition already,
Now, my question is, that the flash has a limited endurance of 10k cycles. Is there any recommend tool, that allows to do wear leveling? I use the K22FN512 at the moment, later I want to use the KV4x.
(I saw Flex Memory, but those devices dont have it.)
Any recommendation how to do that?
Thanks for your hints Mark, I guess I will look at those code sources.
Having to use normal speed mode is a show-stopper for me. I simply cannot change the BusClk as I'm building a power supply, and the bus clock is driving the PWM-Waveform.
Is there a manner to write in High-Speed mode? What happens if I do it anyhow? I simply cannot change the BusClk or my system will suffer.
In High Speed RUN mode flash writes will not operate - they will return a failure.
If the chip is run at 120MHz in RUN mode it works, but this is running the chip out of specification.
Therefore you will either need to run at 80MHz or clock the PWMs from a different source that doesn't need to be changed when programming.
If you use a K22FN1M instead of K22FN512, which doesn't have HSRUN mode and can use RUN mode up to 120MHz there is no restriction.
Kinetis for professionals: http://www.utasker.com/services.html
In the uTasker project there is a method called "PARAMETER_AREA" which corresponds to your requirements. It will allow the K22 Flash to be modified 10 million times by defining 2 flash sectors for the storage (or 20 million for 4 sectors, etc.). Same for KV parts.
You can do the same very simply for storing a time value as follows:
1. Define 2 sectors of 4k for the operation
2. Each time you start, search through the area to find the 'last' value, which is the valid one
3. Each time you write, write just a long word or phrase (depending of Flash type) to the "end" of the list.
4. During step 2, if the last value is in the second flash sector, delete the first (to make space for its use again)
5. If in step 3 the second flash sector is full, write the new value at the start of the first sector
6. During step 2, if the last value is in the first sector and the second sector is not blank, delete the second sector
I may have missed a detail or two but the principle should be clear.
The new life expectancy is calculated by:
Number of writes in a 4k sector (assuming phrase writes) is 4k/8 = 512
Giving effectively 10k x 512 update cycles for the sector = 5'120k writes
Due to the two sectors (acting as a swap block to retain the newest value while the older ones are deleted) this doubles to 10'240k
Using multiple sectors again increases the effective 'changes' that can be made to the time value.
In the "PARAMETER_AREA" operation a set of parameters can also be saved, with the lifetime reducing according to the block size that needs to be written each time, but the basic operation is the same.
Dear Mark, thanks for pointing out that solution. This seems very promissing and feasable to me, as 8k of Flash are not terrible much.
Is there any prewritten Flash-Programming library, i can easily use? If not which application note can I follow?
(I use kinetis design studio without sdk)
You can use functions for the sdk as base if you need to use NXP code.
If you need more powerful but free code (including PARAMETER_AREA and simulation) you can get it from the Open Source uTasker project at http://www.utasker.com/forum/index.php?topic=1721.msg7086#msg7086
For professional work you can also get a fully up-to-date and supported version at http://www.utasker.com
Beware that you can't use high speed run mode in your present K22 when programming flash (use RUN mode - 80MHz - for your tests).
P.S. See flash operation in the video https://www.youtube.com/watch?v=c9GRYXFs9LU&list=PLWKlVb_MqDQFZAulrUywU30v869JBYi9Q&index=4
whereby the user interface for general testing is shown at about 6:00