stm32h7xx_hal_dfsdm.c 105 KB

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