Skip to main content
Tesla DeLorean
Guru
February 3, 2014
Question

Programmable CRC peripheral in newer STM32 devices

  • February 3, 2014
  • 6 replies
  • 2967 views
Posted on February 03, 2014 at 03:04

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
    This topic has been closed for replies.

    6 replies

    fauser_gustavo
    Visitor II
    September 30, 2014
    Posted on September 30, 2014 at 21:33

    Hi Clivel,

    Did you get the right anwser on modbus CRC16 using the hardware CRC on STM32F3 ???

    Tesla DeLorean
    Guru
    September 30, 2014
    Posted on October 01, 2014 at 01:02

    Did you get the right answer on modbus CRC16 using the hardware CRC on STM32F3 ???

    Assume that it does and that I provided code that demonstrates such.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    fauser_gustavo
    Visitor II
    October 7, 2014
    Posted on October 07, 2014 at 16:56

    I've made a BIG STUPID mistake kakaakakaka

    But I asked you because I'm using a proprietary hardware and I'm not using the driver functions that ST provide.

    But everything worked well here.

    Thanks for the code.

    dfacchin
    Associate
    April 15, 2016
    Posted on April 15, 2016 at 17:54

    Hi everybody,

    I was testing around the F7 functionalities and the CRC was giving me some headache, searching for a solution I landed here. The code provided by Clive was not working for me, I had to change the function CRC_HardwareBlock to consider the reversal bit order when the buffer is not multiple of 4bytes This is my function

    uint32_t CRC_HardwareBlock(int Size, const uint8_t *Buffer)
    {
    uint32_t data32;
    uint16_t data16;
    uint32_t data8;
    CRC->CR = (CRC->CR&0x9F) | 0x60;
    while(Size >= 4) // Do as much as we can at 32-bits
    {
    data32 = *((uint32_t *)Buffer);
    CRC->DR = data32;
    Buffer += 4;
    Size -= 4;
    }
    CRC->CR = (CRC->CR&0x9F) | 0x40;
    while(Size >= 2) // Perhaps one of these
    {
    *((uint16_t *)&CRC->DR) = *((uint16_t *)Buffer);
    Buffer += 2;
    Size -= 2;
    }
    CRC->CR = (CRC->CR&0x9F) | 0x20; 
    while(Size--) // Perhaps one of these
    *((uint8_t *)&CRC->DR) = *Buffer++;
    return(CRC->DR); // Return final CRC computation
    }

    CRC->CR is overwritten and doesn't care about your initialization I also had problem with the F7 and the optimization, had to compile the code with optimization level 0 in keil.
    Tesla DeLorean
    Guru
    April 15, 2016
    Posted on April 15, 2016 at 19:05

    This would likely remedy the optimization issues

    *((volatile uint16_t *)&CRC->DR) = ...

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    April 15, 2016
    Posted on April 15, 2016 at 19:08

    Can you provide some specific detail of the CRC, polynomial, shift-direction, that has an issue and a couple of test cases for this?

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..