This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/EK-TM4C129EXL: CRC-32 with 0x4C11DB7 polynomial

Expert 1660 points
Part Number: EK-TM4C129EXL


Tool/software: Code Composer Studio

I am trying to use the CRC module to calculate the CRC-32 using the polynomial 0x4C11DB7 with EK-TM4C129EXL

I have tried several combinations of seed, bit reversal, endiannes etc. but so far I do not get the same results for the same input data.

//*****************************************************************************
//
// crc32.c - Simple CRC-32 demo
//
// Copyright (c) 2013-2017 Texas Instruments Incorporated.  All rights reserved.
// Software License Agreement
// 
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
// 
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
// 
// This is part of revision 2.1.4.178 of the EK-TM4C129EXL Firmware Package.
//
//*****************************************************************************

#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_ccm.h"
#include "inc/hw_memmap.h"
#include "driverlib/crc.h"
#include "driverlib/debug.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/udma.h"
#include "drivers/pinout.h"
#include "utils/uartstdio.h"

//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>CRC-32 Demo (crc32)</h1>
//!
//! Simple demo showing an CRC-32 operation using the CCM0 module.
//!
//
//*****************************************************************************

//*****************************************************************************
//
// Configuration defines.
//
//*****************************************************************************
        uint32_t g_ui32Result;
        //

        // Random data for generating CRC.
        //
        uint32_t g_ui32RandomData[16] =
        {
         0x8a5f1b22, 0xcb935d29, 0xcc1ac092, 0x5dad8c9e,
         0x6a83b39f, 0x8607dc60, 0xda0ba4d2, 0xf49b0fa2,
         0xaf35d524, 0xffa8001d, 0xbcc931e8, 0x4a2c99ef,
         0x7fa297ab, 0xab943bae, 0x07c61cc4, 0x47c8627d
        };

        int main(void)
        {

           // g_ui32Result=0;
            //
            // Enable the CRC module.
            //
            SysCtlPeripheralEnable(SYSCTL_PERIPH_CCM0);
            //
            // Wait for the CRC module to be ready.
            //
            while(!SysCtlPeripheralReady(SYSCTL_PERIPH_CCM0))
            {
            }
            //
            // Configure the CRC module.
            //



            // CRCConfigSet(EC_BASE, CRC_CFG_INIT_SEED | CRC_CFG_TYPE_P4C11DB7 | CRC_CFG_SIZE_32BIT);
//              CRCConfigSet(CCM0_BASE, CRC_CFG_INIT_SEED | CRC_CFG_RESINV | CRC_CFG_TYPE_P4C11DB7 |
//                           CRC_CFG_OBR | CRC_CFG_IBR | CRC_CFG_SIZE_32BIT);
//            //
            CRCConfigSet(CCM0_BASE, ( CRC_CFG_INIT_SEED | CRC_CFG_RESINV | CRC_CFG_TYPE_P4C11DB7 | CRC_CFG_OBR | CRC_CFG_IBR |
            CRC_CFG_SIZE_32BIT));

            // Set the seed value.This value is the start value for CRC operations. If this value is not written, then the residual seed from
            //  the previous operation is used as the starting value.
            //
            //  CRCSeedSet(EC_BASE, 0x5a5a5a5a);
            //  CRCSeedSet(CCM0_BASE, 0x5a5a5a5a);

              uint32_t seed = 0x5a5a5a5a;
              CRCSeedSet(CCM0_BASE, seed);

            //
            // Process the data and get the result. The result should be
            // 0x75fd6f5c.
            //
            //g_ui32Result = CRCDataProcess(EC_BASE, g_ui32RandomData, 16, false);
              g_ui32Result = CRCDataProcess(CCM0_BASE, g_ui32RandomData, 16, false);

            while(1);

        }











  • Hello Bob,

    the above code was written following the above thread but  The __REV()  function  requires intrinsics.h i tried to find it in google with no success 

  • Using this code, the answer matches the on-line calculator you linked to in your first post:

    //*****************************************************************************
    //
    // Copyright (c) 2019 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    // 
    // Texas Instruments (TI) is supplying this software for use solely and
    // exclusively on TI's microcontroller products. The software is owned by
    // TI and/or its suppliers, and is protected under applicable copyright
    // laws. You may not combine this software with "viral" open-source
    // software in order to form a larger program.
    // 
    // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
    // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
    // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
    // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
    // DAMAGES, FOR ANY REASON WHATSOEVER.
    // 
    //*****************************************************************************
    
    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/crc.h"
    #include "driverlib/sw_crc.h"
    
    const uint8_t buf[] = {'1','2','3','4','5','6','7','8','9'};
    
    volatile uint32_t result;
    
    int
    main(void)
    {
        uint32_t ui32SysClock;
    
        //
        // Run from the PLL at 120 MHz.
        //
        ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN |
                                           SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);
    
        SysCtlPeripheralEnable(SYSCTL_PERIPH_CCM0);
    
        CRCConfigSet(CCM0_BASE, (CRC_CFG_INIT_1 | CRC_CFG_RESINV | CRC_CFG_TYPE_P4C11DB7 | CRC_CFG_OBR |
                CRC_CFG_IBR | CRC_CFG_SIZE_8BIT));
    
        result = CRCDataProcess(CCM0_BASE, (uint32_t *)buf, sizeof(buf), true);
    }
    

  • thanks Bob Crosby

  • my last question is do you know how to swap the result value of CRC

    in this threat swapping was done by The __REV()  function which requires intrinsics.h and it's not available on google

    is there any way to do this

    https://e2e.ti.com/support/microcontrollers/other/f/908/t/552167

  • Are you asking about the code on github? I am no longer to access it. If your question is how to change the byte order of a 32-bit integer, here is a simple function to do that.

    uint32_t swapBytes(uint32_t word)
    {
        uint32_t answer;
    
        answer = (word & 0xFF000000u) >> 24u;
        answer |= (word & 0x00FF0000u) >> 8u;
        answer |= (word & 0x0000FF00u) << 8u;
        answer |= (word & 0x000000FFu) << 24u;
        return answer;
    }