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 10:45:10 2015 +0100
Revision:
630:825f75ca301e
Parent:
441:d2c15dda23c1
Synchronized with git revision 54fbe4144faf309c37205a5d39fa665daa919f10

Full URL: https://github.com/mbedmicro/mbed/commit/54fbe4144faf309c37205a5d39fa665daa919f10/

NUCLEO_F031K6 : Add new target

Who changed what in which revision?

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