1 | /**
|
---|
2 | ******************************************************************************
|
---|
3 | * @file stm32f4xx_hal_crc.c
|
---|
4 | * @author MCD Application Team
|
---|
5 | * @version V1.4.1
|
---|
6 | * @date 09-October-2015
|
---|
7 | * @brief CRC HAL module driver.
|
---|
8 | * This file provides firmware functions to manage the following
|
---|
9 | * functionalities of the Cyclic Redundancy Check (CRC) peripheral:
|
---|
10 | * + Initialization and de-initialization functions
|
---|
11 | * + Peripheral Control functions
|
---|
12 | * + Peripheral State functions
|
---|
13 | *
|
---|
14 | @verbatim
|
---|
15 | ==============================================================================
|
---|
16 | ##### How to use this driver #####
|
---|
17 | ==============================================================================
|
---|
18 | [..]
|
---|
19 | The CRC HAL driver can be used as follows:
|
---|
20 |
|
---|
21 | (#) Enable CRC AHB clock using __HAL_RCC_CRC_CLK_ENABLE();
|
---|
22 |
|
---|
23 | (#) Use HAL_CRC_Accumulate() function to compute the CRC value of
|
---|
24 | a 32-bit data buffer using combination of the previous CRC value
|
---|
25 | and the new one.
|
---|
26 |
|
---|
27 | (#) Use HAL_CRC_Calculate() function to compute the CRC Value of
|
---|
28 | a new 32-bit data buffer. This function resets the CRC computation
|
---|
29 | unit before starting the computation to avoid getting wrong CRC values.
|
---|
30 |
|
---|
31 | @endverbatim
|
---|
32 | ******************************************************************************
|
---|
33 | * @attention
|
---|
34 | *
|
---|
35 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
---|
36 | *
|
---|
37 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
38 | * are permitted provided that the following conditions are met:
|
---|
39 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
40 | * this list of conditions and the following disclaimer.
|
---|
41 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
42 | * this list of conditions and the following disclaimer in the documentation
|
---|
43 | * and/or other materials provided with the distribution.
|
---|
44 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
---|
45 | * may be used to endorse or promote products derived from this software
|
---|
46 | * without specific prior written permission.
|
---|
47 | *
|
---|
48 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
---|
49 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
51 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
---|
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
---|
54 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
---|
55 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
56 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
57 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
58 | *
|
---|
59 | ******************************************************************************
|
---|
60 | */
|
---|
61 |
|
---|
62 | /* Includes ------------------------------------------------------------------*/
|
---|
63 | #include "stm32f4xx_hal.h"
|
---|
64 |
|
---|
65 | /** @addtogroup STM32F4xx_HAL_Driver
|
---|
66 | * @{
|
---|
67 | */
|
---|
68 |
|
---|
69 | /** @addtogroup CRC
|
---|
70 | * @{
|
---|
71 | */
|
---|
72 |
|
---|
73 | #ifdef HAL_CRC_MODULE_ENABLED
|
---|
74 |
|
---|
75 | /* Private typedef -----------------------------------------------------------*/
|
---|
76 | /* Private define ------------------------------------------------------------*/
|
---|
77 | /* Private macro -------------------------------------------------------------*/
|
---|
78 | /* Private variables ---------------------------------------------------------*/
|
---|
79 | /* Private function prototypes -----------------------------------------------*/
|
---|
80 | /* Private functions ---------------------------------------------------------*/
|
---|
81 | /* Exported functions --------------------------------------------------------*/
|
---|
82 |
|
---|
83 | /** @addtogroup CRC_Exported_Functions
|
---|
84 | * @{
|
---|
85 | */
|
---|
86 |
|
---|
87 | /** @addtogroup CRC_Exported_Functions_Group1
|
---|
88 | * @brief Initialization and de-initialization functions
|
---|
89 | *
|
---|
90 | @verbatim
|
---|
91 | ==============================================================================
|
---|
92 | ##### Initialization and de-initialization functions #####
|
---|
93 | ==============================================================================
|
---|
94 | [..] This section provides functions allowing to:
|
---|
95 | (+) Initialize the CRC according to the specified parameters
|
---|
96 | in the CRC_InitTypeDef and create the associated handle
|
---|
97 | (+) DeInitialize the CRC peripheral
|
---|
98 | (+) Initialize the CRC MSP
|
---|
99 | (+) DeInitialize CRC MSP
|
---|
100 |
|
---|
101 | @endverbatim
|
---|
102 | * @{
|
---|
103 | */
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * @brief Initializes the CRC according to the specified
|
---|
107 | * parameters in the CRC_InitTypeDef and creates the associated handle.
|
---|
108 | * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
|
---|
109 | * the configuration information for CRC
|
---|
110 | * @retval HAL status
|
---|
111 | */
|
---|
112 | HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
|
---|
113 | {
|
---|
114 | /* Check the CRC handle allocation */
|
---|
115 | if(hcrc == NULL)
|
---|
116 | {
|
---|
117 | return HAL_ERROR;
|
---|
118 | }
|
---|
119 |
|
---|
120 | /* Check the parameters */
|
---|
121 | assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
|
---|
122 |
|
---|
123 | if(hcrc->State == HAL_CRC_STATE_RESET)
|
---|
124 | {
|
---|
125 | /* Allocate lock resource and initialize it */
|
---|
126 | hcrc->Lock = HAL_UNLOCKED;
|
---|
127 | /* Init the low level hardware */
|
---|
128 | HAL_CRC_MspInit(hcrc);
|
---|
129 | }
|
---|
130 |
|
---|
131 | /* Change CRC peripheral state */
|
---|
132 | hcrc->State = HAL_CRC_STATE_BUSY;
|
---|
133 |
|
---|
134 | /* Change CRC peripheral state */
|
---|
135 | hcrc->State = HAL_CRC_STATE_READY;
|
---|
136 |
|
---|
137 | /* Return function status */
|
---|
138 | return HAL_OK;
|
---|
139 | }
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * @brief DeInitializes the CRC peripheral.
|
---|
143 | * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
|
---|
144 | * the configuration information for CRC
|
---|
145 | * @retval HAL status
|
---|
146 | */
|
---|
147 | HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)
|
---|
148 | {
|
---|
149 | /* Check the CRC handle allocation */
|
---|
150 | if(hcrc == NULL)
|
---|
151 | {
|
---|
152 | return HAL_ERROR;
|
---|
153 | }
|
---|
154 |
|
---|
155 | /* Check the parameters */
|
---|
156 | assert_param(IS_CRC_ALL_INSTANCE(hcrc->Instance));
|
---|
157 |
|
---|
158 | /* Change CRC peripheral state */
|
---|
159 | hcrc->State = HAL_CRC_STATE_BUSY;
|
---|
160 |
|
---|
161 | /* DeInit the low level hardware */
|
---|
162 | HAL_CRC_MspDeInit(hcrc);
|
---|
163 |
|
---|
164 | /* Change CRC peripheral state */
|
---|
165 | hcrc->State = HAL_CRC_STATE_RESET;
|
---|
166 |
|
---|
167 | /* Release Lock */
|
---|
168 | __HAL_UNLOCK(hcrc);
|
---|
169 |
|
---|
170 | /* Return function status */
|
---|
171 | return HAL_OK;
|
---|
172 | }
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * @brief Initializes the CRC MSP.
|
---|
176 | * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
|
---|
177 | * the configuration information for CRC
|
---|
178 | * @retval None
|
---|
179 | */
|
---|
180 | __weak void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
|
---|
181 | {
|
---|
182 | /* NOTE : This function Should not be modified, when the callback is needed,
|
---|
183 | the HAL_CRC_MspInit could be implemented in the user file
|
---|
184 | */
|
---|
185 | }
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * @brief DeInitializes the CRC MSP.
|
---|
189 | * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
|
---|
190 | * the configuration information for CRC
|
---|
191 | * @retval None
|
---|
192 | */
|
---|
193 | __weak void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
|
---|
194 | {
|
---|
195 | /* NOTE : This function Should not be modified, when the callback is needed,
|
---|
196 | the HAL_CRC_MspDeInit could be implemented in the user file
|
---|
197 | */
|
---|
198 | }
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * @}
|
---|
202 | */
|
---|
203 |
|
---|
204 | /** @addtogroup CRC_Exported_Functions_Group2
|
---|
205 | * @brief Peripheral Control functions
|
---|
206 | *
|
---|
207 | @verbatim
|
---|
208 | ==============================================================================
|
---|
209 | ##### Peripheral Control functions #####
|
---|
210 | ==============================================================================
|
---|
211 | [..] This section provides functions allowing to:
|
---|
212 | (+) Compute the 32-bit CRC value of 32-bit data buffer,
|
---|
213 | using combination of the previous CRC value and the new one.
|
---|
214 | (+) Compute the 32-bit CRC value of 32-bit data buffer,
|
---|
215 | independently of the previous CRC value.
|
---|
216 |
|
---|
217 | @endverbatim
|
---|
218 | * @{
|
---|
219 | */
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * @brief Computes the 32-bit CRC of 32-bit data buffer using combination
|
---|
223 | * of the previous CRC value and the new one.
|
---|
224 | * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
|
---|
225 | * the configuration information for CRC
|
---|
226 | * @param pBuffer: pointer to the buffer containing the data to be computed
|
---|
227 | * @param BufferLength: length of the buffer to be computed
|
---|
228 | * @retval 32-bit CRC
|
---|
229 | */
|
---|
230 | uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
|
---|
231 | {
|
---|
232 | uint32_t index = 0;
|
---|
233 |
|
---|
234 | /* Process Locked */
|
---|
235 | __HAL_LOCK(hcrc);
|
---|
236 |
|
---|
237 | /* Change CRC peripheral state */
|
---|
238 | hcrc->State = HAL_CRC_STATE_BUSY;
|
---|
239 |
|
---|
240 | /* Enter Data to the CRC calculator */
|
---|
241 | for(index = 0; index < BufferLength; index++)
|
---|
242 | {
|
---|
243 | hcrc->Instance->DR = pBuffer[index];
|
---|
244 | }
|
---|
245 |
|
---|
246 | /* Change CRC peripheral state */
|
---|
247 | hcrc->State = HAL_CRC_STATE_READY;
|
---|
248 |
|
---|
249 | /* Process Unlocked */
|
---|
250 | __HAL_UNLOCK(hcrc);
|
---|
251 |
|
---|
252 | /* Return the CRC computed value */
|
---|
253 | return hcrc->Instance->DR;
|
---|
254 | }
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * @brief Computes the 32-bit CRC of 32-bit data buffer independently
|
---|
258 | * of the previous CRC value.
|
---|
259 | * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
|
---|
260 | * the configuration information for CRC
|
---|
261 | * @param pBuffer: Pointer to the buffer containing the data to be computed
|
---|
262 | * @param BufferLength: Length of the buffer to be computed
|
---|
263 | * @retval 32-bit CRC
|
---|
264 | */
|
---|
265 | uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, uint32_t pBuffer[], uint32_t BufferLength)
|
---|
266 | {
|
---|
267 | uint32_t index = 0;
|
---|
268 |
|
---|
269 | /* Process Locked */
|
---|
270 | __HAL_LOCK(hcrc);
|
---|
271 |
|
---|
272 | /* Change CRC peripheral state */
|
---|
273 | hcrc->State = HAL_CRC_STATE_BUSY;
|
---|
274 |
|
---|
275 | /* Reset CRC Calculation Unit */
|
---|
276 | __HAL_CRC_DR_RESET(hcrc);
|
---|
277 |
|
---|
278 | /* Enter Data to the CRC calculator */
|
---|
279 | for(index = 0; index < BufferLength; index++)
|
---|
280 | {
|
---|
281 | hcrc->Instance->DR = pBuffer[index];
|
---|
282 | }
|
---|
283 |
|
---|
284 | /* Change CRC peripheral state */
|
---|
285 | hcrc->State = HAL_CRC_STATE_READY;
|
---|
286 |
|
---|
287 | /* Process Unlocked */
|
---|
288 | __HAL_UNLOCK(hcrc);
|
---|
289 |
|
---|
290 | /* Return the CRC computed value */
|
---|
291 | return hcrc->Instance->DR;
|
---|
292 | }
|
---|
293 |
|
---|
294 | /**
|
---|
295 | * @}
|
---|
296 | */
|
---|
297 |
|
---|
298 |
|
---|
299 | /** @addtogroup CRC_Exported_Functions_Group3
|
---|
300 | * @brief Peripheral State functions
|
---|
301 | *
|
---|
302 | @verbatim
|
---|
303 | ==============================================================================
|
---|
304 | ##### Peripheral State functions #####
|
---|
305 | ==============================================================================
|
---|
306 | [..]
|
---|
307 | This subsection permits to get in run-time the status of the peripheral
|
---|
308 | and the data flow.
|
---|
309 |
|
---|
310 | @endverbatim
|
---|
311 | * @{
|
---|
312 | */
|
---|
313 |
|
---|
314 | /**
|
---|
315 | * @brief Returns the CRC state.
|
---|
316 | * @param hcrc: pointer to a CRC_HandleTypeDef structure that contains
|
---|
317 | * the configuration information for CRC
|
---|
318 | * @retval HAL state
|
---|
319 | */
|
---|
320 | HAL_CRC_StateTypeDef HAL_CRC_GetState(CRC_HandleTypeDef *hcrc)
|
---|
321 | {
|
---|
322 | return hcrc->State;
|
---|
323 | }
|
---|
324 |
|
---|
325 | /**
|
---|
326 | * @}
|
---|
327 | */
|
---|
328 |
|
---|
329 | /**
|
---|
330 | * @}
|
---|
331 | */
|
---|
332 |
|
---|
333 | #endif /* HAL_CRC_MODULE_ENABLED */
|
---|
334 | /**
|
---|
335 | * @}
|
---|
336 | */
|
---|
337 |
|
---|
338 | /**
|
---|
339 | * @}
|
---|
340 | */
|
---|
341 |
|
---|
342 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
---|