VisualHMI RW power-down storage area: Flash lifespan, sector landing sequence, and secure initialization

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

The RW area is thepower-down save registerof the HMI: addresses 0x0000~0x7FFF, totaling 64KB (32768×2 bytes), based on Flash storage, with a default value of 0xFFFF upon power-on. Data that cannot be lost during power-off, such as parameters, recipes, and operating status, are stored here. However, it has a lifespan and potential pitfalls, and improper use can damage the firmware.

1. RW area characteristics

itemValue
address range0x0000 ~ 0x7FFF (32768 words)
storage mediumFlash (power-down save)
default value0xFFFF
Flash lifespanApproximately 100,000 erase-write cycles
Write mechanismInternal 4KB write cache queue, triggering an erase-write cycle approximately every 400 writes

2. ⚠️ Fatal risk: Excessive erase-writes can corrupt the firmware

The RW area andfirmware area are physically adjacent. Repeated erase-writes to the RW area, if it spreads to the firmware area, will directly damage the device: black screen, no firmware, blue screen. This is a serious issue, not just a scare tactic.

Additionally, Flash is written insector order(lower addresses are written first), and there is aconsistency risk for cross-sector flag bits- if a flag's two bytes fall in different sectors, a power loss during writing may result in half-new and half-old data.

3. Use correct posture

  • Address continuous allocation: Place parameters together in one section, don't scatter them everywhere
  • set_array batch writing: Write a group at a time, don't set one by one
  • Control writing frequency: Only write when the value changes, don't refresh periodically
  • Flag bits placed in the same sector: Flags that require atomicity should be placed together
  • Perform boundary value checks during startup: Read RW upon power-on to verify validity (magic number 0x55AA)
function on_init()
  -- 上电检查 RW 是否已初始化(魔数 0x55AA)
  if get_uint16(VT_RW, 0x2000) ~= 0x55AA then
    -- 首次上电,写入默认参数
    set_uint16(VT_RW, 0x2000, 0x55AA)   -- 魔数
    set_uint16(VT_RW, 0x2001, 50)       -- 温度上限默认值
    set_uint16(VT_RW, 0x2002, 4800)     -- 波特率默认值
  else
    -- 已初始化,检查参数边界
    local t = get_uint16(VT_RW, 0x2001)
    if t  100 then
      set_uint16(VT_RW, 0x2001, 50)     -- 越界恢复默认
    end
  end
end

Recommend the dual strategy of "same sector flag + parameter boundary check": confirm initialization with magic number, and perform boundary check to prevent dirty data.

Three iron laws:① It is strictly prohibited to store high-frequency real-time data in RW- curves, counts, and real-time values should be stored in LW. Only parameters that need to be retained during power-down should be entered into RW;② Before writing, check whether the value has changed. If it hasn't, don't write. A 100,000-cycle lifespan cannot withstand periodic refreshing;③ Upon power-on, an initialization check must be performed, using the magic number 0x55AA + boundary verification. Otherwise, the first power-on will read 0xFFFF, which is completely random.

Compiled from Guangzhou Dacai Technology VisualHMI development documentation (hmi-doc.gz-dc.com) LUA tutorial "RW Storage", copyright reserved by Dacai Technology.

Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.