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:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Parent:
441:d2c15dda23c1
Child:
630:825f75ca301e
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

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

Initial version of drivers for SAMR21

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