Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
stm32l4xx_ll_crc.h
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_ll_crc.h 00004 * @author MCD Application Team 00005 * @version V1.5.1 00006 * @date 31-May-2016 00007 * @brief Header file of CRC LL module. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 /* Define to prevent recursive inclusion -------------------------------------*/ 00039 #ifndef __STM32L4xx_LL_CRC_H 00040 #define __STM32L4xx_LL_CRC_H 00041 00042 #ifdef __cplusplus 00043 extern "C" { 00044 #endif 00045 00046 /* Includes ------------------------------------------------------------------*/ 00047 #include "stm32l4xx.h" 00048 00049 /** @addtogroup STM32L4xx_LL_Driver 00050 * @{ 00051 */ 00052 00053 #if defined(CRC) 00054 00055 /** @defgroup CRC_LL CRC 00056 * @{ 00057 */ 00058 00059 /* Private types -------------------------------------------------------------*/ 00060 /* Private variables ---------------------------------------------------------*/ 00061 /* Private constants ---------------------------------------------------------*/ 00062 /* Private macros ------------------------------------------------------------*/ 00063 00064 /* Exported types ------------------------------------------------------------*/ 00065 /* Exported constants --------------------------------------------------------*/ 00066 /** @defgroup CRC_LL_Exported_Constants CRC Exported Constants 00067 * @{ 00068 */ 00069 00070 /** @defgroup CRC_LL_EC_POLYLENGTH Polynomial length 00071 * @{ 00072 */ 00073 #define LL_CRC_POLYLENGTH_32B (uint32_t)0x00000000U /*!< 32 bits Polynomial size */ 00074 #define LL_CRC_POLYLENGTH_16B CRC_CR_POLYSIZE_0 /*!< 16 bits Polynomial size */ 00075 #define LL_CRC_POLYLENGTH_8B CRC_CR_POLYSIZE_1 /*!< 8 bits Polynomial size */ 00076 #define LL_CRC_POLYLENGTH_7B (CRC_CR_POLYSIZE_1 | CRC_CR_POLYSIZE_0) /*!< 7 bits Polynomial size */ 00077 /** 00078 * @} 00079 */ 00080 00081 /** @defgroup CRC_LL_EC_INDATA_REVERSE Input Data Reverse 00082 * @{ 00083 */ 00084 #define LL_CRC_INDATA_REVERSE_NONE (uint32_t)0x00000000U /*!< Input Data bit order not affected */ 00085 #define LL_CRC_INDATA_REVERSE_BYTE CRC_CR_REV_IN_0 /*!< Input Data bit reversal done by byte */ 00086 #define LL_CRC_INDATA_REVERSE_HALFWORD CRC_CR_REV_IN_1 /*!< Input Data bit reversal done by half-word */ 00087 #define LL_CRC_INDATA_REVERSE_WORD (CRC_CR_REV_IN_1 | CRC_CR_REV_IN_0) /*!< Input Data bit reversal done by word */ 00088 /** 00089 * @} 00090 */ 00091 00092 /** @defgroup CRC_LL_EC_OUTDATA_REVERSE Output Data Reverse 00093 * @{ 00094 */ 00095 #define LL_CRC_OUTDATA_REVERSE_NONE (uint32_t)0x00000000U /*!< Output Data bit order not affected */ 00096 #define LL_CRC_OUTDATA_REVERSE_BIT CRC_CR_REV_OUT /*!< Output Data bit reversal done by bit */ 00097 /** 00098 * @} 00099 */ 00100 00101 /** @defgroup CRC_LL_EC_Default_Polynomial_Value Default CRC generating polynomial value 00102 * @brief Normal representation of this polynomial value is 00103 * 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 . 00104 * @{ 00105 */ 00106 #define LL_CRC_DEFAULT_CRC32_POLY (uint32_t)0x04C11DB7U /*!< Default CRC generating polynomial value */ 00107 /** 00108 * @} 00109 */ 00110 00111 /** @defgroup CRC_LL_EC_Default_InitValue Default CRC computation initialization value 00112 * @{ 00113 */ 00114 #define LL_CRC_DEFAULT_CRC_INITVALUE (uint32_t)0xFFFFFFFFU /*!< Default CRC computation initialization value */ 00115 /** 00116 * @} 00117 */ 00118 00119 /** 00120 * @} 00121 */ 00122 00123 /* Exported macro ------------------------------------------------------------*/ 00124 /** @defgroup CRC_LL_Exported_Macros CRC Exported Macros 00125 * @{ 00126 */ 00127 00128 /** @defgroup CRC_LL_EM_WRITE_READ Common Write and read registers Macros 00129 * @{ 00130 */ 00131 00132 /** 00133 * @brief Write a value in CRC register 00134 * @param __INSTANCE__ CRC Instance 00135 * @param __REG__ Register to be written 00136 * @param __VALUE__ Value to be written in the register 00137 * @retval None 00138 */ 00139 #define LL_CRC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__)) 00140 00141 /** 00142 * @brief Read a value in CRC register 00143 * @param __INSTANCE__ CRC Instance 00144 * @param __REG__ Register to be read 00145 * @retval Register value 00146 */ 00147 #define LL_CRC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__) 00148 /** 00149 * @} 00150 */ 00151 00152 /** 00153 * @} 00154 */ 00155 00156 00157 /* Exported functions --------------------------------------------------------*/ 00158 /** @defgroup CRC_LL_Exported_Functions CRC Exported Functions 00159 * @{ 00160 */ 00161 00162 /** @defgroup CRC_LL_EF_Configuration CRC Configuration functions 00163 * @{ 00164 */ 00165 00166 /** 00167 * @brief Reset the CRC calculation unit. 00168 * @note If Programmable Initial CRC value feature 00169 * is available, also set the Data Register to the value stored in the 00170 * CRC_INIT register, otherwise, reset Data Register to its default value. 00171 * @rmtoll CR RESET LL_CRC_ResetCRCCalculationUnit 00172 * @param CRCx CRC Instance 00173 * @retval None 00174 */ 00175 __STATIC_INLINE void LL_CRC_ResetCRCCalculationUnit(CRC_TypeDef *CRCx) 00176 { 00177 SET_BIT(CRCx->CR, CRC_CR_RESET); 00178 } 00179 00180 /** 00181 * @brief Configure size of the polynomial. 00182 * @rmtoll CR POLYSIZE LL_CRC_SetPolynomialSize 00183 * @param CRCx CRC Instance 00184 * @param PolySize This parameter can be one of the following values: 00185 * @arg @ref LL_CRC_POLYLENGTH_32B 00186 * @arg @ref LL_CRC_POLYLENGTH_16B 00187 * @arg @ref LL_CRC_POLYLENGTH_8B 00188 * @arg @ref LL_CRC_POLYLENGTH_7B 00189 * @retval None 00190 */ 00191 __STATIC_INLINE void LL_CRC_SetPolynomialSize(CRC_TypeDef *CRCx, uint32_t PolySize) 00192 { 00193 MODIFY_REG(CRCx->CR, CRC_CR_POLYSIZE, PolySize); 00194 } 00195 00196 /** 00197 * @brief Return size of the polynomial. 00198 * @rmtoll CR POLYSIZE LL_CRC_GetPolynomialSize 00199 * @param CRCx CRC Instance 00200 * @retval Returned value can be one of the following values: 00201 * @arg @ref LL_CRC_POLYLENGTH_32B 00202 * @arg @ref LL_CRC_POLYLENGTH_16B 00203 * @arg @ref LL_CRC_POLYLENGTH_8B 00204 * @arg @ref LL_CRC_POLYLENGTH_7B 00205 */ 00206 __STATIC_INLINE uint32_t LL_CRC_GetPolynomialSize(CRC_TypeDef *CRCx) 00207 { 00208 return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_POLYSIZE)); 00209 } 00210 00211 /** 00212 * @brief Configure the reversal of the bit order of the input data 00213 * @rmtoll CR REV_IN LL_CRC_SetInputDataReverseMode 00214 * @param CRCx CRC Instance 00215 * @param ReverseMode This parameter can be one of the following values: 00216 * @arg @ref LL_CRC_INDATA_REVERSE_NONE 00217 * @arg @ref LL_CRC_INDATA_REVERSE_BYTE 00218 * @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD 00219 * @arg @ref LL_CRC_INDATA_REVERSE_WORD 00220 * @retval None 00221 */ 00222 __STATIC_INLINE void LL_CRC_SetInputDataReverseMode(CRC_TypeDef *CRCx, uint32_t ReverseMode) 00223 { 00224 MODIFY_REG(CRCx->CR, CRC_CR_REV_IN, ReverseMode); 00225 } 00226 00227 /** 00228 * @brief Return type of reversal for input data bit order 00229 * @rmtoll CR REV_IN LL_CRC_GetInputDataReverseMode 00230 * @param CRCx CRC Instance 00231 * @retval Returned value can be one of the following values: 00232 * @arg @ref LL_CRC_INDATA_REVERSE_NONE 00233 * @arg @ref LL_CRC_INDATA_REVERSE_BYTE 00234 * @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD 00235 * @arg @ref LL_CRC_INDATA_REVERSE_WORD 00236 */ 00237 __STATIC_INLINE uint32_t LL_CRC_GetInputDataReverseMode(CRC_TypeDef *CRCx) 00238 { 00239 return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_REV_IN)); 00240 } 00241 00242 /** 00243 * @brief Configure the reversal of the bit order of the Output data 00244 * @rmtoll CR REV_OUT LL_CRC_SetOutputDataReverseMode 00245 * @param CRCx CRC Instance 00246 * @param ReverseMode This parameter can be one of the following values: 00247 * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE 00248 * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT 00249 * @retval None 00250 */ 00251 __STATIC_INLINE void LL_CRC_SetOutputDataReverseMode(CRC_TypeDef *CRCx, uint32_t ReverseMode) 00252 { 00253 MODIFY_REG(CRCx->CR, CRC_CR_REV_OUT, ReverseMode); 00254 } 00255 00256 /** 00257 * @brief Configure the reversal of the bit order of the Output data 00258 * @rmtoll CR REV_OUT LL_CRC_GetOutputDataReverseMode 00259 * @param CRCx CRC Instance 00260 * @retval Returned value can be one of the following values: 00261 * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE 00262 * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT 00263 */ 00264 __STATIC_INLINE uint32_t LL_CRC_GetOutputDataReverseMode(CRC_TypeDef *CRCx) 00265 { 00266 return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_REV_OUT)); 00267 } 00268 00269 /** 00270 * @brief Initialize the Programmable initial CRC value. 00271 * @note If the CRC size is less than 32 bits, the least significant bits 00272 * are used to write the correct value 00273 * @note LL_CRC_DEFAULT_CRC_INITVALUE could be used as value for InitCrc parameter. 00274 * @rmtoll INIT INIT LL_CRC_SetInitialData 00275 * @param CRCx CRC Instance 00276 * @param InitCrc Value to be programmed in Programmable initial CRC value register 00277 * @retval None 00278 */ 00279 __STATIC_INLINE void LL_CRC_SetInitialData(CRC_TypeDef *CRCx, uint32_t InitCrc) 00280 { 00281 WRITE_REG(CRCx->INIT, InitCrc); 00282 } 00283 00284 /** 00285 * @brief Return current Initial CRC value. 00286 * @note If the CRC size is less than 32 bits, the least significant bits 00287 * are used to read the correct value 00288 * @rmtoll INIT INIT LL_CRC_GetInitialData 00289 * @param CRCx CRC Instance 00290 * @retval Value programmed in Programmable initial CRC value register 00291 */ 00292 __STATIC_INLINE uint32_t LL_CRC_GetInitialData(CRC_TypeDef *CRCx) 00293 { 00294 return (uint32_t)(READ_REG(CRCx->INIT)); 00295 } 00296 00297 /** 00298 * @brief Initialize the Programmable polynomial value 00299 * (coefficients of the polynomial to be used for CRC calculation). 00300 * @note LL_CRC_DEFAULT_CRC32_POLY could be used as value for PolynomCoef parameter. 00301 * @note Please check Reference Manual and existing Errata Sheets, 00302 * regarding possible limitations for Polynomial values usage. 00303 * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65 00304 * @rmtoll POL POL LL_CRC_SetPolynomialCoef 00305 * @param CRCx CRC Instance 00306 * @param PolynomCoef Value to be programmed in Programmable Polynomial value register 00307 * @retval None 00308 */ 00309 __STATIC_INLINE void LL_CRC_SetPolynomialCoef(CRC_TypeDef *CRCx, uint32_t PolynomCoef) 00310 { 00311 WRITE_REG(CRCx->POL, PolynomCoef); 00312 } 00313 00314 /** 00315 * @brief Return current Programmable polynomial value 00316 * @note Please check Reference Manual and existing Errata Sheets, 00317 * regarding possible limitations for Polynomial values usage. 00318 * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65 00319 * @rmtoll POL POL LL_CRC_GetPolynomialCoef 00320 * @param CRCx CRC Instance 00321 * @retval Value programmed in Programmable Polynomial value register 00322 */ 00323 __STATIC_INLINE uint32_t LL_CRC_GetPolynomialCoef(CRC_TypeDef *CRCx) 00324 { 00325 return (uint32_t)(READ_REG(CRCx->POL)); 00326 } 00327 00328 /** 00329 * @} 00330 */ 00331 00332 /** @defgroup CRC_LL_EF_Data_Management Data_Management 00333 * @{ 00334 */ 00335 00336 /** 00337 * @brief Write given 32-bit data to the CRC calculator 00338 * @rmtoll DR DR LL_CRC_FeedData32 00339 * @param CRCx CRC Instance 00340 * @param InData value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFFFFFF 00341 * @retval None 00342 */ 00343 __STATIC_INLINE void LL_CRC_FeedData32(CRC_TypeDef *CRCx, uint32_t InData) 00344 { 00345 WRITE_REG(CRCx->DR, InData); 00346 } 00347 00348 /** 00349 * @brief Write given 16-bit data to the CRC calculator 00350 * @rmtoll DR DR LL_CRC_FeedData16 00351 * @param CRCx CRC Instance 00352 * @param InData 16 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFF 00353 * @retval None 00354 */ 00355 __STATIC_INLINE void LL_CRC_FeedData16(CRC_TypeDef *CRCx, uint16_t InData) 00356 { 00357 *(uint16_t __IO *)(&CRCx->DR) = (uint16_t) InData; 00358 } 00359 00360 /** 00361 * @brief Write given 8-bit data to the CRC calculator 00362 * @rmtoll DR DR LL_CRC_FeedData8 00363 * @param CRCx CRC Instance 00364 * @param InData 8 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFF 00365 * @retval None 00366 */ 00367 __STATIC_INLINE void LL_CRC_FeedData8(CRC_TypeDef *CRCx, uint8_t InData) 00368 { 00369 *(uint8_t __IO *)(&CRCx->DR) = (uint8_t) InData; 00370 } 00371 00372 /** 00373 * @brief Return current CRC calculation result. 32 bits value is returned. 00374 * @rmtoll DR DR LL_CRC_ReadData32 00375 * @param CRCx CRC Instance 00376 * @retval Current CRC calculation result as stored in CRC_DR register (32 bits). 00377 */ 00378 __STATIC_INLINE uint32_t LL_CRC_ReadData32(CRC_TypeDef *CRCx) 00379 { 00380 return (uint32_t)(READ_REG(CRCx->DR)); 00381 } 00382 00383 /** 00384 * @brief Return current CRC calculation result. 16 bits value is returned. 00385 * @note This function is expected to be used in a 16 bits CRC polynomial size context. 00386 * @rmtoll DR DR LL_CRC_ReadData16 00387 * @param CRCx CRC Instance 00388 * @retval Current CRC calculation result as stored in CRC_DR register (16 bits). 00389 */ 00390 __STATIC_INLINE uint16_t LL_CRC_ReadData16(CRC_TypeDef *CRCx) 00391 { 00392 return (uint16_t)READ_REG(CRCx->DR); 00393 } 00394 00395 /** 00396 * @brief Return current CRC calculation result. 8 bits value is returned. 00397 * @note This function is expected to be used in a 8 bits CRC polynomial size context. 00398 * @rmtoll DR DR LL_CRC_ReadData8 00399 * @param CRCx CRC Instance 00400 * @retval Current CRC calculation result as stored in CRC_DR register (8 bits). 00401 */ 00402 __STATIC_INLINE uint8_t LL_CRC_ReadData8(CRC_TypeDef *CRCx) 00403 { 00404 return (uint8_t)READ_REG(CRCx->DR); 00405 } 00406 00407 /** 00408 * @brief Return current CRC calculation result. 7 bits value is returned. 00409 * @note This function is expected to be used in a 7 bits CRC polynomial size context. 00410 * @rmtoll DR DR LL_CRC_ReadData7 00411 * @param CRCx CRC Instance 00412 * @retval Current CRC calculation result as stored in CRC_DR register (7 bits). 00413 */ 00414 __STATIC_INLINE uint8_t LL_CRC_ReadData7(CRC_TypeDef *CRCx) 00415 { 00416 return (uint8_t)(READ_REG(CRCx->DR) & 0x7FU); 00417 } 00418 00419 /** 00420 * @brief Return data stored in the Independent Data(IDR) register. 00421 * @note This register can be used as a temporary storage location for one byte. 00422 * @rmtoll IDR IDR LL_CRC_Read_IDR 00423 * @param CRCx CRC Instance 00424 * @retval Value stored in CRC_IDR register (General-purpose 8-bit data register). 00425 */ 00426 __STATIC_INLINE uint32_t LL_CRC_Read_IDR(CRC_TypeDef *CRCx) 00427 { 00428 return (uint32_t)(READ_REG(CRCx->IDR)); 00429 } 00430 00431 /** 00432 * @brief Store data in the Independent Data(IDR) register. 00433 * @note This register can be used as a temporary storage location for one byte. 00434 * @rmtoll IDR IDR LL_CRC_Write_IDR 00435 * @param CRCx CRC Instance 00436 * @param InData value to be stored in CRC_IDR register (8-bit) between between Min_Data=0 and Max_Data=0xFF 00437 * @retval None 00438 */ 00439 __STATIC_INLINE void LL_CRC_Write_IDR(CRC_TypeDef *CRCx, uint32_t InData) 00440 { 00441 *((uint8_t __IO *)(&CRCx->IDR)) = (uint8_t) InData; 00442 } 00443 /** 00444 * @} 00445 */ 00446 00447 #if defined(USE_FULL_LL_DRIVER) 00448 /** @defgroup CRC_LL_EF_Init Initialization and de-initialization functions 00449 * @{ 00450 */ 00451 00452 ErrorStatus LL_CRC_DeInit(CRC_TypeDef *CRCx); 00453 00454 /** 00455 * @} 00456 */ 00457 #endif /* USE_FULL_LL_DRIVER */ 00458 00459 /** 00460 * @} 00461 */ 00462 00463 /** 00464 * @} 00465 */ 00466 00467 #endif /* defined(CRC) */ 00468 00469 /** 00470 * @} 00471 */ 00472 00473 #ifdef __cplusplus 00474 } 00475 #endif 00476 00477 #endif /* __STM32L4xx_LL_CRC_H */ 00478 00479 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 10:59:59 by
