stm32h7xx_hal_crc.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_crc.h
  4. * @author MCD Application Team
  5. * @brief Header file of CRC HAL 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_HAL_CRC_H
  20. #define STM32H7xx_HAL_CRC_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32h7xx_hal_def.h"
  26. /** @addtogroup STM32H7xx_HAL_Driver
  27. * @{
  28. */
  29. /** @addtogroup CRC
  30. * @{
  31. */
  32. /* Exported types ------------------------------------------------------------*/
  33. /** @defgroup CRC_Exported_Types CRC Exported Types
  34. * @{
  35. */
  36. /**
  37. * @brief CRC HAL State Structure definition
  38. */
  39. typedef enum
  40. {
  41. HAL_CRC_STATE_RESET = 0x00U, /*!< CRC not yet initialized or disabled */
  42. HAL_CRC_STATE_READY = 0x01U, /*!< CRC initialized and ready for use */
  43. HAL_CRC_STATE_BUSY = 0x02U, /*!< CRC internal process is ongoing */
  44. HAL_CRC_STATE_TIMEOUT = 0x03U, /*!< CRC timeout state */
  45. HAL_CRC_STATE_ERROR = 0x04U /*!< CRC error state */
  46. } HAL_CRC_StateTypeDef;
  47. /**
  48. * @brief CRC Init Structure definition
  49. */
  50. typedef struct
  51. {
  52. uint8_t DefaultPolynomialUse; /*!< This parameter is a value of @ref CRC_Default_Polynomial and indicates if default polynomial is used.
  53. If set to DEFAULT_POLYNOMIAL_ENABLE, resort to default
  54. X^32 + X^26 + X^23 + X^22 + X^16 + X^12 + X^11 + X^10 +X^8 + X^7 + X^5 +
  55. X^4 + X^2+ X +1.
  56. In that case, there is no need to set GeneratingPolynomial field.
  57. If otherwise set to DEFAULT_POLYNOMIAL_DISABLE, GeneratingPolynomial and
  58. CRCLength fields must be set. */
  59. uint8_t DefaultInitValueUse; /*!< This parameter is a value of @ref CRC_Default_InitValue_Use and indicates if default init value is used.
  60. If set to DEFAULT_INIT_VALUE_ENABLE, resort to default
  61. 0xFFFFFFFF value. In that case, there is no need to set InitValue field. If
  62. otherwise set to DEFAULT_INIT_VALUE_DISABLE, InitValue field must be set. */
  63. uint32_t GeneratingPolynomial; /*!< Set CRC generating polynomial as a 7, 8, 16 or 32-bit long value for a polynomial degree
  64. respectively equal to 7, 8, 16 or 32. This field is written in normal,
  65. representation e.g., for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1
  66. is written 0x65. No need to specify it if DefaultPolynomialUse is set to
  67. DEFAULT_POLYNOMIAL_ENABLE. */
  68. uint32_t CRCLength; /*!< This parameter is a value of @ref CRC_Polynomial_Sizes and indicates CRC length.
  69. Value can be either one of
  70. @arg @ref CRC_POLYLENGTH_32B (32-bit CRC),
  71. @arg @ref CRC_POLYLENGTH_16B (16-bit CRC),
  72. @arg @ref CRC_POLYLENGTH_8B (8-bit CRC),
  73. @arg @ref CRC_POLYLENGTH_7B (7-bit CRC). */
  74. uint32_t InitValue; /*!< Init value to initiate CRC computation. No need to specify it if DefaultInitValueUse
  75. is set to DEFAULT_INIT_VALUE_ENABLE. */
  76. uint32_t InputDataInversionMode; /*!< This parameter is a value of @ref CRCEx_Input_Data_Inversion and specifies input data inversion mode.
  77. Can be either one of the following values
  78. @arg @ref CRC_INPUTDATA_INVERSION_NONE no input data inversion
  79. @arg @ref CRC_INPUTDATA_INVERSION_BYTE byte-wise inversion, 0x1A2B3C4D
  80. becomes 0x58D43CB2
  81. @arg @ref CRC_INPUTDATA_INVERSION_HALFWORD halfword-wise inversion,
  82. 0x1A2B3C4D becomes 0xD458B23C
  83. @arg @ref CRC_INPUTDATA_INVERSION_WORD word-wise inversion, 0x1A2B3C4D
  84. becomes 0xB23CD458 */
  85. uint32_t OutputDataInversionMode; /*!< This parameter is a value of @ref CRCEx_Output_Data_Inversion and specifies output data (i.e. CRC) inversion mode.
  86. Can be either
  87. @arg @ref CRC_OUTPUTDATA_INVERSION_DISABLE no CRC inversion,
  88. @arg @ref CRC_OUTPUTDATA_INVERSION_ENABLE CRC 0x11223344 is converted
  89. into 0x22CC4488 */
  90. } CRC_InitTypeDef;
  91. /**
  92. * @brief CRC Handle Structure definition
  93. */
  94. typedef struct
  95. {
  96. CRC_TypeDef *Instance; /*!< Register base address */
  97. CRC_InitTypeDef Init; /*!< CRC configuration parameters */
  98. HAL_LockTypeDef Lock; /*!< CRC Locking object */
  99. __IO HAL_CRC_StateTypeDef State; /*!< CRC communication state */
  100. uint32_t InputDataFormat; /*!< This parameter is a value of @ref CRC_Input_Buffer_Format and specifies input data format.
  101. Can be either
  102. @arg @ref CRC_INPUTDATA_FORMAT_BYTES input data is a stream of bytes
  103. (8-bit data)
  104. @arg @ref CRC_INPUTDATA_FORMAT_HALFWORDS input data is a stream of
  105. half-words (16-bit data)
  106. @arg @ref CRC_INPUTDATA_FORMAT_WORDS input data is a stream of words
  107. (32-bit data)
  108. Note that constant CRC_INPUT_FORMAT_UNDEFINED is defined but an initialization
  109. error must occur if InputBufferFormat is not one of the three values listed
  110. above */
  111. } CRC_HandleTypeDef;
  112. /**
  113. * @}
  114. */
  115. /* Exported constants --------------------------------------------------------*/
  116. /** @defgroup CRC_Exported_Constants CRC Exported Constants
  117. * @{
  118. */
  119. /** @defgroup CRC_Default_Polynomial_Value Default CRC generating polynomial
  120. * @{
  121. */
  122. #define DEFAULT_CRC32_POLY 0x04C11DB7U /*!< 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 */
  123. /**
  124. * @}
  125. */
  126. /** @defgroup CRC_Default_InitValue Default CRC computation initialization value
  127. * @{
  128. */
  129. #define DEFAULT_CRC_INITVALUE 0xFFFFFFFFU /*!< Initial CRC default value */
  130. /**
  131. * @}
  132. */
  133. /** @defgroup CRC_Default_Polynomial Indicates whether or not default polynomial is used
  134. * @{
  135. */
  136. #define DEFAULT_POLYNOMIAL_ENABLE ((uint8_t)0x00U) /*!< Enable default generating polynomial 0x04C11DB7 */
  137. #define DEFAULT_POLYNOMIAL_DISABLE ((uint8_t)0x01U) /*!< Disable default generating polynomial 0x04C11DB7 */
  138. /**
  139. * @}
  140. */
  141. /** @defgroup CRC_Default_InitValue_Use Indicates whether or not default init value is used
  142. * @{
  143. */
  144. #define DEFAULT_INIT_VALUE_ENABLE ((uint8_t)0x00U) /*!< Enable initial CRC default value */
  145. #define DEFAULT_INIT_VALUE_DISABLE ((uint8_t)0x01U) /*!< Disable initial CRC default value */
  146. /**
  147. * @}
  148. */
  149. /** @defgroup CRC_Polynomial_Sizes Polynomial sizes to configure the peripheral
  150. * @{
  151. */
  152. #define CRC_POLYLENGTH_32B 0x00000000U /*!< Resort to a 32-bit long generating polynomial */
  153. #define CRC_POLYLENGTH_16B CRC_CR_POLYSIZE_0 /*!< Resort to a 16-bit long generating polynomial */
  154. #define CRC_POLYLENGTH_8B CRC_CR_POLYSIZE_1 /*!< Resort to a 8-bit long generating polynomial */
  155. #define CRC_POLYLENGTH_7B CRC_CR_POLYSIZE /*!< Resort to a 7-bit long generating polynomial */
  156. /**
  157. * @}
  158. */
  159. /** @defgroup CRC_Polynomial_Size_Definitions CRC polynomial possible sizes actual definitions
  160. * @{
  161. */
  162. #define HAL_CRC_LENGTH_32B 32U /*!< 32-bit long CRC */
  163. #define HAL_CRC_LENGTH_16B 16U /*!< 16-bit long CRC */
  164. #define HAL_CRC_LENGTH_8B 8U /*!< 8-bit long CRC */
  165. #define HAL_CRC_LENGTH_7B 7U /*!< 7-bit long CRC */
  166. /**
  167. * @}
  168. */
  169. /** @defgroup CRC_Input_Buffer_Format Input Buffer Format
  170. * @{
  171. */
  172. /* WARNING: CRC_INPUT_FORMAT_UNDEFINED is created for reference purposes but
  173. * an error is triggered in HAL_CRC_Init() if InputDataFormat field is set
  174. * to CRC_INPUT_FORMAT_UNDEFINED: the format MUST be defined by the user for
  175. * the CRC APIs to provide a correct result */
  176. #define CRC_INPUTDATA_FORMAT_UNDEFINED 0x00000000U /*!< Undefined input data format */
  177. #define CRC_INPUTDATA_FORMAT_BYTES 0x00000001U /*!< Input data in byte format */
  178. #define CRC_INPUTDATA_FORMAT_HALFWORDS 0x00000002U /*!< Input data in half-word format */
  179. #define CRC_INPUTDATA_FORMAT_WORDS 0x00000003U /*!< Input data in word format */
  180. /**
  181. * @}
  182. */
  183. /**
  184. * @}
  185. */
  186. /* Exported macros -----------------------------------------------------------*/
  187. /** @defgroup CRC_Exported_Macros CRC Exported Macros
  188. * @{
  189. */
  190. /** @brief Reset CRC handle state.
  191. * @param __HANDLE__ CRC handle.
  192. * @retval None
  193. */
  194. #define __HAL_CRC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRC_STATE_RESET)
  195. /**
  196. * @brief Reset CRC Data Register.
  197. * @param __HANDLE__ CRC handle
  198. * @retval None
  199. */
  200. #define __HAL_CRC_DR_RESET(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRC_CR_RESET)
  201. /**
  202. * @brief Set CRC INIT non-default value
  203. * @param __HANDLE__ CRC handle
  204. * @param __INIT__ 32-bit initial value
  205. * @retval None
  206. */
  207. #define __HAL_CRC_INITIALCRCVALUE_CONFIG(__HANDLE__, __INIT__) ((__HANDLE__)->Instance->INIT = (__INIT__))
  208. /**
  209. * @brief Store data in the Independent Data (ID) register.
  210. * @param __HANDLE__ CRC handle
  211. * @param __VALUE__ Value to be stored in the ID register
  212. * @note Refer to the Reference Manual to get the authorized __VALUE__ length in bits
  213. * @retval None
  214. */
  215. #define __HAL_CRC_SET_IDR(__HANDLE__, __VALUE__) (WRITE_REG((__HANDLE__)->Instance->IDR, (__VALUE__)))
  216. /**
  217. * @brief Return the data stored in the Independent Data (ID) register.
  218. * @param __HANDLE__ CRC handle
  219. * @note Refer to the Reference Manual to get the authorized __VALUE__ length in bits
  220. * @retval Value of the ID register
  221. */
  222. #define __HAL_CRC_GET_IDR(__HANDLE__) (((__HANDLE__)->Instance->IDR) & CRC_IDR_IDR)
  223. /**
  224. * @}
  225. */
  226. /* Private macros --------------------------------------------------------*/
  227. /** @defgroup CRC_Private_Macros CRC Private Macros
  228. * @{
  229. */
  230. #define IS_DEFAULT_POLYNOMIAL(DEFAULT) (((DEFAULT) == DEFAULT_POLYNOMIAL_ENABLE) || \
  231. ((DEFAULT) == DEFAULT_POLYNOMIAL_DISABLE))
  232. #define IS_DEFAULT_INIT_VALUE(VALUE) (((VALUE) == DEFAULT_INIT_VALUE_ENABLE) || \
  233. ((VALUE) == DEFAULT_INIT_VALUE_DISABLE))
  234. #define IS_CRC_POL_LENGTH(LENGTH) (((LENGTH) == CRC_POLYLENGTH_32B) || \
  235. ((LENGTH) == CRC_POLYLENGTH_16B) || \
  236. ((LENGTH) == CRC_POLYLENGTH_8B) || \
  237. ((LENGTH) == CRC_POLYLENGTH_7B))
  238. #define IS_CRC_INPUTDATA_FORMAT(FORMAT) (((FORMAT) == CRC_INPUTDATA_FORMAT_BYTES) || \
  239. ((FORMAT) == CRC_INPUTDATA_FORMAT_HALFWORDS) || \
  240. ((FORMAT) == CRC_INPUTDATA_FORMAT_WORDS))
  241. /**
  242. * @}
  243. */
  244. /* Include CRC HAL Extended module */
  245. #include "stm32h7xx_hal_crc_ex.h"
  246. /* Exported functions --------------------------------------------------------*/
  247. /** @defgroup CRC_Exported_Functions CRC Exported Functions
  248. * @{
  249. */
  250. /* Initialization and de-initialization functions ****************************/
  251. /** @defgroup CRC_Exported_Functions_Group1 Initialization and de-initialization functions
  252. * @{
  253. */
  254. HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc);
  255. HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc);
  256. void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc);
  257. void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc);
  258. /**
  259. * @}
  260. */
  261. /* Peripheral Control functions ***********************************************/
  262. /** @defgroup CRC_Exported_Functions_Group2 Peripheral Control functions
  263. * @{
  264. */
  265. uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength);
  266. uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength);
  267. /**
  268. * @}
  269. */
  270. /* Peripheral State and Error functions ***************************************/
  271. /** @defgroup CRC_Exported_Functions_Group3 Peripheral State functions
  272. * @{
  273. */
  274. HAL_CRC_StateTypeDef HAL_CRC_GetState(const CRC_HandleTypeDef *hcrc);
  275. /**
  276. * @}
  277. */
  278. /**
  279. * @}
  280. */
  281. /**
  282. * @}
  283. */
  284. /**
  285. * @}
  286. */
  287. #ifdef __cplusplus
  288. }
  289. #endif
  290. #endif /* STM32H7xx_HAL_CRC_H */