1. 程式人生 > 其它 >MCU OTA升級流程

MCU OTA升級流程

升級APP

Upper Lower 獲取整個韌體包的長度、CRC32資訊(HEX 8位元組) 通訊檔案:driver.txt {"OTA_MCU":{"APP":{"get":["length","CRC32","version"]}}}\r {"OTA_MCU":{"APP":{"get":{"length":%d,"CRC32":"%s","version":"%s"}}}}\r
上位機由CRC32值判斷是否要更新韌體 傳送指令,使下位機至Bootloader程式 {"OTA_MCU":{"start":"Bootloader"}}\r 下位機切換到Bootloader程式,通訊檔案:boot.txt 傳送整個韌體包的長度、CRC32資訊(HEX 8位元組) {"OTA_MCU":{"APP":{"set":{"length":%d,"CRC32":"%s","version":"%s"}}}}\r
{"OTA_MCU":{"APP":{"set":{"length":%d,"CRC32":"%s","version":"%s"}}}}\r 開始對韌體分包,依次下發資料包(Base64編碼前,單次傳輸韌體包長度最大2048Byte) {"OTA_MCU":{"APP":{"updata":{"offset":%d,"length":%d,"CRC32":"%s","data":"%s(base64編碼)"}}}}\r
{"OTA_MCU":{"APP":{"updata":{"offset":%d,"length":%d,"CRC32":"%s"("data"不回覆,減輕通道壓力)}}}}\r ...... 獲取整個韌體包的長度、CRC32資訊(HEX 8位元組),上位機由CRC32值判斷韌體是否更新成功 {"OTA_MCU":{"APP":{"get":["length","CRC32","version"]}}}\r {"OTA_MCU":{"APP":{"get":{"length":%d,"CRC32":"%s","version":"%s"}}}}\r 傳送指令,使下位機至APP程式 {"OTA_MCU":{"start":"APP"}}\r 下位機切換到APP程式,通訊檔案:driver.txt Upper Lower

升級Bootloader

Upper Lower 獲取整個韌體包的長度、CRC32資訊(HEX 8位元組) 通訊檔案:driver.txt {"OTA_MCU":{"Bootloader":{"get":["length","CRC32","version"]}}}\r {"OTA_MCU":{"Bootloader":{"get":{"length":%d,"CRC32":"%s","version":"%s"}}}}\r 上位機由CRC32值判斷是否要更新韌體 傳送整個韌體包的長度、CRC32資訊(HEX 8位元組) {"OTA_MCU":{"Bootloader":{"set":{"length":%d,"CRC32":"%s","version":"%s"}}}}\r {"OTA_MCU":{"Bootloader":{"set":{"length":%d,"CRC32":"%s","version":"%s"}}}}\r 開始對韌體分包,依次下發資料包(Base64編碼前,單次傳輸韌體包長度最大2048Byte) {"OTA_MCU":{"Bootloader":{"updata":{"offset":%d,"length":%d,"CRC32":"%s","data":"%s(base64編碼)"}}}}\r {"OTA_MCU":{"Bootloader":{"updata":{"offset":%d,"length":%d,"CRC32":"%s"("data"不回覆,減輕通道壓力)}}}}\r ...... 獲取整個韌體包的長度、CRC32資訊(HEX 8位元組),上位機由CRC32值判斷韌體是否更新成功 {"OTA_MCU":{"Bootloader":{"get":["length","CRC32","version"]}}}\r {"OTA_MCU":{"Bootloader":{"get":{"length":%d,"CRC32":"%s","version":"%s"}}}}\r Upper Lower

CRC32原始碼計算

: CRC-32使用MPEG_2多項式:0x04C11DB7

uint32_t uiCRC32_MPEG2(uint32_t *puiInitCRC, uint8_t *pucDataBuff, uint32_t uiLength)
{
    uint32_t uiPolynomial = 0x04C11DB7, uiInputCRC = 0xFFFFFFFF, i = 0;
    uint8_t ucMask = 0;

    if(puiInitCRC != NULL)
        uiInputCRC = *puiInitCRC;

    for(i = 0; i < uiLength; ++i)
    {
        uiInputCRC ^= (uint32_t)(*pucDataBuff++) << 24;

        for(ucMask = 1; ucMask; ucMask <<= 1)
        {
            if(uiInputCRC & 0x80000000)
                uiInputCRC = (uiInputCRC << 1) ^ uiPolynomial;
            else
                uiInputCRC <<= 1;
        }
    }

    return uiInputCRC;
}