2 ******************************************************************************
3 * @file stm32h7xx_ll_crc.h
4 * @author MCD Application Team
5 * @brief Header file of CRC LL module.
6 ******************************************************************************
9 * Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.
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.
16 ******************************************************************************
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32H7xx_LL_CRC_H
21 #define STM32H7xx_LL_CRC_H
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32h7xx.h"
30 /** @addtogroup STM32H7xx_LL_Driver
36 /** @defgroup CRC_LL CRC
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /* Private macros ------------------------------------------------------------*/
45 /* Exported types ------------------------------------------------------------*/
46 /* Exported constants --------------------------------------------------------*/
47 /** @defgroup CRC_LL_Exported_Constants CRC Exported Constants
51 /** @defgroup CRC_LL_EC_POLYLENGTH Polynomial length
54 #define LL_CRC_POLYLENGTH_32B 0x00000000U /*!< 32 bits Polynomial size */
55 #define LL_CRC_POLYLENGTH_16B CRC_CR_POLYSIZE_0 /*!< 16 bits Polynomial size */
56 #define LL_CRC_POLYLENGTH_8B CRC_CR_POLYSIZE_1 /*!< 8 bits Polynomial size */
57 #define LL_CRC_POLYLENGTH_7B (CRC_CR_POLYSIZE_1 | CRC_CR_POLYSIZE_0) /*!< 7 bits Polynomial size */
62 /** @defgroup CRC_LL_EC_INDATA_REVERSE Input Data Reverse
65 #define LL_CRC_INDATA_REVERSE_NONE 0x00000000U /*!< Input Data bit order not affected */
66 #define LL_CRC_INDATA_REVERSE_BYTE CRC_CR_REV_IN_0 /*!< Input Data bit reversal done by byte */
67 #define LL_CRC_INDATA_REVERSE_HALFWORD CRC_CR_REV_IN_1 /*!< Input Data bit reversal done by half-word */
68 #define LL_CRC_INDATA_REVERSE_WORD (CRC_CR_REV_IN_1 | CRC_CR_REV_IN_0) /*!< Input Data bit reversal done by word */
73 /** @defgroup CRC_LL_EC_OUTDATA_REVERSE Output Data Reverse
76 #define LL_CRC_OUTDATA_REVERSE_NONE 0x00000000U /*!< Output Data bit order not affected */
77 #define LL_CRC_OUTDATA_REVERSE_BIT CRC_CR_REV_OUT /*!< Output Data bit reversal done by bit */
82 /** @defgroup CRC_LL_EC_Default_Polynomial_Value Default CRC generating polynomial value
83 * @brief Normal representation of this polynomial value is
84 * 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 .
87 #define LL_CRC_DEFAULT_CRC32_POLY 0x04C11DB7U /*!< Default CRC generating polynomial value */
92 /** @defgroup CRC_LL_EC_Default_InitValue Default CRC computation initialization value
95 #define LL_CRC_DEFAULT_CRC_INITVALUE 0xFFFFFFFFU /*!< Default CRC computation initialization value */
104 /* Exported macro ------------------------------------------------------------*/
105 /** @defgroup CRC_LL_Exported_Macros CRC Exported Macros
109 /** @defgroup CRC_LL_EM_WRITE_READ Common Write and read registers Macros
114 * @brief Write a value in CRC register
115 * @param __INSTANCE__ CRC Instance
116 * @param __REG__ Register to be written
117 * @param __VALUE__ Value to be written in the register
120 #define LL_CRC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, __VALUE__)
123 * @brief Read a value in CRC register
124 * @param __INSTANCE__ CRC Instance
125 * @param __REG__ Register to be read
126 * @retval Register value
128 #define LL_CRC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
138 /* Exported functions --------------------------------------------------------*/
139 /** @defgroup CRC_LL_Exported_Functions CRC Exported Functions
143 /** @defgroup CRC_LL_EF_Configuration CRC Configuration functions
148 * @brief Reset the CRC calculation unit.
149 * @note If Programmable Initial CRC value feature
150 * is available, also set the Data Register to the value stored in the
151 * CRC_INIT register, otherwise, reset Data Register to its default value.
152 * @rmtoll CR RESET LL_CRC_ResetCRCCalculationUnit
153 * @param CRCx CRC Instance
156 __STATIC_INLINE
void LL_CRC_ResetCRCCalculationUnit(CRC_TypeDef
*CRCx
)
158 SET_BIT(CRCx
->CR
, CRC_CR_RESET
);
162 * @brief Configure size of the polynomial.
163 * @rmtoll CR POLYSIZE LL_CRC_SetPolynomialSize
164 * @param CRCx CRC Instance
165 * @param PolySize This parameter can be one of the following values:
166 * @arg @ref LL_CRC_POLYLENGTH_32B
167 * @arg @ref LL_CRC_POLYLENGTH_16B
168 * @arg @ref LL_CRC_POLYLENGTH_8B
169 * @arg @ref LL_CRC_POLYLENGTH_7B
172 __STATIC_INLINE
void LL_CRC_SetPolynomialSize(CRC_TypeDef
*CRCx
, uint32_t PolySize
)
174 MODIFY_REG(CRCx
->CR
, CRC_CR_POLYSIZE
, PolySize
);
178 * @brief Return size of the polynomial.
179 * @rmtoll CR POLYSIZE LL_CRC_GetPolynomialSize
180 * @param CRCx CRC Instance
181 * @retval Returned value can be one of the following values:
182 * @arg @ref LL_CRC_POLYLENGTH_32B
183 * @arg @ref LL_CRC_POLYLENGTH_16B
184 * @arg @ref LL_CRC_POLYLENGTH_8B
185 * @arg @ref LL_CRC_POLYLENGTH_7B
187 __STATIC_INLINE
uint32_t LL_CRC_GetPolynomialSize(const CRC_TypeDef
*CRCx
)
189 return (uint32_t)(READ_BIT(CRCx
->CR
, CRC_CR_POLYSIZE
));
193 * @brief Configure the reversal of the bit order of the input data
194 * @rmtoll CR REV_IN LL_CRC_SetInputDataReverseMode
195 * @param CRCx CRC Instance
196 * @param ReverseMode This parameter can be one of the following values:
197 * @arg @ref LL_CRC_INDATA_REVERSE_NONE
198 * @arg @ref LL_CRC_INDATA_REVERSE_BYTE
199 * @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD
200 * @arg @ref LL_CRC_INDATA_REVERSE_WORD
203 __STATIC_INLINE
void LL_CRC_SetInputDataReverseMode(CRC_TypeDef
*CRCx
, uint32_t ReverseMode
)
205 MODIFY_REG(CRCx
->CR
, CRC_CR_REV_IN
, ReverseMode
);
209 * @brief Return type of reversal for input data bit order
210 * @rmtoll CR REV_IN LL_CRC_GetInputDataReverseMode
211 * @param CRCx CRC Instance
212 * @retval Returned value can be one of the following values:
213 * @arg @ref LL_CRC_INDATA_REVERSE_NONE
214 * @arg @ref LL_CRC_INDATA_REVERSE_BYTE
215 * @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD
216 * @arg @ref LL_CRC_INDATA_REVERSE_WORD
218 __STATIC_INLINE
uint32_t LL_CRC_GetInputDataReverseMode(const CRC_TypeDef
*CRCx
)
220 return (uint32_t)(READ_BIT(CRCx
->CR
, CRC_CR_REV_IN
));
224 * @brief Configure the reversal of the bit order of the Output data
225 * @rmtoll CR REV_OUT LL_CRC_SetOutputDataReverseMode
226 * @param CRCx CRC Instance
227 * @param ReverseMode This parameter can be one of the following values:
228 * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
229 * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
232 __STATIC_INLINE
void LL_CRC_SetOutputDataReverseMode(CRC_TypeDef
*CRCx
, uint32_t ReverseMode
)
234 MODIFY_REG(CRCx
->CR
, CRC_CR_REV_OUT
, ReverseMode
);
238 * @brief Return type of reversal of the bit order of the Output data
239 * @rmtoll CR REV_OUT LL_CRC_GetOutputDataReverseMode
240 * @param CRCx CRC Instance
241 * @retval Returned value can be one of the following values:
242 * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
243 * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
245 __STATIC_INLINE
uint32_t LL_CRC_GetOutputDataReverseMode(const CRC_TypeDef
*CRCx
)
247 return (uint32_t)(READ_BIT(CRCx
->CR
, CRC_CR_REV_OUT
));
251 * @brief Initialize the Programmable initial CRC value.
252 * @note If the CRC size is less than 32 bits, the least significant bits
253 * are used to write the correct value
254 * @note LL_CRC_DEFAULT_CRC_INITVALUE could be used as value for InitCrc parameter.
255 * @rmtoll INIT INIT LL_CRC_SetInitialData
256 * @param CRCx CRC Instance
257 * @param InitCrc Value to be programmed in Programmable initial CRC value register
260 __STATIC_INLINE
void LL_CRC_SetInitialData(CRC_TypeDef
*CRCx
, uint32_t InitCrc
)
262 WRITE_REG(CRCx
->INIT
, InitCrc
);
266 * @brief Return current Initial CRC value.
267 * @note If the CRC size is less than 32 bits, the least significant bits
268 * are used to read the correct value
269 * @rmtoll INIT INIT LL_CRC_GetInitialData
270 * @param CRCx CRC Instance
271 * @retval Value programmed in Programmable initial CRC value register
273 __STATIC_INLINE
uint32_t LL_CRC_GetInitialData(const CRC_TypeDef
*CRCx
)
275 return (uint32_t)(READ_REG(CRCx
->INIT
));
279 * @brief Initialize the Programmable polynomial value
280 * (coefficients of the polynomial to be used for CRC calculation).
281 * @note LL_CRC_DEFAULT_CRC32_POLY could be used as value for PolynomCoef parameter.
282 * @note Please check Reference Manual and existing Errata Sheets,
283 * regarding possible limitations for Polynomial values usage.
284 * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
285 * @rmtoll POL POL LL_CRC_SetPolynomialCoef
286 * @param CRCx CRC Instance
287 * @param PolynomCoef Value to be programmed in Programmable Polynomial value register
290 __STATIC_INLINE
void LL_CRC_SetPolynomialCoef(CRC_TypeDef
*CRCx
, uint32_t PolynomCoef
)
292 WRITE_REG(CRCx
->POL
, PolynomCoef
);
296 * @brief Return current Programmable polynomial value
297 * @note Please check Reference Manual and existing Errata Sheets,
298 * regarding possible limitations for Polynomial values usage.
299 * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
300 * @rmtoll POL POL LL_CRC_GetPolynomialCoef
301 * @param CRCx CRC Instance
302 * @retval Value programmed in Programmable Polynomial value register
304 __STATIC_INLINE
uint32_t LL_CRC_GetPolynomialCoef(const CRC_TypeDef
*CRCx
)
306 return (uint32_t)(READ_REG(CRCx
->POL
));
313 /** @defgroup CRC_LL_EF_Data_Management Data_Management
318 * @brief Write given 32-bit data to the CRC calculator
319 * @rmtoll DR DR LL_CRC_FeedData32
320 * @param CRCx CRC Instance
321 * @param InData value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFFFFFF
324 __STATIC_INLINE
void LL_CRC_FeedData32(CRC_TypeDef
*CRCx
, uint32_t InData
)
326 WRITE_REG(CRCx
->DR
, InData
);
330 * @brief Write given 16-bit data to the CRC calculator
331 * @rmtoll DR DR LL_CRC_FeedData16
332 * @param CRCx CRC Instance
333 * @param InData 16 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFF
336 __STATIC_INLINE
void LL_CRC_FeedData16(CRC_TypeDef
*CRCx
, uint16_t InData
)
340 pReg
= (__IO
uint16_t *)(__IO
void *)(&CRCx
->DR
); /* Derogation MisraC2012 R.11.5 */
345 * @brief Write given 8-bit data to the CRC calculator
346 * @rmtoll DR DR LL_CRC_FeedData8
347 * @param CRCx CRC Instance
348 * @param InData 8 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFF
351 __STATIC_INLINE
void LL_CRC_FeedData8(CRC_TypeDef
*CRCx
, uint8_t InData
)
353 *(uint8_t __IO
*)(&CRCx
->DR
) = (uint8_t) InData
;
357 * @brief Return current CRC calculation result. 32 bits value is returned.
358 * @rmtoll DR DR LL_CRC_ReadData32
359 * @param CRCx CRC Instance
360 * @retval Current CRC calculation result as stored in CRC_DR register (32 bits).
362 __STATIC_INLINE
uint32_t LL_CRC_ReadData32(const CRC_TypeDef
*CRCx
)
364 return (uint32_t)(READ_REG(CRCx
->DR
));
368 * @brief Return current CRC calculation result. 16 bits value is returned.
369 * @note This function is expected to be used in a 16 bits CRC polynomial size context.
370 * @rmtoll DR DR LL_CRC_ReadData16
371 * @param CRCx CRC Instance
372 * @retval Current CRC calculation result as stored in CRC_DR register (16 bits).
374 __STATIC_INLINE
uint16_t LL_CRC_ReadData16(const CRC_TypeDef
*CRCx
)
376 return (uint16_t)READ_REG(CRCx
->DR
);
380 * @brief Return current CRC calculation result. 8 bits value is returned.
381 * @note This function is expected to be used in a 8 bits CRC polynomial size context.
382 * @rmtoll DR DR LL_CRC_ReadData8
383 * @param CRCx CRC Instance
384 * @retval Current CRC calculation result as stored in CRC_DR register (8 bits).
386 __STATIC_INLINE
uint8_t LL_CRC_ReadData8(const CRC_TypeDef
*CRCx
)
388 return (uint8_t)READ_REG(CRCx
->DR
);
392 * @brief Return current CRC calculation result. 7 bits value is returned.
393 * @note This function is expected to be used in a 7 bits CRC polynomial size context.
394 * @rmtoll DR DR LL_CRC_ReadData7
395 * @param CRCx CRC Instance
396 * @retval Current CRC calculation result as stored in CRC_DR register (7 bits).
398 __STATIC_INLINE
uint8_t LL_CRC_ReadData7(const CRC_TypeDef
*CRCx
)
400 return (uint8_t)(READ_REG(CRCx
->DR
) & 0x7FU
);
404 * @brief Return data stored in the Independent Data(IDR) register.
405 * @note This register can be used as a temporary storage location for one 32-bit long data.
406 * @rmtoll IDR IDR LL_CRC_Read_IDR
407 * @param CRCx CRC Instance
408 * @retval Value stored in CRC_IDR register (General-purpose 32-bit data register).
410 __STATIC_INLINE
uint32_t LL_CRC_Read_IDR(const CRC_TypeDef
*CRCx
)
412 return (uint32_t)(READ_REG(CRCx
->IDR
));
416 * @brief Store data in the Independent Data(IDR) register.
417 * @note This register can be used as a temporary storage location for one 32-bit long data.
418 * @rmtoll IDR IDR LL_CRC_Write_IDR
419 * @param CRCx CRC Instance
420 * @param InData value to be stored in CRC_IDR register (32-bit) between Min_Data=0 and Max_Data=0xFFFFFFFF
423 __STATIC_INLINE
void LL_CRC_Write_IDR(CRC_TypeDef
*CRCx
, uint32_t InData
)
425 *((uint32_t __IO
*)(&CRCx
->IDR
)) = (uint32_t) InData
;
431 #if defined(USE_FULL_LL_DRIVER)
432 /** @defgroup CRC_LL_EF_Init Initialization and de-initialization functions
436 ErrorStatus
LL_CRC_DeInit(const CRC_TypeDef
*CRCx
);
441 #endif /* USE_FULL_LL_DRIVER */
451 #endif /* defined(CRC) */
461 #endif /* STM32H7xx_LL_CRC_H */