TUKS MCU Introductory course / TUKS-COURSE-TIMER
Committer:
elmot
Date:
Fri Feb 24 21:13:56 2017 +0000
Revision:
1:d0dfbce63a89
Ready-to-copy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elmot 1:d0dfbce63a89 1 /**
elmot 1:d0dfbce63a89 2 ******************************************************************************
elmot 1:d0dfbce63a89 3 * @file stm32l4xx_hal_dfsdm.c
elmot 1:d0dfbce63a89 4 * @author MCD Application Team
elmot 1:d0dfbce63a89 5 * @version V1.5.1
elmot 1:d0dfbce63a89 6 * @date 31-May-2016
elmot 1:d0dfbce63a89 7 * @brief This file provides firmware functions to manage the following
elmot 1:d0dfbce63a89 8 * functionalities of the Digital Filter for Sigma-Delta Modulators
elmot 1:d0dfbce63a89 9 * (DFSDM) peripherals:
elmot 1:d0dfbce63a89 10 * + Initialization and configuration of channels and filters
elmot 1:d0dfbce63a89 11 * + Regular channels configuration
elmot 1:d0dfbce63a89 12 * + Injected channels configuration
elmot 1:d0dfbce63a89 13 * + Regular/Injected Channels DMA Configuration
elmot 1:d0dfbce63a89 14 * + Interrupts and flags management
elmot 1:d0dfbce63a89 15 * + Analog watchdog feature
elmot 1:d0dfbce63a89 16 * + Short-circuit detector feature
elmot 1:d0dfbce63a89 17 * + Extremes detector feature
elmot 1:d0dfbce63a89 18 * + Clock absence detector feature
elmot 1:d0dfbce63a89 19 * + Break generation on analog watchdog or short-circuit event
elmot 1:d0dfbce63a89 20 *
elmot 1:d0dfbce63a89 21 @verbatim
elmot 1:d0dfbce63a89 22 ==============================================================================
elmot 1:d0dfbce63a89 23 ##### How to use this driver #####
elmot 1:d0dfbce63a89 24 ==============================================================================
elmot 1:d0dfbce63a89 25 [..]
elmot 1:d0dfbce63a89 26 *** Channel initialization ***
elmot 1:d0dfbce63a89 27 ==============================
elmot 1:d0dfbce63a89 28 [..]
elmot 1:d0dfbce63a89 29 (#) User has first to initialize channels (before filters initialization).
elmot 1:d0dfbce63a89 30 (#) As prerequisite, fill in the HAL_DFSDM_ChannelMspInit() :
elmot 1:d0dfbce63a89 31 (++) Enable DFSDMz clock interface with __HAL_RCC_DFSDMz_CLK_ENABLE().
elmot 1:d0dfbce63a89 32 (++) Enable the clocks for the DFSDMz GPIOS with __HAL_RCC_GPIOx_CLK_ENABLE().
elmot 1:d0dfbce63a89 33 (++) Configure these DFSDMz pins in alternate mode using HAL_GPIO_Init().
elmot 1:d0dfbce63a89 34 (++) If interrupt mode is used, enable and configure DFSDMz_FLT0 global
elmot 1:d0dfbce63a89 35 interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
elmot 1:d0dfbce63a89 36 (#) Configure the output clock, input, serial interface, analog watchdog,
elmot 1:d0dfbce63a89 37 offset and data right bit shift parameters for this channel using the
elmot 1:d0dfbce63a89 38 HAL_DFSDM_ChannelInit() function.
elmot 1:d0dfbce63a89 39
elmot 1:d0dfbce63a89 40 *** Channel clock absence detector ***
elmot 1:d0dfbce63a89 41 ======================================
elmot 1:d0dfbce63a89 42 [..]
elmot 1:d0dfbce63a89 43 (#) Start clock absence detector using HAL_DFSDM_ChannelCkabStart() or
elmot 1:d0dfbce63a89 44 HAL_DFSDM_ChannelCkabStart_IT().
elmot 1:d0dfbce63a89 45 (#) In polling mode, use HAL_DFSDM_ChannelPollForCkab() to detect the clock
elmot 1:d0dfbce63a89 46 absence.
elmot 1:d0dfbce63a89 47 (#) In interrupt mode, HAL_DFSDM_ChannelCkabCallback() will be called if
elmot 1:d0dfbce63a89 48 clock absence is detected.
elmot 1:d0dfbce63a89 49 (#) Stop clock absence detector using HAL_DFSDM_ChannelCkabStop() or
elmot 1:d0dfbce63a89 50 HAL_DFSDM_ChannelCkabStop_IT().
elmot 1:d0dfbce63a89 51 (#) Please note that the same mode (polling or interrupt) has to be used
elmot 1:d0dfbce63a89 52 for all channels because the channels are sharing the same interrupt.
elmot 1:d0dfbce63a89 53 (#) Please note also that in interrupt mode, if clock absence detector is
elmot 1:d0dfbce63a89 54 stopped for one channel, interrupt will be disabled for all channels.
elmot 1:d0dfbce63a89 55
elmot 1:d0dfbce63a89 56 *** Channel short circuit detector ***
elmot 1:d0dfbce63a89 57 ======================================
elmot 1:d0dfbce63a89 58 [..]
elmot 1:d0dfbce63a89 59 (#) Start short circuit detector using HAL_DFSDM_ChannelScdStart() or
elmot 1:d0dfbce63a89 60 or HAL_DFSDM_ChannelScdStart_IT().
elmot 1:d0dfbce63a89 61 (#) In polling mode, use HAL_DFSDM_ChannelPollForScd() to detect short
elmot 1:d0dfbce63a89 62 circuit.
elmot 1:d0dfbce63a89 63 (#) In interrupt mode, HAL_DFSDM_ChannelScdCallback() will be called if
elmot 1:d0dfbce63a89 64 short circuit is detected.
elmot 1:d0dfbce63a89 65 (#) Stop short circuit detector using HAL_DFSDM_ChannelScdStop() or
elmot 1:d0dfbce63a89 66 or HAL_DFSDM_ChannelScdStop_IT().
elmot 1:d0dfbce63a89 67 (#) Please note that the same mode (polling or interrupt) has to be used
elmot 1:d0dfbce63a89 68 for all channels because the channels are sharing the same interrupt.
elmot 1:d0dfbce63a89 69 (#) Please note also that in interrupt mode, if short circuit detector is
elmot 1:d0dfbce63a89 70 stopped for one channel, interrupt will be disabled for all channels.
elmot 1:d0dfbce63a89 71
elmot 1:d0dfbce63a89 72 *** Channel analog watchdog value ***
elmot 1:d0dfbce63a89 73 =====================================
elmot 1:d0dfbce63a89 74 [..]
elmot 1:d0dfbce63a89 75 (#) Get analog watchdog filter value of a channel using
elmot 1:d0dfbce63a89 76 HAL_DFSDM_ChannelGetAwdValue().
elmot 1:d0dfbce63a89 77
elmot 1:d0dfbce63a89 78 *** Channel offset value ***
elmot 1:d0dfbce63a89 79 =====================================
elmot 1:d0dfbce63a89 80 [..]
elmot 1:d0dfbce63a89 81 (#) Modify offset value of a channel using HAL_DFSDM_ChannelModifyOffset().
elmot 1:d0dfbce63a89 82
elmot 1:d0dfbce63a89 83 *** Filter initialization ***
elmot 1:d0dfbce63a89 84 =============================
elmot 1:d0dfbce63a89 85 [..]
elmot 1:d0dfbce63a89 86 (#) After channel initialization, user has to init filters.
elmot 1:d0dfbce63a89 87 (#) As prerequisite, fill in the HAL_DFSDM_FilterMspInit() :
elmot 1:d0dfbce63a89 88 (++) If interrupt mode is used , enable and configure DFSDMz_FLTx global
elmot 1:d0dfbce63a89 89 interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
elmot 1:d0dfbce63a89 90 Please note that DFSDMz_FLT0 global interrupt could be already
elmot 1:d0dfbce63a89 91 enabled if interrupt is used for channel.
elmot 1:d0dfbce63a89 92 (++) If DMA mode is used, configure DMA with HAL_DMA_Init() and link it
elmot 1:d0dfbce63a89 93 with DFSDMz filter handle using __HAL_LINKDMA().
elmot 1:d0dfbce63a89 94 (#) Configure the regular conversion, injected conversion and filter
elmot 1:d0dfbce63a89 95 parameters for this filter using the HAL_DFSDM_FilterInit() function.
elmot 1:d0dfbce63a89 96
elmot 1:d0dfbce63a89 97 *** Filter regular channel conversion ***
elmot 1:d0dfbce63a89 98 =========================================
elmot 1:d0dfbce63a89 99 [..]
elmot 1:d0dfbce63a89 100 (#) Select regular channel and enable/disable continuous mode using
elmot 1:d0dfbce63a89 101 HAL_DFSDM_FilterConfigRegChannel().
elmot 1:d0dfbce63a89 102 (#) Start regular conversion using HAL_DFSDM_FilterRegularStart(),
elmot 1:d0dfbce63a89 103 HAL_DFSDM_FilterRegularStart_IT(), HAL_DFSDM_FilterRegularStart_DMA() or
elmot 1:d0dfbce63a89 104 HAL_DFSDM_FilterRegularMsbStart_DMA().
elmot 1:d0dfbce63a89 105 (#) In polling mode, use HAL_DFSDM_FilterPollForRegConversion() to detect
elmot 1:d0dfbce63a89 106 the end of regular conversion.
elmot 1:d0dfbce63a89 107 (#) In interrupt mode, HAL_DFSDM_FilterRegConvCpltCallback() will be called
elmot 1:d0dfbce63a89 108 at the end of regular conversion.
elmot 1:d0dfbce63a89 109 (#) Get value of regular conversion and corresponding channel using
elmot 1:d0dfbce63a89 110 HAL_DFSDM_FilterGetRegularValue().
elmot 1:d0dfbce63a89 111 (#) In DMA mode, HAL_DFSDM_FilterRegConvHalfCpltCallback() and
elmot 1:d0dfbce63a89 112 HAL_DFSDM_FilterRegConvCpltCallback() will be called respectively at the
elmot 1:d0dfbce63a89 113 half transfer and at the transfer complete. Please note that
elmot 1:d0dfbce63a89 114 HAL_DFSDM_FilterRegConvHalfCpltCallback() will be called only in DMA
elmot 1:d0dfbce63a89 115 circular mode.
elmot 1:d0dfbce63a89 116 (#) Stop regular conversion using HAL_DFSDM_FilterRegularStop(),
elmot 1:d0dfbce63a89 117 HAL_DFSDM_FilterRegularStop_IT() or HAL_DFSDM_FilterRegularStop_DMA().
elmot 1:d0dfbce63a89 118
elmot 1:d0dfbce63a89 119 *** Filter injected channels conversion ***
elmot 1:d0dfbce63a89 120 ===========================================
elmot 1:d0dfbce63a89 121 [..]
elmot 1:d0dfbce63a89 122 (#) Select injected channels using HAL_DFSDM_FilterConfigInjChannel().
elmot 1:d0dfbce63a89 123 (#) Start injected conversion using HAL_DFSDM_FilterInjectedStart(),
elmot 1:d0dfbce63a89 124 HAL_DFSDM_FilterInjectedStart_IT(), HAL_DFSDM_FilterInjectedStart_DMA() or
elmot 1:d0dfbce63a89 125 HAL_DFSDM_FilterInjectedMsbStart_DMA().
elmot 1:d0dfbce63a89 126 (#) In polling mode, use HAL_DFSDM_FilterPollForInjConversion() to detect
elmot 1:d0dfbce63a89 127 the end of injected conversion.
elmot 1:d0dfbce63a89 128 (#) In interrupt mode, HAL_DFSDM_FilterInjConvCpltCallback() will be called
elmot 1:d0dfbce63a89 129 at the end of injected conversion.
elmot 1:d0dfbce63a89 130 (#) Get value of injected conversion and corresponding channel using
elmot 1:d0dfbce63a89 131 HAL_DFSDM_FilterGetInjectedValue().
elmot 1:d0dfbce63a89 132 (#) In DMA mode, HAL_DFSDM_FilterInjConvHalfCpltCallback() and
elmot 1:d0dfbce63a89 133 HAL_DFSDM_FilterInjConvCpltCallback() will be called respectively at the
elmot 1:d0dfbce63a89 134 half transfer and at the transfer complete. Please note that
elmot 1:d0dfbce63a89 135 HAL_DFSDM_FilterInjConvCpltCallback() will be called only in DMA
elmot 1:d0dfbce63a89 136 circular mode.
elmot 1:d0dfbce63a89 137 (#) Stop injected conversion using HAL_DFSDM_FilterInjectedStop(),
elmot 1:d0dfbce63a89 138 HAL_DFSDM_FilterInjectedStop_IT() or HAL_DFSDM_FilterInjectedStop_DMA().
elmot 1:d0dfbce63a89 139
elmot 1:d0dfbce63a89 140 *** Filter analog watchdog ***
elmot 1:d0dfbce63a89 141 ==============================
elmot 1:d0dfbce63a89 142 [..]
elmot 1:d0dfbce63a89 143 (#) Start filter analog watchdog using HAL_DFSDM_FilterAwdStart_IT().
elmot 1:d0dfbce63a89 144 (#) HAL_DFSDM_FilterAwdCallback() will be called if analog watchdog occurs.
elmot 1:d0dfbce63a89 145 (#) Stop filter analog watchdog using HAL_DFSDM_FilterAwdStop_IT().
elmot 1:d0dfbce63a89 146
elmot 1:d0dfbce63a89 147 *** Filter extreme detector ***
elmot 1:d0dfbce63a89 148 ===============================
elmot 1:d0dfbce63a89 149 [..]
elmot 1:d0dfbce63a89 150 (#) Start filter extreme detector using HAL_DFSDM_FilterExdStart().
elmot 1:d0dfbce63a89 151 (#) Get extreme detector maximum value using HAL_DFSDM_FilterGetExdMaxValue().
elmot 1:d0dfbce63a89 152 (#) Get extreme detector minimum value using HAL_DFSDM_FilterGetExdMinValue().
elmot 1:d0dfbce63a89 153 (#) Start filter extreme detector using HAL_DFSDM_FilterExdStop().
elmot 1:d0dfbce63a89 154
elmot 1:d0dfbce63a89 155 *** Filter conversion time ***
elmot 1:d0dfbce63a89 156 ==============================
elmot 1:d0dfbce63a89 157 [..]
elmot 1:d0dfbce63a89 158 (#) Get conversion time value using HAL_DFSDM_FilterGetConvTimeValue().
elmot 1:d0dfbce63a89 159
elmot 1:d0dfbce63a89 160 @endverbatim
elmot 1:d0dfbce63a89 161 ******************************************************************************
elmot 1:d0dfbce63a89 162 * @attention
elmot 1:d0dfbce63a89 163 *
elmot 1:d0dfbce63a89 164 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
elmot 1:d0dfbce63a89 165 *
elmot 1:d0dfbce63a89 166 * Redistribution and use in source and binary forms, with or without modification,
elmot 1:d0dfbce63a89 167 * are permitted provided that the following conditions are met:
elmot 1:d0dfbce63a89 168 * 1. Redistributions of source code must retain the above copyright notice,
elmot 1:d0dfbce63a89 169 * this list of conditions and the following disclaimer.
elmot 1:d0dfbce63a89 170 * 2. Redistributions in binary form must reproduce the above copyright notice,
elmot 1:d0dfbce63a89 171 * this list of conditions and the following disclaimer in the documentation
elmot 1:d0dfbce63a89 172 * and/or other materials provided with the distribution.
elmot 1:d0dfbce63a89 173 * 3. Neither the name of STMicroelectronics nor the names of its contributors
elmot 1:d0dfbce63a89 174 * may be used to endorse or promote products derived from this software
elmot 1:d0dfbce63a89 175 * without specific prior written permission.
elmot 1:d0dfbce63a89 176 *
elmot 1:d0dfbce63a89 177 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
elmot 1:d0dfbce63a89 178 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
elmot 1:d0dfbce63a89 179 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
elmot 1:d0dfbce63a89 180 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
elmot 1:d0dfbce63a89 181 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
elmot 1:d0dfbce63a89 182 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
elmot 1:d0dfbce63a89 183 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
elmot 1:d0dfbce63a89 184 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
elmot 1:d0dfbce63a89 185 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
elmot 1:d0dfbce63a89 186 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
elmot 1:d0dfbce63a89 187 *
elmot 1:d0dfbce63a89 188 ******************************************************************************
elmot 1:d0dfbce63a89 189 */
elmot 1:d0dfbce63a89 190
elmot 1:d0dfbce63a89 191 /* Includes ------------------------------------------------------------------*/
elmot 1:d0dfbce63a89 192 #include "stm32l4xx_hal.h"
elmot 1:d0dfbce63a89 193
elmot 1:d0dfbce63a89 194 /** @addtogroup STM32L4xx_HAL_Driver
elmot 1:d0dfbce63a89 195 * @{
elmot 1:d0dfbce63a89 196 */
elmot 1:d0dfbce63a89 197 #ifdef HAL_DFSDM_MODULE_ENABLED
elmot 1:d0dfbce63a89 198 #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx)
elmot 1:d0dfbce63a89 199 /** @defgroup DFSDM DFSDM
elmot 1:d0dfbce63a89 200 * @brief DFSDM HAL driver module
elmot 1:d0dfbce63a89 201 * @{
elmot 1:d0dfbce63a89 202 */
elmot 1:d0dfbce63a89 203
elmot 1:d0dfbce63a89 204 /* Private typedef -----------------------------------------------------------*/
elmot 1:d0dfbce63a89 205 /* Private define ------------------------------------------------------------*/
elmot 1:d0dfbce63a89 206 /** @defgroup DFSDM_Private_Define DFSDM Private Define
elmot 1:d0dfbce63a89 207 * @{
elmot 1:d0dfbce63a89 208 */
elmot 1:d0dfbce63a89 209 #define DFSDM_CHCFGR1_CLK_DIV_OFFSET POSITION_VAL(DFSDM_CHCFGR1_CKOUTDIV)
elmot 1:d0dfbce63a89 210 #define DFSDM_CHAWSCDR_BKSCD_OFFSET POSITION_VAL(DFSDM_CHAWSCDR_BKSCD)
elmot 1:d0dfbce63a89 211 #define DFSDM_CHAWSCDR_FOSR_OFFSET POSITION_VAL(DFSDM_CHAWSCDR_AWFOSR)
elmot 1:d0dfbce63a89 212 #define DFSDM_CHCFGR2_OFFSET_OFFSET POSITION_VAL(DFSDM_CHCFGR2_OFFSET)
elmot 1:d0dfbce63a89 213 #define DFSDM_CHCFGR2_DTRBS_OFFSET POSITION_VAL(DFSDM_CHCFGR2_DTRBS)
elmot 1:d0dfbce63a89 214 #define DFSDM_FLTFCR_FOSR_OFFSET POSITION_VAL(DFSDM_FLTFCR_FOSR)
elmot 1:d0dfbce63a89 215 #define DFSDM_FLTCR1_MSB_RCH_OFFSET 8
elmot 1:d0dfbce63a89 216 #define DFSDM_FLTCR2_EXCH_OFFSET POSITION_VAL(DFSDM_FLTCR2_EXCH)
elmot 1:d0dfbce63a89 217 #define DFSDM_FLTCR2_AWDCH_OFFSET POSITION_VAL(DFSDM_FLTCR2_AWDCH)
elmot 1:d0dfbce63a89 218 #define DFSDM_FLTISR_CKABF_OFFSET POSITION_VAL(DFSDM_FLTISR_CKABF)
elmot 1:d0dfbce63a89 219 #define DFSDM_FLTISR_SCDF_OFFSET POSITION_VAL(DFSDM_FLTISR_SCDF)
elmot 1:d0dfbce63a89 220 #define DFSDM_FLTICR_CLRCKABF_OFFSET POSITION_VAL(DFSDM_FLTICR_CLRCKABF)
elmot 1:d0dfbce63a89 221 #define DFSDM_FLTICR_CLRSCDF_OFFSET POSITION_VAL(DFSDM_FLTICR_CLRSCSDF)
elmot 1:d0dfbce63a89 222 #define DFSDM_FLTRDATAR_DATA_OFFSET POSITION_VAL(DFSDM_FLTRDATAR_RDATA)
elmot 1:d0dfbce63a89 223 #define DFSDM_FLTJDATAR_DATA_OFFSET POSITION_VAL(DFSDM_FLTJDATAR_JDATA)
elmot 1:d0dfbce63a89 224 #define DFSDM_FLTAWHTR_THRESHOLD_OFFSET POSITION_VAL(DFSDM_FLTAWHTR_AWHT)
elmot 1:d0dfbce63a89 225 #define DFSDM_FLTAWLTR_THRESHOLD_OFFSET POSITION_VAL(DFSDM_FLTAWLTR_AWLT)
elmot 1:d0dfbce63a89 226 #define DFSDM_FLTEXMAX_DATA_OFFSET POSITION_VAL(DFSDM_FLTEXMAX_EXMAX)
elmot 1:d0dfbce63a89 227 #define DFSDM_FLTEXMIN_DATA_OFFSET POSITION_VAL(DFSDM_FLTEXMIN_EXMIN)
elmot 1:d0dfbce63a89 228 #define DFSDM_FLTCNVTIMR_DATA_OFFSET POSITION_VAL(DFSDM_FLTCNVTIMR_CNVCNT)
elmot 1:d0dfbce63a89 229 #define DFSDM_FLTAWSR_HIGH_OFFSET POSITION_VAL(DFSDM_FLTAWSR_AWHTF)
elmot 1:d0dfbce63a89 230 #define DFSDM_MSB_MASK 0xFFFF0000U
elmot 1:d0dfbce63a89 231 #define DFSDM_LSB_MASK 0x0000FFFFU
elmot 1:d0dfbce63a89 232 #define DFSDM_CKAB_TIMEOUT 5000U
elmot 1:d0dfbce63a89 233 #define DFSDM1_CHANNEL_NUMBER 8U
elmot 1:d0dfbce63a89 234 /**
elmot 1:d0dfbce63a89 235 * @}
elmot 1:d0dfbce63a89 236 */
elmot 1:d0dfbce63a89 237
elmot 1:d0dfbce63a89 238 /* Private macro -------------------------------------------------------------*/
elmot 1:d0dfbce63a89 239 /* Private variables ---------------------------------------------------------*/
elmot 1:d0dfbce63a89 240 /** @defgroup DFSDM_Private_Variables DFSDM Private Variables
elmot 1:d0dfbce63a89 241 * @{
elmot 1:d0dfbce63a89 242 */
elmot 1:d0dfbce63a89 243 __IO uint32_t v_dfsdm1ChannelCounter = 0;
elmot 1:d0dfbce63a89 244 DFSDM_Channel_HandleTypeDef* a_dfsdm1ChannelHandle[DFSDM1_CHANNEL_NUMBER] = {NULL};
elmot 1:d0dfbce63a89 245 /**
elmot 1:d0dfbce63a89 246 * @}
elmot 1:d0dfbce63a89 247 */
elmot 1:d0dfbce63a89 248
elmot 1:d0dfbce63a89 249 /* Private function prototypes -----------------------------------------------*/
elmot 1:d0dfbce63a89 250 /** @defgroup DFSDM_Private_Functions DFSDM Private Functions
elmot 1:d0dfbce63a89 251 * @{
elmot 1:d0dfbce63a89 252 */
elmot 1:d0dfbce63a89 253 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels);
elmot 1:d0dfbce63a89 254 static uint32_t DFSDM_GetChannelFromInstance(DFSDM_Channel_TypeDef* Instance);
elmot 1:d0dfbce63a89 255 static void DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
elmot 1:d0dfbce63a89 256 static void DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef* hdfsdm_filter);
elmot 1:d0dfbce63a89 257 static void DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef* hdfsdm_filter);
elmot 1:d0dfbce63a89 258 static void DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef* hdfsdm_filter);
elmot 1:d0dfbce63a89 259 static void DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef *hdma);
elmot 1:d0dfbce63a89 260 static void DFSDM_DMARegularConvCplt(DMA_HandleTypeDef *hdma);
elmot 1:d0dfbce63a89 261 static void DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef *hdma);
elmot 1:d0dfbce63a89 262 static void DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef *hdma);
elmot 1:d0dfbce63a89 263 static void DFSDM_DMAError(DMA_HandleTypeDef *hdma);
elmot 1:d0dfbce63a89 264 /**
elmot 1:d0dfbce63a89 265 * @}
elmot 1:d0dfbce63a89 266 */
elmot 1:d0dfbce63a89 267
elmot 1:d0dfbce63a89 268 /* Exported functions --------------------------------------------------------*/
elmot 1:d0dfbce63a89 269 /** @defgroup DFSDM_Exported_Functions DFSDM Exported Functions
elmot 1:d0dfbce63a89 270 * @{
elmot 1:d0dfbce63a89 271 */
elmot 1:d0dfbce63a89 272
elmot 1:d0dfbce63a89 273 /** @defgroup DFSDM_Exported_Functions_Group1_Channel Channel initialization and de-initialization functions
elmot 1:d0dfbce63a89 274 * @brief Channel initialization and de-initialization functions
elmot 1:d0dfbce63a89 275 *
elmot 1:d0dfbce63a89 276 @verbatim
elmot 1:d0dfbce63a89 277 ==============================================================================
elmot 1:d0dfbce63a89 278 ##### Channel initialization and de-initialization functions #####
elmot 1:d0dfbce63a89 279 ==============================================================================
elmot 1:d0dfbce63a89 280 [..] This section provides functions allowing to:
elmot 1:d0dfbce63a89 281 (+) Initialize the DFSDM channel.
elmot 1:d0dfbce63a89 282 (+) De-initialize the DFSDM channel.
elmot 1:d0dfbce63a89 283 @endverbatim
elmot 1:d0dfbce63a89 284 * @{
elmot 1:d0dfbce63a89 285 */
elmot 1:d0dfbce63a89 286
elmot 1:d0dfbce63a89 287 /**
elmot 1:d0dfbce63a89 288 * @brief Initialize the DFSDM channel according to the specified parameters
elmot 1:d0dfbce63a89 289 * in the DFSDM_ChannelInitTypeDef structure and initialize the associated handle.
elmot 1:d0dfbce63a89 290 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 291 * @retval HAL status.
elmot 1:d0dfbce63a89 292 */
elmot 1:d0dfbce63a89 293 HAL_StatusTypeDef HAL_DFSDM_ChannelInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 294 {
elmot 1:d0dfbce63a89 295 /* Check DFSDM Channel handle */
elmot 1:d0dfbce63a89 296 if(hdfsdm_channel == NULL)
elmot 1:d0dfbce63a89 297 {
elmot 1:d0dfbce63a89 298 return HAL_ERROR;
elmot 1:d0dfbce63a89 299 }
elmot 1:d0dfbce63a89 300
elmot 1:d0dfbce63a89 301 /* Check parameters */
elmot 1:d0dfbce63a89 302 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
elmot 1:d0dfbce63a89 303 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_channel->Init.OutputClock.Activation));
elmot 1:d0dfbce63a89 304 assert_param(IS_DFSDM_CHANNEL_INPUT(hdfsdm_channel->Init.Input.Multiplexer));
elmot 1:d0dfbce63a89 305 assert_param(IS_DFSDM_CHANNEL_DATA_PACKING(hdfsdm_channel->Init.Input.DataPacking));
elmot 1:d0dfbce63a89 306 assert_param(IS_DFSDM_CHANNEL_INPUT_PINS(hdfsdm_channel->Init.Input.Pins));
elmot 1:d0dfbce63a89 307 assert_param(IS_DFSDM_CHANNEL_SERIAL_INTERFACE_TYPE(hdfsdm_channel->Init.SerialInterface.Type));
elmot 1:d0dfbce63a89 308 assert_param(IS_DFSDM_CHANNEL_SPI_CLOCK(hdfsdm_channel->Init.SerialInterface.SpiClock));
elmot 1:d0dfbce63a89 309 assert_param(IS_DFSDM_CHANNEL_FILTER_ORDER(hdfsdm_channel->Init.Awd.FilterOrder));
elmot 1:d0dfbce63a89 310 assert_param(IS_DFSDM_CHANNEL_FILTER_OVS_RATIO(hdfsdm_channel->Init.Awd.Oversampling));
elmot 1:d0dfbce63a89 311 assert_param(IS_DFSDM_CHANNEL_OFFSET(hdfsdm_channel->Init.Offset));
elmot 1:d0dfbce63a89 312 assert_param(IS_DFSDM_CHANNEL_RIGHT_BIT_SHIFT(hdfsdm_channel->Init.RightBitShift));
elmot 1:d0dfbce63a89 313
elmot 1:d0dfbce63a89 314 /* Check that channel has not been already initialized */
elmot 1:d0dfbce63a89 315 if(a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] != NULL)
elmot 1:d0dfbce63a89 316 {
elmot 1:d0dfbce63a89 317 return HAL_ERROR;
elmot 1:d0dfbce63a89 318 }
elmot 1:d0dfbce63a89 319
elmot 1:d0dfbce63a89 320 /* Call MSP init function */
elmot 1:d0dfbce63a89 321 HAL_DFSDM_ChannelMspInit(hdfsdm_channel);
elmot 1:d0dfbce63a89 322
elmot 1:d0dfbce63a89 323 /* Update the channel counter */
elmot 1:d0dfbce63a89 324 v_dfsdm1ChannelCounter++;
elmot 1:d0dfbce63a89 325
elmot 1:d0dfbce63a89 326 /* Configure output serial clock and enable global DFSDM interface only for first channel */
elmot 1:d0dfbce63a89 327 if(v_dfsdm1ChannelCounter == 1)
elmot 1:d0dfbce63a89 328 {
elmot 1:d0dfbce63a89 329 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK(hdfsdm_channel->Init.OutputClock.Selection));
elmot 1:d0dfbce63a89 330 /* Set the output serial clock source */
elmot 1:d0dfbce63a89 331 DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTSRC);
elmot 1:d0dfbce63a89 332 DFSDM1_Channel0->CHCFGR1 |= hdfsdm_channel->Init.OutputClock.Selection;
elmot 1:d0dfbce63a89 333
elmot 1:d0dfbce63a89 334 /* Reset clock divider */
elmot 1:d0dfbce63a89 335 DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTDIV);
elmot 1:d0dfbce63a89 336 if(hdfsdm_channel->Init.OutputClock.Activation == ENABLE)
elmot 1:d0dfbce63a89 337 {
elmot 1:d0dfbce63a89 338 assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK_DIVIDER(hdfsdm_channel->Init.OutputClock.Divider));
elmot 1:d0dfbce63a89 339 /* Set the output clock divider */
elmot 1:d0dfbce63a89 340 DFSDM1_Channel0->CHCFGR1 |= (uint32_t) ((hdfsdm_channel->Init.OutputClock.Divider - 1) <<
elmot 1:d0dfbce63a89 341 DFSDM_CHCFGR1_CLK_DIV_OFFSET);
elmot 1:d0dfbce63a89 342 }
elmot 1:d0dfbce63a89 343
elmot 1:d0dfbce63a89 344 /* enable the DFSDM global interface */
elmot 1:d0dfbce63a89 345 DFSDM1_Channel0->CHCFGR1 |= DFSDM_CHCFGR1_DFSDMEN;
elmot 1:d0dfbce63a89 346 }
elmot 1:d0dfbce63a89 347
elmot 1:d0dfbce63a89 348 /* Set channel input parameters */
elmot 1:d0dfbce63a89 349 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_DATPACK | DFSDM_CHCFGR1_DATMPX |
elmot 1:d0dfbce63a89 350 DFSDM_CHCFGR1_CHINSEL);
elmot 1:d0dfbce63a89 351 hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.Input.Multiplexer |
elmot 1:d0dfbce63a89 352 hdfsdm_channel->Init.Input.DataPacking |
elmot 1:d0dfbce63a89 353 hdfsdm_channel->Init.Input.Pins);
elmot 1:d0dfbce63a89 354
elmot 1:d0dfbce63a89 355 /* Set serial interface parameters */
elmot 1:d0dfbce63a89 356 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SITP | DFSDM_CHCFGR1_SPICKSEL);
elmot 1:d0dfbce63a89 357 hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.SerialInterface.Type |
elmot 1:d0dfbce63a89 358 hdfsdm_channel->Init.SerialInterface.SpiClock);
elmot 1:d0dfbce63a89 359
elmot 1:d0dfbce63a89 360 /* Set analog watchdog parameters */
elmot 1:d0dfbce63a89 361 hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_AWFORD | DFSDM_CHAWSCDR_AWFOSR);
elmot 1:d0dfbce63a89 362 hdfsdm_channel->Instance->CHAWSCDR |= (hdfsdm_channel->Init.Awd.FilterOrder |
elmot 1:d0dfbce63a89 363 ((hdfsdm_channel->Init.Awd.Oversampling - 1) << DFSDM_CHAWSCDR_FOSR_OFFSET));
elmot 1:d0dfbce63a89 364
elmot 1:d0dfbce63a89 365 /* Set channel offset and right bit shift */
elmot 1:d0dfbce63a89 366 hdfsdm_channel->Instance->CHCFGR2 &= ~(DFSDM_CHCFGR2_OFFSET | DFSDM_CHCFGR2_DTRBS);
elmot 1:d0dfbce63a89 367 hdfsdm_channel->Instance->CHCFGR2 |= (((uint32_t) hdfsdm_channel->Init.Offset << DFSDM_CHCFGR2_OFFSET_OFFSET) |
elmot 1:d0dfbce63a89 368 (hdfsdm_channel->Init.RightBitShift << DFSDM_CHCFGR2_DTRBS_OFFSET));
elmot 1:d0dfbce63a89 369
elmot 1:d0dfbce63a89 370 /* Enable DFSDM channel */
elmot 1:d0dfbce63a89 371 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CHEN;
elmot 1:d0dfbce63a89 372
elmot 1:d0dfbce63a89 373 /* Set DFSDM Channel to ready state */
elmot 1:d0dfbce63a89 374 hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_READY;
elmot 1:d0dfbce63a89 375
elmot 1:d0dfbce63a89 376 /* Store channel handle in DFSDM channel handle table */
elmot 1:d0dfbce63a89 377 a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] = hdfsdm_channel;
elmot 1:d0dfbce63a89 378
elmot 1:d0dfbce63a89 379 return HAL_OK;
elmot 1:d0dfbce63a89 380 }
elmot 1:d0dfbce63a89 381
elmot 1:d0dfbce63a89 382 /**
elmot 1:d0dfbce63a89 383 * @brief De-initialize the DFSDM channel.
elmot 1:d0dfbce63a89 384 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 385 * @retval HAL status.
elmot 1:d0dfbce63a89 386 */
elmot 1:d0dfbce63a89 387 HAL_StatusTypeDef HAL_DFSDM_ChannelDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 388 {
elmot 1:d0dfbce63a89 389 /* Check DFSDM Channel handle */
elmot 1:d0dfbce63a89 390 if(hdfsdm_channel == NULL)
elmot 1:d0dfbce63a89 391 {
elmot 1:d0dfbce63a89 392 return HAL_ERROR;
elmot 1:d0dfbce63a89 393 }
elmot 1:d0dfbce63a89 394
elmot 1:d0dfbce63a89 395 /* Check parameters */
elmot 1:d0dfbce63a89 396 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
elmot 1:d0dfbce63a89 397
elmot 1:d0dfbce63a89 398 /* Check that channel has not been already deinitialized */
elmot 1:d0dfbce63a89 399 if(a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] == NULL)
elmot 1:d0dfbce63a89 400 {
elmot 1:d0dfbce63a89 401 return HAL_ERROR;
elmot 1:d0dfbce63a89 402 }
elmot 1:d0dfbce63a89 403
elmot 1:d0dfbce63a89 404 /* Disable the DFSDM channel */
elmot 1:d0dfbce63a89 405 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CHEN);
elmot 1:d0dfbce63a89 406
elmot 1:d0dfbce63a89 407 /* Update the channel counter */
elmot 1:d0dfbce63a89 408 v_dfsdm1ChannelCounter--;
elmot 1:d0dfbce63a89 409
elmot 1:d0dfbce63a89 410 /* Disable global DFSDM at deinit of last channel */
elmot 1:d0dfbce63a89 411 if(v_dfsdm1ChannelCounter == 0)
elmot 1:d0dfbce63a89 412 {
elmot 1:d0dfbce63a89 413 DFSDM1_Channel0->CHCFGR1 &= ~(DFSDM_CHCFGR1_DFSDMEN);
elmot 1:d0dfbce63a89 414 }
elmot 1:d0dfbce63a89 415
elmot 1:d0dfbce63a89 416 /* Call MSP deinit function */
elmot 1:d0dfbce63a89 417 HAL_DFSDM_ChannelMspDeInit(hdfsdm_channel);
elmot 1:d0dfbce63a89 418
elmot 1:d0dfbce63a89 419 /* Set DFSDM Channel in reset state */
elmot 1:d0dfbce63a89 420 hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_RESET;
elmot 1:d0dfbce63a89 421
elmot 1:d0dfbce63a89 422 /* Reset channel handle in DFSDM channel handle table */
elmot 1:d0dfbce63a89 423 a_dfsdm1ChannelHandle[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] = (DFSDM_Channel_HandleTypeDef *) NULL;
elmot 1:d0dfbce63a89 424
elmot 1:d0dfbce63a89 425 return HAL_OK;
elmot 1:d0dfbce63a89 426 }
elmot 1:d0dfbce63a89 427
elmot 1:d0dfbce63a89 428 /**
elmot 1:d0dfbce63a89 429 * @brief Initialize the DFSDM channel MSP.
elmot 1:d0dfbce63a89 430 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 431 * @retval None
elmot 1:d0dfbce63a89 432 */
elmot 1:d0dfbce63a89 433 __weak void HAL_DFSDM_ChannelMspInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 434 {
elmot 1:d0dfbce63a89 435 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 436 UNUSED(hdfsdm_channel);
elmot 1:d0dfbce63a89 437
elmot 1:d0dfbce63a89 438 /* NOTE : This function should not be modified, when the function is needed,
elmot 1:d0dfbce63a89 439 the HAL_DFSDM_ChannelMspInit could be implemented in the user file.
elmot 1:d0dfbce63a89 440 */
elmot 1:d0dfbce63a89 441 }
elmot 1:d0dfbce63a89 442
elmot 1:d0dfbce63a89 443 /**
elmot 1:d0dfbce63a89 444 * @brief De-initialize the DFSDM channel MSP.
elmot 1:d0dfbce63a89 445 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 446 * @retval None
elmot 1:d0dfbce63a89 447 */
elmot 1:d0dfbce63a89 448 __weak void HAL_DFSDM_ChannelMspDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 449 {
elmot 1:d0dfbce63a89 450 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 451 UNUSED(hdfsdm_channel);
elmot 1:d0dfbce63a89 452
elmot 1:d0dfbce63a89 453 /* NOTE : This function should not be modified, when the function is needed,
elmot 1:d0dfbce63a89 454 the HAL_DFSDM_ChannelMspDeInit could be implemented in the user file.
elmot 1:d0dfbce63a89 455 */
elmot 1:d0dfbce63a89 456 }
elmot 1:d0dfbce63a89 457
elmot 1:d0dfbce63a89 458 /**
elmot 1:d0dfbce63a89 459 * @}
elmot 1:d0dfbce63a89 460 */
elmot 1:d0dfbce63a89 461
elmot 1:d0dfbce63a89 462 /** @defgroup DFSDM_Exported_Functions_Group2_Channel Channel operation functions
elmot 1:d0dfbce63a89 463 * @brief Channel operation functions
elmot 1:d0dfbce63a89 464 *
elmot 1:d0dfbce63a89 465 @verbatim
elmot 1:d0dfbce63a89 466 ==============================================================================
elmot 1:d0dfbce63a89 467 ##### Channel operation functions #####
elmot 1:d0dfbce63a89 468 ==============================================================================
elmot 1:d0dfbce63a89 469 [..] This section provides functions allowing to:
elmot 1:d0dfbce63a89 470 (+) Manage clock absence detector feature.
elmot 1:d0dfbce63a89 471 (+) Manage short circuit detector feature.
elmot 1:d0dfbce63a89 472 (+) Get analog watchdog value.
elmot 1:d0dfbce63a89 473 (+) Modify offset value.
elmot 1:d0dfbce63a89 474 @endverbatim
elmot 1:d0dfbce63a89 475 * @{
elmot 1:d0dfbce63a89 476 */
elmot 1:d0dfbce63a89 477
elmot 1:d0dfbce63a89 478 /**
elmot 1:d0dfbce63a89 479 * @brief This function allows to start clock absence detection in polling mode.
elmot 1:d0dfbce63a89 480 * @note Same mode has to be used for all channels.
elmot 1:d0dfbce63a89 481 * @note If clock is not available on this channel during 5 seconds,
elmot 1:d0dfbce63a89 482 * clock absence detection will not be activated and function
elmot 1:d0dfbce63a89 483 * will return HAL_TIMEOUT error.
elmot 1:d0dfbce63a89 484 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 485 * @retval HAL status
elmot 1:d0dfbce63a89 486 */
elmot 1:d0dfbce63a89 487 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStart(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 488 {
elmot 1:d0dfbce63a89 489 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 490 uint32_t channel;
elmot 1:d0dfbce63a89 491 uint32_t tickstart;
elmot 1:d0dfbce63a89 492
elmot 1:d0dfbce63a89 493 /* Check parameters */
elmot 1:d0dfbce63a89 494 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
elmot 1:d0dfbce63a89 495
elmot 1:d0dfbce63a89 496 /* Check DFSDM channel state */
elmot 1:d0dfbce63a89 497 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
elmot 1:d0dfbce63a89 498 {
elmot 1:d0dfbce63a89 499 /* Return error status */
elmot 1:d0dfbce63a89 500 status = HAL_ERROR;
elmot 1:d0dfbce63a89 501 }
elmot 1:d0dfbce63a89 502 else
elmot 1:d0dfbce63a89 503 {
elmot 1:d0dfbce63a89 504 /* Get channel number from channel instance */
elmot 1:d0dfbce63a89 505 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
elmot 1:d0dfbce63a89 506
elmot 1:d0dfbce63a89 507 /* Get timeout */
elmot 1:d0dfbce63a89 508 tickstart = HAL_GetTick();
elmot 1:d0dfbce63a89 509
elmot 1:d0dfbce63a89 510 /* Clear clock absence flag */
elmot 1:d0dfbce63a89 511 while((((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_OFFSET + channel)) & 1) != 0)
elmot 1:d0dfbce63a89 512 {
elmot 1:d0dfbce63a89 513 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRCKABF_OFFSET + channel));
elmot 1:d0dfbce63a89 514
elmot 1:d0dfbce63a89 515 /* Check the Timeout */
elmot 1:d0dfbce63a89 516 if((HAL_GetTick()-tickstart) > DFSDM_CKAB_TIMEOUT)
elmot 1:d0dfbce63a89 517 {
elmot 1:d0dfbce63a89 518 /* Set timeout status */
elmot 1:d0dfbce63a89 519 status = HAL_TIMEOUT;
elmot 1:d0dfbce63a89 520 break;
elmot 1:d0dfbce63a89 521 }
elmot 1:d0dfbce63a89 522 }
elmot 1:d0dfbce63a89 523
elmot 1:d0dfbce63a89 524 if(status == HAL_OK)
elmot 1:d0dfbce63a89 525 {
elmot 1:d0dfbce63a89 526 /* Start clock absence detection */
elmot 1:d0dfbce63a89 527 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CKABEN;
elmot 1:d0dfbce63a89 528 }
elmot 1:d0dfbce63a89 529 }
elmot 1:d0dfbce63a89 530 /* Return function status */
elmot 1:d0dfbce63a89 531 return status;
elmot 1:d0dfbce63a89 532 }
elmot 1:d0dfbce63a89 533
elmot 1:d0dfbce63a89 534 /**
elmot 1:d0dfbce63a89 535 * @brief This function allows to poll for the clock absence detection.
elmot 1:d0dfbce63a89 536 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 537 * @param Timeout : Timeout value in milliseconds.
elmot 1:d0dfbce63a89 538 * @retval HAL status
elmot 1:d0dfbce63a89 539 */
elmot 1:d0dfbce63a89 540 HAL_StatusTypeDef HAL_DFSDM_ChannelPollForCkab(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
elmot 1:d0dfbce63a89 541 uint32_t Timeout)
elmot 1:d0dfbce63a89 542 {
elmot 1:d0dfbce63a89 543 uint32_t tickstart;
elmot 1:d0dfbce63a89 544 uint32_t channel;
elmot 1:d0dfbce63a89 545
elmot 1:d0dfbce63a89 546 /* Check parameters */
elmot 1:d0dfbce63a89 547 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
elmot 1:d0dfbce63a89 548
elmot 1:d0dfbce63a89 549 /* Check DFSDM channel state */
elmot 1:d0dfbce63a89 550 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
elmot 1:d0dfbce63a89 551 {
elmot 1:d0dfbce63a89 552 /* Return error status */
elmot 1:d0dfbce63a89 553 return HAL_ERROR;
elmot 1:d0dfbce63a89 554 }
elmot 1:d0dfbce63a89 555 else
elmot 1:d0dfbce63a89 556 {
elmot 1:d0dfbce63a89 557 /* Get channel number from channel instance */
elmot 1:d0dfbce63a89 558 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
elmot 1:d0dfbce63a89 559
elmot 1:d0dfbce63a89 560 /* Get timeout */
elmot 1:d0dfbce63a89 561 tickstart = HAL_GetTick();
elmot 1:d0dfbce63a89 562
elmot 1:d0dfbce63a89 563 /* Wait clock absence detection */
elmot 1:d0dfbce63a89 564 while((((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_OFFSET + channel)) & 1) == 0)
elmot 1:d0dfbce63a89 565 {
elmot 1:d0dfbce63a89 566 /* Check the Timeout */
elmot 1:d0dfbce63a89 567 if(Timeout != HAL_MAX_DELAY)
elmot 1:d0dfbce63a89 568 {
elmot 1:d0dfbce63a89 569 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
elmot 1:d0dfbce63a89 570 {
elmot 1:d0dfbce63a89 571 /* Return timeout status */
elmot 1:d0dfbce63a89 572 return HAL_TIMEOUT;
elmot 1:d0dfbce63a89 573 }
elmot 1:d0dfbce63a89 574 }
elmot 1:d0dfbce63a89 575 }
elmot 1:d0dfbce63a89 576
elmot 1:d0dfbce63a89 577 /* Clear clock absence detection flag */
elmot 1:d0dfbce63a89 578 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRCKABF_OFFSET + channel));
elmot 1:d0dfbce63a89 579
elmot 1:d0dfbce63a89 580 /* Return function status */
elmot 1:d0dfbce63a89 581 return HAL_OK;
elmot 1:d0dfbce63a89 582 }
elmot 1:d0dfbce63a89 583 }
elmot 1:d0dfbce63a89 584
elmot 1:d0dfbce63a89 585 /**
elmot 1:d0dfbce63a89 586 * @brief This function allows to stop clock absence detection in polling mode.
elmot 1:d0dfbce63a89 587 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 588 * @retval HAL status
elmot 1:d0dfbce63a89 589 */
elmot 1:d0dfbce63a89 590 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStop(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 591 {
elmot 1:d0dfbce63a89 592 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 593 uint32_t channel;
elmot 1:d0dfbce63a89 594
elmot 1:d0dfbce63a89 595 /* Check parameters */
elmot 1:d0dfbce63a89 596 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
elmot 1:d0dfbce63a89 597
elmot 1:d0dfbce63a89 598 /* Check DFSDM channel state */
elmot 1:d0dfbce63a89 599 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
elmot 1:d0dfbce63a89 600 {
elmot 1:d0dfbce63a89 601 /* Return error status */
elmot 1:d0dfbce63a89 602 status = HAL_ERROR;
elmot 1:d0dfbce63a89 603 }
elmot 1:d0dfbce63a89 604 else
elmot 1:d0dfbce63a89 605 {
elmot 1:d0dfbce63a89 606 /* Stop clock absence detection */
elmot 1:d0dfbce63a89 607 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKABEN);
elmot 1:d0dfbce63a89 608
elmot 1:d0dfbce63a89 609 /* Clear clock absence flag */
elmot 1:d0dfbce63a89 610 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
elmot 1:d0dfbce63a89 611 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRCKABF_OFFSET + channel));
elmot 1:d0dfbce63a89 612 }
elmot 1:d0dfbce63a89 613 /* Return function status */
elmot 1:d0dfbce63a89 614 return status;
elmot 1:d0dfbce63a89 615 }
elmot 1:d0dfbce63a89 616
elmot 1:d0dfbce63a89 617 /**
elmot 1:d0dfbce63a89 618 * @brief This function allows to start clock absence detection in interrupt mode.
elmot 1:d0dfbce63a89 619 * @note Same mode has to be used for all channels.
elmot 1:d0dfbce63a89 620 * @note If clock is not available on this channel during 5 seconds,
elmot 1:d0dfbce63a89 621 * clock absence detection will not be activated and function
elmot 1:d0dfbce63a89 622 * will return HAL_TIMEOUT error.
elmot 1:d0dfbce63a89 623 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 624 * @retval HAL status
elmot 1:d0dfbce63a89 625 */
elmot 1:d0dfbce63a89 626 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStart_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 627 {
elmot 1:d0dfbce63a89 628 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 629 uint32_t channel;
elmot 1:d0dfbce63a89 630 uint32_t tickstart;
elmot 1:d0dfbce63a89 631
elmot 1:d0dfbce63a89 632 /* Check parameters */
elmot 1:d0dfbce63a89 633 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
elmot 1:d0dfbce63a89 634
elmot 1:d0dfbce63a89 635 /* Check DFSDM channel state */
elmot 1:d0dfbce63a89 636 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
elmot 1:d0dfbce63a89 637 {
elmot 1:d0dfbce63a89 638 /* Return error status */
elmot 1:d0dfbce63a89 639 status = HAL_ERROR;
elmot 1:d0dfbce63a89 640 }
elmot 1:d0dfbce63a89 641 else
elmot 1:d0dfbce63a89 642 {
elmot 1:d0dfbce63a89 643 /* Get channel number from channel instance */
elmot 1:d0dfbce63a89 644 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
elmot 1:d0dfbce63a89 645
elmot 1:d0dfbce63a89 646 /* Get timeout */
elmot 1:d0dfbce63a89 647 tickstart = HAL_GetTick();
elmot 1:d0dfbce63a89 648
elmot 1:d0dfbce63a89 649 /* Clear clock absence flag */
elmot 1:d0dfbce63a89 650 while((((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_OFFSET + channel)) & 1) != 0)
elmot 1:d0dfbce63a89 651 {
elmot 1:d0dfbce63a89 652 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRCKABF_OFFSET + channel));
elmot 1:d0dfbce63a89 653
elmot 1:d0dfbce63a89 654 /* Check the Timeout */
elmot 1:d0dfbce63a89 655 if((HAL_GetTick()-tickstart) > DFSDM_CKAB_TIMEOUT)
elmot 1:d0dfbce63a89 656 {
elmot 1:d0dfbce63a89 657 /* Set timeout status */
elmot 1:d0dfbce63a89 658 status = HAL_TIMEOUT;
elmot 1:d0dfbce63a89 659 break;
elmot 1:d0dfbce63a89 660 }
elmot 1:d0dfbce63a89 661 }
elmot 1:d0dfbce63a89 662
elmot 1:d0dfbce63a89 663 if(status == HAL_OK)
elmot 1:d0dfbce63a89 664 {
elmot 1:d0dfbce63a89 665 /* Activate clock absence detection interrupt */
elmot 1:d0dfbce63a89 666 DFSDM1_Filter0->FLTCR2 |= DFSDM_FLTCR2_CKABIE;
elmot 1:d0dfbce63a89 667
elmot 1:d0dfbce63a89 668 /* Start clock absence detection */
elmot 1:d0dfbce63a89 669 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CKABEN;
elmot 1:d0dfbce63a89 670 }
elmot 1:d0dfbce63a89 671 }
elmot 1:d0dfbce63a89 672 /* Return function status */
elmot 1:d0dfbce63a89 673 return status;
elmot 1:d0dfbce63a89 674 }
elmot 1:d0dfbce63a89 675
elmot 1:d0dfbce63a89 676 /**
elmot 1:d0dfbce63a89 677 * @brief Clock absence detection callback.
elmot 1:d0dfbce63a89 678 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 679 * @retval None
elmot 1:d0dfbce63a89 680 */
elmot 1:d0dfbce63a89 681 __weak void HAL_DFSDM_ChannelCkabCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 682 {
elmot 1:d0dfbce63a89 683 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 684 UNUSED(hdfsdm_channel);
elmot 1:d0dfbce63a89 685
elmot 1:d0dfbce63a89 686 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 687 the HAL_DFSDM_ChannelCkabCallback could be implemented in the user file
elmot 1:d0dfbce63a89 688 */
elmot 1:d0dfbce63a89 689 }
elmot 1:d0dfbce63a89 690
elmot 1:d0dfbce63a89 691 /**
elmot 1:d0dfbce63a89 692 * @brief This function allows to stop clock absence detection in interrupt mode.
elmot 1:d0dfbce63a89 693 * @note Interrupt will be disabled for all channels
elmot 1:d0dfbce63a89 694 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 695 * @retval HAL status
elmot 1:d0dfbce63a89 696 */
elmot 1:d0dfbce63a89 697 HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStop_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 698 {
elmot 1:d0dfbce63a89 699 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 700 uint32_t channel;
elmot 1:d0dfbce63a89 701
elmot 1:d0dfbce63a89 702 /* Check parameters */
elmot 1:d0dfbce63a89 703 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
elmot 1:d0dfbce63a89 704
elmot 1:d0dfbce63a89 705 /* Check DFSDM channel state */
elmot 1:d0dfbce63a89 706 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
elmot 1:d0dfbce63a89 707 {
elmot 1:d0dfbce63a89 708 /* Return error status */
elmot 1:d0dfbce63a89 709 status = HAL_ERROR;
elmot 1:d0dfbce63a89 710 }
elmot 1:d0dfbce63a89 711 else
elmot 1:d0dfbce63a89 712 {
elmot 1:d0dfbce63a89 713 /* Stop clock absence detection */
elmot 1:d0dfbce63a89 714 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKABEN);
elmot 1:d0dfbce63a89 715
elmot 1:d0dfbce63a89 716 /* Clear clock absence flag */
elmot 1:d0dfbce63a89 717 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
elmot 1:d0dfbce63a89 718 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRCKABF_OFFSET + channel));
elmot 1:d0dfbce63a89 719
elmot 1:d0dfbce63a89 720 /* Disable clock absence detection interrupt */
elmot 1:d0dfbce63a89 721 DFSDM1_Filter0->FLTCR2 &= ~(DFSDM_FLTCR2_CKABIE);
elmot 1:d0dfbce63a89 722 }
elmot 1:d0dfbce63a89 723 /* Return function status */
elmot 1:d0dfbce63a89 724 return status;
elmot 1:d0dfbce63a89 725 }
elmot 1:d0dfbce63a89 726
elmot 1:d0dfbce63a89 727 /**
elmot 1:d0dfbce63a89 728 * @brief This function allows to start short circuit detection in polling mode.
elmot 1:d0dfbce63a89 729 * @note Same mode has to be used for all channels
elmot 1:d0dfbce63a89 730 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 731 * @param Threshold : Short circuit detector threshold.
elmot 1:d0dfbce63a89 732 * This parameter must be a number between Min_Data = 0 and Max_Data = 255.
elmot 1:d0dfbce63a89 733 * @param BreakSignal : Break signals assigned to short circuit event.
elmot 1:d0dfbce63a89 734 * This parameter can be a values combination of @ref DFSDM_BreakSignals.
elmot 1:d0dfbce63a89 735 * @retval HAL status
elmot 1:d0dfbce63a89 736 */
elmot 1:d0dfbce63a89 737 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStart(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
elmot 1:d0dfbce63a89 738 uint32_t Threshold,
elmot 1:d0dfbce63a89 739 uint32_t BreakSignal)
elmot 1:d0dfbce63a89 740 {
elmot 1:d0dfbce63a89 741 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 742
elmot 1:d0dfbce63a89 743 /* Check parameters */
elmot 1:d0dfbce63a89 744 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
elmot 1:d0dfbce63a89 745 assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold));
elmot 1:d0dfbce63a89 746 assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal));
elmot 1:d0dfbce63a89 747
elmot 1:d0dfbce63a89 748 /* Check DFSDM channel state */
elmot 1:d0dfbce63a89 749 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
elmot 1:d0dfbce63a89 750 {
elmot 1:d0dfbce63a89 751 /* Return error status */
elmot 1:d0dfbce63a89 752 status = HAL_ERROR;
elmot 1:d0dfbce63a89 753 }
elmot 1:d0dfbce63a89 754 else
elmot 1:d0dfbce63a89 755 {
elmot 1:d0dfbce63a89 756 /* Configure threshold and break signals */
elmot 1:d0dfbce63a89 757 hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_BKSCD | DFSDM_CHAWSCDR_SCDT);
elmot 1:d0dfbce63a89 758 hdfsdm_channel->Instance->CHAWSCDR |= ((BreakSignal << DFSDM_CHAWSCDR_BKSCD_OFFSET) | \
elmot 1:d0dfbce63a89 759 Threshold);
elmot 1:d0dfbce63a89 760
elmot 1:d0dfbce63a89 761 /* Start short circuit detection */
elmot 1:d0dfbce63a89 762 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_SCDEN;
elmot 1:d0dfbce63a89 763 }
elmot 1:d0dfbce63a89 764 /* Return function status */
elmot 1:d0dfbce63a89 765 return status;
elmot 1:d0dfbce63a89 766 }
elmot 1:d0dfbce63a89 767
elmot 1:d0dfbce63a89 768 /**
elmot 1:d0dfbce63a89 769 * @brief This function allows to poll for the short circuit detection.
elmot 1:d0dfbce63a89 770 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 771 * @param Timeout : Timeout value in milliseconds.
elmot 1:d0dfbce63a89 772 * @retval HAL status
elmot 1:d0dfbce63a89 773 */
elmot 1:d0dfbce63a89 774 HAL_StatusTypeDef HAL_DFSDM_ChannelPollForScd(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
elmot 1:d0dfbce63a89 775 uint32_t Timeout)
elmot 1:d0dfbce63a89 776 {
elmot 1:d0dfbce63a89 777 uint32_t tickstart;
elmot 1:d0dfbce63a89 778 uint32_t channel;
elmot 1:d0dfbce63a89 779
elmot 1:d0dfbce63a89 780 /* Check parameters */
elmot 1:d0dfbce63a89 781 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
elmot 1:d0dfbce63a89 782
elmot 1:d0dfbce63a89 783 /* Check DFSDM channel state */
elmot 1:d0dfbce63a89 784 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
elmot 1:d0dfbce63a89 785 {
elmot 1:d0dfbce63a89 786 /* Return error status */
elmot 1:d0dfbce63a89 787 return HAL_ERROR;
elmot 1:d0dfbce63a89 788 }
elmot 1:d0dfbce63a89 789 else
elmot 1:d0dfbce63a89 790 {
elmot 1:d0dfbce63a89 791 /* Get channel number from channel instance */
elmot 1:d0dfbce63a89 792 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
elmot 1:d0dfbce63a89 793
elmot 1:d0dfbce63a89 794 /* Get timeout */
elmot 1:d0dfbce63a89 795 tickstart = HAL_GetTick();
elmot 1:d0dfbce63a89 796
elmot 1:d0dfbce63a89 797 /* Wait short circuit detection */
elmot 1:d0dfbce63a89 798 while(((DFSDM1_Filter0->FLTISR & DFSDM_FLTISR_SCDF) >> (DFSDM_FLTISR_SCDF_OFFSET + channel)) == 0)
elmot 1:d0dfbce63a89 799 {
elmot 1:d0dfbce63a89 800 /* Check the Timeout */
elmot 1:d0dfbce63a89 801 if(Timeout != HAL_MAX_DELAY)
elmot 1:d0dfbce63a89 802 {
elmot 1:d0dfbce63a89 803 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
elmot 1:d0dfbce63a89 804 {
elmot 1:d0dfbce63a89 805 /* Return timeout status */
elmot 1:d0dfbce63a89 806 return HAL_TIMEOUT;
elmot 1:d0dfbce63a89 807 }
elmot 1:d0dfbce63a89 808 }
elmot 1:d0dfbce63a89 809 }
elmot 1:d0dfbce63a89 810
elmot 1:d0dfbce63a89 811 /* Clear short circuit detection flag */
elmot 1:d0dfbce63a89 812 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRSCDF_OFFSET + channel));
elmot 1:d0dfbce63a89 813
elmot 1:d0dfbce63a89 814 /* Return function status */
elmot 1:d0dfbce63a89 815 return HAL_OK;
elmot 1:d0dfbce63a89 816 }
elmot 1:d0dfbce63a89 817 }
elmot 1:d0dfbce63a89 818
elmot 1:d0dfbce63a89 819 /**
elmot 1:d0dfbce63a89 820 * @brief This function allows to stop short circuit detection in polling mode.
elmot 1:d0dfbce63a89 821 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 822 * @retval HAL status
elmot 1:d0dfbce63a89 823 */
elmot 1:d0dfbce63a89 824 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStop(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 825 {
elmot 1:d0dfbce63a89 826 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 827 uint32_t channel;
elmot 1:d0dfbce63a89 828
elmot 1:d0dfbce63a89 829 /* Check parameters */
elmot 1:d0dfbce63a89 830 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
elmot 1:d0dfbce63a89 831
elmot 1:d0dfbce63a89 832 /* Check DFSDM channel state */
elmot 1:d0dfbce63a89 833 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
elmot 1:d0dfbce63a89 834 {
elmot 1:d0dfbce63a89 835 /* Return error status */
elmot 1:d0dfbce63a89 836 status = HAL_ERROR;
elmot 1:d0dfbce63a89 837 }
elmot 1:d0dfbce63a89 838 else
elmot 1:d0dfbce63a89 839 {
elmot 1:d0dfbce63a89 840 /* Stop short circuit detection */
elmot 1:d0dfbce63a89 841 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SCDEN);
elmot 1:d0dfbce63a89 842
elmot 1:d0dfbce63a89 843 /* Clear short circuit detection flag */
elmot 1:d0dfbce63a89 844 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
elmot 1:d0dfbce63a89 845 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRSCDF_OFFSET + channel));
elmot 1:d0dfbce63a89 846 }
elmot 1:d0dfbce63a89 847 /* Return function status */
elmot 1:d0dfbce63a89 848 return status;
elmot 1:d0dfbce63a89 849 }
elmot 1:d0dfbce63a89 850
elmot 1:d0dfbce63a89 851 /**
elmot 1:d0dfbce63a89 852 * @brief This function allows to start short circuit detection in interrupt mode.
elmot 1:d0dfbce63a89 853 * @note Same mode has to be used for all channels
elmot 1:d0dfbce63a89 854 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 855 * @param Threshold : Short circuit detector threshold.
elmot 1:d0dfbce63a89 856 * This parameter must be a number between Min_Data = 0 and Max_Data = 255.
elmot 1:d0dfbce63a89 857 * @param BreakSignal : Break signals assigned to short circuit event.
elmot 1:d0dfbce63a89 858 * This parameter can be a values combination of @ref DFSDM_BreakSignals.
elmot 1:d0dfbce63a89 859 * @retval HAL status
elmot 1:d0dfbce63a89 860 */
elmot 1:d0dfbce63a89 861 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStart_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
elmot 1:d0dfbce63a89 862 uint32_t Threshold,
elmot 1:d0dfbce63a89 863 uint32_t BreakSignal)
elmot 1:d0dfbce63a89 864 {
elmot 1:d0dfbce63a89 865 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 866
elmot 1:d0dfbce63a89 867 /* Check parameters */
elmot 1:d0dfbce63a89 868 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
elmot 1:d0dfbce63a89 869 assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold));
elmot 1:d0dfbce63a89 870 assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal));
elmot 1:d0dfbce63a89 871
elmot 1:d0dfbce63a89 872 /* Check DFSDM channel state */
elmot 1:d0dfbce63a89 873 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
elmot 1:d0dfbce63a89 874 {
elmot 1:d0dfbce63a89 875 /* Return error status */
elmot 1:d0dfbce63a89 876 status = HAL_ERROR;
elmot 1:d0dfbce63a89 877 }
elmot 1:d0dfbce63a89 878 else
elmot 1:d0dfbce63a89 879 {
elmot 1:d0dfbce63a89 880 /* Activate short circuit detection interrupt */
elmot 1:d0dfbce63a89 881 DFSDM1_Filter0->FLTCR2 |= DFSDM_FLTCR2_SCDIE;
elmot 1:d0dfbce63a89 882
elmot 1:d0dfbce63a89 883 /* Configure threshold and break signals */
elmot 1:d0dfbce63a89 884 hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_BKSCD | DFSDM_CHAWSCDR_SCDT);
elmot 1:d0dfbce63a89 885 hdfsdm_channel->Instance->CHAWSCDR |= ((BreakSignal << DFSDM_CHAWSCDR_BKSCD_OFFSET) | \
elmot 1:d0dfbce63a89 886 Threshold);
elmot 1:d0dfbce63a89 887
elmot 1:d0dfbce63a89 888 /* Start short circuit detection */
elmot 1:d0dfbce63a89 889 hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_SCDEN;
elmot 1:d0dfbce63a89 890 }
elmot 1:d0dfbce63a89 891 /* Return function status */
elmot 1:d0dfbce63a89 892 return status;
elmot 1:d0dfbce63a89 893 }
elmot 1:d0dfbce63a89 894
elmot 1:d0dfbce63a89 895 /**
elmot 1:d0dfbce63a89 896 * @brief Short circuit detection callback.
elmot 1:d0dfbce63a89 897 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 898 * @retval None
elmot 1:d0dfbce63a89 899 */
elmot 1:d0dfbce63a89 900 __weak void HAL_DFSDM_ChannelScdCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 901 {
elmot 1:d0dfbce63a89 902 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 903 UNUSED(hdfsdm_channel);
elmot 1:d0dfbce63a89 904
elmot 1:d0dfbce63a89 905 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 906 the HAL_DFSDM_ChannelScdCallback could be implemented in the user file
elmot 1:d0dfbce63a89 907 */
elmot 1:d0dfbce63a89 908 }
elmot 1:d0dfbce63a89 909
elmot 1:d0dfbce63a89 910 /**
elmot 1:d0dfbce63a89 911 * @brief This function allows to stop short circuit detection in interrupt mode.
elmot 1:d0dfbce63a89 912 * @note Interrupt will be disabled for all channels
elmot 1:d0dfbce63a89 913 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 914 * @retval HAL status
elmot 1:d0dfbce63a89 915 */
elmot 1:d0dfbce63a89 916 HAL_StatusTypeDef HAL_DFSDM_ChannelScdStop_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 917 {
elmot 1:d0dfbce63a89 918 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 919 uint32_t channel;
elmot 1:d0dfbce63a89 920
elmot 1:d0dfbce63a89 921 /* Check parameters */
elmot 1:d0dfbce63a89 922 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
elmot 1:d0dfbce63a89 923
elmot 1:d0dfbce63a89 924 /* Check DFSDM channel state */
elmot 1:d0dfbce63a89 925 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
elmot 1:d0dfbce63a89 926 {
elmot 1:d0dfbce63a89 927 /* Return error status */
elmot 1:d0dfbce63a89 928 status = HAL_ERROR;
elmot 1:d0dfbce63a89 929 }
elmot 1:d0dfbce63a89 930 else
elmot 1:d0dfbce63a89 931 {
elmot 1:d0dfbce63a89 932 /* Stop short circuit detection */
elmot 1:d0dfbce63a89 933 hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SCDEN);
elmot 1:d0dfbce63a89 934
elmot 1:d0dfbce63a89 935 /* Clear short circuit detection flag */
elmot 1:d0dfbce63a89 936 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
elmot 1:d0dfbce63a89 937 DFSDM1_Filter0->FLTICR = (1 << (DFSDM_FLTICR_CLRSCDF_OFFSET + channel));
elmot 1:d0dfbce63a89 938
elmot 1:d0dfbce63a89 939 /* Disable short circuit detection interrupt */
elmot 1:d0dfbce63a89 940 DFSDM1_Filter0->FLTCR2 &= ~(DFSDM_FLTCR2_SCDIE);
elmot 1:d0dfbce63a89 941 }
elmot 1:d0dfbce63a89 942 /* Return function status */
elmot 1:d0dfbce63a89 943 return status;
elmot 1:d0dfbce63a89 944 }
elmot 1:d0dfbce63a89 945
elmot 1:d0dfbce63a89 946 /**
elmot 1:d0dfbce63a89 947 * @brief This function allows to get channel analog watchdog value.
elmot 1:d0dfbce63a89 948 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 949 * @retval Channel analog watchdog value.
elmot 1:d0dfbce63a89 950 */
elmot 1:d0dfbce63a89 951 int16_t HAL_DFSDM_ChannelGetAwdValue(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 952 {
elmot 1:d0dfbce63a89 953 return (int16_t) hdfsdm_channel->Instance->CHWDATAR;
elmot 1:d0dfbce63a89 954 }
elmot 1:d0dfbce63a89 955
elmot 1:d0dfbce63a89 956 /**
elmot 1:d0dfbce63a89 957 * @brief This function allows to modify channel offset value.
elmot 1:d0dfbce63a89 958 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 959 * @param Offset : DFSDM channel offset.
elmot 1:d0dfbce63a89 960 * This parameter must be a number between Min_Data = -8388608 and Max_Data = 8388607.
elmot 1:d0dfbce63a89 961 * @retval HAL status.
elmot 1:d0dfbce63a89 962 */
elmot 1:d0dfbce63a89 963 HAL_StatusTypeDef HAL_DFSDM_ChannelModifyOffset(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
elmot 1:d0dfbce63a89 964 int32_t Offset)
elmot 1:d0dfbce63a89 965 {
elmot 1:d0dfbce63a89 966 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 967
elmot 1:d0dfbce63a89 968 /* Check parameters */
elmot 1:d0dfbce63a89 969 assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
elmot 1:d0dfbce63a89 970 assert_param(IS_DFSDM_CHANNEL_OFFSET(Offset));
elmot 1:d0dfbce63a89 971
elmot 1:d0dfbce63a89 972 /* Check DFSDM channel state */
elmot 1:d0dfbce63a89 973 if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
elmot 1:d0dfbce63a89 974 {
elmot 1:d0dfbce63a89 975 /* Return error status */
elmot 1:d0dfbce63a89 976 status = HAL_ERROR;
elmot 1:d0dfbce63a89 977 }
elmot 1:d0dfbce63a89 978 else
elmot 1:d0dfbce63a89 979 {
elmot 1:d0dfbce63a89 980 /* Modify channel offset */
elmot 1:d0dfbce63a89 981 hdfsdm_channel->Instance->CHCFGR2 &= ~(DFSDM_CHCFGR2_OFFSET);
elmot 1:d0dfbce63a89 982 hdfsdm_channel->Instance->CHCFGR2 |= ((uint32_t) Offset << DFSDM_CHCFGR2_OFFSET_OFFSET);
elmot 1:d0dfbce63a89 983 }
elmot 1:d0dfbce63a89 984 /* Return function status */
elmot 1:d0dfbce63a89 985 return status;
elmot 1:d0dfbce63a89 986 }
elmot 1:d0dfbce63a89 987
elmot 1:d0dfbce63a89 988 /**
elmot 1:d0dfbce63a89 989 * @}
elmot 1:d0dfbce63a89 990 */
elmot 1:d0dfbce63a89 991
elmot 1:d0dfbce63a89 992 /** @defgroup DFSDM_Exported_Functions_Group3_Channel Channel state function
elmot 1:d0dfbce63a89 993 * @brief Channel state function
elmot 1:d0dfbce63a89 994 *
elmot 1:d0dfbce63a89 995 @verbatim
elmot 1:d0dfbce63a89 996 ==============================================================================
elmot 1:d0dfbce63a89 997 ##### Channel state function #####
elmot 1:d0dfbce63a89 998 ==============================================================================
elmot 1:d0dfbce63a89 999 [..] This section provides function allowing to:
elmot 1:d0dfbce63a89 1000 (+) Get channel handle state.
elmot 1:d0dfbce63a89 1001 @endverbatim
elmot 1:d0dfbce63a89 1002 * @{
elmot 1:d0dfbce63a89 1003 */
elmot 1:d0dfbce63a89 1004
elmot 1:d0dfbce63a89 1005 /**
elmot 1:d0dfbce63a89 1006 * @brief This function allows to get the current DFSDM channel handle state.
elmot 1:d0dfbce63a89 1007 * @param hdfsdm_channel : DFSDM channel handle.
elmot 1:d0dfbce63a89 1008 * @retval DFSDM channel state.
elmot 1:d0dfbce63a89 1009 */
elmot 1:d0dfbce63a89 1010 HAL_DFSDM_Channel_StateTypeDef HAL_DFSDM_ChannelGetState(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
elmot 1:d0dfbce63a89 1011 {
elmot 1:d0dfbce63a89 1012 /* Return DFSDM channel handle state */
elmot 1:d0dfbce63a89 1013 return hdfsdm_channel->State;
elmot 1:d0dfbce63a89 1014 }
elmot 1:d0dfbce63a89 1015
elmot 1:d0dfbce63a89 1016 /**
elmot 1:d0dfbce63a89 1017 * @}
elmot 1:d0dfbce63a89 1018 */
elmot 1:d0dfbce63a89 1019
elmot 1:d0dfbce63a89 1020 /** @defgroup DFSDM_Exported_Functions_Group1_Filter Filter initialization and de-initialization functions
elmot 1:d0dfbce63a89 1021 * @brief Filter initialization and de-initialization functions
elmot 1:d0dfbce63a89 1022 *
elmot 1:d0dfbce63a89 1023 @verbatim
elmot 1:d0dfbce63a89 1024 ==============================================================================
elmot 1:d0dfbce63a89 1025 ##### Filter initialization and de-initialization functions #####
elmot 1:d0dfbce63a89 1026 ==============================================================================
elmot 1:d0dfbce63a89 1027 [..] This section provides functions allowing to:
elmot 1:d0dfbce63a89 1028 (+) Initialize the DFSDM filter.
elmot 1:d0dfbce63a89 1029 (+) De-initialize the DFSDM filter.
elmot 1:d0dfbce63a89 1030 @endverbatim
elmot 1:d0dfbce63a89 1031 * @{
elmot 1:d0dfbce63a89 1032 */
elmot 1:d0dfbce63a89 1033
elmot 1:d0dfbce63a89 1034 /**
elmot 1:d0dfbce63a89 1035 * @brief Initialize the DFSDM filter according to the specified parameters
elmot 1:d0dfbce63a89 1036 * in the DFSDM_FilterInitTypeDef structure and initialize the associated handle.
elmot 1:d0dfbce63a89 1037 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1038 * @retval HAL status.
elmot 1:d0dfbce63a89 1039 */
elmot 1:d0dfbce63a89 1040 HAL_StatusTypeDef HAL_DFSDM_FilterInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 1041 {
elmot 1:d0dfbce63a89 1042 /* Check DFSDM Channel handle */
elmot 1:d0dfbce63a89 1043 if(hdfsdm_filter == NULL)
elmot 1:d0dfbce63a89 1044 {
elmot 1:d0dfbce63a89 1045 return HAL_ERROR;
elmot 1:d0dfbce63a89 1046 }
elmot 1:d0dfbce63a89 1047
elmot 1:d0dfbce63a89 1048 /* Check parameters */
elmot 1:d0dfbce63a89 1049 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1050 assert_param(IS_DFSDM_FILTER_REG_TRIGGER(hdfsdm_filter->Init.RegularParam.Trigger));
elmot 1:d0dfbce63a89 1051 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.RegularParam.FastMode));
elmot 1:d0dfbce63a89 1052 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.RegularParam.DmaMode));
elmot 1:d0dfbce63a89 1053 assert_param(IS_DFSDM_FILTER_INJ_TRIGGER(hdfsdm_filter->Init.InjectedParam.Trigger));
elmot 1:d0dfbce63a89 1054 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.InjectedParam.ScanMode));
elmot 1:d0dfbce63a89 1055 assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.InjectedParam.DmaMode));
elmot 1:d0dfbce63a89 1056 assert_param(IS_DFSDM_FILTER_SINC_ORDER(hdfsdm_filter->Init.FilterParam.SincOrder));
elmot 1:d0dfbce63a89 1057 assert_param(IS_DFSDM_FILTER_OVS_RATIO(hdfsdm_filter->Init.FilterParam.Oversampling));
elmot 1:d0dfbce63a89 1058 assert_param(IS_DFSDM_FILTER_INTEGRATOR_OVS_RATIO(hdfsdm_filter->Init.FilterParam.IntOversampling));
elmot 1:d0dfbce63a89 1059
elmot 1:d0dfbce63a89 1060 /* Check parameters compatibility */
elmot 1:d0dfbce63a89 1061 if((hdfsdm_filter->Instance == DFSDM1_Filter0) &&
elmot 1:d0dfbce63a89 1062 ((hdfsdm_filter->Init.RegularParam.Trigger == DFSDM_FILTER_SYNC_TRIGGER) ||
elmot 1:d0dfbce63a89 1063 (hdfsdm_filter->Init.InjectedParam.Trigger == DFSDM_FILTER_SYNC_TRIGGER)))
elmot 1:d0dfbce63a89 1064 {
elmot 1:d0dfbce63a89 1065 return HAL_ERROR;
elmot 1:d0dfbce63a89 1066 }
elmot 1:d0dfbce63a89 1067
elmot 1:d0dfbce63a89 1068 /* Initialize DFSDM filter variables with default values */
elmot 1:d0dfbce63a89 1069 hdfsdm_filter->RegularContMode = DFSDM_CONTINUOUS_CONV_OFF;
elmot 1:d0dfbce63a89 1070 hdfsdm_filter->InjectedChannelsNbr = 1;
elmot 1:d0dfbce63a89 1071 hdfsdm_filter->InjConvRemaining = 1;
elmot 1:d0dfbce63a89 1072 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_NONE;
elmot 1:d0dfbce63a89 1073
elmot 1:d0dfbce63a89 1074 /* Call MSP init function */
elmot 1:d0dfbce63a89 1075 HAL_DFSDM_FilterMspInit(hdfsdm_filter);
elmot 1:d0dfbce63a89 1076
elmot 1:d0dfbce63a89 1077 /* Set regular parameters */
elmot 1:d0dfbce63a89 1078 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RSYNC);
elmot 1:d0dfbce63a89 1079 if(hdfsdm_filter->Init.RegularParam.FastMode == ENABLE)
elmot 1:d0dfbce63a89 1080 {
elmot 1:d0dfbce63a89 1081 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_FAST;
elmot 1:d0dfbce63a89 1082 }
elmot 1:d0dfbce63a89 1083 else
elmot 1:d0dfbce63a89 1084 {
elmot 1:d0dfbce63a89 1085 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_FAST);
elmot 1:d0dfbce63a89 1086 }
elmot 1:d0dfbce63a89 1087
elmot 1:d0dfbce63a89 1088 if(hdfsdm_filter->Init.RegularParam.DmaMode == ENABLE)
elmot 1:d0dfbce63a89 1089 {
elmot 1:d0dfbce63a89 1090 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RDMAEN;
elmot 1:d0dfbce63a89 1091 }
elmot 1:d0dfbce63a89 1092 else
elmot 1:d0dfbce63a89 1093 {
elmot 1:d0dfbce63a89 1094 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RDMAEN);
elmot 1:d0dfbce63a89 1095 }
elmot 1:d0dfbce63a89 1096
elmot 1:d0dfbce63a89 1097 /* Set injected parameters */
elmot 1:d0dfbce63a89 1098 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSYNC | DFSDM_FLTCR1_JEXTEN | DFSDM_FLTCR1_JEXTSEL);
elmot 1:d0dfbce63a89 1099 if(hdfsdm_filter->Init.InjectedParam.Trigger == DFSDM_FILTER_EXT_TRIGGER)
elmot 1:d0dfbce63a89 1100 {
elmot 1:d0dfbce63a89 1101 assert_param(IS_DFSDM_FILTER_EXT_TRIG(hdfsdm_filter->Init.InjectedParam.ExtTrigger));
elmot 1:d0dfbce63a89 1102 assert_param(IS_DFSDM_FILTER_EXT_TRIG_EDGE(hdfsdm_filter->Init.InjectedParam.ExtTriggerEdge));
elmot 1:d0dfbce63a89 1103 hdfsdm_filter->Instance->FLTCR1 |= (hdfsdm_filter->Init.InjectedParam.ExtTrigger);
elmot 1:d0dfbce63a89 1104 }
elmot 1:d0dfbce63a89 1105
elmot 1:d0dfbce63a89 1106 if(hdfsdm_filter->Init.InjectedParam.ScanMode == ENABLE)
elmot 1:d0dfbce63a89 1107 {
elmot 1:d0dfbce63a89 1108 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSCAN;
elmot 1:d0dfbce63a89 1109 }
elmot 1:d0dfbce63a89 1110 else
elmot 1:d0dfbce63a89 1111 {
elmot 1:d0dfbce63a89 1112 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSCAN);
elmot 1:d0dfbce63a89 1113 }
elmot 1:d0dfbce63a89 1114
elmot 1:d0dfbce63a89 1115 if(hdfsdm_filter->Init.InjectedParam.DmaMode == ENABLE)
elmot 1:d0dfbce63a89 1116 {
elmot 1:d0dfbce63a89 1117 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JDMAEN;
elmot 1:d0dfbce63a89 1118 }
elmot 1:d0dfbce63a89 1119 else
elmot 1:d0dfbce63a89 1120 {
elmot 1:d0dfbce63a89 1121 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JDMAEN);
elmot 1:d0dfbce63a89 1122 }
elmot 1:d0dfbce63a89 1123
elmot 1:d0dfbce63a89 1124 /* Set filter parameters */
elmot 1:d0dfbce63a89 1125 hdfsdm_filter->Instance->FLTFCR &= ~(DFSDM_FLTFCR_FORD | DFSDM_FLTFCR_FOSR | DFSDM_FLTFCR_IOSR);
elmot 1:d0dfbce63a89 1126 hdfsdm_filter->Instance->FLTFCR |= (hdfsdm_filter->Init.FilterParam.SincOrder |
elmot 1:d0dfbce63a89 1127 ((hdfsdm_filter->Init.FilterParam.Oversampling - 1) << DFSDM_FLTFCR_FOSR_OFFSET) |
elmot 1:d0dfbce63a89 1128 (hdfsdm_filter->Init.FilterParam.IntOversampling - 1));
elmot 1:d0dfbce63a89 1129
elmot 1:d0dfbce63a89 1130 /* Store regular and injected triggers and injected scan mode*/
elmot 1:d0dfbce63a89 1131 hdfsdm_filter->RegularTrigger = hdfsdm_filter->Init.RegularParam.Trigger;
elmot 1:d0dfbce63a89 1132 hdfsdm_filter->InjectedTrigger = hdfsdm_filter->Init.InjectedParam.Trigger;
elmot 1:d0dfbce63a89 1133 hdfsdm_filter->ExtTriggerEdge = hdfsdm_filter->Init.InjectedParam.ExtTriggerEdge;
elmot 1:d0dfbce63a89 1134 hdfsdm_filter->InjectedScanMode = hdfsdm_filter->Init.InjectedParam.ScanMode;
elmot 1:d0dfbce63a89 1135
elmot 1:d0dfbce63a89 1136 /* Enable DFSDM filter */
elmot 1:d0dfbce63a89 1137 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
elmot 1:d0dfbce63a89 1138
elmot 1:d0dfbce63a89 1139 /* Set DFSDM filter to ready state */
elmot 1:d0dfbce63a89 1140 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_READY;
elmot 1:d0dfbce63a89 1141
elmot 1:d0dfbce63a89 1142 return HAL_OK;
elmot 1:d0dfbce63a89 1143 }
elmot 1:d0dfbce63a89 1144
elmot 1:d0dfbce63a89 1145 /**
elmot 1:d0dfbce63a89 1146 * @brief De-initializes the DFSDM filter.
elmot 1:d0dfbce63a89 1147 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1148 * @retval HAL status.
elmot 1:d0dfbce63a89 1149 */
elmot 1:d0dfbce63a89 1150 HAL_StatusTypeDef HAL_DFSDM_FilterDeInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 1151 {
elmot 1:d0dfbce63a89 1152 /* Check DFSDM filter handle */
elmot 1:d0dfbce63a89 1153 if(hdfsdm_filter == NULL)
elmot 1:d0dfbce63a89 1154 {
elmot 1:d0dfbce63a89 1155 return HAL_ERROR;
elmot 1:d0dfbce63a89 1156 }
elmot 1:d0dfbce63a89 1157
elmot 1:d0dfbce63a89 1158 /* Check parameters */
elmot 1:d0dfbce63a89 1159 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1160
elmot 1:d0dfbce63a89 1161 /* Disable the DFSDM filter */
elmot 1:d0dfbce63a89 1162 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
elmot 1:d0dfbce63a89 1163
elmot 1:d0dfbce63a89 1164 /* Call MSP deinit function */
elmot 1:d0dfbce63a89 1165 HAL_DFSDM_FilterMspDeInit(hdfsdm_filter);
elmot 1:d0dfbce63a89 1166
elmot 1:d0dfbce63a89 1167 /* Set DFSDM filter in reset state */
elmot 1:d0dfbce63a89 1168 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_RESET;
elmot 1:d0dfbce63a89 1169
elmot 1:d0dfbce63a89 1170 return HAL_OK;
elmot 1:d0dfbce63a89 1171 }
elmot 1:d0dfbce63a89 1172
elmot 1:d0dfbce63a89 1173 /**
elmot 1:d0dfbce63a89 1174 * @brief Initializes the DFSDM filter MSP.
elmot 1:d0dfbce63a89 1175 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1176 * @retval None
elmot 1:d0dfbce63a89 1177 */
elmot 1:d0dfbce63a89 1178 __weak void HAL_DFSDM_FilterMspInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 1179 {
elmot 1:d0dfbce63a89 1180 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1181 UNUSED(hdfsdm_filter);
elmot 1:d0dfbce63a89 1182
elmot 1:d0dfbce63a89 1183 /* NOTE : This function should not be modified, when the function is needed,
elmot 1:d0dfbce63a89 1184 the HAL_DFSDM_FilterMspInit could be implemented in the user file.
elmot 1:d0dfbce63a89 1185 */
elmot 1:d0dfbce63a89 1186 }
elmot 1:d0dfbce63a89 1187
elmot 1:d0dfbce63a89 1188 /**
elmot 1:d0dfbce63a89 1189 * @brief De-initializes the DFSDM filter MSP.
elmot 1:d0dfbce63a89 1190 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1191 * @retval None
elmot 1:d0dfbce63a89 1192 */
elmot 1:d0dfbce63a89 1193 __weak void HAL_DFSDM_FilterMspDeInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 1194 {
elmot 1:d0dfbce63a89 1195 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1196 UNUSED(hdfsdm_filter);
elmot 1:d0dfbce63a89 1197
elmot 1:d0dfbce63a89 1198 /* NOTE : This function should not be modified, when the function is needed,
elmot 1:d0dfbce63a89 1199 the HAL_DFSDM_FilterMspDeInit could be implemented in the user file.
elmot 1:d0dfbce63a89 1200 */
elmot 1:d0dfbce63a89 1201 }
elmot 1:d0dfbce63a89 1202
elmot 1:d0dfbce63a89 1203 /**
elmot 1:d0dfbce63a89 1204 * @}
elmot 1:d0dfbce63a89 1205 */
elmot 1:d0dfbce63a89 1206
elmot 1:d0dfbce63a89 1207 /** @defgroup DFSDM_Exported_Functions_Group2_Filter Filter control functions
elmot 1:d0dfbce63a89 1208 * @brief Filter control functions
elmot 1:d0dfbce63a89 1209 *
elmot 1:d0dfbce63a89 1210 @verbatim
elmot 1:d0dfbce63a89 1211 ==============================================================================
elmot 1:d0dfbce63a89 1212 ##### Filter control functions #####
elmot 1:d0dfbce63a89 1213 ==============================================================================
elmot 1:d0dfbce63a89 1214 [..] This section provides functions allowing to:
elmot 1:d0dfbce63a89 1215 (+) Select channel and enable/disable continuous mode for regular conversion.
elmot 1:d0dfbce63a89 1216 (+) Select channels for injected conversion.
elmot 1:d0dfbce63a89 1217 @endverbatim
elmot 1:d0dfbce63a89 1218 * @{
elmot 1:d0dfbce63a89 1219 */
elmot 1:d0dfbce63a89 1220
elmot 1:d0dfbce63a89 1221 /**
elmot 1:d0dfbce63a89 1222 * @brief This function allows to select channel and to enable/disable
elmot 1:d0dfbce63a89 1223 * continuous mode for regular conversion.
elmot 1:d0dfbce63a89 1224 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1225 * @param Channel : Channel for regular conversion.
elmot 1:d0dfbce63a89 1226 * This parameter can be a value of @ref DFSDM_Channel_Selection.
elmot 1:d0dfbce63a89 1227 * @param ContinuousMode : Enable/disable continuous mode for regular conversion.
elmot 1:d0dfbce63a89 1228 * This parameter can be a value of @ref DFSDM_ContinuousMode.
elmot 1:d0dfbce63a89 1229 * @retval HAL status
elmot 1:d0dfbce63a89 1230 */
elmot 1:d0dfbce63a89 1231 HAL_StatusTypeDef HAL_DFSDM_FilterConfigRegChannel(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 1232 uint32_t Channel,
elmot 1:d0dfbce63a89 1233 uint32_t ContinuousMode)
elmot 1:d0dfbce63a89 1234 {
elmot 1:d0dfbce63a89 1235 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1236
elmot 1:d0dfbce63a89 1237 /* Check parameters */
elmot 1:d0dfbce63a89 1238 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1239 assert_param(IS_DFSDM_REGULAR_CHANNEL(Channel));
elmot 1:d0dfbce63a89 1240 assert_param(IS_DFSDM_CONTINUOUS_MODE(ContinuousMode));
elmot 1:d0dfbce63a89 1241
elmot 1:d0dfbce63a89 1242 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1243 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_RESET) &&
elmot 1:d0dfbce63a89 1244 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_ERROR))
elmot 1:d0dfbce63a89 1245 {
elmot 1:d0dfbce63a89 1246 /* Configure channel and continuous mode for regular conversion */
elmot 1:d0dfbce63a89 1247 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RCH | DFSDM_FLTCR1_RCONT);
elmot 1:d0dfbce63a89 1248 if(ContinuousMode == DFSDM_CONTINUOUS_CONV_ON)
elmot 1:d0dfbce63a89 1249 {
elmot 1:d0dfbce63a89 1250 hdfsdm_filter->Instance->FLTCR1 |= (uint32_t) (((Channel & DFSDM_MSB_MASK) << DFSDM_FLTCR1_MSB_RCH_OFFSET) |
elmot 1:d0dfbce63a89 1251 DFSDM_FLTCR1_RCONT);
elmot 1:d0dfbce63a89 1252 }
elmot 1:d0dfbce63a89 1253 else
elmot 1:d0dfbce63a89 1254 {
elmot 1:d0dfbce63a89 1255 hdfsdm_filter->Instance->FLTCR1 |= (uint32_t) ((Channel & DFSDM_MSB_MASK) << DFSDM_FLTCR1_MSB_RCH_OFFSET);
elmot 1:d0dfbce63a89 1256 }
elmot 1:d0dfbce63a89 1257 /* Store continuous mode information */
elmot 1:d0dfbce63a89 1258 hdfsdm_filter->RegularContMode = ContinuousMode;
elmot 1:d0dfbce63a89 1259 }
elmot 1:d0dfbce63a89 1260 else
elmot 1:d0dfbce63a89 1261 {
elmot 1:d0dfbce63a89 1262 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1263 }
elmot 1:d0dfbce63a89 1264
elmot 1:d0dfbce63a89 1265 /* Return function status */
elmot 1:d0dfbce63a89 1266 return status;
elmot 1:d0dfbce63a89 1267 }
elmot 1:d0dfbce63a89 1268
elmot 1:d0dfbce63a89 1269 /**
elmot 1:d0dfbce63a89 1270 * @brief This function allows to select channels for injected conversion.
elmot 1:d0dfbce63a89 1271 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1272 * @param Channel : Channels for injected conversion.
elmot 1:d0dfbce63a89 1273 * This parameter can be a values combination of @ref DFSDM_Channel_Selection.
elmot 1:d0dfbce63a89 1274 * @retval HAL status
elmot 1:d0dfbce63a89 1275 */
elmot 1:d0dfbce63a89 1276 HAL_StatusTypeDef HAL_DFSDM_FilterConfigInjChannel(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 1277 uint32_t Channel)
elmot 1:d0dfbce63a89 1278 {
elmot 1:d0dfbce63a89 1279 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1280
elmot 1:d0dfbce63a89 1281 /* Check parameters */
elmot 1:d0dfbce63a89 1282 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1283 assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel));
elmot 1:d0dfbce63a89 1284
elmot 1:d0dfbce63a89 1285 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1286 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_RESET) &&
elmot 1:d0dfbce63a89 1287 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_ERROR))
elmot 1:d0dfbce63a89 1288 {
elmot 1:d0dfbce63a89 1289 /* Configure channel for injected conversion */
elmot 1:d0dfbce63a89 1290 hdfsdm_filter->Instance->FLTJCHGR = (uint32_t) (Channel & DFSDM_LSB_MASK);
elmot 1:d0dfbce63a89 1291 /* Store number of injected channels */
elmot 1:d0dfbce63a89 1292 hdfsdm_filter->InjectedChannelsNbr = DFSDM_GetInjChannelsNbr(Channel);
elmot 1:d0dfbce63a89 1293 /* Update number of injected channels remaining */
elmot 1:d0dfbce63a89 1294 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
elmot 1:d0dfbce63a89 1295 hdfsdm_filter->InjectedChannelsNbr : 1;
elmot 1:d0dfbce63a89 1296 }
elmot 1:d0dfbce63a89 1297 else
elmot 1:d0dfbce63a89 1298 {
elmot 1:d0dfbce63a89 1299 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1300 }
elmot 1:d0dfbce63a89 1301 /* Return function status */
elmot 1:d0dfbce63a89 1302 return status;
elmot 1:d0dfbce63a89 1303 }
elmot 1:d0dfbce63a89 1304
elmot 1:d0dfbce63a89 1305 /**
elmot 1:d0dfbce63a89 1306 * @}
elmot 1:d0dfbce63a89 1307 */
elmot 1:d0dfbce63a89 1308
elmot 1:d0dfbce63a89 1309 /** @defgroup DFSDM_Exported_Functions_Group3_Filter Filter operation functions
elmot 1:d0dfbce63a89 1310 * @brief Filter operation functions
elmot 1:d0dfbce63a89 1311 *
elmot 1:d0dfbce63a89 1312 @verbatim
elmot 1:d0dfbce63a89 1313 ==============================================================================
elmot 1:d0dfbce63a89 1314 ##### Filter operation functions #####
elmot 1:d0dfbce63a89 1315 ==============================================================================
elmot 1:d0dfbce63a89 1316 [..] This section provides functions allowing to:
elmot 1:d0dfbce63a89 1317 (+) Start conversion of regular/injected channel.
elmot 1:d0dfbce63a89 1318 (+) Poll for the end of regular/injected conversion.
elmot 1:d0dfbce63a89 1319 (+) Stop conversion of regular/injected channel.
elmot 1:d0dfbce63a89 1320 (+) Start conversion of regular/injected channel and enable interrupt.
elmot 1:d0dfbce63a89 1321 (+) Call the callback functions at the end of regular/injected conversions.
elmot 1:d0dfbce63a89 1322 (+) Stop conversion of regular/injected channel and disable interrupt.
elmot 1:d0dfbce63a89 1323 (+) Start conversion of regular/injected channel and enable DMA transfer.
elmot 1:d0dfbce63a89 1324 (+) Stop conversion of regular/injected channel and disable DMA transfer.
elmot 1:d0dfbce63a89 1325 (+) Start analog watchdog and enable interrupt.
elmot 1:d0dfbce63a89 1326 (+) Call the callback function when analog watchdog occurs.
elmot 1:d0dfbce63a89 1327 (+) Stop analog watchdog and disable interrupt.
elmot 1:d0dfbce63a89 1328 (+) Start extreme detector.
elmot 1:d0dfbce63a89 1329 (+) Stop extreme detector.
elmot 1:d0dfbce63a89 1330 (+) Get result of regular channel conversion.
elmot 1:d0dfbce63a89 1331 (+) Get result of injected channel conversion.
elmot 1:d0dfbce63a89 1332 (+) Get extreme detector maximum and minimum values.
elmot 1:d0dfbce63a89 1333 (+) Get conversion time.
elmot 1:d0dfbce63a89 1334 (+) Handle DFSDM interrupt request.
elmot 1:d0dfbce63a89 1335 @endverbatim
elmot 1:d0dfbce63a89 1336 * @{
elmot 1:d0dfbce63a89 1337 */
elmot 1:d0dfbce63a89 1338
elmot 1:d0dfbce63a89 1339 /**
elmot 1:d0dfbce63a89 1340 * @brief This function allows to start regular conversion in polling mode.
elmot 1:d0dfbce63a89 1341 * @note This function should be called only when DFSDM filter instance is
elmot 1:d0dfbce63a89 1342 * in idle state or if injected conversion is ongoing.
elmot 1:d0dfbce63a89 1343 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1344 * @retval HAL status
elmot 1:d0dfbce63a89 1345 */
elmot 1:d0dfbce63a89 1346 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 1347 {
elmot 1:d0dfbce63a89 1348 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1349
elmot 1:d0dfbce63a89 1350 /* Check parameters */
elmot 1:d0dfbce63a89 1351 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1352
elmot 1:d0dfbce63a89 1353 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1354 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
elmot 1:d0dfbce63a89 1355 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
elmot 1:d0dfbce63a89 1356 {
elmot 1:d0dfbce63a89 1357 /* Start regular conversion */
elmot 1:d0dfbce63a89 1358 DFSDM_RegConvStart(hdfsdm_filter);
elmot 1:d0dfbce63a89 1359 }
elmot 1:d0dfbce63a89 1360 else
elmot 1:d0dfbce63a89 1361 {
elmot 1:d0dfbce63a89 1362 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1363 }
elmot 1:d0dfbce63a89 1364 /* Return function status */
elmot 1:d0dfbce63a89 1365 return status;
elmot 1:d0dfbce63a89 1366 }
elmot 1:d0dfbce63a89 1367
elmot 1:d0dfbce63a89 1368 /**
elmot 1:d0dfbce63a89 1369 * @brief This function allows to poll for the end of regular conversion.
elmot 1:d0dfbce63a89 1370 * @note This function should be called only if regular conversion is ongoing.
elmot 1:d0dfbce63a89 1371 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1372 * @param Timeout : Timeout value in milliseconds.
elmot 1:d0dfbce63a89 1373 * @retval HAL status
elmot 1:d0dfbce63a89 1374 */
elmot 1:d0dfbce63a89 1375 HAL_StatusTypeDef HAL_DFSDM_FilterPollForRegConversion(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 1376 uint32_t Timeout)
elmot 1:d0dfbce63a89 1377 {
elmot 1:d0dfbce63a89 1378 uint32_t tickstart;
elmot 1:d0dfbce63a89 1379
elmot 1:d0dfbce63a89 1380 /* Check parameters */
elmot 1:d0dfbce63a89 1381 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1382
elmot 1:d0dfbce63a89 1383 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1384 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
elmot 1:d0dfbce63a89 1385 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
elmot 1:d0dfbce63a89 1386 {
elmot 1:d0dfbce63a89 1387 /* Return error status */
elmot 1:d0dfbce63a89 1388 return HAL_ERROR;
elmot 1:d0dfbce63a89 1389 }
elmot 1:d0dfbce63a89 1390 else
elmot 1:d0dfbce63a89 1391 {
elmot 1:d0dfbce63a89 1392 /* Get timeout */
elmot 1:d0dfbce63a89 1393 tickstart = HAL_GetTick();
elmot 1:d0dfbce63a89 1394
elmot 1:d0dfbce63a89 1395 /* Wait end of regular conversion */
elmot 1:d0dfbce63a89 1396 while((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_REOCF) != DFSDM_FLTISR_REOCF)
elmot 1:d0dfbce63a89 1397 {
elmot 1:d0dfbce63a89 1398 /* Check the Timeout */
elmot 1:d0dfbce63a89 1399 if(Timeout != HAL_MAX_DELAY)
elmot 1:d0dfbce63a89 1400 {
elmot 1:d0dfbce63a89 1401 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
elmot 1:d0dfbce63a89 1402 {
elmot 1:d0dfbce63a89 1403 /* Return timeout status */
elmot 1:d0dfbce63a89 1404 return HAL_TIMEOUT;
elmot 1:d0dfbce63a89 1405 }
elmot 1:d0dfbce63a89 1406 }
elmot 1:d0dfbce63a89 1407 }
elmot 1:d0dfbce63a89 1408 /* Check if overrun occurs */
elmot 1:d0dfbce63a89 1409 if((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_ROVRF) == DFSDM_FLTISR_ROVRF)
elmot 1:d0dfbce63a89 1410 {
elmot 1:d0dfbce63a89 1411 /* Update error code and call error callback */
elmot 1:d0dfbce63a89 1412 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_REGULAR_OVERRUN;
elmot 1:d0dfbce63a89 1413 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
elmot 1:d0dfbce63a89 1414
elmot 1:d0dfbce63a89 1415 /* Clear regular overrun flag */
elmot 1:d0dfbce63a89 1416 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRROVRF;
elmot 1:d0dfbce63a89 1417 }
elmot 1:d0dfbce63a89 1418 /* Update DFSDM filter state only if not continuous conversion and SW trigger */
elmot 1:d0dfbce63a89 1419 if((hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
elmot 1:d0dfbce63a89 1420 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
elmot 1:d0dfbce63a89 1421 {
elmot 1:d0dfbce63a89 1422 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \
elmot 1:d0dfbce63a89 1423 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ;
elmot 1:d0dfbce63a89 1424 }
elmot 1:d0dfbce63a89 1425 /* Return function status */
elmot 1:d0dfbce63a89 1426 return HAL_OK;
elmot 1:d0dfbce63a89 1427 }
elmot 1:d0dfbce63a89 1428 }
elmot 1:d0dfbce63a89 1429
elmot 1:d0dfbce63a89 1430 /**
elmot 1:d0dfbce63a89 1431 * @brief This function allows to stop regular conversion in polling mode.
elmot 1:d0dfbce63a89 1432 * @note This function should be called only if regular conversion is ongoing.
elmot 1:d0dfbce63a89 1433 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1434 * @retval HAL status
elmot 1:d0dfbce63a89 1435 */
elmot 1:d0dfbce63a89 1436 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 1437 {
elmot 1:d0dfbce63a89 1438 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1439
elmot 1:d0dfbce63a89 1440 /* Check parameters */
elmot 1:d0dfbce63a89 1441 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1442
elmot 1:d0dfbce63a89 1443 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1444 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
elmot 1:d0dfbce63a89 1445 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
elmot 1:d0dfbce63a89 1446 {
elmot 1:d0dfbce63a89 1447 /* Return error status */
elmot 1:d0dfbce63a89 1448 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1449 }
elmot 1:d0dfbce63a89 1450 else
elmot 1:d0dfbce63a89 1451 {
elmot 1:d0dfbce63a89 1452 /* Stop regular conversion */
elmot 1:d0dfbce63a89 1453 DFSDM_RegConvStop(hdfsdm_filter);
elmot 1:d0dfbce63a89 1454 }
elmot 1:d0dfbce63a89 1455 /* Return function status */
elmot 1:d0dfbce63a89 1456 return status;
elmot 1:d0dfbce63a89 1457 }
elmot 1:d0dfbce63a89 1458
elmot 1:d0dfbce63a89 1459 /**
elmot 1:d0dfbce63a89 1460 * @brief This function allows to start regular conversion in interrupt mode.
elmot 1:d0dfbce63a89 1461 * @note This function should be called only when DFSDM filter instance is
elmot 1:d0dfbce63a89 1462 * in idle state or if injected conversion is ongoing.
elmot 1:d0dfbce63a89 1463 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1464 * @retval HAL status
elmot 1:d0dfbce63a89 1465 */
elmot 1:d0dfbce63a89 1466 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 1467 {
elmot 1:d0dfbce63a89 1468 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1469
elmot 1:d0dfbce63a89 1470 /* Check parameters */
elmot 1:d0dfbce63a89 1471 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1472
elmot 1:d0dfbce63a89 1473 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1474 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
elmot 1:d0dfbce63a89 1475 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
elmot 1:d0dfbce63a89 1476 {
elmot 1:d0dfbce63a89 1477 /* Enable interrupts for regular conversions */
elmot 1:d0dfbce63a89 1478 hdfsdm_filter->Instance->FLTCR2 |= (DFSDM_FLTCR2_REOCIE | DFSDM_FLTCR2_ROVRIE);
elmot 1:d0dfbce63a89 1479
elmot 1:d0dfbce63a89 1480 /* Start regular conversion */
elmot 1:d0dfbce63a89 1481 DFSDM_RegConvStart(hdfsdm_filter);
elmot 1:d0dfbce63a89 1482 }
elmot 1:d0dfbce63a89 1483 else
elmot 1:d0dfbce63a89 1484 {
elmot 1:d0dfbce63a89 1485 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1486 }
elmot 1:d0dfbce63a89 1487 /* Return function status */
elmot 1:d0dfbce63a89 1488 return status;
elmot 1:d0dfbce63a89 1489 }
elmot 1:d0dfbce63a89 1490
elmot 1:d0dfbce63a89 1491 /**
elmot 1:d0dfbce63a89 1492 * @brief This function allows to stop regular conversion in interrupt mode.
elmot 1:d0dfbce63a89 1493 * @note This function should be called only if regular conversion is ongoing.
elmot 1:d0dfbce63a89 1494 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1495 * @retval HAL status
elmot 1:d0dfbce63a89 1496 */
elmot 1:d0dfbce63a89 1497 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 1498 {
elmot 1:d0dfbce63a89 1499 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1500
elmot 1:d0dfbce63a89 1501 /* Check parameters */
elmot 1:d0dfbce63a89 1502 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1503
elmot 1:d0dfbce63a89 1504 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1505 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
elmot 1:d0dfbce63a89 1506 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
elmot 1:d0dfbce63a89 1507 {
elmot 1:d0dfbce63a89 1508 /* Return error status */
elmot 1:d0dfbce63a89 1509 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1510 }
elmot 1:d0dfbce63a89 1511 else
elmot 1:d0dfbce63a89 1512 {
elmot 1:d0dfbce63a89 1513 /* Disable interrupts for regular conversions */
elmot 1:d0dfbce63a89 1514 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_REOCIE | DFSDM_FLTCR2_ROVRIE);
elmot 1:d0dfbce63a89 1515
elmot 1:d0dfbce63a89 1516 /* Stop regular conversion */
elmot 1:d0dfbce63a89 1517 DFSDM_RegConvStop(hdfsdm_filter);
elmot 1:d0dfbce63a89 1518 }
elmot 1:d0dfbce63a89 1519 /* Return function status */
elmot 1:d0dfbce63a89 1520 return status;
elmot 1:d0dfbce63a89 1521 }
elmot 1:d0dfbce63a89 1522
elmot 1:d0dfbce63a89 1523 /**
elmot 1:d0dfbce63a89 1524 * @brief This function allows to start regular conversion in DMA mode.
elmot 1:d0dfbce63a89 1525 * @note This function should be called only when DFSDM filter instance is
elmot 1:d0dfbce63a89 1526 * in idle state or if injected conversion is ongoing.
elmot 1:d0dfbce63a89 1527 * Please note that data on buffer will contain signed regular conversion
elmot 1:d0dfbce63a89 1528 * value on 24 most significant bits and corresponding channel on 3 least
elmot 1:d0dfbce63a89 1529 * significant bits.
elmot 1:d0dfbce63a89 1530 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1531 * @param pData : The destination buffer address.
elmot 1:d0dfbce63a89 1532 * @param Length : The length of data to be transferred from DFSDM filter to memory.
elmot 1:d0dfbce63a89 1533 * @retval HAL status
elmot 1:d0dfbce63a89 1534 */
elmot 1:d0dfbce63a89 1535 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 1536 int32_t *pData,
elmot 1:d0dfbce63a89 1537 uint32_t Length)
elmot 1:d0dfbce63a89 1538 {
elmot 1:d0dfbce63a89 1539 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1540
elmot 1:d0dfbce63a89 1541 /* Check parameters */
elmot 1:d0dfbce63a89 1542 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1543
elmot 1:d0dfbce63a89 1544 /* Check destination address and length */
elmot 1:d0dfbce63a89 1545 if((pData == NULL) || (Length == 0))
elmot 1:d0dfbce63a89 1546 {
elmot 1:d0dfbce63a89 1547 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1548 }
elmot 1:d0dfbce63a89 1549 /* Check that DMA is enabled for regular conversion */
elmot 1:d0dfbce63a89 1550 else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_RDMAEN) != DFSDM_FLTCR1_RDMAEN)
elmot 1:d0dfbce63a89 1551 {
elmot 1:d0dfbce63a89 1552 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1553 }
elmot 1:d0dfbce63a89 1554 /* Check parameters compatibility */
elmot 1:d0dfbce63a89 1555 else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
elmot 1:d0dfbce63a89 1556 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
elmot 1:d0dfbce63a89 1557 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_NORMAL) && \
elmot 1:d0dfbce63a89 1558 (Length != 1))
elmot 1:d0dfbce63a89 1559 {
elmot 1:d0dfbce63a89 1560 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1561 }
elmot 1:d0dfbce63a89 1562 else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
elmot 1:d0dfbce63a89 1563 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
elmot 1:d0dfbce63a89 1564 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR))
elmot 1:d0dfbce63a89 1565 {
elmot 1:d0dfbce63a89 1566 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1567 }
elmot 1:d0dfbce63a89 1568 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1569 else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
elmot 1:d0dfbce63a89 1570 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
elmot 1:d0dfbce63a89 1571 {
elmot 1:d0dfbce63a89 1572 /* Set callbacks on DMA handler */
elmot 1:d0dfbce63a89 1573 hdfsdm_filter->hdmaReg->XferCpltCallback = DFSDM_DMARegularConvCplt;
elmot 1:d0dfbce63a89 1574 hdfsdm_filter->hdmaReg->XferErrorCallback = DFSDM_DMAError;
elmot 1:d0dfbce63a89 1575 hdfsdm_filter->hdmaReg->XferHalfCpltCallback = (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR) ?\
elmot 1:d0dfbce63a89 1576 DFSDM_DMARegularHalfConvCplt : NULL;
elmot 1:d0dfbce63a89 1577
elmot 1:d0dfbce63a89 1578 /* Start DMA in interrupt mode */
elmot 1:d0dfbce63a89 1579 if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaReg, (uint32_t)&hdfsdm_filter->Instance->FLTRDATAR, \
elmot 1:d0dfbce63a89 1580 (uint32_t) pData, Length) != HAL_OK)
elmot 1:d0dfbce63a89 1581 {
elmot 1:d0dfbce63a89 1582 /* Set DFSDM filter in error state */
elmot 1:d0dfbce63a89 1583 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
elmot 1:d0dfbce63a89 1584 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1585 }
elmot 1:d0dfbce63a89 1586 else
elmot 1:d0dfbce63a89 1587 {
elmot 1:d0dfbce63a89 1588 /* Start regular conversion */
elmot 1:d0dfbce63a89 1589 DFSDM_RegConvStart(hdfsdm_filter);
elmot 1:d0dfbce63a89 1590 }
elmot 1:d0dfbce63a89 1591 }
elmot 1:d0dfbce63a89 1592 else
elmot 1:d0dfbce63a89 1593 {
elmot 1:d0dfbce63a89 1594 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1595 }
elmot 1:d0dfbce63a89 1596 /* Return function status */
elmot 1:d0dfbce63a89 1597 return status;
elmot 1:d0dfbce63a89 1598 }
elmot 1:d0dfbce63a89 1599
elmot 1:d0dfbce63a89 1600 /**
elmot 1:d0dfbce63a89 1601 * @brief This function allows to start regular conversion in DMA mode and to get
elmot 1:d0dfbce63a89 1602 * only the 16 most significant bits of conversion.
elmot 1:d0dfbce63a89 1603 * @note This function should be called only when DFSDM filter instance is
elmot 1:d0dfbce63a89 1604 * in idle state or if injected conversion is ongoing.
elmot 1:d0dfbce63a89 1605 * Please note that data on buffer will contain signed 16 most significant
elmot 1:d0dfbce63a89 1606 * bits of regular conversion.
elmot 1:d0dfbce63a89 1607 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1608 * @param pData : The destination buffer address.
elmot 1:d0dfbce63a89 1609 * @param Length : The length of data to be transferred from DFSDM filter to memory.
elmot 1:d0dfbce63a89 1610 * @retval HAL status
elmot 1:d0dfbce63a89 1611 */
elmot 1:d0dfbce63a89 1612 HAL_StatusTypeDef HAL_DFSDM_FilterRegularMsbStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 1613 int16_t *pData,
elmot 1:d0dfbce63a89 1614 uint32_t Length)
elmot 1:d0dfbce63a89 1615 {
elmot 1:d0dfbce63a89 1616 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1617
elmot 1:d0dfbce63a89 1618 /* Check parameters */
elmot 1:d0dfbce63a89 1619 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1620
elmot 1:d0dfbce63a89 1621 /* Check destination address and length */
elmot 1:d0dfbce63a89 1622 if((pData == NULL) || (Length == 0))
elmot 1:d0dfbce63a89 1623 {
elmot 1:d0dfbce63a89 1624 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1625 }
elmot 1:d0dfbce63a89 1626 /* Check that DMA is enabled for regular conversion */
elmot 1:d0dfbce63a89 1627 else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_RDMAEN) != DFSDM_FLTCR1_RDMAEN)
elmot 1:d0dfbce63a89 1628 {
elmot 1:d0dfbce63a89 1629 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1630 }
elmot 1:d0dfbce63a89 1631 /* Check parameters compatibility */
elmot 1:d0dfbce63a89 1632 else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
elmot 1:d0dfbce63a89 1633 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
elmot 1:d0dfbce63a89 1634 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_NORMAL) && \
elmot 1:d0dfbce63a89 1635 (Length != 1))
elmot 1:d0dfbce63a89 1636 {
elmot 1:d0dfbce63a89 1637 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1638 }
elmot 1:d0dfbce63a89 1639 else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
elmot 1:d0dfbce63a89 1640 (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
elmot 1:d0dfbce63a89 1641 (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR))
elmot 1:d0dfbce63a89 1642 {
elmot 1:d0dfbce63a89 1643 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1644 }
elmot 1:d0dfbce63a89 1645 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1646 else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
elmot 1:d0dfbce63a89 1647 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
elmot 1:d0dfbce63a89 1648 {
elmot 1:d0dfbce63a89 1649 /* Set callbacks on DMA handler */
elmot 1:d0dfbce63a89 1650 hdfsdm_filter->hdmaReg->XferCpltCallback = DFSDM_DMARegularConvCplt;
elmot 1:d0dfbce63a89 1651 hdfsdm_filter->hdmaReg->XferErrorCallback = DFSDM_DMAError;
elmot 1:d0dfbce63a89 1652 hdfsdm_filter->hdmaReg->XferHalfCpltCallback = (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR) ?\
elmot 1:d0dfbce63a89 1653 DFSDM_DMARegularHalfConvCplt : NULL;
elmot 1:d0dfbce63a89 1654
elmot 1:d0dfbce63a89 1655 /* Start DMA in interrupt mode */
elmot 1:d0dfbce63a89 1656 if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaReg, (uint32_t)(&hdfsdm_filter->Instance->FLTRDATAR) + 2, \
elmot 1:d0dfbce63a89 1657 (uint32_t) pData, Length) != HAL_OK)
elmot 1:d0dfbce63a89 1658 {
elmot 1:d0dfbce63a89 1659 /* Set DFSDM filter in error state */
elmot 1:d0dfbce63a89 1660 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
elmot 1:d0dfbce63a89 1661 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1662 }
elmot 1:d0dfbce63a89 1663 else
elmot 1:d0dfbce63a89 1664 {
elmot 1:d0dfbce63a89 1665 /* Start regular conversion */
elmot 1:d0dfbce63a89 1666 DFSDM_RegConvStart(hdfsdm_filter);
elmot 1:d0dfbce63a89 1667 }
elmot 1:d0dfbce63a89 1668 }
elmot 1:d0dfbce63a89 1669 else
elmot 1:d0dfbce63a89 1670 {
elmot 1:d0dfbce63a89 1671 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1672 }
elmot 1:d0dfbce63a89 1673 /* Return function status */
elmot 1:d0dfbce63a89 1674 return status;
elmot 1:d0dfbce63a89 1675 }
elmot 1:d0dfbce63a89 1676
elmot 1:d0dfbce63a89 1677 /**
elmot 1:d0dfbce63a89 1678 * @brief This function allows to stop regular conversion in DMA mode.
elmot 1:d0dfbce63a89 1679 * @note This function should be called only if regular conversion is ongoing.
elmot 1:d0dfbce63a89 1680 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1681 * @retval HAL status
elmot 1:d0dfbce63a89 1682 */
elmot 1:d0dfbce63a89 1683 HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 1684 {
elmot 1:d0dfbce63a89 1685 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1686
elmot 1:d0dfbce63a89 1687 /* Check parameters */
elmot 1:d0dfbce63a89 1688 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1689
elmot 1:d0dfbce63a89 1690 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1691 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
elmot 1:d0dfbce63a89 1692 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
elmot 1:d0dfbce63a89 1693 {
elmot 1:d0dfbce63a89 1694 /* Return error status */
elmot 1:d0dfbce63a89 1695 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1696 }
elmot 1:d0dfbce63a89 1697 else
elmot 1:d0dfbce63a89 1698 {
elmot 1:d0dfbce63a89 1699 /* Stop current DMA transfer */
elmot 1:d0dfbce63a89 1700 if(HAL_DMA_Abort(hdfsdm_filter->hdmaReg) != HAL_OK)
elmot 1:d0dfbce63a89 1701 {
elmot 1:d0dfbce63a89 1702 /* Set DFSDM filter in error state */
elmot 1:d0dfbce63a89 1703 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
elmot 1:d0dfbce63a89 1704 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1705 }
elmot 1:d0dfbce63a89 1706 else
elmot 1:d0dfbce63a89 1707 {
elmot 1:d0dfbce63a89 1708 /* Stop regular conversion */
elmot 1:d0dfbce63a89 1709 DFSDM_RegConvStop(hdfsdm_filter);
elmot 1:d0dfbce63a89 1710 }
elmot 1:d0dfbce63a89 1711 }
elmot 1:d0dfbce63a89 1712 /* Return function status */
elmot 1:d0dfbce63a89 1713 return status;
elmot 1:d0dfbce63a89 1714 }
elmot 1:d0dfbce63a89 1715
elmot 1:d0dfbce63a89 1716 /**
elmot 1:d0dfbce63a89 1717 * @brief This function allows to get regular conversion value.
elmot 1:d0dfbce63a89 1718 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1719 * @param Channel : Corresponding channel of regular conversion.
elmot 1:d0dfbce63a89 1720 * @retval Regular conversion value
elmot 1:d0dfbce63a89 1721 */
elmot 1:d0dfbce63a89 1722 int32_t HAL_DFSDM_FilterGetRegularValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 1723 uint32_t *Channel)
elmot 1:d0dfbce63a89 1724 {
elmot 1:d0dfbce63a89 1725 uint32_t reg = 0;
elmot 1:d0dfbce63a89 1726 int32_t value = 0;
elmot 1:d0dfbce63a89 1727
elmot 1:d0dfbce63a89 1728 /* Check parameters */
elmot 1:d0dfbce63a89 1729 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1730 assert_param(Channel != NULL);
elmot 1:d0dfbce63a89 1731
elmot 1:d0dfbce63a89 1732 /* Get value of data register for regular channel */
elmot 1:d0dfbce63a89 1733 reg = hdfsdm_filter->Instance->FLTRDATAR;
elmot 1:d0dfbce63a89 1734
elmot 1:d0dfbce63a89 1735 /* Extract channel and regular conversion value */
elmot 1:d0dfbce63a89 1736 *Channel = (reg & DFSDM_FLTRDATAR_RDATACH);
elmot 1:d0dfbce63a89 1737 value = ((reg & DFSDM_FLTRDATAR_RDATA) >> DFSDM_FLTRDATAR_DATA_OFFSET);
elmot 1:d0dfbce63a89 1738
elmot 1:d0dfbce63a89 1739 /* return regular conversion value */
elmot 1:d0dfbce63a89 1740 return value;
elmot 1:d0dfbce63a89 1741 }
elmot 1:d0dfbce63a89 1742
elmot 1:d0dfbce63a89 1743 /**
elmot 1:d0dfbce63a89 1744 * @brief This function allows to start injected conversion in polling mode.
elmot 1:d0dfbce63a89 1745 * @note This function should be called only when DFSDM filter instance is
elmot 1:d0dfbce63a89 1746 * in idle state or if regular conversion is ongoing.
elmot 1:d0dfbce63a89 1747 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1748 * @retval HAL status
elmot 1:d0dfbce63a89 1749 */
elmot 1:d0dfbce63a89 1750 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 1751 {
elmot 1:d0dfbce63a89 1752 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1753
elmot 1:d0dfbce63a89 1754 /* Check parameters */
elmot 1:d0dfbce63a89 1755 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1756
elmot 1:d0dfbce63a89 1757 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1758 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
elmot 1:d0dfbce63a89 1759 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
elmot 1:d0dfbce63a89 1760 {
elmot 1:d0dfbce63a89 1761 /* Start injected conversion */
elmot 1:d0dfbce63a89 1762 DFSDM_InjConvStart(hdfsdm_filter);
elmot 1:d0dfbce63a89 1763 }
elmot 1:d0dfbce63a89 1764 else
elmot 1:d0dfbce63a89 1765 {
elmot 1:d0dfbce63a89 1766 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1767 }
elmot 1:d0dfbce63a89 1768 /* Return function status */
elmot 1:d0dfbce63a89 1769 return status;
elmot 1:d0dfbce63a89 1770 }
elmot 1:d0dfbce63a89 1771
elmot 1:d0dfbce63a89 1772 /**
elmot 1:d0dfbce63a89 1773 * @brief This function allows to poll for the end of injected conversion.
elmot 1:d0dfbce63a89 1774 * @note This function should be called only if injected conversion is ongoing.
elmot 1:d0dfbce63a89 1775 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1776 * @param Timeout : Timeout value in milliseconds.
elmot 1:d0dfbce63a89 1777 * @retval HAL status
elmot 1:d0dfbce63a89 1778 */
elmot 1:d0dfbce63a89 1779 HAL_StatusTypeDef HAL_DFSDM_FilterPollForInjConversion(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 1780 uint32_t Timeout)
elmot 1:d0dfbce63a89 1781 {
elmot 1:d0dfbce63a89 1782 uint32_t tickstart;
elmot 1:d0dfbce63a89 1783
elmot 1:d0dfbce63a89 1784 /* Check parameters */
elmot 1:d0dfbce63a89 1785 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1786
elmot 1:d0dfbce63a89 1787 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1788 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
elmot 1:d0dfbce63a89 1789 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
elmot 1:d0dfbce63a89 1790 {
elmot 1:d0dfbce63a89 1791 /* Return error status */
elmot 1:d0dfbce63a89 1792 return HAL_ERROR;
elmot 1:d0dfbce63a89 1793 }
elmot 1:d0dfbce63a89 1794 else
elmot 1:d0dfbce63a89 1795 {
elmot 1:d0dfbce63a89 1796 /* Get timeout */
elmot 1:d0dfbce63a89 1797 tickstart = HAL_GetTick();
elmot 1:d0dfbce63a89 1798
elmot 1:d0dfbce63a89 1799 /* Wait end of injected conversions */
elmot 1:d0dfbce63a89 1800 while((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JEOCF) != DFSDM_FLTISR_JEOCF)
elmot 1:d0dfbce63a89 1801 {
elmot 1:d0dfbce63a89 1802 /* Check the Timeout */
elmot 1:d0dfbce63a89 1803 if(Timeout != HAL_MAX_DELAY)
elmot 1:d0dfbce63a89 1804 {
elmot 1:d0dfbce63a89 1805 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
elmot 1:d0dfbce63a89 1806 {
elmot 1:d0dfbce63a89 1807 /* Return timeout status */
elmot 1:d0dfbce63a89 1808 return HAL_TIMEOUT;
elmot 1:d0dfbce63a89 1809 }
elmot 1:d0dfbce63a89 1810 }
elmot 1:d0dfbce63a89 1811 }
elmot 1:d0dfbce63a89 1812 /* Check if overrun occurs */
elmot 1:d0dfbce63a89 1813 if((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JOVRF) == DFSDM_FLTISR_JOVRF)
elmot 1:d0dfbce63a89 1814 {
elmot 1:d0dfbce63a89 1815 /* Update error code and call error callback */
elmot 1:d0dfbce63a89 1816 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INJECTED_OVERRUN;
elmot 1:d0dfbce63a89 1817 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
elmot 1:d0dfbce63a89 1818
elmot 1:d0dfbce63a89 1819 /* Clear injected overrun flag */
elmot 1:d0dfbce63a89 1820 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRJOVRF;
elmot 1:d0dfbce63a89 1821 }
elmot 1:d0dfbce63a89 1822
elmot 1:d0dfbce63a89 1823 /* Update remaining injected conversions */
elmot 1:d0dfbce63a89 1824 hdfsdm_filter->InjConvRemaining--;
elmot 1:d0dfbce63a89 1825 if(hdfsdm_filter->InjConvRemaining == 0)
elmot 1:d0dfbce63a89 1826 {
elmot 1:d0dfbce63a89 1827 /* Update DFSDM filter state only if trigger is software */
elmot 1:d0dfbce63a89 1828 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
elmot 1:d0dfbce63a89 1829 {
elmot 1:d0dfbce63a89 1830 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \
elmot 1:d0dfbce63a89 1831 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG;
elmot 1:d0dfbce63a89 1832 }
elmot 1:d0dfbce63a89 1833
elmot 1:d0dfbce63a89 1834 /* end of injected sequence, reset the value */
elmot 1:d0dfbce63a89 1835 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
elmot 1:d0dfbce63a89 1836 hdfsdm_filter->InjectedChannelsNbr : 1;
elmot 1:d0dfbce63a89 1837 }
elmot 1:d0dfbce63a89 1838
elmot 1:d0dfbce63a89 1839 /* Return function status */
elmot 1:d0dfbce63a89 1840 return HAL_OK;
elmot 1:d0dfbce63a89 1841 }
elmot 1:d0dfbce63a89 1842 }
elmot 1:d0dfbce63a89 1843
elmot 1:d0dfbce63a89 1844 /**
elmot 1:d0dfbce63a89 1845 * @brief This function allows to stop injected conversion in polling mode.
elmot 1:d0dfbce63a89 1846 * @note This function should be called only if injected conversion is ongoing.
elmot 1:d0dfbce63a89 1847 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1848 * @retval HAL status
elmot 1:d0dfbce63a89 1849 */
elmot 1:d0dfbce63a89 1850 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 1851 {
elmot 1:d0dfbce63a89 1852 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1853
elmot 1:d0dfbce63a89 1854 /* Check parameters */
elmot 1:d0dfbce63a89 1855 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1856
elmot 1:d0dfbce63a89 1857 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1858 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
elmot 1:d0dfbce63a89 1859 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
elmot 1:d0dfbce63a89 1860 {
elmot 1:d0dfbce63a89 1861 /* Return error status */
elmot 1:d0dfbce63a89 1862 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1863 }
elmot 1:d0dfbce63a89 1864 else
elmot 1:d0dfbce63a89 1865 {
elmot 1:d0dfbce63a89 1866 /* Stop injected conversion */
elmot 1:d0dfbce63a89 1867 DFSDM_InjConvStop(hdfsdm_filter);
elmot 1:d0dfbce63a89 1868 }
elmot 1:d0dfbce63a89 1869 /* Return function status */
elmot 1:d0dfbce63a89 1870 return status;
elmot 1:d0dfbce63a89 1871 }
elmot 1:d0dfbce63a89 1872
elmot 1:d0dfbce63a89 1873 /**
elmot 1:d0dfbce63a89 1874 * @brief This function allows to start injected conversion in interrupt mode.
elmot 1:d0dfbce63a89 1875 * @note This function should be called only when DFSDM filter instance is
elmot 1:d0dfbce63a89 1876 * in idle state or if regular conversion is ongoing.
elmot 1:d0dfbce63a89 1877 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1878 * @retval HAL status
elmot 1:d0dfbce63a89 1879 */
elmot 1:d0dfbce63a89 1880 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 1881 {
elmot 1:d0dfbce63a89 1882 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1883
elmot 1:d0dfbce63a89 1884 /* Check parameters */
elmot 1:d0dfbce63a89 1885 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1886
elmot 1:d0dfbce63a89 1887 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1888 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
elmot 1:d0dfbce63a89 1889 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
elmot 1:d0dfbce63a89 1890 {
elmot 1:d0dfbce63a89 1891 /* Enable interrupts for injected conversions */
elmot 1:d0dfbce63a89 1892 hdfsdm_filter->Instance->FLTCR2 |= (DFSDM_FLTCR2_JEOCIE | DFSDM_FLTCR2_JOVRIE);
elmot 1:d0dfbce63a89 1893
elmot 1:d0dfbce63a89 1894 /* Start injected conversion */
elmot 1:d0dfbce63a89 1895 DFSDM_InjConvStart(hdfsdm_filter);
elmot 1:d0dfbce63a89 1896 }
elmot 1:d0dfbce63a89 1897 else
elmot 1:d0dfbce63a89 1898 {
elmot 1:d0dfbce63a89 1899 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1900 }
elmot 1:d0dfbce63a89 1901 /* Return function status */
elmot 1:d0dfbce63a89 1902 return status;
elmot 1:d0dfbce63a89 1903 }
elmot 1:d0dfbce63a89 1904
elmot 1:d0dfbce63a89 1905 /**
elmot 1:d0dfbce63a89 1906 * @brief This function allows to stop injected conversion in interrupt mode.
elmot 1:d0dfbce63a89 1907 * @note This function should be called only if injected conversion is ongoing.
elmot 1:d0dfbce63a89 1908 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1909 * @retval HAL status
elmot 1:d0dfbce63a89 1910 */
elmot 1:d0dfbce63a89 1911 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 1912 {
elmot 1:d0dfbce63a89 1913 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1914
elmot 1:d0dfbce63a89 1915 /* Check parameters */
elmot 1:d0dfbce63a89 1916 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1917
elmot 1:d0dfbce63a89 1918 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1919 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
elmot 1:d0dfbce63a89 1920 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
elmot 1:d0dfbce63a89 1921 {
elmot 1:d0dfbce63a89 1922 /* Return error status */
elmot 1:d0dfbce63a89 1923 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1924 }
elmot 1:d0dfbce63a89 1925 else
elmot 1:d0dfbce63a89 1926 {
elmot 1:d0dfbce63a89 1927 /* Disable interrupts for injected conversions */
elmot 1:d0dfbce63a89 1928 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_JEOCIE | DFSDM_FLTCR2_JOVRIE);
elmot 1:d0dfbce63a89 1929
elmot 1:d0dfbce63a89 1930 /* Stop injected conversion */
elmot 1:d0dfbce63a89 1931 DFSDM_InjConvStop(hdfsdm_filter);
elmot 1:d0dfbce63a89 1932 }
elmot 1:d0dfbce63a89 1933 /* Return function status */
elmot 1:d0dfbce63a89 1934 return status;
elmot 1:d0dfbce63a89 1935 }
elmot 1:d0dfbce63a89 1936
elmot 1:d0dfbce63a89 1937 /**
elmot 1:d0dfbce63a89 1938 * @brief This function allows to start injected conversion in DMA mode.
elmot 1:d0dfbce63a89 1939 * @note This function should be called only when DFSDM filter instance is
elmot 1:d0dfbce63a89 1940 * in idle state or if regular conversion is ongoing.
elmot 1:d0dfbce63a89 1941 * Please note that data on buffer will contain signed injected conversion
elmot 1:d0dfbce63a89 1942 * value on 24 most significant bits and corresponding channel on 3 least
elmot 1:d0dfbce63a89 1943 * significant bits.
elmot 1:d0dfbce63a89 1944 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 1945 * @param pData : The destination buffer address.
elmot 1:d0dfbce63a89 1946 * @param Length : The length of data to be transferred from DFSDM filter to memory.
elmot 1:d0dfbce63a89 1947 * @retval HAL status
elmot 1:d0dfbce63a89 1948 */
elmot 1:d0dfbce63a89 1949 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 1950 int32_t *pData,
elmot 1:d0dfbce63a89 1951 uint32_t Length)
elmot 1:d0dfbce63a89 1952 {
elmot 1:d0dfbce63a89 1953 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 1954
elmot 1:d0dfbce63a89 1955 /* Check parameters */
elmot 1:d0dfbce63a89 1956 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 1957
elmot 1:d0dfbce63a89 1958 /* Check destination address and length */
elmot 1:d0dfbce63a89 1959 if((pData == NULL) || (Length == 0))
elmot 1:d0dfbce63a89 1960 {
elmot 1:d0dfbce63a89 1961 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1962 }
elmot 1:d0dfbce63a89 1963 /* Check that DMA is enabled for injected conversion */
elmot 1:d0dfbce63a89 1964 else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_JDMAEN) != DFSDM_FLTCR1_JDMAEN)
elmot 1:d0dfbce63a89 1965 {
elmot 1:d0dfbce63a89 1966 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1967 }
elmot 1:d0dfbce63a89 1968 /* Check parameters compatibility */
elmot 1:d0dfbce63a89 1969 else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
elmot 1:d0dfbce63a89 1970 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_NORMAL) && \
elmot 1:d0dfbce63a89 1971 (Length > hdfsdm_filter->InjConvRemaining))
elmot 1:d0dfbce63a89 1972 {
elmot 1:d0dfbce63a89 1973 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1974 }
elmot 1:d0dfbce63a89 1975 else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
elmot 1:d0dfbce63a89 1976 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR))
elmot 1:d0dfbce63a89 1977 {
elmot 1:d0dfbce63a89 1978 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1979 }
elmot 1:d0dfbce63a89 1980 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 1981 else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
elmot 1:d0dfbce63a89 1982 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
elmot 1:d0dfbce63a89 1983 {
elmot 1:d0dfbce63a89 1984 /* Set callbacks on DMA handler */
elmot 1:d0dfbce63a89 1985 hdfsdm_filter->hdmaInj->XferCpltCallback = DFSDM_DMAInjectedConvCplt;
elmot 1:d0dfbce63a89 1986 hdfsdm_filter->hdmaInj->XferErrorCallback = DFSDM_DMAError;
elmot 1:d0dfbce63a89 1987 hdfsdm_filter->hdmaInj->XferHalfCpltCallback = (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR) ?\
elmot 1:d0dfbce63a89 1988 DFSDM_DMAInjectedHalfConvCplt : NULL;
elmot 1:d0dfbce63a89 1989
elmot 1:d0dfbce63a89 1990 /* Start DMA in interrupt mode */
elmot 1:d0dfbce63a89 1991 if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaInj, (uint32_t)&hdfsdm_filter->Instance->FLTJDATAR, \
elmot 1:d0dfbce63a89 1992 (uint32_t) pData, Length) != HAL_OK)
elmot 1:d0dfbce63a89 1993 {
elmot 1:d0dfbce63a89 1994 /* Set DFSDM filter in error state */
elmot 1:d0dfbce63a89 1995 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
elmot 1:d0dfbce63a89 1996 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1997 }
elmot 1:d0dfbce63a89 1998 else
elmot 1:d0dfbce63a89 1999 {
elmot 1:d0dfbce63a89 2000 /* Start injected conversion */
elmot 1:d0dfbce63a89 2001 DFSDM_InjConvStart(hdfsdm_filter);
elmot 1:d0dfbce63a89 2002 }
elmot 1:d0dfbce63a89 2003 }
elmot 1:d0dfbce63a89 2004 else
elmot 1:d0dfbce63a89 2005 {
elmot 1:d0dfbce63a89 2006 status = HAL_ERROR;
elmot 1:d0dfbce63a89 2007 }
elmot 1:d0dfbce63a89 2008 /* Return function status */
elmot 1:d0dfbce63a89 2009 return status;
elmot 1:d0dfbce63a89 2010 }
elmot 1:d0dfbce63a89 2011
elmot 1:d0dfbce63a89 2012 /**
elmot 1:d0dfbce63a89 2013 * @brief This function allows to start injected conversion in DMA mode and to get
elmot 1:d0dfbce63a89 2014 * only the 16 most significant bits of conversion.
elmot 1:d0dfbce63a89 2015 * @note This function should be called only when DFSDM filter instance is
elmot 1:d0dfbce63a89 2016 * in idle state or if regular conversion is ongoing.
elmot 1:d0dfbce63a89 2017 * Please note that data on buffer will contain signed 16 most significant
elmot 1:d0dfbce63a89 2018 * bits of injected conversion.
elmot 1:d0dfbce63a89 2019 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2020 * @param pData : The destination buffer address.
elmot 1:d0dfbce63a89 2021 * @param Length : The length of data to be transferred from DFSDM filter to memory.
elmot 1:d0dfbce63a89 2022 * @retval HAL status
elmot 1:d0dfbce63a89 2023 */
elmot 1:d0dfbce63a89 2024 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedMsbStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 2025 int16_t *pData,
elmot 1:d0dfbce63a89 2026 uint32_t Length)
elmot 1:d0dfbce63a89 2027 {
elmot 1:d0dfbce63a89 2028 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 2029
elmot 1:d0dfbce63a89 2030 /* Check parameters */
elmot 1:d0dfbce63a89 2031 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 2032
elmot 1:d0dfbce63a89 2033 /* Check destination address and length */
elmot 1:d0dfbce63a89 2034 if((pData == NULL) || (Length == 0))
elmot 1:d0dfbce63a89 2035 {
elmot 1:d0dfbce63a89 2036 status = HAL_ERROR;
elmot 1:d0dfbce63a89 2037 }
elmot 1:d0dfbce63a89 2038 /* Check that DMA is enabled for injected conversion */
elmot 1:d0dfbce63a89 2039 else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_JDMAEN) != DFSDM_FLTCR1_JDMAEN)
elmot 1:d0dfbce63a89 2040 {
elmot 1:d0dfbce63a89 2041 status = HAL_ERROR;
elmot 1:d0dfbce63a89 2042 }
elmot 1:d0dfbce63a89 2043 /* Check parameters compatibility */
elmot 1:d0dfbce63a89 2044 else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
elmot 1:d0dfbce63a89 2045 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_NORMAL) && \
elmot 1:d0dfbce63a89 2046 (Length > hdfsdm_filter->InjConvRemaining))
elmot 1:d0dfbce63a89 2047 {
elmot 1:d0dfbce63a89 2048 status = HAL_ERROR;
elmot 1:d0dfbce63a89 2049 }
elmot 1:d0dfbce63a89 2050 else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
elmot 1:d0dfbce63a89 2051 (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR))
elmot 1:d0dfbce63a89 2052 {
elmot 1:d0dfbce63a89 2053 status = HAL_ERROR;
elmot 1:d0dfbce63a89 2054 }
elmot 1:d0dfbce63a89 2055 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 2056 else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
elmot 1:d0dfbce63a89 2057 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
elmot 1:d0dfbce63a89 2058 {
elmot 1:d0dfbce63a89 2059 /* Set callbacks on DMA handler */
elmot 1:d0dfbce63a89 2060 hdfsdm_filter->hdmaInj->XferCpltCallback = DFSDM_DMAInjectedConvCplt;
elmot 1:d0dfbce63a89 2061 hdfsdm_filter->hdmaInj->XferErrorCallback = DFSDM_DMAError;
elmot 1:d0dfbce63a89 2062 hdfsdm_filter->hdmaInj->XferHalfCpltCallback = (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR) ?\
elmot 1:d0dfbce63a89 2063 DFSDM_DMAInjectedHalfConvCplt : NULL;
elmot 1:d0dfbce63a89 2064
elmot 1:d0dfbce63a89 2065 /* Start DMA in interrupt mode */
elmot 1:d0dfbce63a89 2066 if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaInj, (uint32_t)(&hdfsdm_filter->Instance->FLTJDATAR) + 2, \
elmot 1:d0dfbce63a89 2067 (uint32_t) pData, Length) != HAL_OK)
elmot 1:d0dfbce63a89 2068 {
elmot 1:d0dfbce63a89 2069 /* Set DFSDM filter in error state */
elmot 1:d0dfbce63a89 2070 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
elmot 1:d0dfbce63a89 2071 status = HAL_ERROR;
elmot 1:d0dfbce63a89 2072 }
elmot 1:d0dfbce63a89 2073 else
elmot 1:d0dfbce63a89 2074 {
elmot 1:d0dfbce63a89 2075 /* Start injected conversion */
elmot 1:d0dfbce63a89 2076 DFSDM_InjConvStart(hdfsdm_filter);
elmot 1:d0dfbce63a89 2077 }
elmot 1:d0dfbce63a89 2078 }
elmot 1:d0dfbce63a89 2079 else
elmot 1:d0dfbce63a89 2080 {
elmot 1:d0dfbce63a89 2081 status = HAL_ERROR;
elmot 1:d0dfbce63a89 2082 }
elmot 1:d0dfbce63a89 2083 /* Return function status */
elmot 1:d0dfbce63a89 2084 return status;
elmot 1:d0dfbce63a89 2085 }
elmot 1:d0dfbce63a89 2086
elmot 1:d0dfbce63a89 2087 /**
elmot 1:d0dfbce63a89 2088 * @brief This function allows to stop injected conversion in DMA mode.
elmot 1:d0dfbce63a89 2089 * @note This function should be called only if injected conversion is ongoing.
elmot 1:d0dfbce63a89 2090 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2091 * @retval HAL status
elmot 1:d0dfbce63a89 2092 */
elmot 1:d0dfbce63a89 2093 HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 2094 {
elmot 1:d0dfbce63a89 2095 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 2096
elmot 1:d0dfbce63a89 2097 /* Check parameters */
elmot 1:d0dfbce63a89 2098 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 2099
elmot 1:d0dfbce63a89 2100 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 2101 if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
elmot 1:d0dfbce63a89 2102 (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
elmot 1:d0dfbce63a89 2103 {
elmot 1:d0dfbce63a89 2104 /* Return error status */
elmot 1:d0dfbce63a89 2105 status = HAL_ERROR;
elmot 1:d0dfbce63a89 2106 }
elmot 1:d0dfbce63a89 2107 else
elmot 1:d0dfbce63a89 2108 {
elmot 1:d0dfbce63a89 2109 /* Stop current DMA transfer */
elmot 1:d0dfbce63a89 2110 if(HAL_DMA_Abort(hdfsdm_filter->hdmaInj) != HAL_OK)
elmot 1:d0dfbce63a89 2111 {
elmot 1:d0dfbce63a89 2112 /* Set DFSDM filter in error state */
elmot 1:d0dfbce63a89 2113 hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
elmot 1:d0dfbce63a89 2114 status = HAL_ERROR;
elmot 1:d0dfbce63a89 2115 }
elmot 1:d0dfbce63a89 2116 else
elmot 1:d0dfbce63a89 2117 {
elmot 1:d0dfbce63a89 2118 /* Stop regular conversion */
elmot 1:d0dfbce63a89 2119 DFSDM_InjConvStop(hdfsdm_filter);
elmot 1:d0dfbce63a89 2120 }
elmot 1:d0dfbce63a89 2121 }
elmot 1:d0dfbce63a89 2122 /* Return function status */
elmot 1:d0dfbce63a89 2123 return status;
elmot 1:d0dfbce63a89 2124 }
elmot 1:d0dfbce63a89 2125
elmot 1:d0dfbce63a89 2126 /**
elmot 1:d0dfbce63a89 2127 * @brief This function allows to get injected conversion value.
elmot 1:d0dfbce63a89 2128 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2129 * @param Channel : Corresponding channel of injected conversion.
elmot 1:d0dfbce63a89 2130 * @retval Injected conversion value
elmot 1:d0dfbce63a89 2131 */
elmot 1:d0dfbce63a89 2132 int32_t HAL_DFSDM_FilterGetInjectedValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 2133 uint32_t *Channel)
elmot 1:d0dfbce63a89 2134 {
elmot 1:d0dfbce63a89 2135 uint32_t reg = 0;
elmot 1:d0dfbce63a89 2136 int32_t value = 0;
elmot 1:d0dfbce63a89 2137
elmot 1:d0dfbce63a89 2138 /* Check parameters */
elmot 1:d0dfbce63a89 2139 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 2140 assert_param(Channel != NULL);
elmot 1:d0dfbce63a89 2141
elmot 1:d0dfbce63a89 2142 /* Get value of data register for injected channel */
elmot 1:d0dfbce63a89 2143 reg = hdfsdm_filter->Instance->FLTJDATAR;
elmot 1:d0dfbce63a89 2144
elmot 1:d0dfbce63a89 2145 /* Extract channel and injected conversion value */
elmot 1:d0dfbce63a89 2146 *Channel = (reg & DFSDM_FLTJDATAR_JDATACH);
elmot 1:d0dfbce63a89 2147 value = ((reg & DFSDM_FLTJDATAR_JDATA) >> DFSDM_FLTJDATAR_DATA_OFFSET);
elmot 1:d0dfbce63a89 2148
elmot 1:d0dfbce63a89 2149 /* return regular conversion value */
elmot 1:d0dfbce63a89 2150 return value;
elmot 1:d0dfbce63a89 2151 }
elmot 1:d0dfbce63a89 2152
elmot 1:d0dfbce63a89 2153 /**
elmot 1:d0dfbce63a89 2154 * @brief This function allows to start filter analog watchdog in interrupt mode.
elmot 1:d0dfbce63a89 2155 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2156 * @param awdParam : DFSDM filter analog watchdog parameters.
elmot 1:d0dfbce63a89 2157 * @retval HAL status
elmot 1:d0dfbce63a89 2158 */
elmot 1:d0dfbce63a89 2159 HAL_StatusTypeDef HAL_DFSDM_FilterAwdStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 2160 DFSDM_Filter_AwdParamTypeDef *awdParam)
elmot 1:d0dfbce63a89 2161 {
elmot 1:d0dfbce63a89 2162 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 2163
elmot 1:d0dfbce63a89 2164 /* Check parameters */
elmot 1:d0dfbce63a89 2165 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 2166 assert_param(IS_DFSDM_FILTER_AWD_DATA_SOURCE(awdParam->DataSource));
elmot 1:d0dfbce63a89 2167 assert_param(IS_DFSDM_INJECTED_CHANNEL(awdParam->Channel));
elmot 1:d0dfbce63a89 2168 assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam->HighThreshold));
elmot 1:d0dfbce63a89 2169 assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam->LowThreshold));
elmot 1:d0dfbce63a89 2170 assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam->HighBreakSignal));
elmot 1:d0dfbce63a89 2171 assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam->LowBreakSignal));
elmot 1:d0dfbce63a89 2172
elmot 1:d0dfbce63a89 2173 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 2174 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
elmot 1:d0dfbce63a89 2175 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
elmot 1:d0dfbce63a89 2176 {
elmot 1:d0dfbce63a89 2177 /* Return error status */
elmot 1:d0dfbce63a89 2178 status = HAL_ERROR;
elmot 1:d0dfbce63a89 2179 }
elmot 1:d0dfbce63a89 2180 else
elmot 1:d0dfbce63a89 2181 {
elmot 1:d0dfbce63a89 2182 /* Set analog watchdog data source */
elmot 1:d0dfbce63a89 2183 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_AWFSEL);
elmot 1:d0dfbce63a89 2184 hdfsdm_filter->Instance->FLTCR1 |= awdParam->DataSource;
elmot 1:d0dfbce63a89 2185
elmot 1:d0dfbce63a89 2186 /* Set thresholds and break signals */
elmot 1:d0dfbce63a89 2187 hdfsdm_filter->Instance->FLTAWHTR &= ~(DFSDM_FLTAWHTR_AWHT | DFSDM_FLTAWHTR_BKAWH);
elmot 1:d0dfbce63a89 2188 hdfsdm_filter->Instance->FLTAWHTR |= (((uint32_t) awdParam->HighThreshold << DFSDM_FLTAWHTR_THRESHOLD_OFFSET) | \
elmot 1:d0dfbce63a89 2189 awdParam->HighBreakSignal);
elmot 1:d0dfbce63a89 2190 hdfsdm_filter->Instance->FLTAWLTR &= ~(DFSDM_FLTAWLTR_AWLT | DFSDM_FLTAWLTR_BKAWL);
elmot 1:d0dfbce63a89 2191 hdfsdm_filter->Instance->FLTAWLTR |= (((uint32_t) awdParam->LowThreshold << DFSDM_FLTAWLTR_THRESHOLD_OFFSET) | \
elmot 1:d0dfbce63a89 2192 awdParam->LowBreakSignal);
elmot 1:d0dfbce63a89 2193
elmot 1:d0dfbce63a89 2194 /* Set channels and interrupt for analog watchdog */
elmot 1:d0dfbce63a89 2195 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_AWDCH);
elmot 1:d0dfbce63a89 2196 hdfsdm_filter->Instance->FLTCR2 |= (((awdParam->Channel & DFSDM_LSB_MASK) << DFSDM_FLTCR2_AWDCH_OFFSET) | \
elmot 1:d0dfbce63a89 2197 DFSDM_FLTCR2_AWDIE);
elmot 1:d0dfbce63a89 2198 }
elmot 1:d0dfbce63a89 2199 /* Return function status */
elmot 1:d0dfbce63a89 2200 return status;
elmot 1:d0dfbce63a89 2201 }
elmot 1:d0dfbce63a89 2202
elmot 1:d0dfbce63a89 2203 /**
elmot 1:d0dfbce63a89 2204 * @brief This function allows to stop filter analog watchdog in interrupt mode.
elmot 1:d0dfbce63a89 2205 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2206 * @retval HAL status
elmot 1:d0dfbce63a89 2207 */
elmot 1:d0dfbce63a89 2208 HAL_StatusTypeDef HAL_DFSDM_FilterAwdStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 2209 {
elmot 1:d0dfbce63a89 2210 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 2211
elmot 1:d0dfbce63a89 2212 /* Check parameters */
elmot 1:d0dfbce63a89 2213 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 2214
elmot 1:d0dfbce63a89 2215 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 2216 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
elmot 1:d0dfbce63a89 2217 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
elmot 1:d0dfbce63a89 2218 {
elmot 1:d0dfbce63a89 2219 /* Return error status */
elmot 1:d0dfbce63a89 2220 status = HAL_ERROR;
elmot 1:d0dfbce63a89 2221 }
elmot 1:d0dfbce63a89 2222 else
elmot 1:d0dfbce63a89 2223 {
elmot 1:d0dfbce63a89 2224 /* Reset channels for analog watchdog and deactivate interrupt */
elmot 1:d0dfbce63a89 2225 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_AWDCH | DFSDM_FLTCR2_AWDIE);
elmot 1:d0dfbce63a89 2226
elmot 1:d0dfbce63a89 2227 /* Clear all analog watchdog flags */
elmot 1:d0dfbce63a89 2228 hdfsdm_filter->Instance->FLTAWCFR = (DFSDM_FLTAWCFR_CLRAWHTF | DFSDM_FLTAWCFR_CLRAWLTF);
elmot 1:d0dfbce63a89 2229
elmot 1:d0dfbce63a89 2230 /* Reset thresholds and break signals */
elmot 1:d0dfbce63a89 2231 hdfsdm_filter->Instance->FLTAWHTR &= ~(DFSDM_FLTAWHTR_AWHT | DFSDM_FLTAWHTR_BKAWH);
elmot 1:d0dfbce63a89 2232 hdfsdm_filter->Instance->FLTAWLTR &= ~(DFSDM_FLTAWLTR_AWLT | DFSDM_FLTAWLTR_BKAWL);
elmot 1:d0dfbce63a89 2233
elmot 1:d0dfbce63a89 2234 /* Reset analog watchdog data source */
elmot 1:d0dfbce63a89 2235 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_AWFSEL);
elmot 1:d0dfbce63a89 2236 }
elmot 1:d0dfbce63a89 2237 /* Return function status */
elmot 1:d0dfbce63a89 2238 return status;
elmot 1:d0dfbce63a89 2239 }
elmot 1:d0dfbce63a89 2240
elmot 1:d0dfbce63a89 2241 /**
elmot 1:d0dfbce63a89 2242 * @brief This function allows to start extreme detector feature.
elmot 1:d0dfbce63a89 2243 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2244 * @param Channel : Channels where extreme detector is enabled.
elmot 1:d0dfbce63a89 2245 * This parameter can be a values combination of @ref DFSDM_Channel_Selection.
elmot 1:d0dfbce63a89 2246 * @retval HAL status
elmot 1:d0dfbce63a89 2247 */
elmot 1:d0dfbce63a89 2248 HAL_StatusTypeDef HAL_DFSDM_FilterExdStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 2249 uint32_t Channel)
elmot 1:d0dfbce63a89 2250 {
elmot 1:d0dfbce63a89 2251 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 2252
elmot 1:d0dfbce63a89 2253 /* Check parameters */
elmot 1:d0dfbce63a89 2254 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 2255 assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel));
elmot 1:d0dfbce63a89 2256
elmot 1:d0dfbce63a89 2257 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 2258 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
elmot 1:d0dfbce63a89 2259 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
elmot 1:d0dfbce63a89 2260 {
elmot 1:d0dfbce63a89 2261 /* Return error status */
elmot 1:d0dfbce63a89 2262 status = HAL_ERROR;
elmot 1:d0dfbce63a89 2263 }
elmot 1:d0dfbce63a89 2264 else
elmot 1:d0dfbce63a89 2265 {
elmot 1:d0dfbce63a89 2266 /* Set channels for extreme detector */
elmot 1:d0dfbce63a89 2267 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_EXCH);
elmot 1:d0dfbce63a89 2268 hdfsdm_filter->Instance->FLTCR2 |= ((Channel & DFSDM_LSB_MASK) << DFSDM_FLTCR2_EXCH_OFFSET);
elmot 1:d0dfbce63a89 2269 }
elmot 1:d0dfbce63a89 2270 /* Return function status */
elmot 1:d0dfbce63a89 2271 return status;
elmot 1:d0dfbce63a89 2272 }
elmot 1:d0dfbce63a89 2273
elmot 1:d0dfbce63a89 2274 /**
elmot 1:d0dfbce63a89 2275 * @brief This function allows to stop extreme detector feature.
elmot 1:d0dfbce63a89 2276 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2277 * @retval HAL status
elmot 1:d0dfbce63a89 2278 */
elmot 1:d0dfbce63a89 2279 HAL_StatusTypeDef HAL_DFSDM_FilterExdStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 2280 {
elmot 1:d0dfbce63a89 2281 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 2282 __IO uint32_t reg1;
elmot 1:d0dfbce63a89 2283 __IO uint32_t reg2;
elmot 1:d0dfbce63a89 2284
elmot 1:d0dfbce63a89 2285 /* Check parameters */
elmot 1:d0dfbce63a89 2286 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 2287
elmot 1:d0dfbce63a89 2288 /* Check DFSDM filter state */
elmot 1:d0dfbce63a89 2289 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
elmot 1:d0dfbce63a89 2290 (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
elmot 1:d0dfbce63a89 2291 {
elmot 1:d0dfbce63a89 2292 /* Return error status */
elmot 1:d0dfbce63a89 2293 status = HAL_ERROR;
elmot 1:d0dfbce63a89 2294 }
elmot 1:d0dfbce63a89 2295 else
elmot 1:d0dfbce63a89 2296 {
elmot 1:d0dfbce63a89 2297 /* Reset channels for extreme detector */
elmot 1:d0dfbce63a89 2298 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_EXCH);
elmot 1:d0dfbce63a89 2299
elmot 1:d0dfbce63a89 2300 /* Clear extreme detector values */
elmot 1:d0dfbce63a89 2301 reg1 = hdfsdm_filter->Instance->FLTEXMAX;
elmot 1:d0dfbce63a89 2302 reg2 = hdfsdm_filter->Instance->FLTEXMIN;
elmot 1:d0dfbce63a89 2303 UNUSED(reg1); /* To avoid GCC warning */
elmot 1:d0dfbce63a89 2304 UNUSED(reg2); /* To avoid GCC warning */
elmot 1:d0dfbce63a89 2305 }
elmot 1:d0dfbce63a89 2306 /* Return function status */
elmot 1:d0dfbce63a89 2307 return status;
elmot 1:d0dfbce63a89 2308 }
elmot 1:d0dfbce63a89 2309
elmot 1:d0dfbce63a89 2310 /**
elmot 1:d0dfbce63a89 2311 * @brief This function allows to get extreme detector maximum value.
elmot 1:d0dfbce63a89 2312 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2313 * @param Channel : Corresponding channel.
elmot 1:d0dfbce63a89 2314 * @retval Extreme detector maximum value
elmot 1:d0dfbce63a89 2315 * This value is between Min_Data = -8388608 and Max_Data = 8388607.
elmot 1:d0dfbce63a89 2316 */
elmot 1:d0dfbce63a89 2317 int32_t HAL_DFSDM_FilterGetExdMaxValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 2318 uint32_t *Channel)
elmot 1:d0dfbce63a89 2319 {
elmot 1:d0dfbce63a89 2320 uint32_t reg = 0;
elmot 1:d0dfbce63a89 2321 int32_t value = 0;
elmot 1:d0dfbce63a89 2322
elmot 1:d0dfbce63a89 2323 /* Check parameters */
elmot 1:d0dfbce63a89 2324 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 2325 assert_param(Channel != NULL);
elmot 1:d0dfbce63a89 2326
elmot 1:d0dfbce63a89 2327 /* Get value of extreme detector maximum register */
elmot 1:d0dfbce63a89 2328 reg = hdfsdm_filter->Instance->FLTEXMAX;
elmot 1:d0dfbce63a89 2329
elmot 1:d0dfbce63a89 2330 /* Extract channel and extreme detector maximum value */
elmot 1:d0dfbce63a89 2331 *Channel = (reg & DFSDM_FLTEXMAX_EXMAXCH);
elmot 1:d0dfbce63a89 2332 value = ((reg & DFSDM_FLTEXMAX_EXMAX) >> DFSDM_FLTEXMAX_DATA_OFFSET);
elmot 1:d0dfbce63a89 2333
elmot 1:d0dfbce63a89 2334 /* return extreme detector maximum value */
elmot 1:d0dfbce63a89 2335 return value;
elmot 1:d0dfbce63a89 2336 }
elmot 1:d0dfbce63a89 2337
elmot 1:d0dfbce63a89 2338 /**
elmot 1:d0dfbce63a89 2339 * @brief This function allows to get extreme detector minimum value.
elmot 1:d0dfbce63a89 2340 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2341 * @param Channel : Corresponding channel.
elmot 1:d0dfbce63a89 2342 * @retval Extreme detector minimum value
elmot 1:d0dfbce63a89 2343 * This value is between Min_Data = -8388608 and Max_Data = 8388607.
elmot 1:d0dfbce63a89 2344 */
elmot 1:d0dfbce63a89 2345 int32_t HAL_DFSDM_FilterGetExdMinValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 2346 uint32_t *Channel)
elmot 1:d0dfbce63a89 2347 {
elmot 1:d0dfbce63a89 2348 uint32_t reg = 0;
elmot 1:d0dfbce63a89 2349 int32_t value = 0;
elmot 1:d0dfbce63a89 2350
elmot 1:d0dfbce63a89 2351 /* Check parameters */
elmot 1:d0dfbce63a89 2352 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 2353 assert_param(Channel != NULL);
elmot 1:d0dfbce63a89 2354
elmot 1:d0dfbce63a89 2355 /* Get value of extreme detector minimum register */
elmot 1:d0dfbce63a89 2356 reg = hdfsdm_filter->Instance->FLTEXMIN;
elmot 1:d0dfbce63a89 2357
elmot 1:d0dfbce63a89 2358 /* Extract channel and extreme detector minimum value */
elmot 1:d0dfbce63a89 2359 *Channel = (reg & DFSDM_FLTEXMIN_EXMINCH);
elmot 1:d0dfbce63a89 2360 value = ((reg & DFSDM_FLTEXMIN_EXMIN) >> DFSDM_FLTEXMIN_DATA_OFFSET);
elmot 1:d0dfbce63a89 2361
elmot 1:d0dfbce63a89 2362 /* return extreme detector minimum value */
elmot 1:d0dfbce63a89 2363 return value;
elmot 1:d0dfbce63a89 2364 }
elmot 1:d0dfbce63a89 2365
elmot 1:d0dfbce63a89 2366 /**
elmot 1:d0dfbce63a89 2367 * @brief This function allows to get conversion time value.
elmot 1:d0dfbce63a89 2368 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2369 * @retval Conversion time value
elmot 1:d0dfbce63a89 2370 * @note To get time in second, this value has to be divided by DFSDM clock frequency.
elmot 1:d0dfbce63a89 2371 */
elmot 1:d0dfbce63a89 2372 uint32_t HAL_DFSDM_FilterGetConvTimeValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 2373 {
elmot 1:d0dfbce63a89 2374 uint32_t reg = 0;
elmot 1:d0dfbce63a89 2375 uint32_t value = 0;
elmot 1:d0dfbce63a89 2376
elmot 1:d0dfbce63a89 2377 /* Check parameters */
elmot 1:d0dfbce63a89 2378 assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
elmot 1:d0dfbce63a89 2379
elmot 1:d0dfbce63a89 2380 /* Get value of conversion timer register */
elmot 1:d0dfbce63a89 2381 reg = hdfsdm_filter->Instance->FLTCNVTIMR;
elmot 1:d0dfbce63a89 2382
elmot 1:d0dfbce63a89 2383 /* Extract conversion time value */
elmot 1:d0dfbce63a89 2384 value = ((reg & DFSDM_FLTCNVTIMR_CNVCNT) >> DFSDM_FLTCNVTIMR_DATA_OFFSET);
elmot 1:d0dfbce63a89 2385
elmot 1:d0dfbce63a89 2386 /* return extreme detector minimum value */
elmot 1:d0dfbce63a89 2387 return value;
elmot 1:d0dfbce63a89 2388 }
elmot 1:d0dfbce63a89 2389
elmot 1:d0dfbce63a89 2390 /**
elmot 1:d0dfbce63a89 2391 * @brief This function handles the DFSDM interrupts.
elmot 1:d0dfbce63a89 2392 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2393 * @retval None
elmot 1:d0dfbce63a89 2394 */
elmot 1:d0dfbce63a89 2395 void HAL_DFSDM_IRQHandler(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 2396 {
elmot 1:d0dfbce63a89 2397 /* Check if overrun occurs during regular conversion */
elmot 1:d0dfbce63a89 2398 if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_ROVRF) != 0) && \
elmot 1:d0dfbce63a89 2399 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_ROVRIE) != 0))
elmot 1:d0dfbce63a89 2400 {
elmot 1:d0dfbce63a89 2401 /* Clear regular overrun flag */
elmot 1:d0dfbce63a89 2402 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRROVRF;
elmot 1:d0dfbce63a89 2403
elmot 1:d0dfbce63a89 2404 /* Update error code */
elmot 1:d0dfbce63a89 2405 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_REGULAR_OVERRUN;
elmot 1:d0dfbce63a89 2406
elmot 1:d0dfbce63a89 2407 /* Call error callback */
elmot 1:d0dfbce63a89 2408 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
elmot 1:d0dfbce63a89 2409 }
elmot 1:d0dfbce63a89 2410 /* Check if overrun occurs during injected conversion */
elmot 1:d0dfbce63a89 2411 else if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JOVRF) != 0) && \
elmot 1:d0dfbce63a89 2412 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_JOVRIE) != 0))
elmot 1:d0dfbce63a89 2413 {
elmot 1:d0dfbce63a89 2414 /* Clear injected overrun flag */
elmot 1:d0dfbce63a89 2415 hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRJOVRF;
elmot 1:d0dfbce63a89 2416
elmot 1:d0dfbce63a89 2417 /* Update error code */
elmot 1:d0dfbce63a89 2418 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INJECTED_OVERRUN;
elmot 1:d0dfbce63a89 2419
elmot 1:d0dfbce63a89 2420 /* Call error callback */
elmot 1:d0dfbce63a89 2421 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
elmot 1:d0dfbce63a89 2422 }
elmot 1:d0dfbce63a89 2423 /* Check if end of regular conversion */
elmot 1:d0dfbce63a89 2424 else if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_REOCF) != 0) && \
elmot 1:d0dfbce63a89 2425 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_REOCIE) != 0))
elmot 1:d0dfbce63a89 2426 {
elmot 1:d0dfbce63a89 2427 /* Call regular conversion complete callback */
elmot 1:d0dfbce63a89 2428 HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter);
elmot 1:d0dfbce63a89 2429
elmot 1:d0dfbce63a89 2430 /* End of conversion if mode is not continuous and software trigger */
elmot 1:d0dfbce63a89 2431 if((hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
elmot 1:d0dfbce63a89 2432 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
elmot 1:d0dfbce63a89 2433 {
elmot 1:d0dfbce63a89 2434 /* Disable interrupts for regular conversions */
elmot 1:d0dfbce63a89 2435 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_REOCIE);
elmot 1:d0dfbce63a89 2436
elmot 1:d0dfbce63a89 2437 /* Update DFSDM filter state */
elmot 1:d0dfbce63a89 2438 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \
elmot 1:d0dfbce63a89 2439 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ;
elmot 1:d0dfbce63a89 2440 }
elmot 1:d0dfbce63a89 2441 }
elmot 1:d0dfbce63a89 2442 /* Check if end of injected conversion */
elmot 1:d0dfbce63a89 2443 else if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JEOCF) != 0) && \
elmot 1:d0dfbce63a89 2444 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_JEOCIE) != 0))
elmot 1:d0dfbce63a89 2445 {
elmot 1:d0dfbce63a89 2446 /* Call injected conversion complete callback */
elmot 1:d0dfbce63a89 2447 HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter);
elmot 1:d0dfbce63a89 2448
elmot 1:d0dfbce63a89 2449 /* Update remaining injected conversions */
elmot 1:d0dfbce63a89 2450 hdfsdm_filter->InjConvRemaining--;
elmot 1:d0dfbce63a89 2451 if(hdfsdm_filter->InjConvRemaining == 0)
elmot 1:d0dfbce63a89 2452 {
elmot 1:d0dfbce63a89 2453 /* End of conversion if trigger is software */
elmot 1:d0dfbce63a89 2454 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
elmot 1:d0dfbce63a89 2455 {
elmot 1:d0dfbce63a89 2456 /* Disable interrupts for injected conversions */
elmot 1:d0dfbce63a89 2457 hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_JEOCIE);
elmot 1:d0dfbce63a89 2458
elmot 1:d0dfbce63a89 2459 /* Update DFSDM filter state */
elmot 1:d0dfbce63a89 2460 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \
elmot 1:d0dfbce63a89 2461 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG;
elmot 1:d0dfbce63a89 2462 }
elmot 1:d0dfbce63a89 2463 /* end of injected sequence, reset the value */
elmot 1:d0dfbce63a89 2464 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
elmot 1:d0dfbce63a89 2465 hdfsdm_filter->InjectedChannelsNbr : 1;
elmot 1:d0dfbce63a89 2466 }
elmot 1:d0dfbce63a89 2467 }
elmot 1:d0dfbce63a89 2468 /* Check if analog watchdog occurs */
elmot 1:d0dfbce63a89 2469 else if(((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_AWDF) != 0) && \
elmot 1:d0dfbce63a89 2470 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_AWDIE) != 0))
elmot 1:d0dfbce63a89 2471 {
elmot 1:d0dfbce63a89 2472 uint32_t reg = 0;
elmot 1:d0dfbce63a89 2473 uint32_t threshold = 0;
elmot 1:d0dfbce63a89 2474 uint32_t channel = 0;
elmot 1:d0dfbce63a89 2475
elmot 1:d0dfbce63a89 2476 /* Get channel and threshold */
elmot 1:d0dfbce63a89 2477 reg = hdfsdm_filter->Instance->FLTAWSR;
elmot 1:d0dfbce63a89 2478 threshold = ((reg & DFSDM_FLTAWSR_AWLTF) != 0) ? DFSDM_AWD_LOW_THRESHOLD : DFSDM_AWD_HIGH_THRESHOLD;
elmot 1:d0dfbce63a89 2479 if(threshold == DFSDM_AWD_HIGH_THRESHOLD)
elmot 1:d0dfbce63a89 2480 {
elmot 1:d0dfbce63a89 2481 reg = reg >> DFSDM_FLTAWSR_HIGH_OFFSET;
elmot 1:d0dfbce63a89 2482 }
elmot 1:d0dfbce63a89 2483 while((reg & 1) == 0)
elmot 1:d0dfbce63a89 2484 {
elmot 1:d0dfbce63a89 2485 channel++;
elmot 1:d0dfbce63a89 2486 reg = reg >> 1;
elmot 1:d0dfbce63a89 2487 }
elmot 1:d0dfbce63a89 2488 /* Clear analog watchdog flag */
elmot 1:d0dfbce63a89 2489 hdfsdm_filter->Instance->FLTAWCFR = (threshold == DFSDM_AWD_HIGH_THRESHOLD) ? \
elmot 1:d0dfbce63a89 2490 (1 << (DFSDM_FLTAWSR_HIGH_OFFSET + channel)) : \
elmot 1:d0dfbce63a89 2491 (1 << channel);
elmot 1:d0dfbce63a89 2492
elmot 1:d0dfbce63a89 2493 /* Call analog watchdog callback */
elmot 1:d0dfbce63a89 2494 HAL_DFSDM_FilterAwdCallback(hdfsdm_filter, channel, threshold);
elmot 1:d0dfbce63a89 2495 }
elmot 1:d0dfbce63a89 2496 /* Check if clock absence occurs */
elmot 1:d0dfbce63a89 2497 else if((hdfsdm_filter->Instance == DFSDM1_Filter0) && \
elmot 1:d0dfbce63a89 2498 ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_CKABF) != 0) && \
elmot 1:d0dfbce63a89 2499 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_CKABIE) != 0))
elmot 1:d0dfbce63a89 2500 {
elmot 1:d0dfbce63a89 2501 uint32_t reg = 0;
elmot 1:d0dfbce63a89 2502 uint32_t channel = 0;
elmot 1:d0dfbce63a89 2503
elmot 1:d0dfbce63a89 2504 reg = ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_CKABF) >> DFSDM_FLTISR_CKABF_OFFSET);
elmot 1:d0dfbce63a89 2505
elmot 1:d0dfbce63a89 2506 while(channel < DFSDM1_CHANNEL_NUMBER)
elmot 1:d0dfbce63a89 2507 {
elmot 1:d0dfbce63a89 2508 /* Check if flag is set and corresponding channel is enabled */
elmot 1:d0dfbce63a89 2509 if(((reg & 1) != 0) && (a_dfsdm1ChannelHandle[channel] != NULL))
elmot 1:d0dfbce63a89 2510 {
elmot 1:d0dfbce63a89 2511 /* Check clock absence has been enabled for this channel */
elmot 1:d0dfbce63a89 2512 if((a_dfsdm1ChannelHandle[channel]->Instance->CHCFGR1 & DFSDM_CHCFGR1_CKABEN) != 0)
elmot 1:d0dfbce63a89 2513 {
elmot 1:d0dfbce63a89 2514 /* Clear clock absence flag */
elmot 1:d0dfbce63a89 2515 hdfsdm_filter->Instance->FLTICR = (1 << (DFSDM_FLTICR_CLRCKABF_OFFSET + channel));
elmot 1:d0dfbce63a89 2516
elmot 1:d0dfbce63a89 2517 /* Call clock absence callback */
elmot 1:d0dfbce63a89 2518 HAL_DFSDM_ChannelCkabCallback(a_dfsdm1ChannelHandle[channel]);
elmot 1:d0dfbce63a89 2519 }
elmot 1:d0dfbce63a89 2520 }
elmot 1:d0dfbce63a89 2521 channel++;
elmot 1:d0dfbce63a89 2522 reg = reg >> 1;
elmot 1:d0dfbce63a89 2523 }
elmot 1:d0dfbce63a89 2524 }
elmot 1:d0dfbce63a89 2525 /* Check if short circuit detection occurs */
elmot 1:d0dfbce63a89 2526 else if((hdfsdm_filter->Instance == DFSDM1_Filter0) && \
elmot 1:d0dfbce63a89 2527 ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_SCDF) != 0) && \
elmot 1:d0dfbce63a89 2528 ((hdfsdm_filter->Instance->FLTCR2 & DFSDM_FLTCR2_SCDIE) != 0))
elmot 1:d0dfbce63a89 2529 {
elmot 1:d0dfbce63a89 2530 uint32_t reg = 0;
elmot 1:d0dfbce63a89 2531 uint32_t channel = 0;
elmot 1:d0dfbce63a89 2532
elmot 1:d0dfbce63a89 2533 /* Get channel */
elmot 1:d0dfbce63a89 2534 reg = ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_SCDF) >> DFSDM_FLTISR_SCDF_OFFSET);
elmot 1:d0dfbce63a89 2535 while((reg & 1) == 0)
elmot 1:d0dfbce63a89 2536 {
elmot 1:d0dfbce63a89 2537 channel++;
elmot 1:d0dfbce63a89 2538 reg = reg >> 1;
elmot 1:d0dfbce63a89 2539 }
elmot 1:d0dfbce63a89 2540
elmot 1:d0dfbce63a89 2541 /* Clear short circuit detection flag */
elmot 1:d0dfbce63a89 2542 hdfsdm_filter->Instance->FLTICR = (1 << (DFSDM_FLTICR_CLRSCDF_OFFSET + channel));
elmot 1:d0dfbce63a89 2543
elmot 1:d0dfbce63a89 2544 /* Call short circuit detection callback */
elmot 1:d0dfbce63a89 2545 HAL_DFSDM_ChannelScdCallback(a_dfsdm1ChannelHandle[channel]);
elmot 1:d0dfbce63a89 2546 }
elmot 1:d0dfbce63a89 2547 }
elmot 1:d0dfbce63a89 2548
elmot 1:d0dfbce63a89 2549 /**
elmot 1:d0dfbce63a89 2550 * @brief Regular conversion complete callback.
elmot 1:d0dfbce63a89 2551 * @note In interrupt mode, user has to read conversion value in this function
elmot 1:d0dfbce63a89 2552 * using HAL_DFSDM_FilterGetRegularValue.
elmot 1:d0dfbce63a89 2553 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2554 * @retval None
elmot 1:d0dfbce63a89 2555 */
elmot 1:d0dfbce63a89 2556 __weak void HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 2557 {
elmot 1:d0dfbce63a89 2558 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 2559 UNUSED(hdfsdm_filter);
elmot 1:d0dfbce63a89 2560
elmot 1:d0dfbce63a89 2561 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 2562 the HAL_DFSDM_FilterRegConvCpltCallback could be implemented in the user file.
elmot 1:d0dfbce63a89 2563 */
elmot 1:d0dfbce63a89 2564 }
elmot 1:d0dfbce63a89 2565
elmot 1:d0dfbce63a89 2566 /**
elmot 1:d0dfbce63a89 2567 * @brief Half regular conversion complete callback.
elmot 1:d0dfbce63a89 2568 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2569 * @retval None
elmot 1:d0dfbce63a89 2570 */
elmot 1:d0dfbce63a89 2571 __weak void HAL_DFSDM_FilterRegConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 2572 {
elmot 1:d0dfbce63a89 2573 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 2574 UNUSED(hdfsdm_filter);
elmot 1:d0dfbce63a89 2575
elmot 1:d0dfbce63a89 2576 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 2577 the HAL_DFSDM_FilterRegConvHalfCpltCallback could be implemented in the user file.
elmot 1:d0dfbce63a89 2578 */
elmot 1:d0dfbce63a89 2579 }
elmot 1:d0dfbce63a89 2580
elmot 1:d0dfbce63a89 2581 /**
elmot 1:d0dfbce63a89 2582 * @brief Injected conversion complete callback.
elmot 1:d0dfbce63a89 2583 * @note In interrupt mode, user has to read conversion value in this function
elmot 1:d0dfbce63a89 2584 * using HAL_DFSDM_FilterGetInjectedValue.
elmot 1:d0dfbce63a89 2585 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2586 * @retval None
elmot 1:d0dfbce63a89 2587 */
elmot 1:d0dfbce63a89 2588 __weak void HAL_DFSDM_FilterInjConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 2589 {
elmot 1:d0dfbce63a89 2590 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 2591 UNUSED(hdfsdm_filter);
elmot 1:d0dfbce63a89 2592
elmot 1:d0dfbce63a89 2593 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 2594 the HAL_DFSDM_FilterInjConvCpltCallback could be implemented in the user file.
elmot 1:d0dfbce63a89 2595 */
elmot 1:d0dfbce63a89 2596 }
elmot 1:d0dfbce63a89 2597
elmot 1:d0dfbce63a89 2598 /**
elmot 1:d0dfbce63a89 2599 * @brief Half injected conversion complete callback.
elmot 1:d0dfbce63a89 2600 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2601 * @retval None
elmot 1:d0dfbce63a89 2602 */
elmot 1:d0dfbce63a89 2603 __weak void HAL_DFSDM_FilterInjConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 2604 {
elmot 1:d0dfbce63a89 2605 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 2606 UNUSED(hdfsdm_filter);
elmot 1:d0dfbce63a89 2607
elmot 1:d0dfbce63a89 2608 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 2609 the HAL_DFSDM_FilterInjConvHalfCpltCallback could be implemented in the user file.
elmot 1:d0dfbce63a89 2610 */
elmot 1:d0dfbce63a89 2611 }
elmot 1:d0dfbce63a89 2612
elmot 1:d0dfbce63a89 2613 /**
elmot 1:d0dfbce63a89 2614 * @brief Filter analog watchdog callback.
elmot 1:d0dfbce63a89 2615 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2616 * @param Channel : Corresponding channel.
elmot 1:d0dfbce63a89 2617 * @param Threshold : Low or high threshold has been reached.
elmot 1:d0dfbce63a89 2618 * @retval None
elmot 1:d0dfbce63a89 2619 */
elmot 1:d0dfbce63a89 2620 __weak void HAL_DFSDM_FilterAwdCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
elmot 1:d0dfbce63a89 2621 uint32_t Channel, uint32_t Threshold)
elmot 1:d0dfbce63a89 2622 {
elmot 1:d0dfbce63a89 2623 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 2624 UNUSED(hdfsdm_filter);
elmot 1:d0dfbce63a89 2625 UNUSED(Channel);
elmot 1:d0dfbce63a89 2626 UNUSED(Threshold);
elmot 1:d0dfbce63a89 2627
elmot 1:d0dfbce63a89 2628 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 2629 the HAL_DFSDM_FilterAwdCallback could be implemented in the user file.
elmot 1:d0dfbce63a89 2630 */
elmot 1:d0dfbce63a89 2631 }
elmot 1:d0dfbce63a89 2632
elmot 1:d0dfbce63a89 2633 /**
elmot 1:d0dfbce63a89 2634 * @brief Error callback.
elmot 1:d0dfbce63a89 2635 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2636 * @retval None
elmot 1:d0dfbce63a89 2637 */
elmot 1:d0dfbce63a89 2638 __weak void HAL_DFSDM_FilterErrorCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 2639 {
elmot 1:d0dfbce63a89 2640 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 2641 UNUSED(hdfsdm_filter);
elmot 1:d0dfbce63a89 2642
elmot 1:d0dfbce63a89 2643 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 2644 the HAL_DFSDM_FilterErrorCallback could be implemented in the user file.
elmot 1:d0dfbce63a89 2645 */
elmot 1:d0dfbce63a89 2646 }
elmot 1:d0dfbce63a89 2647
elmot 1:d0dfbce63a89 2648 /**
elmot 1:d0dfbce63a89 2649 * @}
elmot 1:d0dfbce63a89 2650 */
elmot 1:d0dfbce63a89 2651
elmot 1:d0dfbce63a89 2652 /** @defgroup DFSDM_Exported_Functions_Group4_Filter Filter state functions
elmot 1:d0dfbce63a89 2653 * @brief Filter state functions
elmot 1:d0dfbce63a89 2654 *
elmot 1:d0dfbce63a89 2655 @verbatim
elmot 1:d0dfbce63a89 2656 ==============================================================================
elmot 1:d0dfbce63a89 2657 ##### Filter state functions #####
elmot 1:d0dfbce63a89 2658 ==============================================================================
elmot 1:d0dfbce63a89 2659 [..] This section provides functions allowing to:
elmot 1:d0dfbce63a89 2660 (+) Get the DFSDM filter state.
elmot 1:d0dfbce63a89 2661 (+) Get the DFSDM filter error.
elmot 1:d0dfbce63a89 2662 @endverbatim
elmot 1:d0dfbce63a89 2663 * @{
elmot 1:d0dfbce63a89 2664 */
elmot 1:d0dfbce63a89 2665
elmot 1:d0dfbce63a89 2666 /**
elmot 1:d0dfbce63a89 2667 * @brief This function allows to get the current DFSDM filter handle state.
elmot 1:d0dfbce63a89 2668 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2669 * @retval DFSDM filter state.
elmot 1:d0dfbce63a89 2670 */
elmot 1:d0dfbce63a89 2671 HAL_DFSDM_Filter_StateTypeDef HAL_DFSDM_FilterGetState(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 2672 {
elmot 1:d0dfbce63a89 2673 /* Return DFSDM filter handle state */
elmot 1:d0dfbce63a89 2674 return hdfsdm_filter->State;
elmot 1:d0dfbce63a89 2675 }
elmot 1:d0dfbce63a89 2676
elmot 1:d0dfbce63a89 2677 /**
elmot 1:d0dfbce63a89 2678 * @brief This function allows to get the current DFSDM filter error.
elmot 1:d0dfbce63a89 2679 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2680 * @retval DFSDM filter error code.
elmot 1:d0dfbce63a89 2681 */
elmot 1:d0dfbce63a89 2682 uint32_t HAL_DFSDM_FilterGetError(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
elmot 1:d0dfbce63a89 2683 {
elmot 1:d0dfbce63a89 2684 return hdfsdm_filter->ErrorCode;
elmot 1:d0dfbce63a89 2685 }
elmot 1:d0dfbce63a89 2686
elmot 1:d0dfbce63a89 2687 /**
elmot 1:d0dfbce63a89 2688 * @}
elmot 1:d0dfbce63a89 2689 */
elmot 1:d0dfbce63a89 2690
elmot 1:d0dfbce63a89 2691 /**
elmot 1:d0dfbce63a89 2692 * @}
elmot 1:d0dfbce63a89 2693 */
elmot 1:d0dfbce63a89 2694 /* End of exported functions -------------------------------------------------*/
elmot 1:d0dfbce63a89 2695
elmot 1:d0dfbce63a89 2696 /* Private functions ---------------------------------------------------------*/
elmot 1:d0dfbce63a89 2697 /** @addtogroup DFSDM_Private_Functions DFSDM Private Functions
elmot 1:d0dfbce63a89 2698 * @{
elmot 1:d0dfbce63a89 2699 */
elmot 1:d0dfbce63a89 2700
elmot 1:d0dfbce63a89 2701 /**
elmot 1:d0dfbce63a89 2702 * @brief DMA half transfer complete callback for regular conversion.
elmot 1:d0dfbce63a89 2703 * @param hdma : DMA handle.
elmot 1:d0dfbce63a89 2704 * @retval None
elmot 1:d0dfbce63a89 2705 */
elmot 1:d0dfbce63a89 2706 static void DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef *hdma)
elmot 1:d0dfbce63a89 2707 {
elmot 1:d0dfbce63a89 2708 /* Get DFSDM filter handle */
elmot 1:d0dfbce63a89 2709 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
elmot 1:d0dfbce63a89 2710
elmot 1:d0dfbce63a89 2711 /* Call regular half conversion complete callback */
elmot 1:d0dfbce63a89 2712 HAL_DFSDM_FilterRegConvHalfCpltCallback(hdfsdm_filter);
elmot 1:d0dfbce63a89 2713 }
elmot 1:d0dfbce63a89 2714
elmot 1:d0dfbce63a89 2715 /**
elmot 1:d0dfbce63a89 2716 * @brief DMA transfer complete callback for regular conversion.
elmot 1:d0dfbce63a89 2717 * @param hdma : DMA handle.
elmot 1:d0dfbce63a89 2718 * @retval None
elmot 1:d0dfbce63a89 2719 */
elmot 1:d0dfbce63a89 2720 static void DFSDM_DMARegularConvCplt(DMA_HandleTypeDef *hdma)
elmot 1:d0dfbce63a89 2721 {
elmot 1:d0dfbce63a89 2722 /* Get DFSDM filter handle */
elmot 1:d0dfbce63a89 2723 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
elmot 1:d0dfbce63a89 2724
elmot 1:d0dfbce63a89 2725 /* Call regular conversion complete callback */
elmot 1:d0dfbce63a89 2726 HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter);
elmot 1:d0dfbce63a89 2727 }
elmot 1:d0dfbce63a89 2728
elmot 1:d0dfbce63a89 2729 /**
elmot 1:d0dfbce63a89 2730 * @brief DMA half transfer complete callback for injected conversion.
elmot 1:d0dfbce63a89 2731 * @param hdma : DMA handle.
elmot 1:d0dfbce63a89 2732 * @retval None
elmot 1:d0dfbce63a89 2733 */
elmot 1:d0dfbce63a89 2734 static void DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef *hdma)
elmot 1:d0dfbce63a89 2735 {
elmot 1:d0dfbce63a89 2736 /* Get DFSDM filter handle */
elmot 1:d0dfbce63a89 2737 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
elmot 1:d0dfbce63a89 2738
elmot 1:d0dfbce63a89 2739 /* Call injected half conversion complete callback */
elmot 1:d0dfbce63a89 2740 HAL_DFSDM_FilterInjConvHalfCpltCallback(hdfsdm_filter);
elmot 1:d0dfbce63a89 2741 }
elmot 1:d0dfbce63a89 2742
elmot 1:d0dfbce63a89 2743 /**
elmot 1:d0dfbce63a89 2744 * @brief DMA transfer complete callback for injected conversion.
elmot 1:d0dfbce63a89 2745 * @param hdma : DMA handle.
elmot 1:d0dfbce63a89 2746 * @retval None
elmot 1:d0dfbce63a89 2747 */
elmot 1:d0dfbce63a89 2748 static void DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef *hdma)
elmot 1:d0dfbce63a89 2749 {
elmot 1:d0dfbce63a89 2750 /* Get DFSDM filter handle */
elmot 1:d0dfbce63a89 2751 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
elmot 1:d0dfbce63a89 2752
elmot 1:d0dfbce63a89 2753 /* Call injected conversion complete callback */
elmot 1:d0dfbce63a89 2754 HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter);
elmot 1:d0dfbce63a89 2755 }
elmot 1:d0dfbce63a89 2756
elmot 1:d0dfbce63a89 2757 /**
elmot 1:d0dfbce63a89 2758 * @brief DMA error callback.
elmot 1:d0dfbce63a89 2759 * @param hdma : DMA handle.
elmot 1:d0dfbce63a89 2760 * @retval None
elmot 1:d0dfbce63a89 2761 */
elmot 1:d0dfbce63a89 2762 static void DFSDM_DMAError(DMA_HandleTypeDef *hdma)
elmot 1:d0dfbce63a89 2763 {
elmot 1:d0dfbce63a89 2764 /* Get DFSDM filter handle */
elmot 1:d0dfbce63a89 2765 DFSDM_Filter_HandleTypeDef* hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
elmot 1:d0dfbce63a89 2766
elmot 1:d0dfbce63a89 2767 /* Update error code */
elmot 1:d0dfbce63a89 2768 hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_DMA;
elmot 1:d0dfbce63a89 2769
elmot 1:d0dfbce63a89 2770 /* Call error callback */
elmot 1:d0dfbce63a89 2771 HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
elmot 1:d0dfbce63a89 2772 }
elmot 1:d0dfbce63a89 2773
elmot 1:d0dfbce63a89 2774 /**
elmot 1:d0dfbce63a89 2775 * @brief This function allows to get the number of injected channels.
elmot 1:d0dfbce63a89 2776 * @param Channels : bitfield of injected channels.
elmot 1:d0dfbce63a89 2777 * @retval Number of injected channels.
elmot 1:d0dfbce63a89 2778 */
elmot 1:d0dfbce63a89 2779 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels)
elmot 1:d0dfbce63a89 2780 {
elmot 1:d0dfbce63a89 2781 uint32_t nbChannels = 0;
elmot 1:d0dfbce63a89 2782 uint32_t tmp;
elmot 1:d0dfbce63a89 2783
elmot 1:d0dfbce63a89 2784 /* Get the number of channels from bitfield */
elmot 1:d0dfbce63a89 2785 tmp = (uint32_t) (Channels & DFSDM_LSB_MASK);
elmot 1:d0dfbce63a89 2786 while(tmp != 0)
elmot 1:d0dfbce63a89 2787 {
elmot 1:d0dfbce63a89 2788 if((tmp & 1) != 0)
elmot 1:d0dfbce63a89 2789 {
elmot 1:d0dfbce63a89 2790 nbChannels++;
elmot 1:d0dfbce63a89 2791 }
elmot 1:d0dfbce63a89 2792 tmp = (uint32_t) (tmp >> 1);
elmot 1:d0dfbce63a89 2793 }
elmot 1:d0dfbce63a89 2794 return nbChannels;
elmot 1:d0dfbce63a89 2795 }
elmot 1:d0dfbce63a89 2796
elmot 1:d0dfbce63a89 2797 /**
elmot 1:d0dfbce63a89 2798 * @brief This function allows to get the channel number from channel instance.
elmot 1:d0dfbce63a89 2799 * @param Instance : DFSDM channel instance.
elmot 1:d0dfbce63a89 2800 * @retval Channel number.
elmot 1:d0dfbce63a89 2801 */
elmot 1:d0dfbce63a89 2802 static uint32_t DFSDM_GetChannelFromInstance(DFSDM_Channel_TypeDef* Instance)
elmot 1:d0dfbce63a89 2803 {
elmot 1:d0dfbce63a89 2804 uint32_t channel = 0xFF;
elmot 1:d0dfbce63a89 2805
elmot 1:d0dfbce63a89 2806 /* Get channel from instance */
elmot 1:d0dfbce63a89 2807 if(Instance == DFSDM1_Channel0)
elmot 1:d0dfbce63a89 2808 {
elmot 1:d0dfbce63a89 2809 channel = 0;
elmot 1:d0dfbce63a89 2810 }
elmot 1:d0dfbce63a89 2811 else if(Instance == DFSDM1_Channel1)
elmot 1:d0dfbce63a89 2812 {
elmot 1:d0dfbce63a89 2813 channel = 1;
elmot 1:d0dfbce63a89 2814 }
elmot 1:d0dfbce63a89 2815 else if(Instance == DFSDM1_Channel2)
elmot 1:d0dfbce63a89 2816 {
elmot 1:d0dfbce63a89 2817 channel = 2;
elmot 1:d0dfbce63a89 2818 }
elmot 1:d0dfbce63a89 2819 else if(Instance == DFSDM1_Channel3)
elmot 1:d0dfbce63a89 2820 {
elmot 1:d0dfbce63a89 2821 channel = 3;
elmot 1:d0dfbce63a89 2822 }
elmot 1:d0dfbce63a89 2823 else if(Instance == DFSDM1_Channel4)
elmot 1:d0dfbce63a89 2824 {
elmot 1:d0dfbce63a89 2825 channel = 4;
elmot 1:d0dfbce63a89 2826 }
elmot 1:d0dfbce63a89 2827 else if(Instance == DFSDM1_Channel5)
elmot 1:d0dfbce63a89 2828 {
elmot 1:d0dfbce63a89 2829 channel = 5;
elmot 1:d0dfbce63a89 2830 }
elmot 1:d0dfbce63a89 2831 else if(Instance == DFSDM1_Channel6)
elmot 1:d0dfbce63a89 2832 {
elmot 1:d0dfbce63a89 2833 channel = 6;
elmot 1:d0dfbce63a89 2834 }
elmot 1:d0dfbce63a89 2835 else if(Instance == DFSDM1_Channel7)
elmot 1:d0dfbce63a89 2836 {
elmot 1:d0dfbce63a89 2837 channel = 7;
elmot 1:d0dfbce63a89 2838 }
elmot 1:d0dfbce63a89 2839
elmot 1:d0dfbce63a89 2840 return channel;
elmot 1:d0dfbce63a89 2841 }
elmot 1:d0dfbce63a89 2842
elmot 1:d0dfbce63a89 2843 /**
elmot 1:d0dfbce63a89 2844 * @brief This function allows to really start regular conversion.
elmot 1:d0dfbce63a89 2845 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2846 * @retval None
elmot 1:d0dfbce63a89 2847 */
elmot 1:d0dfbce63a89 2848 static void DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef* hdfsdm_filter)
elmot 1:d0dfbce63a89 2849 {
elmot 1:d0dfbce63a89 2850 /* Check regular trigger */
elmot 1:d0dfbce63a89 2851 if(hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER)
elmot 1:d0dfbce63a89 2852 {
elmot 1:d0dfbce63a89 2853 /* Software start of regular conversion */
elmot 1:d0dfbce63a89 2854 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
elmot 1:d0dfbce63a89 2855 }
elmot 1:d0dfbce63a89 2856 else /* synchronous trigger */
elmot 1:d0dfbce63a89 2857 {
elmot 1:d0dfbce63a89 2858 /* Disable DFSDM filter */
elmot 1:d0dfbce63a89 2859 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
elmot 1:d0dfbce63a89 2860
elmot 1:d0dfbce63a89 2861 /* Set RSYNC bit in DFSDM_FLTCR1 register */
elmot 1:d0dfbce63a89 2862 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSYNC;
elmot 1:d0dfbce63a89 2863
elmot 1:d0dfbce63a89 2864 /* Enable DFSDM filter */
elmot 1:d0dfbce63a89 2865 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
elmot 1:d0dfbce63a89 2866
elmot 1:d0dfbce63a89 2867 /* If injected conversion was in progress, restart it */
elmot 1:d0dfbce63a89 2868 if(hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ)
elmot 1:d0dfbce63a89 2869 {
elmot 1:d0dfbce63a89 2870 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
elmot 1:d0dfbce63a89 2871 {
elmot 1:d0dfbce63a89 2872 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART;
elmot 1:d0dfbce63a89 2873 }
elmot 1:d0dfbce63a89 2874 /* Update remaining injected conversions */
elmot 1:d0dfbce63a89 2875 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
elmot 1:d0dfbce63a89 2876 hdfsdm_filter->InjectedChannelsNbr : 1;
elmot 1:d0dfbce63a89 2877 }
elmot 1:d0dfbce63a89 2878 }
elmot 1:d0dfbce63a89 2879 /* Update DFSDM filter state */
elmot 1:d0dfbce63a89 2880 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) ? \
elmot 1:d0dfbce63a89 2881 HAL_DFSDM_FILTER_STATE_REG : HAL_DFSDM_FILTER_STATE_REG_INJ;
elmot 1:d0dfbce63a89 2882 }
elmot 1:d0dfbce63a89 2883
elmot 1:d0dfbce63a89 2884 /**
elmot 1:d0dfbce63a89 2885 * @brief This function allows to really stop regular conversion.
elmot 1:d0dfbce63a89 2886 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2887 * @retval None
elmot 1:d0dfbce63a89 2888 */
elmot 1:d0dfbce63a89 2889 static void DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef* hdfsdm_filter)
elmot 1:d0dfbce63a89 2890 {
elmot 1:d0dfbce63a89 2891 /* Disable DFSDM filter */
elmot 1:d0dfbce63a89 2892 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
elmot 1:d0dfbce63a89 2893
elmot 1:d0dfbce63a89 2894 /* If regular trigger was synchronous, reset RSYNC bit in DFSDM_FLTCR1 register */
elmot 1:d0dfbce63a89 2895 if(hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SYNC_TRIGGER)
elmot 1:d0dfbce63a89 2896 {
elmot 1:d0dfbce63a89 2897 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RSYNC);
elmot 1:d0dfbce63a89 2898 }
elmot 1:d0dfbce63a89 2899
elmot 1:d0dfbce63a89 2900 /* Enable DFSDM filter */
elmot 1:d0dfbce63a89 2901 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
elmot 1:d0dfbce63a89 2902
elmot 1:d0dfbce63a89 2903 /* If injected conversion was in progress, restart it */
elmot 1:d0dfbce63a89 2904 if(hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG_INJ)
elmot 1:d0dfbce63a89 2905 {
elmot 1:d0dfbce63a89 2906 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
elmot 1:d0dfbce63a89 2907 {
elmot 1:d0dfbce63a89 2908 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART;
elmot 1:d0dfbce63a89 2909 }
elmot 1:d0dfbce63a89 2910 /* Update remaining injected conversions */
elmot 1:d0dfbce63a89 2911 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
elmot 1:d0dfbce63a89 2912 hdfsdm_filter->InjectedChannelsNbr : 1;
elmot 1:d0dfbce63a89 2913 }
elmot 1:d0dfbce63a89 2914
elmot 1:d0dfbce63a89 2915 /* Update DFSDM filter state */
elmot 1:d0dfbce63a89 2916 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \
elmot 1:d0dfbce63a89 2917 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ;
elmot 1:d0dfbce63a89 2918 }
elmot 1:d0dfbce63a89 2919
elmot 1:d0dfbce63a89 2920 /**
elmot 1:d0dfbce63a89 2921 * @brief This function allows to really start injected conversion.
elmot 1:d0dfbce63a89 2922 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2923 * @retval None
elmot 1:d0dfbce63a89 2924 */
elmot 1:d0dfbce63a89 2925 static void DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef* hdfsdm_filter)
elmot 1:d0dfbce63a89 2926 {
elmot 1:d0dfbce63a89 2927 /* Check injected trigger */
elmot 1:d0dfbce63a89 2928 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
elmot 1:d0dfbce63a89 2929 {
elmot 1:d0dfbce63a89 2930 /* Software start of injected conversion */
elmot 1:d0dfbce63a89 2931 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART;
elmot 1:d0dfbce63a89 2932 }
elmot 1:d0dfbce63a89 2933 else /* external or synchronous trigger */
elmot 1:d0dfbce63a89 2934 {
elmot 1:d0dfbce63a89 2935 /* Disable DFSDM filter */
elmot 1:d0dfbce63a89 2936 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
elmot 1:d0dfbce63a89 2937
elmot 1:d0dfbce63a89 2938 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SYNC_TRIGGER)
elmot 1:d0dfbce63a89 2939 {
elmot 1:d0dfbce63a89 2940 /* Set JSYNC bit in DFSDM_FLTCR1 register */
elmot 1:d0dfbce63a89 2941 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSYNC;
elmot 1:d0dfbce63a89 2942 }
elmot 1:d0dfbce63a89 2943 else /* external trigger */
elmot 1:d0dfbce63a89 2944 {
elmot 1:d0dfbce63a89 2945 /* Set JEXTEN[1:0] bits in DFSDM_FLTCR1 register */
elmot 1:d0dfbce63a89 2946 hdfsdm_filter->Instance->FLTCR1 |= hdfsdm_filter->ExtTriggerEdge;
elmot 1:d0dfbce63a89 2947 }
elmot 1:d0dfbce63a89 2948
elmot 1:d0dfbce63a89 2949 /* Enable DFSDM filter */
elmot 1:d0dfbce63a89 2950 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
elmot 1:d0dfbce63a89 2951
elmot 1:d0dfbce63a89 2952 /* If regular conversion was in progress, restart it */
elmot 1:d0dfbce63a89 2953 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) && \
elmot 1:d0dfbce63a89 2954 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
elmot 1:d0dfbce63a89 2955 {
elmot 1:d0dfbce63a89 2956 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
elmot 1:d0dfbce63a89 2957 }
elmot 1:d0dfbce63a89 2958 }
elmot 1:d0dfbce63a89 2959 /* Update DFSDM filter state */
elmot 1:d0dfbce63a89 2960 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) ? \
elmot 1:d0dfbce63a89 2961 HAL_DFSDM_FILTER_STATE_INJ : HAL_DFSDM_FILTER_STATE_REG_INJ;
elmot 1:d0dfbce63a89 2962 }
elmot 1:d0dfbce63a89 2963
elmot 1:d0dfbce63a89 2964 /**
elmot 1:d0dfbce63a89 2965 * @brief This function allows to really stop injected conversion.
elmot 1:d0dfbce63a89 2966 * @param hdfsdm_filter : DFSDM filter handle.
elmot 1:d0dfbce63a89 2967 * @retval None
elmot 1:d0dfbce63a89 2968 */
elmot 1:d0dfbce63a89 2969 static void DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef* hdfsdm_filter)
elmot 1:d0dfbce63a89 2970 {
elmot 1:d0dfbce63a89 2971 /* Disable DFSDM filter */
elmot 1:d0dfbce63a89 2972 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
elmot 1:d0dfbce63a89 2973
elmot 1:d0dfbce63a89 2974 /* If injected trigger was synchronous, reset JSYNC bit in DFSDM_FLTCR1 register */
elmot 1:d0dfbce63a89 2975 if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SYNC_TRIGGER)
elmot 1:d0dfbce63a89 2976 {
elmot 1:d0dfbce63a89 2977 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSYNC);
elmot 1:d0dfbce63a89 2978 }
elmot 1:d0dfbce63a89 2979 else if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_EXT_TRIGGER)
elmot 1:d0dfbce63a89 2980 {
elmot 1:d0dfbce63a89 2981 /* Reset JEXTEN[1:0] bits in DFSDM_FLTCR1 register */
elmot 1:d0dfbce63a89 2982 hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JEXTEN);
elmot 1:d0dfbce63a89 2983 }
elmot 1:d0dfbce63a89 2984
elmot 1:d0dfbce63a89 2985 /* Enable DFSDM filter */
elmot 1:d0dfbce63a89 2986 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
elmot 1:d0dfbce63a89 2987
elmot 1:d0dfbce63a89 2988 /* If regular conversion was in progress, restart it */
elmot 1:d0dfbce63a89 2989 if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG_INJ) && \
elmot 1:d0dfbce63a89 2990 (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
elmot 1:d0dfbce63a89 2991 {
elmot 1:d0dfbce63a89 2992 hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
elmot 1:d0dfbce63a89 2993 }
elmot 1:d0dfbce63a89 2994
elmot 1:d0dfbce63a89 2995 /* Update remaining injected conversions */
elmot 1:d0dfbce63a89 2996 hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
elmot 1:d0dfbce63a89 2997 hdfsdm_filter->InjectedChannelsNbr : 1;
elmot 1:d0dfbce63a89 2998
elmot 1:d0dfbce63a89 2999 /* Update DFSDM filter state */
elmot 1:d0dfbce63a89 3000 hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \
elmot 1:d0dfbce63a89 3001 HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG;
elmot 1:d0dfbce63a89 3002 }
elmot 1:d0dfbce63a89 3003
elmot 1:d0dfbce63a89 3004 /**
elmot 1:d0dfbce63a89 3005 * @}
elmot 1:d0dfbce63a89 3006 */
elmot 1:d0dfbce63a89 3007 /* End of private functions --------------------------------------------------*/
elmot 1:d0dfbce63a89 3008
elmot 1:d0dfbce63a89 3009 /**
elmot 1:d0dfbce63a89 3010 * @}
elmot 1:d0dfbce63a89 3011 */
elmot 1:d0dfbce63a89 3012 #endif /* STM32L471xx || STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx */
elmot 1:d0dfbce63a89 3013 #endif /* HAL_DFSDM_MODULE_ENABLED */
elmot 1:d0dfbce63a89 3014 /**
elmot 1:d0dfbce63a89 3015 * @}
elmot 1:d0dfbce63a89 3016 */
elmot 1:d0dfbce63a89 3017
elmot 1:d0dfbce63a89 3018 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/