stm32g0xx_ll_adc.h 284 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_ll_adc.h
  4. * @author MCD Application Team
  5. * @brief Header file of ADC LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2018 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32G0xx_LL_ADC_H
  20. #define STM32G0xx_LL_ADC_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32g0xx.h"
  26. /** @addtogroup STM32G0xx_LL_Driver
  27. * @{
  28. */
  29. #if defined (ADC1)
  30. /** @defgroup ADC_LL ADC
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private constants ---------------------------------------------------------*/
  36. /** @defgroup ADC_LL_Private_Constants ADC Private Constants
  37. * @{
  38. */
  39. /* Internal mask for ADC group regular sequencer: */
  40. /* To select into literal LL_ADC_REG_RANK_x the relevant bits for: */
  41. /* - sequencer rank bits position into the selected register */
  42. #define ADC_REG_RANK_ID_SQRX_MASK (ADC_CHANNEL_ID_NUMBER_MASK_POSBIT0)
  43. /* Definition of ADC group regular sequencer bits information to be inserted */
  44. /* into ADC group regular sequencer ranks literals definition. */
  45. #define ADC_REG_RANK_1_SQRX_BITOFFSET_POS ( 0UL) /* Equivalent to bitfield "ADC_CHSELR_SQ1" position in register */
  46. #define ADC_REG_RANK_2_SQRX_BITOFFSET_POS ( 4UL) /* Equivalent to bitfield "ADC_CHSELR_SQ2" position in register */
  47. #define ADC_REG_RANK_3_SQRX_BITOFFSET_POS ( 8UL) /* Equivalent to bitfield "ADC_CHSELR_SQ3" position in register */
  48. #define ADC_REG_RANK_4_SQRX_BITOFFSET_POS (12UL) /* Equivalent to bitfield "ADC_CHSELR_SQ4" position in register */
  49. #define ADC_REG_RANK_5_SQRX_BITOFFSET_POS (16UL) /* Equivalent to bitfield "ADC_CHSELR_SQ5" position in register */
  50. #define ADC_REG_RANK_6_SQRX_BITOFFSET_POS (20UL) /* Equivalent to bitfield "ADC_CHSELR_SQ6" position in register */
  51. #define ADC_REG_RANK_7_SQRX_BITOFFSET_POS (24UL) /* Equivalent to bitfield "ADC_CHSELR_SQ7" position in register */
  52. #define ADC_REG_RANK_8_SQRX_BITOFFSET_POS (28UL) /* Equivalent to bitfield "ADC_CHSELR_SQ8" position in register */
  53. /* Internal mask for ADC group regular trigger: */
  54. /* To select into literal LL_ADC_REG_TRIG_x the relevant bits for: */
  55. /* - regular trigger source */
  56. /* - regular trigger edge */
  57. #define ADC_REG_TRIG_EXT_EDGE_DEFAULT (ADC_CFGR1_EXTEN_0) /* Trigger edge set to rising edge (default setting for
  58. compatibility with some ADC on other STM32 series
  59. having this setting set by HW default value) */
  60. /* Mask containing trigger source masks for each of possible */
  61. /* trigger edge selection duplicated with shifts [0; 4; 8; 12] */
  62. /* corresponding to {SW start; ext trigger; ext trigger; ext trigger}. */
  63. #define ADC_REG_TRIG_SOURCE_MASK (((LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR1_EXTSEL) << (4U * 0UL)) | \
  64. ((ADC_CFGR1_EXTSEL) << (4U * 1UL)) | \
  65. ((ADC_CFGR1_EXTSEL) << (4U * 2UL)) | \
  66. ((ADC_CFGR1_EXTSEL) << (4U * 3UL)) )
  67. /* Mask containing trigger edge masks for each of possible */
  68. /* trigger edge selection duplicated with shifts [0; 4; 8; 12] */
  69. /* corresponding to {SW start; ext trigger; ext trigger; ext trigger}. */
  70. #define ADC_REG_TRIG_EDGE_MASK (((LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR1_EXTEN) << (4U * 0UL)) | \
  71. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 1UL)) | \
  72. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 2UL)) | \
  73. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 3UL)) )
  74. /* Definition of ADC group regular trigger bits information. */
  75. #define ADC_REG_TRIG_EXTSEL_BITOFFSET_POS ( 6UL) /* Equivalent to bitfield "ADC_CFGR1_EXTSEL" position in register */
  76. #define ADC_REG_TRIG_EXTEN_BITOFFSET_POS (10UL) /* Equivalent to bitfield "ADC_CFGR1_EXTEN" position in register */
  77. /* Internal mask for ADC channel: */
  78. /* To select into literal LL_ADC_CHANNEL_x the relevant bits for: */
  79. /* - channel identifier defined by number */
  80. /* - channel identifier defined by bitfield */
  81. /* - channel differentiation between external channels (connected to */
  82. /* GPIO pins) and internal channels (connected to internal paths) */
  83. #define ADC_CHANNEL_ID_NUMBER_MASK (ADC_CFGR1_AWD1CH)
  84. #define ADC_CHANNEL_ID_BITFIELD_MASK (ADC_CHSELR_CHSEL)
  85. #define ADC_CHANNEL_ID_NUMBER_MASK_SEQ (ADC_CHSELR_SQ1 << ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) /* Equivalent to
  86. ADC_CHANNEL_ID_NUMBER_MASK with reduced range: on this STM32 series, ADC group regular sequencer,
  87. if set to mode "fully configurable", can contain channels with a restricted channel number.
  88. Refer to function @ref LL_ADC_REG_SetSequencerConfigurable(). */
  89. #define ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS (26UL) /* Equivalent to bitfield "ADC_CHANNEL_ID_NUMBER_MASK"
  90. position in register */
  91. #define ADC_CHANNEL_ID_MASK (ADC_CHANNEL_ID_NUMBER_MASK | ADC_CHANNEL_ID_BITFIELD_MASK | \
  92. ADC_CHANNEL_ID_INTERNAL_CH_MASK)
  93. /* Equivalent mask of ADC_CHANNEL_NUMBER_MASK aligned on register LSB (bit 0) */
  94. #define ADC_CHANNEL_ID_NUMBER_MASK_POSBIT0 (0x0000001FUL) /* Equivalent to shift: (ADC_CHANNEL_NUMBER_MASK
  95. >> [Position of bitfield "ADC_CHANNEL_NUMBER_MASK" in register]) */
  96. /* Channel differentiation between external and internal channels */
  97. #define ADC_CHANNEL_ID_INTERNAL_CH (0x80000000UL) /* Marker of internal channel */
  98. #define ADC_CHANNEL_ID_INTERNAL_CH_MASK (ADC_CHANNEL_ID_INTERNAL_CH)
  99. /* Definition of channels ID number information to be inserted into */
  100. /* channels literals definition. */
  101. #define ADC_CHANNEL_0_NUMBER (0x00000000UL)
  102. #define ADC_CHANNEL_1_NUMBER (ADC_CFGR1_AWD1CH_0)
  103. #define ADC_CHANNEL_2_NUMBER (ADC_CFGR1_AWD1CH_1)
  104. #define ADC_CHANNEL_3_NUMBER (ADC_CFGR1_AWD1CH_1 | ADC_CFGR1_AWD1CH_0)
  105. #define ADC_CHANNEL_4_NUMBER (ADC_CFGR1_AWD1CH_2)
  106. #define ADC_CHANNEL_5_NUMBER (ADC_CFGR1_AWD1CH_2 | ADC_CFGR1_AWD1CH_0)
  107. #define ADC_CHANNEL_6_NUMBER (ADC_CFGR1_AWD1CH_2 | ADC_CFGR1_AWD1CH_1)
  108. #define ADC_CHANNEL_7_NUMBER (ADC_CFGR1_AWD1CH_2 | ADC_CFGR1_AWD1CH_1 | ADC_CFGR1_AWD1CH_0)
  109. #define ADC_CHANNEL_8_NUMBER (ADC_CFGR1_AWD1CH_3)
  110. #define ADC_CHANNEL_9_NUMBER (ADC_CFGR1_AWD1CH_3 | ADC_CFGR1_AWD1CH_0)
  111. #define ADC_CHANNEL_10_NUMBER (ADC_CFGR1_AWD1CH_3 | ADC_CFGR1_AWD1CH_1)
  112. #define ADC_CHANNEL_11_NUMBER (ADC_CFGR1_AWD1CH_3 | ADC_CFGR1_AWD1CH_1 | ADC_CFGR1_AWD1CH_0)
  113. #define ADC_CHANNEL_12_NUMBER (ADC_CFGR1_AWD1CH_3 | ADC_CFGR1_AWD1CH_2)
  114. #define ADC_CHANNEL_13_NUMBER (ADC_CFGR1_AWD1CH_3 | ADC_CFGR1_AWD1CH_2 | ADC_CFGR1_AWD1CH_0)
  115. #define ADC_CHANNEL_14_NUMBER (ADC_CFGR1_AWD1CH_3 | ADC_CFGR1_AWD1CH_2 | ADC_CFGR1_AWD1CH_1)
  116. #define ADC_CHANNEL_15_NUMBER (ADC_CFGR1_AWD1CH_3 | ADC_CFGR1_AWD1CH_2 | \
  117. ADC_CFGR1_AWD1CH_1 | ADC_CFGR1_AWD1CH_0)
  118. #define ADC_CHANNEL_16_NUMBER (ADC_CFGR1_AWD1CH_4)
  119. #define ADC_CHANNEL_17_NUMBER (ADC_CFGR1_AWD1CH_4 | ADC_CFGR1_AWD1CH_0)
  120. #define ADC_CHANNEL_18_NUMBER (ADC_CFGR1_AWD1CH_4 | ADC_CFGR1_AWD1CH_1)
  121. /* Definition of channels ID bitfield information to be inserted into */
  122. /* channels literals definition. */
  123. #define ADC_CHANNEL_0_BITFIELD (ADC_CHSELR_CHSEL0)
  124. #define ADC_CHANNEL_1_BITFIELD (ADC_CHSELR_CHSEL1)
  125. #define ADC_CHANNEL_2_BITFIELD (ADC_CHSELR_CHSEL2)
  126. #define ADC_CHANNEL_3_BITFIELD (ADC_CHSELR_CHSEL3)
  127. #define ADC_CHANNEL_4_BITFIELD (ADC_CHSELR_CHSEL4)
  128. #define ADC_CHANNEL_5_BITFIELD (ADC_CHSELR_CHSEL5)
  129. #define ADC_CHANNEL_6_BITFIELD (ADC_CHSELR_CHSEL6)
  130. #define ADC_CHANNEL_7_BITFIELD (ADC_CHSELR_CHSEL7)
  131. #define ADC_CHANNEL_8_BITFIELD (ADC_CHSELR_CHSEL8)
  132. #define ADC_CHANNEL_9_BITFIELD (ADC_CHSELR_CHSEL9)
  133. #define ADC_CHANNEL_10_BITFIELD (ADC_CHSELR_CHSEL10)
  134. #define ADC_CHANNEL_11_BITFIELD (ADC_CHSELR_CHSEL11)
  135. #define ADC_CHANNEL_12_BITFIELD (ADC_CHSELR_CHSEL12)
  136. #define ADC_CHANNEL_13_BITFIELD (ADC_CHSELR_CHSEL13)
  137. #define ADC_CHANNEL_14_BITFIELD (ADC_CHSELR_CHSEL14)
  138. #define ADC_CHANNEL_15_BITFIELD (ADC_CHSELR_CHSEL15)
  139. #define ADC_CHANNEL_16_BITFIELD (ADC_CHSELR_CHSEL16)
  140. #define ADC_CHANNEL_17_BITFIELD (ADC_CHSELR_CHSEL17)
  141. #define ADC_CHANNEL_18_BITFIELD (ADC_CHSELR_CHSEL18)
  142. /* Internal mask for ADC channel sampling time: */
  143. /* To select into literals LL_ADC_SAMPLINGTIME_x */
  144. /* the relevant bits for: */
  145. /* (concatenation of multiple bits used in register SMPR) */
  146. /* - ADC channels sampling time: setting channel wise, to map each channel */
  147. /* on one of the common sampling time available. */
  148. /* - ADC channels common sampling time: set a sampling time into one of the */
  149. /* common sampling time available. */
  150. #define ADC_SAMPLING_TIME_CH_MASK (ADC_CHANNEL_ID_BITFIELD_MASK << ADC_SMPR_SMPSEL0_BITOFFSET_POS)
  151. #define ADC_SAMPLING_TIME_SMP_MASK (ADC_SMPR_SMP2 | ADC_SMPR_SMP1)
  152. #define ADC_SAMPLING_TIME_SMP_SHIFT_MASK (ADC_SMPR_SMP2_BITOFFSET_POS | ADC_SMPR_SMP1_BITOFFSET_POS)
  153. /* Internal mask for ADC analog watchdog: */
  154. /* To select into literals LL_ADC_AWD_CHANNELx_xxx the relevant bits for: */
  155. /* (concatenation of multiple bits used in different analog watchdogs, */
  156. /* (feature of several watchdogs not available on all STM32 series)). */
  157. /* - analog watchdog 1: monitored channel defined by number, */
  158. /* selection of ADC group (ADC group regular). */
  159. /* - analog watchdog 2 and 3: monitored channel defined by bitfield, no */
  160. /* selection on groups. */
  161. /* Internal register offset for ADC analog watchdog channel configuration */
  162. #define ADC_AWD_CR1_REGOFFSET (0x00000000UL)
  163. #define ADC_AWD_CR2_REGOFFSET (0x00100000UL)
  164. #define ADC_AWD_CR3_REGOFFSET (0x00200000UL)
  165. /* Register offset gap between AWD1 and AWD2-AWD3 configuration registers */
  166. /* (Set separately as ADC_AWD_CRX_REGOFFSET to spare 32 bits space */
  167. #define ADC_AWD_CR12_REGOFFSETGAP_MASK (ADC_AWD2CR_AWD2CH_0)
  168. #define ADC_AWD_CR12_REGOFFSETGAP_VAL (0x00000024UL)
  169. #define ADC_AWD_CRX_REGOFFSET_MASK (ADC_AWD_CR1_REGOFFSET | ADC_AWD_CR2_REGOFFSET | ADC_AWD_CR3_REGOFFSET)
  170. #define ADC_AWD_CRX_REGOFFSET_BITOFFSET_POS (20UL)
  171. #define ADC_AWD_CR1_CHANNEL_MASK (ADC_CFGR1_AWD1CH | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL)
  172. #define ADC_AWD_CR23_CHANNEL_MASK (ADC_AWD2CR_AWD2CH)
  173. #define ADC_AWD_CR_ALL_CHANNEL_MASK (ADC_AWD_CR1_CHANNEL_MASK | ADC_AWD_CR23_CHANNEL_MASK)
  174. #define ADC_AWD_CRX_REGOFFSET_POS (20UL) /* Position of bits ADC_AWD_CRx_REGOFFSET
  175. in ADC_AWD_CRX_REGOFFSET_MASK */
  176. /* Internal register offset for ADC analog watchdog threshold configuration */
  177. #define ADC_AWD_TR1_REGOFFSET (ADC_AWD_CR1_REGOFFSET)
  178. #define ADC_AWD_TR2_REGOFFSET (ADC_AWD_CR2_REGOFFSET)
  179. #define ADC_AWD_TR3_REGOFFSET (ADC_AWD_CR3_REGOFFSET + (1UL << ADC_AWD_CRX_REGOFFSET_BITOFFSET_POS))
  180. #define ADC_AWD_TRX_REGOFFSET_MASK (ADC_AWD_TR1_REGOFFSET | ADC_AWD_TR2_REGOFFSET | ADC_AWD_TR3_REGOFFSET)
  181. #define ADC_AWD_TRX_REGOFFSET_POS (ADC_AWD_CRX_REGOFFSET_POS) /* Position of bits ADC_SQRx_REGOFFSET
  182. in ADC_AWD_TRX_REGOFFSET_MASK */
  183. #define ADC_AWD_TRX_BIT_HIGH_MASK (0x00010000UL) /* Selection of 1 bit to discriminate
  184. threshold high: mask of bit */
  185. #define ADC_AWD_TRX_BIT_HIGH_POS (16UL) /* Selection of 1 bit to discriminate
  186. threshold high: position of bit */
  187. #define ADC_AWD_TRX_BIT_HIGH_SHIFT4 (ADC_AWD_TRX_BIT_HIGH_POS - 4UL) /* Shift of bit ADC_AWD_TRX_BIT_HIGH to
  188. position to perform a shift of 4 ranks */
  189. #define ADC_AWD_TRX_REGOFFSET_BITOFFSET_POS (20UL)
  190. /* ADC registers bits positions */
  191. #define ADC_CFGR1_RES_BITOFFSET_POS ( 3UL) /* Equivalent to bitfield "ADC_CFGR1_RES" position in register */
  192. #define ADC_CFGR1_AWDSGL_BITOFFSET_POS (22UL) /* Equivalent to bitfield "ADC_CFGR1_AWDSGL" position in register */
  193. #define ADC_TR1_HT1_BITOFFSET_POS (16UL) /* Equivalent to bitfield "ADC_TR1_HT1" position in register */
  194. #define ADC_CHSELR_CHSEL0_BITOFFSET_POS ( 0UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL0" position in register */
  195. #define ADC_CHSELR_CHSEL1_BITOFFSET_POS ( 1UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL1" position in register */
  196. #define ADC_CHSELR_CHSEL2_BITOFFSET_POS ( 2UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL2" position in register */
  197. #define ADC_CHSELR_CHSEL3_BITOFFSET_POS ( 3UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL3" position in register */
  198. #define ADC_CHSELR_CHSEL4_BITOFFSET_POS ( 4UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL4" position in register */
  199. #define ADC_CHSELR_CHSEL5_BITOFFSET_POS ( 5UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL5" position in register */
  200. #define ADC_CHSELR_CHSEL6_BITOFFSET_POS ( 6UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL6" position in register */
  201. #define ADC_CHSELR_CHSEL7_BITOFFSET_POS ( 7UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL7" position in register */
  202. #define ADC_CHSELR_CHSEL8_BITOFFSET_POS ( 8UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL8" position in register */
  203. #define ADC_CHSELR_CHSEL9_BITOFFSET_POS ( 9UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL9" position in register */
  204. #define ADC_CHSELR_CHSEL10_BITOFFSET_POS (10UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL10" position in register */
  205. #define ADC_CHSELR_CHSEL11_BITOFFSET_POS (11UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL11" position in register */
  206. #define ADC_CHSELR_CHSEL12_BITOFFSET_POS (12UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL12" position in register */
  207. #define ADC_CHSELR_CHSEL13_BITOFFSET_POS (13UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL13" position in register */
  208. #define ADC_CHSELR_CHSEL14_BITOFFSET_POS (14UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL14" position in register */
  209. #define ADC_CHSELR_CHSEL15_BITOFFSET_POS (15UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL15" position in register */
  210. #define ADC_CHSELR_CHSEL16_BITOFFSET_POS (16UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL16" position in register */
  211. #define ADC_CHSELR_CHSEL17_BITOFFSET_POS (17UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL17" position in register */
  212. #define ADC_CHSELR_CHSEL18_BITOFFSET_POS (18UL) /* Equivalent to bitfield "ADC_CHSELR_CHSEL18" position in register */
  213. #define ADC_SMPR_SMP1_BITOFFSET_POS ( 0UL) /* Equivalent to bitfield "ADC_SMPR_SMP1" position in register */
  214. #define ADC_SMPR_SMP2_BITOFFSET_POS ( 4UL) /* Equivalent to bitfield "ADC_SMPR_SMP2" position in register */
  215. #define ADC_SMPR_SMPSEL0_BITOFFSET_POS ( 8UL) /* Equivalent to bitfield "ADC_SMPR_SMPSEL0" position in register */
  216. /* ADC registers bits groups */
  217. #define ADC_CR_BITS_PROPERTY_RS (ADC_CR_ADCAL | ADC_CR_ADEN | ADC_CR_ADDIS \
  218. | ADC_CR_ADSTART | ADC_CR_ADSTP) /* ADC register CR bits with
  219. HW property "rs": Software can read as well as set this bit.
  220. Writing '0' has no effect on the bit value. */
  221. /* ADC internal channels related definitions */
  222. /* Internal voltage reference VrefInt */
  223. #define VREFINT_CAL_ADDR ((uint16_t*) (0x1FFF75AAUL)) /* Internal voltage reference, address of
  224. parameter VREFINT_CAL: VrefInt ADC raw data acquired at temperature 30 DegC
  225. (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
  226. #define VREFINT_CAL_VREF ( 3000UL) /* Analog voltage reference (Vref+) value
  227. with which VrefInt has been calibrated in production
  228. (tolerance: +-10 mV) (unit: mV). */
  229. /* Temperature sensor */
  230. #define TEMPSENSOR_CAL1_ADDR ((uint16_t*) (0x1FFF75A8UL)) /* Address of parameter TS_CAL1: On STM32G0,
  231. temperature sensor ADC raw data acquired at temperature 30 DegC
  232. (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
  233. #define TEMPSENSOR_CAL2_ADDR ((uint16_t*) (0x1FFF75CAUL)) /* Address of parameter TS_CAL2: On STM32G0,
  234. temperature sensor ADC raw data acquired at temperature 130 DegC
  235. (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
  236. #define TEMPSENSOR_CAL1_TEMP (( int32_t) 30) /* Temperature at which temperature sensor
  237. has been calibrated in production for data into TEMPSENSOR_CAL1_ADDR
  238. (tolerance: +-5 DegC) (unit: DegC). */
  239. #define TEMPSENSOR_CAL2_TEMP (( int32_t) 130) /* Temperature at which temperature sensor
  240. has been calibrated in production for data into TEMPSENSOR_CAL2_ADDR
  241. (tolerance: +-5 DegC) (unit: DegC). */
  242. #define TEMPSENSOR_CAL_VREFANALOG ( 3000UL) /* Analog voltage reference (Vref+) value
  243. with which temperature sensor has been calibrated in production
  244. (tolerance: +-10 mV) (unit: mV). */
  245. /**
  246. * @}
  247. */
  248. /* Private macros ------------------------------------------------------------*/
  249. /** @defgroup ADC_LL_Private_Macros ADC Private Macros
  250. * @{
  251. */
  252. /**
  253. * @brief Driver macro reserved for internal use: set a pointer to
  254. * a register from a register basis from which an offset
  255. * is applied.
  256. * @param __REG__ Register basis from which the offset is applied.
  257. * @param __REG_OFFFSET__ Offset to be applied (unit: number of registers).
  258. * @retval Pointer to register address
  259. */
  260. #define __ADC_PTR_REG_OFFSET(__REG__, __REG_OFFFSET__) \
  261. ((__IO uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFFSET__) << 2UL))))
  262. /**
  263. * @}
  264. */
  265. /* Exported types ------------------------------------------------------------*/
  266. #if defined(USE_FULL_LL_DRIVER)
  267. /** @defgroup ADC_LL_ES_INIT ADC Exported Init structure
  268. * @{
  269. */
  270. /**
  271. * @brief Structure definition of some features of ADC common parameters
  272. * and multimode
  273. * (all ADC instances belonging to the same ADC common instance).
  274. * @note The setting of these parameters by function @ref LL_ADC_CommonInit()
  275. * is conditioned to ADC instances state (all ADC instances
  276. * sharing the same ADC common instance):
  277. * All ADC instances sharing the same ADC common instance must be
  278. * disabled.
  279. */
  280. typedef struct
  281. {
  282. uint32_t CommonClock; /*!< Set parameter common to several ADC: Clock source and prescaler.
  283. This parameter can be a value of @ref ADC_LL_EC_COMMON_CLOCK_SOURCE
  284. This feature can be modified afterwards using unitary function
  285. @ref LL_ADC_SetCommonClock(). */
  286. } LL_ADC_CommonInitTypeDef;
  287. /**
  288. * @brief Structure definition of some features of ADC instance.
  289. * @note These parameters have an impact on ADC scope: ADC instance.
  290. * Refer to corresponding unitary functions into
  291. * @ref ADC_LL_EF_Configuration_ADC_Instance .
  292. * @note The setting of these parameters by function @ref LL_ADC_Init()
  293. * is conditioned to ADC state:
  294. * ADC instance must be disabled.
  295. * This condition is applied to all ADC features, for efficiency
  296. * and compatibility over all STM32 series. However, the different
  297. * features can be set under different ADC state conditions
  298. * (setting possible with ADC enabled without conversion on going,
  299. * ADC enabled with conversion on going, ...)
  300. * Each feature can be updated afterwards with a unitary function
  301. * and potentially with ADC in a different state than disabled,
  302. * refer to description of each function for setting
  303. * conditioned to ADC state.
  304. */
  305. typedef struct
  306. {
  307. uint32_t Clock; /*!< Set ADC instance clock source and prescaler.
  308. This parameter can be a value of @ref ADC_LL_EC_CLOCK_SOURCE
  309. @note On this STM32 series, this parameter has some clock ratio constraints:
  310. ADC clock synchronous (from PCLK) with prescaler 1 must be enabled
  311. only if PCLK has a 50% duty clock cycle (APB prescaler configured
  312. inside the RCC must be bypassed and the system clock must by 50% duty
  313. cycle).
  314. This feature can be modified afterwards using unitary function
  315. @ref LL_ADC_SetClock().
  316. For more details, refer to description of this function. */
  317. uint32_t Resolution; /*!< Set ADC resolution.
  318. This parameter can be a value of @ref ADC_LL_EC_RESOLUTION
  319. This feature can be modified afterwards using unitary function
  320. @ref LL_ADC_SetResolution(). */
  321. uint32_t DataAlignment; /*!< Set ADC conversion data alignment.
  322. This parameter can be a value of @ref ADC_LL_EC_DATA_ALIGN
  323. This feature can be modified afterwards using unitary function
  324. @ref LL_ADC_SetDataAlignment(). */
  325. uint32_t LowPowerMode; /*!< Set ADC low power mode.
  326. This parameter can be a value of @ref ADC_LL_EC_LP_MODE
  327. This feature can be modified afterwards using unitary function
  328. @ref LL_ADC_SetLowPowerMode(). */
  329. } LL_ADC_InitTypeDef;
  330. /**
  331. * @brief Structure definition of some features of ADC group regular.
  332. * @note These parameters have an impact on ADC scope: ADC group regular.
  333. * Refer to corresponding unitary functions into
  334. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  335. * (functions with prefix "REG").
  336. * @note The setting of these parameters by function @ref LL_ADC_REG_Init()
  337. * is conditioned to ADC state:
  338. * ADC instance must be disabled.
  339. * This condition is applied to all ADC features, for efficiency
  340. * and compatibility over all STM32 series. However, the different
  341. * features can be set under different ADC state conditions
  342. * (setting possible with ADC enabled without conversion on going,
  343. * ADC enabled with conversion on going, ...)
  344. * Each feature can be updated afterwards with a unitary function
  345. * and potentially with ADC in a different state than disabled,
  346. * refer to description of each function for setting
  347. * conditioned to ADC state.
  348. */
  349. typedef struct
  350. {
  351. uint32_t TriggerSource; /*!< Set ADC group regular conversion trigger source: internal (SW start) or
  352. from external peripheral (timer event, external interrupt line).
  353. This parameter can be a value of @ref ADC_LL_EC_REG_TRIGGER_SOURCE
  354. @note On this STM32 series, setting trigger source to external trigger also
  355. set trigger polarity to rising edge(default setting for compatibility
  356. with some ADC on other STM32 series having this setting set by HW
  357. default value).
  358. In case of need to modify trigger edge, use function
  359. @ref LL_ADC_REG_SetTriggerEdge().
  360. This feature can be modified afterwards using unitary function
  361. @ref LL_ADC_REG_SetTriggerSource(). */
  362. uint32_t SequencerLength; /*!< Set ADC group regular sequencer length.
  363. @note This parameter has an effect only if group regular sequencer is set
  364. to mode "fully configurable". Refer to function
  365. @ref LL_ADC_REG_SetSequencerConfigurable().
  366. This parameter can be a value of @ref ADC_LL_EC_REG_SEQ_SCAN_LENGTH
  367. This feature can be modified afterwards using unitary function
  368. @ref LL_ADC_REG_SetSequencerLength(). */
  369. uint32_t SequencerDiscont; /*!< Set ADC group regular sequencer discontinuous mode: sequence subdivided
  370. and scan conversions interrupted every selected number of ranks.
  371. This parameter can be a value of @ref ADC_LL_EC_REG_SEQ_DISCONT_MODE
  372. @note This parameter has an effect only if group regular sequencer is
  373. enabled (depending on the sequencer mode: scan length of 2 ranks or
  374. more, or several ADC channels enabled in group regular sequencer.
  375. Refer to function @ref LL_ADC_REG_SetSequencerConfigurable() ).
  376. This feature can be modified afterwards using unitary function
  377. @ref LL_ADC_REG_SetSequencerDiscont(). */
  378. uint32_t ContinuousMode; /*!< Set ADC continuous conversion mode on ADC group regular, whether ADC
  379. conversions are performed in single mode (one conversion per trigger) or in
  380. continuous mode (after the first trigger, following conversions launched
  381. successively automatically).
  382. This parameter can be a value of @ref ADC_LL_EC_REG_CONTINUOUS_MODE
  383. Note: It is not possible to enable both ADC group regular continuous mode
  384. and discontinuous mode.
  385. This feature can be modified afterwards using unitary function
  386. @ref LL_ADC_REG_SetContinuousMode(). */
  387. uint32_t DMATransfer; /*!< Set ADC group regular conversion data transfer: no transfer or transfer
  388. by DMA, and DMA requests mode.
  389. This parameter can be a value of @ref ADC_LL_EC_REG_DMA_TRANSFER
  390. This feature can be modified afterwards using unitary function
  391. @ref LL_ADC_REG_SetDMATransfer(). */
  392. uint32_t Overrun; /*!< Set ADC group regular behavior in case of overrun:
  393. data preserved or overwritten.
  394. This parameter can be a value of @ref ADC_LL_EC_REG_OVR_DATA_BEHAVIOR
  395. This feature can be modified afterwards using unitary function
  396. @ref LL_ADC_REG_SetOverrun(). */
  397. } LL_ADC_REG_InitTypeDef;
  398. /**
  399. * @}
  400. */
  401. #endif /* USE_FULL_LL_DRIVER */
  402. /* Exported constants --------------------------------------------------------*/
  403. /** @defgroup ADC_LL_Exported_Constants ADC Exported Constants
  404. * @{
  405. */
  406. /** @defgroup ADC_LL_EC_FLAG ADC flags
  407. * @brief Flags defines which can be used with LL_ADC_ReadReg function
  408. * @{
  409. */
  410. #define LL_ADC_FLAG_ADRDY ADC_ISR_ADRDY /*!< ADC flag ADC instance ready */
  411. #define LL_ADC_FLAG_CCRDY ADC_ISR_CCRDY /*!< ADC flag ADC channel configuration ready */
  412. #define LL_ADC_FLAG_EOC ADC_ISR_EOC /*!< ADC flag ADC group regular end of unitary
  413. conversion */
  414. #define LL_ADC_FLAG_EOS ADC_ISR_EOS /*!< ADC flag ADC group regular end of sequence
  415. conversions */
  416. #define LL_ADC_FLAG_OVR ADC_ISR_OVR /*!< ADC flag ADC group regular overrun */
  417. #define LL_ADC_FLAG_EOSMP ADC_ISR_EOSMP /*!< ADC flag ADC group regular end of sampling phase */
  418. #define LL_ADC_FLAG_AWD1 ADC_ISR_AWD1 /*!< ADC flag ADC analog watchdog 1 */
  419. #define LL_ADC_FLAG_AWD2 ADC_ISR_AWD2 /*!< ADC flag ADC analog watchdog 2 */
  420. #define LL_ADC_FLAG_AWD3 ADC_ISR_AWD3 /*!< ADC flag ADC analog watchdog 3 */
  421. #define LL_ADC_FLAG_EOCAL ADC_ISR_EOCAL /*!< ADC flag end of calibration */
  422. /**
  423. * @}
  424. */
  425. /** @defgroup ADC_LL_EC_IT ADC interruptions for configuration (interruption enable or disable)
  426. * @brief IT defines which can be used with LL_ADC_ReadReg and LL_ADC_WriteReg functions
  427. * @{
  428. */
  429. #define LL_ADC_IT_ADRDY ADC_IER_ADRDYIE /*!< ADC interruption ADC instance ready */
  430. #define LL_ADC_IT_CCRDY ADC_IER_CCRDYIE /*!< ADC interruption channel configuration ready */
  431. #define LL_ADC_IT_EOC ADC_IER_EOCIE /*!< ADC interruption ADC group regular end of unitary
  432. conversion */
  433. #define LL_ADC_IT_EOS ADC_IER_EOSIE /*!< ADC interruption ADC group regular end of sequence
  434. conversions */
  435. #define LL_ADC_IT_OVR ADC_IER_OVRIE /*!< ADC interruption ADC group regular overrun */
  436. #define LL_ADC_IT_EOSMP ADC_IER_EOSMPIE /*!< ADC interruption ADC group regular end of sampling
  437. phase */
  438. #define LL_ADC_IT_AWD1 ADC_IER_AWD1IE /*!< ADC interruption ADC analog watchdog 1 */
  439. #define LL_ADC_IT_AWD2 ADC_IER_AWD2IE /*!< ADC interruption ADC analog watchdog 2 */
  440. #define LL_ADC_IT_AWD3 ADC_IER_AWD3IE /*!< ADC interruption ADC analog watchdog 3 */
  441. #define LL_ADC_IT_EOCAL ADC_IER_EOCALIE /*!< ADC interruption ADC end of calibration */
  442. /**
  443. * @}
  444. */
  445. /** @defgroup ADC_LL_EC_REGISTERS ADC registers compliant with specific purpose
  446. * @{
  447. */
  448. /* List of ADC registers intended to be used (most commonly) with */
  449. /* DMA transfer. */
  450. /* Refer to function @ref LL_ADC_DMA_GetRegAddr(). */
  451. #define LL_ADC_DMA_REG_REGULAR_DATA (0x00000000UL) /* ADC group regular conversion data register
  452. (corresponding to register DR) to be used with ADC configured in independent
  453. mode. Without DMA transfer, register accessed by LL function
  454. @ref LL_ADC_REG_ReadConversionData32() and other
  455. functions @ref LL_ADC_REG_ReadConversionDatax() */
  456. /**
  457. * @}
  458. */
  459. /** @defgroup ADC_LL_EC_COMMON_CLOCK_SOURCE ADC common - Clock source
  460. * @{
  461. */
  462. #define LL_ADC_CLOCK_ASYNC_DIV1 (0x00000000UL) /*!< ADC asynchronous clock without
  463. prescaler */
  464. #define LL_ADC_CLOCK_ASYNC_DIV2 (ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with
  465. prescaler division by 2. Setting common to ADC instances of ADC common
  466. group, applied ADC instance wise to each instance clock set to clock source
  467. asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  468. #define LL_ADC_CLOCK_ASYNC_DIV4 (ADC_CCR_PRESC_1) /*!< ADC asynchronous clock with
  469. prescaler division by 4. Setting common to ADC instances of ADC common
  470. group, applied ADC instance wise to each instance clock set to clock source
  471. asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  472. #define LL_ADC_CLOCK_ASYNC_DIV6 (ADC_CCR_PRESC_1 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with
  473. prescaler division by 6. Setting common to ADC instances of ADC common
  474. group, applied ADC instance wise to each instance clock set to clock source
  475. asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  476. #define LL_ADC_CLOCK_ASYNC_DIV8 (ADC_CCR_PRESC_2) /*!< ADC asynchronous clock with
  477. prescaler division by 8. Setting common to ADC instances of ADC common
  478. group, applied ADC instance wise to each instance clock set to clock source
  479. asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  480. #define LL_ADC_CLOCK_ASYNC_DIV10 (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with
  481. prescaler division by 10. Setting common to ADC instances of ADC common
  482. group, applied ADC instance wise to each instance clock set to clock source
  483. asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  484. #define LL_ADC_CLOCK_ASYNC_DIV12 (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_1) /*!< ADC asynchronous clock with
  485. prescaler division by 12. Setting common to ADC instances of ADC common
  486. group, applied ADC instance wise to each instance clock set to clock source
  487. asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  488. #define LL_ADC_CLOCK_ASYNC_DIV16 (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_1 \
  489. | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with
  490. prescaler division by 16. Setting common to ADC instances of ADC common
  491. group, applied ADC instance wise to each instance clock set to clock source
  492. asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  493. #define LL_ADC_CLOCK_ASYNC_DIV32 (ADC_CCR_PRESC_3) /*!< ADC asynchronous clock with
  494. prescaler division by 32. Setting common to ADC instances of ADC common
  495. group, applied ADC instance wise to each instance clock set to clock source
  496. asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  497. #define LL_ADC_CLOCK_ASYNC_DIV64 (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with
  498. prescaler division by 64. Setting common to ADC instances of ADC common
  499. group, applied ADC instance wise to each instance clock set to clock source
  500. asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  501. #define LL_ADC_CLOCK_ASYNC_DIV128 (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_1) /*!< ADC asynchronous clock with
  502. prescaler division by 128. Setting common to ADC instances of ADC common
  503. group, applied ADC instance wise to each instance clock set to clock source
  504. asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  505. #define LL_ADC_CLOCK_ASYNC_DIV256 (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_1 \
  506. | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with
  507. prescaler division by 256. Setting common to ADC instances of ADC common
  508. group, applied ADC instance wise to each instance clock set to clock source
  509. asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  510. /**
  511. * @}
  512. */
  513. /** @defgroup ADC_LL_EC_COMMON_CLOCK_FREQ_MODE ADC common - Clock frequency mode
  514. * @{
  515. */
  516. #define LL_ADC_CLOCK_FREQ_MODE_HIGH (0x00000000UL) /*!< ADC clock mode to high frequency.
  517. On STM32G0, ADC clock frequency above 3.5MHz. */
  518. #define LL_ADC_CLOCK_FREQ_MODE_LOW (ADC_CCR_LFMEN) /*!< ADC clock mode to low frequency.
  519. On STM32G0,ADC clock frequency below 3.5MHz. */
  520. /**
  521. * @}
  522. */
  523. /** @defgroup ADC_LL_EC_COMMON_PATH_INTERNAL ADC common - Measurement path to internal channels
  524. * @{
  525. */
  526. /* Note: Other measurement paths to internal channels may be available */
  527. /* (connections to other peripherals). */
  528. /* If they are not listed below, they do not require any specific */
  529. /* path enable. In this case, Access to measurement path is done */
  530. /* only by selecting the corresponding ADC internal channel. */
  531. #define LL_ADC_PATH_INTERNAL_NONE (0x00000000UL) /*!< ADC measurement paths all disabled */
  532. #define LL_ADC_PATH_INTERNAL_VREFINT (ADC_CCR_VREFEN) /*!< ADC measurement path to internal channel VrefInt */
  533. #define LL_ADC_PATH_INTERNAL_TEMPSENSOR (ADC_CCR_TSEN) /*!< ADC measurement path to internal channel
  534. temperature sensor */
  535. #define LL_ADC_PATH_INTERNAL_VBAT (ADC_CCR_VBATEN) /*!< ADC measurement path to internal channel Vbat */
  536. /**
  537. * @}
  538. */
  539. /** @defgroup ADC_LL_EC_CLOCK_SOURCE ADC instance - Clock source
  540. * @{
  541. */
  542. #define LL_ADC_CLOCK_SYNC_PCLK_DIV4 (ADC_CFGR2_CKMODE_1) /*!< ADC synchronous clock derived from AHB clock
  543. divided by 4 */
  544. #define LL_ADC_CLOCK_SYNC_PCLK_DIV2 (ADC_CFGR2_CKMODE_0) /*!< ADC synchronous clock derived from AHB clock
  545. divided by 2 */
  546. #define LL_ADC_CLOCK_SYNC_PCLK_DIV1 (ADC_CFGR2_CKMODE_1 \
  547. | ADC_CFGR2_CKMODE_0) /*!< ADC synchronous clock derived from AHB clock
  548. not divided */
  549. #define LL_ADC_CLOCK_ASYNC (0x00000000UL) /*!< ADC asynchronous clock. Asynchronous clock
  550. prescaler can be configured using function @ref LL_ADC_SetCommonClock(). */
  551. /**
  552. * @}
  553. */
  554. /** @defgroup ADC_LL_EC_RESOLUTION ADC instance - Resolution
  555. * @{
  556. */
  557. #define LL_ADC_RESOLUTION_12B (0x00000000UL) /*!< ADC resolution 12 bits */
  558. #define LL_ADC_RESOLUTION_10B ( ADC_CFGR1_RES_0) /*!< ADC resolution 10 bits */
  559. #define LL_ADC_RESOLUTION_8B (ADC_CFGR1_RES_1 ) /*!< ADC resolution 8 bits */
  560. #define LL_ADC_RESOLUTION_6B (ADC_CFGR1_RES_1 | ADC_CFGR1_RES_0) /*!< ADC resolution 6 bits */
  561. /**
  562. * @}
  563. */
  564. /** @defgroup ADC_LL_EC_DATA_ALIGN ADC instance - Data alignment
  565. * @{
  566. */
  567. #define LL_ADC_DATA_ALIGN_RIGHT (0x00000000UL) /*!< ADC conversion data alignment: right aligned
  568. (alignment on data register LSB bit 0)*/
  569. #define LL_ADC_DATA_ALIGN_LEFT (ADC_CFGR1_ALIGN) /*!< ADC conversion data alignment: left aligned
  570. (alignment on data register MSB bit 15)*/
  571. /**
  572. * @}
  573. */
  574. /** @defgroup ADC_LL_EC_LP_MODE ADC instance - Low power mode
  575. * @{
  576. */
  577. #define LL_ADC_LP_MODE_NONE (0x00000000UL) /*!< No ADC low power mode activated */
  578. #define LL_ADC_LP_AUTOWAIT (ADC_CFGR1_WAIT) /*!< ADC low power mode auto delay: Dynamic low power
  579. mode, ADC conversions are performed only when necessary
  580. (when previous ADC conversion data is read).
  581. See description with function @ref LL_ADC_SetLowPowerMode(). */
  582. #define LL_ADC_LP_AUTOPOWEROFF (ADC_CFGR1_AUTOFF) /*!< ADC low power mode auto power-off: the ADC
  583. automatically powers-off after a ADC conversion and automatically wakes up
  584. when a new ADC conversion is triggered (with startup time between trigger
  585. and start of sampling). See description with function
  586. @ref LL_ADC_SetLowPowerMode(). */
  587. #define LL_ADC_LP_AUTOWAIT_AUTOPOWEROFF (ADC_CFGR1_WAIT | ADC_CFGR1_AUTOFF) /*!< ADC low power modes auto wait
  588. and auto power-off combined. See description with function @ref LL_ADC_SetLowPowerMode(). */
  589. /**
  590. * @}
  591. */
  592. /** @defgroup ADC_LL_EC_REG_TRIGGER_FREQ ADC group regular - Trigger frequency mode
  593. * @{
  594. */
  595. #define LL_ADC_TRIGGER_FREQ_HIGH (0x00000000UL) /*!< ADC trigger frequency mode set to high frequency.
  596. Note: ADC trigger frequency mode must be set to low frequency when a duration
  597. is exceeded before ADC conversion start trigger event (between ADC enable
  598. and ADC conversion start trigger event or between two ADC conversion start
  599. trigger event).
  600. Duration value: Refer to device datasheet, parameter "tIdle". */
  601. #define LL_ADC_TRIGGER_FREQ_LOW (ADC_CFGR2_LFTRIG) /*!< ADC trigger frequency mode set to low frequency.
  602. Note: ADC trigger frequency mode must be set to low frequency when a duration
  603. is exceeded before ADC conversion start trigger event (between ADC enable
  604. and ADC conversion start trigger event or between two ADC conversion start
  605. trigger event).
  606. Duration value: Refer to device datasheet, parameter "tIdle". */
  607. /**
  608. * @}
  609. */
  610. /** @defgroup ADC_LL_EC_SAMPLINGTIME_COMMON ADC instance - Sampling time common to a group of channels
  611. * @{
  612. */
  613. #define LL_ADC_SAMPLINGTIME_COMMON_1 (ADC_SMPR_SMP1_BITOFFSET_POS) /*!< Set sampling time common to a group
  614. of channels: sampling time nb 1 */
  615. #define LL_ADC_SAMPLINGTIME_COMMON_2 (ADC_SMPR_SMP2_BITOFFSET_POS \
  616. | ADC_SAMPLING_TIME_CH_MASK) /*!< Set sampling time common to a group
  617. of channels: sampling time nb 2 */
  618. /**
  619. * @}
  620. */
  621. /** @defgroup ADC_LL_EC_GROUPS ADC instance - Groups
  622. * @{
  623. */
  624. #define LL_ADC_GROUP_REGULAR (0x00000001UL) /*!< ADC group regular (available on all STM32 devices) */
  625. /**
  626. * @}
  627. */
  628. /** @defgroup ADC_LL_EC_CHANNEL ADC instance - Channel number
  629. * @{
  630. */
  631. #define LL_ADC_CHANNEL_0 (ADC_CHANNEL_0_NUMBER \
  632. | ADC_CHANNEL_0_BITFIELD ) /*!< ADC channel ADCx_IN0 */
  633. #define LL_ADC_CHANNEL_1 (ADC_CHANNEL_1_NUMBER \
  634. | ADC_CHANNEL_1_BITFIELD ) /*!< ADC channel ADCx_IN1 */
  635. #define LL_ADC_CHANNEL_2 (ADC_CHANNEL_2_NUMBER \
  636. | ADC_CHANNEL_2_BITFIELD ) /*!< ADC channel ADCx_IN2 */
  637. #define LL_ADC_CHANNEL_3 (ADC_CHANNEL_3_NUMBER \
  638. | ADC_CHANNEL_3_BITFIELD ) /*!< ADC channel ADCx_IN3 */
  639. #define LL_ADC_CHANNEL_4 (ADC_CHANNEL_4_NUMBER \
  640. | ADC_CHANNEL_4_BITFIELD ) /*!< ADC channel ADCx_IN4 */
  641. #define LL_ADC_CHANNEL_5 (ADC_CHANNEL_5_NUMBER \
  642. | ADC_CHANNEL_5_BITFIELD ) /*!< ADC channel ADCx_IN5 */
  643. #define LL_ADC_CHANNEL_6 (ADC_CHANNEL_6_NUMBER \
  644. | ADC_CHANNEL_6_BITFIELD ) /*!< ADC channel ADCx_IN6 */
  645. #define LL_ADC_CHANNEL_7 (ADC_CHANNEL_7_NUMBER \
  646. | ADC_CHANNEL_7_BITFIELD ) /*!< ADC channel ADCx_IN7 */
  647. #define LL_ADC_CHANNEL_8 (ADC_CHANNEL_8_NUMBER \
  648. | ADC_CHANNEL_8_BITFIELD ) /*!< ADC channel ADCx_IN8 */
  649. #define LL_ADC_CHANNEL_9 (ADC_CHANNEL_9_NUMBER \
  650. | ADC_CHANNEL_9_BITFIELD ) /*!< ADC channel ADCx_IN9 */
  651. #define LL_ADC_CHANNEL_10 (ADC_CHANNEL_10_NUMBER \
  652. | ADC_CHANNEL_10_BITFIELD) /*!< ADC channel ADCx_IN10 */
  653. #define LL_ADC_CHANNEL_11 (ADC_CHANNEL_11_NUMBER \
  654. | ADC_CHANNEL_11_BITFIELD) /*!< ADC channel ADCx_IN11 */
  655. #define LL_ADC_CHANNEL_12 (ADC_CHANNEL_12_NUMBER \
  656. | ADC_CHANNEL_12_BITFIELD) /*!< ADC channel ADCx_IN12 */
  657. #define LL_ADC_CHANNEL_13 (ADC_CHANNEL_13_NUMBER \
  658. | ADC_CHANNEL_13_BITFIELD) /*!< ADC channel ADCx_IN13 */
  659. #define LL_ADC_CHANNEL_14 (ADC_CHANNEL_14_NUMBER \
  660. | ADC_CHANNEL_14_BITFIELD) /*!< ADC channel ADCx_IN14 */
  661. #define LL_ADC_CHANNEL_15 (ADC_CHANNEL_15_NUMBER \
  662. | ADC_CHANNEL_15_BITFIELD) /*!< ADC channel ADCx_IN15 */
  663. #define LL_ADC_CHANNEL_16 (ADC_CHANNEL_16_NUMBER \
  664. | ADC_CHANNEL_16_BITFIELD) /*!< ADC channel ADCx_IN16 */
  665. #define LL_ADC_CHANNEL_17 (ADC_CHANNEL_17_NUMBER \
  666. | ADC_CHANNEL_17_BITFIELD) /*!< ADC channel ADCx_IN17 */
  667. #define LL_ADC_CHANNEL_18 (ADC_CHANNEL_18_NUMBER \
  668. | ADC_CHANNEL_18_BITFIELD) /*!< ADC channel ADCx_IN18 */
  669. #define LL_ADC_CHANNEL_VREFINT (LL_ADC_CHANNEL_13 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel
  670. connected to VrefInt: Internal voltage reference. */
  671. #define LL_ADC_CHANNEL_TEMPSENSOR (LL_ADC_CHANNEL_12 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel
  672. connected to Temperature sensor. */
  673. #define LL_ADC_CHANNEL_VBAT (LL_ADC_CHANNEL_14 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel
  674. connected to Vbat/4: Vbat voltage through a divider ladder of factor 1/3
  675. to have channel voltage always below Vdda. */
  676. /**
  677. * @}
  678. */
  679. /** @defgroup ADC_LL_EC_REG_TRIGGER_SOURCE ADC group regular - Trigger source
  680. * @{
  681. */
  682. #define LL_ADC_REG_TRIG_SOFTWARE (0x00000000UL) /*!< ADC group regular
  683. conversion trigger internal: SW start. */
  684. #define LL_ADC_REG_TRIG_EXT_TIM1_TRGO2 (ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular
  685. conversion trigger from external peripheral: TIM1 TRGO.
  686. Trigger edge set to rising edge (default setting). */
  687. #define LL_ADC_REG_TRIG_EXT_TIM1_CH4 (ADC_CFGR1_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular
  688. conversion trigger from external peripheral: TIM1 channel 4 event
  689. (capture compare: input capture or output capture).
  690. Trigger edge set to rising edge (default setting). */
  691. #if defined(TIM2)
  692. #define LL_ADC_REG_TRIG_EXT_TIM2_TRGO (ADC_CFGR1_EXTSEL_1\
  693. | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular
  694. conversion trigger from external peripheral: TIM2 TRGO.
  695. Trigger edge set to rising edge (default setting). */
  696. #endif /* TIM2 */
  697. #define LL_ADC_REG_TRIG_EXT_TIM3_TRGO (ADC_CFGR1_EXTSEL_1 | ADC_CFGR1_EXTSEL_0 | \
  698. ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular
  699. conversion trigger from external peripheral: TIM3 TRGO.
  700. Trigger edge set to rising edge (default setting). */
  701. #if defined(TIM4)
  702. #define LL_ADC_REG_TRIG_EXT_TIM4_TRGO (ADC_CFGR1_EXTSEL_2 | ADC_CFGR1_EXTSEL_1 | \
  703. ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular
  704. conversion trigger from external peripheral: TIM4 TRGO.
  705. Trigger edge set to rising edge (default setting). */
  706. #endif /* TIM4 */
  707. #if defined(TIM6)
  708. #define LL_ADC_REG_TRIG_EXT_TIM6_TRGO (ADC_CFGR1_EXTSEL_2 | ADC_CFGR1_EXTSEL_0 | \
  709. ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular
  710. conversion trigger from external peripheral: TIM6 TRGO.
  711. Trigger edge set to rising edge (default setting). */
  712. #endif /* TIM6 */
  713. #if defined(TIM15)
  714. #define LL_ADC_REG_TRIG_EXT_TIM15_TRGO (ADC_CFGR1_EXTSEL_2 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular
  715. conversion trigger from external peripheral: TIM15 TRGO.
  716. Trigger edge set to rising edge (default setting). */
  717. #endif /* TIM15 */
  718. #define LL_ADC_REG_TRIG_EXT_EXTI_LINE11 (ADC_CFGR1_EXTSEL_2 | ADC_CFGR1_EXTSEL_1 | \
  719. ADC_CFGR1_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular
  720. conversion trigger from external peripheral: external interrupt line 11.
  721. Trigger edge set to rising edge (default setting). */
  722. /**
  723. * @}
  724. */
  725. /** @defgroup ADC_LL_EC_REG_TRIGGER_EDGE ADC group regular - Trigger edge
  726. * @{
  727. */
  728. #define LL_ADC_REG_TRIG_EXT_RISING (ADC_CFGR1_EXTEN_0) /*!< ADC group regular conversion
  729. trigger polarity set to rising edge */
  730. #define LL_ADC_REG_TRIG_EXT_FALLING (ADC_CFGR1_EXTEN_1) /*!< ADC group regular conversion
  731. trigger polarity set to falling edge */
  732. #define LL_ADC_REG_TRIG_EXT_RISINGFALLING (ADC_CFGR1_EXTEN_1 | ADC_CFGR1_EXTEN_0) /*!< ADC group regular conversion
  733. trigger polarity set to both rising and falling edges */
  734. /**
  735. * @}
  736. */
  737. /** @defgroup ADC_LL_EC_REG_CONTINUOUS_MODE ADC group regular - Continuous mode
  738. * @{
  739. */
  740. #define LL_ADC_REG_CONV_SINGLE (0x00000000UL) /*!< ADC conversions performed in single mode:
  741. one conversion per trigger */
  742. #define LL_ADC_REG_CONV_CONTINUOUS (ADC_CFGR1_CONT) /*!< ADC conversions performed in continuous mode:
  743. after the first trigger, following conversions launched successively
  744. automatically */
  745. /**
  746. * @}
  747. */
  748. /** @defgroup ADC_LL_EC_REG_DMA_TRANSFER ADC group regular - DMA transfer of ADC conversion data
  749. * @{
  750. */
  751. #define LL_ADC_REG_DMA_TRANSFER_NONE (0x00000000UL) /*!< ADC conversions are not transferred by DMA */
  752. #define LL_ADC_REG_DMA_TRANSFER_LIMITED (ADC_CFGR1_DMAEN) /*!< ADC conversion data are transferred by DMA,
  753. in limited mode (one shot mode): DMA transfer requests are stopped when
  754. number of DMA data transfers (number of ADC conversions) is reached.
  755. This ADC mode is intended to be used with DMA mode non-circular. */
  756. #define LL_ADC_REG_DMA_TRANSFER_UNLIMITED (ADC_CFGR1_DMACFG | ADC_CFGR1_DMAEN) /*!< ADC conversion data are
  757. transferred by DMA, in unlimited mode: DMA transfer requests are unlimited,
  758. whatever number of DMA data transferred (number of ADC conversions).
  759. This ADC mode is intended to be used with DMA mode circular. */
  760. /**
  761. * @}
  762. */
  763. /** @defgroup ADC_LL_EC_REG_OVR_DATA_BEHAVIOR ADC group regular - Overrun behavior on conversion data
  764. * @{
  765. */
  766. #define LL_ADC_REG_OVR_DATA_PRESERVED (0x00000000UL) /*!< ADC group regular behavior in case of overrun:
  767. data preserved */
  768. #define LL_ADC_REG_OVR_DATA_OVERWRITTEN (ADC_CFGR1_OVRMOD) /*!< ADC group regular behavior in case of overrun:
  769. data overwritten */
  770. /**
  771. * @}
  772. */
  773. /** @defgroup ADC_LL_EC_REG_SEQ_MODE ADC group regular - Sequencer configuration flexibility
  774. * @{
  775. */
  776. #define LL_ADC_REG_SEQ_FIXED (0x00000000UL) /*!< Sequencer configured to not fully configurable:
  777. sequencer length and each rank affectation to a channel are fixed
  778. by channel HW number. Refer to description of function
  779. @ref LL_ADC_REG_SetSequencerChannels(). */
  780. #define LL_ADC_REG_SEQ_CONFIGURABLE (ADC_CFGR1_CHSELRMOD) /*!< Sequencer configured to fully configurable:
  781. sequencer length and each rank affectation to a channel are configurable.
  782. Refer to description of function @ref LL_ADC_REG_SetSequencerLength(). */
  783. /**
  784. * @}
  785. */
  786. /** @defgroup ADC_LL_EC_REG_SEQ_SCAN_LENGTH ADC group regular - Sequencer scan length
  787. * @{
  788. */
  789. #define LL_ADC_REG_SEQ_SCAN_DISABLE (ADC_CHSELR_SQ2) /*!< ADC group regular sequencer disable
  790. (equivalent to sequencer of 1 rank: ADC conversion on only 1 channel) */
  791. #define LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS (ADC_CHSELR_SQ3) /*!< ADC group regular sequencer enable
  792. with 2 ranks in the sequence */
  793. #define LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS (ADC_CHSELR_SQ4) /*!< ADC group regular sequencer enable
  794. with 3 ranks in the sequence */
  795. #define LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS (ADC_CHSELR_SQ5) /*!< ADC group regular sequencer enable
  796. with 4 ranks in the sequence */
  797. #define LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS (ADC_CHSELR_SQ6) /*!< ADC group regular sequencer enable
  798. with 5 ranks in the sequence */
  799. #define LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS (ADC_CHSELR_SQ7) /*!< ADC group regular sequencer enable
  800. with 6 ranks in the sequence */
  801. #define LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS (ADC_CHSELR_SQ8) /*!< ADC group regular sequencer enable
  802. with 7 ranks in the sequence */
  803. #define LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS (0x00000000UL) /*!< ADC group regular sequencer enable
  804. with 8 ranks in the sequence */
  805. /**
  806. * @}
  807. */
  808. /** @defgroup ADC_LL_EC_REG_SEQ_SCAN_DIRECTION ADC group regular - Sequencer scan direction
  809. * @{
  810. */
  811. #define LL_ADC_REG_SEQ_SCAN_DIR_FORWARD (0x00000000UL) /*!< On this STM32 series, parameter relevant only if
  812. sequencer set to mode not fully configurable, refer to function
  813. @ref LL_ADC_REG_SetSequencerConfigurable(). ADC group regular sequencer scan
  814. direction forward: from lowest channel number to highest channel number
  815. (scan of all ranks, ADC conversion of ranks with channels enabled in
  816. sequencer). On some other STM32 series, this setting is not available
  817. and the default scan direction is forward. */
  818. #define LL_ADC_REG_SEQ_SCAN_DIR_BACKWARD (ADC_CFGR1_SCANDIR) /*!< On this STM32 series, parameter relevant only if
  819. sequencer set to mode not fully configurable, refer to function
  820. @ref LL_ADC_REG_SetSequencerConfigurable(). ADC group regular sequencer scan
  821. direction backward: from highest channel number to lowest channel number
  822. (scan of all ranks, ADC conversion of ranks with channels enabled in
  823. sequencer) */
  824. /**
  825. * @}
  826. */
  827. /** @defgroup ADC_LL_EC_REG_SEQ_DISCONT_MODE ADC group regular - Sequencer discontinuous mode
  828. * @{
  829. */
  830. #define LL_ADC_REG_SEQ_DISCONT_DISABLE (0x00000000UL) /*!< ADC group regular sequencer
  831. discontinuous mode disable */
  832. #define LL_ADC_REG_SEQ_DISCONT_1RANK (ADC_CFGR1_DISCEN) /*!< ADC group regular sequencer
  833. discontinuous mode enable with sequence interruption every rank */
  834. /**
  835. * @}
  836. */
  837. /** @defgroup ADC_LL_EC_REG_SEQ_RANKS ADC group regular - Sequencer ranks
  838. * @{
  839. */
  840. #define LL_ADC_REG_RANK_1 (ADC_REG_RANK_1_SQRX_BITOFFSET_POS) /*!< ADC group regular seq. rank 1 */
  841. #define LL_ADC_REG_RANK_2 (ADC_REG_RANK_2_SQRX_BITOFFSET_POS) /*!< ADC group regular seq. rank 2 */
  842. #define LL_ADC_REG_RANK_3 (ADC_REG_RANK_3_SQRX_BITOFFSET_POS) /*!< ADC group regular seq. rank 3 */
  843. #define LL_ADC_REG_RANK_4 (ADC_REG_RANK_4_SQRX_BITOFFSET_POS) /*!< ADC group regular seq. rank 4 */
  844. #define LL_ADC_REG_RANK_5 (ADC_REG_RANK_5_SQRX_BITOFFSET_POS) /*!< ADC group regular seq. rank 5 */
  845. #define LL_ADC_REG_RANK_6 (ADC_REG_RANK_6_SQRX_BITOFFSET_POS) /*!< ADC group regular seq. rank 6 */
  846. #define LL_ADC_REG_RANK_7 (ADC_REG_RANK_7_SQRX_BITOFFSET_POS) /*!< ADC group regular seq. rank 7 */
  847. #define LL_ADC_REG_RANK_8 (ADC_REG_RANK_8_SQRX_BITOFFSET_POS) /*!< ADC group regular seq. rank 8 */
  848. /**
  849. * @}
  850. */
  851. /** @defgroup ADC_LL_EC_CHANNEL_SAMPLINGTIME Channel - Sampling time
  852. * @{
  853. */
  854. #define LL_ADC_SAMPLINGTIME_1CYCLE_5 (0x00000000UL) /*!< Sampling time 1.5 ADC clock cycle */
  855. #define LL_ADC_SAMPLINGTIME_3CYCLES_5 (ADC_SMPR_SMP1_0) /*!< Sampling time 3.5 ADC clock cycles */
  856. #define LL_ADC_SAMPLINGTIME_7CYCLES_5 (ADC_SMPR_SMP1_1) /*!< Sampling time 7.5 ADC clock cycles */
  857. #define LL_ADC_SAMPLINGTIME_12CYCLES_5 (ADC_SMPR_SMP1_1 \
  858. | ADC_SMPR_SMP1_0) /*!< Sampling time 12.5 ADC clock cycles */
  859. #define LL_ADC_SAMPLINGTIME_19CYCLES_5 (ADC_SMPR_SMP1_2) /*!< Sampling time 19.5 ADC clock cycles */
  860. #define LL_ADC_SAMPLINGTIME_39CYCLES_5 (ADC_SMPR_SMP1_2 \
  861. | ADC_SMPR_SMP1_0) /*!< Sampling time 39.5 ADC clock cycles */
  862. #define LL_ADC_SAMPLINGTIME_79CYCLES_5 (ADC_SMPR_SMP1_2 \
  863. | ADC_SMPR_SMP1_1) /*!< Sampling time 79.5 ADC clock cycles */
  864. #define LL_ADC_SAMPLINGTIME_160CYCLES_5 (ADC_SMPR_SMP1_2 \
  865. | ADC_SMPR_SMP1_1 \
  866. | ADC_SMPR_SMP1_0) /*!< Sampling time 160.5 ADC clock cycles */
  867. /**
  868. * @}
  869. */
  870. /** @defgroup ADC_LL_EC_AWD_NUMBER Analog watchdog - Analog watchdog number
  871. * @{
  872. */
  873. #define LL_ADC_AWD1 (ADC_AWD_CR1_CHANNEL_MASK \
  874. | ADC_AWD_CR1_REGOFFSET) /*!< ADC analog watchdog number 1 */
  875. #define LL_ADC_AWD2 (ADC_AWD_CR23_CHANNEL_MASK \
  876. | ADC_AWD_CR2_REGOFFSET) /*!< ADC analog watchdog number 2 */
  877. #define LL_ADC_AWD3 (ADC_AWD_CR23_CHANNEL_MASK \
  878. | ADC_AWD_CR3_REGOFFSET) /*!< ADC analog watchdog number 3 */
  879. /**
  880. * @}
  881. */
  882. /** @defgroup ADC_LL_EC_AWD_CHANNELS Analog watchdog - Monitored channels
  883. * @{
  884. */
  885. #define LL_ADC_AWD_DISABLE (0x00000000UL) /*!< ADC analog watchdog monitoring
  886. disabled */
  887. #define LL_ADC_AWD_ALL_CHANNELS_REG (ADC_AWD_CR23_CHANNEL_MASK \
  888. | ADC_CFGR1_AWD1EN) /*!< ADC analog watchdog monitoring
  889. of all channels, converted by group regular only */
  890. #define LL_ADC_AWD_CHANNEL_0_REG ((LL_ADC_CHANNEL_0 & ADC_CHANNEL_ID_MASK) \
  891. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  892. of ADC channel ADCx_IN0, converted by group regular only */
  893. #define LL_ADC_AWD_CHANNEL_1_REG ((LL_ADC_CHANNEL_1 & ADC_CHANNEL_ID_MASK) \
  894. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  895. of ADC channel ADCx_IN1, converted by group regular only */
  896. #define LL_ADC_AWD_CHANNEL_2_REG ((LL_ADC_CHANNEL_2 & ADC_CHANNEL_ID_MASK) \
  897. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  898. of ADC channel ADCx_IN2, converted by group regular only */
  899. #define LL_ADC_AWD_CHANNEL_3_REG ((LL_ADC_CHANNEL_3 & ADC_CHANNEL_ID_MASK) \
  900. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  901. of ADC channel ADCx_IN3, converted by group regular only */
  902. #define LL_ADC_AWD_CHANNEL_4_REG ((LL_ADC_CHANNEL_4 & ADC_CHANNEL_ID_MASK) \
  903. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  904. of ADC channel ADCx_IN4, converted by group regular only */
  905. #define LL_ADC_AWD_CHANNEL_5_REG ((LL_ADC_CHANNEL_5 & ADC_CHANNEL_ID_MASK) \
  906. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  907. of ADC channel ADCx_IN5, converted by group regular only */
  908. #define LL_ADC_AWD_CHANNEL_6_REG ((LL_ADC_CHANNEL_6 & ADC_CHANNEL_ID_MASK) \
  909. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  910. of ADC channel ADCx_IN6, converted by group regular only */
  911. #define LL_ADC_AWD_CHANNEL_7_REG ((LL_ADC_CHANNEL_7 & ADC_CHANNEL_ID_MASK) \
  912. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  913. of ADC channel ADCx_IN7, converted by group regular only */
  914. #define LL_ADC_AWD_CHANNEL_8_REG ((LL_ADC_CHANNEL_8 & ADC_CHANNEL_ID_MASK) \
  915. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  916. of ADC channel ADCx_IN8, converted by group regular only */
  917. #define LL_ADC_AWD_CHANNEL_9_REG ((LL_ADC_CHANNEL_9 & ADC_CHANNEL_ID_MASK) \
  918. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  919. of ADC channel ADCx_IN9, converted by group regular only */
  920. #define LL_ADC_AWD_CHANNEL_10_REG ((LL_ADC_CHANNEL_10 & ADC_CHANNEL_ID_MASK) \
  921. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  922. of ADC channel ADCx_IN10, converted by group regular only */
  923. #define LL_ADC_AWD_CHANNEL_11_REG ((LL_ADC_CHANNEL_11 & ADC_CHANNEL_ID_MASK) \
  924. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  925. of ADC channel ADCx_IN11, converted by group regular only */
  926. #define LL_ADC_AWD_CHANNEL_12_REG ((LL_ADC_CHANNEL_12 & ADC_CHANNEL_ID_MASK) \
  927. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  928. of ADC channel ADCx_IN12, converted by group regular only */
  929. #define LL_ADC_AWD_CHANNEL_13_REG ((LL_ADC_CHANNEL_13 & ADC_CHANNEL_ID_MASK) \
  930. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  931. of ADC channel ADCx_IN13, converted by group regular only */
  932. #define LL_ADC_AWD_CHANNEL_14_REG ((LL_ADC_CHANNEL_14 & ADC_CHANNEL_ID_MASK) \
  933. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  934. of ADC channel ADCx_IN14, converted by group regular only */
  935. #define LL_ADC_AWD_CHANNEL_15_REG ((LL_ADC_CHANNEL_15 & ADC_CHANNEL_ID_MASK) \
  936. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  937. of ADC channel ADCx_IN15, converted by group regular only */
  938. #define LL_ADC_AWD_CHANNEL_16_REG ((LL_ADC_CHANNEL_16 & ADC_CHANNEL_ID_MASK) \
  939. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  940. of ADC channel ADCx_IN16, converted by group regular only */
  941. #define LL_ADC_AWD_CHANNEL_17_REG ((LL_ADC_CHANNEL_17 & ADC_CHANNEL_ID_MASK) \
  942. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  943. of ADC channel ADCx_IN17, converted by group regular only */
  944. #define LL_ADC_AWD_CHANNEL_18_REG ((LL_ADC_CHANNEL_18 & ADC_CHANNEL_ID_MASK) \
  945. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  946. of ADC channel ADCx_IN18, converted by group regular only */
  947. #define LL_ADC_AWD_CH_VREFINT_REG ((LL_ADC_CHANNEL_VREFINT & ADC_CHANNEL_ID_MASK) \
  948. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  949. of ADC internal channel connected to VrefInt: Internal
  950. voltage reference, converted by group regular only */
  951. #define LL_ADC_AWD_CH_TEMPSENSOR_REG ((LL_ADC_CHANNEL_TEMPSENSOR & ADC_CHANNEL_ID_MASK) \
  952. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  953. of ADC internal channel connected to internal temperature sensor,
  954. converted by group regular only */
  955. #define LL_ADC_AWD_CH_VBAT_REG ((LL_ADC_CHANNEL_VBAT & ADC_CHANNEL_ID_MASK) \
  956. | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL) /*!< ADC analog watchdog monitoring
  957. of ADC internal channel connected to Vbat/3: Vbat
  958. voltage through a divider ladder of factor 1/3 to have channel voltage always
  959. below Vdda, converted by group regular only */
  960. /**
  961. * @}
  962. */
  963. /** @defgroup ADC_LL_EC_AWD_THRESHOLDS Analog watchdog - Thresholds
  964. * @{
  965. */
  966. #define LL_ADC_AWD_THRESHOLD_HIGH (ADC_AWD1TR_HT1) /*!< ADC analog watchdog threshold high */
  967. #define LL_ADC_AWD_THRESHOLD_LOW (ADC_AWD1TR_LT1) /*!< ADC analog watchdog threshold low */
  968. #define LL_ADC_AWD_THRESHOLDS_HIGH_LOW (ADC_AWD1TR_HT1 \
  969. | ADC_AWD1TR_LT1) /*!< ADC analog watchdog both thresholds high and low
  970. concatenated into the same data */
  971. /**
  972. * @}
  973. */
  974. /** @defgroup ADC_LL_EC_OVS_SCOPE Oversampling - Oversampling scope
  975. * @{
  976. */
  977. #define LL_ADC_OVS_DISABLE (0x00000000UL) /*!< ADC oversampling disabled. */
  978. #define LL_ADC_OVS_GRP_REGULAR_CONTINUED (ADC_CFGR2_OVSE) /*!< ADC oversampling on conversions of
  979. ADC group regular. Literal suffix "continued" is kept for compatibility
  980. with other STM32 devices featuring ADC group injected, in this case other
  981. oversampling scope parameters are available. */
  982. /**
  983. * @}
  984. */
  985. /** @defgroup ADC_LL_EC_OVS_DISCONT_MODE Oversampling - Discontinuous mode
  986. * @{
  987. */
  988. #define LL_ADC_OVS_REG_CONT (0x00000000UL) /*!< ADC oversampling discontinuous mode: continuous mode
  989. (all conversions of oversampling ratio are done from 1 trigger) */
  990. #define LL_ADC_OVS_REG_DISCONT (ADC_CFGR2_TOVS) /*!< ADC oversampling discontinuous mode: discontinuous
  991. mode (each conversion of oversampling ratio needs a trigger) */
  992. /**
  993. * @}
  994. */
  995. /** @defgroup ADC_LL_EC_OVS_RATIO Oversampling - Ratio
  996. * @{
  997. */
  998. #define LL_ADC_OVS_RATIO_2 (0x00000000UL) /*!< ADC oversampling ratio of 2
  999. (sum of conversions data computed to result as oversampling conversion data
  1000. (before potential shift) */
  1001. #define LL_ADC_OVS_RATIO_4 (ADC_CFGR2_OVSR_0) /*!< ADC oversampling ratio of 4
  1002. (sum of conversions data computed to result as oversampling conversion data
  1003. (before potential shift) */
  1004. #define LL_ADC_OVS_RATIO_8 (ADC_CFGR2_OVSR_1) /*!< ADC oversampling ratio of 8
  1005. (sum of conversions data computed to result as oversampling conversion data
  1006. (before potential shift) */
  1007. #define LL_ADC_OVS_RATIO_16 (ADC_CFGR2_OVSR_1 | ADC_CFGR2_OVSR_0) /*!< ADC oversampling ratio of 16
  1008. (sum of conversions data computed to result as oversampling conversion data
  1009. (before potential shift) */
  1010. #define LL_ADC_OVS_RATIO_32 (ADC_CFGR2_OVSR_2) /*!< ADC oversampling ratio of 32
  1011. (sum of conversions data computed to result as oversampling conversion data
  1012. (before potential shift) */
  1013. #define LL_ADC_OVS_RATIO_64 (ADC_CFGR2_OVSR_2 | ADC_CFGR2_OVSR_0) /*!< ADC oversampling ratio of 64
  1014. (sum of conversions data computed to result as oversampling conversion data
  1015. (before potential shift) */
  1016. #define LL_ADC_OVS_RATIO_128 (ADC_CFGR2_OVSR_2 | ADC_CFGR2_OVSR_1) /*!< ADC oversampling ratio of 128
  1017. (sum of conversions data computed to result as oversampling conversion data
  1018. (before potential shift) */
  1019. #define LL_ADC_OVS_RATIO_256 (ADC_CFGR2_OVSR_2 | ADC_CFGR2_OVSR_1 \
  1020. | ADC_CFGR2_OVSR_0) /*!< ADC oversampling ratio of 256
  1021. (sum of conversions data computed to result as oversampling conversion data
  1022. (before potential shift) */
  1023. /**
  1024. * @}
  1025. */
  1026. /** @defgroup ADC_LL_EC_OVS_SHIFT Oversampling - Data right shift
  1027. * @{
  1028. */
  1029. #define LL_ADC_OVS_SHIFT_NONE (0x00000000UL) /*!< ADC oversampling no shift
  1030. (sum of the ADC conversions data is not divided to result as oversampling
  1031. conversion data) */
  1032. #define LL_ADC_OVS_SHIFT_RIGHT_1 (ADC_CFGR2_OVSS_0) /*!< ADC oversampling right shift of 1
  1033. (sum of the ADC conversions data (after OVS ratio) is divided by 2
  1034. to result as oversampling conversion data) */
  1035. #define LL_ADC_OVS_SHIFT_RIGHT_2 (ADC_CFGR2_OVSS_1) /*!< ADC oversampling right shift of 2
  1036. (sum of the ADC conversions data (after OVS ratio) is divided by 4
  1037. to result as oversampling conversion data) */
  1038. #define LL_ADC_OVS_SHIFT_RIGHT_3 (ADC_CFGR2_OVSS_1 | ADC_CFGR2_OVSS_0) /*!< ADC oversampling right shift of 3
  1039. (sum of the ADC conversions data (after OVS ratio) is divided by 8
  1040. to result as oversampling conversion data) */
  1041. #define LL_ADC_OVS_SHIFT_RIGHT_4 (ADC_CFGR2_OVSS_2) /*!< ADC oversampling right shift of 4
  1042. (sum of the ADC conversions data (after OVS ratio) is divided by 16
  1043. to result as oversampling conversion data) */
  1044. #define LL_ADC_OVS_SHIFT_RIGHT_5 (ADC_CFGR2_OVSS_2 | ADC_CFGR2_OVSS_0) /*!< ADC oversampling right shift of 5
  1045. (sum of the ADC conversions data (after OVS ratio) is divided by 32
  1046. to result as oversampling conversion data) */
  1047. #define LL_ADC_OVS_SHIFT_RIGHT_6 (ADC_CFGR2_OVSS_2 | ADC_CFGR2_OVSS_1) /*!< ADC oversampling right shift of 6
  1048. (sum of the ADC conversions data (after OVS ratio) is divided by 64
  1049. to result as oversampling conversion data) */
  1050. #define LL_ADC_OVS_SHIFT_RIGHT_7 (ADC_CFGR2_OVSS_2 | ADC_CFGR2_OVSS_1 \
  1051. | ADC_CFGR2_OVSS_0) /*!< ADC oversampling right shift of 7
  1052. (sum of the ADC conversions data (after OVS ratio) is divided by 128
  1053. to result as oversampling conversion data) */
  1054. #define LL_ADC_OVS_SHIFT_RIGHT_8 (ADC_CFGR2_OVSS_3) /*!< ADC oversampling right shift of 8
  1055. (sum of the ADC conversions data (after OVS ratio) is divided by 256
  1056. to result as oversampling conversion data) */
  1057. /**
  1058. * @}
  1059. */
  1060. /** @defgroup ADC_LL_EC_HELPER_MACRO Definitions of constants used by helper macro
  1061. * @{
  1062. */
  1063. #define LL_ADC_TEMPERATURE_CALC_ERROR ((int16_t)0x7FFF) /* Temperature calculation error using helper macro
  1064. @ref __LL_ADC_CALC_TEMPERATURE(), due to issue on
  1065. calibration parameters. This value is coded on 16 bits
  1066. (to fit on signed word or double word) and corresponds
  1067. to an inconsistent temperature value. */
  1068. /**
  1069. * @}
  1070. */
  1071. /** @defgroup ADC_LL_EC_HW_DELAYS Definitions of ADC hardware constraints delays
  1072. * @note Only ADC peripheral HW delays are defined in ADC LL driver driver,
  1073. * not timeout values.
  1074. * For details on delays values, refer to descriptions in source code
  1075. * above each literal definition.
  1076. * @{
  1077. */
  1078. /* Note: Only ADC peripheral HW delays are defined in ADC LL driver driver, */
  1079. /* not timeout values. */
  1080. /* Timeout values for ADC operations are dependent to device clock */
  1081. /* configuration (system clock versus ADC clock), */
  1082. /* and therefore must be defined in user application. */
  1083. /* Indications for estimation of ADC timeout delays, for this */
  1084. /* STM32 series: */
  1085. /* - ADC calibration time: maximum delay is 82/fADC. */
  1086. /* (refer to device datasheet, parameter "tCAL") */
  1087. /* - ADC enable time: maximum delay is 1 conversion cycle. */
  1088. /* (refer to device datasheet, parameter "tSTAB") */
  1089. /* - ADC disable time: maximum delay should be a few ADC clock cycles */
  1090. /* - ADC stop conversion time: maximum delay should be a few ADC clock */
  1091. /* cycles */
  1092. /* - ADC conversion time: duration depending on ADC clock and ADC */
  1093. /* configuration. */
  1094. /* (refer to device reference manual, section "Timing") */
  1095. /* Delay for ADC stabilization time (ADC voltage regulator start-up time) */
  1096. /* Delay set to maximum value (refer to device datasheet, */
  1097. /* parameter "tADCVREG_STUP"). */
  1098. /* Unit: us */
  1099. #define LL_ADC_DELAY_INTERNAL_REGUL_STAB_US ( 20UL) /*!< Delay for ADC stabilization time (ADC voltage
  1100. regulator start-up time) */
  1101. /* Delay for internal voltage reference stabilization time. */
  1102. /* Delay set to maximum value (refer to device datasheet, */
  1103. /* parameter "tstart_vrefint"). */
  1104. /* Unit: us */
  1105. #define LL_ADC_DELAY_VREFINT_STAB_US ( 12UL) /*!< Delay for internal voltage reference stabilization
  1106. time */
  1107. /* Delay for temperature sensor stabilization time. */
  1108. /* Literal set to maximum value (refer to device datasheet, */
  1109. /* parameter "tSTART"). */
  1110. /* Unit: us */
  1111. #define LL_ADC_DELAY_TEMPSENSOR_STAB_US (120UL) /*!< Delay for temperature sensor stabilization time
  1112. (starting from temperature sensor enable, refer to
  1113. @ref LL_ADC_SetCommonPathInternalCh()) */
  1114. #define LL_ADC_DELAY_TEMPSENSOR_BUFFER_STAB_US ( 15UL) /*!< Delay for temperature sensor buffer stabilization
  1115. time (starting from ADC enable, refer to
  1116. @ref LL_ADC_Enable()) */
  1117. /* Delay required between ADC end of calibration and ADC enable. */
  1118. /* Note: On this STM32 series, a minimum number of ADC clock cycles */
  1119. /* are required between ADC end of calibration and ADC enable. */
  1120. /* Wait time can be computed in user application by waiting for the */
  1121. /* equivalent number of CPU cycles, by taking into account */
  1122. /* ratio of CPU clock versus ADC clock prescalers. */
  1123. /* Unit: ADC clock cycles. */
  1124. #define LL_ADC_DELAY_CALIB_ENABLE_ADC_CYCLES ( 2UL) /*!< Delay required between ADC end of calibration
  1125. and ADC enable */
  1126. /**
  1127. * @}
  1128. */
  1129. /**
  1130. * @}
  1131. */
  1132. /* Exported macro ------------------------------------------------------------*/
  1133. /** @defgroup ADC_LL_Exported_Macros ADC Exported Macros
  1134. * @{
  1135. */
  1136. /** @defgroup ADC_LL_EM_WRITE_READ Common write and read registers Macros
  1137. * @{
  1138. */
  1139. /**
  1140. * @brief Write a value in ADC register
  1141. * @param __INSTANCE__ ADC Instance
  1142. * @param __REG__ Register to be written
  1143. * @param __VALUE__ Value to be written in the register
  1144. * @retval None
  1145. */
  1146. #define LL_ADC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  1147. /**
  1148. * @brief Read a value in ADC register
  1149. * @param __INSTANCE__ ADC Instance
  1150. * @param __REG__ Register to be read
  1151. * @retval Register value
  1152. */
  1153. #define LL_ADC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  1154. /**
  1155. * @}
  1156. */
  1157. /** @defgroup ADC_LL_EM_HELPER_MACRO ADC helper macro
  1158. * @{
  1159. */
  1160. /**
  1161. * @brief Helper macro to get ADC channel number in decimal format
  1162. * from literals LL_ADC_CHANNEL_x.
  1163. * @note Example:
  1164. * __LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_CHANNEL_4)
  1165. * will return decimal number "4".
  1166. * @note The input can be a value from functions where a channel
  1167. * number is returned, either defined with number
  1168. * or with bitfield (only one bit must be set).
  1169. * @param __CHANNEL__ This parameter can be one of the following values:
  1170. * @arg @ref LL_ADC_CHANNEL_0
  1171. * @arg @ref LL_ADC_CHANNEL_1
  1172. * @arg @ref LL_ADC_CHANNEL_2
  1173. * @arg @ref LL_ADC_CHANNEL_3
  1174. * @arg @ref LL_ADC_CHANNEL_4
  1175. * @arg @ref LL_ADC_CHANNEL_5
  1176. * @arg @ref LL_ADC_CHANNEL_6
  1177. * @arg @ref LL_ADC_CHANNEL_7
  1178. * @arg @ref LL_ADC_CHANNEL_8
  1179. * @arg @ref LL_ADC_CHANNEL_9
  1180. * @arg @ref LL_ADC_CHANNEL_10
  1181. * @arg @ref LL_ADC_CHANNEL_11
  1182. * @arg @ref LL_ADC_CHANNEL_12
  1183. * @arg @ref LL_ADC_CHANNEL_13
  1184. * @arg @ref LL_ADC_CHANNEL_14
  1185. * @arg @ref LL_ADC_CHANNEL_15 (1)
  1186. * @arg @ref LL_ADC_CHANNEL_16 (1)
  1187. * @arg @ref LL_ADC_CHANNEL_17 (1)
  1188. * @arg @ref LL_ADC_CHANNEL_18
  1189. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1190. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1191. * @arg @ref LL_ADC_CHANNEL_VBAT
  1192. *
  1193. * (1) On STM32G0, parameter can be set in ADC group sequencer
  1194. * only if sequencer is set in mode "not fully configurable",
  1195. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  1196. * @retval Value between Min_Data=0 and Max_Data=18
  1197. */
  1198. #define __LL_ADC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__) \
  1199. ((((__CHANNEL__) & ADC_CHANNEL_ID_BITFIELD_MASK) == 0UL) ? \
  1200. ( \
  1201. ((__CHANNEL__) & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS \
  1202. ) \
  1203. : \
  1204. ((((__CHANNEL__) & ADC_CHANNEL_0_BITFIELD) == ADC_CHANNEL_0_BITFIELD) ? (0UL) : \
  1205. ((((__CHANNEL__) & ADC_CHANNEL_1_BITFIELD) == ADC_CHANNEL_1_BITFIELD) ? (1UL) : \
  1206. ((((__CHANNEL__) & ADC_CHANNEL_2_BITFIELD) == ADC_CHANNEL_2_BITFIELD) ? (2UL) : \
  1207. ((((__CHANNEL__) & ADC_CHANNEL_3_BITFIELD) == ADC_CHANNEL_3_BITFIELD) ? (3UL) : \
  1208. ((((__CHANNEL__) & ADC_CHANNEL_4_BITFIELD) == ADC_CHANNEL_4_BITFIELD) ? (4UL) : \
  1209. ((((__CHANNEL__) & ADC_CHANNEL_5_BITFIELD) == ADC_CHANNEL_5_BITFIELD) ? (5UL) : \
  1210. ((((__CHANNEL__) & ADC_CHANNEL_6_BITFIELD) == ADC_CHANNEL_6_BITFIELD) ? (6UL) : \
  1211. ((((__CHANNEL__) & ADC_CHANNEL_7_BITFIELD) == ADC_CHANNEL_7_BITFIELD) ? (7UL) : \
  1212. ((((__CHANNEL__) & ADC_CHANNEL_8_BITFIELD) == ADC_CHANNEL_8_BITFIELD) ? (8UL) : \
  1213. ((((__CHANNEL__) & ADC_CHANNEL_9_BITFIELD) == ADC_CHANNEL_9_BITFIELD) ? (9UL) : \
  1214. ((((__CHANNEL__) & ADC_CHANNEL_10_BITFIELD) == ADC_CHANNEL_10_BITFIELD) ? (10UL) : \
  1215. ((((__CHANNEL__) & ADC_CHANNEL_11_BITFIELD) == ADC_CHANNEL_11_BITFIELD) ? (11UL) : \
  1216. ((((__CHANNEL__) & ADC_CHANNEL_12_BITFIELD) == ADC_CHANNEL_12_BITFIELD) ? (12UL) : \
  1217. ((((__CHANNEL__) & ADC_CHANNEL_13_BITFIELD) == ADC_CHANNEL_13_BITFIELD) ? (13UL) : \
  1218. ((((__CHANNEL__) & ADC_CHANNEL_14_BITFIELD) == ADC_CHANNEL_14_BITFIELD) ? (14UL) : \
  1219. ((((__CHANNEL__) & ADC_CHANNEL_15_BITFIELD) == ADC_CHANNEL_15_BITFIELD) ? (15UL) : \
  1220. ((((__CHANNEL__) & ADC_CHANNEL_16_BITFIELD) == ADC_CHANNEL_16_BITFIELD) ? (16UL) : \
  1221. ((((__CHANNEL__) & ADC_CHANNEL_17_BITFIELD) == ADC_CHANNEL_17_BITFIELD) ? (17UL) : \
  1222. ((((__CHANNEL__) & ADC_CHANNEL_18_BITFIELD) == ADC_CHANNEL_18_BITFIELD) ? (18UL) : \
  1223. (0UL)))))))))))))))))))))
  1224. /**
  1225. * @brief Helper macro to get ADC channel in literal format LL_ADC_CHANNEL_x
  1226. * from number in decimal format.
  1227. * @note Example:
  1228. * __LL_ADC_DECIMAL_NB_TO_CHANNEL(4)
  1229. * will return a data equivalent to "LL_ADC_CHANNEL_4".
  1230. * @param __DECIMAL_NB__ Value between Min_Data=0 and Max_Data=18
  1231. * @retval Returned value can be one of the following values:
  1232. * @arg @ref LL_ADC_CHANNEL_0
  1233. * @arg @ref LL_ADC_CHANNEL_1
  1234. * @arg @ref LL_ADC_CHANNEL_2
  1235. * @arg @ref LL_ADC_CHANNEL_3
  1236. * @arg @ref LL_ADC_CHANNEL_4
  1237. * @arg @ref LL_ADC_CHANNEL_5
  1238. * @arg @ref LL_ADC_CHANNEL_6
  1239. * @arg @ref LL_ADC_CHANNEL_7
  1240. * @arg @ref LL_ADC_CHANNEL_8
  1241. * @arg @ref LL_ADC_CHANNEL_9
  1242. * @arg @ref LL_ADC_CHANNEL_10
  1243. * @arg @ref LL_ADC_CHANNEL_11
  1244. * @arg @ref LL_ADC_CHANNEL_12
  1245. * @arg @ref LL_ADC_CHANNEL_13
  1246. * @arg @ref LL_ADC_CHANNEL_14
  1247. * @arg @ref LL_ADC_CHANNEL_15 (1)
  1248. * @arg @ref LL_ADC_CHANNEL_16 (1)
  1249. * @arg @ref LL_ADC_CHANNEL_17 (1)
  1250. * @arg @ref LL_ADC_CHANNEL_18
  1251. * @arg @ref LL_ADC_CHANNEL_VREFINT (2)
  1252. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (2)
  1253. * @arg @ref LL_ADC_CHANNEL_VBAT (2)
  1254. *
  1255. * (1) On STM32G0, parameter can be set in ADC group sequencer
  1256. * only if sequencer is set in mode "not fully configurable",
  1257. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().\n
  1258. * (2) For ADC channel read back from ADC register,
  1259. * comparison with internal channel parameter to be done
  1260. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  1261. */
  1262. #define __LL_ADC_DECIMAL_NB_TO_CHANNEL(__DECIMAL_NB__) \
  1263. (((__DECIMAL_NB__) << ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) | \
  1264. (ADC_CHSELR_CHSEL0 << (__DECIMAL_NB__)))
  1265. /**
  1266. * @brief Helper macro to determine whether the selected channel
  1267. * corresponds to literal definitions of driver.
  1268. * @note The different literal definitions of ADC channels are:
  1269. * - ADC internal channel:
  1270. * LL_ADC_CHANNEL_VREFINT, LL_ADC_CHANNEL_TEMPSENSOR, ...
  1271. * - ADC external channel (channel connected to a GPIO pin):
  1272. * LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...
  1273. * @note The channel parameter must be a value defined from literal
  1274. * definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT,
  1275. * LL_ADC_CHANNEL_TEMPSENSOR, ...),
  1276. * ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...),
  1277. * must not be a value from functions where a channel number is
  1278. * returned from ADC registers,
  1279. * because internal and external channels share the same channel
  1280. * number in ADC registers. The differentiation is made only with
  1281. * parameters definitions of driver.
  1282. * @param __CHANNEL__ This parameter can be one of the following values:
  1283. * @arg @ref LL_ADC_CHANNEL_0
  1284. * @arg @ref LL_ADC_CHANNEL_1
  1285. * @arg @ref LL_ADC_CHANNEL_2
  1286. * @arg @ref LL_ADC_CHANNEL_3
  1287. * @arg @ref LL_ADC_CHANNEL_4
  1288. * @arg @ref LL_ADC_CHANNEL_5
  1289. * @arg @ref LL_ADC_CHANNEL_6
  1290. * @arg @ref LL_ADC_CHANNEL_7
  1291. * @arg @ref LL_ADC_CHANNEL_8
  1292. * @arg @ref LL_ADC_CHANNEL_9
  1293. * @arg @ref LL_ADC_CHANNEL_10
  1294. * @arg @ref LL_ADC_CHANNEL_11
  1295. * @arg @ref LL_ADC_CHANNEL_12
  1296. * @arg @ref LL_ADC_CHANNEL_13
  1297. * @arg @ref LL_ADC_CHANNEL_14
  1298. * @arg @ref LL_ADC_CHANNEL_15 (1)
  1299. * @arg @ref LL_ADC_CHANNEL_16 (1)
  1300. * @arg @ref LL_ADC_CHANNEL_17 (1)
  1301. * @arg @ref LL_ADC_CHANNEL_18
  1302. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1303. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1304. * @arg @ref LL_ADC_CHANNEL_VBAT
  1305. *
  1306. * (1) On STM32G0, parameter can be set in ADC group sequencer
  1307. * only if sequencer is set in mode "not fully configurable",
  1308. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  1309. * @retval Value "0" if the channel corresponds to a parameter definition of a ADC external channel (channel
  1310. connected to a GPIO pin).
  1311. * Value "1" if the channel corresponds to a parameter definition of a ADC internal channel.
  1312. */
  1313. #define __LL_ADC_IS_CHANNEL_INTERNAL(__CHANNEL__) \
  1314. (((__CHANNEL__) & ADC_CHANNEL_ID_INTERNAL_CH_MASK) != 0UL)
  1315. /**
  1316. * @brief Helper macro to convert a channel defined from parameter
  1317. * definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT,
  1318. * LL_ADC_CHANNEL_TEMPSENSOR, ...),
  1319. * to its equivalent parameter definition of a ADC external channel
  1320. * (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...).
  1321. * @note The channel parameter can be, additionally to a value
  1322. * defined from parameter definition of a ADC internal channel
  1323. * (LL_ADC_CHANNEL_VREFINT, LL_ADC_CHANNEL_TEMPSENSOR, ...),
  1324. * a value defined from parameter definition of
  1325. * ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...)
  1326. * or a value from functions where a channel number is returned
  1327. * from ADC registers.
  1328. * @param __CHANNEL__ This parameter can be one of the following values:
  1329. * @arg @ref LL_ADC_CHANNEL_0
  1330. * @arg @ref LL_ADC_CHANNEL_1
  1331. * @arg @ref LL_ADC_CHANNEL_2
  1332. * @arg @ref LL_ADC_CHANNEL_3
  1333. * @arg @ref LL_ADC_CHANNEL_4
  1334. * @arg @ref LL_ADC_CHANNEL_5
  1335. * @arg @ref LL_ADC_CHANNEL_6
  1336. * @arg @ref LL_ADC_CHANNEL_7
  1337. * @arg @ref LL_ADC_CHANNEL_8
  1338. * @arg @ref LL_ADC_CHANNEL_9
  1339. * @arg @ref LL_ADC_CHANNEL_10
  1340. * @arg @ref LL_ADC_CHANNEL_11
  1341. * @arg @ref LL_ADC_CHANNEL_12
  1342. * @arg @ref LL_ADC_CHANNEL_13
  1343. * @arg @ref LL_ADC_CHANNEL_14
  1344. * @arg @ref LL_ADC_CHANNEL_15 (1)
  1345. * @arg @ref LL_ADC_CHANNEL_16 (1)
  1346. * @arg @ref LL_ADC_CHANNEL_17 (1)
  1347. * @arg @ref LL_ADC_CHANNEL_18
  1348. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1349. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1350. * @arg @ref LL_ADC_CHANNEL_VBAT
  1351. *
  1352. * (1) On STM32G0, parameter can be set in ADC group sequencer
  1353. * only if sequencer is set in mode "not fully configurable",
  1354. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  1355. * @retval Returned value can be one of the following values:
  1356. * @arg @ref LL_ADC_CHANNEL_0
  1357. * @arg @ref LL_ADC_CHANNEL_1
  1358. * @arg @ref LL_ADC_CHANNEL_2
  1359. * @arg @ref LL_ADC_CHANNEL_3
  1360. * @arg @ref LL_ADC_CHANNEL_4
  1361. * @arg @ref LL_ADC_CHANNEL_5
  1362. * @arg @ref LL_ADC_CHANNEL_6
  1363. * @arg @ref LL_ADC_CHANNEL_7
  1364. * @arg @ref LL_ADC_CHANNEL_8
  1365. * @arg @ref LL_ADC_CHANNEL_9
  1366. * @arg @ref LL_ADC_CHANNEL_10
  1367. * @arg @ref LL_ADC_CHANNEL_11
  1368. * @arg @ref LL_ADC_CHANNEL_12
  1369. * @arg @ref LL_ADC_CHANNEL_13
  1370. * @arg @ref LL_ADC_CHANNEL_14
  1371. * @arg @ref LL_ADC_CHANNEL_15
  1372. * @arg @ref LL_ADC_CHANNEL_16
  1373. * @arg @ref LL_ADC_CHANNEL_17
  1374. * @arg @ref LL_ADC_CHANNEL_18
  1375. */
  1376. #define __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL(__CHANNEL__) \
  1377. ((__CHANNEL__) & ~ADC_CHANNEL_ID_INTERNAL_CH_MASK)
  1378. /**
  1379. * @brief Helper macro to determine whether the internal channel
  1380. * selected is available on the ADC instance selected.
  1381. * @note The channel parameter must be a value defined from parameter
  1382. * definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT,
  1383. * LL_ADC_CHANNEL_TEMPSENSOR, ...),
  1384. * must not be a value defined from parameter definition of
  1385. * ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...)
  1386. * or a value from functions where a channel number is
  1387. * returned from ADC registers,
  1388. * because internal and external channels share the same channel
  1389. * number in ADC registers. The differentiation is made only with
  1390. * parameters definitions of driver.
  1391. * @param __ADC_INSTANCE__ ADC instance
  1392. * @param __CHANNEL__ This parameter can be one of the following values:
  1393. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1394. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1395. * @arg @ref LL_ADC_CHANNEL_VBAT
  1396. * @retval Value "0" if the internal channel selected is not available on the ADC instance selected.
  1397. * Value "1" if the internal channel selected is available on the ADC instance selected.
  1398. */
  1399. #define __LL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE(__ADC_INSTANCE__, __CHANNEL__) \
  1400. (((__CHANNEL__) == LL_ADC_CHANNEL_VREFINT) || \
  1401. ((__CHANNEL__) == LL_ADC_CHANNEL_TEMPSENSOR) || \
  1402. ((__CHANNEL__) == LL_ADC_CHANNEL_VBAT))
  1403. /**
  1404. * @brief Helper macro to define ADC analog watchdog parameter:
  1405. * define a single channel to monitor with analog watchdog
  1406. * from sequencer channel and groups definition.
  1407. * @note To be used with function @ref LL_ADC_SetAnalogWDMonitChannels().
  1408. * Example:
  1409. * LL_ADC_SetAnalogWDMonitChannels(
  1410. * ADC1, LL_ADC_AWD1,
  1411. * __LL_ADC_ANALOGWD_CHANNEL_GROUP(LL_ADC_CHANNEL4, LL_ADC_GROUP_REGULAR))
  1412. * @param __CHANNEL__ This parameter can be one of the following values:
  1413. * @arg @ref LL_ADC_CHANNEL_0
  1414. * @arg @ref LL_ADC_CHANNEL_1
  1415. * @arg @ref LL_ADC_CHANNEL_2
  1416. * @arg @ref LL_ADC_CHANNEL_3
  1417. * @arg @ref LL_ADC_CHANNEL_4
  1418. * @arg @ref LL_ADC_CHANNEL_5
  1419. * @arg @ref LL_ADC_CHANNEL_6
  1420. * @arg @ref LL_ADC_CHANNEL_7
  1421. * @arg @ref LL_ADC_CHANNEL_8
  1422. * @arg @ref LL_ADC_CHANNEL_9
  1423. * @arg @ref LL_ADC_CHANNEL_10
  1424. * @arg @ref LL_ADC_CHANNEL_11
  1425. * @arg @ref LL_ADC_CHANNEL_12
  1426. * @arg @ref LL_ADC_CHANNEL_13
  1427. * @arg @ref LL_ADC_CHANNEL_14
  1428. * @arg @ref LL_ADC_CHANNEL_15 (1)
  1429. * @arg @ref LL_ADC_CHANNEL_16 (1)
  1430. * @arg @ref LL_ADC_CHANNEL_17 (1)
  1431. * @arg @ref LL_ADC_CHANNEL_18
  1432. * @arg @ref LL_ADC_CHANNEL_VREFINT (2)
  1433. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (2)
  1434. * @arg @ref LL_ADC_CHANNEL_VBAT (2)
  1435. *
  1436. * (1) On STM32G0, parameter can be set in ADC group sequencer
  1437. * only if sequencer is set in mode "not fully configurable",
  1438. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().\n
  1439. * (2) For ADC channel read back from ADC register,
  1440. * comparison with internal channel parameter to be done
  1441. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  1442. * @param __GROUP__ This parameter can be one of the following values:
  1443. * @arg @ref LL_ADC_GROUP_REGULAR
  1444. * @retval Returned value can be one of the following values:
  1445. * @arg @ref LL_ADC_AWD_DISABLE
  1446. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG
  1447. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG
  1448. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG
  1449. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG
  1450. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG
  1451. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG
  1452. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG
  1453. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG
  1454. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG
  1455. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG
  1456. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG
  1457. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG
  1458. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG
  1459. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG
  1460. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG
  1461. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG
  1462. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG
  1463. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG
  1464. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG
  1465. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG
  1466. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG
  1467. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG
  1468. * @arg @ref LL_ADC_AWD_CH_VBAT_REG
  1469. */
  1470. #define __LL_ADC_ANALOGWD_CHANNEL_GROUP(__CHANNEL__, __GROUP__) \
  1471. (((__CHANNEL__) & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL)
  1472. /**
  1473. * @brief Helper macro to set the value of ADC analog watchdog threshold high
  1474. * or low in function of ADC resolution, when ADC resolution is
  1475. * different of 12 bits.
  1476. * @note To be used with function @ref LL_ADC_ConfigAnalogWDThresholds()
  1477. * or @ref LL_ADC_SetAnalogWDThresholds().
  1478. * Example, with a ADC resolution of 8 bits, to set the value of
  1479. * analog watchdog threshold high (on 8 bits):
  1480. * LL_ADC_SetAnalogWDThresholds
  1481. * (< ADCx param >,
  1482. * __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION(LL_ADC_RESOLUTION_8B, <threshold_value_8_bits>)
  1483. * );
  1484. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1485. * @arg @ref LL_ADC_RESOLUTION_12B
  1486. * @arg @ref LL_ADC_RESOLUTION_10B
  1487. * @arg @ref LL_ADC_RESOLUTION_8B
  1488. * @arg @ref LL_ADC_RESOLUTION_6B
  1489. * @param __AWD_THRESHOLD__ Value between Min_Data=0x000 and Max_Data=0xFFF
  1490. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1491. */
  1492. #define __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION(__ADC_RESOLUTION__, __AWD_THRESHOLD__) \
  1493. ((__AWD_THRESHOLD__) << ((__ADC_RESOLUTION__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U )))
  1494. /**
  1495. * @brief Helper macro to get the value of ADC analog watchdog threshold high
  1496. * or low in function of ADC resolution, when ADC resolution is
  1497. * different of 12 bits.
  1498. * @note To be used with function @ref LL_ADC_GetAnalogWDThresholds().
  1499. * Example, with a ADC resolution of 8 bits, to get the value of
  1500. * analog watchdog threshold high (on 8 bits):
  1501. * < threshold_value_6_bits > = __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION
  1502. * (LL_ADC_RESOLUTION_8B,
  1503. * LL_ADC_GetAnalogWDThresholds(<ADCx param>, LL_ADC_AWD_THRESHOLD_HIGH)
  1504. * );
  1505. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1506. * @arg @ref LL_ADC_RESOLUTION_12B
  1507. * @arg @ref LL_ADC_RESOLUTION_10B
  1508. * @arg @ref LL_ADC_RESOLUTION_8B
  1509. * @arg @ref LL_ADC_RESOLUTION_6B
  1510. * @param __AWD_THRESHOLD_12_BITS__ Value between Min_Data=0x000 and Max_Data=0xFFF
  1511. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1512. */
  1513. #define __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION(__ADC_RESOLUTION__, __AWD_THRESHOLD_12_BITS__) \
  1514. ((__AWD_THRESHOLD_12_BITS__) >> ((__ADC_RESOLUTION__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U )))
  1515. /**
  1516. * @brief Helper macro to get the ADC analog watchdog threshold high
  1517. * or low from raw value containing both thresholds concatenated.
  1518. * @note To be used with function @ref LL_ADC_GetAnalogWDThresholds().
  1519. * Example, to get analog watchdog threshold high from the register raw value:
  1520. * __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW(LL_ADC_AWD_THRESHOLD_HIGH, <raw_value_with_both_thresholds>);
  1521. * @param __AWD_THRESHOLD_TYPE__ This parameter can be one of the following values:
  1522. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  1523. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  1524. * @param __AWD_THRESHOLDS__ Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  1525. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1526. */
  1527. #define __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW(__AWD_THRESHOLD_TYPE__, __AWD_THRESHOLDS__) \
  1528. (((__AWD_THRESHOLDS__) >> (((__AWD_THRESHOLD_TYPE__) & ADC_AWD_TRX_BIT_HIGH_MASK) >> ADC_AWD_TRX_BIT_HIGH_SHIFT4)) \
  1529. & LL_ADC_AWD_THRESHOLD_LOW)
  1530. /**
  1531. * @brief Helper macro to select the ADC common instance
  1532. * to which is belonging the selected ADC instance.
  1533. * @note ADC common register instance can be used for:
  1534. * - Set parameters common to several ADC instances
  1535. * - Multimode (for devices with several ADC instances)
  1536. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1537. * @param __ADCx__ ADC instance
  1538. * @retval ADC common register instance
  1539. */
  1540. #define __LL_ADC_COMMON_INSTANCE(__ADCx__) \
  1541. (ADC1_COMMON)
  1542. /**
  1543. * @brief Helper macro to check if all ADC instances sharing the same
  1544. * ADC common instance are disabled.
  1545. * @note This check is required by functions with setting conditioned to
  1546. * ADC state:
  1547. * All ADC instances of the ADC common group must be disabled.
  1548. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1549. * @note On devices with only 1 ADC common instance, parameter of this macro
  1550. * is useless and can be ignored (parameter kept for compatibility
  1551. * with devices featuring several ADC common instances).
  1552. * @param __ADCXY_COMMON__ ADC common instance
  1553. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1554. * @retval Value "0" if all ADC instances sharing the same ADC common instance
  1555. * are disabled.
  1556. * Value "1" if at least one ADC instance sharing the same ADC common instance
  1557. * is enabled.
  1558. */
  1559. #define __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__ADCXY_COMMON__) \
  1560. LL_ADC_IsEnabled(ADC1)
  1561. /**
  1562. * @brief Helper macro to define the ADC conversion data full-scale digital
  1563. * value corresponding to the selected ADC resolution.
  1564. * @note ADC conversion data full-scale corresponds to voltage range
  1565. * determined by analog voltage references Vref+ and Vref-
  1566. * (refer to reference manual).
  1567. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1568. * @arg @ref LL_ADC_RESOLUTION_12B
  1569. * @arg @ref LL_ADC_RESOLUTION_10B
  1570. * @arg @ref LL_ADC_RESOLUTION_8B
  1571. * @arg @ref LL_ADC_RESOLUTION_6B
  1572. * @retval ADC conversion data full-scale digital value (unit: digital value of ADC conversion data)
  1573. */
  1574. #define __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \
  1575. (0xFFFUL >> ((__ADC_RESOLUTION__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1UL)))
  1576. /**
  1577. * @brief Helper macro to convert the ADC conversion data from
  1578. * a resolution to another resolution.
  1579. * @param __DATA__ ADC conversion data to be converted
  1580. * @param __ADC_RESOLUTION_CURRENT__ Resolution of the data to be converted
  1581. * This parameter can be one of the following values:
  1582. * @arg @ref LL_ADC_RESOLUTION_12B
  1583. * @arg @ref LL_ADC_RESOLUTION_10B
  1584. * @arg @ref LL_ADC_RESOLUTION_8B
  1585. * @arg @ref LL_ADC_RESOLUTION_6B
  1586. * @param __ADC_RESOLUTION_TARGET__ Resolution of the data after conversion
  1587. * This parameter can be one of the following values:
  1588. * @arg @ref LL_ADC_RESOLUTION_12B
  1589. * @arg @ref LL_ADC_RESOLUTION_10B
  1590. * @arg @ref LL_ADC_RESOLUTION_8B
  1591. * @arg @ref LL_ADC_RESOLUTION_6B
  1592. * @retval ADC conversion data to the requested resolution
  1593. */
  1594. #define __LL_ADC_CONVERT_DATA_RESOLUTION(__DATA__,\
  1595. __ADC_RESOLUTION_CURRENT__,\
  1596. __ADC_RESOLUTION_TARGET__) \
  1597. (((__DATA__) \
  1598. << ((__ADC_RESOLUTION_CURRENT__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1UL))) \
  1599. >> ((__ADC_RESOLUTION_TARGET__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1UL)) \
  1600. )
  1601. /**
  1602. * @brief Helper macro to calculate the voltage (unit: mVolt)
  1603. * corresponding to a ADC conversion data (unit: digital value).
  1604. * @note Analog reference voltage (Vref+) must be either known from
  1605. * user board environment or can be calculated using ADC measurement
  1606. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1607. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1608. * @param __ADC_DATA__ ADC conversion data (resolution 12 bits)
  1609. * (unit: digital value).
  1610. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1611. * @arg @ref LL_ADC_RESOLUTION_12B
  1612. * @arg @ref LL_ADC_RESOLUTION_10B
  1613. * @arg @ref LL_ADC_RESOLUTION_8B
  1614. * @arg @ref LL_ADC_RESOLUTION_6B
  1615. * @retval ADC conversion data equivalent voltage value (unit: mVolt)
  1616. */
  1617. #define __LL_ADC_CALC_DATA_TO_VOLTAGE(__VREFANALOG_VOLTAGE__,\
  1618. __ADC_DATA__,\
  1619. __ADC_RESOLUTION__) \
  1620. ((__ADC_DATA__) * (__VREFANALOG_VOLTAGE__) \
  1621. / __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \
  1622. )
  1623. /**
  1624. * @brief Helper macro to calculate analog reference voltage (Vref+)
  1625. * (unit: mVolt) from ADC conversion data of internal voltage
  1626. * reference VrefInt.
  1627. * @note Computation is using VrefInt calibration value
  1628. * stored in system memory for each device during production.
  1629. * @note This voltage depends on user board environment: voltage level
  1630. * connected to pin Vref+.
  1631. * On devices with small package, the pin Vref+ is not present
  1632. * and internally bonded to pin Vdda.
  1633. * @note On this STM32 series, calibration data of internal voltage reference
  1634. * VrefInt corresponds to a resolution of 12 bits,
  1635. * this is the recommended ADC resolution to convert voltage of
  1636. * internal voltage reference VrefInt.
  1637. * Otherwise, this macro performs the processing to scale
  1638. * ADC conversion data to 12 bits.
  1639. * @param __VREFINT_ADC_DATA__ ADC conversion data (resolution 12 bits)
  1640. * of internal voltage reference VrefInt (unit: digital value).
  1641. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1642. * @arg @ref LL_ADC_RESOLUTION_12B
  1643. * @arg @ref LL_ADC_RESOLUTION_10B
  1644. * @arg @ref LL_ADC_RESOLUTION_8B
  1645. * @arg @ref LL_ADC_RESOLUTION_6B
  1646. * @retval Analog reference voltage (unit: mV)
  1647. */
  1648. #define __LL_ADC_CALC_VREFANALOG_VOLTAGE(__VREFINT_ADC_DATA__,\
  1649. __ADC_RESOLUTION__) \
  1650. (((uint32_t)(*VREFINT_CAL_ADDR) * VREFINT_CAL_VREF) \
  1651. / __LL_ADC_CONVERT_DATA_RESOLUTION((__VREFINT_ADC_DATA__), \
  1652. (__ADC_RESOLUTION__), \
  1653. LL_ADC_RESOLUTION_12B) \
  1654. )
  1655. /**
  1656. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1657. * from ADC conversion data of internal temperature sensor.
  1658. * @note Computation is using temperature sensor calibration values
  1659. * stored in system memory for each device during production.
  1660. * @note Calculation formula:
  1661. * Temperature = ((TS_ADC_DATA - TS_CAL1)
  1662. * * (TS_CAL2_TEMP - TS_CAL1_TEMP))
  1663. * / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP
  1664. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1665. * Avg_Slope = (TS_CAL2 - TS_CAL1)
  1666. * / (TS_CAL2_TEMP - TS_CAL1_TEMP)
  1667. * TS_CAL1 = equivalent TS_ADC_DATA at temperature
  1668. * TEMP_DEGC_CAL1 (calibrated in factory)
  1669. * TS_CAL2 = equivalent TS_ADC_DATA at temperature
  1670. * TEMP_DEGC_CAL2 (calibrated in factory)
  1671. * Caution: Calculation relevancy under reserve that calibration
  1672. * parameters are correct (address and data).
  1673. * To calculate temperature using temperature sensor
  1674. * datasheet typical values (generic values less, therefore
  1675. * less accurate than calibrated values),
  1676. * use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS().
  1677. * @note As calculation input, the analog reference voltage (Vref+) must be
  1678. * defined as it impacts the ADC LSB equivalent voltage.
  1679. * @note Analog reference voltage (Vref+) must be either known from
  1680. * user board environment or can be calculated using ADC measurement
  1681. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1682. * @note On this STM32 series, calibration data of temperature sensor
  1683. * corresponds to a resolution of 12 bits,
  1684. * this is the recommended ADC resolution to convert voltage of
  1685. * temperature sensor.
  1686. * Otherwise, this macro performs the processing to scale
  1687. * ADC conversion data to 12 bits.
  1688. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1689. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal
  1690. * temperature sensor (unit: digital value).
  1691. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature
  1692. * sensor voltage has been measured.
  1693. * This parameter can be one of the following values:
  1694. * @arg @ref LL_ADC_RESOLUTION_12B
  1695. * @arg @ref LL_ADC_RESOLUTION_10B
  1696. * @arg @ref LL_ADC_RESOLUTION_8B
  1697. * @arg @ref LL_ADC_RESOLUTION_6B
  1698. * @retval Temperature (unit: degree Celsius)
  1699. * In case or error, value LL_ADC_TEMPERATURE_CALC_ERROR is returned (inconsistent temperature value)
  1700. */
  1701. #define __LL_ADC_CALC_TEMPERATURE(__VREFANALOG_VOLTAGE__,\
  1702. __TEMPSENSOR_ADC_DATA__,\
  1703. __ADC_RESOLUTION__)\
  1704. ((((int32_t)*TEMPSENSOR_CAL2_ADDR - (int32_t)*TEMPSENSOR_CAL1_ADDR) != 0) ? \
  1705. (((( ((int32_t)((__LL_ADC_CONVERT_DATA_RESOLUTION((__TEMPSENSOR_ADC_DATA__), \
  1706. (__ADC_RESOLUTION__), \
  1707. LL_ADC_RESOLUTION_12B) \
  1708. * (__VREFANALOG_VOLTAGE__)) \
  1709. / TEMPSENSOR_CAL_VREFANALOG) \
  1710. - (int32_t) *TEMPSENSOR_CAL1_ADDR) \
  1711. ) * (int32_t)(TEMPSENSOR_CAL2_TEMP - TEMPSENSOR_CAL1_TEMP) \
  1712. ) / (int32_t)((int32_t)*TEMPSENSOR_CAL2_ADDR - (int32_t)*TEMPSENSOR_CAL1_ADDR) \
  1713. ) + TEMPSENSOR_CAL1_TEMP \
  1714. ) \
  1715. : \
  1716. ((int32_t)LL_ADC_TEMPERATURE_CALC_ERROR) \
  1717. )
  1718. /**
  1719. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1720. * from ADC conversion data of internal temperature sensor.
  1721. * @note Computation is using temperature sensor typical values
  1722. * (refer to device datasheet).
  1723. * @note Calculation formula:
  1724. * Temperature = (TS_TYP_CALx_VOLT(uV) - TS_ADC_DATA * Conversion_uV)
  1725. * / Avg_Slope + CALx_TEMP
  1726. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1727. * (unit: digital value)
  1728. * Avg_Slope = temperature sensor slope
  1729. * (unit: uV/Degree Celsius)
  1730. * TS_TYP_CALx_VOLT = temperature sensor digital value at
  1731. * temperature CALx_TEMP (unit: mV)
  1732. * Caution: Calculation relevancy under reserve the temperature sensor
  1733. * of the current device has characteristics in line with
  1734. * datasheet typical values.
  1735. * If temperature sensor calibration values are available on
  1736. * on this device (presence of macro __LL_ADC_CALC_TEMPERATURE()),
  1737. * temperature calculation will be more accurate using
  1738. * helper macro @ref __LL_ADC_CALC_TEMPERATURE().
  1739. * @note As calculation input, the analog reference voltage (Vref+) must be
  1740. * defined as it impacts the ADC LSB equivalent voltage.
  1741. * @note Analog reference voltage (Vref+) must be either known from
  1742. * user board environment or can be calculated using ADC measurement
  1743. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1744. * @note ADC measurement data must correspond to a resolution of 12 bits
  1745. * (full scale digital value 4095). If not the case, the data must be
  1746. * preliminarily rescaled to an equivalent resolution of 12 bits.
  1747. * @param __TEMPSENSOR_TYP_AVGSLOPE__ Device datasheet data: Temperature sensor slope typical value
  1748. (unit: uV/DegCelsius).
  1749. * On STM32G0, refer to device datasheet parameter "Avg_Slope".
  1750. * @param __TEMPSENSOR_TYP_CALX_V__ Device datasheet data: Temperature sensor voltage typical value
  1751. (at temperature and Vref+ defined in parameters below) (unit: mV).
  1752. * On STM32G0, refer to datasheet parameter "V30" (corresponding to TS_CAL1).
  1753. * @param __TEMPSENSOR_CALX_TEMP__ Device datasheet data: Temperature at which temperature sensor voltage
  1754. (see parameter above) is corresponding (unit: degree Celsius)
  1755. * @param __VREFANALOG_VOLTAGE__ Analog voltage reference (Vref+) value (unit: mV)
  1756. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal temperature sensor (unit: digital value).
  1757. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature sensor voltage has been measured.
  1758. * This parameter can be one of the following values:
  1759. * @arg @ref LL_ADC_RESOLUTION_12B
  1760. * @arg @ref LL_ADC_RESOLUTION_10B
  1761. * @arg @ref LL_ADC_RESOLUTION_8B
  1762. * @arg @ref LL_ADC_RESOLUTION_6B
  1763. * @retval Temperature (unit: degree Celsius)
  1764. */
  1765. #define __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(__TEMPSENSOR_TYP_AVGSLOPE__,\
  1766. __TEMPSENSOR_TYP_CALX_V__,\
  1767. __TEMPSENSOR_CALX_TEMP__,\
  1768. __VREFANALOG_VOLTAGE__,\
  1769. __TEMPSENSOR_ADC_DATA__,\
  1770. __ADC_RESOLUTION__) \
  1771. (((((int32_t)((((__TEMPSENSOR_ADC_DATA__) * (__VREFANALOG_VOLTAGE__)) \
  1772. / __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__)) \
  1773. * 1000UL) \
  1774. - \
  1775. (int32_t)(((__TEMPSENSOR_TYP_CALX_V__)) \
  1776. * 1000UL) \
  1777. ) \
  1778. ) / (int32_t)(__TEMPSENSOR_TYP_AVGSLOPE__) \
  1779. ) + (int32_t)(__TEMPSENSOR_CALX_TEMP__) \
  1780. )
  1781. /**
  1782. * @}
  1783. */
  1784. /**
  1785. * @}
  1786. */
  1787. /* Exported functions --------------------------------------------------------*/
  1788. /** @defgroup ADC_LL_Exported_Functions ADC Exported Functions
  1789. * @{
  1790. */
  1791. /** @defgroup ADC_LL_EF_DMA_Management ADC DMA management
  1792. * @{
  1793. */
  1794. /* Note: LL ADC functions to set DMA transfer are located into sections of */
  1795. /* configuration of ADC instance, groups and multimode (if available): */
  1796. /* @ref LL_ADC_REG_SetDMATransfer(), ... */
  1797. /**
  1798. * @brief Function to help to configure DMA transfer from ADC: retrieve the
  1799. * ADC register address from ADC instance and a list of ADC registers
  1800. * intended to be used (most commonly) with DMA transfer.
  1801. * @note These ADC registers are data registers:
  1802. * when ADC conversion data is available in ADC data registers,
  1803. * ADC generates a DMA transfer request.
  1804. * @note This macro is intended to be used with LL DMA driver, refer to
  1805. * function "LL_DMA_ConfigAddresses()".
  1806. * Example:
  1807. * LL_DMA_ConfigAddresses(DMA1,
  1808. * LL_DMA_CHANNEL_1,
  1809. * LL_ADC_DMA_GetRegAddr(ADC1, LL_ADC_DMA_REG_REGULAR_DATA),
  1810. * (uint32_t)&< array or variable >,
  1811. * LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
  1812. * @note For devices with several ADC: in multimode, some devices
  1813. * use a different data register outside of ADC instance scope
  1814. * (common data register). This macro manages this register difference,
  1815. * only ADC instance has to be set as parameter.
  1816. * @rmtoll DR DATA LL_ADC_DMA_GetRegAddr
  1817. * @param ADCx ADC instance
  1818. * @param Register This parameter can be one of the following values:
  1819. * @arg @ref LL_ADC_DMA_REG_REGULAR_DATA
  1820. * @retval ADC register address
  1821. */
  1822. __STATIC_INLINE uint32_t LL_ADC_DMA_GetRegAddr(const ADC_TypeDef *ADCx, uint32_t Register)
  1823. {
  1824. /* Prevent unused argument(s) compilation warning */
  1825. (void)(Register);
  1826. /* Retrieve address of register DR */
  1827. return (uint32_t) &(ADCx->DR);
  1828. }
  1829. /**
  1830. * @}
  1831. */
  1832. /** @defgroup ADC_LL_EF_Configuration_ADC_Common Configuration of ADC hierarchical scope: common to several
  1833. * ADC instances
  1834. * @{
  1835. */
  1836. /**
  1837. * @brief Set parameter common to several ADC: Clock source and prescaler.
  1838. * @note On this STM32 series, setting of this feature is conditioned to
  1839. * ADC state:
  1840. * All ADC instances of the ADC common group must be disabled.
  1841. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1842. * ADC instance or by using helper macro helper macro
  1843. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  1844. * @rmtoll CCR PRESC LL_ADC_SetCommonClock
  1845. * @param ADCxy_COMMON ADC common instance
  1846. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1847. * @param CommonClock This parameter can be one of the following values:
  1848. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV1 (1)
  1849. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV2 (1)
  1850. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV4 (1)
  1851. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV6 (1)
  1852. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV8 (1)
  1853. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV10 (1)
  1854. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV12 (1)
  1855. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV16 (1)
  1856. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV32 (1)
  1857. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV64 (1)
  1858. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV128 (1)
  1859. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV256 (1)
  1860. *
  1861. * (1) ADC common clock asynchronous prescaler is applied to
  1862. * each ADC instance if the corresponding ADC instance clock
  1863. * is set to clock source asynchronous.
  1864. * (refer to function @ref LL_ADC_SetClock() ).
  1865. * @retval None
  1866. */
  1867. __STATIC_INLINE void LL_ADC_SetCommonClock(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t CommonClock)
  1868. {
  1869. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_PRESC, CommonClock);
  1870. }
  1871. /**
  1872. * @brief Get parameter common to several ADC: Clock source and prescaler.
  1873. * @rmtoll CCR PRESC LL_ADC_GetCommonClock
  1874. * @param ADCxy_COMMON ADC common instance
  1875. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1876. * @retval Returned value can be one of the following values:
  1877. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV1 (1)
  1878. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV2 (1)
  1879. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV4 (1)
  1880. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV6 (1)
  1881. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV8 (1)
  1882. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV10 (1)
  1883. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV12 (1)
  1884. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV16 (1)
  1885. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV32 (1)
  1886. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV64 (1)
  1887. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV128 (1)
  1888. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV256 (1)
  1889. *
  1890. * (1) ADC common clock asynchronous prescaler is applied to
  1891. * each ADC instance if the corresponding ADC instance clock
  1892. * is set to clock source asynchronous.
  1893. * (refer to function @ref LL_ADC_SetClock() ).
  1894. */
  1895. __STATIC_INLINE uint32_t LL_ADC_GetCommonClock(const ADC_Common_TypeDef *ADCxy_COMMON)
  1896. {
  1897. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_PRESC));
  1898. }
  1899. /**
  1900. * @brief Legacy feature, useless on STM32G0 (ADC common clock low frequency
  1901. mode is automatically managed by ADC peripheral on STM32G0).
  1902. Function kept for legacy purpose.
  1903. * @note On this STM32 series, setting of this feature is conditioned to
  1904. * ADC state:
  1905. * ADC must be disabled or enabled without conversion on going
  1906. * on group regular.
  1907. * @rmtoll CCR LFMEN LL_ADC_SetCommonFrequencyMode
  1908. * @param ADCxy_COMMON ADC common instance
  1909. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1910. * @param CommonFrequencyMode This parameter can be one of the following values:
  1911. * @arg @ref LL_ADC_CLOCK_FREQ_MODE_HIGH
  1912. * @arg @ref LL_ADC_CLOCK_FREQ_MODE_LOW
  1913. * @retval None
  1914. */
  1915. __STATIC_INLINE void LL_ADC_SetCommonFrequencyMode(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t CommonFrequencyMode)
  1916. {
  1917. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_LFMEN, CommonFrequencyMode);
  1918. }
  1919. /**
  1920. * @brief Legacy feature, useless on STM32G0 (ADC common clock low frequency
  1921. mode is automatically managed by ADC peripheral on STM32G0).
  1922. Function kept for legacy purpose.
  1923. * @rmtoll CCR LFMEN LL_ADC_GetCommonFrequencyMode
  1924. * @param ADCxy_COMMON ADC common instance
  1925. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1926. * @retval Returned value can be one of the following values:
  1927. * @arg @ref LL_ADC_CLOCK_FREQ_MODE_HIGH
  1928. * @arg @ref LL_ADC_CLOCK_FREQ_MODE_LOW
  1929. */
  1930. __STATIC_INLINE uint32_t LL_ADC_GetCommonFrequencyMode(const ADC_Common_TypeDef *ADCxy_COMMON)
  1931. {
  1932. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_LFMEN));
  1933. }
  1934. /**
  1935. * @brief Set parameter common to several ADC: measurement path to
  1936. * internal channels (VrefInt, temperature sensor, ...).
  1937. * Configure all paths (overwrite current configuration).
  1938. * @note One or several values can be selected.
  1939. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1940. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1941. * The values not selected are removed from configuration.
  1942. * @note Stabilization time of measurement path to internal channel:
  1943. * After enabling internal paths, before starting ADC conversion,
  1944. * a delay is required for internal voltage reference and
  1945. * temperature sensor stabilization time.
  1946. * Refer to device datasheet.
  1947. * Refer to literal @ref LL_ADC_DELAY_VREFINT_STAB_US.
  1948. * Refer to literals @ref LL_ADC_DELAY_TEMPSENSOR_STAB_US,
  1949. * @ref LL_ADC_DELAY_TEMPSENSOR_BUFFER_STAB_US.
  1950. * @note ADC internal channel sampling time constraint:
  1951. * For ADC conversion of internal channels,
  1952. * a sampling time minimum value is required.
  1953. * Refer to device datasheet.
  1954. * @note On this STM32 series, setting of this feature is conditioned to
  1955. * ADC state:
  1956. * All ADC instances of the ADC common group must be disabled.
  1957. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1958. * ADC instance or by using helper macro helper macro
  1959. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  1960. * @rmtoll CCR VREFEN LL_ADC_SetCommonPathInternalCh\n
  1961. * CCR TSEN LL_ADC_SetCommonPathInternalCh\n
  1962. * CCR VBATEN LL_ADC_SetCommonPathInternalCh
  1963. * @param ADCxy_COMMON ADC common instance
  1964. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1965. * @param PathInternal This parameter can be a combination of the following values:
  1966. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  1967. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  1968. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR
  1969. * @arg @ref LL_ADC_PATH_INTERNAL_VBAT
  1970. * @retval None
  1971. */
  1972. __STATIC_INLINE void LL_ADC_SetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t PathInternal)
  1973. {
  1974. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN | ADC_CCR_VBATEN, PathInternal);
  1975. }
  1976. /**
  1977. * @brief Set parameter common to several ADC: measurement path to
  1978. * internal channels (VrefInt, temperature sensor, ...).
  1979. * Add paths to the current configuration.
  1980. * @note One or several values can be selected.
  1981. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1982. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1983. * @note Stabilization time of measurement path to internal channel:
  1984. * After enabling internal paths, before starting ADC conversion,
  1985. * a delay is required for internal voltage reference and
  1986. * temperature sensor stabilization time.
  1987. * Refer to device datasheet.
  1988. * Refer to literal @ref LL_ADC_DELAY_VREFINT_STAB_US.
  1989. * Refer to literals @ref LL_ADC_DELAY_TEMPSENSOR_STAB_US,
  1990. * @ref LL_ADC_DELAY_TEMPSENSOR_BUFFER_STAB_US.
  1991. * @note ADC internal channel sampling time constraint:
  1992. * For ADC conversion of internal channels,
  1993. * a sampling time minimum value is required.
  1994. * Refer to device datasheet.
  1995. * @note On this STM32 series, setting of this feature is conditioned to
  1996. * ADC state:
  1997. * All ADC instances of the ADC common group must be disabled.
  1998. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1999. * ADC instance or by using helper macro helper macro
  2000. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  2001. * @rmtoll CCR VREFEN LL_ADC_SetCommonPathInternalChAdd\n
  2002. * CCR TSEN LL_ADC_SetCommonPathInternalChAdd\n
  2003. * CCR VBATEN LL_ADC_SetCommonPathInternalChAdd
  2004. * @param ADCxy_COMMON ADC common instance
  2005. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  2006. * @param PathInternal This parameter can be a combination of the following values:
  2007. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  2008. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  2009. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR
  2010. * @arg @ref LL_ADC_PATH_INTERNAL_VBAT
  2011. * @retval None
  2012. */
  2013. __STATIC_INLINE void LL_ADC_SetCommonPathInternalChAdd(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t PathInternal)
  2014. {
  2015. SET_BIT(ADCxy_COMMON->CCR, PathInternal);
  2016. }
  2017. /**
  2018. * @brief Set parameter common to several ADC: measurement path to
  2019. * internal channels (VrefInt, temperature sensor, ...).
  2020. * Remove paths to the current configuration.
  2021. * @note One or several values can be selected.
  2022. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  2023. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  2024. * @note On this STM32 series, setting of this feature is conditioned to
  2025. * ADC state:
  2026. * All ADC instances of the ADC common group must be disabled.
  2027. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  2028. * ADC instance or by using helper macro helper macro
  2029. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  2030. * @rmtoll CCR VREFEN LL_ADC_SetCommonPathInternalChRem\n
  2031. * CCR TSEN LL_ADC_SetCommonPathInternalChRem\n
  2032. * CCR VBATEN LL_ADC_SetCommonPathInternalChRem
  2033. * @param ADCxy_COMMON ADC common instance
  2034. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  2035. * @param PathInternal This parameter can be a combination of the following values:
  2036. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  2037. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  2038. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR
  2039. * @arg @ref LL_ADC_PATH_INTERNAL_VBAT
  2040. * @retval None
  2041. */
  2042. __STATIC_INLINE void LL_ADC_SetCommonPathInternalChRem(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t PathInternal)
  2043. {
  2044. CLEAR_BIT(ADCxy_COMMON->CCR, PathInternal);
  2045. }
  2046. /**
  2047. * @brief Get parameter common to several ADC: measurement path to internal
  2048. * channels (VrefInt, temperature sensor, ...).
  2049. * @note One or several values can be selected.
  2050. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  2051. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  2052. * @rmtoll CCR VREFEN LL_ADC_GetCommonPathInternalCh\n
  2053. * CCR TSEN LL_ADC_GetCommonPathInternalCh\n
  2054. * CCR VBATEN LL_ADC_GetCommonPathInternalCh
  2055. * @param ADCxy_COMMON ADC common instance
  2056. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  2057. * @retval Returned value can be a combination of the following values:
  2058. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  2059. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  2060. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR
  2061. * @arg @ref LL_ADC_PATH_INTERNAL_VBAT
  2062. */
  2063. __STATIC_INLINE uint32_t LL_ADC_GetCommonPathInternalCh(const ADC_Common_TypeDef *ADCxy_COMMON)
  2064. {
  2065. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN | ADC_CCR_VBATEN));
  2066. }
  2067. /**
  2068. * @}
  2069. */
  2070. /** @defgroup ADC_LL_EF_Configuration_ADC_Instance Configuration of ADC hierarchical scope: ADC instance
  2071. * @{
  2072. */
  2073. /**
  2074. * @brief Set ADC instance clock source and prescaler.
  2075. * @note On this STM32 series, setting of this feature is conditioned to
  2076. * ADC state:
  2077. * ADC must be disabled.
  2078. * @rmtoll CFGR2 CKMODE LL_ADC_SetClock
  2079. * @param ADCx ADC instance
  2080. * @param ClockSource This parameter can be one of the following values:
  2081. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV4
  2082. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV2
  2083. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV1 (2)
  2084. * @arg @ref LL_ADC_CLOCK_ASYNC (1)
  2085. *
  2086. * (1) Asynchronous clock prescaler can be configured using
  2087. * function @ref LL_ADC_SetCommonClock().\n
  2088. * (2) Caution: This parameter has some clock ratio constraints:
  2089. * This configuration must be enabled only if PCLK has a 50%
  2090. * duty clock cycle (APB prescaler configured inside the RCC
  2091. * must be bypassed and the system clock must by 50% duty
  2092. * cycle).
  2093. * Refer to reference manual.
  2094. * @retval None
  2095. */
  2096. __STATIC_INLINE void LL_ADC_SetClock(ADC_TypeDef *ADCx, uint32_t ClockSource)
  2097. {
  2098. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_CKMODE, ClockSource);
  2099. }
  2100. /**
  2101. * @brief Get ADC instance clock source and prescaler.
  2102. * @rmtoll CFGR2 CKMODE LL_ADC_GetClock
  2103. * @param ADCx ADC instance
  2104. * @retval Returned value can be one of the following values:
  2105. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV4
  2106. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV2
  2107. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV1 (2)
  2108. * @arg @ref LL_ADC_CLOCK_ASYNC (1)
  2109. *
  2110. * (1) Asynchronous clock prescaler can be retrieved using
  2111. * function @ref LL_ADC_GetCommonClock().\n
  2112. * (2) Caution: This parameter has some clock ratio constraints:
  2113. * This configuration must be enabled only if PCLK has a 50%
  2114. * duty clock cycle (APB prescaler configured inside the RCC
  2115. * must be bypassed and the system clock must by 50% duty
  2116. * cycle).
  2117. * Refer to reference manual.
  2118. */
  2119. __STATIC_INLINE uint32_t LL_ADC_GetClock(const ADC_TypeDef *ADCx)
  2120. {
  2121. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_CKMODE));
  2122. }
  2123. /**
  2124. * @brief Set ADC calibration factor in the mode single-ended
  2125. * or differential (for devices with differential mode available).
  2126. * @note This function is intended to set calibration parameters
  2127. * without having to perform a new calibration using
  2128. * @ref LL_ADC_StartCalibration().
  2129. * @note On this STM32 series, setting of this feature is conditioned to
  2130. * ADC state:
  2131. * ADC must be enabled, without calibration on going, without conversion
  2132. * on going on group regular.
  2133. * @rmtoll CALFACT CALFACT LL_ADC_SetCalibrationFactor
  2134. * @param ADCx ADC instance
  2135. * @param CalibrationFactor Value between Min_Data=0x00 and Max_Data=0x7F
  2136. * @retval None
  2137. */
  2138. __STATIC_INLINE void LL_ADC_SetCalibrationFactor(ADC_TypeDef *ADCx, uint32_t CalibrationFactor)
  2139. {
  2140. MODIFY_REG(ADCx->CALFACT,
  2141. ADC_CALFACT_CALFACT,
  2142. CalibrationFactor);
  2143. }
  2144. /**
  2145. * @brief Get ADC calibration factor in the mode single-ended
  2146. * or differential (for devices with differential mode available).
  2147. * @note Calibration factors are set by hardware after performing
  2148. * a calibration run using function @ref LL_ADC_StartCalibration().
  2149. * @rmtoll CALFACT CALFACT LL_ADC_GetCalibrationFactor
  2150. * @param ADCx ADC instance
  2151. * @retval Value between Min_Data=0x00 and Max_Data=0x7F
  2152. */
  2153. __STATIC_INLINE uint32_t LL_ADC_GetCalibrationFactor(const ADC_TypeDef *ADCx)
  2154. {
  2155. return (uint32_t)(READ_BIT(ADCx->CALFACT, ADC_CALFACT_CALFACT));
  2156. }
  2157. /**
  2158. * @brief Set ADC resolution.
  2159. * Refer to reference manual for alignments formats
  2160. * dependencies to ADC resolutions.
  2161. * @note On this STM32 series, setting of this feature is conditioned to
  2162. * ADC state:
  2163. * ADC must be disabled.
  2164. * @rmtoll CFGR1 RES LL_ADC_SetResolution
  2165. * @param ADCx ADC instance
  2166. * @param Resolution This parameter can be one of the following values:
  2167. * @arg @ref LL_ADC_RESOLUTION_12B
  2168. * @arg @ref LL_ADC_RESOLUTION_10B
  2169. * @arg @ref LL_ADC_RESOLUTION_8B
  2170. * @arg @ref LL_ADC_RESOLUTION_6B
  2171. * @retval None
  2172. */
  2173. __STATIC_INLINE void LL_ADC_SetResolution(ADC_TypeDef *ADCx, uint32_t Resolution)
  2174. {
  2175. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_RES, Resolution);
  2176. }
  2177. /**
  2178. * @brief Get ADC resolution.
  2179. * Refer to reference manual for alignments formats
  2180. * dependencies to ADC resolutions.
  2181. * @rmtoll CFGR1 RES LL_ADC_GetResolution
  2182. * @param ADCx ADC instance
  2183. * @retval Returned value can be one of the following values:
  2184. * @arg @ref LL_ADC_RESOLUTION_12B
  2185. * @arg @ref LL_ADC_RESOLUTION_10B
  2186. * @arg @ref LL_ADC_RESOLUTION_8B
  2187. * @arg @ref LL_ADC_RESOLUTION_6B
  2188. */
  2189. __STATIC_INLINE uint32_t LL_ADC_GetResolution(const ADC_TypeDef *ADCx)
  2190. {
  2191. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_RES));
  2192. }
  2193. /**
  2194. * @brief Set ADC conversion data alignment.
  2195. * @note Refer to reference manual for alignments formats
  2196. * dependencies to ADC resolutions.
  2197. * @note On this STM32 series, setting of this feature is conditioned to
  2198. * ADC state:
  2199. * ADC must be disabled.
  2200. * @rmtoll CFGR1 ALIGN LL_ADC_SetDataAlignment
  2201. * @param ADCx ADC instance
  2202. * @param DataAlignment This parameter can be one of the following values:
  2203. * @arg @ref LL_ADC_DATA_ALIGN_RIGHT
  2204. * @arg @ref LL_ADC_DATA_ALIGN_LEFT
  2205. * @retval None
  2206. */
  2207. __STATIC_INLINE void LL_ADC_SetDataAlignment(ADC_TypeDef *ADCx, uint32_t DataAlignment)
  2208. {
  2209. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_ALIGN, DataAlignment);
  2210. }
  2211. /**
  2212. * @brief Get ADC conversion data alignment.
  2213. * @note Refer to reference manual for alignments formats
  2214. * dependencies to ADC resolutions.
  2215. * @rmtoll CFGR1 ALIGN LL_ADC_GetDataAlignment
  2216. * @param ADCx ADC instance
  2217. * @retval Returned value can be one of the following values:
  2218. * @arg @ref LL_ADC_DATA_ALIGN_RIGHT
  2219. * @arg @ref LL_ADC_DATA_ALIGN_LEFT
  2220. */
  2221. __STATIC_INLINE uint32_t LL_ADC_GetDataAlignment(const ADC_TypeDef *ADCx)
  2222. {
  2223. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_ALIGN));
  2224. }
  2225. /**
  2226. * @brief Set ADC low power mode.
  2227. * @note Description of ADC low power modes:
  2228. * - ADC low power mode "auto wait": Dynamic low power mode,
  2229. * ADC conversions occurrences are limited to the minimum necessary
  2230. * in order to reduce power consumption.
  2231. * New ADC conversion starts only when the previous
  2232. * unitary conversion data (for ADC group regular)
  2233. * has been retrieved by user software.
  2234. * In the meantime, ADC remains idle: does not performs any
  2235. * other conversion.
  2236. * This mode allows to automatically adapt the ADC conversions
  2237. * triggers to the speed of the software that reads the data.
  2238. * Moreover, this avoids risk of overrun for low frequency
  2239. * applications.
  2240. * How to use this low power mode:
  2241. * - It is not recommended to use with interruption or DMA
  2242. * since these modes have to clear immediately the EOC flag
  2243. * (by CPU to free the IRQ pending event or by DMA).
  2244. * Auto wait will work but fort a very short time, discarding
  2245. * its intended benefit (except specific case of high load of CPU
  2246. * or DMA transfers which can justify usage of auto wait).
  2247. * - Do use with polling: 1. Start conversion,
  2248. * 2. Later on, when conversion data is needed: poll for end of
  2249. * conversion to ensure that conversion is completed and
  2250. * retrieve ADC conversion data. This will trig another
  2251. * ADC conversion start.
  2252. * - ADC low power mode "auto power-off" (feature available on
  2253. * this device if parameter LL_ADC_LP_AUTOPOWEROFF is available):
  2254. * the ADC automatically powers-off after a conversion and
  2255. * automatically wakes up when a new conversion is triggered
  2256. * (with startup time between trigger and start of sampling).
  2257. * This feature can be combined with low power mode "auto wait".
  2258. * @note With ADC low power mode "auto wait", the ADC conversion data read
  2259. * is corresponding to previous ADC conversion start, independently
  2260. * of delay during which ADC was idle.
  2261. * Therefore, the ADC conversion data may be outdated: does not
  2262. * correspond to the current voltage level on the selected
  2263. * ADC channel.
  2264. * @note On this STM32 series, setting of this feature is conditioned to
  2265. * ADC state:
  2266. * ADC must be disabled.
  2267. * @rmtoll CFGR1 WAIT LL_ADC_SetLowPowerMode\n
  2268. * CFGR1 AUTOFF LL_ADC_SetLowPowerMode
  2269. * @param ADCx ADC instance
  2270. * @param LowPowerMode This parameter can be one of the following values:
  2271. * @arg @ref LL_ADC_LP_MODE_NONE
  2272. * @arg @ref LL_ADC_LP_AUTOWAIT
  2273. * @arg @ref LL_ADC_LP_AUTOPOWEROFF
  2274. * @arg @ref LL_ADC_LP_AUTOWAIT_AUTOPOWEROFF
  2275. * @retval None
  2276. */
  2277. __STATIC_INLINE void LL_ADC_SetLowPowerMode(ADC_TypeDef *ADCx, uint32_t LowPowerMode)
  2278. {
  2279. MODIFY_REG(ADCx->CFGR1, (ADC_CFGR1_WAIT | ADC_CFGR1_AUTOFF), LowPowerMode);
  2280. }
  2281. /**
  2282. * @brief Get ADC low power mode:
  2283. * @note Description of ADC low power modes:
  2284. * - ADC low power mode "auto wait": Dynamic low power mode,
  2285. * ADC conversions occurrences are limited to the minimum necessary
  2286. * in order to reduce power consumption.
  2287. * New ADC conversion starts only when the previous
  2288. * unitary conversion data (for ADC group regular)
  2289. * has been retrieved by user software.
  2290. * In the meantime, ADC remains idle: does not performs any
  2291. * other conversion.
  2292. * This mode allows to automatically adapt the ADC conversions
  2293. * triggers to the speed of the software that reads the data.
  2294. * Moreover, this avoids risk of overrun for low frequency
  2295. * applications.
  2296. * How to use this low power mode:
  2297. * - It is not recommended to use with interruption or DMA
  2298. * since these modes have to clear immediately the EOC flag
  2299. * (by CPU to free the IRQ pending event or by DMA).
  2300. * Auto wait will work but fort a very short time, discarding
  2301. * its intended benefit (except specific case of high load of CPU
  2302. * or DMA transfers which can justify usage of auto wait).
  2303. * - Do use with polling: 1. Start conversion,
  2304. * 2. Later on, when conversion data is needed: poll for end of
  2305. * conversion to ensure that conversion is completed and
  2306. * retrieve ADC conversion data. This will trig another
  2307. * ADC conversion start.
  2308. * - ADC low power mode "auto power-off" (feature available on
  2309. * this device if parameter LL_ADC_LP_AUTOPOWEROFF is available):
  2310. * the ADC automatically powers-off after a conversion and
  2311. * automatically wakes up when a new conversion is triggered
  2312. * (with startup time between trigger and start of sampling).
  2313. * This feature can be combined with low power mode "auto wait".
  2314. * @note With ADC low power mode "auto wait", the ADC conversion data read
  2315. * is corresponding to previous ADC conversion start, independently
  2316. * of delay during which ADC was idle.
  2317. * Therefore, the ADC conversion data may be outdated: does not
  2318. * correspond to the current voltage level on the selected
  2319. * ADC channel.
  2320. * @rmtoll CFGR1 WAIT LL_ADC_GetLowPowerMode\n
  2321. * CFGR1 AUTOFF LL_ADC_GetLowPowerMode
  2322. * @param ADCx ADC instance
  2323. * @retval Returned value can be one of the following values:
  2324. * @arg @ref LL_ADC_LP_MODE_NONE
  2325. * @arg @ref LL_ADC_LP_AUTOWAIT
  2326. * @arg @ref LL_ADC_LP_AUTOPOWEROFF
  2327. * @arg @ref LL_ADC_LP_AUTOWAIT_AUTOPOWEROFF
  2328. */
  2329. __STATIC_INLINE uint32_t LL_ADC_GetLowPowerMode(const ADC_TypeDef *ADCx)
  2330. {
  2331. return (uint32_t)(READ_BIT(ADCx->CFGR1, (ADC_CFGR1_WAIT | ADC_CFGR1_AUTOFF)));
  2332. }
  2333. /**
  2334. * @brief Set ADC trigger frequency mode.
  2335. * @note ADC trigger frequency mode must be set to low frequency when
  2336. * a duration is exceeded before ADC conversion start trigger event
  2337. * (between ADC enable and ADC conversion start trigger event
  2338. * or between two ADC conversion start trigger event).
  2339. * Duration value: Refer to device datasheet, parameter "tIdle".
  2340. * @note When ADC trigger frequency mode is set to low frequency,
  2341. * some rearm cycles are inserted before performing ADC conversion
  2342. * start, inducing a delay of 2 ADC clock cycles.
  2343. * @note Usage of ADC trigger frequency mode with ADC low power mode:
  2344. * - Low power mode auto wait: Only the first ADC conversion
  2345. * start trigger inserts the rearm delay.
  2346. * - Low power mode auto power-off: ADC trigger frequency mode
  2347. * is discarded.
  2348. * @note On this STM32 series, setting of this feature is conditioned to
  2349. * ADC state:
  2350. * ADC must be disabled.
  2351. * @rmtoll CFGR2 LFTRIG LL_ADC_SetTriggerFrequencyMode
  2352. * @param ADCx ADC instance
  2353. * @param TriggerFrequencyMode This parameter can be one of the following values:
  2354. * @arg @ref LL_ADC_TRIGGER_FREQ_HIGH
  2355. * @arg @ref LL_ADC_TRIGGER_FREQ_LOW
  2356. * @retval None
  2357. */
  2358. __STATIC_INLINE void LL_ADC_SetTriggerFrequencyMode(ADC_TypeDef *ADCx, uint32_t TriggerFrequencyMode)
  2359. {
  2360. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_LFTRIG, TriggerFrequencyMode);
  2361. }
  2362. /**
  2363. * @brief Get ADC trigger frequency mode.
  2364. * @rmtoll CFGR2 LFTRIG LL_ADC_GetTriggerFrequencyMode
  2365. * @param ADCx ADC instance
  2366. * @retval Returned value can be one of the following values:
  2367. * @arg @ref LL_ADC_TRIGGER_FREQ_HIGH
  2368. * @arg @ref LL_ADC_TRIGGER_FREQ_LOW
  2369. */
  2370. __STATIC_INLINE uint32_t LL_ADC_GetTriggerFrequencyMode(const ADC_TypeDef *ADCx)
  2371. {
  2372. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_LFTRIG));
  2373. }
  2374. /**
  2375. * @brief Set sampling time common to a group of channels.
  2376. * @note Unit: ADC clock cycles.
  2377. * @note On this STM32 series, sampling time scope is on ADC instance:
  2378. * Sampling time common to all channels.
  2379. * (on some other STM32 series, sampling time is channel wise)
  2380. * @note In case of internal channel (VrefInt, TempSensor, ...) to be
  2381. * converted:
  2382. * sampling time constraints must be respected (sampling time can be
  2383. * adjusted in function of ADC clock frequency and sampling time
  2384. * setting).
  2385. * Refer to device datasheet for timings values (parameters TS_vrefint,
  2386. * TS_temp, ...).
  2387. * @note Conversion time is the addition of sampling time and processing time.
  2388. * On this STM32 series, ADC processing time is:
  2389. * - 12.5 ADC clock cycles at ADC resolution 12 bits
  2390. * - 10.5 ADC clock cycles at ADC resolution 10 bits
  2391. * - 8.5 ADC clock cycles at ADC resolution 8 bits
  2392. * - 6.5 ADC clock cycles at ADC resolution 6 bits
  2393. * @note In case of ADC conversion of internal channel (VrefInt,
  2394. * temperature sensor, ...), a sampling time minimum value
  2395. * is required.
  2396. * Refer to device datasheet.
  2397. * @note On this STM32 series, setting of this feature is conditioned to
  2398. * ADC state:
  2399. * ADC must be disabled or enabled without conversion on going
  2400. * on group regular.
  2401. * @rmtoll SMPR SMP1 LL_ADC_SetSamplingTimeCommonChannels\n
  2402. * @rmtoll SMPR SMP2 LL_ADC_SetSamplingTimeCommonChannels
  2403. * @param ADCx ADC instance
  2404. * @param SamplingTimeY This parameter can be one of the following values:
  2405. * @arg @ref LL_ADC_SAMPLINGTIME_COMMON_1
  2406. * @arg @ref LL_ADC_SAMPLINGTIME_COMMON_2
  2407. * @param SamplingTime This parameter can be one of the following values:
  2408. * @arg @ref LL_ADC_SAMPLINGTIME_1CYCLE_5
  2409. * @arg @ref LL_ADC_SAMPLINGTIME_3CYCLES_5
  2410. * @arg @ref LL_ADC_SAMPLINGTIME_7CYCLES_5
  2411. * @arg @ref LL_ADC_SAMPLINGTIME_12CYCLES_5
  2412. * @arg @ref LL_ADC_SAMPLINGTIME_19CYCLES_5
  2413. * @arg @ref LL_ADC_SAMPLINGTIME_39CYCLES_5
  2414. * @arg @ref LL_ADC_SAMPLINGTIME_79CYCLES_5
  2415. * @arg @ref LL_ADC_SAMPLINGTIME_160CYCLES_5
  2416. * @retval None
  2417. */
  2418. __STATIC_INLINE void LL_ADC_SetSamplingTimeCommonChannels(ADC_TypeDef *ADCx, uint32_t SamplingTimeY,
  2419. uint32_t SamplingTime)
  2420. {
  2421. MODIFY_REG(ADCx->SMPR,
  2422. ADC_SMPR_SMP1 << (SamplingTimeY & ADC_SAMPLING_TIME_SMP_SHIFT_MASK),
  2423. SamplingTime << (SamplingTimeY & ADC_SAMPLING_TIME_SMP_SHIFT_MASK));
  2424. }
  2425. /**
  2426. * @brief Get sampling time common to a group of channels.
  2427. * @note Unit: ADC clock cycles.
  2428. * @note On this STM32 series, sampling time scope is on ADC instance:
  2429. * Sampling time common to all channels.
  2430. * (on some other STM32 series, sampling time is channel wise)
  2431. * @note Conversion time is the addition of sampling time and processing time.
  2432. * Refer to reference manual for ADC processing time of
  2433. * this STM32 series.
  2434. * @rmtoll SMPR SMP1 LL_ADC_GetSamplingTimeCommonChannels\n
  2435. * @rmtoll SMPR SMP2 LL_ADC_GetSamplingTimeCommonChannels
  2436. * @param ADCx ADC instance
  2437. * @param SamplingTimeY This parameter can be one of the following values:
  2438. * @arg @ref LL_ADC_SAMPLINGTIME_COMMON_1
  2439. * @arg @ref LL_ADC_SAMPLINGTIME_COMMON_2
  2440. * @retval Returned value can be one of the following values:
  2441. * @arg @ref LL_ADC_SAMPLINGTIME_1CYCLE_5
  2442. * @arg @ref LL_ADC_SAMPLINGTIME_3CYCLES_5
  2443. * @arg @ref LL_ADC_SAMPLINGTIME_7CYCLES_5
  2444. * @arg @ref LL_ADC_SAMPLINGTIME_12CYCLES_5
  2445. * @arg @ref LL_ADC_SAMPLINGTIME_19CYCLES_5
  2446. * @arg @ref LL_ADC_SAMPLINGTIME_39CYCLES_5
  2447. * @arg @ref LL_ADC_SAMPLINGTIME_79CYCLES_5
  2448. * @arg @ref LL_ADC_SAMPLINGTIME_160CYCLES_5
  2449. */
  2450. __STATIC_INLINE uint32_t LL_ADC_GetSamplingTimeCommonChannels(const ADC_TypeDef *ADCx, uint32_t SamplingTimeY)
  2451. {
  2452. return (uint32_t)((READ_BIT(ADCx->SMPR, ADC_SMPR_SMP1 << (SamplingTimeY & ADC_SAMPLING_TIME_SMP_SHIFT_MASK)))
  2453. >> (SamplingTimeY & ADC_SAMPLING_TIME_SMP_SHIFT_MASK));
  2454. }
  2455. /**
  2456. * @}
  2457. */
  2458. /** @defgroup ADC_LL_EF_Configuration_ADC_Group_Regular Configuration of ADC hierarchical scope: group regular
  2459. * @{
  2460. */
  2461. /**
  2462. * @brief Set ADC group regular conversion trigger source:
  2463. * internal (SW start) or from external peripheral (timer event,
  2464. * external interrupt line).
  2465. * @note On this STM32 series, setting trigger source to external trigger
  2466. * also set trigger polarity to rising edge
  2467. * (default setting for compatibility with some ADC on other
  2468. * STM32 series having this setting set by HW default value).
  2469. * In case of need to modify trigger edge, use
  2470. * function @ref LL_ADC_REG_SetTriggerEdge().
  2471. * @note On this STM32 series, ADC trigger frequency mode must be set
  2472. * in function of frequency of ADC group regular conversion trigger.
  2473. * Refer to description of function
  2474. * @ref LL_ADC_SetTriggerFrequencyMode().
  2475. * @note Availability of parameters of trigger sources from timer
  2476. * depends on timers availability on the selected device.
  2477. * @note On this STM32 series, setting of this feature is conditioned to
  2478. * ADC state:
  2479. * ADC must be disabled.
  2480. * @rmtoll CFGR1 EXTSEL LL_ADC_REG_SetTriggerSource\n
  2481. * CFGR1 EXTEN LL_ADC_REG_SetTriggerSource
  2482. * @param ADCx ADC instance
  2483. * @param TriggerSource This parameter can be one of the following values:
  2484. * @arg @ref LL_ADC_REG_TRIG_SOFTWARE
  2485. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_TRGO2
  2486. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH4
  2487. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_TRGO (1)
  2488. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM3_TRGO
  2489. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM6_TRGO (1)
  2490. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM15_TRGO (1)
  2491. * @arg @ref LL_ADC_REG_TRIG_EXT_EXTI_LINE11
  2492. *
  2493. * (1) On STM32G0, parameter not available on all devices
  2494. * @retval None
  2495. */
  2496. __STATIC_INLINE void LL_ADC_REG_SetTriggerSource(ADC_TypeDef *ADCx, uint32_t TriggerSource)
  2497. {
  2498. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_EXTEN | ADC_CFGR1_EXTSEL, TriggerSource);
  2499. }
  2500. /**
  2501. * @brief Get ADC group regular conversion trigger source:
  2502. * internal (SW start) or from external peripheral (timer event,
  2503. * external interrupt line).
  2504. * @note To determine whether group regular trigger source is
  2505. * internal (SW start) or external, without detail
  2506. * of which peripheral is selected as external trigger,
  2507. * (equivalent to
  2508. * "if(LL_ADC_REG_GetTriggerSource(ADC1) == LL_ADC_REG_TRIG_SOFTWARE)")
  2509. * use function @ref LL_ADC_REG_IsTriggerSourceSWStart.
  2510. * @note Availability of parameters of trigger sources from timer
  2511. * depends on timers availability on the selected device.
  2512. * @rmtoll CFGR1 EXTSEL LL_ADC_REG_GetTriggerSource\n
  2513. * CFGR1 EXTEN LL_ADC_REG_GetTriggerSource
  2514. * @param ADCx ADC instance
  2515. * @retval Returned value can be one of the following values:
  2516. * @arg @ref LL_ADC_REG_TRIG_SOFTWARE
  2517. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_TRGO2
  2518. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH4
  2519. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_TRGO (1)
  2520. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM3_TRGO
  2521. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM6_TRGO (1)
  2522. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM15_TRGO (1)
  2523. * @arg @ref LL_ADC_REG_TRIG_EXT_EXTI_LINE11
  2524. *
  2525. * (1) On STM32G0, parameter not available on all devices
  2526. */
  2527. __STATIC_INLINE uint32_t LL_ADC_REG_GetTriggerSource(const ADC_TypeDef *ADCx)
  2528. {
  2529. __IO uint32_t trigger_source = READ_BIT(ADCx->CFGR1, ADC_CFGR1_EXTSEL | ADC_CFGR1_EXTEN);
  2530. /* Value for shift of {0; 4; 8; 12} depending on value of bitfield */
  2531. /* corresponding to ADC_CFGR1_EXTEN {0; 1; 2; 3}. */
  2532. uint32_t shift_exten = ((trigger_source & ADC_CFGR1_EXTEN) >> (ADC_REG_TRIG_EXTEN_BITOFFSET_POS - 2UL));
  2533. /* Set bitfield corresponding to ADC_CFGR1_EXTEN and ADC_CFGR1_EXTSEL */
  2534. /* to match with triggers literals definition. */
  2535. return ((trigger_source
  2536. & (ADC_REG_TRIG_SOURCE_MASK >> shift_exten) & ADC_CFGR1_EXTSEL)
  2537. | ((ADC_REG_TRIG_EDGE_MASK >> shift_exten) & ADC_CFGR1_EXTEN)
  2538. );
  2539. }
  2540. /**
  2541. * @brief Get ADC group regular conversion trigger source internal (SW start)
  2542. * or external.
  2543. * @note In case of group regular trigger source set to external trigger,
  2544. * to determine which peripheral is selected as external trigger,
  2545. * use function @ref LL_ADC_REG_GetTriggerSource().
  2546. * @rmtoll CFGR1 EXTEN LL_ADC_REG_IsTriggerSourceSWStart
  2547. * @param ADCx ADC instance
  2548. * @retval Value "0" if trigger source external trigger
  2549. * Value "1" if trigger source SW start.
  2550. */
  2551. __STATIC_INLINE uint32_t LL_ADC_REG_IsTriggerSourceSWStart(const ADC_TypeDef *ADCx)
  2552. {
  2553. return ((READ_BIT(ADCx->CFGR1, ADC_CFGR1_EXTEN) == (LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR1_EXTEN)) ? 1UL : 0UL);
  2554. }
  2555. /**
  2556. * @brief Set ADC group regular conversion trigger polarity.
  2557. * @note Applicable only for trigger source set to external trigger.
  2558. * @note On this STM32 series, setting of this feature is conditioned to
  2559. * ADC state:
  2560. * ADC must be disabled.
  2561. * @rmtoll CFGR1 EXTEN LL_ADC_REG_SetTriggerEdge
  2562. * @param ADCx ADC instance
  2563. * @param ExternalTriggerEdge This parameter can be one of the following values:
  2564. * @arg @ref LL_ADC_REG_TRIG_EXT_RISING
  2565. * @arg @ref LL_ADC_REG_TRIG_EXT_FALLING
  2566. * @arg @ref LL_ADC_REG_TRIG_EXT_RISINGFALLING
  2567. * @retval None
  2568. */
  2569. __STATIC_INLINE void LL_ADC_REG_SetTriggerEdge(ADC_TypeDef *ADCx, uint32_t ExternalTriggerEdge)
  2570. {
  2571. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_EXTEN, ExternalTriggerEdge);
  2572. }
  2573. /**
  2574. * @brief Get ADC group regular conversion trigger polarity.
  2575. * @note Applicable only for trigger source set to external trigger.
  2576. * @rmtoll CFGR1 EXTEN LL_ADC_REG_GetTriggerEdge
  2577. * @param ADCx ADC instance
  2578. * @retval Returned value can be one of the following values:
  2579. * @arg @ref LL_ADC_REG_TRIG_EXT_RISING
  2580. * @arg @ref LL_ADC_REG_TRIG_EXT_FALLING
  2581. * @arg @ref LL_ADC_REG_TRIG_EXT_RISINGFALLING
  2582. */
  2583. __STATIC_INLINE uint32_t LL_ADC_REG_GetTriggerEdge(const ADC_TypeDef *ADCx)
  2584. {
  2585. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_EXTEN));
  2586. }
  2587. /**
  2588. * @brief Set ADC group regular sequencer configuration flexibility.
  2589. * @note On this STM32 series, ADC group regular sequencer both modes
  2590. * "fully configurable" or "not fully configurable" are
  2591. * available:
  2592. * - sequencer configured to fully configurable:
  2593. * sequencer length and each rank
  2594. * affectation to a channel are configurable.
  2595. * Refer to description of function
  2596. * @ref LL_ADC_REG_SetSequencerLength().
  2597. * - sequencer configured to not fully configurable:
  2598. * sequencer length and each rank affectation to a channel
  2599. * are fixed by channel HW number.
  2600. * Refer to description of function
  2601. * @ref LL_ADC_REG_SetSequencerChannels().
  2602. * @note On this STM32 series, after modifying sequencer (functions
  2603. * @ref LL_ADC_REG_SetSequencerLength()
  2604. * @ref LL_ADC_REG_SetSequencerRanks(), ...)
  2605. * it is mandatory to wait for the assertion of CCRDY flag
  2606. * Otherwise, some actions may be ignored.
  2607. * Refer to description of @ref LL_ADC_IsActiveFlag_CCRDY
  2608. * for more details.
  2609. * @note On this STM32 series, setting of this feature is conditioned to
  2610. * ADC state:
  2611. * ADC must be disabled.
  2612. * @rmtoll CFGR CHSELRMOD LL_ADC_REG_SetSequencerConfigurable
  2613. * @param ADCx ADC instance
  2614. * @param Configurability This parameter can be one of the following values:
  2615. * @arg @ref LL_ADC_REG_SEQ_FIXED
  2616. * @arg @ref LL_ADC_REG_SEQ_CONFIGURABLE
  2617. * @retval None
  2618. */
  2619. __STATIC_INLINE void LL_ADC_REG_SetSequencerConfigurable(ADC_TypeDef *ADCx, uint32_t Configurability)
  2620. {
  2621. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_CHSELRMOD, Configurability);
  2622. }
  2623. /**
  2624. * @brief Get ADC group regular sequencer configuration flexibility.
  2625. * @note On this STM32 series, ADC group regular sequencer both modes
  2626. * "fully configurable" or "not fully configurable" are
  2627. * available:
  2628. * - sequencer configured to fully configurable:
  2629. * sequencer length and each rank
  2630. * affectation to a channel are configurable.
  2631. * Refer to description of function
  2632. * @ref LL_ADC_REG_SetSequencerLength().
  2633. * - sequencer configured to not fully configurable:
  2634. * sequencer length and each rank affectation to a channel
  2635. * are fixed by channel HW number.
  2636. * Refer to description of function
  2637. * @ref LL_ADC_REG_SetSequencerChannels().
  2638. * @rmtoll CFGR CHSELRMOD LL_ADC_REG_SetSequencerConfigurable
  2639. * @param ADCx ADC instance
  2640. * @retval Returned value can be one of the following values:
  2641. * @arg @ref LL_ADC_REG_SEQ_FIXED
  2642. * @arg @ref LL_ADC_REG_SEQ_CONFIGURABLE
  2643. */
  2644. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerConfigurable(const ADC_TypeDef *ADCx)
  2645. {
  2646. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_CHSELRMOD));
  2647. }
  2648. /**
  2649. * @brief Set ADC group regular sequencer length and scan direction.
  2650. * @note Description of ADC group regular sequencer features:
  2651. * - For devices with sequencer fully configurable
  2652. * (function "LL_ADC_REG_SetSequencerRanks()" available):
  2653. * sequencer length and each rank affectation to a channel
  2654. * are configurable.
  2655. * This function performs configuration of:
  2656. * - Sequence length: Number of ranks in the scan sequence.
  2657. * - Sequence direction: Unless specified in parameters, sequencer
  2658. * scan direction is forward (from rank 1 to rank n).
  2659. * Sequencer ranks are selected using
  2660. * function "LL_ADC_REG_SetSequencerRanks()".
  2661. * - For devices with sequencer not fully configurable
  2662. * (function "LL_ADC_REG_SetSequencerChannels()" available):
  2663. * sequencer length and each rank affectation to a channel
  2664. * are defined by channel number.
  2665. * This function performs configuration of:
  2666. * - Sequence length: Number of ranks in the scan sequence is
  2667. * defined by number of channels set in the sequence,
  2668. * rank of each channel is fixed by channel HW number.
  2669. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2670. * - Sequence direction: Unless specified in parameters, sequencer
  2671. * scan direction is forward (from lowest channel number to
  2672. * highest channel number).
  2673. * Sequencer ranks are selected using
  2674. * function "LL_ADC_REG_SetSequencerChannels()".
  2675. * To set scan direction differently, refer to function
  2676. * @ref LL_ADC_REG_SetSequencerScanDirection().
  2677. * @note On this STM32 series, ADC group regular sequencer both modes
  2678. * "fully configurable" or "not fully configurable"
  2679. * are available, they can be chosen using
  2680. * function @ref LL_ADC_REG_SetSequencerConfigurable().
  2681. * @note On this STM32 series, after modifying sequencer (functions
  2682. * @ref LL_ADC_REG_SetSequencerLength()
  2683. * @ref LL_ADC_REG_SetSequencerRanks(), ...)
  2684. * it is mandatory to wait for the assertion of CCRDY flag
  2685. * using @ref LL_ADC_IsActiveFlag_CCRDY().
  2686. * Otherwise, some actions may be ignored.
  2687. * Refer to description of @ref LL_ADC_IsActiveFlag_CCRDY
  2688. * for more details.
  2689. * @note Sequencer disabled is equivalent to sequencer of 1 rank:
  2690. * ADC conversion on only 1 channel.
  2691. * @note On this STM32 series, setting of this feature is conditioned to
  2692. * ADC state:
  2693. * ADC must be disabled or enabled without conversion on going
  2694. * on group regular.
  2695. * @rmtoll CHSELR SQ1 LL_ADC_REG_SetSequencerLength\n
  2696. * CHSELR SQ2 LL_ADC_REG_SetSequencerLength\n
  2697. * CHSELR SQ3 LL_ADC_REG_SetSequencerLength\n
  2698. * CHSELR SQ4 LL_ADC_REG_SetSequencerLength\n
  2699. * CHSELR SQ5 LL_ADC_REG_SetSequencerLength\n
  2700. * CHSELR SQ6 LL_ADC_REG_SetSequencerLength\n
  2701. * CHSELR SQ7 LL_ADC_REG_SetSequencerLength\n
  2702. * CHSELR SQ8 LL_ADC_REG_SetSequencerLength
  2703. * @param ADCx ADC instance
  2704. * @param SequencerNbRanks This parameter can be one of the following values:
  2705. * @arg @ref LL_ADC_REG_SEQ_SCAN_DISABLE
  2706. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS
  2707. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS
  2708. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS
  2709. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS
  2710. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS
  2711. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS
  2712. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS
  2713. * @retval None
  2714. */
  2715. __STATIC_INLINE void LL_ADC_REG_SetSequencerLength(ADC_TypeDef *ADCx, uint32_t SequencerNbRanks)
  2716. {
  2717. SET_BIT(ADCx->CHSELR, SequencerNbRanks);
  2718. }
  2719. /**
  2720. * @brief Get ADC group regular sequencer length and scan direction.
  2721. * @note Description of ADC group regular sequencer features:
  2722. * - For devices with sequencer fully configurable
  2723. * (function "LL_ADC_REG_SetSequencerRanks()" available):
  2724. * sequencer length and each rank affectation to a channel
  2725. * are configurable.
  2726. * This function retrieves:
  2727. * - Sequence length: Number of ranks in the scan sequence.
  2728. * - Sequence direction: Unless specified in parameters, sequencer
  2729. * scan direction is forward (from rank 1 to rank n).
  2730. * Sequencer ranks are selected using
  2731. * function "LL_ADC_REG_SetSequencerRanks()".
  2732. * - For devices with sequencer not fully configurable
  2733. * (function "LL_ADC_REG_SetSequencerChannels()" available):
  2734. * sequencer length and each rank affectation to a channel
  2735. * are defined by channel number.
  2736. * This function retrieves:
  2737. * - Sequence length: Number of ranks in the scan sequence is
  2738. * defined by number of channels set in the sequence,
  2739. * rank of each channel is fixed by channel HW number.
  2740. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2741. * - Sequence direction: Unless specified in parameters, sequencer
  2742. * scan direction is forward (from lowest channel number to
  2743. * highest channel number).
  2744. * Sequencer ranks are selected using
  2745. * function "LL_ADC_REG_SetSequencerChannels()".
  2746. * To set scan direction differently, refer to function
  2747. * @ref LL_ADC_REG_SetSequencerScanDirection().
  2748. * @note On this STM32 series, ADC group regular sequencer both modes
  2749. * "fully configurable" or "not fully configurable"
  2750. * are available, they can be chosen using
  2751. * function @ref LL_ADC_REG_SetSequencerConfigurable().
  2752. * @note Sequencer disabled is equivalent to sequencer of 1 rank:
  2753. * ADC conversion on only 1 channel.
  2754. * @rmtoll CHSELR SQ1 LL_ADC_REG_GetSequencerLength\n
  2755. * CHSELR SQ2 LL_ADC_REG_GetSequencerLength\n
  2756. * CHSELR SQ3 LL_ADC_REG_GetSequencerLength\n
  2757. * CHSELR SQ4 LL_ADC_REG_GetSequencerLength\n
  2758. * CHSELR SQ5 LL_ADC_REG_GetSequencerLength\n
  2759. * CHSELR SQ6 LL_ADC_REG_GetSequencerLength\n
  2760. * CHSELR SQ7 LL_ADC_REG_GetSequencerLength\n
  2761. * CHSELR SQ8 LL_ADC_REG_GetSequencerLength
  2762. * @param ADCx ADC instance
  2763. * @retval Returned value can be one of the following values:
  2764. * @arg @ref LL_ADC_REG_SEQ_SCAN_DISABLE
  2765. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS
  2766. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS
  2767. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS
  2768. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS
  2769. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS
  2770. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS
  2771. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS
  2772. */
  2773. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerLength(const ADC_TypeDef *ADCx)
  2774. {
  2775. __IO uint32_t channels_ranks = READ_BIT(ADCx->CHSELR, ADC_CHSELR_SQ_ALL);
  2776. uint32_t sequencer_length = LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS;
  2777. uint32_t rank_index;
  2778. uint32_t rank_shifted;
  2779. /* Parse register for end of sequence identifier */
  2780. /* Note: Value "0xF0UL" corresponds to bitfield of sequencer 2nd rank
  2781. (ADC_CHSELR_SQ2), value "4" to length of end of sequence
  2782. identifier (0xF) */
  2783. for (rank_index = 0U; rank_index <= (28U - 4U); rank_index += 4U)
  2784. {
  2785. rank_shifted = (uint32_t)(0xF0UL << rank_index);
  2786. if ((channels_ranks & rank_shifted) == rank_shifted)
  2787. {
  2788. sequencer_length = rank_shifted;
  2789. break;
  2790. }
  2791. }
  2792. return sequencer_length;
  2793. }
  2794. /**
  2795. * @brief Set ADC group regular sequencer scan direction.
  2796. * @note On this STM32 series, parameter relevant only is sequencer is set
  2797. * to mode not fully configurable,
  2798. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  2799. * @note On some other STM32 series, this setting is not available and
  2800. * the default scan direction is forward.
  2801. * @note On this STM32 series, after modifying sequencer (functions
  2802. * @ref LL_ADC_REG_SetSequencerLength()
  2803. * @ref LL_ADC_REG_SetSequencerRanks(), ...)
  2804. * it is mandatory to wait for the assertion of CCRDY flag
  2805. * using @ref LL_ADC_IsActiveFlag_CCRDY().
  2806. * Otherwise, some actions may be ignored.
  2807. * Refer to description of @ref LL_ADC_IsActiveFlag_CCRDY
  2808. * for more details.
  2809. * @note On this STM32 series, setting of this feature is conditioned to
  2810. * ADC state:
  2811. * ADC must be disabled.
  2812. * @rmtoll CFGR1 SCANDIR LL_ADC_REG_SetSequencerScanDirection
  2813. * @param ADCx ADC instance
  2814. * @param ScanDirection This parameter can be one of the following values:
  2815. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_FORWARD
  2816. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_BACKWARD
  2817. * @retval None
  2818. */
  2819. __STATIC_INLINE void LL_ADC_REG_SetSequencerScanDirection(ADC_TypeDef *ADCx, uint32_t ScanDirection)
  2820. {
  2821. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_SCANDIR, ScanDirection);
  2822. }
  2823. /**
  2824. * @brief Get ADC group regular sequencer scan direction.
  2825. * @note On this STM32 series, parameter relevant only is sequencer is set
  2826. * to mode not fully configurable,
  2827. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  2828. * @note On some other STM32 series, this setting is not available and
  2829. * the default scan direction is forward.
  2830. * @rmtoll CFGR1 SCANDIR LL_ADC_REG_GetSequencerScanDirection
  2831. * @param ADCx ADC instance
  2832. * @retval Returned value can be one of the following values:
  2833. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_FORWARD
  2834. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_BACKWARD
  2835. */
  2836. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerScanDirection(const ADC_TypeDef *ADCx)
  2837. {
  2838. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_SCANDIR));
  2839. }
  2840. /**
  2841. * @brief Set ADC group regular sequencer discontinuous mode:
  2842. * sequence subdivided and scan conversions interrupted every selected
  2843. * number of ranks.
  2844. * @note It is not possible to enable both ADC group regular
  2845. * continuous mode and sequencer discontinuous mode.
  2846. * @note On this STM32 series, setting of this feature is conditioned to
  2847. * ADC state:
  2848. * ADC must be disabled.
  2849. * @rmtoll CFGR1 DISCEN LL_ADC_REG_SetSequencerDiscont\n
  2850. * @param ADCx ADC instance
  2851. * @param SeqDiscont This parameter can be one of the following values:
  2852. * @arg @ref LL_ADC_REG_SEQ_DISCONT_DISABLE
  2853. * @arg @ref LL_ADC_REG_SEQ_DISCONT_1RANK
  2854. * @retval None
  2855. */
  2856. __STATIC_INLINE void LL_ADC_REG_SetSequencerDiscont(ADC_TypeDef *ADCx, uint32_t SeqDiscont)
  2857. {
  2858. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_DISCEN, SeqDiscont);
  2859. }
  2860. /**
  2861. * @brief Get ADC group regular sequencer discontinuous mode:
  2862. * sequence subdivided and scan conversions interrupted every selected
  2863. * number of ranks.
  2864. * @rmtoll CFGR1 DISCEN LL_ADC_REG_GetSequencerDiscont\n
  2865. * @param ADCx ADC instance
  2866. * @retval Returned value can be one of the following values:
  2867. * @arg @ref LL_ADC_REG_SEQ_DISCONT_DISABLE
  2868. * @arg @ref LL_ADC_REG_SEQ_DISCONT_1RANK
  2869. */
  2870. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerDiscont(const ADC_TypeDef *ADCx)
  2871. {
  2872. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_DISCEN));
  2873. }
  2874. /**
  2875. * @brief Set ADC group regular sequence: channel on the selected
  2876. * scan sequence rank.
  2877. * @note This function performs configuration of:
  2878. * - Channels ordering into each rank of scan sequence:
  2879. * whatever channel can be placed into whatever rank.
  2880. * @note On this STM32 series, ADC group regular sequencer is
  2881. * fully configurable: sequencer length and each rank
  2882. * affectation to a channel are configurable.
  2883. * Refer to description of function @ref LL_ADC_REG_SetSequencerLength().
  2884. * @note Depending on devices and packages, some channels may not be available.
  2885. * Refer to device datasheet for channels availability.
  2886. * @note On this STM32 series, to measure internal channels (VrefInt,
  2887. * TempSensor, ...), measurement paths to internal channels must be
  2888. * enabled separately.
  2889. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  2890. * @note On this STM32 series, after modifying sequencer (functions
  2891. * @ref LL_ADC_REG_SetSequencerLength()
  2892. * @ref LL_ADC_REG_SetSequencerRanks(), ...)
  2893. * it is mandatory to wait for the assertion of CCRDY flag
  2894. * using @ref LL_ADC_IsActiveFlag_CCRDY().
  2895. * Otherwise, some actions may be ignored.
  2896. * Refer to description of @ref LL_ADC_IsActiveFlag_CCRDY
  2897. * for more details.
  2898. * @note On this STM32 series, setting of this feature is conditioned to
  2899. * ADC state:
  2900. * ADC must be disabled or enabled without conversion on going
  2901. * on group regular.
  2902. * @rmtoll CHSELR SQ1 LL_ADC_REG_SetSequencerRanks\n
  2903. * CHSELR SQ2 LL_ADC_REG_SetSequencerRanks\n
  2904. * CHSELR SQ3 LL_ADC_REG_SetSequencerRanks\n
  2905. * CHSELR SQ4 LL_ADC_REG_SetSequencerRanks\n
  2906. * CHSELR SQ5 LL_ADC_REG_SetSequencerRanks\n
  2907. * CHSELR SQ6 LL_ADC_REG_SetSequencerRanks\n
  2908. * CHSELR SQ7 LL_ADC_REG_SetSequencerRanks\n
  2909. * CHSELR SQ8 LL_ADC_REG_SetSequencerRanks
  2910. * @param ADCx ADC instance
  2911. * @param Rank This parameter can be one of the following values:
  2912. * @arg @ref LL_ADC_REG_RANK_1
  2913. * @arg @ref LL_ADC_REG_RANK_2
  2914. * @arg @ref LL_ADC_REG_RANK_3
  2915. * @arg @ref LL_ADC_REG_RANK_4
  2916. * @arg @ref LL_ADC_REG_RANK_5
  2917. * @arg @ref LL_ADC_REG_RANK_6
  2918. * @arg @ref LL_ADC_REG_RANK_7
  2919. * @arg @ref LL_ADC_REG_RANK_8
  2920. * @param Channel This parameter can be one of the following values:
  2921. * @arg @ref LL_ADC_CHANNEL_0
  2922. * @arg @ref LL_ADC_CHANNEL_1
  2923. * @arg @ref LL_ADC_CHANNEL_2
  2924. * @arg @ref LL_ADC_CHANNEL_3
  2925. * @arg @ref LL_ADC_CHANNEL_4
  2926. * @arg @ref LL_ADC_CHANNEL_5
  2927. * @arg @ref LL_ADC_CHANNEL_6
  2928. * @arg @ref LL_ADC_CHANNEL_7
  2929. * @arg @ref LL_ADC_CHANNEL_8
  2930. * @arg @ref LL_ADC_CHANNEL_9
  2931. * @arg @ref LL_ADC_CHANNEL_10
  2932. * @arg @ref LL_ADC_CHANNEL_11
  2933. * @arg @ref LL_ADC_CHANNEL_12
  2934. * @arg @ref LL_ADC_CHANNEL_13
  2935. * @arg @ref LL_ADC_CHANNEL_14
  2936. * @arg @ref LL_ADC_CHANNEL_15 (1)
  2937. * @arg @ref LL_ADC_CHANNEL_16 (1)
  2938. * @arg @ref LL_ADC_CHANNEL_17 (1)
  2939. * @arg @ref LL_ADC_CHANNEL_18
  2940. * @arg @ref LL_ADC_CHANNEL_VREFINT
  2941. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  2942. * @arg @ref LL_ADC_CHANNEL_VBAT
  2943. *
  2944. * (1) On STM32G0, parameter can be set in ADC group sequencer
  2945. * only if sequencer is set in mode "not fully configurable",
  2946. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  2947. * @retval None
  2948. */
  2949. __STATIC_INLINE void LL_ADC_REG_SetSequencerRanks(ADC_TypeDef *ADCx, uint32_t Rank, uint32_t Channel)
  2950. {
  2951. /* Set bits with content of parameter "Channel" with bits position */
  2952. /* in register depending on parameter "Rank". */
  2953. /* Parameters "Rank" and "Channel" are used with masks because containing */
  2954. /* other bits reserved for other purpose. */
  2955. MODIFY_REG(ADCx->CHSELR,
  2956. ADC_CHSELR_SQ1 << (Rank & ADC_REG_RANK_ID_SQRX_MASK),
  2957. ((Channel & ADC_CHANNEL_ID_NUMBER_MASK_SEQ) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS)
  2958. << (Rank & ADC_REG_RANK_ID_SQRX_MASK));
  2959. }
  2960. /**
  2961. * @brief Get ADC group regular sequence: channel on the selected
  2962. * scan sequence rank.
  2963. * @note On this STM32 series, ADC group regular sequencer is
  2964. * fully configurable: sequencer length and each rank
  2965. * affectation to a channel are configurable.
  2966. * Refer to description of function @ref LL_ADC_REG_SetSequencerLength().
  2967. * @note Depending on devices and packages, some channels may not be available.
  2968. * Refer to device datasheet for channels availability.
  2969. * @note Usage of the returned channel number:
  2970. * - To reinject this channel into another function LL_ADC_xxx:
  2971. * the returned channel number is only partly formatted on definition
  2972. * of literals LL_ADC_CHANNEL_x. Therefore, it has to be compared
  2973. * with parts of literals LL_ADC_CHANNEL_x or using
  2974. * helper macro @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2975. * Then the selected literal LL_ADC_CHANNEL_x can be used
  2976. * as parameter for another function.
  2977. * - To get the channel number in decimal format:
  2978. * process the returned value with the helper macro
  2979. * @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2980. * @rmtoll CHSELR SQ1 LL_ADC_REG_GetSequencerRanks\n
  2981. * CHSELR SQ2 LL_ADC_REG_GetSequencerRanks\n
  2982. * CHSELR SQ3 LL_ADC_REG_GetSequencerRanks\n
  2983. * CHSELR SQ4 LL_ADC_REG_GetSequencerRanks\n
  2984. * CHSELR SQ5 LL_ADC_REG_GetSequencerRanks\n
  2985. * CHSELR SQ6 LL_ADC_REG_GetSequencerRanks\n
  2986. * CHSELR SQ7 LL_ADC_REG_GetSequencerRanks\n
  2987. * CHSELR SQ8 LL_ADC_REG_GetSequencerRanks
  2988. * @param ADCx ADC instance
  2989. * @param Rank This parameter can be one of the following values:
  2990. * @arg @ref LL_ADC_REG_RANK_1
  2991. * @arg @ref LL_ADC_REG_RANK_2
  2992. * @arg @ref LL_ADC_REG_RANK_3
  2993. * @arg @ref LL_ADC_REG_RANK_4
  2994. * @arg @ref LL_ADC_REG_RANK_5
  2995. * @arg @ref LL_ADC_REG_RANK_6
  2996. * @arg @ref LL_ADC_REG_RANK_7
  2997. * @arg @ref LL_ADC_REG_RANK_8
  2998. * @retval Returned value can be one of the following values:
  2999. * @arg @ref LL_ADC_CHANNEL_0
  3000. * @arg @ref LL_ADC_CHANNEL_1
  3001. * @arg @ref LL_ADC_CHANNEL_2
  3002. * @arg @ref LL_ADC_CHANNEL_3
  3003. * @arg @ref LL_ADC_CHANNEL_4
  3004. * @arg @ref LL_ADC_CHANNEL_5
  3005. * @arg @ref LL_ADC_CHANNEL_6
  3006. * @arg @ref LL_ADC_CHANNEL_7
  3007. * @arg @ref LL_ADC_CHANNEL_8
  3008. * @arg @ref LL_ADC_CHANNEL_9
  3009. * @arg @ref LL_ADC_CHANNEL_10
  3010. * @arg @ref LL_ADC_CHANNEL_11
  3011. * @arg @ref LL_ADC_CHANNEL_12
  3012. * @arg @ref LL_ADC_CHANNEL_13
  3013. * @arg @ref LL_ADC_CHANNEL_14
  3014. * @arg @ref LL_ADC_CHANNEL_15 (1)
  3015. * @arg @ref LL_ADC_CHANNEL_16 (1)
  3016. * @arg @ref LL_ADC_CHANNEL_17 (1)
  3017. * @arg @ref LL_ADC_CHANNEL_18
  3018. * @arg @ref LL_ADC_CHANNEL_VREFINT (2)
  3019. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (2)
  3020. * @arg @ref LL_ADC_CHANNEL_VBAT (2)
  3021. *
  3022. * (1) On STM32G0, parameter can be set in ADC group sequencer
  3023. * only if sequencer is set in mode "not fully configurable",
  3024. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().\n
  3025. * (2) For ADC channel read back from ADC register,
  3026. * comparison with internal channel parameter to be done
  3027. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  3028. */
  3029. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerRanks(const ADC_TypeDef *ADCx, uint32_t Rank)
  3030. {
  3031. return (uint32_t)((READ_BIT(ADCx->CHSELR,
  3032. ADC_CHSELR_SQ1 << (Rank & ADC_REG_RANK_ID_SQRX_MASK))
  3033. >> (Rank & ADC_REG_RANK_ID_SQRX_MASK)
  3034. ) << (ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS)
  3035. );
  3036. }
  3037. /**
  3038. * @brief Set ADC group regular sequence: channel on rank corresponding to
  3039. * channel number.
  3040. * @note This function performs:
  3041. * - Channels ordering into each rank of scan sequence:
  3042. * rank of each channel is fixed by channel HW number
  3043. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  3044. * - Set channels selected by overwriting the current sequencer
  3045. * configuration.
  3046. * @note On this STM32 series, ADC group regular sequencer both modes
  3047. * "fully configurable" or "not fully configurable"
  3048. * are available, they can be chosen using
  3049. * function @ref LL_ADC_REG_SetSequencerConfigurable().
  3050. * This function can be used with setting "not fully configurable".
  3051. * Refer to description of functions @ref LL_ADC_REG_SetSequencerConfigurable()
  3052. * and @ref LL_ADC_REG_SetSequencerLength().
  3053. * @note On this STM32 series, after modifying sequencer (functions
  3054. * @ref LL_ADC_REG_SetSequencerLength()
  3055. * @ref LL_ADC_REG_SetSequencerRanks(), ...)
  3056. * it is mandatory to wait for the assertion of CCRDY flag
  3057. * using @ref LL_ADC_IsActiveFlag_CCRDY().
  3058. * Otherwise, some actions may be ignored.
  3059. * Refer to description of @ref LL_ADC_IsActiveFlag_CCRDY
  3060. * for more details.
  3061. * @note Depending on devices and packages, some channels may not be available.
  3062. * Refer to device datasheet for channels availability.
  3063. * @note On this STM32 series, to measure internal channels (VrefInt,
  3064. * TempSensor, ...), measurement paths to internal channels must be
  3065. * enabled separately.
  3066. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  3067. * @note On this STM32 series, setting of this feature is conditioned to
  3068. * ADC state:
  3069. * ADC must be disabled or enabled without conversion on going
  3070. * on group regular.
  3071. * @note One or several values can be selected.
  3072. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  3073. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_SetSequencerChannels\n
  3074. * CHSELR CHSEL1 LL_ADC_REG_SetSequencerChannels\n
  3075. * CHSELR CHSEL2 LL_ADC_REG_SetSequencerChannels\n
  3076. * CHSELR CHSEL3 LL_ADC_REG_SetSequencerChannels\n
  3077. * CHSELR CHSEL4 LL_ADC_REG_SetSequencerChannels\n
  3078. * CHSELR CHSEL5 LL_ADC_REG_SetSequencerChannels\n
  3079. * CHSELR CHSEL6 LL_ADC_REG_SetSequencerChannels\n
  3080. * CHSELR CHSEL7 LL_ADC_REG_SetSequencerChannels\n
  3081. * CHSELR CHSEL8 LL_ADC_REG_SetSequencerChannels\n
  3082. * CHSELR CHSEL9 LL_ADC_REG_SetSequencerChannels\n
  3083. * CHSELR CHSEL10 LL_ADC_REG_SetSequencerChannels\n
  3084. * CHSELR CHSEL11 LL_ADC_REG_SetSequencerChannels\n
  3085. * CHSELR CHSEL12 LL_ADC_REG_SetSequencerChannels\n
  3086. * CHSELR CHSEL13 LL_ADC_REG_SetSequencerChannels\n
  3087. * CHSELR CHSEL14 LL_ADC_REG_SetSequencerChannels\n
  3088. * CHSELR CHSEL15 LL_ADC_REG_SetSequencerChannels\n
  3089. * CHSELR CHSEL16 LL_ADC_REG_SetSequencerChannels\n
  3090. * CHSELR CHSEL17 LL_ADC_REG_SetSequencerChannels\n
  3091. * CHSELR CHSEL18 LL_ADC_REG_SetSequencerChannels
  3092. * @param ADCx ADC instance
  3093. * @param Channel This parameter can be a combination of the following values:
  3094. * @arg @ref LL_ADC_CHANNEL_0
  3095. * @arg @ref LL_ADC_CHANNEL_1
  3096. * @arg @ref LL_ADC_CHANNEL_2
  3097. * @arg @ref LL_ADC_CHANNEL_3
  3098. * @arg @ref LL_ADC_CHANNEL_4
  3099. * @arg @ref LL_ADC_CHANNEL_5
  3100. * @arg @ref LL_ADC_CHANNEL_6
  3101. * @arg @ref LL_ADC_CHANNEL_7
  3102. * @arg @ref LL_ADC_CHANNEL_8
  3103. * @arg @ref LL_ADC_CHANNEL_9
  3104. * @arg @ref LL_ADC_CHANNEL_10
  3105. * @arg @ref LL_ADC_CHANNEL_11
  3106. * @arg @ref LL_ADC_CHANNEL_12
  3107. * @arg @ref LL_ADC_CHANNEL_13
  3108. * @arg @ref LL_ADC_CHANNEL_14
  3109. * @arg @ref LL_ADC_CHANNEL_15 (1)
  3110. * @arg @ref LL_ADC_CHANNEL_16 (1)
  3111. * @arg @ref LL_ADC_CHANNEL_17 (1)
  3112. * @arg @ref LL_ADC_CHANNEL_18
  3113. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3114. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3115. * @arg @ref LL_ADC_CHANNEL_VBAT
  3116. *
  3117. * (1) On STM32G0, parameter can be set in ADC group sequencer
  3118. * only if sequencer is set in mode "not fully configurable",
  3119. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  3120. * @retval None
  3121. */
  3122. __STATIC_INLINE void LL_ADC_REG_SetSequencerChannels(ADC_TypeDef *ADCx, uint32_t Channel)
  3123. {
  3124. /* Parameter "Channel" is used with masks because containing */
  3125. /* other bits reserved for other purpose. */
  3126. WRITE_REG(ADCx->CHSELR, (Channel & ADC_CHANNEL_ID_BITFIELD_MASK));
  3127. }
  3128. /**
  3129. * @brief Add channel to ADC group regular sequence: channel on rank corresponding to
  3130. * channel number.
  3131. * @note This function performs:
  3132. * - Channels ordering into each rank of scan sequence:
  3133. * rank of each channel is fixed by channel HW number
  3134. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  3135. * - Set channels selected by adding them to the current sequencer
  3136. * configuration.
  3137. * @note On this STM32 series, ADC group regular sequencer both modes
  3138. * "fully configurable" or "not fully configurable"
  3139. * are available, they can be chosen using
  3140. * function @ref LL_ADC_REG_SetSequencerConfigurable().
  3141. * This function can be used with setting "not fully configurable".
  3142. * Refer to description of functions @ref LL_ADC_REG_SetSequencerConfigurable()
  3143. * and @ref LL_ADC_REG_SetSequencerLength().
  3144. * @note On this STM32 series, after modifying sequencer (functions
  3145. * @ref LL_ADC_REG_SetSequencerLength()
  3146. * @ref LL_ADC_REG_SetSequencerRanks(), ...)
  3147. * it is mandatory to wait for the assertion of CCRDY flag
  3148. * using @ref LL_ADC_IsActiveFlag_CCRDY().
  3149. * Otherwise, some actions may be ignored.
  3150. * Refer to description of @ref LL_ADC_IsActiveFlag_CCRDY
  3151. * for more details.
  3152. * @note Depending on devices and packages, some channels may not be available.
  3153. * Refer to device datasheet for channels availability.
  3154. * @note On this STM32 series, to measure internal channels (VrefInt,
  3155. * TempSensor, ...), measurement paths to internal channels must be
  3156. * enabled separately.
  3157. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  3158. * @note On this STM32 series, setting of this feature is conditioned to
  3159. * ADC state:
  3160. * ADC must be disabled or enabled without conversion on going
  3161. * on group regular.
  3162. * @note One or several values can be selected.
  3163. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  3164. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_SetSequencerChAdd\n
  3165. * CHSELR CHSEL1 LL_ADC_REG_SetSequencerChAdd\n
  3166. * CHSELR CHSEL2 LL_ADC_REG_SetSequencerChAdd\n
  3167. * CHSELR CHSEL3 LL_ADC_REG_SetSequencerChAdd\n
  3168. * CHSELR CHSEL4 LL_ADC_REG_SetSequencerChAdd\n
  3169. * CHSELR CHSEL5 LL_ADC_REG_SetSequencerChAdd\n
  3170. * CHSELR CHSEL6 LL_ADC_REG_SetSequencerChAdd\n
  3171. * CHSELR CHSEL7 LL_ADC_REG_SetSequencerChAdd\n
  3172. * CHSELR CHSEL8 LL_ADC_REG_SetSequencerChAdd\n
  3173. * CHSELR CHSEL9 LL_ADC_REG_SetSequencerChAdd\n
  3174. * CHSELR CHSEL10 LL_ADC_REG_SetSequencerChAdd\n
  3175. * CHSELR CHSEL11 LL_ADC_REG_SetSequencerChAdd\n
  3176. * CHSELR CHSEL12 LL_ADC_REG_SetSequencerChAdd\n
  3177. * CHSELR CHSEL13 LL_ADC_REG_SetSequencerChAdd\n
  3178. * CHSELR CHSEL14 LL_ADC_REG_SetSequencerChAdd\n
  3179. * CHSELR CHSEL15 LL_ADC_REG_SetSequencerChAdd\n
  3180. * CHSELR CHSEL16 LL_ADC_REG_SetSequencerChAdd\n
  3181. * CHSELR CHSEL17 LL_ADC_REG_SetSequencerChAdd\n
  3182. * CHSELR CHSEL18 LL_ADC_REG_SetSequencerChAdd
  3183. * @param ADCx ADC instance
  3184. * @param Channel This parameter can be a combination of the following values:
  3185. * @arg @ref LL_ADC_CHANNEL_0
  3186. * @arg @ref LL_ADC_CHANNEL_1
  3187. * @arg @ref LL_ADC_CHANNEL_2
  3188. * @arg @ref LL_ADC_CHANNEL_3
  3189. * @arg @ref LL_ADC_CHANNEL_4
  3190. * @arg @ref LL_ADC_CHANNEL_5
  3191. * @arg @ref LL_ADC_CHANNEL_6
  3192. * @arg @ref LL_ADC_CHANNEL_7
  3193. * @arg @ref LL_ADC_CHANNEL_8
  3194. * @arg @ref LL_ADC_CHANNEL_9
  3195. * @arg @ref LL_ADC_CHANNEL_10
  3196. * @arg @ref LL_ADC_CHANNEL_11
  3197. * @arg @ref LL_ADC_CHANNEL_12
  3198. * @arg @ref LL_ADC_CHANNEL_13
  3199. * @arg @ref LL_ADC_CHANNEL_14
  3200. * @arg @ref LL_ADC_CHANNEL_15 (1)
  3201. * @arg @ref LL_ADC_CHANNEL_16 (1)
  3202. * @arg @ref LL_ADC_CHANNEL_17 (1)
  3203. * @arg @ref LL_ADC_CHANNEL_18
  3204. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3205. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3206. * @arg @ref LL_ADC_CHANNEL_VBAT
  3207. *
  3208. * (1) On STM32G0, parameter can be set in ADC group sequencer
  3209. * only if sequencer is set in mode "not fully configurable",
  3210. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  3211. * @retval None
  3212. */
  3213. __STATIC_INLINE void LL_ADC_REG_SetSequencerChAdd(ADC_TypeDef *ADCx, uint32_t Channel)
  3214. {
  3215. /* Parameter "Channel" is used with masks because containing */
  3216. /* other bits reserved for other purpose. */
  3217. SET_BIT(ADCx->CHSELR, (Channel & ADC_CHANNEL_ID_BITFIELD_MASK));
  3218. }
  3219. /**
  3220. * @brief Remove channel to ADC group regular sequence: channel on rank corresponding to
  3221. * channel number.
  3222. * @note This function performs:
  3223. * - Channels ordering into each rank of scan sequence:
  3224. * rank of each channel is fixed by channel HW number
  3225. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  3226. * - Set channels selected by removing them to the current sequencer
  3227. * configuration.
  3228. * @note On this STM32 series, ADC group regular sequencer both modes
  3229. * "fully configurable" or "not fully configurable"
  3230. * are available, they can be chosen using
  3231. * function @ref LL_ADC_REG_SetSequencerConfigurable().
  3232. * This function can be used with setting "not fully configurable".
  3233. * Refer to description of functions @ref LL_ADC_REG_SetSequencerConfigurable()
  3234. * and @ref LL_ADC_REG_SetSequencerLength().
  3235. * @note On this STM32 series, after modifying sequencer (functions
  3236. * @ref LL_ADC_REG_SetSequencerLength()
  3237. * @ref LL_ADC_REG_SetSequencerRanks(), ...)
  3238. * it is mandatory to wait for the assertion of CCRDY flag
  3239. * using @ref LL_ADC_IsActiveFlag_CCRDY().
  3240. * Otherwise, some actions may be ignored.
  3241. * Refer to description of @ref LL_ADC_IsActiveFlag_CCRDY
  3242. * for more details.
  3243. * @note Depending on devices and packages, some channels may not be available.
  3244. * Refer to device datasheet for channels availability.
  3245. * @note On this STM32 series, to measure internal channels (VrefInt,
  3246. * TempSensor, ...), measurement paths to internal channels must be
  3247. * enabled separately.
  3248. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  3249. * @note On this STM32 series, setting of this feature is conditioned to
  3250. * ADC state:
  3251. * ADC must be disabled or enabled without conversion on going
  3252. * on group regular.
  3253. * @note One or several values can be selected.
  3254. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  3255. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_SetSequencerChRem\n
  3256. * CHSELR CHSEL1 LL_ADC_REG_SetSequencerChRem\n
  3257. * CHSELR CHSEL2 LL_ADC_REG_SetSequencerChRem\n
  3258. * CHSELR CHSEL3 LL_ADC_REG_SetSequencerChRem\n
  3259. * CHSELR CHSEL4 LL_ADC_REG_SetSequencerChRem\n
  3260. * CHSELR CHSEL5 LL_ADC_REG_SetSequencerChRem\n
  3261. * CHSELR CHSEL6 LL_ADC_REG_SetSequencerChRem\n
  3262. * CHSELR CHSEL7 LL_ADC_REG_SetSequencerChRem\n
  3263. * CHSELR CHSEL8 LL_ADC_REG_SetSequencerChRem\n
  3264. * CHSELR CHSEL9 LL_ADC_REG_SetSequencerChRem\n
  3265. * CHSELR CHSEL10 LL_ADC_REG_SetSequencerChRem\n
  3266. * CHSELR CHSEL11 LL_ADC_REG_SetSequencerChRem\n
  3267. * CHSELR CHSEL12 LL_ADC_REG_SetSequencerChRem\n
  3268. * CHSELR CHSEL13 LL_ADC_REG_SetSequencerChRem\n
  3269. * CHSELR CHSEL14 LL_ADC_REG_SetSequencerChRem\n
  3270. * CHSELR CHSEL15 LL_ADC_REG_SetSequencerChRem\n
  3271. * CHSELR CHSEL16 LL_ADC_REG_SetSequencerChRem\n
  3272. * CHSELR CHSEL17 LL_ADC_REG_SetSequencerChRem\n
  3273. * CHSELR CHSEL18 LL_ADC_REG_SetSequencerChRem
  3274. * @param ADCx ADC instance
  3275. * @param Channel This parameter can be a combination of the following values:
  3276. * @arg @ref LL_ADC_CHANNEL_0
  3277. * @arg @ref LL_ADC_CHANNEL_1
  3278. * @arg @ref LL_ADC_CHANNEL_2
  3279. * @arg @ref LL_ADC_CHANNEL_3
  3280. * @arg @ref LL_ADC_CHANNEL_4
  3281. * @arg @ref LL_ADC_CHANNEL_5
  3282. * @arg @ref LL_ADC_CHANNEL_6
  3283. * @arg @ref LL_ADC_CHANNEL_7
  3284. * @arg @ref LL_ADC_CHANNEL_8
  3285. * @arg @ref LL_ADC_CHANNEL_9
  3286. * @arg @ref LL_ADC_CHANNEL_10
  3287. * @arg @ref LL_ADC_CHANNEL_11
  3288. * @arg @ref LL_ADC_CHANNEL_12
  3289. * @arg @ref LL_ADC_CHANNEL_13
  3290. * @arg @ref LL_ADC_CHANNEL_14
  3291. * @arg @ref LL_ADC_CHANNEL_15 (1)
  3292. * @arg @ref LL_ADC_CHANNEL_16 (1)
  3293. * @arg @ref LL_ADC_CHANNEL_17 (1)
  3294. * @arg @ref LL_ADC_CHANNEL_18
  3295. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3296. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3297. * @arg @ref LL_ADC_CHANNEL_VBAT
  3298. *
  3299. * (1) On STM32G0, parameter can be set in ADC group sequencer
  3300. * only if sequencer is set in mode "not fully configurable",
  3301. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  3302. * @retval None
  3303. */
  3304. __STATIC_INLINE void LL_ADC_REG_SetSequencerChRem(ADC_TypeDef *ADCx, uint32_t Channel)
  3305. {
  3306. /* Parameter "Channel" is used with masks because containing */
  3307. /* other bits reserved for other purpose. */
  3308. CLEAR_BIT(ADCx->CHSELR, (Channel & ADC_CHANNEL_ID_BITFIELD_MASK));
  3309. }
  3310. /**
  3311. * @brief Get ADC group regular sequence: channel on rank corresponding to
  3312. * channel number.
  3313. * @note This function performs:
  3314. * - Channels order reading into each rank of scan sequence:
  3315. * rank of each channel is fixed by channel HW number
  3316. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  3317. * @note On this STM32 series, ADC group regular sequencer both modes
  3318. * "fully configurable" or "not fully configurable"
  3319. * are available, they can be chosen using
  3320. * function @ref LL_ADC_REG_SetSequencerConfigurable().
  3321. * This function can be used with setting "not fully configurable".
  3322. * Refer to description of functions @ref LL_ADC_REG_SetSequencerConfigurable()
  3323. * and @ref LL_ADC_REG_SetSequencerLength().
  3324. * @note Depending on devices and packages, some channels may not be available.
  3325. * Refer to device datasheet for channels availability.
  3326. * @note On this STM32 series, to measure internal channels (VrefInt,
  3327. * TempSensor, ...), measurement paths to internal channels must be
  3328. * enabled separately.
  3329. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  3330. * @note On this STM32 series, setting of this feature is conditioned to
  3331. * ADC state:
  3332. * ADC must be disabled or enabled without conversion on going
  3333. * on group regular.
  3334. * @note One or several values can be retrieved.
  3335. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  3336. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_GetSequencerChannels\n
  3337. * CHSELR CHSEL1 LL_ADC_REG_GetSequencerChannels\n
  3338. * CHSELR CHSEL2 LL_ADC_REG_GetSequencerChannels\n
  3339. * CHSELR CHSEL3 LL_ADC_REG_GetSequencerChannels\n
  3340. * CHSELR CHSEL4 LL_ADC_REG_GetSequencerChannels\n
  3341. * CHSELR CHSEL5 LL_ADC_REG_GetSequencerChannels\n
  3342. * CHSELR CHSEL6 LL_ADC_REG_GetSequencerChannels\n
  3343. * CHSELR CHSEL7 LL_ADC_REG_GetSequencerChannels\n
  3344. * CHSELR CHSEL8 LL_ADC_REG_GetSequencerChannels\n
  3345. * CHSELR CHSEL9 LL_ADC_REG_GetSequencerChannels\n
  3346. * CHSELR CHSEL10 LL_ADC_REG_GetSequencerChannels\n
  3347. * CHSELR CHSEL11 LL_ADC_REG_GetSequencerChannels\n
  3348. * CHSELR CHSEL12 LL_ADC_REG_GetSequencerChannels\n
  3349. * CHSELR CHSEL13 LL_ADC_REG_GetSequencerChannels\n
  3350. * CHSELR CHSEL14 LL_ADC_REG_GetSequencerChannels\n
  3351. * CHSELR CHSEL15 LL_ADC_REG_GetSequencerChannels\n
  3352. * CHSELR CHSEL16 LL_ADC_REG_GetSequencerChannels\n
  3353. * CHSELR CHSEL17 LL_ADC_REG_GetSequencerChannels\n
  3354. * CHSELR CHSEL18 LL_ADC_REG_GetSequencerChannels
  3355. * @param ADCx ADC instance
  3356. * @retval Returned value can be a combination of the following values:
  3357. * @arg @ref LL_ADC_CHANNEL_0
  3358. * @arg @ref LL_ADC_CHANNEL_1
  3359. * @arg @ref LL_ADC_CHANNEL_2
  3360. * @arg @ref LL_ADC_CHANNEL_3
  3361. * @arg @ref LL_ADC_CHANNEL_4
  3362. * @arg @ref LL_ADC_CHANNEL_5
  3363. * @arg @ref LL_ADC_CHANNEL_6
  3364. * @arg @ref LL_ADC_CHANNEL_7
  3365. * @arg @ref LL_ADC_CHANNEL_8
  3366. * @arg @ref LL_ADC_CHANNEL_9
  3367. * @arg @ref LL_ADC_CHANNEL_10
  3368. * @arg @ref LL_ADC_CHANNEL_11
  3369. * @arg @ref LL_ADC_CHANNEL_12
  3370. * @arg @ref LL_ADC_CHANNEL_13
  3371. * @arg @ref LL_ADC_CHANNEL_14
  3372. * @arg @ref LL_ADC_CHANNEL_15 (1)
  3373. * @arg @ref LL_ADC_CHANNEL_16 (1)
  3374. * @arg @ref LL_ADC_CHANNEL_17 (1)
  3375. * @arg @ref LL_ADC_CHANNEL_18
  3376. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3377. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3378. * @arg @ref LL_ADC_CHANNEL_VBAT
  3379. *
  3380. * (1) On STM32G0, parameter can be set in ADC group sequencer
  3381. * only if sequencer is set in mode "not fully configurable",
  3382. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  3383. */
  3384. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerChannels(const ADC_TypeDef *ADCx)
  3385. {
  3386. uint32_t channels_bitfield = (uint32_t)READ_BIT(ADCx->CHSELR, ADC_CHSELR_CHSEL);
  3387. return ((((channels_bitfield & ADC_CHSELR_CHSEL0) >> ADC_CHSELR_CHSEL0_BITOFFSET_POS) * LL_ADC_CHANNEL_0)
  3388. | (((channels_bitfield & ADC_CHSELR_CHSEL1) >> ADC_CHSELR_CHSEL1_BITOFFSET_POS) * LL_ADC_CHANNEL_1)
  3389. | (((channels_bitfield & ADC_CHSELR_CHSEL2) >> ADC_CHSELR_CHSEL2_BITOFFSET_POS) * LL_ADC_CHANNEL_2)
  3390. | (((channels_bitfield & ADC_CHSELR_CHSEL3) >> ADC_CHSELR_CHSEL3_BITOFFSET_POS) * LL_ADC_CHANNEL_3)
  3391. | (((channels_bitfield & ADC_CHSELR_CHSEL4) >> ADC_CHSELR_CHSEL4_BITOFFSET_POS) * LL_ADC_CHANNEL_4)
  3392. | (((channels_bitfield & ADC_CHSELR_CHSEL5) >> ADC_CHSELR_CHSEL5_BITOFFSET_POS) * LL_ADC_CHANNEL_5)
  3393. | (((channels_bitfield & ADC_CHSELR_CHSEL6) >> ADC_CHSELR_CHSEL6_BITOFFSET_POS) * LL_ADC_CHANNEL_6)
  3394. | (((channels_bitfield & ADC_CHSELR_CHSEL7) >> ADC_CHSELR_CHSEL7_BITOFFSET_POS) * LL_ADC_CHANNEL_7)
  3395. | (((channels_bitfield & ADC_CHSELR_CHSEL8) >> ADC_CHSELR_CHSEL8_BITOFFSET_POS) * LL_ADC_CHANNEL_8)
  3396. | (((channels_bitfield & ADC_CHSELR_CHSEL9) >> ADC_CHSELR_CHSEL9_BITOFFSET_POS) * LL_ADC_CHANNEL_9)
  3397. | (((channels_bitfield & ADC_CHSELR_CHSEL10) >> ADC_CHSELR_CHSEL10_BITOFFSET_POS) * LL_ADC_CHANNEL_10)
  3398. | (((channels_bitfield & ADC_CHSELR_CHSEL11) >> ADC_CHSELR_CHSEL11_BITOFFSET_POS) * LL_ADC_CHANNEL_11)
  3399. | (((channels_bitfield & ADC_CHSELR_CHSEL12) >> ADC_CHSELR_CHSEL12_BITOFFSET_POS) * LL_ADC_CHANNEL_12)
  3400. | (((channels_bitfield & ADC_CHSELR_CHSEL13) >> ADC_CHSELR_CHSEL13_BITOFFSET_POS) * LL_ADC_CHANNEL_13)
  3401. | (((channels_bitfield & ADC_CHSELR_CHSEL14) >> ADC_CHSELR_CHSEL14_BITOFFSET_POS) * LL_ADC_CHANNEL_14)
  3402. | (((channels_bitfield & ADC_CHSELR_CHSEL15) >> ADC_CHSELR_CHSEL15_BITOFFSET_POS) * LL_ADC_CHANNEL_15)
  3403. | (((channels_bitfield & ADC_CHSELR_CHSEL16) >> ADC_CHSELR_CHSEL16_BITOFFSET_POS) * LL_ADC_CHANNEL_16)
  3404. | (((channels_bitfield & ADC_CHSELR_CHSEL17) >> ADC_CHSELR_CHSEL17_BITOFFSET_POS) * LL_ADC_CHANNEL_17)
  3405. #if defined(ADC_CCR_VBATEN)
  3406. | (((channels_bitfield & ADC_CHSELR_CHSEL18) >> ADC_CHSELR_CHSEL18_BITOFFSET_POS) * LL_ADC_CHANNEL_18)
  3407. #endif /* ADC_CCR_VBATEN */
  3408. );
  3409. }
  3410. /**
  3411. * @brief Set ADC continuous conversion mode on ADC group regular.
  3412. * @note Description of ADC continuous conversion mode:
  3413. * - single mode: one conversion per trigger
  3414. * - continuous mode: after the first trigger, following
  3415. * conversions launched successively automatically.
  3416. * @note It is not possible to enable both ADC group regular
  3417. * continuous mode and sequencer discontinuous mode.
  3418. * @note On this STM32 series, setting of this feature is conditioned to
  3419. * ADC state:
  3420. * ADC must be disabled.
  3421. * @rmtoll CFGR1 CONT LL_ADC_REG_SetContinuousMode
  3422. * @param ADCx ADC instance
  3423. * @param Continuous This parameter can be one of the following values:
  3424. * @arg @ref LL_ADC_REG_CONV_SINGLE
  3425. * @arg @ref LL_ADC_REG_CONV_CONTINUOUS
  3426. * @retval None
  3427. */
  3428. __STATIC_INLINE void LL_ADC_REG_SetContinuousMode(ADC_TypeDef *ADCx, uint32_t Continuous)
  3429. {
  3430. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_CONT, Continuous);
  3431. }
  3432. /**
  3433. * @brief Get ADC continuous conversion mode on ADC group regular.
  3434. * @note Description of ADC continuous conversion mode:
  3435. * - single mode: one conversion per trigger
  3436. * - continuous mode: after the first trigger, following
  3437. * conversions launched successively automatically.
  3438. * @rmtoll CFGR1 CONT LL_ADC_REG_GetContinuousMode
  3439. * @param ADCx ADC instance
  3440. * @retval Returned value can be one of the following values:
  3441. * @arg @ref LL_ADC_REG_CONV_SINGLE
  3442. * @arg @ref LL_ADC_REG_CONV_CONTINUOUS
  3443. */
  3444. __STATIC_INLINE uint32_t LL_ADC_REG_GetContinuousMode(const ADC_TypeDef *ADCx)
  3445. {
  3446. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_CONT));
  3447. }
  3448. /**
  3449. * @brief Set ADC group regular conversion data transfer: no transfer or
  3450. * transfer by DMA, and DMA requests mode.
  3451. * @note If transfer by DMA selected, specifies the DMA requests
  3452. * mode:
  3453. * - Limited mode (One shot mode): DMA transfer requests are stopped
  3454. * when number of DMA data transfers (number of
  3455. * ADC conversions) is reached.
  3456. * This ADC mode is intended to be used with DMA mode non-circular.
  3457. * - Unlimited mode: DMA transfer requests are unlimited,
  3458. * whatever number of DMA data transfers (number of
  3459. * ADC conversions).
  3460. * This ADC mode is intended to be used with DMA mode circular.
  3461. * @note If ADC DMA requests mode is set to unlimited and DMA is set to
  3462. * mode non-circular:
  3463. * when DMA transfers size will be reached, DMA will stop transfers of
  3464. * ADC conversions data ADC will raise an overrun error
  3465. * (overrun flag and interruption if enabled).
  3466. * @note To configure DMA source address (peripheral address),
  3467. * use function @ref LL_ADC_DMA_GetRegAddr().
  3468. * @note On this STM32 series, setting of this feature is conditioned to
  3469. * ADC state:
  3470. * ADC must be disabled.
  3471. * @rmtoll CFGR1 DMAEN LL_ADC_REG_SetDMATransfer\n
  3472. * CFGR1 DMACFG LL_ADC_REG_SetDMATransfer
  3473. * @param ADCx ADC instance
  3474. * @param DMATransfer This parameter can be one of the following values:
  3475. * @arg @ref LL_ADC_REG_DMA_TRANSFER_NONE
  3476. * @arg @ref LL_ADC_REG_DMA_TRANSFER_LIMITED
  3477. * @arg @ref LL_ADC_REG_DMA_TRANSFER_UNLIMITED
  3478. * @retval None
  3479. */
  3480. __STATIC_INLINE void LL_ADC_REG_SetDMATransfer(ADC_TypeDef *ADCx, uint32_t DMATransfer)
  3481. {
  3482. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG, DMATransfer);
  3483. }
  3484. /**
  3485. * @brief Get ADC group regular conversion data transfer: no transfer or
  3486. * transfer by DMA, and DMA requests mode.
  3487. * @note If transfer by DMA selected, specifies the DMA requests
  3488. * mode:
  3489. * - Limited mode (One shot mode): DMA transfer requests are stopped
  3490. * when number of DMA data transfers (number of
  3491. * ADC conversions) is reached.
  3492. * This ADC mode is intended to be used with DMA mode non-circular.
  3493. * - Unlimited mode: DMA transfer requests are unlimited,
  3494. * whatever number of DMA data transfers (number of
  3495. * ADC conversions).
  3496. * This ADC mode is intended to be used with DMA mode circular.
  3497. * @note If ADC DMA requests mode is set to unlimited and DMA is set to
  3498. * mode non-circular:
  3499. * when DMA transfers size will be reached, DMA will stop transfers of
  3500. * ADC conversions data ADC will raise an overrun error
  3501. * (overrun flag and interruption if enabled).
  3502. * @note To configure DMA source address (peripheral address),
  3503. * use function @ref LL_ADC_DMA_GetRegAddr().
  3504. * @rmtoll CFGR1 DMAEN LL_ADC_REG_GetDMATransfer\n
  3505. * CFGR1 DMACFG LL_ADC_REG_GetDMATransfer
  3506. * @param ADCx ADC instance
  3507. * @retval Returned value can be one of the following values:
  3508. * @arg @ref LL_ADC_REG_DMA_TRANSFER_NONE
  3509. * @arg @ref LL_ADC_REG_DMA_TRANSFER_LIMITED
  3510. * @arg @ref LL_ADC_REG_DMA_TRANSFER_UNLIMITED
  3511. */
  3512. __STATIC_INLINE uint32_t LL_ADC_REG_GetDMATransfer(const ADC_TypeDef *ADCx)
  3513. {
  3514. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG));
  3515. }
  3516. /**
  3517. * @brief Set ADC group regular behavior in case of overrun:
  3518. * data preserved or overwritten.
  3519. * @note Compatibility with devices without feature overrun:
  3520. * other devices without this feature have a behavior
  3521. * equivalent to data overwritten.
  3522. * The default setting of overrun is data preserved.
  3523. * Therefore, for compatibility with all devices, parameter
  3524. * overrun should be set to data overwritten.
  3525. * @note On this STM32 series, setting of this feature is conditioned to
  3526. * ADC state:
  3527. * ADC must be disabled.
  3528. * @rmtoll CFGR1 OVRMOD LL_ADC_REG_SetOverrun
  3529. * @param ADCx ADC instance
  3530. * @param Overrun This parameter can be one of the following values:
  3531. * @arg @ref LL_ADC_REG_OVR_DATA_PRESERVED
  3532. * @arg @ref LL_ADC_REG_OVR_DATA_OVERWRITTEN
  3533. * @retval None
  3534. */
  3535. __STATIC_INLINE void LL_ADC_REG_SetOverrun(ADC_TypeDef *ADCx, uint32_t Overrun)
  3536. {
  3537. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_OVRMOD, Overrun);
  3538. }
  3539. /**
  3540. * @brief Get ADC group regular behavior in case of overrun:
  3541. * data preserved or overwritten.
  3542. * @rmtoll CFGR1 OVRMOD LL_ADC_REG_GetOverrun
  3543. * @param ADCx ADC instance
  3544. * @retval Returned value can be one of the following values:
  3545. * @arg @ref LL_ADC_REG_OVR_DATA_PRESERVED
  3546. * @arg @ref LL_ADC_REG_OVR_DATA_OVERWRITTEN
  3547. */
  3548. __STATIC_INLINE uint32_t LL_ADC_REG_GetOverrun(const ADC_TypeDef *ADCx)
  3549. {
  3550. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_OVRMOD));
  3551. }
  3552. /**
  3553. * @}
  3554. */
  3555. /** @defgroup ADC_LL_EF_Configuration_Channels Configuration of ADC hierarchical scope: channels
  3556. * @{
  3557. */
  3558. /**
  3559. * @brief Set sampling time of the selected ADC channel
  3560. * Unit: ADC clock cycles.
  3561. * @note On this device, sampling time is on channel scope: independently
  3562. * of channel mapped on ADC group regular or injected.
  3563. * @note In case of internal channel (VrefInt, TempSensor, ...) to be
  3564. * converted:
  3565. * sampling time constraints must be respected (sampling time can be
  3566. * adjusted in function of ADC clock frequency and sampling time
  3567. * setting).
  3568. * Refer to device datasheet for timings values (parameters TS_vrefint,
  3569. * TS_temp, ...).
  3570. * @note Conversion time is the addition of sampling time and processing time.
  3571. * Refer to reference manual for ADC processing time of
  3572. * this STM32 series.
  3573. * @note In case of ADC conversion of internal channel (VrefInt,
  3574. * temperature sensor, ...), a sampling time minimum value
  3575. * is required.
  3576. * Refer to device datasheet.
  3577. * @note On this STM32 series, setting of this feature is conditioned to
  3578. * ADC state:
  3579. * ADC must be disabled or enabled without conversion on going
  3580. * on group regular.
  3581. * @rmtoll SMPR SMPSEL0 LL_ADC_SetChannelSamplingTime\n
  3582. * SMPR SMPSEL1 LL_ADC_SetChannelSamplingTime\n
  3583. * SMPR SMPSEL2 LL_ADC_SetChannelSamplingTime\n
  3584. * SMPR SMPSEL3 LL_ADC_SetChannelSamplingTime\n
  3585. * SMPR SMPSEL4 LL_ADC_SetChannelSamplingTime\n
  3586. * SMPR SMPSEL5 LL_ADC_SetChannelSamplingTime\n
  3587. * SMPR SMPSEL6 LL_ADC_SetChannelSamplingTime\n
  3588. * SMPR SMPSEL7 LL_ADC_SetChannelSamplingTime\n
  3589. * SMPR SMPSEL8 LL_ADC_SetChannelSamplingTime\n
  3590. * SMPR SMPSEL9 LL_ADC_SetChannelSamplingTime\n
  3591. * SMPR SMPSEL10 LL_ADC_SetChannelSamplingTime\n
  3592. * SMPR SMPSEL11 LL_ADC_SetChannelSamplingTime\n
  3593. * SMPR SMPSEL12 LL_ADC_SetChannelSamplingTime\n
  3594. * SMPR SMPSEL13 LL_ADC_SetChannelSamplingTime\n
  3595. * SMPR SMPSEL14 LL_ADC_SetChannelSamplingTime\n
  3596. * SMPR SMPSEL15 LL_ADC_SetChannelSamplingTime\n
  3597. * SMPR SMPSEL16 LL_ADC_SetChannelSamplingTime\n
  3598. * SMPR SMPSEL17 LL_ADC_SetChannelSamplingTime\n
  3599. * SMPR SMPSEL18 LL_ADC_SetChannelSamplingTime
  3600. * @param ADCx ADC instance
  3601. * @param Channel This parameter can be a combination of the following values:
  3602. * @arg @ref LL_ADC_CHANNEL_0
  3603. * @arg @ref LL_ADC_CHANNEL_1
  3604. * @arg @ref LL_ADC_CHANNEL_2
  3605. * @arg @ref LL_ADC_CHANNEL_3
  3606. * @arg @ref LL_ADC_CHANNEL_4
  3607. * @arg @ref LL_ADC_CHANNEL_5
  3608. * @arg @ref LL_ADC_CHANNEL_6
  3609. * @arg @ref LL_ADC_CHANNEL_7
  3610. * @arg @ref LL_ADC_CHANNEL_8
  3611. * @arg @ref LL_ADC_CHANNEL_9
  3612. * @arg @ref LL_ADC_CHANNEL_10
  3613. * @arg @ref LL_ADC_CHANNEL_11
  3614. * @arg @ref LL_ADC_CHANNEL_12
  3615. * @arg @ref LL_ADC_CHANNEL_13
  3616. * @arg @ref LL_ADC_CHANNEL_14
  3617. * @arg @ref LL_ADC_CHANNEL_15 (1)
  3618. * @arg @ref LL_ADC_CHANNEL_16 (1)
  3619. * @arg @ref LL_ADC_CHANNEL_17 (1)
  3620. * @arg @ref LL_ADC_CHANNEL_18
  3621. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3622. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3623. * @arg @ref LL_ADC_CHANNEL_VBAT
  3624. *
  3625. * (1) On STM32G0, parameter can be set in ADC group sequencer
  3626. * only if sequencer is set in mode "not fully configurable",
  3627. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  3628. * @param SamplingTimeY This parameter can be one of the following values:
  3629. * @arg @ref LL_ADC_SAMPLINGTIME_COMMON_1
  3630. * @arg @ref LL_ADC_SAMPLINGTIME_COMMON_2
  3631. * @retval None
  3632. */
  3633. __STATIC_INLINE void LL_ADC_SetChannelSamplingTime(ADC_TypeDef *ADCx, uint32_t Channel, uint32_t SamplingTimeY)
  3634. {
  3635. /* Parameter "Channel" is used with masks because containing */
  3636. /* other bits reserved for other purpose. */
  3637. MODIFY_REG(ADCx->SMPR,
  3638. (Channel << ADC_SMPR_SMPSEL0_BITOFFSET_POS),
  3639. (Channel << ADC_SMPR_SMPSEL0_BITOFFSET_POS) & (SamplingTimeY & ADC_SAMPLING_TIME_CH_MASK)
  3640. );
  3641. }
  3642. /**
  3643. * @brief Get sampling time of the selected ADC channel
  3644. * Unit: ADC clock cycles.
  3645. * @note On this device, sampling time is on channel scope: independently
  3646. * of channel mapped on ADC group regular or injected.
  3647. * @note Conversion time is the addition of sampling time and processing time.
  3648. * Refer to reference manual for ADC processing time of
  3649. * this STM32 series.
  3650. * @rmtoll SMPR SMPSEL0 LL_ADC_GetChannelSamplingTime\n
  3651. * SMPR SMPSEL1 LL_ADC_GetChannelSamplingTime\n
  3652. * SMPR SMPSEL2 LL_ADC_GetChannelSamplingTime\n
  3653. * SMPR SMPSEL3 LL_ADC_GetChannelSamplingTime\n
  3654. * SMPR SMPSEL4 LL_ADC_GetChannelSamplingTime\n
  3655. * SMPR SMPSEL5 LL_ADC_GetChannelSamplingTime\n
  3656. * SMPR SMPSEL6 LL_ADC_GetChannelSamplingTime\n
  3657. * SMPR SMPSEL7 LL_ADC_GetChannelSamplingTime\n
  3658. * SMPR SMPSEL8 LL_ADC_GetChannelSamplingTime\n
  3659. * SMPR SMPSEL9 LL_ADC_GetChannelSamplingTime\n
  3660. * SMPR SMPSEL10 LL_ADC_GetChannelSamplingTime\n
  3661. * SMPR SMPSEL11 LL_ADC_GetChannelSamplingTime\n
  3662. * SMPR SMPSEL12 LL_ADC_GetChannelSamplingTime\n
  3663. * SMPR SMPSEL13 LL_ADC_GetChannelSamplingTime\n
  3664. * SMPR SMPSEL14 LL_ADC_GetChannelSamplingTime\n
  3665. * SMPR SMPSEL15 LL_ADC_GetChannelSamplingTime\n
  3666. * SMPR SMPSEL16 LL_ADC_GetChannelSamplingTime\n
  3667. * SMPR SMPSEL17 LL_ADC_GetChannelSamplingTime\n
  3668. * SMPR SMPSEL18 LL_ADC_GetChannelSamplingTime
  3669. * @param ADCx ADC instance
  3670. * @param Channel This parameter can be one of the following values:
  3671. * @arg @ref LL_ADC_CHANNEL_0
  3672. * @arg @ref LL_ADC_CHANNEL_1
  3673. * @arg @ref LL_ADC_CHANNEL_2
  3674. * @arg @ref LL_ADC_CHANNEL_3
  3675. * @arg @ref LL_ADC_CHANNEL_4
  3676. * @arg @ref LL_ADC_CHANNEL_5
  3677. * @arg @ref LL_ADC_CHANNEL_6
  3678. * @arg @ref LL_ADC_CHANNEL_7
  3679. * @arg @ref LL_ADC_CHANNEL_8
  3680. * @arg @ref LL_ADC_CHANNEL_9
  3681. * @arg @ref LL_ADC_CHANNEL_10
  3682. * @arg @ref LL_ADC_CHANNEL_11
  3683. * @arg @ref LL_ADC_CHANNEL_12
  3684. * @arg @ref LL_ADC_CHANNEL_13
  3685. * @arg @ref LL_ADC_CHANNEL_14
  3686. * @arg @ref LL_ADC_CHANNEL_15 (1)
  3687. * @arg @ref LL_ADC_CHANNEL_16 (1)
  3688. * @arg @ref LL_ADC_CHANNEL_17 (1)
  3689. * @arg @ref LL_ADC_CHANNEL_18
  3690. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3691. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3692. * @arg @ref LL_ADC_CHANNEL_VBAT
  3693. *
  3694. * (1) On STM32G0, parameter can be set in ADC group sequencer
  3695. * only if sequencer is set in mode "not fully configurable",
  3696. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  3697. * @retval Returned value can be one of the following values:
  3698. * @arg @ref LL_ADC_SAMPLINGTIME_COMMON_1
  3699. * @arg @ref LL_ADC_SAMPLINGTIME_COMMON_2
  3700. */
  3701. __STATIC_INLINE uint32_t LL_ADC_GetChannelSamplingTime(const ADC_TypeDef *ADCx, uint32_t Channel)
  3702. {
  3703. __IO uint32_t smpr = READ_REG(ADCx->SMPR);
  3704. /* Retrieve sampling time bit corresponding to the selected channel */
  3705. /* and shift it to position 0. */
  3706. uint32_t smp_channel_posbit0 = ((smpr & ADC_SAMPLING_TIME_CH_MASK)
  3707. >> ((((Channel & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS)
  3708. + ADC_SMPR_SMPSEL0_BITOFFSET_POS)
  3709. & 0x1FUL));
  3710. /* Select sampling time bitfield depending on sampling time bit value 0 or 1. */
  3711. return ((~(smp_channel_posbit0) * LL_ADC_SAMPLINGTIME_COMMON_1)
  3712. | (smp_channel_posbit0 * LL_ADC_SAMPLINGTIME_COMMON_2));
  3713. }
  3714. /**
  3715. * @}
  3716. */
  3717. /** @defgroup ADC_LL_EF_Configuration_ADC_AnalogWatchdog Configuration of ADC transversal scope: analog watchdog
  3718. * @{
  3719. */
  3720. /**
  3721. * @brief Set ADC analog watchdog monitored channels:
  3722. * a single channel, multiple channels or all channels,
  3723. * on ADC group regular.
  3724. * @note Once monitored channels are selected, analog watchdog
  3725. * is enabled.
  3726. * @note In case of need to define a single channel to monitor
  3727. * with analog watchdog from sequencer channel definition,
  3728. * use helper macro @ref __LL_ADC_ANALOGWD_CHANNEL_GROUP().
  3729. * @note On this STM32 series, there are 2 kinds of analog watchdog
  3730. * instance:
  3731. * - AWD standard (instance AWD1):
  3732. * - channels monitored: can monitor 1 channel or all channels.
  3733. * - groups monitored: ADC group regular.
  3734. * - resolution: resolution is not limited (corresponds to
  3735. * ADC resolution configured).
  3736. * - AWD flexible (instances AWD2, AWD3):
  3737. * - channels monitored: flexible on channels monitored, selection is
  3738. * channel wise, from from 1 to all channels.
  3739. * Specificity of this analog watchdog: Multiple channels can
  3740. * be selected. For example:
  3741. * (LL_ADC_AWD_CHANNEL4_REG_INJ | LL_ADC_AWD_CHANNEL5_REG_INJ | ...)
  3742. * - groups monitored: not selection possible (monitoring on both
  3743. * groups regular and injected).
  3744. * Channels selected are monitored on groups regular and injected:
  3745. * LL_ADC_AWD_CHANNELxx_REG_INJ (do not use parameters
  3746. * LL_ADC_AWD_CHANNELxx_REG and LL_ADC_AWD_CHANNELxx_INJ)
  3747. * - resolution: resolution is not limited (corresponds to
  3748. * ADC resolution configured).
  3749. * @note On this STM32 series, setting of this feature is conditioned to
  3750. * ADC state:
  3751. * ADC must be disabled.
  3752. * @rmtoll CFGR1 AWD1CH LL_ADC_SetAnalogWDMonitChannels\n
  3753. * CFGR1 AWD1SGL LL_ADC_SetAnalogWDMonitChannels\n
  3754. * CFGR1 AWD1EN LL_ADC_SetAnalogWDMonitChannels\n
  3755. * AWD2CR AWD2CH LL_ADC_SetAnalogWDMonitChannels\n
  3756. * AWD3CR AWD3CH LL_ADC_SetAnalogWDMonitChannels
  3757. * @param ADCx ADC instance
  3758. * @param AWDy This parameter can be one of the following values:
  3759. * @arg @ref LL_ADC_AWD1
  3760. * @arg @ref LL_ADC_AWD2
  3761. * @arg @ref LL_ADC_AWD3
  3762. * @param AWDChannelGroup This parameter can be one of the following values:
  3763. * @arg @ref LL_ADC_AWD_DISABLE
  3764. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG
  3765. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG
  3766. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG
  3767. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG
  3768. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG
  3769. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG
  3770. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG
  3771. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG
  3772. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG
  3773. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG
  3774. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG
  3775. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG
  3776. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG
  3777. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG
  3778. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG
  3779. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG
  3780. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG
  3781. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG
  3782. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG
  3783. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG
  3784. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG
  3785. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG
  3786. * @arg @ref LL_ADC_AWD_CH_VBAT_REG
  3787. * @retval None
  3788. */
  3789. __STATIC_INLINE void LL_ADC_SetAnalogWDMonitChannels(ADC_TypeDef *ADCx, uint32_t AWDy, uint32_t AWDChannelGroup)
  3790. {
  3791. /* Set bits with content of parameter "AWDChannelGroup" with bits position */
  3792. /* in register and register position depending on parameter "AWDy". */
  3793. /* Parameters "AWDChannelGroup" and "AWDy" are used with masks because */
  3794. /* containing other bits reserved for other purpose. */
  3795. __IO uint32_t *preg;
  3796. if (AWDy == LL_ADC_AWD1)
  3797. {
  3798. preg = __ADC_PTR_REG_OFFSET(ADCx->CFGR1, 0UL);
  3799. }
  3800. else
  3801. {
  3802. preg = __ADC_PTR_REG_OFFSET(ADCx->AWD2CR,
  3803. ((AWDy & ADC_AWD_CRX_REGOFFSET_MASK)) >> (ADC_AWD_CRX_REGOFFSET_BITOFFSET_POS + 1UL));
  3804. }
  3805. MODIFY_REG(*preg,
  3806. (AWDy & ADC_AWD_CR_ALL_CHANNEL_MASK),
  3807. AWDChannelGroup & AWDy);
  3808. }
  3809. /**
  3810. * @brief Get ADC analog watchdog monitored channel.
  3811. * @note Usage of the returned channel number:
  3812. * - To reinject this channel into another function LL_ADC_xxx:
  3813. * the returned channel number is only partly formatted on definition
  3814. * of literals LL_ADC_CHANNEL_x. Therefore, it has to be compared
  3815. * with parts of literals LL_ADC_CHANNEL_x or using
  3816. * helper macro @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  3817. * Then the selected literal LL_ADC_CHANNEL_x can be used
  3818. * as parameter for another function.
  3819. * - To get the channel number in decimal format:
  3820. * process the returned value with the helper macro
  3821. * @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  3822. * Applicable only when the analog watchdog is set to monitor
  3823. * one channel.
  3824. * @note On this STM32 series, there are 2 kinds of analog watchdog
  3825. * instance:
  3826. * - AWD standard (instance AWD1):
  3827. * - channels monitored: can monitor 1 channel or all channels.
  3828. * - groups monitored: ADC group regular.
  3829. * - resolution: resolution is not limited (corresponds to
  3830. * ADC resolution configured).
  3831. * - AWD flexible (instances AWD2, AWD3):
  3832. * - channels monitored: flexible on channels monitored, selection is
  3833. * channel wise, from from 1 to all channels.
  3834. * Specificity of this analog watchdog: Multiple channels can
  3835. * be selected. For example:
  3836. * (LL_ADC_AWD_CHANNEL4_REG_INJ | LL_ADC_AWD_CHANNEL5_REG_INJ | ...)
  3837. * - groups monitored: not selection possible (monitoring on both
  3838. * groups regular and injected).
  3839. * Channels selected are monitored on groups regular and injected:
  3840. * LL_ADC_AWD_CHANNELxx_REG_INJ (do not use parameters
  3841. * LL_ADC_AWD_CHANNELxx_REG and LL_ADC_AWD_CHANNELxx_INJ)
  3842. * - resolution: resolution is not limited (corresponds to
  3843. * ADC resolution configured).
  3844. * @note On this STM32 series, setting of this feature is conditioned to
  3845. * ADC state:
  3846. * ADC must be disabled or enabled without conversion on going
  3847. * on group regular.
  3848. * @rmtoll CFGR1 AWD1CH LL_ADC_GetAnalogWDMonitChannels\n
  3849. * CFGR1 AWD1SGL LL_ADC_GetAnalogWDMonitChannels\n
  3850. * CFGR1 AWD1EN LL_ADC_GetAnalogWDMonitChannels\n
  3851. * AWD2CR AWD2CH LL_ADC_GetAnalogWDMonitChannels\n
  3852. * AWD3CR AWD3CH LL_ADC_GetAnalogWDMonitChannels
  3853. * @param ADCx ADC instance
  3854. * @param AWDy This parameter can be one of the following values:
  3855. * @arg @ref LL_ADC_AWD1
  3856. * @arg @ref LL_ADC_AWD2 (1)
  3857. * @arg @ref LL_ADC_AWD3 (1)
  3858. *
  3859. * (1) On this AWD number, monitored channel can be retrieved
  3860. * if only 1 channel is programmed (or none or all channels).
  3861. * This function cannot retrieve monitored channel if
  3862. * multiple channels are programmed simultaneously
  3863. * by bitfield.
  3864. * @retval Returned value can be one of the following values:
  3865. * @arg @ref LL_ADC_AWD_DISABLE
  3866. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG
  3867. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG
  3868. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG
  3869. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG
  3870. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG
  3871. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG
  3872. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG
  3873. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG
  3874. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG
  3875. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG
  3876. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG
  3877. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG
  3878. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG
  3879. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG
  3880. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG
  3881. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG
  3882. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG
  3883. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG
  3884. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG
  3885. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG
  3886. */
  3887. __STATIC_INLINE uint32_t LL_ADC_GetAnalogWDMonitChannels(const ADC_TypeDef *ADCx, uint32_t AWDy)
  3888. {
  3889. __IO const uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->CFGR1,
  3890. ((AWDy & ADC_AWD_CRX_REGOFFSET_MASK) >> ADC_AWD_CRX_REGOFFSET_POS)
  3891. + ((AWDy & ADC_AWD_CR12_REGOFFSETGAP_MASK)
  3892. * ADC_AWD_CR12_REGOFFSETGAP_VAL));
  3893. uint32_t analog_wd_monit_channels = (READ_BIT(*preg, AWDy) & AWDy & ADC_AWD_CR_ALL_CHANNEL_MASK);
  3894. /* If "analog_wd_monit_channels" == 0, then the selected AWD is disabled */
  3895. /* (parameter value LL_ADC_AWD_DISABLE). */
  3896. /* Else, the selected AWD is enabled and is monitoring a group of channels */
  3897. /* or a single channel. */
  3898. if (analog_wd_monit_channels != 0UL)
  3899. {
  3900. if (AWDy == LL_ADC_AWD1)
  3901. {
  3902. if ((analog_wd_monit_channels & ADC_CFGR1_AWD1SGL) == 0UL)
  3903. {
  3904. /* AWD monitoring a group of channels */
  3905. analog_wd_monit_channels = ((analog_wd_monit_channels
  3906. | (ADC_AWD_CR23_CHANNEL_MASK)
  3907. )
  3908. & (~(ADC_CFGR1_AWD1CH))
  3909. );
  3910. }
  3911. else
  3912. {
  3913. /* AWD monitoring a single channel */
  3914. analog_wd_monit_channels = (analog_wd_monit_channels
  3915. | (ADC_AWD2CR_AWD2CH_0 << (analog_wd_monit_channels >> ADC_CFGR1_AWD1CH_Pos))
  3916. );
  3917. }
  3918. }
  3919. else
  3920. {
  3921. if ((analog_wd_monit_channels & ADC_AWD_CR23_CHANNEL_MASK) == ADC_AWD_CR23_CHANNEL_MASK)
  3922. {
  3923. /* AWD monitoring a group of channels */
  3924. analog_wd_monit_channels = (ADC_AWD_CR23_CHANNEL_MASK
  3925. | (ADC_CFGR1_AWD1EN)
  3926. );
  3927. }
  3928. else
  3929. {
  3930. /* AWD monitoring a single channel */
  3931. /* AWD monitoring a group of channels */
  3932. analog_wd_monit_channels = (analog_wd_monit_channels
  3933. | (ADC_CFGR1_AWD1EN | ADC_CFGR1_AWD1SGL)
  3934. | (__LL_ADC_CHANNEL_TO_DECIMAL_NB(analog_wd_monit_channels) << ADC_CFGR1_AWD1CH_Pos)
  3935. );
  3936. }
  3937. }
  3938. }
  3939. return analog_wd_monit_channels;
  3940. }
  3941. /**
  3942. * @brief Set ADC analog watchdog thresholds value of both thresholds
  3943. * high and low.
  3944. * @note If value of only one threshold high or low must be set,
  3945. * use function @ref LL_ADC_SetAnalogWDThresholds().
  3946. * @note In case of ADC resolution different of 12 bits,
  3947. * analog watchdog thresholds data require a specific shift.
  3948. * Use helper macro @ref __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION().
  3949. * @note On this STM32 series, there are 2 kinds of analog watchdog
  3950. * instance:
  3951. * - AWD standard (instance AWD1):
  3952. * - channels monitored: can monitor 1 channel or all channels.
  3953. * - groups monitored: ADC group regular.
  3954. * - resolution: resolution is not limited (corresponds to
  3955. * ADC resolution configured).
  3956. * - AWD flexible (instances AWD2, AWD3):
  3957. * - channels monitored: flexible on channels monitored, selection is
  3958. * channel wise, from from 1 to all channels.
  3959. * Specificity of this analog watchdog: Multiple channels can
  3960. * be selected. For example:
  3961. * (LL_ADC_AWD_CHANNEL4_REG_INJ | LL_ADC_AWD_CHANNEL5_REG_INJ | ...)
  3962. * - groups monitored: not selection possible (monitoring on both
  3963. * groups regular and injected).
  3964. * Channels selected are monitored on groups regular and injected:
  3965. * LL_ADC_AWD_CHANNELxx_REG_INJ (do not use parameters
  3966. * LL_ADC_AWD_CHANNELxx_REG and LL_ADC_AWD_CHANNELxx_INJ)
  3967. * - resolution: resolution is not limited (corresponds to
  3968. * ADC resolution configured).
  3969. * @note If ADC oversampling is enabled, ADC analog watchdog thresholds are
  3970. * impacted: the comparison of analog watchdog thresholds is done on
  3971. * oversampling final computation (after ratio and shift application):
  3972. * ADC data register bitfield [15:4] (12 most significant bits).
  3973. * Examples:
  3974. * - Oversampling ratio and shift selected to have ADC conversion data
  3975. * on 12 bits (ratio 16 and shift 4, or ratio 32 and shift 5, ...):
  3976. * ADC analog watchdog thresholds must be divided by 16.
  3977. * - Oversampling ratio and shift selected to have ADC conversion data
  3978. * on 14 bits (ratio 16 and shift 2, or ratio 32 and shift 3, ...):
  3979. * ADC analog watchdog thresholds must be divided by 4.
  3980. * - Oversampling ratio and shift selected to have ADC conversion data
  3981. * on 16 bits (ratio 16 and shift none, or ratio 32 and shift 1, ...):
  3982. * ADC analog watchdog thresholds match directly to ADC data register.
  3983. * @note On this STM32 series, setting of this feature is conditioned to
  3984. * ADC state:
  3985. * ADC must be disabled or enabled without conversion on going
  3986. * on group regular.
  3987. * @rmtoll AWD1TR HT1 LL_ADC_ConfigAnalogWDThresholds\n
  3988. * AWD2TR HT2 LL_ADC_ConfigAnalogWDThresholds\n
  3989. * AWD3TR HT3 LL_ADC_ConfigAnalogWDThresholds\n
  3990. * AWD1TR LT1 LL_ADC_ConfigAnalogWDThresholds\n
  3991. * AWD2TR LT2 LL_ADC_ConfigAnalogWDThresholds\n
  3992. * AWD3TR LT3 LL_ADC_ConfigAnalogWDThresholds
  3993. * @param ADCx ADC instance
  3994. * @param AWDy This parameter can be one of the following values:
  3995. * @arg @ref LL_ADC_AWD1
  3996. * @arg @ref LL_ADC_AWD2
  3997. * @arg @ref LL_ADC_AWD3
  3998. * @param AWDThresholdHighValue Value between Min_Data=0x000 and Max_Data=0xFFF
  3999. * @param AWDThresholdLowValue Value between Min_Data=0x000 and Max_Data=0xFFF
  4000. * @retval None
  4001. */
  4002. __STATIC_INLINE void LL_ADC_ConfigAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDy, uint32_t AWDThresholdHighValue,
  4003. uint32_t AWDThresholdLowValue)
  4004. {
  4005. /* Set bits with content of parameter "AWDThresholdxxxValue" with bits */
  4006. /* position in register and register position depending on parameter */
  4007. /* "AWDy". */
  4008. /* Parameters "AWDy" and "AWDThresholdxxxValue" are used with masks because */
  4009. /* containing other bits reserved for other purpose. */
  4010. __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->AWD1TR,
  4011. (((AWDy & ADC_AWD_TRX_REGOFFSET_MASK))
  4012. >> (ADC_AWD_TRX_REGOFFSET_BITOFFSET_POS))
  4013. + ((ADC_AWD_CR3_REGOFFSET & AWDy)
  4014. >> (ADC_AWD_CRX_REGOFFSET_BITOFFSET_POS + 1UL))
  4015. );
  4016. MODIFY_REG(*preg,
  4017. ADC_AWD1TR_HT1 | ADC_AWD1TR_LT1,
  4018. (AWDThresholdHighValue << ADC_TR1_HT1_BITOFFSET_POS) | AWDThresholdLowValue);
  4019. }
  4020. /**
  4021. * @brief Set ADC analog watchdog threshold value of threshold
  4022. * high or low.
  4023. * @note If values of both thresholds high or low must be set,
  4024. * use function @ref LL_ADC_ConfigAnalogWDThresholds().
  4025. * @note In case of ADC resolution different of 12 bits,
  4026. * analog watchdog thresholds data require a specific shift.
  4027. * Use helper macro @ref __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION().
  4028. * @note On this STM32 series, there are 2 kinds of analog watchdog
  4029. * instance:
  4030. * - AWD standard (instance AWD1):
  4031. * - channels monitored: can monitor 1 channel or all channels.
  4032. * - groups monitored: ADC group regular.
  4033. * - resolution: resolution is not limited (corresponds to
  4034. * ADC resolution configured).
  4035. * - AWD flexible (instances AWD2, AWD3):
  4036. * - channels monitored: flexible on channels monitored, selection is
  4037. * channel wise, from from 1 to all channels.
  4038. * Specificity of this analog watchdog: Multiple channels can
  4039. * be selected. For example:
  4040. * (LL_ADC_AWD_CHANNEL4_REG_INJ | LL_ADC_AWD_CHANNEL5_REG_INJ | ...)
  4041. * - groups monitored: not selection possible (monitoring on both
  4042. * groups regular and injected).
  4043. * Channels selected are monitored on groups regular and injected:
  4044. * LL_ADC_AWD_CHANNELxx_REG_INJ (do not use parameters
  4045. * LL_ADC_AWD_CHANNELxx_REG and LL_ADC_AWD_CHANNELxx_INJ)
  4046. * - resolution: resolution is not limited (corresponds to
  4047. * ADC resolution configured).
  4048. * @note If ADC oversampling is enabled, ADC analog watchdog thresholds are
  4049. * impacted: the comparison of analog watchdog thresholds is done on
  4050. * oversampling final computation (after ratio and shift application):
  4051. * ADC data register bitfield [15:4] (12 most significant bits).
  4052. * Examples:
  4053. * - Oversampling ratio and shift selected to have ADC conversion data
  4054. * on 12 bits (ratio 16 and shift 4, or ratio 32 and shift 5, ...):
  4055. * ADC analog watchdog thresholds must be divided by 16.
  4056. * - Oversampling ratio and shift selected to have ADC conversion data
  4057. * on 14 bits (ratio 16 and shift 2, or ratio 32 and shift 3, ...):
  4058. * ADC analog watchdog thresholds must be divided by 4.
  4059. * - Oversampling ratio and shift selected to have ADC conversion data
  4060. * on 16 bits (ratio 16 and shift none, or ratio 32 and shift 1, ...):
  4061. * ADC analog watchdog thresholds match directly to ADC data register.
  4062. * @note On this STM32 series, setting of this feature is not conditioned to
  4063. * ADC state:
  4064. * ADC can be disabled, enabled with or without conversion on going
  4065. * on ADC group regular.
  4066. * @rmtoll AWD1TR HT1 LL_ADC_SetAnalogWDThresholds\n
  4067. * AWD2TR HT2 LL_ADC_SetAnalogWDThresholds\n
  4068. * AWD3TR HT3 LL_ADC_SetAnalogWDThresholds\n
  4069. * AWD1TR LT1 LL_ADC_SetAnalogWDThresholds\n
  4070. * AWD2TR LT2 LL_ADC_SetAnalogWDThresholds\n
  4071. * AWD3TR LT3 LL_ADC_SetAnalogWDThresholds
  4072. * @param ADCx ADC instance
  4073. * @param AWDy This parameter can be one of the following values:
  4074. * @arg @ref LL_ADC_AWD1
  4075. * @arg @ref LL_ADC_AWD2
  4076. * @arg @ref LL_ADC_AWD3
  4077. * @param AWDThresholdsHighLow This parameter can be one of the following values:
  4078. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  4079. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  4080. * @param AWDThresholdValue Value between Min_Data=0x000 and Max_Data=0xFFF
  4081. * @retval None
  4082. */
  4083. __STATIC_INLINE void LL_ADC_SetAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDy, uint32_t AWDThresholdsHighLow,
  4084. uint32_t AWDThresholdValue)
  4085. {
  4086. /* Set bits with content of parameter "AWDThresholdValue" with bits */
  4087. /* position in register and register position depending on parameters */
  4088. /* "AWDThresholdsHighLow" and "AWDy". */
  4089. /* Parameters "AWDy" and "AWDThresholdValue" are used with masks because */
  4090. /* containing other bits reserved for other purpose. */
  4091. __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->AWD1TR,
  4092. (((AWDy & ADC_AWD_TRX_REGOFFSET_MASK))
  4093. >> (ADC_AWD_TRX_REGOFFSET_BITOFFSET_POS))
  4094. + ((ADC_AWD_CR3_REGOFFSET & AWDy)
  4095. >> (ADC_AWD_CRX_REGOFFSET_BITOFFSET_POS + 1UL)));
  4096. MODIFY_REG(*preg,
  4097. AWDThresholdsHighLow,
  4098. AWDThresholdValue << ((AWDThresholdsHighLow & ADC_AWD_TRX_BIT_HIGH_MASK) >> ADC_AWD_TRX_BIT_HIGH_SHIFT4));
  4099. }
  4100. /**
  4101. * @brief Get ADC analog watchdog threshold value of threshold high,
  4102. * threshold low or raw data with ADC thresholds high and low
  4103. * concatenated.
  4104. * @note If raw data with ADC thresholds high and low is retrieved,
  4105. * the data of each threshold high or low can be isolated
  4106. * using helper macro:
  4107. * @ref __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW().
  4108. * @note In case of ADC resolution different of 12 bits,
  4109. * analog watchdog thresholds data require a specific shift.
  4110. * Use helper macro @ref __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION().
  4111. * @rmtoll AWD1TR HT1 LL_ADC_GetAnalogWDThresholds\n
  4112. * AWD2TR HT2 LL_ADC_GetAnalogWDThresholds\n
  4113. * AWD3TR HT3 LL_ADC_GetAnalogWDThresholds\n
  4114. * AWD1TR LT1 LL_ADC_GetAnalogWDThresholds\n
  4115. * AWD2TR LT2 LL_ADC_GetAnalogWDThresholds\n
  4116. * AWD3TR LT3 LL_ADC_GetAnalogWDThresholds
  4117. * @param ADCx ADC instance
  4118. * @param AWDy This parameter can be one of the following values:
  4119. * @arg @ref LL_ADC_AWD1
  4120. * @arg @ref LL_ADC_AWD2
  4121. * @arg @ref LL_ADC_AWD3
  4122. * @param AWDThresholdsHighLow This parameter can be one of the following values:
  4123. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  4124. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  4125. * @arg @ref LL_ADC_AWD_THRESHOLDS_HIGH_LOW
  4126. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  4127. */
  4128. __STATIC_INLINE uint32_t LL_ADC_GetAnalogWDThresholds(const ADC_TypeDef *ADCx,
  4129. uint32_t AWDy, uint32_t AWDThresholdsHighLow)
  4130. {
  4131. /* Set bits with content of parameter "AWDThresholdValue" with bits */
  4132. /* position in register and register position depending on parameters */
  4133. /* "AWDThresholdsHighLow" and "AWDy". */
  4134. /* Parameters "AWDy" and "AWDThresholdValue" are used with masks because */
  4135. /* containing other bits reserved for other purpose. */
  4136. const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->AWD1TR,
  4137. (((AWDy & ADC_AWD_TRX_REGOFFSET_MASK))
  4138. >> (ADC_AWD_TRX_REGOFFSET_BITOFFSET_POS))
  4139. + ((ADC_AWD_CR3_REGOFFSET & AWDy)
  4140. >> (ADC_AWD_CRX_REGOFFSET_BITOFFSET_POS + 1UL)));
  4141. return (uint32_t)(READ_BIT(*preg,
  4142. (AWDThresholdsHighLow | ADC_AWD1TR_LT1))
  4143. >> (((AWDThresholdsHighLow & ADC_AWD_TRX_BIT_HIGH_MASK) >> ADC_AWD_TRX_BIT_HIGH_SHIFT4)
  4144. & ~(AWDThresholdsHighLow & ADC_AWD1TR_LT1)));
  4145. }
  4146. /**
  4147. * @}
  4148. */
  4149. /** @defgroup ADC_LL_EF_Configuration_ADC_oversampling Configuration of ADC transversal scope: oversampling
  4150. * @{
  4151. */
  4152. /**
  4153. * @brief Set ADC oversampling scope.
  4154. * @note On this STM32 series, setting of this feature is conditioned to
  4155. * ADC state:
  4156. * ADC must be disabled.
  4157. * @rmtoll CFGR2 OVSE LL_ADC_SetOverSamplingScope
  4158. * @param ADCx ADC instance
  4159. * @param OvsScope This parameter can be one of the following values:
  4160. * @arg @ref LL_ADC_OVS_DISABLE
  4161. * @arg @ref LL_ADC_OVS_GRP_REGULAR_CONTINUED
  4162. * @retval None
  4163. */
  4164. __STATIC_INLINE void LL_ADC_SetOverSamplingScope(ADC_TypeDef *ADCx, uint32_t OvsScope)
  4165. {
  4166. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_OVSE, OvsScope);
  4167. }
  4168. /**
  4169. * @brief Get ADC oversampling scope.
  4170. * @rmtoll CFGR2 OVSE LL_ADC_GetOverSamplingScope
  4171. * @param ADCx ADC instance
  4172. * @retval Returned value can be one of the following values:
  4173. * @arg @ref LL_ADC_OVS_DISABLE
  4174. * @arg @ref LL_ADC_OVS_GRP_REGULAR_CONTINUED
  4175. */
  4176. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingScope(const ADC_TypeDef *ADCx)
  4177. {
  4178. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_OVSE));
  4179. }
  4180. /**
  4181. * @brief Set ADC oversampling discontinuous mode (triggered mode)
  4182. * on the selected ADC group.
  4183. * @note Number of oversampled conversions are done either in:
  4184. * - continuous mode (all conversions of oversampling ratio
  4185. * are done from 1 trigger)
  4186. * - discontinuous mode (each conversion of oversampling ratio
  4187. * needs a trigger)
  4188. * @note On this STM32 series, setting of this feature is conditioned to
  4189. * ADC state:
  4190. * ADC must be disabled.
  4191. * @rmtoll CFGR2 TOVS LL_ADC_SetOverSamplingDiscont
  4192. * @param ADCx ADC instance
  4193. * @param OverSamplingDiscont This parameter can be one of the following values:
  4194. * @arg @ref LL_ADC_OVS_REG_CONT
  4195. * @arg @ref LL_ADC_OVS_REG_DISCONT
  4196. * @retval None
  4197. */
  4198. __STATIC_INLINE void LL_ADC_SetOverSamplingDiscont(ADC_TypeDef *ADCx, uint32_t OverSamplingDiscont)
  4199. {
  4200. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_TOVS, OverSamplingDiscont);
  4201. }
  4202. /**
  4203. * @brief Get ADC oversampling discontinuous mode (triggered mode)
  4204. * on the selected ADC group.
  4205. * @note Number of oversampled conversions are done either in:
  4206. * - continuous mode (all conversions of oversampling ratio
  4207. * are done from 1 trigger)
  4208. * - discontinuous mode (each conversion of oversampling ratio
  4209. * needs a trigger)
  4210. * @rmtoll CFGR2 TOVS LL_ADC_GetOverSamplingDiscont
  4211. * @param ADCx ADC instance
  4212. * @retval Returned value can be one of the following values:
  4213. * @arg @ref LL_ADC_OVS_REG_CONT
  4214. * @arg @ref LL_ADC_OVS_REG_DISCONT
  4215. */
  4216. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingDiscont(const ADC_TypeDef *ADCx)
  4217. {
  4218. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_TOVS));
  4219. }
  4220. /**
  4221. * @brief Set ADC oversampling
  4222. * @note This function set the 2 items of oversampling configuration:
  4223. * - ratio
  4224. * - shift
  4225. * @note On this STM32 series, setting of this feature is conditioned to
  4226. * ADC state:
  4227. * ADC must be disabled.
  4228. * @rmtoll CFGR2 OVSS LL_ADC_ConfigOverSamplingRatioShift\n
  4229. * CFGR2 OVSR LL_ADC_ConfigOverSamplingRatioShift
  4230. * @param ADCx ADC instance
  4231. * @param Ratio This parameter can be one of the following values:
  4232. * @arg @ref LL_ADC_OVS_RATIO_2
  4233. * @arg @ref LL_ADC_OVS_RATIO_4
  4234. * @arg @ref LL_ADC_OVS_RATIO_8
  4235. * @arg @ref LL_ADC_OVS_RATIO_16
  4236. * @arg @ref LL_ADC_OVS_RATIO_32
  4237. * @arg @ref LL_ADC_OVS_RATIO_64
  4238. * @arg @ref LL_ADC_OVS_RATIO_128
  4239. * @arg @ref LL_ADC_OVS_RATIO_256
  4240. * @param Shift This parameter can be one of the following values:
  4241. * @arg @ref LL_ADC_OVS_SHIFT_NONE
  4242. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_1
  4243. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_2
  4244. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_3
  4245. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_4
  4246. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_5
  4247. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_6
  4248. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_7
  4249. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_8
  4250. * @retval None
  4251. */
  4252. __STATIC_INLINE void LL_ADC_ConfigOverSamplingRatioShift(ADC_TypeDef *ADCx, uint32_t Ratio, uint32_t Shift)
  4253. {
  4254. MODIFY_REG(ADCx->CFGR2, (ADC_CFGR2_OVSS | ADC_CFGR2_OVSR), (Shift | Ratio));
  4255. }
  4256. /**
  4257. * @brief Get ADC oversampling ratio
  4258. * @rmtoll CFGR2 OVSR LL_ADC_GetOverSamplingRatio
  4259. * @param ADCx ADC instance
  4260. * @retval Ratio This parameter can be one of the following values:
  4261. * @arg @ref LL_ADC_OVS_RATIO_2
  4262. * @arg @ref LL_ADC_OVS_RATIO_4
  4263. * @arg @ref LL_ADC_OVS_RATIO_8
  4264. * @arg @ref LL_ADC_OVS_RATIO_16
  4265. * @arg @ref LL_ADC_OVS_RATIO_32
  4266. * @arg @ref LL_ADC_OVS_RATIO_64
  4267. * @arg @ref LL_ADC_OVS_RATIO_128
  4268. * @arg @ref LL_ADC_OVS_RATIO_256
  4269. */
  4270. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingRatio(const ADC_TypeDef *ADCx)
  4271. {
  4272. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_OVSR));
  4273. }
  4274. /**
  4275. * @brief Get ADC oversampling shift
  4276. * @rmtoll CFGR2 OVSS LL_ADC_GetOverSamplingShift
  4277. * @param ADCx ADC instance
  4278. * @retval Shift This parameter can be one of the following values:
  4279. * @arg @ref LL_ADC_OVS_SHIFT_NONE
  4280. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_1
  4281. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_2
  4282. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_3
  4283. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_4
  4284. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_5
  4285. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_6
  4286. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_7
  4287. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_8
  4288. */
  4289. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingShift(const ADC_TypeDef *ADCx)
  4290. {
  4291. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_OVSS));
  4292. }
  4293. /**
  4294. * @}
  4295. */
  4296. /** @defgroup ADC_LL_EF_Operation_ADC_Instance Operation on ADC hierarchical scope: ADC instance
  4297. * @{
  4298. */
  4299. /**
  4300. * @brief Enable ADC instance internal voltage regulator.
  4301. * @note On this STM32 series, there are three possibilities to enable
  4302. * the voltage regulator:
  4303. * - by enabling it manually
  4304. * using function @ref LL_ADC_EnableInternalRegulator().
  4305. * - by launching a calibration
  4306. * using function @ref LL_ADC_StartCalibration().
  4307. * - by enabling the ADC
  4308. * using function @ref LL_ADC_Enable().
  4309. * @note On this STM32 series, after ADC internal voltage regulator enable,
  4310. * a delay for ADC internal voltage regulator stabilization
  4311. * is required before performing a ADC calibration or ADC enable.
  4312. * Refer to device datasheet, parameter "tADCVREG_STUP".
  4313. * Refer to literal @ref LL_ADC_DELAY_INTERNAL_REGUL_STAB_US.
  4314. * @note On this STM32 series, setting of this feature is conditioned to
  4315. * ADC state:
  4316. * ADC must be ADC disabled.
  4317. * @rmtoll CR ADVREGEN LL_ADC_EnableInternalRegulator
  4318. * @param ADCx ADC instance
  4319. * @retval None
  4320. */
  4321. __STATIC_INLINE void LL_ADC_EnableInternalRegulator(ADC_TypeDef *ADCx)
  4322. {
  4323. /* Note: Write register with some additional bits forced to state reset */
  4324. /* instead of modifying only the selected bit for this function, */
  4325. /* to not interfere with bits with HW property "rs". */
  4326. MODIFY_REG(ADCx->CR,
  4327. ADC_CR_BITS_PROPERTY_RS,
  4328. ADC_CR_ADVREGEN);
  4329. }
  4330. /**
  4331. * @brief Disable ADC internal voltage regulator.
  4332. * @note On this STM32 series, setting of this feature is conditioned to
  4333. * ADC state:
  4334. * ADC must be ADC disabled.
  4335. * @rmtoll CR ADVREGEN LL_ADC_DisableInternalRegulator
  4336. * @param ADCx ADC instance
  4337. * @retval None
  4338. */
  4339. __STATIC_INLINE void LL_ADC_DisableInternalRegulator(ADC_TypeDef *ADCx)
  4340. {
  4341. CLEAR_BIT(ADCx->CR, (ADC_CR_ADVREGEN | ADC_CR_BITS_PROPERTY_RS));
  4342. }
  4343. /**
  4344. * @brief Get the selected ADC instance internal voltage regulator state.
  4345. * @rmtoll CR ADVREGEN LL_ADC_IsInternalRegulatorEnabled
  4346. * @param ADCx ADC instance
  4347. * @retval 0: internal regulator is disabled, 1: internal regulator is enabled.
  4348. */
  4349. __STATIC_INLINE uint32_t LL_ADC_IsInternalRegulatorEnabled(const ADC_TypeDef *ADCx)
  4350. {
  4351. return ((READ_BIT(ADCx->CR, ADC_CR_ADVREGEN) == (ADC_CR_ADVREGEN)) ? 1UL : 0UL);
  4352. }
  4353. /**
  4354. * @brief Enable the selected ADC instance.
  4355. * @note On this STM32 series, after ADC enable, a delay for
  4356. * ADC internal analog stabilization is required before performing a
  4357. * ADC conversion start.
  4358. * Refer to device datasheet, parameter tSTAB.
  4359. * @note On this STM32 series, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  4360. * is enabled and when conversion clock is active.
  4361. * (not only core clock: this ADC has a dual clock domain)
  4362. * @note On this STM32 series, setting of this feature is conditioned to
  4363. * ADC state:
  4364. * ADC must be ADC disabled and ADC internal voltage regulator enabled.
  4365. * @rmtoll CR ADEN LL_ADC_Enable
  4366. * @param ADCx ADC instance
  4367. * @retval None
  4368. */
  4369. __STATIC_INLINE void LL_ADC_Enable(ADC_TypeDef *ADCx)
  4370. {
  4371. /* Note: Write register with some additional bits forced to state reset */
  4372. /* instead of modifying only the selected bit for this function, */
  4373. /* to not interfere with bits with HW property "rs". */
  4374. MODIFY_REG(ADCx->CR,
  4375. ADC_CR_BITS_PROPERTY_RS,
  4376. ADC_CR_ADEN);
  4377. }
  4378. /**
  4379. * @brief Disable the selected ADC instance.
  4380. * @note On this STM32 series, setting of this feature is conditioned to
  4381. * ADC state:
  4382. * ADC must be not disabled. Must be enabled without conversion on going
  4383. * on group regular.
  4384. * @rmtoll CR ADDIS LL_ADC_Disable
  4385. * @param ADCx ADC instance
  4386. * @retval None
  4387. */
  4388. __STATIC_INLINE void LL_ADC_Disable(ADC_TypeDef *ADCx)
  4389. {
  4390. /* Note: Write register with some additional bits forced to state reset */
  4391. /* instead of modifying only the selected bit for this function, */
  4392. /* to not interfere with bits with HW property "rs". */
  4393. MODIFY_REG(ADCx->CR,
  4394. ADC_CR_BITS_PROPERTY_RS,
  4395. ADC_CR_ADDIS);
  4396. }
  4397. /**
  4398. * @brief Get the selected ADC instance enable state.
  4399. * @note On this STM32 series, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  4400. * is enabled and when conversion clock is active.
  4401. * (not only core clock: this ADC has a dual clock domain)
  4402. * @rmtoll CR ADEN LL_ADC_IsEnabled
  4403. * @param ADCx ADC instance
  4404. * @retval 0: ADC is disabled, 1: ADC is enabled.
  4405. */
  4406. __STATIC_INLINE uint32_t LL_ADC_IsEnabled(const ADC_TypeDef *ADCx)
  4407. {
  4408. return ((READ_BIT(ADCx->CR, ADC_CR_ADEN) == (ADC_CR_ADEN)) ? 1UL : 0UL);
  4409. }
  4410. /**
  4411. * @brief Get the selected ADC instance disable state.
  4412. * @rmtoll CR ADDIS LL_ADC_IsDisableOngoing
  4413. * @param ADCx ADC instance
  4414. * @retval 0: no ADC disable command on going.
  4415. */
  4416. __STATIC_INLINE uint32_t LL_ADC_IsDisableOngoing(const ADC_TypeDef *ADCx)
  4417. {
  4418. return ((READ_BIT(ADCx->CR, ADC_CR_ADDIS) == (ADC_CR_ADDIS)) ? 1UL : 0UL);
  4419. }
  4420. /**
  4421. * @brief Start ADC calibration in the mode single-ended
  4422. * or differential (for devices with differential mode available).
  4423. * @note On this STM32 series, a minimum number of ADC clock cycles
  4424. * are required between ADC end of calibration and ADC enable.
  4425. * Refer to literal @ref LL_ADC_DELAY_CALIB_ENABLE_ADC_CYCLES.
  4426. * @note In case of usage of ADC with DMA transfer:
  4427. * On this STM32 series, ADC DMA transfer request should be disabled
  4428. * during calibration:
  4429. * Calibration factor is available in data register
  4430. * and also transferred by DMA.
  4431. * To not insert ADC calibration factor among ADC conversion data
  4432. * in array variable, DMA transfer must be disabled during
  4433. * calibration.
  4434. * (DMA transfer setting backup and disable before calibration,
  4435. * DMA transfer setting restore after calibration.
  4436. * Refer to functions @ref LL_ADC_REG_GetDMATransfer(),
  4437. * @ref LL_ADC_REG_SetDMATransfer() ).
  4438. * @note In case of usage of feature auto power-off:
  4439. * This mode must be disabled during calibration
  4440. * Refer to function @ref LL_ADC_SetLowPowerMode().
  4441. * @note On this STM32 series, setting of this feature is conditioned to
  4442. * ADC state:
  4443. * ADC must be ADC disabled.
  4444. * @rmtoll CR ADCAL LL_ADC_StartCalibration
  4445. * @param ADCx ADC instance
  4446. * @retval None
  4447. */
  4448. __STATIC_INLINE void LL_ADC_StartCalibration(ADC_TypeDef *ADCx)
  4449. {
  4450. /* Note: Write register with some additional bits forced to state reset */
  4451. /* instead of modifying only the selected bit for this function, */
  4452. /* to not interfere with bits with HW property "rs". */
  4453. MODIFY_REG(ADCx->CR,
  4454. ADC_CR_BITS_PROPERTY_RS,
  4455. ADC_CR_ADCAL);
  4456. }
  4457. /**
  4458. * @brief Get ADC calibration state.
  4459. * @rmtoll CR ADCAL LL_ADC_IsCalibrationOnGoing
  4460. * @param ADCx ADC instance
  4461. * @retval 0: calibration complete, 1: calibration in progress.
  4462. */
  4463. __STATIC_INLINE uint32_t LL_ADC_IsCalibrationOnGoing(const ADC_TypeDef *ADCx)
  4464. {
  4465. return ((READ_BIT(ADCx->CR, ADC_CR_ADCAL) == (ADC_CR_ADCAL)) ? 1UL : 0UL);
  4466. }
  4467. /**
  4468. * @}
  4469. */
  4470. /** @defgroup ADC_LL_EF_Operation_ADC_Group_Regular Operation on ADC hierarchical scope: group regular
  4471. * @{
  4472. */
  4473. /**
  4474. * @brief Start ADC group regular conversion.
  4475. * @note On this STM32 series, this function is relevant for both
  4476. * internal trigger (SW start) and external trigger:
  4477. * - If ADC trigger has been set to software start, ADC conversion
  4478. * starts immediately.
  4479. * - If ADC trigger has been set to external trigger, ADC conversion
  4480. * will start at next trigger event (on the selected trigger edge)
  4481. * following the ADC start conversion command.
  4482. * @note On this STM32 series, setting of this feature is conditioned to
  4483. * ADC state:
  4484. * ADC must be enabled without conversion on going on group regular,
  4485. * without conversion stop command on going on group regular,
  4486. * without ADC disable command on going.
  4487. * @rmtoll CR ADSTART LL_ADC_REG_StartConversion
  4488. * @param ADCx ADC instance
  4489. * @retval None
  4490. */
  4491. __STATIC_INLINE void LL_ADC_REG_StartConversion(ADC_TypeDef *ADCx)
  4492. {
  4493. /* Note: Write register with some additional bits forced to state reset */
  4494. /* instead of modifying only the selected bit for this function, */
  4495. /* to not interfere with bits with HW property "rs". */
  4496. MODIFY_REG(ADCx->CR,
  4497. ADC_CR_BITS_PROPERTY_RS,
  4498. ADC_CR_ADSTART);
  4499. }
  4500. /**
  4501. * @brief Stop ADC group regular conversion.
  4502. * @note On this STM32 series, setting of this feature is conditioned to
  4503. * ADC state:
  4504. * ADC must be enabled (potentially with conversion on going on group regular),
  4505. * without ADC disable command on going.
  4506. * @rmtoll CR ADSTP LL_ADC_REG_StopConversion
  4507. * @param ADCx ADC instance
  4508. * @retval None
  4509. */
  4510. __STATIC_INLINE void LL_ADC_REG_StopConversion(ADC_TypeDef *ADCx)
  4511. {
  4512. /* Note: Write register with some additional bits forced to state reset */
  4513. /* instead of modifying only the selected bit for this function, */
  4514. /* to not interfere with bits with HW property "rs". */
  4515. MODIFY_REG(ADCx->CR,
  4516. ADC_CR_BITS_PROPERTY_RS,
  4517. ADC_CR_ADSTP);
  4518. }
  4519. /**
  4520. * @brief Get ADC group regular conversion state.
  4521. * @rmtoll CR ADSTART LL_ADC_REG_IsConversionOngoing
  4522. * @param ADCx ADC instance
  4523. * @retval 0: no conversion is on going on ADC group regular.
  4524. */
  4525. __STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(const ADC_TypeDef *ADCx)
  4526. {
  4527. return ((READ_BIT(ADCx->CR, ADC_CR_ADSTART) == (ADC_CR_ADSTART)) ? 1UL : 0UL);
  4528. }
  4529. /**
  4530. * @brief Get ADC group regular command of conversion stop state
  4531. * @rmtoll CR ADSTP LL_ADC_REG_IsStopConversionOngoing
  4532. * @param ADCx ADC instance
  4533. * @retval 0: no command of conversion stop is on going on ADC group regular.
  4534. */
  4535. __STATIC_INLINE uint32_t LL_ADC_REG_IsStopConversionOngoing(const ADC_TypeDef *ADCx)
  4536. {
  4537. return ((READ_BIT(ADCx->CR, ADC_CR_ADSTP) == (ADC_CR_ADSTP)) ? 1UL : 0UL);
  4538. }
  4539. /**
  4540. * @brief Get ADC group regular conversion data, range fit for
  4541. * all ADC configurations: all ADC resolutions and
  4542. * all oversampling increased data width (for devices
  4543. * with feature oversampling).
  4544. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData32
  4545. * @param ADCx ADC instance
  4546. * @retval Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  4547. */
  4548. __STATIC_INLINE uint32_t LL_ADC_REG_ReadConversionData32(const ADC_TypeDef *ADCx)
  4549. {
  4550. return (uint32_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  4551. }
  4552. /**
  4553. * @brief Get ADC group regular conversion data, range fit for
  4554. * ADC resolution 12 bits.
  4555. * @note For devices with feature oversampling: Oversampling
  4556. * can increase data width, function for extended range
  4557. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  4558. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData12
  4559. * @param ADCx ADC instance
  4560. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  4561. */
  4562. __STATIC_INLINE uint16_t LL_ADC_REG_ReadConversionData12(const ADC_TypeDef *ADCx)
  4563. {
  4564. return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_DATA) & 0x00000FFFUL);
  4565. }
  4566. /**
  4567. * @brief Get ADC group regular conversion data, range fit for
  4568. * ADC resolution 10 bits.
  4569. * @note For devices with feature oversampling: Oversampling
  4570. * can increase data width, function for extended range
  4571. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  4572. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData10
  4573. * @param ADCx ADC instance
  4574. * @retval Value between Min_Data=0x000 and Max_Data=0x3FF
  4575. */
  4576. __STATIC_INLINE uint16_t LL_ADC_REG_ReadConversionData10(const ADC_TypeDef *ADCx)
  4577. {
  4578. return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_DATA) & 0x000003FFUL);
  4579. }
  4580. /**
  4581. * @brief Get ADC group regular conversion data, range fit for
  4582. * ADC resolution 8 bits.
  4583. * @note For devices with feature oversampling: Oversampling
  4584. * can increase data width, function for extended range
  4585. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  4586. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData8
  4587. * @param ADCx ADC instance
  4588. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  4589. */
  4590. __STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData8(const ADC_TypeDef *ADCx)
  4591. {
  4592. return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_DATA) & 0x000000FFUL);
  4593. }
  4594. /**
  4595. * @brief Get ADC group regular conversion data, range fit for
  4596. * ADC resolution 6 bits.
  4597. * @note For devices with feature oversampling: Oversampling
  4598. * can increase data width, function for extended range
  4599. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  4600. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData6
  4601. * @param ADCx ADC instance
  4602. * @retval Value between Min_Data=0x00 and Max_Data=0x3F
  4603. */
  4604. __STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData6(const ADC_TypeDef *ADCx)
  4605. {
  4606. return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_DATA) & 0x0000003FUL);
  4607. }
  4608. /**
  4609. * @}
  4610. */
  4611. /** @defgroup ADC_LL_EF_FLAG_Management ADC flag management
  4612. * @{
  4613. */
  4614. /**
  4615. * @brief Get flag ADC ready.
  4616. * @note On this STM32 series, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  4617. * is enabled and when conversion clock is active.
  4618. * (not only core clock: this ADC has a dual clock domain)
  4619. * @rmtoll ISR ADRDY LL_ADC_IsActiveFlag_ADRDY
  4620. * @param ADCx ADC instance
  4621. * @retval State of bit (1 or 0).
  4622. */
  4623. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_ADRDY(const ADC_TypeDef *ADCx)
  4624. {
  4625. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_ADRDY) == (LL_ADC_FLAG_ADRDY)) ? 1UL : 0UL);
  4626. }
  4627. /**
  4628. * @brief Get flag ADC channel configuration ready.
  4629. * @note On this STM32 series, after modifying sequencer
  4630. * it is mandatory to wait for the assertion of CCRDY flag
  4631. * using @ref LL_ADC_IsActiveFlag_CCRDY().
  4632. * Otherwise, performing some actions (configuration update,
  4633. * ADC conversion start, ... ) will be ignored.
  4634. * Functions requiring wait for CCRDY flag are:
  4635. * @ref LL_ADC_REG_SetSequencerLength()
  4636. * @ref LL_ADC_REG_SetSequencerRanks()
  4637. * @ref LL_ADC_REG_SetSequencerChannels()
  4638. * @ref LL_ADC_REG_SetSequencerChAdd()
  4639. * @ref LL_ADC_REG_SetSequencerChRem()
  4640. * @ref LL_ADC_REG_SetSequencerScanDirection()
  4641. * @ref LL_ADC_REG_SetSequencerConfigurable()
  4642. * @note Duration of ADC channel configuration ready: CCRDY handshake
  4643. * requires 1APB + 2 ADC + 3 APB cycles after the channel configuration
  4644. * has been changed.
  4645. * @rmtoll ISR CCRDY LL_ADC_IsActiveFlag_CCRDY
  4646. * @param ADCx ADC instance
  4647. * @retval State of bit (1 or 0).
  4648. */
  4649. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_CCRDY(const ADC_TypeDef *ADCx)
  4650. {
  4651. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_CCRDY) == (LL_ADC_FLAG_CCRDY)) ? 1UL : 0UL);
  4652. }
  4653. /**
  4654. * @brief Get flag ADC group regular end of unitary conversion.
  4655. * @rmtoll ISR EOC LL_ADC_IsActiveFlag_EOC
  4656. * @param ADCx ADC instance
  4657. * @retval State of bit (1 or 0).
  4658. */
  4659. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOC(const ADC_TypeDef *ADCx)
  4660. {
  4661. return ((READ_BIT(ADCx->ISR, ADC_ISR_EOC) == (ADC_ISR_EOC)) ? 1UL : 0UL);
  4662. }
  4663. /**
  4664. * @brief Get flag ADC group regular end of sequence conversions.
  4665. * @rmtoll ISR EOS LL_ADC_IsActiveFlag_EOS
  4666. * @param ADCx ADC instance
  4667. * @retval State of bit (1 or 0).
  4668. */
  4669. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOS(const ADC_TypeDef *ADCx)
  4670. {
  4671. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOS) == (LL_ADC_FLAG_EOS)) ? 1UL : 0UL);
  4672. }
  4673. /**
  4674. * @brief Get flag ADC group regular overrun.
  4675. * @rmtoll ISR OVR LL_ADC_IsActiveFlag_OVR
  4676. * @param ADCx ADC instance
  4677. * @retval State of bit (1 or 0).
  4678. */
  4679. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_OVR(const ADC_TypeDef *ADCx)
  4680. {
  4681. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_OVR) == (LL_ADC_FLAG_OVR)) ? 1UL : 0UL);
  4682. }
  4683. /**
  4684. * @brief Get flag ADC group regular end of sampling phase.
  4685. * @rmtoll ISR EOSMP LL_ADC_IsActiveFlag_EOSMP
  4686. * @param ADCx ADC instance
  4687. * @retval State of bit (1 or 0).
  4688. */
  4689. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOSMP(const ADC_TypeDef *ADCx)
  4690. {
  4691. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOSMP) == (LL_ADC_FLAG_EOSMP)) ? 1UL : 0UL);
  4692. }
  4693. /**
  4694. * @brief Get flag ADC analog watchdog 1 flag
  4695. * @rmtoll ISR AWD1 LL_ADC_IsActiveFlag_AWD1
  4696. * @param ADCx ADC instance
  4697. * @retval State of bit (1 or 0).
  4698. */
  4699. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_AWD1(const ADC_TypeDef *ADCx)
  4700. {
  4701. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_AWD1) == (LL_ADC_FLAG_AWD1)) ? 1UL : 0UL);
  4702. }
  4703. /**
  4704. * @brief Get flag ADC analog watchdog 2.
  4705. * @rmtoll ISR AWD2 LL_ADC_IsActiveFlag_AWD2
  4706. * @param ADCx ADC instance
  4707. * @retval State of bit (1 or 0).
  4708. */
  4709. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_AWD2(const ADC_TypeDef *ADCx)
  4710. {
  4711. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_AWD2) == (LL_ADC_FLAG_AWD2)) ? 1UL : 0UL);
  4712. }
  4713. /**
  4714. * @brief Get flag ADC analog watchdog 3.
  4715. * @rmtoll ISR AWD3 LL_ADC_IsActiveFlag_AWD3
  4716. * @param ADCx ADC instance
  4717. * @retval State of bit (1 or 0).
  4718. */
  4719. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_AWD3(const ADC_TypeDef *ADCx)
  4720. {
  4721. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_AWD3) == (LL_ADC_FLAG_AWD3)) ? 1UL : 0UL);
  4722. }
  4723. /**
  4724. * @brief Get flag ADC end of calibration.
  4725. * @rmtoll ISR EOCAL LL_ADC_IsActiveFlag_EOCAL
  4726. * @param ADCx ADC instance
  4727. * @retval State of bit (1 or 0).
  4728. */
  4729. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOCAL(const ADC_TypeDef *ADCx)
  4730. {
  4731. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOCAL) == (LL_ADC_FLAG_EOCAL)) ? 1UL : 0UL);
  4732. }
  4733. /**
  4734. * @brief Clear flag ADC ready.
  4735. * @note On this STM32 series, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  4736. * is enabled and when conversion clock is active.
  4737. * (not only core clock: this ADC has a dual clock domain)
  4738. * @rmtoll ISR ADRDY LL_ADC_ClearFlag_ADRDY
  4739. * @param ADCx ADC instance
  4740. * @retval None
  4741. */
  4742. __STATIC_INLINE void LL_ADC_ClearFlag_ADRDY(ADC_TypeDef *ADCx)
  4743. {
  4744. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_ADRDY);
  4745. }
  4746. /**
  4747. * @brief Clear flag ADC channel configuration ready.
  4748. * @rmtoll ISR CCRDY LL_ADC_ClearFlag_CCRDY
  4749. * @param ADCx ADC instance
  4750. * @retval State of bit (1 or 0).
  4751. */
  4752. __STATIC_INLINE void LL_ADC_ClearFlag_CCRDY(ADC_TypeDef *ADCx)
  4753. {
  4754. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_CCRDY);
  4755. }
  4756. /**
  4757. * @brief Clear flag ADC group regular end of unitary conversion.
  4758. * @rmtoll ISR EOC LL_ADC_ClearFlag_EOC
  4759. * @param ADCx ADC instance
  4760. * @retval None
  4761. */
  4762. __STATIC_INLINE void LL_ADC_ClearFlag_EOC(ADC_TypeDef *ADCx)
  4763. {
  4764. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOC);
  4765. }
  4766. /**
  4767. * @brief Clear flag ADC group regular end of sequence conversions.
  4768. * @rmtoll ISR EOS LL_ADC_ClearFlag_EOS
  4769. * @param ADCx ADC instance
  4770. * @retval None
  4771. */
  4772. __STATIC_INLINE void LL_ADC_ClearFlag_EOS(ADC_TypeDef *ADCx)
  4773. {
  4774. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOS);
  4775. }
  4776. /**
  4777. * @brief Clear flag ADC group regular overrun.
  4778. * @rmtoll ISR OVR LL_ADC_ClearFlag_OVR
  4779. * @param ADCx ADC instance
  4780. * @retval None
  4781. */
  4782. __STATIC_INLINE void LL_ADC_ClearFlag_OVR(ADC_TypeDef *ADCx)
  4783. {
  4784. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_OVR);
  4785. }
  4786. /**
  4787. * @brief Clear flag ADC group regular end of sampling phase.
  4788. * @rmtoll ISR EOSMP LL_ADC_ClearFlag_EOSMP
  4789. * @param ADCx ADC instance
  4790. * @retval None
  4791. */
  4792. __STATIC_INLINE void LL_ADC_ClearFlag_EOSMP(ADC_TypeDef *ADCx)
  4793. {
  4794. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOSMP);
  4795. }
  4796. /**
  4797. * @brief Clear flag ADC analog watchdog 1.
  4798. * @rmtoll ISR AWD1 LL_ADC_ClearFlag_AWD1
  4799. * @param ADCx ADC instance
  4800. * @retval None
  4801. */
  4802. __STATIC_INLINE void LL_ADC_ClearFlag_AWD1(ADC_TypeDef *ADCx)
  4803. {
  4804. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_AWD1);
  4805. }
  4806. /**
  4807. * @brief Clear flag ADC analog watchdog 2.
  4808. * @rmtoll ISR AWD2 LL_ADC_ClearFlag_AWD2
  4809. * @param ADCx ADC instance
  4810. * @retval None
  4811. */
  4812. __STATIC_INLINE void LL_ADC_ClearFlag_AWD2(ADC_TypeDef *ADCx)
  4813. {
  4814. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_AWD2);
  4815. }
  4816. /**
  4817. * @brief Clear flag ADC analog watchdog 3.
  4818. * @rmtoll ISR AWD3 LL_ADC_ClearFlag_AWD3
  4819. * @param ADCx ADC instance
  4820. * @retval None
  4821. */
  4822. __STATIC_INLINE void LL_ADC_ClearFlag_AWD3(ADC_TypeDef *ADCx)
  4823. {
  4824. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_AWD3);
  4825. }
  4826. /**
  4827. * @brief Clear flag ADC end of calibration.
  4828. * @rmtoll ISR EOCAL LL_ADC_ClearFlag_EOCAL
  4829. * @param ADCx ADC instance
  4830. * @retval None
  4831. */
  4832. __STATIC_INLINE void LL_ADC_ClearFlag_EOCAL(ADC_TypeDef *ADCx)
  4833. {
  4834. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOCAL);
  4835. }
  4836. /**
  4837. * @}
  4838. */
  4839. /** @defgroup ADC_LL_EF_IT_Management ADC IT management
  4840. * @{
  4841. */
  4842. /**
  4843. * @brief Enable ADC ready.
  4844. * @rmtoll IER ADRDYIE LL_ADC_EnableIT_ADRDY
  4845. * @param ADCx ADC instance
  4846. * @retval None
  4847. */
  4848. __STATIC_INLINE void LL_ADC_EnableIT_ADRDY(ADC_TypeDef *ADCx)
  4849. {
  4850. SET_BIT(ADCx->IER, LL_ADC_IT_ADRDY);
  4851. }
  4852. /**
  4853. * @brief Enable interruption ADC channel configuration ready.
  4854. * @rmtoll IER CCRDYIE LL_ADC_EnableIT_CCRDY
  4855. * @param ADCx ADC instance
  4856. * @retval State of bit (1 or 0).
  4857. */
  4858. __STATIC_INLINE void LL_ADC_EnableIT_CCRDY(ADC_TypeDef *ADCx)
  4859. {
  4860. SET_BIT(ADCx->IER, LL_ADC_FLAG_CCRDY);
  4861. }
  4862. /**
  4863. * @brief Enable interruption ADC group regular end of unitary conversion.
  4864. * @rmtoll IER EOCIE LL_ADC_EnableIT_EOC
  4865. * @param ADCx ADC instance
  4866. * @retval None
  4867. */
  4868. __STATIC_INLINE void LL_ADC_EnableIT_EOC(ADC_TypeDef *ADCx)
  4869. {
  4870. SET_BIT(ADCx->IER, LL_ADC_IT_EOC);
  4871. }
  4872. /**
  4873. * @brief Enable interruption ADC group regular end of sequence conversions.
  4874. * @rmtoll IER EOSIE LL_ADC_EnableIT_EOS
  4875. * @param ADCx ADC instance
  4876. * @retval None
  4877. */
  4878. __STATIC_INLINE void LL_ADC_EnableIT_EOS(ADC_TypeDef *ADCx)
  4879. {
  4880. SET_BIT(ADCx->IER, LL_ADC_IT_EOS);
  4881. }
  4882. /**
  4883. * @brief Enable ADC group regular interruption overrun.
  4884. * @rmtoll IER OVRIE LL_ADC_EnableIT_OVR
  4885. * @param ADCx ADC instance
  4886. * @retval None
  4887. */
  4888. __STATIC_INLINE void LL_ADC_EnableIT_OVR(ADC_TypeDef *ADCx)
  4889. {
  4890. SET_BIT(ADCx->IER, LL_ADC_IT_OVR);
  4891. }
  4892. /**
  4893. * @brief Enable interruption ADC group regular end of sampling.
  4894. * @rmtoll IER EOSMPIE LL_ADC_EnableIT_EOSMP
  4895. * @param ADCx ADC instance
  4896. * @retval None
  4897. */
  4898. __STATIC_INLINE void LL_ADC_EnableIT_EOSMP(ADC_TypeDef *ADCx)
  4899. {
  4900. SET_BIT(ADCx->IER, LL_ADC_IT_EOSMP);
  4901. }
  4902. /**
  4903. * @brief Enable interruption ADC analog watchdog 1.
  4904. * @rmtoll IER AWD1IE LL_ADC_EnableIT_AWD1
  4905. * @param ADCx ADC instance
  4906. * @retval None
  4907. */
  4908. __STATIC_INLINE void LL_ADC_EnableIT_AWD1(ADC_TypeDef *ADCx)
  4909. {
  4910. SET_BIT(ADCx->IER, LL_ADC_IT_AWD1);
  4911. }
  4912. /**
  4913. * @brief Enable interruption ADC analog watchdog 2.
  4914. * @rmtoll IER AWD2IE LL_ADC_EnableIT_AWD2
  4915. * @param ADCx ADC instance
  4916. * @retval None
  4917. */
  4918. __STATIC_INLINE void LL_ADC_EnableIT_AWD2(ADC_TypeDef *ADCx)
  4919. {
  4920. SET_BIT(ADCx->IER, LL_ADC_IT_AWD2);
  4921. }
  4922. /**
  4923. * @brief Enable interruption ADC analog watchdog 3.
  4924. * @rmtoll IER AWD3IE LL_ADC_EnableIT_AWD3
  4925. * @param ADCx ADC instance
  4926. * @retval None
  4927. */
  4928. __STATIC_INLINE void LL_ADC_EnableIT_AWD3(ADC_TypeDef *ADCx)
  4929. {
  4930. SET_BIT(ADCx->IER, LL_ADC_IT_AWD3);
  4931. }
  4932. /**
  4933. * @brief Enable interruption ADC end of calibration.
  4934. * @rmtoll IER EOCALIE LL_ADC_EnableIT_EOCAL
  4935. * @param ADCx ADC instance
  4936. * @retval None
  4937. */
  4938. __STATIC_INLINE void LL_ADC_EnableIT_EOCAL(ADC_TypeDef *ADCx)
  4939. {
  4940. SET_BIT(ADCx->IER, LL_ADC_IT_EOCAL);
  4941. }
  4942. /**
  4943. * @brief Disable interruption ADC ready.
  4944. * @rmtoll IER ADRDYIE LL_ADC_DisableIT_ADRDY
  4945. * @param ADCx ADC instance
  4946. * @retval None
  4947. */
  4948. __STATIC_INLINE void LL_ADC_DisableIT_ADRDY(ADC_TypeDef *ADCx)
  4949. {
  4950. CLEAR_BIT(ADCx->IER, LL_ADC_IT_ADRDY);
  4951. }
  4952. /**
  4953. * @brief Disable interruption ADC channel configuration ready.
  4954. * @rmtoll IER CCRDYIE LL_ADC_DisableIT_CCRDY
  4955. * @param ADCx ADC instance
  4956. * @retval State of bit (1 or 0).
  4957. */
  4958. __STATIC_INLINE void LL_ADC_DisableIT_CCRDY(ADC_TypeDef *ADCx)
  4959. {
  4960. CLEAR_BIT(ADCx->IER, LL_ADC_FLAG_CCRDY);
  4961. }
  4962. /**
  4963. * @brief Disable interruption ADC group regular end of unitary conversion.
  4964. * @rmtoll IER EOCIE LL_ADC_DisableIT_EOC
  4965. * @param ADCx ADC instance
  4966. * @retval None
  4967. */
  4968. __STATIC_INLINE void LL_ADC_DisableIT_EOC(ADC_TypeDef *ADCx)
  4969. {
  4970. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOC);
  4971. }
  4972. /**
  4973. * @brief Disable interruption ADC group regular end of sequence conversions.
  4974. * @rmtoll IER EOSIE LL_ADC_DisableIT_EOS
  4975. * @param ADCx ADC instance
  4976. * @retval None
  4977. */
  4978. __STATIC_INLINE void LL_ADC_DisableIT_EOS(ADC_TypeDef *ADCx)
  4979. {
  4980. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOS);
  4981. }
  4982. /**
  4983. * @brief Disable interruption ADC group regular overrun.
  4984. * @rmtoll IER OVRIE LL_ADC_DisableIT_OVR
  4985. * @param ADCx ADC instance
  4986. * @retval None
  4987. */
  4988. __STATIC_INLINE void LL_ADC_DisableIT_OVR(ADC_TypeDef *ADCx)
  4989. {
  4990. CLEAR_BIT(ADCx->IER, LL_ADC_IT_OVR);
  4991. }
  4992. /**
  4993. * @brief Disable interruption ADC group regular end of sampling.
  4994. * @rmtoll IER EOSMPIE LL_ADC_DisableIT_EOSMP
  4995. * @param ADCx ADC instance
  4996. * @retval None
  4997. */
  4998. __STATIC_INLINE void LL_ADC_DisableIT_EOSMP(ADC_TypeDef *ADCx)
  4999. {
  5000. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOSMP);
  5001. }
  5002. /**
  5003. * @brief Disable interruption ADC analog watchdog 1.
  5004. * @rmtoll IER AWD1IE LL_ADC_DisableIT_AWD1
  5005. * @param ADCx ADC instance
  5006. * @retval None
  5007. */
  5008. __STATIC_INLINE void LL_ADC_DisableIT_AWD1(ADC_TypeDef *ADCx)
  5009. {
  5010. CLEAR_BIT(ADCx->IER, LL_ADC_IT_AWD1);
  5011. }
  5012. /**
  5013. * @brief Disable interruption ADC analog watchdog 2.
  5014. * @rmtoll IER AWD2IE LL_ADC_DisableIT_AWD2
  5015. * @param ADCx ADC instance
  5016. * @retval None
  5017. */
  5018. __STATIC_INLINE void LL_ADC_DisableIT_AWD2(ADC_TypeDef *ADCx)
  5019. {
  5020. CLEAR_BIT(ADCx->IER, LL_ADC_IT_AWD2);
  5021. }
  5022. /**
  5023. * @brief Disable interruption ADC analog watchdog 3.
  5024. * @rmtoll IER AWD3IE LL_ADC_DisableIT_AWD3
  5025. * @param ADCx ADC instance
  5026. * @retval None
  5027. */
  5028. __STATIC_INLINE void LL_ADC_DisableIT_AWD3(ADC_TypeDef *ADCx)
  5029. {
  5030. CLEAR_BIT(ADCx->IER, LL_ADC_IT_AWD3);
  5031. }
  5032. /**
  5033. * @brief Disable interruption ADC end of calibration.
  5034. * @rmtoll IER EOCALIE LL_ADC_DisableIT_EOCAL
  5035. * @param ADCx ADC instance
  5036. * @retval None
  5037. */
  5038. __STATIC_INLINE void LL_ADC_DisableIT_EOCAL(ADC_TypeDef *ADCx)
  5039. {
  5040. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOCAL);
  5041. }
  5042. /**
  5043. * @brief Get state of interruption ADC ready
  5044. * (0: interrupt disabled, 1: interrupt enabled).
  5045. * @rmtoll IER ADRDYIE LL_ADC_IsEnabledIT_ADRDY
  5046. * @param ADCx ADC instance
  5047. * @retval State of bit (1 or 0).
  5048. */
  5049. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_ADRDY(const ADC_TypeDef *ADCx)
  5050. {
  5051. return ((READ_BIT(ADCx->IER, LL_ADC_IT_ADRDY) == (LL_ADC_IT_ADRDY)) ? 1UL : 0UL);
  5052. }
  5053. /**
  5054. * @brief Get state of interruption ADC channel configuration ready.
  5055. * @rmtoll IER CCRDYIE LL_ADC_IsEnabledIT_CCRDY
  5056. * @param ADCx ADC instance
  5057. * @retval State of bit (1 or 0).
  5058. */
  5059. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_CCRDY(const ADC_TypeDef *ADCx)
  5060. {
  5061. return ((READ_BIT(ADCx->IER, LL_ADC_FLAG_CCRDY) == (LL_ADC_FLAG_CCRDY)) ? 1UL : 0UL);
  5062. }
  5063. /**
  5064. * @brief Get state of interruption ADC group regular end of unitary conversion
  5065. * (0: interrupt disabled, 1: interrupt enabled).
  5066. * @rmtoll IER EOCIE LL_ADC_IsEnabledIT_EOC
  5067. * @param ADCx ADC instance
  5068. * @retval State of bit (1 or 0).
  5069. */
  5070. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOC(const ADC_TypeDef *ADCx)
  5071. {
  5072. return ((READ_BIT(ADCx->IER, LL_ADC_IT_EOC) == (LL_ADC_IT_EOC)) ? 1UL : 0UL);
  5073. }
  5074. /**
  5075. * @brief Get state of interruption ADC group regular end of sequence conversions
  5076. * (0: interrupt disabled, 1: interrupt enabled).
  5077. * @rmtoll IER EOSIE LL_ADC_IsEnabledIT_EOS
  5078. * @param ADCx ADC instance
  5079. * @retval State of bit (1 or 0).
  5080. */
  5081. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOS(const ADC_TypeDef *ADCx)
  5082. {
  5083. return ((READ_BIT(ADCx->IER, LL_ADC_IT_EOS) == (LL_ADC_IT_EOS)) ? 1UL : 0UL);
  5084. }
  5085. /**
  5086. * @brief Get state of interruption ADC group regular overrun
  5087. * (0: interrupt disabled, 1: interrupt enabled).
  5088. * @rmtoll IER OVRIE LL_ADC_IsEnabledIT_OVR
  5089. * @param ADCx ADC instance
  5090. * @retval State of bit (1 or 0).
  5091. */
  5092. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_OVR(const ADC_TypeDef *ADCx)
  5093. {
  5094. return ((READ_BIT(ADCx->IER, LL_ADC_IT_OVR) == (LL_ADC_IT_OVR)) ? 1UL : 0UL);
  5095. }
  5096. /**
  5097. * @brief Get state of interruption ADC group regular end of sampling
  5098. * (0: interrupt disabled, 1: interrupt enabled).
  5099. * @rmtoll IER EOSMPIE LL_ADC_IsEnabledIT_EOSMP
  5100. * @param ADCx ADC instance
  5101. * @retval State of bit (1 or 0).
  5102. */
  5103. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOSMP(const ADC_TypeDef *ADCx)
  5104. {
  5105. return ((READ_BIT(ADCx->IER, LL_ADC_IT_EOSMP) == (LL_ADC_IT_EOSMP)) ? 1UL : 0UL);
  5106. }
  5107. /**
  5108. * @brief Get state of interruption ADC analog watchdog 1
  5109. * (0: interrupt disabled, 1: interrupt enabled).
  5110. * @rmtoll IER AWD1IE LL_ADC_IsEnabledIT_AWD1
  5111. * @param ADCx ADC instance
  5112. * @retval State of bit (1 or 0).
  5113. */
  5114. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_AWD1(const ADC_TypeDef *ADCx)
  5115. {
  5116. return ((READ_BIT(ADCx->IER, LL_ADC_IT_AWD1) == (LL_ADC_IT_AWD1)) ? 1UL : 0UL);
  5117. }
  5118. /**
  5119. * @brief Get state of interruption Get ADC analog watchdog 2
  5120. * (0: interrupt disabled, 1: interrupt enabled).
  5121. * @rmtoll IER AWD2IE LL_ADC_IsEnabledIT_AWD2
  5122. * @param ADCx ADC instance
  5123. * @retval State of bit (1 or 0).
  5124. */
  5125. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_AWD2(const ADC_TypeDef *ADCx)
  5126. {
  5127. return ((READ_BIT(ADCx->IER, LL_ADC_IT_AWD2) == (LL_ADC_IT_AWD2)) ? 1UL : 0UL);
  5128. }
  5129. /**
  5130. * @brief Get state of interruption Get ADC analog watchdog 3
  5131. * (0: interrupt disabled, 1: interrupt enabled).
  5132. * @rmtoll IER AWD3IE LL_ADC_IsEnabledIT_AWD3
  5133. * @param ADCx ADC instance
  5134. * @retval State of bit (1 or 0).
  5135. */
  5136. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_AWD3(const ADC_TypeDef *ADCx)
  5137. {
  5138. return ((READ_BIT(ADCx->IER, LL_ADC_IT_AWD3) == (LL_ADC_IT_AWD3)) ? 1UL : 0UL);
  5139. }
  5140. /**
  5141. * @brief Get state of interruption ADC end of calibration
  5142. * (0: interrupt disabled, 1: interrupt enabled).
  5143. * @rmtoll IER EOCALIE LL_ADC_IsEnabledIT_EOCAL
  5144. * @param ADCx ADC instance
  5145. * @retval State of bit (1 or 0).
  5146. */
  5147. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOCAL(const ADC_TypeDef *ADCx)
  5148. {
  5149. return ((READ_BIT(ADCx->IER, LL_ADC_IT_EOCAL) == (LL_ADC_IT_EOCAL)) ? 1UL : 0UL);
  5150. }
  5151. /**
  5152. * @}
  5153. */
  5154. #if defined(USE_FULL_LL_DRIVER)
  5155. /** @defgroup ADC_LL_EF_Init Initialization and de-initialization functions
  5156. * @{
  5157. */
  5158. /* Initialization of some features of ADC common parameters and multimode */
  5159. ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON);
  5160. ErrorStatus LL_ADC_CommonInit(ADC_Common_TypeDef *ADCxy_COMMON, const LL_ADC_CommonInitTypeDef *pADC_CommonInitStruct);
  5161. void LL_ADC_CommonStructInit(LL_ADC_CommonInitTypeDef *pADC_CommonInitStruct);
  5162. /* De-initialization of ADC instance */
  5163. ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx);
  5164. /* Initialization of some features of ADC instance */
  5165. ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, const LL_ADC_InitTypeDef *pADC_InitStruct);
  5166. void LL_ADC_StructInit(LL_ADC_InitTypeDef *pADC_InitStruct);
  5167. /* Initialization of some features of ADC instance and ADC group regular */
  5168. ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, const LL_ADC_REG_InitTypeDef *pADC_RegInitStruct);
  5169. void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *pADC_RegInitStruct);
  5170. /**
  5171. * @}
  5172. */
  5173. #endif /* USE_FULL_LL_DRIVER */
  5174. /**
  5175. * @}
  5176. */
  5177. /**
  5178. * @}
  5179. */
  5180. #endif /* ADC1 */
  5181. /**
  5182. * @}
  5183. */
  5184. #ifdef __cplusplus
  5185. }
  5186. #endif
  5187. #endif /* STM32G0xx_LL_ADC_H */