You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

502 lines
17 KiB

  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. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F0xx_LL_CRC_H
  37. #define __STM32F0xx_LL_CRC_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f0xx.h"
  43. /** @addtogroup STM32F0xx_LL_Driver
  44. * @{
  45. */
  46. #if defined(CRC)
  47. /** @defgroup CRC_LL CRC
  48. * @{
  49. */
  50. /* Private types -------------------------------------------------------------*/
  51. /* Private variables ---------------------------------------------------------*/
  52. /* Private constants ---------------------------------------------------------*/
  53. /* Private macros ------------------------------------------------------------*/
  54. /* Exported types ------------------------------------------------------------*/
  55. /* Exported constants --------------------------------------------------------*/
  56. /** @defgroup CRC_LL_Exported_Constants CRC Exported Constants
  57. * @{
  58. */
  59. #if defined(CRC_PROG_POLYNOMIAL_SUPPORT)
  60. /** @defgroup CRC_LL_EC_POLYLENGTH Polynomial length
  61. * @{
  62. */
  63. #define LL_CRC_POLYLENGTH_32B 0x00000000U /*!< 32 bits Polynomial size */
  64. #define LL_CRC_POLYLENGTH_16B CRC_CR_POLYSIZE_0 /*!< 16 bits Polynomial size */
  65. #define LL_CRC_POLYLENGTH_8B CRC_CR_POLYSIZE_1 /*!< 8 bits Polynomial size */
  66. #define LL_CRC_POLYLENGTH_7B (CRC_CR_POLYSIZE_1 | CRC_CR_POLYSIZE_0) /*!< 7 bits Polynomial size */
  67. /**
  68. * @}
  69. */
  70. #endif
  71. /** @defgroup CRC_LL_EC_INDATA_REVERSE Input Data Reverse
  72. * @{
  73. */
  74. #define LL_CRC_INDATA_REVERSE_NONE 0x00000000U /*!< Input Data bit order not affected */
  75. #define LL_CRC_INDATA_REVERSE_BYTE CRC_CR_REV_IN_0 /*!< Input Data bit reversal done by byte */
  76. #define LL_CRC_INDATA_REVERSE_HALFWORD CRC_CR_REV_IN_1 /*!< Input Data bit reversal done by half-word */
  77. #define LL_CRC_INDATA_REVERSE_WORD (CRC_CR_REV_IN_1 | CRC_CR_REV_IN_0) /*!< Input Data bit reversal done by word */
  78. /**
  79. * @}
  80. */
  81. /** @defgroup CRC_LL_EC_OUTDATA_REVERSE Output Data Reverse
  82. * @{
  83. */
  84. #define LL_CRC_OUTDATA_REVERSE_NONE 0x00000000U /*!< Output Data bit order not affected */
  85. #define LL_CRC_OUTDATA_REVERSE_BIT CRC_CR_REV_OUT /*!< Output Data bit reversal done by bit */
  86. /**
  87. * @}
  88. */
  89. #if defined(CRC_PROG_POLYNOMIAL_SUPPORT)
  90. /** @defgroup CRC_LL_EC_Default_Polynomial_Value Default CRC generating polynomial value
  91. * @brief Normal representation of this polynomial value is
  92. * 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 .
  93. * @{
  94. */
  95. #define LL_CRC_DEFAULT_CRC32_POLY 0x04C11DB7U /*!< Default CRC generating polynomial value */
  96. /**
  97. * @}
  98. */
  99. #endif
  100. /** @defgroup CRC_LL_EC_Default_InitValue Default CRC computation initialization value
  101. * @{
  102. */
  103. #define LL_CRC_DEFAULT_CRC_INITVALUE 0xFFFFFFFFU /*!< Default CRC computation initialization value */
  104. /**
  105. * @}
  106. */
  107. /**
  108. * @}
  109. */
  110. /* Exported macro ------------------------------------------------------------*/
  111. /** @defgroup CRC_LL_Exported_Macros CRC Exported Macros
  112. * @{
  113. */
  114. /** @defgroup CRC_LL_EM_WRITE_READ Common Write and read registers Macros
  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. * @brief Read a value in CRC register
  127. * @param __INSTANCE__ CRC Instance
  128. * @param __REG__ Register to be read
  129. * @retval Register value
  130. */
  131. #define LL_CRC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  132. /**
  133. * @}
  134. */
  135. /**
  136. * @}
  137. */
  138. /* Exported functions --------------------------------------------------------*/
  139. /** @defgroup CRC_LL_Exported_Functions CRC Exported Functions
  140. * @{
  141. */
  142. /** @defgroup CRC_LL_EF_Configuration CRC Configuration functions
  143. * @{
  144. */
  145. /**
  146. * @brief Reset the CRC calculation unit.
  147. * @note If Programmable Initial CRC value feature
  148. * is available, also set the Data Register to the value stored in the
  149. * CRC_INIT register, otherwise, reset Data Register to its default value.
  150. * @rmtoll CR RESET LL_CRC_ResetCRCCalculationUnit
  151. * @param CRCx CRC Instance
  152. * @retval None
  153. */
  154. __STATIC_INLINE void LL_CRC_ResetCRCCalculationUnit(CRC_TypeDef *CRCx)
  155. {
  156. SET_BIT(CRCx->CR, CRC_CR_RESET);
  157. }
  158. #if defined(CRC_PROG_POLYNOMIAL_SUPPORT)
  159. /**
  160. * @brief Configure size of the polynomial.
  161. * @note This function is available only on devices supporting
  162. * Programmable Polynomial feature.
  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
  170. * @retval None
  171. */
  172. __STATIC_INLINE void LL_CRC_SetPolynomialSize(CRC_TypeDef *CRCx, uint32_t PolySize)
  173. {
  174. MODIFY_REG(CRCx->CR, CRC_CR_POLYSIZE, PolySize);
  175. }
  176. /**
  177. * @brief Return size of the polynomial.
  178. * @note This function is available only on devices supporting
  179. * Programmable Polynomial feature.
  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
  187. */
  188. __STATIC_INLINE uint32_t LL_CRC_GetPolynomialSize(CRC_TypeDef *CRCx)
  189. {
  190. return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_POLYSIZE));
  191. }
  192. #endif
  193. /**
  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
  202. * @retval None
  203. */
  204. __STATIC_INLINE void LL_CRC_SetInputDataReverseMode(CRC_TypeDef *CRCx, uint32_t ReverseMode)
  205. {
  206. MODIFY_REG(CRCx->CR, CRC_CR_REV_IN, ReverseMode);
  207. }
  208. /**
  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
  217. */
  218. __STATIC_INLINE uint32_t LL_CRC_GetInputDataReverseMode(CRC_TypeDef *CRCx)
  219. {
  220. return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_REV_IN));
  221. }
  222. /**
  223. * @brief Configure the reversal of the bit order of the Output data
  224. * @rmtoll CR REV_OUT LL_CRC_SetOutputDataReverseMode
  225. * @param CRCx CRC Instance
  226. * @param ReverseMode This parameter can be one of the following values:
  227. * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
  228. * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
  229. * @retval None
  230. */
  231. __STATIC_INLINE void LL_CRC_SetOutputDataReverseMode(CRC_TypeDef *CRCx, uint32_t ReverseMode)
  232. {
  233. MODIFY_REG(CRCx->CR, CRC_CR_REV_OUT, ReverseMode);
  234. }
  235. /**
  236. * @brief Configure the reversal of the bit order of the Output data
  237. * @rmtoll CR REV_OUT LL_CRC_GetOutputDataReverseMode
  238. * @param CRCx CRC Instance
  239. * @retval Returned value can be one of the following values:
  240. * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
  241. * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
  242. */
  243. __STATIC_INLINE uint32_t LL_CRC_GetOutputDataReverseMode(CRC_TypeDef *CRCx)
  244. {
  245. return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_REV_OUT));
  246. }
  247. /**
  248. * @brief Initialize the Programmable initial CRC value.
  249. * @note If the CRC size is less than 32 bits, the least significant bits
  250. * are used to write the correct value
  251. * @note LL_CRC_DEFAULT_CRC_INITVALUE could be used as value for InitCrc parameter.
  252. * @rmtoll INIT INIT LL_CRC_SetInitialData
  253. * @param CRCx CRC Instance
  254. * @param InitCrc Value to be programmed in Programmable initial CRC value register
  255. * @retval None
  256. */
  257. __STATIC_INLINE void LL_CRC_SetInitialData(CRC_TypeDef *CRCx, uint32_t InitCrc)
  258. {
  259. WRITE_REG(CRCx->INIT, InitCrc);
  260. }
  261. /**
  262. * @brief Return current Initial CRC value.
  263. * @note If the CRC size is less than 32 bits, the least significant bits
  264. * are used to read the correct value
  265. * @rmtoll INIT INIT LL_CRC_GetInitialData
  266. * @param CRCx CRC Instance
  267. * @retval Value programmed in Programmable initial CRC value register
  268. */
  269. __STATIC_INLINE uint32_t LL_CRC_GetInitialData(CRC_TypeDef *CRCx)
  270. {
  271. return (uint32_t)(READ_REG(CRCx->INIT));
  272. }
  273. #if defined(CRC_PROG_POLYNOMIAL_SUPPORT)
  274. /**
  275. * @brief Initialize the Programmable polynomial value
  276. * (coefficients of the polynomial to be used for CRC calculation).
  277. * @note This function is available only on devices supporting
  278. * Programmable Polynomial feature.
  279. * @note LL_CRC_DEFAULT_CRC32_POLY could be used as value for PolynomCoef parameter.
  280. * @note Please check Reference Manual and existing Errata Sheets,
  281. * regarding possible limitations for Polynomial values usage.
  282. * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
  283. * @rmtoll POL POL LL_CRC_SetPolynomialCoef
  284. * @param CRCx CRC Instance
  285. * @param PolynomCoef Value to be programmed in Programmable Polynomial value register
  286. * @retval None
  287. */
  288. __STATIC_INLINE void LL_CRC_SetPolynomialCoef(CRC_TypeDef *CRCx, uint32_t PolynomCoef)
  289. {
  290. WRITE_REG(CRCx->POL, PolynomCoef);
  291. }
  292. /**
  293. * @brief Return current Programmable polynomial value
  294. * @note This function is available only on devices supporting
  295. * Programmable Polynomial feature.
  296. * @note Please check Reference Manual and existing Errata Sheets,
  297. * regarding possible limitations for Polynomial values usage.
  298. * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
  299. * @rmtoll POL POL LL_CRC_GetPolynomialCoef
  300. * @param CRCx CRC Instance
  301. * @retval Value programmed in Programmable Polynomial value register
  302. */
  303. __STATIC_INLINE uint32_t LL_CRC_GetPolynomialCoef(CRC_TypeDef *CRCx)
  304. {
  305. return (uint32_t)(READ_REG(CRCx->POL));
  306. }
  307. #endif
  308. /**
  309. * @}
  310. */
  311. /** @defgroup CRC_LL_EF_Data_Management Data_Management
  312. * @{
  313. */
  314. /**
  315. * @brief Write given 32-bit data to the CRC calculator
  316. * @rmtoll DR DR LL_CRC_FeedData32
  317. * @param CRCx CRC Instance
  318. * @param InData value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFFFFFF
  319. * @retval None
  320. */
  321. __STATIC_INLINE void LL_CRC_FeedData32(CRC_TypeDef *CRCx, uint32_t InData)
  322. {
  323. WRITE_REG(CRCx->DR, InData);
  324. }
  325. /**
  326. * @brief Write given 16-bit data to the CRC calculator
  327. * @rmtoll DR DR LL_CRC_FeedData16
  328. * @param CRCx CRC Instance
  329. * @param InData 16 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFF
  330. * @retval None
  331. */
  332. __STATIC_INLINE void LL_CRC_FeedData16(CRC_TypeDef *CRCx, uint16_t InData)
  333. {
  334. *(uint16_t __IO *)(&CRCx->DR) = (uint16_t) InData;
  335. }
  336. /**
  337. * @brief Write given 8-bit data to the CRC calculator
  338. * @rmtoll DR DR LL_CRC_FeedData8
  339. * @param CRCx CRC Instance
  340. * @param InData 8 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFF
  341. * @retval None
  342. */
  343. __STATIC_INLINE void LL_CRC_FeedData8(CRC_TypeDef *CRCx, uint8_t InData)
  344. {
  345. *(uint8_t __IO *)(&CRCx->DR) = (uint8_t) InData;
  346. }
  347. /**
  348. * @brief Return current CRC calculation result. 32 bits value is returned.
  349. * @rmtoll DR DR LL_CRC_ReadData32
  350. * @param CRCx CRC Instance
  351. * @retval Current CRC calculation result as stored in CRC_DR register (32 bits).
  352. */
  353. __STATIC_INLINE uint32_t LL_CRC_ReadData32(CRC_TypeDef *CRCx)
  354. {
  355. return (uint32_t)(READ_REG(CRCx->DR));
  356. }
  357. #if defined(CRC_PROG_POLYNOMIAL_SUPPORT)
  358. /**
  359. * @brief Return current CRC calculation result. 16 bits value is returned.
  360. * @note This function is expected to be used in a 16 bits CRC polynomial size context.
  361. * @note This function is available only on devices supporting
  362. * Programmable Polynomial feature.
  363. * @rmtoll DR DR LL_CRC_ReadData16
  364. * @param CRCx CRC Instance
  365. * @retval Current CRC calculation result as stored in CRC_DR register (16 bits).
  366. */
  367. __STATIC_INLINE uint16_t LL_CRC_ReadData16(CRC_TypeDef *CRCx)
  368. {
  369. return (uint16_t)READ_REG(CRCx->DR);
  370. }
  371. /**
  372. * @brief Return current CRC calculation result. 8 bits value is returned.
  373. * @note This function is expected to be used in a 8 bits CRC polynomial size context.
  374. * @note This function is available only on devices supporting
  375. * Programmable Polynomial feature.
  376. * @rmtoll DR DR LL_CRC_ReadData8
  377. * @param CRCx CRC Instance
  378. * @retval Current CRC calculation result as stored in CRC_DR register (8 bits).
  379. */
  380. __STATIC_INLINE uint8_t LL_CRC_ReadData8(CRC_TypeDef *CRCx)
  381. {
  382. return (uint8_t)READ_REG(CRCx->DR);
  383. }
  384. /**
  385. * @brief Return current CRC calculation result. 7 bits value is returned.
  386. * @note This function is expected to be used in a 7 bits CRC polynomial size context.
  387. * @note This function is available only on devices supporting
  388. * Programmable Polynomial feature.
  389. * @rmtoll DR DR LL_CRC_ReadData7
  390. * @param CRCx CRC Instance
  391. * @retval Current CRC calculation result as stored in CRC_DR register (7 bits).
  392. */
  393. __STATIC_INLINE uint8_t LL_CRC_ReadData7(CRC_TypeDef *CRCx)
  394. {
  395. return (uint8_t)(READ_REG(CRCx->DR) & 0x7FU);
  396. }
  397. #endif
  398. /**
  399. * @brief Return data stored in the Independent Data(IDR) register.
  400. * @note This register can be used as a temporary storage location for one byte.
  401. * @rmtoll IDR IDR LL_CRC_Read_IDR
  402. * @param CRCx CRC Instance
  403. * @retval Value stored in CRC_IDR register (General-purpose 8-bit data register).
  404. */
  405. __STATIC_INLINE uint32_t LL_CRC_Read_IDR(CRC_TypeDef *CRCx)
  406. {
  407. return (uint32_t)(READ_REG(CRCx->IDR));
  408. }
  409. /**
  410. * @brief Store data in the Independent Data(IDR) register.
  411. * @note This register can be used as a temporary storage location for one byte.
  412. * @rmtoll IDR IDR LL_CRC_Write_IDR
  413. * @param CRCx CRC Instance
  414. * @param InData value to be stored in CRC_IDR register (8-bit) between between Min_Data=0 and Max_Data=0xFF
  415. * @retval None
  416. */
  417. __STATIC_INLINE void LL_CRC_Write_IDR(CRC_TypeDef *CRCx, uint32_t InData)
  418. {
  419. *((uint8_t __IO *)(&CRCx->IDR)) = (uint8_t) InData;
  420. }
  421. /**
  422. * @}
  423. */
  424. #if defined(USE_FULL_LL_DRIVER)
  425. /** @defgroup CRC_LL_EF_Init Initialization and de-initialization functions
  426. * @{
  427. */
  428. ErrorStatus LL_CRC_DeInit(CRC_TypeDef *CRCx);
  429. /**
  430. * @}
  431. */
  432. #endif /* USE_FULL_LL_DRIVER */
  433. /**
  434. * @}
  435. */
  436. /**
  437. * @}
  438. */
  439. #endif /* defined(CRC) */
  440. /**
  441. * @}
  442. */
  443. #ifdef __cplusplus
  444. }
  445. #endif
  446. #endif /* __STM32F0xx_LL_CRC_H */
  447. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/