PX4飞控的固件升级可以简单的分为6步,具体如下:
1. 重启飞控
重启飞控,APP发送指令mavlink飞控重启指令, 等待0.5s后进入下一步;
2. 识别bootloader
APP发送“0x21 0x20”,等待飞控反馈“0x12 0x10”,然后进入下一步
3. 擦除原有程序
发送erase指令“0x23 0x20”,等待擦除完成,擦除完成后飞控会返回“0x12 0x10”,擦除一般耗时9s左右;
4. 写入现有程序
读取飞控固件并将其划分成n个252字节长的数据段sq1,sq2,sq3……sqn,最后一帧sqn的长度可能小于252,以实际为准。然后将sq组包成以下packet:
帧头 数据长度 数据 帧尾
0x27 0xfc(最后一帧以实际为准) Sqx(1,2,3….n) 0x20
APP顺序发送packet给飞控,每发送完一个packet需要等待飞控反馈“0x12 0x10”后,再继续发送下一个packet直到发送完所有的packet,然后进入下一步。
5. 确认写入无误(CRC检验)
APP发送“0x29 0x20”查询CRC检验码,飞控会返回:
4个字节的校验码 + 0x12 0x10
APP判断接受的检验码和APP计算出的是否一致来判断是否升级成功。
6. 重启飞控
APP发送“0x30 0x20”重启飞控,飞控回馈“0x12 0x10”。
附:
计算CRC检验码的规则:
// compute CRC of the programmed area
uint32_t sum = 0;
for (unsigned p = 0; p < board_info.fw_size; p += 4) {
uint32_t bytes;
bytes = flash_func_read_word(p);
sum = crc32((uint8_t *)&bytes, sizeof(bytes), sum);
}
CRC32:
static uint32_t crc32(const uint8_t *src, unsigned len, unsigned state)
{
static uint32_t crctab[256];
/* check whether we have generated the CRC table yet */
/* this is much smaller than a static table */
if (crctab[1] == 0) {
for (unsigned i = 0; i < 256; i++) {
uint32_t c = i;
for (unsigned j = 0; j < 8; j++) {
if (c & 1) {
c = 0xedb88320U ^ (c >> 1);
} else {
c = c >> 1;
}
}
crctab[i] = c;
}
}
for (unsigned i = 0; i < len; i++) {
state = crctab[(state ^ src[i]) & 0xff] ^ (state >> 8);
}
return state;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)