mbed library sources

Fork of mbed-src by mbed official

Committer:
moirans2
Date:
Wed Jan 14 20:53:08 2015 +0000
Revision:
445:9a3ffe6cfa19
Parent:
441:d2c15dda23c1
internal clock stm32L051

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 340:28d1f895c6fe 1 /**
mbed_official 340:28d1f895c6fe 2 ******************************************************************************
mbed_official 340:28d1f895c6fe 3 * @file stm32f0xx_hal_crc_ex.c
mbed_official 340:28d1f895c6fe 4 * @author MCD Application Team
mbed_official 441:d2c15dda23c1 5 * @version V1.2.0
mbed_official 441:d2c15dda23c1 6 * @date 11-December-2014
mbed_official 340:28d1f895c6fe 7 * @brief Extended CRC HAL module driver.
mbed_official 340:28d1f895c6fe 8 * This file provides firmware functions to manage the following
mbed_official 340:28d1f895c6fe 9 * functionalities of the CRC peripheral:
mbed_official 340:28d1f895c6fe 10 * + Extended initialization functions
mbed_official 340:28d1f895c6fe 11 *
mbed_official 340:28d1f895c6fe 12 @verbatim
mbed_official 340:28d1f895c6fe 13 ================================================================================
mbed_official 340:28d1f895c6fe 14 ##### Product specific features #####
mbed_official 340:28d1f895c6fe 15 ================================================================================
mbed_official 340:28d1f895c6fe 16
mbed_official 340:28d1f895c6fe 17 ##### How to use this driver #####
mbed_official 340:28d1f895c6fe 18 ================================================================================
mbed_official 340:28d1f895c6fe 19 [..]
mbed_official 340:28d1f895c6fe 20 (+) Extended initialization
mbed_official 340:28d1f895c6fe 21 (+) Set or not user-defined generating
mbed_official 340:28d1f895c6fe 22 polynomial other than default one
mbed_official 340:28d1f895c6fe 23
mbed_official 340:28d1f895c6fe 24 @endverbatim
mbed_official 340:28d1f895c6fe 25 ******************************************************************************
mbed_official 340:28d1f895c6fe 26 * @attention
mbed_official 340:28d1f895c6fe 27 *
mbed_official 340:28d1f895c6fe 28 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 340:28d1f895c6fe 29 *
mbed_official 340:28d1f895c6fe 30 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 340:28d1f895c6fe 31 * are permitted provided that the following conditions are met:
mbed_official 340:28d1f895c6fe 32 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 340:28d1f895c6fe 33 * this list of conditions and the following disclaimer.
mbed_official 340:28d1f895c6fe 34 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 340:28d1f895c6fe 35 * this list of conditions and the following disclaimer in the documentation
mbed_official 340:28d1f895c6fe 36 * and/or other materials provided with the distribution.
mbed_official 340:28d1f895c6fe 37 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 340:28d1f895c6fe 38 * may be used to endorse or promote products derived from this software
mbed_official 340:28d1f895c6fe 39 * without specific prior written permission.
mbed_official 340:28d1f895c6fe 40 *
mbed_official 340:28d1f895c6fe 41 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 340:28d1f895c6fe 42 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 340:28d1f895c6fe 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 340:28d1f895c6fe 44 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 340:28d1f895c6fe 45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 340:28d1f895c6fe 46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 340:28d1f895c6fe 47 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 340:28d1f895c6fe 48 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 340:28d1f895c6fe 49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 340:28d1f895c6fe 50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 340:28d1f895c6fe 51 *
mbed_official 340:28d1f895c6fe 52 ******************************************************************************
mbed_official 340:28d1f895c6fe 53 */
mbed_official 340:28d1f895c6fe 54
mbed_official 340:28d1f895c6fe 55 /* Includes ------------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 56 #include "stm32f0xx_hal.h"
mbed_official 340:28d1f895c6fe 57
mbed_official 340:28d1f895c6fe 58 /** @addtogroup STM32F0xx_HAL_Driver
mbed_official 340:28d1f895c6fe 59 * @{
mbed_official 340:28d1f895c6fe 60 */
mbed_official 340:28d1f895c6fe 61
mbed_official 340:28d1f895c6fe 62 /** @defgroup CRCEx CRCEx Extended HAL Module Driver
mbed_official 340:28d1f895c6fe 63 * @brief CRC Extended HAL module driver
mbed_official 340:28d1f895c6fe 64 * @{
mbed_official 340:28d1f895c6fe 65 */
mbed_official 340:28d1f895c6fe 66
mbed_official 340:28d1f895c6fe 67 #ifdef HAL_CRC_MODULE_ENABLED
mbed_official 340:28d1f895c6fe 68
mbed_official 340:28d1f895c6fe 69 /* Private typedef -----------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 70 /* Private define ------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 71 /* Private macro -------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 72 /* Private variables ---------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 73 /* Private function prototypes -----------------------------------------------*/
mbed_official 340:28d1f895c6fe 74 /* Private functions ---------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 75
mbed_official 340:28d1f895c6fe 76 /** @defgroup CRCEx_Exported_Functions CRCEx Exported Functions
mbed_official 340:28d1f895c6fe 77 * @{
mbed_official 340:28d1f895c6fe 78 */
mbed_official 340:28d1f895c6fe 79
mbed_official 340:28d1f895c6fe 80 /** @defgroup CRCEx_Exported_Functions_Group1 Extended Initialization/de-initialization functions
mbed_official 340:28d1f895c6fe 81 * @brief Extended Initialization and Configuration functions.
mbed_official 340:28d1f895c6fe 82 *
mbed_official 340:28d1f895c6fe 83 @verbatim
mbed_official 340:28d1f895c6fe 84 ===============================================================================
mbed_official 340:28d1f895c6fe 85 ##### Initialization and Configuration functions #####
mbed_official 340:28d1f895c6fe 86 ===============================================================================
mbed_official 340:28d1f895c6fe 87 [..] This section provides functions allowing to:
mbed_official 340:28d1f895c6fe 88 (+) Initialize the CRC generating polynomial: if programmable polynomial
mbed_official 340:28d1f895c6fe 89 feature is applicable to device, set default or non-default generating
mbed_official 340:28d1f895c6fe 90 polynomial according to hcrc->Init.DefaultPolynomialUse parameter.
mbed_official 340:28d1f895c6fe 91 If feature is non-applicable to device in use, HAL_CRCEx_Init straight
mbed_official 340:28d1f895c6fe 92 away reports HAL_OK.
mbed_official 340:28d1f895c6fe 93 (+) Set the generating polynomial
mbed_official 340:28d1f895c6fe 94
mbed_official 340:28d1f895c6fe 95 @endverbatim
mbed_official 340:28d1f895c6fe 96 * @{
mbed_official 340:28d1f895c6fe 97 */
mbed_official 340:28d1f895c6fe 98
mbed_official 340:28d1f895c6fe 99
mbed_official 340:28d1f895c6fe 100 /**
mbed_official 340:28d1f895c6fe 101 * @brief Extended initialization to set generating polynomial
mbed_official 340:28d1f895c6fe 102 * @param hcrc: CRC handle
mbed_official 340:28d1f895c6fe 103 * @retval HAL status
mbed_official 340:28d1f895c6fe 104 */
mbed_official 340:28d1f895c6fe 105 HAL_StatusTypeDef HAL_CRCEx_Init(CRC_HandleTypeDef *hcrc)
mbed_official 340:28d1f895c6fe 106 {
mbed_official 441:d2c15dda23c1 107 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined (STM32F098xx)
mbed_official 340:28d1f895c6fe 108 /* check whether or not non-default generating polynomial has been
mbed_official 340:28d1f895c6fe 109 * picked up by user */
mbed_official 340:28d1f895c6fe 110 assert_param(IS_DEFAULT_POLYNOMIAL(hcrc->Init.DefaultPolynomialUse));
mbed_official 340:28d1f895c6fe 111 if (hcrc->Init.DefaultPolynomialUse == DEFAULT_POLYNOMIAL_ENABLE)
mbed_official 340:28d1f895c6fe 112 {
mbed_official 340:28d1f895c6fe 113 /* initialize IP with default generating polynomial */
mbed_official 340:28d1f895c6fe 114 WRITE_REG(hcrc->Instance->POL, DEFAULT_CRC32_POLY);
mbed_official 340:28d1f895c6fe 115 MODIFY_REG(hcrc->Instance->CR, CRC_CR_POLYSIZE, CRC_POLYLENGTH_32B);
mbed_official 340:28d1f895c6fe 116 }
mbed_official 340:28d1f895c6fe 117 else
mbed_official 340:28d1f895c6fe 118 {
mbed_official 340:28d1f895c6fe 119 /* initialize CRC IP with generating polynomial defined by user */
mbed_official 340:28d1f895c6fe 120 if (HAL_CRCEx_Polynomial_Set(hcrc, hcrc->Init.GeneratingPolynomial, hcrc->Init.CRCLength) != HAL_OK)
mbed_official 340:28d1f895c6fe 121 {
mbed_official 340:28d1f895c6fe 122 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 123 }
mbed_official 340:28d1f895c6fe 124 }
mbed_official 340:28d1f895c6fe 125 #endif /* defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined (STM32F098xx) */
mbed_official 340:28d1f895c6fe 126
mbed_official 340:28d1f895c6fe 127 return HAL_OK;
mbed_official 340:28d1f895c6fe 128 }
mbed_official 340:28d1f895c6fe 129
mbed_official 340:28d1f895c6fe 130 /**
mbed_official 340:28d1f895c6fe 131 * @brief Set the Reverse Input data mode.
mbed_official 340:28d1f895c6fe 132 * @param hcrc: CRC handle
mbed_official 340:28d1f895c6fe 133 * @param InputReverseMode: Input Data inversion mode
mbed_official 340:28d1f895c6fe 134 * This parameter can be one of the following values:
mbed_official 340:28d1f895c6fe 135 * @arg CRC_INPUTDATA_NOINVERSION: no change in bit order (default value)
mbed_official 340:28d1f895c6fe 136 * @arg CRC_INPUTDATA_INVERSION_BYTE: Byte-wise bit reversal
mbed_official 340:28d1f895c6fe 137 * @arg CRC_INPUTDATA_INVERSION_HALFWORD: HalfWord-wise bit reversal
mbed_official 340:28d1f895c6fe 138 * @arg CRC_INPUTDATA_INVERSION_WORD: Word-wise bit reversal
mbed_official 340:28d1f895c6fe 139 * @retval HAL status
mbed_official 340:28d1f895c6fe 140 */
mbed_official 340:28d1f895c6fe 141 HAL_StatusTypeDef HAL_CRCEx_Input_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t InputReverseMode)
mbed_official 340:28d1f895c6fe 142 {
mbed_official 340:28d1f895c6fe 143 /* Check the parameters */
mbed_official 340:28d1f895c6fe 144 assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(InputReverseMode));
mbed_official 340:28d1f895c6fe 145
mbed_official 340:28d1f895c6fe 146 /* Change CRC peripheral state */
mbed_official 340:28d1f895c6fe 147 hcrc->State = HAL_CRC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 148
mbed_official 340:28d1f895c6fe 149 /* set input data inversion mode */
mbed_official 340:28d1f895c6fe 150 MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_IN, InputReverseMode);
mbed_official 340:28d1f895c6fe 151 /* Change CRC peripheral state */
mbed_official 340:28d1f895c6fe 152 hcrc->State = HAL_CRC_STATE_READY;
mbed_official 340:28d1f895c6fe 153
mbed_official 340:28d1f895c6fe 154 /* Return function status */
mbed_official 340:28d1f895c6fe 155 return HAL_OK;
mbed_official 340:28d1f895c6fe 156 }
mbed_official 340:28d1f895c6fe 157
mbed_official 340:28d1f895c6fe 158 /**
mbed_official 340:28d1f895c6fe 159 * @brief Set the Reverse Output data mode.
mbed_official 340:28d1f895c6fe 160 * @param hcrc: CRC handle
mbed_official 340:28d1f895c6fe 161 * @param OutputReverseMode: Output Data inversion mode
mbed_official 340:28d1f895c6fe 162 * This parameter can be one of the following values:
mbed_official 340:28d1f895c6fe 163 * @arg CRC_OUTPUTDATA_INVERSION_DISABLED: no CRC inversion (default value)
mbed_official 340:28d1f895c6fe 164 * @arg CRC_OUTPUTDATA_INVERSION_ENABLED: bit-level inversion (e.g for a 8-bit CRC: 0xB5 becomes 0xAD)
mbed_official 340:28d1f895c6fe 165 * @retval HAL status
mbed_official 340:28d1f895c6fe 166 */
mbed_official 340:28d1f895c6fe 167 HAL_StatusTypeDef HAL_CRCEx_Output_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t OutputReverseMode)
mbed_official 340:28d1f895c6fe 168 {
mbed_official 340:28d1f895c6fe 169 /* Check the parameters */
mbed_official 340:28d1f895c6fe 170 assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(OutputReverseMode));
mbed_official 340:28d1f895c6fe 171
mbed_official 340:28d1f895c6fe 172 /* Change CRC peripheral state */
mbed_official 340:28d1f895c6fe 173 hcrc->State = HAL_CRC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 174
mbed_official 340:28d1f895c6fe 175 /* set output data inversion mode */
mbed_official 340:28d1f895c6fe 176 MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_OUT, OutputReverseMode);
mbed_official 340:28d1f895c6fe 177
mbed_official 340:28d1f895c6fe 178 /* Change CRC peripheral state */
mbed_official 340:28d1f895c6fe 179 hcrc->State = HAL_CRC_STATE_READY;
mbed_official 340:28d1f895c6fe 180
mbed_official 340:28d1f895c6fe 181 /* Return function status */
mbed_official 340:28d1f895c6fe 182 return HAL_OK;
mbed_official 340:28d1f895c6fe 183 }
mbed_official 340:28d1f895c6fe 184
mbed_official 340:28d1f895c6fe 185 #if defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F091xC) || defined (STM32F098xx)
mbed_official 340:28d1f895c6fe 186 /**
mbed_official 340:28d1f895c6fe 187 * @brief Initializes the CRC polynomial if different from default one.
mbed_official 340:28d1f895c6fe 188 * @param hcrc: CRC handle
mbed_official 340:28d1f895c6fe 189 * @param Pol: CRC generating polynomial (7, 8, 16 or 32-bit long)
mbed_official 340:28d1f895c6fe 190 * This parameter is written in normal representation, e.g.
mbed_official 340:28d1f895c6fe 191 * for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
mbed_official 340:28d1f895c6fe 192 * for a polynomial of degree 16, X^16 + X^12 + X^5 + 1 is written 0x1021
mbed_official 340:28d1f895c6fe 193 * @param PolyLength: CRC polynomial length
mbed_official 340:28d1f895c6fe 194 * This parameter can be one of the following values:
mbed_official 340:28d1f895c6fe 195 * @arg CRC_POLYLENGTH_7B: 7-bit long CRC (generating polynomial of degree 7)
mbed_official 340:28d1f895c6fe 196 * @arg CRC_POLYLENGTH_8B: 8-bit long CRC (generating polynomial of degree 8)
mbed_official 340:28d1f895c6fe 197 * @arg CRC_POLYLENGTH_16B: 16-bit long CRC (generating polynomial of degree 16)
mbed_official 340:28d1f895c6fe 198 * @arg CRC_POLYLENGTH_32B: 32-bit long CRC (generating polynomial of degree 32)
mbed_official 340:28d1f895c6fe 199 * @retval HAL status
mbed_official 340:28d1f895c6fe 200 */
mbed_official 340:28d1f895c6fe 201 HAL_StatusTypeDef HAL_CRCEx_Polynomial_Set(CRC_HandleTypeDef *hcrc, uint32_t Pol, uint32_t PolyLength)
mbed_official 340:28d1f895c6fe 202 {
mbed_official 340:28d1f895c6fe 203 uint32_t msb = 31; /* polynomial degree is 32 at most, so msb is initialized to max value */
mbed_official 340:28d1f895c6fe 204
mbed_official 340:28d1f895c6fe 205 /* Check the parameters */
mbed_official 340:28d1f895c6fe 206 assert_param(IS_CRC_POL_LENGTH(PolyLength));
mbed_official 340:28d1f895c6fe 207
mbed_official 340:28d1f895c6fe 208 /* check polynomial definition vs polynomial size:
mbed_official 340:28d1f895c6fe 209 * polynomial length must be aligned with polynomial
mbed_official 340:28d1f895c6fe 210 * definition. HAL_ERROR is reported if Pol degree is
mbed_official 340:28d1f895c6fe 211 * larger than that indicated by PolyLength.
mbed_official 340:28d1f895c6fe 212 * Look for MSB position: msb will contain the degree of
mbed_official 340:28d1f895c6fe 213 * the second to the largest polynomial member. E.g., for
mbed_official 340:28d1f895c6fe 214 * X^7 + X^6 + X^5 + X^2 + 1, msb = 6. */
mbed_official 340:28d1f895c6fe 215 while (((Pol & (1U << msb)) == 0) && (msb-- > 0))
mbed_official 340:28d1f895c6fe 216 {}
mbed_official 340:28d1f895c6fe 217
mbed_official 340:28d1f895c6fe 218 switch (PolyLength)
mbed_official 340:28d1f895c6fe 219 {
mbed_official 340:28d1f895c6fe 220 case CRC_POLYLENGTH_7B:
mbed_official 340:28d1f895c6fe 221 if (msb >= HAL_CRC_LENGTH_7B)
mbed_official 340:28d1f895c6fe 222 {
mbed_official 340:28d1f895c6fe 223 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 224 }
mbed_official 340:28d1f895c6fe 225 break;
mbed_official 340:28d1f895c6fe 226 case CRC_POLYLENGTH_8B:
mbed_official 340:28d1f895c6fe 227 if (msb >= HAL_CRC_LENGTH_8B)
mbed_official 340:28d1f895c6fe 228 {
mbed_official 340:28d1f895c6fe 229 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 230 }
mbed_official 340:28d1f895c6fe 231 break;
mbed_official 340:28d1f895c6fe 232 case CRC_POLYLENGTH_16B:
mbed_official 340:28d1f895c6fe 233 if (msb >= HAL_CRC_LENGTH_16B)
mbed_official 340:28d1f895c6fe 234 {
mbed_official 340:28d1f895c6fe 235 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 236 }
mbed_official 340:28d1f895c6fe 237 break;
mbed_official 340:28d1f895c6fe 238 case CRC_POLYLENGTH_32B:
mbed_official 340:28d1f895c6fe 239 /* no polynomial definition vs. polynomial length issue possible */
mbed_official 340:28d1f895c6fe 240 break;
mbed_official 340:28d1f895c6fe 241 default:
mbed_official 340:28d1f895c6fe 242 break;
mbed_official 340:28d1f895c6fe 243 }
mbed_official 340:28d1f895c6fe 244
mbed_official 340:28d1f895c6fe 245 /* set generating polynomial */
mbed_official 340:28d1f895c6fe 246 WRITE_REG(hcrc->Instance->POL, Pol);
mbed_official 340:28d1f895c6fe 247
mbed_official 340:28d1f895c6fe 248 /* set generating polynomial size */
mbed_official 340:28d1f895c6fe 249 MODIFY_REG(hcrc->Instance->CR, CRC_CR_POLYSIZE, PolyLength);
mbed_official 340:28d1f895c6fe 250
mbed_official 340:28d1f895c6fe 251 /* Return function status */
mbed_official 340:28d1f895c6fe 252 return HAL_OK;
mbed_official 340:28d1f895c6fe 253 }
mbed_official 340:28d1f895c6fe 254 #endif /* #if defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F091xC) || defined (STM32F098xx) */
mbed_official 340:28d1f895c6fe 255
mbed_official 340:28d1f895c6fe 256 /**
mbed_official 340:28d1f895c6fe 257 * @}
mbed_official 340:28d1f895c6fe 258 */
mbed_official 340:28d1f895c6fe 259
mbed_official 340:28d1f895c6fe 260
mbed_official 340:28d1f895c6fe 261 /**
mbed_official 340:28d1f895c6fe 262 * @}
mbed_official 340:28d1f895c6fe 263 */
mbed_official 340:28d1f895c6fe 264
mbed_official 340:28d1f895c6fe 265
mbed_official 340:28d1f895c6fe 266 #endif /* HAL_CRC_MODULE_ENABLED */
mbed_official 340:28d1f895c6fe 267 /**
mbed_official 340:28d1f895c6fe 268 * @}
mbed_official 340:28d1f895c6fe 269 */
mbed_official 340:28d1f895c6fe 270
mbed_official 340:28d1f895c6fe 271 /**
mbed_official 340:28d1f895c6fe 272 * @}
mbed_official 340:28d1f895c6fe 273 */
mbed_official 340:28d1f895c6fe 274
mbed_official 340:28d1f895c6fe 275 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/