STM32F479xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_hal_dfsdm.c 00004 * @author MCD Application Team 00005 * @brief This file provides firmware functions to manage the following 00006 * functionalities of the Digital Filter for Sigma-Delta Modulators 00007 * (DFSDM) peripherals: 00008 * + Initialization and configuration of channels and filters 00009 * + Regular channels configuration 00010 * + Injected channels configuration 00011 * + Regular/Injected Channels DMA Configuration 00012 * + Interrupts and flags management 00013 * + Analog watchdog feature 00014 * + Short-circuit detector feature 00015 * + Extremes detector feature 00016 * + Clock absence detector feature 00017 * + Break generation on analog watchdog or short-circuit event 00018 * 00019 @verbatim 00020 ============================================================================== 00021 ##### How to use this driver ##### 00022 ============================================================================== 00023 [..] 00024 *** Channel initialization *** 00025 ============================== 00026 [..] 00027 (#) User has first to initialize channels (before filters initialization). 00028 (#) As prerequisite, fill in the HAL_DFSDM_ChannelMspInit() : 00029 (++) Enable DFSDMz clock interface with __HAL_RCC_DFSDMz_CLK_ENABLE(). 00030 (++) Enable the clocks for the DFSDMz GPIOS with __HAL_RCC_GPIOx_CLK_ENABLE(). 00031 (++) Configure these DFSDMz pins in alternate mode using HAL_GPIO_Init(). 00032 (++) If interrupt mode is used, enable and configure DFSDMz_FLT0 global 00033 interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ(). 00034 (#) Configure the output clock, input, serial interface, analog watchdog, 00035 offset and data right bit shift parameters for this channel using the 00036 HAL_DFSDM_ChannelInit() function. 00037 00038 *** Channel clock absence detector *** 00039 ====================================== 00040 [..] 00041 (#) Start clock absence detector using HAL_DFSDM_ChannelCkabStart() or 00042 HAL_DFSDM_ChannelCkabStart_IT(). 00043 (#) In polling mode, use HAL_DFSDM_ChannelPollForCkab() to detect the clock 00044 absence. 00045 (#) In interrupt mode, HAL_DFSDM_ChannelCkabCallback() will be called if 00046 clock absence is detected. 00047 (#) Stop clock absence detector using HAL_DFSDM_ChannelCkabStop() or 00048 HAL_DFSDM_ChannelCkabStop_IT(). 00049 (#) Please note that the same mode (polling or interrupt) has to be used 00050 for all channels because the channels are sharing the same interrupt. 00051 (#) Please note also that in interrupt mode, if clock absence detector is 00052 stopped for one channel, interrupt will be disabled for all channels. 00053 00054 *** Channel short circuit detector *** 00055 ====================================== 00056 [..] 00057 (#) Start short circuit detector using HAL_DFSDM_ChannelScdStart() or 00058 or HAL_DFSDM_ChannelScdStart_IT(). 00059 (#) In polling mode, use HAL_DFSDM_ChannelPollForScd() to detect short 00060 circuit. 00061 (#) In interrupt mode, HAL_DFSDM_ChannelScdCallback() will be called if 00062 short circuit is detected. 00063 (#) Stop short circuit detector using HAL_DFSDM_ChannelScdStop() or 00064 or HAL_DFSDM_ChannelScdStop_IT(). 00065 (#) Please note that the same mode (polling or interrupt) has to be used 00066 for all channels because the channels are sharing the same interrupt. 00067 (#) Please note also that in interrupt mode, if short circuit detector is 00068 stopped for one channel, interrupt will be disabled for all channels. 00069 00070 *** Channel analog watchdog value *** 00071 ===================================== 00072 [..] 00073 (#) Get analog watchdog filter value of a channel using 00074 HAL_DFSDM_ChannelGetAwdValue(). 00075 00076 *** Channel offset value *** 00077 ===================================== 00078 [..] 00079 (#) Modify offset value of a channel using HAL_DFSDM_ChannelModifyOffset(). 00080 00081 *** Filter initialization *** 00082 ============================= 00083 [..] 00084 (#) After channel initialization, user has to init filters. 00085 (#) As prerequisite, fill in the HAL_DFSDM_FilterMspInit() : 00086 (++) If interrupt mode is used , enable and configure DFSDMz_FLTx global 00087 interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ(). 00088 Please note that DFSDMz_FLT0 global interrupt could be already 00089 enabled if interrupt is used for channel. 00090 (++) If DMA mode is used, configure DMA with HAL_DMA_Init() and link it 00091 with DFSDMz filter handle using __HAL_LINKDMA(). 00092 (#) Configure the regular conversion, injected conversion and filter 00093 parameters for this filter using the HAL_DFSDM_FilterInit() function. 00094 00095 *** Filter regular channel conversion *** 00096 ========================================= 00097 [..] 00098 (#) Select regular channel and enable/disable continuous mode using 00099 HAL_DFSDM_FilterConfigRegChannel(). 00100 (#) Start regular conversion using HAL_DFSDM_FilterRegularStart(), 00101 HAL_DFSDM_FilterRegularStart_IT(), HAL_DFSDM_FilterRegularStart_DMA() or 00102 HAL_DFSDM_FilterRegularMsbStart_DMA(). 00103 (#) In polling mode, use HAL_DFSDM_FilterPollForRegConversion() to detect 00104 the end of regular conversion. 00105 (#) In interrupt mode, HAL_DFSDM_FilterRegConvCpltCallback() will be called 00106 at the end of regular conversion. 00107 (#) Get value of regular conversion and corresponding channel using 00108 HAL_DFSDM_FilterGetRegularValue(). 00109 (#) In DMA mode, HAL_DFSDM_FilterRegConvHalfCpltCallback() and 00110 HAL_DFSDM_FilterRegConvCpltCallback() will be called respectively at the 00111 half transfer and at the transfer complete. Please note that 00112 HAL_DFSDM_FilterRegConvHalfCpltCallback() will be called only in DMA 00113 circular mode. 00114 (#) Stop regular conversion using HAL_DFSDM_FilterRegularStop(), 00115 HAL_DFSDM_FilterRegularStop_IT() or HAL_DFSDM_FilterRegularStop_DMA(). 00116 00117 *** Filter injected channels conversion *** 00118 =========================================== 00119 [..] 00120 (#) Select injected channels using HAL_DFSDM_FilterConfigInjChannel(). 00121 (#) Start injected conversion using HAL_DFSDM_FilterInjectedStart(), 00122 HAL_DFSDM_FilterInjectedStart_IT(), HAL_DFSDM_FilterInjectedStart_DMA() or 00123 HAL_DFSDM_FilterInjectedMsbStart_DMA(). 00124 (#) In polling mode, use HAL_DFSDM_FilterPollForInjConversion() to detect 00125 the end of injected conversion. 00126 (#) In interrupt mode, HAL_DFSDM_FilterInjConvCpltCallback() will be called 00127 at the end of injected conversion. 00128 (#) Get value of injected conversion and corresponding channel using 00129 HAL_DFSDM_FilterGetInjectedValue(). 00130 (#) In DMA mode, HAL_DFSDM_FilterInjConvHalfCpltCallback() and 00131 HAL_DFSDM_FilterInjConvCpltCallback() will be called respectively at the 00132 half transfer and at the transfer complete. Please note that 00133 HAL_DFSDM_FilterInjConvCpltCallback() will be called only in DMA 00134 circular mode. 00135 (#) Stop injected conversion using HAL_DFSDM_FilterInjectedStop(), 00136 HAL_DFSDM_FilterInjectedStop_IT() or HAL_DFSDM_FilterInjectedStop_DMA(). 00137 00138 *** Filter analog watchdog *** 00139 ============================== 00140 [..] 00141 (#) Start filter analog watchdog using HAL_DFSDM_FilterAwdStart_IT(). 00142 (#) HAL_DFSDM_FilterAwdCallback() will be called if analog watchdog occurs. 00143 (#) Stop filter analog watchdog using HAL_DFSDM_FilterAwdStop_IT(). 00144 00145 *** Filter extreme detector *** 00146 =============================== 00147 [..] 00148 (#) Start filter extreme detector using HAL_DFSDM_FilterExdStart(). 00149 (#) Get extreme detector maximum value using HAL_DFSDM_FilterGetExdMaxValue(). 00150 (#) Get extreme detector minimum value using HAL_DFSDM_FilterGetExdMinValue(). 00151 (#) Start filter extreme detector using HAL_DFSDM_FilterExdStop(). 00152 00153 *** Filter conversion time *** 00154 ============================== 00155 [..] 00156 (#) Get conversion time value using HAL_DFSDM_FilterGetConvTimeValue(). 00157 00158 *** Callback registration *** 00159 ============================= 00160 [..] 00161 The compilation define USE_HAL_DFSDM_REGISTER_CALLBACKS when set to 1 00162 allows the user to configure dynamically the driver callbacks. 00163 Use functions HAL_DFSDM_Channel_RegisterCallback(), 00164 HAL_DFSDM_Filter_RegisterCallback() or 00165 HAL_DFSDM_Filter_RegisterAwdCallback() to register a user callback. 00166 00167 [..] 00168 Function HAL_DFSDM_Channel_RegisterCallback() allows to register 00169 following callbacks: 00170 (+) CkabCallback : DFSDM channel clock absence detection callback. 00171 (+) ScdCallback : DFSDM channel short circuit detection callback. 00172 (+) MspInitCallback : DFSDM channel MSP init callback. 00173 (+) MspDeInitCallback : DFSDM channel MSP de-init callback. 00174 [..] 00175 This function takes as parameters the HAL peripheral handle, the Callback ID 00176 and a pointer to the user callback function. 00177 00178 [..] 00179 Function HAL_DFSDM_Filter_RegisterCallback() allows to register 00180 following callbacks: 00181 (+) RegConvCpltCallback : DFSDM filter regular conversion complete callback. 00182 (+) RegConvHalfCpltCallback : DFSDM filter half regular conversion complete callback. 00183 (+) InjConvCpltCallback : DFSDM filter injected conversion complete callback. 00184 (+) InjConvHalfCpltCallback : DFSDM filter half injected conversion complete callback. 00185 (+) ErrorCallback : DFSDM filter error callback. 00186 (+) MspInitCallback : DFSDM filter MSP init callback. 00187 (+) MspDeInitCallback : DFSDM filter MSP de-init callback. 00188 [..] 00189 This function takes as parameters the HAL peripheral handle, the Callback ID 00190 and a pointer to the user callback function. 00191 00192 [..] 00193 For specific DFSDM filter analog watchdog callback use dedicated register callback: 00194 HAL_DFSDM_Filter_RegisterAwdCallback(). 00195 00196 [..] 00197 Use functions HAL_DFSDM_Channel_UnRegisterCallback() or 00198 HAL_DFSDM_Filter_UnRegisterCallback() to reset a callback to the default 00199 weak function. 00200 00201 [..] 00202 HAL_DFSDM_Channel_UnRegisterCallback() takes as parameters the HAL peripheral handle, 00203 and the Callback ID. 00204 [..] 00205 This function allows to reset following callbacks: 00206 (+) CkabCallback : DFSDM channel clock absence detection callback. 00207 (+) ScdCallback : DFSDM channel short circuit detection callback. 00208 (+) MspInitCallback : DFSDM channel MSP init callback. 00209 (+) MspDeInitCallback : DFSDM channel MSP de-init callback. 00210 00211 [..] 00212 HAL_DFSDM_Filter_UnRegisterCallback() takes as parameters the HAL peripheral handle, 00213 and the Callback ID. 00214 [..] 00215 This function allows to reset following callbacks: 00216 (+) RegConvCpltCallback : DFSDM filter regular conversion complete callback. 00217 (+) RegConvHalfCpltCallback : DFSDM filter half regular conversion complete callback. 00218 (+) InjConvCpltCallback : DFSDM filter injected conversion complete callback. 00219 (+) InjConvHalfCpltCallback : DFSDM filter half injected conversion complete callback. 00220 (+) ErrorCallback : DFSDM filter error callback. 00221 (+) MspInitCallback : DFSDM filter MSP init callback. 00222 (+) MspDeInitCallback : DFSDM filter MSP de-init callback. 00223 00224 [..] 00225 For specific DFSDM filter analog watchdog callback use dedicated unregister callback: 00226 HAL_DFSDM_Filter_UnRegisterAwdCallback(). 00227 00228 [..] 00229 By default, after the call of init function and if the state is RESET 00230 all callbacks are reset to the corresponding legacy weak functions: 00231 examples HAL_DFSDM_ChannelScdCallback(), HAL_DFSDM_FilterErrorCallback(). 00232 Exception done for MspInit and MspDeInit callbacks that are respectively 00233 reset to the legacy weak functions in the init and de-init only when these 00234 callbacks are null (not registered beforehand). 00235 If not, MspInit or MspDeInit are not null, the init and de-init keep and use 00236 the user MspInit/MspDeInit callbacks (registered beforehand) 00237 00238 [..] 00239 Callbacks can be registered/unregistered in READY state only. 00240 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered 00241 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used 00242 during the init/de-init. 00243 In that case first register the MspInit/MspDeInit user callbacks using 00244 HAL_DFSDM_Channel_RegisterCallback() or 00245 HAL_DFSDM_Filter_RegisterCallback() before calling init or de-init function. 00246 00247 [..] 00248 When The compilation define USE_HAL_DFSDM_REGISTER_CALLBACKS is set to 0 or 00249 not defined, the callback registering feature is not available 00250 and weak callbacks are used. 00251 00252 @endverbatim 00253 ****************************************************************************** 00254 * @attention 00255 * 00256 * <h2><center>© Copyright (c) 2017 STMicroelectronics. 00257 * All rights reserved.</center></h2> 00258 * 00259 * This software component is licensed by ST under BSD 3-Clause license, 00260 * the "License"; You may not use this file except in compliance with the 00261 * License. You may obtain a copy of the License at: 00262 * opensource.org/licenses/BSD-3-Clause 00263 * 00264 ****************************************************************************** 00265 */ 00266 00267 /* Includes ------------------------------------------------------------------*/ 00268 #include "stm32f4xx_hal.h" 00269 00270 /** @addtogroup STM32F4xx_HAL_Driver 00271 * @{ 00272 */ 00273 #ifdef HAL_DFSDM_MODULE_ENABLED 00274 #if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) 00275 /** @defgroup DFSDM DFSDM 00276 * @brief DFSDM HAL driver module 00277 * @{ 00278 */ 00279 00280 /* Private typedef -----------------------------------------------------------*/ 00281 /* Private define ------------------------------------------------------------*/ 00282 /** @defgroup DFSDM_Private_Define DFSDM Private Define 00283 * @{ 00284 */ 00285 00286 #define DFSDM_FLTCR1_MSB_RCH_OFFSET 8U 00287 00288 #define DFSDM_MSB_MASK 0xFFFF0000U 00289 #define DFSDM_LSB_MASK 0x0000FFFFU 00290 #define DFSDM_CKAB_TIMEOUT 5000U 00291 #define DFSDM1_CHANNEL_NUMBER 4U 00292 #if defined (DFSDM2_Channel0) 00293 #define DFSDM2_CHANNEL_NUMBER 8U 00294 #endif /* DFSDM2_Channel0 */ 00295 00296 /** 00297 * @} 00298 */ 00299 /** @addtogroup DFSDM_Private_Macros 00300 * @{ 00301 */ 00302 00303 /** 00304 * @} 00305 */ 00306 /* Private macro -------------------------------------------------------------*/ 00307 /* Private variables ---------------------------------------------------------*/ 00308 /** @defgroup DFSDM_Private_Variables DFSDM Private Variables 00309 * @{ 00310 */ 00311 __IO uint32_t v_dfsdm1ChannelCounter = 0U; 00312 DFSDM_Channel_HandleTypeDef* a_dfsdm1ChannelHandle[DFSDM1_CHANNEL_NUMBER] = {NULL}; 00313 00314 #if defined (DFSDM2_Channel0) 00315 __IO uint32_t v_dfsdm2ChannelCounter = 0U; 00316 DFSDM_Channel_HandleTypeDef* a_dfsdm2ChannelHandle[DFSDM2_CHANNEL_NUMBER] = {NULL}; 00317 #endif /* DFSDM2_Channel0 */ 00318 /** 00319 * @} 00320 */ 00321 00322 /* Private function prototypes -----------------------------------------------*/ 00323 /** @defgroup DFSDM_Private_Functions DFSDM Private Functions 00324 * @{ 00325 */ 00326 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels); 00327 static uint32_t DFSDM_GetChannelFromInstance(DFSDM_Channel_TypeDef* Instance); 00328 static void DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter); 00329 static void DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef* hdfsdm_filter); 00330 static void DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef* hdfsdm_filter); 00331 static void DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef* hdfsdm_filter); 00332 static void DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef *hdma); 00333 static void DFSDM_DMARegularConvCplt(DMA_HandleTypeDef *hdma); 00334 static void DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef *hdma); 00335 static void DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef *hdma); 00336 static void DFSDM_DMAError(DMA_HandleTypeDef *hdma); 00337 00338 /** 00339 * @} 00340 */ 00341 00342 /* Exported functions --------------------------------------------------------*/ 00343 /** @defgroup DFSDM_Exported_Functions DFSDM Exported Functions 00344 * @{ 00345 */ 00346 00347 /** @defgroup DFSDM_Exported_Functions_Group1_Channel Channel initialization and de-initialization functions 00348 * @brief Channel initialization and de-initialization functions 00349 * 00350 @verbatim 00351 ============================================================================== 00352 ##### Channel initialization and de-initialization functions ##### 00353 ============================================================================== 00354 [..] This section provides functions allowing to: 00355 (+) Initialize the DFSDM channel. 00356 (+) De-initialize the DFSDM channel. 00357 @endverbatim 00358 * @{ 00359 */ 00360 00361 /** 00362 * @brief Initialize the DFSDM channel according to the specified parameters 00363 * in the DFSDM_ChannelInitTypeDef structure and initialize the associated handle. 00364 * @param hdfsdm_channel DFSDM channel handle. 00365 * @retval HAL status. 00366 */ 00367 HAL_StatusTypeDef HAL_DFSDM_ChannelInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 00368 { 00369 #if defined(DFSDM2_Channel0) 00370 __IO uint32_t* channelCounterPtr; 00371 DFSDM_Channel_HandleTypeDef **channelHandleTable; 00372 DFSDM_Channel_TypeDef* channel0Instance; 00373 #endif /* defined(DFSDM2_Channel0) */ 00374 00375 /* Check DFSDM Channel handle */ 00376 if(hdfsdm_channel == NULL) 00377 { 00378 return HAL_ERROR; 00379 } 00380 00381 /* Check parameters */ 00382 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance)); 00383 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_channel->Init.OutputClock.Activation)); 00384 assert_param(IS_DFSDM_CHANNEL_INPUT(hdfsdm_channel->Init.Input.Multiplexer)); 00385 assert_param(IS_DFSDM_CHANNEL_DATA_PACKING(hdfsdm_channel->Init.Input.DataPacking)); 00386 assert_param(IS_DFSDM_CHANNEL_INPUT_PINS(hdfsdm_channel->Init.Input.Pins)); 00387 assert_param(IS_DFSDM_CHANNEL_SERIAL_INTERFACE_TYPE(hdfsdm_channel->Init.SerialInterface.Type)); 00388 assert_param(IS_DFSDM_CHANNEL_SPI_CLOCK(hdfsdm_channel->Init.SerialInterface.SpiClock)); 00389 assert_param(IS_DFSDM_CHANNEL_FILTER_ORDER(hdfsdm_channel->Init.Awd.FilterOrder)); 00390 assert_param(IS_DFSDM_CHANNEL_FILTER_OVS_RATIO(hdfsdm_channel->Init.Awd.Oversampling)); 00391 assert_param(IS_DFSDM_CHANNEL_OFFSET(hdfsdm_channel->Init.Offset)); 00392 assert_param(IS_DFSDM_CHANNEL_RIGHT_BIT_SHIFT(hdfsdm_channel->Init.RightBitShift)); 00393 00394 #if defined(DFSDM2_Channel0) 00395 /* Get channel counter, channel handle table and channel 0 instance */ 00396 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance)) 00397 { 00398 channelCounterPtr = &v_dfsdm1ChannelCounter; 00399 channelHandleTable = a_dfsdm1ChannelHandle; 00400 channel0Instance = DFSDM1_Channel0; 00401 } 00402 else 00403 { 00404 channelCounterPtr = &v_dfsdm2ChannelCounter; 00405 channelHandleTable = a_dfsdm2ChannelHandle; 00406 channel0Instance = DFSDM2_Channel0; 00407 } 00408 00409 /* Check that channel has not been already initialized */ 00410 if(channelHandleTable[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] != NULL) 00411 { 00412 return HAL_ERROR; 00413 } 00414 00415 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 00416 /* Reset callback pointers to the weak predefined callbacks */ 00417 hdfsdm_channel->CkabCallback = HAL_DFSDM_ChannelCkabCallback; 00418 hdfsdm_channel->ScdCallback = HAL_DFSDM_ChannelScdCallback; 00419 00420 /* Call MSP init function */ 00421 if(hdfsdm_channel->MspInitCallback == NULL) 00422 { 00423 hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit; 00424 } 00425 hdfsdm_channel->MspInitCallback(hdfsdm_channel); 00426 #else 00427 /* Call MSP init function */ 00428 HAL_DFSDM_ChannelMspInit(hdfsdm_channel); 00429 #endif 00430 00431 /* Update the channel counter */ 00432 (*channelCounterPtr)++; 00433 00434 /* Configure output serial clock and enable global DFSDM interface only for first channel */ 00435 if(*channelCounterPtr == 1U) 00436 { 00437 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK(hdfsdm_channel->Init.OutputClock.Selection)); 00438 /* Set the output serial clock source */ 00439 channel0Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTSRC); 00440 channel0Instance->CHCFGR1 |= hdfsdm_channel->Init.OutputClock.Selection; 00441 00442 /* Reset clock divider */ 00443 channel0Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTDIV); 00444 if(hdfsdm_channel->Init.OutputClock.Activation == ENABLE) 00445 { 00446 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK_DIVIDER(hdfsdm_channel->Init.OutputClock.Divider)); 00447 /* Set the output clock divider */ 00448 channel0Instance->CHCFGR1 |= (uint32_t) ((hdfsdm_channel->Init.OutputClock.Divider - 1U) << 00449 DFSDM_CHCFGR1_CKOUTDIV_Pos); 00450 } 00451 00452 /* enable the DFSDM global interface */ 00453 channel0Instance->CHCFGR1 |= DFSDM_CHCFGR1_DFSDMEN; 00454 } 00455 00456 /* Set channel input parameters */ 00457 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_DATPACK | DFSDM_CHCFGR1_DATMPX | 00458 DFSDM_CHCFGR1_CHINSEL); 00459 hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.Input.Multiplexer | 00460 hdfsdm_channel->Init.Input.DataPacking | 00461 hdfsdm_channel->Init.Input.Pins); 00462 00463 /* Set serial interface parameters */ 00464 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SITP | DFSDM_CHCFGR1_SPICKSEL); 00465 hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.SerialInterface.Type | 00466 hdfsdm_channel->Init.SerialInterface.SpiClock); 00467 00468 /* Set analog watchdog parameters */ 00469 hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_AWFORD | DFSDM_CHAWSCDR_AWFOSR); 00470 hdfsdm_channel->Instance->CHAWSCDR |= (hdfsdm_channel->Init.Awd.FilterOrder | 00471 ((hdfsdm_channel->Init.Awd.Oversampling - 1U) << DFSDM_CHAWSCDR_AWFOSR_Pos)); 00472 00473 /* Set channel offset and right bit shift */ 00474 hdfsdm_channel->Instance->CHCFGR2 &= ~(DFSDM_CHCFGR2_OFFSET | DFSDM_CHCFGR2_DTRBS); 00475 hdfsdm_channel->Instance->CHCFGR2 |= (((uint32_t) hdfsdm_channel->Init.Offset << DFSDM_CHCFGR2_OFFSET_Pos) | 00476 (hdfsdm_channel->Init.RightBitShift << DFSDM_CHCFGR2_DTRBS_Pos)); 00477 00478 /* Enable DFSDM channel */ 00479 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CHEN; 00480 00481 /* Set DFSDM Channel to ready state */ 00482 hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_READY; 00483 00484 /* Store channel handle in DFSDM channel handle table */ 00485 channelHandleTable[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] = hdfsdm_channel; 00486 00487 #else 00488 /* Check that channel has not been already initialized */ 00489 if(a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] != NULL) 00490 { 00491 return HAL_ERROR; 00492 } 00493 00494 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 00495 /* Reset callback pointers to the weak predefined callbacks */ 00496 hdfsdm_channel->CkabCallback = HAL_DFSDM_ChannelCkabCallback; 00497 hdfsdm_channel->ScdCallback = HAL_DFSDM_ChannelScdCallback; 00498 00499 /* Call MSP init function */ 00500 if(hdfsdm_channel->MspInitCallback == NULL) 00501 { 00502 hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit; 00503 } 00504 hdfsdm_channel->MspInitCallback(hdfsdm_channel); 00505 #else 00506 /* Call MSP init function */ 00507 HAL_DFSDM_ChannelMspInit(hdfsdm_channel); 00508 #endif 00509 00510 /* Update the channel counter */ 00511 v_dfsdm1ChannelCounter++; 00512 00513 /* Configure output serial clock and enable global DFSDM interface only for first channel */ 00514 if(v_dfsdm1ChannelCounter == 1U) 00515 { 00516 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK(hdfsdm_channel->Init.OutputClock.Selection)); 00517 /* Set the output serial clock source */ 00518 DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTSRC); 00519 DFSDM1_Channel0->CHCFGR1 |= hdfsdm_channel->Init.OutputClock.Selection; 00520 00521 /* Reset clock divider */ 00522 DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTDIV); 00523 if(hdfsdm_channel->Init.OutputClock.Activation == ENABLE) 00524 { 00525 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK_DIVIDER(hdfsdm_channel->Init.OutputClock.Divider)); 00526 /* Set the output clock divider */ 00527 DFSDM1_Channel0->CHCFGR1 |= (uint32_t) ((hdfsdm_channel->Init.OutputClock.Divider - 1U) << 00528 DFSDM_CHCFGR1_CKOUTDIV_Pos); 00529 } 00530 00531 /* enable the DFSDM global interface */ 00532 DFSDM1_Channel0->CHCFGR1 |= DFSDM_CHCFGR1_DFSDMEN; 00533 } 00534 00535 /* Set channel input parameters */ 00536 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_DATPACK | DFSDM_CHCFGR1_DATMPX | 00537 DFSDM_CHCFGR1_CHINSEL); 00538 hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.Input.Multiplexer | 00539 hdfsdm_channel->Init.Input.DataPacking | 00540 hdfsdm_channel->Init.Input.Pins); 00541 00542 /* Set serial interface parameters */ 00543 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SITP | DFSDM_CHCFGR1_SPICKSEL); 00544 hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.SerialInterface.Type | 00545 hdfsdm_channel->Init.SerialInterface.SpiClock); 00546 00547 /* Set analog watchdog parameters */ 00548 hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_AWFORD | DFSDM_CHAWSCDR_AWFOSR); 00549 hdfsdm_channel->Instance->CHAWSCDR |= (hdfsdm_channel->Init.Awd.FilterOrder | 00550 ((hdfsdm_channel->Init.Awd.Oversampling - 1U) << DFSDM_CHAWSCDR_AWFOSR_Pos)); 00551 00552 /* Set channel offset and right bit shift */ 00553 hdfsdm_channel->Instance->CHCFGR2 &= ~(DFSDM_CHCFGR2_OFFSET | DFSDM_CHCFGR2_DTRBS); 00554 hdfsdm_channel->Instance->CHCFGR2 |= (((uint32_t) hdfsdm_channel->Init.Offset << DFSDM_CHCFGR2_OFFSET_Pos) | 00555 (hdfsdm_channel->Init.RightBitShift << DFSDM_CHCFGR2_DTRBS_Pos)); 00556 00557 /* Enable DFSDM channel */ 00558 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CHEN; 00559 00560 /* Set DFSDM Channel to ready state */ 00561 hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_READY; 00562 00563 /* Store channel handle in DFSDM channel handle table */ 00564 a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] = hdfsdm_channel; 00565 #endif /* DFSDM2_Channel0 */ 00566 00567 return HAL_OK; 00568 } 00569 00570 /** 00571 * @brief De-initialize the DFSDM channel. 00572 * @param hdfsdm_channel DFSDM channel handle. 00573 * @retval HAL status. 00574 */ 00575 HAL_StatusTypeDef HAL_DFSDM_ChannelDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 00576 { 00577 #if defined(DFSDM2_Channel0) 00578 __IO uint32_t* channelCounterPtr; 00579 DFSDM_Channel_HandleTypeDef **channelHandleTable; 00580 DFSDM_Channel_TypeDef* channel0Instance; 00581 #endif /* defined(DFSDM2_Channel0) */ 00582 00583 /* Check DFSDM Channel handle */ 00584 if(hdfsdm_channel == NULL) 00585 { 00586 return HAL_ERROR; 00587 } 00588 00589 /* Check parameters */ 00590 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance)); 00591 00592 #if defined(DFSDM2_Channel0) 00593 /* Get channel counter, channel handle table and channel 0 instance */ 00594 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance)) 00595 { 00596 channelCounterPtr = &v_dfsdm1ChannelCounter; 00597 channelHandleTable = a_dfsdm1ChannelHandle; 00598 channel0Instance = DFSDM1_Channel0; 00599 } 00600 else 00601 { 00602 channelCounterPtr = &v_dfsdm2ChannelCounter; 00603 channelHandleTable = a_dfsdm2ChannelHandle; 00604 channel0Instance = DFSDM2_Channel0; 00605 } 00606 00607 /* Check that channel has not been already deinitialized */ 00608 if(channelHandleTable[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] == NULL) 00609 { 00610 return HAL_ERROR; 00611 } 00612 00613 /* Disable the DFSDM channel */ 00614 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CHEN); 00615 00616 /* Update the channel counter */ 00617 (*channelCounterPtr)--; 00618 00619 /* Disable global DFSDM at deinit of last channel */ 00620 if(*channelCounterPtr == 0U) 00621 { 00622 channel0Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_DFSDMEN); 00623 } 00624 00625 /* Call MSP deinit function */ 00626 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 00627 if(hdfsdm_channel->MspDeInitCallback == NULL) 00628 { 00629 hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit; 00630 } 00631 hdfsdm_channel->MspDeInitCallback(hdfsdm_channel); 00632 #else 00633 HAL_DFSDM_ChannelMspDeInit(hdfsdm_channel); 00634 #endif 00635 00636 /* Set DFSDM Channel in reset state */ 00637 hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_RESET; 00638 00639 /* Reset channel handle in DFSDM channel handle table */ 00640 channelHandleTable[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] = NULL; 00641 #else 00642 /* Check that channel has not been already deinitialized */ 00643 if(a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] == NULL) 00644 { 00645 return HAL_ERROR; 00646 } 00647 00648 /* Disable the DFSDM channel */ 00649 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CHEN); 00650 00651 /* Update the channel counter */ 00652 v_dfsdm1ChannelCounter--; 00653 00654 /* Disable global DFSDM at deinit of last channel */ 00655 if(v_dfsdm1ChannelCounter == 0U) 00656 { 00657 DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_DFSDMEN); 00658 } 00659 00660 /* Call MSP deinit function */ 00661 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 00662 if(hdfsdm_channel->MspDeInitCallback == NULL) 00663 { 00664 hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit; 00665 } 00666 hdfsdm_channel->MspDeInitCallback(hdfsdm_channel); 00667 #else 00668 HAL_DFSDM_ChannelMspDeInit(hdfsdm_channel); 00669 #endif 00670 00671 /* Set DFSDM Channel in reset state */ 00672 hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_RESET; 00673 00674 /* Reset channel handle in DFSDM channel handle table */ 00675 a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] = (DFSDM_Channel_HandleTypeDef *) NULL; 00676 #endif /* defined(DFSDM2_Channel0) */ 00677 00678 return HAL_OK; 00679 } 00680 00681 /** 00682 * @brief Initialize the DFSDM channel MSP. 00683 * @param hdfsdm_channel DFSDM channel handle. 00684 * @retval None 00685 */ 00686 __weak void HAL_DFSDM_ChannelMspInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 00687 { 00688 /* Prevent unused argument(s) compilation warning */ 00689 UNUSED(hdfsdm_channel); 00690 /* NOTE : This function should not be modified, when the function is needed, 00691 the HAL_DFSDM_ChannelMspInit could be implemented in the user file. 00692 */ 00693 } 00694 00695 /** 00696 * @brief De-initialize the DFSDM channel MSP. 00697 * @param hdfsdm_channel DFSDM channel handle. 00698 * @retval None 00699 */ 00700 __weak void HAL_DFSDM_ChannelMspDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 00701 { 00702 /* Prevent unused argument(s) compilation warning */ 00703 UNUSED(hdfsdm_channel); 00704 /* NOTE : This function should not be modified, when the function is needed, 00705 the HAL_DFSDM_ChannelMspDeInit could be implemented in the user file. 00706 */ 00707 } 00708 00709 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 00710 /** 00711 * @brief Register a user DFSDM channel callback 00712 * to be used instead of the weak predefined callback. 00713 * @param hdfsdm_channel DFSDM channel handle. 00714 * @param CallbackID ID of the callback to be registered. 00715 * This parameter can be one of the following values: 00716 * @arg @ref HAL_DFSDM_CHANNEL_CKAB_CB_ID clock absence detection callback ID. 00717 * @arg @ref HAL_DFSDM_CHANNEL_SCD_CB_ID short circuit detection callback ID. 00718 * @arg @ref HAL_DFSDM_CHANNEL_MSPINIT_CB_ID MSP init callback ID. 00719 * @arg @ref HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID MSP de-init callback ID. 00720 * @param pCallback pointer to the callback function. 00721 * @retval HAL status. 00722 */ 00723 HAL_StatusTypeDef HAL_DFSDM_Channel_RegisterCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel, 00724 HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID, 00725 pDFSDM_Channel_CallbackTypeDef pCallback) 00726 { 00727 HAL_StatusTypeDef status = HAL_OK; 00728 00729 if(pCallback == NULL) 00730 { 00731 /* update return status */ 00732 status = HAL_ERROR; 00733 } 00734 else 00735 { 00736 if(HAL_DFSDM_CHANNEL_STATE_READY == hdfsdm_channel->State) 00737 { 00738 switch (CallbackID) 00739 { 00740 case HAL_DFSDM_CHANNEL_CKAB_CB_ID : 00741 hdfsdm_channel->CkabCallback = pCallback; 00742 break; 00743 case HAL_DFSDM_CHANNEL_SCD_CB_ID : 00744 hdfsdm_channel->ScdCallback = pCallback; 00745 break; 00746 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID : 00747 hdfsdm_channel->MspInitCallback = pCallback; 00748 break; 00749 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID : 00750 hdfsdm_channel->MspDeInitCallback = pCallback; 00751 break; 00752 default : 00753 /* update return status */ 00754 status = HAL_ERROR; 00755 break; 00756 } 00757 } 00758 else if(HAL_DFSDM_CHANNEL_STATE_RESET == hdfsdm_channel->State) 00759 { 00760 switch (CallbackID) 00761 { 00762 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID : 00763 hdfsdm_channel->MspInitCallback = pCallback; 00764 break; 00765 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID : 00766 hdfsdm_channel->MspDeInitCallback = pCallback; 00767 break; 00768 default : 00769 /* update return status */ 00770 status = HAL_ERROR; 00771 break; 00772 } 00773 } 00774 else 00775 { 00776 /* update return status */ 00777 status = HAL_ERROR; 00778 } 00779 } 00780 return status; 00781 } 00782 00783 /** 00784 * @brief Unregister a user DFSDM channel callback. 00785 * DFSDM channel callback is redirected to the weak predefined callback. 00786 * @param hdfsdm_channel DFSDM channel handle. 00787 * @param CallbackID ID of the callback to be unregistered. 00788 * This parameter can be one of the following values: 00789 * @arg @ref HAL_DFSDM_CHANNEL_CKAB_CB_ID clock absence detection callback ID. 00790 * @arg @ref HAL_DFSDM_CHANNEL_SCD_CB_ID short circuit detection callback ID. 00791 * @arg @ref HAL_DFSDM_CHANNEL_MSPINIT_CB_ID MSP init callback ID. 00792 * @arg @ref HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID MSP de-init callback ID. 00793 * @retval HAL status. 00794 */ 00795 HAL_StatusTypeDef HAL_DFSDM_Channel_UnRegisterCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel, 00796 HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID) 00797 { 00798 HAL_StatusTypeDef status = HAL_OK; 00799 00800 if(HAL_DFSDM_CHANNEL_STATE_READY == hdfsdm_channel->State) 00801 { 00802 switch (CallbackID) 00803 { 00804 case HAL_DFSDM_CHANNEL_CKAB_CB_ID : 00805 hdfsdm_channel->CkabCallback = HAL_DFSDM_ChannelCkabCallback; 00806 break; 00807 case HAL_DFSDM_CHANNEL_SCD_CB_ID : 00808 hdfsdm_channel->ScdCallback = HAL_DFSDM_ChannelScdCallback; 00809 break; 00810 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID : 00811 hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit; 00812 break; 00813 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID : 00814 hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit; 00815 break; 00816 default : 00817 /* update return status */ 00818 status = HAL_ERROR; 00819 break; 00820 } 00821 } 00822 else if(HAL_DFSDM_CHANNEL_STATE_RESET == hdfsdm_channel->State) 00823 { 00824 switch (CallbackID) 00825 { 00826 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID : 00827 hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit; 00828 break; 00829 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID : 00830 hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit; 00831 break; 00832 default : 00833 /* update return status */ 00834 status = HAL_ERROR; 00835 break; 00836 } 00837 } 00838 else 00839 { 00840 /* update return status */ 00841 status = HAL_ERROR; 00842 } 00843 return status; 00844 } 00845 #endif /* USE_HAL_DFSDM_REGISTER_CALLBACKS */ 00846 /** 00847 * @} 00848 */ 00849 00850 /** @defgroup DFSDM_Exported_Functions_Group2_Channel Channel operation functions 00851 * @brief Channel operation functions 00852 * 00853 @verbatim 00854 ============================================================================== 00855 ##### Channel operation functions ##### 00856 ============================================================================== 00857 [..] This section provides functions allowing to: 00858 (+) Manage clock absence detector feature. 00859 (+) Manage short circuit detector feature. 00860 (+) Get analog watchdog value. 00861 (+) Modify offset value. 00862 @endverbatim 00863 * @{ 00864 */ 00865 00866 /** 00867 * @brief This function allows to start clock absence detection in polling mode. 00868 * @note Same mode has to be used for all channels. 00869 * @note If clock is not available on this channel during 5 seconds, 00870 * clock absence detection will not be activated and function 00871 * will return HAL_TIMEOUT error. 00872 * @param hdfsdm_channel DFSDM channel handle. 00873 * @retval HAL status 00874 */ 00875 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStart(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 00876 { 00877 HAL_StatusTypeDef status = HAL_OK; 00878 uint32_t tickstart; 00879 uint32_t channel; 00880 00881 #if defined(DFSDM2_Channel0) 00882 DFSDM_Filter_TypeDef* filter0Instance; 00883 #endif /* defined(DFSDM2_Channel0) */ 00884 00885 /* Check parameters */ 00886 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance)); 00887 00888 /* Check DFSDM channel state */ 00889 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY) 00890 { 00891 /* Return error status */ 00892 status = HAL_ERROR; 00893 } 00894 else 00895 { 00896 #if defined (DFSDM2_Channel0) 00897 /* Get channel counter, channel handle table and channel 0 instance */ 00898 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance)) 00899 { 00900 filter0Instance = DFSDM1_Filter0; 00901 } 00902 else 00903 { 00904 filter0Instance = DFSDM2_Filter0; 00905 } 00906 /* Get channel number from channel instance */ 00907 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance); 00908 00909 /* Get timeout */ 00910 tickstart = HAL_GetTick(); 00911 00912 /* Clear clock absence flag */ 00913 while((((filter0Instance->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1U) != 0U) 00914 { 00915 filter0Instance->FLTICR = (1U << (DFSDM_FLTICR_CLRCKABF_Pos + channel)); 00916 00917 /* Check the Timeout */ 00918 if((HAL_GetTick()-tickstart) > DFSDM_CKAB_TIMEOUT) 00919 { 00920 /* Set timeout status */ 00921 status = HAL_TIMEOUT; 00922 break; 00923 } 00924 } 00925 #else 00926 /* Get channel number from channel instance */ 00927 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance); 00928 00929 /* Get timeout */ 00930 tickstart = HAL_GetTick(); 00931 00932 /* Clear clock absence flag */ 00933 while((((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1U) != 0U) 00934 { 00935 DFSDM1_Filter0->FLTICR = (1U << (DFSDM_FLTICR_CLRCKABF_Pos + channel)); 00936 00937 /* Check the Timeout */ 00938 if((HAL_GetTick()-tickstart) > DFSDM_CKAB_TIMEOUT) 00939 { 00940 /* Set timeout status */ 00941 status = HAL_TIMEOUT; 00942 break; 00943 } 00944 } 00945 #endif /* DFSDM2_Channel0 */ 00946 00947 if(status == HAL_OK) 00948 { 00949 /* Start clock absence detection */ 00950 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CKABEN; 00951 } 00952 } 00953 /* Return function status */ 00954 return status; 00955 } 00956 00957 /** 00958 * @brief This function allows to poll for the clock absence detection. 00959 * @param hdfsdm_channel DFSDM channel handle. 00960 * @param Timeout Timeout value in milliseconds. 00961 * @retval HAL status 00962 */ 00963 HAL_StatusTypeDef HAL_DFSDM_ChannelPollForCkab(DFSDM_Channel_HandleTypeDef *hdfsdm_channel, 00964 uint32_t Timeout) 00965 { 00966 uint32_t tickstart; 00967 uint32_t channel; 00968 #if defined(DFSDM2_Channel0) 00969 DFSDM_Filter_TypeDef* filter0Instance; 00970 #endif /* defined(DFSDM2_Channel0) */ 00971 00972 /* Check parameters */ 00973 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance)); 00974 00975 /* Check DFSDM channel state */ 00976 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY) 00977 { 00978 /* Return error status */ 00979 return HAL_ERROR; 00980 } 00981 else 00982 { 00983 #if defined(DFSDM2_Channel0) 00984 00985 /* Get channel counter, channel handle table and channel 0 instance */ 00986 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance)) 00987 { 00988 filter0Instance = DFSDM1_Filter0; 00989 } 00990 else 00991 { 00992 filter0Instance = DFSDM2_Filter0; 00993 } 00994 00995 /* Get channel number from channel instance */ 00996 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance); 00997 00998 /* Get timeout */ 00999 tickstart = HAL_GetTick(); 01000 01001 /* Wait clock absence detection */ 01002 while((((filter0Instance->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1U) == 0U) 01003 { 01004 /* Check the Timeout */ 01005 if(Timeout != HAL_MAX_DELAY) 01006 { 01007 if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout)) 01008 { 01009 /* Return timeout status */ 01010 return HAL_TIMEOUT; 01011 } 01012 } 01013 } 01014 01015 /* Clear clock absence detection flag */ 01016 filter0Instance->FLTICR = (1U << (DFSDM_FLTICR_CLRCKABF_Pos + channel)); 01017 #else 01018 /* Get channel number from channel instance */ 01019 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance); 01020 01021 /* Get timeout */ 01022 tickstart = HAL_GetTick(); 01023 01024 /* Wait clock absence detection */ 01025 while((((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1U) == 0U) 01026 { 01027 /* Check the Timeout */ 01028 if(Timeout != HAL_MAX_DELAY) 01029 { 01030 if(((HAL_GetTick()-tickstart) > Timeout) || (Timeout == 0U)) 01031 { 01032 /* Return timeout status */ 01033 return HAL_TIMEOUT; 01034 } 01035 } 01036 } 01037 01038 /* Clear clock absence detection flag */ 01039 DFSDM1_Filter0->FLTICR = (1U << (DFSDM_FLTICR_CLRCKABF_Pos + channel)); 01040 #endif /* defined(DFSDM2_Channel0) */ 01041 /* Return function status */ 01042 return HAL_OK; 01043 } 01044 } 01045 01046 /** 01047 * @brief This function allows to stop clock absence detection in polling mode. 01048 * @param hdfsdm_channel DFSDM channel handle. 01049 * @retval HAL status 01050 */ 01051 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStop(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 01052 { 01053 HAL_StatusTypeDef status = HAL_OK; 01054 uint32_t channel; 01055 #if defined(DFSDM2_Channel0) 01056 DFSDM_Filter_TypeDef* filter0Instance; 01057 #endif /* defined(DFSDM2_Channel0) */ 01058 01059 /* Check parameters */ 01060 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance)); 01061 01062 /* Check DFSDM channel state */ 01063 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY) 01064 { 01065 /* Return error status */ 01066 status = HAL_ERROR; 01067 } 01068 else 01069 { 01070 #if defined(DFSDM2_Channel0) 01071 01072 /* Get channel counter, channel handle table and channel 0 instance */ 01073 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance)) 01074 { 01075 filter0Instance = DFSDM1_Filter0; 01076 } 01077 else 01078 { 01079 filter0Instance = DFSDM2_Filter0; 01080 } 01081 01082 /* Stop clock absence detection */ 01083 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKABEN); 01084 01085 /* Clear clock absence flag */ 01086 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance); 01087 filter0Instance->FLTICR = (1U << (DFSDM_FLTICR_CLRCKABF_Pos + channel)); 01088 01089 #else 01090 /* Stop clock absence detection */ 01091 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKABEN); 01092 01093 /* Clear clock absence flag */ 01094 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance); 01095 DFSDM1_Filter0->FLTICR = (1U << (DFSDM_FLTICR_CLRCKABF_Pos + channel)); 01096 #endif /* DFSDM2_Channel0 */ 01097 } 01098 /* Return function status */ 01099 return status; 01100 } 01101 01102 /** 01103 * @brief This function allows to start clock absence detection in interrupt mode. 01104 * @note Same mode has to be used for all channels. 01105 * @note If clock is not available on this channel during 5 seconds, 01106 * clock absence detection will not be activated and function 01107 * will return HAL_TIMEOUT error. 01108 * @param hdfsdm_channel DFSDM channel handle. 01109 * @retval HAL status 01110 */ 01111 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStart_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 01112 { 01113 HAL_StatusTypeDef status = HAL_OK; 01114 uint32_t channel; 01115 uint32_t tickstart; 01116 #if defined(DFSDM2_Channel0) 01117 DFSDM_Filter_TypeDef* filter0Instance; 01118 #endif /* defined(DFSDM2_Channel0) */ 01119 01120 /* Check parameters */ 01121 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance)); 01122 01123 /* Check DFSDM channel state */ 01124 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY) 01125 { 01126 /* Return error status */ 01127 status = HAL_ERROR; 01128 } 01129 else 01130 { 01131 #if defined(DFSDM2_Channel0) 01132 01133 /* Get channel counter, channel handle table and channel 0 instance */ 01134 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance)) 01135 { 01136 filter0Instance = DFSDM1_Filter0; 01137 } 01138 else 01139 { 01140 filter0Instance = DFSDM2_Filter0; 01141 } 01142 01143 /* Get channel number from channel instance */ 01144 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance); 01145 01146 /* Get timeout */ 01147 tickstart = HAL_GetTick(); 01148 01149 /* Clear clock absence flag */ 01150 while((((filter0Instance->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1U) != 0U) 01151 { 01152 filter0Instance->FLTICR = (1U << (DFSDM_FLTICR_CLRCKABF_Pos + channel)); 01153 01154 /* Check the Timeout */ 01155 if((HAL_GetTick()-tickstart) > DFSDM_CKAB_TIMEOUT) 01156 { 01157 /* Set timeout status */ 01158 status = HAL_TIMEOUT; 01159 break; 01160 } 01161 } 01162 01163 if(status == HAL_OK) 01164 { 01165 /* Activate clock absence detection interrupt */ 01166 filter0Instance->FLTCR2 |= DFSDM_FLTCR2_CKABIE; 01167 01168 /* Start clock absence detection */ 01169 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CKABEN; 01170 } 01171 #else 01172 /* Get channel number from channel instance */ 01173 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance); 01174 01175 /* Get timeout */ 01176 tickstart = HAL_GetTick(); 01177 01178 /* Clear clock absence flag */ 01179 while((((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1U) != 0U) 01180 { 01181 DFSDM1_Filter0->FLTICR = (1U << (DFSDM_FLTICR_CLRCKABF_Pos + channel)); 01182 01183 /* Check the Timeout */ 01184 if((HAL_GetTick()-tickstart) > DFSDM_CKAB_TIMEOUT) 01185 { 01186 /* Set timeout status */ 01187 status = HAL_TIMEOUT; 01188 break; 01189 } 01190 } 01191 01192 if(status == HAL_OK) 01193 { 01194 /* Activate clock absence detection interrupt */ 01195 DFSDM1_Filter0->FLTCR2 |= DFSDM_FLTCR2_CKABIE; 01196 01197 /* Start clock absence detection */ 01198 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CKABEN; 01199 } 01200 01201 #endif /* defined(DFSDM2_Channel0) */ 01202 } 01203 /* Return function status */ 01204 return status; 01205 } 01206 01207 /** 01208 * @brief Clock absence detection callback. 01209 * @param hdfsdm_channel DFSDM channel handle. 01210 * @retval None 01211 */ 01212 __weak void HAL_DFSDM_ChannelCkabCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 01213 { 01214 /* Prevent unused argument(s) compilation warning */ 01215 UNUSED(hdfsdm_channel); 01216 /* NOTE : This function should not be modified, when the callback is needed, 01217 the HAL_DFSDM_ChannelCkabCallback could be implemented in the user file 01218 */ 01219 } 01220 01221 /** 01222 * @brief This function allows to stop clock absence detection in interrupt mode. 01223 * @note Interrupt will be disabled for all channels 01224 * @param hdfsdm_channel DFSDM channel handle. 01225 * @retval HAL status 01226 */ 01227 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStop_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 01228 { 01229 HAL_StatusTypeDef status = HAL_OK; 01230 uint32_t channel; 01231 #if defined(DFSDM2_Channel0) 01232 DFSDM_Filter_TypeDef* filter0Instance; 01233 #endif /* defined(DFSDM2_Channel0) */ 01234 01235 /* Check parameters */ 01236 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance)); 01237 01238 /* Check DFSDM channel state */ 01239 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY) 01240 { 01241 /* Return error status */ 01242 status = HAL_ERROR; 01243 } 01244 else 01245 { 01246 #if defined(DFSDM2_Channel0) 01247 01248 /* Get channel counter, channel handle table and channel 0 instance */ 01249 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance)) 01250 { 01251 filter0Instance = DFSDM1_Filter0; 01252 } 01253 else 01254 { 01255 filter0Instance = DFSDM2_Filter0; 01256 } 01257 01258 /* Stop clock absence detection */ 01259 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKABEN); 01260 01261 /* Clear clock absence flag */ 01262 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance); 01263 filter0Instance->FLTICR = (1U << (DFSDM_FLTICR_CLRCKABF_Pos + channel)); 01264 01265 /* Disable clock absence detection interrupt */ 01266 filter0Instance->FLTCR2 &= ~(DFSDM_FLTCR2_CKABIE); 01267 #else 01268 01269 /* Stop clock absence detection */ 01270 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKABEN); 01271 01272 /* Clear clock absence flag */ 01273 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance); 01274 DFSDM1_Filter0->FLTICR = (1U << (DFSDM_FLTICR_CLRCKABF_Pos + channel)); 01275 01276 /* Disable clock absence detection interrupt */ 01277 DFSDM1_Filter0->FLTCR2 &= ~(DFSDM_FLTCR2_CKABIE); 01278 #endif /* DFSDM2_Channel0 */ 01279 } 01280 01281 /* Return function status */ 01282 return status; 01283 } 01284 01285 /** 01286 * @brief This function allows to start short circuit detection in polling mode. 01287 * @note Same mode has to be used for all channels 01288 * @param hdfsdm_channel DFSDM channel handle. 01289 * @param Threshold Short circuit detector threshold. 01290 * This parameter must be a number between Min_Data = 0 and Max_Data = 255. 01291 * @param BreakSignal Break signals assigned to short circuit event. 01292 * This parameter can be a values combination of @ref DFSDM_BreakSignals. 01293 * @retval HAL status 01294 */ 01295 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStart(DFSDM_Channel_HandleTypeDef *hdfsdm_channel, 01296 uint32_t Threshold, 01297 uint32_t BreakSignal) 01298 { 01299 HAL_StatusTypeDef status = HAL_OK; 01300 01301 /* Check parameters */ 01302 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance)); 01303 assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold)); 01304 assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal)); 01305 01306 /* Check DFSDM channel state */ 01307 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY) 01308 { 01309 /* Return error status */ 01310 status = HAL_ERROR; 01311 } 01312 else 01313 { 01314 /* Configure threshold and break signals */ 01315 hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_BKSCD | DFSDM_CHAWSCDR_SCDT); 01316 hdfsdm_channel->Instance->CHAWSCDR |= ((BreakSignal << DFSDM_CHAWSCDR_BKSCD_Pos) | \ 01317 Threshold); 01318 01319 /* Start short circuit detection */ 01320 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_SCDEN; 01321 } 01322 /* Return function status */ 01323 return status; 01324 } 01325 01326 /** 01327 * @brief This function allows to poll for the short circuit detection. 01328 * @param hdfsdm_channel DFSDM channel handle. 01329 * @param Timeout Timeout value in milliseconds. 01330 * @retval HAL status 01331 */ 01332 HAL_StatusTypeDef HAL_DFSDM_ChannelPollForScd(DFSDM_Channel_HandleTypeDef *hdfsdm_channel, 01333 uint32_t Timeout) 01334 { 01335 uint32_t tickstart; 01336 uint32_t channel; 01337 #if defined(DFSDM2_Channel0) 01338 DFSDM_Filter_TypeDef* filter0Instance; 01339 #endif /* defined(DFSDM2_Channel0) */ 01340 01341 /* Check parameters */ 01342 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance)); 01343 01344 /* Check DFSDM channel state */ 01345 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY) 01346 { 01347 /* Return error status */ 01348 return HAL_ERROR; 01349 } 01350 else 01351 { 01352 /* Get channel number from channel instance */ 01353 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance); 01354 01355 #if defined(DFSDM2_Channel0) 01356 /* Get channel counter, channel handle table and channel 0 instance */ 01357 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance)) 01358 { 01359 filter0Instance = DFSDM1_Filter0; 01360 } 01361 else 01362 { 01363 filter0Instance = DFSDM2_Filter0; 01364 } 01365 01366 /* Get timeout */ 01367 tickstart = HAL_GetTick(); 01368 01369 /* Wait short circuit detection */ 01370 while(((filter0Instance->FLTISR & DFSDM_FLTISR_SCDF) >> (DFSDM_FLTISR_SCDF_Pos + channel)) == 0U) 01371 { 01372 /* Check the Timeout */ 01373 if(Timeout != HAL_MAX_DELAY) 01374 { 01375 if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout)) 01376 { 01377 /* Return timeout status */ 01378 return HAL_TIMEOUT; 01379 } 01380 } 01381 } 01382 01383 /* Clear short circuit detection flag */ 01384 filter0Instance->FLTICR = (1U << (DFSDM_FLTICR_CLRSCDF_Pos + channel)); 01385 01386 #else 01387 /* Get timeout */ 01388 tickstart = HAL_GetTick(); 01389 01390 /* Wait short circuit detection */ 01391 while(((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_SCDF) >> (DFSDM_FLTISR_SCDF_Pos + channel)) == 0U) 01392 { 01393 /* Check the Timeout */ 01394 if(Timeout != HAL_MAX_DELAY) 01395 { 01396 if(((HAL_GetTick()-tickstart) > Timeout) || (Timeout == 0U)) 01397 { 01398 /* Return timeout status */ 01399 return HAL_TIMEOUT; 01400 } 01401 } 01402 } 01403 01404 /* Clear short circuit detection flag */ 01405 DFSDM1_Filter0->FLTICR = (1U << (DFSDM_FLTICR_CLRSCDF_Pos + channel)); 01406 #endif /* DFSDM2_Channel0 */ 01407 01408 /* Return function status */ 01409 return HAL_OK; 01410 } 01411 } 01412 01413 /** 01414 * @brief This function allows to stop short circuit detection in polling mode. 01415 * @param hdfsdm_channel DFSDM channel handle. 01416 * @retval HAL status 01417 */ 01418 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStop(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 01419 { 01420 HAL_StatusTypeDef status = HAL_OK; 01421 uint32_t channel; 01422 #if defined(DFSDM2_Channel0) 01423 DFSDM_Filter_TypeDef* filter0Instance; 01424 #endif /* defined(DFSDM2_Channel0) */ 01425 01426 /* Check parameters */ 01427 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance)); 01428 01429 /* Check DFSDM channel state */ 01430 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY) 01431 { 01432 /* Return error status */ 01433 status = HAL_ERROR; 01434 } 01435 else 01436 { 01437 /* Stop short circuit detection */ 01438 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SCDEN); 01439 01440 /* Clear short circuit detection flag */ 01441 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance); 01442 01443 #if defined(DFSDM2_Channel0) 01444 /* Get channel counter, channel handle table and channel 0 instance */ 01445 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance)) 01446 { 01447 filter0Instance = DFSDM1_Filter0; 01448 } 01449 else 01450 { 01451 filter0Instance = DFSDM2_Filter0; 01452 } 01453 01454 filter0Instance->FLTICR = (1U << (DFSDM_FLTICR_CLRSCDF_Pos + channel)); 01455 #else 01456 DFSDM1_Filter0->FLTICR = (1U << (DFSDM_FLTICR_CLRSCDF_Pos + channel)); 01457 #endif /* DFSDM2_Channel0*/ 01458 } 01459 /* Return function status */ 01460 return status; 01461 } 01462 01463 /** 01464 * @brief This function allows to start short circuit detection in interrupt mode. 01465 * @note Same mode has to be used for all channels 01466 * @param hdfsdm_channel DFSDM channel handle. 01467 * @param Threshold Short circuit detector threshold. 01468 * This parameter must be a number between Min_Data = 0 and Max_Data = 255. 01469 * @param BreakSignal Break signals assigned to short circuit event. 01470 * This parameter can be a values combination of @ref DFSDM_BreakSignals. 01471 * @retval HAL status 01472 */ 01473 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStart_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel, 01474 uint32_t Threshold, 01475 uint32_t BreakSignal) 01476 { 01477 HAL_StatusTypeDef status = HAL_OK; 01478 #if defined(DFSDM2_Channel0) 01479 DFSDM_Filter_TypeDef* filter0Instance; 01480 #endif /* defined(DFSDM2_Channel0) */ 01481 01482 /* Check parameters */ 01483 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance)); 01484 assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold)); 01485 assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal)); 01486 01487 /* Check DFSDM channel state */ 01488 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY) 01489 { 01490 /* Return error status */ 01491 status = HAL_ERROR; 01492 } 01493 else 01494 { 01495 #if defined(DFSDM2_Channel0) 01496 /* Get channel counter, channel handle table and channel 0 instance */ 01497 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance)) 01498 { 01499 filter0Instance = DFSDM1_Filter0; 01500 } 01501 else 01502 { 01503 filter0Instance = DFSDM2_Filter0; 01504 } 01505 /* Activate short circuit detection interrupt */ 01506 filter0Instance->FLTCR2 |= DFSDM_FLTCR2_SCDIE; 01507 #else 01508 /* Activate short circuit detection interrupt */ 01509 DFSDM1_Filter0->FLTCR2 |= DFSDM_FLTCR2_SCDIE; 01510 #endif /* DFSDM2_Channel0 */ 01511 01512 /* Configure threshold and break signals */ 01513 hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_BKSCD | DFSDM_CHAWSCDR_SCDT); 01514 hdfsdm_channel->Instance->CHAWSCDR |= ((BreakSignal << DFSDM_CHAWSCDR_BKSCD_Pos) | \ 01515 Threshold); 01516 01517 /* Start short circuit detection */ 01518 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_SCDEN; 01519 } 01520 /* Return function status */ 01521 return status; 01522 } 01523 01524 /** 01525 * @brief Short circuit detection callback. 01526 * @param hdfsdm_channel DFSDM channel handle. 01527 * @retval None 01528 */ 01529 __weak void HAL_DFSDM_ChannelScdCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 01530 { 01531 /* Prevent unused argument(s) compilation warning */ 01532 UNUSED(hdfsdm_channel); 01533 /* NOTE : This function should not be modified, when the callback is needed, 01534 the HAL_DFSDM_ChannelScdCallback could be implemented in the user file 01535 */ 01536 } 01537 01538 /** 01539 * @brief This function allows to stop short circuit detection in interrupt mode. 01540 * @note Interrupt will be disabled for all channels 01541 * @param hdfsdm_channel DFSDM channel handle. 01542 * @retval HAL status 01543 */ 01544 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStop_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 01545 { 01546 HAL_StatusTypeDef status = HAL_OK; 01547 uint32_t channel; 01548 #if defined(DFSDM2_Channel0) 01549 DFSDM_Filter_TypeDef* filter0Instance; 01550 #endif /* defined(DFSDM2_Channel0) */ 01551 01552 /* Check parameters */ 01553 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance)); 01554 01555 /* Check DFSDM channel state */ 01556 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY) 01557 { 01558 /* Return error status */ 01559 status = HAL_ERROR; 01560 } 01561 else 01562 { 01563 /* Stop short circuit detection */ 01564 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SCDEN); 01565 01566 /* Clear short circuit detection flag */ 01567 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance); 01568 #if defined(DFSDM2_Channel0) 01569 /* Get channel counter, channel handle table and channel 0 instance */ 01570 if(IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance)) 01571 { 01572 filter0Instance = DFSDM1_Filter0; 01573 } 01574 else 01575 { 01576 filter0Instance = DFSDM2_Filter0; 01577 } 01578 01579 filter0Instance->FLTICR = (1U << (DFSDM_FLTICR_CLRSCDF_Pos + channel)); 01580 01581 /* Disable short circuit detection interrupt */ 01582 filter0Instance->FLTCR2 &= ~(DFSDM_FLTCR2_SCDIE); 01583 #else 01584 DFSDM1_Filter0->FLTICR = (1U << (DFSDM_FLTICR_CLRSCDF_Pos + channel)); 01585 01586 /* Disable short circuit detection interrupt */ 01587 DFSDM1_Filter0->FLTCR2 &= ~(DFSDM_FLTCR2_SCDIE); 01588 #endif /* DFSDM2_Channel0 */ 01589 } 01590 /* Return function status */ 01591 return status; 01592 } 01593 01594 /** 01595 * @brief This function allows to get channel analog watchdog value. 01596 * @param hdfsdm_channel DFSDM channel handle. 01597 * @retval Channel analog watchdog value. 01598 */ 01599 int16_t HAL_DFSDM_ChannelGetAwdValue(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 01600 { 01601 return (int16_t) hdfsdm_channel->Instance->CHWDATAR; 01602 } 01603 01604 /** 01605 * @brief This function allows to modify channel offset value. 01606 * @param hdfsdm_channel DFSDM channel handle. 01607 * @param Offset DFSDM channel offset. 01608 * This parameter must be a number between Min_Data = -8388608 and Max_Data = 8388607. 01609 * @retval HAL status. 01610 */ 01611 HAL_StatusTypeDef HAL_DFSDM_ChannelModifyOffset(DFSDM_Channel_HandleTypeDef *hdfsdm_channel, 01612 int32_t Offset) 01613 { 01614 HAL_StatusTypeDef status = HAL_OK; 01615 01616 /* Check parameters */ 01617 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance)); 01618 assert_param(IS_DFSDM_CHANNEL_OFFSET(Offset)); 01619 01620 /* Check DFSDM channel state */ 01621 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY) 01622 { 01623 /* Return error status */ 01624 status = HAL_ERROR; 01625 } 01626 else 01627 { 01628 /* Modify channel offset */ 01629 hdfsdm_channel->Instance->CHCFGR2 &= ~(DFSDM_CHCFGR2_OFFSET); 01630 hdfsdm_channel->Instance->CHCFGR2 |= ((uint32_t) Offset << DFSDM_CHCFGR2_OFFSET_Pos); 01631 } 01632 /* Return function status */ 01633 return status; 01634 } 01635 01636 /** 01637 * @} 01638 */ 01639 01640 /** @defgroup DFSDM_Exported_Functions_Group3_Channel Channel state function 01641 * @brief Channel state function 01642 * 01643 @verbatim 01644 ============================================================================== 01645 ##### Channel state function ##### 01646 ============================================================================== 01647 [..] This section provides function allowing to: 01648 (+) Get channel handle state. 01649 @endverbatim 01650 * @{ 01651 */ 01652 01653 /** 01654 * @brief This function allows to get the current DFSDM channel handle state. 01655 * @param hdfsdm_channel DFSDM channel handle. 01656 * @retval DFSDM channel state. 01657 */ 01658 HAL_DFSDM_Channel_StateTypeDef HAL_DFSDM_ChannelGetState(DFSDM_Channel_HandleTypeDef *hdfsdm_channel) 01659 { 01660 /* Return DFSDM channel handle state */ 01661 return hdfsdm_channel->State; 01662 } 01663 01664 /** 01665 * @} 01666 */ 01667 01668 /** @defgroup DFSDM_Exported_Functions_Group1_Filter Filter initialization and de-initialization functions 01669 * @brief Filter initialization and de-initialization functions 01670 * 01671 @verbatim 01672 ============================================================================== 01673 ##### Filter initialization and de-initialization functions ##### 01674 ============================================================================== 01675 [..] This section provides functions allowing to: 01676 (+) Initialize the DFSDM filter. 01677 (+) De-initialize the DFSDM filter. 01678 @endverbatim 01679 * @{ 01680 */ 01681 01682 /** 01683 * @brief Initialize the DFSDM filter according to the specified parameters 01684 * in the DFSDM_FilterInitTypeDef structure and initialize the associated handle. 01685 * @param hdfsdm_filter DFSDM filter handle. 01686 * @retval HAL status. 01687 */ 01688 HAL_StatusTypeDef HAL_DFSDM_FilterInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 01689 { 01690 /* Check DFSDM Channel handle */ 01691 if(hdfsdm_filter == NULL) 01692 { 01693 return HAL_ERROR; 01694 } 01695 01696 /* Check parameters */ 01697 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 01698 assert_param(IS_DFSDM_FILTER_REG_TRIGGER(hdfsdm_filter->Init.RegularParam.Trigger)); 01699 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.RegularParam.FastMode)); 01700 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.RegularParam.DmaMode)); 01701 assert_param(IS_DFSDM_FILTER_INJ_TRIGGER(hdfsdm_filter->Init.InjectedParam.Trigger)); 01702 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.InjectedParam.ScanMode)); 01703 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.InjectedParam.DmaMode)); 01704 assert_param(IS_DFSDM_FILTER_SINC_ORDER(hdfsdm_filter->Init.FilterParam.SincOrder)); 01705 assert_param(IS_DFSDM_FILTER_OVS_RATIO(hdfsdm_filter->Init.FilterParam.Oversampling)); 01706 assert_param(IS_DFSDM_FILTER_INTEGRATOR_OVS_RATIO(hdfsdm_filter->Init.FilterParam.IntOversampling)); 01707 01708 /* Check parameters compatibility */ 01709 if((hdfsdm_filter->Instance == DFSDM1_Filter0) && 01710 ((hdfsdm_filter->Init.RegularParam.Trigger == DFSDM_FILTER_SYNC_TRIGGER) || 01711 (hdfsdm_filter->Init.InjectedParam.Trigger == DFSDM_FILTER_SYNC_TRIGGER))) 01712 { 01713 return HAL_ERROR; 01714 } 01715 #if defined (DFSDM2_Channel0) 01716 if((hdfsdm_filter->Instance == DFSDM2_Filter0) && 01717 ((hdfsdm_filter->Init.RegularParam.Trigger == DFSDM_FILTER_SYNC_TRIGGER) || 01718 (hdfsdm_filter->Init.InjectedParam.Trigger == DFSDM_FILTER_SYNC_TRIGGER))) 01719 { 01720 return HAL_ERROR; 01721 } 01722 #endif /* DFSDM2_Channel0 */ 01723 01724 /* Initialize DFSDM filter variables with default values */ 01725 hdfsdm_filter->RegularContMode = DFSDM_CONTINUOUS_CONV_OFF; 01726 hdfsdm_filter->InjectedChannelsNbr = 1U; 01727 hdfsdm_filter->InjConvRemaining = 1U; 01728 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_NONE; 01729 01730 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 01731 /* Reset callback pointers to the weak predefined callbacks */ 01732 hdfsdm_filter->AwdCallback = HAL_DFSDM_FilterAwdCallback; 01733 hdfsdm_filter->RegConvCpltCallback = HAL_DFSDM_FilterRegConvCpltCallback; 01734 hdfsdm_filter->RegConvHalfCpltCallback = HAL_DFSDM_FilterRegConvHalfCpltCallback; 01735 hdfsdm_filter->InjConvCpltCallback = HAL_DFSDM_FilterInjConvCpltCallback; 01736 hdfsdm_filter->InjConvHalfCpltCallback = HAL_DFSDM_FilterInjConvHalfCpltCallback; 01737 hdfsdm_filter->ErrorCallback = HAL_DFSDM_FilterErrorCallback; 01738 01739 /* Call MSP init function */ 01740 if(hdfsdm_filter->MspInitCallback == NULL) 01741 { 01742 hdfsdm_filter->MspInitCallback = HAL_DFSDM_FilterMspInit; 01743 } 01744 hdfsdm_filter->MspInitCallback(hdfsdm_filter); 01745 #else 01746 /* Call MSP init function */ 01747 HAL_DFSDM_FilterMspInit(hdfsdm_filter); 01748 #endif 01749 01750 /* Set regular parameters */ 01751 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RSYNC); 01752 if(hdfsdm_filter->Init.RegularParam.FastMode == ENABLE) 01753 { 01754 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_FAST; 01755 } 01756 else 01757 { 01758 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_FAST); 01759 } 01760 01761 if(hdfsdm_filter->Init.RegularParam.DmaMode == ENABLE) 01762 { 01763 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RDMAEN; 01764 } 01765 else 01766 { 01767 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RDMAEN); 01768 } 01769 01770 /* Set injected parameters */ 01771 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSYNC | DFSDM_FLTCR1_JEXTEN | DFSDM_FLTCR1_JEXTSEL); 01772 if(hdfsdm_filter->Init.InjectedParam.Trigger == DFSDM_FILTER_EXT_TRIGGER) 01773 { 01774 assert_param(IS_DFSDM_FILTER_EXT_TRIG(hdfsdm_filter->Init.InjectedParam.ExtTrigger)); 01775 assert_param(IS_DFSDM_FILTER_EXT_TRIG_EDGE(hdfsdm_filter->Init.InjectedParam.ExtTriggerEdge)); 01776 hdfsdm_filter->Instance->FLTCR1 |= (hdfsdm_filter->Init.InjectedParam.ExtTrigger); 01777 } 01778 01779 if(hdfsdm_filter->Init.InjectedParam.ScanMode == ENABLE) 01780 { 01781 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSCAN; 01782 } 01783 else 01784 { 01785 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSCAN); 01786 } 01787 01788 if(hdfsdm_filter->Init.InjectedParam.DmaMode == ENABLE) 01789 { 01790 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JDMAEN; 01791 } 01792 else 01793 { 01794 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JDMAEN); 01795 } 01796 01797 /* Set filter parameters */ 01798 hdfsdm_filter->Instance->FLTFCR &= ~(DFSDM_FLTFCR_FORD | DFSDM_FLTFCR_FOSR | DFSDM_FLTFCR_IOSR); 01799 hdfsdm_filter->Instance->FLTFCR |= (hdfsdm_filter->Init.FilterParam.SincOrder | 01800 ((hdfsdm_filter->Init.FilterParam.Oversampling - 1U) << DFSDM_FLTFCR_FOSR_Pos) | 01801 (hdfsdm_filter->Init.FilterParam.IntOversampling - 1U)); 01802 01803 /* Store regular and injected triggers and injected scan mode*/ 01804 hdfsdm_filter->RegularTrigger = hdfsdm_filter->Init.RegularParam.Trigger; 01805 hdfsdm_filter->InjectedTrigger = hdfsdm_filter->Init.InjectedParam.Trigger; 01806 hdfsdm_filter->ExtTriggerEdge = hdfsdm_filter->Init.InjectedParam.ExtTriggerEdge; 01807 hdfsdm_filter->InjectedScanMode = hdfsdm_filter->Init.InjectedParam.ScanMode; 01808 01809 /* Enable DFSDM filter */ 01810 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN; 01811 01812 /* Set DFSDM filter to ready state */ 01813 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_READY; 01814 01815 return HAL_OK; 01816 } 01817 01818 /** 01819 * @brief De-initializes the DFSDM filter. 01820 * @param hdfsdm_filter DFSDM filter handle. 01821 * @retval HAL status. 01822 */ 01823 HAL_StatusTypeDef HAL_DFSDM_FilterDeInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 01824 { 01825 /* Check DFSDM filter handle */ 01826 if(hdfsdm_filter == NULL) 01827 { 01828 return HAL_ERROR; 01829 } 01830 01831 /* Check parameters */ 01832 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 01833 01834 /* Disable the DFSDM filter */ 01835 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN); 01836 01837 /* Call MSP deinit function */ 01838 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 01839 if(hdfsdm_filter->MspDeInitCallback == NULL) 01840 { 01841 hdfsdm_filter->MspDeInitCallback = HAL_DFSDM_FilterMspDeInit; 01842 } 01843 hdfsdm_filter->MspDeInitCallback(hdfsdm_filter); 01844 #else 01845 HAL_DFSDM_FilterMspDeInit(hdfsdm_filter); 01846 #endif 01847 01848 /* Set DFSDM filter in reset state */ 01849 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_RESET; 01850 01851 return HAL_OK; 01852 } 01853 01854 /** 01855 * @brief Initializes the DFSDM filter MSP. 01856 * @param hdfsdm_filter DFSDM filter handle. 01857 * @retval None 01858 */ 01859 __weak void HAL_DFSDM_FilterMspInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 01860 { 01861 /* Prevent unused argument(s) compilation warning */ 01862 UNUSED(hdfsdm_filter); 01863 /* NOTE : This function should not be modified, when the function is needed, 01864 the HAL_DFSDM_FilterMspInit could be implemented in the user file. 01865 */ 01866 } 01867 01868 /** 01869 * @brief De-initializes the DFSDM filter MSP. 01870 * @param hdfsdm_filter DFSDM filter handle. 01871 * @retval None 01872 */ 01873 __weak void HAL_DFSDM_FilterMspDeInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 01874 { 01875 /* Prevent unused argument(s) compilation warning */ 01876 UNUSED(hdfsdm_filter); 01877 /* NOTE : This function should not be modified, when the function is needed, 01878 the HAL_DFSDM_FilterMspDeInit could be implemented in the user file. 01879 */ 01880 } 01881 01882 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 01883 /** 01884 * @brief Register a user DFSDM filter callback 01885 * to be used instead of the weak predefined callback. 01886 * @param hdfsdm_filter DFSDM filter handle. 01887 * @param CallbackID ID of the callback to be registered. 01888 * This parameter can be one of the following values: 01889 * @arg @ref HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID regular conversion complete callback ID. 01890 * @arg @ref HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID half regular conversion complete callback ID. 01891 * @arg @ref HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID injected conversion complete callback ID. 01892 * @arg @ref HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID half injected conversion complete callback ID. 01893 * @arg @ref HAL_DFSDM_FILTER_ERROR_CB_ID error callback ID. 01894 * @arg @ref HAL_DFSDM_FILTER_MSPINIT_CB_ID MSP init callback ID. 01895 * @arg @ref HAL_DFSDM_FILTER_MSPDEINIT_CB_ID MSP de-init callback ID. 01896 * @param pCallback pointer to the callback function. 01897 * @retval HAL status. 01898 */ 01899 HAL_StatusTypeDef HAL_DFSDM_Filter_RegisterCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 01900 HAL_DFSDM_Filter_CallbackIDTypeDef CallbackID, 01901 pDFSDM_Filter_CallbackTypeDef pCallback) 01902 { 01903 HAL_StatusTypeDef status = HAL_OK; 01904 01905 if(pCallback == NULL) 01906 { 01907 /* update the error code */ 01908 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK; 01909 /* update return status */ 01910 status = HAL_ERROR; 01911 } 01912 else 01913 { 01914 if(HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State) 01915 { 01916 switch (CallbackID) 01917 { 01918 case HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID : 01919 hdfsdm_filter->RegConvCpltCallback = pCallback; 01920 break; 01921 case HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID : 01922 hdfsdm_filter->RegConvHalfCpltCallback = pCallback; 01923 break; 01924 case HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID : 01925 hdfsdm_filter->InjConvCpltCallback = pCallback; 01926 break; 01927 case HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID : 01928 hdfsdm_filter->InjConvHalfCpltCallback = pCallback; 01929 break; 01930 case HAL_DFSDM_FILTER_ERROR_CB_ID : 01931 hdfsdm_filter->ErrorCallback = pCallback; 01932 break; 01933 case HAL_DFSDM_FILTER_MSPINIT_CB_ID : 01934 hdfsdm_filter->MspInitCallback = pCallback; 01935 break; 01936 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID : 01937 hdfsdm_filter->MspDeInitCallback = pCallback; 01938 break; 01939 default : 01940 /* update the error code */ 01941 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK; 01942 /* update return status */ 01943 status = HAL_ERROR; 01944 break; 01945 } 01946 } 01947 else if(HAL_DFSDM_FILTER_STATE_RESET == hdfsdm_filter->State) 01948 { 01949 switch (CallbackID) 01950 { 01951 case HAL_DFSDM_FILTER_MSPINIT_CB_ID : 01952 hdfsdm_filter->MspInitCallback = pCallback; 01953 break; 01954 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID : 01955 hdfsdm_filter->MspDeInitCallback = pCallback; 01956 break; 01957 default : 01958 /* update the error code */ 01959 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK; 01960 /* update return status */ 01961 status = HAL_ERROR; 01962 break; 01963 } 01964 } 01965 else 01966 { 01967 /* update the error code */ 01968 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK; 01969 /* update return status */ 01970 status = HAL_ERROR; 01971 } 01972 } 01973 return status; 01974 } 01975 01976 /** 01977 * @brief Unregister a user DFSDM filter callback. 01978 * DFSDM filter callback is redirected to the weak predefined callback. 01979 * @param hdfsdm_filter DFSDM filter handle. 01980 * @param CallbackID ID of the callback to be unregistered. 01981 * This parameter can be one of the following values: 01982 * @arg @ref HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID regular conversion complete callback ID. 01983 * @arg @ref HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID half regular conversion complete callback ID. 01984 * @arg @ref HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID injected conversion complete callback ID. 01985 * @arg @ref HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID half injected conversion complete callback ID. 01986 * @arg @ref HAL_DFSDM_FILTER_ERROR_CB_ID error callback ID. 01987 * @arg @ref HAL_DFSDM_FILTER_MSPINIT_CB_ID MSP init callback ID. 01988 * @arg @ref HAL_DFSDM_FILTER_MSPDEINIT_CB_ID MSP de-init callback ID. 01989 * @retval HAL status. 01990 */ 01991 HAL_StatusTypeDef HAL_DFSDM_Filter_UnRegisterCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 01992 HAL_DFSDM_Filter_CallbackIDTypeDef CallbackID) 01993 { 01994 HAL_StatusTypeDef status = HAL_OK; 01995 01996 if(HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State) 01997 { 01998 switch (CallbackID) 01999 { 02000 case HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID : 02001 hdfsdm_filter->RegConvCpltCallback = HAL_DFSDM_FilterRegConvCpltCallback; 02002 break; 02003 case HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID : 02004 hdfsdm_filter->RegConvHalfCpltCallback = HAL_DFSDM_FilterRegConvHalfCpltCallback; 02005 break; 02006 case HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID : 02007 hdfsdm_filter->InjConvCpltCallback = HAL_DFSDM_FilterInjConvCpltCallback; 02008 break; 02009 case HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID : 02010 hdfsdm_filter->InjConvHalfCpltCallback = HAL_DFSDM_FilterInjConvHalfCpltCallback; 02011 break; 02012 case HAL_DFSDM_FILTER_ERROR_CB_ID : 02013 hdfsdm_filter->ErrorCallback = HAL_DFSDM_FilterErrorCallback; 02014 break; 02015 case HAL_DFSDM_FILTER_MSPINIT_CB_ID : 02016 hdfsdm_filter->MspInitCallback = HAL_DFSDM_FilterMspInit; 02017 break; 02018 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID : 02019 hdfsdm_filter->MspDeInitCallback = HAL_DFSDM_FilterMspDeInit; 02020 break; 02021 default : 02022 /* update the error code */ 02023 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK; 02024 /* update return status */ 02025 status = HAL_ERROR; 02026 break; 02027 } 02028 } 02029 else if(HAL_DFSDM_FILTER_STATE_RESET == hdfsdm_filter->State) 02030 { 02031 switch (CallbackID) 02032 { 02033 case HAL_DFSDM_FILTER_MSPINIT_CB_ID : 02034 hdfsdm_filter->MspInitCallback = HAL_DFSDM_FilterMspInit; 02035 break; 02036 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID : 02037 hdfsdm_filter->MspDeInitCallback = HAL_DFSDM_FilterMspDeInit; 02038 break; 02039 default : 02040 /* update the error code */ 02041 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK; 02042 /* update return status */ 02043 status = HAL_ERROR; 02044 break; 02045 } 02046 } 02047 else 02048 { 02049 /* update the error code */ 02050 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK; 02051 /* update return status */ 02052 status = HAL_ERROR; 02053 } 02054 return status; 02055 } 02056 02057 /** 02058 * @brief Register a user DFSDM filter analog watchdog callback 02059 * to be used instead of the weak predefined callback. 02060 * @param hdfsdm_filter DFSDM filter handle. 02061 * @param pCallback pointer to the DFSDM filter analog watchdog callback function. 02062 * @retval HAL status. 02063 */ 02064 HAL_StatusTypeDef HAL_DFSDM_Filter_RegisterAwdCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 02065 pDFSDM_Filter_AwdCallbackTypeDef pCallback) 02066 { 02067 HAL_StatusTypeDef status = HAL_OK; 02068 02069 if(pCallback == NULL) 02070 { 02071 /* update the error code */ 02072 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK; 02073 /* update return status */ 02074 status = HAL_ERROR; 02075 } 02076 else 02077 { 02078 if(HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State) 02079 { 02080 hdfsdm_filter->AwdCallback = pCallback; 02081 } 02082 else 02083 { 02084 /* update the error code */ 02085 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK; 02086 /* update return status */ 02087 status = HAL_ERROR; 02088 } 02089 } 02090 return status; 02091 } 02092 02093 /** 02094 * @brief Unregister a user DFSDM filter analog watchdog callback. 02095 * DFSDM filter AWD callback is redirected to the weak predefined callback. 02096 * @param hdfsdm_filter DFSDM filter handle. 02097 * @retval HAL status. 02098 */ 02099 HAL_StatusTypeDef HAL_DFSDM_Filter_UnRegisterAwdCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 02100 { 02101 HAL_StatusTypeDef status = HAL_OK; 02102 02103 if(HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State) 02104 { 02105 hdfsdm_filter->AwdCallback = HAL_DFSDM_FilterAwdCallback; 02106 } 02107 else 02108 { 02109 /* update the error code */ 02110 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK; 02111 /* update return status */ 02112 status = HAL_ERROR; 02113 } 02114 return status; 02115 } 02116 #endif /* USE_HAL_DFSDM_REGISTER_CALLBACKS */ 02117 /** 02118 * @} 02119 */ 02120 02121 /** @defgroup DFSDM_Exported_Functions_Group2_Filter Filter control functions 02122 * @brief Filter control functions 02123 * 02124 @verbatim 02125 ============================================================================== 02126 ##### Filter control functions ##### 02127 ============================================================================== 02128 [..] This section provides functions allowing to: 02129 (+) Select channel and enable/disable continuous mode for regular conversion. 02130 (+) Select channels for injected conversion. 02131 @endverbatim 02132 * @{ 02133 */ 02134 02135 /** 02136 * @brief This function allows to select channel and to enable/disable 02137 * continuous mode for regular conversion. 02138 * @param hdfsdm_filter DFSDM filter handle. 02139 * @param Channel Channel for regular conversion. 02140 * This parameter can be a value of @ref DFSDM_Channel_Selection. 02141 * @param ContinuousMode Enable/disable continuous mode for regular conversion. 02142 * This parameter can be a value of @ref DFSDM_ContinuousMode. 02143 * @retval HAL status 02144 */ 02145 HAL_StatusTypeDef HAL_DFSDM_FilterConfigRegChannel(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 02146 uint32_t Channel, 02147 uint32_t ContinuousMode) 02148 { 02149 HAL_StatusTypeDef status = HAL_OK; 02150 02151 /* Check parameters */ 02152 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02153 assert_param(IS_DFSDM_REGULAR_CHANNEL(Channel)); 02154 assert_param(IS_DFSDM_CONTINUOUS_MODE(ContinuousMode)); 02155 02156 /* Check DFSDM filter state */ 02157 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_RESET) && 02158 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_ERROR)) 02159 { 02160 /* Configure channel and continuous mode for regular conversion */ 02161 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RCH | DFSDM_FLTCR1_RCONT); 02162 if(ContinuousMode == DFSDM_CONTINUOUS_CONV_ON) 02163 { 02164 hdfsdm_filter->Instance->FLTCR1 |= (uint32_t) (((Channel & DFSDM_MSB_MASK) << DFSDM_FLTCR1_MSB_RCH_OFFSET) | 02165 DFSDM_FLTCR1_RCONT); 02166 } 02167 else 02168 { 02169 hdfsdm_filter->Instance->FLTCR1 |= (uint32_t) ((Channel & DFSDM_MSB_MASK) << DFSDM_FLTCR1_MSB_RCH_OFFSET); 02170 } 02171 /* Store continuous mode information */ 02172 hdfsdm_filter->RegularContMode = ContinuousMode; 02173 } 02174 else 02175 { 02176 status = HAL_ERROR; 02177 } 02178 02179 /* Return function status */ 02180 return status; 02181 } 02182 02183 /** 02184 * @brief This function allows to select channels for injected conversion. 02185 * @param hdfsdm_filter DFSDM filter handle. 02186 * @param Channel Channels for injected conversion. 02187 * This parameter can be a values combination of @ref DFSDM_Channel_Selection. 02188 * @retval HAL status 02189 */ 02190 HAL_StatusTypeDef HAL_DFSDM_FilterConfigInjChannel(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 02191 uint32_t Channel) 02192 { 02193 HAL_StatusTypeDef status = HAL_OK; 02194 02195 /* Check parameters */ 02196 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02197 assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel)); 02198 02199 /* Check DFSDM filter state */ 02200 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_RESET) && 02201 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_ERROR)) 02202 { 02203 /* Configure channel for injected conversion */ 02204 hdfsdm_filter->Instance->FLTJCHGR = (uint32_t) (Channel & DFSDM_LSB_MASK); 02205 /* Store number of injected channels */ 02206 hdfsdm_filter->InjectedChannelsNbr = DFSDM_GetInjChannelsNbr(Channel); 02207 /* Update number of injected channels remaining */ 02208 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \ 02209 hdfsdm_filter->InjectedChannelsNbr : 1U; 02210 } 02211 else 02212 { 02213 status = HAL_ERROR; 02214 } 02215 /* Return function status */ 02216 return status; 02217 } 02218 02219 /** 02220 * @} 02221 */ 02222 02223 /** @defgroup DFSDM_Exported_Functions_Group3_Filter Filter operation functions 02224 * @brief Filter operation functions 02225 * 02226 @verbatim 02227 ============================================================================== 02228 ##### Filter operation functions ##### 02229 ============================================================================== 02230 [..] This section provides functions allowing to: 02231 (+) Start conversion of regular/injected channel. 02232 (+) Poll for the end of regular/injected conversion. 02233 (+) Stop conversion of regular/injected channel. 02234 (+) Start conversion of regular/injected channel and enable interrupt. 02235 (+) Call the callback functions at the end of regular/injected conversions. 02236 (+) Stop conversion of regular/injected channel and disable interrupt. 02237 (+) Start conversion of regular/injected channel and enable DMA transfer. 02238 (+) Stop conversion of regular/injected channel and disable DMA transfer. 02239 (+) Start analog watchdog and enable interrupt. 02240 (+) Call the callback function when analog watchdog occurs. 02241 (+) Stop analog watchdog and disable interrupt. 02242 (+) Start extreme detector. 02243 (+) Stop extreme detector. 02244 (+) Get result of regular channel conversion. 02245 (+) Get result of injected channel conversion. 02246 (+) Get extreme detector maximum and minimum values. 02247 (+) Get conversion time. 02248 (+) Handle DFSDM interrupt request. 02249 @endverbatim 02250 * @{ 02251 */ 02252 02253 /** 02254 * @brief This function allows to start regular conversion in polling mode. 02255 * @note This function should be called only when DFSDM filter instance is 02256 * in idle state or if injected conversion is ongoing. 02257 * @param hdfsdm_filter DFSDM filter handle. 02258 * @retval HAL status 02259 */ 02260 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 02261 { 02262 HAL_StatusTypeDef status = HAL_OK; 02263 02264 /* Check parameters */ 02265 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02266 02267 /* Check DFSDM filter state */ 02268 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \ 02269 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ)) 02270 { 02271 /* Start regular conversion */ 02272 DFSDM_RegConvStart(hdfsdm_filter); 02273 } 02274 else 02275 { 02276 status = HAL_ERROR; 02277 } 02278 /* Return function status */ 02279 return status; 02280 } 02281 02282 /** 02283 * @brief This function allows to poll for the end of regular conversion. 02284 * @note This function should be called only if regular conversion is ongoing. 02285 * @param hdfsdm_filter DFSDM filter handle. 02286 * @param Timeout Timeout value in milliseconds. 02287 * @retval HAL status 02288 */ 02289 HAL_StatusTypeDef HAL_DFSDM_FilterPollForRegConversion(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 02290 uint32_t Timeout) 02291 { 02292 uint32_t tickstart; 02293 02294 /* Check parameters */ 02295 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02296 02297 /* Check DFSDM filter state */ 02298 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \ 02299 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ)) 02300 { 02301 /* Return error status */ 02302 return HAL_ERROR; 02303 } 02304 else 02305 { 02306 /* Get timeout */ 02307 tickstart = HAL_GetTick(); 02308 02309 /* Wait end of regular conversion */ 02310 while((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_REOCF) != DFSDM_FLTISR_REOCF) 02311 { 02312 /* Check the Timeout */ 02313 if(Timeout != HAL_MAX_DELAY) 02314 { 02315 if(((HAL_GetTick()-tickstart) > Timeout) || (Timeout == 0U)) 02316 { 02317 /* Return timeout status */ 02318 return HAL_TIMEOUT; 02319 } 02320 } 02321 } 02322 /* Check if overrun occurs */ 02323 if((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_ROVRF) == DFSDM_FLTISR_ROVRF) 02324 { 02325 /* Update error code and call error callback */ 02326 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_REGULAR_OVERRUN; 02327 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 02328 hdfsdm_filter->ErrorCallback(hdfsdm_filter); 02329 #else 02330 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter); 02331 #endif 02332 02333 /* Clear regular overrun flag */ 02334 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRROVRF; 02335 } 02336 /* Update DFSDM filter state only if not continuous conversion and SW trigger */ 02337 if((hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \ 02338 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER)) 02339 { 02340 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \ 02341 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ; 02342 } 02343 /* Return function status */ 02344 return HAL_OK; 02345 } 02346 } 02347 02348 /** 02349 * @brief This function allows to stop regular conversion in polling mode. 02350 * @note This function should be called only if regular conversion is ongoing. 02351 * @param hdfsdm_filter DFSDM filter handle. 02352 * @retval HAL status 02353 */ 02354 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 02355 { 02356 HAL_StatusTypeDef status = HAL_OK; 02357 02358 /* Check parameters */ 02359 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02360 02361 /* Check DFSDM filter state */ 02362 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \ 02363 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ)) 02364 { 02365 /* Return error status */ 02366 status = HAL_ERROR; 02367 } 02368 else 02369 { 02370 /* Stop regular conversion */ 02371 DFSDM_RegConvStop(hdfsdm_filter); 02372 } 02373 /* Return function status */ 02374 return status; 02375 } 02376 02377 /** 02378 * @brief This function allows to start regular conversion in interrupt mode. 02379 * @note This function should be called only when DFSDM filter instance is 02380 * in idle state or if injected conversion is ongoing. 02381 * @param hdfsdm_filter DFSDM filter handle. 02382 * @retval HAL status 02383 */ 02384 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 02385 { 02386 HAL_StatusTypeDef status = HAL_OK; 02387 02388 /* Check parameters */ 02389 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02390 02391 /* Check DFSDM filter state */ 02392 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \ 02393 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ)) 02394 { 02395 /* Enable interrupts for regular conversions */ 02396 hdfsdm_filter->Instance->FLTCR2 |= (DFSDM_FLTCR2_REOCIE | DFSDM_FLTCR2_ROVRIE); 02397 02398 /* Start regular conversion */ 02399 DFSDM_RegConvStart(hdfsdm_filter); 02400 } 02401 else 02402 { 02403 status = HAL_ERROR; 02404 } 02405 /* Return function status */ 02406 return status; 02407 } 02408 02409 /** 02410 * @brief This function allows to stop regular conversion in interrupt mode. 02411 * @note This function should be called only if regular conversion is ongoing. 02412 * @param hdfsdm_filter DFSDM filter handle. 02413 * @retval HAL status 02414 */ 02415 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 02416 { 02417 HAL_StatusTypeDef status = HAL_OK; 02418 02419 /* Check parameters */ 02420 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02421 02422 /* Check DFSDM filter state */ 02423 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \ 02424 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ)) 02425 { 02426 /* Return error status */ 02427 status = HAL_ERROR; 02428 } 02429 else 02430 { 02431 /* Disable interrupts for regular conversions */ 02432 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_REOCIE | DFSDM_FLTCR2_ROVRIE); 02433 02434 /* Stop regular conversion */ 02435 DFSDM_RegConvStop(hdfsdm_filter); 02436 } 02437 /* Return function status */ 02438 return status; 02439 } 02440 02441 /** 02442 * @brief This function allows to start regular conversion in DMA mode. 02443 * @note This function should be called only when DFSDM filter instance is 02444 * in idle state or if injected conversion is ongoing. 02445 * Please note that data on buffer will contain signed regular conversion 02446 * value on 24 most significant bits and corresponding channel on 3 least 02447 * significant bits. 02448 * @param hdfsdm_filter DFSDM filter handle. 02449 * @param pData The destination buffer address. 02450 * @param Length The length of data to be transferred from DFSDM filter to memory. 02451 * @retval HAL status 02452 */ 02453 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 02454 int32_t *pData, 02455 uint32_t Length) 02456 { 02457 HAL_StatusTypeDef status = HAL_OK; 02458 02459 /* Check parameters */ 02460 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02461 02462 /* Check destination address and length */ 02463 if((pData == NULL) || (Length == 0U)) 02464 { 02465 status = HAL_ERROR; 02466 } 02467 /* Check that DMA is enabled for regular conversion */ 02468 else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_RDMAEN) != DFSDM_FLTCR1_RDMAEN) 02469 { 02470 status = HAL_ERROR; 02471 } 02472 /* Check parameters compatibility */ 02473 else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \ 02474 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \ 02475 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_NORMAL) && \ 02476 (Length != 1U)) 02477 { 02478 status = HAL_ERROR; 02479 } 02480 else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \ 02481 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \ 02482 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR)) 02483 { 02484 status = HAL_ERROR; 02485 } 02486 /* Check DFSDM filter state */ 02487 else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \ 02488 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ)) 02489 { 02490 /* Set callbacks on DMA handler */ 02491 hdfsdm_filter->hdmaReg->XferCpltCallback = DFSDM_DMARegularConvCplt; 02492 hdfsdm_filter->hdmaReg->XferErrorCallback = DFSDM_DMAError; 02493 hdfsdm_filter->hdmaReg->XferHalfCpltCallback = (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR) ?\ 02494 DFSDM_DMARegularHalfConvCplt : NULL; 02495 02496 /* Start DMA in interrupt mode */ 02497 if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaReg, (uint32_t)&hdfsdm_filter->Instance->FLTRDATAR, \ 02498 (uint32_t) pData, Length) != HAL_OK) 02499 { 02500 /* Set DFSDM filter in error state */ 02501 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR; 02502 status = HAL_ERROR; 02503 } 02504 else 02505 { 02506 /* Start regular conversion */ 02507 DFSDM_RegConvStart(hdfsdm_filter); 02508 } 02509 } 02510 else 02511 { 02512 status = HAL_ERROR; 02513 } 02514 /* Return function status */ 02515 return status; 02516 } 02517 02518 /** 02519 * @brief This function allows to start regular conversion in DMA mode and to get 02520 * only the 16 most significant bits of conversion. 02521 * @note This function should be called only when DFSDM filter instance is 02522 * in idle state or if injected conversion is ongoing. 02523 * Please note that data on buffer will contain signed 16 most significant 02524 * bits of regular conversion. 02525 * @param hdfsdm_filter DFSDM filter handle. 02526 * @param pData The destination buffer address. 02527 * @param Length The length of data to be transferred from DFSDM filter to memory. 02528 * @retval HAL status 02529 */ 02530 HAL_StatusTypeDef HAL_DFSDM_FilterRegularMsbStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 02531 int16_t *pData, 02532 uint32_t Length) 02533 { 02534 HAL_StatusTypeDef status = HAL_OK; 02535 02536 /* Check parameters */ 02537 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02538 02539 /* Check destination address and length */ 02540 if((pData == NULL) || (Length == 0U)) 02541 { 02542 status = HAL_ERROR; 02543 } 02544 /* Check that DMA is enabled for regular conversion */ 02545 else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_RDMAEN) != DFSDM_FLTCR1_RDMAEN) 02546 { 02547 status = HAL_ERROR; 02548 } 02549 /* Check parameters compatibility */ 02550 else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \ 02551 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \ 02552 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_NORMAL) && \ 02553 (Length != 1U)) 02554 { 02555 status = HAL_ERROR; 02556 } 02557 else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \ 02558 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \ 02559 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR)) 02560 { 02561 status = HAL_ERROR; 02562 } 02563 /* Check DFSDM filter state */ 02564 else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \ 02565 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ)) 02566 { 02567 /* Set callbacks on DMA handler */ 02568 hdfsdm_filter->hdmaReg->XferCpltCallback = DFSDM_DMARegularConvCplt; 02569 hdfsdm_filter->hdmaReg->XferErrorCallback = DFSDM_DMAError; 02570 hdfsdm_filter->hdmaReg->XferHalfCpltCallback = (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR) ?\ 02571 DFSDM_DMARegularHalfConvCplt : NULL; 02572 02573 /* Start DMA in interrupt mode */ 02574 if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaReg, (uint32_t)(&hdfsdm_filter->Instance->FLTRDATAR) + 2U, \ 02575 (uint32_t) pData, Length) != HAL_OK) 02576 { 02577 /* Set DFSDM filter in error state */ 02578 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR; 02579 status = HAL_ERROR; 02580 } 02581 else 02582 { 02583 /* Start regular conversion */ 02584 DFSDM_RegConvStart(hdfsdm_filter); 02585 } 02586 } 02587 else 02588 { 02589 status = HAL_ERROR; 02590 } 02591 /* Return function status */ 02592 return status; 02593 } 02594 02595 /** 02596 * @brief This function allows to stop regular conversion in DMA mode. 02597 * @note This function should be called only if regular conversion is ongoing. 02598 * @param hdfsdm_filter DFSDM filter handle. 02599 * @retval HAL status 02600 */ 02601 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 02602 { 02603 HAL_StatusTypeDef status = HAL_OK; 02604 02605 /* Check parameters */ 02606 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02607 02608 /* Check DFSDM filter state */ 02609 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \ 02610 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ)) 02611 { 02612 /* Return error status */ 02613 status = HAL_ERROR; 02614 } 02615 else 02616 { 02617 /* Stop current DMA transfer */ 02618 if(HAL_DMA_Abort(hdfsdm_filter->hdmaReg) != HAL_OK) 02619 { 02620 /* Set DFSDM filter in error state */ 02621 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR; 02622 status = HAL_ERROR; 02623 } 02624 else 02625 { 02626 /* Stop regular conversion */ 02627 DFSDM_RegConvStop(hdfsdm_filter); 02628 } 02629 } 02630 /* Return function status */ 02631 return status; 02632 } 02633 02634 /** 02635 * @brief This function allows to get regular conversion value. 02636 * @param hdfsdm_filter DFSDM filter handle. 02637 * @param Channel Corresponding channel of regular conversion. 02638 * @retval Regular conversion value 02639 */ 02640 int32_t HAL_DFSDM_FilterGetRegularValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 02641 uint32_t *Channel) 02642 { 02643 uint32_t reg = 0U; 02644 int32_t value = 0; 02645 02646 /* Check parameters */ 02647 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02648 assert_param(Channel != NULL); 02649 02650 /* Get value of data register for regular channel */ 02651 reg = hdfsdm_filter->Instance->FLTRDATAR; 02652 02653 /* Extract channel and regular conversion value */ 02654 *Channel = (reg & DFSDM_FLTRDATAR_RDATACH); 02655 value = ((int32_t)(reg & DFSDM_FLTRDATAR_RDATA) >> DFSDM_FLTRDATAR_RDATA_Pos); 02656 02657 /* return regular conversion value */ 02658 return value; 02659 } 02660 02661 /** 02662 * @brief This function allows to start injected conversion in polling mode. 02663 * @note This function should be called only when DFSDM filter instance is 02664 * in idle state or if regular conversion is ongoing. 02665 * @param hdfsdm_filter DFSDM filter handle. 02666 * @retval HAL status 02667 */ 02668 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 02669 { 02670 HAL_StatusTypeDef status = HAL_OK; 02671 02672 /* Check parameters */ 02673 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02674 02675 /* Check DFSDM filter state */ 02676 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \ 02677 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG)) 02678 { 02679 /* Start injected conversion */ 02680 DFSDM_InjConvStart(hdfsdm_filter); 02681 } 02682 else 02683 { 02684 status = HAL_ERROR; 02685 } 02686 /* Return function status */ 02687 return status; 02688 } 02689 02690 /** 02691 * @brief This function allows to poll for the end of injected conversion. 02692 * @note This function should be called only if injected conversion is ongoing. 02693 * @param hdfsdm_filter DFSDM filter handle. 02694 * @param Timeout Timeout value in milliseconds. 02695 * @retval HAL status 02696 */ 02697 HAL_StatusTypeDef HAL_DFSDM_FilterPollForInjConversion(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 02698 uint32_t Timeout) 02699 { 02700 uint32_t tickstart; 02701 02702 /* Check parameters */ 02703 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02704 02705 /* Check DFSDM filter state */ 02706 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \ 02707 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ)) 02708 { 02709 /* Return error status */ 02710 return HAL_ERROR; 02711 } 02712 else 02713 { 02714 /* Get timeout */ 02715 tickstart = HAL_GetTick(); 02716 02717 /* Wait end of injected conversions */ 02718 while((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JEOCF) != DFSDM_FLTISR_JEOCF) 02719 { 02720 /* Check the Timeout */ 02721 if(Timeout != HAL_MAX_DELAY) 02722 { 02723 if( ((HAL_GetTick()-tickstart) > Timeout) || (Timeout == 0U)) 02724 { 02725 /* Return timeout status */ 02726 return HAL_TIMEOUT; 02727 } 02728 } 02729 } 02730 /* Check if overrun occurs */ 02731 if((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JOVRF) == DFSDM_FLTISR_JOVRF) 02732 { 02733 /* Update error code and call error callback */ 02734 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INJECTED_OVERRUN; 02735 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 02736 hdfsdm_filter->ErrorCallback(hdfsdm_filter); 02737 #else 02738 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter); 02739 #endif 02740 02741 /* Clear injected overrun flag */ 02742 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRJOVRF; 02743 } 02744 02745 /* Update remaining injected conversions */ 02746 hdfsdm_filter->InjConvRemaining--; 02747 if(hdfsdm_filter->InjConvRemaining == 0U) 02748 { 02749 /* Update DFSDM filter state only if trigger is software */ 02750 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) 02751 { 02752 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \ 02753 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG; 02754 } 02755 02756 /* end of injected sequence, reset the value */ 02757 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \ 02758 hdfsdm_filter->InjectedChannelsNbr : 1U; 02759 } 02760 02761 /* Return function status */ 02762 return HAL_OK; 02763 } 02764 } 02765 02766 /** 02767 * @brief This function allows to stop injected conversion in polling mode. 02768 * @note This function should be called only if injected conversion is ongoing. 02769 * @param hdfsdm_filter DFSDM filter handle. 02770 * @retval HAL status 02771 */ 02772 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 02773 { 02774 HAL_StatusTypeDef status = HAL_OK; 02775 02776 /* Check parameters */ 02777 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02778 02779 /* Check DFSDM filter state */ 02780 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \ 02781 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ)) 02782 { 02783 /* Return error status */ 02784 status = HAL_ERROR; 02785 } 02786 else 02787 { 02788 /* Stop injected conversion */ 02789 DFSDM_InjConvStop(hdfsdm_filter); 02790 } 02791 /* Return function status */ 02792 return status; 02793 } 02794 02795 /** 02796 * @brief This function allows to start injected conversion in interrupt mode. 02797 * @note This function should be called only when DFSDM filter instance is 02798 * in idle state or if regular conversion is ongoing. 02799 * @param hdfsdm_filter DFSDM filter handle. 02800 * @retval HAL status 02801 */ 02802 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 02803 { 02804 HAL_StatusTypeDef status = HAL_OK; 02805 02806 /* Check parameters */ 02807 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02808 02809 /* Check DFSDM filter state */ 02810 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \ 02811 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG)) 02812 { 02813 /* Enable interrupts for injected conversions */ 02814 hdfsdm_filter->Instance->FLTCR2 |= (DFSDM_FLTCR2_JEOCIE | DFSDM_FLTCR2_JOVRIE); 02815 02816 /* Start injected conversion */ 02817 DFSDM_InjConvStart(hdfsdm_filter); 02818 } 02819 else 02820 { 02821 status = HAL_ERROR; 02822 } 02823 /* Return function status */ 02824 return status; 02825 } 02826 02827 /** 02828 * @brief This function allows to stop injected conversion in interrupt mode. 02829 * @note This function should be called only if injected conversion is ongoing. 02830 * @param hdfsdm_filter DFSDM filter handle. 02831 * @retval HAL status 02832 */ 02833 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 02834 { 02835 HAL_StatusTypeDef status = HAL_OK; 02836 02837 /* Check parameters */ 02838 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02839 02840 /* Check DFSDM filter state */ 02841 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \ 02842 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ)) 02843 { 02844 /* Return error status */ 02845 status = HAL_ERROR; 02846 } 02847 else 02848 { 02849 /* Disable interrupts for injected conversions */ 02850 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_JEOCIE | DFSDM_FLTCR2_JOVRIE); 02851 02852 /* Stop injected conversion */ 02853 DFSDM_InjConvStop(hdfsdm_filter); 02854 } 02855 /* Return function status */ 02856 return status; 02857 } 02858 02859 /** 02860 * @brief This function allows to start injected conversion in DMA mode. 02861 * @note This function should be called only when DFSDM filter instance is 02862 * in idle state or if regular conversion is ongoing. 02863 * Please note that data on buffer will contain signed injected conversion 02864 * value on 24 most significant bits and corresponding channel on 3 least 02865 * significant bits. 02866 * @param hdfsdm_filter DFSDM filter handle. 02867 * @param pData The destination buffer address. 02868 * @param Length The length of data to be transferred from DFSDM filter to memory. 02869 * @retval HAL status 02870 */ 02871 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 02872 int32_t *pData, 02873 uint32_t Length) 02874 { 02875 HAL_StatusTypeDef status = HAL_OK; 02876 02877 /* Check parameters */ 02878 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02879 02880 /* Check destination address and length */ 02881 if((pData == NULL) || (Length == 0U)) 02882 { 02883 status = HAL_ERROR; 02884 } 02885 /* Check that DMA is enabled for injected conversion */ 02886 else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_JDMAEN) != DFSDM_FLTCR1_JDMAEN) 02887 { 02888 status = HAL_ERROR; 02889 } 02890 /* Check parameters compatibility */ 02891 else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \ 02892 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_NORMAL) && \ 02893 (Length > hdfsdm_filter->InjConvRemaining)) 02894 { 02895 status = HAL_ERROR; 02896 } 02897 else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \ 02898 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR)) 02899 { 02900 status = HAL_ERROR; 02901 } 02902 /* Check DFSDM filter state */ 02903 else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \ 02904 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG)) 02905 { 02906 /* Set callbacks on DMA handler */ 02907 hdfsdm_filter->hdmaInj->XferCpltCallback = DFSDM_DMAInjectedConvCplt; 02908 hdfsdm_filter->hdmaInj->XferErrorCallback = DFSDM_DMAError; 02909 hdfsdm_filter->hdmaInj->XferHalfCpltCallback = (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR) ?\ 02910 DFSDM_DMAInjectedHalfConvCplt : NULL; 02911 02912 /* Start DMA in interrupt mode */ 02913 if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaInj, (uint32_t)&hdfsdm_filter->Instance->FLTJDATAR, \ 02914 (uint32_t) pData, Length) != HAL_OK) 02915 { 02916 /* Set DFSDM filter in error state */ 02917 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR; 02918 status = HAL_ERROR; 02919 } 02920 else 02921 { 02922 /* Start injected conversion */ 02923 DFSDM_InjConvStart(hdfsdm_filter); 02924 } 02925 } 02926 else 02927 { 02928 status = HAL_ERROR; 02929 } 02930 /* Return function status */ 02931 return status; 02932 } 02933 02934 /** 02935 * @brief This function allows to start injected conversion in DMA mode and to get 02936 * only the 16 most significant bits of conversion. 02937 * @note This function should be called only when DFSDM filter instance is 02938 * in idle state or if regular conversion is ongoing. 02939 * Please note that data on buffer will contain signed 16 most significant 02940 * bits of injected conversion. 02941 * @param hdfsdm_filter DFSDM filter handle. 02942 * @param pData The destination buffer address. 02943 * @param Length The length of data to be transferred from DFSDM filter to memory. 02944 * @retval HAL status 02945 */ 02946 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedMsbStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 02947 int16_t *pData, 02948 uint32_t Length) 02949 { 02950 HAL_StatusTypeDef status = HAL_OK; 02951 02952 /* Check parameters */ 02953 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 02954 02955 /* Check destination address and length */ 02956 if((pData == NULL) || (Length == 0U)) 02957 { 02958 status = HAL_ERROR; 02959 } 02960 /* Check that DMA is enabled for injected conversion */ 02961 else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_JDMAEN) != DFSDM_FLTCR1_JDMAEN) 02962 { 02963 status = HAL_ERROR; 02964 } 02965 /* Check parameters compatibility */ 02966 else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \ 02967 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_NORMAL) && \ 02968 (Length > hdfsdm_filter->InjConvRemaining)) 02969 { 02970 status = HAL_ERROR; 02971 } 02972 else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \ 02973 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR)) 02974 { 02975 status = HAL_ERROR; 02976 } 02977 /* Check DFSDM filter state */ 02978 else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \ 02979 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG)) 02980 { 02981 /* Set callbacks on DMA handler */ 02982 hdfsdm_filter->hdmaInj->XferCpltCallback = DFSDM_DMAInjectedConvCplt; 02983 hdfsdm_filter->hdmaInj->XferErrorCallback = DFSDM_DMAError; 02984 hdfsdm_filter->hdmaInj->XferHalfCpltCallback = (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR) ?\ 02985 DFSDM_DMAInjectedHalfConvCplt : NULL; 02986 02987 /* Start DMA in interrupt mode */ 02988 if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaInj, (uint32_t)(&hdfsdm_filter->Instance->FLTJDATAR) + 2U, \ 02989 (uint32_t) pData, Length) != HAL_OK) 02990 { 02991 /* Set DFSDM filter in error state */ 02992 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR; 02993 status = HAL_ERROR; 02994 } 02995 else 02996 { 02997 /* Start injected conversion */ 02998 DFSDM_InjConvStart(hdfsdm_filter); 02999 } 03000 } 03001 else 03002 { 03003 status = HAL_ERROR; 03004 } 03005 /* Return function status */ 03006 return status; 03007 } 03008 03009 /** 03010 * @brief This function allows to stop injected conversion in DMA mode. 03011 * @note This function should be called only if injected conversion is ongoing. 03012 * @param hdfsdm_filter DFSDM filter handle. 03013 * @retval HAL status 03014 */ 03015 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 03016 { 03017 HAL_StatusTypeDef status = HAL_OK; 03018 03019 /* Check parameters */ 03020 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 03021 03022 /* Check DFSDM filter state */ 03023 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \ 03024 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ)) 03025 { 03026 /* Return error status */ 03027 status = HAL_ERROR; 03028 } 03029 else 03030 { 03031 /* Stop current DMA transfer */ 03032 if(HAL_DMA_Abort(hdfsdm_filter->hdmaInj) != HAL_OK) 03033 { 03034 /* Set DFSDM filter in error state */ 03035 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR; 03036 status = HAL_ERROR; 03037 } 03038 else 03039 { 03040 /* Stop regular conversion */ 03041 DFSDM_InjConvStop(hdfsdm_filter); 03042 } 03043 } 03044 /* Return function status */ 03045 return status; 03046 } 03047 03048 /** 03049 * @brief This function allows to get injected conversion value. 03050 * @param hdfsdm_filter DFSDM filter handle. 03051 * @param Channel Corresponding channel of injected conversion. 03052 * @retval Injected conversion value 03053 */ 03054 int32_t HAL_DFSDM_FilterGetInjectedValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 03055 uint32_t *Channel) 03056 { 03057 uint32_t reg = 0U; 03058 int32_t value = 0; 03059 03060 /* Check parameters */ 03061 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 03062 assert_param(Channel != NULL); 03063 03064 /* Get value of data register for injected channel */ 03065 reg = hdfsdm_filter->Instance->FLTJDATAR; 03066 03067 /* Extract channel and injected conversion value */ 03068 *Channel = (reg & DFSDM_FLTJDATAR_JDATACH); 03069 value = ((int32_t)(reg & DFSDM_FLTJDATAR_JDATA) >> DFSDM_FLTJDATAR_JDATA_Pos); 03070 03071 /* return regular conversion value */ 03072 return value; 03073 } 03074 03075 /** 03076 * @brief This function allows to start filter analog watchdog in interrupt mode. 03077 * @param hdfsdm_filter DFSDM filter handle. 03078 * @param awdParam DFSDM filter analog watchdog parameters. 03079 * @retval HAL status 03080 */ 03081 HAL_StatusTypeDef HAL_DFSDM_FilterAwdStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 03082 DFSDM_Filter_AwdParamTypeDef *awdParam) 03083 { 03084 HAL_StatusTypeDef status = HAL_OK; 03085 03086 /* Check parameters */ 03087 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 03088 assert_param(IS_DFSDM_FILTER_AWD_DATA_SOURCE(awdParam->DataSource)); 03089 assert_param(IS_DFSDM_INJECTED_CHANNEL(awdParam->Channel)); 03090 assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam->HighThreshold)); 03091 assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam->LowThreshold)); 03092 assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam->HighBreakSignal)); 03093 assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam->LowBreakSignal)); 03094 03095 /* Check DFSDM filter state */ 03096 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \ 03097 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR)) 03098 { 03099 /* Return error status */ 03100 status = HAL_ERROR; 03101 } 03102 else 03103 { 03104 /* Set analog watchdog data source */ 03105 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_AWFSEL); 03106 hdfsdm_filter->Instance->FLTCR1 |= awdParam->DataSource; 03107 03108 /* Set thresholds and break signals */ 03109 hdfsdm_filter->Instance->FLTAWHTR &= ~(DFSDM_FLTAWHTR_AWHT | DFSDM_FLTAWHTR_BKAWH); 03110 hdfsdm_filter->Instance->FLTAWHTR |= (((uint32_t) awdParam->HighThreshold << DFSDM_FLTAWHTR_AWHT_Pos) | \ 03111 awdParam->HighBreakSignal); 03112 hdfsdm_filter->Instance->FLTAWLTR &= ~(DFSDM_FLTAWLTR_AWLT | DFSDM_FLTAWLTR_BKAWL); 03113 hdfsdm_filter->Instance->FLTAWLTR |= (((uint32_t) awdParam->LowThreshold << DFSDM_FLTAWLTR_AWLT_Pos) | \ 03114 awdParam->LowBreakSignal); 03115 03116 /* Set channels and interrupt for analog watchdog */ 03117 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_AWDCH); 03118 hdfsdm_filter->Instance->FLTCR2 |= (((awdParam->Channel & DFSDM_LSB_MASK) << DFSDM_FLTCR2_AWDCH_Pos) | \ 03119 DFSDM_FLTCR2_AWDIE); 03120 } 03121 /* Return function status */ 03122 return status; 03123 } 03124 03125 /** 03126 * @brief This function allows to stop filter analog watchdog in interrupt mode. 03127 * @param hdfsdm_filter DFSDM filter handle. 03128 * @retval HAL status 03129 */ 03130 HAL_StatusTypeDef HAL_DFSDM_FilterAwdStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 03131 { 03132 HAL_StatusTypeDef status = HAL_OK; 03133 03134 /* Check parameters */ 03135 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 03136 03137 /* Check DFSDM filter state */ 03138 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \ 03139 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR)) 03140 { 03141 /* Return error status */ 03142 status = HAL_ERROR; 03143 } 03144 else 03145 { 03146 /* Reset channels for analog watchdog and deactivate interrupt */ 03147 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_AWDCH | DFSDM_FLTCR2_AWDIE); 03148 03149 /* Clear all analog watchdog flags */ 03150 hdfsdm_filter->Instance->FLTAWCFR = (DFSDM_FLTAWCFR_CLRAWHTF | DFSDM_FLTAWCFR_CLRAWLTF); 03151 03152 /* Reset thresholds and break signals */ 03153 hdfsdm_filter->Instance->FLTAWHTR &= ~(DFSDM_FLTAWHTR_AWHT | DFSDM_FLTAWHTR_BKAWH); 03154 hdfsdm_filter->Instance->FLTAWLTR &= ~(DFSDM_FLTAWLTR_AWLT | DFSDM_FLTAWLTR_BKAWL); 03155 03156 /* Reset analog watchdog data source */ 03157 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_AWFSEL); 03158 } 03159 /* Return function status */ 03160 return status; 03161 } 03162 03163 /** 03164 * @brief This function allows to start extreme detector feature. 03165 * @param hdfsdm_filter DFSDM filter handle. 03166 * @param Channel Channels where extreme detector is enabled. 03167 * This parameter can be a values combination of @ref DFSDM_Channel_Selection. 03168 * @retval HAL status 03169 */ 03170 HAL_StatusTypeDef HAL_DFSDM_FilterExdStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 03171 uint32_t Channel) 03172 { 03173 HAL_StatusTypeDef status = HAL_OK; 03174 03175 /* Check parameters */ 03176 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 03177 assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel)); 03178 03179 /* Check DFSDM filter state */ 03180 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \ 03181 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR)) 03182 { 03183 /* Return error status */ 03184 status = HAL_ERROR; 03185 } 03186 else 03187 { 03188 /* Set channels for extreme detector */ 03189 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_EXCH); 03190 hdfsdm_filter->Instance->FLTCR2 |= ((Channel & DFSDM_LSB_MASK) << DFSDM_FLTCR2_EXCH_Pos); 03191 } 03192 /* Return function status */ 03193 return status; 03194 } 03195 03196 /** 03197 * @brief This function allows to stop extreme detector feature. 03198 * @param hdfsdm_filter DFSDM filter handle. 03199 * @retval HAL status 03200 */ 03201 HAL_StatusTypeDef HAL_DFSDM_FilterExdStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 03202 { 03203 HAL_StatusTypeDef status = HAL_OK; 03204 __IO uint32_t reg1; 03205 __IO uint32_t reg2; 03206 03207 /* Check parameters */ 03208 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 03209 03210 /* Check DFSDM filter state */ 03211 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \ 03212 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR)) 03213 { 03214 /* Return error status */ 03215 status = HAL_ERROR; 03216 } 03217 else 03218 { 03219 /* Reset channels for extreme detector */ 03220 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_EXCH); 03221 03222 /* Clear extreme detector values */ 03223 reg1 = hdfsdm_filter->Instance->FLTEXMAX; 03224 reg2 = hdfsdm_filter->Instance->FLTEXMIN; 03225 UNUSED(reg1); /* To avoid GCC warning */ 03226 UNUSED(reg2); /* To avoid GCC warning */ 03227 } 03228 /* Return function status */ 03229 return status; 03230 } 03231 03232 /** 03233 * @brief This function allows to get extreme detector maximum value. 03234 * @param hdfsdm_filter DFSDM filter handle. 03235 * @param Channel Corresponding channel. 03236 * @retval Extreme detector maximum value 03237 * This value is between Min_Data = -8388608 and Max_Data = 8388607. 03238 */ 03239 int32_t HAL_DFSDM_FilterGetExdMaxValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 03240 uint32_t *Channel) 03241 { 03242 uint32_t reg = 0U; 03243 int32_t value = 0; 03244 03245 /* Check parameters */ 03246 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 03247 assert_param(Channel != NULL); 03248 03249 /* Get value of extreme detector maximum register */ 03250 reg = hdfsdm_filter->Instance->FLTEXMAX; 03251 03252 /* Extract channel and extreme detector maximum value */ 03253 *Channel = (reg & DFSDM_FLTEXMAX_EXMAXCH); 03254 value = ((int32_t)(reg & DFSDM_FLTEXMAX_EXMAX) >> DFSDM_FLTEXMAX_EXMAX_Pos); 03255 03256 /* return extreme detector maximum value */ 03257 return value; 03258 } 03259 03260 /** 03261 * @brief This function allows to get extreme detector minimum value. 03262 * @param hdfsdm_filter DFSDM filter handle. 03263 * @param Channel Corresponding channel. 03264 * @retval Extreme detector minimum value 03265 * This value is between Min_Data = -8388608 and Max_Data = 8388607. 03266 */ 03267 int32_t HAL_DFSDM_FilterGetExdMinValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 03268 uint32_t *Channel) 03269 { 03270 uint32_t reg = 0U; 03271 int32_t value = 0; 03272 03273 /* Check parameters */ 03274 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 03275 assert_param(Channel != NULL); 03276 03277 /* Get value of extreme detector minimum register */ 03278 reg = hdfsdm_filter->Instance->FLTEXMIN; 03279 03280 /* Extract channel and extreme detector minimum value */ 03281 *Channel = (reg & DFSDM_FLTEXMIN_EXMINCH); 03282 value = ((int32_t)(reg & DFSDM_FLTEXMIN_EXMIN) >> DFSDM_FLTEXMIN_EXMIN_Pos); 03283 03284 /* return extreme detector minimum value */ 03285 return value; 03286 } 03287 03288 /** 03289 * @brief This function allows to get conversion time value. 03290 * @param hdfsdm_filter DFSDM filter handle. 03291 * @retval Conversion time value 03292 * @note To get time in second, this value has to be divided by DFSDM clock frequency. 03293 */ 03294 uint32_t HAL_DFSDM_FilterGetConvTimeValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 03295 { 03296 uint32_t reg = 0U; 03297 uint32_t value = 0U; 03298 03299 /* Check parameters */ 03300 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance)); 03301 03302 /* Get value of conversion timer register */ 03303 reg = hdfsdm_filter->Instance->FLTCNVTIMR; 03304 03305 /* Extract conversion time value */ 03306 value = ((reg & DFSDM_FLTCNVTIMR_CNVCNT) >> DFSDM_FLTCNVTIMR_CNVCNT_Pos); 03307 03308 /* return extreme detector minimum value */ 03309 return value; 03310 } 03311 03312 /** 03313 * @brief This function handles the DFSDM interrupts. 03314 * @param hdfsdm_filter DFSDM filter handle. 03315 * @retval None 03316 */ 03317 void HAL_DFSDM_IRQHandler(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 03318 { 03319 /* Check if overrun occurs during regular conversion */ 03320 if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_ROVRF) != 0U) && \ 03321 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_ROVRIE) != 0U)) 03322 { 03323 /* Clear regular overrun flag */ 03324 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRROVRF; 03325 03326 /* Update error code */ 03327 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_REGULAR_OVERRUN; 03328 03329 /* Call error callback */ 03330 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 03331 hdfsdm_filter->ErrorCallback(hdfsdm_filter); 03332 #else 03333 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter); 03334 #endif 03335 } 03336 /* Check if overrun occurs during injected conversion */ 03337 else if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JOVRF) != 0U) && \ 03338 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_JOVRIE) != 0U)) 03339 { 03340 /* Clear injected overrun flag */ 03341 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRJOVRF; 03342 03343 /* Update error code */ 03344 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INJECTED_OVERRUN; 03345 03346 /* Call error callback */ 03347 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 03348 hdfsdm_filter->ErrorCallback(hdfsdm_filter); 03349 #else 03350 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter); 03351 #endif 03352 } 03353 /* Check if end of regular conversion */ 03354 else if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_REOCF) != 0U) && \ 03355 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_REOCIE) != 0U)) 03356 { 03357 /* Call regular conversion complete callback */ 03358 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 03359 hdfsdm_filter->RegConvCpltCallback(hdfsdm_filter); 03360 #else 03361 HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter); 03362 #endif 03363 03364 /* End of conversion if mode is not continuous and software trigger */ 03365 if((hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \ 03366 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER)) 03367 { 03368 /* Disable interrupts for regular conversions */ 03369 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_REOCIE); 03370 03371 /* Update DFSDM filter state */ 03372 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \ 03373 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ; 03374 } 03375 } 03376 /* Check if end of injected conversion */ 03377 else if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JEOCF) != 0U) && \ 03378 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_JEOCIE) != 0U)) 03379 { 03380 /* Call injected conversion complete callback */ 03381 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 03382 hdfsdm_filter->InjConvCpltCallback(hdfsdm_filter); 03383 #else 03384 HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter); 03385 #endif 03386 03387 /* Update remaining injected conversions */ 03388 hdfsdm_filter->InjConvRemaining--; 03389 if(hdfsdm_filter->InjConvRemaining == 0U) 03390 { 03391 /* End of conversion if trigger is software */ 03392 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) 03393 { 03394 /* Disable interrupts for injected conversions */ 03395 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_JEOCIE); 03396 03397 /* Update DFSDM filter state */ 03398 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \ 03399 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG; 03400 } 03401 /* end of injected sequence, reset the value */ 03402 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \ 03403 hdfsdm_filter->InjectedChannelsNbr : 1U; 03404 } 03405 } 03406 /* Check if analog watchdog occurs */ 03407 else if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_AWDF) != 0U) && \ 03408 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_AWDIE) != 0U)) 03409 { 03410 uint32_t reg = 0U; 03411 uint32_t threshold = 0U; 03412 uint32_t channel = 0U; 03413 03414 /* Get channel and threshold */ 03415 reg = hdfsdm_filter->Instance->FLTAWSR; 03416 threshold = ((reg & DFSDM_FLTAWSR_AWLTF) != 0U) ? DFSDM_AWD_LOW_THRESHOLD : DFSDM_AWD_HIGH_THRESHOLD; 03417 if(threshold == DFSDM_AWD_HIGH_THRESHOLD) 03418 { 03419 reg = reg >> DFSDM_FLTAWSR_AWHTF_Pos; 03420 } 03421 while((reg & 1U) == 0U) 03422 { 03423 channel++; 03424 reg = reg >> 1U; 03425 } 03426 /* Clear analog watchdog flag */ 03427 hdfsdm_filter->Instance->FLTAWCFR = (threshold == DFSDM_AWD_HIGH_THRESHOLD) ? \ 03428 (1U << (DFSDM_FLTAWSR_AWHTF_Pos + channel)) : \ 03429 (1U << channel); 03430 03431 /* Call analog watchdog callback */ 03432 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 03433 hdfsdm_filter->AwdCallback(hdfsdm_filter, channel, threshold); 03434 #else 03435 HAL_DFSDM_FilterAwdCallback(hdfsdm_filter, channel, threshold); 03436 #endif 03437 } 03438 /* Check if clock absence occurs */ 03439 else if((hdfsdm_filter->Instance == DFSDM1_Filter0) && \ 03440 ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_CKABF) != 0U) && \ 03441 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_CKABIE) != 0U)) 03442 { 03443 uint32_t reg = 0U; 03444 uint32_t channel = 0U; 03445 03446 reg = ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_CKABF) >> DFSDM_FLTISR_CKABF_Pos); 03447 03448 while(channel < DFSDM1_CHANNEL_NUMBER) 03449 { 03450 /* Check if flag is set and corresponding channel is enabled */ 03451 if(((reg & 1U) != 0U) && (a_dfsdm1ChannelHandle[channel] != NULL)) 03452 { 03453 /* Check clock absence has been enabled for this channel */ 03454 if((a_dfsdm1ChannelHandle[channel]->Instance->CHCFGR1 & DFSDM_CHCFGR1_CKABEN) != 0U) 03455 { 03456 /* Clear clock absence flag */ 03457 hdfsdm_filter->Instance->FLTICR = (1U << (DFSDM_FLTICR_CLRCKABF_Pos + channel)); 03458 03459 /* Call clock absence callback */ 03460 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 03461 a_dfsdm1ChannelHandle[channel]->CkabCallback(a_dfsdm1ChannelHandle[channel]); 03462 #else 03463 HAL_DFSDM_ChannelCkabCallback(a_dfsdm1ChannelHandle[channel]); 03464 #endif 03465 } 03466 } 03467 channel++; 03468 reg = reg >> 1U; 03469 } 03470 } 03471 #if defined (DFSDM2_Channel0) 03472 /* Check if clock absence occurs */ 03473 else if((hdfsdm_filter->Instance == DFSDM2_Filter0) && \ 03474 ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_CKABF) != 0U) && \ 03475 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_CKABIE) != 0U)) 03476 { 03477 uint32_t reg = 0U; 03478 uint32_t channel = 0U; 03479 03480 reg = ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_CKABF) >> DFSDM_FLTISR_CKABF_Pos); 03481 03482 while(channel < DFSDM2_CHANNEL_NUMBER) 03483 { 03484 /* Check if flag is set and corresponding channel is enabled */ 03485 if(((reg & 1U) != 0U) && (a_dfsdm2ChannelHandle[channel] != NULL)) 03486 { 03487 /* Check clock absence has been enabled for this channel */ 03488 if((a_dfsdm2ChannelHandle[channel]->Instance->CHCFGR1 & DFSDM_CHCFGR1_CKABEN) != 0U) 03489 { 03490 /* Clear clock absence flag */ 03491 hdfsdm_filter->Instance->FLTICR = (1U << (DFSDM_FLTICR_CLRCKABF_Pos + channel)); 03492 03493 /* Call clock absence callback */ 03494 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 03495 a_dfsdm2ChannelHandle[channel]->CkabCallback(a_dfsdm2ChannelHandle[channel]); 03496 #else 03497 HAL_DFSDM_ChannelCkabCallback(a_dfsdm2ChannelHandle[channel]); 03498 #endif 03499 } 03500 } 03501 channel++; 03502 reg = reg >> 1U; 03503 } 03504 } 03505 #endif /* DFSDM2_Channel0 */ 03506 /* Check if short circuit detection occurs */ 03507 else if((hdfsdm_filter->Instance == DFSDM1_Filter0) && \ 03508 ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_SCDF) != 0U) && \ 03509 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_SCDIE) != 0U)) 03510 { 03511 uint32_t reg = 0U; 03512 uint32_t channel = 0U; 03513 03514 /* Get channel */ 03515 reg = ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_SCDF) >> DFSDM_FLTISR_SCDF_Pos); 03516 while((reg & 1U) == 0U) 03517 { 03518 channel++; 03519 reg = reg >> 1U; 03520 } 03521 03522 /* Clear short circuit detection flag */ 03523 hdfsdm_filter->Instance->FLTICR = (1U << (DFSDM_FLTICR_CLRSCDF_Pos + channel)); 03524 03525 /* Call short circuit detection callback */ 03526 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 03527 a_dfsdm1ChannelHandle[channel]->ScdCallback(a_dfsdm1ChannelHandle[channel]); 03528 #else 03529 HAL_DFSDM_ChannelScdCallback(a_dfsdm1ChannelHandle[channel]); 03530 #endif 03531 } 03532 #if defined (DFSDM2_Channel0) 03533 /* Check if short circuit detection occurs */ 03534 else if((hdfsdm_filter->Instance == DFSDM2_Filter0) && \ 03535 ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_SCDF) != 0U) && \ 03536 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_SCDIE) != 0U)) 03537 { 03538 uint32_t reg = 0U; 03539 uint32_t channel = 0U; 03540 03541 /* Get channel */ 03542 reg = ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_SCDF) >> DFSDM_FLTISR_SCDF_Pos); 03543 while((reg & 1U) == 0U) 03544 { 03545 channel++; 03546 reg = reg >> 1U; 03547 } 03548 03549 /* Clear short circuit detection flag */ 03550 hdfsdm_filter->Instance->FLTICR = (1U << (DFSDM_FLTICR_CLRSCDF_Pos + channel)); 03551 03552 /* Call short circuit detection callback */ 03553 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 03554 a_dfsdm2ChannelHandle[channel]->ScdCallback(a_dfsdm2ChannelHandle[channel]); 03555 #else 03556 HAL_DFSDM_ChannelScdCallback(a_dfsdm2ChannelHandle[channel]); 03557 #endif 03558 } 03559 #endif /* DFSDM2_Channel0 */ 03560 } 03561 03562 /** 03563 * @brief Regular conversion complete callback. 03564 * @note In interrupt mode, user has to read conversion value in this function 03565 * using HAL_DFSDM_FilterGetRegularValue. 03566 * @param hdfsdm_filter DFSDM filter handle. 03567 * @retval None 03568 */ 03569 __weak void HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 03570 { 03571 /* Prevent unused argument(s) compilation warning */ 03572 UNUSED(hdfsdm_filter); 03573 /* NOTE : This function should not be modified, when the callback is needed, 03574 the HAL_DFSDM_FilterRegConvCpltCallback could be implemented in the user file. 03575 */ 03576 } 03577 03578 /** 03579 * @brief Half regular conversion complete callback. 03580 * @param hdfsdm_filter DFSDM filter handle. 03581 * @retval None 03582 */ 03583 __weak void HAL_DFSDM_FilterRegConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 03584 { 03585 /* Prevent unused argument(s) compilation warning */ 03586 UNUSED(hdfsdm_filter); 03587 /* NOTE : This function should not be modified, when the callback is needed, 03588 the HAL_DFSDM_FilterRegConvHalfCpltCallback could be implemented in the user file. 03589 */ 03590 } 03591 03592 /** 03593 * @brief Injected conversion complete callback. 03594 * @note In interrupt mode, user has to read conversion value in this function 03595 * using HAL_DFSDM_FilterGetInjectedValue. 03596 * @param hdfsdm_filter DFSDM filter handle. 03597 * @retval None 03598 */ 03599 __weak void HAL_DFSDM_FilterInjConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 03600 { 03601 /* Prevent unused argument(s) compilation warning */ 03602 UNUSED(hdfsdm_filter); 03603 /* NOTE : This function should not be modified, when the callback is needed, 03604 the HAL_DFSDM_FilterInjConvCpltCallback could be implemented in the user file. 03605 */ 03606 } 03607 03608 /** 03609 * @brief Half injected conversion complete callback. 03610 * @param hdfsdm_filter DFSDM filter handle. 03611 * @retval None 03612 */ 03613 __weak void HAL_DFSDM_FilterInjConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 03614 { 03615 /* Prevent unused argument(s) compilation warning */ 03616 UNUSED(hdfsdm_filter); 03617 /* NOTE : This function should not be modified, when the callback is needed, 03618 the HAL_DFSDM_FilterInjConvHalfCpltCallback could be implemented in the user file. 03619 */ 03620 } 03621 03622 /** 03623 * @brief Filter analog watchdog callback. 03624 * @param hdfsdm_filter DFSDM filter handle. 03625 * @param Channel Corresponding channel. 03626 * @param Threshold Low or high threshold has been reached. 03627 * @retval None 03628 */ 03629 __weak void HAL_DFSDM_FilterAwdCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, 03630 uint32_t Channel, uint32_t Threshold) 03631 { 03632 /* Prevent unused argument(s) compilation warning */ 03633 UNUSED(hdfsdm_filter); 03634 UNUSED(Channel); 03635 UNUSED(Threshold); 03636 03637 /* NOTE : This function should not be modified, when the callback is needed, 03638 the HAL_DFSDM_FilterAwdCallback could be implemented in the user file. 03639 */ 03640 } 03641 03642 /** 03643 * @brief Error callback. 03644 * @param hdfsdm_filter DFSDM filter handle. 03645 * @retval None 03646 */ 03647 __weak void HAL_DFSDM_FilterErrorCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 03648 { 03649 /* Prevent unused argument(s) compilation warning */ 03650 UNUSED(hdfsdm_filter); 03651 /* NOTE : This function should not be modified, when the callback is needed, 03652 the HAL_DFSDM_FilterErrorCallback could be implemented in the user file. 03653 */ 03654 } 03655 03656 /** 03657 * @} 03658 */ 03659 03660 /** @defgroup DFSDM_Exported_Functions_Group4_Filter Filter state functions 03661 * @brief Filter state functions 03662 * 03663 @verbatim 03664 ============================================================================== 03665 ##### Filter state functions ##### 03666 ============================================================================== 03667 [..] This section provides functions allowing to: 03668 (+) Get the DFSDM filter state. 03669 (+) Get the DFSDM filter error. 03670 @endverbatim 03671 * @{ 03672 */ 03673 03674 /** 03675 * @brief This function allows to get the current DFSDM filter handle state. 03676 * @param hdfsdm_filter DFSDM filter handle. 03677 * @retval DFSDM filter state. 03678 */ 03679 HAL_DFSDM_Filter_StateTypeDef HAL_DFSDM_FilterGetState(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 03680 { 03681 /* Return DFSDM filter handle state */ 03682 return hdfsdm_filter->State; 03683 } 03684 03685 /** 03686 * @brief This function allows to get the current DFSDM filter error. 03687 * @param hdfsdm_filter DFSDM filter handle. 03688 * @retval DFSDM filter error code. 03689 */ 03690 uint32_t HAL_DFSDM_FilterGetError(DFSDM_Filter_HandleTypeDef *hdfsdm_filter) 03691 { 03692 return hdfsdm_filter->ErrorCode; 03693 } 03694 03695 /** 03696 * @} 03697 */ 03698 03699 /** @defgroup DFSDM_Exported_Functions_Group5_Filter MultiChannel operation functions 03700 * @brief Filter state functions 03701 * 03702 @verbatim 03703 ============================================================================== 03704 ##### Filter MultiChannel operation functions ##### 03705 ============================================================================== 03706 [..] This section provides functions allowing to: 03707 (+) Control the DFSDM Multi channel delay block 03708 @endverbatim 03709 * @{ 03710 */ 03711 #if defined(SYSCFG_MCHDLYCR_BSCKSEL) 03712 /** 03713 * @brief Select the DFSDM2 as clock source for the bitstream clock. 03714 * @note The SYSCFG clock marco __HAL_RCC_SYSCFG_CLK_ENABLE() must be called 03715 * before HAL_DFSDM_BitstreamClock_Start() 03716 */ 03717 void HAL_DFSDM_BitstreamClock_Start(void) 03718 { 03719 uint32_t tmp = 0; 03720 03721 tmp = SYSCFG->MCHDLYCR; 03722 tmp = (tmp &(~SYSCFG_MCHDLYCR_BSCKSEL)); 03723 03724 SYSCFG->MCHDLYCR = (tmp|SYSCFG_MCHDLYCR_BSCKSEL); 03725 } 03726 03727 /** 03728 * @brief Stop the DFSDM2 as clock source for the bitstream clock. 03729 * @note The SYSCFG clock marco __HAL_RCC_SYSCFG_CLK_ENABLE() must be called 03730 * before HAL_DFSDM_BitstreamClock_Stop() 03731 * @retval None 03732 */ 03733 void HAL_DFSDM_BitstreamClock_Stop(void) 03734 { 03735 uint32_t tmp = 0U; 03736 03737 tmp = SYSCFG->MCHDLYCR; 03738 tmp = (tmp &(~SYSCFG_MCHDLYCR_BSCKSEL)); 03739 03740 SYSCFG->MCHDLYCR = tmp; 03741 } 03742 03743 /** 03744 * @brief Disable Delay Clock for DFSDM1/2. 03745 * @param MCHDLY HAL_MCHDLY_CLOCK_DFSDM2. 03746 * HAL_MCHDLY_CLOCK_DFSDM1. 03747 * @note The SYSCFG clock marco __HAL_RCC_SYSCFG_CLK_ENABLE() must be called 03748 * before HAL_DFSDM_DisableDelayClock() 03749 * @retval None 03750 */ 03751 void HAL_DFSDM_DisableDelayClock(uint32_t MCHDLY) 03752 { 03753 uint32_t tmp = 0U; 03754 03755 assert_param(IS_DFSDM_DELAY_CLOCK(MCHDLY)); 03756 03757 tmp = SYSCFG->MCHDLYCR; 03758 if(MCHDLY == HAL_MCHDLY_CLOCK_DFSDM2) 03759 { 03760 tmp = tmp &(~SYSCFG_MCHDLYCR_MCHDLY2EN); 03761 } 03762 else 03763 { 03764 tmp = tmp &(~SYSCFG_MCHDLYCR_MCHDLY1EN); 03765 } 03766 03767 SYSCFG->MCHDLYCR = tmp; 03768 } 03769 03770 /** 03771 * @brief Enable Delay Clock for DFSDM1/2. 03772 * @param MCHDLY HAL_MCHDLY_CLOCK_DFSDM2. 03773 * HAL_MCHDLY_CLOCK_DFSDM1. 03774 * @note The SYSCFG clock marco __HAL_RCC_SYSCFG_CLK_ENABLE() must be called 03775 * before HAL_DFSDM_EnableDelayClock() 03776 * @retval None 03777 */ 03778 void HAL_DFSDM_EnableDelayClock(uint32_t MCHDLY) 03779 { 03780 uint32_t tmp = 0U; 03781 03782 assert_param(IS_DFSDM_DELAY_CLOCK(MCHDLY)); 03783 03784 tmp = SYSCFG->MCHDLYCR; 03785 tmp = tmp & ~MCHDLY; 03786 03787 SYSCFG->MCHDLYCR = (tmp|MCHDLY); 03788 } 03789 03790 /** 03791 * @brief Select the source for CKin signals for DFSDM1/2. 03792 * @param source DFSDM2_CKIN_PAD. 03793 * DFSDM2_CKIN_DM. 03794 * DFSDM1_CKIN_PAD. 03795 * DFSDM1_CKIN_DM. 03796 * @retval None 03797 */ 03798 void HAL_DFSDM_ClockIn_SourceSelection(uint32_t source) 03799 { 03800 uint32_t tmp = 0U; 03801 03802 assert_param(IS_DFSDM_CLOCKIN_SELECTION(source)); 03803 03804 tmp = SYSCFG->MCHDLYCR; 03805 03806 if((source == HAL_DFSDM2_CKIN_PAD) || (source == HAL_DFSDM2_CKIN_DM)) 03807 { 03808 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM2CFG); 03809 03810 if(source == HAL_DFSDM2_CKIN_PAD) 03811 { 03812 source = 0x000000U; 03813 } 03814 } 03815 else 03816 { 03817 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM1CFG); 03818 } 03819 03820 SYSCFG->MCHDLYCR = (source|tmp); 03821 } 03822 03823 /** 03824 * @brief Select the source for CKOut signals for DFSDM1/2. 03825 * @param source: DFSDM2_CKOUT_DFSDM2. 03826 * DFSDM2_CKOUT_M27. 03827 * DFSDM1_CKOUT_DFSDM1. 03828 * DFSDM1_CKOUT_M27. 03829 * @retval None 03830 */ 03831 void HAL_DFSDM_ClockOut_SourceSelection(uint32_t source) 03832 { 03833 uint32_t tmp = 0U; 03834 03835 assert_param(IS_DFSDM_CLOCKOUT_SELECTION(source)); 03836 03837 tmp = SYSCFG->MCHDLYCR; 03838 03839 if((source == HAL_DFSDM2_CKOUT_DFSDM2) || (source == HAL_DFSDM2_CKOUT_M27)) 03840 { 03841 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM2CKOSEL); 03842 03843 if(source == HAL_DFSDM2_CKOUT_DFSDM2) 03844 { 03845 source = 0x000U; 03846 } 03847 } 03848 else 03849 { 03850 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM1CKOSEL); 03851 } 03852 03853 SYSCFG->MCHDLYCR = (source|tmp); 03854 } 03855 03856 /** 03857 * @brief Select the source for DataIn0 signals for DFSDM1/2. 03858 * @param source DATAIN0_DFSDM2_PAD. 03859 * DATAIN0_DFSDM2_DATAIN1. 03860 * DATAIN0_DFSDM1_PAD. 03861 * DATAIN0_DFSDM1_DATAIN1. 03862 * @retval None 03863 */ 03864 void HAL_DFSDM_DataIn0_SourceSelection(uint32_t source) 03865 { 03866 uint32_t tmp = 0U; 03867 03868 assert_param(IS_DFSDM_DATAIN0_SRC_SELECTION(source)); 03869 03870 tmp = SYSCFG->MCHDLYCR; 03871 03872 if((source == HAL_DATAIN0_DFSDM2_PAD)|| (source == HAL_DATAIN0_DFSDM2_DATAIN1)) 03873 { 03874 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM2D0SEL); 03875 if(source == HAL_DATAIN0_DFSDM2_PAD) 03876 { 03877 source = 0x00000U; 03878 } 03879 } 03880 else 03881 { 03882 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM1D0SEL); 03883 } 03884 SYSCFG->MCHDLYCR = (source|tmp); 03885 } 03886 03887 /** 03888 * @brief Select the source for DataIn2 signals for DFSDM1/2. 03889 * @param source DATAIN2_DFSDM2_PAD. 03890 * DATAIN2_DFSDM2_DATAIN3. 03891 * DATAIN2_DFSDM1_PAD. 03892 * DATAIN2_DFSDM1_DATAIN3. 03893 * @retval None 03894 */ 03895 void HAL_DFSDM_DataIn2_SourceSelection(uint32_t source) 03896 { 03897 uint32_t tmp = 0U; 03898 03899 assert_param(IS_DFSDM_DATAIN2_SRC_SELECTION(source)); 03900 03901 tmp = SYSCFG->MCHDLYCR; 03902 03903 if((source == HAL_DATAIN2_DFSDM2_PAD)|| (source == HAL_DATAIN2_DFSDM2_DATAIN3)) 03904 { 03905 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM2D2SEL); 03906 if (source == HAL_DATAIN2_DFSDM2_PAD) 03907 { 03908 source = 0x0000U; 03909 } 03910 } 03911 else 03912 { 03913 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM1D2SEL); 03914 } 03915 SYSCFG->MCHDLYCR = (source|tmp); 03916 } 03917 03918 /** 03919 * @brief Select the source for DataIn4 signals for DFSDM2. 03920 * @param source DATAIN4_DFSDM2_PAD. 03921 * DATAIN4_DFSDM2_DATAIN5 03922 * @retval None 03923 */ 03924 void HAL_DFSDM_DataIn4_SourceSelection(uint32_t source) 03925 { 03926 uint32_t tmp = 0U; 03927 03928 assert_param(IS_DFSDM_DATAIN4_SRC_SELECTION(source)); 03929 03930 tmp = SYSCFG->MCHDLYCR; 03931 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM2D4SEL); 03932 03933 SYSCFG->MCHDLYCR = (source|tmp); 03934 } 03935 03936 /** 03937 * @brief Select the source for DataIn6 signals for DFSDM2. 03938 * @param source DATAIN6_DFSDM2_PAD. 03939 * DATAIN6_DFSDM2_DATAIN7. 03940 * @retval None 03941 */ 03942 void HAL_DFSDM_DataIn6_SourceSelection(uint32_t source) 03943 { 03944 uint32_t tmp = 0U; 03945 03946 assert_param(IS_DFSDM_DATAIN6_SRC_SELECTION(source)); 03947 03948 tmp = SYSCFG->MCHDLYCR; 03949 03950 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM2D6SEL); 03951 03952 SYSCFG->MCHDLYCR = (source|tmp); 03953 } 03954 03955 /** 03956 * @brief Configure the distribution of the bitstream clock gated from TIM4_OC 03957 * for DFSDM1 or TIM3_OC for DFSDM2 03958 * @param source DFSDM1_CLKIN0_TIM4OC2 03959 * DFSDM1_CLKIN2_TIM4OC2 03960 * DFSDM1_CLKIN1_TIM4OC1 03961 * DFSDM1_CLKIN3_TIM4OC1 03962 * DFSDM2_CLKIN0_TIM3OC4 03963 * DFSDM2_CLKIN4_TIM3OC4 03964 * DFSDM2_CLKIN1_TIM3OC3 03965 * DFSDM2_CLKIN5_TIM3OC3 03966 * DFSDM2_CLKIN2_TIM3OC2 03967 * DFSDM2_CLKIN6_TIM3OC2 03968 * DFSDM2_CLKIN3_TIM3OC1 03969 * DFSDM2_CLKIN7_TIM3OC1 03970 * @retval None 03971 */ 03972 void HAL_DFSDM_BitStreamClkDistribution_Config(uint32_t source) 03973 { 03974 uint32_t tmp = 0U; 03975 03976 assert_param(IS_DFSDM_BITSTREM_CLK_DISTRIBUTION(source)); 03977 03978 tmp = SYSCFG->MCHDLYCR; 03979 03980 if ((source == HAL_DFSDM1_CLKIN0_TIM4OC2) || (source == HAL_DFSDM1_CLKIN2_TIM4OC2)) 03981 { 03982 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM1CK02SEL); 03983 } 03984 else if ((source == HAL_DFSDM1_CLKIN1_TIM4OC1) || (source == HAL_DFSDM1_CLKIN3_TIM4OC1)) 03985 { 03986 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM1CK13SEL); 03987 } 03988 else if ((source == HAL_DFSDM2_CLKIN0_TIM3OC4) || (source == HAL_DFSDM2_CLKIN4_TIM3OC4)) 03989 { 03990 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM2CK04SEL); 03991 } 03992 else if ((source == HAL_DFSDM2_CLKIN1_TIM3OC3) || (source == HAL_DFSDM2_CLKIN5_TIM3OC3)) 03993 { 03994 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM2CK15SEL); 03995 03996 }else if ((source == HAL_DFSDM2_CLKIN2_TIM3OC2) || (source == HAL_DFSDM2_CLKIN6_TIM3OC2)) 03997 { 03998 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM2CK26SEL); 03999 } 04000 else 04001 { 04002 tmp = (tmp & ~SYSCFG_MCHDLYCR_DFSDM2CK37SEL); 04003 } 04004 04005 if((source == HAL_DFSDM1_CLKIN0_TIM4OC2) ||(source == HAL_DFSDM1_CLKIN1_TIM4OC1)|| 04006 (source == HAL_DFSDM2_CLKIN0_TIM3OC4) ||(source == HAL_DFSDM2_CLKIN1_TIM3OC3)|| 04007 (source == HAL_DFSDM2_CLKIN2_TIM3OC2) ||(source == HAL_DFSDM2_CLKIN3_TIM3OC1)) 04008 { 04009 source = 0x0000U; 04010 } 04011 04012 SYSCFG->MCHDLYCR = (source|tmp); 04013 } 04014 04015 /** 04016 * @brief Configure multi channel delay block: Use DFSDM2 audio clock source as input 04017 * clock for DFSDM1 and DFSDM2 filters to Synchronize DFSDMx filters. 04018 * Set the path of the DFSDM2 clock output (dfsdm2_ckout) to the 04019 * DFSDM1/2 CkInx and data inputs channels by configuring following MCHDLY muxes 04020 * or demuxes: M1, M2, M3, M4, M5, M6, M7, M8, DM1, DM2, DM3, DM4, DM5, DM6, 04021 * M9, M10, M11, M12, M13, M14, M15, M16, M17, M18, M19, M20 based on the 04022 * contains of the DFSDM_MultiChannelConfigTypeDef structure 04023 * @param mchdlystruct Structure of multi channel configuration 04024 * @retval None 04025 * @note The SYSCFG clock marco __HAL_RCC_SYSCFG_CLK_ENABLE() must be called 04026 * before HAL_DFSDM_ConfigMultiChannelDelay() 04027 * @note The HAL_DFSDM_ConfigMultiChannelDelay() function clears the SYSCFG-MCHDLYCR 04028 * register before setting the new configuration. 04029 */ 04030 void HAL_DFSDM_ConfigMultiChannelDelay(DFSDM_MultiChannelConfigTypeDef* mchdlystruct) 04031 { 04032 uint32_t mchdlyreg = 0U; 04033 04034 assert_param(IS_DFSDM_DFSDM1_CLKOUT(mchdlystruct->DFSDM1ClockOut)); 04035 assert_param(IS_DFSDM_DFSDM2_CLKOUT(mchdlystruct->DFSDM2ClockOut)); 04036 assert_param(IS_DFSDM_DFSDM1_CLKIN(mchdlystruct->DFSDM1ClockIn)); 04037 assert_param(IS_DFSDM_DFSDM2_CLKIN(mchdlystruct->DFSDM2ClockIn)); 04038 assert_param(IS_DFSDM_DFSDM1_BIT_CLK((mchdlystruct->DFSDM1BitClkDistribution))); 04039 assert_param(IS_DFSDM_DFSDM2_BIT_CLK(mchdlystruct->DFSDM2BitClkDistribution)); 04040 assert_param(IS_DFSDM_DFSDM1_DATA_DISTRIBUTION(mchdlystruct->DFSDM1DataDistribution)); 04041 assert_param(IS_DFSDM_DFSDM2_DATA_DISTRIBUTION(mchdlystruct->DFSDM2DataDistribution)); 04042 04043 mchdlyreg = (SYSCFG->MCHDLYCR & 0x80103U); 04044 04045 SYSCFG->MCHDLYCR = (mchdlyreg |(mchdlystruct->DFSDM1ClockOut)|(mchdlystruct->DFSDM2ClockOut)| 04046 (mchdlystruct->DFSDM1ClockIn)|(mchdlystruct->DFSDM2ClockIn)| 04047 (mchdlystruct->DFSDM1BitClkDistribution)| (mchdlystruct->DFSDM2BitClkDistribution)| 04048 (mchdlystruct->DFSDM1DataDistribution)| (mchdlystruct->DFSDM2DataDistribution)); 04049 04050 } 04051 #endif /* SYSCFG_MCHDLYCR_BSCKSEL */ 04052 /** 04053 * @} 04054 */ 04055 /** 04056 * @} 04057 */ 04058 /* End of exported functions -------------------------------------------------*/ 04059 04060 /* Private functions ---------------------------------------------------------*/ 04061 /** @addtogroup DFSDM_Private_Functions DFSDM Private Functions 04062 * @{ 04063 */ 04064 04065 /** 04066 * @brief DMA half transfer complete callback for regular conversion. 04067 * @param hdma DMA handle. 04068 * @retval None 04069 */ 04070 static void DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef *hdma) 04071 { 04072 /* Get DFSDM filter handle */ 04073 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent; 04074 04075 /* Call regular half conversion complete callback */ 04076 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 04077 hdfsdm_filter->RegConvHalfCpltCallback(hdfsdm_filter); 04078 #else 04079 HAL_DFSDM_FilterRegConvHalfCpltCallback(hdfsdm_filter); 04080 #endif 04081 } 04082 04083 /** 04084 * @brief DMA transfer complete callback for regular conversion. 04085 * @param hdma DMA handle. 04086 * @retval None 04087 */ 04088 static void DFSDM_DMARegularConvCplt(DMA_HandleTypeDef *hdma) 04089 { 04090 /* Get DFSDM filter handle */ 04091 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent; 04092 04093 /* Call regular conversion complete callback */ 04094 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 04095 hdfsdm_filter->RegConvCpltCallback(hdfsdm_filter); 04096 #else 04097 HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter); 04098 #endif 04099 } 04100 04101 /** 04102 * @brief DMA half transfer complete callback for injected conversion. 04103 * @param hdma DMA handle. 04104 * @retval None 04105 */ 04106 static void DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef *hdma) 04107 { 04108 /* Get DFSDM filter handle */ 04109 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent; 04110 04111 /* Call injected half conversion complete callback */ 04112 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 04113 hdfsdm_filter->InjConvHalfCpltCallback(hdfsdm_filter); 04114 #else 04115 HAL_DFSDM_FilterInjConvHalfCpltCallback(hdfsdm_filter); 04116 #endif 04117 } 04118 04119 /** 04120 * @brief DMA transfer complete callback for injected conversion. 04121 * @param hdma DMA handle. 04122 * @retval None 04123 */ 04124 static void DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef *hdma) 04125 { 04126 /* Get DFSDM filter handle */ 04127 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent; 04128 04129 /* Call injected conversion complete callback */ 04130 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 04131 hdfsdm_filter->InjConvCpltCallback(hdfsdm_filter); 04132 #else 04133 HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter); 04134 #endif 04135 } 04136 04137 /** 04138 * @brief DMA error callback. 04139 * @param hdma DMA handle. 04140 * @retval None 04141 */ 04142 static void DFSDM_DMAError(DMA_HandleTypeDef *hdma) 04143 { 04144 /* Get DFSDM filter handle */ 04145 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent; 04146 04147 /* Update error code */ 04148 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_DMA; 04149 04150 /* Call error callback */ 04151 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1) 04152 hdfsdm_filter->ErrorCallback(hdfsdm_filter); 04153 #else 04154 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter); 04155 #endif 04156 } 04157 04158 /** 04159 * @brief This function allows to get the number of injected channels. 04160 * @param Channels bitfield of injected channels. 04161 * @retval Number of injected channels. 04162 */ 04163 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels) 04164 { 04165 uint32_t nbChannels = 0U; 04166 uint32_t tmp; 04167 04168 /* Get the number of channels from bitfield */ 04169 tmp = (uint32_t) (Channels & DFSDM_LSB_MASK); 04170 while(tmp != 0U) 04171 { 04172 if((tmp & 1U) != 0U) 04173 { 04174 nbChannels++; 04175 } 04176 tmp = (uint32_t) (tmp >> 1U); 04177 } 04178 return nbChannels; 04179 } 04180 04181 /** 04182 * @brief This function allows to get the channel number from channel instance. 04183 * @param Instance DFSDM channel instance. 04184 * @retval Channel number. 04185 */ 04186 static uint32_t DFSDM_GetChannelFromInstance(DFSDM_Channel_TypeDef* Instance) 04187 { 04188 uint32_t channel; 04189 04190 /* Get channel from instance */ 04191 #if defined(DFSDM2_Channel0) 04192 if((Instance == DFSDM1_Channel0) || (Instance == DFSDM2_Channel0)) 04193 { 04194 channel = 0U; 04195 } 04196 else if((Instance == DFSDM1_Channel1) || (Instance == DFSDM2_Channel1)) 04197 { 04198 channel = 1U; 04199 } 04200 else if((Instance == DFSDM1_Channel2) || (Instance == DFSDM2_Channel2)) 04201 { 04202 channel = 2U; 04203 } 04204 else if((Instance == DFSDM1_Channel3) || (Instance == DFSDM2_Channel3)) 04205 { 04206 channel = 3U; 04207 } 04208 else if(Instance == DFSDM2_Channel4) 04209 { 04210 channel = 4U; 04211 } 04212 else if(Instance == DFSDM2_Channel5) 04213 { 04214 channel = 5U; 04215 } 04216 else if(Instance == DFSDM2_Channel6) 04217 { 04218 channel = 6U; 04219 } 04220 else /* DFSDM2_Channel7 */ 04221 { 04222 channel = 7U; 04223 } 04224 04225 #else 04226 if(Instance == DFSDM1_Channel0) 04227 { 04228 channel = 0U; 04229 } 04230 else if(Instance == DFSDM1_Channel1) 04231 { 04232 channel = 1U; 04233 } 04234 else if(Instance == DFSDM1_Channel2) 04235 { 04236 channel = 2U; 04237 } 04238 else /* DFSDM1_Channel3 */ 04239 { 04240 channel = 3U; 04241 } 04242 #endif /* defined(DFSDM2_Channel0) */ 04243 04244 return channel; 04245 } 04246 04247 /** 04248 * @brief This function allows to really start regular conversion. 04249 * @param hdfsdm_filter DFSDM filter handle. 04250 * @retval None 04251 */ 04252 static void DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef* hdfsdm_filter) 04253 { 04254 /* Check regular trigger */ 04255 if(hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) 04256 { 04257 /* Software start of regular conversion */ 04258 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART; 04259 } 04260 else /* synchronous trigger */ 04261 { 04262 /* Disable DFSDM filter */ 04263 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN); 04264 04265 /* Set RSYNC bit in DFSDM_FLTCR1 register */ 04266 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSYNC; 04267 04268 /* Enable DFSDM filter */ 04269 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN; 04270 04271 /* If injected conversion was in progress, restart it */ 04272 if(hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) 04273 { 04274 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) 04275 { 04276 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART; 04277 } 04278 /* Update remaining injected conversions */ 04279 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \ 04280 hdfsdm_filter->InjectedChannelsNbr : 1U; 04281 } 04282 } 04283 /* Update DFSDM filter state */ 04284 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) ? \ 04285 HAL_DFSDM_FILTER_STATE_REG : HAL_DFSDM_FILTER_STATE_REG_INJ; 04286 } 04287 04288 /** 04289 * @brief This function allows to really stop regular conversion. 04290 * @param hdfsdm_filter DFSDM filter handle. 04291 * @retval None 04292 */ 04293 static void DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef* hdfsdm_filter) 04294 { 04295 /* Disable DFSDM filter */ 04296 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN); 04297 04298 /* If regular trigger was synchronous, reset RSYNC bit in DFSDM_FLTCR1 register */ 04299 if(hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SYNC_TRIGGER) 04300 { 04301 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RSYNC); 04302 } 04303 04304 /* Enable DFSDM filter */ 04305 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN; 04306 04307 /* If injected conversion was in progress, restart it */ 04308 if(hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG_INJ) 04309 { 04310 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) 04311 { 04312 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART; 04313 } 04314 /* Update remaining injected conversions */ 04315 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \ 04316 hdfsdm_filter->InjectedChannelsNbr : 1U; 04317 } 04318 04319 /* Update DFSDM filter state */ 04320 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \ 04321 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ; 04322 } 04323 04324 /** 04325 * @brief This function allows to really start injected conversion. 04326 * @param hdfsdm_filter DFSDM filter handle. 04327 * @retval None 04328 */ 04329 static void DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef* hdfsdm_filter) 04330 { 04331 /* Check injected trigger */ 04332 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) 04333 { 04334 /* Software start of injected conversion */ 04335 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART; 04336 } 04337 else /* external or synchronous trigger */ 04338 { 04339 /* Disable DFSDM filter */ 04340 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN); 04341 04342 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SYNC_TRIGGER) 04343 { 04344 /* Set JSYNC bit in DFSDM_FLTCR1 register */ 04345 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSYNC; 04346 } 04347 else /* external trigger */ 04348 { 04349 /* Set JEXTEN[1:0] bits in DFSDM_FLTCR1 register */ 04350 hdfsdm_filter->Instance->FLTCR1 |= hdfsdm_filter->ExtTriggerEdge; 04351 } 04352 04353 /* Enable DFSDM filter */ 04354 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN; 04355 04356 /* If regular conversion was in progress, restart it */ 04357 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) && \ 04358 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER)) 04359 { 04360 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART; 04361 } 04362 } 04363 /* Update DFSDM filter state */ 04364 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) ? \ 04365 HAL_DFSDM_FILTER_STATE_INJ : HAL_DFSDM_FILTER_STATE_REG_INJ; 04366 } 04367 04368 /** 04369 * @brief This function allows to really stop injected conversion. 04370 * @param hdfsdm_filter DFSDM filter handle. 04371 * @retval None 04372 */ 04373 static void DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef* hdfsdm_filter) 04374 { 04375 /* Disable DFSDM filter */ 04376 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN); 04377 04378 /* If injected trigger was synchronous, reset JSYNC bit in DFSDM_FLTCR1 register */ 04379 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SYNC_TRIGGER) 04380 { 04381 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSYNC); 04382 } 04383 else if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_EXT_TRIGGER) 04384 { 04385 /* Reset JEXTEN[1:0] bits in DFSDM_FLTCR1 register */ 04386 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JEXTEN); 04387 } 04388 04389 else 04390 { 04391 /* Nothing to do */ 04392 } 04393 /* Enable DFSDM filter */ 04394 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN; 04395 04396 /* If regular conversion was in progress, restart it */ 04397 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG_INJ) && \ 04398 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER)) 04399 { 04400 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART; 04401 } 04402 04403 /* Update remaining injected conversions */ 04404 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \ 04405 hdfsdm_filter->InjectedChannelsNbr : 1U; 04406 04407 /* Update DFSDM filter state */ 04408 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \ 04409 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG; 04410 } 04411 /** 04412 * @} 04413 */ 04414 /* End of private functions --------------------------------------------------*/ 04415 04416 /** 04417 * @} 04418 */ 04419 #endif /* STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */ 04420 #endif /* HAL_DFSDM_MODULE_ENABLED */ 04421 /** 04422 * @} 04423 */ 04424 04425 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/