Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect CRC32 on STM32F429 #585

Closed
xobs opened this issue Feb 7, 2024 · 1 comment · Fixed by renode/renode-infrastructure#97
Closed

Incorrect CRC32 on STM32F429 #585

xobs opened this issue Feb 7, 2024 · 1 comment · Fixed by renode/renode-infrastructure#97

Comments

@xobs
Copy link
Contributor

xobs commented Feb 7, 2024

Description

I'm seeing what I believe is an incorrect CRC32 calculation on an STM32F429. I can't explain why this would be, except perhaps that they use the reflected version when providing the CRC to the user.

Expected behaviour

I'm working on understanding a binary firmware. It contains this code:

  Peripherals::CRC.CR = 1;
  Peripherals::CRC.DR = 0xf407a5c2;
  uVar1 = Peripherals::CRC.DR;
  if (uVar1 != 0xb5e8b5cd) {
    do {
                    /* WARNING: Do nothing block with infinite loop */
    } while( true );
  }

With the current implementation of STM32F4_CRC, the resulting value is 0x74EA5CA6. If I instead reflect both the inputs and the outputs, I get the matching value of 0xb5e8b5cd:

            crc = new CRCEngine(CRCPolynomial.CRC32, init: 0xFFFFFFFF, xorOutput: 0, reflectInput: true, reflectOutput: true);

Additional information

I can verify that the output of https://github.com/dimmykar/stm32-crc32-calculator matches what I see -- namely that the CRC32 of 0xF407A5C2 should evaluate to 0xb5e8b5cd.

Has this ever been validated against real hardware? If so, something isn't quite adding up. If not, then it can be fixed in the model.

Do you plan to address this issue and file a PR?

It's an easy enough fix, but if there is hardware and tests that already use the existing behaviour then I'd rather not touch it and keep using my modified model.

xobs added a commit to xobs/renode-infrastructure that referenced this issue Feb 16, 2024
The STM32F4 CRC engine uses the MPEG2 polynomial and configuration. This
is different from most other CRC engines, and is somewhat surprising.

This patch fixes renode/renode#585

Signed-off-by: Sean Cross <sean@xobs.io>
RenodeBot pushed a commit to antmicro/renode that referenced this issue Mar 22, 2024
The STM32F4 CRC engine uses the MPEG2 polynomial and configuration. This
is different from most other CRC engines, and is somewhat surprising.

This patch fixes renode#585
@mszprejda
Copy link
Contributor

The fix from renode/renode-infrastructure#97 is merged. Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants