STM32F4xx HAL Driver
master
STM32CubeF4 HAL / LL Drivers API Reference
Toggle main menu visibility
Loading...
Searching...
No Matches
stm32f4xx_hal_crc.c
Go to the documentation of this file.
1
44
45
/* Includes ------------------------------------------------------------------*/
46
#include "
stm32f4xx_hal.h
"
47
51
56
57
#ifdef HAL_CRC_MODULE_ENABLED
58
59
/* Private typedef -----------------------------------------------------------*/
60
/* Private define ------------------------------------------------------------*/
61
/* Private macro -------------------------------------------------------------*/
62
/* Private variables ---------------------------------------------------------*/
63
/* Private function prototypes -----------------------------------------------*/
64
65
/* Exported functions --------------------------------------------------------*/
66
70
88
95
HAL_StatusTypeDef
HAL_CRC_Init
(
CRC_HandleTypeDef
*hcrc)
96
{
97
/* Check the CRC handle allocation */
98
if
(hcrc == NULL)
99
{
100
return
HAL_ERROR
;
101
}
102
103
/* Check the parameters */
104
assert_param
(IS_CRC_ALL_INSTANCE(hcrc->
Instance
));
105
106
if
(hcrc->
State
==
HAL_CRC_STATE_RESET
)
107
{
108
/* Allocate lock resource and initialize it */
109
hcrc->
Lock
=
HAL_UNLOCKED
;
110
/* Init the low level hardware */
111
HAL_CRC_MspInit
(hcrc);
112
}
113
114
/* Change CRC peripheral state */
115
hcrc->
State
=
HAL_CRC_STATE_READY
;
116
117
/* Return function status */
118
return
HAL_OK
;
119
}
120
126
HAL_StatusTypeDef
HAL_CRC_DeInit
(
CRC_HandleTypeDef
*hcrc)
127
{
128
/* Check the CRC handle allocation */
129
if
(hcrc == NULL)
130
{
131
return
HAL_ERROR
;
132
}
133
134
/* Check the parameters */
135
assert_param
(IS_CRC_ALL_INSTANCE(hcrc->
Instance
));
136
137
/* Check the CRC peripheral state */
138
if
(hcrc->
State
==
HAL_CRC_STATE_BUSY
)
139
{
140
return
HAL_BUSY
;
141
}
142
143
/* Change CRC peripheral state */
144
hcrc->
State
=
HAL_CRC_STATE_BUSY
;
145
146
/* Reset CRC calculation unit */
147
__HAL_CRC_DR_RESET
(hcrc);
148
149
/* Reset IDR register content */
150
__HAL_CRC_SET_IDR
(hcrc, 0);
151
152
/* DeInit the low level hardware */
153
HAL_CRC_MspDeInit
(hcrc);
154
155
/* Change CRC peripheral state */
156
hcrc->
State
=
HAL_CRC_STATE_RESET
;
157
158
/* Process unlocked */
159
__HAL_UNLOCK
(hcrc);
160
161
/* Return function status */
162
return
HAL_OK
;
163
}
164
170
__weak
void
HAL_CRC_MspInit
(
CRC_HandleTypeDef
*hcrc)
171
{
172
/* Prevent unused argument(s) compilation warning */
173
UNUSED(hcrc);
174
175
/* NOTE : This function should not be modified, when the callback is needed,
176
the HAL_CRC_MspInit can be implemented in the user file
177
*/
178
}
179
185
__weak
void
HAL_CRC_MspDeInit
(
CRC_HandleTypeDef
*hcrc)
186
{
187
/* Prevent unused argument(s) compilation warning */
188
UNUSED(hcrc);
189
190
/* NOTE : This function should not be modified, when the callback is needed,
191
the HAL_CRC_MspDeInit can be implemented in the user file
192
*/
193
}
194
198
218
227
uint32_t
HAL_CRC_Accumulate
(
CRC_HandleTypeDef
*hcrc,
const
uint32_t pBuffer[], uint32_t BufferLength)
228
{
229
uint32_t index;
/* CRC input data buffer index */
230
uint32_t temp = 0U;
/* CRC output (read from hcrc->Instance->DR register) */
231
232
/* Change CRC peripheral state */
233
hcrc->
State
=
HAL_CRC_STATE_BUSY
;
234
235
/* Enter Data to the CRC calculator */
236
for
(index = 0U; index < BufferLength; index++)
237
{
238
hcrc->
Instance
->DR = pBuffer[index];
239
}
240
temp = hcrc->
Instance
->DR;
241
242
/* Change CRC peripheral state */
243
hcrc->
State
=
HAL_CRC_STATE_READY
;
244
245
/* Return the CRC computed value */
246
return
temp;
247
}
248
257
uint32_t
HAL_CRC_Calculate
(
CRC_HandleTypeDef
*hcrc,
const
uint32_t pBuffer[], uint32_t BufferLength)
258
{
259
uint32_t index;
/* CRC input data buffer index */
260
uint32_t temp = 0U;
/* CRC output (read from hcrc->Instance->DR register) */
261
262
/* Change CRC peripheral state */
263
hcrc->
State
=
HAL_CRC_STATE_BUSY
;
264
265
/* Reset CRC Calculation Unit (hcrc->Instance->INIT is
266
* written in hcrc->Instance->DR) */
267
__HAL_CRC_DR_RESET
(hcrc);
268
269
/* Enter 32-bit input data to the CRC calculator */
270
for
(index = 0U; index < BufferLength; index++)
271
{
272
hcrc->
Instance
->DR = pBuffer[index];
273
}
274
temp = hcrc->
Instance
->DR;
275
276
/* Change CRC peripheral state */
277
hcrc->
State
=
HAL_CRC_STATE_READY
;
278
279
/* Return the CRC computed value */
280
return
temp;
281
}
282
286
300
306
HAL_CRC_StateTypeDef
HAL_CRC_GetState
(
const
CRC_HandleTypeDef
*hcrc)
307
{
308
/* Return CRC handle state */
309
return
hcrc->
State
;
310
}
311
315
319
320
321
#endif
/* HAL_CRC_MODULE_ENABLED */
325
HAL_CRC_Init
HAL_StatusTypeDef HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
HAL_CRC_MspInit
void HAL_CRC_MspInit(CRC_HandleTypeDef *hcrc)
HAL_CRC_MspDeInit
void HAL_CRC_MspDeInit(CRC_HandleTypeDef *hcrc)
HAL_CRC_DeInit
HAL_StatusTypeDef HAL_CRC_DeInit(CRC_HandleTypeDef *hcrc)
HAL_CRC_Calculate
uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc, const uint32_t pBuffer[], uint32_t BufferLength)
HAL_CRC_Accumulate
uint32_t HAL_CRC_Accumulate(CRC_HandleTypeDef *hcrc, const uint32_t pBuffer[], uint32_t BufferLength)
HAL_CRC_GetState
HAL_CRC_StateTypeDef HAL_CRC_GetState(const CRC_HandleTypeDef *hcrc)
__HAL_CRC_DR_RESET
#define __HAL_CRC_DR_RESET(__HANDLE__)
Reset CRC Data Register.
Definition
stm32f4xx_hal_crc.h:97
__HAL_CRC_SET_IDR
#define __HAL_CRC_SET_IDR(__HANDLE__, __VALUE__)
Store data in the Independent Data (ID) register.
Definition
stm32f4xx_hal_crc.h:106
HAL_CRC_StateTypeDef
HAL_CRC_StateTypeDef
CRC HAL State Structure definition.
Definition
stm32f4xx_hal_crc.h:47
HAL_CRC_STATE_RESET
@ HAL_CRC_STATE_RESET
Definition
stm32f4xx_hal_crc.h:48
HAL_CRC_STATE_BUSY
@ HAL_CRC_STATE_BUSY
Definition
stm32f4xx_hal_crc.h:50
HAL_CRC_STATE_READY
@ HAL_CRC_STATE_READY
Definition
stm32f4xx_hal_crc.h:49
assert_param
#define assert_param(expr)
Definition
stm32_assert_template.h:46
stm32f4xx_hal.h
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition.
Definition
stm32f4xx_hal_def.h:39
HAL_ERROR
@ HAL_ERROR
Definition
stm32f4xx_hal_def.h:41
HAL_OK
@ HAL_OK
Definition
stm32f4xx_hal_def.h:40
HAL_BUSY
@ HAL_BUSY
Definition
stm32f4xx_hal_def.h:42
__HAL_UNLOCK
#define __HAL_UNLOCK(__HANDLE__)
Definition
stm32f4xx_hal_def.h:105
HAL_UNLOCKED
@ HAL_UNLOCKED
Definition
stm32f4xx_hal_def.h:51
CRC_HandleTypeDef
CRC Handle Structure definition.
Definition
stm32f4xx_hal_crc.h:60
CRC_HandleTypeDef::Instance
CRC_TypeDef * Instance
Definition
stm32f4xx_hal_crc.h:61
CRC_HandleTypeDef::Lock
HAL_LockTypeDef Lock
Definition
stm32f4xx_hal_crc.h:63
CRC_HandleTypeDef::State
volatile HAL_CRC_StateTypeDef State
Definition
stm32f4xx_hal_crc.h:65
hal-driver
Src
stm32f4xx_hal_crc.c
Generated by
1.17.0