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.
Dependents: Space_Invaders_Demo neopixels gpio_test_stm32f3_discovery gpio_test_systimer ... more
stm32f30x_crc.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f30x_crc.c 00004 * @author MCD Application Team 00005 * @version V1.2.3 00006 * @date 10-July-2015 00007 * @brief This file provides firmware functions to manage the following 00008 * functionalities of CRC computation unit peripheral: 00009 * + Configuration of the CRC computation unit 00010 * + CRC computation of one/many 32-bit data 00011 * + CRC Independent register (IDR) access 00012 * 00013 @verbatim 00014 00015 =============================================================================== 00016 ##### How to use this driver ##### 00017 =============================================================================== 00018 [..] 00019 (#) Enable CRC AHB clock using RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE) 00020 function. 00021 (#) Select the polynomial size: 7-bit, 8-bit, 16-bit or 32-bit. 00022 (#) Set the polynomial coefficients using CRC_SetPolynomial(); 00023 (#) If required, select the reverse operation on input data 00024 using CRC_ReverseInputDataSelect(); 00025 (#) If required, enable the reverse operation on output data 00026 using CRC_ReverseOutputDataCmd(Enable); 00027 (#) If required, set the initialization remainder value using 00028 CRC_SetInitRegister(); 00029 (#) use CRC_CalcCRC() function to compute the CRC of a 32-bit data 00030 or use CRC_CalcBlockCRC() function to compute the CRC if a 32-bit 00031 data buffer. 00032 00033 @endverbatim 00034 00035 ****************************************************************************** 00036 * @attention 00037 * 00038 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> 00039 * 00040 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00041 * You may not use this file except in compliance with the License. 00042 * You may obtain a copy of the License at: 00043 * 00044 * http://www.st.com/software_license_agreement_liberty_v2 00045 * 00046 * Unless required by applicable law or agreed to in writing, software 00047 * distributed under the License is distributed on an "AS IS" BASIS, 00048 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00049 * See the License for the specific language governing permissions and 00050 * limitations under the License. 00051 * 00052 ****************************************************************************** 00053 */ 00054 00055 /* Includes ------------------------------------------------------------------*/ 00056 #include "stm32f30x_crc.h" 00057 00058 /** @addtogroup STM32F30x_StdPeriph_Driver 00059 * @{ 00060 */ 00061 00062 /** @defgroup CRC 00063 * @brief CRC driver modules 00064 * @{ 00065 */ 00066 00067 /* Private typedef -----------------------------------------------------------*/ 00068 /* Private define ------------------------------------------------------------*/ 00069 /* Private macro -------------------------------------------------------------*/ 00070 /* Private variables ---------------------------------------------------------*/ 00071 /* Private function prototypes -----------------------------------------------*/ 00072 /* Private functions ---------------------------------------------------------*/ 00073 00074 /** @defgroup CRC_Private_Functions 00075 * @{ 00076 */ 00077 00078 /** @defgroup CRC_Group1 Configuration of the CRC computation unit functions 00079 * @brief Configuration of the CRC computation unit functions 00080 * 00081 @verbatim 00082 =============================================================================== 00083 ##### CRC configuration functions ##### 00084 =============================================================================== 00085 00086 @endverbatim 00087 * @{ 00088 */ 00089 00090 /** 00091 * @brief Deinitializes CRC peripheral registers to their default reset values. 00092 * @param None 00093 * @retval None 00094 */ 00095 void CRC_DeInit(void) 00096 { 00097 /* Set DR register to reset value */ 00098 CRC->DR = 0xFFFFFFFF; 00099 /* Set the POL register to the reset value: 0x04C11DB7 */ 00100 CRC->POL = 0x04C11DB7; 00101 /* Reset IDR register */ 00102 CRC->IDR = 0x00; 00103 /* Set INIT register to reset value */ 00104 CRC->INIT = 0xFFFFFFFF; 00105 /* Reset the CRC calculation unit */ 00106 CRC->CR = CRC_CR_RESET; 00107 } 00108 00109 /** 00110 * @brief Resets the CRC calculation unit and sets INIT register content in DR register. 00111 * @param None 00112 * @retval None 00113 */ 00114 void CRC_ResetDR(void) 00115 { 00116 /* Reset CRC generator */ 00117 CRC->CR |= CRC_CR_RESET; 00118 } 00119 00120 /** 00121 * @brief Selects the polynomial size. 00122 * @param CRC_PolSize: Specifies the polynomial size. 00123 * This parameter can be: 00124 * @arg CRC_PolSize_7: 7-bit polynomial for CRC calculation 00125 * @arg CRC_PolSize_8: 8-bit polynomial for CRC calculation 00126 * @arg CRC_PolSize_16: 16-bit polynomial for CRC calculation 00127 * @arg CRC_PolSize_32: 32-bit polynomial for CRC calculation 00128 * @retval None 00129 */ 00130 void CRC_PolynomialSizeSelect(uint32_t CRC_PolSize) 00131 { 00132 uint32_t tmpcr = 0; 00133 00134 /* Check the parameter */ 00135 assert_param(IS_CRC_POL_SIZE(CRC_PolSize)); 00136 00137 /* Get CR register value */ 00138 tmpcr = CRC->CR; 00139 00140 /* Reset POL_SIZE bits */ 00141 tmpcr &= (uint32_t)~((uint32_t)CRC_CR_POLSIZE); 00142 /* Set the polynomial size */ 00143 tmpcr |= (uint32_t)CRC_PolSize; 00144 00145 /* Write to CR register */ 00146 CRC->CR = (uint32_t)tmpcr; 00147 } 00148 00149 /** 00150 * @brief Selects the reverse operation to be performed on input data. 00151 * @param CRC_ReverseInputData: Specifies the reverse operation on input data. 00152 * This parameter can be: 00153 * @arg CRC_ReverseInputData_No: No reverse operation is performed 00154 * @arg CRC_ReverseInputData_8bits: reverse operation performed on 8 bits 00155 * @arg CRC_ReverseInputData_16bits: reverse operation performed on 16 bits 00156 * @arg CRC_ReverseInputData_32bits: reverse operation performed on 32 bits 00157 * @retval None 00158 */ 00159 void CRC_ReverseInputDataSelect(uint32_t CRC_ReverseInputData) 00160 { 00161 uint32_t tmpcr = 0; 00162 00163 /* Check the parameter */ 00164 assert_param(IS_CRC_REVERSE_INPUT_DATA(CRC_ReverseInputData)); 00165 00166 /* Get CR register value */ 00167 tmpcr = CRC->CR; 00168 00169 /* Reset REV_IN bits */ 00170 tmpcr &= (uint32_t)~((uint32_t)CRC_CR_REV_IN); 00171 /* Set the reverse operation */ 00172 tmpcr |= (uint32_t)CRC_ReverseInputData; 00173 00174 /* Write to CR register */ 00175 CRC->CR = (uint32_t)tmpcr; 00176 } 00177 00178 /** 00179 * @brief Enables or disable the reverse operation on output data. 00180 * The reverse operation on output data is performed on 32-bit. 00181 * @param NewState: new state of the reverse operation on output data. 00182 * This parameter can be: ENABLE or DISABLE. 00183 * @retval None 00184 */ 00185 void CRC_ReverseOutputDataCmd(FunctionalState NewState) 00186 { 00187 /* Check the parameters */ 00188 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00189 00190 if (NewState != DISABLE) 00191 { 00192 /* Enable reverse operation on output data */ 00193 CRC->CR |= CRC_CR_REV_OUT; 00194 } 00195 else 00196 { 00197 /* Disable reverse operation on output data */ 00198 CRC->CR &= (uint32_t)~((uint32_t)CRC_CR_REV_OUT); 00199 } 00200 } 00201 00202 /** 00203 * @brief Initializes the INIT register. 00204 * @note After resetting CRC calculation unit, CRC_InitValue is stored in DR register 00205 * @param CRC_InitValue: Programmable initial CRC value 00206 * @retval None 00207 */ 00208 void CRC_SetInitRegister(uint32_t CRC_InitValue) 00209 { 00210 CRC->INIT = CRC_InitValue; 00211 } 00212 00213 /** 00214 * @brief Initializes the polynomial coefficients. 00215 * @param CRC_Pol: Polynomial to be used for CRC calculation. 00216 * @retval None 00217 */ 00218 void CRC_SetPolynomial(uint32_t CRC_Pol) 00219 { 00220 CRC->POL = CRC_Pol; 00221 } 00222 00223 /** 00224 * @} 00225 */ 00226 00227 /** @defgroup CRC_Group2 CRC computation of one/many 32-bit data functions 00228 * @brief CRC computation of one/many 32-bit data functions 00229 * 00230 @verbatim 00231 =============================================================================== 00232 ##### CRC computation functions ##### 00233 =============================================================================== 00234 00235 @endverbatim 00236 * @{ 00237 */ 00238 00239 /** 00240 * @brief Computes the 32-bit CRC of a given data word(32-bit). 00241 * @param CRC_Data: data word(32-bit) to compute its CRC 00242 * @retval 32-bit CRC 00243 */ 00244 uint32_t CRC_CalcCRC(uint32_t CRC_Data) 00245 { 00246 CRC->DR = CRC_Data; 00247 00248 return (CRC->DR); 00249 } 00250 00251 /** 00252 * @brief Computes the 16-bit CRC of a given 16-bit data. 00253 * @param CRC_Data: data half-word(16-bit) to compute its CRC 00254 * @retval 16-bit CRC 00255 */ 00256 uint32_t CRC_CalcCRC16bits(uint16_t CRC_Data) 00257 { 00258 *(uint16_t*)(CRC_BASE) = (uint16_t) CRC_Data; 00259 00260 return (CRC->DR); 00261 } 00262 00263 /** 00264 * @brief Computes the 8-bit CRC of a given 8-bit data. 00265 * @param CRC_Data: 8-bit data to compute its CRC 00266 * @retval 8-bit CRC 00267 */ 00268 uint32_t CRC_CalcCRC8bits(uint8_t CRC_Data) 00269 { 00270 *(uint8_t*)(CRC_BASE) = (uint8_t) CRC_Data; 00271 00272 return (CRC->DR); 00273 } 00274 00275 /** 00276 * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 00277 * @param pBuffer: pointer to the buffer containing the data to be computed 00278 * @param BufferLength: length of the buffer to be computed 00279 * @retval 32-bit CRC 00280 */ 00281 uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 00282 { 00283 uint32_t index = 0; 00284 00285 for(index = 0; index < BufferLength; index++) 00286 { 00287 CRC->DR = pBuffer[index]; 00288 } 00289 return (CRC->DR); 00290 } 00291 00292 /** 00293 * @brief Returns the current CRC value. 00294 * @param None 00295 * @retval 32-bit CRC 00296 */ 00297 uint32_t CRC_GetCRC(void) 00298 { 00299 return (CRC->DR); 00300 } 00301 00302 /** 00303 * @} 00304 */ 00305 00306 /** @defgroup CRC_Group3 CRC Independent Register (IDR) access functions 00307 * @brief CRC Independent Register (IDR) access (write/read) functions 00308 * 00309 @verbatim 00310 =============================================================================== 00311 ##### CRC Independent Register (IDR) access functions ##### 00312 =============================================================================== 00313 00314 @endverbatim 00315 * @{ 00316 */ 00317 00318 /** 00319 * @brief Stores an 8-bit data in the Independent Data(ID) register. 00320 * @param CRC_IDValue: 8-bit value to be stored in the ID register 00321 * @retval None 00322 */ 00323 void CRC_SetIDRegister(uint8_t CRC_IDValue) 00324 { 00325 CRC->IDR = CRC_IDValue; 00326 } 00327 00328 /** 00329 * @brief Returns the 8-bit data stored in the Independent Data(ID) register 00330 * @param None 00331 * @retval 8-bit value of the ID register 00332 */ 00333 uint8_t CRC_GetIDRegister(void) 00334 { 00335 return (CRC->IDR); 00336 } 00337 00338 /** 00339 * @} 00340 */ 00341 00342 /** 00343 * @} 00344 */ 00345 00346 /** 00347 * @} 00348 */ 00349 00350 /** 00351 * @} 00352 */ 00353 00354 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 17:34:44 by
