AnsweredAssumed Answered

Wrong CRC calculation with optimized code

Question asked by obid.matic on Feb 16, 2016
Latest reply on Feb 24, 2016 by obid.matic
Hi.

I encountered a problem where I use CRC hardware with optimized code in Keil. I use CRC hardware inside of interrupt routine and without optimization I get correct result. But if I turn optimization on (level 1 is enough) I don't get correct result anymore. Do you have any idea what could be wrong here?

Before calculation (already inside of ISR) I reset CRC and then do 6 consecutive writes to DR register. First I write a half-word and after that five writes of a byte variable from an array. Then I store a result to new 8-bit variable:

*(uint16_t *)&CRC->DR = half_word_var;
*(uint8_t *)&CRC->DR = byte_array[0];
*(uint8_t *)&CRC->DR = byte_array[1];
*(uint8_t *)&CRC->DR = byte_array[2];
*(uint8_t *)&CRC->DR = byte_array[3];
*(uint8_t *)&CRC->DR = byte_array[4];
*(uint8_t *)&CRC->DR = byte_array[5];

byte_result = (uint8_t)CRC->DR;

Outcomes