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.
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.
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.
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 toapp_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 toapp_battery_power_check_and_sleep_handle'
.log/flash.o: In function flash_write_page':
flash.c:(.text.flash_write_page+0xc): undefined reference toapp_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 toapp_battery_power_check_and_sleep_handle'
.log/app.o: In function main_loop':
app.c:(.text.main_loop+0x14): undefined reference toapp_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
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 toapp_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 toapp_battery_power_check_and_sleep_handle'
.log/flash.o: In function flash_write_page':
flash.c:(.text.flash_write_page+0xc): undefined reference toapp_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 toapp_battery_power_check_and_sleep_handle'
.log/app.o: In function main_loop':
app.c:(.text.main_loop+0x14): undefined reference toapp_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
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.
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.