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