cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with CRC unit

Robert Harrison
Associate
Posted on May 10, 2018 at 09:28

STM32L452C

My code:

__HAL_RCC_CRC_CLK_ENABLE();

CRC->POL = (uint32_t) 0x1021;//CRC-16-CCITT

CRC->INIT = (uint32_t) 0xFFFF;

CRC->CR = (uint32_t) 0x09;//REV_OUT = 0, REV_IN = 00, POLYSIZE = 01, RESET = 1

CRC->DR = '1';

CRC->DR = '2';

CRC->DR = '3';

CRC->DR = '4';

The correct result for this CRC is 0x5349 but when I read the DR I get 0xb23b

I have tried all combinations of input and output bit reversal, doesn't work.

4 REPLIES 4
Nesrine M_O
Lead II
Posted on May 10, 2018 at 10:18

Hi

robert.015

,

I recommend you to have a look to CRC examples under the STM32L4 firmware package, it may helpful to start your own project:STM32Cube_FW_L4_V1.0\Projects\NUCLEO-L452RE\Examples\CRC

-Nesrine-

Posted on May 10, 2018 at 10:59

Thanks. I just realised that the cubeMX utility doesn't copy all the HAL drivers to your project dir. I was missing 'stm32l4xx_hal_crc.c' etc.

Posted on May 16, 2018 at 17:55

DR is a 32-bit wide register, you need to write bytes 8-bit wide, thusly...

*((volatile uint8_t *)&CRC->DR) = '1';

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 16, 2018 at 17:48

Could you please  precise the MX version are you using?

if your are using an older version please use the latest one and tell us if the issue still again