stm32f4xx_dfsdm.c 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_dfsdm.c
  4. * @author MCD Application Team
  5. * @version V1.8.1
  6. * @date 27-January-2022
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of Digital Filter for Sigma Delta modulator
  9. * (DFSDM) peripheral:
  10. * + Initialization functions.
  11. * + Configuration functions.
  12. * + Interrupts and flags management functions.
  13. *
  14. * @verbatim
  15. *
  16. ================================================================================
  17. ##### How to use this driver #####
  18. ================================================================================
  19. [..]
  20. @endverbatim
  21. ******************************************************************************
  22. * @attention
  23. *
  24. * Copyright (c) 2016 STMicroelectronics.
  25. * All rights reserved.
  26. *
  27. * This software is licensed under terms that can be found in the LICENSE file
  28. * in the root directory of this software component.
  29. * If no LICENSE file comes with this software, it is provided AS-IS.
  30. *
  31. ******************************************************************************
  32. */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "stm32f4xx_dfsdm.h"
  35. #include "stm32f4xx_rcc.h"
  36. /** @addtogroup STM32F4xx_StdPeriph_Driver
  37. * @{
  38. */
  39. /** @defgroup DFSDM
  40. * @brief DFSDM driver modules
  41. * @{
  42. */
  43. #if defined(STM32F412xG) || defined(STM32F413_423xx)
  44. /* External variables --------------------------------------------------------*/
  45. /* Private typedef -----------------------------------------------------------*/
  46. /* Private defines -----------------------------------------------------------*/
  47. #define CHCFGR_INIT_CLEAR_MASK (uint32_t) 0xFFFE0F10
  48. /* Private macros ------------------------------------------------------------*/
  49. /* Private variables ---------------------------------------------------------*/
  50. /* Private function prototypes -----------------------------------------------*/
  51. /* Private functions ---------------------------------------------------------*/
  52. /** @defgroup DFSDM_Private_Functions
  53. * @{
  54. */
  55. /** @defgroup DFSDM_Group1 Initialization functions
  56. * @brief Initialization functions
  57. *
  58. @verbatim
  59. ===============================================================================
  60. Initialization functions
  61. ===============================================================================
  62. This section provides functions allowing to:
  63. - Deinitialize the DFSDM
  64. - Initialize DFSDM serial channels transceiver
  65. - Initialize DFSDM filter
  66. @endverbatim
  67. * @{
  68. */
  69. /**
  70. * @brief Deinitializes the DFSDM peripheral registers to their default reset values.
  71. * @param None.
  72. * @retval None.
  73. *
  74. */
  75. void DFSDM_DeInit(void)
  76. {
  77. /* Enable LPTx reset state */
  78. RCC_APB2PeriphResetCmd(RCC_APB2Periph_DFSDM1, ENABLE);
  79. RCC_APB2PeriphResetCmd(RCC_APB2Periph_DFSDM1, DISABLE);
  80. #if defined(STM32F413_423xx)
  81. RCC_APB2PeriphResetCmd(RCC_APB2Periph_DFSDM2, ENABLE);
  82. RCC_APB2PeriphResetCmd(RCC_APB2Periph_DFSDM2, DISABLE);
  83. #endif /* STM32F413_423xx */
  84. }
  85. /**
  86. * @brief Initializes the DFSDM serial channels transceiver according to the specified
  87. * parameters in the DFSDM_TransceiverInit.
  88. * @param DFSDM_Channelx: specifies the channel to be selected.
  89. * This parameter can be one of the following values :
  90. * @arg DFSDM1_Channel0 : DFSDM 1 Channel 0
  91. * @arg DFSDM1_Channel1 : DFSDM 1 Channel 1
  92. * @arg DFSDM1_Channel2 : DFSDM 1 Channel 2
  93. * @arg DFSDM1_Channel3 : DFSDM 1 Channel 3
  94. * @arg DFSDM2_Channel0 : DFSDM 2 Channel 0 (available only for STM32F413_423xx devices)
  95. * @arg DFSDM2_Channel1 : DFSDM 2 Channel 1 (available only for STM32F413_423xx devices)
  96. * @arg DFSDM2_Channel2 : DFSDM 2 Channel 2 (available only for STM32F413_423xx devices)
  97. * @arg DFSDM2_Channel3 : DFSDM 2 Channel 3 (available only for STM32F413_423xx devices)
  98. * @arg DFSDM2_Channel4 : DFSDM 2 Channel 4 (available only for STM32F413_423xx devices)
  99. * @arg DFSDM2_Channel5 : DFSDM 2 Channel 5 (available only for STM32F413_423xx devices)
  100. * @arg DFSDM2_Channel6 : DFSDM 2 Channel 6 (available only for STM32F413_423xx devices)
  101. * @arg DFSDM2_Channel7 : DFSDM 2 Channel 7 (available only for STM32F413_423xx devices)
  102. * @param DFSDM_TransceiverInitStruct: pointer to a DFSDM_TransceiverInitTypeDef structure
  103. * that contains the configuration information for the specified channel.
  104. * @retval None
  105. * @note It is mandatory to disable the selected channel to use this function.
  106. */
  107. void DFSDM_TransceiverInit(DFSDM_Channel_TypeDef* DFSDM_Channelx, DFSDM_TransceiverInitTypeDef* DFSDM_TransceiverInitStruct)
  108. {
  109. uint32_t tmpreg1 = 0;
  110. uint32_t tmpreg2 = 0;
  111. /* Check the parameters */
  112. assert_param(IS_DFSDM_ALL_CHANNEL(DFSDM_Channelx));
  113. assert_param(IS_DFSDM_INTERFACE(DFSDM_TransceiverInitStruct->DFSDM_Interface));
  114. assert_param(IS_DFSDM_Input_MODE(DFSDM_TransceiverInitStruct->DFSDM_Input));
  115. assert_param(IS_DFSDM_Redirection_STATE(DFSDM_TransceiverInitStruct->DFSDM_Redirection));
  116. assert_param(IS_DFSDM_PACK_MODE(DFSDM_TransceiverInitStruct->DFSDM_PackingMode));
  117. assert_param(IS_DFSDM_CLOCK(DFSDM_TransceiverInitStruct->DFSDM_Clock));
  118. assert_param(IS_DFSDM_DATA_RIGHT_BIT_SHIFT(DFSDM_TransceiverInitStruct->DFSDM_DataRightShift));
  119. assert_param(IS_DFSDM_OFFSET(DFSDM_TransceiverInitStruct->DFSDM_Offset));
  120. assert_param(IS_DFSDM_CLK_DETECTOR_STATE(DFSDM_TransceiverInitStruct->DFSDM_CLKAbsenceDetector));
  121. assert_param(IS_DFSDM_SC_DETECTOR_STATE(DFSDM_TransceiverInitStruct->DFSDM_ShortCircuitDetector));
  122. /* Get the DFSDM Channelx CHCFGR1 value */
  123. tmpreg1 = DFSDM_Channelx->CHCFGR1;
  124. /* Clear SITP, CKABEN, SCDEN and SPICKSEL bits */
  125. tmpreg1 &= CHCFGR_INIT_CLEAR_MASK;
  126. /* Set or Reset SITP bits according to DFSDM_Interface value */
  127. /* Set or Reset SPICKSEL bits according to DFSDM_Clock value */
  128. /* Set or Reset DATMPX bits according to DFSDM_InputMode value */
  129. /* Set or Reset CHINSEL bits according to DFSDM_Redirection value */
  130. /* Set or Reset DATPACK bits according to DFSDM_PackingMode value */
  131. /* Set or Reset CKABEN bit according to DFSDM_CLKAbsenceDetector value */
  132. /* Set or Reset SCDEN bit according to DFSDM_ShortCircuitDetector value */
  133. tmpreg1 |= (DFSDM_TransceiverInitStruct->DFSDM_Interface |
  134. DFSDM_TransceiverInitStruct->DFSDM_Clock |
  135. DFSDM_TransceiverInitStruct->DFSDM_Input |
  136. DFSDM_TransceiverInitStruct->DFSDM_Redirection |
  137. DFSDM_TransceiverInitStruct->DFSDM_PackingMode |
  138. DFSDM_TransceiverInitStruct->DFSDM_CLKAbsenceDetector |
  139. DFSDM_TransceiverInitStruct->DFSDM_ShortCircuitDetector);
  140. /* Write to DFSDM Channelx CHCFGR1R */
  141. DFSDM_Channelx->CHCFGR1 = tmpreg1;
  142. /* Get the DFSDM Channelx CHCFGR2 value */
  143. tmpreg2 = DFSDM_Channelx->CHCFGR2;
  144. /* Clear DTRBS and OFFSET bits */
  145. tmpreg2 &= ~(DFSDM_CHCFGR2_DTRBS | DFSDM_CHCFGR2_OFFSET);
  146. /* Set or Reset DTRBS bits according to DFSDM_DataRightShift value */
  147. /* Set or Reset OFFSET bits according to DFSDM_Offset value */
  148. tmpreg2 |= (((DFSDM_TransceiverInitStruct->DFSDM_DataRightShift) <<3 ) |
  149. ((DFSDM_TransceiverInitStruct->DFSDM_Offset) <<8 ));
  150. /* Write to DFSDM Channelx CHCFGR1R */
  151. DFSDM_Channelx->CHCFGR2 = tmpreg2;
  152. }
  153. /**
  154. * @brief Fills each DFSDM_TransceiverInitStruct member with its default value.
  155. * @param DFSDM_TransceiverInitStruct : pointer to a DFSDM_TransceiverInitTypeDef structure
  156. * which will be initialized.
  157. * @retval None
  158. */
  159. void DFSDM_TransceiverStructInit(DFSDM_TransceiverInitTypeDef* DFSDM_TransceiverInitStruct)
  160. {
  161. /* SPI with rising edge to strobe data is selected as default serial interface */
  162. DFSDM_TransceiverInitStruct->DFSDM_Interface = DFSDM_Interface_SPI_FallingEdge;
  163. /* Clock coming from internal DFSDM_CKOUT output is selected as default serial clock */
  164. DFSDM_TransceiverInitStruct->DFSDM_Clock = DFSDM_Clock_Internal;
  165. /* No data right bit-shift is selected as default data right bit-shift */
  166. DFSDM_TransceiverInitStruct->DFSDM_DataRightShift = 0x0;
  167. /* No offset is selected as default offset */
  168. DFSDM_TransceiverInitStruct->DFSDM_Offset = 0x0;
  169. /* Clock Absence Detector is Enabled as default state */
  170. DFSDM_TransceiverInitStruct->DFSDM_CLKAbsenceDetector = DFSDM_CLKAbsenceDetector_Enable;
  171. }
  172. /**
  173. * @brief Initializes the DFSDMx Filter according to the specified
  174. * parameters in the DFSDM_FilterInitStruct.
  175. * @param DFSDMx: specifies the filter to be selected :
  176. * This parameter can be one of the following values :
  177. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  178. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  179. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  180. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  181. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  182. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  183. * @param DFSDM_FilterInitStruct: pointer to a DFSDM_FilterInitTypeDef structure
  184. * that contains the configuration information for the specified filter.
  185. * @retval None
  186. *
  187. * @note It is mandatory to disable the selected filter to use this function.
  188. */
  189. void DFSDM_FilterInit(DFSDM_Filter_TypeDef* DFSDMx, DFSDM_FilterInitTypeDef* DFSDM_FilterInitStruct)
  190. {
  191. uint32_t tmpreg1 = 0;
  192. /* Check the parameters */
  193. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  194. assert_param(IS_DFSDM_SINC_ORDER(DFSDM_FilterInitStruct->DFSDM_SincOrder));
  195. assert_param(IS_DFSDM_SINC_OVRSMPL_RATIO(DFSDM_FilterInitStruct->DFSDM_FilterOversamplingRatio));
  196. assert_param(IS_DFSDM_INTG_OVRSMPL_RATIO(DFSDM_FilterInitStruct->DFSDM_IntegratorOversamplingRatio));
  197. /* Get the DFSDMx FCR value */
  198. tmpreg1 = DFSDMx->FLTFCR;
  199. /* Clear FORD, FOSR and IOSR bits */
  200. tmpreg1 &= ~(DFSDM_FLTFCR_FORD | DFSDM_FLTFCR_FOSR | DFSDM_FLTFCR_IOSR);
  201. /* Set or Reset FORD bits according to DFSDM_SincOrder value */
  202. /* Set or Reset FOSR bits according to DFSDM_FilterOversamplingRatio value */
  203. /* Set or Reset IOSR bits according to DFSDM_IntegratorOversamplingRatio value */
  204. tmpreg1 |= (DFSDM_FilterInitStruct->DFSDM_SincOrder |
  205. ((DFSDM_FilterInitStruct->DFSDM_FilterOversamplingRatio -1) << 16) |
  206. (DFSDM_FilterInitStruct->DFSDM_IntegratorOversamplingRatio -1));
  207. /* Write to DFSDMx FCR */
  208. DFSDMx->FLTFCR = tmpreg1;
  209. }
  210. /**
  211. * @brief Fills each DFSDM_FilterInitStruct member with its default value.
  212. * @param DFSDM_FilterInitStruct: pointer to a DFSDM_FilterInitTypeDef structure
  213. * which will be initialized.
  214. * @retval None
  215. */
  216. void DFSDM_FilterStructInit(DFSDM_FilterInitTypeDef* DFSDM_FilterInitStruct)
  217. {
  218. /* Order = 3 is selected as default sinc order */
  219. DFSDM_FilterInitStruct->DFSDM_SincOrder = DFSDM_SincOrder_Sinc3;
  220. /* Ratio = 64 is selected as default oversampling ratio */
  221. DFSDM_FilterInitStruct->DFSDM_FilterOversamplingRatio = 64 ;
  222. /* Ratio = 4 is selected as default integrator oversampling ratio */
  223. DFSDM_FilterInitStruct->DFSDM_IntegratorOversamplingRatio = 4;
  224. }
  225. /**
  226. * @}
  227. */
  228. /** @defgroup DFSDM_Group2 Configuration functions
  229. * @brief Configuration functions
  230. *
  231. @verbatim
  232. ===============================================================================
  233. Configuration functions
  234. ===============================================================================
  235. This section provides functions allowing to configure DFSDM:
  236. - Enable/Disable (DFSDM peripheral, Channel, Filter)
  237. - Configure Clock output
  238. - Configure Injected/Regular channels for Conversion
  239. - Configure short circuit detector
  240. - Configure Analog watchdog filter
  241. @endverbatim
  242. * @{
  243. */
  244. #if defined(STM32F412xG)
  245. /**
  246. * @brief Enables or disables the DFSDM peripheral.
  247. * @param NewState: new state of the DFSDM interface.
  248. * This parameter can be: ENABLE or DISABLE.
  249. * @retval None
  250. */
  251. void DFSDM_Command(FunctionalState NewState)
  252. {
  253. /* Check the parameters */
  254. assert_param(IS_FUNCTIONAL_STATE(NewState));
  255. if (NewState != DISABLE)
  256. {
  257. /* Set the ENABLE bit */
  258. DFSDM1_Channel0 -> CHCFGR1 |= DFSDM_CHCFGR1_DFSDMEN;
  259. }
  260. else
  261. {
  262. /* Reset the ENABLE bit */
  263. DFSDM1_Channel0 -> CHCFGR1 &= ~(DFSDM_CHCFGR1_DFSDMEN);
  264. }
  265. }
  266. #endif /* STM32F412xG */
  267. #if defined(STM32F413_423xx)
  268. /**
  269. * @brief Enables or disables the DFSDM peripheral.
  270. * @param Instance: select the instance of DFSDM
  271. * This parameter can be: 1 or 2.
  272. * @param NewState: new state of the DFSDM interface.
  273. * This parameter can be: ENABLE or DISABLE.
  274. * @retval None
  275. */
  276. void DFSDM_Cmd(uint32_t Instance, FunctionalState NewState)
  277. {
  278. /* Check the parameters */
  279. assert_param(IS_FUNCTIONAL_STATE(NewState));
  280. if(Instance == 1)
  281. {
  282. if (NewState != DISABLE)
  283. {
  284. /* Set the ENABLE bit */
  285. DFSDM1_Channel0 -> CHCFGR1 |= DFSDM_CHCFGR1_DFSDMEN;
  286. }
  287. else
  288. {
  289. /* Reset the ENABLE bit */
  290. DFSDM1_Channel0 -> CHCFGR1 &= ~(DFSDM_CHCFGR1_DFSDMEN);
  291. }
  292. }
  293. else /* DFSDM2 */
  294. {
  295. if (NewState != DISABLE)
  296. {
  297. /* Set the ENABLE bit */
  298. DFSDM2_Channel0 -> CHCFGR1 |= DFSDM_CHCFGR1_DFSDMEN;
  299. }
  300. else
  301. {
  302. /* Reset the ENABLE bit */
  303. DFSDM2_Channel0 -> CHCFGR1 &= ~(DFSDM_CHCFGR1_DFSDMEN);
  304. }
  305. }
  306. }
  307. #endif /* STM32F413_423xx */
  308. /**
  309. * @brief Enables or disables the specified DFSDM serial channelx.
  310. * @param DFSDM_Channelx: specifies the channel to be selected.
  311. * This parameter can be one of the following values :
  312. * @arg DFSDM1_Channel0 : DFSDM 1 Channel 0
  313. * @arg DFSDM1_Channel1 : DFSDM 1 Channel 1
  314. * @arg DFSDM1_Channel2 : DFSDM 1 Channel 2
  315. * @arg DFSDM1_Channel3 : DFSDM 1 Channel 3
  316. * @arg DFSDM2_Channel0 : DFSDM 2 Channel 0 (available only for STM32F413_423xx devices)
  317. * @arg DFSDM2_Channel1 : DFSDM 2 Channel 1 (available only for STM32F413_423xx devices)
  318. * @arg DFSDM2_Channel2 : DFSDM 2 Channel 2 (available only for STM32F413_423xx devices)
  319. * @arg DFSDM2_Channel3 : DFSDM 2 Channel 3 (available only for STM32F413_423xx devices)
  320. * @arg DFSDM2_Channel4 : DFSDM 2 Channel 4 (available only for STM32F413_423xx devices)
  321. * @arg DFSDM2_Channel5 : DFSDM 2 Channel 5 (available only for STM32F413_423xx devices)
  322. * @arg DFSDM2_Channel6 : DFSDM 2 Channel 6 (available only for STM32F413_423xx devices)
  323. * @arg DFSDM2_Channel7 : DFSDM 2 Channel 7 (available only for STM32F413_423xx devices)
  324. * @param NewState: new state of the DFSDM serial channelx .
  325. * This parameter can be: ENABLE or DISABLE.
  326. * @retval None
  327. */
  328. void DFSDM_ChannelCmd(DFSDM_Channel_TypeDef* DFSDM_Channelx, FunctionalState NewState)
  329. {
  330. /* Check the parameters */
  331. assert_param(IS_DFSDM_ALL_CHANNEL(DFSDM_Channelx));
  332. assert_param(IS_FUNCTIONAL_STATE(NewState));
  333. if (NewState != DISABLE)
  334. {
  335. /* Set the ENABLE bit */
  336. DFSDM_Channelx->CHCFGR1 |= DFSDM_CHCFGR1_CHEN;
  337. }
  338. else
  339. {
  340. /* Reset the ENABLE bit */
  341. DFSDM_Channelx->CHCFGR1 &= ~(DFSDM_CHCFGR1_CHEN);
  342. }
  343. }
  344. /**
  345. * @brief Enables or disables the specified DFSDMx Filter.
  346. * @param DFSDMx: specifies the filter to be selected :
  347. * This parameter can be one of the following values :
  348. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  349. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  350. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  351. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  352. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  353. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  354. * @param NewState: new state of the selected DFSDM module.
  355. * This parameter can be: ENABLE or DISABLE.
  356. * @retval None
  357. */
  358. void DFSDM_FilterCmd(DFSDM_Filter_TypeDef* DFSDMx, FunctionalState NewState)
  359. {
  360. /* Check the parameters */
  361. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  362. assert_param(IS_FUNCTIONAL_STATE(NewState));
  363. if (NewState != DISABLE)
  364. {
  365. /* Set the ENABLE bit */
  366. DFSDMx->FLTCR1 |= DFSDM_FLTCR1_DFEN;
  367. }
  368. else
  369. {
  370. /* Reset the ENABLE bit */
  371. DFSDMx->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
  372. }
  373. }
  374. #if defined(STM32F412xG)
  375. /**
  376. * @brief Configures the Output serial clock divider.
  377. * @param DFSDM_ClkOutDivision: Defines the divider for the output serial clock
  378. * This parameter can be a value between 1 and 256.
  379. * @retval None
  380. * @note The output serial clock is stopped if the divider =1.
  381. * By default the serial output clock is stopped.
  382. */
  383. void DFSDM_ConfigClkOutputDivider(uint32_t DFSDM_ClkOutDivision)
  384. {
  385. uint32_t tmpreg1 = 0;
  386. /* Check the parameters */
  387. assert_param(IS_DFSDM_CLOCK_OUT_DIVIDER(DFSDM_ClkOutDivision));
  388. /* Get the DFSDM_Channel0 CHCFGR1 value */
  389. tmpreg1 = DFSDM1_Channel0 -> CHCFGR1;
  390. /* Clear the CKOUTDIV bits */
  391. tmpreg1 &= (uint32_t)(~DFSDM_CHCFGR1_CKOUTDIV);
  392. /* Set or Reset the CKOUTDIV bits */
  393. tmpreg1 |= (uint32_t)((DFSDM_ClkOutDivision - 1) << 16);
  394. /* Write to DFSDM Channel0 CHCFGR1 */
  395. DFSDM1_Channel0 -> CHCFGR1 = tmpreg1;
  396. }
  397. /**
  398. * @brief Configures the Output serial clock source.
  399. * @param DFSDM_ClkOutSource: Defines the divider for the output serial clock
  400. * This parameter can be a value of:
  401. * @arg DFSDM_ClkOutSource_SysClock
  402. * @arg DFSDM_ClkOutSource_AudioClock
  403. * @retval None
  404. */
  405. void DFSDM_ConfigClkOutputSource(uint32_t DFSDM_ClkOutSource)
  406. {
  407. uint32_t tmpreg1 = 0;
  408. /* Check the parameters */
  409. assert_param(IS_DFSDM_CLOCK_OUT_SOURCE(DFSDM_ClkOutSource));
  410. /* Get the DFSDM_Channel0 CHCFGR1 value */
  411. tmpreg1 = DFSDM1_Channel0 -> CHCFGR1;
  412. /* Clear the CKOUTSRC bit */
  413. tmpreg1 &= ~(DFSDM_CHCFGR1_CKOUTSRC);
  414. /* Set or Reset the CKOUTSRC bit */
  415. tmpreg1 |= DFSDM_ClkOutSource;
  416. /* Write to DFSDM Channel0 CHCFGR1 */
  417. DFSDM1_Channel0 -> CHCFGR1 = tmpreg1;
  418. }
  419. #endif /* STM32F412xG */
  420. #if defined(STM32F413_423xx)
  421. /**
  422. * @brief Configures the Output serial clock divider.
  423. * @param Instance: select the instance of DFSDM
  424. * This parameter can be: 1 or 2.
  425. * @param DFSDM_ClkOutDivision: Defines the divider for the output serial clock
  426. * This parameter can be a value between 1 and 256.
  427. * @retval None
  428. * @note The output serial clock is stopped if the divider =1.
  429. * By default the serial output clock is stopped.
  430. */
  431. void DFSDM_ConfigClkOutputDivider(uint32_t Instance, uint32_t DFSDM_ClkOutDivision)
  432. {
  433. uint32_t tmpreg1 = 0;
  434. if(Instance == 1)
  435. {
  436. /* Check the parameters */
  437. assert_param(IS_DFSDM_CLOCK_OUT_DIVIDER(DFSDM_ClkOutDivision));
  438. /* Get the DFSDM_Channel0 CHCFGR1 value */
  439. tmpreg1 = DFSDM1_Channel0 -> CHCFGR1;
  440. /* Clear the CKOUTDIV bits */
  441. tmpreg1 &= (uint32_t)(~DFSDM_CHCFGR1_CKOUTDIV);
  442. /* Set or Reset the CKOUTDIV bits */
  443. tmpreg1 |= (uint32_t)((DFSDM_ClkOutDivision - 1) << 16);
  444. /* Write to DFSDM Channel0 CHCFGR1 */
  445. DFSDM1_Channel0 -> CHCFGR1 = tmpreg1;
  446. }
  447. else /* DFSDM2 */
  448. {
  449. /* Check the parameters */
  450. assert_param(IS_DFSDM_CLOCK_OUT_DIVIDER(DFSDM_ClkOutDivision));
  451. /* Get the DFSDM_Channel0 CHCFGR1 value */
  452. tmpreg1 = DFSDM2_Channel0 -> CHCFGR1;
  453. /* Clear the CKOUTDIV bits */
  454. tmpreg1 &= (uint32_t)(~DFSDM_CHCFGR1_CKOUTDIV);
  455. /* Set or Reset the CKOUTDIV bits */
  456. tmpreg1 |= (uint32_t)((DFSDM_ClkOutDivision - 1) << 16);
  457. /* Write to DFSDM Channel0 CHCFGR1 */
  458. DFSDM2_Channel0 -> CHCFGR1 = tmpreg1;
  459. }
  460. }
  461. /**
  462. * @brief Configures the Output serial clock source.
  463. * @param Instance: select the instance of DFSDM
  464. * This parameter can be: 1 or 2.
  465. * @param DFSDM_ClkOutSource: Defines the divider for the output serial clock
  466. * This parameter can be a value of:
  467. * @arg DFSDM_ClkOutSource_SysClock
  468. * @arg DFSDM_ClkOutSource_AudioClock
  469. * @retval None
  470. */
  471. void DFSDM_ConfigClkOutputSource(uint32_t Instance, uint32_t DFSDM_ClkOutSource)
  472. {
  473. uint32_t tmpreg1 = 0;
  474. if(Instance == 1)
  475. {
  476. /* Check the parameters */
  477. assert_param(IS_DFSDM_CLOCK_OUT_SOURCE(DFSDM_ClkOutSource));
  478. /* Get the DFSDM_Channel0 CHCFGR1 value */
  479. tmpreg1 = DFSDM1_Channel0 -> CHCFGR1;
  480. /* Clear the CKOUTSRC bit */
  481. tmpreg1 &= ~(DFSDM_CHCFGR1_CKOUTSRC);
  482. /* Set or Reset the CKOUTSRC bit */
  483. tmpreg1 |= DFSDM_ClkOutSource;
  484. /* Write to DFSDM Channel0 CHCFGR1 */
  485. DFSDM1_Channel0 -> CHCFGR1 = tmpreg1;
  486. }
  487. else /* DFSDM2 */
  488. {
  489. /* Check the parameters */
  490. assert_param(IS_DFSDM_CLOCK_OUT_SOURCE(DFSDM_ClkOutSource));
  491. /* Get the DFSDM_Channel0 CHCFGR1 value */
  492. tmpreg1 = DFSDM2_Channel0 -> CHCFGR1;
  493. /* Clear the CKOUTSRC bit */
  494. tmpreg1 &= ~(DFSDM_CHCFGR1_CKOUTSRC);
  495. /* Set or Reset the CKOUTSRC bit */
  496. tmpreg1 |= DFSDM_ClkOutSource;
  497. /* Write to DFSDM Channel0 CHCFGR1 */
  498. DFSDM2_Channel0 -> CHCFGR1 = tmpreg1;
  499. }
  500. }
  501. #endif /* STM32F413_423xx */
  502. /**
  503. * @brief Enables or disables the specified Break_i siganl to the specified DFSDM_Channelx.
  504. * @param DFSDM_Channelx: specifies the channel to be selected.
  505. * This parameter can be one of the following values :
  506. * @arg DFSDM1_Channel0 : DFSDM 1 Channel 0
  507. * @arg DFSDM1_Channel1 : DFSDM 1 Channel 1
  508. * @arg DFSDM1_Channel2 : DFSDM 1 Channel 2
  509. * @arg DFSDM1_Channel3 : DFSDM 1 Channel 3
  510. * @arg DFSDM2_Channel0 : DFSDM 2 Channel 0 (available only for STM32F413_423xx devices)
  511. * @arg DFSDM2_Channel1 : DFSDM 2 Channel 1 (available only for STM32F413_423xx devices)
  512. * @arg DFSDM2_Channel2 : DFSDM 2 Channel 2 (available only for STM32F413_423xx devices)
  513. * @arg DFSDM2_Channel3 : DFSDM 2 Channel 3 (available only for STM32F413_423xx devices)
  514. * @arg DFSDM2_Channel4 : DFSDM 2 Channel 4 (available only for STM32F413_423xx devices)
  515. * @arg DFSDM2_Channel5 : DFSDM 2 Channel 5 (available only for STM32F413_423xx devices)
  516. * @arg DFSDM2_Channel6 : DFSDM 2 Channel 6 (available only for STM32F413_423xx devices)
  517. * @arg DFSDM2_Channel7 : DFSDM 2 Channel 7 (available only for STM32F413_423xx devices)
  518. * @param DFSDM_SCDBreak_i: where i can be a value from 0 to 3 to select the specified Break signal.
  519. * @param NewState: new state of the selected DFSDM_SCDBreak_i.
  520. * This parameter can be: ENABLE or DISABLE.
  521. * @retval None
  522. */
  523. void DFSDM_ConfigBRKAnalogWatchDog(DFSDM_Channel_TypeDef* DFSDM_Channelx, uint32_t DFSDM_SCDBreak_i, FunctionalState NewState)
  524. {
  525. /* Check the parameters */
  526. assert_param(IS_DFSDM_ALL_CHANNEL(DFSDM_Channelx));
  527. assert_param(IS_DFSDM_SCD_BREAK_SIGNAL(DFSDM_SCDBreak_i));
  528. assert_param(IS_FUNCTIONAL_STATE(NewState));
  529. if (NewState != DISABLE)
  530. {
  531. /* Set the BKSCD[i] bit */
  532. DFSDM_Channelx -> CHAWSCDR |= DFSDM_SCDBreak_i;
  533. }
  534. else
  535. {
  536. /* Reset the BKSCD[i] bit */
  537. DFSDM_Channelx -> CHAWSCDR &= ~(DFSDM_SCDBreak_i);
  538. }
  539. }
  540. /**
  541. * @brief Enables or disables the specified Break_i siganl to the specified DFSDM_Channelx.
  542. * @param DFSDM_Channelx: specifies the channel to be selected.
  543. * This parameter can be one of the following values :
  544. * @arg DFSDM1_Channel0 : DFSDM 1 Channel 0
  545. * @arg DFSDM1_Channel1 : DFSDM 1 Channel 1
  546. * @arg DFSDM1_Channel2 : DFSDM 1 Channel 2
  547. * @arg DFSDM1_Channel3 : DFSDM 1 Channel 3
  548. * @arg DFSDM2_Channel0 : DFSDM 2 Channel 0 (available only for STM32F413_423xx devices)
  549. * @arg DFSDM2_Channel1 : DFSDM 2 Channel 1 (available only for STM32F413_423xx devices)
  550. * @arg DFSDM2_Channel2 : DFSDM 2 Channel 2 (available only for STM32F413_423xx devices)
  551. * @arg DFSDM2_Channel3 : DFSDM 2 Channel 3 (available only for STM32F413_423xx devices)
  552. * @arg DFSDM2_Channel4 : DFSDM 2 Channel 4 (available only for STM32F413_423xx devices)
  553. * @arg DFSDM2_Channel5 : DFSDM 2 Channel 5 (available only for STM32F413_423xx devices)
  554. * @arg DFSDM2_Channel6 : DFSDM 2 Channel 6 (available only for STM32F413_423xx devices)
  555. * @arg DFSDM2_Channel7 : DFSDM 2 Channel 7 (available only for STM32F413_423xx devices)
  556. * @param DFSDM_SCDBreak_i: where i can be a value from 0 to 3 to select the specified Break signal.
  557. * @param NewState: new state of the selected DFSDM_SCDBreak_i.
  558. * This parameter can be: ENABLE or DISABLE.
  559. * @retval None
  560. */
  561. void DFSDM_ConfigBRKShortCircuitDetector(DFSDM_Channel_TypeDef* DFSDM_Channelx, uint32_t DFSDM_SCDBreak_i, FunctionalState NewState)
  562. {
  563. /* Check the parameters */
  564. assert_param(IS_DFSDM_ALL_CHANNEL(DFSDM_Channelx));
  565. assert_param(IS_DFSDM_SCD_BREAK_SIGNAL(DFSDM_SCDBreak_i));
  566. assert_param(IS_FUNCTIONAL_STATE(NewState));
  567. if (NewState != DISABLE)
  568. {
  569. /* Set the BKSCD[i] bit */
  570. DFSDM_Channelx -> CHAWSCDR |= DFSDM_SCDBreak_i;
  571. }
  572. else
  573. {
  574. /* Reset the BKSCD[i] bit */
  575. DFSDM_Channelx -> CHAWSCDR &= ~(DFSDM_SCDBreak_i);
  576. }
  577. }
  578. /**
  579. * @brief Defines the threshold counter for the short circuit detector for the selected DFSDM_Channelx.
  580. * @param DFSDM_Channelx: specifies the channel to be selected.
  581. * This parameter can be one of the following values :
  582. * @arg DFSDM1_Channel0 : DFSDM 1 Channel 0
  583. * @arg DFSDM1_Channel1 : DFSDM 1 Channel 1
  584. * @arg DFSDM1_Channel2 : DFSDM 1 Channel 2
  585. * @arg DFSDM1_Channel3 : DFSDM 1 Channel 3
  586. * @arg DFSDM2_Channel0 : DFSDM 2 Channel 0 (available only for STM32F413_423xx devices)
  587. * @arg DFSDM2_Channel1 : DFSDM 2 Channel 1 (available only for STM32F413_423xx devices)
  588. * @arg DFSDM2_Channel2 : DFSDM 2 Channel 2 (available only for STM32F413_423xx devices)
  589. * @arg DFSDM2_Channel3 : DFSDM 2 Channel 3 (available only for STM32F413_423xx devices)
  590. * @arg DFSDM2_Channel4 : DFSDM 2 Channel 4 (available only for STM32F413_423xx devices)
  591. * @arg DFSDM2_Channel5 : DFSDM 2 Channel 5 (available only for STM32F413_423xx devices)
  592. * @arg DFSDM2_Channel6 : DFSDM 2 Channel 6 (available only for STM32F413_423xx devices)
  593. * @arg DFSDM2_Channel7 : DFSDM 2 Channel 7 (available only for STM32F413_423xx devices)
  594. * @param DFSDM_SCDThreshold: The threshold counter, this parameter can be a value between 0 and 255.
  595. * @retval None
  596. */
  597. void DFSDM_ConfigShortCircuitThreshold(DFSDM_Channel_TypeDef* DFSDM_Channelx, uint32_t DFSDM_SCDThreshold)
  598. {
  599. uint32_t tmpreg1 = 0;
  600. /* Check the parameters */
  601. assert_param(IS_DFSDM_ALL_CHANNEL(DFSDM_Channelx));
  602. assert_param(IS_DFSDM_CSD_THRESHOLD_VALUE(DFSDM_SCDThreshold));
  603. /* Get the DFSDM_Channelx AWSCDR value */
  604. tmpreg1 = DFSDM_Channelx -> CHAWSCDR;
  605. /* Clear the SCDT bits */
  606. tmpreg1 &= ~(DFSDM_CHAWSCDR_SCDT);
  607. /* Set or Reset the SCDT bits */
  608. tmpreg1 |= DFSDM_SCDThreshold;
  609. /* Write to DFSDM Channelx AWSCDR */
  610. DFSDM_Channelx -> CHAWSCDR = tmpreg1;
  611. }
  612. /**
  613. * @brief Selects the channel to be guarded by the Analog watchdog for the selected DFSDMx,
  614. * and select if the fast analog watchdog is enabled or not.
  615. * @param DFSDMx: specifies the filter to be selected :
  616. * This parameter can be one of the following values :
  617. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  618. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  619. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  620. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  621. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  622. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  623. * @param DFSDM_AWDChannelx: where x can be a value from 0 to 7 to select the DFSDM Channel.
  624. * @param DFSDM_AWDFastMode: The analog watchdog fast mode.
  625. * This parameter can be a value of @ref DFSDM_AWD_Fast_Mode_Selection.
  626. * @retval None
  627. */
  628. void DFSDM_ConfigAnalogWatchdog(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_AWDChannelx, uint32_t DFSDM_AWDFastMode)
  629. {
  630. uint32_t tmpreg1 = 0;
  631. uint32_t tmpreg2 = 0;
  632. /* Check the parameters */
  633. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  634. assert_param(IS_DFSDM_AWD_CHANNEL(DFSDM_AWDChannelx));
  635. assert_param(IS_DFSDM_AWD_MODE(DFSDM_AWDFastMode));
  636. /* Get the DFSDMx CR2 value */
  637. tmpreg1 = DFSDMx -> FLTCR2;
  638. /* Clear the AWDCH bits */
  639. tmpreg1 &= ~(DFSDM_FLTCR2_AWDCH);
  640. /* Set or Reset the AWDCH bits */
  641. tmpreg1 |= DFSDM_AWDChannelx;
  642. /* Write to DFSDMx CR2 Register */
  643. DFSDMx -> FLTCR2 |= tmpreg1;
  644. /* Get the DFSDMx CR1 value */
  645. tmpreg2 = DFSDMx->FLTCR1;
  646. /* Clear the AWFSEL bit */
  647. tmpreg2 &= ~(DFSDM_FLTCR1_AWFSEL);
  648. /* Set or Reset the AWFSEL bit */
  649. tmpreg2 |= DFSDM_AWDFastMode;
  650. /* Write to DFSDMx CR1 Register */
  651. DFSDMx->FLTCR1 = tmpreg2;
  652. }
  653. /**
  654. * @brief Selects the channel to be guarded by the Analog watchdog of the selected DFSDMx, and the mode to be used.
  655. * @param DFSDMx: specifies the filter to be selected :
  656. * This parameter can be one of the following values :
  657. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  658. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  659. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  660. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  661. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  662. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  663. * @param DFSDM_ExtremChannelx: where x can be a value from 0 to 7 to select the Channel to be connected
  664. * to the Extremes detector.
  665. * @retval None
  666. */
  667. void DFSDM_SelectExtremesDetectorChannel(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_ExtremChannelx)
  668. {
  669. uint32_t tmpreg1 = 0;
  670. /* Check the parameters */
  671. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  672. assert_param(IS_DFSDM_EXTREM_CHANNEL(DFSDM_ExtremChannelx));
  673. /* Get the DFSDMx CR2 value */
  674. tmpreg1 = DFSDMx -> FLTCR2;
  675. /* Clear the EXCH bits */
  676. tmpreg1 &= ~(DFSDM_FLTCR2_EXCH);
  677. /* Set or Reset the AWDCH bits */
  678. tmpreg1 |= DFSDM_ExtremChannelx;
  679. /* Write to DFSDMx CR2 Register */
  680. DFSDMx -> FLTCR2 = tmpreg1;
  681. }
  682. /**
  683. * @brief Returns the regular conversion data by the DFSDMx.
  684. * @param DFSDMx: specifies the filter to be selected :
  685. * This parameter can be one of the following values :
  686. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  687. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  688. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  689. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  690. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  691. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  692. * @retval The converted regular data.
  693. * @note This function returns a signed value.
  694. */
  695. int32_t DFSDM_GetRegularConversionData(DFSDM_Filter_TypeDef* DFSDMx)
  696. {
  697. uint32_t reg = 0;
  698. int32_t value = 0;
  699. /* Check the parameters */
  700. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  701. /* Get value of data register for regular channel */
  702. reg = DFSDMx -> FLTRDATAR;
  703. /* Extract conversion value */
  704. value = (((reg & 0xFFFFFF00) >> 8));
  705. /* Return the conversion result */
  706. return value;
  707. }
  708. /**
  709. * @brief Returns the injected conversion data by the DFSDMx.
  710. * @param DFSDMx: specifies the filter to be selected :
  711. * This parameter can be one of the following values :
  712. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  713. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  714. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  715. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  716. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  717. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  718. * @retval The converted regular data.
  719. * @note This function returns a signed value.
  720. */
  721. int32_t DFSDM_GetInjectedConversionData(DFSDM_Filter_TypeDef* DFSDMx)
  722. {
  723. uint32_t reg = 0;
  724. int32_t value = 0;
  725. /* Check the parameters */
  726. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  727. /* Get value of data register for regular channel */
  728. reg = DFSDMx -> FLTJDATAR;
  729. /* Extract conversion value */
  730. value = ((reg & 0xFFFFFF00) >> 8);
  731. /* Return the conversion result */
  732. return value;
  733. }
  734. /**
  735. * @brief Returns the highest value converted by the DFSDMx.
  736. * @param DFSDMx: specifies the filter to be selected :
  737. * This parameter can be one of the following values :
  738. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  739. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  740. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  741. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  742. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  743. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  744. * @retval The highest converted value.
  745. * @note This function returns a signed value.
  746. */
  747. int32_t DFSDM_GetMaxValue(DFSDM_Filter_TypeDef* DFSDMx)
  748. {
  749. int32_t value = 0;
  750. /* Check the parameters */
  751. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  752. value = ((DFSDMx -> FLTEXMAX) >> 8);
  753. /* Return the highest converted value */
  754. return value;
  755. }
  756. /**
  757. * @brief Returns the lowest value converted by the DFSDMx.
  758. * @param DFSDMx: specifies the filter to be selected :
  759. * This parameter can be one of the following values :
  760. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  761. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  762. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  763. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  764. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  765. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  766. * @retval The lowest converted value.
  767. * @note This function returns a signed value.
  768. */
  769. int32_t DFSDM_GetMinValue(DFSDM_Filter_TypeDef* DFSDMx)
  770. {
  771. int32_t value = 0;
  772. /* Check the parameters */
  773. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  774. value = ((DFSDMx -> FLTEXMIN) >> 8);
  775. /* Return the lowest conversion value */
  776. return value;
  777. }
  778. /**
  779. * @brief Returns the number of channel on which is captured the highest converted data by the DFSDMx.
  780. * @param DFSDMx: specifies the filter to be selected :
  781. * This parameter can be one of the following values :
  782. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  783. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  784. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  785. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  786. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  787. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  788. * @retval The highest converted value.
  789. */
  790. int32_t DFSDM_GetMaxValueChannel(DFSDM_Filter_TypeDef* DFSDMx)
  791. {
  792. /* Check the parameters */
  793. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  794. /* Return the highest converted value */
  795. return ((DFSDMx -> FLTEXMAX) & (~DFSDM_FLTEXMAX_EXMAXCH));
  796. }
  797. /**
  798. * @brief Returns the number of channel on which is captured the lowest converted data by the DFSDMx.
  799. * @param DFSDMx: specifies the filter to be selected :
  800. * This parameter can be one of the following values :
  801. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  802. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  803. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  804. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  805. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  806. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  807. * @retval The lowest converted value.
  808. */
  809. int32_t DFSDM_GetMinValueChannel(DFSDM_Filter_TypeDef* DFSDMx)
  810. {
  811. /* Check the parameters */
  812. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  813. /* Return the lowest converted value */
  814. return ((DFSDMx -> FLTEXMIN) & (~DFSDM_FLTEXMIN_EXMINCH));
  815. }
  816. /**
  817. * @brief Returns the conversion time (in 28-bit timer unit) for DFSDMx.
  818. * @param DFSDMx: specifies the filter to be selected :
  819. * This parameter can be one of the following values :
  820. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  821. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  822. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  823. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  824. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  825. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  826. * @retval Conversion time.
  827. */
  828. uint32_t DFSDM_GetConversionTime(DFSDM_Filter_TypeDef* DFSDMx)
  829. {
  830. /* Check the parameters */
  831. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  832. /* Return the lowest converted value */
  833. return ((DFSDMx -> FLTCNVTIMR >> 4) & 0x0FFFFFFF);
  834. }
  835. /**
  836. * @brief Configures Sinc Filter for the Analog watchdog by setting
  837. * the Sinc filter order and the Oversampling ratio for the specified DFSDM_Channelx.
  838. * @param DFSDM_Channelx: specifies the channel to be selected.
  839. * This parameter can be one of the following values :
  840. * @arg DFSDM1_Channel0 : DFSDM 1 Channel 0
  841. * @arg DFSDM1_Channel1 : DFSDM 1 Channel 1
  842. * @arg DFSDM1_Channel2 : DFSDM 1 Channel 2
  843. * @arg DFSDM1_Channel3 : DFSDM 1 Channel 3
  844. * @arg DFSDM2_Channel0 : DFSDM 2 Channel 0 (available only for STM32F413_423xx devices)
  845. * @arg DFSDM2_Channel1 : DFSDM 2 Channel 1 (available only for STM32F413_423xx devices)
  846. * @arg DFSDM2_Channel2 : DFSDM 2 Channel 2 (available only for STM32F413_423xx devices)
  847. * @arg DFSDM2_Channel3 : DFSDM 2 Channel 3 (available only for STM32F413_423xx devices)
  848. * @arg DFSDM2_Channel4 : DFSDM 2 Channel 4 (available only for STM32F413_423xx devices)
  849. * @arg DFSDM2_Channel5 : DFSDM 2 Channel 5 (available only for STM32F413_423xx devices)
  850. * @arg DFSDM2_Channel6 : DFSDM 2 Channel 6 (available only for STM32F413_423xx devices)
  851. * @arg DFSDM2_Channel7 : DFSDM 2 Channel 7 (available only for STM32F413_423xx devices)
  852. * @param DFSDM_AWDSincOrder: The Sinc Filter order this parameter can be a value of @ref DFSDM_AWD_Sinc_Order.
  853. * @param DFSDM_AWDSincOverSampleRatio: The Filter Oversampling ratio, this parameter can be a value between 1 and 32.
  854. * @retval None
  855. */
  856. void DFSDM_ConfigAWDFilter(DFSDM_Channel_TypeDef* DFSDM_Channelx, uint32_t DFSDM_AWDSincOrder, uint32_t DFSDM_AWDSincOverSampleRatio)
  857. {
  858. uint32_t tmpreg1 = 0;
  859. /* Check the parameters */
  860. assert_param(IS_DFSDM_ALL_CHANNEL(DFSDM_Channelx));
  861. assert_param(IS_DFSDM_AWD_SINC_ORDER(DFSDM_AWDSincOrder));
  862. assert_param(IS_DFSDM_AWD_OVRSMPL_RATIO(DFSDM_AWDSincOverSampleRatio));
  863. /* Get the DFSDM_Channelx CHAWSCDR value */
  864. tmpreg1 = DFSDM_Channelx -> CHAWSCDR;
  865. /* Clear the FORD and FOSR bits */
  866. tmpreg1 &= ~(DFSDM_CHAWSCDR_AWFORD | DFSDM_CHAWSCDR_AWFOSR);
  867. /* Set or Reset the SCDT bits */
  868. tmpreg1 |= (DFSDM_AWDSincOrder | ((DFSDM_AWDSincOverSampleRatio -1) << 16)) ;
  869. /* Write to DFSDM Channelx CHAWSCDR */
  870. DFSDM_Channelx -> CHAWSCDR = tmpreg1;
  871. }
  872. /**
  873. * @brief Returns the last Analog Watchdog Filter conversion result data for channelx.
  874. * @param DFSDM_Channelx: specifies the channel to be selected.
  875. * This parameter can be one of the following values :
  876. * @arg DFSDM1_Channel0 : DFSDM 1 Channel 0
  877. * @arg DFSDM1_Channel1 : DFSDM 1 Channel 1
  878. * @arg DFSDM1_Channel2 : DFSDM 1 Channel 2
  879. * @arg DFSDM1_Channel3 : DFSDM 1 Channel 3
  880. * @arg DFSDM2_Channel0 : DFSDM 2 Channel 0 (available only for STM32F413_423xx devices)
  881. * @arg DFSDM2_Channel1 : DFSDM 2 Channel 1 (available only for STM32F413_423xx devices)
  882. * @arg DFSDM2_Channel2 : DFSDM 2 Channel 2 (available only for STM32F413_423xx devices)
  883. * @arg DFSDM2_Channel3 : DFSDM 2 Channel 3 (available only for STM32F413_423xx devices)
  884. * @arg DFSDM2_Channel4 : DFSDM 2 Channel 4 (available only for STM32F413_423xx devices)
  885. * @arg DFSDM2_Channel5 : DFSDM 2 Channel 5 (available only for STM32F413_423xx devices)
  886. * @arg DFSDM2_Channel6 : DFSDM 2 Channel 6 (available only for STM32F413_423xx devices)
  887. * @arg DFSDM2_Channel7 : DFSDM 2 Channel 7 (available only for STM32F413_423xx devices)
  888. * @retval The Data conversion value.
  889. */
  890. uint32_t DFSDM_GetAWDConversionValue(DFSDM_Channel_TypeDef* DFSDM_Channelx)
  891. {
  892. /* Check the parameters */
  893. assert_param(IS_DFSDM_ALL_CHANNEL(DFSDM_Channelx));
  894. /* Return the last analog watchdog filter conversion value */
  895. return DFSDM_Channelx -> CHWDATAR;
  896. }
  897. /**
  898. * @brief Configures the High Threshold and the Low threshold for the Analog watchdog of the selected DFSDMx.
  899. * @param DFSDMx: specifies the filter to be selected :
  900. * This parameter can be one of the following values :
  901. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  902. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  903. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  904. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  905. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  906. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  907. * @param DFSDM_HighThreshold: High threshold value. This parameter can be value between 0 and 0xFFFFFF.
  908. * @param DFSDM_LowThreshold: Low threshold value. This parameter can be value between 0 and 0xFFFFFF.
  909. * @retval None.
  910. * @note In case of channels transceivers monitoring (Analog Watchdog fast mode Enabled)),
  911. * only the higher 16 bits define the 16-bit threshold compared with analog watchdog filter output.
  912. */
  913. void DFSDM_SetAWDThreshold(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_HighThreshold, uint32_t DFSDM_LowThreshold)
  914. {
  915. uint32_t tmpreg1 = 0;
  916. uint32_t tmpreg2 = 0;
  917. /* Check the parameters */
  918. assert_param(IS_DFSDM_HIGH_THRESHOLD(DFSDM_HighThreshold));
  919. assert_param(IS_DFSDM_LOW_THRESHOLD(DFSDM_LowThreshold));
  920. /* Get the DFSDMx AWHTR value */
  921. tmpreg1 = DFSDMx -> FLTAWHTR;
  922. /* Clear the AWHT bits */
  923. tmpreg1 &= ~(DFSDM_FLTAWHTR_AWHT);
  924. /* Set or Reset the AWHT bits */
  925. tmpreg1 |= (DFSDM_HighThreshold << 8 );
  926. /* Write to DFSDMx AWHTR Register */
  927. DFSDMx -> FLTAWHTR = tmpreg1;
  928. /* Get the DFSDMx AWLTR value */
  929. tmpreg2 = DFSDMx -> FLTAWLTR;
  930. /* Clear the AWLTR bits */
  931. tmpreg2 &= ~(DFSDM_FLTAWLTR_AWLT);
  932. /* Set or Reset the AWLTR bits */
  933. tmpreg2 |= (DFSDM_LowThreshold << 8 );
  934. /* Write to DFSDMx AWLTR Register */
  935. DFSDMx -> FLTAWLTR = tmpreg2;
  936. }
  937. /**
  938. * @brief Selects the injected channel for the selected DFSDMx.
  939. * @param DFSDMx: specifies the filter to be selected :
  940. * This parameter can be one of the following values :
  941. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  942. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  943. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  944. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  945. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  946. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  947. * @param DFSDM_InjectedChannelx: where x can be a value from 0 to 7 to select the Channel to be configuraed as
  948. * injected channel.
  949. * @retval None
  950. * @note User can select up to 8 channels.
  951. */
  952. void DFSDM_SelectInjectedChannel(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_InjectedChannelx)
  953. {
  954. uint32_t tmpreg1 = 0;
  955. /* Check the parameters */
  956. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  957. assert_param(IS_DFSDM_INJECT_CHANNEL(DFSDM_InjectedChannelx));
  958. /* Get the DFSDMx JCHGR value */
  959. tmpreg1 = DFSDMx -> FLTJCHGR;
  960. /* Clear the JCHGR bits */
  961. tmpreg1 &= ~(DFSDM_FLTJCHGR_JCHG);
  962. /* Set or Reset the JCHGR bits */
  963. tmpreg1 |= DFSDM_InjectedChannelx;
  964. /* Write to DFSDMx JCHGR Register */
  965. DFSDMx -> FLTJCHGR |= tmpreg1;
  966. }
  967. /**
  968. * @brief Selects the regular channel for the selected DFSDMx.
  969. * @param DFSDMx: specifies the filter to be selected :
  970. * This parameter can be one of the following values :
  971. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  972. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  973. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  974. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  975. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  976. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  977. * @param DFSDM_RegularChannelx: where x can be a value from 0 to 7 to select the Channel to be configurated as
  978. * regular channel.
  979. * @retval None
  980. * @note User can select only one channel.
  981. */
  982. void DFSDM_SelectRegularChannel(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_RegularChannelx)
  983. {
  984. uint32_t tmpreg1 = 0;
  985. /* Check the parameters */
  986. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  987. assert_param(IS_DFSDM_REGULAR_CHANNEL(DFSDM_RegularChannelx));
  988. /* Get the DFSDMx CR1 value */
  989. tmpreg1 = DFSDMx -> FLTCR1;
  990. /* Clear the RCH bits */
  991. tmpreg1 &= ~(DFSDM_FLTCR1_RCH);
  992. /* Set or Reset the RCH bits */
  993. tmpreg1 |= DFSDM_RegularChannelx;
  994. /* Write to DFSDMx CR1 Register */
  995. DFSDMx -> FLTCR1 = tmpreg1;
  996. }
  997. /**
  998. * @brief Starts a software start for the injected group of channels of the selected DFSDMx.
  999. * @param DFSDMx: specifies the filter to be selected :
  1000. * This parameter can be one of the following values :
  1001. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1002. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1003. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1004. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1005. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1006. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1007. * @retval None
  1008. */
  1009. void DFSDM_StartSoftwareInjectedConversion(DFSDM_Filter_TypeDef* DFSDMx)
  1010. {
  1011. /* Check the parameters */
  1012. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  1013. /* Write 1 to DFSDMx CR1 RSWSTAR bit */
  1014. DFSDMx -> FLTCR1 |= DFSDM_FLTCR1_JSWSTART;
  1015. }
  1016. /**
  1017. * @brief Starts a software start of the regular channel of the selected DFSDMx.
  1018. * @param DFSDMx: specifies the filter to be selected :
  1019. * This parameter can be one of the following values :
  1020. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1021. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1022. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1023. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1024. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1025. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1026. * @retval None
  1027. */
  1028. void DFSDM_StartSoftwareRegularConversion(DFSDM_Filter_TypeDef* DFSDMx)
  1029. {
  1030. /* Check the parameters */
  1031. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  1032. /* Write 1 to DFSDMx CR1 RSWSTAR bit */
  1033. DFSDMx -> FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
  1034. }
  1035. /**
  1036. * @brief Selects the Trigger signal to launch the injected conversions of the selected DFSDMx.
  1037. * @param DFSDMx: specifies the filter to be selected :
  1038. * This parameter can be one of the following values :
  1039. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1040. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1041. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1042. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1043. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1044. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1045. * @param DFSDM_InjectedTrigger: the trigger signal.
  1046. * This parameter can be a value of: @ref DFSDM_Injected_Trigger_signal
  1047. * @param DFSDM_TriggerEdge: the edge of the selected trigger
  1048. * This parameter can be a value of: @ref DFSDM_Trigger_Edge_selection
  1049. * @retval None.
  1050. * @note This function can be used only when the filter is disabled, use DFSDM_FilterCmd()
  1051. * to disable the filter.
  1052. */
  1053. void DFSDM_ConfigInjectedTrigger(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_Trigger, uint32_t DFSDM_TriggerEdge)
  1054. {
  1055. uint32_t tmpreg1 = 0;
  1056. /* Check the parameters */
  1057. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  1058. if (DFSDMx == DFSDM0)
  1059. {
  1060. assert_param(IS_DFSDM0_INJ_TRIGGER(DFSDM_Trigger));
  1061. }
  1062. else
  1063. {
  1064. assert_param(IS_DFSDM1_INJ_TRIGGER(DFSDM_Trigger));
  1065. }
  1066. assert_param(IS_DFSDM_TRIGGER_EDGE(DFSDM_TriggerEdge));
  1067. /* Get the DFSDMx CR1 value */
  1068. tmpreg1 = DFSDMx -> FLTCR1;
  1069. /* Clear the JEXTSEL & JEXTEN bits */
  1070. tmpreg1 &= ~(DFSDM_FLTCR1_JEXTSEL | DFSDM_FLTCR1_JEXTEN);
  1071. /* Set or Reset the JEXTSEL & JEXTEN bits */
  1072. tmpreg1 |= (DFSDM_Trigger | DFSDM_TriggerEdge);
  1073. /* Write to DFSDMx CR1 Register */
  1074. DFSDMx -> FLTCR1 = tmpreg1;
  1075. }
  1076. /**
  1077. * @brief Starts an injected conversion synchronously when in DFSDM0
  1078. * an injected conversion started by software.
  1079. * @param DFSDMx: specifies the filter to be selected :
  1080. * This parameter can be one of the following values :
  1081. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1082. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1083. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1084. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1085. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1086. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1087. * @retval None
  1088. * @note This function can be used only when the filter is disabled, use DFSDM_FilterCmd()
  1089. * to disable the filter.
  1090. */
  1091. void DFSDM_SynchronousFilter0InjectedStart(DFSDM_Filter_TypeDef* DFSDMx)
  1092. {
  1093. /* Check the parameters */
  1094. assert_param(IS_DFSDM_SYNC_FILTER(DFSDMx));
  1095. /* Write 1 to DFSDMx CR1 JSYNC bit */
  1096. DFSDMx -> FLTCR1 |= DFSDM_FLTCR1_JSYNC;
  1097. }
  1098. /**
  1099. * @brief Starts a regular conversion synchronously when in DFSDM0
  1100. * a regular conversion started by software.
  1101. * @param DFSDMx: specifies the filter to be selected :
  1102. * This parameter can be one of the following values :
  1103. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1104. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1105. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1106. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1107. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1108. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1109. * @retval None
  1110. * @note This function can be used only when the filter is disabled, use DFSDM_FilterCmd()
  1111. * to disable the filter.
  1112. */
  1113. void DFSDM_SynchronousFilter0RegularStart(DFSDM_Filter_TypeDef* DFSDMx)
  1114. {
  1115. /* Check the parameters */
  1116. assert_param(IS_DFSDM_SYNC_FILTER(DFSDMx));
  1117. /* Write 1 to DFSDMx CR1 RSYNC bit */
  1118. DFSDMx -> FLTCR1 |= DFSDM_FLTCR1_RSYNC;
  1119. }
  1120. /**
  1121. * @brief Enables or Disables the continue mode for Regular conversion for the selected filter DFSDMx.
  1122. * @param DFSDMx: specifies the filter to be selected :
  1123. * This parameter can be one of the following values :
  1124. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1125. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1126. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1127. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1128. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1129. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1130. * @param NewState: new state of the Continuous mode.
  1131. * This parameter can be: ENABLE or DISABLE.
  1132. * @retval None
  1133. */
  1134. void DFSDM_RegularContinuousModeCmd(DFSDM_Filter_TypeDef* DFSDMx, FunctionalState NewState)
  1135. {
  1136. /* Check the parameters */
  1137. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  1138. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1139. if (NewState != DISABLE)
  1140. {
  1141. /* Enable the RCONT bit */
  1142. DFSDMx -> FLTCR1 |= DFSDM_FLTCR1_RCONT;
  1143. }
  1144. else
  1145. {
  1146. /* Disable the RCONT bit */
  1147. DFSDMx -> FLTCR1 &= ~(DFSDM_FLTCR1_RCONT);
  1148. }
  1149. }
  1150. /**
  1151. * @brief Enables or Disables the Fast mode for the selected filter DFSDMx.
  1152. * @param DFSDMx: specifies the filter to be selected :
  1153. * This parameter can be one of the following values :
  1154. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1155. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1156. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1157. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1158. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1159. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1160. * @param NewState: new state of the Fast mode.
  1161. * This parameter can be: ENABLE or DISABLE.
  1162. * @retval None
  1163. * @note If just a single channel is selected in continuous mode (either by executing a regular
  1164. * conversion or by executing a injected conversion with only one channel selected),
  1165. * the sampling rate can be increased several times by enabling the fast mode.
  1166. * @note This function can be used only when the filter is disabled, use DFSDM_FilterCmd()
  1167. * to disable the filter.
  1168. */
  1169. void DFSDM_FastModeCmd(DFSDM_Filter_TypeDef* DFSDMx, FunctionalState NewState)
  1170. {
  1171. /* Check the parameters */
  1172. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  1173. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1174. if (NewState != DISABLE)
  1175. {
  1176. /* Enable the FAST bit */
  1177. DFSDMx -> FLTCR1 |= DFSDM_FLTCR1_FAST;
  1178. }
  1179. else
  1180. {
  1181. /* Disable the FAST bit */
  1182. DFSDMx -> FLTCR1 &= ~(DFSDM_FLTCR1_FAST);
  1183. }
  1184. }
  1185. /**
  1186. * @brief Selects the injected conversions mode for the selected DFSDMx.
  1187. * Injected conversions can operates in Single mode or Scan mode.
  1188. * @param DFSDMx: specifies the filter to be selected :
  1189. * This parameter can be one of the following values :
  1190. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1191. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1192. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1193. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1194. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1195. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1196. * @param DFSDM_InjectConvMode: The injected conversion mode, this parameter can be:
  1197. * @arg DFSDM_InjectConvMode_Single
  1198. * @arg DFSDM_InjectConvMode_Scan
  1199. * @retval None.
  1200. * @note This function can be used only when the filter is disabled, use DFSDM_FilterCmd()
  1201. * to disable the filter.
  1202. */
  1203. void DFSDM_SelectInjectedConversionMode(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_InjectConvMode)
  1204. {
  1205. /* Check the parameters */
  1206. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  1207. assert_param(IS_DFSDM_INJ_CONV_MODE(DFSDM_InjectConvMode));
  1208. /* Clear the JSCAN bit */
  1209. DFSDMx -> FLTCR1 &= ~(DFSDM_FLTCR1_JSCAN);
  1210. /* Write to DFSDMx CR1 Register */
  1211. DFSDMx -> FLTCR1 |= DFSDM_InjectConvMode;
  1212. }
  1213. /**
  1214. * @brief Enables or Disables the DMA to read data for the injected channel group of the selected filter DFSDMx.
  1215. * @param DFSDMx: specifies the filter to be selected :
  1216. * This parameter can be one of the following values :
  1217. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1218. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1219. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1220. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1221. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1222. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1223. * @param DFSDM_DMAConversionMode: Selects the mode to be configured for DMA read .
  1224. * @arg DFSDM_DMAConversionMode_Regular: DMA channel Enabled/Disabled to read data for the regular conversion
  1225. * @arg DFSDM_DMAConversionMode_Injected: DMA channel Enabled/Disabled to read data for the Injected conversion
  1226. * @param NewState: new state of the DMA channel.
  1227. * This parameter can be: ENABLE or DISABLE.
  1228. * @retval None.
  1229. * @note This function can be used only when the filter is disabled, use DFSDM_FilterCmd()
  1230. * to disable the filter.
  1231. */
  1232. void DFSDM_DMATransferConfig(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_DMAConversionMode, FunctionalState NewState)
  1233. {
  1234. /* Check the parameters */
  1235. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  1236. assert_param(IS_DFSDM_CONVERSION_MODE(DFSDM_DMAConversionMode));
  1237. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1238. if (NewState != DISABLE)
  1239. {
  1240. /* Enable the JDMAEN or RDMAEN bit */
  1241. DFSDMx -> FLTCR1 |= (DFSDM_FLTCR1_JDMAEN << DFSDM_DMAConversionMode) ;
  1242. }
  1243. else
  1244. {
  1245. /* Disable the JDMAEN or RDMAEN bit */
  1246. DFSDMx -> FLTCR1 &= ~(DFSDM_FLTCR1_JDMAEN << DFSDM_DMAConversionMode);
  1247. }
  1248. }
  1249. /** @defgroup DFSDM_Group3 Interrupts and flags management functions
  1250. * @brief Interrupts and flags management functions
  1251. *
  1252. @verbatim
  1253. ===============================================================================
  1254. Interrupts and flags management functions
  1255. ===============================================================================
  1256. This section provides functions allowing to configure the DFSDM Interrupts, get
  1257. the status and clear flags bits.
  1258. The LPT provides 7 Flags and Interrupts sources (2 flags and Interrupt sources
  1259. are available only on LPT peripherals equipped with encoder mode interface)
  1260. Flags and Interrupts sources:
  1261. =============================
  1262. 1. End of injected conversion.
  1263. 2. End of regular conversion.
  1264. 3. Injected data overrun.
  1265. 4. Regular data overrun.
  1266. 5. Analog watchdog.
  1267. 6. Short circuit detector.
  1268. 7. Channel clock absence
  1269. - To enable a specific interrupt source, use "DFSDM_ITConfig",
  1270. "DFSDM_ITClockAbsenceCmd" and "DFSDM_ITShortCircuitDetectorCmd" functions.
  1271. - To check if an interrupt was occurred, call "DFSDM_GetITStatus","DFSDM_GetClockAbsenceITStatusfunction"
  1272. and "DFSDM_GetGetShortCircuitITStatus" functions and read returned values.
  1273. - To get a flag status, call the "DFSDM_GetFlagStatus" ,"DFSDM_GetClockAbsenceFlagStatus" ,"DFSDM_GetShortCircuitFlagStatus"
  1274. and "DFSDM_GetWatchdogFlagStatus" functions and read the returned value.
  1275. - To clear a flag or an interrupt, use DFSDM_ClearFlag,DFSDM_ClearClockAbsenceFlag,
  1276. DFSDM_ClearShortCircuitFlag,DFSDM_ClearAnalogWatchdogFlag functions with the
  1277. corresponding flag (interrupt).
  1278. @endverbatim
  1279. * @{
  1280. */
  1281. /**
  1282. * @brief Enables or disables the specified DFSDMx interrupts.
  1283. * @param DFSDMx: specifies the filter to be selected :
  1284. * This parameter can be one of the following values :
  1285. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1286. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1287. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1288. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1289. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1290. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1291. * @param DFSDM_IT: specifies the DFSDM interrupts sources to be enabled or disabled.
  1292. * This parameter can be any combination of the following values:
  1293. * @arg DFSDM_IT_JEOC: End of injected conversion Interrupt source
  1294. * @arg DFSDM_IT_REOC: End of regular conversion Interrupt source
  1295. * @arg DFSDM_IT_JOVR: Injected data overrun Interrupt source
  1296. * @arg DFSDM_IT_ROVR: Regular data overrun Interrupt source
  1297. * @arg DFSDM_IT_AWD : Analog watchdog Interrupt source
  1298. * @param NewState: new state of the DFSDM interrupts.
  1299. * This parameter can be: ENABLE or DISABLE.
  1300. * @retval None
  1301. */
  1302. void DFSDM_ITConfig(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_IT, FunctionalState NewState)
  1303. {
  1304. /* Check the parameters */
  1305. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  1306. assert_param(IS_DFSDM_IT(DFSDM_IT));
  1307. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1308. if (NewState != DISABLE)
  1309. {
  1310. /* Enable the Interrupt sources */
  1311. DFSDMx->FLTCR2 |= DFSDM_IT;
  1312. }
  1313. else
  1314. {
  1315. /* Disable the Interrupt sources */
  1316. DFSDMx->FLTCR2 &= ~(DFSDM_IT);
  1317. }
  1318. }
  1319. #if defined(STM32F412xG)
  1320. /**
  1321. * @brief Enables or disables the Clock Absence Interrupt.
  1322. * @param NewState: new state of the interrupt.
  1323. * This parameter can be: ENABLE or DISABLE.
  1324. * @retval None
  1325. */
  1326. void DFSDM_ITClockAbsenceCmd(FunctionalState NewState)
  1327. {
  1328. /* Check the parameters */
  1329. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1330. if (NewState != DISABLE)
  1331. {
  1332. /* Enable the Interrupt source */
  1333. DFSDM1_0->FLTCR2 |= DFSDM_IT_CKAB;
  1334. }
  1335. else
  1336. {
  1337. /* Disable the Interrupt source */
  1338. DFSDM1_0->FLTCR2 &= ~(DFSDM_IT_CKAB);
  1339. }
  1340. }
  1341. /**
  1342. * @brief Enables or disables the Short Circuit Detector Interrupt.
  1343. * @param NewState: new state of the interrupt.
  1344. * This parameter can be: ENABLE or DISABLE.
  1345. * @retval None
  1346. */
  1347. void DFSDM_ITShortCircuitDetectorCmd(FunctionalState NewState)
  1348. {
  1349. /* Check the parameters */
  1350. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1351. if (NewState != DISABLE)
  1352. {
  1353. /* Enable the Interrupt source */
  1354. DFSDM1_0->FLTCR2 |= DFSDM_IT_SCD;
  1355. }
  1356. else
  1357. {
  1358. /* Disable the Interrupt source */
  1359. DFSDM1_0->FLTCR2 &= ~(DFSDM_IT_SCD);
  1360. }
  1361. }
  1362. #endif /* STM32F412xG */
  1363. #if defined(STM32F413_423xx)
  1364. /**
  1365. * @brief Enables or disables the Clock Absence Interrupt.
  1366. * @param Instance: select the instance of DFSDM
  1367. * This parameter can be: 1 or 2.
  1368. * @param NewState: new state of the interrupt.
  1369. * This parameter can be: ENABLE or DISABLE.
  1370. * @retval None
  1371. */
  1372. void DFSDM_ITClockAbsenceCmd(uint32_t Instance, FunctionalState NewState)
  1373. {
  1374. /* Check the parameters */
  1375. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1376. if(Instance == 1)
  1377. {
  1378. if (NewState != DISABLE)
  1379. {
  1380. /* Enable the Interrupt source */
  1381. DFSDM1_0->FLTCR2 |= DFSDM_IT_CKAB;
  1382. }
  1383. else
  1384. {
  1385. /* Disable the Interrupt source */
  1386. DFSDM1_0->FLTCR2 &= ~(DFSDM_IT_CKAB);
  1387. }
  1388. }
  1389. else /* DFSDM2 */
  1390. {
  1391. if (NewState != DISABLE)
  1392. {
  1393. /* Enable the Interrupt source */
  1394. DFSDM2_0->FLTCR2 |= DFSDM_IT_CKAB;
  1395. }
  1396. else
  1397. {
  1398. /* Disable the Interrupt source */
  1399. DFSDM2_0->FLTCR2 &= ~(DFSDM_IT_CKAB);
  1400. }
  1401. }
  1402. }
  1403. /**
  1404. * @brief Enables or disables the Short Circuit Detector Interrupt.
  1405. * @param Instance: select the instance of DFSDM
  1406. * This parameter can be: 1 or 2.
  1407. * @param NewState: new state of the interrupt.
  1408. * This parameter can be: ENABLE or DISABLE.
  1409. * @retval None
  1410. */
  1411. void DFSDM_ITShortCircuitDetectorCmd(uint32_t Instance, FunctionalState NewState)
  1412. {
  1413. /* Check the parameters */
  1414. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1415. if(Instance == 1)
  1416. {
  1417. if (NewState != DISABLE)
  1418. {
  1419. /* Enable the Interrupt source */
  1420. DFSDM1_0->FLTCR2 |= DFSDM_IT_SCD;
  1421. }
  1422. else
  1423. {
  1424. /* Disable the Interrupt source */
  1425. DFSDM1_0->FLTCR2 &= ~(DFSDM_IT_SCD);
  1426. }
  1427. }
  1428. else /* DFSDM2 */
  1429. {
  1430. if (NewState != DISABLE)
  1431. {
  1432. /* Enable the Interrupt source */
  1433. DFSDM2_0->FLTCR2 |= DFSDM_IT_SCD;
  1434. }
  1435. else
  1436. {
  1437. /* Disable the Interrupt source */
  1438. DFSDM2_0->FLTCR2 &= ~(DFSDM_IT_SCD);
  1439. }
  1440. }
  1441. }
  1442. #endif /* STM32F413_423xx */
  1443. /**
  1444. * @brief Checks whether the specified DFSDM flag is set or not.
  1445. * @param DFSDMx: specifies the filter to be selected :
  1446. * This parameter can be one of the following values :
  1447. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1448. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1449. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1450. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1451. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1452. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1453. * @param LPT_FLAG: specifies the flag to check.
  1454. * This parameter can be any combination of the following values:
  1455. * @arg DFSDM_FLAG_JEOC: End of injected conversion Flag
  1456. * @arg DFSDM_FLAG_REOC: End of regular conversion Flag
  1457. * @arg DFSDM_FLAG_JOVR: Injected data overrun Flag
  1458. * @arg DFSDM_FLAG_ROVR: Regular data overrun Flag
  1459. * @arg DFSDM_FLAG_AWD: Analog watchdog Flag
  1460. * @arg DFSDM_FLAG_JCIP: Injected conversion in progress status
  1461. * @arg DFSDM_FLAG_RCIP: Regular conversion in progress status
  1462. * @retval None
  1463. */
  1464. FlagStatus DFSDM_GetFlagStatus(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_FLAG)
  1465. {
  1466. ITStatus bitstatus = RESET;
  1467. /* Check the parameters */
  1468. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  1469. assert_param(IS_DFSDM_FLAG(DFSDM_FLAG));
  1470. if ((DFSDMx->FLTISR & DFSDM_FLAG) != RESET )
  1471. {
  1472. bitstatus = SET;
  1473. }
  1474. else
  1475. {
  1476. bitstatus = RESET;
  1477. }
  1478. return bitstatus;
  1479. }
  1480. #if defined(STM32F412xG)
  1481. /**
  1482. * @brief Checks whether the specified Clock Absence Channel flag is set or not.
  1483. * @param DFSDM_FLAG_CLKAbsence: specifies the flag to check.
  1484. * This parameter can be a value of @ref DFSDM_Clock_Absence_Flag_Definition
  1485. * @retval None
  1486. */
  1487. FlagStatus DFSDM_GetClockAbsenceFlagStatus(uint32_t DFSDM_FLAG_CLKAbsence)
  1488. {
  1489. ITStatus bitstatus = RESET;
  1490. /* Check the parameters */
  1491. assert_param(IS_DFSDM_CLK_ABS_FLAG(DFSDM_FLAG_CLKAbsence));
  1492. if((DFSDM1_0->FLTISR & DFSDM_FLAG_CLKAbsence) != RESET)
  1493. {
  1494. bitstatus = SET;
  1495. }
  1496. else
  1497. {
  1498. bitstatus = RESET;
  1499. }
  1500. return bitstatus;
  1501. }
  1502. /**
  1503. * @brief Checks whether the specified Short Circuit Channel Detector flag is set or not.
  1504. * @param DFSDM_FLAG_SCD: specifies the flag to check.
  1505. * This parameter can be a value of @ref DFSDM_SCD_Flag_Definition
  1506. * @retval None
  1507. */
  1508. FlagStatus DFSDM_GetShortCircuitFlagStatus(uint32_t DFSDM_FLAG_SCD)
  1509. {
  1510. ITStatus bitstatus = RESET;
  1511. /* Check the parameters */
  1512. assert_param(IS_DFSDM_SCD_FLAG(DFSDM_FLAG_SCD));
  1513. if ((DFSDM1_0->FLTISR & DFSDM_FLAG_SCD) != RESET)
  1514. {
  1515. bitstatus = SET;
  1516. }
  1517. else
  1518. {
  1519. bitstatus = RESET;
  1520. }
  1521. return bitstatus;
  1522. }
  1523. #endif /* STM32F412xG */
  1524. #if defined(STM32F413_423xx)
  1525. /**
  1526. * @brief Checks whether the specified Clock Absence Channel flag is set or not.
  1527. * @param Instance: select the instance of DFSDM
  1528. * This parameter can be: 1 or 2.
  1529. * @param DFSDM_FLAG_CLKAbsence: specifies the flag to check.
  1530. * This parameter can be a value of @ref DFSDM_Clock_Absence_Flag_Definition
  1531. * @retval None
  1532. */
  1533. FlagStatus DFSDM_GetClockAbsenceFlagStatus(uint32_t Instance, uint32_t DFSDM_FLAG_CLKAbsence)
  1534. {
  1535. ITStatus bitstatus = RESET;
  1536. /* Check the parameters */
  1537. assert_param(IS_DFSDM_CLK_ABS_FLAG(DFSDM_FLAG_CLKAbsence));
  1538. if(Instance == 1)
  1539. {
  1540. if((DFSDM1_0->FLTISR & DFSDM_FLAG_CLKAbsence) != RESET)
  1541. {
  1542. bitstatus = SET;
  1543. }
  1544. else
  1545. {
  1546. bitstatus = RESET;
  1547. }
  1548. }
  1549. else /* DFSDM2 */
  1550. {
  1551. /* Check the parameters */
  1552. assert_param(IS_DFSDM_CLK_ABS_FLAG(DFSDM_FLAG_CLKAbsence));
  1553. if((DFSDM2_0->FLTISR & DFSDM_FLAG_CLKAbsence) != RESET)
  1554. {
  1555. bitstatus = SET;
  1556. }
  1557. else
  1558. {
  1559. bitstatus = RESET;
  1560. }
  1561. }
  1562. return bitstatus;
  1563. }
  1564. /**
  1565. * @brief Checks whether the specified Short Circuit Channel Detector flag is set or not.
  1566. * @param Instance: select the instance of DFSDM
  1567. * This parameter can be: 1 or 2.
  1568. * @param DFSDM_FLAG_SCD: specifies the flag to check.
  1569. * This parameter can be a value of @ref DFSDM_SCD_Flag_Definition
  1570. * @retval None
  1571. */
  1572. FlagStatus DFSDM_GetShortCircuitFlagStatus(uint32_t Instance, uint32_t DFSDM_FLAG_SCD)
  1573. {
  1574. ITStatus bitstatus = RESET;
  1575. /* Check the parameters */
  1576. assert_param(IS_DFSDM_SCD_FLAG(DFSDM_FLAG_SCD));
  1577. if(Instance == 1)
  1578. {
  1579. if ((DFSDM1_0->FLTISR & DFSDM_FLAG_SCD) != RESET)
  1580. {
  1581. bitstatus = SET;
  1582. }
  1583. else
  1584. {
  1585. bitstatus = RESET;
  1586. }
  1587. }
  1588. else /* DFSDM2 */
  1589. {
  1590. if ((DFSDM2_0->FLTISR & DFSDM_FLAG_SCD) != RESET)
  1591. {
  1592. bitstatus = SET;
  1593. }
  1594. else
  1595. {
  1596. bitstatus = RESET;
  1597. }
  1598. }
  1599. return bitstatus;
  1600. }
  1601. #endif /* STM32F413_423xx */
  1602. /**
  1603. * @brief Checks whether the specified Watchdog threshold flag is set or not.
  1604. * @param DFSDMx: specifies the filter to be selected :
  1605. * This parameter can be one of the following values :
  1606. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1607. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1608. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1609. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1610. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1611. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1612. * @param DFSDM_AWDChannelx: where x can be a value from 0 to 7 to select the DFSDM Channel.
  1613. * @param DFSDM_Threshold: specifies the Threshold.
  1614. * This parameter can be a value of @ref DFSDM_Threshold_Selection.
  1615. * @retval None
  1616. */
  1617. FlagStatus DFSDM_GetWatchdogFlagStatus(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_AWDChannelx, uint8_t DFSDM_Threshold)
  1618. {
  1619. ITStatus bitstatus = RESET;
  1620. /* Check the parameters */
  1621. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  1622. assert_param(IS_DFSDM_Threshold(DFSDM_Threshold));
  1623. assert_param(IS_DFSDM_AWD_CHANNEL(DFSDM_AWDChannelx));
  1624. if ((DFSDMx->FLTAWSR & ((DFSDM_AWDChannelx >> 16) << DFSDM_Threshold) ) != RESET)
  1625. {
  1626. bitstatus = SET;
  1627. }
  1628. else
  1629. {
  1630. bitstatus = RESET;
  1631. }
  1632. return bitstatus;
  1633. }
  1634. /**
  1635. * @brief Clears the DFSDMx's pending flag.
  1636. * @param DFSDMx: specifies the filter to be selected :
  1637. * This parameter can be one of the following values :
  1638. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1639. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1640. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1641. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1642. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1643. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1644. * @param DFSDM_CLEARF: specifies the pending bit to clear.
  1645. * This parameter can be any combination of the following values:
  1646. * @arg DFSDM_CLEARF_JOVR: Injected data overrun Clear Flag
  1647. * @arg DFSDM_CLEARF_ROVR: Regular data overrun Clear Flag
  1648. * @retval None
  1649. */
  1650. void DFSDM_ClearFlag(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_CLEARF)
  1651. {
  1652. /* Check the parameters */
  1653. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  1654. assert_param(IS_DFSDM_CLEAR_FLAG(DFSDM_CLEARF));
  1655. /* Clear the pending Flag Bit */
  1656. DFSDMx->FLTICR |= DFSDM_CLEARF;
  1657. }
  1658. #if defined(STM32F412xG)
  1659. /**
  1660. * @brief Clears the DFSDMx's pending Clock Absence Channel flag.
  1661. * @param DFSDM_CLEARF_CLKAbsence: specifies the pending bit to clear.
  1662. * This parameter can be any combination of @ref DFSDM_Clear_ClockAbs_Flag_Definition
  1663. * @retval None
  1664. */
  1665. void DFSDM_ClearClockAbsenceFlag(uint32_t DFSDM_CLEARF_CLKAbsence)
  1666. {
  1667. /* Check the parameters */
  1668. assert_param(IS_DFSDM_CLK_ABS_CLEARF(DFSDM_CLEARF_CLKAbsence));
  1669. /* Clear the IT pending Flag Bit */
  1670. DFSDM1_0->FLTICR |= DFSDM_CLEARF_CLKAbsence;
  1671. }
  1672. /**
  1673. * @brief Clears the DFSDMx's pending Short circuit Channel flag.
  1674. * @param DFSDM_CLEARF_SCD: specifies the pending bit to clear.
  1675. * This parameter can be any combination of @ref DFSDM_Clear_Short_Circuit_Flag_Definition
  1676. * @retval None
  1677. */
  1678. void DFSDM_ClearShortCircuitFlag(uint32_t DFSDM_CLEARF_SCD)
  1679. {
  1680. /* Check the parameters */
  1681. assert_param(IS_DFSDM_SCD_CHANNEL_FLAG(DFSDM_CLEARF_SCD));
  1682. /* Clear the pending Flag Bit */
  1683. DFSDM1_0->FLTICR |= DFSDM_CLEARF_SCD;
  1684. }
  1685. #endif /* STM32F412xG */
  1686. #if defined(STM32F413_423xx)
  1687. /**
  1688. * @brief Clears the DFSDMx's pending Clock Absence Channel flag.
  1689. * @param Instance: select the instance of DFSDM
  1690. * This parameter can be: 1 or 2.
  1691. * @param DFSDM_CLEARF_CLKAbsence: specifies the pending bit to clear.
  1692. * This parameter can be any combination of @ref DFSDM_Clear_ClockAbs_Flag_Definition
  1693. * @retval None
  1694. */
  1695. void DFSDM_ClearClockAbsenceFlag(uint32_t Instance, uint32_t DFSDM_CLEARF_CLKAbsence)
  1696. {
  1697. /* Check the parameters */
  1698. assert_param(IS_DFSDM_CLK_ABS_CLEARF(DFSDM_CLEARF_CLKAbsence));
  1699. if(Instance == 1)
  1700. {
  1701. /* Clear the IT pending Flag Bit */
  1702. DFSDM1_0->FLTICR |= DFSDM_CLEARF_CLKAbsence;
  1703. }
  1704. else /* DFSDM2 */
  1705. {
  1706. /* Clear the IT pending Flag Bit */
  1707. DFSDM2_0->FLTICR |= DFSDM_CLEARF_CLKAbsence;
  1708. }
  1709. }
  1710. /**
  1711. * @brief Clears the DFSDMx's pending Short circuit Channel flag.
  1712. * @param Instance: select the instance of DFSDM
  1713. * This parameter can be: 1 or 2.
  1714. * @param DFSDM_CLEARF_SCD: specifies the pending bit to clear.
  1715. * This parameter can be any combination of @ref DFSDM_Clear_Short_Circuit_Flag_Definition
  1716. * @retval None
  1717. */
  1718. void DFSDM_ClearShortCircuitFlag(uint32_t Instance, uint32_t DFSDM_CLEARF_SCD)
  1719. {
  1720. /* Check the parameters */
  1721. assert_param(IS_DFSDM_SCD_CHANNEL_FLAG(DFSDM_CLEARF_SCD));
  1722. if(Instance == 1)
  1723. {
  1724. /* Clear the pending Flag Bit */
  1725. DFSDM1_0->FLTICR |= DFSDM_CLEARF_SCD;
  1726. }
  1727. else
  1728. {
  1729. /* Clear the pending Flag Bit */
  1730. DFSDM2_0->FLTICR |= DFSDM_CLEARF_SCD;
  1731. }
  1732. }
  1733. #endif /* STM32F413_423xx */
  1734. /**
  1735. * @brief Clears the DFSDMx's pending Analog watchdog Channel flag.
  1736. * @param DFSDMx: specifies the filter to be selected :
  1737. * This parameter can be one of the following values :
  1738. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1739. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1740. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1741. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1742. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1743. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1744. * @param DFSDM_AWDChannelx: where x can be a value from 0 to 7 to select the DFSDM Channel.
  1745. * @param DFSDM_Threshold: specifies the Threshold.
  1746. * This parameter can be a value of @ref DFSDM_Threshold_Selection.
  1747. * @retval None
  1748. */
  1749. void DFSDM_ClearAnalogWatchdogFlag(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_AWDChannelx, uint8_t DFSDM_Threshold)
  1750. {
  1751. /* Check the parameters */
  1752. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  1753. assert_param(IS_DFSDM_Threshold(DFSDM_Threshold));
  1754. assert_param(IS_DFSDM_AWD_CHANNEL(DFSDM_AWDChannelx));
  1755. if ((DFSDMx->FLTAWSR & ((DFSDM_AWDChannelx >> 16) << DFSDM_Threshold) ) != RESET)
  1756. {
  1757. /* Clear the pending Flag Bit */
  1758. DFSDMx->FLTAWCFR |= (DFSDM_AWDChannelx >> 16) << DFSDM_Threshold;
  1759. }
  1760. }
  1761. /**
  1762. * @brief Check whether the specified DFSDM interrupt has occurred or not.
  1763. * @param DFSDMx: specifies the filter to be selected :
  1764. * This parameter can be one of the following values :
  1765. * @arg DFSDM1_0 : DFSDM 1 Filter 0
  1766. * @arg DFSDM1_1 : DFSDM 1 Filter 1
  1767. * @arg DFSDM2_0 : DFSDM 2 Filter 0 (available only for STM32F413_423xx devices)
  1768. * @arg DFSDM2_1 : DFSDM 2 Filter 1 (available only for STM32F413_423xx devices)
  1769. * @arg DFSDM2_2 : DFSDM 2 Filter 2 (available only for STM32F413_423xx devices)
  1770. * @arg DFSDM2_3 : DFSDM 2 Filter 3 (available only for STM32F413_423xx devices)
  1771. * @param DFSDM_IT: specifies the DFSDM interrupt source to check.
  1772. * @arg DFSDM_IT_JEOC: End of injected conversion Interrupt source
  1773. * @arg DFSDM_IT_REOC: End of regular conversion Interrupt source
  1774. * @arg DFSDM_IT_JOVR: Injected data overrun Interrupt source
  1775. * @arg DFSDM_IT_ROVR: Regular data overrun Interrupt source
  1776. * @arg DFSDM_IT_AWD : Analog watchdog Interrupt source
  1777. * @retval The new state of DFSDM_IT (SET or RESET).
  1778. */
  1779. ITStatus DFSDM_GetITStatus(DFSDM_Filter_TypeDef* DFSDMx, uint32_t DFSDM_IT)
  1780. {
  1781. ITStatus bitstatus = RESET;
  1782. uint32_t itstatus = 0x0, itenable = 0x0;
  1783. /* Check the parameters */
  1784. assert_param(IS_DFSDM_ALL_FILTER(DFSDMx));
  1785. assert_param(IS_DFSDM_IT(DFSDM_IT));
  1786. /* Get the Interrupt Status bit value */
  1787. itstatus = DFSDMx->FLTISR & DFSDM_IT;
  1788. /* Check if the Interrupt is enabled */
  1789. itenable = DFSDMx->FLTCR2 & DFSDM_IT;
  1790. if ((itstatus != RESET) && (itenable != RESET))
  1791. {
  1792. bitstatus = SET;
  1793. }
  1794. else
  1795. {
  1796. bitstatus = RESET;
  1797. }
  1798. return bitstatus;
  1799. }
  1800. #if defined(STM32F412xG)
  1801. /**
  1802. * @brief Check whether the specified Clock Absence channel interrupt has occurred or not.
  1803. * @param DFSDM_IT_CLKAbsence: specifies on which channel check the interrupt source.
  1804. * This parameter can be a value of @ref DFSDM_Clock_Absence_Interrupt_Definition.
  1805. * @retval The new state of DFSDM_IT (SET or RESET).
  1806. * @note Clock absence interrupt is handled only by DFSDM0.
  1807. */
  1808. ITStatus DFSDM_GetClockAbsenceITStatus(uint32_t DFSDM_IT_CLKAbsence)
  1809. {
  1810. ITStatus bitstatus = RESET;
  1811. uint32_t itstatus = 0x0, itenable = 0x0;
  1812. /* Check the parameters */
  1813. assert_param(IS_DFSDM_CLK_ABS_IT(DFSDM_IT_CLKAbsence));
  1814. /* Get the Interrupt Status bit value */
  1815. itstatus = DFSDM0->FLTISR & DFSDM_IT_CLKAbsence;
  1816. /* Check if the Interrupt is enabled */
  1817. itenable = DFSDM0->FLTCR2 & DFSDM_IT_CKAB;
  1818. if ((itstatus != RESET) && (itenable != RESET))
  1819. {
  1820. bitstatus = SET;
  1821. }
  1822. else
  1823. {
  1824. bitstatus = RESET;
  1825. }
  1826. return bitstatus;
  1827. }
  1828. /**
  1829. * @brief Check whether the specified Short Circuit channel interrupt has occurred or not.
  1830. * @param DFSDM_IT_SCR: specifies on which channel check the interrupt source.
  1831. * This parameter can be a value of @ref DFSDM_SCD_Interrupt_Definition.
  1832. * @retval The new state of DFSDM_IT (SET or RESET).
  1833. * @note Short circuit interrupt is handled only by DFSDM0.
  1834. */
  1835. ITStatus DFSDM_GetShortCircuitITStatus(uint32_t DFSDM_IT_SCR)
  1836. {
  1837. ITStatus bitstatus = RESET;
  1838. uint32_t itstatus = 0x0, itenable = 0x0;
  1839. /* Check the parameters */
  1840. assert_param(IS_DFSDM_SCD_IT(DFSDM_IT_SCR));
  1841. /* Get the Interrupt Status bit value */
  1842. itstatus = DFSDM0->FLTISR & DFSDM_IT_SCR;
  1843. /* Check if the Interrupt is enabled */
  1844. itenable = DFSDM0->FLTCR2 & DFSDM_IT_SCD;
  1845. if ((itstatus != RESET) && (itenable != RESET))
  1846. {
  1847. bitstatus = SET;
  1848. }
  1849. else
  1850. {
  1851. bitstatus = RESET;
  1852. }
  1853. return bitstatus;
  1854. }
  1855. #endif /* STM32F412xG */
  1856. #if defined(STM32F413_423xx)
  1857. /**
  1858. * @brief Check whether the specified Clock Absence channel interrupt has occurred or not.
  1859. * @param Instance: select the instance of DFSDM
  1860. * This parameter can be: 1 or 2.
  1861. * @param DFSDM_IT_CLKAbsence: specifies on which channel check the interrupt source.
  1862. * This parameter can be a value of @ref DFSDM_Clock_Absence_Interrupt_Definition.
  1863. * @retval The new state of DFSDM_IT (SET or RESET).
  1864. * @note Clock absence interrupt is handled only by DFSDM0.
  1865. */
  1866. ITStatus DFSDM_GetClockAbsenceITStatus(uint32_t Instance, uint32_t DFSDM_IT_CLKAbsence)
  1867. {
  1868. ITStatus bitstatus = RESET;
  1869. uint32_t itstatus = 0x0, itenable = 0x0;
  1870. /* Check the parameters */
  1871. assert_param(IS_DFSDM_CLK_ABS_IT(DFSDM_IT_CLKAbsence));
  1872. if(Instance == 1)
  1873. {
  1874. /* Get the Interrupt Status bit value */
  1875. itstatus = DFSDM1_0->FLTISR & DFSDM_IT_CLKAbsence;
  1876. /* Check if the Interrupt is enabled */
  1877. itenable = DFSDM1_0->FLTCR2 & DFSDM_IT_CKAB;
  1878. }
  1879. else
  1880. {
  1881. /* Get the Interrupt Status bit value */
  1882. itstatus = DFSDM2_0->FLTISR & DFSDM_IT_CLKAbsence;
  1883. /* Check if the Interrupt is enabled */
  1884. itenable = DFSDM1_0->FLTCR2 & DFSDM_IT_CKAB;
  1885. }
  1886. if ((itstatus != RESET) && (itenable != RESET))
  1887. {
  1888. bitstatus = SET;
  1889. }
  1890. else
  1891. {
  1892. bitstatus = RESET;
  1893. }
  1894. return bitstatus;
  1895. }
  1896. /**
  1897. * @brief Check whether the specified Short Circuit channel interrupt has occurred or not.
  1898. * @param Instance: select the instance of DFSDM
  1899. * This parameter can be: 1 or 2.
  1900. * @param DFSDM_IT_SCR: specifies on which channel check the interrupt source.
  1901. * This parameter can be a value of @ref DFSDM_SCD_Interrupt_Definition.
  1902. * @retval The new state of DFSDM_IT (SET or RESET).
  1903. * @note Short circuit interrupt is handled only by Filter 0.
  1904. */
  1905. ITStatus DFSDM_GetShortCircuitITStatus(uint32_t Instance, uint32_t DFSDM_IT_SCR)
  1906. {
  1907. ITStatus bitstatus = RESET;
  1908. uint32_t itstatus = 0x0, itenable = 0x0;
  1909. /* Check the parameters */
  1910. assert_param(IS_DFSDM_SCD_IT(DFSDM_IT_SCR));
  1911. if(Instance == 1)
  1912. {
  1913. /* Get the Interrupt Status bit value */
  1914. itstatus = DFSDM1_0->FLTISR & DFSDM_IT_SCR;
  1915. /* Check if the Interrupt is enabled */
  1916. itenable = DFSDM1_0->FLTCR2 & DFSDM_IT_SCD;
  1917. }
  1918. else /* DFSDM2 */
  1919. {
  1920. /* Get the Interrupt Status bit value */
  1921. itstatus = DFSDM2_0->FLTISR & DFSDM_IT_SCR;
  1922. /* Check if the Interrupt is enabled */
  1923. itenable = DFSDM2_0->FLTCR2 & DFSDM_IT_SCD;
  1924. }
  1925. if ((itstatus != RESET) && (itenable != RESET))
  1926. {
  1927. bitstatus = SET;
  1928. }
  1929. else
  1930. {
  1931. bitstatus = RESET;
  1932. }
  1933. return bitstatus;
  1934. }
  1935. #endif /* STM32F413_423xx */
  1936. /**
  1937. * @}
  1938. */
  1939. /**
  1940. * @}
  1941. */
  1942. #endif /* STM32F412xG || STM32F413_423xx */
  1943. /**
  1944. * @}
  1945. */
  1946. /**
  1947. * @}
  1948. */