stm32f7xx_hal_crc.h 16 KB

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