Page 1 of 2
firmware corruption
Posted: 2024年 Nov 13日 12:58
by percy(unwired)
what are the possible reasons for firmware corruption on BT3L MODULE.
this is a battery operated keypad.
Device works fine issue mostly occurs when the battery drains out.
the device does not go through the built in reset routine by pressing the keys.
have tried reseting and activating the module using the bdt tool however no luck.
the device works fine after the firmware is reflashed.
the firmware currently does not contain any routines accessing the nvram or flash memory.
Re: firmware corruption
Posted: 2024年 Nov 13日 14:06
by joey_nobug
If a mesh message is sent, the mesh stack will operate the flash. However, due to low battery power, the VCC will also be low, which may lead to issues when writing or erasing the flash. By enabling the macro definition BATT_CHECK_ENABLE, you can initiate low battery protection, thereby reducing the risk of firmware corruption caused by flash operations under low power conditions. Since this issue arises from the hardware design of the chip, this method can only reduce the probability of the problem occurring but cannot fundamentally solve it. If this does not completely resolve your issue, it is recommended to implement additional low battery protection measures at the hardware level.
Re: firmware corruption
Posted: 2024年 Nov 13日 16:36
by percy(unwired)
not only the firmware flash region and even the tuya token/license being erased or corrupted.
Re: firmware corruption
Posted: 2024年 Nov 13日 16:38
by joey_nobug
percy(unwired) 2024年 Nov 13日 16:36
not only the firmware flash region and even the tuya token/license being erased or corrupted.
Yes, because in low power conditions, flash operations are unpredictable and various strange anomalies may occur.
Re: firmware corruption
Posted: 2024年 Nov 14日 12:20
by percy(unwired)
The battery check macro is disabled in app_config_8258.h other than enabling the same, what are the other settings required to enable battery voltage detection on the TL_C4 ADC port.
Also any other settings or configuration required to prevent flash memory errors.
Since the power consumption of the module is high in sleep mode i will be enabling the deep sleep mode which would require saving and retrieving data from nvram.
I have attached the current battery voltage detection schematic for your reference.
let me know how the battery check macro needs to be implemented in the sdk.
Re: firmware corruption
Posted: 2024年 Nov 14日 14:16
by joey_nobug
The low voltage detection is entirely internal and does not require external circuitry. The principle is to measure the VCC input voltage using the ADC by directly detecting pin PC5 (internally in the chip, not externally accessible). When the VCC voltage is lower than the threshold configured by the VBAT_ALARM_THRES_MV macro (in millivolts), the system will enter sleep mode and use a timer to wake up. Upon waking, it will continue to check the voltage, and if the voltage is still below the required level, it will return to sleep. If you want to use PC4 to measure the battery voltage, do not enable the BATT_CHECK_ENABLE macro definition. Instead, you can use the ADC to detect it and provide a valid voltage range for low voltage protection.
Re: firmware corruption
Posted: 2024年 Nov 14日 15:20
by percy(unwired)
if i enable the BATT_CHECK_ENABLE macro following error appears during build
./vendor/tlsr825x_smesh/sdk/telink_sig_mesh_sdk/drivers/8258/flash.c: In function 'flash_erase_sector':
./vendor/tlsr825x_smesh/sdk/telink_sig_mesh_sdk/drivers/8258/flash.c:224:5: warning: implicit declaration of function 'app_battery_power_check_and_sleep_handle'
[ld] tc32-elf-ld --gc-sections -T ./vendor/tlsr825x_smesh/sdk/telink_sig_mesh_sdk/boot.link $O_FILES $LIB_DIRS "-(" $LIBS "-)" -o $ELF
.log/flash.o: In function flash_erase_sector':
flash.c:(.text.flash_erase_sector+0x8): undefined reference to
app_battery_power_check_and_sleep_handle'
.log/flash.o: In function flash_erase_sector_ota':
flash.c:(.text.flash_erase_sector_ota+0x8): undefined reference to
app_battery_power_check_and_sleep_handle'
.log/flash.o: In function flash_write_page':
flash.c:(.text.flash_write_page+0xc): undefined reference to
app_battery_power_check_and_sleep_handle'
.log/flash.o: In function flash_write_page_ota':
flash.c:(.text.flash_write_page_ota+0xc): undefined reference to
app_battery_power_check_and_sleep_handle'
.log/app.o: In function main_loop':
app.c:(.text.main_loop+0x14): undefined reference to
app_battery_power_check_and_sleep_handle'
.log/app.o:app.c:(.text.user_init+0x6): more undefined references to `app_battery_power_check_and_sleep_handle' follow
[o-list] tc32-elf-objdump -x -D -l -S $ELF > $LST
tc32-elf-objdump: '.log/output.elf': No such file
[o-bin] tc32-elf-objcopy -O binary $ELF $OUTPUT/output.bin
tc32-elf-objcopy: '.log/output.elf': No such file
[o-size] tc32-elf-size -t $ELF
tc32-elf-size: '.log/output.elf': No such file
0 0 0 0 0 (TOTALS)
build end, create final fw...
copy ./.log/output.bin -> UG
build fail
Re: firmware corruption
Posted: 2024年 Nov 14日 15:55
by joey_nobug
percy(unwired) 2024年 Nov 14日 15:20
if i enable the BATT_CHECK_ENABLE macro following error appears during build
./vendor/tlsr825x_smesh/sdk/telink_sig_mesh_sdk/drivers/8258/flash.c: In function 'flash_erase_sector':
./vendor/tlsr825x_smesh/sdk/telink_sig_mesh_sdk/drivers/8258/flash.c:224:5: warning: implicit declaration of function 'app_battery_power_check_and_sleep_handle'
[ld] tc32-elf-ld --gc-sections -T ./vendor/tlsr825x_smesh/sdk/telink_sig_mesh_sdk/boot.link $O_FILES $LIB_DIRS "-(" $LIBS "-)" -o $ELF
.log/flash.o: In function flash_erase_sector':
flash.c:(.text.flash_erase_sector+0x8): undefined reference to
app_battery_power_check_and_sleep_handle'
.log/flash.o: In function flash_erase_sector_ota':
flash.c:(.text.flash_erase_sector_ota+0x8): undefined reference to
app_battery_power_check_and_sleep_handle'
.log/flash.o: In function flash_write_page':
flash.c:(.text.flash_write_page+0xc): undefined reference to
app_battery_power_check_and_sleep_handle'
.log/flash.o: In function flash_write_page_ota':
flash.c:(.text.flash_write_page_ota+0xc): undefined reference to
app_battery_power_check_and_sleep_handle'
.log/app.o: In function main_loop':
app.c:(.text.main_loop+0x14): undefined reference to
app_battery_power_check_and_sleep_handle'
.log/app.o:app.c:(.text.user_init+0x6): more undefined references to `app_battery_power_check_and_sleep_handle' follow
[o-list] tc32-elf-objdump -x -D -l -S $ELF > $LST
tc32-elf-objdump: '.log/output.elf': No such file
[o-bin] tc32-elf-objcopy -O binary $ELF $OUTPUT/output.bin
tc32-elf-objcopy: '.log/output.elf': No such file
[o-size] tc32-elf-size -t $ELF
tc32-elf-size: '.log/output.elf': No such file
0 0 0 0 0 (TOTALS)
build end, create final fw...
copy ./.log/output.bin -> UG
build fail
Which version of TuyaOS are you using?
Re: firmware corruption
Posted: 2024年 Nov 14日 16:09
by joey_nobug
Add the file "$PROJECT_ROOT/vendor/tlsr825x_smesh/sdk/telink_sig_mesh_sdk/vendor/common/battery_check.c" to the project in the software\TuyaOS\vendor\tlsr825x_smesh\toolchain\templates\vendor.json.
Re: firmware corruption
Posted: 2024年 Nov 14日 18:03
by percy(unwired)
sdk version currently in use is 3.8
it worked able to build without errors with Batt_check_enabled. how do we debug and check if the macro is working and what are the currently set voltage levels at which the macro will be triggered.