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 Sep 28 14:00:11 2015 +0100
Revision:
632:7687fb9c4f91
Parent:
385:be64abf45658
Child:
634:ac7d6880524d
Synchronized with git revision f7ce4ed029cc611121464252ff28d5e8beb895b0

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

NUCLEO_F303K8 - add support of the STM32F303K8

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 632:7687fb9c4f91 5 * @version V1.1.1
mbed_official 632:7687fb9c4f91 6 * @date 19-June-2015
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 632:7687fb9c4f91 37 * <h2><center>&copy; COPYRIGHT(c) 2015 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 375:3d36234a1087 71 /** @defgroup CRC CRC HAL module driver
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 static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength);
mbed_official 237:f3da66175598 84 static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength);
mbed_official 375:3d36234a1087 85
mbed_official 375:3d36234a1087 86 /* Exported functions --------------------------------------------------------*/
mbed_official 375:3d36234a1087 87 /** @defgroup CRC_Exported_Functions CRC Exported Functions
mbed_official 237:f3da66175598 88 * @{
mbed_official 237:f3da66175598 89 */
mbed_official 237:f3da66175598 90
mbed_official 375:3d36234a1087 91 /** @defgroup CRC_Exported_Functions_Group1 Initialization and de-initialization functions
mbed_official 237:f3da66175598 92 * @brief Initialization and Configuration functions.
mbed_official 237:f3da66175598 93 *
mbed_official 237:f3da66175598 94 @verbatim
mbed_official 237:f3da66175598 95 ===============================================================================
mbed_official 237:f3da66175598 96 ##### Initialization/de-initialization functions #####
mbed_official 237:f3da66175598 97 ===============================================================================
mbed_official 237:f3da66175598 98 [..] This section provides functions allowing to:
mbed_official 237:f3da66175598 99 (+) Initialize the CRC according to the specified parameters
mbed_official 237:f3da66175598 100 in the CRC_InitTypeDef and create the associated handle
mbed_official 237:f3da66175598 101 (+) DeInitialize the CRC peripheral
mbed_official 237:f3da66175598 102 (+) Initialize the CRC MSP
mbed_official 237:f3da66175598 103 (+) DeInitialize CRC MSP
mbed_official 237:f3da66175598 104
mbed_official 237:f3da66175598 105 @endverbatim
mbed_official 237:f3da66175598 106 * @{
mbed_official 237:f3da66175598 107 */
mbed_official 237:f3da66175598 108
mbed_official 237:f3da66175598 109 /**
mbed_official 237:f3da66175598 110 * @brief Initializes the CRC according to the specified
mbed_official 237:f3da66175598 111 * parameters in the CRC_InitTypeDef and creates the associated handle.
mbed_official 237:f3da66175598 112 * @param hcrc: CRC handle
mbed_official 237:f3da66175598 113 * @retval HAL status
mbed_official 237:f3da66175598 114 */
mbed_official 237:f3da66175598 115 HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
mbed_official 237:f3da66175598 116 {
mbed_official 237:f3da66175598 117 /* Check the CRC handle allocation */
mbed_official 632:7687fb9c4f91 118 if(hcrc == NULL)
mbed_official 237:f3da66175598 119 {
mbed_official 237:f3da66175598 120 return HAL_ERROR;
mbed_official 237:f3da66175598 121 }
mbed_official 237:f3da66175598 122
mbed_official 237:f3da66175598 123 /* Check the parameters */
mbed_official 237:f3da66175598 124 assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
mbed_official 237:f3da66175598 125
mbed_official 237:f3da66175598 126 if(hcrc->State == HAL_CRC_STATE_RESET)
mbed_official 237:f3da66175598 127 {
mbed_official 237:f3da66175598 128 /* Init the low level hardware */
mbed_official 237:f3da66175598 129 HAL_CRC_MspInit(hcrc);
mbed_official 237:f3da66175598 130 }
mbed_official 237:f3da66175598 131
mbed_official 237:f3da66175598 132 hcrc->State = HAL_CRC_STATE_BUSY;
mbed_official 237:f3da66175598 133
mbed_official 237:f3da66175598 134 /* check whether or not non-default generating polynomial has been
mbed_official 237:f3da66175598 135 * picked up by user */
mbed_official 237:f3da66175598 136 assert_param(IS_DEFAULT_POLYNOMIAL(hcrc->Init.DefaultPolynomialUse));
mbed_official 237:f3da66175598 137 if (hcrc->Init.DefaultPolynomialUse == DEFAULT_POLYNOMIAL_ENABLE)
mbed_official 237:f3da66175598 138 {
mbed_official 237:f3da66175598 139 /* initialize IP with default generating polynomial */
mbed_official 237:f3da66175598 140 WRITE_REG(hcrc->Instance->POL, DEFAULT_CRC32_POLY);
mbed_official 237:f3da66175598 141 MODIFY_REG(hcrc->Instance->CR, CRC_CR_POLYSIZE, CRC_POLYLENGTH_32B);
mbed_official 237:f3da66175598 142 }
mbed_official 237:f3da66175598 143 else
mbed_official 237:f3da66175598 144 {
mbed_official 237:f3da66175598 145 /* initialize CRC IP with generating polynomial defined by user */
mbed_official 237:f3da66175598 146 if (HAL_CRCEx_Polynomial_Set(hcrc, hcrc->Init.GeneratingPolynomial, hcrc->Init.CRCLength) != HAL_OK)
mbed_official 237:f3da66175598 147 {
mbed_official 237:f3da66175598 148 return HAL_ERROR;
mbed_official 237:f3da66175598 149 }
mbed_official 237:f3da66175598 150 }
mbed_official 237:f3da66175598 151
mbed_official 237:f3da66175598 152 /* check whether or not non-default CRC initial value has been
mbed_official 237:f3da66175598 153 * picked up by user */
mbed_official 237:f3da66175598 154 assert_param(IS_DEFAULT_INIT_VALUE(hcrc->Init.DefaultInitValueUse));
mbed_official 237:f3da66175598 155 if (hcrc->Init.DefaultInitValueUse == DEFAULT_INIT_VALUE_ENABLE)
mbed_official 237:f3da66175598 156 {
mbed_official 237:f3da66175598 157 WRITE_REG(hcrc->Instance->INIT, DEFAULT_CRC_INITVALUE);
mbed_official 237:f3da66175598 158 }
mbed_official 237:f3da66175598 159 else
mbed_official 237:f3da66175598 160 {
mbed_official 237:f3da66175598 161 WRITE_REG(hcrc->Instance->INIT, hcrc->Init.InitValue);
mbed_official 237:f3da66175598 162 }
mbed_official 237:f3da66175598 163
mbed_official 237:f3da66175598 164
mbed_official 237:f3da66175598 165 /* set input data inversion mode */
mbed_official 237:f3da66175598 166 assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(hcrc->Init.InputDataInversionMode));
mbed_official 237:f3da66175598 167 MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_IN, hcrc->Init.InputDataInversionMode);
mbed_official 237:f3da66175598 168
mbed_official 237:f3da66175598 169 /* set output data inversion mode */
mbed_official 237:f3da66175598 170 assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(hcrc->Init.OutputDataInversionMode));
mbed_official 237:f3da66175598 171 MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_OUT, hcrc->Init.OutputDataInversionMode);
mbed_official 237:f3da66175598 172
mbed_official 237:f3da66175598 173 /* makes sure the input data format (bytes, halfwords or words stream)
mbed_official 237:f3da66175598 174 * is properly specified by user */
mbed_official 237:f3da66175598 175 assert_param(IS_CRC_INPUTDATA_FORMAT(hcrc->InputDataFormat));
mbed_official 237:f3da66175598 176
mbed_official 237:f3da66175598 177 /* Change CRC peripheral state */
mbed_official 237:f3da66175598 178 hcrc->State = HAL_CRC_STATE_READY;
mbed_official 237:f3da66175598 179
mbed_official 237:f3da66175598 180 /* Return function status */
mbed_official 237:f3da66175598 181 return HAL_OK;
mbed_official 237:f3da66175598 182 }
mbed_official 237:f3da66175598 183
mbed_official 237:f3da66175598 184 /**
mbed_official 237:f3da66175598 185 * @brief DeInitializes the CRC peripheral.
mbed_official 237:f3da66175598 186 * @param hcrc: CRC handle
mbed_official 237:f3da66175598 187 * @retval HAL status
mbed_official 237:f3da66175598 188 */
mbed_official 237:f3da66175598 189 HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)
mbed_official 237:f3da66175598 190 {
mbed_official 237:f3da66175598 191 /* Check the CRC handle allocation */
mbed_official 632:7687fb9c4f91 192 if(hcrc == NULL)
mbed_official 237:f3da66175598 193 {
mbed_official 237:f3da66175598 194 return HAL_ERROR;
mbed_official 237:f3da66175598 195 }
mbed_official 237:f3da66175598 196
mbed_official 237:f3da66175598 197 /* Check the parameters */
mbed_official 237:f3da66175598 198 assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
mbed_official 237:f3da66175598 199
mbed_official 237:f3da66175598 200 /* Check the CRC peripheral state */
mbed_official 237:f3da66175598 201 if(hcrc->State == HAL_CRC_STATE_BUSY)
mbed_official 237:f3da66175598 202 {
mbed_official 237:f3da66175598 203 return HAL_BUSY;
mbed_official 237:f3da66175598 204 }
mbed_official 237:f3da66175598 205
mbed_official 237:f3da66175598 206 /* Change CRC peripheral state */
mbed_official 237:f3da66175598 207 hcrc->State = HAL_CRC_STATE_BUSY;
mbed_official 237:f3da66175598 208
mbed_official 237:f3da66175598 209 /* DeInit the low level hardware */
mbed_official 237:f3da66175598 210 HAL_CRC_MspDeInit(hcrc);
mbed_official 237:f3da66175598 211
mbed_official 237:f3da66175598 212 /* Change CRC peripheral state */
mbed_official 237:f3da66175598 213 hcrc->State = HAL_CRC_STATE_RESET;
mbed_official 237:f3da66175598 214
mbed_official 237:f3da66175598 215 /* Process unlocked */
mbed_official 237:f3da66175598 216 __HAL_UNLOCK(hcrc);
mbed_official 237:f3da66175598 217
mbed_official 237:f3da66175598 218 /* Return function status */
mbed_official 237:f3da66175598 219 return HAL_OK;
mbed_official 237:f3da66175598 220 }
mbed_official 237:f3da66175598 221
mbed_official 237:f3da66175598 222 /**
mbed_official 237:f3da66175598 223 * @brief Initializes the CRC MSP.
mbed_official 237:f3da66175598 224 * @param hcrc: CRC handle
mbed_official 237:f3da66175598 225 * @retval None
mbed_official 237:f3da66175598 226 */
mbed_official 237:f3da66175598 227 __weak void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
mbed_official 237:f3da66175598 228 {
mbed_official 237:f3da66175598 229 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 230 the HAL_CRC_MspInit can be implemented in the user file
mbed_official 237:f3da66175598 231 */
mbed_official 237:f3da66175598 232 }
mbed_official 237:f3da66175598 233
mbed_official 237:f3da66175598 234 /**
mbed_official 237:f3da66175598 235 * @brief DeInitializes the CRC MSP.
mbed_official 237:f3da66175598 236 * @param hcrc: CRC handle
mbed_official 237:f3da66175598 237 * @retval None
mbed_official 237:f3da66175598 238 */
mbed_official 237:f3da66175598 239 __weak void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
mbed_official 237:f3da66175598 240 {
mbed_official 237:f3da66175598 241 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 242 the HAL_CRC_MspDeInit can be implemented in the user file
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
mbed_official 375:3d36234a1087 250 /** @defgroup CRC_Exported_Functions_Group2 Peripheral Control functions
mbed_official 237:f3da66175598 251 * @brief management functions.
mbed_official 237:f3da66175598 252 *
mbed_official 237:f3da66175598 253 @verbatim
mbed_official 237:f3da66175598 254 ===============================================================================
mbed_official 237:f3da66175598 255 ##### Peripheral Control functions #####
mbed_official 237:f3da66175598 256 ===============================================================================
mbed_official 237:f3da66175598 257 [..] This section provides functions allowing to:
mbed_official 237:f3da66175598 258 (+) Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
mbed_official 237:f3da66175598 259 using combination of the previous CRC value and the new one.
mbed_official 237:f3da66175598 260
mbed_official 237:f3da66175598 261 or
mbed_official 237:f3da66175598 262
mbed_official 237:f3da66175598 263 (+) Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
mbed_official 237:f3da66175598 264 independently of the previous CRC value.
mbed_official 237:f3da66175598 265
mbed_official 237:f3da66175598 266 @endverbatim
mbed_official 237:f3da66175598 267 * @{
mbed_official 237:f3da66175598 268 */
mbed_official 237:f3da66175598 269
mbed_official 237:f3da66175598 270 /**
mbed_official 237:f3da66175598 271 * @brief Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
mbed_official 237:f3da66175598 272 * starting with the previously computed CRC as initialization value.
mbed_official 237:f3da66175598 273 * @param hcrc: CRC handle
mbed_official 237:f3da66175598 274 * @param pBuffer: pointer to the input data buffer, exact input data format is
mbed_official 237:f3da66175598 275 * provided by hcrc->InputDataFormat.
mbed_official 237:f3da66175598 276 * @param BufferLength: input data buffer length
mbed_official 237:f3da66175598 277 * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
mbed_official 237:f3da66175598 278 */
mbed_official 237:f3da66175598 279 uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
mbed_official 237:f3da66175598 280 {
mbed_official 237:f3da66175598 281 uint32_t index = 0; /* CRC input data buffer index */
mbed_official 237:f3da66175598 282 uint32_t temp = 0; /* CRC output (read from hcrc->Instance->DR register) */
mbed_official 237:f3da66175598 283
mbed_official 237:f3da66175598 284 /* Process locked */
mbed_official 237:f3da66175598 285 __HAL_LOCK(hcrc);
mbed_official 237:f3da66175598 286
mbed_official 237:f3da66175598 287 /* Change CRC peripheral state */
mbed_official 237:f3da66175598 288 hcrc->State = HAL_CRC_STATE_BUSY;
mbed_official 237:f3da66175598 289
mbed_official 237:f3da66175598 290 switch (hcrc->InputDataFormat)
mbed_official 237:f3da66175598 291 {
mbed_official 237:f3da66175598 292 case CRC_INPUTDATA_FORMAT_WORDS:
mbed_official 237:f3da66175598 293 /* Enter Data to the CRC calculator */
mbed_official 237:f3da66175598 294 for(index = 0; index < BufferLength; index++)
mbed_official 237:f3da66175598 295 {
mbed_official 237:f3da66175598 296 hcrc->Instance->DR = pBuffer[index];
mbed_official 237:f3da66175598 297 }
mbed_official 237:f3da66175598 298 temp = hcrc->Instance->DR;
mbed_official 237:f3da66175598 299 break;
mbed_official 237:f3da66175598 300
mbed_official 237:f3da66175598 301 case CRC_INPUTDATA_FORMAT_BYTES:
mbed_official 237:f3da66175598 302 temp = CRC_Handle_8(hcrc, (uint8_t*)pBuffer, BufferLength);
mbed_official 237:f3da66175598 303 break;
mbed_official 237:f3da66175598 304
mbed_official 237:f3da66175598 305 case CRC_INPUTDATA_FORMAT_HALFWORDS:
mbed_official 237:f3da66175598 306 temp = CRC_Handle_16(hcrc, (uint16_t*)pBuffer, BufferLength);
mbed_official 237:f3da66175598 307 break;
mbed_official 237:f3da66175598 308 }
mbed_official 237:f3da66175598 309
mbed_official 237:f3da66175598 310 /* Change CRC peripheral state */
mbed_official 237:f3da66175598 311 hcrc->State = HAL_CRC_STATE_READY;
mbed_official 237:f3da66175598 312
mbed_official 237:f3da66175598 313 /* Process unlocked */
mbed_official 237:f3da66175598 314 __HAL_UNLOCK(hcrc);
mbed_official 237:f3da66175598 315
mbed_official 237:f3da66175598 316 /* Return the CRC computed value */
mbed_official 237:f3da66175598 317 return temp;
mbed_official 237:f3da66175598 318 }
mbed_official 237:f3da66175598 319
mbed_official 237:f3da66175598 320
mbed_official 237:f3da66175598 321 /**
mbed_official 237:f3da66175598 322 * @brief Compute the 7, 8, 16 or 32-bit CRC value of an 8, 16 or 32-bit data buffer
mbed_official 237:f3da66175598 323 * starting with hcrc->Instance->INIT as initialization value.
mbed_official 237:f3da66175598 324 * @param hcrc: CRC handle
mbed_official 237:f3da66175598 325 * @param pBuffer: pointer to the input data buffer, exact input data format is
mbed_official 237:f3da66175598 326 * provided by hcrc->InputDataFormat.
mbed_official 237:f3da66175598 327 * @param BufferLength: input data buffer length
mbed_official 237:f3da66175598 328 * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
mbed_official 237:f3da66175598 329 */
mbed_official 237:f3da66175598 330 uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
mbed_official 237:f3da66175598 331 {
mbed_official 237:f3da66175598 332 uint32_t index = 0; /* CRC input data buffer index */
mbed_official 237:f3da66175598 333 uint32_t temp = 0; /* CRC output (read from hcrc->Instance->DR register) */
mbed_official 237:f3da66175598 334
mbed_official 237:f3da66175598 335 /* Process locked */
mbed_official 237:f3da66175598 336 __HAL_LOCK(hcrc);
mbed_official 237:f3da66175598 337
mbed_official 237:f3da66175598 338 /* Change CRC peripheral state */
mbed_official 237:f3da66175598 339 hcrc->State = HAL_CRC_STATE_BUSY;
mbed_official 237:f3da66175598 340
mbed_official 237:f3da66175598 341 /* Reset CRC Calculation Unit (hcrc->Instance->INIT is
mbed_official 237:f3da66175598 342 * written in hcrc->Instance->DR) */
mbed_official 237:f3da66175598 343 __HAL_CRC_DR_RESET(hcrc);
mbed_official 237:f3da66175598 344
mbed_official 237:f3da66175598 345 switch (hcrc->InputDataFormat)
mbed_official 237:f3da66175598 346 {
mbed_official 237:f3da66175598 347 case CRC_INPUTDATA_FORMAT_WORDS:
mbed_official 237:f3da66175598 348 /* Enter 32-bit input data to the CRC calculator */
mbed_official 237:f3da66175598 349 for(index = 0; index < BufferLength; index++)
mbed_official 237:f3da66175598 350 {
mbed_official 237:f3da66175598 351 hcrc->Instance->DR = pBuffer[index];
mbed_official 237:f3da66175598 352 }
mbed_official 237:f3da66175598 353 temp = hcrc->Instance->DR;
mbed_official 237:f3da66175598 354 break;
mbed_official 237:f3da66175598 355
mbed_official 237:f3da66175598 356 case CRC_INPUTDATA_FORMAT_BYTES:
mbed_official 237:f3da66175598 357 /* Specific 8-bit input data handling */
mbed_official 237:f3da66175598 358 temp = CRC_Handle_8(hcrc, (uint8_t*)pBuffer, BufferLength);
mbed_official 237:f3da66175598 359 break;
mbed_official 237:f3da66175598 360
mbed_official 237:f3da66175598 361 case CRC_INPUTDATA_FORMAT_HALFWORDS:
mbed_official 237:f3da66175598 362 /* Specific 16-bit input data handling */
mbed_official 237:f3da66175598 363 temp = CRC_Handle_16(hcrc, (uint16_t*)pBuffer, BufferLength);
mbed_official 237:f3da66175598 364 break;
mbed_official 237:f3da66175598 365 }
mbed_official 237:f3da66175598 366
mbed_official 237:f3da66175598 367 /* Change CRC peripheral state */
mbed_official 237:f3da66175598 368 hcrc->State = HAL_CRC_STATE_READY;
mbed_official 237:f3da66175598 369
mbed_official 237:f3da66175598 370 /* Process unlocked */
mbed_official 237:f3da66175598 371 __HAL_UNLOCK(hcrc);
mbed_official 237:f3da66175598 372
mbed_official 237:f3da66175598 373 /* Return the CRC computed value */
mbed_official 237:f3da66175598 374 return temp;
mbed_official 237:f3da66175598 375 }
mbed_official 375:3d36234a1087 376
mbed_official 375:3d36234a1087 377 /**
mbed_official 375:3d36234a1087 378 * @}
mbed_official 375:3d36234a1087 379 */
mbed_official 375:3d36234a1087 380
mbed_official 375:3d36234a1087 381 /** @defgroup CRC_Exported_Functions_Group3 Peripheral State functions
mbed_official 375:3d36234a1087 382 * @brief Peripheral State functions.
mbed_official 375:3d36234a1087 383 *
mbed_official 375:3d36234a1087 384 @verbatim
mbed_official 375:3d36234a1087 385 ===============================================================================
mbed_official 375:3d36234a1087 386 ##### Peripheral State functions #####
mbed_official 375:3d36234a1087 387 ===============================================================================
mbed_official 375:3d36234a1087 388 [..]
mbed_official 375:3d36234a1087 389 This subsection permits to get in run-time the status of the peripheral
mbed_official 375:3d36234a1087 390 and the data flow.
mbed_official 375:3d36234a1087 391
mbed_official 375:3d36234a1087 392 @endverbatim
mbed_official 375:3d36234a1087 393 * @{
mbed_official 375:3d36234a1087 394 */
mbed_official 375:3d36234a1087 395
mbed_official 375:3d36234a1087 396 /**
mbed_official 375:3d36234a1087 397 * @brief Returns the CRC state.
mbed_official 375:3d36234a1087 398 * @param hcrc: CRC handle
mbed_official 375:3d36234a1087 399 * @retval HAL state
mbed_official 375:3d36234a1087 400 */
mbed_official 375:3d36234a1087 401 HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)
mbed_official 375:3d36234a1087 402 {
mbed_official 375:3d36234a1087 403 return hcrc->State;
mbed_official 375:3d36234a1087 404 }
mbed_official 375:3d36234a1087 405
mbed_official 375:3d36234a1087 406 /**
mbed_official 375:3d36234a1087 407 * @}
mbed_official 375:3d36234a1087 408 */
mbed_official 375:3d36234a1087 409
mbed_official 375:3d36234a1087 410 /**
mbed_official 375:3d36234a1087 411 * @}
mbed_official 375:3d36234a1087 412 */
mbed_official 237:f3da66175598 413
mbed_official 237:f3da66175598 414
mbed_official 375:3d36234a1087 415 /** @defgroup CRC_Private_Functions CRC Private Functions
mbed_official 375:3d36234a1087 416 * @{
mbed_official 375:3d36234a1087 417 */
mbed_official 237:f3da66175598 418 /**
mbed_official 237:f3da66175598 419 * @brief Enter 8-bit input data to the CRC calculator.
mbed_official 237:f3da66175598 420 * Specific data handling to optimize processing time.
mbed_official 237:f3da66175598 421 * @param hcrc: CRC handle
mbed_official 237:f3da66175598 422 * @param pBuffer: pointer to the input data buffer
mbed_official 237:f3da66175598 423 * @param BufferLength: input data buffer length
mbed_official 237:f3da66175598 424 * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
mbed_official 237:f3da66175598 425 */
mbed_official 237:f3da66175598 426 static uint32_t CRC_Handle_8(CRC_HandleTypeDef *hcrc, uint8_t pBuffer[], uint32_t BufferLength)
mbed_official 237:f3da66175598 427 {
mbed_official 237:f3da66175598 428 uint32_t i = 0; /* input data buffer index */
mbed_official 237:f3da66175598 429
mbed_official 237:f3da66175598 430 /* Processing time optimization: 4 bytes are entered in a row with a single word write,
mbed_official 237:f3da66175598 431 * last bytes must be carefully fed to the CRC calculator to ensure a correct type
mbed_official 237:f3da66175598 432 * handling by the IP */
mbed_official 237:f3da66175598 433 for(i = 0; i < (BufferLength/4); i++)
mbed_official 237:f3da66175598 434 {
mbed_official 237:f3da66175598 435 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 436 }
mbed_official 237:f3da66175598 437 /* last bytes specific handling */
mbed_official 237:f3da66175598 438 if ((BufferLength%4) != 0)
mbed_official 237:f3da66175598 439 {
mbed_official 237:f3da66175598 440 if (BufferLength%4 == 1)
mbed_official 237:f3da66175598 441 {
mbed_official 237:f3da66175598 442 *(uint8_t*) (&hcrc->Instance->DR) = pBuffer[4*i];
mbed_official 237:f3da66175598 443 }
mbed_official 237:f3da66175598 444 if (BufferLength%4 == 2)
mbed_official 237:f3da66175598 445 {
mbed_official 237:f3da66175598 446 *(uint16_t*) (&hcrc->Instance->DR) = (pBuffer[4*i]<<8) | pBuffer[4*i+1];
mbed_official 237:f3da66175598 447 }
mbed_official 237:f3da66175598 448 if (BufferLength%4 == 3)
mbed_official 237:f3da66175598 449 {
mbed_official 237:f3da66175598 450 *(uint16_t*) (&hcrc->Instance->DR) = (pBuffer[4*i]<<8) | pBuffer[4*i+1];
mbed_official 237:f3da66175598 451 *(uint8_t*) (&hcrc->Instance->DR) = pBuffer[4*i+2];
mbed_official 237:f3da66175598 452 }
mbed_official 237:f3da66175598 453 }
mbed_official 237:f3da66175598 454
mbed_official 237:f3da66175598 455 /* Return the CRC computed value */
mbed_official 237:f3da66175598 456 return hcrc->Instance->DR;
mbed_official 237:f3da66175598 457 }
mbed_official 237:f3da66175598 458
mbed_official 237:f3da66175598 459
mbed_official 237:f3da66175598 460
mbed_official 237:f3da66175598 461 /**
mbed_official 237:f3da66175598 462 * @brief Enter 16-bit input data to the CRC calculator.
mbed_official 237:f3da66175598 463 * Specific data handling to optimize processing time.
mbed_official 237:f3da66175598 464 * @param hcrc: CRC handle
mbed_official 237:f3da66175598 465 * @param pBuffer: pointer to the input data buffer
mbed_official 237:f3da66175598 466 * @param BufferLength: input data buffer length
mbed_official 237:f3da66175598 467 * @retval uint32_t CRC (returned value LSBs for CRC shorter than 32 bits)
mbed_official 237:f3da66175598 468 */
mbed_official 237:f3da66175598 469 static uint32_t CRC_Handle_16(CRC_HandleTypeDef *hcrc, uint16_t pBuffer[], uint32_t BufferLength)
mbed_official 237:f3da66175598 470 {
mbed_official 237:f3da66175598 471 uint32_t i = 0; /* input data buffer index */
mbed_official 237:f3da66175598 472
mbed_official 237:f3da66175598 473 /* Processing time optimization: 2 HalfWords are entered in a row with a single word write,
mbed_official 237:f3da66175598 474 * in case of odd length, last HalfWord must be carefully fed to the CRC calculator to ensure
mbed_official 237:f3da66175598 475 * a correct type handling by the IP */
mbed_official 237:f3da66175598 476 for(i = 0; i < (BufferLength/2); i++)
mbed_official 237:f3da66175598 477 {
mbed_official 237:f3da66175598 478 hcrc->Instance->DR = (pBuffer[2*i]<<16) | pBuffer[2*i+1];
mbed_official 237:f3da66175598 479 }
mbed_official 237:f3da66175598 480 if ((BufferLength%2) != 0)
mbed_official 237:f3da66175598 481 {
mbed_official 237:f3da66175598 482 *(uint16_t*) (&hcrc->Instance->DR) = pBuffer[2*i];
mbed_official 237:f3da66175598 483 }
mbed_official 237:f3da66175598 484
mbed_official 237:f3da66175598 485 /* Return the CRC computed value */
mbed_official 237:f3da66175598 486 return hcrc->Instance->DR;
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 #endif /* HAL_CRC_MODULE_ENABLED */
mbed_official 237:f3da66175598 494 /**
mbed_official 237:f3da66175598 495 * @}
mbed_official 237:f3da66175598 496 */
mbed_official 237:f3da66175598 497
mbed_official 237:f3da66175598 498 /**
mbed_official 237:f3da66175598 499 * @}
mbed_official 237:f3da66175598 500 */
mbed_official 237:f3da66175598 501
mbed_official 237:f3da66175598 502 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/