You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

3860 lines
130 KiB

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