This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How Do You Write a Single Variable to Flash?

I'm using a C167 chip, I need to save just a single variable to Flash. The value will be used as part of a configuration parameter. Is there a nice simple way of using Flash to save just a single variable? Thanks

Parents
  • The method for erasing and programming flash depends on the particular device. You really have to check the data sheet. Typically, you have to present a specific sequence of values on the address and data busses, followed by the address and value you want to write. For AMD-style parts, which is pretty much anyone but Intel, the sequence is usually something like:

    Addr Data
    ---- -----
    AAAA 55
    5555 AA
    SA A0 ; SA is any address in the sector
    addr data ; Addr is the actual address to program,
    ;data is the value you want

    Flash memory is usually divided into "sectors" of some number of words, with the size depending on the device.

    Flash sectors must be erased before writing. An entire sector must be erased as a unit. Erasure sets all bits in the sector to '1'. Programming (writing) flash can only set a 1 to a 0. You can program flash multiple times without erasing, and you can even program the same location multiple times if it happens that you never need to change a 0 to a 1.

    Many micros with built-in flash also have a built-in code library in their boot ROM with routines to do the programming that you can call. See your data sheet.

    While flash does have a limited number of write cycles, this number is generally pretty high if you're talking about configuration data. Typical lifetimes these days are 1,000,000 erase cycles for generic parts. Sometimes you see 100,000. Flash intended only for program updates -- usually built into a micro -- sometimes guarantee only 10,000 erase cycles. But even that is enough to reprogram the chip twice a day, every day, for ten years. You can't use flash for operating variables as though it were RAM, but for holding code or configuration parameters, and even for a lot of logging applications, the lifetime really isn't much of a concern in practice.

    Is everyone else eagerly awaiting MRAM?

Reply
  • The method for erasing and programming flash depends on the particular device. You really have to check the data sheet. Typically, you have to present a specific sequence of values on the address and data busses, followed by the address and value you want to write. For AMD-style parts, which is pretty much anyone but Intel, the sequence is usually something like:

    Addr Data
    ---- -----
    AAAA 55
    5555 AA
    SA A0 ; SA is any address in the sector
    addr data ; Addr is the actual address to program,
    ;data is the value you want

    Flash memory is usually divided into "sectors" of some number of words, with the size depending on the device.

    Flash sectors must be erased before writing. An entire sector must be erased as a unit. Erasure sets all bits in the sector to '1'. Programming (writing) flash can only set a 1 to a 0. You can program flash multiple times without erasing, and you can even program the same location multiple times if it happens that you never need to change a 0 to a 1.

    Many micros with built-in flash also have a built-in code library in their boot ROM with routines to do the programming that you can call. See your data sheet.

    While flash does have a limited number of write cycles, this number is generally pretty high if you're talking about configuration data. Typical lifetimes these days are 1,000,000 erase cycles for generic parts. Sometimes you see 100,000. Flash intended only for program updates -- usually built into a micro -- sometimes guarantee only 10,000 erase cycles. But even that is enough to reprogram the chip twice a day, every day, for ten years. You can't use flash for operating variables as though it were RAM, but for holding code or configuration parameters, and even for a lot of logging applications, the lifetime really isn't much of a concern in practice.

    Is everyone else eagerly awaiting MRAM?

Children