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