stm32f7xx_hal_crc.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_crc.h
  4. * @author MCD Application Team
  5. * @version V1.2.0
  6. * @date 30-December-2016
  7. * @brief Header file of CRC HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F7xx_HAL_CRC_H
  39. #define __STM32F7xx_HAL_CRC_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. /** @addtogroup STM32F7xx_HAL_Driver
  46. * @{
  47. */
  48. /** @defgroup CRC CRC
  49. * @brief CRC HAL module driver
  50. * @{
  51. */
  52. /* Exported types ------------------------------------------------------------*/
  53. /** @defgroup CRC_Exported_Types CRC Exported Types
  54. * @{
  55. */
  56. /** @defgroup CRC_Exported_Types_Group1 CRC State Structure definition
  57. * @{
  58. */
  59. typedef enum
  60. {
  61. HAL_CRC_STATE_RESET = 0x00U, /*!< CRC not yet initialized or disabled */
  62. HAL_CRC_STATE_READY = 0x01U, /*!< CRC initialized and ready for use */
  63. HAL_CRC_STATE_BUSY = 0x02U, /*!< CRC internal process is ongoing */
  64. HAL_CRC_STATE_TIMEOUT = 0x03U, /*!< CRC timeout state */
  65. HAL_CRC_STATE_ERROR = 0x04U /*!< CRC error state */
  66. }HAL_CRC_StateTypeDef;
  67. /**
  68. * @}
  69. */
  70. /** @defgroup CRC_Exported_Types_Group2 CRC Init Structure definition
  71. * @{
  72. */
  73. typedef struct
  74. {
  75. uint8_t DefaultPolynomialUse; /*!< This parameter is a value of @ref CRC_Default_Polynomial and indicates if default polynomial is used.
  76. If set to DEFAULT_POLYNOMIAL_ENABLE, resort to default
  77. 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.
  78. In that case, there is no need to set GeneratingPolynomial field.
  79. If otherwise set to DEFAULT_POLYNOMIAL_DISABLE, GeneratingPolynomial and CRCLength fields must be set */
  80. uint8_t DefaultInitValueUse; /*!< This parameter is a value of @ref CRC_Default_InitValue_Use and indicates if default init value is used.
  81. If set to DEFAULT_INIT_VALUE_ENABLE, resort to default
  82. 0xFFFFFFFF value. In that case, there is no need to set InitValue field.
  83. If otherwise set to DEFAULT_INIT_VALUE_DISABLE, InitValue field must be set */
  84. uint32_t GeneratingPolynomial; /*!< Set CRC generating polynomial. 7, 8, 16 or 32-bit long value for a polynomial degree
  85. respectively equal to 7, 8, 16 or 32. This field is written in normal representation,
  86. e.g., for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65.
  87. No need to specify it if DefaultPolynomialUse is set to DEFAULT_POLYNOMIAL_ENABLE */
  88. uint32_t CRCLength; /*!< This parameter is a value of @ref CRC_Polynomial_Sizes and indicates CRC length.
  89. Value can be either one of
  90. CRC_POLYLENGTH_32B (32-bit CRC)
  91. CRC_POLYLENGTH_16B (16-bit CRC)
  92. CRC_POLYLENGTH_8B (8-bit CRC)
  93. CRC_POLYLENGTH_7B (7-bit CRC) */
  94. uint32_t InitValue; /*!< Init value to initiate CRC computation. No need to specify it if DefaultInitValueUse
  95. is set to DEFAULT_INIT_VALUE_ENABLE */
  96. uint32_t InputDataInversionMode; /*!< This parameter is a value of @ref CRCEx_Input_Data_Inversion and specifies input data inversion mode.
  97. Can be either one of the following values
  98. CRC_INPUTDATA_INVERSION_NONE no input data inversion
  99. CRC_INPUTDATA_INVERSION_BYTE byte-wise inversion, 0x1A2B3C4D becomes 0x58D43CB2
  100. CRC_INPUTDATA_INVERSION_HALFWORD halfword-wise inversion, 0x1A2B3C4D becomes 0xD458B23C
  101. CRC_INPUTDATA_INVERSION_WORD word-wise inversion, 0x1A2B3C4D becomes 0xB23CD458 */
  102. uint32_t OutputDataInversionMode; /*!< This parameter is a value of @ref CRCEx_Output_Data_Inversion and specifies output data (i.e. CRC) inversion mode.
  103. Can be either
  104. CRC_OUTPUTDATA_INVERSION_DISABLE no CRC inversion, or
  105. CRC_OUTPUTDATA_INVERSION_ENABLE CRC 0x11223344 is converted into 0x22CC4488 */
  106. }CRC_InitTypeDef;
  107. /**
  108. * @}
  109. */
  110. /** @defgroup CRC_Exported_Types_Group3 CRC Handle Structure definition
  111. * @{
  112. */
  113. typedef struct
  114. {
  115. CRC_TypeDef *Instance; /*!< Register base address */
  116. CRC_InitTypeDef Init; /*!< CRC configuration parameters */
  117. HAL_LockTypeDef Lock; /*!< CRC Locking object */
  118. __IO HAL_CRC_StateTypeDef State; /*!< CRC communication state */
  119. uint32_t InputDataFormat; /*!< This parameter is a value of @ref CRC_Input_Buffer_Format and specifies input data format.
  120. Can be either
  121. CRC_INPUTDATA_FORMAT_BYTES input data is a stream of bytes (8-bit data)
  122. CRC_INPUTDATA_FORMAT_HALFWORDS input data is a stream of half-words (16-bit data)
  123. CRC_INPUTDATA_FORMAT_WORDS input data is a stream of words (32-bits data)
  124. Note that constant CRC_INPUT_FORMAT_UNDEFINED is defined but an initialization error
  125. must occur if InputBufferFormat is not one of the three values listed above */
  126. }CRC_HandleTypeDef;
  127. /**
  128. * @}
  129. */
  130. /**
  131. * @}
  132. */
  133. /* Exported constants --------------------------------------------------------*/
  134. /** @defgroup CRC_Exported_Constants CRC exported constants
  135. * @{
  136. */
  137. /** @defgroup CRC_Default_Polynomial_Value Default CRC generating polynomial
  138. * @{
  139. */
  140. #define DEFAULT_CRC32_POLY 0x04C11DB7U
  141. /**
  142. * @}
  143. */
  144. /** @defgroup CRC_Default_InitValue Default CRC computation initialization value
  145. * @{
  146. */
  147. #define DEFAULT_CRC_INITVALUE 0xFFFFFFFFU
  148. /**
  149. * @}
  150. */
  151. /** @defgroup CRC_Default_Polynomial Indicates whether or not default polynomial is used
  152. * @{
  153. */
  154. #define DEFAULT_POLYNOMIAL_ENABLE ((uint8_t)0x00U)
  155. #define DEFAULT_POLYNOMIAL_DISABLE ((uint8_t)0x01U)
  156. /**
  157. * @}
  158. */
  159. /** @defgroup CRC_Default_InitValue_Use Indicates whether or not default init value is used
  160. * @{
  161. */
  162. #define DEFAULT_INIT_VALUE_ENABLE ((uint8_t)0x00U)
  163. #define DEFAULT_INIT_VALUE_DISABLE ((uint8_t)0x01U)
  164. /**
  165. * @}
  166. */
  167. /** @defgroup CRC_Polynomial_Sizes Polynomial sizes to configure the IP
  168. * @{
  169. */
  170. #define CRC_POLYLENGTH_32B ((uint32_t)0x00000000U)
  171. #define CRC_POLYLENGTH_16B ((uint32_t)CRC_CR_POLYSIZE_0)
  172. #define CRC_POLYLENGTH_8B ((uint32_t)CRC_CR_POLYSIZE_1)
  173. #define CRC_POLYLENGTH_7B ((uint32_t)CRC_CR_POLYSIZE)
  174. /**
  175. * @}
  176. */
  177. /** @defgroup CRC_Polynomial_Size_Definitions CRC polynomial possible sizes actual definitions
  178. * @{
  179. */
  180. #define HAL_CRC_LENGTH_32B 32U
  181. #define HAL_CRC_LENGTH_16B 16U
  182. #define HAL_CRC_LENGTH_8B 8U
  183. #define HAL_CRC_LENGTH_7B 7U
  184. /**
  185. * @}
  186. */
  187. /** @defgroup CRC_Input_Buffer_Format CRC input buffer format
  188. * @{
  189. */
  190. /* WARNING: CRC_INPUT_FORMAT_UNDEFINED is created for reference purposes but
  191. * an error is triggered in HAL_CRC_Init() if InputDataFormat field is set
  192. * to CRC_INPUT_FORMAT_UNDEFINED: the format MUST be defined by the user for
  193. * the CRC APIs to provide a correct result */
  194. #define CRC_INPUTDATA_FORMAT_UNDEFINED ((uint32_t)0x00000000U)
  195. #define CRC_INPUTDATA_FORMAT_BYTES ((uint32_t)0x00000001U)
  196. #define CRC_INPUTDATA_FORMAT_HALFWORDS ((uint32_t)0x00000002U)
  197. #define CRC_INPUTDATA_FORMAT_WORDS ((uint32_t)0x00000003U)
  198. /**
  199. * @}
  200. */
  201. /**
  202. * @}
  203. */
  204. /* Exported macros -----------------------------------------------------------*/
  205. /** @defgroup CRC_Exported_Macros CRC exported macros
  206. * @{
  207. */
  208. /** @brief Reset CRC handle state
  209. * @param __HANDLE__: CRC handle.
  210. * @retval None
  211. */
  212. #define __HAL_CRC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRC_STATE_RESET)
  213. /**
  214. * @brief Reset CRC Data Register.
  215. * @param __HANDLE__: CRC handle
  216. * @retval None.
  217. */
  218. #define __HAL_CRC_DR_RESET(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRC_CR_RESET)
  219. /**
  220. * @brief Set CRC INIT non-default value
  221. * @param __HANDLE__ : CRC handle
  222. * @param __INIT__ : 32-bit initial value
  223. * @retval None.
  224. */
  225. #define __HAL_CRC_INITIALCRCVALUE_CONFIG(__HANDLE__, __INIT__) ((__HANDLE__)->Instance->INIT = (__INIT__))
  226. /**
  227. * @brief Stores a 8-bit data in the Independent Data(ID) register.
  228. * @param __HANDLE__: CRC handle
  229. * @param __VALUE__: 8-bit value to be stored in the ID register
  230. * @retval None
  231. */
  232. #define __HAL_CRC_SET_IDR(__HANDLE__, __VALUE__) (WRITE_REG((__HANDLE__)->Instance->IDR, CRC_IDR_IDR, (__VALUE__)))
  233. /**
  234. * @brief Returns the 8-bit data stored in the Independent Data(ID) register.
  235. * @param __HANDLE__: CRC handle
  236. * @retval 8-bit value of the ID register
  237. */
  238. #define __HAL_CRC_GET_IDR(__HANDLE__) (((__HANDLE__)->Instance->IDR) & CRC_IDR_IDR)
  239. /**
  240. * @}
  241. */
  242. /* Include CRC HAL Extension module */
  243. #include "stm32f7xx_hal_crc_ex.h"
  244. /* Exported functions --------------------------------------------------------*/
  245. /** @defgroup CRC_Exported_Functions CRC Exported Functions
  246. * @{
  247. */
  248. /** @defgroup CRC_Exported_Functions_Group1 Initialization/de-initialization functions
  249. * @{
  250. */
  251. /* Initialization and de-initialization functions ****************************/
  252. HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc);
  253. HAL_StatusTypeDef HAL_CRC_DeInit (CRC_HandleTypeDef *hcrc);
  254. void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc);
  255. void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc);
  256. /**
  257. * @}
  258. */
  259. /* Aliases for inter STM32 series compatibility */
  260. #define HAL_CRC_Input_Data_Reverse HAL_CRCEx_Input_Data_Reverse
  261. #define HAL_CRC_Output_Data_Reverse HAL_CRCEx_Output_Data_Reverse
  262. /** @defgroup CRC_Exported_Functions_Group2 Peripheral Control functions
  263. * @{
  264. */
  265. /* Peripheral Control functions ***********************************************/
  266. uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength);
  267. uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength);
  268. /**
  269. * @}
  270. */
  271. /** @defgroup CRC_Exported_Functions_Group3 Peripheral State functions
  272. * @{
  273. */
  274. /* Peripheral State and Error functions ***************************************/
  275. HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc);
  276. /**
  277. * @}
  278. */
  279. /**
  280. * @}
  281. */
  282. /* Private types -------------------------------------------------------------*/
  283. /** @defgroup CRC_Private_Types CRC Private Types
  284. * @{
  285. */
  286. /**
  287. * @}
  288. */
  289. /* Private defines -----------------------------------------------------------*/
  290. /** @defgroup CRC_Private_Defines CRC Private Defines
  291. * @{
  292. */
  293. /**
  294. * @}
  295. */
  296. /* Private variables ---------------------------------------------------------*/
  297. /** @defgroup CRC_Private_Variables CRC Private Variables
  298. * @{
  299. */
  300. /**
  301. * @}
  302. */
  303. /* Private constants ---------------------------------------------------------*/
  304. /** @defgroup CRC_Private_Constants CRC Private Constants
  305. * @{
  306. */
  307. /**
  308. * @}
  309. */
  310. /* Private macros ------------------------------------------------------------*/
  311. /** @defgroup CRC_Private_Macros CRC Private Macros
  312. * @{
  313. */
  314. #define IS_DEFAULT_POLYNOMIAL(__DEFAULT__) (((__DEFAULT__) == DEFAULT_POLYNOMIAL_ENABLE) || \
  315. ((__DEFAULT__) == DEFAULT_POLYNOMIAL_DISABLE))
  316. #define IS_DEFAULT_INIT_VALUE(__VALUE__) (((__VALUE__) == DEFAULT_INIT_VALUE_ENABLE) || \
  317. ((__VALUE__) == DEFAULT_INIT_VALUE_DISABLE))
  318. #define IS_CRC_POL_LENGTH(__LENGTH__) (((__LENGTH__) == CRC_POLYLENGTH_32B) || \
  319. ((__LENGTH__) == CRC_POLYLENGTH_16B) || \
  320. ((__LENGTH__) == CRC_POLYLENGTH_8B) || \
  321. ((__LENGTH__) == CRC_POLYLENGTH_7B))
  322. #define IS_CRC_INPUTDATA_FORMAT(__FORMAT__) (((__FORMAT__) == CRC_INPUTDATA_FORMAT_BYTES) || \
  323. ((__FORMAT__) == CRC_INPUTDATA_FORMAT_HALFWORDS) || \
  324. ((__FORMAT__) == CRC_INPUTDATA_FORMAT_WORDS))
  325. /**
  326. * @}
  327. */
  328. /* Private functions prototypes ----------------------------------------------*/
  329. /** @defgroup CRC_Private_Functions_Prototypes CRC Private Functions Prototypes
  330. * @{
  331. */
  332. /**
  333. * @}
  334. */
  335. /* Private functions ---------------------------------------------------------*/
  336. /** @defgroup CRC_Private_Functions CRC Private Functions
  337. * @{
  338. */
  339. /**
  340. * @}
  341. */
  342. /**
  343. * @}
  344. */
  345. /**
  346. * @}
  347. */
  348. #ifdef __cplusplus
  349. }
  350. #endif
  351. #endif /* __STM32F7xx_HAL_CRC_H */
  352. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/