cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert polynomial number to good value

Pilous Droip
Senior

I have polynomial for CRC 0x8C. And in STM I must write 0x31, because it is rotate.

But I don't know, how to convert this value to good value.

In binary:

0x8C - 0b10001100

0x31 - 0b00110001

I create function:

uint8_t ror8_polynomial(uint8_t poly, uint8_t count)
{
	return (poly << count) | (poly >> (8 - count));
}

And I call this function:

uint8_t test = MP_STM32F7_CRC__rol8_polynomial(0x8C, 6);

My new value is: 0x23 - 0b00100011

Any idea, what is wrong?

4 REPLIES 4
AvaTar
Lead

> But I don't know, how to convert this value to good value.

Not sure what you mean with "good value".

But your question is IMHO purely about C language, and not STM32-specific. So general C tutorials should apply. especially the sections about data types, numerical literals, and the preprocessor.

There are many variants to how CRC is exactly performed - direction of shift (combined with endianness issues), "direct" or "nondirect" form, initial value - and combinations of these. If you have one form as "standard" (usually prescribed by some standard or given by some existing implementation) and you want to use other form because it's "available" in hardware (i.e. STM32's CRC unit here), the polynomial (and also input and output data) might need to be transformed, but the exact form of that transformation depends on the many details of both the "standard" and "available" form.

What I want to say is, that maybe you want to mirror the poly, not to rotate. Or maybe do some other transformation. You gave as too little information (and even if you'd give us more, it's unlikely anybody is willing to do the tedious analysis for you).

JW

>>What I want to say is, that maybe you want to mirror the poly, not to rotate.

Exactly, you're trying to account for the STM32 implementation shift in the other direction.

Basically a BITREV type operation. I've posted examples to the forum before.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pilous Droip
Senior

I'm sorry. I didn't see mirror.... :grinning_face: It is a stupid mistake....

Here is solution.