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
| item | Value |
|---|---|
| address range | 0x0000 ~ 0x7FFF (32768 words) |
| storage medium | Flash (power-down save) |
| default value | 0xFFFF |
| Flash lifespan | Approximately 100,000 erase-write cycles |
| Write mechanism | Internal 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
endRecommend the dual strategy of "same sector flag + parameter boundary check": confirm initialization with magic number, and perform boundary check to prevent dirty data.
Compiled from Guangzhou Dacai Technology VisualHMI development documentation (hmi-doc.gz-dc.com) LUA tutorial "RW Storage", copyright reserved by Dacai Technology.
Leave a Reply