2 ******************************************************************************
3 * @file stm32h7xx_hal_dfsdm.c
4 * @author MCD Application Team
5 * @brief This file provides firmware functions to manage the following
6 * functionalities of the Digital Filter for Sigma-Delta Modulators
8 * + Initialization and configuration of channels and filters
9 * + Regular channels configuration
10 * + Injected channels configuration
11 * + Regular/Injected Channels DMA Configuration
12 * + Interrupts and flags management
13 * + Analog watchdog feature
14 * + Short-circuit detector feature
15 * + Extremes detector feature
16 * + Clock absence detector feature
17 * + Break generation on analog watchdog or short-circuit event
20 ==============================================================================
21 ##### How to use this driver #####
22 ==============================================================================
24 *** Channel initialization ***
25 ==============================
27 (#) User has first to initialize channels (before filters initialization).
28 (#) As prerequisite, fill in the HAL_DFSDM_ChannelMspInit() :
29 (++) Enable DFSDMz clock interface with __HAL_RCC_DFSDMz_CLK_ENABLE().
30 (++) Enable the clocks for the DFSDMz GPIOS with __HAL_RCC_GPIOx_CLK_ENABLE().
31 (++) Configure these DFSDMz pins in alternate mode using HAL_GPIO_Init().
32 (++) If interrupt mode is used, enable and configure DFSDMz_FLT0 global
33 interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
34 (#) Configure the output clock, input, serial interface, analog watchdog,
35 offset and data right bit shift parameters for this channel using the
36 HAL_DFSDM_ChannelInit() function.
38 *** Channel clock absence detector ***
39 ======================================
41 (#) Start clock absence detector using HAL_DFSDM_ChannelCkabStart() or
42 HAL_DFSDM_ChannelCkabStart_IT().
43 (#) In polling mode, use HAL_DFSDM_ChannelPollForCkab() to detect the clock
45 (#) In interrupt mode, HAL_DFSDM_ChannelCkabCallback() will be called if
46 clock absence is detected.
47 (#) Stop clock absence detector using HAL_DFSDM_ChannelCkabStop() or
48 HAL_DFSDM_ChannelCkabStop_IT().
49 (#) Please note that the same mode (polling or interrupt) has to be used
50 for all channels because the channels are sharing the same interrupt.
51 (#) Please note also that in interrupt mode, if clock absence detector is
52 stopped for one channel, interrupt will be disabled for all channels.
54 *** Channel short circuit detector ***
55 ======================================
57 (#) Start short circuit detector using HAL_DFSDM_ChannelScdStart() or
58 or HAL_DFSDM_ChannelScdStart_IT().
59 (#) In polling mode, use HAL_DFSDM_ChannelPollForScd() to detect short
61 (#) In interrupt mode, HAL_DFSDM_ChannelScdCallback() will be called if
62 short circuit is detected.
63 (#) Stop short circuit detector using HAL_DFSDM_ChannelScdStop() or
64 or HAL_DFSDM_ChannelScdStop_IT().
65 (#) Please note that the same mode (polling or interrupt) has to be used
66 for all channels because the channels are sharing the same interrupt.
67 (#) Please note also that in interrupt mode, if short circuit detector is
68 stopped for one channel, interrupt will be disabled for all channels.
70 *** Channel analog watchdog value ***
71 =====================================
73 (#) Get analog watchdog filter value of a channel using
74 HAL_DFSDM_ChannelGetAwdValue().
76 *** Channel offset value ***
77 =====================================
79 (#) Modify offset value of a channel using HAL_DFSDM_ChannelModifyOffset().
81 *** Filter initialization ***
82 =============================
84 (#) After channel initialization, user has to init filters.
85 (#) As prerequisite, fill in the HAL_DFSDM_FilterMspInit() :
86 (++) If interrupt mode is used , enable and configure DFSDMz_FLTx global
87 interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
88 Please note that DFSDMz_FLT0 global interrupt could be already
89 enabled if interrupt is used for channel.
90 (++) If DMA mode is used, configure DMA with HAL_DMA_Init() and link it
91 with DFSDMz filter handle using __HAL_LINKDMA().
92 (#) Configure the regular conversion, injected conversion and filter
93 parameters for this filter using the HAL_DFSDM_FilterInit() function.
95 *** Filter regular channel conversion ***
96 =========================================
98 (#) Select regular channel and enable/disable continuous mode using
99 HAL_DFSDM_FilterConfigRegChannel().
100 (#) Start regular conversion using HAL_DFSDM_FilterRegularStart(),
101 HAL_DFSDM_FilterRegularStart_IT(), HAL_DFSDM_FilterRegularStart_DMA() or
102 HAL_DFSDM_FilterRegularMsbStart_DMA().
103 (#) In polling mode, use HAL_DFSDM_FilterPollForRegConversion() to detect
104 the end of regular conversion.
105 (#) In interrupt mode, HAL_DFSDM_FilterRegConvCpltCallback() will be called
106 at the end of regular conversion.
107 (#) Get value of regular conversion and corresponding channel using
108 HAL_DFSDM_FilterGetRegularValue().
109 (#) In DMA mode, HAL_DFSDM_FilterRegConvHalfCpltCallback() and
110 HAL_DFSDM_FilterRegConvCpltCallback() will be called respectively at the
111 half transfer and at the transfer complete. Please note that
112 HAL_DFSDM_FilterRegConvHalfCpltCallback() will be called only in DMA
114 (#) Stop regular conversion using HAL_DFSDM_FilterRegularStop(),
115 HAL_DFSDM_FilterRegularStop_IT() or HAL_DFSDM_FilterRegularStop_DMA().
117 *** Filter injected channels conversion ***
118 ===========================================
120 (#) Select injected channels using HAL_DFSDM_FilterConfigInjChannel().
121 (#) Start injected conversion using HAL_DFSDM_FilterInjectedStart(),
122 HAL_DFSDM_FilterInjectedStart_IT(), HAL_DFSDM_FilterInjectedStart_DMA() or
123 HAL_DFSDM_FilterInjectedMsbStart_DMA().
124 (#) In polling mode, use HAL_DFSDM_FilterPollForInjConversion() to detect
125 the end of injected conversion.
126 (#) In interrupt mode, HAL_DFSDM_FilterInjConvCpltCallback() will be called
127 at the end of injected conversion.
128 (#) Get value of injected conversion and corresponding channel using
129 HAL_DFSDM_FilterGetInjectedValue().
130 (#) In DMA mode, HAL_DFSDM_FilterInjConvHalfCpltCallback() and
131 HAL_DFSDM_FilterInjConvCpltCallback() will be called respectively at the
132 half transfer and at the transfer complete. Please note that
133 HAL_DFSDM_FilterInjConvCpltCallback() will be called only in DMA
135 (#) Stop injected conversion using HAL_DFSDM_FilterInjectedStop(),
136 HAL_DFSDM_FilterInjectedStop_IT() or HAL_DFSDM_FilterInjectedStop_DMA().
138 *** Filter analog watchdog ***
139 ==============================
141 (#) Start filter analog watchdog using HAL_DFSDM_FilterAwdStart_IT().
142 (#) HAL_DFSDM_FilterAwdCallback() will be called if analog watchdog occurs.
143 (#) Stop filter analog watchdog using HAL_DFSDM_FilterAwdStop_IT().
145 *** Filter extreme detector ***
146 ===============================
148 (#) Start filter extreme detector using HAL_DFSDM_FilterExdStart().
149 (#) Get extreme detector maximum value using HAL_DFSDM_FilterGetExdMaxValue().
150 (#) Get extreme detector minimum value using HAL_DFSDM_FilterGetExdMinValue().
151 (#) Start filter extreme detector using HAL_DFSDM_FilterExdStop().
153 *** Filter conversion time ***
154 ==============================
156 (#) Get conversion time value using HAL_DFSDM_FilterGetConvTimeValue().
158 *** Callback registration ***
159 =============================
161 The compilation define USE_HAL_DFSDM_REGISTER_CALLBACKS when set to 1
162 allows the user to configure dynamically the driver callbacks.
163 Use functions HAL_DFSDM_Channel_RegisterCallback(),
164 HAL_DFSDM_Filter_RegisterCallback() or
165 HAL_DFSDM_Filter_RegisterAwdCallback() to register a user callback.
168 Function HAL_DFSDM_Channel_RegisterCallback() allows to register
170 (+) CkabCallback : DFSDM channel clock absence detection callback.
171 (+) ScdCallback : DFSDM channel short circuit detection callback.
172 (+) MspInitCallback : DFSDM channel MSP init callback.
173 (+) MspDeInitCallback : DFSDM channel MSP de-init callback.
175 This function takes as parameters the HAL peripheral handle, the Callback ID
176 and a pointer to the user callback function.
179 Function HAL_DFSDM_Filter_RegisterCallback() allows to register
181 (+) RegConvCpltCallback : DFSDM filter regular conversion complete callback.
182 (+) RegConvHalfCpltCallback : DFSDM filter half regular conversion complete callback.
183 (+) InjConvCpltCallback : DFSDM filter injected conversion complete callback.
184 (+) InjConvHalfCpltCallback : DFSDM filter half injected conversion complete callback.
185 (+) ErrorCallback : DFSDM filter error callback.
186 (+) MspInitCallback : DFSDM filter MSP init callback.
187 (+) MspDeInitCallback : DFSDM filter MSP de-init callback.
189 This function takes as parameters the HAL peripheral handle, the Callback ID
190 and a pointer to the user callback function.
193 For specific DFSDM filter analog watchdog callback use dedicated register callback:
194 HAL_DFSDM_Filter_RegisterAwdCallback().
197 Use functions HAL_DFSDM_Channel_UnRegisterCallback() or
198 HAL_DFSDM_Filter_UnRegisterCallback() to reset a callback to the default
202 HAL_DFSDM_Channel_UnRegisterCallback() takes as parameters the HAL peripheral handle,
205 This function allows to reset following callbacks:
206 (+) CkabCallback : DFSDM channel clock absence detection callback.
207 (+) ScdCallback : DFSDM channel short circuit detection callback.
208 (+) MspInitCallback : DFSDM channel MSP init callback.
209 (+) MspDeInitCallback : DFSDM channel MSP de-init callback.
212 HAL_DFSDM_Filter_UnRegisterCallback() takes as parameters the HAL peripheral handle,
215 This function allows to reset following callbacks:
216 (+) RegConvCpltCallback : DFSDM filter regular conversion complete callback.
217 (+) RegConvHalfCpltCallback : DFSDM filter half regular conversion complete callback.
218 (+) InjConvCpltCallback : DFSDM filter injected conversion complete callback.
219 (+) InjConvHalfCpltCallback : DFSDM filter half injected conversion complete callback.
220 (+) ErrorCallback : DFSDM filter error callback.
221 (+) MspInitCallback : DFSDM filter MSP init callback.
222 (+) MspDeInitCallback : DFSDM filter MSP de-init callback.
225 For specific DFSDM filter analog watchdog callback use dedicated unregister callback:
226 HAL_DFSDM_Filter_UnRegisterAwdCallback().
229 By default, after the call of init function and if the state is RESET
230 all callbacks are reset to the corresponding legacy weak functions:
231 examples HAL_DFSDM_ChannelScdCallback(), HAL_DFSDM_FilterErrorCallback().
232 Exception done for MspInit and MspDeInit callbacks that are respectively
233 reset to the legacy weak functions in the init and de-init only when these
234 callbacks are null (not registered beforehand).
235 If not, MspInit or MspDeInit are not null, the init and de-init keep and use
236 the user MspInit/MspDeInit callbacks (registered beforehand)
239 Callbacks can be registered/unregistered in READY state only.
240 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
241 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
242 during the init/de-init.
243 In that case first register the MspInit/MspDeInit user callbacks using
244 HAL_DFSDM_Channel_RegisterCallback() or
245 HAL_DFSDM_Filter_RegisterCallback() before calling init or de-init function.
248 When The compilation define USE_HAL_DFSDM_REGISTER_CALLBACKS is set to 0 or
249 not defined, the callback registering feature is not available
250 and weak callbacks are used.
253 ******************************************************************************
256 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
257 * All rights reserved.</center></h2>
259 * This software component is licensed by ST under BSD 3-Clause license,
260 * the "License"; You may not use this file except in compliance with the
261 * License. You may obtain a copy of the License at:
262 * opensource.org/licenses/BSD-3-Clause
264 ******************************************************************************
267 /* Includes ------------------------------------------------------------------*/
268 #include "stm32h7xx_hal.h"
270 /** @addtogroup STM32H7xx_HAL_Driver
273 #ifdef HAL_DFSDM_MODULE_ENABLED
275 /** @defgroup DFSDM DFSDM
276 * @brief DFSDM HAL driver module
280 /* Private typedef -----------------------------------------------------------*/
281 /* Private define ------------------------------------------------------------*/
282 /** @defgroup DFSDM_Private_Define DFSDM Private Define
285 #define DFSDM_FLTCR1_MSB_RCH_OFFSET 8
286 #define DFSDM_MSB_MASK 0xFFFF0000U
287 #define DFSDM_LSB_MASK 0x0000FFFFU
288 #define DFSDM_CKAB_TIMEOUT 5000U
289 #define DFSDM1_CHANNEL_NUMBER 8U
290 #if defined(DFSDM2_Channel0)
291 #define DFSDM2_CHANNEL_NUMBER 2U
292 #endif /* DFSDM2_Channel0 */
297 /* Private macro -------------------------------------------------------------*/
298 /* Private variables ---------------------------------------------------------*/
299 /** @defgroup DFSDM_Private_Variables DFSDM Private Variables
302 static __IO
uint32_t v_dfsdm1ChannelCounter
= 0;
303 static DFSDM_Channel_HandleTypeDef
*a_dfsdm1ChannelHandle
[DFSDM1_CHANNEL_NUMBER
] = {NULL
};
304 #if defined(DFSDM2_Channel0)
305 static __IO
uint32_t v_dfsdm2ChannelCounter
= 0;
306 static DFSDM_Channel_HandleTypeDef
*a_dfsdm2ChannelHandle
[DFSDM2_CHANNEL_NUMBER
] = {NULL
};
307 #endif /* DFSDM2_Channel0 */
312 /* Private function prototypes -----------------------------------------------*/
313 /** @defgroup DFSDM_Private_Functions DFSDM Private Functions
316 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels
);
317 static uint32_t DFSDM_GetChannelFromInstance(const DFSDM_Channel_TypeDef
*Instance
);
318 static void DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
);
319 static void DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
);
320 static void DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
);
321 static void DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
);
322 static void DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef
*hdma
);
323 static void DFSDM_DMARegularConvCplt(DMA_HandleTypeDef
*hdma
);
324 static void DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef
*hdma
);
325 static void DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef
*hdma
);
326 static void DFSDM_DMAError(DMA_HandleTypeDef
*hdma
);
331 /* Exported functions --------------------------------------------------------*/
332 /** @defgroup DFSDM_Exported_Functions DFSDM Exported Functions
336 /** @defgroup DFSDM_Exported_Functions_Group1_Channel Channel initialization and de-initialization functions
337 * @brief Channel initialization and de-initialization functions
340 ==============================================================================
341 ##### Channel initialization and de-initialization functions #####
342 ==============================================================================
343 [..] This section provides functions allowing to:
344 (+) Initialize the DFSDM channel.
345 (+) De-initialize the DFSDM channel.
351 * @brief Initialize the DFSDM channel according to the specified parameters
352 * in the DFSDM_ChannelInitTypeDef structure and initialize the associated handle.
353 * @param hdfsdm_channel DFSDM channel handle.
354 * @retval HAL status.
356 HAL_StatusTypeDef
HAL_DFSDM_ChannelInit(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
358 __IO
uint32_t *channelCounterPtr
;
359 DFSDM_Channel_HandleTypeDef
**channelHandleTable
;
360 DFSDM_Channel_TypeDef
*channel0Instance
;
362 /* Check DFSDM Channel handle */
363 if(hdfsdm_channel
== NULL
)
368 /* Check parameters */
369 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
370 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_channel
->Init
.OutputClock
.Activation
));
371 assert_param(IS_DFSDM_CHANNEL_INPUT(hdfsdm_channel
->Init
.Input
.Multiplexer
));
372 assert_param(IS_DFSDM_CHANNEL_DATA_PACKING(hdfsdm_channel
->Init
.Input
.DataPacking
));
373 assert_param(IS_DFSDM_CHANNEL_INPUT_PINS(hdfsdm_channel
->Init
.Input
.Pins
));
374 assert_param(IS_DFSDM_CHANNEL_SERIAL_INTERFACE_TYPE(hdfsdm_channel
->Init
.SerialInterface
.Type
));
375 assert_param(IS_DFSDM_CHANNEL_SPI_CLOCK(hdfsdm_channel
->Init
.SerialInterface
.SpiClock
));
376 assert_param(IS_DFSDM_CHANNEL_FILTER_ORDER(hdfsdm_channel
->Init
.Awd
.FilterOrder
));
377 assert_param(IS_DFSDM_CHANNEL_FILTER_OVS_RATIO(hdfsdm_channel
->Init
.Awd
.Oversampling
));
378 assert_param(IS_DFSDM_CHANNEL_OFFSET(hdfsdm_channel
->Init
.Offset
));
379 assert_param(IS_DFSDM_CHANNEL_RIGHT_BIT_SHIFT(hdfsdm_channel
->Init
.RightBitShift
));
381 #if defined(DFSDM2_Channel0)
382 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
384 channelCounterPtr
= &v_dfsdm1ChannelCounter
;
385 channelHandleTable
= a_dfsdm1ChannelHandle
;
386 channel0Instance
= DFSDM1_Channel0
;
390 channelCounterPtr
= &v_dfsdm2ChannelCounter
;
391 channelHandleTable
= a_dfsdm2ChannelHandle
;
392 channel0Instance
= DFSDM2_Channel0
;
394 #else /* DFSDM2_Channel0 */
395 channelCounterPtr
= &v_dfsdm1ChannelCounter
;
396 channelHandleTable
= a_dfsdm1ChannelHandle
;
397 channel0Instance
= DFSDM1_Channel0
;
398 #endif /* DFSDM2_Channel0 */
400 /* Check that channel has not been already initialized */
401 if (channelHandleTable
[DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
)] != NULL
)
406 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
407 /* Reset callback pointers to the weak predefined callbacks */
408 hdfsdm_channel
->CkabCallback
= HAL_DFSDM_ChannelCkabCallback
;
409 hdfsdm_channel
->ScdCallback
= HAL_DFSDM_ChannelScdCallback
;
411 /* Call MSP init function */
412 if(hdfsdm_channel
->MspInitCallback
== NULL
)
414 hdfsdm_channel
->MspInitCallback
= HAL_DFSDM_ChannelMspInit
;
416 hdfsdm_channel
->MspInitCallback(hdfsdm_channel
);
418 /* Call MSP init function */
419 HAL_DFSDM_ChannelMspInit(hdfsdm_channel
);
422 /* Update the channel counter */
423 (*channelCounterPtr
)++;
425 /* Configure output serial clock and enable global DFSDM interface only for first channel */
426 if(*channelCounterPtr
== 1U)
428 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK(hdfsdm_channel
->Init
.OutputClock
.Selection
));
429 /* Set the output serial clock source */
430 channel0Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CKOUTSRC
);
431 channel0Instance
->CHCFGR1
|= hdfsdm_channel
->Init
.OutputClock
.Selection
;
433 /* Reset clock divider */
434 channel0Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CKOUTDIV
);
435 if(hdfsdm_channel
->Init
.OutputClock
.Activation
== ENABLE
)
437 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK_DIVIDER(hdfsdm_channel
->Init
.OutputClock
.Divider
));
438 /* Set the output clock divider */
439 channel0Instance
->CHCFGR1
|= (uint32_t)((hdfsdm_channel
->Init
.OutputClock
.Divider
- 1U) <<
440 DFSDM_CHCFGR1_CKOUTDIV_Pos
);
443 /* enable the DFSDM global interface */
444 channel0Instance
->CHCFGR1
|= DFSDM_CHCFGR1_DFSDMEN
;
447 /* Set channel input parameters */
448 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_DATPACK
| DFSDM_CHCFGR1_DATMPX
|
449 DFSDM_CHCFGR1_CHINSEL
);
450 hdfsdm_channel
->Instance
->CHCFGR1
|= (hdfsdm_channel
->Init
.Input
.Multiplexer
|
451 hdfsdm_channel
->Init
.Input
.DataPacking
|
452 hdfsdm_channel
->Init
.Input
.Pins
);
454 /* Set serial interface parameters */
455 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_SITP
| DFSDM_CHCFGR1_SPICKSEL
);
456 hdfsdm_channel
->Instance
->CHCFGR1
|= (hdfsdm_channel
->Init
.SerialInterface
.Type
|
457 hdfsdm_channel
->Init
.SerialInterface
.SpiClock
);
459 /* Set analog watchdog parameters */
460 hdfsdm_channel
->Instance
->CHAWSCDR
&= ~(DFSDM_CHAWSCDR_AWFORD
| DFSDM_CHAWSCDR_AWFOSR
);
461 hdfsdm_channel
->Instance
->CHAWSCDR
|= (hdfsdm_channel
->Init
.Awd
.FilterOrder
|
462 ((hdfsdm_channel
->Init
.Awd
.Oversampling
- 1U) << DFSDM_CHAWSCDR_AWFOSR_Pos
));
464 /* Set channel offset and right bit shift */
465 hdfsdm_channel
->Instance
->CHCFGR2
&= ~(DFSDM_CHCFGR2_OFFSET
| DFSDM_CHCFGR2_DTRBS
);
466 hdfsdm_channel
->Instance
->CHCFGR2
|= (((uint32_t) hdfsdm_channel
->Init
.Offset
<< DFSDM_CHCFGR2_OFFSET_Pos
) |
467 (hdfsdm_channel
->Init
.RightBitShift
<< DFSDM_CHCFGR2_DTRBS_Pos
));
469 /* Enable DFSDM channel */
470 hdfsdm_channel
->Instance
->CHCFGR1
|= DFSDM_CHCFGR1_CHEN
;
472 /* Set DFSDM Channel to ready state */
473 hdfsdm_channel
->State
= HAL_DFSDM_CHANNEL_STATE_READY
;
475 /* Store channel handle in DFSDM channel handle table */
476 channelHandleTable
[DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
)] = hdfsdm_channel
;
482 * @brief De-initialize the DFSDM channel.
483 * @param hdfsdm_channel DFSDM channel handle.
484 * @retval HAL status.
486 HAL_StatusTypeDef
HAL_DFSDM_ChannelDeInit(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
488 __IO
uint32_t *channelCounterPtr
;
489 DFSDM_Channel_HandleTypeDef
**channelHandleTable
;
490 DFSDM_Channel_TypeDef
*channel0Instance
;
492 /* Check DFSDM Channel handle */
493 if(hdfsdm_channel
== NULL
)
498 /* Check parameters */
499 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
501 #if defined(DFSDM2_Channel0)
502 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
504 channelCounterPtr
= &v_dfsdm1ChannelCounter
;
505 channelHandleTable
= a_dfsdm1ChannelHandle
;
506 channel0Instance
= DFSDM1_Channel0
;
510 channelCounterPtr
= &v_dfsdm2ChannelCounter
;
511 channelHandleTable
= a_dfsdm2ChannelHandle
;
512 channel0Instance
= DFSDM2_Channel0
;
514 #else /* DFSDM2_Channel0 */
515 channelCounterPtr
= &v_dfsdm1ChannelCounter
;
516 channelHandleTable
= a_dfsdm1ChannelHandle
;
517 channel0Instance
= DFSDM1_Channel0
;
518 #endif /* DFSDM2_Channel0 */
520 /* Check that channel has not been already deinitialized */
521 if (channelHandleTable
[DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
)] == NULL
)
526 /* Disable the DFSDM channel */
527 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CHEN
);
529 /* Update the channel counter */
530 (*channelCounterPtr
)--;
532 /* Disable global DFSDM at deinit of last channel */
533 if (*channelCounterPtr
== 0U)
535 channel0Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_DFSDMEN
);
538 /* Call MSP deinit function */
539 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
540 if(hdfsdm_channel
->MspDeInitCallback
== NULL
)
542 hdfsdm_channel
->MspDeInitCallback
= HAL_DFSDM_ChannelMspDeInit
;
544 hdfsdm_channel
->MspDeInitCallback(hdfsdm_channel
);
546 HAL_DFSDM_ChannelMspDeInit(hdfsdm_channel
);
549 /* Set DFSDM Channel in reset state */
550 hdfsdm_channel
->State
= HAL_DFSDM_CHANNEL_STATE_RESET
;
552 /* Reset channel handle in DFSDM channel handle table */
553 channelHandleTable
[DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
)] = (DFSDM_Channel_HandleTypeDef
*) NULL
;
559 * @brief Initialize the DFSDM channel MSP.
560 * @param hdfsdm_channel DFSDM channel handle.
563 __weak
void HAL_DFSDM_ChannelMspInit(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
565 /* Prevent unused argument(s) compilation warning */
566 UNUSED(hdfsdm_channel
);
568 /* NOTE : This function should not be modified, when the function is needed,
569 the HAL_DFSDM_ChannelMspInit could be implemented in the user file.
574 * @brief De-initialize the DFSDM channel MSP.
575 * @param hdfsdm_channel DFSDM channel handle.
578 __weak
void HAL_DFSDM_ChannelMspDeInit(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
580 /* Prevent unused argument(s) compilation warning */
581 UNUSED(hdfsdm_channel
);
583 /* NOTE : This function should not be modified, when the function is needed,
584 the HAL_DFSDM_ChannelMspDeInit could be implemented in the user file.
588 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
590 * @brief Register a user DFSDM channel callback
591 * to be used instead of the weak predefined callback.
592 * @param hdfsdm_channel DFSDM channel handle.
593 * @param CallbackID ID of the callback to be registered.
594 * This parameter can be one of the following values:
595 * @arg @ref HAL_DFSDM_CHANNEL_CKAB_CB_ID clock absence detection callback ID.
596 * @arg @ref HAL_DFSDM_CHANNEL_SCD_CB_ID short circuit detection callback ID.
597 * @arg @ref HAL_DFSDM_CHANNEL_MSPINIT_CB_ID MSP init callback ID.
598 * @arg @ref HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID MSP de-init callback ID.
599 * @param pCallback pointer to the callback function.
600 * @retval HAL status.
602 HAL_StatusTypeDef
HAL_DFSDM_Channel_RegisterCallback(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
,
603 HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID
,
604 pDFSDM_Channel_CallbackTypeDef pCallback
)
606 HAL_StatusTypeDef status
= HAL_OK
;
608 if(pCallback
== NULL
)
610 /* update return status */
615 if(HAL_DFSDM_CHANNEL_STATE_READY
== hdfsdm_channel
->State
)
619 case HAL_DFSDM_CHANNEL_CKAB_CB_ID
:
620 hdfsdm_channel
->CkabCallback
= pCallback
;
622 case HAL_DFSDM_CHANNEL_SCD_CB_ID
:
623 hdfsdm_channel
->ScdCallback
= pCallback
;
625 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID
:
626 hdfsdm_channel
->MspInitCallback
= pCallback
;
628 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID
:
629 hdfsdm_channel
->MspDeInitCallback
= pCallback
;
632 /* update return status */
637 else if(HAL_DFSDM_CHANNEL_STATE_RESET
== hdfsdm_channel
->State
)
641 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID
:
642 hdfsdm_channel
->MspInitCallback
= pCallback
;
644 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID
:
645 hdfsdm_channel
->MspDeInitCallback
= pCallback
;
648 /* update return status */
655 /* update return status */
663 * @brief Unregister a user DFSDM channel callback.
664 * DFSDM channel callback is redirected to the weak predefined callback.
665 * @param hdfsdm_channel DFSDM channel handle.
666 * @param CallbackID ID of the callback to be unregistered.
667 * This parameter can be one of the following values:
668 * @arg @ref HAL_DFSDM_CHANNEL_CKAB_CB_ID clock absence detection callback ID.
669 * @arg @ref HAL_DFSDM_CHANNEL_SCD_CB_ID short circuit detection callback ID.
670 * @arg @ref HAL_DFSDM_CHANNEL_MSPINIT_CB_ID MSP init callback ID.
671 * @arg @ref HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID MSP de-init callback ID.
672 * @retval HAL status.
674 HAL_StatusTypeDef
HAL_DFSDM_Channel_UnRegisterCallback(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
,
675 HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID
)
677 HAL_StatusTypeDef status
= HAL_OK
;
679 if(HAL_DFSDM_CHANNEL_STATE_READY
== hdfsdm_channel
->State
)
683 case HAL_DFSDM_CHANNEL_CKAB_CB_ID
:
684 hdfsdm_channel
->CkabCallback
= HAL_DFSDM_ChannelCkabCallback
;
686 case HAL_DFSDM_CHANNEL_SCD_CB_ID
:
687 hdfsdm_channel
->ScdCallback
= HAL_DFSDM_ChannelScdCallback
;
689 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID
:
690 hdfsdm_channel
->MspInitCallback
= HAL_DFSDM_ChannelMspInit
;
692 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID
:
693 hdfsdm_channel
->MspDeInitCallback
= HAL_DFSDM_ChannelMspDeInit
;
696 /* update return status */
701 else if(HAL_DFSDM_CHANNEL_STATE_RESET
== hdfsdm_channel
->State
)
705 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID
:
706 hdfsdm_channel
->MspInitCallback
= HAL_DFSDM_ChannelMspInit
;
708 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID
:
709 hdfsdm_channel
->MspDeInitCallback
= HAL_DFSDM_ChannelMspDeInit
;
712 /* update return status */
719 /* update return status */
724 #endif /* USE_HAL_DFSDM_REGISTER_CALLBACKS */
730 /** @defgroup DFSDM_Exported_Functions_Group2_Channel Channel operation functions
731 * @brief Channel operation functions
734 ==============================================================================
735 ##### Channel operation functions #####
736 ==============================================================================
737 [..] This section provides functions allowing to:
738 (+) Manage clock absence detector feature.
739 (+) Manage short circuit detector feature.
740 (+) Get analog watchdog value.
741 (+) Modify offset value.
747 * @brief This function allows to start clock absence detection in polling mode.
748 * @note Same mode has to be used for all channels.
749 * @note If clock is not available on this channel during 5 seconds,
750 * clock absence detection will not be activated and function
751 * will return HAL_TIMEOUT error.
752 * @param hdfsdm_channel DFSDM channel handle.
755 HAL_StatusTypeDef
HAL_DFSDM_ChannelCkabStart(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
757 HAL_StatusTypeDef status
= HAL_OK
;
760 DFSDM_Filter_TypeDef
*filter0Instance
;
762 /* Check parameters */
763 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
765 #if defined(DFSDM2_Channel0)
766 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
768 filter0Instance
= DFSDM1_Filter0
;
772 filter0Instance
= DFSDM2_Filter0
;
774 #else /* DFSDM2_Channel0 */
775 filter0Instance
= DFSDM1_Filter0
;
776 #endif /* DFSDM2_Channel0 */
778 /* Check DFSDM channel state */
779 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
781 /* Return error status */
786 /* Get channel number from channel instance */
787 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
790 tickstart
= HAL_GetTick();
792 /* Clear clock absence flag */
793 while ((((filter0Instance
->FLTISR
& DFSDM_FLTISR_CKABF
) >> (DFSDM_FLTISR_CKABF_Pos
+ channel
)) & 1U) != 0U)
795 filter0Instance
->FLTICR
= (1UL << (DFSDM_FLTICR_CLRCKABF_Pos
+ channel
));
797 /* Check the Timeout */
798 if((HAL_GetTick()-tickstart
) > DFSDM_CKAB_TIMEOUT
)
800 /* Set timeout status */
801 status
= HAL_TIMEOUT
;
808 /* Start clock absence detection */
809 hdfsdm_channel
->Instance
->CHCFGR1
|= DFSDM_CHCFGR1_CKABEN
;
812 /* Return function status */
817 * @brief This function allows to poll for the clock absence detection.
818 * @param hdfsdm_channel DFSDM channel handle.
819 * @param Timeout Timeout value in milliseconds.
822 HAL_StatusTypeDef
HAL_DFSDM_ChannelPollForCkab(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
,
827 DFSDM_Filter_TypeDef
*filter0Instance
;
829 /* Check parameters */
830 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
832 #if defined(DFSDM2_Channel0)
833 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
835 filter0Instance
= DFSDM1_Filter0
;
839 filter0Instance
= DFSDM2_Filter0
;
841 #else /* DFSDM2_Channel0 */
842 filter0Instance
= DFSDM1_Filter0
;
843 #endif /* DFSDM2_Channel0 */
845 /* Check DFSDM channel state */
846 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
848 /* Return error status */
853 /* Get channel number from channel instance */
854 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
857 tickstart
= HAL_GetTick();
859 /* Wait clock absence detection */
860 while ((((filter0Instance
->FLTISR
& DFSDM_FLTISR_CKABF
) >> (DFSDM_FLTISR_CKABF_Pos
+ channel
)) & 1U) == 0U)
862 /* Check the Timeout */
863 if(Timeout
!= HAL_MAX_DELAY
)
865 if(((HAL_GetTick()-tickstart
) > Timeout
) || (Timeout
== 0U))
867 /* Return timeout status */
873 /* Clear clock absence detection flag */
874 filter0Instance
->FLTICR
= (1UL << (DFSDM_FLTICR_CLRCKABF_Pos
+ channel
));
876 /* Return function status */
882 * @brief This function allows to stop clock absence detection in polling mode.
883 * @param hdfsdm_channel DFSDM channel handle.
886 HAL_StatusTypeDef
HAL_DFSDM_ChannelCkabStop(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
888 HAL_StatusTypeDef status
= HAL_OK
;
890 DFSDM_Filter_TypeDef
*filter0Instance
;
892 /* Check parameters */
893 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
895 #if defined(DFSDM2_Channel0)
896 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
898 filter0Instance
= DFSDM1_Filter0
;
902 filter0Instance
= DFSDM2_Filter0
;
904 #else /* DFSDM2_Channel0 */
905 filter0Instance
= DFSDM1_Filter0
;
906 #endif /* DFSDM2_Channel0 */
908 /* Check DFSDM channel state */
909 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
911 /* Return error status */
916 /* Stop clock absence detection */
917 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CKABEN
);
919 /* Clear clock absence flag */
920 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
921 filter0Instance
->FLTICR
= (1UL << (DFSDM_FLTICR_CLRCKABF_Pos
+ channel
));
923 /* Return function status */
928 * @brief This function allows to start clock absence detection in interrupt mode.
929 * @note Same mode has to be used for all channels.
930 * @note If clock is not available on this channel during 5 seconds,
931 * clock absence detection will not be activated and function
932 * will return HAL_TIMEOUT error.
933 * @param hdfsdm_channel DFSDM channel handle.
936 HAL_StatusTypeDef
HAL_DFSDM_ChannelCkabStart_IT(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
938 HAL_StatusTypeDef status
= HAL_OK
;
941 DFSDM_Filter_TypeDef
*filter0Instance
;
943 /* Check parameters */
944 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
946 #if defined(DFSDM2_Channel0)
947 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
949 filter0Instance
= DFSDM1_Filter0
;
953 filter0Instance
= DFSDM2_Filter0
;
955 #else /* DFSDM2_Channel0 */
956 filter0Instance
= DFSDM1_Filter0
;
957 #endif /* DFSDM2_Channel0 */
959 /* Check DFSDM channel state */
960 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
962 /* Return error status */
967 /* Get channel number from channel instance */
968 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
971 tickstart
= HAL_GetTick();
973 /* Clear clock absence flag */
974 while ((((filter0Instance
->FLTISR
& DFSDM_FLTISR_CKABF
) >> (DFSDM_FLTISR_CKABF_Pos
+ channel
)) & 1U) != 0U)
976 filter0Instance
->FLTICR
= (1UL << (DFSDM_FLTICR_CLRCKABF_Pos
+ channel
));
978 /* Check the Timeout */
979 if((HAL_GetTick()-tickstart
) > DFSDM_CKAB_TIMEOUT
)
981 /* Set timeout status */
982 status
= HAL_TIMEOUT
;
989 /* Activate clock absence detection interrupt */
990 filter0Instance
->FLTCR2
|= DFSDM_FLTCR2_CKABIE
;
992 /* Start clock absence detection */
993 hdfsdm_channel
->Instance
->CHCFGR1
|= DFSDM_CHCFGR1_CKABEN
;
996 /* Return function status */
1001 * @brief Clock absence detection callback.
1002 * @param hdfsdm_channel DFSDM channel handle.
1005 __weak
void HAL_DFSDM_ChannelCkabCallback(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
1007 /* Prevent unused argument(s) compilation warning */
1008 UNUSED(hdfsdm_channel
);
1010 /* NOTE : This function should not be modified, when the callback is needed,
1011 the HAL_DFSDM_ChannelCkabCallback could be implemented in the user file
1016 * @brief This function allows to stop clock absence detection in interrupt mode.
1017 * @note Interrupt will be disabled for all channels
1018 * @param hdfsdm_channel DFSDM channel handle.
1019 * @retval HAL status
1021 HAL_StatusTypeDef
HAL_DFSDM_ChannelCkabStop_IT(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
1023 HAL_StatusTypeDef status
= HAL_OK
;
1025 DFSDM_Filter_TypeDef
*filter0Instance
;
1027 /* Check parameters */
1028 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1030 #if defined(DFSDM2_Channel0)
1031 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
1033 filter0Instance
= DFSDM1_Filter0
;
1037 filter0Instance
= DFSDM2_Filter0
;
1039 #else /* DFSDM2_Channel0 */
1040 filter0Instance
= DFSDM1_Filter0
;
1041 #endif /* DFSDM2_Channel0 */
1043 /* Check DFSDM channel state */
1044 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1046 /* Return error status */
1051 /* Stop clock absence detection */
1052 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CKABEN
);
1054 /* Clear clock absence flag */
1055 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
1056 filter0Instance
->FLTICR
= (1UL << (DFSDM_FLTICR_CLRCKABF_Pos
+ channel
));
1058 /* Disable clock absence detection interrupt */
1059 filter0Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_CKABIE
);
1061 /* Return function status */
1066 * @brief This function allows to start short circuit detection in polling mode.
1067 * @note Same mode has to be used for all channels
1068 * @param hdfsdm_channel DFSDM channel handle.
1069 * @param Threshold Short circuit detector threshold.
1070 * This parameter must be a number between Min_Data = 0 and Max_Data = 255.
1071 * @param BreakSignal Break signals assigned to short circuit event.
1072 * This parameter can be a values combination of @ref DFSDM_BreakSignals.
1073 * @retval HAL status
1075 HAL_StatusTypeDef
HAL_DFSDM_ChannelScdStart(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
,
1077 uint32_t BreakSignal
)
1079 HAL_StatusTypeDef status
= HAL_OK
;
1081 /* Check parameters */
1082 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1083 assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold
));
1084 assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal
));
1086 /* Check DFSDM channel state */
1087 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1089 /* Return error status */
1094 /* Configure threshold and break signals */
1095 hdfsdm_channel
->Instance
->CHAWSCDR
&= ~(DFSDM_CHAWSCDR_BKSCD
| DFSDM_CHAWSCDR_SCDT
);
1096 hdfsdm_channel
->Instance
->CHAWSCDR
|= ((BreakSignal
<< DFSDM_CHAWSCDR_BKSCD_Pos
) | \
1099 /* Start short circuit detection */
1100 hdfsdm_channel
->Instance
->CHCFGR1
|= DFSDM_CHCFGR1_SCDEN
;
1102 /* Return function status */
1107 * @brief This function allows to poll for the short circuit detection.
1108 * @param hdfsdm_channel DFSDM channel handle.
1109 * @param Timeout Timeout value in milliseconds.
1110 * @retval HAL status
1112 HAL_StatusTypeDef
HAL_DFSDM_ChannelPollForScd(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
,
1117 DFSDM_Filter_TypeDef
*filter0Instance
;
1119 /* Check parameters */
1120 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1122 #if defined(DFSDM2_Channel0)
1123 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
1125 filter0Instance
= DFSDM1_Filter0
;
1129 filter0Instance
= DFSDM2_Filter0
;
1131 #else /* DFSDM2_Channel0 */
1132 filter0Instance
= DFSDM1_Filter0
;
1133 #endif /* DFSDM2_Channel0 */
1135 /* Check DFSDM channel state */
1136 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1138 /* Return error status */
1143 /* Get channel number from channel instance */
1144 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
1147 tickstart
= HAL_GetTick();
1149 /* Wait short circuit detection */
1150 while (((filter0Instance
->FLTISR
& DFSDM_FLTISR_SCDF
) >> (DFSDM_FLTISR_SCDF_Pos
+ channel
)) == 0U)
1152 /* Check the Timeout */
1153 if(Timeout
!= HAL_MAX_DELAY
)
1155 if(((HAL_GetTick()-tickstart
) > Timeout
) || (Timeout
== 0U))
1157 /* Return timeout status */
1163 /* Clear short circuit detection flag */
1164 filter0Instance
->FLTICR
= (1UL << (DFSDM_FLTICR_CLRSCDF_Pos
+ channel
));
1166 /* Return function status */
1172 * @brief This function allows to stop short circuit detection in polling mode.
1173 * @param hdfsdm_channel DFSDM channel handle.
1174 * @retval HAL status
1176 HAL_StatusTypeDef
HAL_DFSDM_ChannelScdStop(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
1178 HAL_StatusTypeDef status
= HAL_OK
;
1180 DFSDM_Filter_TypeDef
*filter0Instance
;
1182 /* Check parameters */
1183 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1185 #if defined(DFSDM2_Channel0)
1186 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
1188 filter0Instance
= DFSDM1_Filter0
;
1192 filter0Instance
= DFSDM2_Filter0
;
1194 #else /* DFSDM2_Channel0 */
1195 filter0Instance
= DFSDM1_Filter0
;
1196 #endif /* DFSDM2_Channel0 */
1198 /* Check DFSDM channel state */
1199 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1201 /* Return error status */
1206 /* Stop short circuit detection */
1207 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_SCDEN
);
1209 /* Clear short circuit detection flag */
1210 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
1211 filter0Instance
->FLTICR
= (1UL << (DFSDM_FLTICR_CLRSCDF_Pos
+ channel
));
1213 /* Return function status */
1218 * @brief This function allows to start short circuit detection in interrupt mode.
1219 * @note Same mode has to be used for all channels
1220 * @param hdfsdm_channel DFSDM channel handle.
1221 * @param Threshold Short circuit detector threshold.
1222 * This parameter must be a number between Min_Data = 0 and Max_Data = 255.
1223 * @param BreakSignal Break signals assigned to short circuit event.
1224 * This parameter can be a values combination of @ref DFSDM_BreakSignals.
1225 * @retval HAL status
1227 HAL_StatusTypeDef
HAL_DFSDM_ChannelScdStart_IT(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
,
1229 uint32_t BreakSignal
)
1231 HAL_StatusTypeDef status
= HAL_OK
;
1232 DFSDM_Filter_TypeDef
*filter0Instance
;
1234 /* Check parameters */
1235 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1236 assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold
));
1237 assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal
));
1239 #if defined(DFSDM2_Channel0)
1240 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
1242 filter0Instance
= DFSDM1_Filter0
;
1246 filter0Instance
= DFSDM2_Filter0
;
1248 #else /* DFSDM2_Channel0 */
1249 filter0Instance
= DFSDM1_Filter0
;
1250 #endif /* DFSDM2_Channel0 */
1252 /* Check DFSDM channel state */
1253 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1255 /* Return error status */
1260 /* Activate short circuit detection interrupt */
1261 filter0Instance
->FLTCR2
|= DFSDM_FLTCR2_SCDIE
;
1263 /* Configure threshold and break signals */
1264 hdfsdm_channel
->Instance
->CHAWSCDR
&= ~(DFSDM_CHAWSCDR_BKSCD
| DFSDM_CHAWSCDR_SCDT
);
1265 hdfsdm_channel
->Instance
->CHAWSCDR
|= ((BreakSignal
<< DFSDM_CHAWSCDR_BKSCD_Pos
) | \
1268 /* Start short circuit detection */
1269 hdfsdm_channel
->Instance
->CHCFGR1
|= DFSDM_CHCFGR1_SCDEN
;
1271 /* Return function status */
1276 * @brief Short circuit detection callback.
1277 * @param hdfsdm_channel DFSDM channel handle.
1280 __weak
void HAL_DFSDM_ChannelScdCallback(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
1282 /* Prevent unused argument(s) compilation warning */
1283 UNUSED(hdfsdm_channel
);
1285 /* NOTE : This function should not be modified, when the callback is needed,
1286 the HAL_DFSDM_ChannelScdCallback could be implemented in the user file
1291 * @brief This function allows to stop short circuit detection in interrupt mode.
1292 * @note Interrupt will be disabled for all channels
1293 * @param hdfsdm_channel DFSDM channel handle.
1294 * @retval HAL status
1296 HAL_StatusTypeDef
HAL_DFSDM_ChannelScdStop_IT(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
1298 HAL_StatusTypeDef status
= HAL_OK
;
1300 DFSDM_Filter_TypeDef
*filter0Instance
;
1302 /* Check parameters */
1303 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1305 #if defined(DFSDM2_Channel0)
1306 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
1308 filter0Instance
= DFSDM1_Filter0
;
1312 filter0Instance
= DFSDM2_Filter0
;
1314 #else /* DFSDM2_Channel0 */
1315 filter0Instance
= DFSDM1_Filter0
;
1316 #endif /* DFSDM2_Channel0 */
1318 /* Check DFSDM channel state */
1319 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1321 /* Return error status */
1326 /* Stop short circuit detection */
1327 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_SCDEN
);
1329 /* Clear short circuit detection flag */
1330 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
1331 filter0Instance
->FLTICR
= (1UL << (DFSDM_FLTICR_CLRSCDF_Pos
+ channel
));
1333 /* Disable short circuit detection interrupt */
1334 filter0Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_SCDIE
);
1336 /* Return function status */
1341 * @brief This function allows to get channel analog watchdog value.
1342 * @param hdfsdm_channel DFSDM channel handle.
1343 * @retval Channel analog watchdog value.
1345 int16_t HAL_DFSDM_ChannelGetAwdValue(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
1347 return (int16_t) hdfsdm_channel
->Instance
->CHWDATAR
;
1351 * @brief This function allows to modify channel offset value.
1352 * @param hdfsdm_channel DFSDM channel handle.
1353 * @param Offset DFSDM channel offset.
1354 * This parameter must be a number between Min_Data = -8388608 and Max_Data = 8388607.
1355 * @retval HAL status.
1357 HAL_StatusTypeDef
HAL_DFSDM_ChannelModifyOffset(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
,
1360 HAL_StatusTypeDef status
= HAL_OK
;
1362 /* Check parameters */
1363 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1364 assert_param(IS_DFSDM_CHANNEL_OFFSET(Offset
));
1366 /* Check DFSDM channel state */
1367 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1369 /* Return error status */
1374 /* Modify channel offset */
1375 hdfsdm_channel
->Instance
->CHCFGR2
&= ~(DFSDM_CHCFGR2_OFFSET
);
1376 hdfsdm_channel
->Instance
->CHCFGR2
|= ((uint32_t) Offset
<< DFSDM_CHCFGR2_OFFSET_Pos
);
1378 /* Return function status */
1386 /** @defgroup DFSDM_Exported_Functions_Group3_Channel Channel state function
1387 * @brief Channel state function
1390 ==============================================================================
1391 ##### Channel state function #####
1392 ==============================================================================
1393 [..] This section provides function allowing to:
1394 (+) Get channel handle state.
1400 * @brief This function allows to get the current DFSDM channel handle state.
1401 * @param hdfsdm_channel DFSDM channel handle.
1402 * @retval DFSDM channel state.
1404 HAL_DFSDM_Channel_StateTypeDef
HAL_DFSDM_ChannelGetState(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
1406 /* Return DFSDM channel handle state */
1407 return hdfsdm_channel
->State
;
1414 /** @defgroup DFSDM_Exported_Functions_Group1_Filter Filter initialization and de-initialization functions
1415 * @brief Filter initialization and de-initialization functions
1418 ==============================================================================
1419 ##### Filter initialization and de-initialization functions #####
1420 ==============================================================================
1421 [..] This section provides functions allowing to:
1422 (+) Initialize the DFSDM filter.
1423 (+) De-initialize the DFSDM filter.
1429 * @brief Initialize the DFSDM filter according to the specified parameters
1430 * in the DFSDM_FilterInitTypeDef structure and initialize the associated handle.
1431 * @param hdfsdm_filter DFSDM filter handle.
1432 * @retval HAL status.
1434 HAL_StatusTypeDef
HAL_DFSDM_FilterInit(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
1436 const DFSDM_Filter_TypeDef
*filter0Instance
;
1438 /* Check DFSDM Channel handle */
1439 if(hdfsdm_filter
== NULL
)
1444 /* Check parameters */
1445 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1446 assert_param(IS_DFSDM_FILTER_REG_TRIGGER(hdfsdm_filter
->Init
.RegularParam
.Trigger
));
1447 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter
->Init
.RegularParam
.FastMode
));
1448 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter
->Init
.RegularParam
.DmaMode
));
1449 assert_param(IS_DFSDM_FILTER_INJ_TRIGGER(hdfsdm_filter
->Init
.InjectedParam
.Trigger
));
1450 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter
->Init
.InjectedParam
.ScanMode
));
1451 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter
->Init
.InjectedParam
.DmaMode
));
1452 assert_param(IS_DFSDM_FILTER_SINC_ORDER(hdfsdm_filter
->Init
.FilterParam
.SincOrder
));
1453 assert_param(IS_DFSDM_FILTER_OVS_RATIO(hdfsdm_filter
->Init
.FilterParam
.Oversampling
));
1454 assert_param(IS_DFSDM_FILTER_INTEGRATOR_OVS_RATIO(hdfsdm_filter
->Init
.FilterParam
.IntOversampling
));
1456 #if defined(DFSDM2_Channel0)
1457 if (IS_DFSDM1_FILTER_INSTANCE(hdfsdm_filter
->Instance
))
1459 filter0Instance
= DFSDM1_Filter0
;
1463 filter0Instance
= DFSDM2_Filter0
;
1465 #else /* DFSDM2_Channel0 */
1466 filter0Instance
= DFSDM1_Filter0
;
1467 #endif /* DFSDM2_Channel0 */
1469 /* Check parameters compatibility */
1470 if ((hdfsdm_filter
->Instance
== filter0Instance
) &&
1471 ((hdfsdm_filter
->Init
.RegularParam
.Trigger
== DFSDM_FILTER_SYNC_TRIGGER
) ||
1472 (hdfsdm_filter
->Init
.InjectedParam
.Trigger
== DFSDM_FILTER_SYNC_TRIGGER
)))
1477 /* Initialize DFSDM filter variables with default values */
1478 hdfsdm_filter
->RegularContMode
= DFSDM_CONTINUOUS_CONV_OFF
;
1479 hdfsdm_filter
->InjectedChannelsNbr
= 1;
1480 hdfsdm_filter
->InjConvRemaining
= 1;
1481 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_NONE
;
1483 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
1484 /* Reset callback pointers to the weak predefined callbacks */
1485 hdfsdm_filter
->AwdCallback
= HAL_DFSDM_FilterAwdCallback
;
1486 hdfsdm_filter
->RegConvCpltCallback
= HAL_DFSDM_FilterRegConvCpltCallback
;
1487 hdfsdm_filter
->RegConvHalfCpltCallback
= HAL_DFSDM_FilterRegConvHalfCpltCallback
;
1488 hdfsdm_filter
->InjConvCpltCallback
= HAL_DFSDM_FilterInjConvCpltCallback
;
1489 hdfsdm_filter
->InjConvHalfCpltCallback
= HAL_DFSDM_FilterInjConvHalfCpltCallback
;
1490 hdfsdm_filter
->ErrorCallback
= HAL_DFSDM_FilterErrorCallback
;
1492 /* Call MSP init function */
1493 if(hdfsdm_filter
->MspInitCallback
== NULL
)
1495 hdfsdm_filter
->MspInitCallback
= HAL_DFSDM_FilterMspInit
;
1497 hdfsdm_filter
->MspInitCallback(hdfsdm_filter
);
1499 /* Call MSP init function */
1500 HAL_DFSDM_FilterMspInit(hdfsdm_filter
);
1503 /* Set regular parameters */
1504 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_RSYNC
);
1505 if(hdfsdm_filter
->Init
.RegularParam
.FastMode
== ENABLE
)
1507 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_FAST
;
1511 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_FAST
);
1514 if(hdfsdm_filter
->Init
.RegularParam
.DmaMode
== ENABLE
)
1516 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_RDMAEN
;
1520 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_RDMAEN
);
1523 /* Set injected parameters */
1524 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_JSYNC
| DFSDM_FLTCR1_JEXTEN
| DFSDM_FLTCR1_JEXTSEL
);
1525 if(hdfsdm_filter
->Init
.InjectedParam
.Trigger
== DFSDM_FILTER_EXT_TRIGGER
)
1527 assert_param(IS_DFSDM_FILTER_EXT_TRIG(hdfsdm_filter
->Init
.InjectedParam
.ExtTrigger
));
1528 assert_param(IS_DFSDM_FILTER_EXT_TRIG_EDGE(hdfsdm_filter
->Init
.InjectedParam
.ExtTriggerEdge
));
1529 hdfsdm_filter
->Instance
->FLTCR1
|= (hdfsdm_filter
->Init
.InjectedParam
.ExtTrigger
);
1532 if(hdfsdm_filter
->Init
.InjectedParam
.ScanMode
== ENABLE
)
1534 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_JSCAN
;
1538 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_JSCAN
);
1541 if(hdfsdm_filter
->Init
.InjectedParam
.DmaMode
== ENABLE
)
1543 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_JDMAEN
;
1547 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_JDMAEN
);
1550 /* Set filter parameters */
1551 hdfsdm_filter
->Instance
->FLTFCR
&= ~(DFSDM_FLTFCR_FORD
| DFSDM_FLTFCR_FOSR
| DFSDM_FLTFCR_IOSR
);
1552 hdfsdm_filter
->Instance
->FLTFCR
|= (hdfsdm_filter
->Init
.FilterParam
.SincOrder
|
1553 ((hdfsdm_filter
->Init
.FilterParam
.Oversampling
- 1U) << DFSDM_FLTFCR_FOSR_Pos
) |
1554 (hdfsdm_filter
->Init
.FilterParam
.IntOversampling
- 1U));
1556 /* Store regular and injected triggers and injected scan mode*/
1557 hdfsdm_filter
->RegularTrigger
= hdfsdm_filter
->Init
.RegularParam
.Trigger
;
1558 hdfsdm_filter
->InjectedTrigger
= hdfsdm_filter
->Init
.InjectedParam
.Trigger
;
1559 hdfsdm_filter
->ExtTriggerEdge
= hdfsdm_filter
->Init
.InjectedParam
.ExtTriggerEdge
;
1560 hdfsdm_filter
->InjectedScanMode
= hdfsdm_filter
->Init
.InjectedParam
.ScanMode
;
1562 /* Enable DFSDM filter */
1563 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_DFEN
;
1565 /* Set DFSDM filter to ready state */
1566 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_READY
;
1572 * @brief De-initializes the DFSDM filter.
1573 * @param hdfsdm_filter DFSDM filter handle.
1574 * @retval HAL status.
1576 HAL_StatusTypeDef
HAL_DFSDM_FilterDeInit(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
1578 /* Check DFSDM filter handle */
1579 if(hdfsdm_filter
== NULL
)
1584 /* Check parameters */
1585 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1587 /* Disable the DFSDM filter */
1588 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_DFEN
);
1590 /* Call MSP deinit function */
1591 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
1592 if(hdfsdm_filter
->MspDeInitCallback
== NULL
)
1594 hdfsdm_filter
->MspDeInitCallback
= HAL_DFSDM_FilterMspDeInit
;
1596 hdfsdm_filter
->MspDeInitCallback(hdfsdm_filter
);
1598 HAL_DFSDM_FilterMspDeInit(hdfsdm_filter
);
1601 /* Set DFSDM filter in reset state */
1602 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_RESET
;
1608 * @brief Initializes the DFSDM filter MSP.
1609 * @param hdfsdm_filter DFSDM filter handle.
1612 __weak
void HAL_DFSDM_FilterMspInit(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
1614 /* Prevent unused argument(s) compilation warning */
1615 UNUSED(hdfsdm_filter
);
1617 /* NOTE : This function should not be modified, when the function is needed,
1618 the HAL_DFSDM_FilterMspInit could be implemented in the user file.
1623 * @brief De-initializes the DFSDM filter MSP.
1624 * @param hdfsdm_filter DFSDM filter handle.
1627 __weak
void HAL_DFSDM_FilterMspDeInit(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
1629 /* Prevent unused argument(s) compilation warning */
1630 UNUSED(hdfsdm_filter
);
1632 /* NOTE : This function should not be modified, when the function is needed,
1633 the HAL_DFSDM_FilterMspDeInit could be implemented in the user file.
1637 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
1639 * @brief Register a user DFSDM filter callback
1640 * to be used instead of the weak predefined callback.
1641 * @param hdfsdm_filter DFSDM filter handle.
1642 * @param CallbackID ID of the callback to be registered.
1643 * This parameter can be one of the following values:
1644 * @arg @ref HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID regular conversion complete callback ID.
1645 * @arg @ref HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID half regular conversion complete callback ID.
1646 * @arg @ref HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID injected conversion complete callback ID.
1647 * @arg @ref HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID half injected conversion complete callback ID.
1648 * @arg @ref HAL_DFSDM_FILTER_ERROR_CB_ID error callback ID.
1649 * @arg @ref HAL_DFSDM_FILTER_MSPINIT_CB_ID MSP init callback ID.
1650 * @arg @ref HAL_DFSDM_FILTER_MSPDEINIT_CB_ID MSP de-init callback ID.
1651 * @param pCallback pointer to the callback function.
1652 * @retval HAL status.
1654 HAL_StatusTypeDef
HAL_DFSDM_Filter_RegisterCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
1655 HAL_DFSDM_Filter_CallbackIDTypeDef CallbackID
,
1656 pDFSDM_Filter_CallbackTypeDef pCallback
)
1658 HAL_StatusTypeDef status
= HAL_OK
;
1660 if(pCallback
== NULL
)
1662 /* update the error code */
1663 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INVALID_CALLBACK
;
1664 /* update return status */
1669 if(HAL_DFSDM_FILTER_STATE_READY
== hdfsdm_filter
->State
)
1673 case HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID
:
1674 hdfsdm_filter
->RegConvCpltCallback
= pCallback
;
1676 case HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID
:
1677 hdfsdm_filter
->RegConvHalfCpltCallback
= pCallback
;
1679 case HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID
:
1680 hdfsdm_filter
->InjConvCpltCallback
= pCallback
;
1682 case HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID
:
1683 hdfsdm_filter
->InjConvHalfCpltCallback
= pCallback
;
1685 case HAL_DFSDM_FILTER_ERROR_CB_ID
:
1686 hdfsdm_filter
->ErrorCallback
= pCallback
;
1688 case HAL_DFSDM_FILTER_MSPINIT_CB_ID
:
1689 hdfsdm_filter
->MspInitCallback
= pCallback
;
1691 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID
:
1692 hdfsdm_filter
->MspDeInitCallback
= pCallback
;
1695 /* update the error code */
1696 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INVALID_CALLBACK
;
1697 /* update return status */
1702 else if(HAL_DFSDM_FILTER_STATE_RESET
== hdfsdm_filter
->State
)
1706 case HAL_DFSDM_FILTER_MSPINIT_CB_ID
:
1707 hdfsdm_filter
->MspInitCallback
= pCallback
;
1709 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID
:
1710 hdfsdm_filter
->MspDeInitCallback
= pCallback
;
1713 /* update the error code */
1714 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INVALID_CALLBACK
;
1715 /* update return status */
1722 /* update the error code */
1723 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INVALID_CALLBACK
;
1724 /* update return status */
1732 * @brief Unregister a user DFSDM filter callback.
1733 * DFSDM filter callback is redirected to the weak predefined callback.
1734 * @param hdfsdm_filter DFSDM filter handle.
1735 * @param CallbackID ID of the callback to be unregistered.
1736 * This parameter can be one of the following values:
1737 * @arg @ref HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID regular conversion complete callback ID.
1738 * @arg @ref HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID half regular conversion complete callback ID.
1739 * @arg @ref HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID injected conversion complete callback ID.
1740 * @arg @ref HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID half injected conversion complete callback ID.
1741 * @arg @ref HAL_DFSDM_FILTER_ERROR_CB_ID error callback ID.
1742 * @arg @ref HAL_DFSDM_FILTER_MSPINIT_CB_ID MSP init callback ID.
1743 * @arg @ref HAL_DFSDM_FILTER_MSPDEINIT_CB_ID MSP de-init callback ID.
1744 * @retval HAL status.
1746 HAL_StatusTypeDef
HAL_DFSDM_Filter_UnRegisterCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
1747 HAL_DFSDM_Filter_CallbackIDTypeDef CallbackID
)
1749 HAL_StatusTypeDef status
= HAL_OK
;
1751 if(HAL_DFSDM_FILTER_STATE_READY
== hdfsdm_filter
->State
)
1755 case HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID
:
1756 hdfsdm_filter
->RegConvCpltCallback
= HAL_DFSDM_FilterRegConvCpltCallback
;
1758 case HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID
:
1759 hdfsdm_filter
->RegConvHalfCpltCallback
= HAL_DFSDM_FilterRegConvHalfCpltCallback
;
1761 case HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID
:
1762 hdfsdm_filter
->InjConvCpltCallback
= HAL_DFSDM_FilterInjConvCpltCallback
;
1764 case HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID
:
1765 hdfsdm_filter
->InjConvHalfCpltCallback
= HAL_DFSDM_FilterInjConvHalfCpltCallback
;
1767 case HAL_DFSDM_FILTER_ERROR_CB_ID
:
1768 hdfsdm_filter
->ErrorCallback
= HAL_DFSDM_FilterErrorCallback
;
1770 case HAL_DFSDM_FILTER_MSPINIT_CB_ID
:
1771 hdfsdm_filter
->MspInitCallback
= HAL_DFSDM_FilterMspInit
;
1773 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID
:
1774 hdfsdm_filter
->MspDeInitCallback
= HAL_DFSDM_FilterMspDeInit
;
1777 /* update the error code */
1778 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INVALID_CALLBACK
;
1779 /* update return status */
1784 else if(HAL_DFSDM_FILTER_STATE_RESET
== hdfsdm_filter
->State
)
1788 case HAL_DFSDM_FILTER_MSPINIT_CB_ID
:
1789 hdfsdm_filter
->MspInitCallback
= HAL_DFSDM_FilterMspInit
;
1791 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID
:
1792 hdfsdm_filter
->MspDeInitCallback
= HAL_DFSDM_FilterMspDeInit
;
1795 /* update the error code */
1796 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INVALID_CALLBACK
;
1797 /* update return status */
1804 /* update the error code */
1805 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INVALID_CALLBACK
;
1806 /* update return status */
1813 * @brief Register a user DFSDM filter analog watchdog callback
1814 * to be used instead of the weak predefined callback.
1815 * @param hdfsdm_filter DFSDM filter handle.
1816 * @param pCallback pointer to the DFSDM filter analog watchdog callback function.
1817 * @retval HAL status.
1819 HAL_StatusTypeDef
HAL_DFSDM_Filter_RegisterAwdCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
1820 pDFSDM_Filter_AwdCallbackTypeDef pCallback
)
1822 HAL_StatusTypeDef status
= HAL_OK
;
1824 if(pCallback
== NULL
)
1826 /* update the error code */
1827 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INVALID_CALLBACK
;
1828 /* update return status */
1833 if(HAL_DFSDM_FILTER_STATE_READY
== hdfsdm_filter
->State
)
1835 hdfsdm_filter
->AwdCallback
= pCallback
;
1839 /* update the error code */
1840 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INVALID_CALLBACK
;
1841 /* update return status */
1849 * @brief Unregister a user DFSDM filter analog watchdog callback.
1850 * DFSDM filter AWD callback is redirected to the weak predefined callback.
1851 * @param hdfsdm_filter DFSDM filter handle.
1852 * @retval HAL status.
1854 HAL_StatusTypeDef
HAL_DFSDM_Filter_UnRegisterAwdCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
1856 HAL_StatusTypeDef status
= HAL_OK
;
1858 if(HAL_DFSDM_FILTER_STATE_READY
== hdfsdm_filter
->State
)
1860 hdfsdm_filter
->AwdCallback
= HAL_DFSDM_FilterAwdCallback
;
1864 /* update the error code */
1865 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INVALID_CALLBACK
;
1866 /* update return status */
1871 #endif /* USE_HAL_DFSDM_REGISTER_CALLBACKS */
1877 /** @defgroup DFSDM_Exported_Functions_Group2_Filter Filter control functions
1878 * @brief Filter control functions
1881 ==============================================================================
1882 ##### Filter control functions #####
1883 ==============================================================================
1884 [..] This section provides functions allowing to:
1885 (+) Select channel and enable/disable continuous mode for regular conversion.
1886 (+) Select channels for injected conversion.
1892 * @brief This function allows to select channel and to enable/disable
1893 * continuous mode for regular conversion.
1894 * @param hdfsdm_filter DFSDM filter handle.
1895 * @param Channel Channel for regular conversion.
1896 * This parameter can be a value of @ref DFSDM_Channel_Selection.
1897 * @param ContinuousMode Enable/disable continuous mode for regular conversion.
1898 * This parameter can be a value of @ref DFSDM_ContinuousMode.
1899 * @retval HAL status
1901 HAL_StatusTypeDef
HAL_DFSDM_FilterConfigRegChannel(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
1903 uint32_t ContinuousMode
)
1905 HAL_StatusTypeDef status
= HAL_OK
;
1907 /* Check parameters */
1908 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1909 assert_param(IS_DFSDM_REGULAR_CHANNEL(Channel
));
1910 assert_param(IS_DFSDM_CONTINUOUS_MODE(ContinuousMode
));
1912 /* Check DFSDM filter state */
1913 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_RESET
) &&
1914 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_ERROR
))
1916 /* Configure channel and continuous mode for regular conversion */
1917 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_RCH
| DFSDM_FLTCR1_RCONT
);
1918 if(ContinuousMode
== DFSDM_CONTINUOUS_CONV_ON
)
1920 hdfsdm_filter
->Instance
->FLTCR1
|= (uint32_t) (((Channel
& DFSDM_MSB_MASK
) << DFSDM_FLTCR1_MSB_RCH_OFFSET
) |
1921 DFSDM_FLTCR1_RCONT
);
1925 hdfsdm_filter
->Instance
->FLTCR1
|= (uint32_t) ((Channel
& DFSDM_MSB_MASK
) << DFSDM_FLTCR1_MSB_RCH_OFFSET
);
1927 /* Store continuous mode information */
1928 hdfsdm_filter
->RegularContMode
= ContinuousMode
;
1935 /* Return function status */
1940 * @brief This function allows to select channels for injected conversion.
1941 * @param hdfsdm_filter DFSDM filter handle.
1942 * @param Channel Channels for injected conversion.
1943 * This parameter can be a values combination of @ref DFSDM_Channel_Selection.
1944 * @retval HAL status
1946 HAL_StatusTypeDef
HAL_DFSDM_FilterConfigInjChannel(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
1949 HAL_StatusTypeDef status
= HAL_OK
;
1951 /* Check parameters */
1952 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1953 assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel
));
1955 /* Check DFSDM filter state */
1956 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_RESET
) &&
1957 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_ERROR
))
1959 /* Configure channel for injected conversion */
1960 hdfsdm_filter
->Instance
->FLTJCHGR
= (uint32_t) (Channel
& DFSDM_LSB_MASK
);
1961 /* Store number of injected channels */
1962 hdfsdm_filter
->InjectedChannelsNbr
= DFSDM_GetInjChannelsNbr(Channel
);
1963 /* Update number of injected channels remaining */
1964 hdfsdm_filter
->InjConvRemaining
= (hdfsdm_filter
->InjectedScanMode
== ENABLE
) ? \
1965 hdfsdm_filter
->InjectedChannelsNbr
: 1U;
1971 /* Return function status */
1979 /** @defgroup DFSDM_Exported_Functions_Group3_Filter Filter operation functions
1980 * @brief Filter operation functions
1983 ==============================================================================
1984 ##### Filter operation functions #####
1985 ==============================================================================
1986 [..] This section provides functions allowing to:
1987 (+) Start conversion of regular/injected channel.
1988 (+) Poll for the end of regular/injected conversion.
1989 (+) Stop conversion of regular/injected channel.
1990 (+) Start conversion of regular/injected channel and enable interrupt.
1991 (+) Call the callback functions at the end of regular/injected conversions.
1992 (+) Stop conversion of regular/injected channel and disable interrupt.
1993 (+) Start conversion of regular/injected channel and enable DMA transfer.
1994 (+) Stop conversion of regular/injected channel and disable DMA transfer.
1995 (+) Start analog watchdog and enable interrupt.
1996 (+) Call the callback function when analog watchdog occurs.
1997 (+) Stop analog watchdog and disable interrupt.
1998 (+) Start extreme detector.
1999 (+) Stop extreme detector.
2000 (+) Get result of regular channel conversion.
2001 (+) Get result of injected channel conversion.
2002 (+) Get extreme detector maximum and minimum values.
2003 (+) Get conversion time.
2004 (+) Handle DFSDM interrupt request.
2010 * @brief This function allows to start regular conversion in polling mode.
2011 * @note This function should be called only when DFSDM filter instance is
2012 * in idle state or if injected conversion is ongoing.
2013 * @param hdfsdm_filter DFSDM filter handle.
2014 * @retval HAL status
2016 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularStart(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2018 HAL_StatusTypeDef status
= HAL_OK
;
2020 /* Check parameters */
2021 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2023 /* Check DFSDM filter state */
2024 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
2025 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
))
2027 /* Start regular conversion */
2028 DFSDM_RegConvStart(hdfsdm_filter
);
2034 /* Return function status */
2039 * @brief This function allows to poll for the end of regular conversion.
2040 * @note This function should be called only if regular conversion is ongoing.
2041 * @param hdfsdm_filter DFSDM filter handle.
2042 * @param Timeout Timeout value in milliseconds.
2043 * @retval HAL status
2045 HAL_StatusTypeDef
HAL_DFSDM_FilterPollForRegConversion(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2050 /* Check parameters */
2051 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2053 /* Check DFSDM filter state */
2054 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG
) && \
2055 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
2057 /* Return error status */
2063 tickstart
= HAL_GetTick();
2065 /* Wait end of regular conversion */
2066 while((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_REOCF
) != DFSDM_FLTISR_REOCF
)
2068 /* Check the Timeout */
2069 if(Timeout
!= HAL_MAX_DELAY
)
2071 if(((HAL_GetTick() - tickstart
) > Timeout
) || (Timeout
== 0U))
2073 /* Return timeout status */
2078 /* Check if overrun occurs */
2079 if((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_ROVRF
) == DFSDM_FLTISR_ROVRF
)
2081 /* Update error code and call error callback */
2082 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_REGULAR_OVERRUN
;
2083 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
2084 hdfsdm_filter
->ErrorCallback(hdfsdm_filter
);
2086 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter
);
2089 /* Clear regular overrun flag */
2090 hdfsdm_filter
->Instance
->FLTICR
= DFSDM_FLTICR_CLRROVRF
;
2092 /* Update DFSDM filter state only if not continuous conversion and SW trigger */
2093 if((hdfsdm_filter
->RegularContMode
== DFSDM_CONTINUOUS_CONV_OFF
) && \
2094 (hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
))
2096 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
) ? \
2097 HAL_DFSDM_FILTER_STATE_READY
: HAL_DFSDM_FILTER_STATE_INJ
;
2099 /* Return function status */
2105 * @brief This function allows to stop regular conversion in polling mode.
2106 * @note This function should be called only if regular conversion is ongoing.
2107 * @param hdfsdm_filter DFSDM filter handle.
2108 * @retval HAL status
2110 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularStop(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2112 HAL_StatusTypeDef status
= HAL_OK
;
2114 /* Check parameters */
2115 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2117 /* Check DFSDM filter state */
2118 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG
) && \
2119 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
2121 /* Return error status */
2126 /* Stop regular conversion */
2127 DFSDM_RegConvStop(hdfsdm_filter
);
2129 /* Return function status */
2134 * @brief This function allows to start regular conversion in interrupt mode.
2135 * @note This function should be called only when DFSDM filter instance is
2136 * in idle state or if injected conversion is ongoing.
2137 * @param hdfsdm_filter DFSDM filter handle.
2138 * @retval HAL status
2140 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularStart_IT(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2142 HAL_StatusTypeDef status
= HAL_OK
;
2144 /* Check parameters */
2145 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2147 /* Check DFSDM filter state */
2148 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
2149 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
))
2151 /* Enable interrupts for regular conversions */
2152 hdfsdm_filter
->Instance
->FLTCR2
|= (DFSDM_FLTCR2_REOCIE
| DFSDM_FLTCR2_ROVRIE
);
2154 /* Start regular conversion */
2155 DFSDM_RegConvStart(hdfsdm_filter
);
2161 /* Return function status */
2166 * @brief This function allows to stop regular conversion in interrupt mode.
2167 * @note This function should be called only if regular conversion is ongoing.
2168 * @param hdfsdm_filter DFSDM filter handle.
2169 * @retval HAL status
2171 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularStop_IT(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2173 HAL_StatusTypeDef status
= HAL_OK
;
2175 /* Check parameters */
2176 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2178 /* Check DFSDM filter state */
2179 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG
) && \
2180 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
2182 /* Return error status */
2187 /* Disable interrupts for regular conversions */
2188 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_REOCIE
| DFSDM_FLTCR2_ROVRIE
);
2190 /* Stop regular conversion */
2191 DFSDM_RegConvStop(hdfsdm_filter
);
2193 /* Return function status */
2198 * @brief This function allows to start regular conversion in DMA mode.
2199 * @note This function should be called only when DFSDM filter instance is
2200 * in idle state or if injected conversion is ongoing.
2201 * Please note that data on buffer will contain signed regular conversion
2202 * value on 24 most significant bits and corresponding channel on 3 least
2204 * @param hdfsdm_filter DFSDM filter handle.
2205 * @param pData The destination buffer address.
2206 * @param Length The length of data to be transferred from DFSDM filter to memory.
2207 * @retval HAL status
2209 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularStart_DMA(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2213 HAL_StatusTypeDef status
= HAL_OK
;
2215 /* Check parameters */
2216 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2218 /* Check destination address and length */
2219 if((pData
== NULL
) || (Length
== 0U))
2223 /* Check that DMA is enabled for regular conversion */
2224 else if((hdfsdm_filter
->Instance
->FLTCR1
& DFSDM_FLTCR1_RDMAEN
) != DFSDM_FLTCR1_RDMAEN
)
2228 /* Check parameters compatibility */
2229 else if((hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2230 (hdfsdm_filter
->RegularContMode
== DFSDM_CONTINUOUS_CONV_OFF
) && \
2231 (hdfsdm_filter
->hdmaReg
->Init
.Mode
== DMA_NORMAL
) && \
2236 else if((hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2237 (hdfsdm_filter
->RegularContMode
== DFSDM_CONTINUOUS_CONV_OFF
) && \
2238 (hdfsdm_filter
->hdmaReg
->Init
.Mode
== DMA_CIRCULAR
))
2242 /* Check DFSDM filter state */
2243 else if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
2244 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
))
2246 /* Set callbacks on DMA handler */
2247 hdfsdm_filter
->hdmaReg
->XferCpltCallback
= DFSDM_DMARegularConvCplt
;
2248 hdfsdm_filter
->hdmaReg
->XferErrorCallback
= DFSDM_DMAError
;
2249 hdfsdm_filter
->hdmaReg
->XferHalfCpltCallback
= (hdfsdm_filter
->hdmaReg
->Init
.Mode
== DMA_CIRCULAR
) ?\
2250 DFSDM_DMARegularHalfConvCplt
: NULL
;
2252 /* Start DMA in interrupt mode */
2253 if(HAL_DMA_Start_IT(hdfsdm_filter
->hdmaReg
, (uint32_t)&hdfsdm_filter
->Instance
->FLTRDATAR
, \
2254 (uint32_t) pData
, Length
) != HAL_OK
)
2256 /* Set DFSDM filter in error state */
2257 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_ERROR
;
2262 /* Start regular conversion */
2263 DFSDM_RegConvStart(hdfsdm_filter
);
2270 /* Return function status */
2275 * @brief This function allows to start regular conversion in DMA mode and to get
2276 * only the 16 most significant bits of conversion.
2277 * @note This function should be called only when DFSDM filter instance is
2278 * in idle state or if injected conversion is ongoing.
2279 * Please note that data on buffer will contain signed 16 most significant
2280 * bits of regular conversion.
2281 * @param hdfsdm_filter DFSDM filter handle.
2282 * @param pData The destination buffer address.
2283 * @param Length The length of data to be transferred from DFSDM filter to memory.
2284 * @retval HAL status
2286 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularMsbStart_DMA(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2290 HAL_StatusTypeDef status
= HAL_OK
;
2292 /* Check parameters */
2293 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2295 /* Check destination address and length */
2296 if((pData
== NULL
) || (Length
== 0U))
2300 /* Check that DMA is enabled for regular conversion */
2301 else if((hdfsdm_filter
->Instance
->FLTCR1
& DFSDM_FLTCR1_RDMAEN
) != DFSDM_FLTCR1_RDMAEN
)
2305 /* Check parameters compatibility */
2306 else if((hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2307 (hdfsdm_filter
->RegularContMode
== DFSDM_CONTINUOUS_CONV_OFF
) && \
2308 (hdfsdm_filter
->hdmaReg
->Init
.Mode
== DMA_NORMAL
) && \
2313 else if((hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2314 (hdfsdm_filter
->RegularContMode
== DFSDM_CONTINUOUS_CONV_OFF
) && \
2315 (hdfsdm_filter
->hdmaReg
->Init
.Mode
== DMA_CIRCULAR
))
2319 /* Check DFSDM filter state */
2320 else if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
2321 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
))
2323 /* Set callbacks on DMA handler */
2324 hdfsdm_filter
->hdmaReg
->XferCpltCallback
= DFSDM_DMARegularConvCplt
;
2325 hdfsdm_filter
->hdmaReg
->XferErrorCallback
= DFSDM_DMAError
;
2326 hdfsdm_filter
->hdmaReg
->XferHalfCpltCallback
= (hdfsdm_filter
->hdmaReg
->Init
.Mode
== DMA_CIRCULAR
) ?\
2327 DFSDM_DMARegularHalfConvCplt
: NULL
;
2329 /* Start DMA in interrupt mode */
2330 if(HAL_DMA_Start_IT(hdfsdm_filter
->hdmaReg
, (uint32_t)(&hdfsdm_filter
->Instance
->FLTRDATAR
) + 2U, \
2331 (uint32_t) pData
, Length
) != HAL_OK
)
2333 /* Set DFSDM filter in error state */
2334 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_ERROR
;
2339 /* Start regular conversion */
2340 DFSDM_RegConvStart(hdfsdm_filter
);
2347 /* Return function status */
2352 * @brief This function allows to stop regular conversion in DMA mode.
2353 * @note This function should be called only if regular conversion is ongoing.
2354 * @param hdfsdm_filter DFSDM filter handle.
2355 * @retval HAL status
2357 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularStop_DMA(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2359 HAL_StatusTypeDef status
= HAL_OK
;
2361 /* Check parameters */
2362 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2364 /* Check DFSDM filter state */
2365 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG
) && \
2366 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
2368 /* Return error status */
2373 /* Stop current DMA transfer */
2374 if(HAL_DMA_Abort(hdfsdm_filter
->hdmaReg
) != HAL_OK
)
2376 /* Set DFSDM filter in error state */
2377 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_ERROR
;
2382 /* Stop regular conversion */
2383 DFSDM_RegConvStop(hdfsdm_filter
);
2386 /* Return function status */
2391 * @brief This function allows to get regular conversion value.
2392 * @param hdfsdm_filter DFSDM filter handle.
2393 * @param Channel Corresponding channel of regular conversion.
2394 * @retval Regular conversion value
2396 int32_t HAL_DFSDM_FilterGetRegularValue(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2402 /* Check parameters */
2403 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2404 assert_param(Channel
!= (void *)0);
2406 /* Get value of data register for regular channel */
2407 reg
= hdfsdm_filter
->Instance
->FLTRDATAR
;
2409 /* Extract channel and regular conversion value */
2410 *Channel
= (reg
& DFSDM_FLTRDATAR_RDATACH
);
2411 /* Regular conversion value is a signed value located on 24 MSB of register */
2412 /* So after applying a mask on these bits we have to perform a division by 256 (2 raised to the power of 8) */
2413 reg
&= DFSDM_FLTRDATAR_RDATA
;
2414 value
= ((int32_t)reg
) / 256;
2416 /* return regular conversion value */
2421 * @brief This function allows to start injected conversion in polling mode.
2422 * @note This function should be called only when DFSDM filter instance is
2423 * in idle state or if regular conversion is ongoing.
2424 * @param hdfsdm_filter DFSDM filter handle.
2425 * @retval HAL status
2427 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedStart(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2429 HAL_StatusTypeDef status
= HAL_OK
;
2431 /* Check parameters */
2432 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2434 /* Check DFSDM filter state */
2435 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
2436 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
))
2438 /* Start injected conversion */
2439 DFSDM_InjConvStart(hdfsdm_filter
);
2445 /* Return function status */
2450 * @brief This function allows to poll for the end of injected conversion.
2451 * @note This function should be called only if injected conversion is ongoing.
2452 * @param hdfsdm_filter DFSDM filter handle.
2453 * @param Timeout Timeout value in milliseconds.
2454 * @retval HAL status
2456 HAL_StatusTypeDef
HAL_DFSDM_FilterPollForInjConversion(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2461 /* Check parameters */
2462 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2464 /* Check DFSDM filter state */
2465 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_INJ
) && \
2466 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
2468 /* Return error status */
2474 tickstart
= HAL_GetTick();
2476 /* Wait end of injected conversions */
2477 while((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_JEOCF
) != DFSDM_FLTISR_JEOCF
)
2479 /* Check the Timeout */
2480 if(Timeout
!= HAL_MAX_DELAY
)
2482 if(((HAL_GetTick() - tickstart
) > Timeout
) || (Timeout
== 0U))
2484 /* Return timeout status */
2489 /* Check if overrun occurs */
2490 if((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_JOVRF
) == DFSDM_FLTISR_JOVRF
)
2492 /* Update error code and call error callback */
2493 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INJECTED_OVERRUN
;
2494 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
2495 hdfsdm_filter
->ErrorCallback(hdfsdm_filter
);
2497 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter
);
2500 /* Clear injected overrun flag */
2501 hdfsdm_filter
->Instance
->FLTICR
= DFSDM_FLTICR_CLRJOVRF
;
2504 /* Update remaining injected conversions */
2505 hdfsdm_filter
->InjConvRemaining
--;
2506 if(hdfsdm_filter
->InjConvRemaining
== 0U)
2508 /* Update DFSDM filter state only if trigger is software */
2509 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
)
2511 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
) ? \
2512 HAL_DFSDM_FILTER_STATE_READY
: HAL_DFSDM_FILTER_STATE_REG
;
2515 /* end of injected sequence, reset the value */
2516 hdfsdm_filter
->InjConvRemaining
= (hdfsdm_filter
->InjectedScanMode
== ENABLE
) ? \
2517 hdfsdm_filter
->InjectedChannelsNbr
: 1U;
2520 /* Return function status */
2526 * @brief This function allows to stop injected conversion in polling mode.
2527 * @note This function should be called only if injected conversion is ongoing.
2528 * @param hdfsdm_filter DFSDM filter handle.
2529 * @retval HAL status
2531 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedStop(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2533 HAL_StatusTypeDef status
= HAL_OK
;
2535 /* Check parameters */
2536 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2538 /* Check DFSDM filter state */
2539 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_INJ
) && \
2540 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
2542 /* Return error status */
2547 /* Stop injected conversion */
2548 DFSDM_InjConvStop(hdfsdm_filter
);
2550 /* Return function status */
2555 * @brief This function allows to start injected conversion in interrupt mode.
2556 * @note This function should be called only when DFSDM filter instance is
2557 * in idle state or if regular conversion is ongoing.
2558 * @param hdfsdm_filter DFSDM filter handle.
2559 * @retval HAL status
2561 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedStart_IT(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2563 HAL_StatusTypeDef status
= HAL_OK
;
2565 /* Check parameters */
2566 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2568 /* Check DFSDM filter state */
2569 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
2570 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
))
2572 /* Enable interrupts for injected conversions */
2573 hdfsdm_filter
->Instance
->FLTCR2
|= (DFSDM_FLTCR2_JEOCIE
| DFSDM_FLTCR2_JOVRIE
);
2575 /* Start injected conversion */
2576 DFSDM_InjConvStart(hdfsdm_filter
);
2582 /* Return function status */
2587 * @brief This function allows to stop injected conversion in interrupt mode.
2588 * @note This function should be called only if injected conversion is ongoing.
2589 * @param hdfsdm_filter DFSDM filter handle.
2590 * @retval HAL status
2592 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedStop_IT(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2594 HAL_StatusTypeDef status
= HAL_OK
;
2596 /* Check parameters */
2597 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2599 /* Check DFSDM filter state */
2600 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_INJ
) && \
2601 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
2603 /* Return error status */
2608 /* Disable interrupts for injected conversions */
2609 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_JEOCIE
| DFSDM_FLTCR2_JOVRIE
);
2611 /* Stop injected conversion */
2612 DFSDM_InjConvStop(hdfsdm_filter
);
2614 /* Return function status */
2619 * @brief This function allows to start injected conversion in DMA mode.
2620 * @note This function should be called only when DFSDM filter instance is
2621 * in idle state or if regular conversion is ongoing.
2622 * Please note that data on buffer will contain signed injected conversion
2623 * value on 24 most significant bits and corresponding channel on 3 least
2625 * @param hdfsdm_filter DFSDM filter handle.
2626 * @param pData The destination buffer address.
2627 * @param Length The length of data to be transferred from DFSDM filter to memory.
2628 * @retval HAL status
2630 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedStart_DMA(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2634 HAL_StatusTypeDef status
= HAL_OK
;
2636 /* Check parameters */
2637 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2639 /* Check destination address and length */
2640 if((pData
== NULL
) || (Length
== 0U))
2644 /* Check that DMA is enabled for injected conversion */
2645 else if((hdfsdm_filter
->Instance
->FLTCR1
& DFSDM_FLTCR1_JDMAEN
) != DFSDM_FLTCR1_JDMAEN
)
2649 /* Check parameters compatibility */
2650 else if((hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2651 (hdfsdm_filter
->hdmaInj
->Init
.Mode
== DMA_NORMAL
) && \
2652 (Length
> hdfsdm_filter
->InjConvRemaining
))
2656 else if((hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2657 (hdfsdm_filter
->hdmaInj
->Init
.Mode
== DMA_CIRCULAR
))
2661 /* Check DFSDM filter state */
2662 else if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
2663 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
))
2665 /* Set callbacks on DMA handler */
2666 hdfsdm_filter
->hdmaInj
->XferCpltCallback
= DFSDM_DMAInjectedConvCplt
;
2667 hdfsdm_filter
->hdmaInj
->XferErrorCallback
= DFSDM_DMAError
;
2668 hdfsdm_filter
->hdmaInj
->XferHalfCpltCallback
= (hdfsdm_filter
->hdmaInj
->Init
.Mode
== DMA_CIRCULAR
) ?\
2669 DFSDM_DMAInjectedHalfConvCplt
: NULL
;
2671 /* Start DMA in interrupt mode */
2672 if(HAL_DMA_Start_IT(hdfsdm_filter
->hdmaInj
, (uint32_t)&hdfsdm_filter
->Instance
->FLTJDATAR
, \
2673 (uint32_t) pData
, Length
) != HAL_OK
)
2675 /* Set DFSDM filter in error state */
2676 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_ERROR
;
2681 /* Start injected conversion */
2682 DFSDM_InjConvStart(hdfsdm_filter
);
2689 /* Return function status */
2694 * @brief This function allows to start injected conversion in DMA mode and to get
2695 * only the 16 most significant bits of conversion.
2696 * @note This function should be called only when DFSDM filter instance is
2697 * in idle state or if regular conversion is ongoing.
2698 * Please note that data on buffer will contain signed 16 most significant
2699 * bits of injected conversion.
2700 * @param hdfsdm_filter DFSDM filter handle.
2701 * @param pData The destination buffer address.
2702 * @param Length The length of data to be transferred from DFSDM filter to memory.
2703 * @retval HAL status
2705 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedMsbStart_DMA(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2709 HAL_StatusTypeDef status
= HAL_OK
;
2711 /* Check parameters */
2712 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2714 /* Check destination address and length */
2715 if((pData
== NULL
) || (Length
== 0U))
2719 /* Check that DMA is enabled for injected conversion */
2720 else if((hdfsdm_filter
->Instance
->FLTCR1
& DFSDM_FLTCR1_JDMAEN
) != DFSDM_FLTCR1_JDMAEN
)
2724 /* Check parameters compatibility */
2725 else if((hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2726 (hdfsdm_filter
->hdmaInj
->Init
.Mode
== DMA_NORMAL
) && \
2727 (Length
> hdfsdm_filter
->InjConvRemaining
))
2731 else if((hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2732 (hdfsdm_filter
->hdmaInj
->Init
.Mode
== DMA_CIRCULAR
))
2736 /* Check DFSDM filter state */
2737 else if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
2738 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
))
2740 /* Set callbacks on DMA handler */
2741 hdfsdm_filter
->hdmaInj
->XferCpltCallback
= DFSDM_DMAInjectedConvCplt
;
2742 hdfsdm_filter
->hdmaInj
->XferErrorCallback
= DFSDM_DMAError
;
2743 hdfsdm_filter
->hdmaInj
->XferHalfCpltCallback
= (hdfsdm_filter
->hdmaInj
->Init
.Mode
== DMA_CIRCULAR
) ?\
2744 DFSDM_DMAInjectedHalfConvCplt
: NULL
;
2746 /* Start DMA in interrupt mode */
2747 if(HAL_DMA_Start_IT(hdfsdm_filter
->hdmaInj
, (uint32_t)(&hdfsdm_filter
->Instance
->FLTJDATAR
) + 2U, \
2748 (uint32_t) pData
, Length
) != HAL_OK
)
2750 /* Set DFSDM filter in error state */
2751 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_ERROR
;
2756 /* Start injected conversion */
2757 DFSDM_InjConvStart(hdfsdm_filter
);
2764 /* Return function status */
2769 * @brief This function allows to stop injected conversion in DMA mode.
2770 * @note This function should be called only if injected conversion is ongoing.
2771 * @param hdfsdm_filter DFSDM filter handle.
2772 * @retval HAL status
2774 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedStop_DMA(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2776 HAL_StatusTypeDef status
= HAL_OK
;
2778 /* Check parameters */
2779 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2781 /* Check DFSDM filter state */
2782 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_INJ
) && \
2783 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
2785 /* Return error status */
2790 /* Stop current DMA transfer */
2791 if(HAL_DMA_Abort(hdfsdm_filter
->hdmaInj
) != HAL_OK
)
2793 /* Set DFSDM filter in error state */
2794 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_ERROR
;
2799 /* Stop regular conversion */
2800 DFSDM_InjConvStop(hdfsdm_filter
);
2803 /* Return function status */
2808 * @brief This function allows to get injected conversion value.
2809 * @param hdfsdm_filter DFSDM filter handle.
2810 * @param Channel Corresponding channel of injected conversion.
2811 * @retval Injected conversion value
2813 int32_t HAL_DFSDM_FilterGetInjectedValue(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2819 /* Check parameters */
2820 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2821 assert_param(Channel
!= (void *)0);
2823 /* Get value of data register for injected channel */
2824 reg
= hdfsdm_filter
->Instance
->FLTJDATAR
;
2826 /* Extract channel and injected conversion value */
2827 *Channel
= (reg
& DFSDM_FLTJDATAR_JDATACH
);
2828 /* Injected conversion value is a signed value located on 24 MSB of register */
2829 /* So after applying a mask on these bits we have to perform a division by 256 (2 raised to the power of 8) */
2830 reg
&= DFSDM_FLTJDATAR_JDATA
;
2831 value
= ((int32_t)reg
) / 256;
2833 /* return regular conversion value */
2838 * @brief This function allows to start filter analog watchdog in interrupt mode.
2839 * @param hdfsdm_filter DFSDM filter handle.
2840 * @param awdParam DFSDM filter analog watchdog parameters.
2841 * @retval HAL status
2843 HAL_StatusTypeDef
HAL_DFSDM_FilterAwdStart_IT(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2844 DFSDM_Filter_AwdParamTypeDef
*awdParam
)
2846 HAL_StatusTypeDef status
= HAL_OK
;
2848 /* Check parameters */
2849 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2850 assert_param(IS_DFSDM_FILTER_AWD_DATA_SOURCE(awdParam
->DataSource
));
2851 assert_param(IS_DFSDM_INJECTED_CHANNEL(awdParam
->Channel
));
2852 assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam
->HighThreshold
));
2853 assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam
->LowThreshold
));
2854 assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam
->HighBreakSignal
));
2855 assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam
->LowBreakSignal
));
2857 /* Check DFSDM filter state */
2858 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_RESET
) || \
2859 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_ERROR
))
2861 /* Return error status */
2866 /* Set analog watchdog data source */
2867 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_AWFSEL
);
2868 hdfsdm_filter
->Instance
->FLTCR1
|= awdParam
->DataSource
;
2870 /* Set thresholds and break signals */
2871 hdfsdm_filter
->Instance
->FLTAWHTR
&= ~(DFSDM_FLTAWHTR_AWHT
| DFSDM_FLTAWHTR_BKAWH
);
2872 hdfsdm_filter
->Instance
->FLTAWHTR
|= (((uint32_t) awdParam
->HighThreshold
<< DFSDM_FLTAWHTR_AWHT_Pos
) | \
2873 awdParam
->HighBreakSignal
);
2874 hdfsdm_filter
->Instance
->FLTAWLTR
&= ~(DFSDM_FLTAWLTR_AWLT
| DFSDM_FLTAWLTR_BKAWL
);
2875 hdfsdm_filter
->Instance
->FLTAWLTR
|= (((uint32_t) awdParam
->LowThreshold
<< DFSDM_FLTAWLTR_AWLT_Pos
) | \
2876 awdParam
->LowBreakSignal
);
2878 /* Set channels and interrupt for analog watchdog */
2879 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_AWDCH
);
2880 hdfsdm_filter
->Instance
->FLTCR2
|= (((awdParam
->Channel
& DFSDM_LSB_MASK
) << DFSDM_FLTCR2_AWDCH_Pos
) | \
2881 DFSDM_FLTCR2_AWDIE
);
2883 /* Return function status */
2888 * @brief This function allows to stop filter analog watchdog in interrupt mode.
2889 * @param hdfsdm_filter DFSDM filter handle.
2890 * @retval HAL status
2892 HAL_StatusTypeDef
HAL_DFSDM_FilterAwdStop_IT(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2894 HAL_StatusTypeDef status
= HAL_OK
;
2896 /* Check parameters */
2897 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2899 /* Check DFSDM filter state */
2900 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_RESET
) || \
2901 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_ERROR
))
2903 /* Return error status */
2908 /* Reset channels for analog watchdog and deactivate interrupt */
2909 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_AWDCH
| DFSDM_FLTCR2_AWDIE
);
2911 /* Clear all analog watchdog flags */
2912 hdfsdm_filter
->Instance
->FLTAWCFR
= (DFSDM_FLTAWCFR_CLRAWHTF
| DFSDM_FLTAWCFR_CLRAWLTF
);
2914 /* Reset thresholds and break signals */
2915 hdfsdm_filter
->Instance
->FLTAWHTR
&= ~(DFSDM_FLTAWHTR_AWHT
| DFSDM_FLTAWHTR_BKAWH
);
2916 hdfsdm_filter
->Instance
->FLTAWLTR
&= ~(DFSDM_FLTAWLTR_AWLT
| DFSDM_FLTAWLTR_BKAWL
);
2918 /* Reset analog watchdog data source */
2919 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_AWFSEL
);
2921 /* Return function status */
2926 * @brief This function allows to start extreme detector feature.
2927 * @param hdfsdm_filter DFSDM filter handle.
2928 * @param Channel Channels where extreme detector is enabled.
2929 * This parameter can be a values combination of @ref DFSDM_Channel_Selection.
2930 * @retval HAL status
2932 HAL_StatusTypeDef
HAL_DFSDM_FilterExdStart(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2935 HAL_StatusTypeDef status
= HAL_OK
;
2937 /* Check parameters */
2938 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2939 assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel
));
2941 /* Check DFSDM filter state */
2942 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_RESET
) || \
2943 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_ERROR
))
2945 /* Return error status */
2950 /* Set channels for extreme detector */
2951 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_EXCH
);
2952 hdfsdm_filter
->Instance
->FLTCR2
|= ((Channel
& DFSDM_LSB_MASK
) << DFSDM_FLTCR2_EXCH_Pos
);
2954 /* Return function status */
2959 * @brief This function allows to stop extreme detector feature.
2960 * @param hdfsdm_filter DFSDM filter handle.
2961 * @retval HAL status
2963 HAL_StatusTypeDef
HAL_DFSDM_FilterExdStop(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2965 HAL_StatusTypeDef status
= HAL_OK
;
2969 /* Check parameters */
2970 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2972 /* Check DFSDM filter state */
2973 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_RESET
) || \
2974 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_ERROR
))
2976 /* Return error status */
2981 /* Reset channels for extreme detector */
2982 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_EXCH
);
2984 /* Clear extreme detector values */
2985 reg1
= hdfsdm_filter
->Instance
->FLTEXMAX
;
2986 reg2
= hdfsdm_filter
->Instance
->FLTEXMIN
;
2987 UNUSED(reg1
); /* To avoid GCC warning */
2988 UNUSED(reg2
); /* To avoid GCC warning */
2990 /* Return function status */
2995 * @brief This function allows to get extreme detector maximum value.
2996 * @param hdfsdm_filter DFSDM filter handle.
2997 * @param Channel Corresponding channel.
2998 * @retval Extreme detector maximum value
2999 * This value is between Min_Data = -8388608 and Max_Data = 8388607.
3001 int32_t HAL_DFSDM_FilterGetExdMaxValue(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
3007 /* Check parameters */
3008 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
3009 assert_param(Channel
!= (void *)0);
3011 /* Get value of extreme detector maximum register */
3012 reg
= hdfsdm_filter
->Instance
->FLTEXMAX
;
3014 /* Extract channel and extreme detector maximum value */
3015 *Channel
= (reg
& DFSDM_FLTEXMAX_EXMAXCH
);
3016 /* Extreme detector maximum value is a signed value located on 24 MSB of register */
3017 /* So after applying a mask on these bits we have to perform a division by 256 (2 raised to the power of 8) */
3018 reg
&= DFSDM_FLTEXMAX_EXMAX
;
3019 value
= ((int32_t)reg
) / 256;
3021 /* return extreme detector maximum value */
3026 * @brief This function allows to get extreme detector minimum value.
3027 * @param hdfsdm_filter DFSDM filter handle.
3028 * @param Channel Corresponding channel.
3029 * @retval Extreme detector minimum value
3030 * This value is between Min_Data = -8388608 and Max_Data = 8388607.
3032 int32_t HAL_DFSDM_FilterGetExdMinValue(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
3038 /* Check parameters */
3039 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
3040 assert_param(Channel
!= (void *)0);
3042 /* Get value of extreme detector minimum register */
3043 reg
= hdfsdm_filter
->Instance
->FLTEXMIN
;
3045 /* Extract channel and extreme detector minimum value */
3046 *Channel
= (reg
& DFSDM_FLTEXMIN_EXMINCH
);
3047 /* Extreme detector minimum value is a signed value located on 24 MSB of register */
3048 /* So after applying a mask on these bits we have to perform a division by 256 (2 raised to the power of 8) */
3049 reg
&= DFSDM_FLTEXMIN_EXMIN
;
3050 value
= ((int32_t)reg
) / 256;
3052 /* return extreme detector minimum value */
3057 * @brief This function allows to get conversion time value.
3058 * @param hdfsdm_filter DFSDM filter handle.
3059 * @retval Conversion time value
3060 * @note To get time in second, this value has to be divided by DFSDM clock frequency.
3062 uint32_t HAL_DFSDM_FilterGetConvTimeValue(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3067 /* Check parameters */
3068 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
3070 /* Get value of conversion timer register */
3071 reg
= hdfsdm_filter
->Instance
->FLTCNVTIMR
;
3073 /* Extract conversion time value */
3074 value
= ((reg
& DFSDM_FLTCNVTIMR_CNVCNT
) >> DFSDM_FLTCNVTIMR_CNVCNT_Pos
);
3076 /* return extreme detector minimum value */
3081 * @brief This function handles the DFSDM interrupts.
3082 * @param hdfsdm_filter DFSDM filter handle.
3085 void HAL_DFSDM_IRQHandler(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3087 DFSDM_Channel_HandleTypeDef
**channelHandleTable
;
3088 const DFSDM_Filter_TypeDef
*filter0Instance
;
3089 uint32_t channelNumber
;
3091 /* Get FTLISR and FLTCR2 register values */
3092 const uint32_t temp_fltisr
= hdfsdm_filter
->Instance
->FLTISR
;
3093 const uint32_t temp_fltcr2
= hdfsdm_filter
->Instance
->FLTCR2
;
3095 #if defined(DFSDM2_Channel0)
3096 if (IS_DFSDM1_FILTER_INSTANCE(hdfsdm_filter
->Instance
))
3098 channelHandleTable
= a_dfsdm1ChannelHandle
;
3099 filter0Instance
= DFSDM1_Filter0
;
3100 channelNumber
= DFSDM1_CHANNEL_NUMBER
;
3104 channelHandleTable
= a_dfsdm2ChannelHandle
;
3105 filter0Instance
= DFSDM2_Filter0
;
3106 channelNumber
= DFSDM2_CHANNEL_NUMBER
;
3108 #else /* DFSDM2_Channel0 */
3109 channelHandleTable
= a_dfsdm1ChannelHandle
;
3110 filter0Instance
= DFSDM1_Filter0
;
3111 channelNumber
= DFSDM1_CHANNEL_NUMBER
;
3112 #endif /* DFSDM2_Channel0 */
3114 /* Check if overrun occurs during regular conversion */
3115 if(((temp_fltisr
& DFSDM_FLTISR_ROVRF
) != 0U) && \
3116 ((temp_fltcr2
& DFSDM_FLTCR2_ROVRIE
) != 0U))
3118 /* Clear regular overrun flag */
3119 hdfsdm_filter
->Instance
->FLTICR
= DFSDM_FLTICR_CLRROVRF
;
3121 /* Update error code */
3122 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_REGULAR_OVERRUN
;
3124 /* Call error callback */
3125 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3126 hdfsdm_filter
->ErrorCallback(hdfsdm_filter
);
3128 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter
);
3131 /* Check if overrun occurs during injected conversion */
3132 else if(((temp_fltisr
& DFSDM_FLTISR_JOVRF
) != 0U) && \
3133 ((temp_fltcr2
& DFSDM_FLTCR2_JOVRIE
) != 0U))
3135 /* Clear injected overrun flag */
3136 hdfsdm_filter
->Instance
->FLTICR
= DFSDM_FLTICR_CLRJOVRF
;
3138 /* Update error code */
3139 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INJECTED_OVERRUN
;
3141 /* Call error callback */
3142 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3143 hdfsdm_filter
->ErrorCallback(hdfsdm_filter
);
3145 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter
);
3148 /* Check if end of regular conversion */
3149 else if(((temp_fltisr
& DFSDM_FLTISR_REOCF
) != 0U) && \
3150 ((temp_fltcr2
& DFSDM_FLTCR2_REOCIE
) != 0U))
3152 /* Call regular conversion complete callback */
3153 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3154 hdfsdm_filter
->RegConvCpltCallback(hdfsdm_filter
);
3156 HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter
);
3159 /* End of conversion if mode is not continuous and software trigger */
3160 if((hdfsdm_filter
->RegularContMode
== DFSDM_CONTINUOUS_CONV_OFF
) && \
3161 (hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
))
3163 /* Disable interrupts for regular conversions */
3164 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_REOCIE
);
3166 /* Update DFSDM filter state */
3167 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
) ? \
3168 HAL_DFSDM_FILTER_STATE_READY
: HAL_DFSDM_FILTER_STATE_INJ
;
3171 /* Check if end of injected conversion */
3172 else if(((temp_fltisr
& DFSDM_FLTISR_JEOCF
) != 0U) && \
3173 ((temp_fltcr2
& DFSDM_FLTCR2_JEOCIE
) != 0U))
3175 /* Call injected conversion complete callback */
3176 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3177 hdfsdm_filter
->InjConvCpltCallback(hdfsdm_filter
);
3179 HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter
);
3182 /* Update remaining injected conversions */
3183 hdfsdm_filter
->InjConvRemaining
--;
3184 if(hdfsdm_filter
->InjConvRemaining
== 0U)
3186 /* End of conversion if trigger is software */
3187 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
)
3189 /* Disable interrupts for injected conversions */
3190 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_JEOCIE
);
3192 /* Update DFSDM filter state */
3193 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
) ? \
3194 HAL_DFSDM_FILTER_STATE_READY
: HAL_DFSDM_FILTER_STATE_REG
;
3196 /* end of injected sequence, reset the value */
3197 hdfsdm_filter
->InjConvRemaining
= (hdfsdm_filter
->InjectedScanMode
== ENABLE
) ? \
3198 hdfsdm_filter
->InjectedChannelsNbr
: 1U;
3201 /* Check if analog watchdog occurs */
3202 else if(((temp_fltisr
& DFSDM_FLTISR_AWDF
) != 0U) && \
3203 ((temp_fltcr2
& DFSDM_FLTCR2_AWDIE
) != 0U))
3207 uint32_t channel
= 0;
3209 /* Get channel and threshold */
3210 reg
= hdfsdm_filter
->Instance
->FLTAWSR
;
3211 threshold
= ((reg
& DFSDM_FLTAWSR_AWLTF
) != 0U) ? DFSDM_AWD_LOW_THRESHOLD
: DFSDM_AWD_HIGH_THRESHOLD
;
3212 if(threshold
== DFSDM_AWD_HIGH_THRESHOLD
)
3214 reg
= reg
>> DFSDM_FLTAWSR_AWHTF_Pos
;
3216 while (((reg
& 1U) == 0U) && (channel
< (channelNumber
- 1U)))
3221 /* Clear analog watchdog flag */
3222 hdfsdm_filter
->Instance
->FLTAWCFR
= (threshold
== DFSDM_AWD_HIGH_THRESHOLD
) ? \
3223 (1UL << (DFSDM_FLTAWSR_AWHTF_Pos
+ channel
)) : \
3226 /* Call analog watchdog callback */
3227 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3228 hdfsdm_filter
->AwdCallback(hdfsdm_filter
, channel
, threshold
);
3230 HAL_DFSDM_FilterAwdCallback(hdfsdm_filter
, channel
, threshold
);
3233 /* Check if clock absence occurs */
3234 else if((hdfsdm_filter
->Instance
== filter0Instance
) && \
3235 ((temp_fltisr
& DFSDM_FLTISR_CKABF
) != 0U) && \
3236 ((temp_fltcr2
& DFSDM_FLTCR2_CKABIE
) != 0U))
3239 uint32_t channel
= 0;
3241 reg
= ((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_CKABF
) >> DFSDM_FLTISR_CKABF_Pos
);
3243 while (channel
< channelNumber
)
3245 /* Check if flag is set and corresponding channel is enabled */
3246 if (((reg
& 1U) != 0U) && (channelHandleTable
[channel
] != NULL
))
3248 /* Check clock absence has been enabled for this channel */
3249 if ((channelHandleTable
[channel
]->Instance
->CHCFGR1
& DFSDM_CHCFGR1_CKABEN
) != 0U)
3251 /* Clear clock absence flag */
3252 hdfsdm_filter
->Instance
->FLTICR
= (1UL << (DFSDM_FLTICR_CLRCKABF_Pos
+ channel
));
3254 /* Call clock absence callback */
3255 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3256 channelHandleTable
[channel
]->CkabCallback(channelHandleTable
[channel
]);
3258 HAL_DFSDM_ChannelCkabCallback(channelHandleTable
[channel
]);
3266 /* Check if short circuit detection occurs */
3267 else if((hdfsdm_filter
->Instance
== filter0Instance
) && \
3268 ((temp_fltisr
& DFSDM_FLTISR_SCDF
) != 0U) && \
3269 ((temp_fltcr2
& DFSDM_FLTCR2_SCDIE
) != 0U))
3272 uint32_t channel
= 0;
3275 reg
= ((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_SCDF
) >> DFSDM_FLTISR_SCDF_Pos
);
3276 while (((reg
& 1U) == 0U) && (channel
< (channelNumber
- 1U)))
3282 /* Clear short circuit detection flag */
3283 hdfsdm_filter
->Instance
->FLTICR
= (1UL << (DFSDM_FLTICR_CLRSCDF_Pos
+ channel
));
3285 /* Call short circuit detection callback */
3286 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3287 channelHandleTable
[channel
]->ScdCallback(channelHandleTable
[channel
]);
3289 HAL_DFSDM_ChannelScdCallback(channelHandleTable
[channel
]);
3295 * @brief Regular conversion complete callback.
3296 * @note In interrupt mode, user has to read conversion value in this function
3297 * using HAL_DFSDM_FilterGetRegularValue.
3298 * @param hdfsdm_filter DFSDM filter handle.
3301 __weak
void HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3303 /* Prevent unused argument(s) compilation warning */
3304 UNUSED(hdfsdm_filter
);
3306 /* NOTE : This function should not be modified, when the callback is needed,
3307 the HAL_DFSDM_FilterRegConvCpltCallback could be implemented in the user file.
3312 * @brief Half regular conversion complete callback.
3313 * @param hdfsdm_filter DFSDM filter handle.
3316 __weak
void HAL_DFSDM_FilterRegConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3318 /* Prevent unused argument(s) compilation warning */
3319 UNUSED(hdfsdm_filter
);
3321 /* NOTE : This function should not be modified, when the callback is needed,
3322 the HAL_DFSDM_FilterRegConvHalfCpltCallback could be implemented in the user file.
3327 * @brief Injected conversion complete callback.
3328 * @note In interrupt mode, user has to read conversion value in this function
3329 * using HAL_DFSDM_FilterGetInjectedValue.
3330 * @param hdfsdm_filter DFSDM filter handle.
3333 __weak
void HAL_DFSDM_FilterInjConvCpltCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3335 /* Prevent unused argument(s) compilation warning */
3336 UNUSED(hdfsdm_filter
);
3338 /* NOTE : This function should not be modified, when the callback is needed,
3339 the HAL_DFSDM_FilterInjConvCpltCallback could be implemented in the user file.
3344 * @brief Half injected conversion complete callback.
3345 * @param hdfsdm_filter DFSDM filter handle.
3348 __weak
void HAL_DFSDM_FilterInjConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3350 /* Prevent unused argument(s) compilation warning */
3351 UNUSED(hdfsdm_filter
);
3353 /* NOTE : This function should not be modified, when the callback is needed,
3354 the HAL_DFSDM_FilterInjConvHalfCpltCallback could be implemented in the user file.
3359 * @brief Filter analog watchdog callback.
3360 * @param hdfsdm_filter DFSDM filter handle.
3361 * @param Channel Corresponding channel.
3362 * @param Threshold Low or high threshold has been reached.
3365 __weak
void HAL_DFSDM_FilterAwdCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
3366 uint32_t Channel
, uint32_t Threshold
)
3368 /* Prevent unused argument(s) compilation warning */
3369 UNUSED(hdfsdm_filter
);
3373 /* NOTE : This function should not be modified, when the callback is needed,
3374 the HAL_DFSDM_FilterAwdCallback could be implemented in the user file.
3379 * @brief Error callback.
3380 * @param hdfsdm_filter DFSDM filter handle.
3383 __weak
void HAL_DFSDM_FilterErrorCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3385 /* Prevent unused argument(s) compilation warning */
3386 UNUSED(hdfsdm_filter
);
3388 /* NOTE : This function should not be modified, when the callback is needed,
3389 the HAL_DFSDM_FilterErrorCallback could be implemented in the user file.
3397 /** @defgroup DFSDM_Exported_Functions_Group4_Filter Filter state functions
3398 * @brief Filter state functions
3401 ==============================================================================
3402 ##### Filter state functions #####
3403 ==============================================================================
3404 [..] This section provides functions allowing to:
3405 (+) Get the DFSDM filter state.
3406 (+) Get the DFSDM filter error.
3412 * @brief This function allows to get the current DFSDM filter handle state.
3413 * @param hdfsdm_filter DFSDM filter handle.
3414 * @retval DFSDM filter state.
3416 HAL_DFSDM_Filter_StateTypeDef
HAL_DFSDM_FilterGetState(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3418 /* Return DFSDM filter handle state */
3419 return hdfsdm_filter
->State
;
3423 * @brief This function allows to get the current DFSDM filter error.
3424 * @param hdfsdm_filter DFSDM filter handle.
3425 * @retval DFSDM filter error code.
3427 uint32_t HAL_DFSDM_FilterGetError(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3429 return hdfsdm_filter
->ErrorCode
;
3439 /* End of exported functions -------------------------------------------------*/
3441 /* Private functions ---------------------------------------------------------*/
3442 /** @addtogroup DFSDM_Private_Functions DFSDM Private Functions
3447 * @brief DMA half transfer complete callback for regular conversion.
3448 * @param hdma DMA handle.
3451 static void DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef
*hdma
)
3453 /* Get DFSDM filter handle */
3454 DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
= (DFSDM_Filter_HandleTypeDef
*) ((DMA_HandleTypeDef
*)hdma
)->Parent
;
3456 /* Call regular half conversion complete callback */
3457 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3458 hdfsdm_filter
->RegConvHalfCpltCallback(hdfsdm_filter
);
3460 HAL_DFSDM_FilterRegConvHalfCpltCallback(hdfsdm_filter
);
3465 * @brief DMA transfer complete callback for regular conversion.
3466 * @param hdma DMA handle.
3469 static void DFSDM_DMARegularConvCplt(DMA_HandleTypeDef
*hdma
)
3471 /* Get DFSDM filter handle */
3472 DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
= (DFSDM_Filter_HandleTypeDef
*) ((DMA_HandleTypeDef
*)hdma
)->Parent
;
3474 /* Call regular conversion complete callback */
3475 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3476 hdfsdm_filter
->RegConvCpltCallback(hdfsdm_filter
);
3478 HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter
);
3483 * @brief DMA half transfer complete callback for injected conversion.
3484 * @param hdma DMA handle.
3487 static void DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef
*hdma
)
3489 /* Get DFSDM filter handle */
3490 DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
= (DFSDM_Filter_HandleTypeDef
*) ((DMA_HandleTypeDef
*)hdma
)->Parent
;
3492 /* Call injected half conversion complete callback */
3493 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3494 hdfsdm_filter
->InjConvHalfCpltCallback(hdfsdm_filter
);
3496 HAL_DFSDM_FilterInjConvHalfCpltCallback(hdfsdm_filter
);
3501 * @brief DMA transfer complete callback for injected conversion.
3502 * @param hdma DMA handle.
3505 static void DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef
*hdma
)
3507 /* Get DFSDM filter handle */
3508 DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
= (DFSDM_Filter_HandleTypeDef
*) ((DMA_HandleTypeDef
*)hdma
)->Parent
;
3510 /* Call injected conversion complete callback */
3511 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3512 hdfsdm_filter
->InjConvCpltCallback(hdfsdm_filter
);
3514 HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter
);
3519 * @brief DMA error callback.
3520 * @param hdma DMA handle.
3523 static void DFSDM_DMAError(DMA_HandleTypeDef
*hdma
)
3525 /* Get DFSDM filter handle */
3526 DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
= (DFSDM_Filter_HandleTypeDef
*) ((DMA_HandleTypeDef
*)hdma
)->Parent
;
3528 /* Update error code */
3529 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_DMA
;
3531 /* Call error callback */
3532 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3533 hdfsdm_filter
->ErrorCallback(hdfsdm_filter
);
3535 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter
);
3540 * @brief This function allows to get the number of injected channels.
3541 * @param Channels bitfield of injected channels.
3542 * @retval Number of injected channels.
3544 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels
)
3546 uint32_t nbChannels
= 0;
3549 /* Get the number of channels from bitfield */
3550 tmp
= (uint32_t)(Channels
& DFSDM_LSB_MASK
);
3553 if((tmp
& 1U) != 0U)
3557 tmp
= (uint32_t)(tmp
>> 1);
3563 * @brief This function allows to get the channel number from channel instance.
3564 * @param Instance DFSDM channel instance.
3565 * @retval Channel number.
3567 static uint32_t DFSDM_GetChannelFromInstance(const DFSDM_Channel_TypeDef
* Instance
)
3571 /* Get channel from instance */
3572 if(Instance
== DFSDM1_Channel0
)
3576 #if defined(DFSDM2_Channel0)
3577 else if (Instance
== DFSDM2_Channel0
)
3581 else if (Instance
== DFSDM2_Channel1
)
3585 #endif /* DFSDM2_Channel0 */
3586 else if(Instance
== DFSDM1_Channel1
)
3590 else if(Instance
== DFSDM1_Channel2
)
3594 else if(Instance
== DFSDM1_Channel3
)
3598 else if(Instance
== DFSDM1_Channel4
)
3602 else if(Instance
== DFSDM1_Channel5
)
3606 else if(Instance
== DFSDM1_Channel6
)
3610 else /* DFSDM1_Channel7 */
3619 * @brief This function allows to really start regular conversion.
3620 * @param hdfsdm_filter DFSDM filter handle.
3623 static void DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3625 /* Check regular trigger */
3626 if(hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
)
3628 /* Software start of regular conversion */
3629 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_RSWSTART
;
3631 else /* synchronous trigger */
3633 /* Disable DFSDM filter */
3634 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_DFEN
);
3636 /* Set RSYNC bit in DFSDM_FLTCR1 register */
3637 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_RSYNC
;
3639 /* Enable DFSDM filter */
3640 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_DFEN
;
3642 /* If injected conversion was in progress, restart it */
3643 if(hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
)
3645 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
)
3647 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_JSWSTART
;
3649 /* Update remaining injected conversions */
3650 hdfsdm_filter
->InjConvRemaining
= (hdfsdm_filter
->InjectedScanMode
== ENABLE
) ? \
3651 hdfsdm_filter
->InjectedChannelsNbr
: 1U;
3654 /* Update DFSDM filter state */
3655 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) ? \
3656 HAL_DFSDM_FILTER_STATE_REG
: HAL_DFSDM_FILTER_STATE_REG_INJ
;
3660 * @brief This function allows to really stop regular conversion.
3661 * @param hdfsdm_filter DFSDM filter handle.
3664 static void DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3666 /* Disable DFSDM filter */
3667 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_DFEN
);
3669 /* If regular trigger was synchronous, reset RSYNC bit in DFSDM_FLTCR1 register */
3670 if(hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SYNC_TRIGGER
)
3672 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_RSYNC
);
3675 /* Enable DFSDM filter */
3676 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_DFEN
;
3678 /* If injected conversion was in progress, restart it */
3679 if(hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG_INJ
)
3681 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
)
3683 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_JSWSTART
;
3685 /* Update remaining injected conversions */
3686 hdfsdm_filter
->InjConvRemaining
= (hdfsdm_filter
->InjectedScanMode
== ENABLE
) ? \
3687 hdfsdm_filter
->InjectedChannelsNbr
: 1U;
3690 /* Update DFSDM filter state */
3691 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
) ? \
3692 HAL_DFSDM_FILTER_STATE_READY
: HAL_DFSDM_FILTER_STATE_INJ
;
3696 * @brief This function allows to really start injected conversion.
3697 * @param hdfsdm_filter DFSDM filter handle.
3700 static void DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3702 /* Check injected trigger */
3703 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
)
3705 /* Software start of injected conversion */
3706 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_JSWSTART
;
3708 else /* external or synchronous trigger */
3710 /* Disable DFSDM filter */
3711 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_DFEN
);
3713 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SYNC_TRIGGER
)
3715 /* Set JSYNC bit in DFSDM_FLTCR1 register */
3716 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_JSYNC
;
3718 else /* external trigger */
3720 /* Set JEXTEN[1:0] bits in DFSDM_FLTCR1 register */
3721 hdfsdm_filter
->Instance
->FLTCR1
|= hdfsdm_filter
->ExtTriggerEdge
;
3724 /* Enable DFSDM filter */
3725 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_DFEN
;
3727 /* If regular conversion was in progress, restart it */
3728 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
) && \
3729 (hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
))
3731 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_RSWSTART
;
3734 /* Update DFSDM filter state */
3735 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) ? \
3736 HAL_DFSDM_FILTER_STATE_INJ
: HAL_DFSDM_FILTER_STATE_REG_INJ
;
3740 * @brief This function allows to really stop injected conversion.
3741 * @param hdfsdm_filter DFSDM filter handle.
3744 static void DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3746 /* Disable DFSDM filter */
3747 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_DFEN
);
3749 /* If injected trigger was synchronous, reset JSYNC bit in DFSDM_FLTCR1 register */
3750 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SYNC_TRIGGER
)
3752 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_JSYNC
);
3754 else if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_EXT_TRIGGER
)
3756 /* Reset JEXTEN[1:0] bits in DFSDM_FLTCR1 register */
3757 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_JEXTEN
);
3764 /* Enable DFSDM filter */
3765 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_DFEN
;
3767 /* If regular conversion was in progress, restart it */
3768 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG_INJ
) && \
3769 (hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
))
3771 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_RSWSTART
;
3774 /* Update remaining injected conversions */
3775 hdfsdm_filter
->InjConvRemaining
= (hdfsdm_filter
->InjectedScanMode
== ENABLE
) ? \
3776 hdfsdm_filter
->InjectedChannelsNbr
: 1U;
3778 /* Update DFSDM filter state */
3779 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
) ? \
3780 HAL_DFSDM_FILTER_STATE_READY
: HAL_DFSDM_FILTER_STATE_REG
;
3786 /* End of private functions --------------------------------------------------*/
3792 #endif /* HAL_DFSDM_MODULE_ENABLED */
3798 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/