STM8S + Cosmic compiler = CRC calculation problems

Discussion created by kuczek.krzysztof.001 on Apr 8, 2017
Latest reply on Apr 12, 2017 by Clive One


I got strange problems with CRC calculation. It simply works in "different" way that the same code running on win32 or msp430 emulator.


there is a function generated by pycrc script.


typedef uint16_t crc_t;
crc_t crc_update(crc_t crc, const void *data, size_t data_len)
const unsigned char *d = (const unsigned char *)data;
unsigned int i;
bool bit;
unsigned char c;

while (data_len--) {
c = *d++;
for (i = 0x01; i & 0xff; i <<= 1) {
bit = crc & 0x8000;
if (c & i) {
bit = !bit;
crc <<= 1;
if (bit) {
crc ^= 0x8005;
crc &= 0xffff;
return crc & 0xffff;


And i use it to calculate crc of the data stored in eeprom memory

For debuging purpose i created additional crcDef to track crc_update return values. The "settings" structure is filled by zeros (eeprom is empty).


uint16_t calcCrc, crcDef;
calcCrc = crc_init();
calcCrc = crc_update(calcCrc, &defaultSettings, sizeof(defaultSettings));
 crcDef = calcCrc;
 calcCrc = crc_update(calcCrc, &settings, sizeof(settings));
 sprintf(buff, "defCrc=%d caclcrc=%d \n\r", crcDef, calcCrc );


The result is like following

defCrc=20076 caclcrc=0


It means that second crc_update call does not take calcCrc value under consideration.


Do you have idea what I'm doing wrong. The same coding is working pretty well on win32 or msp430 platform.

Thank you in advance