mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri May 30 15:30:09 2014 +0100
Revision:
218:44081b78fdc2
Parent:
205:c41fc65bcfb4
Synchronized with git revision d854859072d318241476ccc5f335965444d4c1d8

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

[NUCLEO_F072RB] Update CubeF0 HAL driver

Who changed what in which revision?

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