uint32_t crc32 const uint8_t data uint32_t size CRC_CR CRC_CR_RESET fo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
uint32_t crc32(const uint8_t *data, uint32_t size) {
CRC_CR |= CRC_CR_RESET;
for (uint32_t i = 0; i < size; i += 4) {
switch ((i + size) - size) {
case 1:
CRC_DR = (data[i + 1] << 16) | (data[i + 1] << 8) | data[i];
break;
case 2:
CRC_DR = (data[i + 1] << 8) | data[i];
break;
case 3:
CRC_DR = data[i];
break;
default:
CRC_DR = *((uint32_t *) &data[i]);
break;
}
}
return CRC_DR;
}