stm32h7xx_ll_crc.h 16 KB

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