mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Mon Nov 03 10:45:07 2014 +0000
Revision:
382:ee426a420dbb
Parent:
targets/cmsis/TARGET_STM/TARGET_DISCO_L053C8/stm32l0xx_hal_crc.c@376:cb4d9db17537
Child:
387:643a59b3dbac
Synchronized with git revision d54467eb07f62efd9ccdf44f1ede7fe1c1b0cf83

Full URL: https://github.com/mbedmicro/mbed/commit/d54467eb07f62efd9ccdf44f1ede7fe1c1b0cf83/

Who changed what in which revision?

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