STM32L486xx HAL User Manual
stm32l4xx_hal_crc.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_crc.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of CRC HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00010   *
00011   * Redistribution and use in source and binary forms, with or without modification,
00012   * are permitted provided that the following conditions are met:
00013   *   1. Redistributions of source code must retain the above copyright notice,
00014   *      this list of conditions and the following disclaimer.
00015   *   2. Redistributions in binary form must reproduce the above copyright notice,
00016   *      this list of conditions and the following disclaimer in the documentation
00017   *      and/or other materials provided with the distribution.
00018   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019   *      may be used to endorse or promote products derived from this software
00020   *      without specific prior written permission.
00021   *
00022   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032   *
00033   ******************************************************************************
00034   */
00035 
00036 /* Define to prevent recursive inclusion -------------------------------------*/
00037 #ifndef __STM32L4xx_HAL_CRC_H
00038 #define __STM32L4xx_HAL_CRC_H
00039 
00040 #ifdef __cplusplus
00041 extern "C" {
00042 #endif
00043 
00044 /* Includes ------------------------------------------------------------------*/
00045 #include "stm32l4xx_hal_def.h"
00046 
00047 /** @addtogroup STM32L4xx_HAL_Driver
00048   * @{
00049   */
00050 
00051 /** @addtogroup CRC
00052   * @{
00053   */
00054 
00055 /* Exported types ------------------------------------------------------------*/
00056 /** @defgroup CRC_Exported_Types CRC Exported Types
00057   * @{
00058   */
00059 
00060 /**
00061   * @brief  CRC HAL State Structure definition
00062   */
00063 typedef enum
00064 {
00065   HAL_CRC_STATE_RESET     = 0x00U,  /*!< CRC not yet initialized or disabled */
00066   HAL_CRC_STATE_READY     = 0x01U,  /*!< CRC initialized and ready for use   */
00067   HAL_CRC_STATE_BUSY      = 0x02U,  /*!< CRC internal process is ongoing     */
00068   HAL_CRC_STATE_TIMEOUT   = 0x03U,  /*!< CRC timeout state                   */
00069   HAL_CRC_STATE_ERROR     = 0x04U   /*!< CRC error state                     */
00070 } HAL_CRC_StateTypeDef;
00071 
00072 /**
00073   * @brief CRC Init Structure definition
00074   */
00075 typedef struct
00076 {
00077   uint8_t DefaultPolynomialUse;       /*!< This parameter is a value of @ref CRC_Default_Polynomial and indicates if default polynomial is used.
00078                                             If set to DEFAULT_POLYNOMIAL_ENABLE, resort to default
00079                                             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.
00080                                             In that case, there is no need to set GeneratingPolynomial field.
00081                                             If otherwise set to DEFAULT_POLYNOMIAL_DISABLE, GeneratingPolynomial and CRCLength fields must be set. */
00082 
00083   uint8_t DefaultInitValueUse;        /*!< This parameter is a value of @ref CRC_Default_InitValue_Use and indicates if default init value is used.
00084                                            If set to DEFAULT_INIT_VALUE_ENABLE, resort to default
00085                                            0xFFFFFFFF value. In that case, there is no need to set InitValue field.
00086                                            If otherwise set to DEFAULT_INIT_VALUE_DISABLE,  InitValue field must be set. */
00087 
00088   uint32_t GeneratingPolynomial;      /*!< Set CRC generating polynomial as a 7, 8, 16 or 32-bit long value for a polynomial degree
00089                                            respectively equal to 7, 8, 16 or 32. This field is written in normal representation,
00090                                            e.g., for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65.
00091                                            No need to specify it if DefaultPolynomialUse is set to DEFAULT_POLYNOMIAL_ENABLE.   */
00092 
00093   uint32_t CRCLength;                 /*!< This parameter is a value of @ref CRC_Polynomial_Sizes and indicates CRC length.
00094                                            Value can be either one of
00095                                            @arg @ref CRC_POLYLENGTH_32B                  (32-bit CRC),
00096                                            @arg @ref CRC_POLYLENGTH_16B                  (16-bit CRC),
00097                                            @arg @ref CRC_POLYLENGTH_8B                   (8-bit CRC),
00098                                            @arg @ref CRC_POLYLENGTH_7B                   (7-bit CRC). */
00099 
00100   uint32_t InitValue;                 /*!< Init value to initiate CRC computation. No need to specify it if DefaultInitValueUse
00101                                            is set to DEFAULT_INIT_VALUE_ENABLE.   */
00102 
00103   uint32_t InputDataInversionMode;    /*!< This parameter is a value of @ref CRCEx_Input_Data_Inversion and specifies input data inversion mode.
00104                                            Can be either one of the following values
00105                                            @arg @ref CRC_INPUTDATA_INVERSION_NONE       no input data inversion
00106                                            @arg @ref CRC_INPUTDATA_INVERSION_BYTE       byte-wise inversion, 0x1A2B3C4D becomes 0x58D43CB2
00107                                            @arg @ref CRC_INPUTDATA_INVERSION_HALFWORD   halfword-wise inversion, 0x1A2B3C4D becomes 0xD458B23C
00108                                            @arg @ref CRC_INPUTDATA_INVERSION_WORD       word-wise inversion, 0x1A2B3C4D becomes 0xB23CD458 */
00109 
00110   uint32_t OutputDataInversionMode;   /*!< This parameter is a value of @ref CRCEx_Output_Data_Inversion and specifies output data (i.e. CRC) inversion mode.
00111                                             Can be either
00112                                             @arg @ref CRC_OUTPUTDATA_INVERSION_DISABLE   no CRC inversion,
00113                                             @arg @ref CRC_OUTPUTDATA_INVERSION_ENABLE    CRC 0x11223344 is converted into 0x22CC4488 */
00114 } CRC_InitTypeDef;
00115 
00116 /**
00117   * @brief  CRC Handle Structure definition
00118   */
00119 typedef struct
00120 {
00121   CRC_TypeDef                 *Instance;   /*!< Register base address        */
00122 
00123   CRC_InitTypeDef             Init;        /*!< CRC configuration parameters */
00124 
00125   HAL_LockTypeDef             Lock;        /*!< CRC Locking object           */
00126 
00127   __IO HAL_CRC_StateTypeDef   State;       /*!< CRC communication state      */
00128 
00129   uint32_t InputDataFormat;                /*!< This parameter is a value of @ref CRC_Input_Buffer_Format and specifies input data format.
00130                                             Can be either
00131                                             @arg @ref CRC_INPUTDATA_FORMAT_BYTES       input data is a stream of bytes (8-bit data)
00132                                             @arg @ref CRC_INPUTDATA_FORMAT_HALFWORDS   input data is a stream of half-words (16-bit data)
00133                                             @arg @ref CRC_INPUTDATA_FORMAT_WORDS       input data is a stream of words (32-bit data)
00134 
00135                                            Note that constant CRC_INPUT_FORMAT_UNDEFINED is defined but an initialization error
00136                                            must occur if InputBufferFormat is not one of the three values listed above  */
00137 } CRC_HandleTypeDef;
00138 /**
00139   * @}
00140   */
00141 
00142 /* Exported constants --------------------------------------------------------*/
00143 /** @defgroup CRC_Exported_Constants CRC Exported Constants
00144   * @{
00145   */
00146 
00147 /** @defgroup CRC_Default_Polynomial_Value    Default CRC generating polynomial
00148   * @{
00149   */
00150 #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 */
00151 /**
00152   * @}
00153   */
00154 
00155 /** @defgroup CRC_Default_InitValue    Default CRC computation initialization value
00156   * @{
00157   */
00158 #define DEFAULT_CRC_INITVALUE   0xFFFFFFFFU  /*!< Initial CRC default value */
00159 /**
00160   * @}
00161   */
00162 
00163 /** @defgroup CRC_Default_Polynomial    Indicates whether or not default polynomial is used
00164   * @{
00165   */
00166 #define DEFAULT_POLYNOMIAL_ENABLE       ((uint8_t)0x00U)  /*!< Enable default generating polynomial 0x04C11DB7  */
00167 #define DEFAULT_POLYNOMIAL_DISABLE      ((uint8_t)0x01U)  /*!< Disable default generating polynomial 0x04C11DB7 */
00168 /**
00169   * @}
00170   */
00171 
00172 /** @defgroup CRC_Default_InitValue_Use    Indicates whether or not default init value is used
00173   * @{
00174   */
00175 #define DEFAULT_INIT_VALUE_ENABLE      ((uint8_t)0x00U) /*!< Enable initial CRC default value  */
00176 #define DEFAULT_INIT_VALUE_DISABLE     ((uint8_t)0x01U) /*!< Disable initial CRC default value */
00177 /**
00178   * @}
00179   */
00180 
00181 /** @defgroup CRC_Polynomial_Sizes Polynomial sizes to configure the IP
00182   * @{
00183   */
00184 #define CRC_POLYLENGTH_32B                  0x00000000U        /*!< Resort to a 32-bit long generating polynomial */
00185 #define CRC_POLYLENGTH_16B                  CRC_CR_POLYSIZE_0  /*!< Resort to a 16-bit long generating polynomial */
00186 #define CRC_POLYLENGTH_8B                   CRC_CR_POLYSIZE_1  /*!< Resort to a 8-bit long generating polynomial  */
00187 #define CRC_POLYLENGTH_7B                   CRC_CR_POLYSIZE    /*!< Resort to a 7-bit long generating polynomial  */
00188 /**
00189   * @}
00190   */
00191 
00192 /** @defgroup CRC_Polynomial_Size_Definitions CRC polynomial possible sizes actual definitions
00193   * @{
00194   */
00195 #define HAL_CRC_LENGTH_32B     32U          /*!< 32-bit long CRC */
00196 #define HAL_CRC_LENGTH_16B     16U          /*!< 16-bit long CRC */
00197 #define HAL_CRC_LENGTH_8B       8U          /*!< 8-bit long CRC  */
00198 #define HAL_CRC_LENGTH_7B       7U          /*!< 7-bit long CRC  */
00199 /**
00200   * @}
00201   */
00202 
00203 /** @defgroup CRC_Input_Buffer_Format Input Buffer Format
00204   * @{
00205   */
00206 /* WARNING: CRC_INPUT_FORMAT_UNDEFINED is created for reference purposes but
00207  * an error is triggered in HAL_CRC_Init() if InputDataFormat field is set
00208  * to CRC_INPUT_FORMAT_UNDEFINED: the format MUST be defined by the user for
00209  * the CRC APIs to provide a correct result */
00210 #define CRC_INPUTDATA_FORMAT_UNDEFINED             0x00000000U  /*!< Undefined input data format    */
00211 #define CRC_INPUTDATA_FORMAT_BYTES                 0x00000001U  /*!< Input data in byte format      */
00212 #define CRC_INPUTDATA_FORMAT_HALFWORDS             0x00000002U  /*!< Input data in half-word format */
00213 #define CRC_INPUTDATA_FORMAT_WORDS                 0x00000003U  /*!< Input data in word format      */
00214 /**
00215   * @}
00216   */
00217 
00218 /** @defgroup CRC_Aliases CRC API aliases
00219   * @{
00220   */
00221 #define HAL_CRC_Input_Data_Reverse   HAL_CRCEx_Input_Data_Reverse    /*!< Aliased to HAL_CRCEx_Input_Data_Reverse for inter STM32 series compatibility  */
00222 #define HAL_CRC_Output_Data_Reverse  HAL_CRCEx_Output_Data_Reverse   /*!< Aliased to HAL_CRCEx_Output_Data_Reverse for inter STM32 series compatibility */
00223 /**
00224   * @}
00225   */
00226 
00227 /**
00228   * @}
00229   */
00230 
00231 /* Exported macros -----------------------------------------------------------*/
00232 /** @defgroup CRC_Exported_Macros CRC Exported Macros
00233   * @{
00234   */
00235 
00236 /** @brief Reset CRC handle state.
00237   * @param  __HANDLE__ CRC handle.
00238   * @retval None
00239   */
00240 #define __HAL_CRC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CRC_STATE_RESET)
00241 
00242 /**
00243   * @brief  Reset CRC Data Register.
00244   * @param  __HANDLE__ CRC handle
00245   * @retval None
00246   */
00247 #define __HAL_CRC_DR_RESET(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRC_CR_RESET)
00248 
00249 /**
00250   * @brief  Set CRC INIT non-default value
00251   * @param  __HANDLE__ CRC handle
00252   * @param  __INIT__ 32-bit initial value
00253   * @retval None
00254   */
00255 #define __HAL_CRC_INITIALCRCVALUE_CONFIG(__HANDLE__, __INIT__) ((__HANDLE__)->Instance->INIT = (__INIT__))
00256 
00257 /**
00258   * @brief Store data in the Independent Data (ID) register.
00259   * @param __HANDLE__ CRC handle
00260   * @param __VALUE__  Value to be stored in the ID register
00261   * @note  Refer to the Reference Manual to get the authorized __VALUE__ length in bits
00262   * @retval None
00263   */
00264 #define __HAL_CRC_SET_IDR(__HANDLE__, __VALUE__) (WRITE_REG((__HANDLE__)->Instance->IDR, (__VALUE__)))
00265 
00266 /**
00267   * @brief Return the data stored in the Independent Data (ID) register.
00268   * @param __HANDLE__ CRC handle
00269   * @note  Refer to the Reference Manual to get the authorized __VALUE__ length in bits
00270   * @retval Value of the ID register
00271   */
00272 #define __HAL_CRC_GET_IDR(__HANDLE__) (((__HANDLE__)->Instance->IDR) & CRC_IDR_IDR)
00273 /**
00274   * @}
00275   */
00276 
00277 
00278 /* Private macros --------------------------------------------------------*/
00279 /** @defgroup  CRC_Private_Macros CRC Private Macros
00280   * @{
00281   */
00282 
00283 #define IS_DEFAULT_POLYNOMIAL(DEFAULT) (((DEFAULT) == DEFAULT_POLYNOMIAL_ENABLE) || \
00284                                         ((DEFAULT) == DEFAULT_POLYNOMIAL_DISABLE))
00285 
00286 
00287 #define IS_DEFAULT_INIT_VALUE(VALUE)  (((VALUE) == DEFAULT_INIT_VALUE_ENABLE) || \
00288                                        ((VALUE) == DEFAULT_INIT_VALUE_DISABLE))
00289 
00290 #define IS_CRC_POL_LENGTH(LENGTH)     (((LENGTH) == CRC_POLYLENGTH_32B) || \
00291                                        ((LENGTH) == CRC_POLYLENGTH_16B) || \
00292                                        ((LENGTH) == CRC_POLYLENGTH_8B)  || \
00293                                        ((LENGTH) == CRC_POLYLENGTH_7B))
00294 
00295 #define IS_CRC_INPUTDATA_FORMAT(FORMAT)           (((FORMAT) == CRC_INPUTDATA_FORMAT_BYTES)     || \
00296                                                    ((FORMAT) == CRC_INPUTDATA_FORMAT_HALFWORDS) || \
00297                                                    ((FORMAT) == CRC_INPUTDATA_FORMAT_WORDS))
00298 
00299 /**
00300   * @}
00301   */
00302 
00303 /* Include CRC HAL Extended module */
00304 #include "stm32l4xx_hal_crc_ex.h"
00305 
00306 /* Exported functions --------------------------------------------------------*/
00307 /** @defgroup CRC_Exported_Functions CRC Exported Functions
00308   * @{
00309   */
00310 
00311 /* Initialization and de-initialization functions  ****************************/
00312 /** @defgroup CRC_Exported_Functions_Group1 Initialization and de-initialization functions
00313   * @{
00314   */
00315 HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc);
00316 HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc);
00317 void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc);
00318 void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc);
00319 /**
00320   * @}
00321   */
00322 
00323 /* Peripheral Control functions ***********************************************/
00324 /** @defgroup CRC_Exported_Functions_Group2 Peripheral Control functions
00325   * @{
00326   */
00327 uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength);
00328 uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength);
00329 /**
00330   * @}
00331   */
00332 
00333 /* Peripheral State and Error functions ***************************************/
00334 /** @defgroup CRC_Exported_Functions_Group3 Peripheral State functions
00335   * @{
00336   */
00337 HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc);
00338 /**
00339   * @}
00340   */
00341 
00342 /**
00343   * @}
00344   */
00345 
00346 /**
00347   * @}
00348   */
00349 
00350 /**
00351   * @}
00352   */
00353 
00354 #ifdef __cplusplus
00355 }
00356 #endif
00357 
00358 #endif /* __STM32L4xx_HAL_CRC_H */
00359 
00360 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/