2 ******************************************************************************
\r
3 * @file stm32l4xx_hal_dfsdm.c
\r
4 * @author MCD Application Team
\r
5 * @brief This file provides firmware functions to manage the following
\r
6 * functionalities of the Digital Filter for Sigma-Delta Modulators
\r
7 * (DFSDM) peripherals:
\r
8 * + Initialization and configuration of channels and filters
\r
9 * + Regular channels configuration
\r
10 * + Injected channels configuration
\r
11 * + Regular/Injected Channels DMA Configuration
\r
12 * + Interrupts and flags management
\r
13 * + Analog watchdog feature
\r
14 * + Short-circuit detector feature
\r
15 * + Extremes detector feature
\r
16 * + Clock absence detector feature
\r
17 * + Break generation on analog watchdog or short-circuit event
\r
20 ==============================================================================
\r
21 ##### How to use this driver #####
\r
22 ==============================================================================
\r
24 *** Channel initialization ***
\r
25 ==============================
\r
27 (#) User has first to initialize channels (before filters initialization).
\r
28 (#) As prerequisite, fill in the HAL_DFSDM_ChannelMspInit() :
\r
29 (++) Enable DFSDMz clock interface with __HAL_RCC_DFSDMz_CLK_ENABLE().
\r
30 (++) Enable the clocks for the DFSDMz GPIOS with __HAL_RCC_GPIOx_CLK_ENABLE().
\r
31 (++) Configure these DFSDMz pins in alternate mode using HAL_GPIO_Init().
\r
32 (++) If interrupt mode is used, enable and configure DFSDMz_FLT0 global
\r
33 interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
\r
34 (#) Configure the output clock, input, serial interface, analog watchdog,
\r
35 offset and data right bit shift parameters for this channel using the
\r
36 HAL_DFSDM_ChannelInit() function.
\r
38 *** Channel clock absence detector ***
\r
39 ======================================
\r
41 (#) Start clock absence detector using HAL_DFSDM_ChannelCkabStart() or
\r
42 HAL_DFSDM_ChannelCkabStart_IT().
\r
43 (#) In polling mode, use HAL_DFSDM_ChannelPollForCkab() to detect the clock
\r
45 (#) In interrupt mode, HAL_DFSDM_ChannelCkabCallback() will be called if
\r
46 clock absence is detected.
\r
47 (#) Stop clock absence detector using HAL_DFSDM_ChannelCkabStop() or
\r
48 HAL_DFSDM_ChannelCkabStop_IT().
\r
49 (#) Please note that the same mode (polling or interrupt) has to be used
\r
50 for all channels because the channels are sharing the same interrupt.
\r
51 (#) Please note also that in interrupt mode, if clock absence detector is
\r
52 stopped for one channel, interrupt will be disabled for all channels.
\r
54 *** Channel short circuit detector ***
\r
55 ======================================
\r
57 (#) Start short circuit detector using HAL_DFSDM_ChannelScdStart() or
\r
58 or HAL_DFSDM_ChannelScdStart_IT().
\r
59 (#) In polling mode, use HAL_DFSDM_ChannelPollForScd() to detect short
\r
61 (#) In interrupt mode, HAL_DFSDM_ChannelScdCallback() will be called if
\r
62 short circuit is detected.
\r
63 (#) Stop short circuit detector using HAL_DFSDM_ChannelScdStop() or
\r
64 or HAL_DFSDM_ChannelScdStop_IT().
\r
65 (#) Please note that the same mode (polling or interrupt) has to be used
\r
66 for all channels because the channels are sharing the same interrupt.
\r
67 (#) Please note also that in interrupt mode, if short circuit detector is
\r
68 stopped for one channel, interrupt will be disabled for all channels.
\r
70 *** Channel analog watchdog value ***
\r
71 =====================================
\r
73 (#) Get analog watchdog filter value of a channel using
\r
74 HAL_DFSDM_ChannelGetAwdValue().
\r
76 *** Channel offset value ***
\r
77 =====================================
\r
79 (#) Modify offset value of a channel using HAL_DFSDM_ChannelModifyOffset().
\r
81 *** Filter initialization ***
\r
82 =============================
\r
84 (#) After channel initialization, user has to init filters.
\r
85 (#) As prerequisite, fill in the HAL_DFSDM_FilterMspInit() :
\r
86 (++) If interrupt mode is used , enable and configure DFSDMz_FLTx global
\r
87 interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
\r
88 Please note that DFSDMz_FLT0 global interrupt could be already
\r
89 enabled if interrupt is used for channel.
\r
90 (++) If DMA mode is used, configure DMA with HAL_DMA_Init() and link it
\r
91 with DFSDMz filter handle using __HAL_LINKDMA().
\r
92 (#) Configure the regular conversion, injected conversion and filter
\r
93 parameters for this filter using the HAL_DFSDM_FilterInit() function.
\r
95 *** Filter regular channel conversion ***
\r
96 =========================================
\r
98 (#) Select regular channel and enable/disable continuous mode using
\r
99 HAL_DFSDM_FilterConfigRegChannel().
\r
100 (#) Start regular conversion using HAL_DFSDM_FilterRegularStart(),
\r
101 HAL_DFSDM_FilterRegularStart_IT(), HAL_DFSDM_FilterRegularStart_DMA() or
\r
102 HAL_DFSDM_FilterRegularMsbStart_DMA().
\r
103 (#) In polling mode, use HAL_DFSDM_FilterPollForRegConversion() to detect
\r
104 the end of regular conversion.
\r
105 (#) In interrupt mode, HAL_DFSDM_FilterRegConvCpltCallback() will be called
\r
106 at the end of regular conversion.
\r
107 (#) Get value of regular conversion and corresponding channel using
\r
108 HAL_DFSDM_FilterGetRegularValue().
\r
109 (#) In DMA mode, HAL_DFSDM_FilterRegConvHalfCpltCallback() and
\r
110 HAL_DFSDM_FilterRegConvCpltCallback() will be called respectively at the
\r
111 half transfer and at the transfer complete. Please note that
\r
112 HAL_DFSDM_FilterRegConvHalfCpltCallback() will be called only in DMA
\r
114 (#) Stop regular conversion using HAL_DFSDM_FilterRegularStop(),
\r
115 HAL_DFSDM_FilterRegularStop_IT() or HAL_DFSDM_FilterRegularStop_DMA().
\r
117 *** Filter injected channels conversion ***
\r
118 ===========================================
\r
120 (#) Select injected channels using HAL_DFSDM_FilterConfigInjChannel().
\r
121 (#) Start injected conversion using HAL_DFSDM_FilterInjectedStart(),
\r
122 HAL_DFSDM_FilterInjectedStart_IT(), HAL_DFSDM_FilterInjectedStart_DMA() or
\r
123 HAL_DFSDM_FilterInjectedMsbStart_DMA().
\r
124 (#) In polling mode, use HAL_DFSDM_FilterPollForInjConversion() to detect
\r
125 the end of injected conversion.
\r
126 (#) In interrupt mode, HAL_DFSDM_FilterInjConvCpltCallback() will be called
\r
127 at the end of injected conversion.
\r
128 (#) Get value of injected conversion and corresponding channel using
\r
129 HAL_DFSDM_FilterGetInjectedValue().
\r
130 (#) In DMA mode, HAL_DFSDM_FilterInjConvHalfCpltCallback() and
\r
131 HAL_DFSDM_FilterInjConvCpltCallback() will be called respectively at the
\r
132 half transfer and at the transfer complete. Please note that
\r
133 HAL_DFSDM_FilterInjConvCpltCallback() will be called only in DMA
\r
135 (#) Stop injected conversion using HAL_DFSDM_FilterInjectedStop(),
\r
136 HAL_DFSDM_FilterInjectedStop_IT() or HAL_DFSDM_FilterInjectedStop_DMA().
\r
138 *** Filter analog watchdog ***
\r
139 ==============================
\r
141 (#) Start filter analog watchdog using HAL_DFSDM_FilterAwdStart_IT().
\r
142 (#) HAL_DFSDM_FilterAwdCallback() will be called if analog watchdog occurs.
\r
143 (#) Stop filter analog watchdog using HAL_DFSDM_FilterAwdStop_IT().
\r
145 *** Filter extreme detector ***
\r
146 ===============================
\r
148 (#) Start filter extreme detector using HAL_DFSDM_FilterExdStart().
\r
149 (#) Get extreme detector maximum value using HAL_DFSDM_FilterGetExdMaxValue().
\r
150 (#) Get extreme detector minimum value using HAL_DFSDM_FilterGetExdMinValue().
\r
151 (#) Start filter extreme detector using HAL_DFSDM_FilterExdStop().
\r
153 *** Filter conversion time ***
\r
154 ==============================
\r
156 (#) Get conversion time value using HAL_DFSDM_FilterGetConvTimeValue().
\r
158 *** Callback registration ***
\r
159 =============================
\r
161 The compilation define USE_HAL_DFSDM_REGISTER_CALLBACKS when set to 1
\r
162 allows the user to configure dynamically the driver callbacks.
\r
163 Use functions HAL_DFSDM_Channel_RegisterCallback(),
\r
164 HAL_DFSDM_Filter_RegisterCallback() or
\r
165 HAL_DFSDM_Filter_RegisterAwdCallback() to register a user callback.
\r
168 Function HAL_DFSDM_Channel_RegisterCallback() allows to register
\r
169 following callbacks:
\r
170 (+) CkabCallback : DFSDM channel clock absence detection callback.
\r
171 (+) ScdCallback : DFSDM channel short circuit detection callback.
\r
172 (+) MspInitCallback : DFSDM channel MSP init callback.
\r
173 (+) MspDeInitCallback : DFSDM channel MSP de-init callback.
\r
175 This function takes as parameters the HAL peripheral handle, the Callback ID
\r
176 and a pointer to the user callback function.
\r
179 Function HAL_DFSDM_Filter_RegisterCallback() allows to register
\r
180 following callbacks:
\r
181 (+) RegConvCpltCallback : DFSDM filter regular conversion complete callback.
\r
182 (+) RegConvHalfCpltCallback : DFSDM filter half regular conversion complete callback.
\r
183 (+) InjConvCpltCallback : DFSDM filter injected conversion complete callback.
\r
184 (+) InjConvHalfCpltCallback : DFSDM filter half injected conversion complete callback.
\r
185 (+) ErrorCallback : DFSDM filter error callback.
\r
186 (+) MspInitCallback : DFSDM filter MSP init callback.
\r
187 (+) MspDeInitCallback : DFSDM filter MSP de-init callback.
\r
189 This function takes as parameters the HAL peripheral handle, the Callback ID
\r
190 and a pointer to the user callback function.
\r
193 For specific DFSDM filter analog watchdog callback use dedicated register callback:
\r
194 HAL_DFSDM_Filter_RegisterAwdCallback().
\r
197 Use functions HAL_DFSDM_Channel_UnRegisterCallback() or
\r
198 HAL_DFSDM_Filter_UnRegisterCallback() to reset a callback to the default
\r
202 HAL_DFSDM_Channel_UnRegisterCallback() takes as parameters the HAL peripheral handle,
\r
203 and the Callback ID.
\r
205 This function allows to reset following callbacks:
\r
206 (+) CkabCallback : DFSDM channel clock absence detection callback.
\r
207 (+) ScdCallback : DFSDM channel short circuit detection callback.
\r
208 (+) MspInitCallback : DFSDM channel MSP init callback.
\r
209 (+) MspDeInitCallback : DFSDM channel MSP de-init callback.
\r
212 HAL_DFSDM_Filter_UnRegisterCallback() takes as parameters the HAL peripheral handle,
\r
213 and the Callback ID.
\r
215 This function allows to reset following callbacks:
\r
216 (+) RegConvCpltCallback : DFSDM filter regular conversion complete callback.
\r
217 (+) RegConvHalfCpltCallback : DFSDM filter half regular conversion complete callback.
\r
218 (+) InjConvCpltCallback : DFSDM filter injected conversion complete callback.
\r
219 (+) InjConvHalfCpltCallback : DFSDM filter half injected conversion complete callback.
\r
220 (+) ErrorCallback : DFSDM filter error callback.
\r
221 (+) MspInitCallback : DFSDM filter MSP init callback.
\r
222 (+) MspDeInitCallback : DFSDM filter MSP de-init callback.
\r
225 For specific DFSDM filter analog watchdog callback use dedicated unregister callback:
\r
226 HAL_DFSDM_Filter_UnRegisterAwdCallback().
\r
229 By default, after the call of init function and if the state is RESET
\r
230 all callbacks are reset to the corresponding legacy weak functions:
\r
231 examples HAL_DFSDM_ChannelScdCallback(), HAL_DFSDM_FilterErrorCallback().
\r
232 Exception done for MspInit and MspDeInit callbacks that are respectively
\r
233 reset to the legacy weak functions in the init and de-init only when these
\r
234 callbacks are null (not registered beforehand).
\r
235 If not, MspInit or MspDeInit are not null, the init and de-init keep and use
\r
236 the user MspInit/MspDeInit callbacks (registered beforehand)
\r
239 Callbacks can be registered/unregistered in READY state only.
\r
240 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
\r
241 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
\r
242 during the init/de-init.
\r
243 In that case first register the MspInit/MspDeInit user callbacks using
\r
244 HAL_DFSDM_Channel_RegisterCallback() or
\r
245 HAL_DFSDM_Filter_RegisterCallback() before calling init or de-init function.
\r
248 When The compilation define USE_HAL_DFSDM_REGISTER_CALLBACKS is set to 0 or
\r
249 not defined, the callback registering feature is not available
\r
250 and weak callbacks are used.
\r
253 ******************************************************************************
\r
256 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
257 * All rights reserved.</center></h2>
\r
259 * This software component is licensed by ST under BSD 3-Clause license,
\r
260 * the "License"; You may not use this file except in compliance with the
\r
261 * License. You may obtain a copy of the License at:
\r
262 * opensource.org/licenses/BSD-3-Clause
\r
264 ******************************************************************************
\r
267 /* Includes ------------------------------------------------------------------*/
\r
268 #include "stm32l4xx_hal.h"
\r
270 /** @addtogroup STM32L4xx_HAL_Driver
\r
273 #ifdef HAL_DFSDM_MODULE_ENABLED
\r
275 #if defined(STM32L451xx) || defined(STM32L452xx) || defined(STM32L462xx) || \
\r
276 defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) || \
\r
277 defined(STM32L496xx) || defined(STM32L4A6xx) || \
\r
278 defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
\r
280 /** @defgroup DFSDM DFSDM
\r
281 * @brief DFSDM HAL driver module
\r
285 /* Private typedef -----------------------------------------------------------*/
\r
286 /* Private define ------------------------------------------------------------*/
\r
287 /** @defgroup DFSDM_Private_Define DFSDM Private Define
\r
290 #define DFSDM_FLTCR1_MSB_RCH_OFFSET 8
\r
291 #define DFSDM_MSB_MASK 0xFFFF0000U
\r
292 #define DFSDM_LSB_MASK 0x0000FFFFU
\r
293 #define DFSDM_CKAB_TIMEOUT 5000U
\r
294 #if defined(STM32L451xx) || defined(STM32L452xx) || defined(STM32L462xx)
\r
295 #define DFSDM1_CHANNEL_NUMBER 4U
\r
296 #else /* STM32L451xx || STM32L452xx || STM32L462xx */
\r
297 #define DFSDM1_CHANNEL_NUMBER 8U
\r
298 #endif /* STM32L451xx || STM32L452xx || STM32L462xx */
\r
303 /* Private macro -------------------------------------------------------------*/
\r
304 /* Private variables ---------------------------------------------------------*/
\r
305 /** @defgroup DFSDM_Private_Variables DFSDM Private Variables
\r
308 static __IO uint32_t v_dfsdm1ChannelCounter = 0;
\r
309 static DFSDM_Channel_HandleTypeDef *a_dfsdm1ChannelHandle[DFSDM1_CHANNEL_NUMBER] = {NULL};
\r
314 /* Private function prototypes -----------------------------------------------*/
\r
315 /** @defgroup DFSDM_Private_Functions DFSDM Private Functions
\r
318 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels);
\r
319 static uint32_t DFSDM_GetChannelFromInstance(const DFSDM_Channel_TypeDef *Instance);
\r
320 static void DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
\r
321 static void DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
\r
322 static void DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
\r
323 static void DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
\r
324 static void DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef *hdma);
\r
325 static void DFSDM_DMARegularConvCplt(DMA_HandleTypeDef *hdma);
\r
326 static void DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef *hdma);
\r
327 static void DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef *hdma);
\r
328 static void DFSDM_DMAError(DMA_HandleTypeDef *hdma);
\r
333 /* Exported functions --------------------------------------------------------*/
\r
334 /** @defgroup DFSDM_Exported_Functions DFSDM Exported Functions
\r
338 /** @defgroup DFSDM_Exported_Functions_Group1_Channel Channel initialization and de-initialization functions
\r
339 * @brief Channel initialization and de-initialization functions
\r
342 ==============================================================================
\r
343 ##### Channel initialization and de-initialization functions #####
\r
344 ==============================================================================
\r
345 [..] This section provides functions allowing to:
\r
346 (+) Initialize the DFSDM channel.
\r
347 (+) De-initialize the DFSDM channel.
\r
353 * @brief Initialize the DFSDM channel according to the specified parameters
\r
354 * in the DFSDM_ChannelInitTypeDef structure and initialize the associated handle.
\r
355 * @param hdfsdm_channel DFSDM channel handle.
\r
356 * @retval HAL status.
\r
358 HAL_StatusTypeDef HAL_DFSDM_ChannelInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
360 /* Check DFSDM Channel handle */
\r
361 if (hdfsdm_channel == NULL)
\r
366 /* Check parameters */
\r
367 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
\r
368 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_channel->Init.OutputClock.Activation));
\r
369 assert_param(IS_DFSDM_CHANNEL_INPUT(hdfsdm_channel->Init.Input.Multiplexer));
\r
370 assert_param(IS_DFSDM_CHANNEL_DATA_PACKING(hdfsdm_channel->Init.Input.DataPacking));
\r
371 assert_param(IS_DFSDM_CHANNEL_INPUT_PINS(hdfsdm_channel->Init.Input.Pins));
\r
372 assert_param(IS_DFSDM_CHANNEL_SERIAL_INTERFACE_TYPE(hdfsdm_channel->Init.SerialInterface.Type));
\r
373 assert_param(IS_DFSDM_CHANNEL_SPI_CLOCK(hdfsdm_channel->Init.SerialInterface.SpiClock));
\r
374 assert_param(IS_DFSDM_CHANNEL_FILTER_ORDER(hdfsdm_channel->Init.Awd.FilterOrder));
\r
375 assert_param(IS_DFSDM_CHANNEL_FILTER_OVS_RATIO(hdfsdm_channel->Init.Awd.Oversampling));
\r
376 assert_param(IS_DFSDM_CHANNEL_OFFSET(hdfsdm_channel->Init.Offset));
\r
377 assert_param(IS_DFSDM_CHANNEL_RIGHT_BIT_SHIFT(hdfsdm_channel->Init.RightBitShift));
\r
379 /* Check that channel has not been already initialized */
\r
380 if (a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] != NULL)
\r
385 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
386 /* Reset callback pointers to the weak predefined callbacks */
\r
387 hdfsdm_channel->CkabCallback = HAL_DFSDM_ChannelCkabCallback;
\r
388 hdfsdm_channel->ScdCallback = HAL_DFSDM_ChannelScdCallback;
\r
390 /* Call MSP init function */
\r
391 if (hdfsdm_channel->MspInitCallback == NULL)
\r
393 hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit;
\r
395 hdfsdm_channel->MspInitCallback(hdfsdm_channel);
\r
397 /* Call MSP init function */
\r
398 HAL_DFSDM_ChannelMspInit(hdfsdm_channel);
\r
401 /* Update the channel counter */
\r
402 v_dfsdm1ChannelCounter++;
\r
404 /* Configure output serial clock and enable global DFSDM interface only for first channel */
\r
405 if (v_dfsdm1ChannelCounter == 1U)
\r
407 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK(hdfsdm_channel->Init.OutputClock.Selection));
\r
408 /* Set the output serial clock source */
\r
409 DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTSRC);
\r
410 DFSDM1_Channel0->CHCFGR1 |= hdfsdm_channel->Init.OutputClock.Selection;
\r
412 /* Reset clock divider */
\r
413 DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTDIV);
\r
414 if (hdfsdm_channel->Init.OutputClock.Activation == ENABLE)
\r
416 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK_DIVIDER(hdfsdm_channel->Init.OutputClock.Divider));
\r
417 /* Set the output clock divider */
\r
418 DFSDM1_Channel0->CHCFGR1 |= (uint32_t)((hdfsdm_channel->Init.OutputClock.Divider - 1U) <<
\r
419 DFSDM_CHCFGR1_CKOUTDIV_Pos);
\r
422 /* enable the DFSDM global interface */
\r
423 DFSDM1_Channel0->CHCFGR1 |= DFSDM_CHCFGR1_DFSDMEN;
\r
426 /* Set channel input parameters */
\r
427 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_DATPACK | DFSDM_CHCFGR1_DATMPX |
\r
428 DFSDM_CHCFGR1_CHINSEL);
\r
429 hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.Input.Multiplexer |
\r
430 hdfsdm_channel->Init.Input.DataPacking |
\r
431 hdfsdm_channel->Init.Input.Pins);
\r
433 /* Set serial interface parameters */
\r
434 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SITP | DFSDM_CHCFGR1_SPICKSEL);
\r
435 hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.SerialInterface.Type |
\r
436 hdfsdm_channel->Init.SerialInterface.SpiClock);
\r
438 /* Set analog watchdog parameters */
\r
439 hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_AWFORD | DFSDM_CHAWSCDR_AWFOSR);
\r
440 hdfsdm_channel->Instance->CHAWSCDR |= (hdfsdm_channel->Init.Awd.FilterOrder |
\r
441 ((hdfsdm_channel->Init.Awd.Oversampling - 1U) << DFSDM_CHAWSCDR_AWFOSR_Pos));
\r
443 /* Set channel offset and right bit shift */
\r
444 hdfsdm_channel->Instance->CHCFGR2 &= ~(DFSDM_CHCFGR2_OFFSET | DFSDM_CHCFGR2_DTRBS);
\r
445 hdfsdm_channel->Instance->CHCFGR2 |= (((uint32_t) hdfsdm_channel->Init.Offset << DFSDM_CHCFGR2_OFFSET_Pos) |
\r
446 (hdfsdm_channel->Init.RightBitShift << DFSDM_CHCFGR2_DTRBS_Pos));
\r
448 /* Enable DFSDM channel */
\r
449 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CHEN;
\r
451 /* Set DFSDM Channel to ready state */
\r
452 hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_READY;
\r
454 /* Store channel handle in DFSDM channel handle table */
\r
455 a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] = hdfsdm_channel;
\r
461 * @brief De-initialize the DFSDM channel.
\r
462 * @param hdfsdm_channel DFSDM channel handle.
\r
463 * @retval HAL status.
\r
465 HAL_StatusTypeDef HAL_DFSDM_ChannelDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
467 /* Check DFSDM Channel handle */
\r
468 if (hdfsdm_channel == NULL)
\r
473 /* Check parameters */
\r
474 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
\r
476 /* Check that channel has not been already deinitialized */
\r
477 if (a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] == NULL)
\r
482 /* Disable the DFSDM channel */
\r
483 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CHEN);
\r
485 /* Update the channel counter */
\r
486 v_dfsdm1ChannelCounter--;
\r
488 /* Disable global DFSDM at deinit of last channel */
\r
489 if (v_dfsdm1ChannelCounter == 0U)
\r
491 DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_DFSDMEN);
\r
494 /* Call MSP deinit function */
\r
495 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
496 if (hdfsdm_channel->MspDeInitCallback == NULL)
\r
498 hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit;
\r
500 hdfsdm_channel->MspDeInitCallback(hdfsdm_channel);
\r
502 HAL_DFSDM_ChannelMspDeInit(hdfsdm_channel);
\r
505 /* Set DFSDM Channel in reset state */
\r
506 hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_RESET;
\r
508 /* Reset channel handle in DFSDM channel handle table */
\r
509 a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] = (DFSDM_Channel_HandleTypeDef *) NULL;
\r
515 * @brief Initialize the DFSDM channel MSP.
\r
516 * @param hdfsdm_channel DFSDM channel handle.
\r
519 __weak void HAL_DFSDM_ChannelMspInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
521 /* Prevent unused argument(s) compilation warning */
\r
522 UNUSED(hdfsdm_channel);
\r
524 /* NOTE : This function should not be modified, when the function is needed,
\r
525 the HAL_DFSDM_ChannelMspInit could be implemented in the user file.
\r
530 * @brief De-initialize the DFSDM channel MSP.
\r
531 * @param hdfsdm_channel DFSDM channel handle.
\r
534 __weak void HAL_DFSDM_ChannelMspDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
536 /* Prevent unused argument(s) compilation warning */
\r
537 UNUSED(hdfsdm_channel);
\r
539 /* NOTE : This function should not be modified, when the function is needed,
\r
540 the HAL_DFSDM_ChannelMspDeInit could be implemented in the user file.
\r
544 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
546 * @brief Register a user DFSDM channel callback
\r
547 * to be used instead of the weak predefined callback.
\r
548 * @param hdfsdm_channel DFSDM channel handle.
\r
549 * @param CallbackID ID of the callback to be registered.
\r
550 * This parameter can be one of the following values:
\r
551 * @arg @ref HAL_DFSDM_CHANNEL_CKAB_CB_ID clock absence detection callback ID.
\r
552 * @arg @ref HAL_DFSDM_CHANNEL_SCD_CB_ID short circuit detection callback ID.
\r
553 * @arg @ref HAL_DFSDM_CHANNEL_MSPINIT_CB_ID MSP init callback ID.
\r
554 * @arg @ref HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID MSP de-init callback ID.
\r
555 * @param pCallback pointer to the callback function.
\r
556 * @retval HAL status.
\r
558 HAL_StatusTypeDef HAL_DFSDM_Channel_RegisterCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
\r
559 HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID,
\r
560 pDFSDM_Channel_CallbackTypeDef pCallback)
\r
562 HAL_StatusTypeDef status = HAL_OK;
\r
564 if (pCallback == NULL)
\r
566 /* update return status */
\r
567 status = HAL_ERROR;
\r
571 if (HAL_DFSDM_CHANNEL_STATE_READY == hdfsdm_channel->State)
\r
573 switch (CallbackID)
\r
575 case HAL_DFSDM_CHANNEL_CKAB_CB_ID :
\r
576 hdfsdm_channel->CkabCallback = pCallback;
\r
578 case HAL_DFSDM_CHANNEL_SCD_CB_ID :
\r
579 hdfsdm_channel->ScdCallback = pCallback;
\r
581 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
\r
582 hdfsdm_channel->MspInitCallback = pCallback;
\r
584 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
\r
585 hdfsdm_channel->MspDeInitCallback = pCallback;
\r
588 /* update return status */
\r
589 status = HAL_ERROR;
\r
593 else if (HAL_DFSDM_CHANNEL_STATE_RESET == hdfsdm_channel->State)
\r
595 switch (CallbackID)
\r
597 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
\r
598 hdfsdm_channel->MspInitCallback = pCallback;
\r
600 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
\r
601 hdfsdm_channel->MspDeInitCallback = pCallback;
\r
604 /* update return status */
\r
605 status = HAL_ERROR;
\r
611 /* update return status */
\r
612 status = HAL_ERROR;
\r
619 * @brief Unregister a user DFSDM channel callback.
\r
620 * DFSDM channel callback is redirected to the weak predefined callback.
\r
621 * @param hdfsdm_channel DFSDM channel handle.
\r
622 * @param CallbackID ID of the callback to be unregistered.
\r
623 * This parameter can be one of the following values:
\r
624 * @arg @ref HAL_DFSDM_CHANNEL_CKAB_CB_ID clock absence detection callback ID.
\r
625 * @arg @ref HAL_DFSDM_CHANNEL_SCD_CB_ID short circuit detection callback ID.
\r
626 * @arg @ref HAL_DFSDM_CHANNEL_MSPINIT_CB_ID MSP init callback ID.
\r
627 * @arg @ref HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID MSP de-init callback ID.
\r
628 * @retval HAL status.
\r
630 HAL_StatusTypeDef HAL_DFSDM_Channel_UnRegisterCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
\r
631 HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID)
\r
633 HAL_StatusTypeDef status = HAL_OK;
\r
635 if (HAL_DFSDM_CHANNEL_STATE_READY == hdfsdm_channel->State)
\r
637 switch (CallbackID)
\r
639 case HAL_DFSDM_CHANNEL_CKAB_CB_ID :
\r
640 hdfsdm_channel->CkabCallback = HAL_DFSDM_ChannelCkabCallback;
\r
642 case HAL_DFSDM_CHANNEL_SCD_CB_ID :
\r
643 hdfsdm_channel->ScdCallback = HAL_DFSDM_ChannelScdCallback;
\r
645 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
\r
646 hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit;
\r
648 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
\r
649 hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit;
\r
652 /* update return status */
\r
653 status = HAL_ERROR;
\r
657 else if (HAL_DFSDM_CHANNEL_STATE_RESET == hdfsdm_channel->State)
\r
659 switch (CallbackID)
\r
661 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
\r
662 hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit;
\r
664 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
\r
665 hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit;
\r
668 /* update return status */
\r
669 status = HAL_ERROR;
\r
675 /* update return status */
\r
676 status = HAL_ERROR;
\r
680 #endif /* USE_HAL_DFSDM_REGISTER_CALLBACKS */
\r
686 /** @defgroup DFSDM_Exported_Functions_Group2_Channel Channel operation functions
\r
687 * @brief Channel operation functions
\r
690 ==============================================================================
\r
691 ##### Channel operation functions #####
\r
692 ==============================================================================
\r
693 [..] This section provides functions allowing to:
\r
694 (+) Manage clock absence detector feature.
\r
695 (+) Manage short circuit detector feature.
\r
696 (+) Get analog watchdog value.
\r
697 (+) Modify offset value.
\r
703 * @brief This function allows to start clock absence detection in polling mode.
\r
704 * @note Same mode has to be used for all channels.
\r
705 * @note If clock is not available on this channel during 5 seconds,
\r
706 * clock absence detection will not be activated and function
\r
707 * will return HAL_TIMEOUT error.
\r
708 * @param hdfsdm_channel DFSDM channel handle.
\r
709 * @retval HAL status
\r
711 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStart(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
713 HAL_StatusTypeDef status = HAL_OK;
\r
715 uint32_t tickstart;
\r
717 /* Check parameters */
\r
718 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
\r
720 /* Check DFSDM channel state */
\r
721 if (hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
\r
723 /* Return error status */
\r
724 status = HAL_ERROR;
\r
728 /* Get channel number from channel instance */
\r
729 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
\r
732 tickstart = HAL_GetTick();
\r
734 /* Clear clock absence flag */
\r
735 while ((((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1U) != 0U)
\r
737 DFSDM1_Filter0->FLTICR = (1UL << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
\r
739 /* Check the Timeout */
\r
740 if ((HAL_GetTick() - tickstart) > DFSDM_CKAB_TIMEOUT)
\r
742 /* Set timeout status */
\r
743 status = HAL_TIMEOUT;
\r
748 if (status == HAL_OK)
\r
750 /* Start clock absence detection */
\r
751 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CKABEN;
\r
754 /* Return function status */
\r
759 * @brief This function allows to poll for the clock absence detection.
\r
760 * @param hdfsdm_channel DFSDM channel handle.
\r
761 * @param Timeout Timeout value in milliseconds.
\r
762 * @retval HAL status
\r
764 HAL_StatusTypeDef HAL_DFSDM_ChannelPollForCkab(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
\r
767 uint32_t tickstart;
\r
770 /* Check parameters */
\r
771 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
\r
773 /* Check DFSDM channel state */
\r
774 if (hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
\r
776 /* Return error status */
\r
781 /* Get channel number from channel instance */
\r
782 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
\r
785 tickstart = HAL_GetTick();
\r
787 /* Wait clock absence detection */
\r
788 while ((((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1U) == 0U)
\r
790 /* Check the Timeout */
\r
791 if (Timeout != HAL_MAX_DELAY)
\r
793 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
\r
795 /* Return timeout status */
\r
796 return HAL_TIMEOUT;
\r
801 /* Clear clock absence detection flag */
\r
802 DFSDM1_Filter0->FLTICR = (1UL << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
\r
804 /* Return function status */
\r
810 * @brief This function allows to stop clock absence detection in polling mode.
\r
811 * @param hdfsdm_channel DFSDM channel handle.
\r
812 * @retval HAL status
\r
814 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStop(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
816 HAL_StatusTypeDef status = HAL_OK;
\r
819 /* Check parameters */
\r
820 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
\r
822 /* Check DFSDM channel state */
\r
823 if (hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
\r
825 /* Return error status */
\r
826 status = HAL_ERROR;
\r
830 /* Stop clock absence detection */
\r
831 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKABEN);
\r
833 /* Clear clock absence flag */
\r
834 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
\r
835 DFSDM1_Filter0->FLTICR = (1UL << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
\r
837 /* Return function status */
\r
842 * @brief This function allows to start clock absence detection in interrupt mode.
\r
843 * @note Same mode has to be used for all channels.
\r
844 * @note If clock is not available on this channel during 5 seconds,
\r
845 * clock absence detection will not be activated and function
\r
846 * will return HAL_TIMEOUT error.
\r
847 * @param hdfsdm_channel DFSDM channel handle.
\r
848 * @retval HAL status
\r
850 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStart_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
852 HAL_StatusTypeDef status = HAL_OK;
\r
854 uint32_t tickstart;
\r
856 /* Check parameters */
\r
857 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
\r
859 /* Check DFSDM channel state */
\r
860 if (hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
\r
862 /* Return error status */
\r
863 status = HAL_ERROR;
\r
867 /* Get channel number from channel instance */
\r
868 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
\r
871 tickstart = HAL_GetTick();
\r
873 /* Clear clock absence flag */
\r
874 while ((((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1U) != 0U)
\r
876 DFSDM1_Filter0->FLTICR = (1UL << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
\r
878 /* Check the Timeout */
\r
879 if ((HAL_GetTick() - tickstart) > DFSDM_CKAB_TIMEOUT)
\r
881 /* Set timeout status */
\r
882 status = HAL_TIMEOUT;
\r
887 if (status == HAL_OK)
\r
889 /* Activate clock absence detection interrupt */
\r
890 DFSDM1_Filter0->FLTCR2 |= DFSDM_FLTCR2_CKABIE;
\r
892 /* Start clock absence detection */
\r
893 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CKABEN;
\r
896 /* Return function status */
\r
901 * @brief Clock absence detection callback.
\r
902 * @param hdfsdm_channel DFSDM channel handle.
\r
905 __weak void HAL_DFSDM_ChannelCkabCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
907 /* Prevent unused argument(s) compilation warning */
\r
908 UNUSED(hdfsdm_channel);
\r
910 /* NOTE : This function should not be modified, when the callback is needed,
\r
911 the HAL_DFSDM_ChannelCkabCallback could be implemented in the user file
\r
916 * @brief This function allows to stop clock absence detection in interrupt mode.
\r
917 * @note Interrupt will be disabled for all channels
\r
918 * @param hdfsdm_channel DFSDM channel handle.
\r
919 * @retval HAL status
\r
921 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStop_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
923 HAL_StatusTypeDef status = HAL_OK;
\r
926 /* Check parameters */
\r
927 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
\r
929 /* Check DFSDM channel state */
\r
930 if (hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
\r
932 /* Return error status */
\r
933 status = HAL_ERROR;
\r
937 /* Stop clock absence detection */
\r
938 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKABEN);
\r
940 /* Clear clock absence flag */
\r
941 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
\r
942 DFSDM1_Filter0->FLTICR = (1UL << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
\r
944 /* Disable clock absence detection interrupt */
\r
945 DFSDM1_Filter0->FLTCR2 &= ~(DFSDM_FLTCR2_CKABIE);
\r
947 /* Return function status */
\r
952 * @brief This function allows to start short circuit detection in polling mode.
\r
953 * @note Same mode has to be used for all channels
\r
954 * @param hdfsdm_channel DFSDM channel handle.
\r
955 * @param Threshold Short circuit detector threshold.
\r
956 * This parameter must be a number between Min_Data = 0 and Max_Data = 255.
\r
957 * @param BreakSignal Break signals assigned to short circuit event.
\r
958 * This parameter can be a values combination of @ref DFSDM_BreakSignals.
\r
959 * @retval HAL status
\r
961 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStart(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
\r
962 uint32_t Threshold,
\r
963 uint32_t BreakSignal)
\r
965 HAL_StatusTypeDef status = HAL_OK;
\r
967 /* Check parameters */
\r
968 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
\r
969 assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold));
\r
970 assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal));
\r
972 /* Check DFSDM channel state */
\r
973 if (hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
\r
975 /* Return error status */
\r
976 status = HAL_ERROR;
\r
980 /* Configure threshold and break signals */
\r
981 hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_BKSCD | DFSDM_CHAWSCDR_SCDT);
\r
982 hdfsdm_channel->Instance->CHAWSCDR |= ((BreakSignal << DFSDM_CHAWSCDR_BKSCD_Pos) | \
\r
985 /* Start short circuit detection */
\r
986 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_SCDEN;
\r
988 /* Return function status */
\r
993 * @brief This function allows to poll for the short circuit detection.
\r
994 * @param hdfsdm_channel DFSDM channel handle.
\r
995 * @param Timeout Timeout value in milliseconds.
\r
996 * @retval HAL status
\r
998 HAL_StatusTypeDef HAL_DFSDM_ChannelPollForScd(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
\r
1001 uint32_t tickstart;
\r
1004 /* Check parameters */
\r
1005 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
\r
1007 /* Check DFSDM channel state */
\r
1008 if (hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
\r
1010 /* Return error status */
\r
1015 /* Get channel number from channel instance */
\r
1016 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
\r
1019 tickstart = HAL_GetTick();
\r
1021 /* Wait short circuit detection */
\r
1022 while (((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_SCDF) >> (DFSDM_FLTISR_SCDF_Pos + channel)) == 0U)
\r
1024 /* Check the Timeout */
\r
1025 if (Timeout != HAL_MAX_DELAY)
\r
1027 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
\r
1029 /* Return timeout status */
\r
1030 return HAL_TIMEOUT;
\r
1035 /* Clear short circuit detection flag */
\r
1036 DFSDM1_Filter0->FLTICR = (1UL << (DFSDM_FLTICR_CLRSCDF_Pos + channel));
\r
1038 /* Return function status */
\r
1044 * @brief This function allows to stop short circuit detection in polling mode.
\r
1045 * @param hdfsdm_channel DFSDM channel handle.
\r
1046 * @retval HAL status
\r
1048 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStop(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
1050 HAL_StatusTypeDef status = HAL_OK;
\r
1053 /* Check parameters */
\r
1054 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
\r
1056 /* Check DFSDM channel state */
\r
1057 if (hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
\r
1059 /* Return error status */
\r
1060 status = HAL_ERROR;
\r
1064 /* Stop short circuit detection */
\r
1065 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SCDEN);
\r
1067 /* Clear short circuit detection flag */
\r
1068 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
\r
1069 DFSDM1_Filter0->FLTICR = (1UL << (DFSDM_FLTICR_CLRSCDF_Pos + channel));
\r
1071 /* Return function status */
\r
1076 * @brief This function allows to start short circuit detection in interrupt mode.
\r
1077 * @note Same mode has to be used for all channels
\r
1078 * @param hdfsdm_channel DFSDM channel handle.
\r
1079 * @param Threshold Short circuit detector threshold.
\r
1080 * This parameter must be a number between Min_Data = 0 and Max_Data = 255.
\r
1081 * @param BreakSignal Break signals assigned to short circuit event.
\r
1082 * This parameter can be a values combination of @ref DFSDM_BreakSignals.
\r
1083 * @retval HAL status
\r
1085 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStart_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
\r
1086 uint32_t Threshold,
\r
1087 uint32_t BreakSignal)
\r
1089 HAL_StatusTypeDef status = HAL_OK;
\r
1091 /* Check parameters */
\r
1092 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
\r
1093 assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold));
\r
1094 assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal));
\r
1096 /* Check DFSDM channel state */
\r
1097 if (hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
\r
1099 /* Return error status */
\r
1100 status = HAL_ERROR;
\r
1104 /* Activate short circuit detection interrupt */
\r
1105 DFSDM1_Filter0->FLTCR2 |= DFSDM_FLTCR2_SCDIE;
\r
1107 /* Configure threshold and break signals */
\r
1108 hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_BKSCD | DFSDM_CHAWSCDR_SCDT);
\r
1109 hdfsdm_channel->Instance->CHAWSCDR |= ((BreakSignal << DFSDM_CHAWSCDR_BKSCD_Pos) | \
\r
1112 /* Start short circuit detection */
\r
1113 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_SCDEN;
\r
1115 /* Return function status */
\r
1120 * @brief Short circuit detection callback.
\r
1121 * @param hdfsdm_channel DFSDM channel handle.
\r
1124 __weak void HAL_DFSDM_ChannelScdCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
1126 /* Prevent unused argument(s) compilation warning */
\r
1127 UNUSED(hdfsdm_channel);
\r
1129 /* NOTE : This function should not be modified, when the callback is needed,
\r
1130 the HAL_DFSDM_ChannelScdCallback could be implemented in the user file
\r
1135 * @brief This function allows to stop short circuit detection in interrupt mode.
\r
1136 * @note Interrupt will be disabled for all channels
\r
1137 * @param hdfsdm_channel DFSDM channel handle.
\r
1138 * @retval HAL status
\r
1140 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStop_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
1142 HAL_StatusTypeDef status = HAL_OK;
\r
1145 /* Check parameters */
\r
1146 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
\r
1148 /* Check DFSDM channel state */
\r
1149 if (hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
\r
1151 /* Return error status */
\r
1152 status = HAL_ERROR;
\r
1156 /* Stop short circuit detection */
\r
1157 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SCDEN);
\r
1159 /* Clear short circuit detection flag */
\r
1160 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
\r
1161 DFSDM1_Filter0->FLTICR = (1UL << (DFSDM_FLTICR_CLRSCDF_Pos + channel));
\r
1163 /* Disable short circuit detection interrupt */
\r
1164 DFSDM1_Filter0->FLTCR2 &= ~(DFSDM_FLTCR2_SCDIE);
\r
1166 /* Return function status */
\r
1171 * @brief This function allows to get channel analog watchdog value.
\r
1172 * @param hdfsdm_channel DFSDM channel handle.
\r
1173 * @retval Channel analog watchdog value.
\r
1175 int16_t HAL_DFSDM_ChannelGetAwdValue(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
1177 return (int16_t) hdfsdm_channel->Instance->CHWDATAR;
\r
1181 * @brief This function allows to modify channel offset value.
\r
1182 * @param hdfsdm_channel DFSDM channel handle.
\r
1183 * @param Offset DFSDM channel offset.
\r
1184 * This parameter must be a number between Min_Data = -8388608 and Max_Data = 8388607.
\r
1185 * @retval HAL status.
\r
1187 HAL_StatusTypeDef HAL_DFSDM_ChannelModifyOffset(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
\r
1190 HAL_StatusTypeDef status = HAL_OK;
\r
1192 /* Check parameters */
\r
1193 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
\r
1194 assert_param(IS_DFSDM_CHANNEL_OFFSET(Offset));
\r
1196 /* Check DFSDM channel state */
\r
1197 if (hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
\r
1199 /* Return error status */
\r
1200 status = HAL_ERROR;
\r
1204 /* Modify channel offset */
\r
1205 hdfsdm_channel->Instance->CHCFGR2 &= ~(DFSDM_CHCFGR2_OFFSET);
\r
1206 hdfsdm_channel->Instance->CHCFGR2 |= ((uint32_t) Offset << DFSDM_CHCFGR2_OFFSET_Pos);
\r
1208 /* Return function status */
\r
1216 /** @defgroup DFSDM_Exported_Functions_Group3_Channel Channel state function
\r
1217 * @brief Channel state function
\r
1220 ==============================================================================
\r
1221 ##### Channel state function #####
\r
1222 ==============================================================================
\r
1223 [..] This section provides function allowing to:
\r
1224 (+) Get channel handle state.
\r
1230 * @brief This function allows to get the current DFSDM channel handle state.
\r
1231 * @param hdfsdm_channel DFSDM channel handle.
\r
1232 * @retval DFSDM channel state.
\r
1234 HAL_DFSDM_Channel_StateTypeDef HAL_DFSDM_ChannelGetState(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
\r
1236 /* Return DFSDM channel handle state */
\r
1237 return hdfsdm_channel->State;
\r
1244 /** @defgroup DFSDM_Exported_Functions_Group1_Filter Filter initialization and de-initialization functions
\r
1245 * @brief Filter initialization and de-initialization functions
\r
1248 ==============================================================================
\r
1249 ##### Filter initialization and de-initialization functions #####
\r
1250 ==============================================================================
\r
1251 [..] This section provides functions allowing to:
\r
1252 (+) Initialize the DFSDM filter.
\r
1253 (+) De-initialize the DFSDM filter.
\r
1259 * @brief Initialize the DFSDM filter according to the specified parameters
\r
1260 * in the DFSDM_FilterInitTypeDef structure and initialize the associated handle.
\r
1261 * @param hdfsdm_filter DFSDM filter handle.
\r
1262 * @retval HAL status.
\r
1264 HAL_StatusTypeDef HAL_DFSDM_FilterInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
1266 /* Check DFSDM Channel handle */
\r
1267 if (hdfsdm_filter == NULL)
\r
1272 /* Check parameters */
\r
1273 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
1274 assert_param(IS_DFSDM_FILTER_REG_TRIGGER(hdfsdm_filter->Init.RegularParam.Trigger));
\r
1275 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.RegularParam.FastMode));
\r
1276 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.RegularParam.DmaMode));
\r
1277 assert_param(IS_DFSDM_FILTER_INJ_TRIGGER(hdfsdm_filter->Init.InjectedParam.Trigger));
\r
1278 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.InjectedParam.ScanMode));
\r
1279 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.InjectedParam.DmaMode));
\r
1280 assert_param(IS_DFSDM_FILTER_SINC_ORDER(hdfsdm_filter->Init.FilterParam.SincOrder));
\r
1281 assert_param(IS_DFSDM_FILTER_OVS_RATIO(hdfsdm_filter->Init.FilterParam.Oversampling));
\r
1282 assert_param(IS_DFSDM_FILTER_INTEGRATOR_OVS_RATIO(hdfsdm_filter->Init.FilterParam.IntOversampling));
\r
1284 /* Check parameters compatibility */
\r
1285 if ((hdfsdm_filter->Instance == DFSDM1_Filter0) &&
\r
1286 ((hdfsdm_filter->Init.RegularParam.Trigger == DFSDM_FILTER_SYNC_TRIGGER) ||
\r
1287 (hdfsdm_filter->Init.InjectedParam.Trigger == DFSDM_FILTER_SYNC_TRIGGER)))
\r
1292 /* Initialize DFSDM filter variables with default values */
\r
1293 hdfsdm_filter->RegularContMode = DFSDM_CONTINUOUS_CONV_OFF;
\r
1294 hdfsdm_filter->InjectedChannelsNbr = 1;
\r
1295 hdfsdm_filter->InjConvRemaining = 1;
\r
1296 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_NONE;
\r
1298 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
1299 /* Reset callback pointers to the weak predefined callbacks */
\r
1300 hdfsdm_filter->AwdCallback = HAL_DFSDM_FilterAwdCallback;
\r
1301 hdfsdm_filter->RegConvCpltCallback = HAL_DFSDM_FilterRegConvCpltCallback;
\r
1302 hdfsdm_filter->RegConvHalfCpltCallback = HAL_DFSDM_FilterRegConvHalfCpltCallback;
\r
1303 hdfsdm_filter->InjConvCpltCallback = HAL_DFSDM_FilterInjConvCpltCallback;
\r
1304 hdfsdm_filter->InjConvHalfCpltCallback = HAL_DFSDM_FilterInjConvHalfCpltCallback;
\r
1305 hdfsdm_filter->ErrorCallback = HAL_DFSDM_FilterErrorCallback;
\r
1307 /* Call MSP init function */
\r
1308 if (hdfsdm_filter->MspInitCallback == NULL)
\r
1310 hdfsdm_filter->MspInitCallback = HAL_DFSDM_FilterMspInit;
\r
1312 hdfsdm_filter->MspInitCallback(hdfsdm_filter);
\r
1314 /* Call MSP init function */
\r
1315 HAL_DFSDM_FilterMspInit(hdfsdm_filter);
\r
1318 /* Set regular parameters */
\r
1319 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RSYNC);
\r
1320 if (hdfsdm_filter->Init.RegularParam.FastMode == ENABLE)
\r
1322 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_FAST;
\r
1326 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_FAST);
\r
1329 if (hdfsdm_filter->Init.RegularParam.DmaMode == ENABLE)
\r
1331 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RDMAEN;
\r
1335 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RDMAEN);
\r
1338 /* Set injected parameters */
\r
1339 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSYNC | DFSDM_FLTCR1_JEXTEN | DFSDM_FLTCR1_JEXTSEL);
\r
1340 if (hdfsdm_filter->Init.InjectedParam.Trigger == DFSDM_FILTER_EXT_TRIGGER)
\r
1342 assert_param(IS_DFSDM_FILTER_EXT_TRIG(hdfsdm_filter->Init.InjectedParam.ExtTrigger));
\r
1343 assert_param(IS_DFSDM_FILTER_EXT_TRIG_EDGE(hdfsdm_filter->Init.InjectedParam.ExtTriggerEdge));
\r
1344 hdfsdm_filter->Instance->FLTCR1 |= (hdfsdm_filter->Init.InjectedParam.ExtTrigger);
\r
1347 if (hdfsdm_filter->Init.InjectedParam.ScanMode == ENABLE)
\r
1349 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSCAN;
\r
1353 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSCAN);
\r
1356 if (hdfsdm_filter->Init.InjectedParam.DmaMode == ENABLE)
\r
1358 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JDMAEN;
\r
1362 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JDMAEN);
\r
1365 /* Set filter parameters */
\r
1366 hdfsdm_filter->Instance->FLTFCR &= ~(DFSDM_FLTFCR_FORD | DFSDM_FLTFCR_FOSR | DFSDM_FLTFCR_IOSR);
\r
1367 hdfsdm_filter->Instance->FLTFCR |= (hdfsdm_filter->Init.FilterParam.SincOrder |
\r
1368 ((hdfsdm_filter->Init.FilterParam.Oversampling - 1U) << DFSDM_FLTFCR_FOSR_Pos) |
\r
1369 (hdfsdm_filter->Init.FilterParam.IntOversampling - 1U));
\r
1371 /* Store regular and injected triggers and injected scan mode*/
\r
1372 hdfsdm_filter->RegularTrigger = hdfsdm_filter->Init.RegularParam.Trigger;
\r
1373 hdfsdm_filter->InjectedTrigger = hdfsdm_filter->Init.InjectedParam.Trigger;
\r
1374 hdfsdm_filter->ExtTriggerEdge = hdfsdm_filter->Init.InjectedParam.ExtTriggerEdge;
\r
1375 hdfsdm_filter->InjectedScanMode = hdfsdm_filter->Init.InjectedParam.ScanMode;
\r
1377 /* Enable DFSDM filter */
\r
1378 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
\r
1380 /* Set DFSDM filter to ready state */
\r
1381 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_READY;
\r
1387 * @brief De-initializes the DFSDM filter.
\r
1388 * @param hdfsdm_filter DFSDM filter handle.
\r
1389 * @retval HAL status.
\r
1391 HAL_StatusTypeDef HAL_DFSDM_FilterDeInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
1393 /* Check DFSDM filter handle */
\r
1394 if (hdfsdm_filter == NULL)
\r
1399 /* Check parameters */
\r
1400 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
1402 /* Disable the DFSDM filter */
\r
1403 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
\r
1405 /* Call MSP deinit function */
\r
1406 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
1407 if (hdfsdm_filter->MspDeInitCallback == NULL)
\r
1409 hdfsdm_filter->MspDeInitCallback = HAL_DFSDM_FilterMspDeInit;
\r
1411 hdfsdm_filter->MspDeInitCallback(hdfsdm_filter);
\r
1413 HAL_DFSDM_FilterMspDeInit(hdfsdm_filter);
\r
1416 /* Set DFSDM filter in reset state */
\r
1417 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_RESET;
\r
1423 * @brief Initializes the DFSDM filter MSP.
\r
1424 * @param hdfsdm_filter DFSDM filter handle.
\r
1427 __weak void HAL_DFSDM_FilterMspInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
1429 /* Prevent unused argument(s) compilation warning */
\r
1430 UNUSED(hdfsdm_filter);
\r
1432 /* NOTE : This function should not be modified, when the function is needed,
\r
1433 the HAL_DFSDM_FilterMspInit could be implemented in the user file.
\r
1438 * @brief De-initializes the DFSDM filter MSP.
\r
1439 * @param hdfsdm_filter DFSDM filter handle.
\r
1442 __weak void HAL_DFSDM_FilterMspDeInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
1444 /* Prevent unused argument(s) compilation warning */
\r
1445 UNUSED(hdfsdm_filter);
\r
1447 /* NOTE : This function should not be modified, when the function is needed,
\r
1448 the HAL_DFSDM_FilterMspDeInit could be implemented in the user file.
\r
1452 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
1454 * @brief Register a user DFSDM filter callback
\r
1455 * to be used instead of the weak predefined callback.
\r
1456 * @param hdfsdm_filter DFSDM filter handle.
\r
1457 * @param CallbackID ID of the callback to be registered.
\r
1458 * This parameter can be one of the following values:
\r
1459 * @arg @ref HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID regular conversion complete callback ID.
\r
1460 * @arg @ref HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID half regular conversion complete callback ID.
\r
1461 * @arg @ref HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID injected conversion complete callback ID.
\r
1462 * @arg @ref HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID half injected conversion complete callback ID.
\r
1463 * @arg @ref HAL_DFSDM_FILTER_ERROR_CB_ID error callback ID.
\r
1464 * @arg @ref HAL_DFSDM_FILTER_MSPINIT_CB_ID MSP init callback ID.
\r
1465 * @arg @ref HAL_DFSDM_FILTER_MSPDEINIT_CB_ID MSP de-init callback ID.
\r
1466 * @param pCallback pointer to the callback function.
\r
1467 * @retval HAL status.
\r
1469 HAL_StatusTypeDef HAL_DFSDM_Filter_RegisterCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
1470 HAL_DFSDM_Filter_CallbackIDTypeDef CallbackID,
\r
1471 pDFSDM_Filter_CallbackTypeDef pCallback)
\r
1473 HAL_StatusTypeDef status = HAL_OK;
\r
1475 if (pCallback == NULL)
\r
1477 /* update the error code */
\r
1478 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
\r
1479 /* update return status */
\r
1480 status = HAL_ERROR;
\r
1484 if (HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State)
\r
1486 switch (CallbackID)
\r
1488 case HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID :
\r
1489 hdfsdm_filter->RegConvCpltCallback = pCallback;
\r
1491 case HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID :
\r
1492 hdfsdm_filter->RegConvHalfCpltCallback = pCallback;
\r
1494 case HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID :
\r
1495 hdfsdm_filter->InjConvCpltCallback = pCallback;
\r
1497 case HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID :
\r
1498 hdfsdm_filter->InjConvHalfCpltCallback = pCallback;
\r
1500 case HAL_DFSDM_FILTER_ERROR_CB_ID :
\r
1501 hdfsdm_filter->ErrorCallback = pCallback;
\r
1503 case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
\r
1504 hdfsdm_filter->MspInitCallback = pCallback;
\r
1506 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
\r
1507 hdfsdm_filter->MspDeInitCallback = pCallback;
\r
1510 /* update the error code */
\r
1511 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
\r
1512 /* update return status */
\r
1513 status = HAL_ERROR;
\r
1517 else if (HAL_DFSDM_FILTER_STATE_RESET == hdfsdm_filter->State)
\r
1519 switch (CallbackID)
\r
1521 case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
\r
1522 hdfsdm_filter->MspInitCallback = pCallback;
\r
1524 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
\r
1525 hdfsdm_filter->MspDeInitCallback = pCallback;
\r
1528 /* update the error code */
\r
1529 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
\r
1530 /* update return status */
\r
1531 status = HAL_ERROR;
\r
1537 /* update the error code */
\r
1538 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
\r
1539 /* update return status */
\r
1540 status = HAL_ERROR;
\r
1547 * @brief Unregister a user DFSDM filter callback.
\r
1548 * DFSDM filter callback is redirected to the weak predefined callback.
\r
1549 * @param hdfsdm_filter DFSDM filter handle.
\r
1550 * @param CallbackID ID of the callback to be unregistered.
\r
1551 * This parameter can be one of the following values:
\r
1552 * @arg @ref HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID regular conversion complete callback ID.
\r
1553 * @arg @ref HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID half regular conversion complete callback ID.
\r
1554 * @arg @ref HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID injected conversion complete callback ID.
\r
1555 * @arg @ref HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID half injected conversion complete callback ID.
\r
1556 * @arg @ref HAL_DFSDM_FILTER_ERROR_CB_ID error callback ID.
\r
1557 * @arg @ref HAL_DFSDM_FILTER_MSPINIT_CB_ID MSP init callback ID.
\r
1558 * @arg @ref HAL_DFSDM_FILTER_MSPDEINIT_CB_ID MSP de-init callback ID.
\r
1559 * @retval HAL status.
\r
1561 HAL_StatusTypeDef HAL_DFSDM_Filter_UnRegisterCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
1562 HAL_DFSDM_Filter_CallbackIDTypeDef CallbackID)
\r
1564 HAL_StatusTypeDef status = HAL_OK;
\r
1566 if (HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State)
\r
1568 switch (CallbackID)
\r
1570 case HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID :
\r
1571 hdfsdm_filter->RegConvCpltCallback = HAL_DFSDM_FilterRegConvCpltCallback;
\r
1573 case HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID :
\r
1574 hdfsdm_filter->RegConvHalfCpltCallback = HAL_DFSDM_FilterRegConvHalfCpltCallback;
\r
1576 case HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID :
\r
1577 hdfsdm_filter->InjConvCpltCallback = HAL_DFSDM_FilterInjConvCpltCallback;
\r
1579 case HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID :
\r
1580 hdfsdm_filter->InjConvHalfCpltCallback = HAL_DFSDM_FilterInjConvHalfCpltCallback;
\r
1582 case HAL_DFSDM_FILTER_ERROR_CB_ID :
\r
1583 hdfsdm_filter->ErrorCallback = HAL_DFSDM_FilterErrorCallback;
\r
1585 case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
\r
1586 hdfsdm_filter->MspInitCallback = HAL_DFSDM_FilterMspInit;
\r
1588 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
\r
1589 hdfsdm_filter->MspDeInitCallback = HAL_DFSDM_FilterMspDeInit;
\r
1592 /* update the error code */
\r
1593 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
\r
1594 /* update return status */
\r
1595 status = HAL_ERROR;
\r
1599 else if (HAL_DFSDM_FILTER_STATE_RESET == hdfsdm_filter->State)
\r
1601 switch (CallbackID)
\r
1603 case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
\r
1604 hdfsdm_filter->MspInitCallback = HAL_DFSDM_FilterMspInit;
\r
1606 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
\r
1607 hdfsdm_filter->MspDeInitCallback = HAL_DFSDM_FilterMspDeInit;
\r
1610 /* update the error code */
\r
1611 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
\r
1612 /* update return status */
\r
1613 status = HAL_ERROR;
\r
1619 /* update the error code */
\r
1620 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
\r
1621 /* update return status */
\r
1622 status = HAL_ERROR;
\r
1628 * @brief Register a user DFSDM filter analog watchdog callback
\r
1629 * to be used instead of the weak predefined callback.
\r
1630 * @param hdfsdm_filter DFSDM filter handle.
\r
1631 * @param pCallback pointer to the DFSDM filter analog watchdog callback function.
\r
1632 * @retval HAL status.
\r
1634 HAL_StatusTypeDef HAL_DFSDM_Filter_RegisterAwdCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
1635 pDFSDM_Filter_AwdCallbackTypeDef pCallback)
\r
1637 HAL_StatusTypeDef status = HAL_OK;
\r
1639 if (pCallback == NULL)
\r
1641 /* update the error code */
\r
1642 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
\r
1643 /* update return status */
\r
1644 status = HAL_ERROR;
\r
1648 if (HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State)
\r
1650 hdfsdm_filter->AwdCallback = pCallback;
\r
1654 /* update the error code */
\r
1655 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
\r
1656 /* update return status */
\r
1657 status = HAL_ERROR;
\r
1664 * @brief Unregister a user DFSDM filter analog watchdog callback.
\r
1665 * DFSDM filter AWD callback is redirected to the weak predefined callback.
\r
1666 * @param hdfsdm_filter DFSDM filter handle.
\r
1667 * @retval HAL status.
\r
1669 HAL_StatusTypeDef HAL_DFSDM_Filter_UnRegisterAwdCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
1671 HAL_StatusTypeDef status = HAL_OK;
\r
1673 if (HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State)
\r
1675 hdfsdm_filter->AwdCallback = HAL_DFSDM_FilterAwdCallback;
\r
1679 /* update the error code */
\r
1680 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
\r
1681 /* update return status */
\r
1682 status = HAL_ERROR;
\r
1686 #endif /* USE_HAL_DFSDM_REGISTER_CALLBACKS */
\r
1692 /** @defgroup DFSDM_Exported_Functions_Group2_Filter Filter control functions
\r
1693 * @brief Filter control functions
\r
1696 ==============================================================================
\r
1697 ##### Filter control functions #####
\r
1698 ==============================================================================
\r
1699 [..] This section provides functions allowing to:
\r
1700 (+) Select channel and enable/disable continuous mode for regular conversion.
\r
1701 (+) Select channels for injected conversion.
\r
1707 * @brief This function allows to select channel and to enable/disable
\r
1708 * continuous mode for regular conversion.
\r
1709 * @param hdfsdm_filter DFSDM filter handle.
\r
1710 * @param Channel Channel for regular conversion.
\r
1711 * This parameter can be a value of @ref DFSDM_Channel_Selection.
\r
1712 * @param ContinuousMode Enable/disable continuous mode for regular conversion.
\r
1713 * This parameter can be a value of @ref DFSDM_ContinuousMode.
\r
1714 * @retval HAL status
\r
1716 HAL_StatusTypeDef HAL_DFSDM_FilterConfigRegChannel(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
1718 uint32_t ContinuousMode)
\r
1720 HAL_StatusTypeDef status = HAL_OK;
\r
1722 /* Check parameters */
\r
1723 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
1724 assert_param(IS_DFSDM_REGULAR_CHANNEL(Channel));
\r
1725 assert_param(IS_DFSDM_CONTINUOUS_MODE(ContinuousMode));
\r
1727 /* Check DFSDM filter state */
\r
1728 if ((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_RESET) &&
\r
1729 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_ERROR))
\r
1731 /* Configure channel and continuous mode for regular conversion */
\r
1732 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RCH | DFSDM_FLTCR1_RCONT);
\r
1733 if (ContinuousMode == DFSDM_CONTINUOUS_CONV_ON)
\r
1735 hdfsdm_filter->Instance->FLTCR1 |= (uint32_t)(((Channel & DFSDM_MSB_MASK) << DFSDM_FLTCR1_MSB_RCH_OFFSET) |
\r
1736 DFSDM_FLTCR1_RCONT);
\r
1740 hdfsdm_filter->Instance->FLTCR1 |= (uint32_t)((Channel & DFSDM_MSB_MASK) << DFSDM_FLTCR1_MSB_RCH_OFFSET);
\r
1742 /* Store continuous mode information */
\r
1743 hdfsdm_filter->RegularContMode = ContinuousMode;
\r
1747 status = HAL_ERROR;
\r
1750 /* Return function status */
\r
1755 * @brief This function allows to select channels for injected conversion.
\r
1756 * @param hdfsdm_filter DFSDM filter handle.
\r
1757 * @param Channel Channels for injected conversion.
\r
1758 * This parameter can be a values combination of @ref DFSDM_Channel_Selection.
\r
1759 * @retval HAL status
\r
1761 HAL_StatusTypeDef HAL_DFSDM_FilterConfigInjChannel(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
1764 HAL_StatusTypeDef status = HAL_OK;
\r
1766 /* Check parameters */
\r
1767 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
1768 assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel));
\r
1770 /* Check DFSDM filter state */
\r
1771 if ((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_RESET) &&
\r
1772 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_ERROR))
\r
1774 /* Configure channel for injected conversion */
\r
1775 hdfsdm_filter->Instance->FLTJCHGR = (uint32_t)(Channel & DFSDM_LSB_MASK);
\r
1776 /* Store number of injected channels */
\r
1777 hdfsdm_filter->InjectedChannelsNbr = DFSDM_GetInjChannelsNbr(Channel);
\r
1778 /* Update number of injected channels remaining */
\r
1779 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
\r
1780 hdfsdm_filter->InjectedChannelsNbr : 1U;
\r
1784 status = HAL_ERROR;
\r
1786 /* Return function status */
\r
1794 /** @defgroup DFSDM_Exported_Functions_Group3_Filter Filter operation functions
\r
1795 * @brief Filter operation functions
\r
1798 ==============================================================================
\r
1799 ##### Filter operation functions #####
\r
1800 ==============================================================================
\r
1801 [..] This section provides functions allowing to:
\r
1802 (+) Start conversion of regular/injected channel.
\r
1803 (+) Poll for the end of regular/injected conversion.
\r
1804 (+) Stop conversion of regular/injected channel.
\r
1805 (+) Start conversion of regular/injected channel and enable interrupt.
\r
1806 (+) Call the callback functions at the end of regular/injected conversions.
\r
1807 (+) Stop conversion of regular/injected channel and disable interrupt.
\r
1808 (+) Start conversion of regular/injected channel and enable DMA transfer.
\r
1809 (+) Stop conversion of regular/injected channel and disable DMA transfer.
\r
1810 (+) Start analog watchdog and enable interrupt.
\r
1811 (+) Call the callback function when analog watchdog occurs.
\r
1812 (+) Stop analog watchdog and disable interrupt.
\r
1813 (+) Start extreme detector.
\r
1814 (+) Stop extreme detector.
\r
1815 (+) Get result of regular channel conversion.
\r
1816 (+) Get result of injected channel conversion.
\r
1817 (+) Get extreme detector maximum and minimum values.
\r
1818 (+) Get conversion time.
\r
1819 (+) Handle DFSDM interrupt request.
\r
1825 * @brief This function allows to start regular conversion in polling mode.
\r
1826 * @note This function should be called only when DFSDM filter instance is
\r
1827 * in idle state or if injected conversion is ongoing.
\r
1828 * @param hdfsdm_filter DFSDM filter handle.
\r
1829 * @retval HAL status
\r
1831 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
1833 HAL_StatusTypeDef status = HAL_OK;
\r
1835 /* Check parameters */
\r
1836 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
1838 /* Check DFSDM filter state */
\r
1839 if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
\r
1840 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
\r
1842 /* Start regular conversion */
\r
1843 DFSDM_RegConvStart(hdfsdm_filter);
\r
1847 status = HAL_ERROR;
\r
1849 /* Return function status */
\r
1854 * @brief This function allows to poll for the end of regular conversion.
\r
1855 * @note This function should be called only if regular conversion is ongoing.
\r
1856 * @param hdfsdm_filter DFSDM filter handle.
\r
1857 * @param Timeout Timeout value in milliseconds.
\r
1858 * @retval HAL status
\r
1860 HAL_StatusTypeDef HAL_DFSDM_FilterPollForRegConversion(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
1863 uint32_t tickstart;
\r
1865 /* Check parameters */
\r
1866 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
1868 /* Check DFSDM filter state */
\r
1869 if ((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
\r
1870 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
\r
1872 /* Return error status */
\r
1878 tickstart = HAL_GetTick();
\r
1880 /* Wait end of regular conversion */
\r
1881 while ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_REOCF) != DFSDM_FLTISR_REOCF)
\r
1883 /* Check the Timeout */
\r
1884 if (Timeout != HAL_MAX_DELAY)
\r
1886 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
\r
1888 /* Return timeout status */
\r
1889 return HAL_TIMEOUT;
\r
1893 /* Check if overrun occurs */
\r
1894 if ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_ROVRF) == DFSDM_FLTISR_ROVRF)
\r
1896 /* Update error code and call error callback */
\r
1897 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_REGULAR_OVERRUN;
\r
1898 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
1899 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
\r
1901 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
\r
1904 /* Clear regular overrun flag */
\r
1905 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRROVRF;
\r
1907 /* Update DFSDM filter state only if not continuous conversion and SW trigger */
\r
1908 if ((hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
\r
1909 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
\r
1911 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \
\r
1912 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ;
\r
1914 /* Return function status */
\r
1920 * @brief This function allows to stop regular conversion in polling mode.
\r
1921 * @note This function should be called only if regular conversion is ongoing.
\r
1922 * @param hdfsdm_filter DFSDM filter handle.
\r
1923 * @retval HAL status
\r
1925 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
1927 HAL_StatusTypeDef status = HAL_OK;
\r
1929 /* Check parameters */
\r
1930 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
1932 /* Check DFSDM filter state */
\r
1933 if ((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
\r
1934 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
\r
1936 /* Return error status */
\r
1937 status = HAL_ERROR;
\r
1941 /* Stop regular conversion */
\r
1942 DFSDM_RegConvStop(hdfsdm_filter);
\r
1944 /* Return function status */
\r
1949 * @brief This function allows to start regular conversion in interrupt mode.
\r
1950 * @note This function should be called only when DFSDM filter instance is
\r
1951 * in idle state or if injected conversion is ongoing.
\r
1952 * @param hdfsdm_filter DFSDM filter handle.
\r
1953 * @retval HAL status
\r
1955 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
1957 HAL_StatusTypeDef status = HAL_OK;
\r
1959 /* Check parameters */
\r
1960 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
1962 /* Check DFSDM filter state */
\r
1963 if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
\r
1964 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
\r
1966 /* Enable interrupts for regular conversions */
\r
1967 hdfsdm_filter->Instance->FLTCR2 |= (DFSDM_FLTCR2_REOCIE | DFSDM_FLTCR2_ROVRIE);
\r
1969 /* Start regular conversion */
\r
1970 DFSDM_RegConvStart(hdfsdm_filter);
\r
1974 status = HAL_ERROR;
\r
1976 /* Return function status */
\r
1981 * @brief This function allows to stop regular conversion in interrupt mode.
\r
1982 * @note This function should be called only if regular conversion is ongoing.
\r
1983 * @param hdfsdm_filter DFSDM filter handle.
\r
1984 * @retval HAL status
\r
1986 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
1988 HAL_StatusTypeDef status = HAL_OK;
\r
1990 /* Check parameters */
\r
1991 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
1993 /* Check DFSDM filter state */
\r
1994 if ((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
\r
1995 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
\r
1997 /* Return error status */
\r
1998 status = HAL_ERROR;
\r
2002 /* Disable interrupts for regular conversions */
\r
2003 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_REOCIE | DFSDM_FLTCR2_ROVRIE);
\r
2005 /* Stop regular conversion */
\r
2006 DFSDM_RegConvStop(hdfsdm_filter);
\r
2008 /* Return function status */
\r
2013 * @brief This function allows to start regular conversion in DMA mode.
\r
2014 * @note This function should be called only when DFSDM filter instance is
\r
2015 * in idle state or if injected conversion is ongoing.
\r
2016 * Please note that data on buffer will contain signed regular conversion
\r
2017 * value on 24 most significant bits and corresponding channel on 3 least
\r
2018 * significant bits.
\r
2019 * @param hdfsdm_filter DFSDM filter handle.
\r
2020 * @param pData The destination buffer address.
\r
2021 * @param Length The length of data to be transferred from DFSDM filter to memory.
\r
2022 * @retval HAL status
\r
2024 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
2028 HAL_StatusTypeDef status = HAL_OK;
\r
2030 /* Check parameters */
\r
2031 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2033 /* Check destination address and length */
\r
2034 if ((pData == NULL) || (Length == 0U))
\r
2036 status = HAL_ERROR;
\r
2038 /* Check that DMA is enabled for regular conversion */
\r
2039 else if ((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_RDMAEN) != DFSDM_FLTCR1_RDMAEN)
\r
2041 status = HAL_ERROR;
\r
2043 /* Check parameters compatibility */
\r
2044 else if ((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
\r
2045 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
\r
2046 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_NORMAL) && \
\r
2049 status = HAL_ERROR;
\r
2051 else if ((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
\r
2052 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
\r
2053 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR))
\r
2055 status = HAL_ERROR;
\r
2057 /* Check DFSDM filter state */
\r
2058 else if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
\r
2059 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
\r
2061 /* Set callbacks on DMA handler */
\r
2062 hdfsdm_filter->hdmaReg->XferCpltCallback = DFSDM_DMARegularConvCplt;
\r
2063 hdfsdm_filter->hdmaReg->XferErrorCallback = DFSDM_DMAError;
\r
2064 hdfsdm_filter->hdmaReg->XferHalfCpltCallback = (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR) ? \
\r
2065 DFSDM_DMARegularHalfConvCplt : NULL;
\r
2067 /* Start DMA in interrupt mode */
\r
2068 if (HAL_DMA_Start_IT(hdfsdm_filter->hdmaReg, (uint32_t)&hdfsdm_filter->Instance->FLTRDATAR, \
\r
2069 (uint32_t) pData, Length) != HAL_OK)
\r
2071 /* Set DFSDM filter in error state */
\r
2072 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
\r
2073 status = HAL_ERROR;
\r
2077 /* Start regular conversion */
\r
2078 DFSDM_RegConvStart(hdfsdm_filter);
\r
2083 status = HAL_ERROR;
\r
2085 /* Return function status */
\r
2090 * @brief This function allows to start regular conversion in DMA mode and to get
\r
2091 * only the 16 most significant bits of conversion.
\r
2092 * @note This function should be called only when DFSDM filter instance is
\r
2093 * in idle state or if injected conversion is ongoing.
\r
2094 * Please note that data on buffer will contain signed 16 most significant
\r
2095 * bits of regular conversion.
\r
2096 * @param hdfsdm_filter DFSDM filter handle.
\r
2097 * @param pData The destination buffer address.
\r
2098 * @param Length The length of data to be transferred from DFSDM filter to memory.
\r
2099 * @retval HAL status
\r
2101 HAL_StatusTypeDef HAL_DFSDM_FilterRegularMsbStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
2105 HAL_StatusTypeDef status = HAL_OK;
\r
2107 /* Check parameters */
\r
2108 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2110 /* Check destination address and length */
\r
2111 if ((pData == NULL) || (Length == 0U))
\r
2113 status = HAL_ERROR;
\r
2115 /* Check that DMA is enabled for regular conversion */
\r
2116 else if ((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_RDMAEN) != DFSDM_FLTCR1_RDMAEN)
\r
2118 status = HAL_ERROR;
\r
2120 /* Check parameters compatibility */
\r
2121 else if ((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
\r
2122 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
\r
2123 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_NORMAL) && \
\r
2126 status = HAL_ERROR;
\r
2128 else if ((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
\r
2129 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
\r
2130 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR))
\r
2132 status = HAL_ERROR;
\r
2134 /* Check DFSDM filter state */
\r
2135 else if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
\r
2136 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
\r
2138 /* Set callbacks on DMA handler */
\r
2139 hdfsdm_filter->hdmaReg->XferCpltCallback = DFSDM_DMARegularConvCplt;
\r
2140 hdfsdm_filter->hdmaReg->XferErrorCallback = DFSDM_DMAError;
\r
2141 hdfsdm_filter->hdmaReg->XferHalfCpltCallback = (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR) ? \
\r
2142 DFSDM_DMARegularHalfConvCplt : NULL;
\r
2144 /* Start DMA in interrupt mode */
\r
2145 if (HAL_DMA_Start_IT(hdfsdm_filter->hdmaReg, (uint32_t)(&hdfsdm_filter->Instance->FLTRDATAR) + 2U, \
\r
2146 (uint32_t) pData, Length) != HAL_OK)
\r
2148 /* Set DFSDM filter in error state */
\r
2149 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
\r
2150 status = HAL_ERROR;
\r
2154 /* Start regular conversion */
\r
2155 DFSDM_RegConvStart(hdfsdm_filter);
\r
2160 status = HAL_ERROR;
\r
2162 /* Return function status */
\r
2167 * @brief This function allows to stop regular conversion in DMA mode.
\r
2168 * @note This function should be called only if regular conversion is ongoing.
\r
2169 * @param hdfsdm_filter DFSDM filter handle.
\r
2170 * @retval HAL status
\r
2172 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
2174 HAL_StatusTypeDef status = HAL_OK;
\r
2176 /* Check parameters */
\r
2177 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2179 /* Check DFSDM filter state */
\r
2180 if ((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
\r
2181 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
\r
2183 /* Return error status */
\r
2184 status = HAL_ERROR;
\r
2188 /* Stop current DMA transfer */
\r
2189 if (HAL_DMA_Abort(hdfsdm_filter->hdmaReg) != HAL_OK)
\r
2191 /* Set DFSDM filter in error state */
\r
2192 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
\r
2193 status = HAL_ERROR;
\r
2197 /* Stop regular conversion */
\r
2198 DFSDM_RegConvStop(hdfsdm_filter);
\r
2201 /* Return function status */
\r
2206 * @brief This function allows to get regular conversion value.
\r
2207 * @param hdfsdm_filter DFSDM filter handle.
\r
2208 * @param Channel Corresponding channel of regular conversion.
\r
2209 * @retval Regular conversion value
\r
2211 int32_t HAL_DFSDM_FilterGetRegularValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
2212 uint32_t *Channel)
\r
2217 /* Check parameters */
\r
2218 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2219 assert_param(Channel != (void *)0);
\r
2221 /* Get value of data register for regular channel */
\r
2222 reg = hdfsdm_filter->Instance->FLTRDATAR;
\r
2224 /* Extract channel and regular conversion value */
\r
2225 *Channel = (reg & DFSDM_FLTRDATAR_RDATACH);
\r
2226 /* Regular conversion value is a signed value located on 24 MSB of register */
\r
2227 /* So after applying a mask on these bits we have to perform a division by 256 (2 raised to the power of 8) */
\r
2228 reg &= DFSDM_FLTRDATAR_RDATA;
\r
2229 value = ((int32_t)reg) / 256;
\r
2231 /* return regular conversion value */
\r
2236 * @brief This function allows to start injected conversion in polling mode.
\r
2237 * @note This function should be called only when DFSDM filter instance is
\r
2238 * in idle state or if regular conversion is ongoing.
\r
2239 * @param hdfsdm_filter DFSDM filter handle.
\r
2240 * @retval HAL status
\r
2242 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
2244 HAL_StatusTypeDef status = HAL_OK;
\r
2246 /* Check parameters */
\r
2247 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2249 /* Check DFSDM filter state */
\r
2250 if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
\r
2251 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
\r
2253 /* Start injected conversion */
\r
2254 DFSDM_InjConvStart(hdfsdm_filter);
\r
2258 status = HAL_ERROR;
\r
2260 /* Return function status */
\r
2265 * @brief This function allows to poll for the end of injected conversion.
\r
2266 * @note This function should be called only if injected conversion is ongoing.
\r
2267 * @param hdfsdm_filter DFSDM filter handle.
\r
2268 * @param Timeout Timeout value in milliseconds.
\r
2269 * @retval HAL status
\r
2271 HAL_StatusTypeDef HAL_DFSDM_FilterPollForInjConversion(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
2274 uint32_t tickstart;
\r
2276 /* Check parameters */
\r
2277 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2279 /* Check DFSDM filter state */
\r
2280 if ((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
\r
2281 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
\r
2283 /* Return error status */
\r
2289 tickstart = HAL_GetTick();
\r
2291 /* Wait end of injected conversions */
\r
2292 while ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JEOCF) != DFSDM_FLTISR_JEOCF)
\r
2294 /* Check the Timeout */
\r
2295 if (Timeout != HAL_MAX_DELAY)
\r
2297 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
\r
2299 /* Return timeout status */
\r
2300 return HAL_TIMEOUT;
\r
2304 /* Check if overrun occurs */
\r
2305 if ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JOVRF) == DFSDM_FLTISR_JOVRF)
\r
2307 /* Update error code and call error callback */
\r
2308 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INJECTED_OVERRUN;
\r
2309 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
2310 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
\r
2312 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
\r
2315 /* Clear injected overrun flag */
\r
2316 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRJOVRF;
\r
2319 /* Update remaining injected conversions */
\r
2320 hdfsdm_filter->InjConvRemaining--;
\r
2321 if (hdfsdm_filter->InjConvRemaining == 0U)
\r
2323 /* Update DFSDM filter state only if trigger is software */
\r
2324 if (hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
\r
2326 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \
\r
2327 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG;
\r
2330 /* end of injected sequence, reset the value */
\r
2331 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
\r
2332 hdfsdm_filter->InjectedChannelsNbr : 1U;
\r
2335 /* Return function status */
\r
2341 * @brief This function allows to stop injected conversion in polling mode.
\r
2342 * @note This function should be called only if injected conversion is ongoing.
\r
2343 * @param hdfsdm_filter DFSDM filter handle.
\r
2344 * @retval HAL status
\r
2346 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
2348 HAL_StatusTypeDef status = HAL_OK;
\r
2350 /* Check parameters */
\r
2351 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2353 /* Check DFSDM filter state */
\r
2354 if ((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
\r
2355 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
\r
2357 /* Return error status */
\r
2358 status = HAL_ERROR;
\r
2362 /* Stop injected conversion */
\r
2363 DFSDM_InjConvStop(hdfsdm_filter);
\r
2365 /* Return function status */
\r
2370 * @brief This function allows to start injected conversion in interrupt mode.
\r
2371 * @note This function should be called only when DFSDM filter instance is
\r
2372 * in idle state or if regular conversion is ongoing.
\r
2373 * @param hdfsdm_filter DFSDM filter handle.
\r
2374 * @retval HAL status
\r
2376 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
2378 HAL_StatusTypeDef status = HAL_OK;
\r
2380 /* Check parameters */
\r
2381 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2383 /* Check DFSDM filter state */
\r
2384 if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
\r
2385 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
\r
2387 /* Enable interrupts for injected conversions */
\r
2388 hdfsdm_filter->Instance->FLTCR2 |= (DFSDM_FLTCR2_JEOCIE | DFSDM_FLTCR2_JOVRIE);
\r
2390 /* Start injected conversion */
\r
2391 DFSDM_InjConvStart(hdfsdm_filter);
\r
2395 status = HAL_ERROR;
\r
2397 /* Return function status */
\r
2402 * @brief This function allows to stop injected conversion in interrupt mode.
\r
2403 * @note This function should be called only if injected conversion is ongoing.
\r
2404 * @param hdfsdm_filter DFSDM filter handle.
\r
2405 * @retval HAL status
\r
2407 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
2409 HAL_StatusTypeDef status = HAL_OK;
\r
2411 /* Check parameters */
\r
2412 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2414 /* Check DFSDM filter state */
\r
2415 if ((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
\r
2416 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
\r
2418 /* Return error status */
\r
2419 status = HAL_ERROR;
\r
2423 /* Disable interrupts for injected conversions */
\r
2424 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_JEOCIE | DFSDM_FLTCR2_JOVRIE);
\r
2426 /* Stop injected conversion */
\r
2427 DFSDM_InjConvStop(hdfsdm_filter);
\r
2429 /* Return function status */
\r
2434 * @brief This function allows to start injected conversion in DMA mode.
\r
2435 * @note This function should be called only when DFSDM filter instance is
\r
2436 * in idle state or if regular conversion is ongoing.
\r
2437 * Please note that data on buffer will contain signed injected conversion
\r
2438 * value on 24 most significant bits and corresponding channel on 3 least
\r
2439 * significant bits.
\r
2440 * @param hdfsdm_filter DFSDM filter handle.
\r
2441 * @param pData The destination buffer address.
\r
2442 * @param Length The length of data to be transferred from DFSDM filter to memory.
\r
2443 * @retval HAL status
\r
2445 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
2449 HAL_StatusTypeDef status = HAL_OK;
\r
2451 /* Check parameters */
\r
2452 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2454 /* Check destination address and length */
\r
2455 if ((pData == NULL) || (Length == 0U))
\r
2457 status = HAL_ERROR;
\r
2459 /* Check that DMA is enabled for injected conversion */
\r
2460 else if ((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_JDMAEN) != DFSDM_FLTCR1_JDMAEN)
\r
2462 status = HAL_ERROR;
\r
2464 /* Check parameters compatibility */
\r
2465 else if ((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
\r
2466 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_NORMAL) && \
\r
2467 (Length > hdfsdm_filter->InjConvRemaining))
\r
2469 status = HAL_ERROR;
\r
2471 else if ((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
\r
2472 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR))
\r
2474 status = HAL_ERROR;
\r
2476 /* Check DFSDM filter state */
\r
2477 else if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
\r
2478 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
\r
2480 /* Set callbacks on DMA handler */
\r
2481 hdfsdm_filter->hdmaInj->XferCpltCallback = DFSDM_DMAInjectedConvCplt;
\r
2482 hdfsdm_filter->hdmaInj->XferErrorCallback = DFSDM_DMAError;
\r
2483 hdfsdm_filter->hdmaInj->XferHalfCpltCallback = (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR) ? \
\r
2484 DFSDM_DMAInjectedHalfConvCplt : NULL;
\r
2486 /* Start DMA in interrupt mode */
\r
2487 if (HAL_DMA_Start_IT(hdfsdm_filter->hdmaInj, (uint32_t)&hdfsdm_filter->Instance->FLTJDATAR, \
\r
2488 (uint32_t) pData, Length) != HAL_OK)
\r
2490 /* Set DFSDM filter in error state */
\r
2491 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
\r
2492 status = HAL_ERROR;
\r
2496 /* Start injected conversion */
\r
2497 DFSDM_InjConvStart(hdfsdm_filter);
\r
2502 status = HAL_ERROR;
\r
2504 /* Return function status */
\r
2509 * @brief This function allows to start injected conversion in DMA mode and to get
\r
2510 * only the 16 most significant bits of conversion.
\r
2511 * @note This function should be called only when DFSDM filter instance is
\r
2512 * in idle state or if regular conversion is ongoing.
\r
2513 * Please note that data on buffer will contain signed 16 most significant
\r
2514 * bits of injected conversion.
\r
2515 * @param hdfsdm_filter DFSDM filter handle.
\r
2516 * @param pData The destination buffer address.
\r
2517 * @param Length The length of data to be transferred from DFSDM filter to memory.
\r
2518 * @retval HAL status
\r
2520 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedMsbStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
2524 HAL_StatusTypeDef status = HAL_OK;
\r
2526 /* Check parameters */
\r
2527 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2529 /* Check destination address and length */
\r
2530 if ((pData == NULL) || (Length == 0U))
\r
2532 status = HAL_ERROR;
\r
2534 /* Check that DMA is enabled for injected conversion */
\r
2535 else if ((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_JDMAEN) != DFSDM_FLTCR1_JDMAEN)
\r
2537 status = HAL_ERROR;
\r
2539 /* Check parameters compatibility */
\r
2540 else if ((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
\r
2541 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_NORMAL) && \
\r
2542 (Length > hdfsdm_filter->InjConvRemaining))
\r
2544 status = HAL_ERROR;
\r
2546 else if ((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
\r
2547 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR))
\r
2549 status = HAL_ERROR;
\r
2551 /* Check DFSDM filter state */
\r
2552 else if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
\r
2553 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
\r
2555 /* Set callbacks on DMA handler */
\r
2556 hdfsdm_filter->hdmaInj->XferCpltCallback = DFSDM_DMAInjectedConvCplt;
\r
2557 hdfsdm_filter->hdmaInj->XferErrorCallback = DFSDM_DMAError;
\r
2558 hdfsdm_filter->hdmaInj->XferHalfCpltCallback = (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR) ? \
\r
2559 DFSDM_DMAInjectedHalfConvCplt : NULL;
\r
2561 /* Start DMA in interrupt mode */
\r
2562 if (HAL_DMA_Start_IT(hdfsdm_filter->hdmaInj, (uint32_t)(&hdfsdm_filter->Instance->FLTJDATAR) + 2U, \
\r
2563 (uint32_t) pData, Length) != HAL_OK)
\r
2565 /* Set DFSDM filter in error state */
\r
2566 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
\r
2567 status = HAL_ERROR;
\r
2571 /* Start injected conversion */
\r
2572 DFSDM_InjConvStart(hdfsdm_filter);
\r
2577 status = HAL_ERROR;
\r
2579 /* Return function status */
\r
2584 * @brief This function allows to stop injected conversion in DMA mode.
\r
2585 * @note This function should be called only if injected conversion is ongoing.
\r
2586 * @param hdfsdm_filter DFSDM filter handle.
\r
2587 * @retval HAL status
\r
2589 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
2591 HAL_StatusTypeDef status = HAL_OK;
\r
2593 /* Check parameters */
\r
2594 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2596 /* Check DFSDM filter state */
\r
2597 if ((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
\r
2598 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
\r
2600 /* Return error status */
\r
2601 status = HAL_ERROR;
\r
2605 /* Stop current DMA transfer */
\r
2606 if (HAL_DMA_Abort(hdfsdm_filter->hdmaInj) != HAL_OK)
\r
2608 /* Set DFSDM filter in error state */
\r
2609 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
\r
2610 status = HAL_ERROR;
\r
2614 /* Stop regular conversion */
\r
2615 DFSDM_InjConvStop(hdfsdm_filter);
\r
2618 /* Return function status */
\r
2623 * @brief This function allows to get injected conversion value.
\r
2624 * @param hdfsdm_filter DFSDM filter handle.
\r
2625 * @param Channel Corresponding channel of injected conversion.
\r
2626 * @retval Injected conversion value
\r
2628 int32_t HAL_DFSDM_FilterGetInjectedValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
2629 uint32_t *Channel)
\r
2634 /* Check parameters */
\r
2635 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2636 assert_param(Channel != (void *)0);
\r
2638 /* Get value of data register for injected channel */
\r
2639 reg = hdfsdm_filter->Instance->FLTJDATAR;
\r
2641 /* Extract channel and injected conversion value */
\r
2642 *Channel = (reg & DFSDM_FLTJDATAR_JDATACH);
\r
2643 /* Injected conversion value is a signed value located on 24 MSB of register */
\r
2644 /* So after applying a mask on these bits we have to perform a division by 256 (2 raised to the power of 8) */
\r
2645 reg &= DFSDM_FLTJDATAR_JDATA;
\r
2646 value = ((int32_t)reg) / 256;
\r
2648 /* return regular conversion value */
\r
2653 * @brief This function allows to start filter analog watchdog in interrupt mode.
\r
2654 * @param hdfsdm_filter DFSDM filter handle.
\r
2655 * @param awdParam DFSDM filter analog watchdog parameters.
\r
2656 * @retval HAL status
\r
2658 HAL_StatusTypeDef HAL_DFSDM_FilterAwdStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
2659 DFSDM_Filter_AwdParamTypeDef *awdParam)
\r
2661 HAL_StatusTypeDef status = HAL_OK;
\r
2663 /* Check parameters */
\r
2664 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2665 assert_param(IS_DFSDM_FILTER_AWD_DATA_SOURCE(awdParam->DataSource));
\r
2666 assert_param(IS_DFSDM_INJECTED_CHANNEL(awdParam->Channel));
\r
2667 assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam->HighThreshold));
\r
2668 assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam->LowThreshold));
\r
2669 assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam->HighBreakSignal));
\r
2670 assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam->LowBreakSignal));
\r
2672 /* Check DFSDM filter state */
\r
2673 if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
\r
2674 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
\r
2676 /* Return error status */
\r
2677 status = HAL_ERROR;
\r
2681 /* Set analog watchdog data source */
\r
2682 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_AWFSEL);
\r
2683 hdfsdm_filter->Instance->FLTCR1 |= awdParam->DataSource;
\r
2685 /* Set thresholds and break signals */
\r
2686 hdfsdm_filter->Instance->FLTAWHTR &= ~(DFSDM_FLTAWHTR_AWHT | DFSDM_FLTAWHTR_BKAWH);
\r
2687 hdfsdm_filter->Instance->FLTAWHTR |= (((uint32_t) awdParam->HighThreshold << DFSDM_FLTAWHTR_AWHT_Pos) | \
\r
2688 awdParam->HighBreakSignal);
\r
2689 hdfsdm_filter->Instance->FLTAWLTR &= ~(DFSDM_FLTAWLTR_AWLT | DFSDM_FLTAWLTR_BKAWL);
\r
2690 hdfsdm_filter->Instance->FLTAWLTR |= (((uint32_t) awdParam->LowThreshold << DFSDM_FLTAWLTR_AWLT_Pos) | \
\r
2691 awdParam->LowBreakSignal);
\r
2693 /* Set channels and interrupt for analog watchdog */
\r
2694 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_AWDCH);
\r
2695 hdfsdm_filter->Instance->FLTCR2 |= (((awdParam->Channel & DFSDM_LSB_MASK) << DFSDM_FLTCR2_AWDCH_Pos) | \
\r
2696 DFSDM_FLTCR2_AWDIE);
\r
2698 /* Return function status */
\r
2703 * @brief This function allows to stop filter analog watchdog in interrupt mode.
\r
2704 * @param hdfsdm_filter DFSDM filter handle.
\r
2705 * @retval HAL status
\r
2707 HAL_StatusTypeDef HAL_DFSDM_FilterAwdStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
2709 HAL_StatusTypeDef status = HAL_OK;
\r
2711 /* Check parameters */
\r
2712 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2714 /* Check DFSDM filter state */
\r
2715 if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
\r
2716 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
\r
2718 /* Return error status */
\r
2719 status = HAL_ERROR;
\r
2723 /* Reset channels for analog watchdog and deactivate interrupt */
\r
2724 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_AWDCH | DFSDM_FLTCR2_AWDIE);
\r
2726 /* Clear all analog watchdog flags */
\r
2727 hdfsdm_filter->Instance->FLTAWCFR = (DFSDM_FLTAWCFR_CLRAWHTF | DFSDM_FLTAWCFR_CLRAWLTF);
\r
2729 /* Reset thresholds and break signals */
\r
2730 hdfsdm_filter->Instance->FLTAWHTR &= ~(DFSDM_FLTAWHTR_AWHT | DFSDM_FLTAWHTR_BKAWH);
\r
2731 hdfsdm_filter->Instance->FLTAWLTR &= ~(DFSDM_FLTAWLTR_AWLT | DFSDM_FLTAWLTR_BKAWL);
\r
2733 /* Reset analog watchdog data source */
\r
2734 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_AWFSEL);
\r
2736 /* Return function status */
\r
2741 * @brief This function allows to start extreme detector feature.
\r
2742 * @param hdfsdm_filter DFSDM filter handle.
\r
2743 * @param Channel Channels where extreme detector is enabled.
\r
2744 * This parameter can be a values combination of @ref DFSDM_Channel_Selection.
\r
2745 * @retval HAL status
\r
2747 HAL_StatusTypeDef HAL_DFSDM_FilterExdStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
2750 HAL_StatusTypeDef status = HAL_OK;
\r
2752 /* Check parameters */
\r
2753 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2754 assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel));
\r
2756 /* Check DFSDM filter state */
\r
2757 if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
\r
2758 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
\r
2760 /* Return error status */
\r
2761 status = HAL_ERROR;
\r
2765 /* Set channels for extreme detector */
\r
2766 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_EXCH);
\r
2767 hdfsdm_filter->Instance->FLTCR2 |= ((Channel & DFSDM_LSB_MASK) << DFSDM_FLTCR2_EXCH_Pos);
\r
2769 /* Return function status */
\r
2774 * @brief This function allows to stop extreme detector feature.
\r
2775 * @param hdfsdm_filter DFSDM filter handle.
\r
2776 * @retval HAL status
\r
2778 HAL_StatusTypeDef HAL_DFSDM_FilterExdStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
2780 HAL_StatusTypeDef status = HAL_OK;
\r
2781 __IO uint32_t reg1;
\r
2782 __IO uint32_t reg2;
\r
2784 /* Check parameters */
\r
2785 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2787 /* Check DFSDM filter state */
\r
2788 if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
\r
2789 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
\r
2791 /* Return error status */
\r
2792 status = HAL_ERROR;
\r
2796 /* Reset channels for extreme detector */
\r
2797 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_EXCH);
\r
2799 /* Clear extreme detector values */
\r
2800 reg1 = hdfsdm_filter->Instance->FLTEXMAX;
\r
2801 reg2 = hdfsdm_filter->Instance->FLTEXMIN;
\r
2802 UNUSED(reg1); /* To avoid GCC warning */
\r
2803 UNUSED(reg2); /* To avoid GCC warning */
\r
2805 /* Return function status */
\r
2810 * @brief This function allows to get extreme detector maximum value.
\r
2811 * @param hdfsdm_filter DFSDM filter handle.
\r
2812 * @param Channel Corresponding channel.
\r
2813 * @retval Extreme detector maximum value
\r
2814 * This value is between Min_Data = -8388608 and Max_Data = 8388607.
\r
2816 int32_t HAL_DFSDM_FilterGetExdMaxValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
2817 uint32_t *Channel)
\r
2822 /* Check parameters */
\r
2823 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2824 assert_param(Channel != (void *)0);
\r
2826 /* Get value of extreme detector maximum register */
\r
2827 reg = hdfsdm_filter->Instance->FLTEXMAX;
\r
2829 /* Extract channel and extreme detector maximum value */
\r
2830 *Channel = (reg & DFSDM_FLTEXMAX_EXMAXCH);
\r
2831 /* Extreme detector maximum value is a signed value located on 24 MSB of register */
\r
2832 /* So after applying a mask on these bits we have to perform a division by 256 (2 raised to the power of 8) */
\r
2833 reg &= DFSDM_FLTEXMAX_EXMAX;
\r
2834 value = ((int32_t)reg) / 256;
\r
2836 /* return extreme detector maximum value */
\r
2841 * @brief This function allows to get extreme detector minimum value.
\r
2842 * @param hdfsdm_filter DFSDM filter handle.
\r
2843 * @param Channel Corresponding channel.
\r
2844 * @retval Extreme detector minimum value
\r
2845 * This value is between Min_Data = -8388608 and Max_Data = 8388607.
\r
2847 int32_t HAL_DFSDM_FilterGetExdMinValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
2848 uint32_t *Channel)
\r
2853 /* Check parameters */
\r
2854 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2855 assert_param(Channel != (void *)0);
\r
2857 /* Get value of extreme detector minimum register */
\r
2858 reg = hdfsdm_filter->Instance->FLTEXMIN;
\r
2860 /* Extract channel and extreme detector minimum value */
\r
2861 *Channel = (reg & DFSDM_FLTEXMIN_EXMINCH);
\r
2862 /* Extreme detector minimum value is a signed value located on 24 MSB of register */
\r
2863 /* So after applying a mask on these bits we have to perform a division by 256 (2 raised to the power of 8) */
\r
2864 reg &= DFSDM_FLTEXMIN_EXMIN;
\r
2865 value = ((int32_t)reg) / 256;
\r
2867 /* return extreme detector minimum value */
\r
2872 * @brief This function allows to get conversion time value.
\r
2873 * @param hdfsdm_filter DFSDM filter handle.
\r
2874 * @retval Conversion time value
\r
2875 * @note To get time in second, this value has to be divided by DFSDM clock frequency.
\r
2877 uint32_t HAL_DFSDM_FilterGetConvTimeValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
2882 /* Check parameters */
\r
2883 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
\r
2885 /* Get value of conversion timer register */
\r
2886 reg = hdfsdm_filter->Instance->FLTCNVTIMR;
\r
2888 /* Extract conversion time value */
\r
2889 value = ((reg & DFSDM_FLTCNVTIMR_CNVCNT) >> DFSDM_FLTCNVTIMR_CNVCNT_Pos);
\r
2891 /* return extreme detector minimum value */
\r
2896 * @brief This function handles the DFSDM interrupts.
\r
2897 * @param hdfsdm_filter DFSDM filter handle.
\r
2900 void HAL_DFSDM_IRQHandler(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
2902 /* Get FTLISR and FLTCR2 register values */
\r
2903 const uint32_t temp_fltisr = hdfsdm_filter->Instance->FLTISR;
\r
2904 const uint32_t temp_fltcr2 = hdfsdm_filter->Instance->FLTCR2;
\r
2906 /* Check if overrun occurs during regular conversion */
\r
2907 if (((temp_fltisr & DFSDM_FLTISR_ROVRF) != 0U) && \
\r
2908 ((temp_fltcr2 & DFSDM_FLTCR2_ROVRIE) != 0U))
\r
2910 /* Clear regular overrun flag */
\r
2911 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRROVRF;
\r
2913 /* Update error code */
\r
2914 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_REGULAR_OVERRUN;
\r
2916 /* Call error callback */
\r
2917 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
2918 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
\r
2920 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
\r
2923 /* Check if overrun occurs during injected conversion */
\r
2924 else if (((temp_fltisr & DFSDM_FLTISR_JOVRF) != 0U) && \
\r
2925 ((temp_fltcr2 & DFSDM_FLTCR2_JOVRIE) != 0U))
\r
2927 /* Clear injected overrun flag */
\r
2928 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRJOVRF;
\r
2930 /* Update error code */
\r
2931 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INJECTED_OVERRUN;
\r
2933 /* Call error callback */
\r
2934 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
2935 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
\r
2937 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
\r
2940 /* Check if end of regular conversion */
\r
2941 else if (((temp_fltisr & DFSDM_FLTISR_REOCF) != 0U) && \
\r
2942 ((temp_fltcr2 & DFSDM_FLTCR2_REOCIE) != 0U))
\r
2944 /* Call regular conversion complete callback */
\r
2945 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
2946 hdfsdm_filter->RegConvCpltCallback(hdfsdm_filter);
\r
2948 HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter);
\r
2951 /* End of conversion if mode is not continuous and software trigger */
\r
2952 if ((hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
\r
2953 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
\r
2955 /* Disable interrupts for regular conversions */
\r
2956 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_REOCIE);
\r
2958 /* Update DFSDM filter state */
\r
2959 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \
\r
2960 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ;
\r
2963 /* Check if end of injected conversion */
\r
2964 else if (((temp_fltisr & DFSDM_FLTISR_JEOCF) != 0U) && \
\r
2965 ((temp_fltcr2 & DFSDM_FLTCR2_JEOCIE) != 0U))
\r
2967 /* Call injected conversion complete callback */
\r
2968 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
2969 hdfsdm_filter->InjConvCpltCallback(hdfsdm_filter);
\r
2971 HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter);
\r
2974 /* Update remaining injected conversions */
\r
2975 hdfsdm_filter->InjConvRemaining--;
\r
2976 if (hdfsdm_filter->InjConvRemaining == 0U)
\r
2978 /* End of conversion if trigger is software */
\r
2979 if (hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
\r
2981 /* Disable interrupts for injected conversions */
\r
2982 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_JEOCIE);
\r
2984 /* Update DFSDM filter state */
\r
2985 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \
\r
2986 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG;
\r
2988 /* end of injected sequence, reset the value */
\r
2989 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
\r
2990 hdfsdm_filter->InjectedChannelsNbr : 1U;
\r
2993 /* Check if analog watchdog occurs */
\r
2994 else if (((temp_fltisr & DFSDM_FLTISR_AWDF) != 0U) && \
\r
2995 ((temp_fltcr2 & DFSDM_FLTCR2_AWDIE) != 0U))
\r
2998 uint32_t threshold;
\r
2999 uint32_t channel = 0;
\r
3001 /* Get channel and threshold */
\r
3002 reg = hdfsdm_filter->Instance->FLTAWSR;
\r
3003 threshold = ((reg & DFSDM_FLTAWSR_AWLTF) != 0U) ? DFSDM_AWD_LOW_THRESHOLD : DFSDM_AWD_HIGH_THRESHOLD;
\r
3004 if (threshold == DFSDM_AWD_HIGH_THRESHOLD)
\r
3006 reg = reg >> DFSDM_FLTAWSR_AWHTF_Pos;
\r
3008 while (((reg & 1U) == 0U) && (channel < (DFSDM1_CHANNEL_NUMBER - 1U)))
\r
3013 /* Clear analog watchdog flag */
\r
3014 hdfsdm_filter->Instance->FLTAWCFR = (threshold == DFSDM_AWD_HIGH_THRESHOLD) ? \
\r
3015 (1UL << (DFSDM_FLTAWSR_AWHTF_Pos + channel)) : \
\r
3018 /* Call analog watchdog callback */
\r
3019 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
3020 hdfsdm_filter->AwdCallback(hdfsdm_filter, channel, threshold);
\r
3022 HAL_DFSDM_FilterAwdCallback(hdfsdm_filter, channel, threshold);
\r
3025 /* Check if clock absence occurs */
\r
3026 else if ((hdfsdm_filter->Instance == DFSDM1_Filter0) && \
\r
3027 ((temp_fltisr & DFSDM_FLTISR_CKABF) != 0U) && \
\r
3028 ((temp_fltcr2 & DFSDM_FLTCR2_CKABIE) != 0U))
\r
3031 uint32_t channel = 0;
\r
3033 reg = ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_CKABF) >> DFSDM_FLTISR_CKABF_Pos);
\r
3035 while (channel < DFSDM1_CHANNEL_NUMBER)
\r
3037 /* Check if flag is set and corresponding channel is enabled */
\r
3038 if (((reg & 1U) != 0U) && (a_dfsdm1ChannelHandle[channel] != NULL))
\r
3040 /* Check clock absence has been enabled for this channel */
\r
3041 if ((a_dfsdm1ChannelHandle[channel]->Instance->CHCFGR1 & DFSDM_CHCFGR1_CKABEN) != 0U)
\r
3043 /* Clear clock absence flag */
\r
3044 hdfsdm_filter->Instance->FLTICR = (1UL << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
\r
3046 /* Call clock absence callback */
\r
3047 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
3048 a_dfsdm1ChannelHandle[channel]->CkabCallback(a_dfsdm1ChannelHandle[channel]);
\r
3050 HAL_DFSDM_ChannelCkabCallback(a_dfsdm1ChannelHandle[channel]);
\r
3058 /* Check if short circuit detection occurs */
\r
3059 else if ((hdfsdm_filter->Instance == DFSDM1_Filter0) && \
\r
3060 ((temp_fltisr & DFSDM_FLTISR_SCDF) != 0U) && \
\r
3061 ((temp_fltcr2 & DFSDM_FLTCR2_SCDIE) != 0U))
\r
3064 uint32_t channel = 0;
\r
3067 reg = ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_SCDF) >> DFSDM_FLTISR_SCDF_Pos);
\r
3068 while (((reg & 1U) == 0U) && (channel < (DFSDM1_CHANNEL_NUMBER - 1U)))
\r
3074 /* Clear short circuit detection flag */
\r
3075 hdfsdm_filter->Instance->FLTICR = (1UL << (DFSDM_FLTICR_CLRSCDF_Pos + channel));
\r
3077 /* Call short circuit detection callback */
\r
3078 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
3079 a_dfsdm1ChannelHandle[channel]->ScdCallback(a_dfsdm1ChannelHandle[channel]);
\r
3081 HAL_DFSDM_ChannelScdCallback(a_dfsdm1ChannelHandle[channel]);
\r
3087 * @brief Regular conversion complete callback.
\r
3088 * @note In interrupt mode, user has to read conversion value in this function
\r
3089 * using HAL_DFSDM_FilterGetRegularValue.
\r
3090 * @param hdfsdm_filter DFSDM filter handle.
\r
3093 __weak void HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
3095 /* Prevent unused argument(s) compilation warning */
\r
3096 UNUSED(hdfsdm_filter);
\r
3098 /* NOTE : This function should not be modified, when the callback is needed,
\r
3099 the HAL_DFSDM_FilterRegConvCpltCallback could be implemented in the user file.
\r
3104 * @brief Half regular conversion complete callback.
\r
3105 * @param hdfsdm_filter DFSDM filter handle.
\r
3108 __weak void HAL_DFSDM_FilterRegConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
3110 /* Prevent unused argument(s) compilation warning */
\r
3111 UNUSED(hdfsdm_filter);
\r
3113 /* NOTE : This function should not be modified, when the callback is needed,
\r
3114 the HAL_DFSDM_FilterRegConvHalfCpltCallback could be implemented in the user file.
\r
3119 * @brief Injected conversion complete callback.
\r
3120 * @note In interrupt mode, user has to read conversion value in this function
\r
3121 * using HAL_DFSDM_FilterGetInjectedValue.
\r
3122 * @param hdfsdm_filter DFSDM filter handle.
\r
3125 __weak void HAL_DFSDM_FilterInjConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
3127 /* Prevent unused argument(s) compilation warning */
\r
3128 UNUSED(hdfsdm_filter);
\r
3130 /* NOTE : This function should not be modified, when the callback is needed,
\r
3131 the HAL_DFSDM_FilterInjConvCpltCallback could be implemented in the user file.
\r
3136 * @brief Half injected conversion complete callback.
\r
3137 * @param hdfsdm_filter DFSDM filter handle.
\r
3140 __weak void HAL_DFSDM_FilterInjConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
3142 /* Prevent unused argument(s) compilation warning */
\r
3143 UNUSED(hdfsdm_filter);
\r
3145 /* NOTE : This function should not be modified, when the callback is needed,
\r
3146 the HAL_DFSDM_FilterInjConvHalfCpltCallback could be implemented in the user file.
\r
3151 * @brief Filter analog watchdog callback.
\r
3152 * @param hdfsdm_filter DFSDM filter handle.
\r
3153 * @param Channel Corresponding channel.
\r
3154 * @param Threshold Low or high threshold has been reached.
\r
3157 __weak void HAL_DFSDM_FilterAwdCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
\r
3158 uint32_t Channel, uint32_t Threshold)
\r
3160 /* Prevent unused argument(s) compilation warning */
\r
3161 UNUSED(hdfsdm_filter);
\r
3163 UNUSED(Threshold);
\r
3165 /* NOTE : This function should not be modified, when the callback is needed,
\r
3166 the HAL_DFSDM_FilterAwdCallback could be implemented in the user file.
\r
3171 * @brief Error callback.
\r
3172 * @param hdfsdm_filter DFSDM filter handle.
\r
3175 __weak void HAL_DFSDM_FilterErrorCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
3177 /* Prevent unused argument(s) compilation warning */
\r
3178 UNUSED(hdfsdm_filter);
\r
3180 /* NOTE : This function should not be modified, when the callback is needed,
\r
3181 the HAL_DFSDM_FilterErrorCallback could be implemented in the user file.
\r
3189 /** @defgroup DFSDM_Exported_Functions_Group4_Filter Filter state functions
\r
3190 * @brief Filter state functions
\r
3193 ==============================================================================
\r
3194 ##### Filter state functions #####
\r
3195 ==============================================================================
\r
3196 [..] This section provides functions allowing to:
\r
3197 (+) Get the DFSDM filter state.
\r
3198 (+) Get the DFSDM filter error.
\r
3204 * @brief This function allows to get the current DFSDM filter handle state.
\r
3205 * @param hdfsdm_filter DFSDM filter handle.
\r
3206 * @retval DFSDM filter state.
\r
3208 HAL_DFSDM_Filter_StateTypeDef HAL_DFSDM_FilterGetState(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
3210 /* Return DFSDM filter handle state */
\r
3211 return hdfsdm_filter->State;
\r
3215 * @brief This function allows to get the current DFSDM filter error.
\r
3216 * @param hdfsdm_filter DFSDM filter handle.
\r
3217 * @retval DFSDM filter error code.
\r
3219 uint32_t HAL_DFSDM_FilterGetError(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
3221 return hdfsdm_filter->ErrorCode;
\r
3231 /* End of exported functions -------------------------------------------------*/
\r
3233 /* Private functions ---------------------------------------------------------*/
\r
3234 /** @addtogroup DFSDM_Private_Functions DFSDM Private Functions
\r
3239 * @brief DMA half transfer complete callback for regular conversion.
\r
3240 * @param hdma DMA handle.
\r
3243 static void DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef *hdma)
\r
3245 /* Get DFSDM filter handle */
\r
3246 DFSDM_Filter_HandleTypeDef *hdfsdm_filter = (DFSDM_Filter_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
\r
3248 /* Call regular half conversion complete callback */
\r
3249 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
3250 hdfsdm_filter->RegConvHalfCpltCallback(hdfsdm_filter);
\r
3252 HAL_DFSDM_FilterRegConvHalfCpltCallback(hdfsdm_filter);
\r
3257 * @brief DMA transfer complete callback for regular conversion.
\r
3258 * @param hdma DMA handle.
\r
3261 static void DFSDM_DMARegularConvCplt(DMA_HandleTypeDef *hdma)
\r
3263 /* Get DFSDM filter handle */
\r
3264 DFSDM_Filter_HandleTypeDef *hdfsdm_filter = (DFSDM_Filter_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
\r
3266 /* Call regular conversion complete callback */
\r
3267 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
3268 hdfsdm_filter->RegConvCpltCallback(hdfsdm_filter);
\r
3270 HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter);
\r
3275 * @brief DMA half transfer complete callback for injected conversion.
\r
3276 * @param hdma DMA handle.
\r
3279 static void DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef *hdma)
\r
3281 /* Get DFSDM filter handle */
\r
3282 DFSDM_Filter_HandleTypeDef *hdfsdm_filter = (DFSDM_Filter_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
\r
3284 /* Call injected half conversion complete callback */
\r
3285 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
3286 hdfsdm_filter->InjConvHalfCpltCallback(hdfsdm_filter);
\r
3288 HAL_DFSDM_FilterInjConvHalfCpltCallback(hdfsdm_filter);
\r
3293 * @brief DMA transfer complete callback for injected conversion.
\r
3294 * @param hdma DMA handle.
\r
3297 static void DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef *hdma)
\r
3299 /* Get DFSDM filter handle */
\r
3300 DFSDM_Filter_HandleTypeDef *hdfsdm_filter = (DFSDM_Filter_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
\r
3302 /* Call injected conversion complete callback */
\r
3303 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
3304 hdfsdm_filter->InjConvCpltCallback(hdfsdm_filter);
\r
3306 HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter);
\r
3311 * @brief DMA error callback.
\r
3312 * @param hdma DMA handle.
\r
3315 static void DFSDM_DMAError(DMA_HandleTypeDef *hdma)
\r
3317 /* Get DFSDM filter handle */
\r
3318 DFSDM_Filter_HandleTypeDef *hdfsdm_filter = (DFSDM_Filter_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
\r
3320 /* Update error code */
\r
3321 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_DMA;
\r
3323 /* Call error callback */
\r
3324 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
\r
3325 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
\r
3327 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
\r
3332 * @brief This function allows to get the number of injected channels.
\r
3333 * @param Channels bitfield of injected channels.
\r
3334 * @retval Number of injected channels.
\r
3336 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels)
\r
3338 uint32_t nbChannels = 0;
\r
3341 /* Get the number of channels from bitfield */
\r
3342 tmp = (uint32_t)(Channels & DFSDM_LSB_MASK);
\r
3345 if ((tmp & 1U) != 0U)
\r
3349 tmp = (uint32_t)(tmp >> 1);
\r
3351 return nbChannels;
\r
3355 * @brief This function allows to get the channel number from channel instance.
\r
3356 * @param Instance DFSDM channel instance.
\r
3357 * @retval Channel number.
\r
3359 static uint32_t DFSDM_GetChannelFromInstance(const DFSDM_Channel_TypeDef *Instance)
\r
3363 /* Get channel from instance */
\r
3364 if (Instance == DFSDM1_Channel0)
\r
3368 else if (Instance == DFSDM1_Channel1)
\r
3372 else if (Instance == DFSDM1_Channel2)
\r
3376 else if (Instance == DFSDM1_Channel3)
\r
3380 #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) || \
\r
3381 defined(STM32L496xx) || defined(STM32L4A6xx) || \
\r
3382 defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
\r
3383 else if (Instance == DFSDM1_Channel4)
\r
3387 else if (Instance == DFSDM1_Channel5)
\r
3391 else if (Instance == DFSDM1_Channel6)
\r
3395 else if (Instance == DFSDM1_Channel7)
\r
3399 #endif /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx || STM32L496xx || STM32L4A6xx || STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
\r
3409 * @brief This function allows to really start regular conversion.
\r
3410 * @param hdfsdm_filter DFSDM filter handle.
\r
3413 static void DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
3415 /* Check regular trigger */
\r
3416 if (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER)
\r
3418 /* Software start of regular conversion */
\r
3419 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
\r
3421 else /* synchronous trigger */
\r
3423 /* Disable DFSDM filter */
\r
3424 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
\r
3426 /* Set RSYNC bit in DFSDM_FLTCR1 register */
\r
3427 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSYNC;
\r
3429 /* Enable DFSDM filter */
\r
3430 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
\r
3432 /* If injected conversion was in progress, restart it */
\r
3433 if (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ)
\r
3435 if (hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
\r
3437 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART;
\r
3439 /* Update remaining injected conversions */
\r
3440 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
\r
3441 hdfsdm_filter->InjectedChannelsNbr : 1U;
\r
3444 /* Update DFSDM filter state */
\r
3445 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) ? \
\r
3446 HAL_DFSDM_FILTER_STATE_REG : HAL_DFSDM_FILTER_STATE_REG_INJ;
\r
3450 * @brief This function allows to really stop regular conversion.
\r
3451 * @param hdfsdm_filter DFSDM filter handle.
\r
3454 static void DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
3456 /* Disable DFSDM filter */
\r
3457 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
\r
3459 /* If regular trigger was synchronous, reset RSYNC bit in DFSDM_FLTCR1 register */
\r
3460 if (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SYNC_TRIGGER)
\r
3462 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RSYNC);
\r
3465 /* Enable DFSDM filter */
\r
3466 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
\r
3468 /* If injected conversion was in progress, restart it */
\r
3469 if (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG_INJ)
\r
3471 if (hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
\r
3473 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART;
\r
3475 /* Update remaining injected conversions */
\r
3476 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
\r
3477 hdfsdm_filter->InjectedChannelsNbr : 1U;
\r
3480 /* Update DFSDM filter state */
\r
3481 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \
\r
3482 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ;
\r
3486 * @brief This function allows to really start injected conversion.
\r
3487 * @param hdfsdm_filter DFSDM filter handle.
\r
3490 static void DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
3492 /* Check injected trigger */
\r
3493 if (hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
\r
3495 /* Software start of injected conversion */
\r
3496 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART;
\r
3498 else /* external or synchronous trigger */
\r
3500 /* Disable DFSDM filter */
\r
3501 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
\r
3503 if (hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SYNC_TRIGGER)
\r
3505 /* Set JSYNC bit in DFSDM_FLTCR1 register */
\r
3506 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSYNC;
\r
3508 else /* external trigger */
\r
3510 /* Set JEXTEN[1:0] bits in DFSDM_FLTCR1 register */
\r
3511 hdfsdm_filter->Instance->FLTCR1 |= hdfsdm_filter->ExtTriggerEdge;
\r
3514 /* Enable DFSDM filter */
\r
3515 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
\r
3517 /* If regular conversion was in progress, restart it */
\r
3518 if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) && \
\r
3519 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
\r
3521 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
\r
3524 /* Update DFSDM filter state */
\r
3525 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) ? \
\r
3526 HAL_DFSDM_FILTER_STATE_INJ : HAL_DFSDM_FILTER_STATE_REG_INJ;
\r
3530 * @brief This function allows to really stop injected conversion.
\r
3531 * @param hdfsdm_filter DFSDM filter handle.
\r
3534 static void DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
\r
3536 /* Disable DFSDM filter */
\r
3537 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
\r
3539 /* If injected trigger was synchronous, reset JSYNC bit in DFSDM_FLTCR1 register */
\r
3540 if (hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SYNC_TRIGGER)
\r
3542 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSYNC);
\r
3544 else if (hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_EXT_TRIGGER)
\r
3546 /* Reset JEXTEN[1:0] bits in DFSDM_FLTCR1 register */
\r
3547 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JEXTEN);
\r
3551 /* Nothing to do */
\r
3554 /* Enable DFSDM filter */
\r
3555 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
\r
3557 /* If regular conversion was in progress, restart it */
\r
3558 if ((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG_INJ) && \
\r
3559 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
\r
3561 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
\r
3564 /* Update remaining injected conversions */
\r
3565 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
\r
3566 hdfsdm_filter->InjectedChannelsNbr : 1U;
\r
3568 /* Update DFSDM filter state */
\r
3569 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \
\r
3570 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG;
\r
3576 /* End of private functions --------------------------------------------------*/
\r
3582 #endif /* STM32L451xx || STM32L452xx || STM32L462xx || STM32L471xx || STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx || STM32L496xx || STM32L4A6xx || STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
\r
3584 #endif /* HAL_DFSDM_MODULE_ENABLED */
\r
3590 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r