 |
Arduino Core for STM32
1.0
|
- Basic example of CRC calculation using append
uint8_t testArray[] = {1,2,3,4,5};
void app(void){
for(int i = 0; i < 4; i++){
}
uint32_t CRC_result =
crc.
append(testArray[4], 0xFF);
while(1){
}
}
*
- Basic example of CRC calculation using compute
uint8_t testArray[] = {1,2,3,4,5};
void app(void){
uint32_t CRC_result =
crc.
compute(testArray, 5, 0x00, 0xFF);
while(1){
}
}
- Basic example of CRC calculation using computeAndWriteToEnd
uint8_t testArray[6] = {1,2,3,4,5};
void app(void){
uint32_t CRC_result2 = testArray[5];
while(1){
}
}
- Basic example of CRC check
uint8_t testArray[6] = {1,2,3,4,5};
void app(void){
bool valid =
crc.
check(testArray, 5, 0x00, 0xFF);
testArray[2] = 12;
bool stillValid =
crc.
check(testArray, 5, 0x00, 0xFF);
while(1){
}
}
- Example of CRC-32 calculation
uint8_t testArray[9] = {1,2,3,4,5};
void app(void){
bool valid =
crc.
check(testArray, 5, 0xFFFFFFFFUL, 0xFFFFFFFFUL);
testArray[2] = 12;
bool stillValid =
crc.
check(testArray, 5, 0xFFFFFFFFUL, 0xFFFFFFFFUL);
while(1){
}
}
- Note
- Those examples works only with c++, but STM32CubeIDE does not allow you to change main.c to main.cpp, so you have to create own c++ file, and include it in main.h. In your cpp file create function, that will be called in main() function. In this case, function name is app() and is called in main() function between tags USER CODE BEGIN 2 and USER CODE END 2.
- See also
- Hardware CRC documentation
-
HardwareCRC
bool setOutputReverse(bool reverse)
Sets, if output CRC data bits will be reversed(reflected) or not.
Definition: HardwareCRC.cpp:491
void reset(uint32_t initValue=DEFAULT_HCRC_INITVAL)
Resets calculation and sets initial value.
Definition: HardwareCRC.cpp:92
uint32_t compute(const uint8_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
Resets and computes CRC value of the whole array.
Definition: HardwareCRC.cpp:255
bool setPolynomial32(uint32_t polynomial=CRC32_POLY)
Sets CRC-32 polynomial.
Definition: HardwareCRC.cpp:63
#define CRC8_POLY
Definition: HardwareCRC.h:119
uint32_t append(const uint8_t data, uint32_t finalXOR=0x00)
Appends another data to previous CRC calculation and calculates new CRC value.
Definition: HardwareCRC.cpp:100
bool setPolynomial8(uint32_t polynomial=CRC8_POLY)
Sets CRC-8 polynomial.
Definition: HardwareCRC.cpp:37
bool setInputReverse(bool reverse)
Sets, if input data bits will be reversed(reflected) or not.
Definition: HardwareCRC.cpp:481
uint32_t computeAndWriteToEnd(uint8_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
Resets, computes CRC value of the whole array and attaches calculated CRC value at the end of the arr...
Definition: HardwareCRC.cpp:270
This file contains class, that provides hardware CRC calculation.
HardwareCRC crc
Definition: HardwareCRC.cpp:539
bool check(const uint8_t *data, uint32_t dataLength, uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
Checks if the array (with CRC attached at the end) is valid.
Definition: HardwareCRC.cpp:354
bool begin()
Enables CRC hardware calculation unit.
Definition: HardwareCRC.cpp:11