Skip to main content
danielblesener9
Associate III
June 5, 2018
Solved

Over the Air Update BLE, STM32F2, CRC Always 0?

  • June 5, 2018
  • 5 replies
  • 1566 views
Posted on June 05, 2018 at 17:21

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

    This topic has been closed for replies.
    Best answer by Tesla DeLorean
    Posted on June 14, 2018 at 18:26

    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) Block

    return(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

    5 replies

    Tesla DeLorean
    Guru
    June 5, 2018
    Posted on June 05, 2018 at 20:22

    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.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    danielblesener9
    Associate III
    June 7, 2018
    Posted on June 07, 2018 at 17:17

    Hi Clive, sorry for the late reply. 

    That makes a lot more sense. Thank you for your help.

    danielblesener9
    Associate III
    June 14, 2018
    Posted on June 14, 2018 at 17:06

    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=false