Repository navigation
Telink: do not drop flash writes on ZBIT flash chips (512 kB Zbeacon / HOBEIAN lose pairing on restart) - #554
gyimesibalazs wants to merge 1 commit into
Conversation
For ZBIT flash (JEDEC 0x13325E / 0x14325E) the SDK measures the supply voltage with the ADC before every program and erase command and silently skips the command when the reading is bad. No ADC pin is configured here, so the Zigbee stack's data was never stored and the device lost its network at every restart. Mains devices now report a good supply to that check; battery devices keep it.
|
A follow-up on why this probably also matters for the "bad router" reports (#501), not only for the lost pairing. A router keeps its outgoing NWK frame counter in flash: So after a power loss such a router starts counting its outgoing NWK frames again from a low value. Its neighbours keep the highest counter they have seen from it and drop every frame below that as a replay, silently. Until the counter has passed the old value the router can neither forward nor be heard: its children are cut off and routes through it fail, which from the outside looks like other devices dropping out of the network, and power-cycling things around it "helps" only by chance. That fits the descriptions in #501 (devices started to drop after the switch joined; power-cycling the switch and the coordinator fixed it), but it is an explanation from the code and the flash dump: I have not observed such a drop-out on my network. |
Problem
On modules with a ZBIT flash chip (JEDEC id
5e3213/ mid0x13325E, also0x14325E) the Zigbee stack's data never reaches the flash: network key, bindings, frame counter. The device joins and works until the next restart, then comes up factory new and tries to join again.This is the Zbeacon TS0001 behaviour reported in #219 ("after power is removed the pairing is lost and it enters pairing mode immediately", "changing the config string enters pairing mode"), and very likely the cause of the open issues on the 512 kB HOBEIAN / Zbeacon devices listed in
docs/known_issues.md, which use the same flash.Cause
For ZBIT flash the SDK measures the supply voltage with the ADC before every program and erase command and silently skips the command when the reading is not above the threshold or fluctuates (
flash_mspi_write_ram()inplatform/chip_8258/flash.c, enabled byflash_is_zb()indrv_hw.c).On the TLSR8258 the supply can only be measured through a free GPIO in VBAT mode. This firmware has
VOLTAGE_DETECT_ADC_PIN = 0, so the reading is meaningless and most writes are dropped. Writes that happen to pass (for example the firmware's own items early at start-up) are stored, which is why the device settings survive while the network data does not.Evidence (Zbeacon TS0001, JEDEC
5e3213, unmodifiedMODULE_TUYA_DEFAULT_A_TS00011.1.3 build)0x34000–0x3FFFF(ZB_INFO, address table, APS, ZCL, frame counter, OTA) completely blank, the APP module at0x7A000written.nv_flashWriteNew()on a module in0x34000–0x3FFFFone minute after start gotNV_ITEM_CHECK_ERROR(the data was not there on read-back), while the stack reported joined / not factory new / commissioning success.Fix
flash.cis compiled withadc_get_result_with_fluctrenamed to a small function inpatch_sdk/flash_zbit.c(same mechanism as the existingdrv_nv.cpatch):BT<pin>): the ADC is set up on that pin, so the SDK's check is kept.No behaviour change for other flash chips: the SDK only runs this check when
flash_is_zb()is true.Not covered