2026-03-23 1:03 AM
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?
Solved! Go to Solution.
2026-03-23 3:25 AM
You need to take *address* (i.e. use the & operator), to be cast and then dereferenced:
*(__IO uint8_t *)&(CRC->DR) = Temp;JW
2026-03-23 3:25 AM
You need to take *address* (i.e. use the & operator), to be cast and then dereferenced:
*(__IO uint8_t *)&(CRC->DR) = Temp;JW
2026-03-23 3:28 AM
Oh... oops.
Yes, I thought it would be something embarrassingly simple. Thank you @waclawek.jan !