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.

MSPM0L1117: Cannot replicate CRC-16 AUG CCIT results on a host MCU

Part Number: MSPM0L1117
Other Parts Discussed in Thread: SYSCONFIG,

Hi E2E Team,

I am attempting to replicate the following CRCP settings from the MSPM0L1117 SysConfig:

image.png

As seen below, when using DL_CRCP_calculateBlock16 with data 0x0002 and size 0x02, the end result is 0x6070:

image.png

I need to replicate these results on a host MCU, but so far I have not been able to find the correct function and settings to make this a reality

#include <stdint.h>
#include <stdio.h>

/**
 * Calculates the CRC-16/AUG-CCITT checksum for a given data buffer.
 *
 * Parameters:
 *   data: Pointer to the input data array.
 *   len: Length of the input data in bytes.
 *
 * Returns:
 *   The calculated 16-bit CRC checksum.
 */
uint16_t crc16_aug_ccitt(const uint8_t *data, size_t len) {
    // Parameters for CRC-16/AUG-CCITT:
    // Polynomial: 0x1021
    // Initial value (seed): 0x0F1D
    // Input data not reflected, output CRC not reflected, no final XOR.
    uint16_t crc = 0x0F1D; 
    uint16_t polynomial = 0x1021;

    for (size_t i = 0; i < len; ++i) {
        crc ^= (uint16_t)(data[i] << 8); // XOR current byte with the high byte of CRC

        for (int j = 0; j < 8; ++j) {
            if (crc & 0x8000) {
                crc = (crc << 1) ^ polynomial;
            } else {
                crc <<= 1;
            }
        }
    }

    return crc; // No final XOR operation
}

int main() {
    //...
    uint8_t input_data[] = {0x00, 0x02};
    size_t data_len = sizeof(input_data);

    uint16_t result = crc16_aug_ccitt(input_data, data_len);

    //...
}

I have attempted different byte orders for both input_data and crc, but so far I have not been able to replicate a result of 0x6070.  Can you please help determine what is incorrect or missing about my algorithm?

Thanks,
Ryan

  • Hi Ryan,

    Firstly the input size of DL_CRCP_calculateBlock16() is the number of 16-bit data, so for {0x00,0x02} input the input for the API need to be 1.

    And as the endianness is set as big end order, you need to change the input data order and CRC seed order such as {0x02, 0x00} and 0x1D0F.

    Actually I recommend to directly change the slave side CRC configuration as little end, so you could get an expected result as your current code and configuration. 

  • Thanks for the help Pengfei!  I'm not too comfortable with altering the peripheral side CRC configuration at the moment.  After taking a break and looking at your response, I was able to amend my c code to get the expected output with the original MSPM0L1117 application.

    #include <stdint.h>
    #include <stdio.h>
    
    /**
     * Calculates the CRC-16/AUG-CCITT checksum for a given data buffer.
     *
     * Parameters:
     *   data: Pointer to the input data array.
     *   len: Length of the input data in bytes.
     *
     * Returns:
     *   The calculated 16-bit CRC checksum.
     */
    uint16_t crc16_aug_ccitt(const uint16_t *data, size_t len) {
        // Parameters for CRC-16/AUG-CCITT:
        // Polynomial: 0x1021
        // Initial value (seed): 0x0F1D (from user input 0xf1d)
        // Input data not reflected, output CRC not reflected, no final XOR.
        uint16_t crc = 0x1D0F; 
        uint16_t polynomial = 0x1021;
    
        for (size_t i = 0; i < len; ++i) {
            crc ^= (uint16_t)(data[i] << 8); // XOR current byte with the high byte of CRC
    
            for (int j = 0; j < 8; ++j) {
                if (crc & 0x8000) {
                    crc = (crc << 1) ^ polynomial;
                } else {
                    crc <<= 1;
                }
            }
        }
    
        return crc; // No final XOR operation
    }
    
    int main() {
        // Input data 0x00000002 represented as a byte array (Big Endian)
        // The most significant byte of the input is processed first.
        uint16_t input_data[] = {0x0000, 0x0002};
        size_t data_len = sizeof(input_data);
    
        uint16_t result = crc16_aug_ccitt(input_data, data_len);
    
        printf("Calculated CRC-16/AUG-CCITT for 0x00000002: 0x%04X\n", result);
    
        return 0;
    }

    This returns 0x6070 which is what I was expecting to receive.  Thanks again for the support!

    Regards,
    Ryan