Updated and Validated
[betaflight.git] / lib / main / STM32F7 / Drivers / STM32F7xx_HAL_Driver / Src / stm32f7xx_hal_dfsdm.c
blobdaeb1f90ee3ff7a86a9c22bd03c632ba1f4b49bb
1 /**
2 ******************************************************************************
3 * @file stm32f7xx_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
7 * (DFSDM) peripherals:
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
19 @verbatim
20 ==============================================================================
21 ##### How to use this driver #####
22 ==============================================================================
23 [..]
24 *** Channel initialization ***
25 ==============================
26 [..]
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 ======================================
40 [..]
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
44 absence.
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 ======================================
56 [..]
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
60 circuit.
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 =====================================
72 [..]
73 (#) Get analog watchdog filter value of a channel using
74 HAL_DFSDM_ChannelGetAwdValue().
76 *** Channel offset value ***
77 =====================================
78 [..]
79 (#) Modify offset value of a channel using HAL_DFSDM_ChannelModifyOffset().
81 *** Filter initialization ***
82 =============================
83 [..]
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 =========================================
97 [..]
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
113 circular mode.
114 (#) Stop regular conversion using HAL_DFSDM_FilterRegularStop(),
115 HAL_DFSDM_FilterRegularStop_IT() or HAL_DFSDM_FilterRegularStop_DMA().
117 *** Filter injected channels conversion ***
118 ===========================================
119 [..]
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
134 circular mode.
135 (#) Stop injected conversion using HAL_DFSDM_FilterInjectedStop(),
136 HAL_DFSDM_FilterInjectedStop_IT() or HAL_DFSDM_FilterInjectedStop_DMA().
138 *** Filter analog watchdog ***
139 ==============================
140 [..]
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 ===============================
147 [..]
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 ==============================
155 [..]
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 @ref HAL_DFSDM_Channel_RegisterCallback(),
164 @ref HAL_DFSDM_Filter_RegisterCallback() or
165 @ref HAL_DFSDM_Filter_RegisterAwdCallback() to register a user callback.
167 Function @ref HAL_DFSDM_Channel_RegisterCallback() allows to register
168 following callbacks:
169 (+) CkabCallback : DFSDM channel clock absence detection callback.
170 (+) ScdCallback : DFSDM channel short circuit detection callback.
171 (+) MspInitCallback : DFSDM channel MSP init callback.
172 (+) MspDeInitCallback : DFSDM channel MSP de-init callback.
173 This function takes as parameters the HAL peripheral handle, the Callback ID
174 and a pointer to the user callback function.
176 Function @ref HAL_DFSDM_Filter_RegisterCallback() allows to register
177 following callbacks:
178 (+) RegConvCpltCallback : DFSDM filter regular conversion complete callback.
179 (+) RegConvHalfCpltCallback : DFSDM filter half regular conversion complete callback.
180 (+) InjConvCpltCallback : DFSDM filter injected conversion complete callback.
181 (+) InjConvHalfCpltCallback : DFSDM filter half injected conversion complete callback.
182 (+) ErrorCallback : DFSDM filter error callback.
183 (+) MspInitCallback : DFSDM filter MSP init callback.
184 (+) MspDeInitCallback : DFSDM filter MSP de-init callback.
185 This function takes as parameters the HAL peripheral handle, the Callback ID
186 and a pointer to the user callback function.
188 For specific DFSDM filter analog watchdog callback use dedicated register callback:
189 @ref HAL_DFSDM_Filter_RegisterAwdCallback().
191 Use functions @ref HAL_DFSDM_Channel_UnRegisterCallback() or
192 @ref HAL_DFSDM_Filter_UnRegisterCallback() to reset a callback to the default
193 weak function.
195 @ref HAL_DFSDM_Channel_UnRegisterCallback() takes as parameters the HAL peripheral handle,
196 and the Callback ID.
197 This function allows to reset following callbacks:
198 (+) CkabCallback : DFSDM channel clock absence detection callback.
199 (+) ScdCallback : DFSDM channel short circuit detection callback.
200 (+) MspInitCallback : DFSDM channel MSP init callback.
201 (+) MspDeInitCallback : DFSDM channel MSP de-init callback.
203 @ref HAL_DFSDM_Filter_UnRegisterCallback() takes as parameters the HAL peripheral handle,
204 and the Callback ID.
205 This function allows to reset following callbacks:
206 (+) RegConvCpltCallback : DFSDM filter regular conversion complete callback.
207 (+) RegConvHalfCpltCallback : DFSDM filter half regular conversion complete callback.
208 (+) InjConvCpltCallback : DFSDM filter injected conversion complete callback.
209 (+) InjConvHalfCpltCallback : DFSDM filter half injected conversion complete callback.
210 (+) ErrorCallback : DFSDM filter error callback.
211 (+) MspInitCallback : DFSDM filter MSP init callback.
212 (+) MspDeInitCallback : DFSDM filter MSP de-init callback.
214 For specific DFSDM filter analog watchdog callback use dedicated unregister callback:
215 @ref HAL_DFSDM_Filter_UnRegisterAwdCallback().
217 By default, after the call of init function and if the state is RESET
218 all callbacks are reset to the corresponding legacy weak functions:
219 examples @ref HAL_DFSDM_ChannelScdCallback(), @ref HAL_DFSDM_FilterErrorCallback().
220 Exception done for MspInit and MspDeInit callbacks that are respectively
221 reset to the legacy weak functions in the init and de-init only when these
222 callbacks are null (not registered beforehand).
223 If not, MspInit or MspDeInit are not null, the init and de-init keep and use
224 the user MspInit/MspDeInit callbacks (registered beforehand)
226 Callbacks can be registered/unregistered in READY state only.
227 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
228 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
229 during the init/de-init.
230 In that case first register the MspInit/MspDeInit user callbacks using
231 @ref HAL_DFSDM_Channel_RegisterCallback() or
232 @ref HAL_DFSDM_Filter_RegisterCallback() before calling init or de-init function.
234 When The compilation define USE_HAL_DFSDM_REGISTER_CALLBACKS is set to 0 or
235 not defined, the callback registering feature is not available
236 and weak callbacks are used.
237 @endverbatim
238 ******************************************************************************
239 * @attention
241 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
242 * All rights reserved.</center></h2>
244 * This software component is licensed by ST under BSD 3-Clause license,
245 * the "License"; You may not use this file except in compliance with the
246 * License. You may obtain a copy of the License at:
247 * opensource.org/licenses/BSD-3-Clause
249 ******************************************************************************
252 /* Includes ------------------------------------------------------------------*/
253 #include "stm32f7xx_hal.h"
255 /** @addtogroup STM32F7xx_HAL_Driver
256 * @{
258 #ifdef HAL_DFSDM_MODULE_ENABLED
259 #if defined (STM32F765xx) || defined(STM32F767xx) || defined(STM32F769xx) || defined(STM32F777xx) || defined(STM32F779xx)
260 /** @defgroup DFSDM DFSDM
261 * @brief DFSDM HAL driver module
262 * @{
265 /* Private typedef -----------------------------------------------------------*/
266 /* Private define ------------------------------------------------------------*/
267 /** @defgroup DFSDM_Private_Define DFSDM Private Define
268 * @{
271 #define DFSDM_FLTCR1_MSB_RCH_OFFSET 8
273 #define DFSDM_MSB_MASK 0xFFFF0000U
274 #define DFSDM_LSB_MASK 0x0000FFFFU
275 #define DFSDM_CKAB_TIMEOUT 5000U
276 #define DFSDM1_CHANNEL_NUMBER 8U
278 * @}
281 /* Private macro -------------------------------------------------------------*/
282 /* Private variables ---------------------------------------------------------*/
283 /** @defgroup DFSDM_Private_Variables DFSDM Private Variables
284 * @{
286 __IO uint32_t v_dfsdm1ChannelCounter = 0;
287 DFSDM_Channel_HandleTypeDef* a_dfsdm1ChannelHandle[DFSDM1_CHANNEL_NUMBER] = {NULL};
289 * @}
292 /* Private function prototypes -----------------------------------------------*/
293 /** @defgroup DFSDM_Private_Functions DFSDM Private Functions
294 * @{
296 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels);
297 static uint32_t DFSDM_GetChannelFromInstance(DFSDM_Channel_TypeDef* Instance);
298 static void DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
299 static void DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef* hdfsdm_filter);
300 static void DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef* hdfsdm_filter);
301 static void DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef* hdfsdm_filter);
302 static void DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef *hdma);
303 static void DFSDM_DMARegularConvCplt(DMA_HandleTypeDef *hdma);
304 static void DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef *hdma);
305 static void DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef *hdma);
306 static void DFSDM_DMAError(DMA_HandleTypeDef *hdma);
308 * @}
311 /* Exported functions --------------------------------------------------------*/
312 /** @defgroup DFSDM_Exported_Functions DFSDM Exported Functions
313 * @{
316 /** @defgroup DFSDM_Exported_Functions_Group1_Channel Channel initialization and de-initialization functions
317 * @brief Channel initialization and de-initialization functions
319 @verbatim
320 ==============================================================================
321 ##### Channel initialization and de-initialization functions #####
322 ==============================================================================
323 [..] This section provides functions allowing to:
324 (+) Initialize the DFSDM channel.
325 (+) De-initialize the DFSDM channel.
326 @endverbatim
327 * @{
331 * @brief Initialize the DFSDM channel according to the specified parameters
332 * in the DFSDM_ChannelInitTypeDef structure and initialize the associated handle.
333 * @param hdfsdm_channel DFSDM channel handle.
334 * @retval HAL status.
336 HAL_StatusTypeDef HAL_DFSDM_ChannelInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
338 /* Check DFSDM Channel handle */
339 if(hdfsdm_channel == NULL)
341 return HAL_ERROR;
344 /* Check parameters */
345 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
346 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_channel->Init.OutputClock.Activation));
347 assert_param(IS_DFSDM_CHANNEL_INPUT(hdfsdm_channel->Init.Input.Multiplexer));
348 assert_param(IS_DFSDM_CHANNEL_DATA_PACKING(hdfsdm_channel->Init.Input.DataPacking));
349 assert_param(IS_DFSDM_CHANNEL_INPUT_PINS(hdfsdm_channel->Init.Input.Pins));
350 assert_param(IS_DFSDM_CHANNEL_SERIAL_INTERFACE_TYPE(hdfsdm_channel->Init.SerialInterface.Type));
351 assert_param(IS_DFSDM_CHANNEL_SPI_CLOCK(hdfsdm_channel->Init.SerialInterface.SpiClock));
352 assert_param(IS_DFSDM_CHANNEL_FILTER_ORDER(hdfsdm_channel->Init.Awd.FilterOrder));
353 assert_param(IS_DFSDM_CHANNEL_FILTER_OVS_RATIO(hdfsdm_channel->Init.Awd.Oversampling));
354 assert_param(IS_DFSDM_CHANNEL_OFFSET(hdfsdm_channel->Init.Offset));
355 assert_param(IS_DFSDM_CHANNEL_RIGHT_BIT_SHIFT(hdfsdm_channel->Init.RightBitShift));
357 /* Check that channel has not been already initialized */
358 if(a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] != NULL)
360 return HAL_ERROR;
363 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
364 /* Reset callback pointers to the weak predefined callbacks */
365 hdfsdm_channel->CkabCallback = HAL_DFSDM_ChannelCkabCallback;
366 hdfsdm_channel->ScdCallback = HAL_DFSDM_ChannelScdCallback;
368 /* Call MSP init function */
369 if(hdfsdm_channel->MspInitCallback == NULL)
371 hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit;
373 hdfsdm_channel->MspInitCallback(hdfsdm_channel);
374 #else
375 /* Call MSP init function */
376 HAL_DFSDM_ChannelMspInit(hdfsdm_channel);
377 #endif
379 /* Update the channel counter */
380 v_dfsdm1ChannelCounter++;
382 /* Configure output serial clock and enable global DFSDM interface only for first channel */
383 if(v_dfsdm1ChannelCounter == 1)
385 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK(hdfsdm_channel->Init.OutputClock.Selection));
386 /* Set the output serial clock source */
387 DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTSRC);
388 DFSDM1_Channel0->CHCFGR1 |= hdfsdm_channel->Init.OutputClock.Selection;
390 /* Reset clock divider */
391 DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTDIV);
392 if(hdfsdm_channel->Init.OutputClock.Activation == ENABLE)
394 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK_DIVIDER(hdfsdm_channel->Init.OutputClock.Divider));
395 /* Set the output clock divider */
396 DFSDM1_Channel0->CHCFGR1 |= (uint32_t) ((hdfsdm_channel->Init.OutputClock.Divider - 1) <<
397 DFSDM_CHCFGR1_CKOUTDIV_Pos);
400 /* enable the DFSDM global interface */
401 DFSDM1_Channel0->CHCFGR1 |= DFSDM_CHCFGR1_DFSDMEN;
404 /* Set channel input parameters */
405 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_DATPACK | DFSDM_CHCFGR1_DATMPX |
406 DFSDM_CHCFGR1_CHINSEL);
407 hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.Input.Multiplexer |
408 hdfsdm_channel->Init.Input.DataPacking |
409 hdfsdm_channel->Init.Input.Pins);
411 /* Set serial interface parameters */
412 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SITP | DFSDM_CHCFGR1_SPICKSEL);
413 hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.SerialInterface.Type |
414 hdfsdm_channel->Init.SerialInterface.SpiClock);
416 /* Set analog watchdog parameters */
417 hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_AWFORD | DFSDM_CHAWSCDR_AWFOSR);
418 hdfsdm_channel->Instance->CHAWSCDR |= (hdfsdm_channel->Init.Awd.FilterOrder |
419 ((hdfsdm_channel->Init.Awd.Oversampling - 1) << DFSDM_CHAWSCDR_AWFOSR_Pos));
421 /* Set channel offset and right bit shift */
422 hdfsdm_channel->Instance->CHCFGR2 &= ~(DFSDM_CHCFGR2_OFFSET | DFSDM_CHCFGR2_DTRBS);
423 hdfsdm_channel->Instance->CHCFGR2 |= (((uint32_t) hdfsdm_channel->Init.Offset << DFSDM_CHCFGR2_OFFSET_Pos) |
424 (hdfsdm_channel->Init.RightBitShift << DFSDM_CHCFGR2_DTRBS_Pos));
426 /* Enable DFSDM channel */
427 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CHEN;
429 /* Set DFSDM Channel to ready state */
430 hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_READY;
432 /* Store channel handle in DFSDM channel handle table */
433 a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] = hdfsdm_channel;
435 return HAL_OK;
439 * @brief De-initialize the DFSDM channel.
440 * @param hdfsdm_channel DFSDM channel handle.
441 * @retval HAL status.
443 HAL_StatusTypeDef HAL_DFSDM_ChannelDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
445 /* Check DFSDM Channel handle */
446 if(hdfsdm_channel == NULL)
448 return HAL_ERROR;
451 /* Check parameters */
452 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
454 /* Check that channel has not been already deinitialized */
455 if(a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] == NULL)
457 return HAL_ERROR;
460 /* Disable the DFSDM channel */
461 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CHEN);
463 /* Update the channel counter */
464 v_dfsdm1ChannelCounter--;
466 /* Disable global DFSDM at deinit of last channel */
467 if(v_dfsdm1ChannelCounter == 0)
469 DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_DFSDMEN);
472 /* Call MSP deinit function */
473 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
474 if(hdfsdm_channel->MspDeInitCallback == NULL)
476 hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit;
478 hdfsdm_channel->MspDeInitCallback(hdfsdm_channel);
479 #else
480 HAL_DFSDM_ChannelMspDeInit(hdfsdm_channel);
481 #endif
483 /* Set DFSDM Channel in reset state */
484 hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_RESET;
486 /* Reset channel handle in DFSDM channel handle table */
487 a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] = (DFSDM_Channel_HandleTypeDef *) NULL;
489 return HAL_OK;
493 * @brief Initialize the DFSDM channel MSP.
494 * @param hdfsdm_channel DFSDM channel handle.
495 * @retval None
497 __weak void HAL_DFSDM_ChannelMspInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
499 /* Prevent unused argument(s) compilation warning */
500 UNUSED(hdfsdm_channel);
502 /* NOTE : This function should not be modified, when the function is needed,
503 the HAL_DFSDM_ChannelMspInit could be implemented in the user file.
508 * @brief De-initialize the DFSDM channel MSP.
509 * @param hdfsdm_channel DFSDM channel handle.
510 * @retval None
512 __weak void HAL_DFSDM_ChannelMspDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
514 /* Prevent unused argument(s) compilation warning */
515 UNUSED(hdfsdm_channel);
517 /* NOTE : This function should not be modified, when the function is needed,
518 the HAL_DFSDM_ChannelMspDeInit could be implemented in the user file.
521 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
523 * @brief Register a user DFSDM channel callback
524 * to be used instead of the weak predefined callback.
525 * @param hdfsdm_channel DFSDM channel handle.
526 * @param CallbackID ID of the callback to be registered.
527 * This parameter can be one of the following values:
528 * @arg @ref HAL_DFSDM_CHANNEL_CKAB_CB_ID clock absence detection callback ID.
529 * @arg @ref HAL_DFSDM_CHANNEL_SCD_CB_ID short circuit detection callback ID.
530 * @arg @ref HAL_DFSDM_CHANNEL_MSPINIT_CB_ID MSP init callback ID.
531 * @arg @ref HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID MSP de-init callback ID.
532 * @param pCallback pointer to the callback function.
533 * @retval HAL status.
535 HAL_StatusTypeDef HAL_DFSDM_Channel_RegisterCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
536 HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID,
537 pDFSDM_Channel_CallbackTypeDef pCallback)
539 HAL_StatusTypeDef status = HAL_OK;
541 if(pCallback == NULL)
543 /* update return status */
544 status = HAL_ERROR;
546 else
548 if(HAL_DFSDM_CHANNEL_STATE_READY == hdfsdm_channel->State)
550 switch (CallbackID)
552 case HAL_DFSDM_CHANNEL_CKAB_CB_ID :
553 hdfsdm_channel->CkabCallback = pCallback;
554 break;
555 case HAL_DFSDM_CHANNEL_SCD_CB_ID :
556 hdfsdm_channel->ScdCallback = pCallback;
557 break;
558 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
559 hdfsdm_channel->MspInitCallback = pCallback;
560 break;
561 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
562 hdfsdm_channel->MspDeInitCallback = pCallback;
563 break;
564 default :
565 /* update return status */
566 status = HAL_ERROR;
567 break;
570 else if(HAL_DFSDM_CHANNEL_STATE_RESET == hdfsdm_channel->State)
572 switch (CallbackID)
574 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
575 hdfsdm_channel->MspInitCallback = pCallback;
576 break;
577 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
578 hdfsdm_channel->MspDeInitCallback = pCallback;
579 break;
580 default :
581 /* update return status */
582 status = HAL_ERROR;
583 break;
586 else
588 /* update return status */
589 status = HAL_ERROR;
592 return status;
596 * @brief Unregister a user DFSDM channel callback.
597 * DFSDM channel callback is redirected to the weak predefined callback.
598 * @param hdfsdm_channel DFSDM channel handle.
599 * @param CallbackID ID of the callback to be unregistered.
600 * This parameter can be one of the following values:
601 * @arg @ref HAL_DFSDM_CHANNEL_CKAB_CB_ID clock absence detection callback ID.
602 * @arg @ref HAL_DFSDM_CHANNEL_SCD_CB_ID short circuit detection callback ID.
603 * @arg @ref HAL_DFSDM_CHANNEL_MSPINIT_CB_ID MSP init callback ID.
604 * @arg @ref HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID MSP de-init callback ID.
605 * @retval HAL status.
607 HAL_StatusTypeDef HAL_DFSDM_Channel_UnRegisterCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
608 HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID)
610 HAL_StatusTypeDef status = HAL_OK;
612 if(HAL_DFSDM_CHANNEL_STATE_READY == hdfsdm_channel->State)
614 switch (CallbackID)
616 case HAL_DFSDM_CHANNEL_CKAB_CB_ID :
617 hdfsdm_channel->CkabCallback = HAL_DFSDM_ChannelCkabCallback;
618 break;
619 case HAL_DFSDM_CHANNEL_SCD_CB_ID :
620 hdfsdm_channel->ScdCallback = HAL_DFSDM_ChannelScdCallback;
621 break;
622 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
623 hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit;
624 break;
625 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
626 hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit;
627 break;
628 default :
629 /* update return status */
630 status = HAL_ERROR;
631 break;
634 else if(HAL_DFSDM_CHANNEL_STATE_RESET == hdfsdm_channel->State)
636 switch (CallbackID)
638 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
639 hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit;
640 break;
641 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
642 hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit;
643 break;
644 default :
645 /* update return status */
646 status = HAL_ERROR;
647 break;
650 else
652 /* update return status */
653 status = HAL_ERROR;
655 return status;
657 #endif /* USE_HAL_DFSDM_REGISTER_CALLBACKS */
660 * @}
663 /** @defgroup DFSDM_Exported_Functions_Group2_Channel Channel operation functions
664 * @brief Channel operation functions
666 @verbatim
667 ==============================================================================
668 ##### Channel operation functions #####
669 ==============================================================================
670 [..] This section provides functions allowing to:
671 (+) Manage clock absence detector feature.
672 (+) Manage short circuit detector feature.
673 (+) Get analog watchdog value.
674 (+) Modify offset value.
675 @endverbatim
676 * @{
680 * @brief This function allows to start clock absence detection in polling mode.
681 * @note Same mode has to be used for all channels.
682 * @note If clock is not available on this channel during 5 seconds,
683 * clock absence detection will not be activated and function
684 * will return HAL_TIMEOUT error.
685 * @param hdfsdm_channel DFSDM channel handle.
686 * @retval HAL status
688 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStart(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
690 HAL_StatusTypeDef status = HAL_OK;
691 uint32_t channel;
692 uint32_t tickstart;
694 /* Check parameters */
695 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
697 /* Check DFSDM channel state */
698 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
700 /* Return error status */
701 status = HAL_ERROR;
703 else
705 /* Get channel number from channel instance */
706 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
708 /* Get timeout */
709 tickstart = HAL_GetTick();
711 /* Clear clock absence flag */
712 while((((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1) != 0)
714 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
716 /* Check the Timeout */
717 if((HAL_GetTick()-tickstart) > DFSDM_CKAB_TIMEOUT)
719 /* Set timeout status */
720 status = HAL_TIMEOUT;
721 break;
725 if(status == HAL_OK)
727 /* Start clock absence detection */
728 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CKABEN;
731 /* Return function status */
732 return status;
736 * @brief This function allows to poll for the clock absence detection.
737 * @param hdfsdm_channel DFSDM channel handle.
738 * @param Timeout Timeout value in milliseconds.
739 * @retval HAL status
741 HAL_StatusTypeDef HAL_DFSDM_ChannelPollForCkab(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
742 uint32_t Timeout)
744 uint32_t tickstart;
745 uint32_t channel;
747 /* Check parameters */
748 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
750 /* Check DFSDM channel state */
751 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
753 /* Return error status */
754 return HAL_ERROR;
756 else
758 /* Get channel number from channel instance */
759 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
761 /* Get timeout */
762 tickstart = HAL_GetTick();
764 /* Wait clock absence detection */
765 while((((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1) == 0)
767 /* Check the Timeout */
768 if(Timeout != HAL_MAX_DELAY)
770 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
772 /* Return timeout status */
773 return HAL_TIMEOUT;
778 /* Clear clock absence detection flag */
779 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
781 /* Return function status */
782 return HAL_OK;
787 * @brief This function allows to stop clock absence detection in polling mode.
788 * @param hdfsdm_channel DFSDM channel handle.
789 * @retval HAL status
791 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStop(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
793 HAL_StatusTypeDef status = HAL_OK;
794 uint32_t channel;
796 /* Check parameters */
797 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
799 /* Check DFSDM channel state */
800 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
802 /* Return error status */
803 status = HAL_ERROR;
805 else
807 /* Stop clock absence detection */
808 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKABEN);
810 /* Clear clock absence flag */
811 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
812 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
814 /* Return function status */
815 return status;
819 * @brief This function allows to start clock absence detection in interrupt mode.
820 * @note Same mode has to be used for all channels.
821 * @note If clock is not available on this channel during 5 seconds,
822 * clock absence detection will not be activated and function
823 * will return HAL_TIMEOUT error.
824 * @param hdfsdm_channel DFSDM channel handle.
825 * @retval HAL status
827 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStart_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
829 HAL_StatusTypeDef status = HAL_OK;
830 uint32_t channel;
831 uint32_t tickstart;
833 /* Check parameters */
834 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
836 /* Check DFSDM channel state */
837 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
839 /* Return error status */
840 status = HAL_ERROR;
842 else
844 /* Get channel number from channel instance */
845 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
847 /* Get timeout */
848 tickstart = HAL_GetTick();
850 /* Clear clock absence flag */
851 while((((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1) != 0)
853 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
855 /* Check the Timeout */
856 if((HAL_GetTick()-tickstart) > DFSDM_CKAB_TIMEOUT)
858 /* Set timeout status */
859 status = HAL_TIMEOUT;
860 break;
864 if(status == HAL_OK)
866 /* Activate clock absence detection interrupt */
867 DFSDM1_Filter0->FLTCR2 |= DFSDM_FLTCR2_CKABIE;
869 /* Start clock absence detection */
870 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CKABEN;
873 /* Return function status */
874 return status;
878 * @brief Clock absence detection callback.
879 * @param hdfsdm_channel DFSDM channel handle.
880 * @retval None
882 __weak void HAL_DFSDM_ChannelCkabCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
884 /* Prevent unused argument(s) compilation warning */
885 UNUSED(hdfsdm_channel);
887 /* NOTE : This function should not be modified, when the callback is needed,
888 the HAL_DFSDM_ChannelCkabCallback could be implemented in the user file
893 * @brief This function allows to stop clock absence detection in interrupt mode.
894 * @note Interrupt will be disabled for all channels
895 * @param hdfsdm_channel DFSDM channel handle.
896 * @retval HAL status
898 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStop_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
900 HAL_StatusTypeDef status = HAL_OK;
901 uint32_t channel;
903 /* Check parameters */
904 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
906 /* Check DFSDM channel state */
907 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
909 /* Return error status */
910 status = HAL_ERROR;
912 else
914 /* Stop clock absence detection */
915 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKABEN);
917 /* Clear clock absence flag */
918 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
919 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
921 /* Disable clock absence detection interrupt */
922 DFSDM1_Filter0->FLTCR2 &= ~(DFSDM_FLTCR2_CKABIE);
924 /* Return function status */
925 return status;
929 * @brief This function allows to start short circuit detection in polling mode.
930 * @note Same mode has to be used for all channels
931 * @param hdfsdm_channel DFSDM channel handle.
932 * @param Threshold Short circuit detector threshold.
933 * This parameter must be a number between Min_Data = 0 and Max_Data = 255.
934 * @param BreakSignal Break signals assigned to short circuit event.
935 * This parameter can be a values combination of @ref DFSDM_BreakSignals.
936 * @retval HAL status
938 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStart(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
939 uint32_t Threshold,
940 uint32_t BreakSignal)
942 HAL_StatusTypeDef status = HAL_OK;
944 /* Check parameters */
945 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
946 assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold));
947 assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal));
949 /* Check DFSDM channel state */
950 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
952 /* Return error status */
953 status = HAL_ERROR;
955 else
957 /* Configure threshold and break signals */
958 hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_BKSCD | DFSDM_CHAWSCDR_SCDT);
959 hdfsdm_channel->Instance->CHAWSCDR |= ((BreakSignal << DFSDM_CHAWSCDR_BKSCD_Pos) | \
960 Threshold);
962 /* Start short circuit detection */
963 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_SCDEN;
965 /* Return function status */
966 return status;
970 * @brief This function allows to poll for the short circuit detection.
971 * @param hdfsdm_channel DFSDM channel handle.
972 * @param Timeout Timeout value in milliseconds.
973 * @retval HAL status
975 HAL_StatusTypeDef HAL_DFSDM_ChannelPollForScd(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
976 uint32_t Timeout)
978 uint32_t tickstart;
979 uint32_t channel;
981 /* Check parameters */
982 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
984 /* Check DFSDM channel state */
985 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
987 /* Return error status */
988 return HAL_ERROR;
990 else
992 /* Get channel number from channel instance */
993 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
995 /* Get timeout */
996 tickstart = HAL_GetTick();
998 /* Wait short circuit detection */
999 while(((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_SCDF) >> (DFSDM_FLTISR_SCDF_Pos + channel)) == 0)
1001 /* Check the Timeout */
1002 if(Timeout != HAL_MAX_DELAY)
1004 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
1006 /* Return timeout status */
1007 return HAL_TIMEOUT;
1012 /* Clear short circuit detection flag */
1013 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRSCDF_Pos + channel));
1015 /* Return function status */
1016 return HAL_OK;
1021 * @brief This function allows to stop short circuit detection in polling mode.
1022 * @param hdfsdm_channel DFSDM channel handle.
1023 * @retval HAL status
1025 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStop(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
1027 HAL_StatusTypeDef status = HAL_OK;
1028 uint32_t channel;
1030 /* Check parameters */
1031 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
1033 /* Check DFSDM channel state */
1034 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
1036 /* Return error status */
1037 status = HAL_ERROR;
1039 else
1041 /* Stop short circuit detection */
1042 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SCDEN);
1044 /* Clear short circuit detection flag */
1045 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
1046 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRSCDF_Pos + channel));
1048 /* Return function status */
1049 return status;
1053 * @brief This function allows to start short circuit detection in interrupt mode.
1054 * @note Same mode has to be used for all channels
1055 * @param hdfsdm_channel DFSDM channel handle.
1056 * @param Threshold Short circuit detector threshold.
1057 * This parameter must be a number between Min_Data = 0 and Max_Data = 255.
1058 * @param BreakSignal Break signals assigned to short circuit event.
1059 * This parameter can be a values combination of @ref DFSDM_BreakSignals.
1060 * @retval HAL status
1062 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStart_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
1063 uint32_t Threshold,
1064 uint32_t BreakSignal)
1066 HAL_StatusTypeDef status = HAL_OK;
1068 /* Check parameters */
1069 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
1070 assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold));
1071 assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal));
1073 /* Check DFSDM channel state */
1074 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
1076 /* Return error status */
1077 status = HAL_ERROR;
1079 else
1081 /* Activate short circuit detection interrupt */
1082 DFSDM1_Filter0->FLTCR2 |= DFSDM_FLTCR2_SCDIE;
1084 /* Configure threshold and break signals */
1085 hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_BKSCD | DFSDM_CHAWSCDR_SCDT);
1086 hdfsdm_channel->Instance->CHAWSCDR |= ((BreakSignal << DFSDM_CHAWSCDR_BKSCD_Pos) | \
1087 Threshold);
1089 /* Start short circuit detection */
1090 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_SCDEN;
1092 /* Return function status */
1093 return status;
1097 * @brief Short circuit detection callback.
1098 * @param hdfsdm_channel DFSDM channel handle.
1099 * @retval None
1101 __weak void HAL_DFSDM_ChannelScdCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
1103 /* Prevent unused argument(s) compilation warning */
1104 UNUSED(hdfsdm_channel);
1106 /* NOTE : This function should not be modified, when the callback is needed,
1107 the HAL_DFSDM_ChannelScdCallback could be implemented in the user file
1112 * @brief This function allows to stop short circuit detection in interrupt mode.
1113 * @note Interrupt will be disabled for all channels
1114 * @param hdfsdm_channel DFSDM channel handle.
1115 * @retval HAL status
1117 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStop_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
1119 HAL_StatusTypeDef status = HAL_OK;
1120 uint32_t channel;
1122 /* Check parameters */
1123 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
1125 /* Check DFSDM channel state */
1126 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
1128 /* Return error status */
1129 status = HAL_ERROR;
1131 else
1133 /* Stop short circuit detection */
1134 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SCDEN);
1136 /* Clear short circuit detection flag */
1137 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
1138 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRSCDF_Pos + channel));
1140 /* Disable short circuit detection interrupt */
1141 DFSDM1_Filter0->FLTCR2 &= ~(DFSDM_FLTCR2_SCDIE);
1143 /* Return function status */
1144 return status;
1148 * @brief This function allows to get channel analog watchdog value.
1149 * @param hdfsdm_channel DFSDM channel handle.
1150 * @retval Channel analog watchdog value.
1152 int16_t HAL_DFSDM_ChannelGetAwdValue(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
1154 return (int16_t) hdfsdm_channel->Instance->CHWDATAR;
1158 * @brief This function allows to modify channel offset value.
1159 * @param hdfsdm_channel DFSDM channel handle.
1160 * @param Offset DFSDM channel offset.
1161 * This parameter must be a number between Min_Data = -8388608 and Max_Data = 8388607.
1162 * @retval HAL status.
1164 HAL_StatusTypeDef HAL_DFSDM_ChannelModifyOffset(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
1165 int32_t Offset)
1167 HAL_StatusTypeDef status = HAL_OK;
1169 /* Check parameters */
1170 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
1171 assert_param(IS_DFSDM_CHANNEL_OFFSET(Offset));
1173 /* Check DFSDM channel state */
1174 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
1176 /* Return error status */
1177 status = HAL_ERROR;
1179 else
1181 /* Modify channel offset */
1182 hdfsdm_channel->Instance->CHCFGR2 &= ~(DFSDM_CHCFGR2_OFFSET);
1183 hdfsdm_channel->Instance->CHCFGR2 |= ((uint32_t) Offset << DFSDM_CHCFGR2_OFFSET_Pos);
1185 /* Return function status */
1186 return status;
1190 * @}
1193 /** @defgroup DFSDM_Exported_Functions_Group3_Channel Channel state function
1194 * @brief Channel state function
1196 @verbatim
1197 ==============================================================================
1198 ##### Channel state function #####
1199 ==============================================================================
1200 [..] This section provides function allowing to:
1201 (+) Get channel handle state.
1202 @endverbatim
1203 * @{
1207 * @brief This function allows to get the current DFSDM channel handle state.
1208 * @param hdfsdm_channel DFSDM channel handle.
1209 * @retval DFSDM channel state.
1211 HAL_DFSDM_Channel_StateTypeDef HAL_DFSDM_ChannelGetState(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
1213 /* Return DFSDM channel handle state */
1214 return hdfsdm_channel->State;
1218 * @}
1221 /** @defgroup DFSDM_Exported_Functions_Group1_Filter Filter initialization and de-initialization functions
1222 * @brief Filter initialization and de-initialization functions
1224 @verbatim
1225 ==============================================================================
1226 ##### Filter initialization and de-initialization functions #####
1227 ==============================================================================
1228 [..] This section provides functions allowing to:
1229 (+) Initialize the DFSDM filter.
1230 (+) De-initialize the DFSDM filter.
1231 @endverbatim
1232 * @{
1236 * @brief Initialize the DFSDM filter according to the specified parameters
1237 * in the DFSDM_FilterInitTypeDef structure and initialize the associated handle.
1238 * @param hdfsdm_filter DFSDM filter handle.
1239 * @retval HAL status.
1241 HAL_StatusTypeDef HAL_DFSDM_FilterInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
1243 /* Check DFSDM Channel handle */
1244 if(hdfsdm_filter == NULL)
1246 return HAL_ERROR;
1249 /* Check parameters */
1250 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
1251 assert_param(IS_DFSDM_FILTER_REG_TRIGGER(hdfsdm_filter->Init.RegularParam.Trigger));
1252 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.RegularParam.FastMode));
1253 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.RegularParam.DmaMode));
1254 assert_param(IS_DFSDM_FILTER_INJ_TRIGGER(hdfsdm_filter->Init.InjectedParam.Trigger));
1255 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.InjectedParam.ScanMode));
1256 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.InjectedParam.DmaMode));
1257 assert_param(IS_DFSDM_FILTER_SINC_ORDER(hdfsdm_filter->Init.FilterParam.SincOrder));
1258 assert_param(IS_DFSDM_FILTER_OVS_RATIO(hdfsdm_filter->Init.FilterParam.Oversampling));
1259 assert_param(IS_DFSDM_FILTER_INTEGRATOR_OVS_RATIO(hdfsdm_filter->Init.FilterParam.IntOversampling));
1261 /* Check parameters compatibility */
1262 if((hdfsdm_filter->Instance == DFSDM1_Filter0) &&
1263 ((hdfsdm_filter->Init.RegularParam.Trigger == DFSDM_FILTER_SYNC_TRIGGER) ||
1264 (hdfsdm_filter->Init.InjectedParam.Trigger == DFSDM_FILTER_SYNC_TRIGGER)))
1266 return HAL_ERROR;
1269 /* Initialize DFSDM filter variables with default values */
1270 hdfsdm_filter->RegularContMode = DFSDM_CONTINUOUS_CONV_OFF;
1271 hdfsdm_filter->InjectedChannelsNbr = 1;
1272 hdfsdm_filter->InjConvRemaining = 1;
1273 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_NONE;
1275 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
1276 /* Reset callback pointers to the weak predefined callbacks */
1277 hdfsdm_filter->AwdCallback = HAL_DFSDM_FilterAwdCallback;
1278 hdfsdm_filter->RegConvCpltCallback = HAL_DFSDM_FilterRegConvCpltCallback;
1279 hdfsdm_filter->RegConvHalfCpltCallback = HAL_DFSDM_FilterRegConvHalfCpltCallback;
1280 hdfsdm_filter->InjConvCpltCallback = HAL_DFSDM_FilterInjConvCpltCallback;
1281 hdfsdm_filter->InjConvHalfCpltCallback = HAL_DFSDM_FilterInjConvHalfCpltCallback;
1282 hdfsdm_filter->ErrorCallback = HAL_DFSDM_FilterErrorCallback;
1284 /* Call MSP init function */
1285 if(hdfsdm_filter->MspInitCallback == NULL)
1287 hdfsdm_filter->MspInitCallback = HAL_DFSDM_FilterMspInit;
1289 hdfsdm_filter->MspInitCallback(hdfsdm_filter);
1290 #else
1291 /* Call MSP init function */
1292 HAL_DFSDM_FilterMspInit(hdfsdm_filter);
1293 #endif
1295 /* Set regular parameters */
1296 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RSYNC);
1297 if(hdfsdm_filter->Init.RegularParam.FastMode == ENABLE)
1299 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_FAST;
1301 else
1303 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_FAST);
1306 if(hdfsdm_filter->Init.RegularParam.DmaMode == ENABLE)
1308 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RDMAEN;
1310 else
1312 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RDMAEN);
1315 /* Set injected parameters */
1316 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSYNC | DFSDM_FLTCR1_JEXTEN | DFSDM_FLTCR1_JEXTSEL);
1317 if(hdfsdm_filter->Init.InjectedParam.Trigger == DFSDM_FILTER_EXT_TRIGGER)
1319 assert_param(IS_DFSDM_FILTER_EXT_TRIG(hdfsdm_filter->Init.InjectedParam.ExtTrigger));
1320 assert_param(IS_DFSDM_FILTER_EXT_TRIG_EDGE(hdfsdm_filter->Init.InjectedParam.ExtTriggerEdge));
1321 hdfsdm_filter->Instance->FLTCR1 |= (hdfsdm_filter->Init.InjectedParam.ExtTrigger);
1324 if(hdfsdm_filter->Init.InjectedParam.ScanMode == ENABLE)
1326 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSCAN;
1328 else
1330 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSCAN);
1333 if(hdfsdm_filter->Init.InjectedParam.DmaMode == ENABLE)
1335 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JDMAEN;
1337 else
1339 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JDMAEN);
1342 /* Set filter parameters */
1343 hdfsdm_filter->Instance->FLTFCR &= ~(DFSDM_FLTFCR_FORD | DFSDM_FLTFCR_FOSR | DFSDM_FLTFCR_IOSR);
1344 hdfsdm_filter->Instance->FLTFCR |= (hdfsdm_filter->Init.FilterParam.SincOrder |
1345 ((hdfsdm_filter->Init.FilterParam.Oversampling - 1) << DFSDM_FLTFCR_FOSR_Pos) |
1346 (hdfsdm_filter->Init.FilterParam.IntOversampling - 1));
1348 /* Store regular and injected triggers and injected scan mode*/
1349 hdfsdm_filter->RegularTrigger = hdfsdm_filter->Init.RegularParam.Trigger;
1350 hdfsdm_filter->InjectedTrigger = hdfsdm_filter->Init.InjectedParam.Trigger;
1351 hdfsdm_filter->ExtTriggerEdge = hdfsdm_filter->Init.InjectedParam.ExtTriggerEdge;
1352 hdfsdm_filter->InjectedScanMode = hdfsdm_filter->Init.InjectedParam.ScanMode;
1354 /* Enable DFSDM filter */
1355 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
1357 /* Set DFSDM filter to ready state */
1358 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_READY;
1360 return HAL_OK;
1364 * @brief De-initializes the DFSDM filter.
1365 * @param hdfsdm_filter DFSDM filter handle.
1366 * @retval HAL status.
1368 HAL_StatusTypeDef HAL_DFSDM_FilterDeInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
1370 /* Check DFSDM filter handle */
1371 if(hdfsdm_filter == NULL)
1373 return HAL_ERROR;
1376 /* Check parameters */
1377 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
1379 /* Disable the DFSDM filter */
1380 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
1382 /* Call MSP deinit function */
1383 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
1384 if(hdfsdm_filter->MspDeInitCallback == NULL)
1386 hdfsdm_filter->MspDeInitCallback = HAL_DFSDM_FilterMspDeInit;
1388 hdfsdm_filter->MspDeInitCallback(hdfsdm_filter);
1389 #else
1390 HAL_DFSDM_FilterMspDeInit(hdfsdm_filter);
1391 #endif
1393 /* Set DFSDM filter in reset state */
1394 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_RESET;
1396 return HAL_OK;
1400 * @brief Initializes the DFSDM filter MSP.
1401 * @param hdfsdm_filter DFSDM filter handle.
1402 * @retval None
1404 __weak void HAL_DFSDM_FilterMspInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
1406 /* Prevent unused argument(s) compilation warning */
1407 UNUSED(hdfsdm_filter);
1409 /* NOTE : This function should not be modified, when the function is needed,
1410 the HAL_DFSDM_FilterMspInit could be implemented in the user file.
1415 * @brief De-initializes the DFSDM filter MSP.
1416 * @param hdfsdm_filter DFSDM filter handle.
1417 * @retval None
1419 __weak void HAL_DFSDM_FilterMspDeInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
1421 /* Prevent unused argument(s) compilation warning */
1422 UNUSED(hdfsdm_filter);
1424 /* NOTE : This function should not be modified, when the function is needed,
1425 the HAL_DFSDM_FilterMspDeInit could be implemented in the user file.
1429 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
1431 * @brief Register a user DFSDM filter callback
1432 * to be used instead of the weak predefined callback.
1433 * @param hdfsdm_filter DFSDM filter handle.
1434 * @param CallbackID ID of the callback to be registered.
1435 * This parameter can be one of the following values:
1436 * @arg @ref HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID regular conversion complete callback ID.
1437 * @arg @ref HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID half regular conversion complete callback ID.
1438 * @arg @ref HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID injected conversion complete callback ID.
1439 * @arg @ref HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID half injected conversion complete callback ID.
1440 * @arg @ref HAL_DFSDM_FILTER_ERROR_CB_ID error callback ID.
1441 * @arg @ref HAL_DFSDM_FILTER_MSPINIT_CB_ID MSP init callback ID.
1442 * @arg @ref HAL_DFSDM_FILTER_MSPDEINIT_CB_ID MSP de-init callback ID.
1443 * @param pCallback pointer to the callback function.
1444 * @retval HAL status.
1446 HAL_StatusTypeDef HAL_DFSDM_Filter_RegisterCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
1447 HAL_DFSDM_Filter_CallbackIDTypeDef CallbackID,
1448 pDFSDM_Filter_CallbackTypeDef pCallback)
1450 HAL_StatusTypeDef status = HAL_OK;
1452 if(pCallback == NULL)
1454 /* update the error code */
1455 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1456 /* update return status */
1457 status = HAL_ERROR;
1459 else
1461 if(HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State)
1463 switch (CallbackID)
1465 case HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID :
1466 hdfsdm_filter->RegConvCpltCallback = pCallback;
1467 break;
1468 case HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID :
1469 hdfsdm_filter->RegConvHalfCpltCallback = pCallback;
1470 break;
1471 case HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID :
1472 hdfsdm_filter->InjConvCpltCallback = pCallback;
1473 break;
1474 case HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID :
1475 hdfsdm_filter->InjConvHalfCpltCallback = pCallback;
1476 break;
1477 case HAL_DFSDM_FILTER_ERROR_CB_ID :
1478 hdfsdm_filter->ErrorCallback = pCallback;
1479 break;
1480 case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
1481 hdfsdm_filter->MspInitCallback = pCallback;
1482 break;
1483 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
1484 hdfsdm_filter->MspDeInitCallback = pCallback;
1485 break;
1486 default :
1487 /* update the error code */
1488 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1489 /* update return status */
1490 status = HAL_ERROR;
1491 break;
1494 else if(HAL_DFSDM_FILTER_STATE_RESET == hdfsdm_filter->State)
1496 switch (CallbackID)
1498 case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
1499 hdfsdm_filter->MspInitCallback = pCallback;
1500 break;
1501 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
1502 hdfsdm_filter->MspDeInitCallback = pCallback;
1503 break;
1504 default :
1505 /* update the error code */
1506 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1507 /* update return status */
1508 status = HAL_ERROR;
1509 break;
1512 else
1514 /* update the error code */
1515 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1516 /* update return status */
1517 status = HAL_ERROR;
1520 return status;
1524 * @brief Unregister a user DFSDM filter callback.
1525 * DFSDM filter callback is redirected to the weak predefined callback.
1526 * @param hdfsdm_filter DFSDM filter handle.
1527 * @param CallbackID ID of the callback to be unregistered.
1528 * This parameter can be one of the following values:
1529 * @arg @ref HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID regular conversion complete callback ID.
1530 * @arg @ref HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID half regular conversion complete callback ID.
1531 * @arg @ref HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID injected conversion complete callback ID.
1532 * @arg @ref HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID half injected conversion complete callback ID.
1533 * @arg @ref HAL_DFSDM_FILTER_ERROR_CB_ID error callback ID.
1534 * @arg @ref HAL_DFSDM_FILTER_MSPINIT_CB_ID MSP init callback ID.
1535 * @arg @ref HAL_DFSDM_FILTER_MSPDEINIT_CB_ID MSP de-init callback ID.
1536 * @retval HAL status.
1538 HAL_StatusTypeDef HAL_DFSDM_Filter_UnRegisterCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
1539 HAL_DFSDM_Filter_CallbackIDTypeDef CallbackID)
1541 HAL_StatusTypeDef status = HAL_OK;
1543 if(HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State)
1545 switch (CallbackID)
1547 case HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID :
1548 hdfsdm_filter->RegConvCpltCallback = HAL_DFSDM_FilterRegConvCpltCallback;
1549 break;
1550 case HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID :
1551 hdfsdm_filter->RegConvHalfCpltCallback = HAL_DFSDM_FilterRegConvHalfCpltCallback;
1552 break;
1553 case HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID :
1554 hdfsdm_filter->InjConvCpltCallback = HAL_DFSDM_FilterInjConvCpltCallback;
1555 break;
1556 case HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID :
1557 hdfsdm_filter->InjConvHalfCpltCallback = HAL_DFSDM_FilterInjConvHalfCpltCallback;
1558 break;
1559 case HAL_DFSDM_FILTER_ERROR_CB_ID :
1560 hdfsdm_filter->ErrorCallback = HAL_DFSDM_FilterErrorCallback;
1561 break;
1562 case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
1563 hdfsdm_filter->MspInitCallback = HAL_DFSDM_FilterMspInit;
1564 break;
1565 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
1566 hdfsdm_filter->MspDeInitCallback = HAL_DFSDM_FilterMspDeInit;
1567 break;
1568 default :
1569 /* update the error code */
1570 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1571 /* update return status */
1572 status = HAL_ERROR;
1573 break;
1576 else if(HAL_DFSDM_FILTER_STATE_RESET == hdfsdm_filter->State)
1578 switch (CallbackID)
1580 case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
1581 hdfsdm_filter->MspInitCallback = HAL_DFSDM_FilterMspInit;
1582 break;
1583 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
1584 hdfsdm_filter->MspDeInitCallback = HAL_DFSDM_FilterMspDeInit;
1585 break;
1586 default :
1587 /* update the error code */
1588 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1589 /* update return status */
1590 status = HAL_ERROR;
1591 break;
1594 else
1596 /* update the error code */
1597 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1598 /* update return status */
1599 status = HAL_ERROR;
1601 return status;
1605 * @brief Register a user DFSDM filter analog watchdog callback
1606 * to be used instead of the weak predefined callback.
1607 * @param hdfsdm_filter DFSDM filter handle.
1608 * @param pCallback pointer to the DFSDM filter analog watchdog callback function.
1609 * @retval HAL status.
1611 HAL_StatusTypeDef HAL_DFSDM_Filter_RegisterAwdCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
1612 pDFSDM_Filter_AwdCallbackTypeDef pCallback)
1614 HAL_StatusTypeDef status = HAL_OK;
1616 if(pCallback == NULL)
1618 /* update the error code */
1619 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1620 /* update return status */
1621 status = HAL_ERROR;
1623 else
1625 if(HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State)
1627 hdfsdm_filter->AwdCallback = pCallback;
1629 else
1631 /* update the error code */
1632 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1633 /* update return status */
1634 status = HAL_ERROR;
1637 return status;
1641 * @brief Unregister a user DFSDM filter analog watchdog callback.
1642 * DFSDM filter AWD callback is redirected to the weak predefined callback.
1643 * @param hdfsdm_filter DFSDM filter handle.
1644 * @retval HAL status.
1646 HAL_StatusTypeDef HAL_DFSDM_Filter_UnRegisterAwdCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
1648 HAL_StatusTypeDef status = HAL_OK;
1650 if(HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State)
1652 hdfsdm_filter->AwdCallback = HAL_DFSDM_FilterAwdCallback;
1654 else
1656 /* update the error code */
1657 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1658 /* update return status */
1659 status = HAL_ERROR;
1661 return status;
1663 #endif /* USE_HAL_DFSDM_REGISTER_CALLBACKS */
1666 * @}
1669 /** @defgroup DFSDM_Exported_Functions_Group2_Filter Filter control functions
1670 * @brief Filter control functions
1672 @verbatim
1673 ==============================================================================
1674 ##### Filter control functions #####
1675 ==============================================================================
1676 [..] This section provides functions allowing to:
1677 (+) Select channel and enable/disable continuous mode for regular conversion.
1678 (+) Select channels for injected conversion.
1679 @endverbatim
1680 * @{
1684 * @brief This function allows to select channel and to enable/disable
1685 * continuous mode for regular conversion.
1686 * @param hdfsdm_filter DFSDM filter handle.
1687 * @param Channel Channel for regular conversion.
1688 * This parameter can be a value of @ref DFSDM_Channel_Selection.
1689 * @param ContinuousMode Enable/disable continuous mode for regular conversion.
1690 * This parameter can be a value of @ref DFSDM_ContinuousMode.
1691 * @retval HAL status
1693 HAL_StatusTypeDef HAL_DFSDM_FilterConfigRegChannel(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
1694 uint32_t Channel,
1695 uint32_t ContinuousMode)
1697 HAL_StatusTypeDef status = HAL_OK;
1699 /* Check parameters */
1700 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
1701 assert_param(IS_DFSDM_REGULAR_CHANNEL(Channel));
1702 assert_param(IS_DFSDM_CONTINUOUS_MODE(ContinuousMode));
1704 /* Check DFSDM filter state */
1705 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_RESET) &&
1706 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_ERROR))
1708 /* Configure channel and continuous mode for regular conversion */
1709 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RCH | DFSDM_FLTCR1_RCONT);
1710 if(ContinuousMode == DFSDM_CONTINUOUS_CONV_ON)
1712 hdfsdm_filter->Instance->FLTCR1 |= (uint32_t) (((Channel & DFSDM_MSB_MASK) << DFSDM_FLTCR1_MSB_RCH_OFFSET) |
1713 DFSDM_FLTCR1_RCONT);
1715 else
1717 hdfsdm_filter->Instance->FLTCR1 |= (uint32_t) ((Channel & DFSDM_MSB_MASK) << DFSDM_FLTCR1_MSB_RCH_OFFSET);
1719 /* Store continuous mode information */
1720 hdfsdm_filter->RegularContMode = ContinuousMode;
1722 else
1724 status = HAL_ERROR;
1727 /* Return function status */
1728 return status;
1732 * @brief This function allows to select channels for injected conversion.
1733 * @param hdfsdm_filter DFSDM filter handle.
1734 * @param Channel Channels for injected conversion.
1735 * This parameter can be a values combination of @ref DFSDM_Channel_Selection.
1736 * @retval HAL status
1738 HAL_StatusTypeDef HAL_DFSDM_FilterConfigInjChannel(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
1739 uint32_t Channel)
1741 HAL_StatusTypeDef status = HAL_OK;
1743 /* Check parameters */
1744 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
1745 assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel));
1747 /* Check DFSDM filter state */
1748 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_RESET) &&
1749 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_ERROR))
1751 /* Configure channel for injected conversion */
1752 hdfsdm_filter->Instance->FLTJCHGR = (uint32_t) (Channel & DFSDM_LSB_MASK);
1753 /* Store number of injected channels */
1754 hdfsdm_filter->InjectedChannelsNbr = DFSDM_GetInjChannelsNbr(Channel);
1755 /* Update number of injected channels remaining */
1756 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
1757 hdfsdm_filter->InjectedChannelsNbr : 1;
1759 else
1761 status = HAL_ERROR;
1763 /* Return function status */
1764 return status;
1768 * @}
1771 /** @defgroup DFSDM_Exported_Functions_Group3_Filter Filter operation functions
1772 * @brief Filter operation functions
1774 @verbatim
1775 ==============================================================================
1776 ##### Filter operation functions #####
1777 ==============================================================================
1778 [..] This section provides functions allowing to:
1779 (+) Start conversion of regular/injected channel.
1780 (+) Poll for the end of regular/injected conversion.
1781 (+) Stop conversion of regular/injected channel.
1782 (+) Start conversion of regular/injected channel and enable interrupt.
1783 (+) Call the callback functions at the end of regular/injected conversions.
1784 (+) Stop conversion of regular/injected channel and disable interrupt.
1785 (+) Start conversion of regular/injected channel and enable DMA transfer.
1786 (+) Stop conversion of regular/injected channel and disable DMA transfer.
1787 (+) Start analog watchdog and enable interrupt.
1788 (+) Call the callback function when analog watchdog occurs.
1789 (+) Stop analog watchdog and disable interrupt.
1790 (+) Start extreme detector.
1791 (+) Stop extreme detector.
1792 (+) Get result of regular channel conversion.
1793 (+) Get result of injected channel conversion.
1794 (+) Get extreme detector maximum and minimum values.
1795 (+) Get conversion time.
1796 (+) Handle DFSDM interrupt request.
1797 @endverbatim
1798 * @{
1802 * @brief This function allows to start regular conversion in polling mode.
1803 * @note This function should be called only when DFSDM filter instance is
1804 * in idle state or if injected conversion is ongoing.
1805 * @param hdfsdm_filter DFSDM filter handle.
1806 * @retval HAL status
1808 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
1810 HAL_StatusTypeDef status = HAL_OK;
1812 /* Check parameters */
1813 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
1815 /* Check DFSDM filter state */
1816 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
1817 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
1819 /* Start regular conversion */
1820 DFSDM_RegConvStart(hdfsdm_filter);
1822 else
1824 status = HAL_ERROR;
1826 /* Return function status */
1827 return status;
1831 * @brief This function allows to poll for the end of regular conversion.
1832 * @note This function should be called only if regular conversion is ongoing.
1833 * @param hdfsdm_filter DFSDM filter handle.
1834 * @param Timeout Timeout value in milliseconds.
1835 * @retval HAL status
1837 HAL_StatusTypeDef HAL_DFSDM_FilterPollForRegConversion(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
1838 uint32_t Timeout)
1840 uint32_t tickstart;
1842 /* Check parameters */
1843 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
1845 /* Check DFSDM filter state */
1846 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
1847 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
1849 /* Return error status */
1850 return HAL_ERROR;
1852 else
1854 /* Get timeout */
1855 tickstart = HAL_GetTick();
1857 /* Wait end of regular conversion */
1858 while((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_REOCF) != DFSDM_FLTISR_REOCF)
1860 /* Check the Timeout */
1861 if(Timeout != HAL_MAX_DELAY)
1863 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
1865 /* Return timeout status */
1866 return HAL_TIMEOUT;
1870 /* Check if overrun occurs */
1871 if((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_ROVRF) == DFSDM_FLTISR_ROVRF)
1873 /* Update error code and call error callback */
1874 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_REGULAR_OVERRUN;
1875 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
1876 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
1877 #else
1878 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
1879 #endif
1881 /* Clear regular overrun flag */
1882 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRROVRF;
1884 /* Update DFSDM filter state only if not continuous conversion and SW trigger */
1885 if((hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
1886 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
1888 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \
1889 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ;
1891 /* Return function status */
1892 return HAL_OK;
1897 * @brief This function allows to stop regular conversion in polling mode.
1898 * @note This function should be called only if regular conversion is ongoing.
1899 * @param hdfsdm_filter DFSDM filter handle.
1900 * @retval HAL status
1902 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
1904 HAL_StatusTypeDef status = HAL_OK;
1906 /* Check parameters */
1907 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
1909 /* Check DFSDM filter state */
1910 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
1911 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
1913 /* Return error status */
1914 status = HAL_ERROR;
1916 else
1918 /* Stop regular conversion */
1919 DFSDM_RegConvStop(hdfsdm_filter);
1921 /* Return function status */
1922 return status;
1926 * @brief This function allows to start regular conversion in interrupt mode.
1927 * @note This function should be called only when DFSDM filter instance is
1928 * in idle state or if injected conversion is ongoing.
1929 * @param hdfsdm_filter DFSDM filter handle.
1930 * @retval HAL status
1932 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
1934 HAL_StatusTypeDef status = HAL_OK;
1936 /* Check parameters */
1937 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
1939 /* Check DFSDM filter state */
1940 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
1941 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
1943 /* Enable interrupts for regular conversions */
1944 hdfsdm_filter->Instance->FLTCR2 |= (DFSDM_FLTCR2_REOCIE | DFSDM_FLTCR2_ROVRIE);
1946 /* Start regular conversion */
1947 DFSDM_RegConvStart(hdfsdm_filter);
1949 else
1951 status = HAL_ERROR;
1953 /* Return function status */
1954 return status;
1958 * @brief This function allows to stop regular conversion in interrupt mode.
1959 * @note This function should be called only if regular conversion is ongoing.
1960 * @param hdfsdm_filter DFSDM filter handle.
1961 * @retval HAL status
1963 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
1965 HAL_StatusTypeDef status = HAL_OK;
1967 /* Check parameters */
1968 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
1970 /* Check DFSDM filter state */
1971 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
1972 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
1974 /* Return error status */
1975 status = HAL_ERROR;
1977 else
1979 /* Disable interrupts for regular conversions */
1980 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_REOCIE | DFSDM_FLTCR2_ROVRIE);
1982 /* Stop regular conversion */
1983 DFSDM_RegConvStop(hdfsdm_filter);
1985 /* Return function status */
1986 return status;
1990 * @brief This function allows to start regular conversion in DMA mode.
1991 * @note This function should be called only when DFSDM filter instance is
1992 * in idle state or if injected conversion is ongoing.
1993 * Please note that data on buffer will contain signed regular conversion
1994 * value on 24 most significant bits and corresponding channel on 3 least
1995 * significant bits.
1996 * @param hdfsdm_filter DFSDM filter handle.
1997 * @param pData The destination buffer address.
1998 * @param Length The length of data to be transferred from DFSDM filter to memory.
1999 * @retval HAL status
2001 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
2002 int32_t *pData,
2003 uint32_t Length)
2005 HAL_StatusTypeDef status = HAL_OK;
2007 /* Check parameters */
2008 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2010 /* Check destination address and length */
2011 if((pData == NULL) || (Length == 0))
2013 status = HAL_ERROR;
2015 /* Check that DMA is enabled for regular conversion */
2016 else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_RDMAEN) != DFSDM_FLTCR1_RDMAEN)
2018 status = HAL_ERROR;
2020 /* Check parameters compatibility */
2021 else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
2022 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
2023 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_NORMAL) && \
2024 (Length != 1))
2026 status = HAL_ERROR;
2028 else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
2029 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
2030 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR))
2032 status = HAL_ERROR;
2034 /* Check DFSDM filter state */
2035 else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
2036 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
2038 /* Set callbacks on DMA handler */
2039 hdfsdm_filter->hdmaReg->XferCpltCallback = DFSDM_DMARegularConvCplt;
2040 hdfsdm_filter->hdmaReg->XferErrorCallback = DFSDM_DMAError;
2041 hdfsdm_filter->hdmaReg->XferHalfCpltCallback = (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR) ?\
2042 DFSDM_DMARegularHalfConvCplt : NULL;
2044 /* Start DMA in interrupt mode */
2045 if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaReg, (uint32_t)&hdfsdm_filter->Instance->FLTRDATAR, \
2046 (uint32_t) pData, Length) != HAL_OK)
2048 /* Set DFSDM filter in error state */
2049 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
2050 status = HAL_ERROR;
2052 else
2054 /* Start regular conversion */
2055 DFSDM_RegConvStart(hdfsdm_filter);
2058 else
2060 status = HAL_ERROR;
2062 /* Return function status */
2063 return status;
2067 * @brief This function allows to start regular conversion in DMA mode and to get
2068 * only the 16 most significant bits of conversion.
2069 * @note This function should be called only when DFSDM filter instance is
2070 * in idle state or if injected conversion is ongoing.
2071 * Please note that data on buffer will contain signed 16 most significant
2072 * bits of regular conversion.
2073 * @param hdfsdm_filter DFSDM filter handle.
2074 * @param pData The destination buffer address.
2075 * @param Length The length of data to be transferred from DFSDM filter to memory.
2076 * @retval HAL status
2078 HAL_StatusTypeDef HAL_DFSDM_FilterRegularMsbStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
2079 int16_t *pData,
2080 uint32_t Length)
2082 HAL_StatusTypeDef status = HAL_OK;
2084 /* Check parameters */
2085 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2087 /* Check destination address and length */
2088 if((pData == NULL) || (Length == 0))
2090 status = HAL_ERROR;
2092 /* Check that DMA is enabled for regular conversion */
2093 else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_RDMAEN) != DFSDM_FLTCR1_RDMAEN)
2095 status = HAL_ERROR;
2097 /* Check parameters compatibility */
2098 else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
2099 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
2100 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_NORMAL) && \
2101 (Length != 1))
2103 status = HAL_ERROR;
2105 else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
2106 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
2107 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR))
2109 status = HAL_ERROR;
2111 /* Check DFSDM filter state */
2112 else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
2113 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
2115 /* Set callbacks on DMA handler */
2116 hdfsdm_filter->hdmaReg->XferCpltCallback = DFSDM_DMARegularConvCplt;
2117 hdfsdm_filter->hdmaReg->XferErrorCallback = DFSDM_DMAError;
2118 hdfsdm_filter->hdmaReg->XferHalfCpltCallback = (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR) ?\
2119 DFSDM_DMARegularHalfConvCplt : NULL;
2121 /* Start DMA in interrupt mode */
2122 if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaReg, (uint32_t)(&hdfsdm_filter->Instance->FLTRDATAR) + 2, \
2123 (uint32_t) pData, Length) != HAL_OK)
2125 /* Set DFSDM filter in error state */
2126 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
2127 status = HAL_ERROR;
2129 else
2131 /* Start regular conversion */
2132 DFSDM_RegConvStart(hdfsdm_filter);
2135 else
2137 status = HAL_ERROR;
2139 /* Return function status */
2140 return status;
2144 * @brief This function allows to stop regular conversion in DMA mode.
2145 * @note This function should be called only if regular conversion is ongoing.
2146 * @param hdfsdm_filter DFSDM filter handle.
2147 * @retval HAL status
2149 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
2151 HAL_StatusTypeDef status = HAL_OK;
2153 /* Check parameters */
2154 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2156 /* Check DFSDM filter state */
2157 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
2158 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
2160 /* Return error status */
2161 status = HAL_ERROR;
2163 else
2165 /* Stop current DMA transfer */
2166 if(HAL_DMA_Abort(hdfsdm_filter->hdmaReg) != HAL_OK)
2168 /* Set DFSDM filter in error state */
2169 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
2170 status = HAL_ERROR;
2172 else
2174 /* Stop regular conversion */
2175 DFSDM_RegConvStop(hdfsdm_filter);
2178 /* Return function status */
2179 return status;
2183 * @brief This function allows to get regular conversion value.
2184 * @param hdfsdm_filter DFSDM filter handle.
2185 * @param Channel Corresponding channel of regular conversion.
2186 * @retval Regular conversion value
2188 int32_t HAL_DFSDM_FilterGetRegularValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
2189 uint32_t *Channel)
2191 uint32_t reg = 0;
2192 int32_t value = 0;
2194 /* Check parameters */
2195 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2196 assert_param(Channel != NULL);
2198 /* Get value of data register for regular channel */
2199 reg = hdfsdm_filter->Instance->FLTRDATAR;
2201 /* Extract channel and regular conversion value */
2202 *Channel = (reg & DFSDM_FLTRDATAR_RDATACH);
2203 value = ((int32_t)(reg & DFSDM_FLTRDATAR_RDATA) >> DFSDM_FLTRDATAR_RDATA_Pos);
2205 /* return regular conversion value */
2206 return value;
2210 * @brief This function allows to start injected conversion in polling mode.
2211 * @note This function should be called only when DFSDM filter instance is
2212 * in idle state or if regular conversion is ongoing.
2213 * @param hdfsdm_filter DFSDM filter handle.
2214 * @retval HAL status
2216 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
2218 HAL_StatusTypeDef status = HAL_OK;
2220 /* Check parameters */
2221 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2223 /* Check DFSDM filter state */
2224 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
2225 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
2227 /* Start injected conversion */
2228 DFSDM_InjConvStart(hdfsdm_filter);
2230 else
2232 status = HAL_ERROR;
2234 /* Return function status */
2235 return status;
2239 * @brief This function allows to poll for the end of injected conversion.
2240 * @note This function should be called only if injected conversion is ongoing.
2241 * @param hdfsdm_filter DFSDM filter handle.
2242 * @param Timeout Timeout value in milliseconds.
2243 * @retval HAL status
2245 HAL_StatusTypeDef HAL_DFSDM_FilterPollForInjConversion(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
2246 uint32_t Timeout)
2248 uint32_t tickstart;
2250 /* Check parameters */
2251 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2253 /* Check DFSDM filter state */
2254 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
2255 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
2257 /* Return error status */
2258 return HAL_ERROR;
2260 else
2262 /* Get timeout */
2263 tickstart = HAL_GetTick();
2265 /* Wait end of injected conversions */
2266 while((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JEOCF) != DFSDM_FLTISR_JEOCF)
2268 /* Check the Timeout */
2269 if(Timeout != HAL_MAX_DELAY)
2271 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
2273 /* Return timeout status */
2274 return HAL_TIMEOUT;
2278 /* Check if overrun occurs */
2279 if((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JOVRF) == DFSDM_FLTISR_JOVRF)
2281 /* Update error code and call error callback */
2282 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INJECTED_OVERRUN;
2283 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
2284 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
2285 #else
2286 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
2287 #endif
2289 /* Clear injected overrun flag */
2290 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRJOVRF;
2293 /* Update remaining injected conversions */
2294 hdfsdm_filter->InjConvRemaining--;
2295 if(hdfsdm_filter->InjConvRemaining == 0)
2297 /* Update DFSDM filter state only if trigger is software */
2298 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
2300 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \
2301 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG;
2304 /* end of injected sequence, reset the value */
2305 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
2306 hdfsdm_filter->InjectedChannelsNbr : 1;
2309 /* Return function status */
2310 return HAL_OK;
2315 * @brief This function allows to stop injected conversion in polling mode.
2316 * @note This function should be called only if injected conversion is ongoing.
2317 * @param hdfsdm_filter DFSDM filter handle.
2318 * @retval HAL status
2320 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
2322 HAL_StatusTypeDef status = HAL_OK;
2324 /* Check parameters */
2325 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2327 /* Check DFSDM filter state */
2328 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
2329 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
2331 /* Return error status */
2332 status = HAL_ERROR;
2334 else
2336 /* Stop injected conversion */
2337 DFSDM_InjConvStop(hdfsdm_filter);
2339 /* Return function status */
2340 return status;
2344 * @brief This function allows to start injected conversion in interrupt mode.
2345 * @note This function should be called only when DFSDM filter instance is
2346 * in idle state or if regular conversion is ongoing.
2347 * @param hdfsdm_filter DFSDM filter handle.
2348 * @retval HAL status
2350 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
2352 HAL_StatusTypeDef status = HAL_OK;
2354 /* Check parameters */
2355 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2357 /* Check DFSDM filter state */
2358 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
2359 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
2361 /* Enable interrupts for injected conversions */
2362 hdfsdm_filter->Instance->FLTCR2 |= (DFSDM_FLTCR2_JEOCIE | DFSDM_FLTCR2_JOVRIE);
2364 /* Start injected conversion */
2365 DFSDM_InjConvStart(hdfsdm_filter);
2367 else
2369 status = HAL_ERROR;
2371 /* Return function status */
2372 return status;
2376 * @brief This function allows to stop injected conversion in interrupt mode.
2377 * @note This function should be called only if injected conversion is ongoing.
2378 * @param hdfsdm_filter DFSDM filter handle.
2379 * @retval HAL status
2381 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
2383 HAL_StatusTypeDef status = HAL_OK;
2385 /* Check parameters */
2386 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2388 /* Check DFSDM filter state */
2389 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
2390 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
2392 /* Return error status */
2393 status = HAL_ERROR;
2395 else
2397 /* Disable interrupts for injected conversions */
2398 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_JEOCIE | DFSDM_FLTCR2_JOVRIE);
2400 /* Stop injected conversion */
2401 DFSDM_InjConvStop(hdfsdm_filter);
2403 /* Return function status */
2404 return status;
2408 * @brief This function allows to start injected conversion in DMA mode.
2409 * @note This function should be called only when DFSDM filter instance is
2410 * in idle state or if regular conversion is ongoing.
2411 * Please note that data on buffer will contain signed injected conversion
2412 * value on 24 most significant bits and corresponding channel on 3 least
2413 * significant bits.
2414 * @param hdfsdm_filter DFSDM filter handle.
2415 * @param pData The destination buffer address.
2416 * @param Length The length of data to be transferred from DFSDM filter to memory.
2417 * @retval HAL status
2419 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
2420 int32_t *pData,
2421 uint32_t Length)
2423 HAL_StatusTypeDef status = HAL_OK;
2425 /* Check parameters */
2426 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2428 /* Check destination address and length */
2429 if((pData == NULL) || (Length == 0))
2431 status = HAL_ERROR;
2433 /* Check that DMA is enabled for injected conversion */
2434 else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_JDMAEN) != DFSDM_FLTCR1_JDMAEN)
2436 status = HAL_ERROR;
2438 /* Check parameters compatibility */
2439 else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
2440 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_NORMAL) && \
2441 (Length > hdfsdm_filter->InjConvRemaining))
2443 status = HAL_ERROR;
2445 else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
2446 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR))
2448 status = HAL_ERROR;
2450 /* Check DFSDM filter state */
2451 else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
2452 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
2454 /* Set callbacks on DMA handler */
2455 hdfsdm_filter->hdmaInj->XferCpltCallback = DFSDM_DMAInjectedConvCplt;
2456 hdfsdm_filter->hdmaInj->XferErrorCallback = DFSDM_DMAError;
2457 hdfsdm_filter->hdmaInj->XferHalfCpltCallback = (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR) ?\
2458 DFSDM_DMAInjectedHalfConvCplt : NULL;
2460 /* Start DMA in interrupt mode */
2461 if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaInj, (uint32_t)&hdfsdm_filter->Instance->FLTJDATAR, \
2462 (uint32_t) pData, Length) != HAL_OK)
2464 /* Set DFSDM filter in error state */
2465 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
2466 status = HAL_ERROR;
2468 else
2470 /* Start injected conversion */
2471 DFSDM_InjConvStart(hdfsdm_filter);
2474 else
2476 status = HAL_ERROR;
2478 /* Return function status */
2479 return status;
2483 * @brief This function allows to start injected conversion in DMA mode and to get
2484 * only the 16 most significant bits of conversion.
2485 * @note This function should be called only when DFSDM filter instance is
2486 * in idle state or if regular conversion is ongoing.
2487 * Please note that data on buffer will contain signed 16 most significant
2488 * bits of injected conversion.
2489 * @param hdfsdm_filter DFSDM filter handle.
2490 * @param pData The destination buffer address.
2491 * @param Length The length of data to be transferred from DFSDM filter to memory.
2492 * @retval HAL status
2494 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedMsbStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
2495 int16_t *pData,
2496 uint32_t Length)
2498 HAL_StatusTypeDef status = HAL_OK;
2500 /* Check parameters */
2501 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2503 /* Check destination address and length */
2504 if((pData == NULL) || (Length == 0))
2506 status = HAL_ERROR;
2508 /* Check that DMA is enabled for injected conversion */
2509 else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_JDMAEN) != DFSDM_FLTCR1_JDMAEN)
2511 status = HAL_ERROR;
2513 /* Check parameters compatibility */
2514 else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
2515 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_NORMAL) && \
2516 (Length > hdfsdm_filter->InjConvRemaining))
2518 status = HAL_ERROR;
2520 else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
2521 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR))
2523 status = HAL_ERROR;
2525 /* Check DFSDM filter state */
2526 else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
2527 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
2529 /* Set callbacks on DMA handler */
2530 hdfsdm_filter->hdmaInj->XferCpltCallback = DFSDM_DMAInjectedConvCplt;
2531 hdfsdm_filter->hdmaInj->XferErrorCallback = DFSDM_DMAError;
2532 hdfsdm_filter->hdmaInj->XferHalfCpltCallback = (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR) ?\
2533 DFSDM_DMAInjectedHalfConvCplt : NULL;
2535 /* Start DMA in interrupt mode */
2536 if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaInj, (uint32_t)(&hdfsdm_filter->Instance->FLTJDATAR) + 2, \
2537 (uint32_t) pData, Length) != HAL_OK)
2539 /* Set DFSDM filter in error state */
2540 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
2541 status = HAL_ERROR;
2543 else
2545 /* Start injected conversion */
2546 DFSDM_InjConvStart(hdfsdm_filter);
2549 else
2551 status = HAL_ERROR;
2553 /* Return function status */
2554 return status;
2558 * @brief This function allows to stop injected conversion in DMA mode.
2559 * @note This function should be called only if injected conversion is ongoing.
2560 * @param hdfsdm_filter DFSDM filter handle.
2561 * @retval HAL status
2563 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
2565 HAL_StatusTypeDef status = HAL_OK;
2567 /* Check parameters */
2568 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2570 /* Check DFSDM filter state */
2571 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
2572 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
2574 /* Return error status */
2575 status = HAL_ERROR;
2577 else
2579 /* Stop current DMA transfer */
2580 if(HAL_DMA_Abort(hdfsdm_filter->hdmaInj) != HAL_OK)
2582 /* Set DFSDM filter in error state */
2583 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
2584 status = HAL_ERROR;
2586 else
2588 /* Stop regular conversion */
2589 DFSDM_InjConvStop(hdfsdm_filter);
2592 /* Return function status */
2593 return status;
2597 * @brief This function allows to get injected conversion value.
2598 * @param hdfsdm_filter DFSDM filter handle.
2599 * @param Channel Corresponding channel of injected conversion.
2600 * @retval Injected conversion value
2602 int32_t HAL_DFSDM_FilterGetInjectedValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
2603 uint32_t *Channel)
2605 uint32_t reg = 0;
2606 int32_t value = 0;
2608 /* Check parameters */
2609 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2610 assert_param(Channel != NULL);
2612 /* Get value of data register for injected channel */
2613 reg = hdfsdm_filter->Instance->FLTJDATAR;
2615 /* Extract channel and injected conversion value */
2616 *Channel = (reg & DFSDM_FLTJDATAR_JDATACH);
2617 value = ((int32_t)(reg & DFSDM_FLTJDATAR_JDATA) >> DFSDM_FLTJDATAR_JDATA_Pos);
2619 /* return regular conversion value */
2620 return value;
2624 * @brief This function allows to start filter analog watchdog in interrupt mode.
2625 * @param hdfsdm_filter DFSDM filter handle.
2626 * @param awdParam DFSDM filter analog watchdog parameters.
2627 * @retval HAL status
2629 HAL_StatusTypeDef HAL_DFSDM_FilterAwdStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
2630 DFSDM_Filter_AwdParamTypeDef *awdParam)
2632 HAL_StatusTypeDef status = HAL_OK;
2634 /* Check parameters */
2635 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2636 assert_param(IS_DFSDM_FILTER_AWD_DATA_SOURCE(awdParam->DataSource));
2637 assert_param(IS_DFSDM_INJECTED_CHANNEL(awdParam->Channel));
2638 assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam->HighThreshold));
2639 assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam->LowThreshold));
2640 assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam->HighBreakSignal));
2641 assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam->LowBreakSignal));
2643 /* Check DFSDM filter state */
2644 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
2645 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
2647 /* Return error status */
2648 status = HAL_ERROR;
2650 else
2652 /* Set analog watchdog data source */
2653 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_AWFSEL);
2654 hdfsdm_filter->Instance->FLTCR1 |= awdParam->DataSource;
2656 /* Set thresholds and break signals */
2657 hdfsdm_filter->Instance->FLTAWHTR &= ~(DFSDM_FLTAWHTR_AWHT | DFSDM_FLTAWHTR_BKAWH);
2658 hdfsdm_filter->Instance->FLTAWHTR |= (((uint32_t) awdParam->HighThreshold << DFSDM_FLTAWHTR_AWHT_Pos) | \
2659 awdParam->HighBreakSignal);
2660 hdfsdm_filter->Instance->FLTAWLTR &= ~(DFSDM_FLTAWLTR_AWLT | DFSDM_FLTAWLTR_BKAWL);
2661 hdfsdm_filter->Instance->FLTAWLTR |= (((uint32_t) awdParam->LowThreshold << DFSDM_FLTAWLTR_AWLT_Pos) | \
2662 awdParam->LowBreakSignal);
2664 /* Set channels and interrupt for analog watchdog */
2665 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_AWDCH);
2666 hdfsdm_filter->Instance->FLTCR2 |= (((awdParam->Channel & DFSDM_LSB_MASK) << DFSDM_FLTCR2_AWDCH_Pos) | \
2667 DFSDM_FLTCR2_AWDIE);
2669 /* Return function status */
2670 return status;
2674 * @brief This function allows to stop filter analog watchdog in interrupt mode.
2675 * @param hdfsdm_filter DFSDM filter handle.
2676 * @retval HAL status
2678 HAL_StatusTypeDef HAL_DFSDM_FilterAwdStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
2680 HAL_StatusTypeDef status = HAL_OK;
2682 /* Check parameters */
2683 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2685 /* Check DFSDM filter state */
2686 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
2687 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
2689 /* Return error status */
2690 status = HAL_ERROR;
2692 else
2694 /* Reset channels for analog watchdog and deactivate interrupt */
2695 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_AWDCH | DFSDM_FLTCR2_AWDIE);
2697 /* Clear all analog watchdog flags */
2698 hdfsdm_filter->Instance->FLTAWCFR = (DFSDM_FLTAWCFR_CLRAWHTF | DFSDM_FLTAWCFR_CLRAWLTF);
2700 /* Reset thresholds and break signals */
2701 hdfsdm_filter->Instance->FLTAWHTR &= ~(DFSDM_FLTAWHTR_AWHT | DFSDM_FLTAWHTR_BKAWH);
2702 hdfsdm_filter->Instance->FLTAWLTR &= ~(DFSDM_FLTAWLTR_AWLT | DFSDM_FLTAWLTR_BKAWL);
2704 /* Reset analog watchdog data source */
2705 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_AWFSEL);
2707 /* Return function status */
2708 return status;
2712 * @brief This function allows to start extreme detector feature.
2713 * @param hdfsdm_filter DFSDM filter handle.
2714 * @param Channel Channels where extreme detector is enabled.
2715 * This parameter can be a values combination of @ref DFSDM_Channel_Selection.
2716 * @retval HAL status
2718 HAL_StatusTypeDef HAL_DFSDM_FilterExdStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
2719 uint32_t Channel)
2721 HAL_StatusTypeDef status = HAL_OK;
2723 /* Check parameters */
2724 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2725 assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel));
2727 /* Check DFSDM filter state */
2728 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
2729 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
2731 /* Return error status */
2732 status = HAL_ERROR;
2734 else
2736 /* Set channels for extreme detector */
2737 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_EXCH);
2738 hdfsdm_filter->Instance->FLTCR2 |= ((Channel & DFSDM_LSB_MASK) << DFSDM_FLTCR2_EXCH_Pos);
2740 /* Return function status */
2741 return status;
2745 * @brief This function allows to stop extreme detector feature.
2746 * @param hdfsdm_filter DFSDM filter handle.
2747 * @retval HAL status
2749 HAL_StatusTypeDef HAL_DFSDM_FilterExdStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
2751 HAL_StatusTypeDef status = HAL_OK;
2752 __IO uint32_t reg1;
2753 __IO uint32_t reg2;
2755 /* Check parameters */
2756 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2758 /* Check DFSDM filter state */
2759 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
2760 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
2762 /* Return error status */
2763 status = HAL_ERROR;
2765 else
2767 /* Reset channels for extreme detector */
2768 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_EXCH);
2770 /* Clear extreme detector values */
2771 reg1 = hdfsdm_filter->Instance->FLTEXMAX;
2772 reg2 = hdfsdm_filter->Instance->FLTEXMIN;
2773 UNUSED(reg1); /* To avoid GCC warning */
2774 UNUSED(reg2); /* To avoid GCC warning */
2776 /* Return function status */
2777 return status;
2781 * @brief This function allows to get extreme detector maximum value.
2782 * @param hdfsdm_filter DFSDM filter handle.
2783 * @param Channel Corresponding channel.
2784 * @retval Extreme detector maximum value
2785 * This value is between Min_Data = -8388608 and Max_Data = 8388607.
2787 int32_t HAL_DFSDM_FilterGetExdMaxValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
2788 uint32_t *Channel)
2790 uint32_t reg = 0;
2791 int32_t value = 0;
2793 /* Check parameters */
2794 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2795 assert_param(Channel != NULL);
2797 /* Get value of extreme detector maximum register */
2798 reg = hdfsdm_filter->Instance->FLTEXMAX;
2800 /* Extract channel and extreme detector maximum value */
2801 *Channel = (reg & DFSDM_FLTEXMAX_EXMAXCH);
2802 value = ((int32_t)(reg & DFSDM_FLTEXMAX_EXMAX) >> DFSDM_FLTEXMAX_EXMAX_Pos);
2804 /* return extreme detector maximum value */
2805 return value;
2809 * @brief This function allows to get extreme detector minimum value.
2810 * @param hdfsdm_filter DFSDM filter handle.
2811 * @param Channel Corresponding channel.
2812 * @retval Extreme detector minimum value
2813 * This value is between Min_Data = -8388608 and Max_Data = 8388607.
2815 int32_t HAL_DFSDM_FilterGetExdMinValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
2816 uint32_t *Channel)
2818 uint32_t reg = 0;
2819 int32_t value = 0;
2821 /* Check parameters */
2822 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2823 assert_param(Channel != NULL);
2825 /* Get value of extreme detector minimum register */
2826 reg = hdfsdm_filter->Instance->FLTEXMIN;
2828 /* Extract channel and extreme detector minimum value */
2829 *Channel = (reg & DFSDM_FLTEXMIN_EXMINCH);
2830 value = ((int32_t)(reg & DFSDM_FLTEXMIN_EXMIN) >> DFSDM_FLTEXMIN_EXMIN_Pos);
2832 /* return extreme detector minimum value */
2833 return value;
2837 * @brief This function allows to get conversion time value.
2838 * @param hdfsdm_filter DFSDM filter handle.
2839 * @retval Conversion time value
2840 * @note To get time in second, this value has to be divided by DFSDM clock frequency.
2842 uint32_t HAL_DFSDM_FilterGetConvTimeValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
2844 uint32_t reg = 0;
2845 uint32_t value = 0;
2847 /* Check parameters */
2848 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2850 /* Get value of conversion timer register */
2851 reg = hdfsdm_filter->Instance->FLTCNVTIMR;
2853 /* Extract conversion time value */
2854 value = ((reg & DFSDM_FLTCNVTIMR_CNVCNT) >> DFSDM_FLTCNVTIMR_CNVCNT_Pos);
2856 /* return extreme detector minimum value */
2857 return value;
2861 * @brief This function handles the DFSDM interrupts.
2862 * @param hdfsdm_filter DFSDM filter handle.
2863 * @retval None
2865 void HAL_DFSDM_IRQHandler(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
2867 /* Check if overrun occurs during regular conversion */
2868 if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_ROVRF) != 0) && \
2869 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_ROVRIE) != 0))
2871 /* Clear regular overrun flag */
2872 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRROVRF;
2874 /* Update error code */
2875 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_REGULAR_OVERRUN;
2877 /* Call error callback */
2878 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
2879 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
2880 #else
2881 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
2882 #endif
2884 /* Check if overrun occurs during injected conversion */
2885 else if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JOVRF) != 0) && \
2886 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_JOVRIE) != 0))
2888 /* Clear injected overrun flag */
2889 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRJOVRF;
2891 /* Update error code */
2892 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INJECTED_OVERRUN;
2894 /* Call error callback */
2895 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
2896 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
2897 #else
2898 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
2899 #endif
2901 /* Check if end of regular conversion */
2902 else if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_REOCF) != 0) && \
2903 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_REOCIE) != 0))
2905 /* Call regular conversion complete callback */
2906 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
2907 hdfsdm_filter->RegConvCpltCallback(hdfsdm_filter);
2908 #else
2909 HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter);
2910 #endif
2912 /* End of conversion if mode is not continuous and software trigger */
2913 if((hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
2914 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
2916 /* Disable interrupts for regular conversions */
2917 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_REOCIE);
2919 /* Update DFSDM filter state */
2920 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \
2921 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ;
2924 /* Check if end of injected conversion */
2925 else if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JEOCF) != 0) && \
2926 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_JEOCIE) != 0))
2928 /* Call injected conversion complete callback */
2929 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
2930 hdfsdm_filter->InjConvCpltCallback(hdfsdm_filter);
2931 #else
2932 HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter);
2933 #endif
2935 /* Update remaining injected conversions */
2936 hdfsdm_filter->InjConvRemaining--;
2937 if(hdfsdm_filter->InjConvRemaining == 0)
2939 /* End of conversion if trigger is software */
2940 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
2942 /* Disable interrupts for injected conversions */
2943 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_JEOCIE);
2945 /* Update DFSDM filter state */
2946 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \
2947 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG;
2949 /* end of injected sequence, reset the value */
2950 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
2951 hdfsdm_filter->InjectedChannelsNbr : 1;
2954 /* Check if analog watchdog occurs */
2955 else if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_AWDF) != 0) && \
2956 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_AWDIE) != 0))
2958 uint32_t reg = 0;
2959 uint32_t threshold = 0;
2960 uint32_t channel = 0;
2962 /* Get channel and threshold */
2963 reg = hdfsdm_filter->Instance->FLTAWSR;
2964 threshold = ((reg & DFSDM_FLTAWSR_AWLTF) != 0) ? DFSDM_AWD_LOW_THRESHOLD : DFSDM_AWD_HIGH_THRESHOLD;
2965 if(threshold == DFSDM_AWD_HIGH_THRESHOLD)
2967 reg = reg >> DFSDM_FLTAWSR_AWHTF_Pos;
2969 while((reg & 1) == 0)
2971 channel++;
2972 reg = reg >> 1;
2974 /* Clear analog watchdog flag */
2975 hdfsdm_filter->Instance->FLTAWCFR = (threshold == DFSDM_AWD_HIGH_THRESHOLD) ? \
2976 (1 << (DFSDM_FLTAWSR_AWHTF_Pos + channel)) : \
2977 (1 << channel);
2979 /* Call analog watchdog callback */
2980 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
2981 hdfsdm_filter->AwdCallback(hdfsdm_filter, channel, threshold);
2982 #else
2983 HAL_DFSDM_FilterAwdCallback(hdfsdm_filter, channel, threshold);
2984 #endif
2986 /* Check if clock absence occurs */
2987 else if((hdfsdm_filter->Instance == DFSDM1_Filter0) && \
2988 ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_CKABF) != 0) && \
2989 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_CKABIE) != 0))
2991 uint32_t reg = 0;
2992 uint32_t channel = 0;
2994 reg = ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_CKABF) >> DFSDM_FLTISR_CKABF_Pos);
2996 while(channel < DFSDM1_CHANNEL_NUMBER)
2998 /* Check if flag is set and corresponding channel is enabled */
2999 if(((reg & 1) != 0) && (a_dfsdm1ChannelHandle[channel] != NULL))
3001 /* Check clock absence has been enabled for this channel */
3002 if((a_dfsdm1ChannelHandle[channel]->Instance->CHCFGR1 & DFSDM_CHCFGR1_CKABEN) != 0)
3004 /* Clear clock absence flag */
3005 hdfsdm_filter->Instance->FLTICR = (1 << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
3007 /* Call clock absence callback */
3008 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3009 a_dfsdm1ChannelHandle[channel]->CkabCallback(a_dfsdm1ChannelHandle[channel]);
3010 #else
3011 HAL_DFSDM_ChannelCkabCallback(a_dfsdm1ChannelHandle[channel]);
3012 #endif
3015 channel++;
3016 reg = reg >> 1;
3019 /* Check if short circuit detection occurs */
3020 else if((hdfsdm_filter->Instance == DFSDM1_Filter0) && \
3021 ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_SCDF) != 0) && \
3022 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_SCDIE) != 0))
3024 uint32_t reg = 0;
3025 uint32_t channel = 0;
3027 /* Get channel */
3028 reg = ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_SCDF) >> DFSDM_FLTISR_SCDF_Pos);
3029 while((reg & 1) == 0)
3031 channel++;
3032 reg = reg >> 1;
3035 /* Clear short circuit detection flag */
3036 hdfsdm_filter->Instance->FLTICR = (1 << (DFSDM_FLTICR_CLRSCDF_Pos + channel));
3038 /* Call short circuit detection callback */
3039 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3040 a_dfsdm1ChannelHandle[channel]->ScdCallback(a_dfsdm1ChannelHandle[channel]);
3041 #else
3042 HAL_DFSDM_ChannelScdCallback(a_dfsdm1ChannelHandle[channel]);
3043 #endif
3048 * @brief Regular conversion complete callback.
3049 * @note In interrupt mode, user has to read conversion value in this function
3050 * using HAL_DFSDM_FilterGetRegularValue.
3051 * @param hdfsdm_filter DFSDM filter handle.
3052 * @retval None
3054 __weak void HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
3056 /* Prevent unused argument(s) compilation warning */
3057 UNUSED(hdfsdm_filter);
3059 /* NOTE : This function should not be modified, when the callback is needed,
3060 the HAL_DFSDM_FilterRegConvCpltCallback could be implemented in the user file.
3065 * @brief Half regular conversion complete callback.
3066 * @param hdfsdm_filter DFSDM filter handle.
3067 * @retval None
3069 __weak void HAL_DFSDM_FilterRegConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
3071 /* Prevent unused argument(s) compilation warning */
3072 UNUSED(hdfsdm_filter);
3074 /* NOTE : This function should not be modified, when the callback is needed,
3075 the HAL_DFSDM_FilterRegConvHalfCpltCallback could be implemented in the user file.
3080 * @brief Injected conversion complete callback.
3081 * @note In interrupt mode, user has to read conversion value in this function
3082 * using HAL_DFSDM_FilterGetInjectedValue.
3083 * @param hdfsdm_filter DFSDM filter handle.
3084 * @retval None
3086 __weak void HAL_DFSDM_FilterInjConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
3088 /* Prevent unused argument(s) compilation warning */
3089 UNUSED(hdfsdm_filter);
3091 /* NOTE : This function should not be modified, when the callback is needed,
3092 the HAL_DFSDM_FilterInjConvCpltCallback could be implemented in the user file.
3097 * @brief Half injected conversion complete callback.
3098 * @param hdfsdm_filter DFSDM filter handle.
3099 * @retval None
3101 __weak void HAL_DFSDM_FilterInjConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
3103 /* Prevent unused argument(s) compilation warning */
3104 UNUSED(hdfsdm_filter);
3106 /* NOTE : This function should not be modified, when the callback is needed,
3107 the HAL_DFSDM_FilterInjConvHalfCpltCallback could be implemented in the user file.
3112 * @brief Filter analog watchdog callback.
3113 * @param hdfsdm_filter DFSDM filter handle.
3114 * @param Channel Corresponding channel.
3115 * @param Threshold Low or high threshold has been reached.
3116 * @retval None
3118 __weak void HAL_DFSDM_FilterAwdCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
3119 uint32_t Channel, uint32_t Threshold)
3121 /* Prevent unused argument(s) compilation warning */
3122 UNUSED(hdfsdm_filter);
3123 UNUSED(Channel);
3124 UNUSED(Threshold);
3126 /* NOTE : This function should not be modified, when the callback is needed,
3127 the HAL_DFSDM_FilterAwdCallback could be implemented in the user file.
3132 * @brief Error callback.
3133 * @param hdfsdm_filter DFSDM filter handle.
3134 * @retval None
3136 __weak void HAL_DFSDM_FilterErrorCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
3138 /* Prevent unused argument(s) compilation warning */
3139 UNUSED(hdfsdm_filter);
3141 /* NOTE : This function should not be modified, when the callback is needed,
3142 the HAL_DFSDM_FilterErrorCallback could be implemented in the user file.
3147 * @}
3150 /** @defgroup DFSDM_Exported_Functions_Group4_Filter Filter state functions
3151 * @brief Filter state functions
3153 @verbatim
3154 ==============================================================================
3155 ##### Filter state functions #####
3156 ==============================================================================
3157 [..] This section provides functions allowing to:
3158 (+) Get the DFSDM filter state.
3159 (+) Get the DFSDM filter error.
3160 @endverbatim
3161 * @{
3165 * @brief This function allows to get the current DFSDM filter handle state.
3166 * @param hdfsdm_filter DFSDM filter handle.
3167 * @retval DFSDM filter state.
3169 HAL_DFSDM_Filter_StateTypeDef HAL_DFSDM_FilterGetState(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
3171 /* Return DFSDM filter handle state */
3172 return hdfsdm_filter->State;
3176 * @brief This function allows to get the current DFSDM filter error.
3177 * @param hdfsdm_filter DFSDM filter handle.
3178 * @retval DFSDM filter error code.
3180 uint32_t HAL_DFSDM_FilterGetError(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
3182 return hdfsdm_filter->ErrorCode;
3186 * @}
3190 * @}
3192 /* End of exported functions -------------------------------------------------*/
3194 /* Private functions ---------------------------------------------------------*/
3195 /** @addtogroup DFSDM_Private_Functions DFSDM Private Functions
3196 * @{
3200 * @brief DMA half transfer complete callback for regular conversion.
3201 * @param hdma DMA handle.
3202 * @retval None
3204 static void DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef *hdma)
3206 /* Get DFSDM filter handle */
3207 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
3209 /* Call regular half conversion complete callback */
3210 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3211 hdfsdm_filter->RegConvHalfCpltCallback(hdfsdm_filter);
3212 #else
3213 HAL_DFSDM_FilterRegConvHalfCpltCallback(hdfsdm_filter);
3214 #endif
3218 * @brief DMA transfer complete callback for regular conversion.
3219 * @param hdma DMA handle.
3220 * @retval None
3222 static void DFSDM_DMARegularConvCplt(DMA_HandleTypeDef *hdma)
3224 /* Get DFSDM filter handle */
3225 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
3227 /* Call regular conversion complete callback */
3228 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3229 hdfsdm_filter->RegConvCpltCallback(hdfsdm_filter);
3230 #else
3231 HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter);
3232 #endif
3236 * @brief DMA half transfer complete callback for injected conversion.
3237 * @param hdma DMA handle.
3238 * @retval None
3240 static void DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef *hdma)
3242 /* Get DFSDM filter handle */
3243 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
3245 /* Call injected half conversion complete callback */
3246 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3247 hdfsdm_filter->InjConvHalfCpltCallback(hdfsdm_filter);
3248 #else
3249 HAL_DFSDM_FilterInjConvHalfCpltCallback(hdfsdm_filter);
3250 #endif
3254 * @brief DMA transfer complete callback for injected conversion.
3255 * @param hdma DMA handle.
3256 * @retval None
3258 static void DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef *hdma)
3260 /* Get DFSDM filter handle */
3261 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
3263 /* Call injected conversion complete callback */
3264 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3265 hdfsdm_filter->InjConvCpltCallback(hdfsdm_filter);
3266 #else
3267 HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter);
3268 #endif
3272 * @brief DMA error callback.
3273 * @param hdma DMA handle.
3274 * @retval None
3276 static void DFSDM_DMAError(DMA_HandleTypeDef *hdma)
3278 /* Get DFSDM filter handle */
3279 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
3281 /* Update error code */
3282 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_DMA;
3284 /* Call error callback */
3285 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3286 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
3287 #else
3288 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
3289 #endif
3293 * @brief This function allows to get the number of injected channels.
3294 * @param Channels bitfield of injected channels.
3295 * @retval Number of injected channels.
3297 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels)
3299 uint32_t nbChannels = 0;
3300 uint32_t tmp;
3302 /* Get the number of channels from bitfield */
3303 tmp = (uint32_t) (Channels & DFSDM_LSB_MASK);
3304 while(tmp != 0)
3306 if((tmp & 1) != 0)
3308 nbChannels++;
3310 tmp = (uint32_t) (tmp >> 1);
3312 return nbChannels;
3316 * @brief This function allows to get the channel number from channel instance.
3317 * @param Instance DFSDM channel instance.
3318 * @retval Channel number.
3320 static uint32_t DFSDM_GetChannelFromInstance(DFSDM_Channel_TypeDef* Instance)
3322 uint32_t channel = 0xFF;
3324 /* Get channel from instance */
3325 if(Instance == DFSDM1_Channel0)
3327 channel = 0;
3329 else if(Instance == DFSDM1_Channel1)
3331 channel = 1;
3333 else if(Instance == DFSDM1_Channel2)
3335 channel = 2;
3337 else if(Instance == DFSDM1_Channel3)
3339 channel = 3;
3341 else if(Instance == DFSDM1_Channel4)
3343 channel = 4;
3345 else if(Instance == DFSDM1_Channel5)
3347 channel = 5;
3349 else if(Instance == DFSDM1_Channel6)
3351 channel = 6;
3353 else if(Instance == DFSDM1_Channel7)
3355 channel = 7;
3358 return channel;
3362 * @brief This function allows to really start regular conversion.
3363 * @param hdfsdm_filter DFSDM filter handle.
3364 * @retval None
3366 static void DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef* hdfsdm_filter)
3368 /* Check regular trigger */
3369 if(hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER)
3371 /* Software start of regular conversion */
3372 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
3374 else /* synchronous trigger */
3376 /* Disable DFSDM filter */
3377 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
3379 /* Set RSYNC bit in DFSDM_FLTCR1 register */
3380 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSYNC;
3382 /* Enable DFSDM filter */
3383 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
3385 /* If injected conversion was in progress, restart it */
3386 if(hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ)
3388 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
3390 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART;
3392 /* Update remaining injected conversions */
3393 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
3394 hdfsdm_filter->InjectedChannelsNbr : 1;
3397 /* Update DFSDM filter state */
3398 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) ? \
3399 HAL_DFSDM_FILTER_STATE_REG : HAL_DFSDM_FILTER_STATE_REG_INJ;
3403 * @brief This function allows to really stop regular conversion.
3404 * @param hdfsdm_filter DFSDM filter handle.
3405 * @retval None
3407 static void DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef* hdfsdm_filter)
3409 /* Disable DFSDM filter */
3410 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
3412 /* If regular trigger was synchronous, reset RSYNC bit in DFSDM_FLTCR1 register */
3413 if(hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SYNC_TRIGGER)
3415 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RSYNC);
3418 /* Enable DFSDM filter */
3419 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
3421 /* If injected conversion was in progress, restart it */
3422 if(hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG_INJ)
3424 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
3426 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART;
3428 /* Update remaining injected conversions */
3429 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
3430 hdfsdm_filter->InjectedChannelsNbr : 1;
3433 /* Update DFSDM filter state */
3434 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \
3435 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ;
3439 * @brief This function allows to really start injected conversion.
3440 * @param hdfsdm_filter DFSDM filter handle.
3441 * @retval None
3443 static void DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef* hdfsdm_filter)
3445 /* Check injected trigger */
3446 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
3448 /* Software start of injected conversion */
3449 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART;
3451 else /* external or synchronous trigger */
3453 /* Disable DFSDM filter */
3454 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
3456 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SYNC_TRIGGER)
3458 /* Set JSYNC bit in DFSDM_FLTCR1 register */
3459 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSYNC;
3461 else /* external trigger */
3463 /* Set JEXTEN[1:0] bits in DFSDM_FLTCR1 register */
3464 hdfsdm_filter->Instance->FLTCR1 |= hdfsdm_filter->ExtTriggerEdge;
3467 /* Enable DFSDM filter */
3468 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
3470 /* If regular conversion was in progress, restart it */
3471 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) && \
3472 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
3474 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
3477 /* Update DFSDM filter state */
3478 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) ? \
3479 HAL_DFSDM_FILTER_STATE_INJ : HAL_DFSDM_FILTER_STATE_REG_INJ;
3483 * @brief This function allows to really stop injected conversion.
3484 * @param hdfsdm_filter DFSDM filter handle.
3485 * @retval None
3487 static void DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef* hdfsdm_filter)
3489 /* Disable DFSDM filter */
3490 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
3492 /* If injected trigger was synchronous, reset JSYNC bit in DFSDM_FLTCR1 register */
3493 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SYNC_TRIGGER)
3495 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSYNC);
3497 else if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_EXT_TRIGGER)
3499 /* Reset JEXTEN[1:0] bits in DFSDM_FLTCR1 register */
3500 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JEXTEN);
3503 /* Enable DFSDM filter */
3504 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
3506 /* If regular conversion was in progress, restart it */
3507 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG_INJ) && \
3508 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
3510 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
3513 /* Update remaining injected conversions */
3514 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
3515 hdfsdm_filter->InjectedChannelsNbr : 1;
3517 /* Update DFSDM filter state */
3518 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \
3519 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG;
3523 * @}
3525 /* End of private functions --------------------------------------------------*/
3528 * @}
3530 #endif /* STM32F767xx || STM32F769xx || STM32F777xx || STM32F779xx */
3531 #endif /* HAL_DFSDM_MODULE_ENABLED */
3533 * @}
3536 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/