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.

MSPM0G3519: CRC16 not working for mspm0

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

Hello, 

For a project that needs CRC16 calculation, I have tried to get the microcontroller CRC peripheral to do the calculation but it does not work.

I have already tried the CRC32 on the microcontroller and it works just fine.

What could be the problem or is there a sample CRC16 project that I could use as a guide.

Thanks.

  • Hi Abayomi,
    Before answering your question, I'd like to confirm a few details:
    Are you using DriverLib functions or direct register operations? Note that the MSPM0G3519 only supports CRC16-CCITT.
    So please make sure your expected output is based on this standard.
    The most common reason CRC16 doesn't work while CRC32 does is bit order (bit reversal) handling. 
    Thanks.
  • Hi Jasper,

    Thanks for the quick reply.

    I am using the Driver Lib genrated by sysconfig for the CRC operation.  

    The snapshot of the Sysconfig is below:

    I have looked at the impementation but I could not find the problem.

    Is there a crc16 example I could use?

    Thanks

  • Hi Abayomi,

    I verified the CRC-P peripheral on the LP-MSPM0G3519 LaunchPad using the official SDK example and confirmed it works correctly.
    After comparing configurations, the SysConfig settings used in the SDK example are shown in the attached screenshot. I'd recommend adjusting your configuration to match.
    With this configuration, computing CRC on the test data
    {0x1234, 0x5678, 0x9012}
    gives a result of
    0x2C81
    You can use the same data to verify your setup.
    If the issue persists after making the adjustment, please provide the following so I can investigate further:
    Your input data (in hex)
    The actual output value you're getting
    Your expected value and how it was calculated

    Thanks
  • Hi,

    Thanks for the reply.

    I would try it out soon.

    I would like to ask it this would also work when calculating the CRC16 of a flash memory area?  The CRC value of the memroy area has already been calculated from the linker command file.

    Thanks.


  • Hi Abayomi,

    Technically, you can use the CRC-P peripheral to calculate CRC16 over a Flash memory area. I recommend reading the Flash data byte by byte for the calculation.
    The key requirement is that the CRC-P peripheral configuration must exactly match the parameters used in the linker command file, including:
    • Polynomial,
    • Seed (initial value),
    • RefIn / RefOut
    Once these are confirmed to match, the results from both sides should align.
    Thanks.
  • Hi Jasper,

    Thanks.  I tried the proposal but the CRC result still did correspond to the linker generated CRC result.

    The implementation is below

    Linker command file:      

    GROUP
    {
      FLASH_APP               : origin = _APP_START_ADDRESS_, length = 0x00070000 - _APP_START_ADDRESS_ - 0x80
    }crc(_flash_crc_table, algorithm=CRC16_802_15_4)
    }
    Calculation in code:
        uint16_t crc_result = DL_CRCP_calculateMemoryRange16(CRCP0, CRC_SEED, (uint16_t *)p_crc_table->recs[0].addr, 
        (uint16_t *)(p_crc_table->recs[0].addr + p_crc_table->recs[0].size));
    The generated configuration code is below:
    DL_CRCP_setPolynomial(CRCP0, DL_CRCP_CRCPOLY_POLYNOMIAL_16_AUG_CCIT);
        DL_CRCP_init(CRCP0, DL_CRCP_POLYNOMIAL_SIZE_16, DL_CRCP_BIT_NOT_REVERSED,
            DL_CRCP_INPUT_ENDIANESS_BIG_ENDIAN, DL_CRCP_OUTPUT_BYTESWAP_DISABLED);

        DL_CRCP_setSeed16(CRCP0, CRCP_SEED);
    where the CRCP_SEED is  0xF1D
    The configuration using sysconfig is below:
    Where could the problem be.
    Thanks

  • Hi Abayomi,

    Thank you for providing the CRC algorithm information from your Flash - this is very helpful.
    The configuration I shared earlier was based on the SDK example (CRC-16/AUG-CCITT), which was used to verify that the CRC-P peripheral works correctly on the G3519. Since your Flash uses the CRC-16/802.15.4 algorithm, the mismatch is caused by a difference in parameters between the two configurations.
    To match CRC-16/802.15.4, please update the following settings:
    Change Seed to 0x0000
    Change BitOrder to Reversed
    All other parameters can remain unchanged. Please re-verify the result after making these adjustments.

    Thanks.

  • Hi Jasper,

    I worked with the suggestion you gave by the CRC calcution result was not the same a the calculation done by the linker.

    Where can the problem be?

    I have gone thorugh all my implementation and did not discover anything in it.

    Is there an example implementation I can use?

    Thanks.

    Yomi

  • Hello,
    Could you please share your current configuration parameters so I can verify the settings? Specifically, I'd like to confirm the following:
    • Seed is set to
      0x0000
    • BitOrder is set to Reversed
    • ByteOrder is set to Big Endian
    Additionally, could you let me know whether the data length of your Flash calculation region is an odd or even number of bytes? This will help narrow down the issue.
  • Hello Jasper,

    I am enclosing two snapshots for you

    1. sysconfig

    2. The CRC parameters form the linker command file used in the calculation

    From the second picture, you can the the start address and the size of the flash memory that is been computed.

    I expect your feedback.

    Thanks

  • Hi Abayomi,

    I reviewed the source code from driverlib ,the function what you used is defined as 

    uint16_t DL_CRCP_calculateMemoryRange16(
    CRCP_Regs* crcp, uint16_t seed, uint16_t* ptrStart, const uint16_t* ptrEnd)
    {
    DL_CRCP_setSeed16(crcp, seed);

    uint16_t* ptr = ptrStart;

    while (ptr <= ptrEnd) {
    DL_CRCP_feedData16(crcp, (uint16_t) *ptr);
    ptr = ptr + 1;
    }

    return ((uint16_t) DL_CRCP_getResult16(crcp));
    }

    the 4th parameter ptrEnd is inclusive, meaning the function will calculate up to and including that address.

    However, in your current code:

    The ptrEnd you passed points one address beyond the last valid byte, which causes the function to calculate 2 extra bytes beyond your intended region, resulting in a CRC mismatch with the linker-generated value.
    Please update as follows:
    DL_CRCP_calculateMemoryRange16(
        CRCP0, CRC_SEED,
        (uint16_t *)p_crc_table->recs[0].addr,
        (uint16_t *)(p_crc_table->recs[0].addr + p_crc_table->recs[0].size - 2)  // last valid 16-bit word
    );

    Additionally, I have one more question to verify: Does your Flash region defined in the linker include the memory area where the CRC value itself is stored?
    Thanks.