common setup for python crc (6.1.1) and stm32 hardware CRC unit?

36 Views Asked by At

I'm sending data from python code to stm32g0xx mcu. I'm using stm32 hardware CRC computing unit and https://pypi.org/project/crc/ as the other side. Unfortunately I can't catch the common setup for both sides.

The mcu side is configured in the default way:

            hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;
            hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;
            hcrc.Init.CRCLength = CRC_POLYLENGTH_32B;
            hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;
            hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;
            hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;

On the python side, I'm trying every setup with the same polynomial 0x04C11DB7 (CRC32, BZIP2 and POSIX) but haven't succeeded yet.

Can you please recommend me a better way instead of trying every possible combination?

Thx

1

There are 1 best solutions below

0
ladmanj On

The magic formula for the python code to be compatible with the STM32 default is:

from crc import Calculator, Configuration

config = Configuration(
    width=32,
    polynomial=0x04C11DB7,
    init_value=0xffffffff,
    final_xor_value=0,
    reverse_input=False,
    reverse_output=False,
)

Thanks to @Ilya who confirmed my own thoughts I already had at the time.