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:
Tue Jun 24 14:45:08 2014 +0100
Revision:
237:f3da66175598
Child:
375:3d36234a1087
Synchronized with git revision 8ef659bca81f12dfc896b5a7af7c2abbd1a1b8b7

Full URL: https://github.com/mbedmicro/mbed/commit/8ef659bca81f12dfc896b5a7af7c2abbd1a1b8b7/

[NUCLEO_F334R8] Add platform files

Who changed what in which revision?

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