Stor Object

Top  Previous  Next


The stor object provides access to the non-volatile (EEPROM) memory, in which your application can store data that must not be lost when the device is switched off.


note_warning-wtOn the advice of one of our customers we are giving you the following reminder: Like all other EEPROMs on the market, EEPROM ICs used in Tibbo devices allow for a limited number of write cycles. As the Wikipedia article on EEPROMs ( states, the EEPROM "...has a limited life for erasing and reprogramming, now reaching a million operations in modern EEPROMs. In an EEPROM that is frequently reprogrammed while the computer is in use, the life of the EEPROM is an important design consideration." When planning to use the stor. object, please carefully consider if the planned mode of EEPROM use will allow the EEPROM to work reliably through the entire projected life of your product. Please also read the Prolonging and estimating the life of your EEPROM section below.


The stor.size read-only property tells you the amount of EEPROM memory offered by the stor object. The stor.set is used to write the data to the EEPROM, while the stor.get method is used to read the data from the EEPROM.

Here is a simple example how to save the IP address of your device in the EEPROM:



dim s as string

dim x as byte


s=ddval(net.ip) 'this way it will take less space in the EEPROM (only 4 bytes needed)

x= stor.set(s,0) 'write EEPROM


'check result

if x<>len(s) then

 'EEPROM write failure- do something about this!

end if



And here is how you read this data back from the EEPROM:






Notice, that with the stor object addresses are counted from 1, not 0. That is, the first memory location has address 1.


Special configuration area

The EEPROM IC of the device is also used to store certain configuration information required by the device. Memory available to your application equals the capacity of the IC minus the size of the special configuration area.

By default, when you access the first byte of the EEPROM you are actually accessing the first memory location above the special configuration area. One property — stor.base — returns the size of this offset. On startup, stor.base is equal to the size of the special configuration area, so your program can only access the memory above this area.

You can change the stor.base and access configuration area when you need. For example, you can change the MAC address this way- next time the device boots up it will start using newly set address.


Prolonging and estimating the life of your EEPROM

Here are some ideas on prolonging the life of your EEPROM:

Limit the number of updates you make to the EEPROM's data. For example, if you are counting events, then do not write to the EEPROM every time you increment the count. Instead, keep a counter variable in RAM and implement the EEPROM update policy. For example, you may choose to update the EEPROM once for every 100 increments of the RAM counter, or after x hours of inactivity.
Before writing data into an EEPROM location, read this location to see if it already contains the data to be written. In EEPROMs, writing the same data into the same location still counts as a write cycle!
Use a wear leveling scheme, in which you rotate your storage area through a range of EEPROM addresses. For example, if you have a 32-bit counter, create an array of 32-bit locations and rotate between these locations when incrementing the counter. This one should be taken in conjunction with the next point...
When placing a frequently updated data into the EEPROM, try to keep this data within sector boundaries. Like flash storage, EEPROMs do have sectors. Tibbo devices with 2KB EEPROMs have 16-byte sectors. Devices with 256-byte EEPROMs have 8-byte sectors. When you update the data in a portion of a sector, you are actually wearing off the entire sector! When counting sector boundaries, take into the account the stor.base property — it gives all your writes a fixed offset! For example, on the EM1000 (2KB EEPROM), to write into the third sector of the EEPROM, use stor.setdata(s,4), because stor.base=29 and 29+4=33, i.e. the first location of the third 16-byte sector (stor. locations are counted from 1).
Use redundancy — keep two or more copies of your EEPROM data and protect the data with checksums. Should one copy fail, there will be another copy to use. This also helps against abrupt power failures. If the power is turned off while the EEPROM write is in progress you may lose your data. Having a backup copy helps in such situations.
Consider using our STG library — it will save you a lot of headache in dealing with EEPROM data.


When estimating the life of the EEPROM in your system, consider the following:

Always take into the account the underlying sector nature of EEPROM ICs. Writing even a single byte into a sector reduces the lifespan of the entire sector.
Writing a string of several characters constitutes the number of write cycles equal to the number of characters in that string. Executing stor.setdata("ABC",4) counts as three write cycles, not one.
High ambient temperature reduces the life of EEPROMs.
All vendor estimates for the projected EEPROM life are probabilistic in nature. You will encounter "stronger" and "weaker" specimen with vastly different endurance levels. All in all, it is quite safe to assume that your EEPROM will last for at least 1 million write cycles per sector... and yet, there is no guarantee of that.