mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
186:707f6e361f3e
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /**
<> 144:ef7eb2e8f9f7 2 ******************************************************************************
<> 144:ef7eb2e8f9f7 3 * @file stm32l0xx_hal_crc.c
<> 144:ef7eb2e8f9f7 4 * @author MCD Application Team
<> 144:ef7eb2e8f9f7 5 * @brief CRC HAL module driver.
<> 144:ef7eb2e8f9f7 6 *
<> 144:ef7eb2e8f9f7 7 * This file provides firmware functions to manage the following
<> 144:ef7eb2e8f9f7 8 * functionalities of the CRC peripheral:
<> 144:ef7eb2e8f9f7 9 * + Initialization and de-initialization functions
<> 144:ef7eb2e8f9f7 10 * + Peripheral Control functions
<> 144:ef7eb2e8f9f7 11 * + Peripheral State functions
<> 144:ef7eb2e8f9f7 12 *
<> 144:ef7eb2e8f9f7 13 @verbatim
<> 144:ef7eb2e8f9f7 14 ===============================================================================
<> 144:ef7eb2e8f9f7 15 ##### CRC How to use this driver #####
<> 144:ef7eb2e8f9f7 16 ===============================================================================
<> 144:ef7eb2e8f9f7 17 [..]
<> 144:ef7eb2e8f9f7 18
<> 144:ef7eb2e8f9f7 19 (#) Enable CRC AHB clock using __HAL_RCC_CRC_CLK_ENABLE();
<> 144:ef7eb2e8f9f7 20
<> 144:ef7eb2e8f9f7 21 (#) Initialize CRC calculator
<> 144:ef7eb2e8f9f7 22 (++) specify generating polynomial (IP default or non-default one)
<> 144:ef7eb2e8f9f7 23 (++) specify initialization value (IP default or non-default one)
<> 144:ef7eb2e8f9f7 24 (++) specify input data format
<> 144:ef7eb2e8f9f7 25 (++) specify input or output data inversion mode if any
<> 144:ef7eb2e8f9f7 26
<> 144:ef7eb2e8f9f7 27 (#) Use HAL_CRC_Accumulate() function to compute the CRC value of the
<> 144:ef7eb2e8f9f7 28 input data buffer starting with the previously computed CRC as
<> 144:ef7eb2e8f9f7 29 initialization value
<> 144:ef7eb2e8f9f7 30
<> 144:ef7eb2e8f9f7 31 (#) Use HAL_CRC_Calculate() function to compute the CRC value of the
<> 144:ef7eb2e8f9f7 32 input data buffer starting with the defined initialization value
<> 144:ef7eb2e8f9f7 33 (default or non-default) to initiate CRC calculation
<> 144:ef7eb2e8f9f7 34
<> 144:ef7eb2e8f9f7 35 @endverbatim
<> 144:ef7eb2e8f9f7 36 ******************************************************************************
<> 144:ef7eb2e8f9f7 37 * @attention
<> 144:ef7eb2e8f9f7 38 *
<> 144:ef7eb2e8f9f7 39 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
<> 144:ef7eb2e8f9f7 40 *
<> 144:ef7eb2e8f9f7 41 * Redistribution and use in source and binary forms, with or without modification,
<> 144:ef7eb2e8f9f7 42 * are permitted provided that the following conditions are met:
<> 144:ef7eb2e8f9f7 43 * 1. Redistributions of source code must retain the above copyright notice,
<> 144:ef7eb2e8f9f7 44 * this list of conditions and the following disclaimer.
<> 144:ef7eb2e8f9f7 45 * 2. Redistributions in binary form must reproduce the above copyright notice,
<> 144:ef7eb2e8f9f7 46 * this list of conditions and the following disclaimer in the documentation
<> 144:ef7eb2e8f9f7 47 * and/or other materials provided with the distribution.
<> 144:ef7eb2e8f9f7 48 * 3. Neither the name of STMicroelectronics nor the names of its contributors
<> 144:ef7eb2e8f9f7 49 * may be used to endorse or promote products derived from this software
<> 144:ef7eb2e8f9f7 50 * without specific prior written permission.
<> 144:ef7eb2e8f9f7 51 *
<> 144:ef7eb2e8f9f7 52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
<> 144:ef7eb2e8f9f7 53 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
<> 144:ef7eb2e8f9f7 54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 144:ef7eb2e8f9f7 55 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
<> 144:ef7eb2e8f9f7 56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
<> 144:ef7eb2e8f9f7 57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
<> 144:ef7eb2e8f9f7 58 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
<> 144:ef7eb2e8f9f7 59 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
<> 144:ef7eb2e8f9f7 60 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<> 144:ef7eb2e8f9f7 61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 144:ef7eb2e8f9f7 62 *
<> 144:ef7eb2e8f9f7 63 ******************************************************************************
<> 144:ef7eb2e8f9f7 64 */
<> 144:ef7eb2e8f9f7 65
<> 144:ef7eb2e8f9f7 66 /* Includes ------------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 67 #include "stm32l0xx_hal.h"
<> 144:ef7eb2e8f9f7 68
<> 144:ef7eb2e8f9f7 69 /** @addtogroup STM32L0xx_HAL_Driver
<> 144:ef7eb2e8f9f7 70 * @{
<> 144:ef7eb2e8f9f7 71 */
<> 144:ef7eb2e8f9f7 72
<> 144:ef7eb2e8f9f7 73 #ifdef HAL_CRC_MODULE_ENABLED
<> 144:ef7eb2e8f9f7 74
<> 144:ef7eb2e8f9f7 75 /** @addtogroup CRC
<> 144:ef7eb2e8f9f7 76 * @brief CRC HAL module driver
<> 144:ef7eb2e8f9f7 77 * @{
<> 144:ef7eb2e8f9f7 78 */
<> 144:ef7eb2e8f9f7 79
<> 144:ef7eb2e8f9f7 80 /** @addtogroup CRC_Private
<> 144:ef7eb2e8f9f7 81 * @{
<> 144:ef7eb2e8f9f7 82 */
<> 144:ef7eb2e8f9f7 83 /* Private typedef -----------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 84 /* Private define ------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 85 /* Private macro -------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 86 /* Private variables ---------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 87 /* Private function prototypes -----------------------------------------------*/
<> 144:ef7eb2e8f9f7 88 static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength);
<> 144:ef7eb2e8f9f7 89 static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength);
<> 144:ef7eb2e8f9f7 90 /**
<> 144:ef7eb2e8f9f7 91 * @}
<> 144:ef7eb2e8f9f7 92 */
<> 144:ef7eb2e8f9f7 93
<> 144:ef7eb2e8f9f7 94 /* Exported functions --------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 95 /** @addtogroup CRC_Exported_Functions
<> 144:ef7eb2e8f9f7 96 * @{
<> 144:ef7eb2e8f9f7 97 */
<> 144:ef7eb2e8f9f7 98
<> 144:ef7eb2e8f9f7 99 /** @addtogroup CRC_Exported_Functions_Group1
<> 144:ef7eb2e8f9f7 100 * @brief Initialization and Configuration functions.
<> 144:ef7eb2e8f9f7 101 *
<> 144:ef7eb2e8f9f7 102 @verbatim
<> 144:ef7eb2e8f9f7 103 ===============================================================================
<> 144:ef7eb2e8f9f7 104 ##### Initialization and de-initialization functions #####
<> 144:ef7eb2e8f9f7 105 ===============================================================================
<> 144:ef7eb2e8f9f7 106 [..]
<> 144:ef7eb2e8f9f7 107 This section provides functions allowing to:
<> 144:ef7eb2e8f9f7 108
<> 144:ef7eb2e8f9f7 109 (#) Initialize the CRC according to the specified parameters
<> 144:ef7eb2e8f9f7 110 in the CRC_InitTypeDef and create the associated handle
<> 144:ef7eb2e8f9f7 111
<> 144:ef7eb2e8f9f7 112 (#) DeInitialize the CRC peripheral
<> 144:ef7eb2e8f9f7 113
<> 144:ef7eb2e8f9f7 114 (#) Initialize the CRC MSP
<> 144:ef7eb2e8f9f7 115
<> 144:ef7eb2e8f9f7 116 (#) DeInitialize CRC MSP
<> 144:ef7eb2e8f9f7 117
<> 144:ef7eb2e8f9f7 118 @endverbatim
<> 144:ef7eb2e8f9f7 119 * @{
<> 144:ef7eb2e8f9f7 120 */
<> 144:ef7eb2e8f9f7 121
<> 144:ef7eb2e8f9f7 122 /**
<> 144:ef7eb2e8f9f7 123 * @brief Initializes the CRC according to the specified
<> 144:ef7eb2e8f9f7 124 * parameters in the CRC_InitTypeDef and creates the associated handle.
<> 144:ef7eb2e8f9f7 125 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 126 * @retval HAL status
<> 144:ef7eb2e8f9f7 127 */
<> 144:ef7eb2e8f9f7 128 HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
<> 144:ef7eb2e8f9f7 129 {
<> 144:ef7eb2e8f9f7 130 /* Check the CRC handle allocation */
<> 144:ef7eb2e8f9f7 131 if(hcrc == NULL)
<> 144:ef7eb2e8f9f7 132 {
<> 144:ef7eb2e8f9f7 133 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 134 }
<> 144:ef7eb2e8f9f7 135
<> 144:ef7eb2e8f9f7 136 /* Check the parameters */
<> 144:ef7eb2e8f9f7 137 assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
<> 144:ef7eb2e8f9f7 138
<> 144:ef7eb2e8f9f7 139 if(hcrc->State == HAL_CRC_STATE_RESET)
<> 144:ef7eb2e8f9f7 140 {
<> 144:ef7eb2e8f9f7 141 /* Allocate lock resource and initialize it */
<> 144:ef7eb2e8f9f7 142 hcrc->Lock = HAL_UNLOCKED;
<> 144:ef7eb2e8f9f7 143
<> 144:ef7eb2e8f9f7 144 /* Init the low level hardware */
<> 144:ef7eb2e8f9f7 145 HAL_CRC_MspInit(hcrc);
<> 144:ef7eb2e8f9f7 146 }
<> 144:ef7eb2e8f9f7 147
<> 144:ef7eb2e8f9f7 148 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 149 hcrc->State = HAL_CRC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 150
<> 144:ef7eb2e8f9f7 151 /* check whether or not non-default generating polynomial has been
<> 144:ef7eb2e8f9f7 152 * picked up by user */
<> 144:ef7eb2e8f9f7 153 assert_param(IS_DEFAULT_POLYNOMIAL(hcrc->Init.DefaultPolynomialUse));
<> 144:ef7eb2e8f9f7 154 if (hcrc->Init.DefaultPolynomialUse == DEFAULT_POLYNOMIAL_ENABLE)
<> 144:ef7eb2e8f9f7 155 {
<> 144:ef7eb2e8f9f7 156 /* initialize IP with default generating polynomial */
<> 144:ef7eb2e8f9f7 157 WRITE_REG(hcrc->Instance->POL, DEFAULT_CRC32_POLY);
<> 144:ef7eb2e8f9f7 158 MODIFY_REG(hcrc->Instance->CR, CRC_CR_POLYSIZE, CRC_POLYLENGTH_32B);
<> 144:ef7eb2e8f9f7 159 }
<> 144:ef7eb2e8f9f7 160 else
<> 144:ef7eb2e8f9f7 161 {
<> 144:ef7eb2e8f9f7 162 /* initialize CRC IP with generating polynomial defined by user */
<> 144:ef7eb2e8f9f7 163 assert_param(IS_CRC_POL_LENGTH(hcrc->Init.CRCLength));
<> 144:ef7eb2e8f9f7 164 if (HAL_CRCEx_Polynomial_Set(hcrc, hcrc->Init.GeneratingPolynomial, hcrc->Init.CRCLength) != HAL_OK)
<> 144:ef7eb2e8f9f7 165 {
<> 144:ef7eb2e8f9f7 166 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 167 }
<> 144:ef7eb2e8f9f7 168 }
<> 144:ef7eb2e8f9f7 169
<> 144:ef7eb2e8f9f7 170 /* check whether or not non-default CRC initial value has been
<> 144:ef7eb2e8f9f7 171 * picked up by user */
<> 144:ef7eb2e8f9f7 172 assert_param(IS_DEFAULT_INIT_VALUE(hcrc->Init.DefaultInitValueUse));
<> 144:ef7eb2e8f9f7 173 if (hcrc->Init.DefaultInitValueUse == DEFAULT_INIT_VALUE_ENABLE)
<> 144:ef7eb2e8f9f7 174 {
<> 144:ef7eb2e8f9f7 175 WRITE_REG(hcrc->Instance->INIT, DEFAULT_CRC_INITVALUE);
<> 144:ef7eb2e8f9f7 176 }
<> 144:ef7eb2e8f9f7 177 else
<> 144:ef7eb2e8f9f7 178 {
<> 144:ef7eb2e8f9f7 179 WRITE_REG(hcrc->Instance->INIT, hcrc->Init.InitValue);
<> 144:ef7eb2e8f9f7 180 }
<> 144:ef7eb2e8f9f7 181
<> 144:ef7eb2e8f9f7 182
<> 144:ef7eb2e8f9f7 183 /* set input data inversion mode */
<> 144:ef7eb2e8f9f7 184 assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(hcrc->Init.InputDataInversionMode));
<> 144:ef7eb2e8f9f7 185 MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_IN, hcrc->Init.InputDataInversionMode);
<> 144:ef7eb2e8f9f7 186
<> 144:ef7eb2e8f9f7 187 /* set output data inversion mode */
<> 144:ef7eb2e8f9f7 188 assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(hcrc->Init.OutputDataInversionMode));
<> 144:ef7eb2e8f9f7 189 MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_OUT, hcrc->Init.OutputDataInversionMode);
<> 144:ef7eb2e8f9f7 190
<> 144:ef7eb2e8f9f7 191 /* makes sure the input data format (bytes, halfwords or words stream)
<> 144:ef7eb2e8f9f7 192 * is properly specified by user */
<> 144:ef7eb2e8f9f7 193 assert_param(IS_CRC_INPUTDATA_FORMAT(hcrc->InputDataFormat));
<> 144:ef7eb2e8f9f7 194
<> 144:ef7eb2e8f9f7 195 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 196 hcrc->State = HAL_CRC_STATE_READY;
<> 144:ef7eb2e8f9f7 197
<> 144:ef7eb2e8f9f7 198 /* Return function status */
<> 144:ef7eb2e8f9f7 199 return HAL_OK;
<> 144:ef7eb2e8f9f7 200 }
<> 144:ef7eb2e8f9f7 201
<> 144:ef7eb2e8f9f7 202 /**
<> 144:ef7eb2e8f9f7 203 * @brief DeInitializes the CRC peripheral.
<> 144:ef7eb2e8f9f7 204 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 205 * @retval HAL status
<> 144:ef7eb2e8f9f7 206 */
<> 144:ef7eb2e8f9f7 207 HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)
<> 144:ef7eb2e8f9f7 208 {
<> 144:ef7eb2e8f9f7 209 /* Check the CRC handle allocation */
<> 144:ef7eb2e8f9f7 210 if(hcrc == NULL)
<> 144:ef7eb2e8f9f7 211 {
<> 144:ef7eb2e8f9f7 212 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 213 }
<> 144:ef7eb2e8f9f7 214
<> 144:ef7eb2e8f9f7 215 /* Check the parameters */
<> 144:ef7eb2e8f9f7 216 assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
<> 144:ef7eb2e8f9f7 217
<> 144:ef7eb2e8f9f7 218 /* Check the CRC peripheral state */
<> 144:ef7eb2e8f9f7 219 if(hcrc->State == HAL_CRC_STATE_BUSY)
<> 144:ef7eb2e8f9f7 220 {
<> 144:ef7eb2e8f9f7 221 return HAL_BUSY;
<> 144:ef7eb2e8f9f7 222 }
<> 144:ef7eb2e8f9f7 223
<> 144:ef7eb2e8f9f7 224 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 225 hcrc->State = HAL_CRC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 226
<> 144:ef7eb2e8f9f7 227 /* Reset CRC calculation unit */
<> 144:ef7eb2e8f9f7 228 __HAL_CRC_DR_RESET(hcrc);
Anna Bridge 186:707f6e361f3e 229
Anna Bridge 186:707f6e361f3e 230 /* Reset IDR register content */
Anna Bridge 186:707f6e361f3e 231 CLEAR_BIT(hcrc->Instance->IDR, CRC_IDR_IDR) ;
<> 144:ef7eb2e8f9f7 232
<> 144:ef7eb2e8f9f7 233 /* DeInit the low level hardware */
<> 144:ef7eb2e8f9f7 234 HAL_CRC_MspDeInit(hcrc);
<> 144:ef7eb2e8f9f7 235
<> 144:ef7eb2e8f9f7 236 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 237 hcrc->State = HAL_CRC_STATE_RESET;
Anna Bridge 186:707f6e361f3e 238
<> 144:ef7eb2e8f9f7 239 /* Process unlocked */
<> 144:ef7eb2e8f9f7 240 __HAL_UNLOCK(hcrc);
<> 144:ef7eb2e8f9f7 241
<> 144:ef7eb2e8f9f7 242 /* Return function status */
<> 144:ef7eb2e8f9f7 243 return HAL_OK;
<> 144:ef7eb2e8f9f7 244 }
<> 144:ef7eb2e8f9f7 245
<> 144:ef7eb2e8f9f7 246 /**
<> 144:ef7eb2e8f9f7 247 * @brief Initializes the CRC MSP.
<> 144:ef7eb2e8f9f7 248 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 249 * @retval None
<> 144:ef7eb2e8f9f7 250 */
<> 144:ef7eb2e8f9f7 251 __weak void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
<> 144:ef7eb2e8f9f7 252 {
<> 144:ef7eb2e8f9f7 253 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 254 UNUSED(hcrc);
<> 144:ef7eb2e8f9f7 255
<> 144:ef7eb2e8f9f7 256 /* NOTE : This function should not be modified, when the callback is needed,
<> 144:ef7eb2e8f9f7 257 the HAL_CRC_MspInit can be implemented in the user file
<> 144:ef7eb2e8f9f7 258 */
<> 144:ef7eb2e8f9f7 259 }
<> 144:ef7eb2e8f9f7 260
<> 144:ef7eb2e8f9f7 261 /**
<> 144:ef7eb2e8f9f7 262 * @brief DeInitializes the CRC MSP.
<> 144:ef7eb2e8f9f7 263 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 264 * @retval None
<> 144:ef7eb2e8f9f7 265 */
<> 144:ef7eb2e8f9f7 266 __weak void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
<> 144:ef7eb2e8f9f7 267 {
<> 144:ef7eb2e8f9f7 268 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 269 UNUSED(hcrc);
<> 144:ef7eb2e8f9f7 270
<> 144:ef7eb2e8f9f7 271 /* NOTE : This function should not be modified, when the callback is needed,
<> 144:ef7eb2e8f9f7 272 the HAL_CRC_MspDeInit can be implemented in the user file
<> 144:ef7eb2e8f9f7 273 */
<> 144:ef7eb2e8f9f7 274 }
<> 144:ef7eb2e8f9f7 275
<> 144:ef7eb2e8f9f7 276
<> 144:ef7eb2e8f9f7 277 /**
<> 144:ef7eb2e8f9f7 278 * @}
<> 144:ef7eb2e8f9f7 279 */
<> 144:ef7eb2e8f9f7 280
<> 144:ef7eb2e8f9f7 281 /** @addtogroup CRC_Exported_Functions_Group2
<> 144:ef7eb2e8f9f7 282 * @brief management functions.
<> 144:ef7eb2e8f9f7 283 *
<> 144:ef7eb2e8f9f7 284 @verbatim
<> 144:ef7eb2e8f9f7 285 ===============================================================================
<> 144:ef7eb2e8f9f7 286 ##### Peripheral Control functions #####
<> 144:ef7eb2e8f9f7 287 ===============================================================================
<> 144:ef7eb2e8f9f7 288 [..] This section provides functions allowing to:
<> 144:ef7eb2e8f9f7 289
<> 144:ef7eb2e8f9f7 290 (#) Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
<> 144:ef7eb2e8f9f7 291 using combination of the previous CRC value and the new one.
<> 144:ef7eb2e8f9f7 292
<> 144:ef7eb2e8f9f7 293 or
<> 144:ef7eb2e8f9f7 294
<> 144:ef7eb2e8f9f7 295 (#) Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
<> 144:ef7eb2e8f9f7 296 independently of the previous CRC value.
<> 144:ef7eb2e8f9f7 297
<> 144:ef7eb2e8f9f7 298 @endverbatim
<> 144:ef7eb2e8f9f7 299 * @{
<> 144:ef7eb2e8f9f7 300 */
<> 144:ef7eb2e8f9f7 301
<> 144:ef7eb2e8f9f7 302 /**
<> 144:ef7eb2e8f9f7 303 * @brief Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
<> 144:ef7eb2e8f9f7 304 * starting with the previously computed CRC as initialization value.
<> 144:ef7eb2e8f9f7 305 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 306 * @param pBuffer: pointer to the input data buffer, exact input data format is
<> 144:ef7eb2e8f9f7 307 * provided by hcrc->InputDataFormat.
<> 144:ef7eb2e8f9f7 308 * @param BufferLength: input data buffer length (number of bytes if pBuffer
<> 144:ef7eb2e8f9f7 309 * type is * uint8_t, number of half-words if pBuffer type is * uint16_t,
<> 144:ef7eb2e8f9f7 310 * number of words if pBuffer type is * uint32_t).
<> 144:ef7eb2e8f9f7 311 * @note By default, the API expects a uint32_t pointer as input buffer parameter.
<> 144:ef7eb2e8f9f7 312 * Input buffer pointers with other types simply need to be cast in uint32_t
<> 144:ef7eb2e8f9f7 313 * and the API will internally adjust its input data processing based on the
<> 144:ef7eb2e8f9f7 314 * handle field hcrc->InputDataFormat.
<> 144:ef7eb2e8f9f7 315 * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
<> 144:ef7eb2e8f9f7 316 */
<> 144:ef7eb2e8f9f7 317 uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
<> 144:ef7eb2e8f9f7 318 {
<> 151:5eaa88a5bcc7 319 uint32_t index = 0U; /* CRC input data buffer index */
<> 151:5eaa88a5bcc7 320 uint32_t temp = 0U; /* CRC output (read from hcrc->Instance->DR register) */
<> 144:ef7eb2e8f9f7 321
<> 144:ef7eb2e8f9f7 322 /* Process locked */
<> 144:ef7eb2e8f9f7 323 __HAL_LOCK(hcrc);
<> 144:ef7eb2e8f9f7 324
<> 144:ef7eb2e8f9f7 325 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 326 hcrc->State = HAL_CRC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 327
<> 144:ef7eb2e8f9f7 328 switch (hcrc->InputDataFormat)
<> 144:ef7eb2e8f9f7 329 {
<> 144:ef7eb2e8f9f7 330 case CRC_INPUTDATA_FORMAT_WORDS:
<> 144:ef7eb2e8f9f7 331 /* Enter Data to the CRC calculator */
<> 151:5eaa88a5bcc7 332 for(index = 0U; index < BufferLength; index++)
<> 144:ef7eb2e8f9f7 333 {
<> 144:ef7eb2e8f9f7 334 hcrc->Instance->DR = pBuffer[index];
<> 144:ef7eb2e8f9f7 335 }
<> 144:ef7eb2e8f9f7 336 temp = hcrc->Instance->DR;
<> 144:ef7eb2e8f9f7 337 break;
<> 144:ef7eb2e8f9f7 338
<> 144:ef7eb2e8f9f7 339 case CRC_INPUTDATA_FORMAT_BYTES:
<> 144:ef7eb2e8f9f7 340 temp = CRC_Handle_8(hcrc, (uint8_t*)pBuffer, BufferLength);
<> 144:ef7eb2e8f9f7 341 break;
<> 144:ef7eb2e8f9f7 342
<> 144:ef7eb2e8f9f7 343 case CRC_INPUTDATA_FORMAT_HALFWORDS:
<> 144:ef7eb2e8f9f7 344 temp = CRC_Handle_16(hcrc, (uint16_t*)pBuffer, BufferLength);
<> 144:ef7eb2e8f9f7 345 break;
<> 144:ef7eb2e8f9f7 346 default:
<> 144:ef7eb2e8f9f7 347 break;
<> 144:ef7eb2e8f9f7 348 }
<> 144:ef7eb2e8f9f7 349
<> 144:ef7eb2e8f9f7 350 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 351 hcrc->State = HAL_CRC_STATE_READY;
<> 144:ef7eb2e8f9f7 352
<> 144:ef7eb2e8f9f7 353 /* Process unlocked */
<> 144:ef7eb2e8f9f7 354 __HAL_UNLOCK(hcrc);
<> 144:ef7eb2e8f9f7 355
<> 144:ef7eb2e8f9f7 356 /* Return the CRC computed value */
<> 144:ef7eb2e8f9f7 357 return temp;
<> 144:ef7eb2e8f9f7 358 }
<> 144:ef7eb2e8f9f7 359
<> 144:ef7eb2e8f9f7 360
<> 144:ef7eb2e8f9f7 361 /**
<> 144:ef7eb2e8f9f7 362 * @brief Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
<> 144:ef7eb2e8f9f7 363 * starting with hcrc->Instance->INIT as initialization value.
<> 144:ef7eb2e8f9f7 364 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 365 * @param pBuffer: pointer to the input data buffer, exact input data format is
<> 144:ef7eb2e8f9f7 366 * provided by hcrc->InputDataFormat.
<> 144:ef7eb2e8f9f7 367 * @param BufferLength: input data buffer length (number of bytes if pBuffer
<> 144:ef7eb2e8f9f7 368 * type is * uint8_t, number of half-words if pBuffer type is * uint16_t,
<> 144:ef7eb2e8f9f7 369 * number of words if pBuffer type is * uint32_t).
<> 144:ef7eb2e8f9f7 370 * @note By default, the API expects a uint32_t pointer as input buffer parameter.
<> 144:ef7eb2e8f9f7 371 * Input buffer pointers with other types simply need to be cast in uint32_t
<> 144:ef7eb2e8f9f7 372 * and the API will internally adjust its input data processing based on the
<> 144:ef7eb2e8f9f7 373 * handle field hcrc->InputDataFormat.
<> 144:ef7eb2e8f9f7 374 * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
<> 144:ef7eb2e8f9f7 375 */
<> 144:ef7eb2e8f9f7 376 uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
<> 144:ef7eb2e8f9f7 377 {
<> 151:5eaa88a5bcc7 378 uint32_t index = 0U; /* CRC input data buffer index */
<> 151:5eaa88a5bcc7 379 uint32_t temp = 0U; /* CRC output (read from hcrc->Instance->DR register) */
<> 144:ef7eb2e8f9f7 380
<> 144:ef7eb2e8f9f7 381 /* Process locked */
<> 144:ef7eb2e8f9f7 382 __HAL_LOCK(hcrc);
<> 144:ef7eb2e8f9f7 383
<> 144:ef7eb2e8f9f7 384 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 385 hcrc->State = HAL_CRC_STATE_BUSY;
<> 144:ef7eb2e8f9f7 386
<> 144:ef7eb2e8f9f7 387 /* Reset CRC Calculation Unit (hcrc->Instance->INIT is
<> 144:ef7eb2e8f9f7 388 * written in hcrc->Instance->DR) */
<> 144:ef7eb2e8f9f7 389 __HAL_CRC_DR_RESET(hcrc);
<> 144:ef7eb2e8f9f7 390
<> 144:ef7eb2e8f9f7 391 switch (hcrc->InputDataFormat)
<> 144:ef7eb2e8f9f7 392 {
<> 144:ef7eb2e8f9f7 393 case CRC_INPUTDATA_FORMAT_WORDS:
<> 144:ef7eb2e8f9f7 394 /* Enter 32-bit input data to the CRC calculator */
<> 151:5eaa88a5bcc7 395 for(index = 0U; index < BufferLength; index++)
<> 144:ef7eb2e8f9f7 396 {
<> 144:ef7eb2e8f9f7 397 hcrc->Instance->DR = pBuffer[index];
<> 144:ef7eb2e8f9f7 398 }
<> 144:ef7eb2e8f9f7 399 temp = hcrc->Instance->DR;
<> 144:ef7eb2e8f9f7 400 break;
<> 144:ef7eb2e8f9f7 401
<> 144:ef7eb2e8f9f7 402 case CRC_INPUTDATA_FORMAT_BYTES:
<> 144:ef7eb2e8f9f7 403 /* Specific 8-bit input data handling */
<> 144:ef7eb2e8f9f7 404 temp = CRC_Handle_8(hcrc, (uint8_t*)pBuffer, BufferLength);
<> 144:ef7eb2e8f9f7 405 break;
<> 144:ef7eb2e8f9f7 406
<> 144:ef7eb2e8f9f7 407 case CRC_INPUTDATA_FORMAT_HALFWORDS:
<> 144:ef7eb2e8f9f7 408 /* Specific 16-bit input data handling */
<> 144:ef7eb2e8f9f7 409 temp = CRC_Handle_16(hcrc, (uint16_t*)pBuffer, BufferLength);
<> 144:ef7eb2e8f9f7 410 break;
<> 144:ef7eb2e8f9f7 411 default:
<> 144:ef7eb2e8f9f7 412 break;
<> 144:ef7eb2e8f9f7 413 }
<> 144:ef7eb2e8f9f7 414
<> 144:ef7eb2e8f9f7 415 /* Change CRC peripheral state */
<> 144:ef7eb2e8f9f7 416 hcrc->State = HAL_CRC_STATE_READY;
<> 144:ef7eb2e8f9f7 417
<> 144:ef7eb2e8f9f7 418 /* Process unlocked */
<> 144:ef7eb2e8f9f7 419 __HAL_UNLOCK(hcrc);
<> 144:ef7eb2e8f9f7 420
<> 144:ef7eb2e8f9f7 421 /* Return the CRC computed value */
<> 144:ef7eb2e8f9f7 422 return temp;
<> 144:ef7eb2e8f9f7 423 }
<> 144:ef7eb2e8f9f7 424
Anna Bridge 186:707f6e361f3e 425 #if __GNUC__
Anna Bridge 186:707f6e361f3e 426 # define MAY_ALIAS __attribute__ ((__may_alias__))
Anna Bridge 186:707f6e361f3e 427 #else
Anna Bridge 186:707f6e361f3e 428 # define MAY_ALIAS
Anna Bridge 186:707f6e361f3e 429 #endif
<> 144:ef7eb2e8f9f7 430
Anna Bridge 186:707f6e361f3e 431 typedef __IO uint8_t MAY_ALIAS uint8_io_t;
Anna Bridge 186:707f6e361f3e 432 typedef __IO uint16_t MAY_ALIAS uint16_io_t;
<> 144:ef7eb2e8f9f7 433
<> 144:ef7eb2e8f9f7 434 /**
<> 144:ef7eb2e8f9f7 435 * @}
<> 144:ef7eb2e8f9f7 436 */
<> 144:ef7eb2e8f9f7 437
<> 144:ef7eb2e8f9f7 438 /** @addtogroup CRC_Exported_Functions_Group3
<> 144:ef7eb2e8f9f7 439 * @brief Peripheral State functions.
<> 144:ef7eb2e8f9f7 440 *
<> 144:ef7eb2e8f9f7 441 @verbatim
<> 144:ef7eb2e8f9f7 442 ===============================================================================
<> 144:ef7eb2e8f9f7 443 ##### Peripheral State functions #####
<> 144:ef7eb2e8f9f7 444 ===============================================================================
<> 144:ef7eb2e8f9f7 445 [..]
<> 144:ef7eb2e8f9f7 446 This subsection permits to get in run-time the status of the peripheral.
<> 144:ef7eb2e8f9f7 447
<> 144:ef7eb2e8f9f7 448 @endverbatim
<> 144:ef7eb2e8f9f7 449 * @{
<> 144:ef7eb2e8f9f7 450 */
<> 144:ef7eb2e8f9f7 451
<> 144:ef7eb2e8f9f7 452 /**
<> 144:ef7eb2e8f9f7 453 * @brief Returns the CRC state.
<> 144:ef7eb2e8f9f7 454 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 455 * @retval HAL state
<> 144:ef7eb2e8f9f7 456 */
<> 144:ef7eb2e8f9f7 457 HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)
<> 144:ef7eb2e8f9f7 458 {
<> 144:ef7eb2e8f9f7 459 return hcrc->State;
<> 144:ef7eb2e8f9f7 460 }
<> 144:ef7eb2e8f9f7 461
<> 144:ef7eb2e8f9f7 462 /**
<> 144:ef7eb2e8f9f7 463 * @}
<> 144:ef7eb2e8f9f7 464 */
<> 144:ef7eb2e8f9f7 465
<> 144:ef7eb2e8f9f7 466 /**
<> 144:ef7eb2e8f9f7 467 * @}
<> 144:ef7eb2e8f9f7 468 */
<> 144:ef7eb2e8f9f7 469
<> 144:ef7eb2e8f9f7 470 /** @addtogroup CRC_Private
<> 144:ef7eb2e8f9f7 471 * @{
<> 144:ef7eb2e8f9f7 472 */
<> 144:ef7eb2e8f9f7 473 /**
<> 144:ef7eb2e8f9f7 474 * @brief Enter 8-bit input data to the CRC calculator.
<> 144:ef7eb2e8f9f7 475 * Specific data handling to optimize processing time.
<> 144:ef7eb2e8f9f7 476 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 477 * @param pBuffer: pointer to the input data buffer
<> 144:ef7eb2e8f9f7 478 * @param BufferLength: input data buffer length
<> 144:ef7eb2e8f9f7 479 * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
<> 144:ef7eb2e8f9f7 480 */
<> 144:ef7eb2e8f9f7 481 static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength)
<> 144:ef7eb2e8f9f7 482 {
<> 151:5eaa88a5bcc7 483 uint32_t i = 0U; /* input data buffer index */
<> 144:ef7eb2e8f9f7 484
<> 144:ef7eb2e8f9f7 485 /* Processing time optimization: 4 bytes are entered in a row with a single word write,
<> 144:ef7eb2e8f9f7 486 * last bytes must be carefully fed to the CRC calculator to ensure a correct type
<> 144:ef7eb2e8f9f7 487 * handling by the IP */
<> 151:5eaa88a5bcc7 488 for(i = 0U; i < (BufferLength/4U); i++)
<> 144:ef7eb2e8f9f7 489 {
<> 151:5eaa88a5bcc7 490 hcrc->Instance->DR = ((uint32_t)pBuffer[4U*i]<<24U) | ((uint32_t)pBuffer[4U*i+1U]<<16U) | ((uint32_t)pBuffer[4U*i+2U]<<8U) | (uint32_t)pBuffer[4U*i+3U];
<> 144:ef7eb2e8f9f7 491 }
<> 144:ef7eb2e8f9f7 492 /* last bytes specific handling */
<> 151:5eaa88a5bcc7 493 if ((BufferLength%4U) != 0U)
<> 144:ef7eb2e8f9f7 494 {
<> 151:5eaa88a5bcc7 495 if (BufferLength%4U == 1U)
<> 144:ef7eb2e8f9f7 496 {
Anna Bridge 186:707f6e361f3e 497 *(uint8_io_t*) (&hcrc->Instance->DR) = pBuffer[4U*i];
<> 144:ef7eb2e8f9f7 498 }
<> 151:5eaa88a5bcc7 499 if (BufferLength%4U == 2U)
<> 144:ef7eb2e8f9f7 500 {
Anna Bridge 186:707f6e361f3e 501 *(uint16_io_t*) (&hcrc->Instance->DR) = ((uint32_t)pBuffer[4U*i]<<8U) | (uint32_t)pBuffer[4U*i+1U];
<> 144:ef7eb2e8f9f7 502 }
<> 151:5eaa88a5bcc7 503 if (BufferLength%4U == 3U)
<> 144:ef7eb2e8f9f7 504 {
Anna Bridge 186:707f6e361f3e 505 *(uint16_io_t*) (&hcrc->Instance->DR) = ((uint32_t)pBuffer[4U*i]<<8U) | (uint32_t)pBuffer[4U*i+1U];
Anna Bridge 186:707f6e361f3e 506 *(uint8_io_t*) (&hcrc->Instance->DR) = pBuffer[4U*i+2U];
<> 144:ef7eb2e8f9f7 507 }
<> 144:ef7eb2e8f9f7 508 }
<> 144:ef7eb2e8f9f7 509
<> 144:ef7eb2e8f9f7 510 /* Return the CRC computed value */
<> 144:ef7eb2e8f9f7 511 return hcrc->Instance->DR;
<> 144:ef7eb2e8f9f7 512 }
<> 144:ef7eb2e8f9f7 513
<> 144:ef7eb2e8f9f7 514 /**
<> 144:ef7eb2e8f9f7 515 * @brief Enter 16-bit input data to the CRC calculator.
<> 144:ef7eb2e8f9f7 516 * Specific data handling to optimize processing time.
<> 144:ef7eb2e8f9f7 517 * @param hcrc: CRC handle
<> 144:ef7eb2e8f9f7 518 * @param pBuffer: pointer to the input data buffer
<> 144:ef7eb2e8f9f7 519 * @param BufferLength: input data buffer length
<> 144:ef7eb2e8f9f7 520 * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
<> 144:ef7eb2e8f9f7 521 */
<> 144:ef7eb2e8f9f7 522 static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength)
<> 144:ef7eb2e8f9f7 523 {
<> 151:5eaa88a5bcc7 524 uint32_t i = 0U; /* input data buffer index */
<> 144:ef7eb2e8f9f7 525
<> 144:ef7eb2e8f9f7 526 /* Processing time optimization: 2 HalfWords are entered in a row with a single word write,
<> 144:ef7eb2e8f9f7 527 * in case of odd length, last HalfWord must be carefully fed to the CRC calculator to ensure
<> 144:ef7eb2e8f9f7 528 * a correct type handling by the IP */
<> 151:5eaa88a5bcc7 529 for(i = 0U; i < (BufferLength/2U); i++)
<> 144:ef7eb2e8f9f7 530 {
<> 151:5eaa88a5bcc7 531 hcrc->Instance->DR = ((uint32_t)pBuffer[2U*i]<<16U) | (uint32_t)pBuffer[2U*i+1U];
<> 144:ef7eb2e8f9f7 532 }
<> 151:5eaa88a5bcc7 533 if ((BufferLength%2U) != 0U)
<> 144:ef7eb2e8f9f7 534 {
Anna Bridge 186:707f6e361f3e 535 *(uint16_io_t*) (&hcrc->Instance->DR) = pBuffer[2U*i];
<> 144:ef7eb2e8f9f7 536 }
<> 144:ef7eb2e8f9f7 537
<> 144:ef7eb2e8f9f7 538 /* Return the CRC computed value */
<> 144:ef7eb2e8f9f7 539 return hcrc->Instance->DR;
<> 144:ef7eb2e8f9f7 540 }
<> 144:ef7eb2e8f9f7 541
<> 144:ef7eb2e8f9f7 542 /**
<> 144:ef7eb2e8f9f7 543 * @}
<> 144:ef7eb2e8f9f7 544 */
<> 144:ef7eb2e8f9f7 545
<> 144:ef7eb2e8f9f7 546 /**
<> 144:ef7eb2e8f9f7 547 * @}
<> 144:ef7eb2e8f9f7 548 */
<> 144:ef7eb2e8f9f7 549
<> 144:ef7eb2e8f9f7 550 #endif /* HAL_CRC_MODULE_ENABLED */
<> 144:ef7eb2e8f9f7 551
<> 144:ef7eb2e8f9f7 552 /**
<> 144:ef7eb2e8f9f7 553 * @}
<> 144:ef7eb2e8f9f7 554 */
<> 144:ef7eb2e8f9f7 555
<> 144:ef7eb2e8f9f7 556 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
<> 144:ef7eb2e8f9f7 557