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.

AM2634: How to perform CRC operation in AM2634 MCU?

Part Number: AM2634
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

Hi teams

i am using the AM2634 MCU, i have few questions.

1. How to do CRC calculation of the Whole flash memory of this MCU? can you mention the way?

2. where is the Linker File present in this MCU I can't able to find the file? 

3. Can you say the way how to perform the CRC calculation of the whole flash memory and how to verify?

  • 1. How to do CRC calculation of the Whole flash memory of this MCU? can you mention the way?

    There is no onboard flash memory on this MCU. I suspect you mean a CRC calculation of the program code. You need to find the start and end address of .text section in your map file then perform the CRC on that range or ranges. To do a CRC32 calculation, see this thread: https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1410470/am2634-how-to-calculate-the-crc-in-am2634

    2. where is the Linker File present in this MCU I can't able to find the file? 

    If you're using examples, the linker script linker.cmd is generated automatically by SYSCONFIG and output to .\Debug\syscfg\linker.cmd.

    3. Can you say the way how to perform the CRC calculation of the whole flash memory and how to verify?

    Same as question 1 isn't it?

  • Hi Kier,

    Thank you for your replay,

    1. My requirement is not to use the example code which you provided in the sdk.

        so here i created the crc function of my own in that i need to find the crc by using my function

        below i attached my sample code to calculate crc,

    uint32_t CRC32Calculate(const uint8_t* data, uint32_t length, const st_CRC32_param* ptrParam)
    {
        uint32_t result;
        uint8_t buffer;
        if ((length != EMPTY_BUFFER) && (ptrParam->polynomial != EMPTY_BUFFER)) // Checking if data is valid
        {
            uint32_t crc = ptrParam->initial;
            for (uint32_t i = 0U; i < length; i++)
            {
    
    
                // Use reflection based on RefelectDataFlag
                if ((ptrParam->RefelectDataFlag) != 0U)
                {
                    buffer = (uint8_t)ReverseBits(data[i], BYTES_BY_BYTES); // Reflect data
                }
                else
                {
                    buffer = data[i]; // No reflection
                }
    
                // XOR buffer with the relevant bits of the current CRC
                buffer ^= (uint8_t)(crc >> (WIDTH - BYTES_BY_BYTES)); // Explicit cast to 8-bit
    
                // Update CRC using the lookup table and polynomial
                crc = CRCTableCreation[buffer] ^ (crc << BYTES_BY_BYTES);
            }
    
            // Use reflection for the final CRC value based on RefelectRemainderFlag
            if ((ptrParam->RefelectRemainderFlag != 0U)) // Explicit boolean condition
            {
                result = (ReverseBits(crc, WIDTH) ^ ptrParam->finalXor); // Reflect final CRC
            }
            else
            {
                result = (crc ^ ptrParam->finalXor); // No reflection
            }
        }
        else
        {
            result = 0U; // RESULT 0 for invalid input
        }
        return result;
    }
    
    
    
    



    so here i need to calculate the CRC for the whole flash memory and we need to implement with out using  sdk provided examples.


    2. i have an approach let suppose we know the flash address starting from  FLASH : ORIGIN = 0x60100000 , LENGTH = 0x80000
    so can i directly use this address as 

    #define FLASH_START_ADDR 0x60100000
    #define FLASH_SIZE 0x80000

    // Calculate CRC32 of flash data
    uint32_t crcResult = CRC32Calculate(flashData, FLASH_SIZE, &crcParams);

    can i do like this? 

  • Hi Kier,

    Thank you for your replay,

    1. My requirement is not to use the example code which you provided in the sdk.

        so here i created the crc function of my own in that i need to find the crc by using my function

        below i attached my sample code to calculate crc,

    uint32_t CRC32Calculate(const uint8_t* data, uint32_t length, const st_CRC32_param* ptrParam)
    {
        uint32_t result;
        uint8_t buffer;
        if ((length != EMPTY_BUFFER) && (ptrParam->polynomial != EMPTY_BUFFER)) // Checking if data is valid
        {
            uint32_t crc = ptrParam->initial;
            for (uint32_t i = 0U; i < length; i++)
            {
    
    
                // Use reflection based on RefelectDataFlag
                if ((ptrParam->RefelectDataFlag) != 0U)
                {
                    buffer = (uint8_t)ReverseBits(data[i], BYTES_BY_BYTES); // Reflect data
                }
                else
                {
                    buffer = data[i]; // No reflection
                }
    
                // XOR buffer with the relevant bits of the current CRC
                buffer ^= (uint8_t)(crc >> (WIDTH - BYTES_BY_BYTES)); // Explicit cast to 8-bit
    
                // Update CRC using the lookup table and polynomial
                crc = CRCTableCreation[buffer] ^ (crc << BYTES_BY_BYTES);
            }
    
            // Use reflection for the final CRC value based on RefelectRemainderFlag
            if ((ptrParam->RefelectRemainderFlag != 0U)) // Explicit boolean condition
            {
                result = (ReverseBits(crc, WIDTH) ^ ptrParam->finalXor); // Reflect final CRC
            }
            else
            {
                result = (crc ^ ptrParam->finalXor); // No reflection
            }
        }
        else
        {
            result = 0U; // RESULT 0 for invalid input
        }
        return result;
    }
    
    
    
    



    so here i need to calculate the CRC for the whole flash memory and we need to implement with out using  sdk provided examples.


    2. i have an approach let suppose we know the flash address starting from  FLASH : ORIGIN = 0x60100000 , LENGTH = 0x80000
    so can i directly use this address as 

    #define FLASH_START_ADDR 0x60100000
    #define FLASH_SIZE 0x80000

    // Calculate CRC32 of flash data
    uint32_t crcResult = CRC32Calculate(flashData, FLASH_SIZE, &crcParams);

    can i do like this? 

  • Yes, you can use your own code to calculate the CRC. 

    Compared with the software solution, the MCRC has faster CRC calculation without extra memory usage and additional CPU load. The MCRC is implemented with a Linear Feedback Shift Register (LFSR) to generate a CRC of the data. The CPU can directly feed data into the MCRC module, which is useful for calculating the CRC of an outgoing data-stream or for verifying an incoming data-stream for transmission errors.

    You can write a simple function to calculate CRC using MCRC. For example:

    #define MCRC_CTRL0   (*(volatile uint32 *)0x35000000U)
    #define MCRC_CTRL2   (*(volatile uint32 *)0x35000010U)
    #define MCRC_STATUS      (*(volatile uint32 *)0x35000028U)
    #define MCRC_SIGREGL1  (*(volatile uint32 *)0x35000060U)
    #define MCRC_SIGREGH1 (*(volatile uint32 *)0x35000064U)
    #define MCRC_SIGREG     (*(volatile uint64 *)0x35000060U)


    crc_calculate(uint64_t startAddr, uint32_t count)

    {

        volatile uint32 index = 0u; 

        MCRC_CTRL0 |= 0x00000001U;          /* Reset the CRC Module */
        MCRC_CTRL0 &= 0xFFFFFFFEU;
        MCRC_CTRL2 |= 0x00000003U;          /* Configure to Full CPU Mode */

        for (index=0u; index < count; index++)

        {
              MCRC_SIGREG = (uint64)(*startAddr);
              startAddr++;
        }

        return (MCRC_SIGREG);

    }

  • Hi QJ Wang,

    Thank You for your replay so, i tried your logic in GPIO LED code i just replaced your logic i attached the code below.

    what are ever we flash it will load into the RAM memory so i consider  OCRAM : ORIGIN = 0x70040000 , LENGTH = 0x40000 this one


    #include <drivers/gpio.h>
    #include <kernel/dpl/AddrTranslateP.h>
    #include <kernel/dpl/DebugP.h>
    #include <kernel/dpl/ClockP.h>
    #include "ti_drivers_config.h"
    #include "ti_drivers_open_close.h"
    #include "ti_board_open_close.h"
    #include <sdl/sdl_mcrc.h>
    #include <stdint.h>
    
    #define MCRC_CTRL0   (*(volatile uint32_t *)0x35000000U)
    #define MCRC_CTRL2   (*(volatile uint32_t *)0x35000010U)
    #define MCRC_STATUS      (*(volatile uint32_t *)0x35000028U)
    #define MCRC_SIGREGL1  (*(volatile uint32_t *)0x35000060U)
    #define MCRC_SIGREGH1 (*(volatile uint32_t *)0x35000064U)
    #define MCRC_SIGREG     (*(volatile uint64_t *)0x35000060U)
    
    /* Function to calculate CRC */
    uint32_t crc_calculate(uint64_t startAddr, uint32_t count)
    {
        volatile uint32_t index = 0u;
    
        MCRC_CTRL0 |= 0x00000001U;          /* Reset the CRC Module */
        MCRC_CTRL0 &= 0xFFFFFFFEU;
        MCRC_CTRL2 |= 0x00000003U;          /* Configure to Full CPU Mode */
    
        for (index = 0u; index < count; index++)
        {
            MCRC_SIGREG = *(volatile uint64_t *)startAddr;
            startAddr += sizeof(uint64_t);  // Increment by the size of uint64_t
        }
    
        return (uint32_t)(MCRC_SIGREG);      // Return lower 32 bits of the CRC
    }
    
    void gpio_led_blink_main(void *args)
    {
        /* Open drivers to open the UART driver for console */
        Drivers_open();
        Board_driversOpen();
    
        DebugP_log("Test Started ...\r\n");
    
        uint64_t startAddr = 0x70040000;  // Starting address in OCRAM
        uint32_t count = 0x40000 / sizeof(uint64_t);  // Number of 64-bit words to read
        uint32_t CRC = crc_calculate(startAddr, count);
        DebugP_log("CRC value is %0XX\r\n", CRC);
    
        DebugP_log("All tests have passed!!\r\n");
    
        Board_driversClose();
        Drivers_close();
    }
    

    I got the value can you just verify this logic if is ok?

    Below is my output.

    Here, i have the doupt i need a tool or external software or inbuild software to do CRC32 calculation....and in that tool i need to test my Flash Address or Ram address in the run time and i need to check the both the implementation is right or wrong?

    kindly provide the solution, Thank you.

  • Hi,

    The MCRC on AM263x supports CRC-16, CRC-32, and CRC-64. The CRC type is selected by the config value in MCRC_CTRL0[4:3] for CH1 and MCRC_CTRL0[12:11] for CH2.

    You need to write your own SW code to calculate the CRC using CRC-32 polynomial:

    CRC32: f(x) = x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1