mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_DISCO_F051R8/stm32f0xx_crc.c@308:59cc78a25982, 2014-09-05 (annotated)
- Committer:
- todotani
- Date:
- Fri Sep 05 14:20:33 2014 +0000
- Revision:
- 308:59cc78a25982
- Parent:
- 130:1dec54e4aec3
BLE_Health_Thermometer for mbed HRM1017 with BLE library 0.1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 130:1dec54e4aec3 | 1 | /** |
mbed_official | 130:1dec54e4aec3 | 2 | ****************************************************************************** |
mbed_official | 130:1dec54e4aec3 | 3 | * @file stm32f0xx_crc.c |
mbed_official | 130:1dec54e4aec3 | 4 | * @author MCD Application Team |
mbed_official | 130:1dec54e4aec3 | 5 | * @version V1.3.0 |
mbed_official | 130:1dec54e4aec3 | 6 | * @date 16-January-2014 |
mbed_official | 130:1dec54e4aec3 | 7 | * @brief This file provides firmware functions to manage the following |
mbed_official | 130:1dec54e4aec3 | 8 | * functionalities of CRC computation unit peripheral: |
mbed_official | 130:1dec54e4aec3 | 9 | * + Configuration of the CRC computation unit |
mbed_official | 130:1dec54e4aec3 | 10 | * + CRC computation of one/many 32-bit data |
mbed_official | 130:1dec54e4aec3 | 11 | * + CRC Independent register (IDR) access |
mbed_official | 130:1dec54e4aec3 | 12 | * |
mbed_official | 130:1dec54e4aec3 | 13 | * @verbatim |
mbed_official | 130:1dec54e4aec3 | 14 | =============================================================================== |
mbed_official | 130:1dec54e4aec3 | 15 | ##### How to use this driver ##### |
mbed_official | 130:1dec54e4aec3 | 16 | =============================================================================== |
mbed_official | 130:1dec54e4aec3 | 17 | [..] |
mbed_official | 130:1dec54e4aec3 | 18 | |
mbed_official | 130:1dec54e4aec3 | 19 | (+) Enable CRC AHB clock using RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE) |
mbed_official | 130:1dec54e4aec3 | 20 | function |
mbed_official | 130:1dec54e4aec3 | 21 | (+) If required, select the reverse operation on input data |
mbed_official | 130:1dec54e4aec3 | 22 | using CRC_ReverseInputDataSelect() |
mbed_official | 130:1dec54e4aec3 | 23 | (+) If required, enable the reverse operation on output data |
mbed_official | 130:1dec54e4aec3 | 24 | using CRC_ReverseOutputDataCmd(Enable) |
mbed_official | 130:1dec54e4aec3 | 25 | (+) use CRC_CalcCRC() function to compute the CRC of a 32-bit data |
mbed_official | 130:1dec54e4aec3 | 26 | or use CRC_CalcBlockCRC() function to compute the CRC if a 32-bit |
mbed_official | 130:1dec54e4aec3 | 27 | data buffer |
mbed_official | 130:1dec54e4aec3 | 28 | (@) To compute the CRC of a new data use CRC_ResetDR() to reset |
mbed_official | 130:1dec54e4aec3 | 29 | the CRC computation unit before starting the computation |
mbed_official | 130:1dec54e4aec3 | 30 | otherwise you can get wrong CRC values. |
mbed_official | 130:1dec54e4aec3 | 31 | |
mbed_official | 130:1dec54e4aec3 | 32 | @endverbatim |
mbed_official | 130:1dec54e4aec3 | 33 | * |
mbed_official | 130:1dec54e4aec3 | 34 | ****************************************************************************** |
mbed_official | 130:1dec54e4aec3 | 35 | * @attention |
mbed_official | 130:1dec54e4aec3 | 36 | * |
mbed_official | 130:1dec54e4aec3 | 37 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 130:1dec54e4aec3 | 38 | * |
mbed_official | 130:1dec54e4aec3 | 39 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 130:1dec54e4aec3 | 40 | * are permitted provided that the following conditions are met: |
mbed_official | 130:1dec54e4aec3 | 41 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 130:1dec54e4aec3 | 42 | * this list of conditions and the following disclaimer. |
mbed_official | 130:1dec54e4aec3 | 43 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 130:1dec54e4aec3 | 44 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 130:1dec54e4aec3 | 45 | * and/or other materials provided with the distribution. |
mbed_official | 130:1dec54e4aec3 | 46 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 130:1dec54e4aec3 | 47 | * may be used to endorse or promote products derived from this software |
mbed_official | 130:1dec54e4aec3 | 48 | * without specific prior written permission. |
mbed_official | 130:1dec54e4aec3 | 49 | * |
mbed_official | 130:1dec54e4aec3 | 50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 130:1dec54e4aec3 | 51 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 130:1dec54e4aec3 | 52 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 130:1dec54e4aec3 | 53 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 130:1dec54e4aec3 | 54 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 130:1dec54e4aec3 | 55 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 130:1dec54e4aec3 | 56 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 130:1dec54e4aec3 | 57 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 130:1dec54e4aec3 | 58 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 130:1dec54e4aec3 | 59 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 130:1dec54e4aec3 | 60 | * |
mbed_official | 130:1dec54e4aec3 | 61 | ****************************************************************************** |
mbed_official | 130:1dec54e4aec3 | 62 | */ |
mbed_official | 130:1dec54e4aec3 | 63 | |
mbed_official | 130:1dec54e4aec3 | 64 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 65 | #include "stm32f0xx_crc.h" |
mbed_official | 130:1dec54e4aec3 | 66 | |
mbed_official | 130:1dec54e4aec3 | 67 | /** @addtogroup STM32F0xx_StdPeriph_Driver |
mbed_official | 130:1dec54e4aec3 | 68 | * @{ |
mbed_official | 130:1dec54e4aec3 | 69 | */ |
mbed_official | 130:1dec54e4aec3 | 70 | |
mbed_official | 130:1dec54e4aec3 | 71 | /** @defgroup CRC |
mbed_official | 130:1dec54e4aec3 | 72 | * @brief CRC driver modules |
mbed_official | 130:1dec54e4aec3 | 73 | * @{ |
mbed_official | 130:1dec54e4aec3 | 74 | */ |
mbed_official | 130:1dec54e4aec3 | 75 | |
mbed_official | 130:1dec54e4aec3 | 76 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 77 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 78 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 79 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 80 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 81 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 130:1dec54e4aec3 | 82 | |
mbed_official | 130:1dec54e4aec3 | 83 | /** @defgroup CRC_Private_Functions |
mbed_official | 130:1dec54e4aec3 | 84 | * @{ |
mbed_official | 130:1dec54e4aec3 | 85 | */ |
mbed_official | 130:1dec54e4aec3 | 86 | |
mbed_official | 130:1dec54e4aec3 | 87 | /** @defgroup CRC_Group1 Configuration of the CRC computation unit functions |
mbed_official | 130:1dec54e4aec3 | 88 | * @brief Configuration of the CRC computation unit functions |
mbed_official | 130:1dec54e4aec3 | 89 | * |
mbed_official | 130:1dec54e4aec3 | 90 | @verbatim |
mbed_official | 130:1dec54e4aec3 | 91 | =============================================================================== |
mbed_official | 130:1dec54e4aec3 | 92 | ##### CRC configuration functions ##### |
mbed_official | 130:1dec54e4aec3 | 93 | =============================================================================== |
mbed_official | 130:1dec54e4aec3 | 94 | |
mbed_official | 130:1dec54e4aec3 | 95 | @endverbatim |
mbed_official | 130:1dec54e4aec3 | 96 | * @{ |
mbed_official | 130:1dec54e4aec3 | 97 | */ |
mbed_official | 130:1dec54e4aec3 | 98 | |
mbed_official | 130:1dec54e4aec3 | 99 | /** |
mbed_official | 130:1dec54e4aec3 | 100 | * @brief Deinitializes CRC peripheral registers to their default reset values. |
mbed_official | 130:1dec54e4aec3 | 101 | * @param None |
mbed_official | 130:1dec54e4aec3 | 102 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 103 | */ |
mbed_official | 130:1dec54e4aec3 | 104 | void CRC_DeInit(void) |
mbed_official | 130:1dec54e4aec3 | 105 | { |
mbed_official | 130:1dec54e4aec3 | 106 | /* Set DR register to reset value */ |
mbed_official | 130:1dec54e4aec3 | 107 | CRC->DR = 0xFFFFFFFF; |
mbed_official | 130:1dec54e4aec3 | 108 | |
mbed_official | 130:1dec54e4aec3 | 109 | /* Set the POL register to the reset value: 0x04C11DB7 */ |
mbed_official | 130:1dec54e4aec3 | 110 | CRC->POL = 0x04C11DB7; |
mbed_official | 130:1dec54e4aec3 | 111 | |
mbed_official | 130:1dec54e4aec3 | 112 | /* Reset IDR register */ |
mbed_official | 130:1dec54e4aec3 | 113 | CRC->IDR = 0x00; |
mbed_official | 130:1dec54e4aec3 | 114 | |
mbed_official | 130:1dec54e4aec3 | 115 | /* Set INIT register to reset value */ |
mbed_official | 130:1dec54e4aec3 | 116 | CRC->INIT = 0xFFFFFFFF; |
mbed_official | 130:1dec54e4aec3 | 117 | |
mbed_official | 130:1dec54e4aec3 | 118 | /* Reset the CRC calculation unit */ |
mbed_official | 130:1dec54e4aec3 | 119 | CRC->CR = CRC_CR_RESET; |
mbed_official | 130:1dec54e4aec3 | 120 | } |
mbed_official | 130:1dec54e4aec3 | 121 | |
mbed_official | 130:1dec54e4aec3 | 122 | /** |
mbed_official | 130:1dec54e4aec3 | 123 | * @brief Resets the CRC calculation unit and sets INIT register content in DR register. |
mbed_official | 130:1dec54e4aec3 | 124 | * @param None |
mbed_official | 130:1dec54e4aec3 | 125 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 126 | */ |
mbed_official | 130:1dec54e4aec3 | 127 | void CRC_ResetDR(void) |
mbed_official | 130:1dec54e4aec3 | 128 | { |
mbed_official | 130:1dec54e4aec3 | 129 | /* Reset CRC generator */ |
mbed_official | 130:1dec54e4aec3 | 130 | CRC->CR |= CRC_CR_RESET; |
mbed_official | 130:1dec54e4aec3 | 131 | } |
mbed_official | 130:1dec54e4aec3 | 132 | |
mbed_official | 130:1dec54e4aec3 | 133 | /** |
mbed_official | 130:1dec54e4aec3 | 134 | * @brief Selects the polynomial size. This function is only applicable for |
mbed_official | 130:1dec54e4aec3 | 135 | * STM32F072 devices. |
mbed_official | 130:1dec54e4aec3 | 136 | * @param CRC_PolSize: Specifies the polynomial size. |
mbed_official | 130:1dec54e4aec3 | 137 | * This parameter can be: |
mbed_official | 130:1dec54e4aec3 | 138 | * @arg CRC_PolSize_7: 7-bit polynomial for CRC calculation |
mbed_official | 130:1dec54e4aec3 | 139 | * @arg CRC_PolSize_8: 8-bit polynomial for CRC calculation |
mbed_official | 130:1dec54e4aec3 | 140 | * @arg CRC_PolSize_16: 16-bit polynomial for CRC calculation |
mbed_official | 130:1dec54e4aec3 | 141 | * @arg CRC_PolSize_32: 32-bit polynomial for CRC calculation |
mbed_official | 130:1dec54e4aec3 | 142 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 143 | */ |
mbed_official | 130:1dec54e4aec3 | 144 | void CRC_PolynomialSizeSelect(uint32_t CRC_PolSize) |
mbed_official | 130:1dec54e4aec3 | 145 | { |
mbed_official | 130:1dec54e4aec3 | 146 | uint32_t tmpcr = 0; |
mbed_official | 130:1dec54e4aec3 | 147 | |
mbed_official | 130:1dec54e4aec3 | 148 | /* Check the parameter */ |
mbed_official | 130:1dec54e4aec3 | 149 | assert_param(IS_CRC_POL_SIZE(CRC_PolSize)); |
mbed_official | 130:1dec54e4aec3 | 150 | |
mbed_official | 130:1dec54e4aec3 | 151 | /* Get CR register value */ |
mbed_official | 130:1dec54e4aec3 | 152 | tmpcr = CRC->CR; |
mbed_official | 130:1dec54e4aec3 | 153 | |
mbed_official | 130:1dec54e4aec3 | 154 | /* Reset POL_SIZE bits */ |
mbed_official | 130:1dec54e4aec3 | 155 | tmpcr &= (uint32_t)~((uint32_t)CRC_CR_POLSIZE); |
mbed_official | 130:1dec54e4aec3 | 156 | /* Set the polynomial size */ |
mbed_official | 130:1dec54e4aec3 | 157 | tmpcr |= (uint32_t)CRC_PolSize; |
mbed_official | 130:1dec54e4aec3 | 158 | |
mbed_official | 130:1dec54e4aec3 | 159 | /* Write to CR register */ |
mbed_official | 130:1dec54e4aec3 | 160 | CRC->CR = (uint32_t)tmpcr; |
mbed_official | 130:1dec54e4aec3 | 161 | } |
mbed_official | 130:1dec54e4aec3 | 162 | |
mbed_official | 130:1dec54e4aec3 | 163 | /** |
mbed_official | 130:1dec54e4aec3 | 164 | * @brief Selects the reverse operation to be performed on input data. |
mbed_official | 130:1dec54e4aec3 | 165 | * @param CRC_ReverseInputData: Specifies the reverse operation on input data. |
mbed_official | 130:1dec54e4aec3 | 166 | * This parameter can be: |
mbed_official | 130:1dec54e4aec3 | 167 | * @arg CRC_ReverseInputData_No: No reverse operation is performed |
mbed_official | 130:1dec54e4aec3 | 168 | * @arg CRC_ReverseInputData_8bits: reverse operation performed on 8 bits |
mbed_official | 130:1dec54e4aec3 | 169 | * @arg CRC_ReverseInputData_16bits: reverse operation performed on 16 bits |
mbed_official | 130:1dec54e4aec3 | 170 | * @arg CRC_ReverseInputData_32bits: reverse operation performed on 32 bits |
mbed_official | 130:1dec54e4aec3 | 171 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 172 | */ |
mbed_official | 130:1dec54e4aec3 | 173 | void CRC_ReverseInputDataSelect(uint32_t CRC_ReverseInputData) |
mbed_official | 130:1dec54e4aec3 | 174 | { |
mbed_official | 130:1dec54e4aec3 | 175 | uint32_t tmpcr = 0; |
mbed_official | 130:1dec54e4aec3 | 176 | |
mbed_official | 130:1dec54e4aec3 | 177 | /* Check the parameter */ |
mbed_official | 130:1dec54e4aec3 | 178 | assert_param(IS_CRC_REVERSE_INPUT_DATA(CRC_ReverseInputData)); |
mbed_official | 130:1dec54e4aec3 | 179 | |
mbed_official | 130:1dec54e4aec3 | 180 | /* Get CR register value */ |
mbed_official | 130:1dec54e4aec3 | 181 | tmpcr = CRC->CR; |
mbed_official | 130:1dec54e4aec3 | 182 | |
mbed_official | 130:1dec54e4aec3 | 183 | /* Reset REV_IN bits */ |
mbed_official | 130:1dec54e4aec3 | 184 | tmpcr &= (uint32_t)~((uint32_t)CRC_CR_REV_IN); |
mbed_official | 130:1dec54e4aec3 | 185 | /* Set the reverse operation */ |
mbed_official | 130:1dec54e4aec3 | 186 | tmpcr |= (uint32_t)CRC_ReverseInputData; |
mbed_official | 130:1dec54e4aec3 | 187 | |
mbed_official | 130:1dec54e4aec3 | 188 | /* Write to CR register */ |
mbed_official | 130:1dec54e4aec3 | 189 | CRC->CR = (uint32_t)tmpcr; |
mbed_official | 130:1dec54e4aec3 | 190 | } |
mbed_official | 130:1dec54e4aec3 | 191 | |
mbed_official | 130:1dec54e4aec3 | 192 | /** |
mbed_official | 130:1dec54e4aec3 | 193 | * @brief Enables or disable the reverse operation on output data. |
mbed_official | 130:1dec54e4aec3 | 194 | * The reverse operation on output data is performed on 32-bit. |
mbed_official | 130:1dec54e4aec3 | 195 | * @param NewState: new state of the reverse operation on output data. |
mbed_official | 130:1dec54e4aec3 | 196 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 130:1dec54e4aec3 | 197 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 198 | */ |
mbed_official | 130:1dec54e4aec3 | 199 | void CRC_ReverseOutputDataCmd(FunctionalState NewState) |
mbed_official | 130:1dec54e4aec3 | 200 | { |
mbed_official | 130:1dec54e4aec3 | 201 | /* Check the parameters */ |
mbed_official | 130:1dec54e4aec3 | 202 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 130:1dec54e4aec3 | 203 | |
mbed_official | 130:1dec54e4aec3 | 204 | if (NewState != DISABLE) |
mbed_official | 130:1dec54e4aec3 | 205 | { |
mbed_official | 130:1dec54e4aec3 | 206 | /* Enable reverse operation on output data */ |
mbed_official | 130:1dec54e4aec3 | 207 | CRC->CR |= CRC_CR_REV_OUT; |
mbed_official | 130:1dec54e4aec3 | 208 | } |
mbed_official | 130:1dec54e4aec3 | 209 | else |
mbed_official | 130:1dec54e4aec3 | 210 | { |
mbed_official | 130:1dec54e4aec3 | 211 | /* Disable reverse operation on output data */ |
mbed_official | 130:1dec54e4aec3 | 212 | CRC->CR &= (uint32_t)~((uint32_t)CRC_CR_REV_OUT); |
mbed_official | 130:1dec54e4aec3 | 213 | } |
mbed_official | 130:1dec54e4aec3 | 214 | } |
mbed_official | 130:1dec54e4aec3 | 215 | |
mbed_official | 130:1dec54e4aec3 | 216 | /** |
mbed_official | 130:1dec54e4aec3 | 217 | * @brief Initializes the INIT register. |
mbed_official | 130:1dec54e4aec3 | 218 | * @note After resetting CRC calculation unit, CRC_InitValue is stored in DR register |
mbed_official | 130:1dec54e4aec3 | 219 | * @param CRC_InitValue: Programmable initial CRC value |
mbed_official | 130:1dec54e4aec3 | 220 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 221 | */ |
mbed_official | 130:1dec54e4aec3 | 222 | void CRC_SetInitRegister(uint32_t CRC_InitValue) |
mbed_official | 130:1dec54e4aec3 | 223 | { |
mbed_official | 130:1dec54e4aec3 | 224 | CRC->INIT = CRC_InitValue; |
mbed_official | 130:1dec54e4aec3 | 225 | } |
mbed_official | 130:1dec54e4aec3 | 226 | |
mbed_official | 130:1dec54e4aec3 | 227 | /** |
mbed_official | 130:1dec54e4aec3 | 228 | * @brief Initializes the polynomail coefficients. This function is only |
mbed_official | 130:1dec54e4aec3 | 229 | * applicable for STM32F072 devices. |
mbed_official | 130:1dec54e4aec3 | 230 | * @param CRC_Pol: Polynomial to be used for CRC calculation. |
mbed_official | 130:1dec54e4aec3 | 231 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 232 | */ |
mbed_official | 130:1dec54e4aec3 | 233 | void CRC_SetPolynomial(uint32_t CRC_Pol) |
mbed_official | 130:1dec54e4aec3 | 234 | { |
mbed_official | 130:1dec54e4aec3 | 235 | CRC->POL = CRC_Pol; |
mbed_official | 130:1dec54e4aec3 | 236 | } |
mbed_official | 130:1dec54e4aec3 | 237 | |
mbed_official | 130:1dec54e4aec3 | 238 | /** |
mbed_official | 130:1dec54e4aec3 | 239 | * @} |
mbed_official | 130:1dec54e4aec3 | 240 | */ |
mbed_official | 130:1dec54e4aec3 | 241 | |
mbed_official | 130:1dec54e4aec3 | 242 | /** @defgroup CRC_Group2 CRC computation of one/many 32-bit data functions |
mbed_official | 130:1dec54e4aec3 | 243 | * @brief CRC computation of one/many 32-bit data functions |
mbed_official | 130:1dec54e4aec3 | 244 | * |
mbed_official | 130:1dec54e4aec3 | 245 | @verbatim |
mbed_official | 130:1dec54e4aec3 | 246 | =============================================================================== |
mbed_official | 130:1dec54e4aec3 | 247 | ##### CRC computation functions ##### |
mbed_official | 130:1dec54e4aec3 | 248 | =============================================================================== |
mbed_official | 130:1dec54e4aec3 | 249 | |
mbed_official | 130:1dec54e4aec3 | 250 | @endverbatim |
mbed_official | 130:1dec54e4aec3 | 251 | * @{ |
mbed_official | 130:1dec54e4aec3 | 252 | */ |
mbed_official | 130:1dec54e4aec3 | 253 | |
mbed_official | 130:1dec54e4aec3 | 254 | /** |
mbed_official | 130:1dec54e4aec3 | 255 | * @brief Computes the 32-bit CRC of a given data word(32-bit). |
mbed_official | 130:1dec54e4aec3 | 256 | * @param CRC_Data: data word(32-bit) to compute its CRC |
mbed_official | 130:1dec54e4aec3 | 257 | * @retval 32-bit CRC |
mbed_official | 130:1dec54e4aec3 | 258 | */ |
mbed_official | 130:1dec54e4aec3 | 259 | uint32_t CRC_CalcCRC(uint32_t CRC_Data) |
mbed_official | 130:1dec54e4aec3 | 260 | { |
mbed_official | 130:1dec54e4aec3 | 261 | CRC->DR = CRC_Data; |
mbed_official | 130:1dec54e4aec3 | 262 | |
mbed_official | 130:1dec54e4aec3 | 263 | return (CRC->DR); |
mbed_official | 130:1dec54e4aec3 | 264 | } |
mbed_official | 130:1dec54e4aec3 | 265 | |
mbed_official | 130:1dec54e4aec3 | 266 | /** |
mbed_official | 130:1dec54e4aec3 | 267 | * @brief Computes the 16-bit CRC of a given 16-bit data. This function is only |
mbed_official | 130:1dec54e4aec3 | 268 | * applicable for STM32F072 devices. |
mbed_official | 130:1dec54e4aec3 | 269 | * @param CRC_Data: data half-word(16-bit) to compute its CRC |
mbed_official | 130:1dec54e4aec3 | 270 | * @retval 16-bit CRC |
mbed_official | 130:1dec54e4aec3 | 271 | */ |
mbed_official | 130:1dec54e4aec3 | 272 | uint32_t CRC_CalcCRC16bits(uint16_t CRC_Data) |
mbed_official | 130:1dec54e4aec3 | 273 | { |
mbed_official | 130:1dec54e4aec3 | 274 | *(uint16_t*)(CRC_BASE) = (uint16_t) CRC_Data; |
mbed_official | 130:1dec54e4aec3 | 275 | |
mbed_official | 130:1dec54e4aec3 | 276 | return (CRC->DR); |
mbed_official | 130:1dec54e4aec3 | 277 | } |
mbed_official | 130:1dec54e4aec3 | 278 | |
mbed_official | 130:1dec54e4aec3 | 279 | /** |
mbed_official | 130:1dec54e4aec3 | 280 | * @brief Computes the 8-bit CRC of a given 8-bit data. This function is only |
mbed_official | 130:1dec54e4aec3 | 281 | * applicable for STM32F072 devices. |
mbed_official | 130:1dec54e4aec3 | 282 | * @param CRC_Data: 8-bit data to compute its CRC |
mbed_official | 130:1dec54e4aec3 | 283 | * @retval 8-bit CRC |
mbed_official | 130:1dec54e4aec3 | 284 | */ |
mbed_official | 130:1dec54e4aec3 | 285 | uint32_t CRC_CalcCRC8bits(uint8_t CRC_Data) |
mbed_official | 130:1dec54e4aec3 | 286 | { |
mbed_official | 130:1dec54e4aec3 | 287 | *(uint8_t*)(CRC_BASE) = (uint8_t) CRC_Data; |
mbed_official | 130:1dec54e4aec3 | 288 | |
mbed_official | 130:1dec54e4aec3 | 289 | return (CRC->DR); |
mbed_official | 130:1dec54e4aec3 | 290 | } |
mbed_official | 130:1dec54e4aec3 | 291 | |
mbed_official | 130:1dec54e4aec3 | 292 | /** |
mbed_official | 130:1dec54e4aec3 | 293 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). |
mbed_official | 130:1dec54e4aec3 | 294 | * @param pBuffer: pointer to the buffer containing the data to be computed |
mbed_official | 130:1dec54e4aec3 | 295 | * @param BufferLength: length of the buffer to be computed |
mbed_official | 130:1dec54e4aec3 | 296 | * @retval 32-bit CRC |
mbed_official | 130:1dec54e4aec3 | 297 | */ |
mbed_official | 130:1dec54e4aec3 | 298 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) |
mbed_official | 130:1dec54e4aec3 | 299 | { |
mbed_official | 130:1dec54e4aec3 | 300 | uint32_t index = 0; |
mbed_official | 130:1dec54e4aec3 | 301 | |
mbed_official | 130:1dec54e4aec3 | 302 | for(index = 0; index < BufferLength; index++) |
mbed_official | 130:1dec54e4aec3 | 303 | { |
mbed_official | 130:1dec54e4aec3 | 304 | CRC->DR = pBuffer[index]; |
mbed_official | 130:1dec54e4aec3 | 305 | } |
mbed_official | 130:1dec54e4aec3 | 306 | return (CRC->DR); |
mbed_official | 130:1dec54e4aec3 | 307 | } |
mbed_official | 130:1dec54e4aec3 | 308 | |
mbed_official | 130:1dec54e4aec3 | 309 | /** |
mbed_official | 130:1dec54e4aec3 | 310 | * @brief Returns the current CRC value. |
mbed_official | 130:1dec54e4aec3 | 311 | * @param None |
mbed_official | 130:1dec54e4aec3 | 312 | * @retval 32-bit CRC |
mbed_official | 130:1dec54e4aec3 | 313 | */ |
mbed_official | 130:1dec54e4aec3 | 314 | uint32_t CRC_GetCRC(void) |
mbed_official | 130:1dec54e4aec3 | 315 | { |
mbed_official | 130:1dec54e4aec3 | 316 | return (CRC->DR); |
mbed_official | 130:1dec54e4aec3 | 317 | } |
mbed_official | 130:1dec54e4aec3 | 318 | |
mbed_official | 130:1dec54e4aec3 | 319 | /** |
mbed_official | 130:1dec54e4aec3 | 320 | * @} |
mbed_official | 130:1dec54e4aec3 | 321 | */ |
mbed_official | 130:1dec54e4aec3 | 322 | |
mbed_official | 130:1dec54e4aec3 | 323 | /** @defgroup CRC_Group3 CRC Independent Register (IDR) access functions |
mbed_official | 130:1dec54e4aec3 | 324 | * @brief CRC Independent Register (IDR) access (write/read) functions |
mbed_official | 130:1dec54e4aec3 | 325 | * |
mbed_official | 130:1dec54e4aec3 | 326 | @verbatim |
mbed_official | 130:1dec54e4aec3 | 327 | =============================================================================== |
mbed_official | 130:1dec54e4aec3 | 328 | ##### CRC Independent Register (IDR) access functions ##### |
mbed_official | 130:1dec54e4aec3 | 329 | =============================================================================== |
mbed_official | 130:1dec54e4aec3 | 330 | |
mbed_official | 130:1dec54e4aec3 | 331 | @endverbatim |
mbed_official | 130:1dec54e4aec3 | 332 | * @{ |
mbed_official | 130:1dec54e4aec3 | 333 | */ |
mbed_official | 130:1dec54e4aec3 | 334 | |
mbed_official | 130:1dec54e4aec3 | 335 | /** |
mbed_official | 130:1dec54e4aec3 | 336 | * @brief Stores an 8-bit data in the Independent Data(ID) register. |
mbed_official | 130:1dec54e4aec3 | 337 | * @param CRC_IDValue: 8-bit value to be stored in the ID register |
mbed_official | 130:1dec54e4aec3 | 338 | * @retval None |
mbed_official | 130:1dec54e4aec3 | 339 | */ |
mbed_official | 130:1dec54e4aec3 | 340 | void CRC_SetIDRegister(uint8_t CRC_IDValue) |
mbed_official | 130:1dec54e4aec3 | 341 | { |
mbed_official | 130:1dec54e4aec3 | 342 | CRC->IDR = CRC_IDValue; |
mbed_official | 130:1dec54e4aec3 | 343 | } |
mbed_official | 130:1dec54e4aec3 | 344 | |
mbed_official | 130:1dec54e4aec3 | 345 | /** |
mbed_official | 130:1dec54e4aec3 | 346 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register |
mbed_official | 130:1dec54e4aec3 | 347 | * @param None |
mbed_official | 130:1dec54e4aec3 | 348 | * @retval 8-bit value of the ID register |
mbed_official | 130:1dec54e4aec3 | 349 | */ |
mbed_official | 130:1dec54e4aec3 | 350 | uint8_t CRC_GetIDRegister(void) |
mbed_official | 130:1dec54e4aec3 | 351 | { |
mbed_official | 130:1dec54e4aec3 | 352 | return (CRC->IDR); |
mbed_official | 130:1dec54e4aec3 | 353 | } |
mbed_official | 130:1dec54e4aec3 | 354 | |
mbed_official | 130:1dec54e4aec3 | 355 | /** |
mbed_official | 130:1dec54e4aec3 | 356 | * @} |
mbed_official | 130:1dec54e4aec3 | 357 | */ |
mbed_official | 130:1dec54e4aec3 | 358 | |
mbed_official | 130:1dec54e4aec3 | 359 | /** |
mbed_official | 130:1dec54e4aec3 | 360 | * @} |
mbed_official | 130:1dec54e4aec3 | 361 | */ |
mbed_official | 130:1dec54e4aec3 | 362 | |
mbed_official | 130:1dec54e4aec3 | 363 | /** |
mbed_official | 130:1dec54e4aec3 | 364 | * @} |
mbed_official | 130:1dec54e4aec3 | 365 | */ |
mbed_official | 130:1dec54e4aec3 | 366 | |
mbed_official | 130:1dec54e4aec3 | 367 | /** |
mbed_official | 130:1dec54e4aec3 | 368 | * @} |
mbed_official | 130:1dec54e4aec3 | 369 | */ |
mbed_official | 130:1dec54e4aec3 | 370 | |
mbed_official | 130:1dec54e4aec3 | 371 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |