stm32f4xx_hal_dfsdm.c 150 KB

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