mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

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