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