Skip to main content
Visitor II
April 15, 2024
Solved

Incorrect CRC value from software and harware SPI CRC

  • April 15, 2024
  • 5 replies
  • 1977 views

Hi, 

In my application, I'm using SPI (SPI1, a full feature set instance) with CRC enabled, on STM32H563ZI, with the configuration as:

WCarey_0-1713170183201.png

I have a CRC implemented based on CCIT standard, which I call 'software CRC'

I see different CRC values for the same bytes of input from the micro and software CRC. 

WCarey_2-1713170893568.png

Fig1. Software CRC which is 0x8B2C (the last 2 bytes shown in Logic Analyzer, with msb first configuration)

WCarey_3-1713170932398.png

Fig2: CRC from ST which is 0x5D0C for the same input.

My software CRC calculation is not wrong and is verified using this calculator (https://crccalc.com/) which yields 0x8B2C.

WCarey_1-1713170240836.png

 

Kindly help in understanding why the 'hardware' CRC is different from 'software'.

 

 

 

    This topic has been closed for replies.
    Best answer by WCarey

    The CRC Polynomial for my software CRC calculation is 0x1021. However, in SPI CRC calculation I had to use 0x11021 to get the same result as software.

    5 replies

    Super User
    April 15, 2024

    It's hard to analyze when the message is long. Try one byte first.

    How exactly is SPI set up (post perhaps read out content of registers) and how exactly do you feed data to it?

    JW

    WCareyAuthor
    Visitor II
    April 18, 2024

    Apologies for the late reply. I could not get the registers content as I'm having trouble viewing the 'Registers Window' in Keil. 

    Here's my SPI configuration.

    WCarey_0-1713427153769.png

     

    WCareyAuthor
    Visitor II
    April 18, 2024

    I have another question. I use HAL_SPi_TransmitReceive_DMA APIs for SPI Tx & Rx i.e during Tx, *pRxData is dummy data and vice versa for Rx. 

    So, I get a CRC error  during Tx as my TransmitReceive API checks for Rx CRC of dummy Rx data. How to handle this?

    Super User
    April 18, 2024

    Sorry, I don't know, I don't have experience with CRC in SPI.

    JW

    WCareyAuthorAnswer
    Visitor II
    April 23, 2024

    The CRC Polynomial for my software CRC calculation is 0x1021. However, in SPI CRC calculation I had to use 0x11021 to get the same result as software.

    Super User
    April 23, 2024

    This is surprising; although the description in RM may hint at it (that description is rather messy).

    Thanks for coming back with the solution.

    JW