Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1 147 Ver.1.0.0
influence OTA speed), and modify this timeout duration accordingly via the interface
as shown below.
void bls_ota_setTimeout(u32 timeout_us);// unit: us
3) Valid OTA data are received (first two bytes are 0~0x1000):
Whenever Slave receives one 20-byte OTA data packet, it will first check if the
adr_index equals slave_adr_index plus 1. If not equal, it indicates packet loss and
OTA failure; if equal, the slave_adr_index value is updated.
Then carry out CRC_16 check to the former 18 bytes; if not match, OTA fails; if
match, the 16-byte valid data are written into corresponding addresses of Flash
(ota_program_offset+adr_index*16 ~ ota_program_offset+adr_index*16 + 15).
During Flash writing process, if there’s any error, OTA also fails.
4) “OTA end” command is received (first two bytes are 0xff02):
Check whether adr_max in OTA end packet and the inverted check value are
correct. If yes, the adr_max can be used to double check whether maximum index
value of data received by Slave from Master equals the adr_max in this packet. If
equal, OTA succeeds; if not equal, OTA fails due to packet loss.
After successful OTA, Slave will set the booting flag of the old firmware address in
Flash as 0, set the booting flag of the new firmware address in Flash as 0x4b, then
MCU reboots.
5) Slave provides OTA state callback function:
After Slave starts OTA, MCU will finally reboot regardless of OTA result. If OTA
succeeds, Slave will set flag before rebooting so that MCU executes the new
firmware; if OTA fails, the incorrect new firmware will be erased before rebooting, so
that MCU still executes the old firmare. Before rebooting, user can judge whether the
OTA state callback function is registered and determine whether to trigger it
correspondingly.
typedef void (*ota_resIndicateCb_t)(int result);
enum{
OTA_SUCCESS = 0, //success
OTA_PACKET_LOSS, //lost one or more OTA PDU
OTA_DATA_CRC_ERR, //data CRC err
OTA_WRITE_FLASH_ERR, //write OTA data to Flash ERR
OTA_DATA_UNCOMPLETE, //lost last one or more OTA PDU
OTA_TIMEOUT, //
};
void bls_ota_registerResultIndicateCb
(ota_resIndicateCb_t cb);
The “enum” lists the 6 options for parameter “result”: the first value indicates OTA
success; the other five values indicate reasons for OTA failure. The “result” is mainly