FreeRTOS TCP/IP stack: question about order of packets when sending file

heinbali01 wrote on Friday, February 27, 2015:

Admittedly, they are not proper CRCs, but just the same type
as a normal Intel hex file.

It is firmware, any wrong bit may make your device unreachable for all further upgrades :slight_smile:

Here is a safe one that I recently wrote:

static portINLINE void vInitialiseCrc32( uint32_t *pulCRC32 )
{
    *pulCRC32 = ~0ul;
}

void vCalculateCrc32( const uint8_t *ucData, int iLength, uint32_t *pulCRC32 )
{
unsigned uBitNr;
const uint32_t ulPolynomial = 0xEDB88320;
const uint8_t *pucCurrent = ucData;
const uint8_t *pucLast = pucCurrent + iLength;
uint32_t ulCRC32 = *pulCRC32;

    /* Calculate  normal CRC32 */
    while( pucCurrent < pucLast )
    {
        ulCRC32 ^= *( pucCurrent++ );
        for( uBitNr = 0; uBitNr < 8u; uBitNr++ )
        {
            if( ( ulCRC32 & 1 ) != 0 )
            {
                ulCRC32 = ( ulCRC32 >> 1 ) ^ ulPolynomial;
            }
            else
            {
                ulCRC32 >>= 1;
            }
        }
    }
    /* Copy it back to the parameter */
    *pulCRC32 = ulCRC32;
}

Regards.