1 /**
2 ******************************************************************************
3 * @file stm32f0xx_ll_crc.h
4 * @author MCD Application Team
5 * @brief Header file of CRC LL module.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2016 STMicroelectronics.
10 * All rights reserved.
11 *
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
15 *
16 ******************************************************************************
17 */
18
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32F0xx_LL_CRC_H
21 #define STM32F0xx_LL_CRC_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f0xx.h"
29
30 /** @addtogroup STM32F0xx_LL_Driver
31 * @{
32 */
33
34 #if defined(CRC)
35
36 /** @defgroup CRC_LL CRC
37 * @{
38 */
39
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /* Private macros ------------------------------------------------------------*/
44
45 /* Exported types ------------------------------------------------------------*/
46 /* Exported constants --------------------------------------------------------*/
47 /** @defgroup CRC_LL_Exported_Constants CRC Exported Constants
48 * @{
49 */
50
51 #if defined(CRC_POL_POL)
52 /** @defgroup CRC_LL_EC_POLYLENGTH Polynomial length
53 * @{
54 */
55 #define LL_CRC_POLYLENGTH_32B 0x00000000U /*!< 32 bits Polynomial size */
56 #define LL_CRC_POLYLENGTH_16B CRC_CR_POLYSIZE_0 /*!< 16 bits Polynomial size */
57 #define LL_CRC_POLYLENGTH_8B CRC_CR_POLYSIZE_1 /*!< 8 bits Polynomial size */
58 #define LL_CRC_POLYLENGTH_7B (CRC_CR_POLYSIZE_1 | CRC_CR_POLYSIZE_0) /*!< 7 bits Polynomial size */
59 /**
60 * @}
61 */
62 #endif /* CRC_POL_POL */
63
64 /** @defgroup CRC_LL_EC_INDATA_REVERSE Input Data Reverse
65 * @{
66 */
67 #define LL_CRC_INDATA_REVERSE_NONE 0x00000000U /*!< Input Data bit order not affected */
68 #define LL_CRC_INDATA_REVERSE_BYTE CRC_CR_REV_IN_0 /*!< Input Data bit reversal done by byte */
69 #define LL_CRC_INDATA_REVERSE_HALFWORD CRC_CR_REV_IN_1 /*!< Input Data bit reversal done by half-word */
70 #define LL_CRC_INDATA_REVERSE_WORD (CRC_CR_REV_IN_1 | CRC_CR_REV_IN_0) /*!< Input Data bit reversal done by word */
71 /**
72 * @}
73 */
74
75 /** @defgroup CRC_LL_EC_OUTDATA_REVERSE Output Data Reverse
76 * @{
77 */
78 #define LL_CRC_OUTDATA_REVERSE_NONE 0x00000000U /*!< Output Data bit order not affected */
79 #define LL_CRC_OUTDATA_REVERSE_BIT CRC_CR_REV_OUT /*!< Output Data bit reversal done by bit */
80 /**
81 * @}
82 */
83
84 #if defined(CRC_POL_POL)
85 /** @defgroup CRC_LL_EC_Default_Polynomial_Value Default CRC generating polynomial value
86 * @brief Normal representation of this polynomial value is
87 * X^32 + X^26 + X^23 + X^22 + X^16 + X^12 + X^11 + X^10 +X^8 + X^7 + X^5 + X^4 + X^2 + X + 1 .
88 * @{
89 */
90 #define LL_CRC_DEFAULT_CRC32_POLY 0x04C11DB7U /*!< Default CRC generating polynomial value */
91 /**
92 * @}
93 */
94 #endif /* CRC_POL_POL */
95
96 /** @defgroup CRC_LL_EC_Default_InitValue Default CRC computation initialization value
97 * @{
98 */
99 #define LL_CRC_DEFAULT_CRC_INITVALUE 0xFFFFFFFFU /*!< Default CRC computation initialization value */
100 /**
101 * @}
102 */
103
104 /**
105 * @}
106 */
107
108 /* Exported macro ------------------------------------------------------------*/
109 /** @defgroup CRC_LL_Exported_Macros CRC Exported Macros
110 * @{
111 */
112
113 /** @defgroup CRC_LL_EM_WRITE_READ Common Write and read registers Macros
114 * @{
115 */
116
117 /**
118 * @brief Write a value in CRC register
119 * @param __INSTANCE__ CRC Instance
120 * @param __REG__ Register to be written
121 * @param __VALUE__ Value to be written in the register
122 * @retval None
123 */
124 #define LL_CRC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, __VALUE__)
125
126 /**
127 * @brief Read a value in CRC register
128 * @param __INSTANCE__ CRC Instance
129 * @param __REG__ Register to be read
130 * @retval Register value
131 */
132 #define LL_CRC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
133 /**
134 * @}
135 */
136
137 /**
138 * @}
139 */
140
141
142 /* Exported functions --------------------------------------------------------*/
143 /** @defgroup CRC_LL_Exported_Functions CRC Exported Functions
144 * @{
145 */
146
147 /** @defgroup CRC_LL_EF_Configuration CRC Configuration functions
148 * @{
149 */
150
151 /**
152 * @brief Reset the CRC calculation unit.
153 * @note If Programmable Initial CRC value feature
154 * is available, also set the Data Register to the value stored in the
155 * CRC_INIT register, otherwise, reset Data Register to its default value.
156 * @rmtoll CR RESET LL_CRC_ResetCRCCalculationUnit
157 * @param CRCx CRC Instance
158 * @retval None
159 */
LL_CRC_ResetCRCCalculationUnit(CRC_TypeDef * CRCx)160 __STATIC_INLINE void LL_CRC_ResetCRCCalculationUnit(CRC_TypeDef *CRCx)
161 {
162 SET_BIT(CRCx->CR, CRC_CR_RESET);
163 }
164
165 #if defined(CRC_POL_POL)
166 /**
167 * @brief Configure size of the polynomial.
168 * @rmtoll CR POLYSIZE LL_CRC_SetPolynomialSize
169 * @param CRCx CRC Instance
170 * @param PolySize This parameter can be one of the following values:
171 * @arg @ref LL_CRC_POLYLENGTH_32B
172 * @arg @ref LL_CRC_POLYLENGTH_16B
173 * @arg @ref LL_CRC_POLYLENGTH_8B
174 * @arg @ref LL_CRC_POLYLENGTH_7B
175 * @retval None
176 */
LL_CRC_SetPolynomialSize(CRC_TypeDef * CRCx,uint32_t PolySize)177 __STATIC_INLINE void LL_CRC_SetPolynomialSize(CRC_TypeDef *CRCx, uint32_t PolySize)
178 {
179 MODIFY_REG(CRCx->CR, CRC_CR_POLYSIZE, PolySize);
180 }
181
182 /**
183 * @brief Return size of the polynomial.
184 * @rmtoll CR POLYSIZE LL_CRC_GetPolynomialSize
185 * @param CRCx CRC Instance
186 * @retval Returned value can be one of the following values:
187 * @arg @ref LL_CRC_POLYLENGTH_32B
188 * @arg @ref LL_CRC_POLYLENGTH_16B
189 * @arg @ref LL_CRC_POLYLENGTH_8B
190 * @arg @ref LL_CRC_POLYLENGTH_7B
191 */
LL_CRC_GetPolynomialSize(CRC_TypeDef * CRCx)192 __STATIC_INLINE uint32_t LL_CRC_GetPolynomialSize(CRC_TypeDef *CRCx)
193 {
194 return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_POLYSIZE));
195 }
196 #endif /* CRC_POL_POL */
197
198 /**
199 * @brief Configure the reversal of the bit order of the input data
200 * @rmtoll CR REV_IN LL_CRC_SetInputDataReverseMode
201 * @param CRCx CRC Instance
202 * @param ReverseMode This parameter can be one of the following values:
203 * @arg @ref LL_CRC_INDATA_REVERSE_NONE
204 * @arg @ref LL_CRC_INDATA_REVERSE_BYTE
205 * @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD
206 * @arg @ref LL_CRC_INDATA_REVERSE_WORD
207 * @retval None
208 */
LL_CRC_SetInputDataReverseMode(CRC_TypeDef * CRCx,uint32_t ReverseMode)209 __STATIC_INLINE void LL_CRC_SetInputDataReverseMode(CRC_TypeDef *CRCx, uint32_t ReverseMode)
210 {
211 MODIFY_REG(CRCx->CR, CRC_CR_REV_IN, ReverseMode);
212 }
213
214 /**
215 * @brief Return type of reversal for input data bit order
216 * @rmtoll CR REV_IN LL_CRC_GetInputDataReverseMode
217 * @param CRCx CRC Instance
218 * @retval Returned value can be one of the following values:
219 * @arg @ref LL_CRC_INDATA_REVERSE_NONE
220 * @arg @ref LL_CRC_INDATA_REVERSE_BYTE
221 * @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD
222 * @arg @ref LL_CRC_INDATA_REVERSE_WORD
223 */
LL_CRC_GetInputDataReverseMode(CRC_TypeDef * CRCx)224 __STATIC_INLINE uint32_t LL_CRC_GetInputDataReverseMode(CRC_TypeDef *CRCx)
225 {
226 return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_REV_IN));
227 }
228
229 /**
230 * @brief Configure the reversal of the bit order of the Output data
231 * @rmtoll CR REV_OUT LL_CRC_SetOutputDataReverseMode
232 * @param CRCx CRC Instance
233 * @param ReverseMode This parameter can be one of the following values:
234 * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
235 * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
236 * @retval None
237 */
LL_CRC_SetOutputDataReverseMode(CRC_TypeDef * CRCx,uint32_t ReverseMode)238 __STATIC_INLINE void LL_CRC_SetOutputDataReverseMode(CRC_TypeDef *CRCx, uint32_t ReverseMode)
239 {
240 MODIFY_REG(CRCx->CR, CRC_CR_REV_OUT, ReverseMode);
241 }
242
243 /**
244 * @brief Return type of reversal of the bit order of the Output data
245 * @rmtoll CR REV_OUT LL_CRC_GetOutputDataReverseMode
246 * @param CRCx CRC Instance
247 * @retval Returned value can be one of the following values:
248 * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
249 * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
250 */
LL_CRC_GetOutputDataReverseMode(CRC_TypeDef * CRCx)251 __STATIC_INLINE uint32_t LL_CRC_GetOutputDataReverseMode(CRC_TypeDef *CRCx)
252 {
253 return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_REV_OUT));
254 }
255
256 /**
257 * @brief Initialize the Programmable initial CRC value.
258 * @note If the CRC size is less than 32 bits, the least significant bits
259 * are used to write the correct value
260 * @note LL_CRC_DEFAULT_CRC_INITVALUE could be used as value for InitCrc parameter.
261 * @rmtoll INIT INIT LL_CRC_SetInitialData
262 * @param CRCx CRC Instance
263 * @param InitCrc Value to be programmed in Programmable initial CRC value register
264 * @retval None
265 */
LL_CRC_SetInitialData(CRC_TypeDef * CRCx,uint32_t InitCrc)266 __STATIC_INLINE void LL_CRC_SetInitialData(CRC_TypeDef *CRCx, uint32_t InitCrc)
267 {
268 WRITE_REG(CRCx->INIT, InitCrc);
269 }
270
271 /**
272 * @brief Return current Initial CRC value.
273 * @note If the CRC size is less than 32 bits, the least significant bits
274 * are used to read the correct value
275 * @rmtoll INIT INIT LL_CRC_GetInitialData
276 * @param CRCx CRC Instance
277 * @retval Value programmed in Programmable initial CRC value register
278 */
LL_CRC_GetInitialData(CRC_TypeDef * CRCx)279 __STATIC_INLINE uint32_t LL_CRC_GetInitialData(CRC_TypeDef *CRCx)
280 {
281 return (uint32_t)(READ_REG(CRCx->INIT));
282 }
283
284 #if defined(CRC_POL_POL)
285 /**
286 * @brief Initialize the Programmable polynomial value
287 * (coefficients of the polynomial to be used for CRC calculation).
288 * @note LL_CRC_DEFAULT_CRC32_POLY could be used as value for PolynomCoef parameter.
289 * @note Please check Reference Manual and existing Errata Sheets,
290 * regarding possible limitations for Polynomial values usage.
291 * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
292 * @rmtoll POL POL LL_CRC_SetPolynomialCoef
293 * @param CRCx CRC Instance
294 * @param PolynomCoef Value to be programmed in Programmable Polynomial value register
295 * @retval None
296 */
LL_CRC_SetPolynomialCoef(CRC_TypeDef * CRCx,uint32_t PolynomCoef)297 __STATIC_INLINE void LL_CRC_SetPolynomialCoef(CRC_TypeDef *CRCx, uint32_t PolynomCoef)
298 {
299 WRITE_REG(CRCx->POL, PolynomCoef);
300 }
301
302 /**
303 * @brief Return current Programmable polynomial value
304 * @note Please check Reference Manual and existing Errata Sheets,
305 * regarding possible limitations for Polynomial values usage.
306 * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
307 * @rmtoll POL POL LL_CRC_GetPolynomialCoef
308 * @param CRCx CRC Instance
309 * @retval Value programmed in Programmable Polynomial value register
310 */
LL_CRC_GetPolynomialCoef(CRC_TypeDef * CRCx)311 __STATIC_INLINE uint32_t LL_CRC_GetPolynomialCoef(CRC_TypeDef *CRCx)
312 {
313 return (uint32_t)(READ_REG(CRCx->POL));
314 }
315 #endif /* CRC_POL_POL */
316
317 /**
318 * @}
319 */
320
321 /** @defgroup CRC_LL_EF_Data_Management Data_Management
322 * @{
323 */
324
325 /**
326 * @brief Write given 32-bit data to the CRC calculator
327 * @rmtoll DR DR LL_CRC_FeedData32
328 * @param CRCx CRC Instance
329 * @param InData value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFFFFFF
330 * @retval None
331 */
LL_CRC_FeedData32(CRC_TypeDef * CRCx,uint32_t InData)332 __STATIC_INLINE void LL_CRC_FeedData32(CRC_TypeDef *CRCx, uint32_t InData)
333 {
334 WRITE_REG(CRCx->DR, InData);
335 }
336
337 /**
338 * @brief Write given 16-bit data to the CRC calculator
339 * @rmtoll DR DR LL_CRC_FeedData16
340 * @param CRCx CRC Instance
341 * @param InData 16 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFF
342 * @retval None
343 */
LL_CRC_FeedData16(CRC_TypeDef * CRCx,uint16_t InData)344 __STATIC_INLINE void LL_CRC_FeedData16(CRC_TypeDef *CRCx, uint16_t InData)
345 {
346 __IO uint16_t *pReg;
347
348 pReg = (__IO uint16_t *)(__IO void *)(&CRCx->DR); /* Derogation MisraC2012 R.11.5 */
349 *pReg = InData;
350 }
351
352 /**
353 * @brief Write given 8-bit data to the CRC calculator
354 * @rmtoll DR DR LL_CRC_FeedData8
355 * @param CRCx CRC Instance
356 * @param InData 8 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFF
357 * @retval None
358 */
LL_CRC_FeedData8(CRC_TypeDef * CRCx,uint8_t InData)359 __STATIC_INLINE void LL_CRC_FeedData8(CRC_TypeDef *CRCx, uint8_t InData)
360 {
361 *(uint8_t __IO *)(&CRCx->DR) = (uint8_t) InData;
362 }
363
364 /**
365 * @brief Return current CRC calculation result. 32 bits value is returned.
366 * @rmtoll DR DR LL_CRC_ReadData32
367 * @param CRCx CRC Instance
368 * @retval Current CRC calculation result as stored in CRC_DR register (32 bits).
369 */
LL_CRC_ReadData32(CRC_TypeDef * CRCx)370 __STATIC_INLINE uint32_t LL_CRC_ReadData32(CRC_TypeDef *CRCx)
371 {
372 return (uint32_t)(READ_REG(CRCx->DR));
373 }
374
375 #if defined(CRC_POL_POL)
376 /**
377 * @brief Return current CRC calculation result. 16 bits value is returned.
378 * @note This function is expected to be used in a 16 bits CRC polynomial size context.
379 * @rmtoll DR DR LL_CRC_ReadData16
380 * @param CRCx CRC Instance
381 * @retval Current CRC calculation result as stored in CRC_DR register (16 bits).
382 */
LL_CRC_ReadData16(CRC_TypeDef * CRCx)383 __STATIC_INLINE uint16_t LL_CRC_ReadData16(CRC_TypeDef *CRCx)
384 {
385 return (uint16_t)READ_REG(CRCx->DR);
386 }
387
388 /**
389 * @brief Return current CRC calculation result. 8 bits value is returned.
390 * @note This function is expected to be used in a 8 bits CRC polynomial size context.
391 * @rmtoll DR DR LL_CRC_ReadData8
392 * @param CRCx CRC Instance
393 * @retval Current CRC calculation result as stored in CRC_DR register (8 bits).
394 */
LL_CRC_ReadData8(CRC_TypeDef * CRCx)395 __STATIC_INLINE uint8_t LL_CRC_ReadData8(CRC_TypeDef *CRCx)
396 {
397 return (uint8_t)READ_REG(CRCx->DR);
398 }
399
400 /**
401 * @brief Return current CRC calculation result. 7 bits value is returned.
402 * @note This function is expected to be used in a 7 bits CRC polynomial size context.
403 * @rmtoll DR DR LL_CRC_ReadData7
404 * @param CRCx CRC Instance
405 * @retval Current CRC calculation result as stored in CRC_DR register (7 bits).
406 */
LL_CRC_ReadData7(CRC_TypeDef * CRCx)407 __STATIC_INLINE uint8_t LL_CRC_ReadData7(CRC_TypeDef *CRCx)
408 {
409 return (uint8_t)(READ_REG(CRCx->DR) & 0x7FU);
410 }
411 #endif /* CRC_POL_POL */
412
413 /**
414 * @brief Return data stored in the Independent Data(IDR) register.
415 * @note This register can be used as a temporary storage location for one byte.
416 * @rmtoll IDR IDR LL_CRC_Read_IDR
417 * @param CRCx CRC Instance
418 * @retval Value stored in CRC_IDR register (General-purpose 8-bit data register).
419 */
LL_CRC_Read_IDR(CRC_TypeDef * CRCx)420 __STATIC_INLINE uint32_t LL_CRC_Read_IDR(CRC_TypeDef *CRCx)
421 {
422 return (uint32_t)(READ_REG(CRCx->IDR));
423 }
424
425 /**
426 * @brief Store data in the Independent Data(IDR) register.
427 * @note This register can be used as a temporary storage location for one byte.
428 * @rmtoll IDR IDR LL_CRC_Write_IDR
429 * @param CRCx CRC Instance
430 * @param InData value to be stored in CRC_IDR register (8-bit) between Min_Data=0 and Max_Data=0xFF
431 * @retval None
432 */
LL_CRC_Write_IDR(CRC_TypeDef * CRCx,uint32_t InData)433 __STATIC_INLINE void LL_CRC_Write_IDR(CRC_TypeDef *CRCx, uint32_t InData)
434 {
435 *((uint8_t __IO *)(&CRCx->IDR)) = (uint8_t) InData;
436 }
437 /**
438 * @}
439 */
440
441 #if defined(USE_FULL_LL_DRIVER)
442 /** @defgroup CRC_LL_EF_Init Initialization and de-initialization functions
443 * @{
444 */
445
446 ErrorStatus LL_CRC_DeInit(CRC_TypeDef *CRCx);
447
448 /**
449 * @}
450 */
451 #endif /* USE_FULL_LL_DRIVER */
452
453 /**
454 * @}
455 */
456
457 /**
458 * @}
459 */
460
461 #endif /* defined(CRC) */
462
463 /**
464 * @}
465 */
466
467 #ifdef __cplusplus
468 }
469 #endif
470
471 #endif /* STM32F0xx_LL_CRC_H */
472