Skip to main content
Visitor II
November 25, 2024
Question

SPI CRC via DMA dosen't work

  • November 25, 2024
  • 3 replies
  • 1985 views

Dear ST,

 

I use STM32F777 and try to receive SPI Data as a slave via SPI DMA. That works only pretty fine, when I don't activate the CRC Checksum calculation. I receive after the DMA threshold the expected data, but when I set: 

.CRCCalculation = SPI_CRCCALCULATION_ENABLE, 
The received data traped in a Error Callback from the SPI, always.
 
All my init values of the SPI are vaild, look like here:
.SPI_CONFIG = {.Mode = SPI_MODE_SLAVE,
                                                             .Direction = SPI_DIRECTION_2LINES_RXONLY,
                                                             .DataSize = SPI_DATASIZE_8BIT,
                                                             .CLKPolarity = SPI_POLARITY_LOW, // => CPOL = 1
                                                             .CLKPhase = SPI_PHASE_2EDGE, //=> CPHA = 0
                                                             .NSS =  SPI_NSS_SOFT, //SPI_NSS_HARD_INPUT,
                                                             .BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2,
                                                             .FirstBit = SPI_FIRSTBIT_MSB,
                                                             .TIMode = SPI_TIMODE_DISABLE,
                                                             .CRCCalculation = SPI_CRCCALCULATION_ENABLE, // ToDo activate CRC
                                                             .CRCPolynomial = CRC16_CCIT_ZERO, // ToDo activate CRC
                                                             .CRCLength =   SPI_CRC_LENGTH_16BIT,//, //ToDo activate CRC
                                                             .NSSPMode = SPI_NSS_PULSE_DISABLE},

Poly is 0x1021

Inti value is 0x0000

 

If I use the CRC HW Unit via SW, that works as well. But I still have to use the combination of DMA and CRC, because that part is on our application, very time critical. I still can not use the CPU instead.

    This topic has been closed for replies.

    3 replies

    Super User
    November 25, 2024

    Disclaimer: I've never used the CRC facility in STM32 SPI.

    > The received data traped in a Error Callback from the SPI, always.

    What is "Error Callback from the SPI"?

    Do you use some "library"? Which one? How? Why? Did you try your own code with possibly better control?

    Have you tried using polled implementation?

    > Dear ST,

    While this forum is monitored by ST, it's primarily user-driven.

    JW

    UlfSAuthor
    Visitor II
    November 25, 2024

    Hi JW,

     

    ErrorCallBack is: 

    HAL_SPI_ErrorCallback()
     
    Do you use some "library"? Which one?
    STM32F7xx_HAL_Driver
    Files include:
    stm32f7xx_hal_crc.c
    stm32f7xx_hal_spi.c
     
    > Did you try your own code with possibly better control?
    Yes and no, we use from ecomatic a layer on top, to deal with all possible transmission-ways like: Transmit Only / Receive Only, TransmitReceive and Error.  But this works!
    The part which dosent work is located deeper in the HAL lib from ST. Because the Error happens after I trigger the DMA request, to wait till x Bytes are received. After receiving, a ITR will called which works without CRC Enable. 
    The SPI Master is an FPGA which send these Data till the end with a 16bit CRC checksum.
    When I read the Register SPI DR from CRC HW unit, the 16bit value is completly different as I expected from the crc of the FPGA. 
    Again, When I use instead the internal HW CRC in SW, initialize it, the CRC calculation is correct?!
    But I can use the HW Unit in SW, unfortunate I dont have this time, these must be calculate during the DMA is receiving datas.
     
    >Have you tried using polled implementation?
    No, is not really a solution for me. When the DMA + CRC calculation is finish, a ITR should be raised (Callback).
     
    Did you have a idea?
     
    Thanks again
    Ulf
    Super User
    November 25, 2024

    So, the problem is, that CRC calculated by the SPI unit does not match CRC calculated by FPGA, correct?

    Can you give a couple of examples?

    JW

    Super User
    November 26, 2024

    I'm confused: are you talking about the CRC module or about the CRC feature of SPI module?

    In the latter case, you'd be presumably looking at the content of SPIx_RXCRCR.

    Using DMA may be tricky: the CRC feature in SPI apparently assumes, that master actually transmits the CRC after data.

    JW

    UlfSAuthor
    Visitor II
    November 26, 2024

    Jan the Master send the CRC 16bit in the data end. I need to use the CRC on the SPI with DMA. 

    x 8 bit data Input

    16 bit crc output. See example above.

    This fails all the time in a SPI Error, because the SPI Errocode shows me 0x2

    UlfSAuthor
    Visitor II
    February 14, 2025

    Any updates regarding that problem? The problem is still not solved and need attention from STM.

    Graduate II
    May 12, 2025

    The CRC is NOT going to be in the DR, the DR is 8-bit in your configuration.

    If you're sending the data with the CRC, you send the data payload, and then once that is gone you read the TX CRC register, and send that.

    The way you're describing it you sound like you want to receive four bytes and respond with the CRC.

    In the receive sense, I'd expect you'd have to receive SIX bytes, and then the CRC will ZERO out

    If you sent the 0xA5 0xA6 0x8C 0x00 0x07 0xFA pattern, the CRC correct check being the bit that checks RX CRC==0

    I agree that the CRC16 for 4-byte MSB First should be 0x07,0xFA

    ST should probably provide the validated test cases, I'm not invested to build a complete example