d368d9a95d3e179549adf8d54c65b7940a2b1bbf
2 ******************************************************************************
3 * @file stm32f7xx_hal_crc_ex.c
4 * @author MCD Application Team
7 * @brief Extended CRC HAL module driver.
9 * This file provides firmware functions to manage the following
10 * functionalities of the CRC peripheral:
11 * + Initialization/de-initialization functions
14 ==============================================================================
15 ##### CRC specific features #####
16 ==============================================================================
18 (#) Polynomial configuration.
19 (#) Input data reverse mode.
20 (#) Output data reverse mode.
23 ******************************************************************************
26 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
28 * Redistribution and use in source and binary forms, with or without modification,
29 * are permitted provided that the following conditions are met:
30 * 1. Redistributions of source code must retain the above copyright notice,
31 * this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright notice,
33 * this list of conditions and the following disclaimer in the documentation
34 * and/or other materials provided with the distribution.
35 * 3. Neither the name of STMicroelectronics nor the names of its contributors
36 * may be used to endorse or promote products derived from this software
37 * without specific prior written permission.
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
45 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
46 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 ******************************************************************************
53 /* Includes ------------------------------------------------------------------*/
54 #include "stm32f7xx_hal.h"
56 /** @addtogroup STM32F7xx_HAL_Driver
61 * @brief CRC Extended HAL module driver
65 #ifdef HAL_CRC_MODULE_ENABLED
67 /* Private typedef -----------------------------------------------------------*/
68 /* Private define ------------------------------------------------------------*/
69 /* Private macro -------------------------------------------------------------*/
70 /* Private variables ---------------------------------------------------------*/
71 /* Private function prototypes -----------------------------------------------*/
72 /* Private functions ---------------------------------------------------------*/
74 /** @addtogroup CRCEx_Exported_Functions
78 /** @addtogroup CRCEx_Exported_Functions_Group1
79 * @brief Extended CRC features functions
82 ===============================================================================
83 ##### CRC Extended features functions #####
84 ===============================================================================
86 This subsection provides function allowing to:
87 (+) Set CRC polynomial if different from default one.
95 * @brief Initializes the CRC polynomial if different from default one.
96 * @param hcrc: CRC handle
97 * @param Pol: CRC generating polynomial (7, 8, 16 or 32-bit long)
98 * This parameter is written in normal representation, e.g.
99 * for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
100 * for a polynomial of degree 16, X^16 + X^12 + X^5 + 1 is written 0x1021
101 * @param PolyLength: CRC polynomial length
102 * This parameter can be one of the following values:
103 * @arg CRC_POLYLENGTH_7B: 7-bit long CRC (generating polynomial of degree 7)
104 * @arg CRC_POLYLENGTH_8B: 8-bit long CRC (generating polynomial of degree 8)
105 * @arg CRC_POLYLENGTH_16B: 16-bit long CRC (generating polynomial of degree 16)
106 * @arg CRC_POLYLENGTH_32B: 32-bit long CRC (generating polynomial of degree 32)
109 HAL_StatusTypeDef
HAL_CRCEx_Polynomial_Set(CRC_HandleTypeDef
*hcrc
, uint32_t Pol
, uint32_t PolyLength
)
111 uint32_t msb
= 31; /* polynomial degree is 32 at most, so msb is initialized to max value */
113 /* Check the parameters */
114 assert_param(IS_CRC_POL_LENGTH(PolyLength
));
116 /* check polynomial definition vs polynomial size:
117 * polynomial length must be aligned with polynomial
118 * definition. HAL_ERROR is reported if Pol degree is
119 * larger than that indicated by PolyLength.
120 * Look for MSB position: msb will contain the degree of
121 * the second to the largest polynomial member. E.g., for
122 * X^7 + X^6 + X^5 + X^2 + 1, msb = 6. */
123 while (((Pol
& ((uint32_t)(0x1) << msb
)) == 0) && (msb
-- > 0))
129 case CRC_POLYLENGTH_7B
:
130 if (msb
>= HAL_CRC_LENGTH_7B
)
135 case CRC_POLYLENGTH_8B
:
136 if (msb
>= HAL_CRC_LENGTH_8B
)
141 case CRC_POLYLENGTH_16B
:
142 if (msb
>= HAL_CRC_LENGTH_16B
)
147 case CRC_POLYLENGTH_32B
:
148 /* no polynomial definition vs. polynomial length issue possible */
154 /* set generating polynomial */
155 WRITE_REG(hcrc
->Instance
->POL
, Pol
);
157 /* set generating polynomial size */
158 MODIFY_REG(hcrc
->Instance
->CR
, CRC_CR_POLYSIZE
, PolyLength
);
160 /* Return function status */
165 * @brief Set the Reverse Input data mode.
166 * @param hcrc: CRC handle
167 * @param InputReverseMode: Input Data inversion mode
168 * This parameter can be one of the following values:
169 * @arg CRC_INPUTDATA_INVERSION_NONE: no change in bit order (default value)
170 * @arg CRC_INPUTDATA_INVERSION_BYTE: Byte-wise bit reversal
171 * @arg CRC_INPUTDATA_INVERSION_HALFWORD: HalfWord-wise bit reversal
172 * @arg CRC_INPUTDATA_INVERSION_WORD: Word-wise bit reversal
175 HAL_StatusTypeDef
HAL_CRCEx_Input_Data_Reverse(CRC_HandleTypeDef
*hcrc
, uint32_t InputReverseMode
)
177 /* Check the parameters */
178 assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(InputReverseMode
));
180 /* Change CRC peripheral state */
181 hcrc
->State
= HAL_CRC_STATE_BUSY
;
183 /* set input data inversion mode */
184 MODIFY_REG(hcrc
->Instance
->CR
, CRC_CR_REV_IN
, InputReverseMode
);
185 /* Change CRC peripheral state */
186 hcrc
->State
= HAL_CRC_STATE_READY
;
188 /* Return function status */
193 * @brief Set the Reverse Output data mode.
194 * @param hcrc: CRC handle
195 * @param OutputReverseMode: Output Data inversion mode
196 * This parameter can be one of the following values:
197 * @arg CRC_OUTPUTDATA_INVERSION_DISABLE: no CRC inversion (default value)
198 * @arg CRC_OUTPUTDATA_INVERSION_ENABLE: bit-level inversion (e.g for a 8-bit CRC: 0xB5 becomes 0xAD)
201 HAL_StatusTypeDef
HAL_CRCEx_Output_Data_Reverse(CRC_HandleTypeDef
*hcrc
, uint32_t OutputReverseMode
)
203 /* Check the parameters */
204 assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(OutputReverseMode
));
206 /* Change CRC peripheral state */
207 hcrc
->State
= HAL_CRC_STATE_BUSY
;
209 /* set output data inversion mode */
210 MODIFY_REG(hcrc
->Instance
->CR
, CRC_CR_REV_OUT
, OutputReverseMode
);
212 /* Change CRC peripheral state */
213 hcrc
->State
= HAL_CRC_STATE_READY
;
215 /* Return function status */
232 #endif /* HAL_CRC_MODULE_ENABLED */
241 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/