Skip to main content
EThom.3
Senior II
March 23, 2026
Solved

Strange CRC behaviour

  • March 23, 2026
  • 1 reply
  • 59 views

I've got some trouble with the CRC unit in an STM32L475.

At first, I got wrong CRC results, but then it dawned on me that the compiled code didn't force only 8 bits at a time into CRC->DR. So I added what I've used elsewhere, to force the compiler to store only 8 bits in a 32-bit register.

*(__IO uint8_t *)(CRC->DR) = Temp;

Temp is a uint8_t variable. Below, it certainly looks like a single byte is transferred to CRC-DR (strb instruction).

 *(__IO uint8_t *)(CRC->DR) = Temp;
 80013ea:	683b 	ldr	r3, [r7, #0]
 80013ec:	7018 	strb	r0, [r3, #0]

However, after I modified my code that way, it would seem that nothing is calculated at all. No matter how many (non-zero) bytes I throw into CRC->DR, the output just stays at 0.

If I revert back to

CRC->DR = Temp;

at least I get something, albeit an incorrect value as soon as I enter more than one byte.

I initialise the CRC unit like this:

 CRC->POL = 0x04C11DB7;
 CRC->INIT = 0;
 CRC->CR = CRC_CR_RESET;

Is there something blatantly obvious I've missed?

Best answer by waclawek.jan

You need to take *address* (i.e. use the & operator), to be cast and then dereferenced:

*(__IO uint8_t *)&(CRC->DR) = Temp;

JW

1 reply

waclawek.jan
waclawek.janBest answer
Super User
March 23, 2026

You need to take *address* (i.e. use the & operator), to be cast and then dereferenced:

*(__IO uint8_t *)&(CRC->DR) = Temp;

JW

EThom.3
EThom.3Author
Senior II
March 23, 2026

Oh... oops.

Yes, I thought it would be something embarrassingly simple. Thank you @waclawek.jan !