Senior Design: Sound Monitor / STM32L4xx_HAL_Driver
Committer:
EricLew
Date:
Mon Nov 02 19:37:23 2015 +0000
Revision:
0:80ee8f3b695e
Errors are with definitions of LCD and QSPI functions. I believe all .h and .c files are  uploaded, but there may need to be certain functions called.

Who changed what in which revision?

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