cancel
Showing results for 
Search instead for 
Did you mean: 

Strange CRC behaviour

EThom.3
Senior II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
waclawek.jan
Super User

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

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

JW

View solution in original post

2 REPLIES 2
waclawek.jan
Super User

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

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

JW

Oh... oops.

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