 |
Arduino Core for STM32
1.0
|
Go to the documentation of this file.
15 #ifndef HARDWARECRC_H_
16 #define HARDWARECRC_H_
21 #if defined(STM32F030x6)
22 #define CRC_CUST_POLY (0x0)
23 #define CRC_IO_REV_SUPP (0x1)
24 #define CRC_CUST_INIT_VAL (0x1)
25 #define CRC_CALC_DELAY //Nothing
27 #elif defined(STM32F070x6)
28 #define CRC_CUST_POLY (0x1)
29 #define CRC_IO_REV_SUPP (0x1)
30 #define CRC_CUST_INIT_VAL (0x1)
31 #define CRC_CALC_DELAY //Nothing
33 #elif defined(STM32F070xB)
34 #define CRC_CUST_POLY (0x1)
35 #define CRC_IO_REV_SUPP (0x1)
36 #define CRC_CUST_INIT_VAL (0x1)
37 #define CRC_CALC_DELAY //Nothing
39 #elif defined(STM32F031x6)
40 #define CRC_CUST_POLY (0x0)
41 #define CRC_IO_REV_SUPP (0x1)
42 #define CRC_CUST_INIT_VAL (0x1)
43 #define CRC_CALC_DELAY //Nothing
45 #elif defined(STM32F103xB)
46 #define CRC_CUST_POLY (0x0)
47 #define CRC_IO_REV_SUPP (0x0)
48 #define CRC_CUST_INIT_VAL (0x0)
49 #define CRC_CALC_DELAY asm("nop"); //Wait 1 tick for every one calculated byte
51 #elif defined(STM32L031xx)
52 #define CRC_CUST_POLY (0x1)
53 #define CRC_IO_REV_SUPP (0x1)
54 #define CRC_CUST_INIT_VAL (0x1)
55 #define CRC_CALC_DELAY //Nothing
57 #elif defined(STM32L432xx)
58 #define CRC_CUST_POLY (0x1) //Custom polynomial supported
59 #define CRC_IO_REV_SUPP (0x1) //Input / output reverse (reflection)supported
60 #define CRC_CUST_INIT_VAL (0x1) //Custom init value supported
61 #define CRC_CALC_DELAY //Nothing
64 #error "This library does not supports selected MCU." //This is here only, because some methods may not works with that chip.
76 #define CRC_X0 (0x01UL)
77 #define CRC_X1 (0x01UL << 1U)
78 #define CRC_X2 (0x01UL << 2U)
79 #define CRC_X3 (0x01UL << 3U)
80 #define CRC_X4 (0x01UL << 4U)
81 #define CRC_X5 (0x01UL << 5U)
82 #define CRC_X6 (0x01UL << 6U)
83 #define CRC_X7 (0x01UL << 7U)
84 #define CRC_X8 (0x01UL << 8U)
85 #define CRC_X9 (0x01UL << 9U)
86 #define CRC_X10 (0x01UL << 10U)
87 #define CRC_X11 (0x01UL << 11U)
88 #define CRC_X12 (0x01UL << 12U)
89 #define CRC_X13 (0x01UL << 13U)
90 #define CRC_X14 (0x01UL << 14U)
91 #define CRC_X15 (0x01UL << 15U)
92 #define CRC_X16 (0x01UL << 16U)
93 #define CRC_X17 (0x01UL << 17U)
94 #define CRC_X18 (0x01UL << 18U)
95 #define CRC_X19 (0x01UL << 19U)
96 #define CRC_X20 (0x01UL << 20U)
97 #define CRC_X21 (0x01UL << 21U)
98 #define CRC_X22 (0x01UL << 22U)
99 #define CRC_X23 (0x01UL << 23U)
100 #define CRC_X24 (0x01UL << 24U)
101 #define CRC_X25 (0x01UL << 25U)
102 #define CRC_X26 (0x01UL << 26U)
103 #define CRC_X27 (0x01UL << 27U)
104 #define CRC_X28 (0x01UL << 28U)
105 #define CRC_X29 (0x01UL << 29U)
106 #define CRC_X30 (0x01UL << 30U)
107 #define CRC_X31 (0x01UL << 31U)
117 #define CRC32_POLY (0x04C11DB7UL)
118 #define CRC16_POLY (0x8005UL)
119 #define CRC8_POLY (0x31UL)
120 #define CRC7_POLY (0x09UL)
126 #define DEFAULT_HCRC_INITVAL (0xFFFFFFFFUL) //Default initial value
129 #define HCRC_POLYSIZE_MASK (0x18) //B00011000
131 #define HCRC_32BIT_POLYSIZE (0x00)
132 #define HCRC_16BIT_POLYSIZE (0x08)
133 #define HCRC_8BIT_POLYSIZE (0x10)
134 #define HCRC_7BIT_POLYSIZE (HCRC_POLYSIZE_MASK)
137 #define HCRC_OUT_REVERSE_MASK (0x80) //B10000000
139 #define HCRC_OUT_REVERSE_ENABLED HCRC_OUT_REVERSE_MASK
140 #define HCRC_OUT_REVERSE_DISABLED (0x0)
143 #define HCRC_IN_REVERSE_MASK (0x60) //B01100000
145 #define HCRC_IN_REVERSE_ENABLED_BYTE (0x20)
146 #define HCRC_IN_REVERSE_ENABLED_HALFWORD (0x40)
147 #define HCRC_IN_REVERSE_ENABLED_WORD HCRC_IN_REVERSE_MASK
148 #define HCRC_IN_REVERSE_DISABLED (0x0)
236 #if CRC_CUST_POLY == (0x1)
254 #if CRC_CUST_INIT_VAL == (0x1)
268 return CRC->DR ^ finalXOR;
284 uint32_t
append(
const uint8_t data, uint32_t finalXOR = 0x00);
294 uint32_t
append(
const uint8_t* data, uint32_t dataLength, uint32_t finalXOR = 0x00);
304 uint32_t
append(
const int8_t* data, uint32_t dataLength, uint32_t finalXOR = 0x00){
305 return append((
const uint8_t*)data, dataLength, finalXOR);
315 uint32_t
append(
const uint16_t data, uint32_t finalXOR = 0x00);
325 uint32_t
append(
const uint16_t* data, uint32_t dataLength, uint32_t finalXOR = 0x00);
335 uint32_t
append(
const int16_t* data, uint32_t dataLength, uint32_t finalXOR = 0x00){
336 return append((
const uint16_t*)data, dataLength, finalXOR);
346 uint32_t
append(
const uint32_t data, uint32_t finalXOR = 0x00);
356 uint32_t
append(
const uint32_t* data, uint32_t dataLength, uint32_t finalXOR = 0x00);
366 uint32_t
append (
const int32_t* data, uint32_t dataLength, uint32_t finalXOR = 0x00){
367 return append((
const uint32_t*)data, dataLength, finalXOR);
391 return compute((
const uint8_t*)data, dataLength, initValue, finalXOR);
415 return compute((
const uint16_t*)data, dataLength, initValue, finalXOR);
439 return compute((
const uint32_t*)data, dataLength, initValue, finalXOR);
523 bool check(
const uint8_t* data, uint32_t dataLength, uint32_t initValue =
DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00);
535 return check((
const uint8_t*)data, dataLength, initValue, finalXOR);
547 bool check(
const uint16_t* data, uint32_t dataLength, uint32_t initValue =
DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00);
559 return check((
const uint16_t*)data, dataLength, initValue, finalXOR);
571 bool check(
const uint32_t* data, uint32_t dataLength, uint32_t initValue =
DEFAULT_HCRC_INITVAL, uint32_t finalXOR = 0x00);
583 return check((
const uint32_t*)data, dataLength, initValue, finalXOR);
612 #if CRC_IO_REV_SUPP == (0x1)
624 #if CRC_IO_REV_SUPP == (0x1)
660 #if CRC_CUST_POLY == (0x1)
661 uint32_t lastPoly = 0;
663 #if CRC_CUST_INIT_VAL == (0x1)
664 uint32_t lastInit = 0;
void end()
Disables hardware CRC calculation unit.
Definition: HardwareCRC.cpp:501
bool check(const int16_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.h:558
uint32_t getPolynomial()
Gets polynomial, that was set.
Definition: HardwareCRC.h:235
uint32_t compute(const int32_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.h:438
uint32_t getCheckValue(uint32_t initValue=DEFAULT_HCRC_INITVAL, uint32_t finalXOR=0x00)
Calculates CRC check value.
Definition: HardwareCRC.cpp:432
uint32_t computeAndWriteToEnd(int32_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.h:510
void setInputReverseSize(uint32_t reverse)
Sets input reverse size to CR register.
Definition: HardwareCRC.cpp:532
static const bool isCustomPolynomialSupported
True when custom polynomials are supported.
Definition: HardwareCRC.h:644
Calculate CRC simply and fast using this class. Calculation is done using hardware CRC calculation un...
Definition: HardwareCRC.h:190
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
uint8_t lastCR
Definition: HardwareCRC.h:659
#define HCRC_IN_REVERSE_DISABLED
Definition: HardwareCRC.h:148
uint8_t getPolynomialLength()
Gets polynomial length in bits.
Definition: HardwareCRC.cpp:74
uint32_t getInitValue()
Gets initial value, that was set using reset(), compute() or computeAndWriteToEnd() method.
Definition: HardwareCRC.h:253
#define CRC16_POLY
Definition: HardwareCRC.h:118
#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
uint32_t getLastCRC(uint32_t finalXOR=0x00)
Gets last calculated CRC result.
Definition: HardwareCRC.h:267
bool setPolynomial16(uint32_t polynomial=CRC16_POLY)
Sets CRC-16 polynomial.
Definition: HardwareCRC.cpp:50
static const bool isCustomInitValueSupported
True when custom initial value is supported, if not, 0xFFFFFFFFUL is set.
Definition: HardwareCRC.h:654
uint32_t append(const int32_t *data, uint32_t dataLength, uint32_t finalXOR=0x00)
Appends another data to previous CRC calculation and calculates new CRC value.
Definition: HardwareCRC.h:366
static const bool isIOReverseSupported
True when input / output reversion (reflection) is supported.
Definition: HardwareCRC.h:649
#define HCRC_OUT_REVERSE_MASK
Definition: HardwareCRC.h:137
uint32_t computeAndWriteToEnd(int16_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.h:486
uint32_t compute(const int16_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.h:414
uint8_t inputReverse
Definition: HardwareCRC.h:679
uint32_t lastFXOR
Definition: HardwareCRC.h:666
uint32_t computeAndWriteToEnd(int8_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.h:462
bool getInputReverse()
Gets, if input data bits will be reversed(reflected) or not.
Definition: HardwareCRC.h:611
bool setPolynomial8(uint32_t polynomial=CRC8_POLY)
Sets CRC-8 polynomial.
Definition: HardwareCRC.cpp:37
uint32_t compute(const int8_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.h:390
bool setInputReverse(bool reverse)
Sets, if input data bits will be reversed(reflected) or not.
Definition: HardwareCRC.cpp:481
bool check(const int32_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.h:582
#define CRC7_POLY
Definition: HardwareCRC.h:120
uint32_t lastCRCCheckValue
Definition: HardwareCRC.h:667
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
bool setPolynomial7(uint32_t polynomial=CRC7_POLY)
Sets CRC-7 polynomial.
Definition: HardwareCRC.cpp:24
This file contains basic (Arduino like) GPIO manipulation functions, delay, random,...
#define HCRC_IN_REVERSE_MASK
Definition: HardwareCRC.h:143
#define HCRC_OUT_REVERSE_ENABLED
Definition: HardwareCRC.h:139
uint32_t append(const int8_t *data, uint32_t dataLength, uint32_t finalXOR=0x00)
Appends another data to previous CRC calculation and calculates new CRC value.
Definition: HardwareCRC.h:304
HardwareCRC crc
Definition: HardwareCRC.cpp:539
uint32_t append(const int16_t *data, uint32_t dataLength, uint32_t finalXOR=0x00)
Appends another data to previous CRC calculation and calculates new CRC value.
Definition: HardwareCRC.h:335
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 check(const int8_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.h:534
bool getOutputReverse()
Gets, if output CRC data bits will be reversed(reflected) or not.
Definition: HardwareCRC.h:623
#define CRC32_POLY
Definition: HardwareCRC.h:117
bool begin()
Enables CRC hardware calculation unit.
Definition: HardwareCRC.cpp:11
#define DEFAULT_HCRC_INITVAL
Definition: HardwareCRC.h:126