mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
186:707f6e361f3e
mbed library release version 165

Who changed what in which revision?

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