2 ******************************************************************************
3 * @file stm32h7xx_ll_crc.h
4 * @author MCD Application Team
5 * @brief Header file of CRC LL module.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32H7xx_LL_CRC_H
22 #define STM32H7xx_LL_CRC_H
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32h7xx.h"
31 /** @addtogroup STM32H7xx_LL_Driver
37 /** @defgroup CRC_LL CRC
41 /* Private types -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 /* Private constants ---------------------------------------------------------*/
44 /* Private macros ------------------------------------------------------------*/
46 /* Exported types ------------------------------------------------------------*/
47 /* Exported constants --------------------------------------------------------*/
48 /** @defgroup CRC_LL_Exported_Constants CRC Exported Constants
52 /** @defgroup CRC_LL_EC_POLYLENGTH Polynomial length
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 */
63 /** @defgroup CRC_LL_EC_INDATA_REVERSE Input Data Reverse
66 #define LL_CRC_INDATA_REVERSE_NONE 0x00000000U /*!< Input Data bit order not affected */
67 #define LL_CRC_INDATA_REVERSE_BYTE CRC_CR_REV_IN_0 /*!< Input Data bit reversal done by byte */
68 #define LL_CRC_INDATA_REVERSE_HALFWORD CRC_CR_REV_IN_1 /*!< Input Data bit reversal done by half-word */
69 #define LL_CRC_INDATA_REVERSE_WORD (CRC_CR_REV_IN_1 | CRC_CR_REV_IN_0) /*!< Input Data bit reversal done by word */
74 /** @defgroup CRC_LL_EC_OUTDATA_REVERSE Output Data Reverse
77 #define LL_CRC_OUTDATA_REVERSE_NONE 0x00000000U /*!< Output Data bit order not affected */
78 #define LL_CRC_OUTDATA_REVERSE_BIT CRC_CR_REV_OUT /*!< Output Data bit reversal done by bit */
83 /** @defgroup CRC_LL_EC_Default_Polynomial_Value Default CRC generating polynomial value
84 * @brief Normal representation of this polynomial value is
85 * 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 #define LL_CRC_DEFAULT_CRC32_POLY 0x04C11DB7U /*!< Default CRC generating polynomial value */
93 /** @defgroup CRC_LL_EC_Default_InitValue Default CRC computation initialization value
96 #define LL_CRC_DEFAULT_CRC_INITVALUE 0xFFFFFFFFU /*!< Default CRC computation initialization value */
105 /* Exported macro ------------------------------------------------------------*/
106 /** @defgroup CRC_LL_Exported_Macros CRC Exported Macros
110 /** @defgroup CRC_LL_EM_WRITE_READ Common Write and read registers Macros
115 * @brief Write a value in CRC register
116 * @param __INSTANCE__ CRC Instance
117 * @param __REG__ Register to be written
118 * @param __VALUE__ Value to be written in the register
121 #define LL_CRC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, __VALUE__)
124 * @brief Read a value in CRC register
125 * @param __INSTANCE__ CRC Instance
126 * @param __REG__ Register to be read
127 * @retval Register value
129 #define LL_CRC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
139 /* Exported functions --------------------------------------------------------*/
140 /** @defgroup CRC_LL_Exported_Functions CRC Exported Functions
144 /** @defgroup CRC_LL_EF_Configuration CRC Configuration functions
149 * @brief Reset the CRC calculation unit.
150 * @note If Programmable Initial CRC value feature
151 * is available, also set the Data Register to the value stored in the
152 * CRC_INIT register, otherwise, reset Data Register to its default value.
153 * @rmtoll CR RESET LL_CRC_ResetCRCCalculationUnit
154 * @param CRCx CRC Instance
157 __STATIC_INLINE
void LL_CRC_ResetCRCCalculationUnit(CRC_TypeDef
*CRCx
)
159 SET_BIT(CRCx
->CR
, CRC_CR_RESET
);
163 * @brief Configure size of the polynomial.
164 * @rmtoll CR POLYSIZE LL_CRC_SetPolynomialSize
165 * @param CRCx CRC Instance
166 * @param PolySize This parameter can be one of the following values:
167 * @arg @ref LL_CRC_POLYLENGTH_32B
168 * @arg @ref LL_CRC_POLYLENGTH_16B
169 * @arg @ref LL_CRC_POLYLENGTH_8B
170 * @arg @ref LL_CRC_POLYLENGTH_7B
173 __STATIC_INLINE
void LL_CRC_SetPolynomialSize(CRC_TypeDef
*CRCx
, uint32_t PolySize
)
175 MODIFY_REG(CRCx
->CR
, CRC_CR_POLYSIZE
, PolySize
);
179 * @brief Return size of the polynomial.
180 * @rmtoll CR POLYSIZE LL_CRC_GetPolynomialSize
181 * @param CRCx CRC Instance
182 * @retval Returned value can be one of the following values:
183 * @arg @ref LL_CRC_POLYLENGTH_32B
184 * @arg @ref LL_CRC_POLYLENGTH_16B
185 * @arg @ref LL_CRC_POLYLENGTH_8B
186 * @arg @ref LL_CRC_POLYLENGTH_7B
188 __STATIC_INLINE
uint32_t LL_CRC_GetPolynomialSize(CRC_TypeDef
*CRCx
)
190 return (uint32_t)(READ_BIT(CRCx
->CR
, CRC_CR_POLYSIZE
));
194 * @brief Configure the reversal of the bit order of the input data
195 * @rmtoll CR REV_IN LL_CRC_SetInputDataReverseMode
196 * @param CRCx CRC Instance
197 * @param ReverseMode This parameter can be one of the following values:
198 * @arg @ref LL_CRC_INDATA_REVERSE_NONE
199 * @arg @ref LL_CRC_INDATA_REVERSE_BYTE
200 * @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD
201 * @arg @ref LL_CRC_INDATA_REVERSE_WORD
204 __STATIC_INLINE
void LL_CRC_SetInputDataReverseMode(CRC_TypeDef
*CRCx
, uint32_t ReverseMode
)
206 MODIFY_REG(CRCx
->CR
, CRC_CR_REV_IN
, ReverseMode
);
210 * @brief Return type of reversal for input data bit order
211 * @rmtoll CR REV_IN LL_CRC_GetInputDataReverseMode
212 * @param CRCx CRC Instance
213 * @retval Returned value can be one of the following values:
214 * @arg @ref LL_CRC_INDATA_REVERSE_NONE
215 * @arg @ref LL_CRC_INDATA_REVERSE_BYTE
216 * @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD
217 * @arg @ref LL_CRC_INDATA_REVERSE_WORD
219 __STATIC_INLINE
uint32_t LL_CRC_GetInputDataReverseMode(CRC_TypeDef
*CRCx
)
221 return (uint32_t)(READ_BIT(CRCx
->CR
, CRC_CR_REV_IN
));
225 * @brief Configure the reversal of the bit order of the Output data
226 * @rmtoll CR REV_OUT LL_CRC_SetOutputDataReverseMode
227 * @param CRCx CRC Instance
228 * @param ReverseMode This parameter can be one of the following values:
229 * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
230 * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
233 __STATIC_INLINE
void LL_CRC_SetOutputDataReverseMode(CRC_TypeDef
*CRCx
, uint32_t ReverseMode
)
235 MODIFY_REG(CRCx
->CR
, CRC_CR_REV_OUT
, ReverseMode
);
239 * @brief Configure the reversal of the bit order of the Output data
240 * @rmtoll CR REV_OUT LL_CRC_GetOutputDataReverseMode
241 * @param CRCx CRC Instance
242 * @retval Returned value can be one of the following values:
243 * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
244 * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
246 __STATIC_INLINE
uint32_t LL_CRC_GetOutputDataReverseMode(CRC_TypeDef
*CRCx
)
248 return (uint32_t)(READ_BIT(CRCx
->CR
, CRC_CR_REV_OUT
));
252 * @brief Initialize the Programmable initial CRC value.
253 * @note If the CRC size is less than 32 bits, the least significant bits
254 * are used to write the correct value
255 * @note LL_CRC_DEFAULT_CRC_INITVALUE could be used as value for InitCrc parameter.
256 * @rmtoll INIT INIT LL_CRC_SetInitialData
257 * @param CRCx CRC Instance
258 * @param InitCrc Value to be programmed in Programmable initial CRC value register
261 __STATIC_INLINE
void LL_CRC_SetInitialData(CRC_TypeDef
*CRCx
, uint32_t InitCrc
)
263 WRITE_REG(CRCx
->INIT
, InitCrc
);
267 * @brief Return current Initial CRC value.
268 * @note If the CRC size is less than 32 bits, the least significant bits
269 * are used to read the correct value
270 * @rmtoll INIT INIT LL_CRC_GetInitialData
271 * @param CRCx CRC Instance
272 * @retval Value programmed in Programmable initial CRC value register
274 __STATIC_INLINE
uint32_t LL_CRC_GetInitialData(CRC_TypeDef
*CRCx
)
276 return (uint32_t)(READ_REG(CRCx
->INIT
));
280 * @brief Initialize the Programmable polynomial value
281 * (coefficients of the polynomial to be used for CRC calculation).
282 * @note LL_CRC_DEFAULT_CRC32_POLY could be used as value for PolynomCoef parameter.
283 * @note Please check Reference Manual and existing Errata Sheets,
284 * regarding possible limitations for Polynomial values usage.
285 * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
286 * @rmtoll POL POL LL_CRC_SetPolynomialCoef
287 * @param CRCx CRC Instance
288 * @param PolynomCoef Value to be programmed in Programmable Polynomial value register
291 __STATIC_INLINE
void LL_CRC_SetPolynomialCoef(CRC_TypeDef
*CRCx
, uint32_t PolynomCoef
)
293 WRITE_REG(CRCx
->POL
, PolynomCoef
);
297 * @brief Return current Programmable polynomial value
298 * @note Please check Reference Manual and existing Errata Sheets,
299 * regarding possible limitations for Polynomial values usage.
300 * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
301 * @rmtoll POL POL LL_CRC_GetPolynomialCoef
302 * @param CRCx CRC Instance
303 * @retval Value programmed in Programmable Polynomial value register
305 __STATIC_INLINE
uint32_t LL_CRC_GetPolynomialCoef(CRC_TypeDef
*CRCx
)
307 return (uint32_t)(READ_REG(CRCx
->POL
));
314 /** @defgroup CRC_LL_EF_Data_Management Data_Management
319 * @brief Write given 32-bit data to the CRC calculator
320 * @rmtoll DR DR LL_CRC_FeedData32
321 * @param CRCx CRC Instance
322 * @param InData value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFFFFFF
325 __STATIC_INLINE
void LL_CRC_FeedData32(CRC_TypeDef
*CRCx
, uint32_t InData
)
327 WRITE_REG(CRCx
->DR
, InData
);
331 * @brief Write given 16-bit data to the CRC calculator
332 * @rmtoll DR DR LL_CRC_FeedData16
333 * @param CRCx CRC Instance
334 * @param InData 16 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFF
337 __STATIC_INLINE
void LL_CRC_FeedData16(CRC_TypeDef
*CRCx
, uint16_t InData
)
341 pReg
= (__IO
uint16_t *)(__IO
void *)(&CRCx
->DR
); /* Derogation MisraC2012 R.11.5 */
346 * @brief Write given 8-bit data to the CRC calculator
347 * @rmtoll DR DR LL_CRC_FeedData8
348 * @param CRCx CRC Instance
349 * @param InData 8 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFF
352 __STATIC_INLINE
void LL_CRC_FeedData8(CRC_TypeDef
*CRCx
, uint8_t InData
)
354 *(uint8_t __IO
*)(&CRCx
->DR
) = (uint8_t) InData
;
358 * @brief Return current CRC calculation result. 32 bits value is returned.
359 * @rmtoll DR DR LL_CRC_ReadData32
360 * @param CRCx CRC Instance
361 * @retval Current CRC calculation result as stored in CRC_DR register (32 bits).
363 __STATIC_INLINE
uint32_t LL_CRC_ReadData32(CRC_TypeDef
*CRCx
)
365 return (uint32_t)(READ_REG(CRCx
->DR
));
369 * @brief Return current CRC calculation result. 16 bits value is returned.
370 * @note This function is expected to be used in a 16 bits CRC polynomial size context.
371 * @rmtoll DR DR LL_CRC_ReadData16
372 * @param CRCx CRC Instance
373 * @retval Current CRC calculation result as stored in CRC_DR register (16 bits).
375 __STATIC_INLINE
uint16_t LL_CRC_ReadData16(CRC_TypeDef
*CRCx
)
377 return (uint16_t)READ_REG(CRCx
->DR
);
381 * @brief Return current CRC calculation result. 8 bits value is returned.
382 * @note This function is expected to be used in a 8 bits CRC polynomial size context.
383 * @rmtoll DR DR LL_CRC_ReadData8
384 * @param CRCx CRC Instance
385 * @retval Current CRC calculation result as stored in CRC_DR register (8 bits).
387 __STATIC_INLINE
uint8_t LL_CRC_ReadData8(CRC_TypeDef
*CRCx
)
389 return (uint8_t)READ_REG(CRCx
->DR
);
393 * @brief Return current CRC calculation result. 7 bits value is returned.
394 * @note This function is expected to be used in a 7 bits CRC polynomial size context.
395 * @rmtoll DR DR LL_CRC_ReadData7
396 * @param CRCx CRC Instance
397 * @retval Current CRC calculation result as stored in CRC_DR register (7 bits).
399 __STATIC_INLINE
uint8_t LL_CRC_ReadData7(CRC_TypeDef
*CRCx
)
401 return (uint8_t)(READ_REG(CRCx
->DR
) & 0x7FU
);
405 * @brief Return data stored in the Independent Data(IDR) register.
406 * @note This register can be used as a temporary storage location for one 32-bit long data.
407 * @rmtoll IDR IDR LL_CRC_Read_IDR
408 * @param CRCx CRC Instance
409 * @retval Value stored in CRC_IDR register (General-purpose 32-bit data register).
411 __STATIC_INLINE
uint32_t LL_CRC_Read_IDR(CRC_TypeDef
*CRCx
)
413 return (uint32_t)(READ_REG(CRCx
->IDR
));
417 * @brief Store data in the Independent Data(IDR) register.
418 * @note This register can be used as a temporary storage location for one 32-bit long data.
419 * @rmtoll IDR IDR LL_CRC_Write_IDR
420 * @param CRCx CRC Instance
421 * @param InData value to be stored in CRC_IDR register (32-bit) between Min_Data=0 and Max_Data=0xFFFFFFFF
424 __STATIC_INLINE
void LL_CRC_Write_IDR(CRC_TypeDef
*CRCx
, uint32_t InData
)
426 *((uint32_t __IO
*)(&CRCx
->IDR
)) = (uint32_t) InData
;
432 #if defined(USE_FULL_LL_DRIVER)
433 /** @defgroup CRC_LL_EF_Init Initialization and de-initialization functions
437 ErrorStatus
LL_CRC_DeInit(CRC_TypeDef
*CRCx
);
442 #endif /* USE_FULL_LL_DRIVER */
452 #endif /* defined(CRC) */
462 #endif /* STM32H7xx_LL_CRC_H */
464 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/