2018-06-05 08:21 AM
I would suggest opening the file attached in notepad++.
Generally speaking the code makes sense. I can get it working without the CRC, which apparently is supposed to equal 0.
Note the following section:
if(psFirmware->ulPage == (psFirmware->ulTotalPages - 1)){
sFirmware.ucRcvdImage = TRUE; //verify FW if(sFirmware.ucUpdateWhat == fwUPDATE_CONSOLE){ ulCRC_Calc = sFirmware.ulFirstWord; sFirmware.ulAddress = UPDATE_IMAGE_ADDRESS+4; size = ((psFirmware->ulTotalPages * 12) /4)-1; }else{ ulCRC_Calc = 0; sFirmware.ulAddress = UPDATE_RADIO_ADDRESS; size = ((psFirmware->ulTotalPages * 12) /4); } for(i = 0x000 ; i < size ; i++){ ulMemoryRead = *(__IO uint32_t*)sFirmware.ulAddress; sFirmware.ulAddress += 4; ulCRC_Calc += ulMemoryRead; //ADD the bits to calculate the checksum } if(1){//ulCRC_Calc == 0){ //verify FW image here if(sFirmware.ucUpdateWhat == fwUPDATE_CONSOLE){ FlashStatus = FLASH_ProgramWord(UPDATE_IMAGE_ADDRESS,sFirmware.ulFirstWord); if(FlashStatus != FLASH_COMPLETE){ while(1); } firmwareUpdateProc(keyFW_RESET); }else{ sFirmware.ulTotalBytes = (psFirmware->ulTotalPages * 12); firmwareUpdateRadio(); } }else{ firmwareEraseUpdateSectors(); NVIC_SystemReset(); } }The code above is saying (if I get rid of the if(1)) that the CRC of the first word, plus all of the words written to flash for the image of the app, should be 0.
I have no clue why this is the case. Is it just standard for the MCU to place a value in the application address that should work this way?
Thank you for your support,
Daniel
Solved! Go to Solution.
2018-06-14 11:26 AM
Ok, so reiterating the mechanics demonstrated here
//****************************************************************************
int main(int argc, char **argv)
{ uint32_t test[] = { 0x11223344, 0xB14257CC };printf('%08X (0xB14257CC) Slow\n',Crc32(0xFFFFFFFF, 0x11223344)); // 0xB14257CC
printf('%08X (0xB14257CC) Fast\n',Crc32Fast(0xFFFFFFFF, 0x11223344)); // 0xB14257CC printf('%08X (0x00000000) Block\n', Crc32FastBlock(0xFFFFFFFF, sizeof(test)/sizeof(uint32_t), test) );// B14257CC (0xB14257CC) Slow
// B14257CC (0xB14257CC) Fast // 00000000 (0x00000000) Blockreturn(0);
}//****************************************************************************
________________ Attachments : stm32tst.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxUt&d=%2Fa%2F0X0000000ayq%2FcEtYjpslan59HlCDfUBXdtWfKhKra.m5tZT0d8CEbaM&asPdf=false2018-06-05 11:22 AM
A CRC is like a long division, you look at the remainder, so if you add the computed CRC on to the end of an image, and then recompute across the new image the values should divide through in an integer fashion leaving a remainder of zero.
So make sure the image being sent is suitably 'signed', with the computed CRC at the end, and a length that includes it.
Not seeing an attachment in the threaded view.
2018-06-07 10:17 AM
Hi Clive, sorry for the late reply.
That makes a lot more sense. Thank you for your help.
2018-06-14 10:06 AM
Hi Clive, what you are saying makes sense. But I am still not getting zero.
I am using .net to add the crc to the beginning of a file I am sending over the air updates via BLE. The over the air updates work if I don't use the CRC...but I am still not getting CRC as zero.
I use the function doCRC to computer the CRC. This has worked for me in the past: (note I attached the source code in the notepad++ file attached to original thread 'net CRC generator'.
Then I add the crc computed value, to the memory that the crc was computed on. I do not get zero. Does anyone see why...??
Thanks much,
D
________________ Attachments : net crc generator.txt.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxUy&d=%2Fa%2F0X0000000ays%2FnyoxRIEUXk2d.FQ69_JX.2b0xvVexcjwQcE5GybX8.k&asPdf=false2018-06-14 10:19 AM
So even if I do something simple like the following:
Dim t(10) As UInt32
For i10 As Integer = 0 To 9 Step 1 t(i10) = i10 Next Dim t_crc As UInt32 = doCRC(t, 10) For i11 As Integer = 0 To 9 Step 1 t_crc = t_crc + t(i11) NextI still do not get 0.
(Do CRC function in the text file attached above).
2018-06-14 11:26 AM
Ok, so reiterating the mechanics demonstrated here
//****************************************************************************
int main(int argc, char **argv)
{ uint32_t test[] = { 0x11223344, 0xB14257CC };printf('%08X (0xB14257CC) Slow\n',Crc32(0xFFFFFFFF, 0x11223344)); // 0xB14257CC
printf('%08X (0xB14257CC) Fast\n',Crc32Fast(0xFFFFFFFF, 0x11223344)); // 0xB14257CC printf('%08X (0x00000000) Block\n', Crc32FastBlock(0xFFFFFFFF, sizeof(test)/sizeof(uint32_t), test) );// B14257CC (0xB14257CC) Slow
// B14257CC (0xB14257CC) Fast // 00000000 (0x00000000) Blockreturn(0);
}//****************************************************************************
________________ Attachments : stm32tst.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxUt&d=%2Fa%2F0X0000000ayq%2FcEtYjpslan59HlCDfUBXdtWfKhKra.m5tZT0d8CEbaM&asPdf=false