stm32f4xx_hal_dfsdm.c 129 KB

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