2 ******************************************************************************
3 * @file stm32f4xx_hal_dfsdm.c
4 * @author MCD Application Team
7 * @brief This file provides firmware functions to manage the following
8 * functionalities of the Digital Filter for Sigma-Delta Modulators
10 * + Initialization and configuration of channels and filters
11 * + Regular channels configuration
12 * + Injected channels configuration
13 * + Regular/Injected Channels DMA Configuration
14 * + Interrupts and flags management
15 * + Analog watchdog feature
16 * + Short-circuit detector feature
17 * + Extremes detector feature
18 * + Clock absence detector feature
19 * + Break generation on analog watchdog or short-circuit event
22 ==============================================================================
23 ##### How to use this driver #####
24 ==============================================================================
26 *** Channel initialization ***
27 ==============================
29 (#) User has first to initialize channels (before filters initialization).
30 (#) As prerequisite, fill in the HAL_DFSDM_ChannelMspInit() :
31 (++) Enable DFSDMz clock interface with __HAL_RCC_DFSDMz_CLK_ENABLE().
32 (++) Enable the clocks for the DFSDMz GPIOS with __HAL_RCC_GPIOx_CLK_ENABLE().
33 (++) Configure these DFSDMz pins in alternate mode using HAL_GPIO_Init().
34 (++) If interrupt mode is used, enable and configure DFSDMz_FLT0 global
35 interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
36 (#) Configure the output clock, input, serial interface, analog watchdog,
37 offset and data right bit shift parameters for this channel using the
38 HAL_DFSDM_ChannelInit() function.
40 *** Channel clock absence detector ***
41 ======================================
43 (#) Start clock absence detector using HAL_DFSDM_ChannelCkabStart() or
44 HAL_DFSDM_ChannelCkabStart_IT().
45 (#) In polling mode, use HAL_DFSDM_ChannelPollForCkab() to detect the clock
47 (#) In interrupt mode, HAL_DFSDM_ChannelCkabCallback() will be called if
48 clock absence is detected.
49 (#) Stop clock absence detector using HAL_DFSDM_ChannelCkabStop() or
50 HAL_DFSDM_ChannelCkabStop_IT().
51 (#) Please note that the same mode (polling or interrupt) has to be used
52 for all channels because the channels are sharing the same interrupt.
53 (#) Please note also that in interrupt mode, if clock absence detector is
54 stopped for one channel, interrupt will be disabled for all channels.
56 *** Channel short circuit detector ***
57 ======================================
59 (#) Start short circuit detector using HAL_DFSDM_ChannelScdStart() or
60 or HAL_DFSDM_ChannelScdStart_IT().
61 (#) In polling mode, use HAL_DFSDM_ChannelPollForScd() to detect short
63 (#) In interrupt mode, HAL_DFSDM_ChannelScdCallback() will be called if
64 short circuit is detected.
65 (#) Stop short circuit detector using HAL_DFSDM_ChannelScdStop() or
66 or HAL_DFSDM_ChannelScdStop_IT().
67 (#) Please note that the same mode (polling or interrupt) has to be used
68 for all channels because the channels are sharing the same interrupt.
69 (#) Please note also that in interrupt mode, if short circuit detector is
70 stopped for one channel, interrupt will be disabled for all channels.
72 *** Channel analog watchdog value ***
73 =====================================
75 (#) Get analog watchdog filter value of a channel using
76 HAL_DFSDM_ChannelGetAwdValue().
78 *** Channel offset value ***
79 =====================================
81 (#) Modify offset value of a channel using HAL_DFSDM_ChannelModifyOffset().
83 *** Filter initialization ***
84 =============================
86 (#) After channel initialization, user has to init filters.
87 (#) As prerequisite, fill in the HAL_DFSDM_FilterMspInit() :
88 (++) If interrupt mode is used , enable and configure DFSDMz_FLTx global
89 interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
90 Please note that DFSDMz_FLT0 global interrupt could be already
91 enabled if interrupt is used for channel.
92 (++) If DMA mode is used, configure DMA with HAL_DMA_Init() and link it
93 with DFSDMz filter handle using __HAL_LINKDMA().
94 (#) Configure the regular conversion, injected conversion and filter
95 parameters for this filter using the HAL_DFSDM_FilterInit() function.
97 *** Filter regular channel conversion ***
98 =========================================
100 (#) Select regular channel and enable/disable continuous mode using
101 HAL_DFSDM_FilterConfigRegChannel().
102 (#) Start regular conversion using HAL_DFSDM_FilterRegularStart(),
103 HAL_DFSDM_FilterRegularStart_IT(), HAL_DFSDM_FilterRegularStart_DMA() or
104 HAL_DFSDM_FilterRegularMsbStart_DMA().
105 (#) In polling mode, use HAL_DFSDM_FilterPollForRegConversion() to detect
106 the end of regular conversion.
107 (#) In interrupt mode, HAL_DFSDM_FilterRegConvCpltCallback() will be called
108 at the end of regular conversion.
109 (#) Get value of regular conversion and corresponding channel using
110 HAL_DFSDM_FilterGetRegularValue().
111 (#) In DMA mode, HAL_DFSDM_FilterRegConvHalfCpltCallback() and
112 HAL_DFSDM_FilterRegConvCpltCallback() will be called respectively at the
113 half transfer and at the transfer complete. Please note that
114 HAL_DFSDM_FilterRegConvHalfCpltCallback() will be called only in DMA
116 (#) Stop regular conversion using HAL_DFSDM_FilterRegularStop(),
117 HAL_DFSDM_FilterRegularStop_IT() or HAL_DFSDM_FilterRegularStop_DMA().
119 *** Filter injected channels conversion ***
120 ===========================================
122 (#) Select injected channels using HAL_DFSDM_FilterConfigInjChannel().
123 (#) Start injected conversion using HAL_DFSDM_FilterInjectedStart(),
124 HAL_DFSDM_FilterInjectedStart_IT(), HAL_DFSDM_FilterInjectedStart_DMA() or
125 HAL_DFSDM_FilterInjectedMsbStart_DMA().
126 (#) In polling mode, use HAL_DFSDM_FilterPollForInjConversion() to detect
127 the end of injected conversion.
128 (#) In interrupt mode, HAL_DFSDM_FilterInjConvCpltCallback() will be called
129 at the end of injected conversion.
130 (#) Get value of injected conversion and corresponding channel using
131 HAL_DFSDM_FilterGetInjectedValue().
132 (#) In DMA mode, HAL_DFSDM_FilterInjConvHalfCpltCallback() and
133 HAL_DFSDM_FilterInjConvCpltCallback() will be called respectively at the
134 half transfer and at the transfer complete. Please note that
135 HAL_DFSDM_FilterInjConvCpltCallback() will be called only in DMA
137 (#) Stop injected conversion using HAL_DFSDM_FilterInjectedStop(),
138 HAL_DFSDM_FilterInjectedStop_IT() or HAL_DFSDM_FilterInjectedStop_DMA().
140 *** Filter analog watchdog ***
141 ==============================
143 (#) Start filter analog watchdog using HAL_DFSDM_FilterAwdStart_IT().
144 (#) HAL_DFSDM_FilterAwdCallback() will be called if analog watchdog occurs.
145 (#) Stop filter analog watchdog using HAL_DFSDM_FilterAwdStop_IT().
147 *** Filter extreme detector ***
148 ===============================
150 (#) Start filter extreme detector using HAL_DFSDM_FilterExdStart().
151 (#) Get extreme detector maximum value using HAL_DFSDM_FilterGetExdMaxValue().
152 (#) Get extreme detector minimum value using HAL_DFSDM_FilterGetExdMinValue().
153 (#) Start filter extreme detector using HAL_DFSDM_FilterExdStop().
155 *** Filter conversion time ***
156 ==============================
158 (#) Get conversion time value using HAL_DFSDM_FilterGetConvTimeValue().
161 ******************************************************************************
164 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
166 * Redistribution and use in source and binary forms, with or without modification,
167 * are permitted provided that the following conditions are met:
168 * 1. Redistributions of source code must retain the above copyright notice,
169 * this list of conditions and the following disclaimer.
170 * 2. Redistributions in binary form must reproduce the above copyright notice,
171 * this list of conditions and the following disclaimer in the documentation
172 * and/or other materials provided with the distribution.
173 * 3. Neither the name of STMicroelectronics nor the names of its contributors
174 * may be used to endorse or promote products derived from this software
175 * without specific prior written permission.
177 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
178 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
179 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
180 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
181 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
182 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
183 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
184 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
185 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
186 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
188 ******************************************************************************
191 /* Includes ------------------------------------------------------------------*/
192 #include "stm32f4xx_hal.h"
194 /** @addtogroup STM32F4xx_HAL_Driver
197 #ifdef HAL_DFSDM_MODULE_ENABLED
198 #if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
199 /** @defgroup DFSDM DFSDM
200 * @brief DFSDM HAL driver module
204 /* Private typedef -----------------------------------------------------------*/
205 /* Private define ------------------------------------------------------------*/
206 /** @defgroup DFSDM_Private_Define DFSDM Private Define
209 #define DFSDM_CHCFGR1_CLK_DIV_OFFSET POSITION_VAL(DFSDM_CHCFGR1_CKOUTDIV)
210 #define DFSDM_CHAWSCDR_BKSCD_OFFSET POSITION_VAL(DFSDM_CHAWSCDR_BKSCD)
211 #define DFSDM_CHAWSCDR_FOSR_OFFSET POSITION_VAL(DFSDM_CHAWSCDR_AWFOSR)
212 #define DFSDM_CHCFGR2_OFFSET_OFFSET POSITION_VAL(DFSDM_CHCFGR2_OFFSET)
213 #define DFSDM_CHCFGR2_DTRBS_OFFSET POSITION_VAL(DFSDM_CHCFGR2_DTRBS)
214 #define DFSDM_FLTFCR_FOSR_OFFSET POSITION_VAL(DFSDM_FLTFCR_FOSR)
215 #define DFSDM_FLTCR1_MSB_RCH_OFFSET 8U
216 #define DFSDM_FLTCR2_EXCH_OFFSET POSITION_VAL(DFSDM_FLTCR2_EXCH)
217 #define DFSDM_FLTCR2_AWDCH_OFFSET POSITION_VAL(DFSDM_FLTCR2_AWDCH)
218 #define DFSDM_FLTISR_CKABF_OFFSET POSITION_VAL(DFSDM_FLTISR_CKABF)
219 #define DFSDM_FLTISR_SCDF_OFFSET POSITION_VAL(DFSDM_FLTISR_SCDF)
220 #define DFSDM_FLTICR_CLRCKABF_OFFSET POSITION_VAL(DFSDM_FLTICR_CLRCKABF)
221 #define DFSDM_FLTICR_CLRSCDF_OFFSET POSITION_VAL(DFSDM_FLTICR_CLRSCSDF)
222 #define DFSDM_FLTRDATAR_DATA_OFFSET POSITION_VAL(DFSDM_FLTRDATAR_RDATA)
223 #define DFSDM_FLTJDATAR_DATA_OFFSET POSITION_VAL(DFSDM_FLTJDATAR_JDATA)
224 #define DFSDM_FLTAWHTR_THRESHOLD_OFFSET POSITION_VAL(DFSDM_FLTAWHTR_AWHT)
225 #define DFSDM_FLTAWLTR_THRESHOLD_OFFSET POSITION_VAL(DFSDM_FLTAWLTR_AWLT)
226 #define DFSDM_FLTEXMAX_DATA_OFFSET POSITION_VAL(DFSDM_FLTEXMAX_EXMAX)
227 #define DFSDM_FLTEXMIN_DATA_OFFSET POSITION_VAL(DFSDM_FLTEXMIN_EXMIN)
228 #define DFSDM_FLTCNVTIMR_DATA_OFFSET POSITION_VAL(DFSDM_FLTCNVTIMR_CNVCNT)
229 #define DFSDM_FLTAWSR_HIGH_OFFSET POSITION_VAL(DFSDM_FLTAWSR_AWHTF)
230 #define DFSDM_MSB_MASK 0xFFFF0000U
231 #define DFSDM_LSB_MASK 0x0000FFFFU
232 #define DFSDM_CKAB_TIMEOUT 5000U
233 #define DFSDM1_CHANNEL_NUMBER 4U
234 #if defined (DFSDM2_Channel0)
235 #define DFSDM2_CHANNEL_NUMBER 8U
236 #endif /* DFSDM2_Channel0 */
241 /** @addtogroup DFSDM_Private_Macros
248 /* Private macro -------------------------------------------------------------*/
249 /* Private variables ---------------------------------------------------------*/
250 /** @defgroup DFSDM_Private_Variables DFSDM Private Variables
253 __IO
uint32_t v_dfsdm1ChannelCounter
= 0U;
254 DFSDM_Channel_HandleTypeDef
* a_dfsdm1ChannelHandle
[DFSDM1_CHANNEL_NUMBER
] = {NULL
};
256 #if defined (DFSDM2_Channel0)
257 __IO
uint32_t v_dfsdm2ChannelCounter
= 0U;
258 DFSDM_Channel_HandleTypeDef
* a_dfsdm2ChannelHandle
[DFSDM2_CHANNEL_NUMBER
] = {NULL
};
259 #endif /* DFSDM2_Channel0 */
264 /* Private function prototypes -----------------------------------------------*/
265 /** @defgroup DFSDM_Private_Functions DFSDM Private Functions
268 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels
);
269 static uint32_t DFSDM_GetChannelFromInstance(DFSDM_Channel_TypeDef
* Instance
);
270 static void DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
);
271 static void DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef
* hdfsdm_filter
);
272 static void DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef
* hdfsdm_filter
);
273 static void DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef
* hdfsdm_filter
);
274 static void DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef
*hdma
);
275 static void DFSDM_DMARegularConvCplt(DMA_HandleTypeDef
*hdma
);
276 static void DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef
*hdma
);
277 static void DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef
*hdma
);
278 static void DFSDM_DMAError(DMA_HandleTypeDef
*hdma
);
284 /* Exported functions --------------------------------------------------------*/
285 /** @defgroup DFSDM_Exported_Functions DFSDM Exported Functions
289 /** @defgroup DFSDM_Exported_Functions_Group1_Channel Channel initialization and de-initialization functions
290 * @brief Channel initialization and de-initialization functions
293 ==============================================================================
294 ##### Channel initialization and de-initialization functions #####
295 ==============================================================================
296 [..] This section provides functions allowing to:
297 (+) Initialize the DFSDM channel.
298 (+) De-initialize the DFSDM channel.
304 * @brief Initialize the DFSDM channel according to the specified parameters
305 * in the DFSDM_ChannelInitTypeDef structure and initialize the associated handle.
306 * @param hdfsdm_channel : DFSDM channel handle.
307 * @retval HAL status.
309 HAL_StatusTypeDef
HAL_DFSDM_ChannelInit(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
311 #if defined(DFSDM2_Channel0)
312 __IO
uint32_t* channelCounterPtr
;
313 DFSDM_Channel_HandleTypeDef
**channelHandleTable
;
314 DFSDM_Channel_TypeDef
* channel0Instance
;
315 #endif /* defined(DFSDM2_Channel0) */
317 /* Check DFSDM Channel handle */
318 if(hdfsdm_channel
== NULL
)
323 /* Check parameters */
324 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
325 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_channel
->Init
.OutputClock
.Activation
));
326 assert_param(IS_DFSDM_CHANNEL_INPUT(hdfsdm_channel
->Init
.Input
.Multiplexer
));
327 assert_param(IS_DFSDM_CHANNEL_DATA_PACKING(hdfsdm_channel
->Init
.Input
.DataPacking
));
328 assert_param(IS_DFSDM_CHANNEL_INPUT_PINS(hdfsdm_channel
->Init
.Input
.Pins
));
329 assert_param(IS_DFSDM_CHANNEL_SERIAL_INTERFACE_TYPE(hdfsdm_channel
->Init
.SerialInterface
.Type
));
330 assert_param(IS_DFSDM_CHANNEL_SPI_CLOCK(hdfsdm_channel
->Init
.SerialInterface
.SpiClock
));
331 assert_param(IS_DFSDM_CHANNEL_FILTER_ORDER(hdfsdm_channel
->Init
.Awd
.FilterOrder
));
332 assert_param(IS_DFSDM_CHANNEL_FILTER_OVS_RATIO(hdfsdm_channel
->Init
.Awd
.Oversampling
));
333 assert_param(IS_DFSDM_CHANNEL_OFFSET(hdfsdm_channel
->Init
.Offset
));
334 assert_param(IS_DFSDM_CHANNEL_RIGHT_BIT_SHIFT(hdfsdm_channel
->Init
.RightBitShift
));
336 #if defined(DFSDM2_Channel0)
337 /* Get channel counter, channel handle table and channel 0 instance */
338 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
340 channelCounterPtr
= &v_dfsdm1ChannelCounter
;
341 channelHandleTable
= a_dfsdm1ChannelHandle
;
342 channel0Instance
= DFSDM1_Channel0
;
346 channelCounterPtr
= &v_dfsdm2ChannelCounter
;
347 channelHandleTable
= a_dfsdm2ChannelHandle
;
348 channel0Instance
= DFSDM2_Channel0
;
351 /* Check that channel has not been already initialized */
352 if(channelHandleTable
[DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
)] != NULL
)
357 /* Call MSP init function */
358 HAL_DFSDM_ChannelMspInit(hdfsdm_channel
);
360 /* Update the channel counter */
361 (*channelCounterPtr
)++;
363 /* Configure output serial clock and enable global DFSDM interface only for first channel */
364 if(*channelCounterPtr
== 1U)
366 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK(hdfsdm_channel
->Init
.OutputClock
.Selection
));
367 /* Set the output serial clock source */
368 channel0Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CKOUTSRC
);
369 channel0Instance
->CHCFGR1
|= hdfsdm_channel
->Init
.OutputClock
.Selection
;
371 /* Reset clock divider */
372 channel0Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CKOUTDIV
);
373 if(hdfsdm_channel
->Init
.OutputClock
.Activation
== ENABLE
)
375 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK_DIVIDER(hdfsdm_channel
->Init
.OutputClock
.Divider
));
376 /* Set the output clock divider */
377 channel0Instance
->CHCFGR1
|= (uint32_t) ((hdfsdm_channel
->Init
.OutputClock
.Divider
- 1U) <<
378 DFSDM_CHCFGR1_CLK_DIV_OFFSET
);
381 /* enable the DFSDM global interface */
382 channel0Instance
->CHCFGR1
|= DFSDM_CHCFGR1_DFSDMEN
;
385 /* Set channel input parameters */
386 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_DATPACK
| DFSDM_CHCFGR1_DATMPX
|
387 DFSDM_CHCFGR1_CHINSEL
);
388 hdfsdm_channel
->Instance
->CHCFGR1
|= (hdfsdm_channel
->Init
.Input
.Multiplexer
|
389 hdfsdm_channel
->Init
.Input
.DataPacking
|
390 hdfsdm_channel
->Init
.Input
.Pins
);
392 /* Set serial interface parameters */
393 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_SITP
| DFSDM_CHCFGR1_SPICKSEL
);
394 hdfsdm_channel
->Instance
->CHCFGR1
|= (hdfsdm_channel
->Init
.SerialInterface
.Type
|
395 hdfsdm_channel
->Init
.SerialInterface
.SpiClock
);
397 /* Set analog watchdog parameters */
398 hdfsdm_channel
->Instance
->CHAWSCDR
&= ~(DFSDM_CHAWSCDR_AWFORD
| DFSDM_CHAWSCDR_AWFOSR
);
399 hdfsdm_channel
->Instance
->CHAWSCDR
|= (hdfsdm_channel
->Init
.Awd
.FilterOrder
|
400 ((hdfsdm_channel
->Init
.Awd
.Oversampling
- 1U) << DFSDM_CHAWSCDR_FOSR_OFFSET
));
402 /* Set channel offset and right bit shift */
403 hdfsdm_channel
->Instance
->CHCFGR2
&= ~(DFSDM_CHCFGR2_OFFSET
| DFSDM_CHCFGR2_DTRBS
);
404 hdfsdm_channel
->Instance
->CHCFGR2
|= (((uint32_t) hdfsdm_channel
->Init
.Offset
<< DFSDM_CHCFGR2_OFFSET_OFFSET
) |
405 (hdfsdm_channel
->Init
.RightBitShift
<< DFSDM_CHCFGR2_DTRBS_OFFSET
));
407 /* Enable DFSDM channel */
408 hdfsdm_channel
->Instance
->CHCFGR1
|= DFSDM_CHCFGR1_CHEN
;
410 /* Set DFSDM Channel to ready state */
411 hdfsdm_channel
->State
= HAL_DFSDM_CHANNEL_STATE_READY
;
413 /* Store channel handle in DFSDM channel handle table */
414 channelHandleTable
[DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
)] = hdfsdm_channel
;
417 /* Check that channel has not been already initialized */
418 if(a_dfsdm1ChannelHandle
[DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
)] != NULL
)
423 /* Call MSP init function */
424 HAL_DFSDM_ChannelMspInit(hdfsdm_channel
);
426 /* Update the channel counter */
427 v_dfsdm1ChannelCounter
++;
429 /* Configure output serial clock and enable global DFSDM interface only for first channel */
430 if(v_dfsdm1ChannelCounter
== 1U)
432 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK(hdfsdm_channel
->Init
.OutputClock
.Selection
));
433 /* Set the output serial clock source */
434 DFSDM1_Channel0
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CKOUTSRC
);
435 DFSDM1_Channel0
->CHCFGR1
|= hdfsdm_channel
->Init
.OutputClock
.Selection
;
437 /* Reset clock divider */
438 DFSDM1_Channel0
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CKOUTDIV
);
439 if(hdfsdm_channel
->Init
.OutputClock
.Activation
== ENABLE
)
441 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK_DIVIDER(hdfsdm_channel
->Init
.OutputClock
.Divider
));
442 /* Set the output clock divider */
443 DFSDM1_Channel0
->CHCFGR1
|= (uint32_t) ((hdfsdm_channel
->Init
.OutputClock
.Divider
- 1U) <<
444 DFSDM_CHCFGR1_CLK_DIV_OFFSET
);
447 /* enable the DFSDM global interface */
448 DFSDM1_Channel0
->CHCFGR1
|= DFSDM_CHCFGR1_DFSDMEN
;
451 /* Set channel input parameters */
452 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_DATPACK
| DFSDM_CHCFGR1_DATMPX
|
453 DFSDM_CHCFGR1_CHINSEL
);
454 hdfsdm_channel
->Instance
->CHCFGR1
|= (hdfsdm_channel
->Init
.Input
.Multiplexer
|
455 hdfsdm_channel
->Init
.Input
.DataPacking
|
456 hdfsdm_channel
->Init
.Input
.Pins
);
458 /* Set serial interface parameters */
459 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_SITP
| DFSDM_CHCFGR1_SPICKSEL
);
460 hdfsdm_channel
->Instance
->CHCFGR1
|= (hdfsdm_channel
->Init
.SerialInterface
.Type
|
461 hdfsdm_channel
->Init
.SerialInterface
.SpiClock
);
463 /* Set analog watchdog parameters */
464 hdfsdm_channel
->Instance
->CHAWSCDR
&= ~(DFSDM_CHAWSCDR_AWFORD
| DFSDM_CHAWSCDR_AWFOSR
);
465 hdfsdm_channel
->Instance
->CHAWSCDR
|= (hdfsdm_channel
->Init
.Awd
.FilterOrder
|
466 ((hdfsdm_channel
->Init
.Awd
.Oversampling
- 1U) << DFSDM_CHAWSCDR_FOSR_OFFSET
));
468 /* Set channel offset and right bit shift */
469 hdfsdm_channel
->Instance
->CHCFGR2
&= ~(DFSDM_CHCFGR2_OFFSET
| DFSDM_CHCFGR2_DTRBS
);
470 hdfsdm_channel
->Instance
->CHCFGR2
|= (((uint32_t) hdfsdm_channel
->Init
.Offset
<< DFSDM_CHCFGR2_OFFSET_OFFSET
) |
471 (hdfsdm_channel
->Init
.RightBitShift
<< DFSDM_CHCFGR2_DTRBS_OFFSET
));
473 /* Enable DFSDM channel */
474 hdfsdm_channel
->Instance
->CHCFGR1
|= DFSDM_CHCFGR1_CHEN
;
476 /* Set DFSDM Channel to ready state */
477 hdfsdm_channel
->State
= HAL_DFSDM_CHANNEL_STATE_READY
;
479 /* Store channel handle in DFSDM channel handle table */
480 a_dfsdm1ChannelHandle
[DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
)] = hdfsdm_channel
;
481 #endif /* DFSDM2_Channel0 */
487 * @brief De-initialize the DFSDM channel.
488 * @param hdfsdm_channel : DFSDM channel handle.
489 * @retval HAL status.
491 HAL_StatusTypeDef
HAL_DFSDM_ChannelDeInit(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
493 #if defined(DFSDM2_Channel0)
494 __IO
uint32_t* channelCounterPtr
;
495 DFSDM_Channel_HandleTypeDef
**channelHandleTable
;
496 DFSDM_Channel_TypeDef
* channel0Instance
;
497 #endif /* defined(DFSDM2_Channel0) */
499 /* Check DFSDM Channel handle */
500 if(hdfsdm_channel
== NULL
)
505 /* Check parameters */
506 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
508 #if defined(DFSDM2_Channel0)
509 /* Get channel counter, channel handle table and channel 0 instance */
510 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
512 channelCounterPtr
= &v_dfsdm1ChannelCounter
;
513 channelHandleTable
= a_dfsdm1ChannelHandle
;
514 channel0Instance
= DFSDM1_Channel0
;
518 channelCounterPtr
= &v_dfsdm2ChannelCounter
;
519 channelHandleTable
= a_dfsdm2ChannelHandle
;
520 channel0Instance
= DFSDM2_Channel0
;
523 /* Check that channel has not been already deinitialized */
524 if(channelHandleTable
[DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
)] == NULL
)
529 /* Disable the DFSDM channel */
530 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CHEN
);
532 /* Update the channel counter */
533 (*channelCounterPtr
)--;
535 /* Disable global DFSDM at deinit of last channel */
536 if(*channelCounterPtr
== 0U)
538 channel0Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_DFSDMEN
);
541 /* Call MSP deinit function */
542 HAL_DFSDM_ChannelMspDeInit(hdfsdm_channel
);
544 /* Set DFSDM Channel in reset state */
545 hdfsdm_channel
->State
= HAL_DFSDM_CHANNEL_STATE_RESET
;
547 /* Reset channel handle in DFSDM channel handle table */
548 channelHandleTable
[DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
)] = NULL
;
550 /* Check that channel has not been already deinitialized */
551 if(a_dfsdm1ChannelHandle
[DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
)] == NULL
)
556 /* Disable the DFSDM channel */
557 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CHEN
);
559 /* Update the channel counter */
560 v_dfsdm1ChannelCounter
--;
562 /* Disable global DFSDM at deinit of last channel */
563 if(v_dfsdm1ChannelCounter
== 0U)
565 DFSDM1_Channel0
->CHCFGR1
&= ~(DFSDM_CHCFGR1_DFSDMEN
);
568 /* Call MSP deinit function */
569 HAL_DFSDM_ChannelMspDeInit(hdfsdm_channel
);
571 /* Set DFSDM Channel in reset state */
572 hdfsdm_channel
->State
= HAL_DFSDM_CHANNEL_STATE_RESET
;
574 /* Reset channel handle in DFSDM channel handle table */
575 a_dfsdm1ChannelHandle
[DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
)] = (DFSDM_Channel_HandleTypeDef
*) NULL
;
576 #endif /* defined(DFSDM2_Channel0) */
582 * @brief Initialize the DFSDM channel MSP.
583 * @param hdfsdm_channel : DFSDM channel handle.
586 __weak
void HAL_DFSDM_ChannelMspInit(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
588 /* Prevent unused argument(s) compilation warning */
589 UNUSED(hdfsdm_channel
);
590 /* NOTE : This function should not be modified, when the function is needed,
591 the HAL_DFSDM_ChannelMspInit could be implemented in the user file.
596 * @brief De-initialize the DFSDM channel MSP.
597 * @param hdfsdm_channel : DFSDM channel handle.
600 __weak
void HAL_DFSDM_ChannelMspDeInit(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
602 /* Prevent unused argument(s) compilation warning */
603 UNUSED(hdfsdm_channel
);
604 /* NOTE : This function should not be modified, when the function is needed,
605 the HAL_DFSDM_ChannelMspDeInit could be implemented in the user file.
613 /** @defgroup DFSDM_Exported_Functions_Group2_Channel Channel operation functions
614 * @brief Channel operation functions
617 ==============================================================================
618 ##### Channel operation functions #####
619 ==============================================================================
620 [..] This section provides functions allowing to:
621 (+) Manage clock absence detector feature.
622 (+) Manage short circuit detector feature.
623 (+) Get analog watchdog value.
624 (+) Modify offset value.
630 * @brief This function allows to start clock absence detection in polling mode.
631 * @note Same mode has to be used for all channels.
632 * @note If clock is not available on this channel during 5 seconds,
633 * clock absence detection will not be activated and function
634 * will return HAL_TIMEOUT error.
635 * @param hdfsdm_channel : DFSDM channel handle.
638 HAL_StatusTypeDef
HAL_DFSDM_ChannelCkabStart(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
640 HAL_StatusTypeDef status
= HAL_OK
;
644 #if defined(DFSDM2_Channel0)
645 DFSDM_Filter_TypeDef
* filter0Instance
;
646 #endif /* defined(DFSDM2_Channel0) */
648 /* Check parameters */
649 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
651 /* Check DFSDM channel state */
652 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
654 /* Return error status */
659 #if defined (DFSDM2_Channel0)
660 /* Get channel counter, channel handle table and channel 0 instance */
661 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
663 filter0Instance
= DFSDM1_Filter0
;
667 filter0Instance
= DFSDM2_Filter0
;
669 /* Get channel number from channel instance */
670 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
673 tickstart
= HAL_GetTick();
675 /* Clear clock absence flag */
676 while((((filter0Instance
->FLTISR
& DFSDM_FLTISR_CKABF
) >> (DFSDM_FLTISR_CKABF_OFFSET
+ channel
)) & 1U) != 0U)
678 filter0Instance
->FLTICR
= (1U << (DFSDM_FLTICR_CLRCKABF_OFFSET
+ channel
));
680 /* Check the Timeout */
681 if((HAL_GetTick()-tickstart
) > DFSDM_CKAB_TIMEOUT
)
683 /* Set timeout status */
684 status
= HAL_TIMEOUT
;
689 /* Get channel number from channel instance */
690 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
693 tickstart
= HAL_GetTick();
695 /* Clear clock absence flag */
696 while((((DFSDM1_Filter0
->FLTISR
& DFSDM_FLTISR_CKABF
) >> (DFSDM_FLTISR_CKABF_OFFSET
+ channel
)) & 1U) != 0U)
698 DFSDM1_Filter0
->FLTICR
= (1U << (DFSDM_FLTICR_CLRCKABF_OFFSET
+ channel
));
700 /* Check the Timeout */
701 if((HAL_GetTick()-tickstart
) > DFSDM_CKAB_TIMEOUT
)
703 /* Set timeout status */
704 status
= HAL_TIMEOUT
;
708 #endif /* DFSDM2_Channel0 */
712 /* Start clock absence detection */
713 hdfsdm_channel
->Instance
->CHCFGR1
|= DFSDM_CHCFGR1_CKABEN
;
716 /* Return function status */
721 * @brief This function allows to poll for the clock absence detection.
722 * @param hdfsdm_channel : DFSDM channel handle.
723 * @param Timeout : Timeout value in milliseconds.
726 HAL_StatusTypeDef
HAL_DFSDM_ChannelPollForCkab(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
,
731 #if defined(DFSDM2_Channel0)
732 DFSDM_Filter_TypeDef
* filter0Instance
;
733 #endif /* defined(DFSDM2_Channel0) */
735 /* Check parameters */
736 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
738 /* Check DFSDM channel state */
739 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
741 /* Return error status */
746 #if defined(DFSDM2_Channel0)
748 /* Get channel counter, channel handle table and channel 0 instance */
749 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
751 filter0Instance
= DFSDM1_Filter0
;
755 filter0Instance
= DFSDM2_Filter0
;
758 /* Get channel number from channel instance */
759 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
762 tickstart
= HAL_GetTick();
764 /* Wait clock absence detection */
765 while((((filter0Instance
->FLTISR
& DFSDM_FLTISR_CKABF
) >> (DFSDM_FLTISR_CKABF_OFFSET
+ channel
)) & 1U) == 0U)
767 /* Check the Timeout */
768 if(Timeout
!= HAL_MAX_DELAY
)
770 if((Timeout
== 0U) || ((HAL_GetTick()-tickstart
) > Timeout
))
772 /* Return timeout status */
778 /* Clear clock absence detection flag */
779 filter0Instance
->FLTICR
= (1U << (DFSDM_FLTICR_CLRCKABF_OFFSET
+ channel
));
781 /* Get channel number from channel instance */
782 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
785 tickstart
= HAL_GetTick();
787 /* Wait clock absence detection */
788 while((((DFSDM1_Filter0
->FLTISR
& DFSDM_FLTISR_CKABF
) >> (DFSDM_FLTISR_CKABF_OFFSET
+ channel
)) & 1U) == 0U)
790 /* Check the Timeout */
791 if(Timeout
!= HAL_MAX_DELAY
)
793 if((Timeout
== 0U) || ((HAL_GetTick()-tickstart
) > Timeout
))
795 /* Return timeout status */
801 /* Clear clock absence detection flag */
802 DFSDM1_Filter0
->FLTICR
= (1U << (DFSDM_FLTICR_CLRCKABF_OFFSET
+ channel
));
803 #endif /* defined(DFSDM2_Channel0) */
804 /* Return function status */
810 * @brief This function allows to stop clock absence detection in polling mode.
811 * @param hdfsdm_channel : DFSDM channel handle.
814 HAL_StatusTypeDef
HAL_DFSDM_ChannelCkabStop(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
816 HAL_StatusTypeDef status
= HAL_OK
;
818 #if defined(DFSDM2_Channel0)
819 DFSDM_Filter_TypeDef
* filter0Instance
;
820 #endif /* defined(DFSDM2_Channel0) */
822 /* Check parameters */
823 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
825 /* Check DFSDM channel state */
826 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
828 /* Return error status */
833 #if defined(DFSDM2_Channel0)
835 /* Get channel counter, channel handle table and channel 0 instance */
836 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
838 filter0Instance
= DFSDM1_Filter0
;
842 filter0Instance
= DFSDM2_Filter0
;
845 /* Stop clock absence detection */
846 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CKABEN
);
848 /* Clear clock absence flag */
849 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
850 filter0Instance
->FLTICR
= (1U << (DFSDM_FLTICR_CLRCKABF_OFFSET
+ channel
));
853 /* Stop clock absence detection */
854 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CKABEN
);
856 /* Clear clock absence flag */
857 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
858 DFSDM1_Filter0
->FLTICR
= (1U << (DFSDM_FLTICR_CLRCKABF_OFFSET
+ channel
));
859 #endif /* DFSDM2_Channel0 */
861 /* Return function status */
866 * @brief This function allows to start clock absence detection in interrupt mode.
867 * @note Same mode has to be used for all channels.
868 * @note If clock is not available on this channel during 5 seconds,
869 * clock absence detection will not be activated and function
870 * will return HAL_TIMEOUT error.
871 * @param hdfsdm_channel : DFSDM channel handle.
874 HAL_StatusTypeDef
HAL_DFSDM_ChannelCkabStart_IT(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
876 HAL_StatusTypeDef status
= HAL_OK
;
879 #if defined(DFSDM2_Channel0)
880 DFSDM_Filter_TypeDef
* filter0Instance
;
881 #endif /* defined(DFSDM2_Channel0) */
883 /* Check parameters */
884 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
886 /* Check DFSDM channel state */
887 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
889 /* Return error status */
894 #if defined(DFSDM2_Channel0)
896 /* Get channel counter, channel handle table and channel 0 instance */
897 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
899 filter0Instance
= DFSDM1_Filter0
;
903 filter0Instance
= DFSDM2_Filter0
;
906 /* Get channel number from channel instance */
907 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
910 tickstart
= HAL_GetTick();
912 /* Clear clock absence flag */
913 while((((filter0Instance
->FLTISR
& DFSDM_FLTISR_CKABF
) >> (DFSDM_FLTISR_CKABF_OFFSET
+ channel
)) & 1U) != 0U)
915 filter0Instance
->FLTICR
= (1U << (DFSDM_FLTICR_CLRCKABF_OFFSET
+ channel
));
917 /* Check the Timeout */
918 if((HAL_GetTick()-tickstart
) > DFSDM_CKAB_TIMEOUT
)
920 /* Set timeout status */
921 status
= HAL_TIMEOUT
;
928 /* Activate clock absence detection interrupt */
929 filter0Instance
->FLTCR2
|= DFSDM_FLTCR2_CKABIE
;
931 /* Start clock absence detection */
932 hdfsdm_channel
->Instance
->CHCFGR1
|= DFSDM_CHCFGR1_CKABEN
;
935 /* Get channel number from channel instance */
936 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
939 tickstart
= HAL_GetTick();
941 /* Clear clock absence flag */
942 while((((DFSDM1_Filter0
->FLTISR
& DFSDM_FLTISR_CKABF
) >> (DFSDM_FLTISR_CKABF_OFFSET
+ channel
)) & 1U) != 0U)
944 DFSDM1_Filter0
->FLTICR
= (1U << (DFSDM_FLTICR_CLRCKABF_OFFSET
+ channel
));
946 /* Check the Timeout */
947 if((HAL_GetTick()-tickstart
) > DFSDM_CKAB_TIMEOUT
)
949 /* Set timeout status */
950 status
= HAL_TIMEOUT
;
957 /* Activate clock absence detection interrupt */
958 DFSDM1_Filter0
->FLTCR2
|= DFSDM_FLTCR2_CKABIE
;
960 /* Start clock absence detection */
961 hdfsdm_channel
->Instance
->CHCFGR1
|= DFSDM_CHCFGR1_CKABEN
;
964 #endif /* defined(DFSDM2_Channel0) */
966 /* Return function status */
971 * @brief Clock absence detection callback.
972 * @param hdfsdm_channel : DFSDM channel handle.
975 __weak
void HAL_DFSDM_ChannelCkabCallback(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
977 /* Prevent unused argument(s) compilation warning */
978 UNUSED(hdfsdm_channel
);
979 /* NOTE : This function should not be modified, when the callback is needed,
980 the HAL_DFSDM_ChannelCkabCallback could be implemented in the user file
985 * @brief This function allows to stop clock absence detection in interrupt mode.
986 * @note Interrupt will be disabled for all channels
987 * @param hdfsdm_channel : DFSDM channel handle.
990 HAL_StatusTypeDef
HAL_DFSDM_ChannelCkabStop_IT(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
992 HAL_StatusTypeDef status
= HAL_OK
;
994 #if defined(DFSDM2_Channel0)
995 DFSDM_Filter_TypeDef
* filter0Instance
;
996 #endif /* defined(DFSDM2_Channel0) */
998 /* Check parameters */
999 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1001 /* Check DFSDM channel state */
1002 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1004 /* Return error status */
1009 #if defined(DFSDM2_Channel0)
1011 /* Get channel counter, channel handle table and channel 0 instance */
1012 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
1014 filter0Instance
= DFSDM1_Filter0
;
1018 filter0Instance
= DFSDM2_Filter0
;
1021 /* Stop clock absence detection */
1022 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CKABEN
);
1024 /* Clear clock absence flag */
1025 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
1026 filter0Instance
->FLTICR
= (1U << (DFSDM_FLTICR_CLRCKABF_OFFSET
+ channel
));
1028 /* Disable clock absence detection interrupt */
1029 filter0Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_CKABIE
);
1032 /* Stop clock absence detection */
1033 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_CKABEN
);
1035 /* Clear clock absence flag */
1036 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
1037 DFSDM1_Filter0
->FLTICR
= (1U << (DFSDM_FLTICR_CLRCKABF_OFFSET
+ channel
));
1039 /* Disable clock absence detection interrupt */
1040 DFSDM1_Filter0
->FLTCR2
&= ~(DFSDM_FLTCR2_CKABIE
);
1041 #endif /* DFSDM2_Channel0 */
1044 /* Return function status */
1049 * @brief This function allows to start short circuit detection in polling mode.
1050 * @note Same mode has to be used for all channels
1051 * @param hdfsdm_channel : DFSDM channel handle.
1052 * @param Threshold : Short circuit detector threshold.
1053 * This parameter must be a number between Min_Data = 0 and Max_Data = 255.
1054 * @param BreakSignal : Break signals assigned to short circuit event.
1055 * This parameter can be a values combination of @ref DFSDM_BreakSignals.
1056 * @retval HAL status
1058 HAL_StatusTypeDef
HAL_DFSDM_ChannelScdStart(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
,
1060 uint32_t BreakSignal
)
1062 HAL_StatusTypeDef status
= HAL_OK
;
1064 /* Check parameters */
1065 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1066 assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold
));
1067 assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal
));
1069 /* Check DFSDM channel state */
1070 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1072 /* Return error status */
1077 /* Configure threshold and break signals */
1078 hdfsdm_channel
->Instance
->CHAWSCDR
&= ~(DFSDM_CHAWSCDR_BKSCD
| DFSDM_CHAWSCDR_SCDT
);
1079 hdfsdm_channel
->Instance
->CHAWSCDR
|= ((BreakSignal
<< DFSDM_CHAWSCDR_BKSCD_OFFSET
) | \
1082 /* Start short circuit detection */
1083 hdfsdm_channel
->Instance
->CHCFGR1
|= DFSDM_CHCFGR1_SCDEN
;
1085 /* Return function status */
1090 * @brief This function allows to poll for the short circuit detection.
1091 * @param hdfsdm_channel : DFSDM channel handle.
1092 * @param Timeout : Timeout value in milliseconds.
1093 * @retval HAL status
1095 HAL_StatusTypeDef
HAL_DFSDM_ChannelPollForScd(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
,
1100 #if defined(DFSDM2_Channel0)
1101 DFSDM_Filter_TypeDef
* filter0Instance
;
1102 #endif /* defined(DFSDM2_Channel0) */
1104 /* Check parameters */
1105 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1107 /* Check DFSDM channel state */
1108 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1110 /* Return error status */
1115 /* Get channel number from channel instance */
1116 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
1118 #if defined(DFSDM2_Channel0)
1119 /* Get channel counter, channel handle table and channel 0 instance */
1120 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
1122 filter0Instance
= DFSDM1_Filter0
;
1126 filter0Instance
= DFSDM2_Filter0
;
1130 tickstart
= HAL_GetTick();
1132 /* Wait short circuit detection */
1133 while(((filter0Instance
->FLTISR
& DFSDM_FLTISR_SCDF
) >> (DFSDM_FLTISR_SCDF_OFFSET
+ channel
)) == 0U)
1135 /* Check the Timeout */
1136 if(Timeout
!= HAL_MAX_DELAY
)
1138 if((Timeout
== 0U) || ((HAL_GetTick()-tickstart
) > Timeout
))
1140 /* Return timeout status */
1146 /* Clear short circuit detection flag */
1147 filter0Instance
->FLTICR
= (1U << (DFSDM_FLTICR_CLRSCDF_OFFSET
+ channel
));
1151 tickstart
= HAL_GetTick();
1153 /* Wait short circuit detection */
1154 while(((DFSDM1_Filter0
->FLTISR
& DFSDM_FLTISR_SCDF
) >> (DFSDM_FLTISR_SCDF_OFFSET
+ channel
)) == 0U)
1156 /* Check the Timeout */
1157 if(Timeout
!= HAL_MAX_DELAY
)
1159 if((Timeout
== 0U) || ((HAL_GetTick()-tickstart
) > Timeout
))
1161 /* Return timeout status */
1167 /* Clear short circuit detection flag */
1168 DFSDM1_Filter0
->FLTICR
= (1U << (DFSDM_FLTICR_CLRSCDF_OFFSET
+ channel
));
1169 #endif /* DFSDM2_Channel0 */
1171 /* Return function status */
1177 * @brief This function allows to stop short circuit detection in polling mode.
1178 * @param hdfsdm_channel : DFSDM channel handle.
1179 * @retval HAL status
1181 HAL_StatusTypeDef
HAL_DFSDM_ChannelScdStop(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
1183 HAL_StatusTypeDef status
= HAL_OK
;
1185 #if defined(DFSDM2_Channel0)
1186 DFSDM_Filter_TypeDef
* filter0Instance
;
1187 #endif /* defined(DFSDM2_Channel0) */
1189 /* Check parameters */
1190 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1192 /* Check DFSDM channel state */
1193 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1195 /* Return error status */
1200 /* Stop short circuit detection */
1201 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_SCDEN
);
1203 /* Clear short circuit detection flag */
1204 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
1206 #if defined(DFSDM2_Channel0)
1207 /* Get channel counter, channel handle table and channel 0 instance */
1208 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
1210 filter0Instance
= DFSDM1_Filter0
;
1214 filter0Instance
= DFSDM2_Filter0
;
1217 filter0Instance
->FLTICR
= (1U << (DFSDM_FLTICR_CLRSCDF_OFFSET
+ channel
));
1219 DFSDM1_Filter0
->FLTICR
= (1U << (DFSDM_FLTICR_CLRSCDF_OFFSET
+ channel
));
1220 #endif /* DFSDM2_Channel0*/
1222 /* Return function status */
1227 * @brief This function allows to start short circuit detection in interrupt mode.
1228 * @note Same mode has to be used for all channels
1229 * @param hdfsdm_channel : DFSDM channel handle.
1230 * @param Threshold : Short circuit detector threshold.
1231 * This parameter must be a number between Min_Data = 0 and Max_Data = 255.
1232 * @param BreakSignal : Break signals assigned to short circuit event.
1233 * This parameter can be a values combination of @ref DFSDM_BreakSignals.
1234 * @retval HAL status
1236 HAL_StatusTypeDef
HAL_DFSDM_ChannelScdStart_IT(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
,
1238 uint32_t BreakSignal
)
1240 HAL_StatusTypeDef status
= HAL_OK
;
1241 #if defined(DFSDM2_Channel0)
1242 DFSDM_Filter_TypeDef
* filter0Instance
;
1243 #endif /* defined(DFSDM2_Channel0) */
1245 /* Check parameters */
1246 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1247 assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold
));
1248 assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal
));
1250 /* Check DFSDM channel state */
1251 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1253 /* Return error status */
1258 #if defined(DFSDM2_Channel0)
1259 /* Get channel counter, channel handle table and channel 0 instance */
1260 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
1262 filter0Instance
= DFSDM1_Filter0
;
1266 filter0Instance
= DFSDM2_Filter0
;
1268 /* Activate short circuit detection interrupt */
1269 filter0Instance
->FLTCR2
|= DFSDM_FLTCR2_SCDIE
;
1271 /* Activate short circuit detection interrupt */
1272 DFSDM1_Filter0
->FLTCR2
|= DFSDM_FLTCR2_SCDIE
;
1273 #endif /* DFSDM2_Channel0 */
1275 /* Configure threshold and break signals */
1276 hdfsdm_channel
->Instance
->CHAWSCDR
&= ~(DFSDM_CHAWSCDR_BKSCD
| DFSDM_CHAWSCDR_SCDT
);
1277 hdfsdm_channel
->Instance
->CHAWSCDR
|= ((BreakSignal
<< DFSDM_CHAWSCDR_BKSCD_OFFSET
) | \
1280 /* Start short circuit detection */
1281 hdfsdm_channel
->Instance
->CHCFGR1
|= DFSDM_CHCFGR1_SCDEN
;
1283 /* Return function status */
1288 * @brief Short circuit detection callback.
1289 * @param hdfsdm_channel : DFSDM channel handle.
1292 __weak
void HAL_DFSDM_ChannelScdCallback(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
1294 /* Prevent unused argument(s) compilation warning */
1295 UNUSED(hdfsdm_channel
);
1296 /* NOTE : This function should not be modified, when the callback is needed,
1297 the HAL_DFSDM_ChannelScdCallback could be implemented in the user file
1302 * @brief This function allows to stop short circuit detection in interrupt mode.
1303 * @note Interrupt will be disabled for all channels
1304 * @param hdfsdm_channel : DFSDM channel handle.
1305 * @retval HAL status
1307 HAL_StatusTypeDef
HAL_DFSDM_ChannelScdStop_IT(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
1309 HAL_StatusTypeDef status
= HAL_OK
;
1311 #if defined(DFSDM2_Channel0)
1312 DFSDM_Filter_TypeDef
* filter0Instance
;
1313 #endif /* defined(DFSDM2_Channel0) */
1315 /* Check parameters */
1316 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1318 /* Check DFSDM channel state */
1319 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1321 /* Return error status */
1326 /* Stop short circuit detection */
1327 hdfsdm_channel
->Instance
->CHCFGR1
&= ~(DFSDM_CHCFGR1_SCDEN
);
1329 /* Clear short circuit detection flag */
1330 channel
= DFSDM_GetChannelFromInstance(hdfsdm_channel
->Instance
);
1331 #if defined(DFSDM2_Channel0)
1332 /* Get channel counter, channel handle table and channel 0 instance */
1333 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel
->Instance
))
1335 filter0Instance
= DFSDM1_Filter0
;
1339 filter0Instance
= DFSDM2_Filter0
;
1342 filter0Instance
->FLTICR
= (1U << (DFSDM_FLTICR_CLRSCDF_OFFSET
+ channel
));
1344 /* Disable short circuit detection interrupt */
1345 filter0Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_SCDIE
);
1347 DFSDM1_Filter0
->FLTICR
= (1U << (DFSDM_FLTICR_CLRSCDF_OFFSET
+ channel
));
1349 /* Disable short circuit detection interrupt */
1350 DFSDM1_Filter0
->FLTCR2
&= ~(DFSDM_FLTCR2_SCDIE
);
1351 #endif /* DFSDM2_Channel0 */
1353 /* Return function status */
1358 * @brief This function allows to get channel analog watchdog value.
1359 * @param hdfsdm_channel : DFSDM channel handle.
1360 * @retval Channel analog watchdog value.
1362 int16_t HAL_DFSDM_ChannelGetAwdValue(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
1364 return (int16_t) hdfsdm_channel
->Instance
->CHWDATAR
;
1368 * @brief This function allows to modify channel offset value.
1369 * @param hdfsdm_channel : DFSDM channel handle.
1370 * @param Offset : DFSDM channel offset.
1371 * This parameter must be a number between Min_Data = -8388608 and Max_Data = 8388607.
1372 * @retval HAL status.
1374 HAL_StatusTypeDef
HAL_DFSDM_ChannelModifyOffset(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
,
1377 HAL_StatusTypeDef status
= HAL_OK
;
1379 /* Check parameters */
1380 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel
->Instance
));
1381 assert_param(IS_DFSDM_CHANNEL_OFFSET(Offset
));
1383 /* Check DFSDM channel state */
1384 if(hdfsdm_channel
->State
!= HAL_DFSDM_CHANNEL_STATE_READY
)
1386 /* Return error status */
1391 /* Modify channel offset */
1392 hdfsdm_channel
->Instance
->CHCFGR2
&= ~(DFSDM_CHCFGR2_OFFSET
);
1393 hdfsdm_channel
->Instance
->CHCFGR2
|= ((uint32_t) Offset
<< DFSDM_CHCFGR2_OFFSET_OFFSET
);
1395 /* Return function status */
1403 /** @defgroup DFSDM_Exported_Functions_Group3_Channel Channel state function
1404 * @brief Channel state function
1407 ==============================================================================
1408 ##### Channel state function #####
1409 ==============================================================================
1410 [..] This section provides function allowing to:
1411 (+) Get channel handle state.
1417 * @brief This function allows to get the current DFSDM channel handle state.
1418 * @param hdfsdm_channel : DFSDM channel handle.
1419 * @retval DFSDM channel state.
1421 HAL_DFSDM_Channel_StateTypeDef
HAL_DFSDM_ChannelGetState(DFSDM_Channel_HandleTypeDef
*hdfsdm_channel
)
1423 /* Return DFSDM channel handle state */
1424 return hdfsdm_channel
->State
;
1431 /** @defgroup DFSDM_Exported_Functions_Group1_Filter Filter initialization and de-initialization functions
1432 * @brief Filter initialization and de-initialization functions
1435 ==============================================================================
1436 ##### Filter initialization and de-initialization functions #####
1437 ==============================================================================
1438 [..] This section provides functions allowing to:
1439 (+) Initialize the DFSDM filter.
1440 (+) De-initialize the DFSDM filter.
1446 * @brief Initialize the DFSDM filter according to the specified parameters
1447 * in the DFSDM_FilterInitTypeDef structure and initialize the associated handle.
1448 * @param hdfsdm_filter : DFSDM filter handle.
1449 * @retval HAL status.
1451 HAL_StatusTypeDef
HAL_DFSDM_FilterInit(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
1453 /* Check DFSDM Channel handle */
1454 if(hdfsdm_filter
== NULL
)
1459 /* Check parameters */
1460 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1461 assert_param(IS_DFSDM_FILTER_REG_TRIGGER(hdfsdm_filter
->Init
.RegularParam
.Trigger
));
1462 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter
->Init
.RegularParam
.FastMode
));
1463 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter
->Init
.RegularParam
.DmaMode
));
1464 assert_param(IS_DFSDM_FILTER_INJ_TRIGGER(hdfsdm_filter
->Init
.InjectedParam
.Trigger
));
1465 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter
->Init
.InjectedParam
.ScanMode
));
1466 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter
->Init
.InjectedParam
.DmaMode
));
1467 assert_param(IS_DFSDM_FILTER_SINC_ORDER(hdfsdm_filter
->Init
.FilterParam
.SincOrder
));
1468 assert_param(IS_DFSDM_FILTER_OVS_RATIO(hdfsdm_filter
->Init
.FilterParam
.Oversampling
));
1469 assert_param(IS_DFSDM_FILTER_INTEGRATOR_OVS_RATIO(hdfsdm_filter
->Init
.FilterParam
.IntOversampling
));
1471 /* Check parameters compatibility */
1472 if((hdfsdm_filter
->Instance
== DFSDM1_Filter0
) &&
1473 ((hdfsdm_filter
->Init
.RegularParam
.Trigger
== DFSDM_FILTER_SYNC_TRIGGER
) ||
1474 (hdfsdm_filter
->Init
.InjectedParam
.Trigger
== DFSDM_FILTER_SYNC_TRIGGER
)))
1478 #if defined (DFSDM2_Channel0)
1479 if((hdfsdm_filter
->Instance
== DFSDM2_Filter0
) &&
1480 ((hdfsdm_filter
->Init
.RegularParam
.Trigger
== DFSDM_FILTER_SYNC_TRIGGER
) ||
1481 (hdfsdm_filter
->Init
.InjectedParam
.Trigger
== DFSDM_FILTER_SYNC_TRIGGER
)))
1485 #endif /* DFSDM2_Channel0 */
1487 /* Initialize DFSDM filter variables with default values */
1488 hdfsdm_filter
->RegularContMode
= DFSDM_CONTINUOUS_CONV_OFF
;
1489 hdfsdm_filter
->InjectedChannelsNbr
= 1U;
1490 hdfsdm_filter
->InjConvRemaining
= 1U;
1491 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_NONE
;
1493 /* Call MSP init function */
1494 HAL_DFSDM_FilterMspInit(hdfsdm_filter
);
1496 /* Set regular parameters */
1497 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_RSYNC
);
1498 if(hdfsdm_filter
->Init
.RegularParam
.FastMode
== ENABLE
)
1500 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_FAST
;
1504 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_FAST
);
1507 if(hdfsdm_filter
->Init
.RegularParam
.DmaMode
== ENABLE
)
1509 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_RDMAEN
;
1513 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_RDMAEN
);
1516 /* Set injected parameters */
1517 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_JSYNC
| DFSDM_FLTCR1_JEXTEN
| DFSDM_FLTCR1_JEXTSEL
);
1518 if(hdfsdm_filter
->Init
.InjectedParam
.Trigger
== DFSDM_FILTER_EXT_TRIGGER
)
1520 assert_param(IS_DFSDM_FILTER_EXT_TRIG(hdfsdm_filter
->Init
.InjectedParam
.ExtTrigger
));
1521 assert_param(IS_DFSDM_FILTER_EXT_TRIG_EDGE(hdfsdm_filter
->Init
.InjectedParam
.ExtTriggerEdge
));
1522 hdfsdm_filter
->Instance
->FLTCR1
|= (hdfsdm_filter
->Init
.InjectedParam
.ExtTrigger
);
1525 if(hdfsdm_filter
->Init
.InjectedParam
.ScanMode
== ENABLE
)
1527 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_JSCAN
;
1531 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_JSCAN
);
1534 if(hdfsdm_filter
->Init
.InjectedParam
.DmaMode
== ENABLE
)
1536 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_JDMAEN
;
1540 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_JDMAEN
);
1543 /* Set filter parameters */
1544 hdfsdm_filter
->Instance
->FLTFCR
&= ~(DFSDM_FLTFCR_FORD
| DFSDM_FLTFCR_FOSR
| DFSDM_FLTFCR_IOSR
);
1545 hdfsdm_filter
->Instance
->FLTFCR
|= (hdfsdm_filter
->Init
.FilterParam
.SincOrder
|
1546 ((hdfsdm_filter
->Init
.FilterParam
.Oversampling
- 1U) << DFSDM_FLTFCR_FOSR_OFFSET
) |
1547 (hdfsdm_filter
->Init
.FilterParam
.IntOversampling
- 1U));
1549 /* Store regular and injected triggers and injected scan mode*/
1550 hdfsdm_filter
->RegularTrigger
= hdfsdm_filter
->Init
.RegularParam
.Trigger
;
1551 hdfsdm_filter
->InjectedTrigger
= hdfsdm_filter
->Init
.InjectedParam
.Trigger
;
1552 hdfsdm_filter
->ExtTriggerEdge
= hdfsdm_filter
->Init
.InjectedParam
.ExtTriggerEdge
;
1553 hdfsdm_filter
->InjectedScanMode
= hdfsdm_filter
->Init
.InjectedParam
.ScanMode
;
1555 /* Enable DFSDM filter */
1556 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_DFEN
;
1558 /* Set DFSDM filter to ready state */
1559 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_READY
;
1565 * @brief De-initializes the DFSDM filter.
1566 * @param hdfsdm_filter : DFSDM filter handle.
1567 * @retval HAL status.
1569 HAL_StatusTypeDef
HAL_DFSDM_FilterDeInit(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
1571 /* Check DFSDM filter handle */
1572 if(hdfsdm_filter
== NULL
)
1577 /* Check parameters */
1578 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1580 /* Disable the DFSDM filter */
1581 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_DFEN
);
1583 /* Call MSP deinit function */
1584 HAL_DFSDM_FilterMspDeInit(hdfsdm_filter
);
1586 /* Set DFSDM filter in reset state */
1587 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_RESET
;
1593 * @brief Initializes the DFSDM filter MSP.
1594 * @param hdfsdm_filter : DFSDM filter handle.
1597 __weak
void HAL_DFSDM_FilterMspInit(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
1599 /* Prevent unused argument(s) compilation warning */
1600 UNUSED(hdfsdm_filter
);
1601 /* NOTE : This function should not be modified, when the function is needed,
1602 the HAL_DFSDM_FilterMspInit could be implemented in the user file.
1607 * @brief De-initializes the DFSDM filter MSP.
1608 * @param hdfsdm_filter : DFSDM filter handle.
1611 __weak
void HAL_DFSDM_FilterMspDeInit(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
1613 /* Prevent unused argument(s) compilation warning */
1614 UNUSED(hdfsdm_filter
);
1615 /* NOTE : This function should not be modified, when the function is needed,
1616 the HAL_DFSDM_FilterMspDeInit could be implemented in the user file.
1624 /** @defgroup DFSDM_Exported_Functions_Group2_Filter Filter control functions
1625 * @brief Filter control functions
1628 ==============================================================================
1629 ##### Filter control functions #####
1630 ==============================================================================
1631 [..] This section provides functions allowing to:
1632 (+) Select channel and enable/disable continuous mode for regular conversion.
1633 (+) Select channels for injected conversion.
1639 * @brief This function allows to select channel and to enable/disable
1640 * continuous mode for regular conversion.
1641 * @param hdfsdm_filter : DFSDM filter handle.
1642 * @param Channel : Channel for regular conversion.
1643 * This parameter can be a value of @ref DFSDM_Channel_Selection.
1644 * @param ContinuousMode : Enable/disable continuous mode for regular conversion.
1645 * This parameter can be a value of @ref DFSDM_ContinuousMode.
1646 * @retval HAL status
1648 HAL_StatusTypeDef
HAL_DFSDM_FilterConfigRegChannel(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
1650 uint32_t ContinuousMode
)
1652 HAL_StatusTypeDef status
= HAL_OK
;
1654 /* Check parameters */
1655 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1656 assert_param(IS_DFSDM_REGULAR_CHANNEL(Channel
));
1657 assert_param(IS_DFSDM_CONTINUOUS_MODE(ContinuousMode
));
1659 /* Check DFSDM filter state */
1660 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_RESET
) &&
1661 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_ERROR
))
1663 /* Configure channel and continuous mode for regular conversion */
1664 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_RCH
| DFSDM_FLTCR1_RCONT
);
1665 if(ContinuousMode
== DFSDM_CONTINUOUS_CONV_ON
)
1667 hdfsdm_filter
->Instance
->FLTCR1
|= (uint32_t) (((Channel
& DFSDM_MSB_MASK
) << DFSDM_FLTCR1_MSB_RCH_OFFSET
) |
1668 DFSDM_FLTCR1_RCONT
);
1672 hdfsdm_filter
->Instance
->FLTCR1
|= (uint32_t) ((Channel
& DFSDM_MSB_MASK
) << DFSDM_FLTCR1_MSB_RCH_OFFSET
);
1674 /* Store continuous mode information */
1675 hdfsdm_filter
->RegularContMode
= ContinuousMode
;
1682 /* Return function status */
1687 * @brief This function allows to select channels for injected conversion.
1688 * @param hdfsdm_filter : DFSDM filter handle.
1689 * @param Channel : Channels for injected conversion.
1690 * This parameter can be a values combination of @ref DFSDM_Channel_Selection.
1691 * @retval HAL status
1693 HAL_StatusTypeDef
HAL_DFSDM_FilterConfigInjChannel(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
1696 HAL_StatusTypeDef status
= HAL_OK
;
1698 /* Check parameters */
1699 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1700 assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel
));
1702 /* Check DFSDM filter state */
1703 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_RESET
) &&
1704 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_ERROR
))
1706 /* Configure channel for injected conversion */
1707 hdfsdm_filter
->Instance
->FLTJCHGR
= (uint32_t) (Channel
& DFSDM_LSB_MASK
);
1708 /* Store number of injected channels */
1709 hdfsdm_filter
->InjectedChannelsNbr
= DFSDM_GetInjChannelsNbr(Channel
);
1710 /* Update number of injected channels remaining */
1711 hdfsdm_filter
->InjConvRemaining
= (hdfsdm_filter
->InjectedScanMode
== ENABLE
) ? \
1712 hdfsdm_filter
->InjectedChannelsNbr
: 1U;
1718 /* Return function status */
1726 /** @defgroup DFSDM_Exported_Functions_Group3_Filter Filter operation functions
1727 * @brief Filter operation functions
1730 ==============================================================================
1731 ##### Filter operation functions #####
1732 ==============================================================================
1733 [..] This section provides functions allowing to:
1734 (+) Start conversion of regular/injected channel.
1735 (+) Poll for the end of regular/injected conversion.
1736 (+) Stop conversion of regular/injected channel.
1737 (+) Start conversion of regular/injected channel and enable interrupt.
1738 (+) Call the callback functions at the end of regular/injected conversions.
1739 (+) Stop conversion of regular/injected channel and disable interrupt.
1740 (+) Start conversion of regular/injected channel and enable DMA transfer.
1741 (+) Stop conversion of regular/injected channel and disable DMA transfer.
1742 (+) Start analog watchdog and enable interrupt.
1743 (+) Call the callback function when analog watchdog occurs.
1744 (+) Stop analog watchdog and disable interrupt.
1745 (+) Start extreme detector.
1746 (+) Stop extreme detector.
1747 (+) Get result of regular channel conversion.
1748 (+) Get result of injected channel conversion.
1749 (+) Get extreme detector maximum and minimum values.
1750 (+) Get conversion time.
1751 (+) Handle DFSDM interrupt request.
1757 * @brief This function allows to start regular conversion in polling mode.
1758 * @note This function should be called only when DFSDM filter instance is
1759 * in idle state or if injected conversion is ongoing.
1760 * @param hdfsdm_filter : DFSDM filter handle.
1761 * @retval HAL status
1763 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularStart(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
1765 HAL_StatusTypeDef status
= HAL_OK
;
1767 /* Check parameters */
1768 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1770 /* Check DFSDM filter state */
1771 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
1772 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
))
1774 /* Start regular conversion */
1775 DFSDM_RegConvStart(hdfsdm_filter
);
1781 /* Return function status */
1786 * @brief This function allows to poll for the end of regular conversion.
1787 * @note This function should be called only if regular conversion is ongoing.
1788 * @param hdfsdm_filter : DFSDM filter handle.
1789 * @param Timeout : Timeout value in milliseconds.
1790 * @retval HAL status
1792 HAL_StatusTypeDef
HAL_DFSDM_FilterPollForRegConversion(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
1797 /* Check parameters */
1798 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1800 /* Check DFSDM filter state */
1801 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG
) && \
1802 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
1804 /* Return error status */
1810 tickstart
= HAL_GetTick();
1812 /* Wait end of regular conversion */
1813 while((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_REOCF
) != DFSDM_FLTISR_REOCF
)
1815 /* Check the Timeout */
1816 if(Timeout
!= HAL_MAX_DELAY
)
1818 if((Timeout
== 0U) || ((HAL_GetTick()-tickstart
) > Timeout
))
1820 /* Return timeout status */
1825 /* Check if overrun occurs */
1826 if((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_ROVRF
) == DFSDM_FLTISR_ROVRF
)
1828 /* Update error code and call error callback */
1829 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_REGULAR_OVERRUN
;
1830 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter
);
1832 /* Clear regular overrun flag */
1833 hdfsdm_filter
->Instance
->FLTICR
= DFSDM_FLTICR_CLRROVRF
;
1835 /* Update DFSDM filter state only if not continuous conversion and SW trigger */
1836 if((hdfsdm_filter
->RegularContMode
== DFSDM_CONTINUOUS_CONV_OFF
) && \
1837 (hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
))
1839 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
) ? \
1840 HAL_DFSDM_FILTER_STATE_READY
: HAL_DFSDM_FILTER_STATE_INJ
;
1842 /* Return function status */
1848 * @brief This function allows to stop regular conversion in polling mode.
1849 * @note This function should be called only if regular conversion is ongoing.
1850 * @param hdfsdm_filter : DFSDM filter handle.
1851 * @retval HAL status
1853 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularStop(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
1855 HAL_StatusTypeDef status
= HAL_OK
;
1857 /* Check parameters */
1858 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1860 /* Check DFSDM filter state */
1861 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG
) && \
1862 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
1864 /* Return error status */
1869 /* Stop regular conversion */
1870 DFSDM_RegConvStop(hdfsdm_filter
);
1872 /* Return function status */
1877 * @brief This function allows to start regular conversion in interrupt mode.
1878 * @note This function should be called only when DFSDM filter instance is
1879 * in idle state or if injected conversion is ongoing.
1880 * @param hdfsdm_filter : DFSDM filter handle.
1881 * @retval HAL status
1883 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularStart_IT(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
1885 HAL_StatusTypeDef status
= HAL_OK
;
1887 /* Check parameters */
1888 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1890 /* Check DFSDM filter state */
1891 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
1892 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
))
1894 /* Enable interrupts for regular conversions */
1895 hdfsdm_filter
->Instance
->FLTCR2
|= (DFSDM_FLTCR2_REOCIE
| DFSDM_FLTCR2_ROVRIE
);
1897 /* Start regular conversion */
1898 DFSDM_RegConvStart(hdfsdm_filter
);
1904 /* Return function status */
1909 * @brief This function allows to stop regular conversion in interrupt mode.
1910 * @note This function should be called only if regular conversion is ongoing.
1911 * @param hdfsdm_filter : DFSDM filter handle.
1912 * @retval HAL status
1914 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularStop_IT(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
1916 HAL_StatusTypeDef status
= HAL_OK
;
1918 /* Check parameters */
1919 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1921 /* Check DFSDM filter state */
1922 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG
) && \
1923 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
1925 /* Return error status */
1930 /* Disable interrupts for regular conversions */
1931 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_REOCIE
| DFSDM_FLTCR2_ROVRIE
);
1933 /* Stop regular conversion */
1934 DFSDM_RegConvStop(hdfsdm_filter
);
1936 /* Return function status */
1941 * @brief This function allows to start regular conversion in DMA mode.
1942 * @note This function should be called only when DFSDM filter instance is
1943 * in idle state or if injected conversion is ongoing.
1944 * Please note that data on buffer will contain signed regular conversion
1945 * value on 24 most significant bits and corresponding channel on 3 least
1947 * @param hdfsdm_filter : DFSDM filter handle.
1948 * @param pData : The destination buffer address.
1949 * @param Length : The length of data to be transferred from DFSDM filter to memory.
1950 * @retval HAL status
1952 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularStart_DMA(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
1956 HAL_StatusTypeDef status
= HAL_OK
;
1958 /* Check parameters */
1959 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
1961 /* Check destination address and length */
1962 if((pData
== NULL
) || (Length
== 0U))
1966 /* Check that DMA is enabled for regular conversion */
1967 else if((hdfsdm_filter
->Instance
->FLTCR1
& DFSDM_FLTCR1_RDMAEN
) != DFSDM_FLTCR1_RDMAEN
)
1971 /* Check parameters compatibility */
1972 else if((hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
1973 (hdfsdm_filter
->RegularContMode
== DFSDM_CONTINUOUS_CONV_OFF
) && \
1974 (hdfsdm_filter
->hdmaReg
->Init
.Mode
== DMA_NORMAL
) && \
1979 else if((hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
1980 (hdfsdm_filter
->RegularContMode
== DFSDM_CONTINUOUS_CONV_OFF
) && \
1981 (hdfsdm_filter
->hdmaReg
->Init
.Mode
== DMA_CIRCULAR
))
1985 /* Check DFSDM filter state */
1986 else if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
1987 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
))
1989 /* Set callbacks on DMA handler */
1990 hdfsdm_filter
->hdmaReg
->XferCpltCallback
= DFSDM_DMARegularConvCplt
;
1991 hdfsdm_filter
->hdmaReg
->XferErrorCallback
= DFSDM_DMAError
;
1992 hdfsdm_filter
->hdmaReg
->XferHalfCpltCallback
= (hdfsdm_filter
->hdmaReg
->Init
.Mode
== DMA_CIRCULAR
) ?\
1993 DFSDM_DMARegularHalfConvCplt
: NULL
;
1995 /* Start DMA in interrupt mode */
1996 if(HAL_DMA_Start_IT(hdfsdm_filter
->hdmaReg
, (uint32_t)&hdfsdm_filter
->Instance
->FLTRDATAR
, \
1997 (uint32_t) pData
, Length
) != HAL_OK
)
1999 /* Set DFSDM filter in error state */
2000 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_ERROR
;
2005 /* Start regular conversion */
2006 DFSDM_RegConvStart(hdfsdm_filter
);
2013 /* Return function status */
2018 * @brief This function allows to start regular conversion in DMA mode and to get
2019 * only the 16 most significant bits of conversion.
2020 * @note This function should be called only when DFSDM filter instance is
2021 * in idle state or if injected conversion is ongoing.
2022 * Please note that data on buffer will contain signed 16 most significant
2023 * bits of regular conversion.
2024 * @param hdfsdm_filter : DFSDM filter handle.
2025 * @param pData : The destination buffer address.
2026 * @param Length : The length of data to be transferred from DFSDM filter to memory.
2027 * @retval HAL status
2029 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularMsbStart_DMA(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2033 HAL_StatusTypeDef status
= HAL_OK
;
2035 /* Check parameters */
2036 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2038 /* Check destination address and length */
2039 if((pData
== NULL
) || (Length
== 0U))
2043 /* Check that DMA is enabled for regular conversion */
2044 else if((hdfsdm_filter
->Instance
->FLTCR1
& DFSDM_FLTCR1_RDMAEN
) != DFSDM_FLTCR1_RDMAEN
)
2048 /* Check parameters compatibility */
2049 else if((hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2050 (hdfsdm_filter
->RegularContMode
== DFSDM_CONTINUOUS_CONV_OFF
) && \
2051 (hdfsdm_filter
->hdmaReg
->Init
.Mode
== DMA_NORMAL
) && \
2056 else if((hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2057 (hdfsdm_filter
->RegularContMode
== DFSDM_CONTINUOUS_CONV_OFF
) && \
2058 (hdfsdm_filter
->hdmaReg
->Init
.Mode
== DMA_CIRCULAR
))
2062 /* Check DFSDM filter state */
2063 else if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
2064 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
))
2066 /* Set callbacks on DMA handler */
2067 hdfsdm_filter
->hdmaReg
->XferCpltCallback
= DFSDM_DMARegularConvCplt
;
2068 hdfsdm_filter
->hdmaReg
->XferErrorCallback
= DFSDM_DMAError
;
2069 hdfsdm_filter
->hdmaReg
->XferHalfCpltCallback
= (hdfsdm_filter
->hdmaReg
->Init
.Mode
== DMA_CIRCULAR
) ?\
2070 DFSDM_DMARegularHalfConvCplt
: NULL
;
2072 /* Start DMA in interrupt mode */
2073 if(HAL_DMA_Start_IT(hdfsdm_filter
->hdmaReg
, (uint32_t)(&hdfsdm_filter
->Instance
->FLTRDATAR
) + 2U, \
2074 (uint32_t) pData
, Length
) != HAL_OK
)
2076 /* Set DFSDM filter in error state */
2077 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_ERROR
;
2082 /* Start regular conversion */
2083 DFSDM_RegConvStart(hdfsdm_filter
);
2090 /* Return function status */
2095 * @brief This function allows to stop regular conversion in DMA mode.
2096 * @note This function should be called only if regular conversion is ongoing.
2097 * @param hdfsdm_filter : DFSDM filter handle.
2098 * @retval HAL status
2100 HAL_StatusTypeDef
HAL_DFSDM_FilterRegularStop_DMA(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2102 HAL_StatusTypeDef status
= HAL_OK
;
2104 /* Check parameters */
2105 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2107 /* Check DFSDM filter state */
2108 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG
) && \
2109 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
2111 /* Return error status */
2116 /* Stop current DMA transfer */
2117 if(HAL_DMA_Abort(hdfsdm_filter
->hdmaReg
) != HAL_OK
)
2119 /* Set DFSDM filter in error state */
2120 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_ERROR
;
2125 /* Stop regular conversion */
2126 DFSDM_RegConvStop(hdfsdm_filter
);
2129 /* Return function status */
2134 * @brief This function allows to get regular conversion value.
2135 * @param hdfsdm_filter : DFSDM filter handle.
2136 * @param Channel : Corresponding channel of regular conversion.
2137 * @retval Regular conversion value
2139 int32_t HAL_DFSDM_FilterGetRegularValue(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2145 /* Check parameters */
2146 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2147 assert_param(Channel
!= NULL
);
2149 /* Get value of data register for regular channel */
2150 reg
= hdfsdm_filter
->Instance
->FLTRDATAR
;
2152 /* Extract channel and regular conversion value */
2153 *Channel
= (reg
& DFSDM_FLTRDATAR_RDATACH
);
2154 value
= ((int32_t)(reg
& DFSDM_FLTRDATAR_RDATA
) >> DFSDM_FLTRDATAR_DATA_OFFSET
);
2156 /* return regular conversion value */
2161 * @brief This function allows to start injected conversion in polling mode.
2162 * @note This function should be called only when DFSDM filter instance is
2163 * in idle state or if regular conversion is ongoing.
2164 * @param hdfsdm_filter : DFSDM filter handle.
2165 * @retval HAL status
2167 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedStart(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2169 HAL_StatusTypeDef status
= HAL_OK
;
2171 /* Check parameters */
2172 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2174 /* Check DFSDM filter state */
2175 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
2176 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
))
2178 /* Start injected conversion */
2179 DFSDM_InjConvStart(hdfsdm_filter
);
2185 /* Return function status */
2190 * @brief This function allows to poll for the end of injected conversion.
2191 * @note This function should be called only if injected conversion is ongoing.
2192 * @param hdfsdm_filter : DFSDM filter handle.
2193 * @param Timeout : Timeout value in milliseconds.
2194 * @retval HAL status
2196 HAL_StatusTypeDef
HAL_DFSDM_FilterPollForInjConversion(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2201 /* Check parameters */
2202 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2204 /* Check DFSDM filter state */
2205 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_INJ
) && \
2206 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
2208 /* Return error status */
2214 tickstart
= HAL_GetTick();
2216 /* Wait end of injected conversions */
2217 while((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_JEOCF
) != DFSDM_FLTISR_JEOCF
)
2219 /* Check the Timeout */
2220 if(Timeout
!= HAL_MAX_DELAY
)
2222 if((Timeout
== 0U) || ((HAL_GetTick()-tickstart
) > Timeout
))
2224 /* Return timeout status */
2229 /* Check if overrun occurs */
2230 if((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_JOVRF
) == DFSDM_FLTISR_JOVRF
)
2232 /* Update error code and call error callback */
2233 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INJECTED_OVERRUN
;
2234 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter
);
2236 /* Clear injected overrun flag */
2237 hdfsdm_filter
->Instance
->FLTICR
= DFSDM_FLTICR_CLRJOVRF
;
2240 /* Update remaining injected conversions */
2241 hdfsdm_filter
->InjConvRemaining
--;
2242 if(hdfsdm_filter
->InjConvRemaining
== 0U)
2244 /* Update DFSDM filter state only if trigger is software */
2245 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
)
2247 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
) ? \
2248 HAL_DFSDM_FILTER_STATE_READY
: HAL_DFSDM_FILTER_STATE_REG
;
2251 /* end of injected sequence, reset the value */
2252 hdfsdm_filter
->InjConvRemaining
= (hdfsdm_filter
->InjectedScanMode
== ENABLE
) ? \
2253 hdfsdm_filter
->InjectedChannelsNbr
: 1U;
2256 /* Return function status */
2262 * @brief This function allows to stop injected conversion in polling mode.
2263 * @note This function should be called only if injected conversion is ongoing.
2264 * @param hdfsdm_filter : DFSDM filter handle.
2265 * @retval HAL status
2267 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedStop(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2269 HAL_StatusTypeDef status
= HAL_OK
;
2271 /* Check parameters */
2272 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2274 /* Check DFSDM filter state */
2275 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_INJ
) && \
2276 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
2278 /* Return error status */
2283 /* Stop injected conversion */
2284 DFSDM_InjConvStop(hdfsdm_filter
);
2286 /* Return function status */
2291 * @brief This function allows to start injected conversion in interrupt mode.
2292 * @note This function should be called only when DFSDM filter instance is
2293 * in idle state or if regular conversion is ongoing.
2294 * @param hdfsdm_filter : DFSDM filter handle.
2295 * @retval HAL status
2297 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedStart_IT(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2299 HAL_StatusTypeDef status
= HAL_OK
;
2301 /* Check parameters */
2302 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2304 /* Check DFSDM filter state */
2305 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
2306 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
))
2308 /* Enable interrupts for injected conversions */
2309 hdfsdm_filter
->Instance
->FLTCR2
|= (DFSDM_FLTCR2_JEOCIE
| DFSDM_FLTCR2_JOVRIE
);
2311 /* Start injected conversion */
2312 DFSDM_InjConvStart(hdfsdm_filter
);
2318 /* Return function status */
2323 * @brief This function allows to stop injected conversion in interrupt mode.
2324 * @note This function should be called only if injected conversion is ongoing.
2325 * @param hdfsdm_filter : DFSDM filter handle.
2326 * @retval HAL status
2328 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedStop_IT(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2330 HAL_StatusTypeDef status
= HAL_OK
;
2332 /* Check parameters */
2333 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2335 /* Check DFSDM filter state */
2336 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_INJ
) && \
2337 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
2339 /* Return error status */
2344 /* Disable interrupts for injected conversions */
2345 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_JEOCIE
| DFSDM_FLTCR2_JOVRIE
);
2347 /* Stop injected conversion */
2348 DFSDM_InjConvStop(hdfsdm_filter
);
2350 /* Return function status */
2355 * @brief This function allows to start injected conversion in DMA mode.
2356 * @note This function should be called only when DFSDM filter instance is
2357 * in idle state or if regular conversion is ongoing.
2358 * Please note that data on buffer will contain signed injected conversion
2359 * value on 24 most significant bits and corresponding channel on 3 least
2361 * @param hdfsdm_filter : DFSDM filter handle.
2362 * @param pData : The destination buffer address.
2363 * @param Length : The length of data to be transferred from DFSDM filter to memory.
2364 * @retval HAL status
2366 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedStart_DMA(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2370 HAL_StatusTypeDef status
= HAL_OK
;
2372 /* Check parameters */
2373 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2375 /* Check destination address and length */
2376 if((pData
== NULL
) || (Length
== 0U))
2380 /* Check that DMA is enabled for injected conversion */
2381 else if((hdfsdm_filter
->Instance
->FLTCR1
& DFSDM_FLTCR1_JDMAEN
) != DFSDM_FLTCR1_JDMAEN
)
2385 /* Check parameters compatibility */
2386 else if((hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2387 (hdfsdm_filter
->hdmaInj
->Init
.Mode
== DMA_NORMAL
) && \
2388 (Length
> hdfsdm_filter
->InjConvRemaining
))
2392 else if((hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2393 (hdfsdm_filter
->hdmaInj
->Init
.Mode
== DMA_CIRCULAR
))
2397 /* Check DFSDM filter state */
2398 else if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
2399 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
))
2401 /* Set callbacks on DMA handler */
2402 hdfsdm_filter
->hdmaInj
->XferCpltCallback
= DFSDM_DMAInjectedConvCplt
;
2403 hdfsdm_filter
->hdmaInj
->XferErrorCallback
= DFSDM_DMAError
;
2404 hdfsdm_filter
->hdmaInj
->XferHalfCpltCallback
= (hdfsdm_filter
->hdmaInj
->Init
.Mode
== DMA_CIRCULAR
) ?\
2405 DFSDM_DMAInjectedHalfConvCplt
: NULL
;
2407 /* Start DMA in interrupt mode */
2408 if(HAL_DMA_Start_IT(hdfsdm_filter
->hdmaInj
, (uint32_t)&hdfsdm_filter
->Instance
->FLTJDATAR
, \
2409 (uint32_t) pData
, Length
) != HAL_OK
)
2411 /* Set DFSDM filter in error state */
2412 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_ERROR
;
2417 /* Start injected conversion */
2418 DFSDM_InjConvStart(hdfsdm_filter
);
2425 /* Return function status */
2430 * @brief This function allows to start injected conversion in DMA mode and to get
2431 * only the 16 most significant bits of conversion.
2432 * @note This function should be called only when DFSDM filter instance is
2433 * in idle state or if regular conversion is ongoing.
2434 * Please note that data on buffer will contain signed 16 most significant
2435 * bits of injected conversion.
2436 * @param hdfsdm_filter : DFSDM filter handle.
2437 * @param pData : The destination buffer address.
2438 * @param Length : The length of data to be transferred from DFSDM filter to memory.
2439 * @retval HAL status
2441 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedMsbStart_DMA(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2445 HAL_StatusTypeDef status
= HAL_OK
;
2447 /* Check parameters */
2448 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2450 /* Check destination address and length */
2451 if((pData
== NULL
) || (Length
== 0U))
2455 /* Check that DMA is enabled for injected conversion */
2456 else if((hdfsdm_filter
->Instance
->FLTCR1
& DFSDM_FLTCR1_JDMAEN
) != DFSDM_FLTCR1_JDMAEN
)
2460 /* Check parameters compatibility */
2461 else if((hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2462 (hdfsdm_filter
->hdmaInj
->Init
.Mode
== DMA_NORMAL
) && \
2463 (Length
> hdfsdm_filter
->InjConvRemaining
))
2467 else if((hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
) && \
2468 (hdfsdm_filter
->hdmaInj
->Init
.Mode
== DMA_CIRCULAR
))
2472 /* Check DFSDM filter state */
2473 else if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) || \
2474 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
))
2476 /* Set callbacks on DMA handler */
2477 hdfsdm_filter
->hdmaInj
->XferCpltCallback
= DFSDM_DMAInjectedConvCplt
;
2478 hdfsdm_filter
->hdmaInj
->XferErrorCallback
= DFSDM_DMAError
;
2479 hdfsdm_filter
->hdmaInj
->XferHalfCpltCallback
= (hdfsdm_filter
->hdmaInj
->Init
.Mode
== DMA_CIRCULAR
) ?\
2480 DFSDM_DMAInjectedHalfConvCplt
: NULL
;
2482 /* Start DMA in interrupt mode */
2483 if(HAL_DMA_Start_IT(hdfsdm_filter
->hdmaInj
, (uint32_t)(&hdfsdm_filter
->Instance
->FLTJDATAR
) + 2U, \
2484 (uint32_t) pData
, Length
) != HAL_OK
)
2486 /* Set DFSDM filter in error state */
2487 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_ERROR
;
2492 /* Start injected conversion */
2493 DFSDM_InjConvStart(hdfsdm_filter
);
2500 /* Return function status */
2505 * @brief This function allows to stop injected conversion in DMA mode.
2506 * @note This function should be called only if injected conversion is ongoing.
2507 * @param hdfsdm_filter : DFSDM filter handle.
2508 * @retval HAL status
2510 HAL_StatusTypeDef
HAL_DFSDM_FilterInjectedStop_DMA(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2512 HAL_StatusTypeDef status
= HAL_OK
;
2514 /* Check parameters */
2515 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2517 /* Check DFSDM filter state */
2518 if((hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_INJ
) && \
2519 (hdfsdm_filter
->State
!= HAL_DFSDM_FILTER_STATE_REG_INJ
))
2521 /* Return error status */
2526 /* Stop current DMA transfer */
2527 if(HAL_DMA_Abort(hdfsdm_filter
->hdmaInj
) != HAL_OK
)
2529 /* Set DFSDM filter in error state */
2530 hdfsdm_filter
->State
= HAL_DFSDM_FILTER_STATE_ERROR
;
2535 /* Stop regular conversion */
2536 DFSDM_InjConvStop(hdfsdm_filter
);
2539 /* Return function status */
2544 * @brief This function allows to get injected conversion value.
2545 * @param hdfsdm_filter : DFSDM filter handle.
2546 * @param Channel : Corresponding channel of injected conversion.
2547 * @retval Injected conversion value
2549 int32_t HAL_DFSDM_FilterGetInjectedValue(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2555 /* Check parameters */
2556 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2557 assert_param(Channel
!= NULL
);
2559 /* Get value of data register for injected channel */
2560 reg
= hdfsdm_filter
->Instance
->FLTJDATAR
;
2562 /* Extract channel and injected conversion value */
2563 *Channel
= (reg
& DFSDM_FLTJDATAR_JDATACH
);
2564 value
= ((int32_t)(reg
& DFSDM_FLTJDATAR_JDATA
) >> DFSDM_FLTJDATAR_DATA_OFFSET
);
2566 /* return regular conversion value */
2571 * @brief This function allows to start filter analog watchdog in interrupt mode.
2572 * @param hdfsdm_filter : DFSDM filter handle.
2573 * @param awdParam : DFSDM filter analog watchdog parameters.
2574 * @retval HAL status
2576 HAL_StatusTypeDef
HAL_DFSDM_FilterAwdStart_IT(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2577 DFSDM_Filter_AwdParamTypeDef
*awdParam
)
2579 HAL_StatusTypeDef status
= HAL_OK
;
2581 /* Check parameters */
2582 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2583 assert_param(IS_DFSDM_FILTER_AWD_DATA_SOURCE(awdParam
->DataSource
));
2584 assert_param(IS_DFSDM_INJECTED_CHANNEL(awdParam
->Channel
));
2585 assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam
->HighThreshold
));
2586 assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam
->LowThreshold
));
2587 assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam
->HighBreakSignal
));
2588 assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam
->LowBreakSignal
));
2590 /* Check DFSDM filter state */
2591 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_RESET
) || \
2592 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_ERROR
))
2594 /* Return error status */
2599 /* Set analog watchdog data source */
2600 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_AWFSEL
);
2601 hdfsdm_filter
->Instance
->FLTCR1
|= awdParam
->DataSource
;
2603 /* Set thresholds and break signals */
2604 hdfsdm_filter
->Instance
->FLTAWHTR
&= ~(DFSDM_FLTAWHTR_AWHT
| DFSDM_FLTAWHTR_BKAWH
);
2605 hdfsdm_filter
->Instance
->FLTAWHTR
|= (((uint32_t) awdParam
->HighThreshold
<< DFSDM_FLTAWHTR_THRESHOLD_OFFSET
) | \
2606 awdParam
->HighBreakSignal
);
2607 hdfsdm_filter
->Instance
->FLTAWLTR
&= ~(DFSDM_FLTAWLTR_AWLT
| DFSDM_FLTAWLTR_BKAWL
);
2608 hdfsdm_filter
->Instance
->FLTAWLTR
|= (((uint32_t) awdParam
->LowThreshold
<< DFSDM_FLTAWLTR_THRESHOLD_OFFSET
) | \
2609 awdParam
->LowBreakSignal
);
2611 /* Set channels and interrupt for analog watchdog */
2612 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_AWDCH
);
2613 hdfsdm_filter
->Instance
->FLTCR2
|= (((awdParam
->Channel
& DFSDM_LSB_MASK
) << DFSDM_FLTCR2_AWDCH_OFFSET
) | \
2614 DFSDM_FLTCR2_AWDIE
);
2616 /* Return function status */
2621 * @brief This function allows to stop filter analog watchdog in interrupt mode.
2622 * @param hdfsdm_filter : DFSDM filter handle.
2623 * @retval HAL status
2625 HAL_StatusTypeDef
HAL_DFSDM_FilterAwdStop_IT(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2627 HAL_StatusTypeDef status
= HAL_OK
;
2629 /* Check parameters */
2630 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2632 /* Check DFSDM filter state */
2633 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_RESET
) || \
2634 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_ERROR
))
2636 /* Return error status */
2641 /* Reset channels for analog watchdog and deactivate interrupt */
2642 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_AWDCH
| DFSDM_FLTCR2_AWDIE
);
2644 /* Clear all analog watchdog flags */
2645 hdfsdm_filter
->Instance
->FLTAWCFR
= (DFSDM_FLTAWCFR_CLRAWHTF
| DFSDM_FLTAWCFR_CLRAWLTF
);
2647 /* Reset thresholds and break signals */
2648 hdfsdm_filter
->Instance
->FLTAWHTR
&= ~(DFSDM_FLTAWHTR_AWHT
| DFSDM_FLTAWHTR_BKAWH
);
2649 hdfsdm_filter
->Instance
->FLTAWLTR
&= ~(DFSDM_FLTAWLTR_AWLT
| DFSDM_FLTAWLTR_BKAWL
);
2651 /* Reset analog watchdog data source */
2652 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_AWFSEL
);
2654 /* Return function status */
2659 * @brief This function allows to start extreme detector feature.
2660 * @param hdfsdm_filter : DFSDM filter handle.
2661 * @param Channel : Channels where extreme detector is enabled.
2662 * This parameter can be a values combination of @ref DFSDM_Channel_Selection.
2663 * @retval HAL status
2665 HAL_StatusTypeDef
HAL_DFSDM_FilterExdStart(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2668 HAL_StatusTypeDef status
= HAL_OK
;
2670 /* Check parameters */
2671 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2672 assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel
));
2674 /* Check DFSDM filter state */
2675 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_RESET
) || \
2676 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_ERROR
))
2678 /* Return error status */
2683 /* Set channels for extreme detector */
2684 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_EXCH
);
2685 hdfsdm_filter
->Instance
->FLTCR2
|= ((Channel
& DFSDM_LSB_MASK
) << DFSDM_FLTCR2_EXCH_OFFSET
);
2687 /* Return function status */
2692 * @brief This function allows to stop extreme detector feature.
2693 * @param hdfsdm_filter : DFSDM filter handle.
2694 * @retval HAL status
2696 HAL_StatusTypeDef
HAL_DFSDM_FilterExdStop(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2698 HAL_StatusTypeDef status
= HAL_OK
;
2702 /* Check parameters */
2703 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2705 /* Check DFSDM filter state */
2706 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_RESET
) || \
2707 (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_ERROR
))
2709 /* Return error status */
2714 /* Reset channels for extreme detector */
2715 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_EXCH
);
2717 /* Clear extreme detector values */
2718 reg1
= hdfsdm_filter
->Instance
->FLTEXMAX
;
2719 reg2
= hdfsdm_filter
->Instance
->FLTEXMIN
;
2720 UNUSED(reg1
); /* To avoid GCC warning */
2721 UNUSED(reg2
); /* To avoid GCC warning */
2723 /* Return function status */
2728 * @brief This function allows to get extreme detector maximum value.
2729 * @param hdfsdm_filter : DFSDM filter handle.
2730 * @param Channel : Corresponding channel.
2731 * @retval Extreme detector maximum value
2732 * This value is between Min_Data = -8388608 and Max_Data = 8388607.
2734 int32_t HAL_DFSDM_FilterGetExdMaxValue(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2740 /* Check parameters */
2741 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2742 assert_param(Channel
!= NULL
);
2744 /* Get value of extreme detector maximum register */
2745 reg
= hdfsdm_filter
->Instance
->FLTEXMAX
;
2747 /* Extract channel and extreme detector maximum value */
2748 *Channel
= (reg
& DFSDM_FLTEXMAX_EXMAXCH
);
2749 value
= ((int32_t)(reg
& DFSDM_FLTEXMAX_EXMAX
) >> DFSDM_FLTEXMAX_DATA_OFFSET
);
2751 /* return extreme detector maximum value */
2756 * @brief This function allows to get extreme detector minimum value.
2757 * @param hdfsdm_filter : DFSDM filter handle.
2758 * @param Channel : Corresponding channel.
2759 * @retval Extreme detector minimum value
2760 * This value is between Min_Data = -8388608 and Max_Data = 8388607.
2762 int32_t HAL_DFSDM_FilterGetExdMinValue(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
2768 /* Check parameters */
2769 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2770 assert_param(Channel
!= NULL
);
2772 /* Get value of extreme detector minimum register */
2773 reg
= hdfsdm_filter
->Instance
->FLTEXMIN
;
2775 /* Extract channel and extreme detector minimum value */
2776 *Channel
= (reg
& DFSDM_FLTEXMIN_EXMINCH
);
2777 value
= ((int32_t)(reg
& DFSDM_FLTEXMIN_EXMIN
) >> DFSDM_FLTEXMIN_DATA_OFFSET
);
2779 /* return extreme detector minimum value */
2784 * @brief This function allows to get conversion time value.
2785 * @param hdfsdm_filter : DFSDM filter handle.
2786 * @retval Conversion time value
2787 * @note To get time in second, this value has to be divided by DFSDM clock frequency.
2789 uint32_t HAL_DFSDM_FilterGetConvTimeValue(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2792 uint32_t value
= 0U;
2794 /* Check parameters */
2795 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter
->Instance
));
2797 /* Get value of conversion timer register */
2798 reg
= hdfsdm_filter
->Instance
->FLTCNVTIMR
;
2800 /* Extract conversion time value */
2801 value
= ((reg
& DFSDM_FLTCNVTIMR_CNVCNT
) >> DFSDM_FLTCNVTIMR_DATA_OFFSET
);
2803 /* return extreme detector minimum value */
2808 * @brief This function handles the DFSDM interrupts.
2809 * @param hdfsdm_filter : DFSDM filter handle.
2812 void HAL_DFSDM_IRQHandler(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
2814 /* Check if overrun occurs during regular conversion */
2815 if(((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_ROVRF
) != 0U) && \
2816 ((hdfsdm_filter
->Instance
->FLTCR2
& DFSDM_FLTCR2_ROVRIE
) != 0U))
2818 /* Clear regular overrun flag */
2819 hdfsdm_filter
->Instance
->FLTICR
= DFSDM_FLTICR_CLRROVRF
;
2821 /* Update error code */
2822 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_REGULAR_OVERRUN
;
2824 /* Call error callback */
2825 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter
);
2827 /* Check if overrun occurs during injected conversion */
2828 else if(((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_JOVRF
) != 0U) && \
2829 ((hdfsdm_filter
->Instance
->FLTCR2
& DFSDM_FLTCR2_JOVRIE
) != 0U))
2831 /* Clear injected overrun flag */
2832 hdfsdm_filter
->Instance
->FLTICR
= DFSDM_FLTICR_CLRJOVRF
;
2834 /* Update error code */
2835 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_INJECTED_OVERRUN
;
2837 /* Call error callback */
2838 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter
);
2840 /* Check if end of regular conversion */
2841 else if(((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_REOCF
) != 0U) && \
2842 ((hdfsdm_filter
->Instance
->FLTCR2
& DFSDM_FLTCR2_REOCIE
) != 0U))
2844 /* Call regular conversion complete callback */
2845 HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter
);
2847 /* End of conversion if mode is not continuous and software trigger */
2848 if((hdfsdm_filter
->RegularContMode
== DFSDM_CONTINUOUS_CONV_OFF
) && \
2849 (hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
))
2851 /* Disable interrupts for regular conversions */
2852 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_REOCIE
);
2854 /* Update DFSDM filter state */
2855 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
) ? \
2856 HAL_DFSDM_FILTER_STATE_READY
: HAL_DFSDM_FILTER_STATE_INJ
;
2859 /* Check if end of injected conversion */
2860 else if(((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_JEOCF
) != 0U) && \
2861 ((hdfsdm_filter
->Instance
->FLTCR2
& DFSDM_FLTCR2_JEOCIE
) != 0U))
2863 /* Call injected conversion complete callback */
2864 HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter
);
2866 /* Update remaining injected conversions */
2867 hdfsdm_filter
->InjConvRemaining
--;
2868 if(hdfsdm_filter
->InjConvRemaining
== 0U)
2870 /* End of conversion if trigger is software */
2871 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
)
2873 /* Disable interrupts for injected conversions */
2874 hdfsdm_filter
->Instance
->FLTCR2
&= ~(DFSDM_FLTCR2_JEOCIE
);
2876 /* Update DFSDM filter state */
2877 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
) ? \
2878 HAL_DFSDM_FILTER_STATE_READY
: HAL_DFSDM_FILTER_STATE_REG
;
2880 /* end of injected sequence, reset the value */
2881 hdfsdm_filter
->InjConvRemaining
= (hdfsdm_filter
->InjectedScanMode
== ENABLE
) ? \
2882 hdfsdm_filter
->InjectedChannelsNbr
: 1U;
2885 /* Check if analog watchdog occurs */
2886 else if(((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_AWDF
) != 0U) && \
2887 ((hdfsdm_filter
->Instance
->FLTCR2
& DFSDM_FLTCR2_AWDIE
) != 0U))
2890 uint32_t threshold
= 0U;
2891 uint32_t channel
= 0U;
2893 /* Get channel and threshold */
2894 reg
= hdfsdm_filter
->Instance
->FLTAWSR
;
2895 threshold
= ((reg
& DFSDM_FLTAWSR_AWLTF
) != 0U) ? DFSDM_AWD_LOW_THRESHOLD
: DFSDM_AWD_HIGH_THRESHOLD
;
2896 if(threshold
== DFSDM_AWD_HIGH_THRESHOLD
)
2898 reg
= reg
>> DFSDM_FLTAWSR_HIGH_OFFSET
;
2900 while((reg
& 1U) == 0U)
2905 /* Clear analog watchdog flag */
2906 hdfsdm_filter
->Instance
->FLTAWCFR
= (threshold
== DFSDM_AWD_HIGH_THRESHOLD
) ? \
2907 (1U << (DFSDM_FLTAWSR_HIGH_OFFSET
+ channel
)) : \
2910 /* Call analog watchdog callback */
2911 HAL_DFSDM_FilterAwdCallback(hdfsdm_filter
, channel
, threshold
);
2913 /* Check if clock absence occurs */
2914 else if((hdfsdm_filter
->Instance
== DFSDM1_Filter0
) && \
2915 ((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_CKABF
) != 0U) && \
2916 ((hdfsdm_filter
->Instance
->FLTCR2
& DFSDM_FLTCR2_CKABIE
) != 0U))
2919 uint32_t channel
= 0U;
2921 reg
= ((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_CKABF
) >> DFSDM_FLTISR_CKABF_OFFSET
);
2923 while(channel
< DFSDM1_CHANNEL_NUMBER
)
2925 /* Check if flag is set and corresponding channel is enabled */
2926 if(((reg
& 1U) != 0U) && (a_dfsdm1ChannelHandle
[channel
] != NULL
))
2928 /* Check clock absence has been enabled for this channel */
2929 if((a_dfsdm1ChannelHandle
[channel
]->Instance
->CHCFGR1
& DFSDM_CHCFGR1_CKABEN
) != 0U)
2931 /* Clear clock absence flag */
2932 hdfsdm_filter
->Instance
->FLTICR
= (1U << (DFSDM_FLTICR_CLRCKABF_OFFSET
+ channel
));
2934 /* Call clock absence callback */
2935 HAL_DFSDM_ChannelCkabCallback(a_dfsdm1ChannelHandle
[channel
]);
2942 #if defined (DFSDM2_Channel0)
2943 /* Check if clock absence occurs */
2944 else if((hdfsdm_filter
->Instance
== DFSDM2_Filter0
) && \
2945 ((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_CKABF
) != 0U) && \
2946 ((hdfsdm_filter
->Instance
->FLTCR2
& DFSDM_FLTCR2_CKABIE
) != 0U))
2949 uint32_t channel
= 0U;
2951 reg
= ((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_CKABF
) >> DFSDM_FLTISR_CKABF_OFFSET
);
2953 while(channel
< DFSDM2_CHANNEL_NUMBER
)
2955 /* Check if flag is set and corresponding channel is enabled */
2956 if(((reg
& 1U) != 0U) && (a_dfsdm2ChannelHandle
[channel
] != NULL
))
2958 /* Check clock absence has been enabled for this channel */
2959 if((a_dfsdm2ChannelHandle
[channel
]->Instance
->CHCFGR1
& DFSDM_CHCFGR1_CKABEN
) != 0U)
2961 /* Clear clock absence flag */
2962 hdfsdm_filter
->Instance
->FLTICR
= (1U << (DFSDM_FLTICR_CLRCKABF_OFFSET
+ channel
));
2964 /* Call clock absence callback */
2965 HAL_DFSDM_ChannelCkabCallback(a_dfsdm2ChannelHandle
[channel
]);
2972 #endif /* DFSDM2_Channel0 */
2973 /* Check if short circuit detection occurs */
2974 else if((hdfsdm_filter
->Instance
== DFSDM1_Filter0
) && \
2975 ((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_SCDF
) != 0U) && \
2976 ((hdfsdm_filter
->Instance
->FLTCR2
& DFSDM_FLTCR2_SCDIE
) != 0U))
2979 uint32_t channel
= 0U;
2982 reg
= ((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_SCDF
) >> DFSDM_FLTISR_SCDF_OFFSET
);
2983 while((reg
& 1U) == 0U)
2989 /* Clear short circuit detection flag */
2990 hdfsdm_filter
->Instance
->FLTICR
= (1U << (DFSDM_FLTICR_CLRSCDF_OFFSET
+ channel
));
2992 /* Call short circuit detection callback */
2993 HAL_DFSDM_ChannelScdCallback(a_dfsdm1ChannelHandle
[channel
]);
2995 #if defined (DFSDM2_Channel0)
2996 /* Check if short circuit detection occurs */
2997 else if((hdfsdm_filter
->Instance
== DFSDM2_Filter0
) && \
2998 ((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_SCDF
) != 0U) && \
2999 ((hdfsdm_filter
->Instance
->FLTCR2
& DFSDM_FLTCR2_SCDIE
) != 0U))
3002 uint32_t channel
= 0U;
3005 reg
= ((hdfsdm_filter
->Instance
->FLTISR
& DFSDM_FLTISR_SCDF
) >> DFSDM_FLTISR_SCDF_OFFSET
);
3006 while((reg
& 1U) == 0U)
3012 /* Clear short circuit detection flag */
3013 hdfsdm_filter
->Instance
->FLTICR
= (1U << (DFSDM_FLTICR_CLRSCDF_OFFSET
+ channel
));
3015 /* Call short circuit detection callback */
3016 HAL_DFSDM_ChannelScdCallback(a_dfsdm2ChannelHandle
[channel
]);
3018 #endif /* DFSDM2_Channel0 */
3022 * @brief Regular conversion complete callback.
3023 * @note In interrupt mode, user has to read conversion value in this function
3024 * using HAL_DFSDM_FilterGetRegularValue.
3025 * @param hdfsdm_filter : DFSDM filter handle.
3028 __weak
void HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3030 /* Prevent unused argument(s) compilation warning */
3031 UNUSED(hdfsdm_filter
);
3032 /* NOTE : This function should not be modified, when the callback is needed,
3033 the HAL_DFSDM_FilterRegConvCpltCallback could be implemented in the user file.
3038 * @brief Half regular conversion complete callback.
3039 * @param hdfsdm_filter : DFSDM filter handle.
3042 __weak
void HAL_DFSDM_FilterRegConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3044 /* Prevent unused argument(s) compilation warning */
3045 UNUSED(hdfsdm_filter
);
3046 /* NOTE : This function should not be modified, when the callback is needed,
3047 the HAL_DFSDM_FilterRegConvHalfCpltCallback could be implemented in the user file.
3052 * @brief Injected conversion complete callback.
3053 * @note In interrupt mode, user has to read conversion value in this function
3054 * using HAL_DFSDM_FilterGetInjectedValue.
3055 * @param hdfsdm_filter : DFSDM filter handle.
3058 __weak
void HAL_DFSDM_FilterInjConvCpltCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3060 /* Prevent unused argument(s) compilation warning */
3061 UNUSED(hdfsdm_filter
);
3062 /* NOTE : This function should not be modified, when the callback is needed,
3063 the HAL_DFSDM_FilterInjConvCpltCallback could be implemented in the user file.
3068 * @brief Half injected conversion complete callback.
3069 * @param hdfsdm_filter : DFSDM filter handle.
3072 __weak
void HAL_DFSDM_FilterInjConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3074 /* Prevent unused argument(s) compilation warning */
3075 UNUSED(hdfsdm_filter
);
3076 /* NOTE : This function should not be modified, when the callback is needed,
3077 the HAL_DFSDM_FilterInjConvHalfCpltCallback could be implemented in the user file.
3082 * @brief Filter analog watchdog callback.
3083 * @param hdfsdm_filter : DFSDM filter handle.
3084 * @param Channel : Corresponding channel.
3085 * @param Threshold : Low or high threshold has been reached.
3088 __weak
void HAL_DFSDM_FilterAwdCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
,
3089 uint32_t Channel
, uint32_t Threshold
)
3091 /* Prevent unused argument(s) compilation warning */
3092 UNUSED(hdfsdm_filter
);
3096 /* NOTE : This function should not be modified, when the callback is needed,
3097 the HAL_DFSDM_FilterAwdCallback could be implemented in the user file.
3102 * @brief Error callback.
3103 * @param hdfsdm_filter : DFSDM filter handle.
3106 __weak
void HAL_DFSDM_FilterErrorCallback(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3108 /* Prevent unused argument(s) compilation warning */
3109 UNUSED(hdfsdm_filter
);
3110 /* NOTE : This function should not be modified, when the callback is needed,
3111 the HAL_DFSDM_FilterErrorCallback could be implemented in the user file.
3119 /** @defgroup DFSDM_Exported_Functions_Group4_Filter Filter state functions
3120 * @brief Filter state functions
3123 ==============================================================================
3124 ##### Filter state functions #####
3125 ==============================================================================
3126 [..] This section provides functions allowing to:
3127 (+) Get the DFSDM filter state.
3128 (+) Get the DFSDM filter error.
3134 * @brief This function allows to get the current DFSDM filter handle state.
3135 * @param hdfsdm_filter : DFSDM filter handle.
3136 * @retval DFSDM filter state.
3138 HAL_DFSDM_Filter_StateTypeDef
HAL_DFSDM_FilterGetState(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3140 /* Return DFSDM filter handle state */
3141 return hdfsdm_filter
->State
;
3145 * @brief This function allows to get the current DFSDM filter error.
3146 * @param hdfsdm_filter : DFSDM filter handle.
3147 * @retval DFSDM filter error code.
3149 uint32_t HAL_DFSDM_FilterGetError(DFSDM_Filter_HandleTypeDef
*hdfsdm_filter
)
3151 return hdfsdm_filter
->ErrorCode
;
3158 /** @defgroup DFSDM_Exported_Functions_Group5_Filter MultiChannel operation functions
3159 * @brief Filter state functions
3162 ==============================================================================
3163 ##### Filter MultiChannel operation functions #####
3164 ==============================================================================
3165 [..] This section provides functions allowing to:
3166 (+) Control the DFSDM Multi channel delay block
3170 #if defined(SYSCFG_MCHDLYCR_BSCKSEL)
3172 * @brief Select the DFSDM2 as clock source for the bitstream clock.
3173 * @note The SYSCFG clock marco __HAL_RCC_SYSCFG_CLK_ENABLE() must be called
3174 * before HAL_DFSDM_BitstreamClock_Start()
3176 void HAL_DFSDM_BitstreamClock_Start(void)
3180 tmp
= SYSCFG
->MCHDLYCR
;
3181 tmp
= (tmp
&(~SYSCFG_MCHDLYCR_BSCKSEL
));
3183 SYSCFG
->MCHDLYCR
= (tmp
|SYSCFG_MCHDLYCR_BSCKSEL
);
3187 * @brief Stop the DFSDM2 as clock source for the bitstream clock.
3188 * @note The SYSCFG clock marco __HAL_RCC_SYSCFG_CLK_ENABLE() must be called
3189 * before HAL_DFSDM_BitstreamClock_Stop()
3192 void HAL_DFSDM_BitstreamClock_Stop(void)
3196 tmp
= SYSCFG
->MCHDLYCR
;
3197 tmp
= (tmp
&(~SYSCFG_MCHDLYCR_BSCKSEL
));
3199 SYSCFG
->MCHDLYCR
= tmp
;
3203 * @brief Disable Delay Clock for DFSDM1/2.
3204 * @param MCHDLY: HAL_MCHDLY_CLOCK_DFSDM2.
3205 * HAL_MCHDLY_CLOCK_DFSDM1.
3206 * @note The SYSCFG clock marco __HAL_RCC_SYSCFG_CLK_ENABLE() must be called
3207 * before HAL_DFSDM_DisableDelayClock()
3210 void HAL_DFSDM_DisableDelayClock(uint32_t MCHDLY
)
3214 assert_param(IS_DFSDM_DELAY_CLOCK(MCHDLY
));
3216 tmp
= SYSCFG
->MCHDLYCR
;
3217 if(MCHDLY
== HAL_MCHDLY_CLOCK_DFSDM2
)
3219 tmp
= tmp
&(~SYSCFG_MCHDLYCR_MCHDLY2EN
);
3223 tmp
= tmp
&(~SYSCFG_MCHDLYCR_MCHDLY1EN
);
3226 SYSCFG
->MCHDLYCR
= tmp
;
3230 * @brief Enable Delay Clock for DFSDM1/2.
3231 * @param MCHDLY: HAL_MCHDLY_CLOCK_DFSDM2.
3232 * HAL_MCHDLY_CLOCK_DFSDM1.
3233 * @note The SYSCFG clock marco __HAL_RCC_SYSCFG_CLK_ENABLE() must be called
3234 * before HAL_DFSDM_EnableDelayClock()
3237 void HAL_DFSDM_EnableDelayClock(uint32_t MCHDLY
)
3241 assert_param(IS_DFSDM_DELAY_CLOCK(MCHDLY
));
3243 tmp
= SYSCFG
->MCHDLYCR
;
3244 tmp
= tmp
& ~MCHDLY
;
3246 SYSCFG
->MCHDLYCR
= (tmp
|MCHDLY
);
3250 * @brief Select the source for CKin signals for DFSDM1/2.
3251 * @param source: DFSDM2_CKIN_PAD.
3257 void HAL_DFSDM_ClockIn_SourceSelection(uint32_t source
)
3261 assert_param(IS_DFSDM_CLOCKIN_SELECTION(source
));
3263 tmp
= SYSCFG
->MCHDLYCR
;
3265 if((source
== HAL_DFSDM2_CKIN_PAD
) || (source
== HAL_DFSDM2_CKIN_DM
))
3267 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM2CFG
);
3269 if(source
== HAL_DFSDM2_CKIN_PAD
)
3276 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM1CFG
);
3279 SYSCFG
->MCHDLYCR
= (source
|tmp
);
3283 * @brief Select the source for CKOut signals for DFSDM1/2.
3284 * @param source: DFSDM2_CKOUT_DFSDM2.
3286 * DFSDM1_CKOUT_DFSDM1.
3290 void HAL_DFSDM_ClockOut_SourceSelection(uint32_t source
)
3294 assert_param(IS_DFSDM_CLOCKOUT_SELECTION(source
));
3296 tmp
= SYSCFG
->MCHDLYCR
;
3298 if((source
== HAL_DFSDM2_CKOUT_DFSDM2
) || (source
== HAL_DFSDM2_CKOUT_M27
))
3300 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM2CKOSEL
);
3302 if(source
== HAL_DFSDM2_CKOUT_DFSDM2
)
3309 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM1CKOSEL
);
3312 SYSCFG
->MCHDLYCR
= (source
|tmp
);
3316 * @brief Select the source for DataIn0 signals for DFSDM1/2.
3317 * @param source: DATAIN0_DFSDM2_PAD.
3318 * DATAIN0_DFSDM2_DATAIN1.
3319 * DATAIN0_DFSDM1_PAD.
3320 * DATAIN0_DFSDM1_DATAIN1.
3323 void HAL_DFSDM_DataIn0_SourceSelection(uint32_t source
)
3327 assert_param(IS_DFSDM_DATAIN0_SRC_SELECTION(source
));
3329 tmp
= SYSCFG
->MCHDLYCR
;
3331 if((source
== HAL_DATAIN0_DFSDM2_PAD
)|| (source
== HAL_DATAIN0_DFSDM2_DATAIN1
))
3333 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM2D0SEL
);
3334 if(source
== HAL_DATAIN0_DFSDM2_PAD
)
3341 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM1D0SEL
);
3343 SYSCFG
->MCHDLYCR
= (source
|tmp
);
3347 * @brief Select the source for DataIn2 signals for DFSDM1/2.
3348 * @param source: DATAIN2_DFSDM2_PAD.
3349 * DATAIN2_DFSDM2_DATAIN3.
3350 * DATAIN2_DFSDM1_PAD.
3351 * DATAIN2_DFSDM1_DATAIN3.
3354 void HAL_DFSDM_DataIn2_SourceSelection(uint32_t source
)
3358 assert_param(IS_DFSDM_DATAIN2_SRC_SELECTION(source
));
3360 tmp
= SYSCFG
->MCHDLYCR
;
3362 if((source
== HAL_DATAIN2_DFSDM2_PAD
)|| (source
== HAL_DATAIN2_DFSDM2_DATAIN3
))
3364 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM2D2SEL
);
3365 if (source
== HAL_DATAIN2_DFSDM2_PAD
)
3372 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM1D2SEL
);
3374 SYSCFG
->MCHDLYCR
= (source
|tmp
);
3378 * @brief Select the source for DataIn4 signals for DFSDM2.
3379 * @param source: DATAIN4_DFSDM2_PAD.
3380 * DATAIN4_DFSDM2_DATAIN5
3383 void HAL_DFSDM_DataIn4_SourceSelection(uint32_t source
)
3387 assert_param(IS_DFSDM_DATAIN4_SRC_SELECTION(source
));
3389 tmp
= SYSCFG
->MCHDLYCR
;
3390 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM2D4SEL
);
3392 SYSCFG
->MCHDLYCR
= (source
|tmp
);
3396 * @brief Select the source for DataIn6 signals for DFSDM2.
3397 * @param source: DATAIN6_DFSDM2_PAD.
3398 * DATAIN6_DFSDM2_DATAIN7.
3401 void HAL_DFSDM_DataIn6_SourceSelection(uint32_t source
)
3405 assert_param(IS_DFSDM_DATAIN6_SRC_SELECTION(source
));
3407 tmp
= SYSCFG
->MCHDLYCR
;
3409 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM2D6SEL
);
3411 SYSCFG
->MCHDLYCR
= (source
|tmp
);
3415 * @brief Configure the distribution of the bitstream clock gated from TIM4_OC
3416 * for DFSDM1 or TIM3_OC for DFSDM2
3417 * @param source: DFSDM1_CLKIN0_TIM4OC2
3418 * DFSDM1_CLKIN2_TIM4OC2
3419 * DFSDM1_CLKIN1_TIM4OC1
3420 * DFSDM1_CLKIN3_TIM4OC1
3421 * DFSDM2_CLKIN0_TIM3OC4
3422 * DFSDM2_CLKIN4_TIM3OC4
3423 * DFSDM2_CLKIN1_TIM3OC3
3424 * DFSDM2_CLKIN5_TIM3OC3
3425 * DFSDM2_CLKIN2_TIM3OC2
3426 * DFSDM2_CLKIN6_TIM3OC2
3427 * DFSDM2_CLKIN3_TIM3OC1
3428 * DFSDM2_CLKIN7_TIM3OC1
3431 void HAL_DFSDM_BitStreamClkDistribution_Config(uint32_t source
)
3435 assert_param(IS_DFSDM_BITSTREM_CLK_DISTRIBUTION(source
));
3437 tmp
= SYSCFG
->MCHDLYCR
;
3439 if ((source
== HAL_DFSDM1_CLKIN0_TIM4OC2
) || (source
== HAL_DFSDM1_CLKIN2_TIM4OC2
))
3441 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM1CK02SEL
);
3443 else if ((source
== HAL_DFSDM1_CLKIN1_TIM4OC1
) || (source
== HAL_DFSDM1_CLKIN3_TIM4OC1
))
3445 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM1CK13SEL
);
3447 else if ((source
== HAL_DFSDM2_CLKIN0_TIM3OC4
) || (source
== HAL_DFSDM2_CLKIN4_TIM3OC4
))
3449 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM2CK04SEL
);
3451 else if ((source
== HAL_DFSDM2_CLKIN1_TIM3OC3
) || (source
== HAL_DFSDM2_CLKIN5_TIM3OC3
))
3453 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM2CK15SEL
);
3455 }else if ((source
== HAL_DFSDM2_CLKIN2_TIM3OC2
) || (source
== HAL_DFSDM2_CLKIN6_TIM3OC2
))
3457 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM2CK26SEL
);
3461 tmp
= (tmp
& ~SYSCFG_MCHDLYCR_DFSDM2CK37SEL
);
3464 if((source
== HAL_DFSDM1_CLKIN0_TIM4OC2
) ||(source
== HAL_DFSDM1_CLKIN1_TIM4OC1
)||
3465 (source
== HAL_DFSDM2_CLKIN0_TIM3OC4
) ||(source
== HAL_DFSDM2_CLKIN1_TIM3OC3
)||
3466 (source
== HAL_DFSDM2_CLKIN2_TIM3OC2
) ||(source
== HAL_DFSDM2_CLKIN3_TIM3OC1
))
3471 SYSCFG
->MCHDLYCR
= (source
|tmp
);
3475 * @brief Configure multi channel delay block: Use DFSDM2 audio clock source as input
3476 * clock for DFSDM1 and DFSDM2 filters to Synchronize DFSDMx filters.
3477 * Set the path of the DFSDM2 clock output (dfsdm2_ckout) to the
3478 * DFSDM1/2 CkInx and data inputs channels by configuring following MCHDLY muxes
3479 * or demuxes: M1, M2, M3, M4, M5, M6, M7, M8, DM1, DM2, DM3, DM4, DM5, DM6,
3480 * M9, M10, M11, M12, M13, M14, M15, M16, M17, M18, M19, M20 based on the
3481 * contains of the DFSDM_MultiChannelConfigTypeDef structure
3482 * @param mchdlystruct: Structure of multi channel configuration
3484 * @note The SYSCFG clock marco __HAL_RCC_SYSCFG_CLK_ENABLE() must be called
3485 * before HAL_DFSDM_ConfigMultiChannelDelay()
3486 * @note The HAL_DFSDM_ConfigMultiChannelDelay() function clears the SYSCFG-MCHDLYCR
3487 * register before setting the new configuration.
3489 void HAL_DFSDM_ConfigMultiChannelDelay(DFSDM_MultiChannelConfigTypeDef
* mchdlystruct
)
3491 uint32_t mchdlyreg
= 0U;
3493 assert_param(IS_DFSDM_DFSDM1_CLKOUT(mchdlystruct
->DFSDM1ClockOut
));
3494 assert_param(IS_DFSDM_DFSDM2_CLKOUT(mchdlystruct
->DFSDM2ClockOut
));
3495 assert_param(IS_DFSDM_DFSDM1_CLKIN(mchdlystruct
->DFSDM1ClockIn
));
3496 assert_param(IS_DFSDM_DFSDM2_CLKIN(mchdlystruct
->DFSDM2ClockIn
));
3497 assert_param(IS_DFSDM_DFSDM1_BIT_CLK((mchdlystruct
->DFSDM1BitClkDistribution
)));
3498 assert_param(IS_DFSDM_DFSDM2_BIT_CLK(mchdlystruct
->DFSDM2BitClkDistribution
));
3499 assert_param(IS_DFSDM_DFSDM1_DATA_DISTRIBUTION(mchdlystruct
->DFSDM1DataDistribution
));
3500 assert_param(IS_DFSDM_DFSDM2_DATA_DISTRIBUTION(mchdlystruct
->DFSDM2DataDistribution
));
3502 mchdlyreg
= (SYSCFG
->MCHDLYCR
& 0x80103U
);
3504 SYSCFG
->MCHDLYCR
= (mchdlyreg
|(mchdlystruct
->DFSDM1ClockOut
)|(mchdlystruct
->DFSDM2ClockOut
)|
3505 (mchdlystruct
->DFSDM1ClockIn
)|(mchdlystruct
->DFSDM2ClockIn
)|
3506 (mchdlystruct
->DFSDM1BitClkDistribution
)| (mchdlystruct
->DFSDM2BitClkDistribution
)|
3507 (mchdlystruct
->DFSDM1DataDistribution
)| (mchdlystruct
->DFSDM2DataDistribution
));
3510 #endif /* SYSCFG_MCHDLYCR_BSCKSEL */
3517 /* End of exported functions -------------------------------------------------*/
3519 /* Private functions ---------------------------------------------------------*/
3520 /** @addtogroup DFSDM_Private_Functions DFSDM Private Functions
3525 * @brief DMA half transfer complete callback for regular conversion.
3526 * @param hdma : DMA handle.
3529 static void DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef
*hdma
)
3531 /* Get DFSDM filter handle */
3532 DFSDM_Filter_HandleTypeDef
* hdfsdm_filter
= (DFSDM_Filter_HandleTypeDef
*) ((DMA_HandleTypeDef
*)hdma
)->Parent
;
3534 /* Call regular half conversion complete callback */
3535 HAL_DFSDM_FilterRegConvHalfCpltCallback(hdfsdm_filter
);
3539 * @brief DMA transfer complete callback for regular conversion.
3540 * @param hdma : DMA handle.
3543 static void DFSDM_DMARegularConvCplt(DMA_HandleTypeDef
*hdma
)
3545 /* Get DFSDM filter handle */
3546 DFSDM_Filter_HandleTypeDef
* hdfsdm_filter
= (DFSDM_Filter_HandleTypeDef
*) ((DMA_HandleTypeDef
*)hdma
)->Parent
;
3548 /* Call regular conversion complete callback */
3549 HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter
);
3553 * @brief DMA half transfer complete callback for injected conversion.
3554 * @param hdma : DMA handle.
3557 static void DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef
*hdma
)
3559 /* Get DFSDM filter handle */
3560 DFSDM_Filter_HandleTypeDef
* hdfsdm_filter
= (DFSDM_Filter_HandleTypeDef
*) ((DMA_HandleTypeDef
*)hdma
)->Parent
;
3562 /* Call injected half conversion complete callback */
3563 HAL_DFSDM_FilterInjConvHalfCpltCallback(hdfsdm_filter
);
3567 * @brief DMA transfer complete callback for injected conversion.
3568 * @param hdma : DMA handle.
3571 static void DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef
*hdma
)
3573 /* Get DFSDM filter handle */
3574 DFSDM_Filter_HandleTypeDef
* hdfsdm_filter
= (DFSDM_Filter_HandleTypeDef
*) ((DMA_HandleTypeDef
*)hdma
)->Parent
;
3576 /* Call injected conversion complete callback */
3577 HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter
);
3581 * @brief DMA error callback.
3582 * @param hdma : DMA handle.
3585 static void DFSDM_DMAError(DMA_HandleTypeDef
*hdma
)
3587 /* Get DFSDM filter handle */
3588 DFSDM_Filter_HandleTypeDef
* hdfsdm_filter
= (DFSDM_Filter_HandleTypeDef
*) ((DMA_HandleTypeDef
*)hdma
)->Parent
;
3590 /* Update error code */
3591 hdfsdm_filter
->ErrorCode
= DFSDM_FILTER_ERROR_DMA
;
3593 /* Call error callback */
3594 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter
);
3598 * @brief This function allows to get the number of injected channels.
3599 * @param Channels : bitfield of injected channels.
3600 * @retval Number of injected channels.
3602 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels
)
3604 uint32_t nbChannels
= 0U;
3607 /* Get the number of channels from bitfield */
3608 tmp
= (uint32_t) (Channels
& DFSDM_LSB_MASK
);
3611 if((tmp
& 1U) != 0U)
3615 tmp
= (uint32_t) (tmp
>> 1U);
3621 * @brief This function allows to get the channel number from channel instance.
3622 * @param Instance : DFSDM channel instance.
3623 * @retval Channel number.
3625 static uint32_t DFSDM_GetChannelFromInstance(DFSDM_Channel_TypeDef
* Instance
)
3627 uint32_t channel
= 0xFFU
;
3629 /* Get channel from instance */
3630 #if defined(DFSDM2_Channel0)
3631 if((Instance
== DFSDM1_Channel0
) || (Instance
== DFSDM2_Channel0
))
3635 else if((Instance
== DFSDM1_Channel1
) || (Instance
== DFSDM2_Channel1
))
3639 else if((Instance
== DFSDM1_Channel2
) || (Instance
== DFSDM2_Channel2
))
3643 else if((Instance
== DFSDM1_Channel3
) || (Instance
== DFSDM2_Channel3
))
3647 else if(Instance
== DFSDM2_Channel4
)
3651 else if(Instance
== DFSDM2_Channel5
)
3655 else if(Instance
== DFSDM2_Channel6
)
3659 else if(Instance
== DFSDM2_Channel7
)
3664 if(Instance
== DFSDM1_Channel0
)
3668 else if(Instance
== DFSDM1_Channel1
)
3672 else if(Instance
== DFSDM1_Channel2
)
3676 else if(Instance
== DFSDM1_Channel3
)
3680 #endif /* defined(DFSDM2_Channel0) */
3686 * @brief This function allows to really start regular conversion.
3687 * @param hdfsdm_filter : DFSDM filter handle.
3690 static void DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef
* hdfsdm_filter
)
3692 /* Check regular trigger */
3693 if(hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
)
3695 /* Software start of regular conversion */
3696 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_RSWSTART
;
3698 else /* synchronous trigger */
3700 /* Disable DFSDM filter */
3701 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_DFEN
);
3703 /* Set RSYNC bit in DFSDM_FLTCR1 register */
3704 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_RSYNC
;
3706 /* Enable DFSDM filter */
3707 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_DFEN
;
3709 /* If injected conversion was in progress, restart it */
3710 if(hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
)
3712 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
)
3714 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_JSWSTART
;
3716 /* Update remaining injected conversions */
3717 hdfsdm_filter
->InjConvRemaining
= (hdfsdm_filter
->InjectedScanMode
== ENABLE
) ? \
3718 hdfsdm_filter
->InjectedChannelsNbr
: 1U;
3721 /* Update DFSDM filter state */
3722 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) ? \
3723 HAL_DFSDM_FILTER_STATE_REG
: HAL_DFSDM_FILTER_STATE_REG_INJ
;
3727 * @brief This function allows to really stop regular conversion.
3728 * @param hdfsdm_filter : DFSDM filter handle.
3731 static void DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef
* hdfsdm_filter
)
3733 /* Disable DFSDM filter */
3734 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_DFEN
);
3736 /* If regular trigger was synchronous, reset RSYNC bit in DFSDM_FLTCR1 register */
3737 if(hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SYNC_TRIGGER
)
3739 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_RSYNC
);
3742 /* Enable DFSDM filter */
3743 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_DFEN
;
3745 /* If injected conversion was in progress, restart it */
3746 if(hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG_INJ
)
3748 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
)
3750 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_JSWSTART
;
3752 /* Update remaining injected conversions */
3753 hdfsdm_filter
->InjConvRemaining
= (hdfsdm_filter
->InjectedScanMode
== ENABLE
) ? \
3754 hdfsdm_filter
->InjectedChannelsNbr
: 1U;
3757 /* Update DFSDM filter state */
3758 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
) ? \
3759 HAL_DFSDM_FILTER_STATE_READY
: HAL_DFSDM_FILTER_STATE_INJ
;
3763 * @brief This function allows to really start injected conversion.
3764 * @param hdfsdm_filter : DFSDM filter handle.
3767 static void DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef
* hdfsdm_filter
)
3769 /* Check injected trigger */
3770 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SW_TRIGGER
)
3772 /* Software start of injected conversion */
3773 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_JSWSTART
;
3775 else /* external or synchronous trigger */
3777 /* Disable DFSDM filter */
3778 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_DFEN
);
3780 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SYNC_TRIGGER
)
3782 /* Set JSYNC bit in DFSDM_FLTCR1 register */
3783 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_JSYNC
;
3785 else /* external trigger */
3787 /* Set JEXTEN[1:0] bits in DFSDM_FLTCR1 register */
3788 hdfsdm_filter
->Instance
->FLTCR1
|= hdfsdm_filter
->ExtTriggerEdge
;
3791 /* Enable DFSDM filter */
3792 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_DFEN
;
3794 /* If regular conversion was in progress, restart it */
3795 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG
) && \
3796 (hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
))
3798 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_RSWSTART
;
3801 /* Update DFSDM filter state */
3802 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_READY
) ? \
3803 HAL_DFSDM_FILTER_STATE_INJ
: HAL_DFSDM_FILTER_STATE_REG_INJ
;
3807 * @brief This function allows to really stop injected conversion.
3808 * @param hdfsdm_filter : DFSDM filter handle.
3811 static void DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef
* hdfsdm_filter
)
3813 /* Disable DFSDM filter */
3814 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_DFEN
);
3816 /* If injected trigger was synchronous, reset JSYNC bit in DFSDM_FLTCR1 register */
3817 if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_SYNC_TRIGGER
)
3819 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_JSYNC
);
3821 else if(hdfsdm_filter
->InjectedTrigger
== DFSDM_FILTER_EXT_TRIGGER
)
3823 /* Reset JEXTEN[1:0] bits in DFSDM_FLTCR1 register */
3824 hdfsdm_filter
->Instance
->FLTCR1
&= ~(DFSDM_FLTCR1_JEXTEN
);
3827 /* Enable DFSDM filter */
3828 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_DFEN
;
3830 /* If regular conversion was in progress, restart it */
3831 if((hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_REG_INJ
) && \
3832 (hdfsdm_filter
->RegularTrigger
== DFSDM_FILTER_SW_TRIGGER
))
3834 hdfsdm_filter
->Instance
->FLTCR1
|= DFSDM_FLTCR1_RSWSTART
;
3837 /* Update remaining injected conversions */
3838 hdfsdm_filter
->InjConvRemaining
= (hdfsdm_filter
->InjectedScanMode
== ENABLE
) ? \
3839 hdfsdm_filter
->InjectedChannelsNbr
: 1U;
3841 /* Update DFSDM filter state */
3842 hdfsdm_filter
->State
= (hdfsdm_filter
->State
== HAL_DFSDM_FILTER_STATE_INJ
) ? \
3843 HAL_DFSDM_FILTER_STATE_READY
: HAL_DFSDM_FILTER_STATE_REG
;
3848 /* End of private functions --------------------------------------------------*/
3853 #endif /* STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
3854 #endif /* HAL_DFSDM_MODULE_ENABLED */
3859 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/