stm32l0xx_ll_adc.h 220 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072
  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_ll_adc.h
  4. * @author MCD Application Team
  5. * @brief Header file of ADC LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 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 __STM32L0xx_LL_ADC_H
  20. #define __STM32L0xx_LL_ADC_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l0xx.h"
  26. /** @addtogroup STM32L0xx_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 trigger: */
  40. /* To select into literal LL_ADC_REG_TRIG_x the relevant bits for: */
  41. /* - regular trigger source */
  42. /* - regular trigger edge */
  43. #define ADC_REG_TRIG_EXT_EDGE_DEFAULT (ADC_CFGR1_EXTEN_0) /* Trigger edge set to rising edge (default setting for compatibility with some ADC on other STM32 families having this setting set by HW default value) */
  44. /* Mask containing trigger source masks for each of possible */
  45. /* trigger edge selection duplicated with shifts [0; 4; 8; 12] */
  46. /* corresponding to {SW start; ext trigger; ext trigger; ext trigger}. */
  47. #define ADC_REG_TRIG_SOURCE_MASK (((LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR1_EXTSEL) << (4U * 0U)) | \
  48. ((ADC_CFGR1_EXTSEL) << (4U * 1U)) | \
  49. ((ADC_CFGR1_EXTSEL) << (4U * 2U)) | \
  50. ((ADC_CFGR1_EXTSEL) << (4U * 3U)) )
  51. /* Mask containing trigger edge masks for each of possible */
  52. /* trigger edge selection duplicated with shifts [0; 4; 8; 12] */
  53. /* corresponding to {SW start; ext trigger; ext trigger; ext trigger}. */
  54. #define ADC_REG_TRIG_EDGE_MASK (((LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR1_EXTEN) << (4U * 0U)) | \
  55. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 1U)) | \
  56. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 2U)) | \
  57. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 3U)) )
  58. /* Definition of ADC group regular trigger bits information. */
  59. #define ADC_REG_TRIG_EXTSEL_BITOFFSET_POS (6U) /* Value equivalent to POSITION_VAL(ADC_CFGR1_EXTSEL) */
  60. #define ADC_REG_TRIG_EXTEN_BITOFFSET_POS (10U) /* Value equivalent to POSITION_VAL(ADC_CFGR1_EXTEN) */
  61. /* Internal mask for ADC channel: */
  62. /* To select into literal LL_ADC_CHANNEL_x the relevant bits for: */
  63. /* - channel identifier defined by number */
  64. /* - channel identifier defined by bitfield */
  65. /* - channel differentiation between external channels (connected to */
  66. /* GPIO pins) and internal channels (connected to internal paths) */
  67. #define ADC_CHANNEL_ID_NUMBER_MASK (ADC_CFGR1_AWDCH)
  68. #define ADC_CHANNEL_ID_BITFIELD_MASK (ADC_CHSELR_CHSEL)
  69. #define ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS (26U)/* Value equivalent to POSITION_VAL(ADC_CHANNEL_ID_NUMBER_MASK) */
  70. #define ADC_CHANNEL_ID_MASK (ADC_CHANNEL_ID_NUMBER_MASK | ADC_CHANNEL_ID_BITFIELD_MASK | ADC_CHANNEL_ID_INTERNAL_CH_MASK)
  71. /* Equivalent mask of ADC_CHANNEL_NUMBER_MASK aligned on register LSB (bit 0) */
  72. #define ADC_CHANNEL_ID_NUMBER_MASK_POSBIT0 (0x0000001FU) /* Equivalent to shift: (ADC_CHANNEL_NUMBER_MASK >> POSITION_VAL(ADC_CHANNEL_NUMBER_MASK)) */
  73. /* Channel differentiation between external and internal channels */
  74. #define ADC_CHANNEL_ID_INTERNAL_CH (0x80000000U) /* Marker of internal channel */
  75. #define ADC_CHANNEL_ID_INTERNAL_CH_MASK (ADC_CHANNEL_ID_INTERNAL_CH)
  76. /* Definition of channels ID number information to be inserted into */
  77. /* channels literals definition. */
  78. #define ADC_CHANNEL_0_NUMBER (0x00000000U)
  79. #define ADC_CHANNEL_1_NUMBER ( ADC_CFGR1_AWDCH_0)
  80. #define ADC_CHANNEL_2_NUMBER ( ADC_CFGR1_AWDCH_1 )
  81. #define ADC_CHANNEL_3_NUMBER ( ADC_CFGR1_AWDCH_1 | ADC_CFGR1_AWDCH_0)
  82. #define ADC_CHANNEL_4_NUMBER ( ADC_CFGR1_AWDCH_2 )
  83. #define ADC_CHANNEL_5_NUMBER ( ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_0)
  84. #define ADC_CHANNEL_6_NUMBER ( ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_1 )
  85. #define ADC_CHANNEL_7_NUMBER ( ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_1 | ADC_CFGR1_AWDCH_0)
  86. #define ADC_CHANNEL_8_NUMBER ( ADC_CFGR1_AWDCH_3 )
  87. #define ADC_CHANNEL_9_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_0)
  88. #define ADC_CHANNEL_10_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_1 )
  89. #define ADC_CHANNEL_11_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_1 | ADC_CFGR1_AWDCH_0)
  90. #define ADC_CHANNEL_12_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_2 )
  91. #define ADC_CHANNEL_13_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_0)
  92. #define ADC_CHANNEL_14_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_1 )
  93. #define ADC_CHANNEL_15_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_1 | ADC_CFGR1_AWDCH_0)
  94. #define ADC_CHANNEL_16_NUMBER (ADC_CFGR1_AWDCH_4 )
  95. #define ADC_CHANNEL_17_NUMBER (ADC_CFGR1_AWDCH_4 | ADC_CFGR1_AWDCH_0)
  96. #define ADC_CHANNEL_18_NUMBER (ADC_CFGR1_AWDCH_4 | ADC_CFGR1_AWDCH_1 )
  97. /* Definition of channels ID bitfield information to be inserted into */
  98. /* channels literals definition. */
  99. #define ADC_CHANNEL_0_BITFIELD (ADC_CHSELR_CHSEL0)
  100. #define ADC_CHANNEL_1_BITFIELD (ADC_CHSELR_CHSEL1)
  101. #define ADC_CHANNEL_2_BITFIELD (ADC_CHSELR_CHSEL2)
  102. #define ADC_CHANNEL_3_BITFIELD (ADC_CHSELR_CHSEL3)
  103. #define ADC_CHANNEL_4_BITFIELD (ADC_CHSELR_CHSEL4)
  104. #define ADC_CHANNEL_5_BITFIELD (ADC_CHSELR_CHSEL5)
  105. #define ADC_CHANNEL_6_BITFIELD (ADC_CHSELR_CHSEL6)
  106. #define ADC_CHANNEL_7_BITFIELD (ADC_CHSELR_CHSEL7)
  107. #define ADC_CHANNEL_8_BITFIELD (ADC_CHSELR_CHSEL8)
  108. #define ADC_CHANNEL_9_BITFIELD (ADC_CHSELR_CHSEL9)
  109. #define ADC_CHANNEL_10_BITFIELD (ADC_CHSELR_CHSEL10)
  110. #define ADC_CHANNEL_11_BITFIELD (ADC_CHSELR_CHSEL11)
  111. #define ADC_CHANNEL_12_BITFIELD (ADC_CHSELR_CHSEL12)
  112. #define ADC_CHANNEL_13_BITFIELD (ADC_CHSELR_CHSEL13)
  113. #define ADC_CHANNEL_14_BITFIELD (ADC_CHSELR_CHSEL14)
  114. #define ADC_CHANNEL_15_BITFIELD (ADC_CHSELR_CHSEL15)
  115. #if defined(ADC_CCR_VLCDEN)
  116. #define ADC_CHANNEL_16_BITFIELD (ADC_CHSELR_CHSEL16)
  117. #endif
  118. #define ADC_CHANNEL_17_BITFIELD (ADC_CHSELR_CHSEL17)
  119. #define ADC_CHANNEL_18_BITFIELD (ADC_CHSELR_CHSEL18)
  120. /* Internal mask for ADC analog watchdog: */
  121. /* To select into literals LL_ADC_AWD_CHANNELx_xxx the relevant bits for: */
  122. /* (concatenation of multiple bits used in different analog watchdogs, */
  123. /* (feature of several watchdogs not available on all STM32 families)). */
  124. /* - analog watchdog 1: monitored channel defined by number, */
  125. /* selection of ADC group (ADC group regular). */
  126. /* Internal register offset for ADC analog watchdog channel configuration */
  127. #define ADC_AWD_CR1_REGOFFSET (0x00000000U)
  128. #define ADC_AWD_CRX_REGOFFSET_MASK (ADC_AWD_CR1_REGOFFSET)
  129. #define ADC_AWD_CR1_CHANNEL_MASK (ADC_CFGR1_AWDCH | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL)
  130. #define ADC_AWD_CR_ALL_CHANNEL_MASK (ADC_AWD_CR1_CHANNEL_MASK)
  131. /* Internal register offset for ADC analog watchdog threshold configuration */
  132. #define ADC_AWD_TR1_REGOFFSET (ADC_AWD_CR1_REGOFFSET)
  133. #define ADC_AWD_TRX_REGOFFSET_MASK (ADC_AWD_TR1_REGOFFSET)
  134. /* ADC registers bits positions */
  135. #define ADC_CFGR1_RES_BITOFFSET_POS (3U) /* Value equivalent to POSITION_VAL(ADC_CFGR1_RES) */
  136. #define ADC_CFGR1_AWDSGL_BITOFFSET_POS (22U) /* Value equivalent to POSITION_VAL(ADC_CFGR1_AWDSGL) */
  137. #define ADC_TR_HT_BITOFFSET_POS (16U) /* Value equivalent to POSITION_VAL(ADC_TR_HT) */
  138. #define ADC_CHSELR_CHSEL0_BITOFFSET_POS (0U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL0) */
  139. #define ADC_CHSELR_CHSEL1_BITOFFSET_POS (1U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL1) */
  140. #define ADC_CHSELR_CHSEL2_BITOFFSET_POS (2U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL2) */
  141. #define ADC_CHSELR_CHSEL3_BITOFFSET_POS (3U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL3) */
  142. #define ADC_CHSELR_CHSEL4_BITOFFSET_POS (4U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL4) */
  143. #define ADC_CHSELR_CHSEL5_BITOFFSET_POS (5U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL5) */
  144. #define ADC_CHSELR_CHSEL6_BITOFFSET_POS (6U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL6) */
  145. #define ADC_CHSELR_CHSEL7_BITOFFSET_POS (7U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL7) */
  146. #define ADC_CHSELR_CHSEL8_BITOFFSET_POS (8U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL8) */
  147. #define ADC_CHSELR_CHSEL9_BITOFFSET_POS (9U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL9) */
  148. #define ADC_CHSELR_CHSEL10_BITOFFSET_POS (10U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL10) */
  149. #define ADC_CHSELR_CHSEL11_BITOFFSET_POS (11U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL11) */
  150. #define ADC_CHSELR_CHSEL12_BITOFFSET_POS (12U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL12) */
  151. #define ADC_CHSELR_CHSEL13_BITOFFSET_POS (13U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL13) */
  152. #define ADC_CHSELR_CHSEL14_BITOFFSET_POS (14U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL14) */
  153. #define ADC_CHSELR_CHSEL15_BITOFFSET_POS (15U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL15) */
  154. #if defined(ADC_CCR_VLCDEN)
  155. #define ADC_CHSELR_CHSEL16_BITOFFSET_POS (16U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL16) */
  156. #endif
  157. #define ADC_CHSELR_CHSEL17_BITOFFSET_POS (17U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL17) */
  158. #define ADC_CHSELR_CHSEL18_BITOFFSET_POS (18U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL18) */
  159. /* ADC registers bits groups */
  160. #define ADC_CR_BITS_PROPERTY_RS (ADC_CR_ADCAL | ADC_CR_ADSTP | ADC_CR_ADSTART | ADC_CR_ADDIS | ADC_CR_ADEN) /* ADC register CR bits with HW property "rs": Software can read as well as set this bit. Writing '0' has no effect on the bit value. */
  161. /* ADC internal channels related definitions */
  162. /* Internal voltage reference VrefInt */
  163. #define VREFINT_CAL_ADDR ((uint16_t*) (0x1FF80078U)) /* Internal voltage reference, address of parameter VREFINT_CAL: VrefInt ADC raw data acquired at temperature 30 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
  164. #define VREFINT_CAL_VREF (3000U) /* Analog voltage reference (Vref+) value with which temperature sensor has been calibrated in production (tolerance: +-10 mV) (unit: mV). */
  165. /* Temperature sensor */
  166. /* Note: On device STM32L011, calibration parameter TS_CAL1 is not available. */
  167. #if !defined(STM32L011xx)
  168. #define TEMPSENSOR_CAL1_ADDR ((uint16_t*) (0x1FF8007AU)) /* Internal temperature sensor, address of parameter TS_CAL1: On STM32L0, temperature sensor ADC raw data acquired at temperature 30 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
  169. #endif
  170. #define TEMPSENSOR_CAL2_ADDR ((uint16_t*) (0x1FF8007EU)) /* Internal temperature sensor, address of parameter TS_CAL2: On STM32L0, temperature sensor ADC raw data acquired at temperature 130 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
  171. #if !defined(STM32L011xx)
  172. #define TEMPSENSOR_CAL1_TEMP (30U) /* Internal temperature sensor, temperature at which temperature sensor has been calibrated in production for data into TEMPSENSOR_CAL1_ADDR (tolerance: +-5 DegC) (unit: DegC). */
  173. #endif
  174. #define TEMPSENSOR_CAL2_TEMP (130U) /* Internal temperature sensor, temperature at which temperature sensor has been calibrated in production for data into TEMPSENSOR_CAL2_ADDR (tolerance: +-5 DegC) (unit: DegC). */
  175. #define TEMPSENSOR_CAL_VREFANALOG (3000U) /* Analog voltage reference (Vref+) voltage with which temperature sensor has been calibrated in production (+-10 mV) (unit: mV). */
  176. /**
  177. * @}
  178. */
  179. #if defined(USE_FULL_LL_DRIVER)
  180. /* Private macros ------------------------------------------------------------*/
  181. /** @defgroup ADC_LL_Private_Macros ADC Private Macros
  182. * @{
  183. */
  184. /**
  185. * @}
  186. */
  187. #endif
  188. /* Exported types ------------------------------------------------------------*/
  189. #if defined(USE_FULL_LL_DRIVER)
  190. /** @defgroup ADC_LL_ES_INIT ADC Exported Init structure
  191. * @{
  192. */
  193. /**
  194. * @brief Structure definition of some features of ADC common parameters
  195. * and multimode
  196. * (all ADC instances belonging to the same ADC common instance).
  197. * @note The setting of these parameters by function @ref LL_ADC_CommonInit()
  198. * is conditioned to ADC instances state (all ADC instances
  199. * sharing the same ADC common instance):
  200. * All ADC instances sharing the same ADC common instance must be
  201. * disabled.
  202. */
  203. typedef struct
  204. {
  205. uint32_t CommonClock; /*!< Set parameter common to several ADC: Clock source and prescaler.
  206. This parameter can be a value of @ref ADC_LL_EC_COMMON_CLOCK_SOURCE
  207. This feature can be modified afterwards using unitary function @ref LL_ADC_SetCommonClock(). */
  208. } LL_ADC_CommonInitTypeDef;
  209. /**
  210. * @brief Structure definition of some features of ADC instance.
  211. * @note These parameters have an impact on ADC scope: ADC instance.
  212. * Refer to corresponding unitary functions into
  213. * @ref ADC_LL_EF_Configuration_ADC_Instance .
  214. * @note The setting of these parameters by function @ref LL_ADC_Init()
  215. * is conditioned to ADC state:
  216. * ADC instance must be disabled.
  217. * This condition is applied to all ADC features, for efficiency
  218. * and compatibility over all STM32 families. However, the different
  219. * features can be set under different ADC state conditions
  220. * (setting possible with ADC enabled without conversion on going,
  221. * ADC enabled with conversion on going, ...)
  222. * Each feature can be updated afterwards with a unitary function
  223. * and potentially with ADC in a different state than disabled,
  224. * refer to description of each function for setting
  225. * conditioned to ADC state.
  226. */
  227. typedef struct
  228. {
  229. uint32_t Clock; /*!< Set ADC instance clock source and prescaler.
  230. This parameter can be a value of @ref ADC_LL_EC_CLOCK_SOURCE
  231. @note On this STM32 series, this parameter has some clock ratio constraints:
  232. ADC clock synchronous (from PCLK) with prescaler 1 must be enabled only if PCLK has a 50% duty clock cycle
  233. (APB prescaler configured inside the RCC must be bypassed and the system clock must by 50% duty cycle).
  234. This feature can be modified afterwards using unitary function @ref LL_ADC_SetClock().
  235. For more details, refer to description of this function. */
  236. uint32_t Resolution; /*!< Set ADC resolution.
  237. This parameter can be a value of @ref ADC_LL_EC_RESOLUTION
  238. This feature can be modified afterwards using unitary function @ref LL_ADC_SetResolution(). */
  239. uint32_t DataAlignment; /*!< Set ADC conversion data alignment.
  240. This parameter can be a value of @ref ADC_LL_EC_DATA_ALIGN
  241. This feature can be modified afterwards using unitary function @ref LL_ADC_SetDataAlignment(). */
  242. uint32_t LowPowerMode; /*!< Set ADC low power mode.
  243. This parameter can be a value of @ref ADC_LL_EC_LP_MODE
  244. This feature can be modified afterwards using unitary function @ref LL_ADC_SetLowPowerMode(). */
  245. } LL_ADC_InitTypeDef;
  246. /**
  247. * @brief Structure definition of some features of ADC group regular.
  248. * @note These parameters have an impact on ADC scope: ADC group regular.
  249. * Refer to corresponding unitary functions into
  250. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  251. * (functions with prefix "REG").
  252. * @note The setting of these parameters by function @ref LL_ADC_REG_Init()
  253. * is conditioned to ADC state:
  254. * ADC instance must be disabled.
  255. * This condition is applied to all ADC features, for efficiency
  256. * and compatibility over all STM32 families. However, the different
  257. * features can be set under different ADC state conditions
  258. * (setting possible with ADC enabled without conversion on going,
  259. * ADC enabled with conversion on going, ...)
  260. * Each feature can be updated afterwards with a unitary function
  261. * and potentially with ADC in a different state than disabled,
  262. * refer to description of each function for setting
  263. * conditioned to ADC state.
  264. */
  265. typedef struct
  266. {
  267. uint32_t TriggerSource; /*!< Set ADC group regular conversion trigger source: internal (SW start) or from external peripheral (timer event, external interrupt line).
  268. This parameter can be a value of @ref ADC_LL_EC_REG_TRIGGER_SOURCE
  269. @note On this STM32 series, setting trigger source to external trigger also set trigger polarity to rising edge
  270. (default setting for compatibility with some ADC on other STM32 families having this setting set by HW default value).
  271. In case of need to modify trigger edge, use function @ref LL_ADC_REG_SetTriggerEdge().
  272. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetTriggerSource(). */
  273. uint32_t SequencerDiscont; /*!< Set ADC group regular sequencer discontinuous mode: sequence subdivided and scan conversions interrupted every selected number of ranks.
  274. This parameter can be a value of @ref ADC_LL_EC_REG_SEQ_DISCONT_MODE
  275. @note This parameter has an effect only if group regular sequencer is enabled
  276. (several ADC channels enabled in group regular sequencer).
  277. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetSequencerDiscont(). */
  278. uint32_t ContinuousMode; /*!< Set ADC continuous conversion mode on ADC group regular, whether ADC conversions are performed in single mode (one conversion per trigger) or in continuous mode (after the first trigger, following conversions launched successively automatically).
  279. This parameter can be a value of @ref ADC_LL_EC_REG_CONTINUOUS_MODE
  280. Note: It is not possible to enable both ADC group regular continuous mode and discontinuous mode.
  281. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetContinuousMode(). */
  282. uint32_t DMATransfer; /*!< Set ADC group regular conversion data transfer: no transfer or transfer by DMA, and DMA requests mode.
  283. This parameter can be a value of @ref ADC_LL_EC_REG_DMA_TRANSFER
  284. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetDMATransfer(). */
  285. uint32_t Overrun; /*!< Set ADC group regular behavior in case of overrun:
  286. data preserved or overwritten.
  287. This parameter can be a value of @ref ADC_LL_EC_REG_OVR_DATA_BEHAVIOR
  288. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetOverrun(). */
  289. } LL_ADC_REG_InitTypeDef;
  290. /**
  291. * @}
  292. */
  293. #endif /* USE_FULL_LL_DRIVER */
  294. /* Exported constants --------------------------------------------------------*/
  295. /** @defgroup ADC_LL_Exported_Constants ADC Exported Constants
  296. * @{
  297. */
  298. /** @defgroup ADC_LL_EC_FLAG ADC flags
  299. * @brief Flags defines which can be used with LL_ADC_ReadReg function
  300. * @{
  301. */
  302. #define LL_ADC_FLAG_ADRDY ADC_ISR_ADRDY /*!< ADC flag ADC instance ready */
  303. #define LL_ADC_FLAG_EOC ADC_ISR_EOC /*!< ADC flag ADC group regular end of unitary conversion */
  304. #define LL_ADC_FLAG_EOS ADC_ISR_EOS /*!< ADC flag ADC group regular end of sequence conversions */
  305. #define LL_ADC_FLAG_OVR ADC_ISR_OVR /*!< ADC flag ADC group regular overrun */
  306. #define LL_ADC_FLAG_EOSMP ADC_ISR_EOSMP /*!< ADC flag ADC group regular end of sampling phase */
  307. #define LL_ADC_FLAG_AWD1 ADC_ISR_AWD /*!< ADC flag ADC analog watchdog 1 */
  308. #define LL_ADC_FLAG_EOCAL ADC_ISR_EOCAL /*!< ADC flag end of calibration */
  309. /**
  310. * @}
  311. */
  312. /** @defgroup ADC_LL_EC_IT ADC interruptions for configuration (interruption enable or disable)
  313. * @brief IT defines which can be used with LL_ADC_ReadReg and LL_ADC_WriteReg functions
  314. * @{
  315. */
  316. #define LL_ADC_IT_ADRDY ADC_IER_ADRDYIE /*!< ADC interruption ADC instance ready */
  317. #define LL_ADC_IT_EOC ADC_IER_EOCIE /*!< ADC interruption ADC group regular end of unitary conversion */
  318. #define LL_ADC_IT_EOS ADC_IER_EOSIE /*!< ADC interruption ADC group regular end of sequence conversions */
  319. #define LL_ADC_IT_OVR ADC_IER_OVRIE /*!< ADC interruption ADC group regular overrun */
  320. #define LL_ADC_IT_EOSMP ADC_IER_EOSMPIE /*!< ADC interruption ADC group regular end of sampling phase */
  321. #define LL_ADC_IT_AWD1 ADC_IER_AWDIE /*!< ADC interruption ADC analog watchdog 1 */
  322. #define LL_ADC_IT_EOCAL ADC_IER_EOCALIE /*!< ADC interruption ADC end of calibration */
  323. /**
  324. * @}
  325. */
  326. /** @defgroup ADC_LL_EC_REGISTERS ADC registers compliant with specific purpose
  327. * @{
  328. */
  329. /* List of ADC registers intended to be used (most commonly) with */
  330. /* DMA transfer. */
  331. /* Refer to function @ref LL_ADC_DMA_GetRegAddr(). */
  332. #define LL_ADC_DMA_REG_REGULAR_DATA (0x00000000U) /* ADC group regular conversion data register (corresponding to register DR) to be used with ADC configured in independent mode. Without DMA transfer, register accessed by LL function @ref LL_ADC_REG_ReadConversionData32() and other functions @ref LL_ADC_REG_ReadConversionDatax() */
  333. /**
  334. * @}
  335. */
  336. /** @defgroup ADC_LL_EC_COMMON_CLOCK_SOURCE ADC common - Clock source
  337. * @{
  338. */
  339. #define LL_ADC_CLOCK_ASYNC_DIV1 (0x00000000U) /*!< ADC asynchronous clock without prescaler */
  340. #define LL_ADC_CLOCK_ASYNC_DIV2 (ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 2. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  341. #define LL_ADC_CLOCK_ASYNC_DIV4 (ADC_CCR_PRESC_1 ) /*!< ADC asynchronous clock with prescaler division by 4. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  342. #define LL_ADC_CLOCK_ASYNC_DIV6 (ADC_CCR_PRESC_1 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 6. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  343. #define LL_ADC_CLOCK_ASYNC_DIV8 (ADC_CCR_PRESC_2 ) /*!< ADC asynchronous clock with prescaler division by 8. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  344. #define LL_ADC_CLOCK_ASYNC_DIV10 (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 10. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  345. #define LL_ADC_CLOCK_ASYNC_DIV12 (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_1 ) /*!< ADC asynchronous clock with prescaler division by 12. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  346. #define LL_ADC_CLOCK_ASYNC_DIV16 (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_1 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 16. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  347. #define LL_ADC_CLOCK_ASYNC_DIV32 (ADC_CCR_PRESC_3) /*!< ADC asynchronous clock with prescaler division by 32. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  348. #define LL_ADC_CLOCK_ASYNC_DIV64 (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 64. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  349. #define LL_ADC_CLOCK_ASYNC_DIV128 (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_1) /*!< ADC asynchronous clock with prescaler division by 128. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  350. #define LL_ADC_CLOCK_ASYNC_DIV256 (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_1 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 256. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  351. /**
  352. * @}
  353. */
  354. /** @defgroup ADC_LL_EC_COMMON_CLOCK_FREQ_MODE ADC common - Clock frequency mode
  355. * @{
  356. */
  357. #define LL_ADC_CLOCK_FREQ_MODE_HIGH (0x00000000U)/*!< ADC clock mode to high frequency. On STM32L0, ADC clock frequency above 2.8MHz. */
  358. #define LL_ADC_CLOCK_FREQ_MODE_LOW (ADC_CCR_LFMEN) /*!< ADC clock mode to low frequency. On STM32L0, ADC clock frequency below 2.8MHz. */
  359. /**
  360. * @}
  361. */
  362. /** @defgroup ADC_LL_EC_COMMON_PATH_INTERNAL ADC common - Measurement path to internal channels
  363. * @{
  364. */
  365. /* Note: Other measurement paths to internal channels may be available */
  366. /* (connections to other peripherals). */
  367. /* If they are not listed below, they do not require any specific */
  368. /* path enable. In this case, Access to measurement path is done */
  369. /* only by selecting the corresponding ADC internal channel. */
  370. #define LL_ADC_PATH_INTERNAL_NONE (0x00000000U)/*!< ADC measurement paths all disabled */
  371. #define LL_ADC_PATH_INTERNAL_VREFINT (ADC_CCR_VREFEN) /*!< ADC measurement path to internal channel VrefInt */
  372. #if defined(ADC_CCR_TSEN)
  373. #define LL_ADC_PATH_INTERNAL_TEMPSENSOR (ADC_CCR_TSEN) /*!< ADC measurement path to internal channel temperature sensor */
  374. #endif
  375. #if defined(ADC_CCR_VLCDEN)
  376. #define LL_ADC_PATH_INTERNAL_VLCD (ADC_CCR_VLCDEN) /*!< ADC measurement path to internal channel Vlcd */
  377. #endif
  378. /**
  379. * @}
  380. */
  381. /** @defgroup ADC_LL_EC_CLOCK_SOURCE ADC instance - Clock source
  382. * @{
  383. */
  384. #define LL_ADC_CLOCK_SYNC_PCLK_DIV4 (ADC_CFGR2_CKMODE_1) /*!< ADC synchronous clock derived from AHB clock divided by 4 */
  385. #define LL_ADC_CLOCK_SYNC_PCLK_DIV2 (ADC_CFGR2_CKMODE_0) /*!< ADC synchronous clock derived from AHB clock divided by 2 */
  386. #define LL_ADC_CLOCK_SYNC_PCLK_DIV1 (ADC_CFGR2_CKMODE_1 | ADC_CFGR2_CKMODE_0) /*!< ADC synchronous clock derived from AHB clock not divided */
  387. #define LL_ADC_CLOCK_ASYNC (0x00000000U) /*!< ADC asynchronous clock. Asynchronous clock prescaler can be configured using function @ref LL_ADC_SetCommonClock(). */
  388. /**
  389. * @}
  390. */
  391. /** @defgroup ADC_LL_EC_RESOLUTION ADC instance - Resolution
  392. * @{
  393. */
  394. #define LL_ADC_RESOLUTION_12B (0x00000000U) /*!< ADC resolution 12 bits */
  395. #define LL_ADC_RESOLUTION_10B ( ADC_CFGR1_RES_0) /*!< ADC resolution 10 bits */
  396. #define LL_ADC_RESOLUTION_8B (ADC_CFGR1_RES_1 ) /*!< ADC resolution 8 bits */
  397. #define LL_ADC_RESOLUTION_6B (ADC_CFGR1_RES_1 | ADC_CFGR1_RES_0) /*!< ADC resolution 6 bits */
  398. /**
  399. * @}
  400. */
  401. /** @defgroup ADC_LL_EC_DATA_ALIGN ADC instance - Data alignment
  402. * @{
  403. */
  404. #define LL_ADC_DATA_ALIGN_RIGHT (0x00000000U)/*!< ADC conversion data alignment: right aligned (alignment on data register LSB bit 0)*/
  405. #define LL_ADC_DATA_ALIGN_LEFT (ADC_CFGR1_ALIGN) /*!< ADC conversion data alignment: left aligned (alignment on data register MSB bit 15)*/
  406. /**
  407. * @}
  408. */
  409. /** @defgroup ADC_LL_EC_LP_MODE ADC instance - Low power mode
  410. * @{
  411. */
  412. #define LL_ADC_LP_MODE_NONE (0x00000000U) /*!< No ADC low power mode activated */
  413. #define LL_ADC_LP_AUTOWAIT (ADC_CFGR1_WAIT) /*!< ADC low power mode auto delay: Dynamic low power mode, ADC conversions are performed only when necessary (when previous ADC conversion data is read). See description with function @ref LL_ADC_SetLowPowerMode(). */
  414. #define LL_ADC_LP_AUTOPOWEROFF (ADC_CFGR1_AUTOFF) /*!< ADC low power mode auto power-off: the ADC automatically powers-off after a ADC conversion and automatically wakes up when a new ADC conversion is triggered (with startup time between trigger and start of sampling). See description with function @ref LL_ADC_SetLowPowerMode(). */
  415. #define LL_ADC_LP_AUTOWAIT_AUTOPOWEROFF (ADC_CFGR1_WAIT | ADC_CFGR1_AUTOFF) /*!< ADC low power modes auto wait and auto power-off combined. See description with function @ref LL_ADC_SetLowPowerMode(). */
  416. /**
  417. * @}
  418. */
  419. /** @defgroup ADC_LL_EC_GROUPS ADC instance - Groups
  420. * @{
  421. */
  422. #define LL_ADC_GROUP_REGULAR (0x00000001U) /*!< ADC group regular (available on all STM32 devices) */
  423. /**
  424. * @}
  425. */
  426. /** @defgroup ADC_LL_EC_CHANNEL ADC instance - Channel number
  427. * @{
  428. */
  429. #define LL_ADC_CHANNEL_0 (ADC_CHANNEL_0_NUMBER | ADC_CHANNEL_0_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN0 */
  430. #define LL_ADC_CHANNEL_1 (ADC_CHANNEL_1_NUMBER | ADC_CHANNEL_1_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN1 */
  431. #define LL_ADC_CHANNEL_2 (ADC_CHANNEL_2_NUMBER | ADC_CHANNEL_2_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN2 */
  432. #define LL_ADC_CHANNEL_3 (ADC_CHANNEL_3_NUMBER | ADC_CHANNEL_3_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN3 */
  433. #define LL_ADC_CHANNEL_4 (ADC_CHANNEL_4_NUMBER | ADC_CHANNEL_4_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN4 */
  434. #define LL_ADC_CHANNEL_5 (ADC_CHANNEL_5_NUMBER | ADC_CHANNEL_5_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN5 */
  435. #define LL_ADC_CHANNEL_6 (ADC_CHANNEL_6_NUMBER | ADC_CHANNEL_6_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN6 */
  436. #define LL_ADC_CHANNEL_7 (ADC_CHANNEL_7_NUMBER | ADC_CHANNEL_7_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN7 */
  437. #define LL_ADC_CHANNEL_8 (ADC_CHANNEL_8_NUMBER | ADC_CHANNEL_8_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN8 */
  438. #define LL_ADC_CHANNEL_9 (ADC_CHANNEL_9_NUMBER | ADC_CHANNEL_9_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN9 */
  439. #define LL_ADC_CHANNEL_10 (ADC_CHANNEL_10_NUMBER | ADC_CHANNEL_10_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN10 */
  440. #define LL_ADC_CHANNEL_11 (ADC_CHANNEL_11_NUMBER | ADC_CHANNEL_11_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN11 */
  441. #define LL_ADC_CHANNEL_12 (ADC_CHANNEL_12_NUMBER | ADC_CHANNEL_12_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN12 */
  442. #define LL_ADC_CHANNEL_13 (ADC_CHANNEL_13_NUMBER | ADC_CHANNEL_13_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN13 */
  443. #define LL_ADC_CHANNEL_14 (ADC_CHANNEL_14_NUMBER | ADC_CHANNEL_14_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN14 */
  444. #define LL_ADC_CHANNEL_15 (ADC_CHANNEL_15_NUMBER | ADC_CHANNEL_15_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN15 */
  445. #define LL_ADC_CHANNEL_17 (ADC_CHANNEL_17_NUMBER | ADC_CHANNEL_17_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN17 */
  446. #define LL_ADC_CHANNEL_18 (ADC_CHANNEL_18_NUMBER | ADC_CHANNEL_18_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN18 */
  447. #define LL_ADC_CHANNEL_VREFINT (LL_ADC_CHANNEL_17 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel connected to VrefInt: Internal voltage reference. */
  448. #define LL_ADC_CHANNEL_TEMPSENSOR (LL_ADC_CHANNEL_18 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel connected to Temperature sensor. */
  449. #if defined(ADC_CCR_VLCDEN)
  450. #define LL_ADC_CHANNEL_16 (ADC_CHANNEL_16_NUMBER | ADC_CHANNEL_16_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN16 */
  451. #define LL_ADC_CHANNEL_VLCD (LL_ADC_CHANNEL_16 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel connected to Vlcd: Vlcd voltage through a divider ladder of factor 1/4, 1/3 or 1/2 (set by LCD voltage generator biasing), to have Vlcd always below Vdda. */
  452. #endif
  453. /**
  454. * @}
  455. */
  456. /** @defgroup ADC_LL_EC_REG_TRIGGER_SOURCE ADC group regular - Trigger source
  457. * @{
  458. */
  459. #define LL_ADC_REG_TRIG_SOFTWARE (0x00000000U) /*!< ADC group regular conversion trigger internal: SW start. */
  460. #define LL_ADC_REG_TRIG_EXT_TIM6_TRGO (ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM6 TRGO. Trigger edge set to rising edge (default setting). */
  461. #define LL_ADC_REG_TRIG_EXT_TIM21_CH2 (ADC_CFGR1_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM21 channel 2 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  462. #define LL_ADC_REG_TRIG_EXT_TIM2_TRGO (ADC_CFGR1_EXTSEL_1 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM2 TRGO. Trigger edge set to rising edge (default setting). */
  463. #define LL_ADC_REG_TRIG_EXT_TIM2_CH4 (ADC_CFGR1_EXTSEL_1 | ADC_CFGR1_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM2 channel 4 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  464. #define LL_ADC_REG_TRIG_EXT_TIM22_TRGO (ADC_CFGR1_EXTSEL_2 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM22 TRGO. Trigger edge set to rising edge (default setting). */
  465. #define LL_ADC_REG_TRIG_EXT_TIM3_TRGO (ADC_CFGR1_EXTSEL_2 | ADC_CFGR1_EXTSEL_1 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM3 TRG0. Trigger edge set to rising edge (default setting). */
  466. #define LL_ADC_REG_TRIG_EXT_EXTI_LINE11 (ADC_CFGR1_EXTSEL_2 | ADC_CFGR1_EXTSEL_1 | ADC_CFGR1_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: external interrupt line 11. Trigger edge set to rising edge (default setting). */
  467. /* ADC group regular external trigger TIM2_CC3 available only on */
  468. /* STM32L0 devices categories: Cat.1, Cat.2, Cat.5 */
  469. #if defined (STM32L011xx) || defined (STM32L021xx) || \
  470. defined (STM32L031xx) || defined (STM32L041xx) || \
  471. defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) || \
  472. defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx) || \
  473. defined (STM32L010x6) || defined (STM32L010x8) || defined (STM32L010xB)
  474. #define LL_ADC_REG_TRIG_EXT_TIM2_CH3 (ADC_CFGR1_EXTSEL_2 | ADC_CFGR1_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM2 channel 4 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  475. #endif
  476. /* ADC group regular external trigger TIM21_TRGO available only on */
  477. /* STM32L0 devices categories: Cat.2, Cat.3, Cat.5 */
  478. #if defined (STM32L031xx) || defined (STM32L041xx) || \
  479. defined (STM32L051xx) || defined (STM32L052xx) || defined (STM32L053xx) || \
  480. defined (STM32L062xx) || defined (STM32L063xx) || \
  481. defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) || \
  482. defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx) || \
  483. defined (STM32L010x6) || defined (STM32L010x8) || defined (STM32L010xB)
  484. #define LL_ADC_REG_TRIG_EXT_TIM21_TRGO (LL_ADC_REG_TRIG_EXT_TIM22_TRGO)
  485. #endif
  486. /**
  487. * @}
  488. */
  489. /** @defgroup ADC_LL_EC_REG_TRIGGER_EDGE ADC group regular - Trigger edge
  490. * @{
  491. */
  492. #define LL_ADC_REG_TRIG_EXT_RISING ( ADC_CFGR1_EXTEN_0) /*!< ADC group regular conversion trigger polarity set to rising edge */
  493. #define LL_ADC_REG_TRIG_EXT_FALLING (ADC_CFGR1_EXTEN_1 ) /*!< ADC group regular conversion trigger polarity set to falling edge */
  494. #define LL_ADC_REG_TRIG_EXT_RISINGFALLING (ADC_CFGR1_EXTEN_1 | ADC_CFGR1_EXTEN_0) /*!< ADC group regular conversion trigger polarity set to both rising and falling edges */
  495. /**
  496. * @}
  497. */
  498. /** @defgroup ADC_LL_EC_REG_CONTINUOUS_MODE ADC group regular - Continuous mode
  499. * @{
  500. */
  501. #define LL_ADC_REG_CONV_SINGLE (0x00000000U) /*!< ADC conversions are performed in single mode: one conversion per trigger */
  502. #define LL_ADC_REG_CONV_CONTINUOUS (ADC_CFGR1_CONT) /*!< ADC conversions are performed in continuous mode: after the first trigger, following conversions launched successively automatically */
  503. /**
  504. * @}
  505. */
  506. /** @defgroup ADC_LL_EC_REG_DMA_TRANSFER ADC group regular - DMA transfer of ADC conversion data
  507. * @{
  508. */
  509. #define LL_ADC_REG_DMA_TRANSFER_NONE (0x00000000U) /*!< ADC conversions are not transferred by DMA */
  510. #define LL_ADC_REG_DMA_TRANSFER_LIMITED ( ADC_CFGR1_DMAEN) /*!< ADC conversion data are transferred by DMA, in limited mode (one shot mode): DMA transfer requests are stopped when number of DMA data transfers (number of ADC conversions) is reached. This ADC mode is intended to be used with DMA mode non-circular. */
  511. #define LL_ADC_REG_DMA_TRANSFER_UNLIMITED (ADC_CFGR1_DMACFG | ADC_CFGR1_DMAEN) /*!< ADC conversion data are transferred by DMA, in unlimited mode: DMA transfer requests are unlimited, whatever number of DMA data transferred (number of ADC conversions). This ADC mode is intended to be used with DMA mode circular. */
  512. /**
  513. * @}
  514. */
  515. /** @defgroup ADC_LL_EC_REG_OVR_DATA_BEHAVIOR ADC group regular - Overrun behavior on conversion data
  516. * @{
  517. */
  518. #define LL_ADC_REG_OVR_DATA_PRESERVED (0x00000000U) /*!< ADC group regular behavior in case of overrun: data preserved */
  519. #define LL_ADC_REG_OVR_DATA_OVERWRITTEN (ADC_CFGR1_OVRMOD) /*!< ADC group regular behavior in case of overrun: data overwritten */
  520. /**
  521. * @}
  522. */
  523. /** @defgroup ADC_LL_EC_REG_SEQ_SCAN_DIRECTION ADC group regular - Sequencer scan direction
  524. * @{
  525. */
  526. #define LL_ADC_REG_SEQ_SCAN_DIR_FORWARD (0x00000000U) /*!< ADC group regular sequencer scan direction forward: from lowest channel number to highest channel number (scan of all ranks, ADC conversion of ranks with channels enabled in sequencer). On some other STM32 families, this setting is not available and the default scan direction is forward. */
  527. #define LL_ADC_REG_SEQ_SCAN_DIR_BACKWARD (ADC_CFGR1_SCANDIR) /*!< ADC group regular sequencer scan direction backward: from highest channel number to lowest channel number (scan of all ranks, ADC conversion of ranks with channels enabled in sequencer) */
  528. /**
  529. * @}
  530. */
  531. /** @defgroup ADC_LL_EC_REG_SEQ_DISCONT_MODE ADC group regular - Sequencer discontinuous mode
  532. * @{
  533. */
  534. #define LL_ADC_REG_SEQ_DISCONT_DISABLE (0x00000000U) /*!< ADC group regular sequencer discontinuous mode disable */
  535. #define LL_ADC_REG_SEQ_DISCONT_1RANK (ADC_CFGR1_DISCEN) /*!< ADC group regular sequencer discontinuous mode enable with sequence interruption every rank */
  536. /**
  537. * @}
  538. */
  539. /** @defgroup ADC_LL_EC_CHANNEL_SAMPLINGTIME Channel - Sampling time
  540. * @{
  541. */
  542. #define LL_ADC_SAMPLINGTIME_1CYCLE_5 (0x00000000U) /*!< Sampling time 1.5 ADC clock cycle */
  543. #define LL_ADC_SAMPLINGTIME_3CYCLES_5 (ADC_SMPR_SMP_0) /*!< Sampling time 3.5 ADC clock cycles */
  544. #define LL_ADC_SAMPLINGTIME_7CYCLES_5 (ADC_SMPR_SMP_1) /*!< Sampling time 7.5 ADC clock cycles */
  545. #define LL_ADC_SAMPLINGTIME_12CYCLES_5 (ADC_SMPR_SMP_1 | ADC_SMPR_SMP_0) /*!< Sampling time 12.5 ADC clock cycles */
  546. #define LL_ADC_SAMPLINGTIME_19CYCLES_5 (ADC_SMPR_SMP_2) /*!< Sampling time 19.5 ADC clock cycles */
  547. #define LL_ADC_SAMPLINGTIME_39CYCLES_5 (ADC_SMPR_SMP_2 | ADC_SMPR_SMP_0) /*!< Sampling time 39.5 ADC clock cycles */
  548. #define LL_ADC_SAMPLINGTIME_79CYCLES_5 (ADC_SMPR_SMP_2 | ADC_SMPR_SMP_1) /*!< Sampling time 79.5 ADC clock cycles */
  549. #define LL_ADC_SAMPLINGTIME_160CYCLES_5 (ADC_SMPR_SMP_2 | ADC_SMPR_SMP_1 | ADC_SMPR_SMP_0) /*!< Sampling time 160.5 ADC clock cycles */
  550. /**
  551. * @}
  552. */
  553. /** @defgroup ADC_LL_EC_AWD_NUMBER Analog watchdog - Analog watchdog number
  554. * @{
  555. */
  556. #define LL_ADC_AWD1 (ADC_AWD_CR1_CHANNEL_MASK | ADC_AWD_CR1_REGOFFSET) /*!< ADC analog watchdog number 1 */
  557. /**
  558. * @}
  559. */
  560. /** @defgroup ADC_LL_EC_AWD_CHANNELS Analog watchdog - Monitored channels
  561. * @{
  562. */
  563. #define LL_ADC_AWD_DISABLE (0x00000000U) /*!< ADC analog watchdog monitoring disabled */
  564. #define LL_ADC_AWD_ALL_CHANNELS_REG ( ADC_CFGR1_AWDEN ) /*!< ADC analog watchdog monitoring of all channels, converted by group regular only */
  565. #define LL_ADC_AWD_CHANNEL_0_REG ((LL_ADC_CHANNEL_0 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN0, converted by group regular only */
  566. #define LL_ADC_AWD_CHANNEL_1_REG ((LL_ADC_CHANNEL_1 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN1, converted by group regular only */
  567. #define LL_ADC_AWD_CHANNEL_2_REG ((LL_ADC_CHANNEL_2 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN2, converted by group regular only */
  568. #define LL_ADC_AWD_CHANNEL_3_REG ((LL_ADC_CHANNEL_3 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN3, converted by group regular only */
  569. #define LL_ADC_AWD_CHANNEL_4_REG ((LL_ADC_CHANNEL_4 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN4, converted by group regular only */
  570. #define LL_ADC_AWD_CHANNEL_5_REG ((LL_ADC_CHANNEL_5 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN5, converted by group regular only */
  571. #define LL_ADC_AWD_CHANNEL_6_REG ((LL_ADC_CHANNEL_6 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN6, converted by group regular only */
  572. #define LL_ADC_AWD_CHANNEL_7_REG ((LL_ADC_CHANNEL_7 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN7, converted by group regular only */
  573. #define LL_ADC_AWD_CHANNEL_8_REG ((LL_ADC_CHANNEL_8 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN8, converted by group regular only */
  574. #define LL_ADC_AWD_CHANNEL_9_REG ((LL_ADC_CHANNEL_9 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN9, converted by group regular only */
  575. #define LL_ADC_AWD_CHANNEL_10_REG ((LL_ADC_CHANNEL_10 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN10, converted by group regular only */
  576. #define LL_ADC_AWD_CHANNEL_11_REG ((LL_ADC_CHANNEL_11 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN11, converted by group regular only */
  577. #define LL_ADC_AWD_CHANNEL_12_REG ((LL_ADC_CHANNEL_12 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN12, converted by group regular only */
  578. #define LL_ADC_AWD_CHANNEL_13_REG ((LL_ADC_CHANNEL_13 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN13, converted by group regular only */
  579. #define LL_ADC_AWD_CHANNEL_14_REG ((LL_ADC_CHANNEL_14 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN14, converted by group regular only */
  580. #define LL_ADC_AWD_CHANNEL_15_REG ((LL_ADC_CHANNEL_15 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN15, converted by group regular only */
  581. #define LL_ADC_AWD_CHANNEL_17_REG ((LL_ADC_CHANNEL_17 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN17, converted by group regular only */
  582. #define LL_ADC_AWD_CHANNEL_18_REG ((LL_ADC_CHANNEL_18 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN18, converted by group regular only */
  583. #define LL_ADC_AWD_CH_VREFINT_REG ((LL_ADC_CHANNEL_VREFINT & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to VrefInt: Internal voltage reference, converted by group regular only */
  584. #define LL_ADC_AWD_CH_TEMPSENSOR_REG ((LL_ADC_CHANNEL_TEMPSENSOR & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to Temperature sensor, converted by group regular only */
  585. #if defined(ADC_CCR_VLCDEN)
  586. #define LL_ADC_AWD_CHANNEL_16_REG ((LL_ADC_CHANNEL_16 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN16, converted by group regular only */
  587. #define LL_ADC_AWD_CH_VLCD_REG ((LL_ADC_CHANNEL_VLCD & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to Vbat/3: Vbat voltage through a divider ladder of factor 1/3 to have Vbat always below Vdda, converted by group regular only */
  588. #endif
  589. /**
  590. * @}
  591. */
  592. /** @defgroup ADC_LL_EC_AWD_THRESHOLDS Analog watchdog - Thresholds
  593. * @{
  594. */
  595. #define LL_ADC_AWD_THRESHOLD_HIGH (ADC_TR_HT ) /*!< ADC analog watchdog threshold high */
  596. #define LL_ADC_AWD_THRESHOLD_LOW ( ADC_TR_LT) /*!< ADC analog watchdog threshold low */
  597. #define LL_ADC_AWD_THRESHOLDS_HIGH_LOW (ADC_TR_HT | ADC_TR_LT) /*!< ADC analog watchdog both thresholds high and low concatenated into the same data */
  598. /**
  599. * @}
  600. */
  601. /** @defgroup ADC_LL_EC_OVS_SCOPE Oversampling - Oversampling scope
  602. * @{
  603. */
  604. #define LL_ADC_OVS_DISABLE (0x00000000U) /*!< ADC oversampling disabled. */
  605. #define LL_ADC_OVS_GRP_REGULAR_CONTINUED ( ADC_CFGR2_OVSE) /*!< ADC oversampling on conversions of ADC group regular. Literal suffix "continued" is kept for compatibility with other STM32 devices featuring ADC group injected, in this case other oversampling scope parameters are available. */
  606. /**
  607. * @}
  608. */
  609. /** @defgroup ADC_LL_EC_OVS_DISCONT_MODE Oversampling - Discontinuous mode
  610. * @{
  611. */
  612. #define LL_ADC_OVS_REG_CONT (0x00000000U) /*!< ADC oversampling discontinuous mode: continuous mode (all conversions of oversampling ratio are done from 1 trigger) */
  613. #define LL_ADC_OVS_REG_DISCONT (ADC_CFGR2_TOVS) /*!< ADC oversampling discontinuous mode: discontinuous mode (each conversion of oversampling ratio needs a trigger) */
  614. /**
  615. * @}
  616. */
  617. /** @defgroup ADC_LL_EC_OVS_RATIO Oversampling - Ratio
  618. * @{
  619. */
  620. #define LL_ADC_OVS_RATIO_2 (0x00000000U) /*!< ADC oversampling ratio of 2 (2 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  621. #define LL_ADC_OVS_RATIO_4 ( ADC_CFGR2_OVSR_0) /*!< ADC oversampling ratio of 4 (4 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  622. #define LL_ADC_OVS_RATIO_8 ( ADC_CFGR2_OVSR_1 ) /*!< ADC oversampling ratio of 8 (8 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  623. #define LL_ADC_OVS_RATIO_16 ( ADC_CFGR2_OVSR_1 | ADC_CFGR2_OVSR_0) /*!< ADC oversampling ratio of 16 (16 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  624. #define LL_ADC_OVS_RATIO_32 (ADC_CFGR2_OVSR_2 ) /*!< ADC oversampling ratio of 32 (32 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  625. #define LL_ADC_OVS_RATIO_64 (ADC_CFGR2_OVSR_2 | ADC_CFGR2_OVSR_0) /*!< ADC oversampling ratio of 64 (64 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  626. #define LL_ADC_OVS_RATIO_128 (ADC_CFGR2_OVSR_2 | ADC_CFGR2_OVSR_1 ) /*!< ADC oversampling ratio of 128 (128 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  627. #define LL_ADC_OVS_RATIO_256 (ADC_CFGR2_OVSR_2 | ADC_CFGR2_OVSR_1 | ADC_CFGR2_OVSR_0) /*!< ADC oversampling ratio of 256 (256 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  628. /**
  629. * @}
  630. */
  631. /** @defgroup ADC_LL_EC_OVS_SHIFT Oversampling - Data shift
  632. * @{
  633. */
  634. #define LL_ADC_OVS_SHIFT_NONE (0x00000000U) /*!< ADC oversampling no shift (sum of the ADC conversions data is not divided to result as the ADC oversampling conversion data) */
  635. #define LL_ADC_OVS_SHIFT_RIGHT_1 ( ADC_CFGR2_OVSS_0) /*!< ADC oversampling shift of 1 (sum of the ADC conversions data is divided by 2 to result as the ADC oversampling conversion data) */
  636. #define LL_ADC_OVS_SHIFT_RIGHT_2 ( ADC_CFGR2_OVSS_1 ) /*!< ADC oversampling shift of 2 (sum of the ADC conversions data is divided by 4 to result as the ADC oversampling conversion data) */
  637. #define LL_ADC_OVS_SHIFT_RIGHT_3 ( ADC_CFGR2_OVSS_1 | ADC_CFGR2_OVSS_0) /*!< ADC oversampling shift of 3 (sum of the ADC conversions data is divided by 8 to result as the ADC oversampling conversion data) */
  638. #define LL_ADC_OVS_SHIFT_RIGHT_4 ( ADC_CFGR2_OVSS_2 ) /*!< ADC oversampling shift of 4 (sum of the ADC conversions data is divided by 16 to result as the ADC oversampling conversion data) */
  639. #define LL_ADC_OVS_SHIFT_RIGHT_5 ( ADC_CFGR2_OVSS_2 | ADC_CFGR2_OVSS_0) /*!< ADC oversampling shift of 5 (sum of the ADC conversions data is divided by 32 to result as the ADC oversampling conversion data) */
  640. #define LL_ADC_OVS_SHIFT_RIGHT_6 ( ADC_CFGR2_OVSS_2 | ADC_CFGR2_OVSS_1 ) /*!< ADC oversampling shift of 6 (sum of the ADC conversions data is divided by 64 to result as the ADC oversampling conversion data) */
  641. #define LL_ADC_OVS_SHIFT_RIGHT_7 ( ADC_CFGR2_OVSS_2 | ADC_CFGR2_OVSS_1 | ADC_CFGR2_OVSS_0) /*!< ADC oversampling shift of 7 (sum of the ADC conversions data is divided by 128 to result as the ADC oversampling conversion data) */
  642. #define LL_ADC_OVS_SHIFT_RIGHT_8 (ADC_CFGR2_OVSS_3 ) /*!< ADC oversampling shift of 8 (sum of the ADC conversions data is divided by 256 to result as the ADC oversampling conversion data) */
  643. /**
  644. * @}
  645. */
  646. /** @defgroup ADC_LL_EC_HW_DELAYS Definitions of ADC hardware constraints delays
  647. * @note Only ADC peripheral HW delays are defined in ADC LL driver driver,
  648. * not timeout values.
  649. * For details on delays values, refer to descriptions in source code
  650. * above each literal definition.
  651. * @{
  652. */
  653. /* Note: Only ADC peripheral HW delays are defined in ADC LL driver driver, */
  654. /* not timeout values. */
  655. /* Timeout values for ADC operations are dependent to device clock */
  656. /* configuration (system clock versus ADC clock), */
  657. /* and therefore must be defined in user application. */
  658. /* Indications for estimation of ADC timeout delays, for this */
  659. /* STM32 series: */
  660. /* - ADC calibration time: maximum delay is 83/fADC. */
  661. /* (refer to device datasheet, parameter "tCAL") */
  662. /* - ADC enable time: maximum delay is 1 conversion cycle. */
  663. /* (refer to device datasheet, parameter "tSTAB") */
  664. /* - ADC disable time: maximum delay should be a few ADC clock cycles */
  665. /* - ADC stop conversion time: maximum delay should be a few ADC clock */
  666. /* cycles */
  667. /* - ADC conversion time: duration depending on ADC clock and ADC */
  668. /* configuration. */
  669. /* (refer to device reference manual, section "Timing") */
  670. /* Delay for ADC stabilization time (ADC voltage regulator start-up time) */
  671. /* Delay set to maximum value (refer to device datasheet, */
  672. /* parameter "tUP_LDO"). */
  673. #define LL_ADC_DELAY_INTERNAL_REGUL_STAB_US (10U) /*!< Delay for ADC stabilization time (ADC voltage regulator start-up time) */
  674. /* Delay for internal voltage reference stabilization time. */
  675. /* Delay set to maximum value (refer to device datasheet, */
  676. /* parameter "TADC_BUF"). */
  677. /* Unit: us */
  678. #define LL_ADC_DELAY_VREFINT_STAB_US (10U) /*!< Delay for internal voltage reference stabilization time */
  679. /* Delay for temperature sensor stabilization time. */
  680. /* Literal set to maximum value (refer to device datasheet, */
  681. /* parameter "tSTART"). */
  682. /* Unit: us */
  683. #define LL_ADC_DELAY_TEMPSENSOR_STAB_US (10U) /*!< Delay for temperature sensor stabilization time */
  684. /* Delay required between ADC end of calibration and ADC enable. */
  685. /* Note: On this STM32 series, a minimum number of ADC clock cycles */
  686. /* are required between ADC end of calibration and ADC enable. */
  687. /* Wait time can be computed in user application by waiting for the */
  688. /* equivalent number of CPU cycles, by taking into account */
  689. /* ratio of CPU clock versus ADC clock prescalers. */
  690. /* Unit: ADC clock cycles. */
  691. #define LL_ADC_DELAY_CALIB_ENABLE_ADC_CYCLES (2U) /*!< Delay required between ADC end of calibration and ADC enable */
  692. /**
  693. * @}
  694. */
  695. /**
  696. * @}
  697. */
  698. /* Exported macro ------------------------------------------------------------*/
  699. /** @defgroup ADC_LL_Exported_Macros ADC Exported Macros
  700. * @{
  701. */
  702. /** @defgroup ADC_LL_EM_WRITE_READ Common write and read registers Macros
  703. * @{
  704. */
  705. /**
  706. * @brief Write a value in ADC register
  707. * @param __INSTANCE__ ADC Instance
  708. * @param __REG__ Register to be written
  709. * @param __VALUE__ Value to be written in the register
  710. * @retval None
  711. */
  712. #define LL_ADC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  713. /**
  714. * @brief Read a value in ADC register
  715. * @param __INSTANCE__ ADC Instance
  716. * @param __REG__ Register to be read
  717. * @retval Register value
  718. */
  719. #define LL_ADC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  720. /**
  721. * @}
  722. */
  723. /** @defgroup ADC_LL_EM_HELPER_MACRO ADC helper macro
  724. * @{
  725. */
  726. /**
  727. * @brief Helper macro to get ADC channel number in decimal format
  728. * from literals LL_ADC_CHANNEL_x.
  729. * @note Example:
  730. * __LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_CHANNEL_4)
  731. * will return decimal number "4".
  732. * @note The input can be a value from functions where a channel
  733. * number is returned, either defined with number
  734. * or with bitfield (only one bit must be set).
  735. * @param __CHANNEL__ This parameter can be one of the following values:
  736. * @arg @ref LL_ADC_CHANNEL_0
  737. * @arg @ref LL_ADC_CHANNEL_1
  738. * @arg @ref LL_ADC_CHANNEL_2
  739. * @arg @ref LL_ADC_CHANNEL_3
  740. * @arg @ref LL_ADC_CHANNEL_4
  741. * @arg @ref LL_ADC_CHANNEL_5
  742. * @arg @ref LL_ADC_CHANNEL_6
  743. * @arg @ref LL_ADC_CHANNEL_7
  744. * @arg @ref LL_ADC_CHANNEL_8
  745. * @arg @ref LL_ADC_CHANNEL_9
  746. * @arg @ref LL_ADC_CHANNEL_10
  747. * @arg @ref LL_ADC_CHANNEL_11
  748. * @arg @ref LL_ADC_CHANNEL_12
  749. * @arg @ref LL_ADC_CHANNEL_13
  750. * @arg @ref LL_ADC_CHANNEL_14
  751. * @arg @ref LL_ADC_CHANNEL_15
  752. * @arg @ref LL_ADC_CHANNEL_16 (1)
  753. * @arg @ref LL_ADC_CHANNEL_17
  754. * @arg @ref LL_ADC_CHANNEL_18
  755. * @arg @ref LL_ADC_CHANNEL_VREFINT
  756. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  757. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  758. *
  759. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  760. * @retval Value between Min_Data=0 and Max_Data=18
  761. */
  762. #if defined(ADC_CCR_VLCDEN)
  763. #define __LL_ADC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__) \
  764. ((((__CHANNEL__) & ADC_CHANNEL_ID_BITFIELD_MASK) == 0U) \
  765. ? ( \
  766. ((__CHANNEL__) & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS \
  767. ) \
  768. : \
  769. ( \
  770. (((__CHANNEL__) & ADC_CHSELR_CHSEL0) == ADC_CHSELR_CHSEL0) ? (0U) : \
  771. ( \
  772. (((__CHANNEL__) & ADC_CHSELR_CHSEL1) == ADC_CHSELR_CHSEL1) ? (1U) : \
  773. ( \
  774. (((__CHANNEL__) & ADC_CHSELR_CHSEL2) == ADC_CHSELR_CHSEL2) ? (2U) : \
  775. ( \
  776. (((__CHANNEL__) & ADC_CHSELR_CHSEL3) == ADC_CHSELR_CHSEL3) ? (3U) : \
  777. ( \
  778. (((__CHANNEL__) & ADC_CHSELR_CHSEL4) == ADC_CHSELR_CHSEL4) ? (4U) : \
  779. ( \
  780. (((__CHANNEL__) & ADC_CHSELR_CHSEL5) == ADC_CHSELR_CHSEL5) ? (5U) : \
  781. ( \
  782. (((__CHANNEL__) & ADC_CHSELR_CHSEL6) == ADC_CHSELR_CHSEL6) ? (6U) : \
  783. ( \
  784. (((__CHANNEL__) & ADC_CHSELR_CHSEL7) == ADC_CHSELR_CHSEL7) ? (7U) : \
  785. ( \
  786. (((__CHANNEL__) & ADC_CHSELR_CHSEL8) == ADC_CHSELR_CHSEL8) ? (8U) : \
  787. ( \
  788. (((__CHANNEL__) & ADC_CHSELR_CHSEL9) == ADC_CHSELR_CHSEL9) ? (9U) : \
  789. ( \
  790. (((__CHANNEL__) & ADC_CHSELR_CHSEL10) == ADC_CHSELR_CHSEL10) ? (10U) : \
  791. ( \
  792. (((__CHANNEL__) & ADC_CHSELR_CHSEL11) == ADC_CHSELR_CHSEL11) ? (11U) : \
  793. ( \
  794. (((__CHANNEL__) & ADC_CHSELR_CHSEL12) == ADC_CHSELR_CHSEL12) ? (12U) : \
  795. ( \
  796. (((__CHANNEL__) & ADC_CHSELR_CHSEL13) == ADC_CHSELR_CHSEL13) ? (13U) : \
  797. ( \
  798. (((__CHANNEL__) & ADC_CHSELR_CHSEL14) == ADC_CHSELR_CHSEL14) ? (14U) : \
  799. ( \
  800. (((__CHANNEL__) & ADC_CHSELR_CHSEL15) == ADC_CHSELR_CHSEL15) ? (15U) : \
  801. ( \
  802. (((__CHANNEL__) & ADC_CHSELR_CHSEL16) == ADC_CHSELR_CHSEL16) ? (16U) : \
  803. ( \
  804. (((__CHANNEL__) & ADC_CHSELR_CHSEL17) == ADC_CHSELR_CHSEL17) ? (17U) : \
  805. ( \
  806. (((__CHANNEL__) & ADC_CHSELR_CHSEL18) == ADC_CHSELR_CHSEL18) ? (18U) : \
  807. (0U) \
  808. ) \
  809. ) \
  810. ) \
  811. ) \
  812. ) \
  813. ) \
  814. ) \
  815. ) \
  816. ) \
  817. ) \
  818. ) \
  819. ) \
  820. ) \
  821. ) \
  822. ) \
  823. ) \
  824. ) \
  825. ) \
  826. ) \
  827. )
  828. #else
  829. #define __LL_ADC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__) \
  830. ((((__CHANNEL__) & ADC_CHANNEL_ID_BITFIELD_MASK) == 0U) \
  831. ? ( \
  832. ((__CHANNEL__) & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS \
  833. ) \
  834. : \
  835. ( \
  836. (((__CHANNEL__) & ADC_CHSELR_CHSEL0) == ADC_CHSELR_CHSEL0) ? (0U) : \
  837. ( \
  838. (((__CHANNEL__) & ADC_CHSELR_CHSEL1) == ADC_CHSELR_CHSEL1) ? (1U) : \
  839. ( \
  840. (((__CHANNEL__) & ADC_CHSELR_CHSEL2) == ADC_CHSELR_CHSEL2) ? (2U) : \
  841. ( \
  842. (((__CHANNEL__) & ADC_CHSELR_CHSEL3) == ADC_CHSELR_CHSEL3) ? (3U) : \
  843. ( \
  844. (((__CHANNEL__) & ADC_CHSELR_CHSEL4) == ADC_CHSELR_CHSEL4) ? (4U) : \
  845. ( \
  846. (((__CHANNEL__) & ADC_CHSELR_CHSEL5) == ADC_CHSELR_CHSEL5) ? (5U) : \
  847. ( \
  848. (((__CHANNEL__) & ADC_CHSELR_CHSEL6) == ADC_CHSELR_CHSEL6) ? (6U) : \
  849. ( \
  850. (((__CHANNEL__) & ADC_CHSELR_CHSEL7) == ADC_CHSELR_CHSEL7) ? (7U) : \
  851. ( \
  852. (((__CHANNEL__) & ADC_CHSELR_CHSEL8) == ADC_CHSELR_CHSEL8) ? (8U) : \
  853. ( \
  854. (((__CHANNEL__) & ADC_CHSELR_CHSEL9) == ADC_CHSELR_CHSEL9) ? (9U) : \
  855. ( \
  856. (((__CHANNEL__) & ADC_CHSELR_CHSEL10) == ADC_CHSELR_CHSEL10) ? (10U) : \
  857. ( \
  858. (((__CHANNEL__) & ADC_CHSELR_CHSEL11) == ADC_CHSELR_CHSEL11) ? (11U) : \
  859. ( \
  860. (((__CHANNEL__) & ADC_CHSELR_CHSEL12) == ADC_CHSELR_CHSEL12) ? (12U) : \
  861. ( \
  862. (((__CHANNEL__) & ADC_CHSELR_CHSEL13) == ADC_CHSELR_CHSEL13) ? (13U) : \
  863. ( \
  864. (((__CHANNEL__) & ADC_CHSELR_CHSEL14) == ADC_CHSELR_CHSEL14) ? (14U) : \
  865. ( \
  866. (((__CHANNEL__) & ADC_CHSELR_CHSEL15) == ADC_CHSELR_CHSEL15) ? (15U) : \
  867. ( \
  868. (((__CHANNEL__) & ADC_CHSELR_CHSEL17) == ADC_CHSELR_CHSEL17) ? (17U) : \
  869. ( \
  870. (((__CHANNEL__) & ADC_CHSELR_CHSEL18) == ADC_CHSELR_CHSEL18) ? (18U) : \
  871. (0U) \
  872. ) \
  873. ) \
  874. ) \
  875. ) \
  876. ) \
  877. ) \
  878. ) \
  879. ) \
  880. ) \
  881. ) \
  882. ) \
  883. ) \
  884. ) \
  885. ) \
  886. ) \
  887. ) \
  888. ) \
  889. ) \
  890. )
  891. #endif
  892. /**
  893. * @brief Helper macro to get ADC channel in literal format LL_ADC_CHANNEL_x
  894. * from number in decimal format.
  895. * @note Example:
  896. * __LL_ADC_DECIMAL_NB_TO_CHANNEL(4)
  897. * will return a data equivalent to "LL_ADC_CHANNEL_4".
  898. * @param __DECIMAL_NB__ Value between Min_Data=0 and Max_Data=18
  899. * @retval Returned value can be one of the following values:
  900. * @arg @ref LL_ADC_CHANNEL_0
  901. * @arg @ref LL_ADC_CHANNEL_1
  902. * @arg @ref LL_ADC_CHANNEL_2
  903. * @arg @ref LL_ADC_CHANNEL_3
  904. * @arg @ref LL_ADC_CHANNEL_4
  905. * @arg @ref LL_ADC_CHANNEL_5
  906. * @arg @ref LL_ADC_CHANNEL_6
  907. * @arg @ref LL_ADC_CHANNEL_7
  908. * @arg @ref LL_ADC_CHANNEL_8
  909. * @arg @ref LL_ADC_CHANNEL_9
  910. * @arg @ref LL_ADC_CHANNEL_10
  911. * @arg @ref LL_ADC_CHANNEL_11
  912. * @arg @ref LL_ADC_CHANNEL_12
  913. * @arg @ref LL_ADC_CHANNEL_13
  914. * @arg @ref LL_ADC_CHANNEL_14
  915. * @arg @ref LL_ADC_CHANNEL_15
  916. * @arg @ref LL_ADC_CHANNEL_16 (1)
  917. * @arg @ref LL_ADC_CHANNEL_17
  918. * @arg @ref LL_ADC_CHANNEL_18
  919. * @arg @ref LL_ADC_CHANNEL_VREFINT (2)
  920. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (2)
  921. * @arg @ref LL_ADC_CHANNEL_VLCD (1)(2)
  922. *
  923. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.\n
  924. * (2) For ADC channel read back from ADC register,
  925. * comparison with internal channel parameter to be done
  926. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  927. */
  928. #define __LL_ADC_DECIMAL_NB_TO_CHANNEL(__DECIMAL_NB__) \
  929. ( \
  930. ((__DECIMAL_NB__) << ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) | \
  931. (ADC_CHSELR_CHSEL0 << (__DECIMAL_NB__)) \
  932. )
  933. /**
  934. * @brief Helper macro to determine whether the selected channel
  935. * corresponds to literal definitions of driver.
  936. * @note The different literal definitions of ADC channels are:
  937. * - ADC internal channel:
  938. * LL_ADC_CHANNEL_VREFINT, LL_ADC_CHANNEL_TEMPSENSOR, ...
  939. * - ADC external channel (channel connected to a GPIO pin):
  940. * LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...
  941. * @note The channel parameter must be a value defined from literal
  942. * definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT,
  943. * LL_ADC_CHANNEL_TEMPSENSOR, ...),
  944. * ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...),
  945. * must not be a value from functions where a channel number is
  946. * returned from ADC registers,
  947. * because internal and external channels share the same channel
  948. * number in ADC registers. The differentiation is made only with
  949. * parameters definitions of driver.
  950. * @param __CHANNEL__ This parameter can be one of the following values:
  951. * @arg @ref LL_ADC_CHANNEL_0
  952. * @arg @ref LL_ADC_CHANNEL_1
  953. * @arg @ref LL_ADC_CHANNEL_2
  954. * @arg @ref LL_ADC_CHANNEL_3
  955. * @arg @ref LL_ADC_CHANNEL_4
  956. * @arg @ref LL_ADC_CHANNEL_5
  957. * @arg @ref LL_ADC_CHANNEL_6
  958. * @arg @ref LL_ADC_CHANNEL_7
  959. * @arg @ref LL_ADC_CHANNEL_8
  960. * @arg @ref LL_ADC_CHANNEL_9
  961. * @arg @ref LL_ADC_CHANNEL_10
  962. * @arg @ref LL_ADC_CHANNEL_11
  963. * @arg @ref LL_ADC_CHANNEL_12
  964. * @arg @ref LL_ADC_CHANNEL_13
  965. * @arg @ref LL_ADC_CHANNEL_14
  966. * @arg @ref LL_ADC_CHANNEL_15
  967. * @arg @ref LL_ADC_CHANNEL_16 (1)
  968. * @arg @ref LL_ADC_CHANNEL_17
  969. * @arg @ref LL_ADC_CHANNEL_18
  970. * @arg @ref LL_ADC_CHANNEL_VREFINT
  971. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  972. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  973. *
  974. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  975. * @retval Value "0" if the channel corresponds to a parameter definition of a ADC external channel (channel connected to a GPIO pin).
  976. * Value "1" if the channel corresponds to a parameter definition of a ADC internal channel.
  977. */
  978. #define __LL_ADC_IS_CHANNEL_INTERNAL(__CHANNEL__) \
  979. (((__CHANNEL__) & ADC_CHANNEL_ID_INTERNAL_CH_MASK) != 0U)
  980. /**
  981. * @brief Helper macro to convert a channel defined from parameter
  982. * definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT,
  983. * LL_ADC_CHANNEL_TEMPSENSOR, ...),
  984. * to its equivalent parameter definition of a ADC external channel
  985. * (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...).
  986. * @note The channel parameter can be, additionally to a value
  987. * defined from parameter definition of a ADC internal channel
  988. * (LL_ADC_CHANNEL_VREFINT, LL_ADC_CHANNEL_TEMPSENSOR, ...),
  989. * a value defined from parameter definition of
  990. * ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...)
  991. * or a value from functions where a channel number is returned
  992. * from ADC registers.
  993. * @param __CHANNEL__ This parameter can be one of the following values:
  994. * @arg @ref LL_ADC_CHANNEL_0
  995. * @arg @ref LL_ADC_CHANNEL_1
  996. * @arg @ref LL_ADC_CHANNEL_2
  997. * @arg @ref LL_ADC_CHANNEL_3
  998. * @arg @ref LL_ADC_CHANNEL_4
  999. * @arg @ref LL_ADC_CHANNEL_5
  1000. * @arg @ref LL_ADC_CHANNEL_6
  1001. * @arg @ref LL_ADC_CHANNEL_7
  1002. * @arg @ref LL_ADC_CHANNEL_8
  1003. * @arg @ref LL_ADC_CHANNEL_9
  1004. * @arg @ref LL_ADC_CHANNEL_10
  1005. * @arg @ref LL_ADC_CHANNEL_11
  1006. * @arg @ref LL_ADC_CHANNEL_12
  1007. * @arg @ref LL_ADC_CHANNEL_13
  1008. * @arg @ref LL_ADC_CHANNEL_14
  1009. * @arg @ref LL_ADC_CHANNEL_15
  1010. * @arg @ref LL_ADC_CHANNEL_16 (1)
  1011. * @arg @ref LL_ADC_CHANNEL_17
  1012. * @arg @ref LL_ADC_CHANNEL_18
  1013. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1014. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1015. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  1016. *
  1017. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  1018. * @retval Returned value can be one of the following values:
  1019. * @arg @ref LL_ADC_CHANNEL_0
  1020. * @arg @ref LL_ADC_CHANNEL_1
  1021. * @arg @ref LL_ADC_CHANNEL_2
  1022. * @arg @ref LL_ADC_CHANNEL_3
  1023. * @arg @ref LL_ADC_CHANNEL_4
  1024. * @arg @ref LL_ADC_CHANNEL_5
  1025. * @arg @ref LL_ADC_CHANNEL_6
  1026. * @arg @ref LL_ADC_CHANNEL_7
  1027. * @arg @ref LL_ADC_CHANNEL_8
  1028. * @arg @ref LL_ADC_CHANNEL_9
  1029. * @arg @ref LL_ADC_CHANNEL_10
  1030. * @arg @ref LL_ADC_CHANNEL_11
  1031. * @arg @ref LL_ADC_CHANNEL_12
  1032. * @arg @ref LL_ADC_CHANNEL_13
  1033. * @arg @ref LL_ADC_CHANNEL_14
  1034. * @arg @ref LL_ADC_CHANNEL_15
  1035. * @arg @ref LL_ADC_CHANNEL_16
  1036. * @arg @ref LL_ADC_CHANNEL_17
  1037. * @arg @ref LL_ADC_CHANNEL_18
  1038. */
  1039. #define __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL(__CHANNEL__) \
  1040. ((__CHANNEL__) & ~ADC_CHANNEL_ID_INTERNAL_CH_MASK)
  1041. /**
  1042. * @brief Helper macro to determine whether the internal channel
  1043. * selected is available on the ADC instance selected.
  1044. * @note The channel parameter must be a value defined from parameter
  1045. * definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT,
  1046. * LL_ADC_CHANNEL_TEMPSENSOR, ...),
  1047. * must not be a value defined from parameter definition of
  1048. * ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...)
  1049. * or a value from functions where a channel number is
  1050. * returned from ADC registers,
  1051. * because internal and external channels share the same channel
  1052. * number in ADC registers. The differentiation is made only with
  1053. * parameters definitions of driver.
  1054. * @param __ADC_INSTANCE__ ADC instance
  1055. * @param __CHANNEL__ This parameter can be one of the following values:
  1056. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1057. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1058. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  1059. *
  1060. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  1061. * @retval Value "0" if the internal channel selected is not available on the ADC instance selected.
  1062. * Value "1" if the internal channel selected is available on the ADC instance selected.
  1063. */
  1064. #if defined(ADC_CCR_VLCDEN)
  1065. #define __LL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE(__ADC_INSTANCE__, __CHANNEL__) \
  1066. ( \
  1067. ((__CHANNEL__) == LL_ADC_CHANNEL_VREFINT) || \
  1068. ((__CHANNEL__) == LL_ADC_CHANNEL_TEMPSENSOR) || \
  1069. ((__CHANNEL__) == LL_ADC_CHANNEL_VLCD) \
  1070. )
  1071. #else
  1072. #define __LL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE(__ADC_INSTANCE__, __CHANNEL__) \
  1073. ( \
  1074. ((__CHANNEL__) == LL_ADC_CHANNEL_VREFINT) || \
  1075. ((__CHANNEL__) == LL_ADC_CHANNEL_TEMPSENSOR) \
  1076. )
  1077. #endif
  1078. /**
  1079. * @brief Helper macro to define ADC analog watchdog parameter:
  1080. * define a single channel to monitor with analog watchdog
  1081. * from sequencer channel and groups definition.
  1082. * @note To be used with function @ref LL_ADC_SetAnalogWDMonitChannels().
  1083. * Example:
  1084. * LL_ADC_SetAnalogWDMonitChannels(
  1085. * ADC1, LL_ADC_AWD1,
  1086. * __LL_ADC_ANALOGWD_CHANNEL_GROUP(LL_ADC_CHANNEL4, LL_ADC_GROUP_REGULAR))
  1087. * @param __CHANNEL__ This parameter can be one of the following values:
  1088. * @arg @ref LL_ADC_CHANNEL_0
  1089. * @arg @ref LL_ADC_CHANNEL_1
  1090. * @arg @ref LL_ADC_CHANNEL_2
  1091. * @arg @ref LL_ADC_CHANNEL_3
  1092. * @arg @ref LL_ADC_CHANNEL_4
  1093. * @arg @ref LL_ADC_CHANNEL_5
  1094. * @arg @ref LL_ADC_CHANNEL_6
  1095. * @arg @ref LL_ADC_CHANNEL_7
  1096. * @arg @ref LL_ADC_CHANNEL_8
  1097. * @arg @ref LL_ADC_CHANNEL_9
  1098. * @arg @ref LL_ADC_CHANNEL_10
  1099. * @arg @ref LL_ADC_CHANNEL_11
  1100. * @arg @ref LL_ADC_CHANNEL_12
  1101. * @arg @ref LL_ADC_CHANNEL_13
  1102. * @arg @ref LL_ADC_CHANNEL_14
  1103. * @arg @ref LL_ADC_CHANNEL_15
  1104. * @arg @ref LL_ADC_CHANNEL_16 (1)
  1105. * @arg @ref LL_ADC_CHANNEL_17
  1106. * @arg @ref LL_ADC_CHANNEL_18
  1107. * @arg @ref LL_ADC_CHANNEL_VREFINT (2)
  1108. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (2)
  1109. * @arg @ref LL_ADC_CHANNEL_VLCD (1)(2)
  1110. *
  1111. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.\n
  1112. * (2) For ADC channel read back from ADC register,
  1113. * comparison with internal channel parameter to be done
  1114. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  1115. * @param __GROUP__ This parameter can be one of the following values:
  1116. * @arg @ref LL_ADC_GROUP_REGULAR
  1117. * @retval Returned value can be one of the following values:
  1118. * @arg @ref LL_ADC_AWD_DISABLE
  1119. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG
  1120. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG
  1121. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG
  1122. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG
  1123. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG
  1124. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG
  1125. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG
  1126. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG
  1127. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG
  1128. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG
  1129. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG
  1130. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG
  1131. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG
  1132. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG
  1133. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG
  1134. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG
  1135. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG
  1136. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG (1)
  1137. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG
  1138. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG
  1139. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG
  1140. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG
  1141. * @arg @ref LL_ADC_AWD_CH_VLCD_REG (1)
  1142. *
  1143. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  1144. */
  1145. #define __LL_ADC_ANALOGWD_CHANNEL_GROUP(__CHANNEL__, __GROUP__) \
  1146. (((__CHANNEL__) & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL)
  1147. /**
  1148. * @brief Helper macro to set the value of ADC analog watchdog threshold high
  1149. * or low in function of ADC resolution, when ADC resolution is
  1150. * different of 12 bits.
  1151. * @note To be used with function @ref LL_ADC_ConfigAnalogWDThresholds()
  1152. * or @ref LL_ADC_SetAnalogWDThresholds().
  1153. * Example, with a ADC resolution of 8 bits, to set the value of
  1154. * analog watchdog threshold high (on 8 bits):
  1155. * LL_ADC_SetAnalogWDThresholds
  1156. * (< ADCx param >,
  1157. * __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION(LL_ADC_RESOLUTION_8B, <threshold_value_8_bits>)
  1158. * );
  1159. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1160. * @arg @ref LL_ADC_RESOLUTION_12B
  1161. * @arg @ref LL_ADC_RESOLUTION_10B
  1162. * @arg @ref LL_ADC_RESOLUTION_8B
  1163. * @arg @ref LL_ADC_RESOLUTION_6B
  1164. * @param __AWD_THRESHOLD__ Value between Min_Data=0x000 and Max_Data=0xFFF
  1165. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1166. */
  1167. #define __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION(__ADC_RESOLUTION__, __AWD_THRESHOLD__) \
  1168. ((__AWD_THRESHOLD__) << ((__ADC_RESOLUTION__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U )))
  1169. /**
  1170. * @brief Helper macro to get the value of ADC analog watchdog threshold high
  1171. * or low in function of ADC resolution, when ADC resolution is
  1172. * different of 12 bits.
  1173. * @note To be used with function @ref LL_ADC_GetAnalogWDThresholds().
  1174. * Example, with a ADC resolution of 8 bits, to get the value of
  1175. * analog watchdog threshold high (on 8 bits):
  1176. * < threshold_value_6_bits > = __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION
  1177. * (LL_ADC_RESOLUTION_8B,
  1178. * LL_ADC_GetAnalogWDThresholds(<ADCx param>, LL_ADC_AWD_THRESHOLD_HIGH)
  1179. * );
  1180. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1181. * @arg @ref LL_ADC_RESOLUTION_12B
  1182. * @arg @ref LL_ADC_RESOLUTION_10B
  1183. * @arg @ref LL_ADC_RESOLUTION_8B
  1184. * @arg @ref LL_ADC_RESOLUTION_6B
  1185. * @param __AWD_THRESHOLD_12_BITS__ Value between Min_Data=0x000 and Max_Data=0xFFF
  1186. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1187. */
  1188. #define __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION(__ADC_RESOLUTION__, __AWD_THRESHOLD_12_BITS__) \
  1189. ((__AWD_THRESHOLD_12_BITS__) >> ((__ADC_RESOLUTION__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U )))
  1190. /**
  1191. * @brief Helper macro to get the ADC analog watchdog threshold high
  1192. * or low from raw value containing both thresholds concatenated.
  1193. * @note To be used with function @ref LL_ADC_GetAnalogWDThresholds().
  1194. * Example, to get analog watchdog threshold high from the register raw value:
  1195. * __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW(LL_ADC_AWD_THRESHOLD_HIGH, <raw_value_with_both_thresholds>);
  1196. * @param __AWD_THRESHOLD_TYPE__ This parameter can be one of the following values:
  1197. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  1198. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  1199. * @param __AWD_THRESHOLDS__ Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  1200. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1201. */
  1202. #define __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW(__AWD_THRESHOLD_TYPE__, __AWD_THRESHOLDS__) \
  1203. (((__AWD_THRESHOLD_TYPE__) == LL_ADC_AWD_THRESHOLD_LOW) \
  1204. ? ( \
  1205. (__AWD_THRESHOLDS__) & LL_ADC_AWD_THRESHOLD_LOW \
  1206. ) \
  1207. : \
  1208. ( \
  1209. ((__AWD_THRESHOLDS__) >> ADC_TR_HT_BITOFFSET_POS) & LL_ADC_AWD_THRESHOLD_LOW \
  1210. ) \
  1211. )
  1212. /**
  1213. * @brief Helper macro to select the ADC common instance
  1214. * to which is belonging the selected ADC instance.
  1215. * @note ADC common register instance can be used for:
  1216. * - Set parameters common to several ADC instances
  1217. * - Multimode (for devices with several ADC instances)
  1218. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1219. * @param __ADCx__ ADC instance
  1220. * @retval ADC common register instance
  1221. */
  1222. #define __LL_ADC_COMMON_INSTANCE(__ADCx__) \
  1223. (ADC1_COMMON)
  1224. /**
  1225. * @brief Helper macro to check if all ADC instances sharing the same
  1226. * ADC common instance are disabled.
  1227. * @note This check is required by functions with setting conditioned to
  1228. * ADC state:
  1229. * All ADC instances of the ADC common group must be disabled.
  1230. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1231. * @note On devices with only 1 ADC common instance, parameter of this macro
  1232. * is useless and can be ignored (parameter kept for compatibility
  1233. * with devices featuring several ADC common instances).
  1234. * @param __ADCXY_COMMON__ ADC common instance
  1235. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1236. * @retval Value "0" if all ADC instances sharing the same ADC common instance
  1237. * are disabled.
  1238. * Value "1" if at least one ADC instance sharing the same ADC common instance
  1239. * is enabled.
  1240. */
  1241. #define __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__ADCXY_COMMON__) \
  1242. LL_ADC_IsEnabled(ADC1)
  1243. /**
  1244. * @brief Helper macro to define the ADC conversion data full-scale digital
  1245. * value corresponding to the selected ADC resolution.
  1246. * @note ADC conversion data full-scale corresponds to voltage range
  1247. * determined by analog voltage references Vref+ and Vref-
  1248. * (refer to reference manual).
  1249. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1250. * @arg @ref LL_ADC_RESOLUTION_12B
  1251. * @arg @ref LL_ADC_RESOLUTION_10B
  1252. * @arg @ref LL_ADC_RESOLUTION_8B
  1253. * @arg @ref LL_ADC_RESOLUTION_6B
  1254. * @retval ADC conversion data equivalent voltage value (unit: mVolt)
  1255. */
  1256. #define __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \
  1257. ((0xFFFU) >> ((__ADC_RESOLUTION__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U)))
  1258. /**
  1259. * @brief Helper macro to convert the ADC conversion data from
  1260. * a resolution to another resolution.
  1261. * @param __DATA__ ADC conversion data to be converted
  1262. * @param __ADC_RESOLUTION_CURRENT__ Resolution of to the data to be converted
  1263. * This parameter can be one of the following values:
  1264. * @arg @ref LL_ADC_RESOLUTION_12B
  1265. * @arg @ref LL_ADC_RESOLUTION_10B
  1266. * @arg @ref LL_ADC_RESOLUTION_8B
  1267. * @arg @ref LL_ADC_RESOLUTION_6B
  1268. * @param __ADC_RESOLUTION_TARGET__ Resolution of the data after conversion
  1269. * This parameter can be one of the following values:
  1270. * @arg @ref LL_ADC_RESOLUTION_12B
  1271. * @arg @ref LL_ADC_RESOLUTION_10B
  1272. * @arg @ref LL_ADC_RESOLUTION_8B
  1273. * @arg @ref LL_ADC_RESOLUTION_6B
  1274. * @retval ADC conversion data to the requested resolution
  1275. */
  1276. #define __LL_ADC_CONVERT_DATA_RESOLUTION(__DATA__, __ADC_RESOLUTION_CURRENT__, __ADC_RESOLUTION_TARGET__) \
  1277. (((__DATA__) \
  1278. << ((__ADC_RESOLUTION_CURRENT__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U))) \
  1279. >> ((__ADC_RESOLUTION_TARGET__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U)) \
  1280. )
  1281. /**
  1282. * @brief Helper macro to calculate the voltage (unit: mVolt)
  1283. * corresponding to a ADC conversion data (unit: digital value).
  1284. * @note Analog reference voltage (Vref+) must be either known from
  1285. * user board environment or can be calculated using ADC measurement
  1286. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1287. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1288. * @param __ADC_DATA__ ADC conversion data (resolution 12 bits)
  1289. * (unit: digital value).
  1290. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1291. * @arg @ref LL_ADC_RESOLUTION_12B
  1292. * @arg @ref LL_ADC_RESOLUTION_10B
  1293. * @arg @ref LL_ADC_RESOLUTION_8B
  1294. * @arg @ref LL_ADC_RESOLUTION_6B
  1295. * @retval ADC conversion data equivalent voltage value (unit: mVolt)
  1296. */
  1297. #define __LL_ADC_CALC_DATA_TO_VOLTAGE(__VREFANALOG_VOLTAGE__,\
  1298. __ADC_DATA__,\
  1299. __ADC_RESOLUTION__) \
  1300. ((__ADC_DATA__) * (__VREFANALOG_VOLTAGE__) \
  1301. / __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \
  1302. )
  1303. /**
  1304. * @brief Helper macro to calculate analog reference voltage (Vref+)
  1305. * (unit: mVolt) from ADC conversion data of internal voltage
  1306. * reference VrefInt.
  1307. * @note Computation is using VrefInt calibration value
  1308. * stored in system memory for each device during production.
  1309. * @note This voltage depends on user board environment: voltage level
  1310. * connected to pin Vref+.
  1311. * On devices with small package, the pin Vref+ is not present
  1312. * and internally bonded to pin Vdda.
  1313. * @note On this STM32 series, calibration data of internal voltage reference
  1314. * VrefInt corresponds to a resolution of 12 bits,
  1315. * this is the recommended ADC resolution to convert voltage of
  1316. * internal voltage reference VrefInt.
  1317. * Otherwise, this macro performs the processing to scale
  1318. * ADC conversion data to 12 bits.
  1319. * @param __VREFINT_ADC_DATA__ ADC conversion data (resolution 12 bits)
  1320. * of internal voltage reference VrefInt (unit: digital value).
  1321. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1322. * @arg @ref LL_ADC_RESOLUTION_12B
  1323. * @arg @ref LL_ADC_RESOLUTION_10B
  1324. * @arg @ref LL_ADC_RESOLUTION_8B
  1325. * @arg @ref LL_ADC_RESOLUTION_6B
  1326. * @retval Analog reference voltage (unit: mV)
  1327. */
  1328. #define __LL_ADC_CALC_VREFANALOG_VOLTAGE(__VREFINT_ADC_DATA__,\
  1329. __ADC_RESOLUTION__) \
  1330. (((uint32_t)(*VREFINT_CAL_ADDR) * VREFINT_CAL_VREF) \
  1331. / __LL_ADC_CONVERT_DATA_RESOLUTION((__VREFINT_ADC_DATA__), \
  1332. (__ADC_RESOLUTION__), \
  1333. LL_ADC_RESOLUTION_12B) \
  1334. )
  1335. /* Note: On device STM32L011, calibration parameter TS_CAL1 is not available. */
  1336. /* Therefore, helper macro __LL_ADC_CALC_TEMPERATURE() is not available.*/
  1337. /* Use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(). */
  1338. /* Note: On device STM32L010xx, temperature sensor is not available. */
  1339. /* Therefore, helper macro related to temperature sensor are */
  1340. /* not available. */
  1341. #if !defined(STM32L011xx) && !defined(STM32L010xB) && !defined(STM32L010x8) && !defined(STM32L010x6) && !defined(STM32L010x4)
  1342. /**
  1343. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1344. * from ADC conversion data of internal temperature sensor.
  1345. * @note Computation is using temperature sensor calibration values
  1346. * stored in system memory for each device during production.
  1347. * @note Calculation formula:
  1348. * Temperature = ((TS_ADC_DATA - TS_CAL1)
  1349. * * (TS_CAL2_TEMP - TS_CAL1_TEMP))
  1350. * / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP
  1351. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1352. * Avg_Slope = (TS_CAL2 - TS_CAL1)
  1353. * / (TS_CAL2_TEMP - TS_CAL1_TEMP)
  1354. * TS_CAL1 = equivalent TS_ADC_DATA at temperature
  1355. * TEMP_DEGC_CAL1 (calibrated in factory)
  1356. * TS_CAL2 = equivalent TS_ADC_DATA at temperature
  1357. * TEMP_DEGC_CAL2 (calibrated in factory)
  1358. * Caution: Calculation relevancy under reserve that calibration
  1359. * parameters are correct (address and data).
  1360. * To calculate temperature using temperature sensor
  1361. * datasheet typical values (generic values less, therefore
  1362. * less accurate than calibrated values),
  1363. * use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS().
  1364. * @note As calculation input, the analog reference voltage (Vref+) must be
  1365. * defined as it impacts the ADC LSB equivalent voltage.
  1366. * @note Analog reference voltage (Vref+) must be either known from
  1367. * user board environment or can be calculated using ADC measurement
  1368. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1369. * @note On this STM32 series, calibration data of temperature sensor
  1370. * corresponds to a resolution of 12 bits,
  1371. * this is the recommended ADC resolution to convert voltage of
  1372. * temperature sensor.
  1373. * Otherwise, this macro performs the processing to scale
  1374. * ADC conversion data to 12 bits.
  1375. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1376. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal
  1377. * temperature sensor (unit: digital value).
  1378. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature
  1379. * sensor voltage has been measured.
  1380. * This parameter can be one of the following values:
  1381. * @arg @ref LL_ADC_RESOLUTION_12B
  1382. * @arg @ref LL_ADC_RESOLUTION_10B
  1383. * @arg @ref LL_ADC_RESOLUTION_8B
  1384. * @arg @ref LL_ADC_RESOLUTION_6B
  1385. * @retval Temperature (unit: degree Celsius)
  1386. */
  1387. #define __LL_ADC_CALC_TEMPERATURE(__VREFANALOG_VOLTAGE__,\
  1388. __TEMPSENSOR_ADC_DATA__,\
  1389. __ADC_RESOLUTION__) \
  1390. (((( ((int32_t)((__LL_ADC_CONVERT_DATA_RESOLUTION((__TEMPSENSOR_ADC_DATA__), \
  1391. (__ADC_RESOLUTION__), \
  1392. LL_ADC_RESOLUTION_12B) \
  1393. * (__VREFANALOG_VOLTAGE__)) \
  1394. / TEMPSENSOR_CAL_VREFANALOG) \
  1395. - (int32_t) *TEMPSENSOR_CAL1_ADDR) \
  1396. ) * (int32_t)(TEMPSENSOR_CAL2_TEMP - TEMPSENSOR_CAL1_TEMP) \
  1397. ) / (int32_t)((int32_t)*TEMPSENSOR_CAL2_ADDR - (int32_t)*TEMPSENSOR_CAL1_ADDR) \
  1398. ) + TEMPSENSOR_CAL1_TEMP \
  1399. )
  1400. #endif
  1401. /* Note: On device STM32L010xx, temperature sensor is not available. */
  1402. /* Therefore, helper macro related to temperature sensor are */
  1403. /* not available. */
  1404. #if !defined(STM32L010xB) && !defined(STM32L010x8) && !defined(STM32L010x6) && !defined(STM32L010x4)
  1405. /**
  1406. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1407. * from ADC conversion data of internal temperature sensor.
  1408. * @note Computation is using temperature sensor typical values
  1409. * (refer to device datasheet).
  1410. * @note Calculation formula:
  1411. * Temperature = (TS_TYP_CALx_VOLT(uV) - TS_ADC_DATA * Conversion_uV)
  1412. * / Avg_Slope + CALx_TEMP
  1413. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1414. * (unit: digital value)
  1415. * Avg_Slope = temperature sensor slope
  1416. * (unit: uV/Degree Celsius)
  1417. * TS_TYP_CALx_VOLT = temperature sensor digital value at
  1418. * temperature CALx_TEMP (unit: mV)
  1419. * Caution: Calculation relevancy under reserve the temperature sensor
  1420. * of the current device has characteristics in line with
  1421. * datasheet typical values.
  1422. * If temperature sensor calibration values are available on
  1423. * on this device (presence of macro __LL_ADC_CALC_TEMPERATURE()),
  1424. * temperature calculation will be more accurate using
  1425. * helper macro @ref __LL_ADC_CALC_TEMPERATURE().
  1426. * @note As calculation input, the analog reference voltage (Vref+) must be
  1427. * defined as it impacts the ADC LSB equivalent voltage.
  1428. * @note Analog reference voltage (Vref+) must be either known from
  1429. * user board environment or can be calculated using ADC measurement
  1430. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1431. * @note ADC measurement data must correspond to a resolution of 12bits
  1432. * (full scale digital value 4095). If not the case, the data must be
  1433. * preliminarily rescaled to an equivalent resolution of 12 bits.
  1434. * @param __TEMPSENSOR_TYP_AVGSLOPE__ Device datasheet data: Temperature sensor slope typical value (unit: uV/DegCelsius).
  1435. * On STM32L0, refer to device datasheet parameter "Avg_Slope".
  1436. * @param __TEMPSENSOR_TYP_CALX_V__ Device datasheet data: Temperature sensor voltage typical value (at temperature and Vref+ defined in parameters below) (unit: mV).
  1437. * On STM32L0, refer to device datasheet parameter "V130" (corresponding to TS_CAL2).
  1438. * @param __TEMPSENSOR_CALX_TEMP__ Device datasheet data: Temperature at which temperature sensor voltage (see parameter above) is corresponding (unit: mV)
  1439. * @param __VREFANALOG_VOLTAGE__ Analog voltage reference (Vref+) voltage (unit: mV)
  1440. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal temperature sensor (unit: digital value).
  1441. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature sensor voltage has been measured.
  1442. * This parameter can be one of the following values:
  1443. * @arg @ref LL_ADC_RESOLUTION_12B
  1444. * @arg @ref LL_ADC_RESOLUTION_10B
  1445. * @arg @ref LL_ADC_RESOLUTION_8B
  1446. * @arg @ref LL_ADC_RESOLUTION_6B
  1447. * @retval Temperature (unit: degree Celsius)
  1448. */
  1449. #define __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(__TEMPSENSOR_TYP_AVGSLOPE__,\
  1450. __TEMPSENSOR_TYP_CALX_V__,\
  1451. __TEMPSENSOR_CALX_TEMP__,\
  1452. __VREFANALOG_VOLTAGE__,\
  1453. __TEMPSENSOR_ADC_DATA__,\
  1454. __ADC_RESOLUTION__) \
  1455. ((( ( \
  1456. (int32_t)((((__TEMPSENSOR_ADC_DATA__) * (__VREFANALOG_VOLTAGE__)) \
  1457. / __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__)) \
  1458. * 1000) \
  1459. - \
  1460. (int32_t)(((__TEMPSENSOR_TYP_CALX_V__)) \
  1461. * 1000) \
  1462. ) \
  1463. ) / (__TEMPSENSOR_TYP_AVGSLOPE__) \
  1464. ) + (__TEMPSENSOR_CALX_TEMP__) \
  1465. )
  1466. #endif
  1467. /**
  1468. * @}
  1469. */
  1470. /**
  1471. * @}
  1472. */
  1473. /* Exported functions --------------------------------------------------------*/
  1474. /** @defgroup ADC_LL_Exported_Functions ADC Exported Functions
  1475. * @{
  1476. */
  1477. /** @defgroup ADC_LL_EF_DMA_Management ADC DMA management
  1478. * @{
  1479. */
  1480. /* Note: LL ADC functions to set DMA transfer are located into sections of */
  1481. /* configuration of ADC instance, groups and multimode (if available): */
  1482. /* @ref LL_ADC_REG_SetDMATransfer(), ... */
  1483. /**
  1484. * @brief Function to help to configure DMA transfer from ADC: retrieve the
  1485. * ADC register address from ADC instance and a list of ADC registers
  1486. * intended to be used (most commonly) with DMA transfer.
  1487. * @note These ADC registers are data registers:
  1488. * when ADC conversion data is available in ADC data registers,
  1489. * ADC generates a DMA transfer request.
  1490. * @note This macro is intended to be used with LL DMA driver, refer to
  1491. * function "LL_DMA_ConfigAddresses()".
  1492. * Example:
  1493. * LL_DMA_ConfigAddresses(DMA1,
  1494. * LL_DMA_CHANNEL_1,
  1495. * LL_ADC_DMA_GetRegAddr(ADC1, LL_ADC_DMA_REG_REGULAR_DATA),
  1496. * (uint32_t)&< array or variable >,
  1497. * LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
  1498. * @note For devices with several ADC: in multimode, some devices
  1499. * use a different data register outside of ADC instance scope
  1500. * (common data register). This macro manages this register difference,
  1501. * only ADC instance has to be set as parameter.
  1502. * @rmtoll DR DATA LL_ADC_DMA_GetRegAddr
  1503. * @param ADCx ADC instance
  1504. * @param Register This parameter can be one of the following values:
  1505. * @arg @ref LL_ADC_DMA_REG_REGULAR_DATA
  1506. * @retval ADC register address
  1507. */
  1508. __STATIC_INLINE uint32_t LL_ADC_DMA_GetRegAddr(ADC_TypeDef *ADCx, uint32_t Register)
  1509. {
  1510. /* Prevent unused argument compilation warning */
  1511. (void)Register;
  1512. /* Retrieve address of register DR */
  1513. return (uint32_t) & (ADCx->DR);
  1514. }
  1515. /**
  1516. * @}
  1517. */
  1518. /** @defgroup ADC_LL_EF_Configuration_ADC_Common Configuration of ADC hierarchical scope: common to several ADC instances
  1519. * @{
  1520. */
  1521. /**
  1522. * @brief Set parameter common to several ADC: Clock source and prescaler.
  1523. * @note On this STM32 series, setting of this feature is conditioned to
  1524. * ADC state:
  1525. * All ADC instances of the ADC common group must be disabled.
  1526. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1527. * ADC instance or by using helper macro helper macro
  1528. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  1529. * @rmtoll CCR PRESC LL_ADC_SetCommonClock
  1530. * @param ADCxy_COMMON ADC common instance
  1531. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1532. * @param CommonClock This parameter can be one of the following values:
  1533. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV1 (1)
  1534. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV2 (1)
  1535. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV4 (1)
  1536. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV6 (1)
  1537. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV8 (1)
  1538. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV10 (1)
  1539. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV12 (1)
  1540. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV16 (1)
  1541. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV32 (1)
  1542. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV64 (1)
  1543. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV128 (1)
  1544. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV256 (1)
  1545. *
  1546. * (1) ADC common clock asynchronous prescaler is applied to
  1547. * each ADC instance if the corresponding ADC instance clock
  1548. * is set to clock source asynchronous.
  1549. * (refer to function @ref LL_ADC_SetClock() ).
  1550. * @retval None
  1551. */
  1552. __STATIC_INLINE void LL_ADC_SetCommonClock(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t CommonClock)
  1553. {
  1554. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_PRESC, CommonClock);
  1555. }
  1556. /**
  1557. * @brief Get parameter common to several ADC: Clock source and prescaler.
  1558. * @rmtoll CCR PRESC LL_ADC_GetCommonClock
  1559. * @param ADCxy_COMMON ADC common instance
  1560. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1561. * @retval Returned value can be one of the following values:
  1562. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV1 (1)
  1563. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV2 (1)
  1564. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV4 (1)
  1565. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV6 (1)
  1566. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV8 (1)
  1567. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV10 (1)
  1568. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV12 (1)
  1569. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV16 (1)
  1570. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV32 (1)
  1571. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV64 (1)
  1572. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV128 (1)
  1573. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV256 (1)
  1574. *
  1575. * (1) ADC common clock asynchronous prescaler is applied to
  1576. * each ADC instance if the corresponding ADC instance clock
  1577. * is set to clock source asynchronous.
  1578. * (refer to function @ref LL_ADC_SetClock() ).
  1579. */
  1580. __STATIC_INLINE uint32_t LL_ADC_GetCommonClock(ADC_Common_TypeDef *ADCxy_COMMON)
  1581. {
  1582. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_PRESC));
  1583. }
  1584. /**
  1585. * @brief Set parameter common to several ADC: Clock low frequency mode.
  1586. * Refer to reference manual for alignments formats
  1587. * dependencies to ADC resolutions.
  1588. * @note On this STM32 series, setting of this feature is conditioned to
  1589. * ADC state:
  1590. * ADC must be disabled or enabled without conversion on going
  1591. * on group regular.
  1592. * @rmtoll CCR LFMEN LL_ADC_SetCommonFrequencyMode
  1593. * @param ADCxy_COMMON ADC common instance
  1594. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1595. * @param CommonFrequencyMode This parameter can be one of the following values:
  1596. * @arg @ref LL_ADC_CLOCK_FREQ_MODE_HIGH
  1597. * @arg @ref LL_ADC_CLOCK_FREQ_MODE_LOW
  1598. * @retval None
  1599. */
  1600. __STATIC_INLINE void LL_ADC_SetCommonFrequencyMode(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t CommonFrequencyMode)
  1601. {
  1602. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_LFMEN, CommonFrequencyMode);
  1603. }
  1604. /**
  1605. * @brief Get parameter common to several ADC: Clock low frequency mode.
  1606. * Refer to reference manual for alignments formats
  1607. * dependencies to ADC resolutions.
  1608. * @rmtoll CCR LFMEN LL_ADC_GetCommonFrequencyMode
  1609. * @param ADCxy_COMMON ADC common instance
  1610. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1611. * @retval Returned value can be one of the following values:
  1612. * @arg @ref LL_ADC_CLOCK_FREQ_MODE_HIGH
  1613. * @arg @ref LL_ADC_CLOCK_FREQ_MODE_LOW
  1614. */
  1615. __STATIC_INLINE uint32_t LL_ADC_GetCommonFrequencyMode(ADC_Common_TypeDef *ADCxy_COMMON)
  1616. {
  1617. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_LFMEN));
  1618. }
  1619. /**
  1620. * @brief Set parameter common to several ADC: measurement path to internal
  1621. * channels (VrefInt, temperature sensor, ...).
  1622. * @note One or several values can be selected.
  1623. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1624. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1625. * @note Stabilization time of measurement path to internal channel:
  1626. * After enabling internal paths, before starting ADC conversion,
  1627. * a delay is required for internal voltage reference and
  1628. * temperature sensor stabilization time.
  1629. * Refer to device datasheet.
  1630. * Refer to literal @ref LL_ADC_DELAY_VREFINT_STAB_US.
  1631. * Refer to literal @ref LL_ADC_DELAY_TEMPSENSOR_STAB_US.
  1632. * @note ADC internal channel sampling time constraint:
  1633. * For ADC conversion of internal channels,
  1634. * a sampling time minimum value is required.
  1635. * Refer to device datasheet.
  1636. * @note On this STM32 series, setting of this feature is conditioned to
  1637. * ADC state:
  1638. * All ADC instances of the ADC common group must be disabled.
  1639. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1640. * ADC instance or by using helper macro helper macro
  1641. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  1642. * @rmtoll CCR VREFEN LL_ADC_SetCommonPathInternalCh\n
  1643. * CCR TSEN LL_ADC_SetCommonPathInternalCh\n
  1644. * CCR VLCDEN LL_ADC_SetCommonPathInternalCh
  1645. * @param ADCxy_COMMON ADC common instance
  1646. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1647. * @param PathInternal This parameter can be a combination of the following values:
  1648. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  1649. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  1650. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR (2)
  1651. * @arg @ref LL_ADC_PATH_INTERNAL_VLCD (1)
  1652. *
  1653. * (1) value not defined in all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  1654. * (2) value not defined in all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx, STM32L04xxx, STM32L03xxx, STM32L02xxx.
  1655. * @retval None
  1656. */
  1657. __STATIC_INLINE void LL_ADC_SetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t PathInternal)
  1658. {
  1659. #if defined (ADC_CCR_VLCDEN) && defined (ADC_CCR_TSEN)
  1660. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN | ADC_CCR_VLCDEN, PathInternal);
  1661. #elif defined (ADC_CCR_TSEN)
  1662. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN, PathInternal);
  1663. #else
  1664. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_VREFEN, PathInternal);
  1665. #endif
  1666. }
  1667. /**
  1668. * @brief Get parameter common to several ADC: measurement path to internal
  1669. * channels (VrefInt, temperature sensor, ...).
  1670. * @note One or several values can be selected.
  1671. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1672. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1673. * @rmtoll CCR VREFEN LL_ADC_GetCommonPathInternalCh\n
  1674. * CCR TSEN LL_ADC_GetCommonPathInternalCh\n
  1675. * CCR VLCDEN LL_ADC_GetCommonPathInternalCh
  1676. * @param ADCxy_COMMON ADC common instance
  1677. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1678. * @retval Returned value can be a combination of the following values:
  1679. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  1680. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  1681. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR (2)
  1682. * @arg @ref LL_ADC_PATH_INTERNAL_VLCD (1)
  1683. *
  1684. * (1) value not defined in all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  1685. * (2) value not defined in all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx, STM32L04xxx, STM32L03xxx, STM32L02xxx.
  1686. */
  1687. __STATIC_INLINE uint32_t LL_ADC_GetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON)
  1688. {
  1689. #if defined (ADC_CCR_VLCDEN) && defined (ADC_CCR_TSEN)
  1690. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN | ADC_CCR_VLCDEN));
  1691. #elif defined (ADC_CCR_TSEN)
  1692. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN));
  1693. #else
  1694. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_VREFEN));
  1695. #endif
  1696. }
  1697. /**
  1698. * @}
  1699. */
  1700. /** @defgroup ADC_LL_EF_Configuration_ADC_Instance Configuration of ADC hierarchical scope: ADC instance
  1701. * @{
  1702. */
  1703. /**
  1704. * @brief Set ADC instance clock source and prescaler.
  1705. * @note On this STM32 series, setting of this feature is conditioned to
  1706. * ADC state:
  1707. * ADC must be disabled.
  1708. * @rmtoll CFGR2 CKMODE LL_ADC_SetClock
  1709. * @param ADCx ADC instance
  1710. * @param ClockSource This parameter can be one of the following values:
  1711. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV4
  1712. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV2
  1713. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV1 (2)
  1714. * @arg @ref LL_ADC_CLOCK_ASYNC (1)
  1715. *
  1716. * (1) Asynchronous clock prescaler can be configured using
  1717. * function @ref LL_ADC_SetCommonClock().\n
  1718. * (2) Caution: This parameter has some clock ratio constraints:
  1719. * This configuration must be enabled only if PCLK has a 50%
  1720. * duty clock cycle (APB prescaler configured inside the RCC
  1721. * must be bypassed and the system clock must by 50% duty
  1722. * cycle).
  1723. * Refer to reference manual.
  1724. * @retval None
  1725. */
  1726. __STATIC_INLINE void LL_ADC_SetClock(ADC_TypeDef *ADCx, uint32_t ClockSource)
  1727. {
  1728. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_CKMODE, ClockSource);
  1729. }
  1730. /**
  1731. * @brief Get ADC instance clock source and prescaler.
  1732. * @rmtoll CFGR2 CKMODE LL_ADC_GetClock
  1733. * @param ADCx ADC instance
  1734. * @retval Returned value can be one of the following values:
  1735. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV4
  1736. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV2
  1737. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV1 (2)
  1738. * @arg @ref LL_ADC_CLOCK_ASYNC (1)
  1739. *
  1740. * (1) Asynchronous clock prescaler can be retrieved using
  1741. * function @ref LL_ADC_GetCommonClock().\n
  1742. * (2) Caution: This parameter has some clock ratio constraints:
  1743. * This configuration must be enabled only if PCLK has a 50%
  1744. * duty clock cycle (APB prescaler configured inside the RCC
  1745. * must be bypassed and the system clock must by 50% duty
  1746. * cycle).
  1747. * Refer to reference manual.
  1748. */
  1749. __STATIC_INLINE uint32_t LL_ADC_GetClock(ADC_TypeDef *ADCx)
  1750. {
  1751. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_CKMODE));
  1752. }
  1753. /**
  1754. * @brief Set ADC calibration factor in the mode single-ended
  1755. * or differential (for devices with differential mode available).
  1756. * @note This function is intended to set calibration parameters
  1757. * without having to perform a new calibration using
  1758. * @ref LL_ADC_StartCalibration().
  1759. * @note On this STM32 series, setting of this feature is conditioned to
  1760. * ADC state:
  1761. * ADC must be enabled, without calibration on going, without conversion
  1762. * on going on group regular.
  1763. * @rmtoll CALFACT CALFACT LL_ADC_SetCalibrationFactor
  1764. * @param ADCx ADC instance
  1765. * @param CalibrationFactor Value between Min_Data=0x00 and Max_Data=0x7F
  1766. * @retval None
  1767. */
  1768. __STATIC_INLINE void LL_ADC_SetCalibrationFactor(ADC_TypeDef *ADCx, uint32_t CalibrationFactor)
  1769. {
  1770. MODIFY_REG(ADCx->CALFACT,
  1771. ADC_CALFACT_CALFACT,
  1772. CalibrationFactor);
  1773. }
  1774. /**
  1775. * @brief Get ADC calibration factor in the mode single-ended
  1776. * or differential (for devices with differential mode available).
  1777. * @note Calibration factors are set by hardware after performing
  1778. * a calibration run using function @ref LL_ADC_StartCalibration().
  1779. * @rmtoll CALFACT CALFACT LL_ADC_GetCalibrationFactor
  1780. * @param ADCx ADC instance
  1781. * @retval Value between Min_Data=0x00 and Max_Data=0x7F
  1782. */
  1783. __STATIC_INLINE uint32_t LL_ADC_GetCalibrationFactor(ADC_TypeDef *ADCx)
  1784. {
  1785. return (uint32_t)(READ_BIT(ADCx->CALFACT, ADC_CALFACT_CALFACT));
  1786. }
  1787. /**
  1788. * @brief Set ADC resolution.
  1789. * Refer to reference manual for alignments formats
  1790. * dependencies to ADC resolutions.
  1791. * @note On this STM32 series, setting of this feature is conditioned to
  1792. * ADC state:
  1793. * ADC must be disabled or enabled without conversion on going
  1794. * on group regular.
  1795. * @rmtoll CFGR1 RES LL_ADC_SetResolution
  1796. * @param ADCx ADC instance
  1797. * @param Resolution This parameter can be one of the following values:
  1798. * @arg @ref LL_ADC_RESOLUTION_12B
  1799. * @arg @ref LL_ADC_RESOLUTION_10B
  1800. * @arg @ref LL_ADC_RESOLUTION_8B
  1801. * @arg @ref LL_ADC_RESOLUTION_6B
  1802. * @retval None
  1803. */
  1804. __STATIC_INLINE void LL_ADC_SetResolution(ADC_TypeDef *ADCx, uint32_t Resolution)
  1805. {
  1806. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_RES, Resolution);
  1807. }
  1808. /**
  1809. * @brief Get ADC resolution.
  1810. * Refer to reference manual for alignments formats
  1811. * dependencies to ADC resolutions.
  1812. * @rmtoll CFGR1 RES LL_ADC_GetResolution
  1813. * @param ADCx ADC instance
  1814. * @retval Returned value can be one of the following values:
  1815. * @arg @ref LL_ADC_RESOLUTION_12B
  1816. * @arg @ref LL_ADC_RESOLUTION_10B
  1817. * @arg @ref LL_ADC_RESOLUTION_8B
  1818. * @arg @ref LL_ADC_RESOLUTION_6B
  1819. */
  1820. __STATIC_INLINE uint32_t LL_ADC_GetResolution(ADC_TypeDef *ADCx)
  1821. {
  1822. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_RES));
  1823. }
  1824. /**
  1825. * @brief Set ADC conversion data alignment.
  1826. * @note Refer to reference manual for alignments formats
  1827. * dependencies to ADC resolutions.
  1828. * @note On this STM32 series, setting of this feature is conditioned to
  1829. * ADC state:
  1830. * ADC must be disabled or enabled without conversion on going
  1831. * on group regular.
  1832. * @rmtoll CFGR1 ALIGN LL_ADC_SetDataAlignment
  1833. * @param ADCx ADC instance
  1834. * @param DataAlignment This parameter can be one of the following values:
  1835. * @arg @ref LL_ADC_DATA_ALIGN_RIGHT
  1836. * @arg @ref LL_ADC_DATA_ALIGN_LEFT
  1837. * @retval None
  1838. */
  1839. __STATIC_INLINE void LL_ADC_SetDataAlignment(ADC_TypeDef *ADCx, uint32_t DataAlignment)
  1840. {
  1841. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_ALIGN, DataAlignment);
  1842. }
  1843. /**
  1844. * @brief Get ADC conversion data alignment.
  1845. * @note Refer to reference manual for alignments formats
  1846. * dependencies to ADC resolutions.
  1847. * @rmtoll CFGR1 ALIGN LL_ADC_GetDataAlignment
  1848. * @param ADCx ADC instance
  1849. * @retval Returned value can be one of the following values:
  1850. * @arg @ref LL_ADC_DATA_ALIGN_RIGHT
  1851. * @arg @ref LL_ADC_DATA_ALIGN_LEFT
  1852. */
  1853. __STATIC_INLINE uint32_t LL_ADC_GetDataAlignment(ADC_TypeDef *ADCx)
  1854. {
  1855. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_ALIGN));
  1856. }
  1857. /**
  1858. * @brief Set ADC low power mode.
  1859. * @note Description of ADC low power modes:
  1860. * - ADC low power mode "auto wait": Dynamic low power mode,
  1861. * ADC conversions occurrences are limited to the minimum necessary
  1862. * in order to reduce power consumption.
  1863. * New ADC conversion starts only when the previous
  1864. * unitary conversion data (for ADC group regular)
  1865. * has been retrieved by user software.
  1866. * In the meantime, ADC remains idle: does not performs any
  1867. * other conversion.
  1868. * This mode allows to automatically adapt the ADC conversions
  1869. * triggers to the speed of the software that reads the data.
  1870. * Moreover, this avoids risk of overrun for low frequency
  1871. * applications.
  1872. * How to use this low power mode:
  1873. * - Do not use with interruption or DMA since these modes
  1874. * have to clear immediately the EOC flag to free the
  1875. * IRQ vector sequencer.
  1876. * - Do use with polling: 1. Start conversion,
  1877. * 2. Later on, when conversion data is needed: poll for end of
  1878. * conversion to ensure that conversion is completed and
  1879. * retrieve ADC conversion data. This will trig another
  1880. * ADC conversion start.
  1881. * - ADC low power mode "auto power-off" (feature available on
  1882. * this device if parameter LL_ADC_LP_MODE_AUTOOFF is available):
  1883. * the ADC automatically powers-off after a conversion and
  1884. * automatically wakes up when a new conversion is triggered
  1885. * (with startup time between trigger and start of sampling).
  1886. * This feature can be combined with low power mode "auto wait".
  1887. * @note With ADC low power mode "auto wait", the ADC conversion data read
  1888. * is corresponding to previous ADC conversion start, independently
  1889. * of delay during which ADC was idle.
  1890. * Therefore, the ADC conversion data may be outdated: does not
  1891. * correspond to the current voltage level on the selected
  1892. * ADC channel.
  1893. * @note On this STM32 series, setting of this feature is conditioned to
  1894. * ADC state:
  1895. * ADC must be disabled or enabled without conversion on going
  1896. * on group regular.
  1897. * @rmtoll CFGR1 WAIT LL_ADC_SetLowPowerMode\n
  1898. * CFGR1 AUTOFF LL_ADC_SetLowPowerMode
  1899. * @param ADCx ADC instance
  1900. * @param LowPowerMode This parameter can be one of the following values:
  1901. * @arg @ref LL_ADC_LP_MODE_NONE
  1902. * @arg @ref LL_ADC_LP_AUTOWAIT
  1903. * @arg @ref LL_ADC_LP_AUTOPOWEROFF
  1904. * @arg @ref LL_ADC_LP_AUTOWAIT_AUTOPOWEROFF
  1905. * @retval None
  1906. */
  1907. __STATIC_INLINE void LL_ADC_SetLowPowerMode(ADC_TypeDef *ADCx, uint32_t LowPowerMode)
  1908. {
  1909. MODIFY_REG(ADCx->CFGR1, (ADC_CFGR1_WAIT | ADC_CFGR1_AUTOFF), LowPowerMode);
  1910. }
  1911. /**
  1912. * @brief Get ADC low power mode:
  1913. * @note Description of ADC low power modes:
  1914. * - ADC low power mode "auto wait": Dynamic low power mode,
  1915. * ADC conversions occurrences are limited to the minimum necessary
  1916. * in order to reduce power consumption.
  1917. * New ADC conversion starts only when the previous
  1918. * unitary conversion data (for ADC group regular)
  1919. * has been retrieved by user software.
  1920. * In the meantime, ADC remains idle: does not performs any
  1921. * other conversion.
  1922. * This mode allows to automatically adapt the ADC conversions
  1923. * triggers to the speed of the software that reads the data.
  1924. * Moreover, this avoids risk of overrun for low frequency
  1925. * applications.
  1926. * How to use this low power mode:
  1927. * - Do not use with interruption or DMA since these modes
  1928. * have to clear immediately the EOC flag to free the
  1929. * IRQ vector sequencer.
  1930. * - Do use with polling: 1. Start conversion,
  1931. * 2. Later on, when conversion data is needed: poll for end of
  1932. * conversion to ensure that conversion is completed and
  1933. * retrieve ADC conversion data. This will trig another
  1934. * ADC conversion start.
  1935. * - ADC low power mode "auto power-off" (feature available on
  1936. * this device if parameter LL_ADC_LP_MODE_AUTOOFF is available):
  1937. * the ADC automatically powers-off after a conversion and
  1938. * automatically wakes up when a new conversion is triggered
  1939. * (with startup time between trigger and start of sampling).
  1940. * This feature can be combined with low power mode "auto wait".
  1941. * @note With ADC low power mode "auto wait", the ADC conversion data read
  1942. * is corresponding to previous ADC conversion start, independently
  1943. * of delay during which ADC was idle.
  1944. * Therefore, the ADC conversion data may be outdated: does not
  1945. * correspond to the current voltage level on the selected
  1946. * ADC channel.
  1947. * @rmtoll CFGR1 WAIT LL_ADC_GetLowPowerMode\n
  1948. * CFGR1 AUTOFF LL_ADC_GetLowPowerMode
  1949. * @param ADCx ADC instance
  1950. * @retval Returned value can be one of the following values:
  1951. * @arg @ref LL_ADC_LP_MODE_NONE
  1952. * @arg @ref LL_ADC_LP_AUTOWAIT
  1953. * @arg @ref LL_ADC_LP_AUTOPOWEROFF
  1954. * @arg @ref LL_ADC_LP_AUTOWAIT_AUTOPOWEROFF
  1955. */
  1956. __STATIC_INLINE uint32_t LL_ADC_GetLowPowerMode(ADC_TypeDef *ADCx)
  1957. {
  1958. return (uint32_t)(READ_BIT(ADCx->CFGR1, (ADC_CFGR1_WAIT | ADC_CFGR1_AUTOFF)));
  1959. }
  1960. /**
  1961. * @brief Set sampling time common to a group of channels.
  1962. * @note Unit: ADC clock cycles.
  1963. * @note On this STM32 series, sampling time scope is on ADC instance:
  1964. * Sampling time common to all channels.
  1965. * (on some other STM32 families, sampling time is channel wise)
  1966. * @note In case of internal channel (VrefInt, TempSensor, ...) to be
  1967. * converted:
  1968. * sampling time constraints must be respected (sampling time can be
  1969. * adjusted in function of ADC clock frequency and sampling time
  1970. * setting).
  1971. * Refer to device datasheet for timings values (parameters TS_vrefint,
  1972. * TS_temp, ...).
  1973. * @note Conversion time is the addition of sampling time and processing time.
  1974. * On this STM32 series, ADC processing time is:
  1975. * - 12.5 ADC clock cycles at ADC resolution 12 bits
  1976. * - 10.5 ADC clock cycles at ADC resolution 10 bits
  1977. * - 8.5 ADC clock cycles at ADC resolution 8 bits
  1978. * - 6.5 ADC clock cycles at ADC resolution 6 bits
  1979. * @note In case of ADC conversion of internal channel (VrefInt,
  1980. * temperature sensor, ...), a sampling time minimum value
  1981. * is required.
  1982. * Refer to device datasheet.
  1983. * @note On this STM32 series, setting of this feature is conditioned to
  1984. * ADC state:
  1985. * ADC must be disabled or enabled without conversion on going
  1986. * on group regular.
  1987. * @rmtoll SMPR SMP LL_ADC_SetSamplingTimeCommonChannels
  1988. * @param ADCx ADC instance
  1989. * @param SamplingTime This parameter can be one of the following values:
  1990. * @arg @ref LL_ADC_SAMPLINGTIME_1CYCLE_5
  1991. * @arg @ref LL_ADC_SAMPLINGTIME_3CYCLES_5
  1992. * @arg @ref LL_ADC_SAMPLINGTIME_7CYCLES_5
  1993. * @arg @ref LL_ADC_SAMPLINGTIME_12CYCLES_5
  1994. * @arg @ref LL_ADC_SAMPLINGTIME_19CYCLES_5
  1995. * @arg @ref LL_ADC_SAMPLINGTIME_39CYCLES_5
  1996. * @arg @ref LL_ADC_SAMPLINGTIME_79CYCLES_5
  1997. * @arg @ref LL_ADC_SAMPLINGTIME_160CYCLES_5
  1998. * @retval None
  1999. */
  2000. __STATIC_INLINE void LL_ADC_SetSamplingTimeCommonChannels(ADC_TypeDef *ADCx, uint32_t SamplingTime)
  2001. {
  2002. MODIFY_REG(ADCx->SMPR, ADC_SMPR_SMP, SamplingTime);
  2003. }
  2004. /**
  2005. * @brief Get sampling time common to a group of channels.
  2006. * @note Unit: ADC clock cycles.
  2007. * @note On this STM32 series, sampling time scope is on ADC instance:
  2008. * Sampling time common to all channels.
  2009. * (on some other STM32 families, sampling time is channel wise)
  2010. * @note Conversion time is the addition of sampling time and processing time.
  2011. * Refer to reference manual for ADC processing time of
  2012. * this STM32 series.
  2013. * @rmtoll SMPR SMP LL_ADC_GetSamplingTimeCommonChannels
  2014. * @param ADCx ADC instance
  2015. * @retval Returned value can be one of the following values:
  2016. * @arg @ref LL_ADC_SAMPLINGTIME_1CYCLE_5
  2017. * @arg @ref LL_ADC_SAMPLINGTIME_3CYCLES_5
  2018. * @arg @ref LL_ADC_SAMPLINGTIME_7CYCLES_5
  2019. * @arg @ref LL_ADC_SAMPLINGTIME_12CYCLES_5
  2020. * @arg @ref LL_ADC_SAMPLINGTIME_19CYCLES_5
  2021. * @arg @ref LL_ADC_SAMPLINGTIME_39CYCLES_5
  2022. * @arg @ref LL_ADC_SAMPLINGTIME_79CYCLES_5
  2023. * @arg @ref LL_ADC_SAMPLINGTIME_160CYCLES_5
  2024. */
  2025. __STATIC_INLINE uint32_t LL_ADC_GetSamplingTimeCommonChannels(ADC_TypeDef *ADCx)
  2026. {
  2027. return (uint32_t)(READ_BIT(ADCx->SMPR, ADC_SMPR_SMP));
  2028. }
  2029. /**
  2030. * @}
  2031. */
  2032. /** @defgroup ADC_LL_EF_Configuration_ADC_Group_Regular Configuration of ADC hierarchical scope: group regular
  2033. * @{
  2034. */
  2035. /**
  2036. * @brief Set ADC group regular conversion trigger source:
  2037. * internal (SW start) or from external peripheral (timer event,
  2038. * external interrupt line).
  2039. * @note On this STM32 series, setting trigger source to external trigger
  2040. * also set trigger polarity to rising edge
  2041. * (default setting for compatibility with some ADC on other
  2042. * STM32 families having this setting set by HW default value).
  2043. * In case of need to modify trigger edge, use
  2044. * function @ref LL_ADC_REG_SetTriggerEdge().
  2045. * @note Availability of parameters of trigger sources from timer
  2046. * depends on timers availability on the selected device.
  2047. * @note On this STM32 series, setting of this feature is conditioned to
  2048. * ADC state:
  2049. * ADC must be disabled or enabled without conversion on going
  2050. * on group regular.
  2051. * @rmtoll CFGR1 EXTSEL LL_ADC_REG_SetTriggerSource\n
  2052. * CFGR1 EXTEN LL_ADC_REG_SetTriggerSource
  2053. * @param ADCx ADC instance
  2054. * @param TriggerSource This parameter can be one of the following values:
  2055. * @arg @ref LL_ADC_REG_TRIG_SOFTWARE
  2056. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM6_TRGO
  2057. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM21_CH2
  2058. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_TRGO
  2059. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_CH4
  2060. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM22_TRGO
  2061. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_CH3 (*)
  2062. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM3_TRGO
  2063. * @arg @ref LL_ADC_REG_TRIG_EXT_EXTI_LINE11
  2064. *
  2065. * (*) value not defined in all devices
  2066. * @retval None
  2067. */
  2068. __STATIC_INLINE void LL_ADC_REG_SetTriggerSource(ADC_TypeDef *ADCx, uint32_t TriggerSource)
  2069. {
  2070. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_EXTEN | ADC_CFGR1_EXTSEL, TriggerSource);
  2071. }
  2072. /**
  2073. * @brief Get ADC group regular conversion trigger source:
  2074. * internal (SW start) or from external peripheral (timer event,
  2075. * external interrupt line).
  2076. * @note To determine whether group regular trigger source is
  2077. * internal (SW start) or external, without detail
  2078. * of which peripheral is selected as external trigger,
  2079. * (equivalent to
  2080. * "if(LL_ADC_REG_GetTriggerSource(ADC1) == LL_ADC_REG_TRIG_SOFTWARE)")
  2081. * use function @ref LL_ADC_REG_IsTriggerSourceSWStart.
  2082. * @note Availability of parameters of trigger sources from timer
  2083. * depends on timers availability on the selected device.
  2084. * @rmtoll CFGR1 EXTSEL LL_ADC_REG_GetTriggerSource\n
  2085. * CFGR1 EXTEN LL_ADC_REG_GetTriggerSource
  2086. * @param ADCx ADC instance
  2087. * @retval Returned value can be one of the following values:
  2088. * @arg @ref LL_ADC_REG_TRIG_SOFTWARE
  2089. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM6_TRGO
  2090. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM21_CH2
  2091. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_TRGO
  2092. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_CH4
  2093. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM22_TRGO
  2094. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_CH3 (*)
  2095. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM3_TRGO
  2096. * @arg @ref LL_ADC_REG_TRIG_EXT_EXTI_LINE11
  2097. *
  2098. * (*) value not defined in all devices
  2099. */
  2100. __STATIC_INLINE uint32_t LL_ADC_REG_GetTriggerSource(ADC_TypeDef *ADCx)
  2101. {
  2102. uint32_t TriggerSource = READ_BIT(ADCx->CFGR1, ADC_CFGR1_EXTSEL | ADC_CFGR1_EXTEN);
  2103. /* Value for shift of {0; 4; 8; 12} depending on value of bitfield */
  2104. /* corresponding to ADC_CFGR1_EXTEN {0; 1; 2; 3}. */
  2105. uint32_t ShiftExten = ((TriggerSource & ADC_CFGR1_EXTEN) >> (ADC_REG_TRIG_EXTEN_BITOFFSET_POS - 2U));
  2106. /* Set bitfield corresponding to ADC_CFGR1_EXTEN and ADC_CFGR1_EXTSEL */
  2107. /* to match with triggers literals definition. */
  2108. return ((TriggerSource
  2109. & (ADC_REG_TRIG_SOURCE_MASK >> ShiftExten) & ADC_CFGR1_EXTSEL)
  2110. | ((ADC_REG_TRIG_EDGE_MASK >> ShiftExten) & ADC_CFGR1_EXTEN)
  2111. );
  2112. }
  2113. /**
  2114. * @brief Get ADC group regular conversion trigger source internal (SW start)
  2115. or external.
  2116. * @note In case of group regular trigger source set to external trigger,
  2117. * to determine which peripheral is selected as external trigger,
  2118. * use function @ref LL_ADC_REG_GetTriggerSource().
  2119. * @rmtoll CFGR1 EXTEN LL_ADC_REG_IsTriggerSourceSWStart
  2120. * @param ADCx ADC instance
  2121. * @retval Value "0" if trigger source external trigger
  2122. * Value "1" if trigger source SW start.
  2123. */
  2124. __STATIC_INLINE uint32_t LL_ADC_REG_IsTriggerSourceSWStart(ADC_TypeDef *ADCx)
  2125. {
  2126. return (READ_BIT(ADCx->CFGR1, ADC_CFGR1_EXTEN) == (LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR1_EXTEN));
  2127. }
  2128. /**
  2129. * @brief Set ADC group regular conversion trigger polarity.
  2130. * @note Applicable only for trigger source set to external trigger.
  2131. * @note On this STM32 series, setting of this feature is conditioned to
  2132. * ADC state:
  2133. * ADC must be disabled or enabled without conversion on going
  2134. * on group regular.
  2135. * @rmtoll CFGR1 EXTEN LL_ADC_REG_SetTriggerEdge
  2136. * @param ADCx ADC instance
  2137. * @param ExternalTriggerEdge This parameter can be one of the following values:
  2138. * @arg @ref LL_ADC_REG_TRIG_EXT_RISING
  2139. * @arg @ref LL_ADC_REG_TRIG_EXT_FALLING
  2140. * @arg @ref LL_ADC_REG_TRIG_EXT_RISINGFALLING
  2141. * @retval None
  2142. */
  2143. __STATIC_INLINE void LL_ADC_REG_SetTriggerEdge(ADC_TypeDef *ADCx, uint32_t ExternalTriggerEdge)
  2144. {
  2145. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_EXTEN, ExternalTriggerEdge);
  2146. }
  2147. /**
  2148. * @brief Get ADC group regular conversion trigger polarity.
  2149. * @note Applicable only for trigger source set to external trigger.
  2150. * @rmtoll CFGR1 EXTEN LL_ADC_REG_GetTriggerEdge
  2151. * @param ADCx ADC instance
  2152. * @retval Returned value can be one of the following values:
  2153. * @arg @ref LL_ADC_REG_TRIG_EXT_RISING
  2154. * @arg @ref LL_ADC_REG_TRIG_EXT_FALLING
  2155. * @arg @ref LL_ADC_REG_TRIG_EXT_RISINGFALLING
  2156. */
  2157. __STATIC_INLINE uint32_t LL_ADC_REG_GetTriggerEdge(ADC_TypeDef *ADCx)
  2158. {
  2159. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_EXTEN));
  2160. }
  2161. /**
  2162. * @brief Set ADC group regular sequencer scan direction.
  2163. * @note On some other STM32 families, this setting is not available and
  2164. * the default scan direction is forward.
  2165. * @note On this STM32 series, setting of this feature is conditioned to
  2166. * ADC state:
  2167. * ADC must be disabled or enabled without conversion on going
  2168. * on group regular.
  2169. * @rmtoll CFGR1 SCANDIR LL_ADC_REG_SetSequencerScanDirection
  2170. * @param ADCx ADC instance
  2171. * @param ScanDirection This parameter can be one of the following values:
  2172. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_FORWARD
  2173. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_BACKWARD
  2174. * @retval None
  2175. */
  2176. __STATIC_INLINE void LL_ADC_REG_SetSequencerScanDirection(ADC_TypeDef *ADCx, uint32_t ScanDirection)
  2177. {
  2178. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_SCANDIR, ScanDirection);
  2179. }
  2180. /**
  2181. * @brief Get ADC group regular sequencer scan direction.
  2182. * @note On some other STM32 families, this setting is not available and
  2183. * the default scan direction is forward.
  2184. * @rmtoll CFGR1 SCANDIR LL_ADC_REG_GetSequencerScanDirection
  2185. * @param ADCx ADC instance
  2186. * @retval Returned value can be one of the following values:
  2187. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_FORWARD
  2188. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_BACKWARD
  2189. */
  2190. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerScanDirection(ADC_TypeDef *ADCx)
  2191. {
  2192. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_SCANDIR));
  2193. }
  2194. /**
  2195. * @brief Set ADC group regular sequencer discontinuous mode:
  2196. * sequence subdivided and scan conversions interrupted every selected
  2197. * number of ranks.
  2198. * @note It is not possible to enable both ADC group regular
  2199. * continuous mode and sequencer discontinuous mode.
  2200. * @note On this STM32 series, setting of this feature is conditioned to
  2201. * ADC state:
  2202. * ADC must be disabled or enabled without conversion on going
  2203. * on group regular.
  2204. * @rmtoll CFGR1 DISCEN LL_ADC_REG_SetSequencerDiscont\n
  2205. * @param ADCx ADC instance
  2206. * @param SeqDiscont This parameter can be one of the following values:
  2207. * @arg @ref LL_ADC_REG_SEQ_DISCONT_DISABLE
  2208. * @arg @ref LL_ADC_REG_SEQ_DISCONT_1RANK
  2209. * @retval None
  2210. */
  2211. __STATIC_INLINE void LL_ADC_REG_SetSequencerDiscont(ADC_TypeDef *ADCx, uint32_t SeqDiscont)
  2212. {
  2213. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_DISCEN, SeqDiscont);
  2214. }
  2215. /**
  2216. * @brief Get ADC group regular sequencer discontinuous mode:
  2217. * sequence subdivided and scan conversions interrupted every selected
  2218. * number of ranks.
  2219. * @rmtoll CFGR1 DISCEN LL_ADC_REG_GetSequencerDiscont\n
  2220. * @param ADCx ADC instance
  2221. * @retval Returned value can be one of the following values:
  2222. * @arg @ref LL_ADC_REG_SEQ_DISCONT_DISABLE
  2223. * @arg @ref LL_ADC_REG_SEQ_DISCONT_1RANK
  2224. */
  2225. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerDiscont(ADC_TypeDef *ADCx)
  2226. {
  2227. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_DISCEN));
  2228. }
  2229. /**
  2230. * @brief Set ADC group regular sequence: channel on rank corresponding to
  2231. * channel number.
  2232. * @note This function performs:
  2233. * - Channels ordering into each rank of scan sequence:
  2234. * rank of each channel is fixed by channel HW number
  2235. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2236. * - Set channels selected by overwriting the current sequencer
  2237. * configuration.
  2238. * @note On this STM32 series, ADC group regular sequencer is
  2239. * not fully configurable: sequencer length and each rank
  2240. * affectation to a channel are fixed by channel HW number.
  2241. * @note Depending on devices and packages, some channels may not be available.
  2242. * Refer to device datasheet for channels availability.
  2243. * @note On this STM32 series, to measure internal channels (VrefInt,
  2244. * TempSensor, ...), measurement paths to internal channels must be
  2245. * enabled separately.
  2246. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  2247. * @note On this STM32 series, setting of this feature is conditioned to
  2248. * ADC state:
  2249. * ADC must be disabled or enabled without conversion on going
  2250. * on group regular.
  2251. * @note One or several values can be selected.
  2252. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  2253. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_SetSequencerChannels\n
  2254. * CHSELR CHSEL1 LL_ADC_REG_SetSequencerChannels\n
  2255. * CHSELR CHSEL2 LL_ADC_REG_SetSequencerChannels\n
  2256. * CHSELR CHSEL3 LL_ADC_REG_SetSequencerChannels\n
  2257. * CHSELR CHSEL4 LL_ADC_REG_SetSequencerChannels\n
  2258. * CHSELR CHSEL5 LL_ADC_REG_SetSequencerChannels\n
  2259. * CHSELR CHSEL6 LL_ADC_REG_SetSequencerChannels\n
  2260. * CHSELR CHSEL7 LL_ADC_REG_SetSequencerChannels\n
  2261. * CHSELR CHSEL8 LL_ADC_REG_SetSequencerChannels\n
  2262. * CHSELR CHSEL9 LL_ADC_REG_SetSequencerChannels\n
  2263. * CHSELR CHSEL10 LL_ADC_REG_SetSequencerChannels\n
  2264. * CHSELR CHSEL11 LL_ADC_REG_SetSequencerChannels\n
  2265. * CHSELR CHSEL12 LL_ADC_REG_SetSequencerChannels\n
  2266. * CHSELR CHSEL13 LL_ADC_REG_SetSequencerChannels\n
  2267. * CHSELR CHSEL14 LL_ADC_REG_SetSequencerChannels\n
  2268. * CHSELR CHSEL15 LL_ADC_REG_SetSequencerChannels\n
  2269. * CHSELR CHSEL16 LL_ADC_REG_SetSequencerChannels\n
  2270. * CHSELR CHSEL17 LL_ADC_REG_SetSequencerChannels\n
  2271. * CHSELR CHSEL18 LL_ADC_REG_SetSequencerChannels
  2272. * @param ADCx ADC instance
  2273. * @param Channel This parameter can be a combination of the following values:
  2274. * @arg @ref LL_ADC_CHANNEL_0
  2275. * @arg @ref LL_ADC_CHANNEL_1
  2276. * @arg @ref LL_ADC_CHANNEL_2
  2277. * @arg @ref LL_ADC_CHANNEL_3
  2278. * @arg @ref LL_ADC_CHANNEL_4
  2279. * @arg @ref LL_ADC_CHANNEL_5
  2280. * @arg @ref LL_ADC_CHANNEL_6
  2281. * @arg @ref LL_ADC_CHANNEL_7
  2282. * @arg @ref LL_ADC_CHANNEL_8
  2283. * @arg @ref LL_ADC_CHANNEL_9
  2284. * @arg @ref LL_ADC_CHANNEL_10
  2285. * @arg @ref LL_ADC_CHANNEL_11
  2286. * @arg @ref LL_ADC_CHANNEL_12
  2287. * @arg @ref LL_ADC_CHANNEL_13
  2288. * @arg @ref LL_ADC_CHANNEL_14
  2289. * @arg @ref LL_ADC_CHANNEL_15
  2290. * @arg @ref LL_ADC_CHANNEL_16 (1)
  2291. * @arg @ref LL_ADC_CHANNEL_17
  2292. * @arg @ref LL_ADC_CHANNEL_18
  2293. * @arg @ref LL_ADC_CHANNEL_VREFINT
  2294. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  2295. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  2296. *
  2297. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  2298. * @retval None
  2299. */
  2300. __STATIC_INLINE void LL_ADC_REG_SetSequencerChannels(ADC_TypeDef *ADCx, uint32_t Channel)
  2301. {
  2302. /* Parameter "Channel" is used with masks because containing */
  2303. /* other bits reserved for other purpose. */
  2304. WRITE_REG(ADCx->CHSELR, (Channel & ADC_CHANNEL_ID_BITFIELD_MASK));
  2305. }
  2306. /**
  2307. * @brief Add channel to ADC group regular sequence: channel on rank corresponding to
  2308. * channel number.
  2309. * @note This function performs:
  2310. * - Channels ordering into each rank of scan sequence:
  2311. * rank of each channel is fixed by channel HW number
  2312. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2313. * - Set channels selected by adding them to the current sequencer
  2314. * configuration.
  2315. * @note On this STM32 series, ADC group regular sequencer is
  2316. * not fully configurable: sequencer length and each rank
  2317. * affectation to a channel are fixed by channel HW number.
  2318. * @note Depending on devices and packages, some channels may not be available.
  2319. * Refer to device datasheet for channels availability.
  2320. * @note On this STM32 series, to measure internal channels (VrefInt,
  2321. * TempSensor, ...), measurement paths to internal channels must be
  2322. * enabled separately.
  2323. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  2324. * @note On this STM32 series, setting of this feature is conditioned to
  2325. * ADC state:
  2326. * ADC must be disabled or enabled without conversion on going
  2327. * on group regular.
  2328. * @note One or several values can be selected.
  2329. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  2330. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_SetSequencerChAdd\n
  2331. * CHSELR CHSEL1 LL_ADC_REG_SetSequencerChAdd\n
  2332. * CHSELR CHSEL2 LL_ADC_REG_SetSequencerChAdd\n
  2333. * CHSELR CHSEL3 LL_ADC_REG_SetSequencerChAdd\n
  2334. * CHSELR CHSEL4 LL_ADC_REG_SetSequencerChAdd\n
  2335. * CHSELR CHSEL5 LL_ADC_REG_SetSequencerChAdd\n
  2336. * CHSELR CHSEL6 LL_ADC_REG_SetSequencerChAdd\n
  2337. * CHSELR CHSEL7 LL_ADC_REG_SetSequencerChAdd\n
  2338. * CHSELR CHSEL8 LL_ADC_REG_SetSequencerChAdd\n
  2339. * CHSELR CHSEL9 LL_ADC_REG_SetSequencerChAdd\n
  2340. * CHSELR CHSEL10 LL_ADC_REG_SetSequencerChAdd\n
  2341. * CHSELR CHSEL11 LL_ADC_REG_SetSequencerChAdd\n
  2342. * CHSELR CHSEL12 LL_ADC_REG_SetSequencerChAdd\n
  2343. * CHSELR CHSEL13 LL_ADC_REG_SetSequencerChAdd\n
  2344. * CHSELR CHSEL14 LL_ADC_REG_SetSequencerChAdd\n
  2345. * CHSELR CHSEL15 LL_ADC_REG_SetSequencerChAdd\n
  2346. * CHSELR CHSEL16 LL_ADC_REG_SetSequencerChAdd\n
  2347. * CHSELR CHSEL17 LL_ADC_REG_SetSequencerChAdd\n
  2348. * CHSELR CHSEL18 LL_ADC_REG_SetSequencerChAdd
  2349. * @param ADCx ADC instance
  2350. * @param Channel This parameter can be a combination of the following values:
  2351. * @arg @ref LL_ADC_CHANNEL_0
  2352. * @arg @ref LL_ADC_CHANNEL_1
  2353. * @arg @ref LL_ADC_CHANNEL_2
  2354. * @arg @ref LL_ADC_CHANNEL_3
  2355. * @arg @ref LL_ADC_CHANNEL_4
  2356. * @arg @ref LL_ADC_CHANNEL_5
  2357. * @arg @ref LL_ADC_CHANNEL_6
  2358. * @arg @ref LL_ADC_CHANNEL_7
  2359. * @arg @ref LL_ADC_CHANNEL_8
  2360. * @arg @ref LL_ADC_CHANNEL_9
  2361. * @arg @ref LL_ADC_CHANNEL_10
  2362. * @arg @ref LL_ADC_CHANNEL_11
  2363. * @arg @ref LL_ADC_CHANNEL_12
  2364. * @arg @ref LL_ADC_CHANNEL_13
  2365. * @arg @ref LL_ADC_CHANNEL_14
  2366. * @arg @ref LL_ADC_CHANNEL_15
  2367. * @arg @ref LL_ADC_CHANNEL_16 (1)
  2368. * @arg @ref LL_ADC_CHANNEL_17
  2369. * @arg @ref LL_ADC_CHANNEL_18
  2370. * @arg @ref LL_ADC_CHANNEL_VREFINT
  2371. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  2372. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  2373. *
  2374. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  2375. * @retval None
  2376. */
  2377. __STATIC_INLINE void LL_ADC_REG_SetSequencerChAdd(ADC_TypeDef *ADCx, uint32_t Channel)
  2378. {
  2379. /* Parameter "Channel" is used with masks because containing */
  2380. /* other bits reserved for other purpose. */
  2381. SET_BIT(ADCx->CHSELR, (Channel & ADC_CHANNEL_ID_BITFIELD_MASK));
  2382. }
  2383. /**
  2384. * @brief Remove channel to ADC group regular sequence: channel on rank corresponding to
  2385. * channel number.
  2386. * @note This function performs:
  2387. * - Channels ordering into each rank of scan sequence:
  2388. * rank of each channel is fixed by channel HW number
  2389. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2390. * - Set channels selected by removing them to the current sequencer
  2391. * configuration.
  2392. * @note On this STM32 series, ADC group regular sequencer is
  2393. * not fully configurable: sequencer length and each rank
  2394. * affectation to a channel are fixed by channel HW number.
  2395. * @note Depending on devices and packages, some channels may not be available.
  2396. * Refer to device datasheet for channels availability.
  2397. * @note On this STM32 series, to measure internal channels (VrefInt,
  2398. * TempSensor, ...), measurement paths to internal channels must be
  2399. * enabled separately.
  2400. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  2401. * @note On this STM32 series, setting of this feature is conditioned to
  2402. * ADC state:
  2403. * ADC must be disabled or enabled without conversion on going
  2404. * on group regular.
  2405. * @note One or several values can be selected.
  2406. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  2407. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_SetSequencerChRem\n
  2408. * CHSELR CHSEL1 LL_ADC_REG_SetSequencerChRem\n
  2409. * CHSELR CHSEL2 LL_ADC_REG_SetSequencerChRem\n
  2410. * CHSELR CHSEL3 LL_ADC_REG_SetSequencerChRem\n
  2411. * CHSELR CHSEL4 LL_ADC_REG_SetSequencerChRem\n
  2412. * CHSELR CHSEL5 LL_ADC_REG_SetSequencerChRem\n
  2413. * CHSELR CHSEL6 LL_ADC_REG_SetSequencerChRem\n
  2414. * CHSELR CHSEL7 LL_ADC_REG_SetSequencerChRem\n
  2415. * CHSELR CHSEL8 LL_ADC_REG_SetSequencerChRem\n
  2416. * CHSELR CHSEL9 LL_ADC_REG_SetSequencerChRem\n
  2417. * CHSELR CHSEL10 LL_ADC_REG_SetSequencerChRem\n
  2418. * CHSELR CHSEL11 LL_ADC_REG_SetSequencerChRem\n
  2419. * CHSELR CHSEL12 LL_ADC_REG_SetSequencerChRem\n
  2420. * CHSELR CHSEL13 LL_ADC_REG_SetSequencerChRem\n
  2421. * CHSELR CHSEL14 LL_ADC_REG_SetSequencerChRem\n
  2422. * CHSELR CHSEL15 LL_ADC_REG_SetSequencerChRem\n
  2423. * CHSELR CHSEL16 LL_ADC_REG_SetSequencerChRem\n
  2424. * CHSELR CHSEL17 LL_ADC_REG_SetSequencerChRem\n
  2425. * CHSELR CHSEL18 LL_ADC_REG_SetSequencerChRem
  2426. * @param ADCx ADC instance
  2427. * @param Channel This parameter can be a combination of the following values:
  2428. * @arg @ref LL_ADC_CHANNEL_0
  2429. * @arg @ref LL_ADC_CHANNEL_1
  2430. * @arg @ref LL_ADC_CHANNEL_2
  2431. * @arg @ref LL_ADC_CHANNEL_3
  2432. * @arg @ref LL_ADC_CHANNEL_4
  2433. * @arg @ref LL_ADC_CHANNEL_5
  2434. * @arg @ref LL_ADC_CHANNEL_6
  2435. * @arg @ref LL_ADC_CHANNEL_7
  2436. * @arg @ref LL_ADC_CHANNEL_8
  2437. * @arg @ref LL_ADC_CHANNEL_9
  2438. * @arg @ref LL_ADC_CHANNEL_10
  2439. * @arg @ref LL_ADC_CHANNEL_11
  2440. * @arg @ref LL_ADC_CHANNEL_12
  2441. * @arg @ref LL_ADC_CHANNEL_13
  2442. * @arg @ref LL_ADC_CHANNEL_14
  2443. * @arg @ref LL_ADC_CHANNEL_15
  2444. * @arg @ref LL_ADC_CHANNEL_16 (1)
  2445. * @arg @ref LL_ADC_CHANNEL_17
  2446. * @arg @ref LL_ADC_CHANNEL_18
  2447. * @arg @ref LL_ADC_CHANNEL_VREFINT
  2448. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  2449. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  2450. *
  2451. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  2452. * @retval None
  2453. */
  2454. __STATIC_INLINE void LL_ADC_REG_SetSequencerChRem(ADC_TypeDef *ADCx, uint32_t Channel)
  2455. {
  2456. /* Parameter "Channel" is used with masks because containing */
  2457. /* other bits reserved for other purpose. */
  2458. CLEAR_BIT(ADCx->CHSELR, (Channel & ADC_CHANNEL_ID_BITFIELD_MASK));
  2459. }
  2460. /**
  2461. * @brief Get ADC group regular sequence: channel on rank corresponding to
  2462. * channel number.
  2463. * @note This function performs:
  2464. * - Channels order reading into each rank of scan sequence:
  2465. * rank of each channel is fixed by channel HW number
  2466. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2467. * @note On this STM32 series, ADC group regular sequencer is
  2468. * not fully configurable: sequencer length and each rank
  2469. * affectation to a channel are fixed by channel HW number.
  2470. * @note Depending on devices and packages, some channels may not be available.
  2471. * Refer to device datasheet for channels availability.
  2472. * @note On this STM32 series, to measure internal channels (VrefInt,
  2473. * TempSensor, ...), measurement paths to internal channels must be
  2474. * enabled separately.
  2475. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  2476. * @note On this STM32 series, setting of this feature is conditioned to
  2477. * ADC state:
  2478. * ADC must be disabled or enabled without conversion on going
  2479. * on group regular.
  2480. * @note One or several values can be retrieved.
  2481. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  2482. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_GetSequencerChannels\n
  2483. * CHSELR CHSEL1 LL_ADC_REG_GetSequencerChannels\n
  2484. * CHSELR CHSEL2 LL_ADC_REG_GetSequencerChannels\n
  2485. * CHSELR CHSEL3 LL_ADC_REG_GetSequencerChannels\n
  2486. * CHSELR CHSEL4 LL_ADC_REG_GetSequencerChannels\n
  2487. * CHSELR CHSEL5 LL_ADC_REG_GetSequencerChannels\n
  2488. * CHSELR CHSEL6 LL_ADC_REG_GetSequencerChannels\n
  2489. * CHSELR CHSEL7 LL_ADC_REG_GetSequencerChannels\n
  2490. * CHSELR CHSEL8 LL_ADC_REG_GetSequencerChannels\n
  2491. * CHSELR CHSEL9 LL_ADC_REG_GetSequencerChannels\n
  2492. * CHSELR CHSEL10 LL_ADC_REG_GetSequencerChannels\n
  2493. * CHSELR CHSEL11 LL_ADC_REG_GetSequencerChannels\n
  2494. * CHSELR CHSEL12 LL_ADC_REG_GetSequencerChannels\n
  2495. * CHSELR CHSEL13 LL_ADC_REG_GetSequencerChannels\n
  2496. * CHSELR CHSEL14 LL_ADC_REG_GetSequencerChannels\n
  2497. * CHSELR CHSEL15 LL_ADC_REG_GetSequencerChannels\n
  2498. * CHSELR CHSEL16 LL_ADC_REG_GetSequencerChannels\n
  2499. * CHSELR CHSEL17 LL_ADC_REG_GetSequencerChannels\n
  2500. * CHSELR CHSEL18 LL_ADC_REG_GetSequencerChannels
  2501. * @param ADCx ADC instance
  2502. * @retval Returned value can be a combination of the following values:
  2503. * @arg @ref LL_ADC_CHANNEL_0
  2504. * @arg @ref LL_ADC_CHANNEL_1
  2505. * @arg @ref LL_ADC_CHANNEL_2
  2506. * @arg @ref LL_ADC_CHANNEL_3
  2507. * @arg @ref LL_ADC_CHANNEL_4
  2508. * @arg @ref LL_ADC_CHANNEL_5
  2509. * @arg @ref LL_ADC_CHANNEL_6
  2510. * @arg @ref LL_ADC_CHANNEL_7
  2511. * @arg @ref LL_ADC_CHANNEL_8
  2512. * @arg @ref LL_ADC_CHANNEL_9
  2513. * @arg @ref LL_ADC_CHANNEL_10
  2514. * @arg @ref LL_ADC_CHANNEL_11
  2515. * @arg @ref LL_ADC_CHANNEL_12
  2516. * @arg @ref LL_ADC_CHANNEL_13
  2517. * @arg @ref LL_ADC_CHANNEL_14
  2518. * @arg @ref LL_ADC_CHANNEL_15
  2519. * @arg @ref LL_ADC_CHANNEL_16 (1)
  2520. * @arg @ref LL_ADC_CHANNEL_17
  2521. * @arg @ref LL_ADC_CHANNEL_18
  2522. * @arg @ref LL_ADC_CHANNEL_VREFINT
  2523. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  2524. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  2525. *
  2526. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  2527. */
  2528. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerChannels(ADC_TypeDef *ADCx)
  2529. {
  2530. uint32_t ChannelsBitfield = READ_BIT(ADCx->CHSELR, ADC_CHSELR_CHSEL);
  2531. return ((((ChannelsBitfield & ADC_CHSELR_CHSEL0) >> ADC_CHSELR_CHSEL0_BITOFFSET_POS) * LL_ADC_CHANNEL_0)
  2532. | (((ChannelsBitfield & ADC_CHSELR_CHSEL1) >> ADC_CHSELR_CHSEL1_BITOFFSET_POS) * LL_ADC_CHANNEL_1)
  2533. | (((ChannelsBitfield & ADC_CHSELR_CHSEL2) >> ADC_CHSELR_CHSEL2_BITOFFSET_POS) * LL_ADC_CHANNEL_2)
  2534. | (((ChannelsBitfield & ADC_CHSELR_CHSEL3) >> ADC_CHSELR_CHSEL3_BITOFFSET_POS) * LL_ADC_CHANNEL_3)
  2535. | (((ChannelsBitfield & ADC_CHSELR_CHSEL4) >> ADC_CHSELR_CHSEL4_BITOFFSET_POS) * LL_ADC_CHANNEL_4)
  2536. | (((ChannelsBitfield & ADC_CHSELR_CHSEL5) >> ADC_CHSELR_CHSEL5_BITOFFSET_POS) * LL_ADC_CHANNEL_5)
  2537. | (((ChannelsBitfield & ADC_CHSELR_CHSEL6) >> ADC_CHSELR_CHSEL6_BITOFFSET_POS) * LL_ADC_CHANNEL_6)
  2538. | (((ChannelsBitfield & ADC_CHSELR_CHSEL7) >> ADC_CHSELR_CHSEL7_BITOFFSET_POS) * LL_ADC_CHANNEL_7)
  2539. | (((ChannelsBitfield & ADC_CHSELR_CHSEL8) >> ADC_CHSELR_CHSEL8_BITOFFSET_POS) * LL_ADC_CHANNEL_8)
  2540. | (((ChannelsBitfield & ADC_CHSELR_CHSEL9) >> ADC_CHSELR_CHSEL9_BITOFFSET_POS) * LL_ADC_CHANNEL_9)
  2541. | (((ChannelsBitfield & ADC_CHSELR_CHSEL10) >> ADC_CHSELR_CHSEL10_BITOFFSET_POS) * LL_ADC_CHANNEL_10)
  2542. | (((ChannelsBitfield & ADC_CHSELR_CHSEL11) >> ADC_CHSELR_CHSEL11_BITOFFSET_POS) * LL_ADC_CHANNEL_11)
  2543. | (((ChannelsBitfield & ADC_CHSELR_CHSEL12) >> ADC_CHSELR_CHSEL12_BITOFFSET_POS) * LL_ADC_CHANNEL_12)
  2544. | (((ChannelsBitfield & ADC_CHSELR_CHSEL13) >> ADC_CHSELR_CHSEL13_BITOFFSET_POS) * LL_ADC_CHANNEL_13)
  2545. | (((ChannelsBitfield & ADC_CHSELR_CHSEL14) >> ADC_CHSELR_CHSEL14_BITOFFSET_POS) * LL_ADC_CHANNEL_14)
  2546. | (((ChannelsBitfield & ADC_CHSELR_CHSEL15) >> ADC_CHSELR_CHSEL15_BITOFFSET_POS) * LL_ADC_CHANNEL_15)
  2547. #if defined(ADC_CCR_VLCDEN)
  2548. | (((ChannelsBitfield & ADC_CHSELR_CHSEL16) >> ADC_CHSELR_CHSEL16_BITOFFSET_POS) * LL_ADC_CHANNEL_16)
  2549. #endif
  2550. | (((ChannelsBitfield & ADC_CHSELR_CHSEL17) >> ADC_CHSELR_CHSEL17_BITOFFSET_POS) * LL_ADC_CHANNEL_17)
  2551. | (((ChannelsBitfield & ADC_CHSELR_CHSEL18) >> ADC_CHSELR_CHSEL18_BITOFFSET_POS) * LL_ADC_CHANNEL_18)
  2552. );
  2553. }
  2554. /**
  2555. * @brief Set ADC continuous conversion mode on ADC group regular.
  2556. * @note Description of ADC continuous conversion mode:
  2557. * - single mode: one conversion per trigger
  2558. * - continuous mode: after the first trigger, following
  2559. * conversions launched successively automatically.
  2560. * @note It is not possible to enable both ADC group regular
  2561. * continuous mode and sequencer discontinuous mode.
  2562. * @note On this STM32 series, setting of this feature is conditioned to
  2563. * ADC state:
  2564. * ADC must be disabled or enabled without conversion on going
  2565. * on group regular.
  2566. * @rmtoll CFGR1 CONT LL_ADC_REG_SetContinuousMode
  2567. * @param ADCx ADC instance
  2568. * @param Continuous This parameter can be one of the following values:
  2569. * @arg @ref LL_ADC_REG_CONV_SINGLE
  2570. * @arg @ref LL_ADC_REG_CONV_CONTINUOUS
  2571. * @retval None
  2572. */
  2573. __STATIC_INLINE void LL_ADC_REG_SetContinuousMode(ADC_TypeDef *ADCx, uint32_t Continuous)
  2574. {
  2575. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_CONT, Continuous);
  2576. }
  2577. /**
  2578. * @brief Get ADC continuous conversion mode on ADC group regular.
  2579. * @note Description of ADC continuous conversion mode:
  2580. * - single mode: one conversion per trigger
  2581. * - continuous mode: after the first trigger, following
  2582. * conversions launched successively automatically.
  2583. * @rmtoll CFGR1 CONT LL_ADC_REG_GetContinuousMode
  2584. * @param ADCx ADC instance
  2585. * @retval Returned value can be one of the following values:
  2586. * @arg @ref LL_ADC_REG_CONV_SINGLE
  2587. * @arg @ref LL_ADC_REG_CONV_CONTINUOUS
  2588. */
  2589. __STATIC_INLINE uint32_t LL_ADC_REG_GetContinuousMode(ADC_TypeDef *ADCx)
  2590. {
  2591. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_CONT));
  2592. }
  2593. /**
  2594. * @brief Set ADC group regular conversion data transfer: no transfer or
  2595. * transfer by DMA, and DMA requests mode.
  2596. * @note If transfer by DMA selected, specifies the DMA requests
  2597. * mode:
  2598. * - Limited mode (One shot mode): DMA transfer requests are stopped
  2599. * when number of DMA data transfers (number of
  2600. * ADC conversions) is reached.
  2601. * This ADC mode is intended to be used with DMA mode non-circular.
  2602. * - Unlimited mode: DMA transfer requests are unlimited,
  2603. * whatever number of DMA data transfers (number of
  2604. * ADC conversions).
  2605. * This ADC mode is intended to be used with DMA mode circular.
  2606. * @note If ADC DMA requests mode is set to unlimited and DMA is set to
  2607. * mode non-circular:
  2608. * when DMA transfers size will be reached, DMA will stop transfers of
  2609. * ADC conversions data ADC will raise an overrun error
  2610. * (overrun flag and interruption if enabled).
  2611. * @note To configure DMA source address (peripheral address),
  2612. * use function @ref LL_ADC_DMA_GetRegAddr().
  2613. * @note On this STM32 series, setting of this feature is conditioned to
  2614. * ADC state:
  2615. * ADC must be disabled or enabled without conversion on going
  2616. * on group regular.
  2617. * @rmtoll CFGR1 DMAEN LL_ADC_REG_SetDMATransfer\n
  2618. * CFGR1 DMACFG LL_ADC_REG_SetDMATransfer
  2619. * @param ADCx ADC instance
  2620. * @param DMATransfer This parameter can be one of the following values:
  2621. * @arg @ref LL_ADC_REG_DMA_TRANSFER_NONE
  2622. * @arg @ref LL_ADC_REG_DMA_TRANSFER_LIMITED
  2623. * @arg @ref LL_ADC_REG_DMA_TRANSFER_UNLIMITED
  2624. * @retval None
  2625. */
  2626. __STATIC_INLINE void LL_ADC_REG_SetDMATransfer(ADC_TypeDef *ADCx, uint32_t DMATransfer)
  2627. {
  2628. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG, DMATransfer);
  2629. }
  2630. /**
  2631. * @brief Get ADC group regular conversion data transfer: no transfer or
  2632. * transfer by DMA, and DMA requests mode.
  2633. * @note If transfer by DMA selected, specifies the DMA requests
  2634. * mode:
  2635. * - Limited mode (One shot mode): DMA transfer requests are stopped
  2636. * when number of DMA data transfers (number of
  2637. * ADC conversions) is reached.
  2638. * This ADC mode is intended to be used with DMA mode non-circular.
  2639. * - Unlimited mode: DMA transfer requests are unlimited,
  2640. * whatever number of DMA data transfers (number of
  2641. * ADC conversions).
  2642. * This ADC mode is intended to be used with DMA mode circular.
  2643. * @note If ADC DMA requests mode is set to unlimited and DMA is set to
  2644. * mode non-circular:
  2645. * when DMA transfers size will be reached, DMA will stop transfers of
  2646. * ADC conversions data ADC will raise an overrun error
  2647. * (overrun flag and interruption if enabled).
  2648. * @note To configure DMA source address (peripheral address),
  2649. * use function @ref LL_ADC_DMA_GetRegAddr().
  2650. * @rmtoll CFGR1 DMAEN LL_ADC_REG_GetDMATransfer\n
  2651. * CFGR1 DMACFG LL_ADC_REG_GetDMATransfer
  2652. * @param ADCx ADC instance
  2653. * @retval Returned value can be one of the following values:
  2654. * @arg @ref LL_ADC_REG_DMA_TRANSFER_NONE
  2655. * @arg @ref LL_ADC_REG_DMA_TRANSFER_LIMITED
  2656. * @arg @ref LL_ADC_REG_DMA_TRANSFER_UNLIMITED
  2657. */
  2658. __STATIC_INLINE uint32_t LL_ADC_REG_GetDMATransfer(ADC_TypeDef *ADCx)
  2659. {
  2660. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG));
  2661. }
  2662. /**
  2663. * @brief Set ADC group regular behavior in case of overrun:
  2664. * data preserved or overwritten.
  2665. * @note Compatibility with devices without feature overrun:
  2666. * other devices without this feature have a behavior
  2667. * equivalent to data overwritten.
  2668. * The default setting of overrun is data preserved.
  2669. * Therefore, for compatibility with all devices, parameter
  2670. * overrun should be set to data overwritten.
  2671. * @note On this STM32 series, setting of this feature is conditioned to
  2672. * ADC state:
  2673. * ADC must be disabled or enabled without conversion on going
  2674. * on group regular.
  2675. * @rmtoll CFGR1 OVRMOD LL_ADC_REG_SetOverrun
  2676. * @param ADCx ADC instance
  2677. * @param Overrun This parameter can be one of the following values:
  2678. * @arg @ref LL_ADC_REG_OVR_DATA_PRESERVED
  2679. * @arg @ref LL_ADC_REG_OVR_DATA_OVERWRITTEN
  2680. * @retval None
  2681. */
  2682. __STATIC_INLINE void LL_ADC_REG_SetOverrun(ADC_TypeDef *ADCx, uint32_t Overrun)
  2683. {
  2684. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_OVRMOD, Overrun);
  2685. }
  2686. /**
  2687. * @brief Get ADC group regular behavior in case of overrun:
  2688. * data preserved or overwritten.
  2689. * @rmtoll CFGR1 OVRMOD LL_ADC_REG_GetOverrun
  2690. * @param ADCx ADC instance
  2691. * @retval Returned value can be one of the following values:
  2692. * @arg @ref LL_ADC_REG_OVR_DATA_PRESERVED
  2693. * @arg @ref LL_ADC_REG_OVR_DATA_OVERWRITTEN
  2694. */
  2695. __STATIC_INLINE uint32_t LL_ADC_REG_GetOverrun(ADC_TypeDef *ADCx)
  2696. {
  2697. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_OVRMOD));
  2698. }
  2699. /**
  2700. * @}
  2701. */
  2702. /** @defgroup ADC_LL_EF_Configuration_ADC_AnalogWatchdog Configuration of ADC transversal scope: analog watchdog
  2703. * @{
  2704. */
  2705. /**
  2706. * @brief Set ADC analog watchdog monitored channels:
  2707. * a single channel or all channels,
  2708. * on ADC group regular.
  2709. * @note Once monitored channels are selected, analog watchdog
  2710. * is enabled.
  2711. * @note In case of need to define a single channel to monitor
  2712. * with analog watchdog from sequencer channel definition,
  2713. * use helper macro @ref __LL_ADC_ANALOGWD_CHANNEL_GROUP().
  2714. * @note On this STM32 series, there is only 1 kind of analog watchdog
  2715. * instance:
  2716. * - AWD standard (instance AWD1):
  2717. * - channels monitored: can monitor 1 channel or all channels.
  2718. * - groups monitored: ADC group regular.
  2719. * - resolution: resolution is not limited (corresponds to
  2720. * ADC resolution configured).
  2721. * @note On this STM32 series, setting of this feature is conditioned to
  2722. * ADC state:
  2723. * ADC must be disabled or enabled without conversion on going
  2724. * on group regular.
  2725. * @rmtoll CFGR1 AWDCH LL_ADC_SetAnalogWDMonitChannels\n
  2726. * CFGR1 AWDSGL LL_ADC_SetAnalogWDMonitChannels\n
  2727. * CFGR1 AWDEN LL_ADC_SetAnalogWDMonitChannels
  2728. * @param ADCx ADC instance
  2729. * @param AWDChannelGroup This parameter can be one of the following values:
  2730. * @arg @ref LL_ADC_AWD_DISABLE
  2731. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG
  2732. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG
  2733. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG
  2734. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG
  2735. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG
  2736. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG
  2737. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG
  2738. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG
  2739. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG
  2740. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG
  2741. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG
  2742. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG
  2743. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG
  2744. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG
  2745. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG
  2746. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG
  2747. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG
  2748. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG (1)
  2749. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG
  2750. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG
  2751. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG
  2752. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG
  2753. * @arg @ref LL_ADC_AWD_CH_VLCD_REG (1)
  2754. *
  2755. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  2756. * @retval None
  2757. */
  2758. __STATIC_INLINE void LL_ADC_SetAnalogWDMonitChannels(ADC_TypeDef *ADCx, uint32_t AWDChannelGroup)
  2759. {
  2760. MODIFY_REG(ADCx->CFGR1,
  2761. (ADC_CFGR1_AWDCH | ADC_CFGR1_AWDSGL | ADC_CFGR1_AWDEN),
  2762. (AWDChannelGroup & ADC_AWD_CR_ALL_CHANNEL_MASK));
  2763. }
  2764. /**
  2765. * @brief Get ADC analog watchdog monitored channel.
  2766. * @note Usage of the returned channel number:
  2767. * - To reinject this channel into another function LL_ADC_xxx:
  2768. * the returned channel number is only partly formatted on definition
  2769. * of literals LL_ADC_CHANNEL_x. Therefore, it has to be compared
  2770. * with parts of literals LL_ADC_CHANNEL_x or using
  2771. * helper macro @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2772. * Then the selected literal LL_ADC_CHANNEL_x can be used
  2773. * as parameter for another function.
  2774. * - To get the channel number in decimal format:
  2775. * process the returned value with the helper macro
  2776. * @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2777. * Applicable only when the analog watchdog is set to monitor
  2778. * one channel.
  2779. * @note On this STM32 series, there is only 1 kind of analog watchdog
  2780. * instance:
  2781. * - AWD standard (instance AWD1):
  2782. * - channels monitored: can monitor 1 channel or all channels.
  2783. * - groups monitored: ADC group regular.
  2784. * - resolution: resolution is not limited (corresponds to
  2785. * ADC resolution configured).
  2786. * @note On this STM32 series, setting of this feature is conditioned to
  2787. * ADC state:
  2788. * ADC must be disabled or enabled without conversion on going
  2789. * on group regular.
  2790. * @rmtoll CFGR1 AWDCH LL_ADC_GetAnalogWDMonitChannels\n
  2791. * CFGR1 AWDSGL LL_ADC_GetAnalogWDMonitChannels\n
  2792. * CFGR1 AWDEN LL_ADC_GetAnalogWDMonitChannels
  2793. * @param ADCx ADC instance
  2794. * @retval Returned value can be one of the following values:
  2795. * @arg @ref LL_ADC_AWD_DISABLE
  2796. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG
  2797. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG
  2798. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG
  2799. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG
  2800. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG
  2801. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG
  2802. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG
  2803. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG
  2804. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG
  2805. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG
  2806. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG
  2807. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG
  2808. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG
  2809. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG
  2810. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG
  2811. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG
  2812. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG
  2813. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG
  2814. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG
  2815. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG
  2816. */
  2817. __STATIC_INLINE uint32_t LL_ADC_GetAnalogWDMonitChannels(ADC_TypeDef *ADCx)
  2818. {
  2819. uint32_t AWDChannelGroup = READ_BIT(ADCx->CFGR1, (ADC_CFGR1_AWDCH | ADC_CFGR1_AWDSGL | ADC_CFGR1_AWDEN));
  2820. /* Note: Set variable according to channel definition including channel ID */
  2821. /* with bitfield. */
  2822. uint32_t AWDChannelSingle = ((AWDChannelGroup & ADC_CFGR1_AWDSGL) >> ADC_CFGR1_AWDSGL_BITOFFSET_POS);
  2823. uint32_t AWDChannelBitField = (ADC_CHANNEL_0_BITFIELD << ((AWDChannelGroup & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS));
  2824. return (AWDChannelGroup | (AWDChannelBitField * AWDChannelSingle));
  2825. }
  2826. /**
  2827. * @brief Set ADC analog watchdog thresholds value of both thresholds
  2828. * high and low.
  2829. * @note If value of only one threshold high or low must be set,
  2830. * use function @ref LL_ADC_SetAnalogWDThresholds().
  2831. * @note In case of ADC resolution different of 12 bits,
  2832. * analog watchdog thresholds data require a specific shift.
  2833. * Use helper macro @ref __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION().
  2834. * @note On this STM32 series, there is only 1 kind of analog watchdog
  2835. * instance:
  2836. * - AWD standard (instance AWD1):
  2837. * - channels monitored: can monitor 1 channel or all channels.
  2838. * - groups monitored: ADC group regular.
  2839. * - resolution: resolution is not limited (corresponds to
  2840. * ADC resolution configured).
  2841. * @note On this STM32 series, setting of this feature is conditioned to
  2842. * ADC state:
  2843. * ADC must be disabled or enabled without conversion on going
  2844. * on group regular.
  2845. * @rmtoll TR HT LL_ADC_ConfigAnalogWDThresholds\n
  2846. * TR LT LL_ADC_ConfigAnalogWDThresholds
  2847. * @param ADCx ADC instance
  2848. * @param AWDThresholdHighValue Value between Min_Data=0x000 and Max_Data=0xFFF
  2849. * @param AWDThresholdLowValue Value between Min_Data=0x000 and Max_Data=0xFFF
  2850. * @retval None
  2851. */
  2852. __STATIC_INLINE void LL_ADC_ConfigAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDThresholdHighValue, uint32_t AWDThresholdLowValue)
  2853. {
  2854. MODIFY_REG(ADCx->TR,
  2855. ADC_TR_HT | ADC_TR_LT,
  2856. (AWDThresholdHighValue << ADC_TR_HT_BITOFFSET_POS) | AWDThresholdLowValue);
  2857. }
  2858. /**
  2859. * @brief Set ADC analog watchdog threshold value of threshold
  2860. * high or low.
  2861. * @note If values of both thresholds high or low must be set,
  2862. * use function @ref LL_ADC_ConfigAnalogWDThresholds().
  2863. * @note In case of ADC resolution different of 12 bits,
  2864. * analog watchdog thresholds data require a specific shift.
  2865. * Use helper macro @ref __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION().
  2866. * @note On this STM32 series, there is only 1 kind of analog watchdog
  2867. * instance:
  2868. * - AWD standard (instance AWD1):
  2869. * - channels monitored: can monitor 1 channel or all channels.
  2870. * - groups monitored: ADC group regular.
  2871. * - resolution: resolution is not limited (corresponds to
  2872. * ADC resolution configured).
  2873. * @note On this STM32 series, setting of this feature is conditioned to
  2874. * ADC state:
  2875. * ADC must be disabled or enabled without conversion on going
  2876. * on group regular.
  2877. * @rmtoll TR HT LL_ADC_SetAnalogWDThresholds\n
  2878. * TR LT LL_ADC_SetAnalogWDThresholds
  2879. * @param ADCx ADC instance
  2880. * @param AWDThresholdsHighLow This parameter can be one of the following values:
  2881. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  2882. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  2883. * @param AWDThresholdValue Value between Min_Data=0x000 and Max_Data=0xFFF
  2884. * @retval None
  2885. */
  2886. __STATIC_INLINE void LL_ADC_SetAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDThresholdsHighLow, uint32_t AWDThresholdValue)
  2887. {
  2888. /* Parameter "AWDThresholdsHighLow" is used with mask "0x00000010" */
  2889. /* to be equivalent to "POSITION_VAL(AWDThresholdsHighLow)": if threshold */
  2890. /* high is selected, then data is shifted to LSB. Else(threshold low), */
  2891. /* data is not shifted. */
  2892. MODIFY_REG(ADCx->TR,
  2893. AWDThresholdsHighLow,
  2894. AWDThresholdValue << ((AWDThresholdsHighLow >> ADC_TR_HT_BITOFFSET_POS) & ((uint32_t)0x00000010U)));
  2895. }
  2896. /**
  2897. * @brief Get ADC analog watchdog threshold value of threshold high,
  2898. * threshold low or raw data with ADC thresholds high and low
  2899. * concatenated.
  2900. * @note If raw data with ADC thresholds high and low is retrieved,
  2901. * the data of each threshold high or low can be isolated
  2902. * using helper macro:
  2903. * @ref __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW().
  2904. * @note In case of ADC resolution different of 12 bits,
  2905. * analog watchdog thresholds data require a specific shift.
  2906. * Use helper macro @ref __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION().
  2907. * @rmtoll TR HT LL_ADC_GetAnalogWDThresholds\n
  2908. * TR LT LL_ADC_GetAnalogWDThresholds
  2909. * @param ADCx ADC instance
  2910. * @param AWDThresholdsHighLow This parameter can be one of the following values:
  2911. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  2912. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  2913. * @arg @ref LL_ADC_AWD_THRESHOLDS_HIGH_LOW
  2914. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  2915. */
  2916. __STATIC_INLINE uint32_t LL_ADC_GetAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDThresholdsHighLow)
  2917. {
  2918. /* Parameter "AWDThresholdsHighLow" is used with mask "0x00000010" */
  2919. /* to be equivalent to "POSITION_VAL(AWDThresholdsHighLow)": if threshold */
  2920. /* high is selected, then data is shifted to LSB. Else(threshold low or */
  2921. /* both thresholds), data is not shifted. */
  2922. return (uint32_t)(READ_BIT(ADCx->TR,
  2923. (AWDThresholdsHighLow | ADC_TR_LT))
  2924. >> ((~AWDThresholdsHighLow) & (0x00000010U))
  2925. );
  2926. }
  2927. /**
  2928. * @}
  2929. */
  2930. /** @defgroup ADC_LL_EF_Configuration_ADC_oversampling Configuration of ADC transversal scope: oversampling
  2931. * @{
  2932. */
  2933. /**
  2934. * @brief Set ADC oversampling scope.
  2935. * @note On this STM32 series, setting of this feature is conditioned to
  2936. * ADC state:
  2937. * ADC must be disabled or enabled without conversion on going
  2938. * on group regular.
  2939. * @rmtoll CFGR2 OVSE LL_ADC_SetOverSamplingScope
  2940. * @param ADCx ADC instance
  2941. * @param OvsScope This parameter can be one of the following values:
  2942. * @arg @ref LL_ADC_OVS_DISABLE
  2943. * @arg @ref LL_ADC_OVS_GRP_REGULAR_CONTINUED
  2944. * @retval None
  2945. */
  2946. __STATIC_INLINE void LL_ADC_SetOverSamplingScope(ADC_TypeDef *ADCx, uint32_t OvsScope)
  2947. {
  2948. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_OVSE, OvsScope);
  2949. }
  2950. /**
  2951. * @brief Get ADC oversampling scope.
  2952. * @rmtoll CFGR2 OVSE LL_ADC_GetOverSamplingScope
  2953. * @param ADCx ADC instance
  2954. * @retval Returned value can be one of the following values:
  2955. * @arg @ref LL_ADC_OVS_DISABLE
  2956. * @arg @ref LL_ADC_OVS_GRP_REGULAR_CONTINUED
  2957. */
  2958. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingScope(ADC_TypeDef *ADCx)
  2959. {
  2960. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_OVSE));
  2961. }
  2962. /**
  2963. * @brief Set ADC oversampling discontinuous mode (triggered mode)
  2964. * on the selected ADC group.
  2965. * @note Number of oversampled conversions are done either in:
  2966. * - continuous mode (all conversions of oversampling ratio
  2967. * are done from 1 trigger)
  2968. * - discontinuous mode (each conversion of oversampling ratio
  2969. * needs a trigger)
  2970. * @note On this STM32 series, setting of this feature is conditioned to
  2971. * ADC state:
  2972. * ADC must be disabled or enabled without conversion on going
  2973. * on group regular.
  2974. * @rmtoll CFGR2 TOVS LL_ADC_SetOverSamplingDiscont
  2975. * @param ADCx ADC instance
  2976. * @param OverSamplingDiscont This parameter can be one of the following values:
  2977. * @arg @ref LL_ADC_OVS_REG_CONT
  2978. * @arg @ref LL_ADC_OVS_REG_DISCONT
  2979. * @retval None
  2980. */
  2981. __STATIC_INLINE void LL_ADC_SetOverSamplingDiscont(ADC_TypeDef *ADCx, uint32_t OverSamplingDiscont)
  2982. {
  2983. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_TOVS, OverSamplingDiscont);
  2984. }
  2985. /**
  2986. * @brief Get ADC oversampling discontinuous mode (triggered mode)
  2987. * on the selected ADC group.
  2988. * @note Number of oversampled conversions are done either in:
  2989. * - continuous mode (all conversions of oversampling ratio
  2990. * are done from 1 trigger)
  2991. * - discontinuous mode (each conversion of oversampling ratio
  2992. * needs a trigger)
  2993. * @rmtoll CFGR2 TOVS LL_ADC_GetOverSamplingDiscont
  2994. * @param ADCx ADC instance
  2995. * @retval Returned value can be one of the following values:
  2996. * @arg @ref LL_ADC_OVS_REG_CONT
  2997. * @arg @ref LL_ADC_OVS_REG_DISCONT
  2998. */
  2999. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingDiscont(ADC_TypeDef *ADCx)
  3000. {
  3001. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_TOVS));
  3002. }
  3003. /**
  3004. * @brief Set ADC oversampling
  3005. * @note This function set the 2 items of oversampling configuration:
  3006. * - ratio
  3007. * - shift
  3008. * @note On this STM32 series, setting of this feature is conditioned to
  3009. * ADC state:
  3010. * ADC must be disabled or enabled without conversion on going
  3011. * on group regular.
  3012. * @rmtoll CFGR2 OVSS LL_ADC_ConfigOverSamplingRatioShift\n
  3013. * CFGR2 OVSR LL_ADC_ConfigOverSamplingRatioShift
  3014. * @param ADCx ADC instance
  3015. * @param Ratio This parameter can be one of the following values:
  3016. * @arg @ref LL_ADC_OVS_RATIO_2
  3017. * @arg @ref LL_ADC_OVS_RATIO_4
  3018. * @arg @ref LL_ADC_OVS_RATIO_8
  3019. * @arg @ref LL_ADC_OVS_RATIO_16
  3020. * @arg @ref LL_ADC_OVS_RATIO_32
  3021. * @arg @ref LL_ADC_OVS_RATIO_64
  3022. * @arg @ref LL_ADC_OVS_RATIO_128
  3023. * @arg @ref LL_ADC_OVS_RATIO_256
  3024. * @param Shift This parameter can be one of the following values:
  3025. * @arg @ref LL_ADC_OVS_SHIFT_NONE
  3026. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_1
  3027. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_2
  3028. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_3
  3029. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_4
  3030. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_5
  3031. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_6
  3032. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_7
  3033. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_8
  3034. * @retval None
  3035. */
  3036. __STATIC_INLINE void LL_ADC_ConfigOverSamplingRatioShift(ADC_TypeDef *ADCx, uint32_t Ratio, uint32_t Shift)
  3037. {
  3038. MODIFY_REG(ADCx->CFGR2, (ADC_CFGR2_OVSS | ADC_CFGR2_OVSR), (Shift | Ratio));
  3039. }
  3040. /**
  3041. * @brief Get ADC oversampling ratio
  3042. * @rmtoll CFGR2 OVSR LL_ADC_GetOverSamplingRatio
  3043. * @param ADCx ADC instance
  3044. * @retval Ratio This parameter can be one of the following values:
  3045. * @arg @ref LL_ADC_OVS_RATIO_2
  3046. * @arg @ref LL_ADC_OVS_RATIO_4
  3047. * @arg @ref LL_ADC_OVS_RATIO_8
  3048. * @arg @ref LL_ADC_OVS_RATIO_16
  3049. * @arg @ref LL_ADC_OVS_RATIO_32
  3050. * @arg @ref LL_ADC_OVS_RATIO_64
  3051. * @arg @ref LL_ADC_OVS_RATIO_128
  3052. * @arg @ref LL_ADC_OVS_RATIO_256
  3053. */
  3054. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingRatio(ADC_TypeDef *ADCx)
  3055. {
  3056. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_OVSR));
  3057. }
  3058. /**
  3059. * @brief Get ADC oversampling shift
  3060. * @rmtoll CFGR2 OVSS LL_ADC_GetOverSamplingShift
  3061. * @param ADCx ADC instance
  3062. * @retval Shift This parameter can be one of the following values:
  3063. * @arg @ref LL_ADC_OVS_SHIFT_NONE
  3064. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_1
  3065. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_2
  3066. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_3
  3067. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_4
  3068. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_5
  3069. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_6
  3070. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_7
  3071. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_8
  3072. */
  3073. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingShift(ADC_TypeDef *ADCx)
  3074. {
  3075. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_OVSS));
  3076. }
  3077. /**
  3078. * @}
  3079. */
  3080. /** @defgroup ADC_LL_EF_Operation_ADC_Instance Operation on ADC hierarchical scope: ADC instance
  3081. * @{
  3082. */
  3083. /**
  3084. * @brief Enable ADC instance internal voltage regulator.
  3085. * @note On this STM32 series, there are three possibilities to enable
  3086. * the voltage regulator:
  3087. * - by enabling it manually
  3088. * using function @ref LL_ADC_EnableInternalRegulator().
  3089. * - by launching a calibration
  3090. * using function @ref LL_ADC_StartCalibration().
  3091. * - by enabling the ADC
  3092. * using function @ref LL_ADC_Enable().
  3093. * @note On this STM32 series, after ADC internal voltage regulator enable,
  3094. * a delay for ADC internal voltage regulator stabilization
  3095. * is required before performing a ADC calibration or ADC enable.
  3096. * Refer to device datasheet, parameter "tUP_LDO".
  3097. * Refer to literal @ref LL_ADC_DELAY_INTERNAL_REGUL_STAB_US.
  3098. * @note On this STM32 series, setting of this feature is conditioned to
  3099. * ADC state:
  3100. * ADC must be ADC disabled.
  3101. * @rmtoll CR ADVREGEN LL_ADC_EnableInternalRegulator
  3102. * @param ADCx ADC instance
  3103. * @retval None
  3104. */
  3105. __STATIC_INLINE void LL_ADC_EnableInternalRegulator(ADC_TypeDef *ADCx)
  3106. {
  3107. /* Note: Write register with some additional bits forced to state reset */
  3108. /* instead of modifying only the selected bit for this function, */
  3109. /* to not interfere with bits with HW property "rs". */
  3110. MODIFY_REG(ADCx->CR,
  3111. ADC_CR_BITS_PROPERTY_RS,
  3112. ADC_CR_ADVREGEN);
  3113. }
  3114. /**
  3115. * @brief Disable ADC internal voltage regulator.
  3116. * @note On this STM32 series, setting of this feature is conditioned to
  3117. * ADC state:
  3118. * ADC must be ADC disabled.
  3119. * @rmtoll CR ADVREGEN LL_ADC_DisableInternalRegulator
  3120. * @param ADCx ADC instance
  3121. * @retval None
  3122. */
  3123. __STATIC_INLINE void LL_ADC_DisableInternalRegulator(ADC_TypeDef *ADCx)
  3124. {
  3125. CLEAR_BIT(ADCx->CR, (ADC_CR_ADVREGEN | ADC_CR_BITS_PROPERTY_RS));
  3126. }
  3127. /**
  3128. * @brief Get the selected ADC instance internal voltage regulator state.
  3129. * @rmtoll CR ADVREGEN LL_ADC_IsInternalRegulatorEnabled
  3130. * @param ADCx ADC instance
  3131. * @retval 0: internal regulator is disabled, 1: internal regulator is enabled.
  3132. */
  3133. __STATIC_INLINE uint32_t LL_ADC_IsInternalRegulatorEnabled(ADC_TypeDef *ADCx)
  3134. {
  3135. return (READ_BIT(ADCx->CR, ADC_CR_ADVREGEN) == (ADC_CR_ADVREGEN));
  3136. }
  3137. /**
  3138. * @brief Enable the selected ADC instance.
  3139. * @note On this STM32 series, after ADC enable, a delay for
  3140. * ADC internal analog stabilization is required before performing a
  3141. * ADC conversion start.
  3142. * Refer to device datasheet, parameter tSTAB.
  3143. * @note On this STM32 series, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  3144. * is enabled and when conversion clock is active.
  3145. * (not only core clock: this ADC has a dual clock domain)
  3146. * @note On this STM32 series, setting of this feature is conditioned to
  3147. * ADC state:
  3148. * ADC must be ADC disabled and ADC internal voltage regulator enabled.
  3149. * @rmtoll CR ADEN LL_ADC_Enable
  3150. * @param ADCx ADC instance
  3151. * @retval None
  3152. */
  3153. __STATIC_INLINE void LL_ADC_Enable(ADC_TypeDef *ADCx)
  3154. {
  3155. /* Note: Write register with some additional bits forced to state reset */
  3156. /* instead of modifying only the selected bit for this function, */
  3157. /* to not interfere with bits with HW property "rs". */
  3158. MODIFY_REG(ADCx->CR,
  3159. ADC_CR_BITS_PROPERTY_RS,
  3160. ADC_CR_ADEN);
  3161. }
  3162. /**
  3163. * @brief Disable the selected ADC instance.
  3164. * @note On this STM32 series, setting of this feature is conditioned to
  3165. * ADC state:
  3166. * ADC must be not disabled. Must be enabled without conversion on going
  3167. * on group regular.
  3168. * @rmtoll CR ADDIS LL_ADC_Disable
  3169. * @param ADCx ADC instance
  3170. * @retval None
  3171. */
  3172. __STATIC_INLINE void LL_ADC_Disable(ADC_TypeDef *ADCx)
  3173. {
  3174. /* Note: Write register with some additional bits forced to state reset */
  3175. /* instead of modifying only the selected bit for this function, */
  3176. /* to not interfere with bits with HW property "rs". */
  3177. MODIFY_REG(ADCx->CR,
  3178. ADC_CR_BITS_PROPERTY_RS,
  3179. ADC_CR_ADDIS);
  3180. }
  3181. /**
  3182. * @brief Get the selected ADC instance enable state.
  3183. * @note On this STM32 series, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  3184. * is enabled and when conversion clock is active.
  3185. * (not only core clock: this ADC has a dual clock domain)
  3186. * @rmtoll CR ADEN LL_ADC_IsEnabled
  3187. * @param ADCx ADC instance
  3188. * @retval 0: ADC is disabled, 1: ADC is enabled.
  3189. */
  3190. __STATIC_INLINE uint32_t LL_ADC_IsEnabled(ADC_TypeDef *ADCx)
  3191. {
  3192. return (READ_BIT(ADCx->CR, ADC_CR_ADEN) == (ADC_CR_ADEN));
  3193. }
  3194. /**
  3195. * @brief Get the selected ADC instance disable state.
  3196. * @rmtoll CR ADDIS LL_ADC_IsDisableOngoing
  3197. * @param ADCx ADC instance
  3198. * @retval 0: no ADC disable command on going.
  3199. */
  3200. __STATIC_INLINE uint32_t LL_ADC_IsDisableOngoing(ADC_TypeDef *ADCx)
  3201. {
  3202. return (READ_BIT(ADCx->CR, ADC_CR_ADDIS) == (ADC_CR_ADDIS));
  3203. }
  3204. /**
  3205. * @brief Start ADC calibration in the mode single-ended
  3206. * or differential (for devices with differential mode available).
  3207. * @note On this STM32 series, a minimum number of ADC clock cycles
  3208. * are required between ADC end of calibration and ADC enable.
  3209. * Refer to literal @ref LL_ADC_DELAY_CALIB_ENABLE_ADC_CYCLES.
  3210. * @note In case of usage of ADC with DMA transfer:
  3211. * On this STM32 series, ADC DMA transfer request should be disabled
  3212. * during calibration:
  3213. * Calibration factor is available in data register
  3214. * and also transferred by DMA.
  3215. * To not insert ADC calibration factor among ADC conversion data
  3216. * in array variable, DMA transfer must be disabled during
  3217. * calibration.
  3218. * (DMA transfer setting backup and disable before calibration,
  3219. * DMA transfer setting restore after calibration.
  3220. * Refer to functions @ref LL_ADC_REG_GetDMATransfer(),
  3221. * @ref LL_ADC_REG_SetDMATransfer() ).
  3222. * @note On this STM32 series, setting of this feature is conditioned to
  3223. * ADC state:
  3224. * ADC must be ADC disabled.
  3225. * @rmtoll CR ADCAL LL_ADC_StartCalibration
  3226. * @param ADCx ADC instance
  3227. * @retval None
  3228. */
  3229. __STATIC_INLINE void LL_ADC_StartCalibration(ADC_TypeDef *ADCx)
  3230. {
  3231. /* Note: Write register with some additional bits forced to state reset */
  3232. /* instead of modifying only the selected bit for this function, */
  3233. /* to not interfere with bits with HW property "rs". */
  3234. MODIFY_REG(ADCx->CR,
  3235. ADC_CR_BITS_PROPERTY_RS,
  3236. ADC_CR_ADCAL);
  3237. }
  3238. /**
  3239. * @brief Get ADC calibration state.
  3240. * @rmtoll CR ADCAL LL_ADC_IsCalibrationOnGoing
  3241. * @param ADCx ADC instance
  3242. * @retval 0: calibration complete, 1: calibration in progress.
  3243. */
  3244. __STATIC_INLINE uint32_t LL_ADC_IsCalibrationOnGoing(ADC_TypeDef *ADCx)
  3245. {
  3246. return (READ_BIT(ADCx->CR, ADC_CR_ADCAL) == (ADC_CR_ADCAL));
  3247. }
  3248. /**
  3249. * @}
  3250. */
  3251. /** @defgroup ADC_LL_EF_Operation_ADC_Group_Regular Operation on ADC hierarchical scope: group regular
  3252. * @{
  3253. */
  3254. /**
  3255. * @brief Start ADC group regular conversion.
  3256. * @note On this STM32 series, this function is relevant for both
  3257. * internal trigger (SW start) and external trigger:
  3258. * - If ADC trigger has been set to software start, ADC conversion
  3259. * starts immediately.
  3260. * - If ADC trigger has been set to external trigger, ADC conversion
  3261. * will start at next trigger event (on the selected trigger edge)
  3262. * following the ADC start conversion command.
  3263. * @note On this STM32 series, setting of this feature is conditioned to
  3264. * ADC state:
  3265. * ADC must be enabled without conversion on going on group regular,
  3266. * without conversion stop command on going on group regular,
  3267. * without ADC disable command on going.
  3268. * @rmtoll CR ADSTART LL_ADC_REG_StartConversion
  3269. * @param ADCx ADC instance
  3270. * @retval None
  3271. */
  3272. __STATIC_INLINE void LL_ADC_REG_StartConversion(ADC_TypeDef *ADCx)
  3273. {
  3274. /* Note: Write register with some additional bits forced to state reset */
  3275. /* instead of modifying only the selected bit for this function, */
  3276. /* to not interfere with bits with HW property "rs". */
  3277. MODIFY_REG(ADCx->CR,
  3278. ADC_CR_BITS_PROPERTY_RS,
  3279. ADC_CR_ADSTART);
  3280. }
  3281. /**
  3282. * @brief Stop ADC group regular conversion.
  3283. * @note On this STM32 series, setting of this feature is conditioned to
  3284. * ADC state:
  3285. * ADC must be enabled with conversion on going on group regular,
  3286. * without ADC disable command on going.
  3287. * @rmtoll CR ADSTP LL_ADC_REG_StopConversion
  3288. * @param ADCx ADC instance
  3289. * @retval None
  3290. */
  3291. __STATIC_INLINE void LL_ADC_REG_StopConversion(ADC_TypeDef *ADCx)
  3292. {
  3293. /* Note: Write register with some additional bits forced to state reset */
  3294. /* instead of modifying only the selected bit for this function, */
  3295. /* to not interfere with bits with HW property "rs". */
  3296. MODIFY_REG(ADCx->CR,
  3297. ADC_CR_BITS_PROPERTY_RS,
  3298. ADC_CR_ADSTP);
  3299. }
  3300. /**
  3301. * @brief Get ADC group regular conversion state.
  3302. * @rmtoll CR ADSTART LL_ADC_REG_IsConversionOngoing
  3303. * @param ADCx ADC instance
  3304. * @retval 0: no conversion is on going on ADC group regular.
  3305. */
  3306. __STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
  3307. {
  3308. return (READ_BIT(ADCx->CR, ADC_CR_ADSTART) == (ADC_CR_ADSTART));
  3309. }
  3310. /**
  3311. * @brief Get ADC group regular command of conversion stop state
  3312. * @rmtoll CR ADSTP LL_ADC_REG_IsStopConversionOngoing
  3313. * @param ADCx ADC instance
  3314. * @retval 0: no command of conversion stop is on going on ADC group regular.
  3315. */
  3316. __STATIC_INLINE uint32_t LL_ADC_REG_IsStopConversionOngoing(ADC_TypeDef *ADCx)
  3317. {
  3318. return (READ_BIT(ADCx->CR, ADC_CR_ADSTP) == (ADC_CR_ADSTP));
  3319. }
  3320. /**
  3321. * @brief Get ADC group regular conversion data, range fit for
  3322. * all ADC configurations: all ADC resolutions and
  3323. * all oversampling increased data width (for devices
  3324. * with feature oversampling).
  3325. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData32
  3326. * @param ADCx ADC instance
  3327. * @retval Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  3328. */
  3329. __STATIC_INLINE uint32_t LL_ADC_REG_ReadConversionData32(ADC_TypeDef *ADCx)
  3330. {
  3331. return (uint32_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  3332. }
  3333. /**
  3334. * @brief Get ADC group regular conversion data, range fit for
  3335. * ADC resolution 12 bits.
  3336. * @note For devices with feature oversampling: Oversampling
  3337. * can increase data width, function for extended range
  3338. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  3339. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData12
  3340. * @param ADCx ADC instance
  3341. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  3342. */
  3343. __STATIC_INLINE uint16_t LL_ADC_REG_ReadConversionData12(ADC_TypeDef *ADCx)
  3344. {
  3345. return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  3346. }
  3347. /**
  3348. * @brief Get ADC group regular conversion data, range fit for
  3349. * ADC resolution 10 bits.
  3350. * @note For devices with feature oversampling: Oversampling
  3351. * can increase data width, function for extended range
  3352. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  3353. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData10
  3354. * @param ADCx ADC instance
  3355. * @retval Value between Min_Data=0x000 and Max_Data=0x3FF
  3356. */
  3357. __STATIC_INLINE uint16_t LL_ADC_REG_ReadConversionData10(ADC_TypeDef *ADCx)
  3358. {
  3359. return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  3360. }
  3361. /**
  3362. * @brief Get ADC group regular conversion data, range fit for
  3363. * ADC resolution 8 bits.
  3364. * @note For devices with feature oversampling: Oversampling
  3365. * can increase data width, function for extended range
  3366. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  3367. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData8
  3368. * @param ADCx ADC instance
  3369. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  3370. */
  3371. __STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData8(ADC_TypeDef *ADCx)
  3372. {
  3373. return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  3374. }
  3375. /**
  3376. * @brief Get ADC group regular conversion data, range fit for
  3377. * ADC resolution 6 bits.
  3378. * @note For devices with feature oversampling: Oversampling
  3379. * can increase data width, function for extended range
  3380. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  3381. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData6
  3382. * @param ADCx ADC instance
  3383. * @retval Value between Min_Data=0x00 and Max_Data=0x3F
  3384. */
  3385. __STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData6(ADC_TypeDef *ADCx)
  3386. {
  3387. return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  3388. }
  3389. /**
  3390. * @}
  3391. */
  3392. /** @defgroup ADC_LL_EF_FLAG_Management ADC flag management
  3393. * @{
  3394. */
  3395. /**
  3396. * @brief Get flag ADC ready.
  3397. * @note On this STM32 series, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  3398. * is enabled and when conversion clock is active.
  3399. * (not only core clock: this ADC has a dual clock domain)
  3400. * @rmtoll ISR ADRDY LL_ADC_IsActiveFlag_ADRDY
  3401. * @param ADCx ADC instance
  3402. * @retval State of bit (1 or 0).
  3403. */
  3404. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_ADRDY(ADC_TypeDef *ADCx)
  3405. {
  3406. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_ADRDY) == (LL_ADC_FLAG_ADRDY));
  3407. }
  3408. /**
  3409. * @brief Get flag ADC group regular end of unitary conversion.
  3410. * @rmtoll ISR EOC LL_ADC_IsActiveFlag_EOC
  3411. * @param ADCx ADC instance
  3412. * @retval State of bit (1 or 0).
  3413. */
  3414. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOC(ADC_TypeDef *ADCx)
  3415. {
  3416. return (READ_BIT(ADCx->ISR, ADC_ISR_EOC) == (ADC_ISR_EOC));
  3417. }
  3418. /**
  3419. * @brief Get flag ADC group regular end of sequence conversions.
  3420. * @rmtoll ISR EOSEQ LL_ADC_IsActiveFlag_EOS
  3421. * @param ADCx ADC instance
  3422. * @retval State of bit (1 or 0).
  3423. */
  3424. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOS(ADC_TypeDef *ADCx)
  3425. {
  3426. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOS) == (LL_ADC_FLAG_EOS));
  3427. }
  3428. /**
  3429. * @brief Get flag ADC group regular overrun.
  3430. * @rmtoll ISR OVR LL_ADC_IsActiveFlag_OVR
  3431. * @param ADCx ADC instance
  3432. * @retval State of bit (1 or 0).
  3433. */
  3434. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_OVR(ADC_TypeDef *ADCx)
  3435. {
  3436. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_OVR) == (LL_ADC_FLAG_OVR));
  3437. }
  3438. /**
  3439. * @brief Get flag ADC group regular end of sampling phase.
  3440. * @rmtoll ISR EOSMP LL_ADC_IsActiveFlag_EOSMP
  3441. * @param ADCx ADC instance
  3442. * @retval State of bit (1 or 0).
  3443. */
  3444. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOSMP(ADC_TypeDef *ADCx)
  3445. {
  3446. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOSMP) == (LL_ADC_FLAG_EOSMP));
  3447. }
  3448. /**
  3449. * @brief Get flag ADC analog watchdog 1 flag
  3450. * @rmtoll ISR AWD LL_ADC_IsActiveFlag_AWD1
  3451. * @param ADCx ADC instance
  3452. * @retval State of bit (1 or 0).
  3453. */
  3454. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_AWD1(ADC_TypeDef *ADCx)
  3455. {
  3456. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_AWD1) == (LL_ADC_FLAG_AWD1));
  3457. }
  3458. /**
  3459. * @brief Get flag ADC end of calibration.
  3460. * @rmtoll ISR EOCAL LL_ADC_IsActiveFlag_EOCAL
  3461. * @param ADCx ADC instance
  3462. * @retval State of bit (1 or 0).
  3463. */
  3464. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOCAL(ADC_TypeDef *ADCx)
  3465. {
  3466. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOCAL) == (LL_ADC_FLAG_EOCAL));
  3467. }
  3468. /**
  3469. * @brief Clear flag ADC ready.
  3470. * @note On this STM32 series, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  3471. * is enabled and when conversion clock is active.
  3472. * (not only core clock: this ADC has a dual clock domain)
  3473. * @rmtoll ISR ADRDY LL_ADC_ClearFlag_ADRDY
  3474. * @param ADCx ADC instance
  3475. * @retval None
  3476. */
  3477. __STATIC_INLINE void LL_ADC_ClearFlag_ADRDY(ADC_TypeDef *ADCx)
  3478. {
  3479. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_ADRDY);
  3480. }
  3481. /**
  3482. * @brief Clear flag ADC group regular end of unitary conversion.
  3483. * @rmtoll ISR EOC LL_ADC_ClearFlag_EOC
  3484. * @param ADCx ADC instance
  3485. * @retval None
  3486. */
  3487. __STATIC_INLINE void LL_ADC_ClearFlag_EOC(ADC_TypeDef *ADCx)
  3488. {
  3489. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOC);
  3490. }
  3491. /**
  3492. * @brief Clear flag ADC group regular end of sequence conversions.
  3493. * @rmtoll ISR EOSEQ LL_ADC_ClearFlag_EOS
  3494. * @param ADCx ADC instance
  3495. * @retval None
  3496. */
  3497. __STATIC_INLINE void LL_ADC_ClearFlag_EOS(ADC_TypeDef *ADCx)
  3498. {
  3499. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOS);
  3500. }
  3501. /**
  3502. * @brief Clear flag ADC group regular overrun.
  3503. * @rmtoll ISR OVR LL_ADC_ClearFlag_OVR
  3504. * @param ADCx ADC instance
  3505. * @retval None
  3506. */
  3507. __STATIC_INLINE void LL_ADC_ClearFlag_OVR(ADC_TypeDef *ADCx)
  3508. {
  3509. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_OVR);
  3510. }
  3511. /**
  3512. * @brief Clear flag ADC group regular end of sampling phase.
  3513. * @rmtoll ISR EOSMP LL_ADC_ClearFlag_EOSMP
  3514. * @param ADCx ADC instance
  3515. * @retval None
  3516. */
  3517. __STATIC_INLINE void LL_ADC_ClearFlag_EOSMP(ADC_TypeDef *ADCx)
  3518. {
  3519. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOSMP);
  3520. }
  3521. /**
  3522. * @brief Clear flag ADC analog watchdog 1.
  3523. * @rmtoll ISR AWD LL_ADC_ClearFlag_AWD1
  3524. * @param ADCx ADC instance
  3525. * @retval None
  3526. */
  3527. __STATIC_INLINE void LL_ADC_ClearFlag_AWD1(ADC_TypeDef *ADCx)
  3528. {
  3529. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_AWD1);
  3530. }
  3531. /**
  3532. * @brief Clear flag ADC end of calibration.
  3533. * @rmtoll ISR EOCAL LL_ADC_ClearFlag_EOCAL
  3534. * @param ADCx ADC instance
  3535. * @retval None
  3536. */
  3537. __STATIC_INLINE void LL_ADC_ClearFlag_EOCAL(ADC_TypeDef *ADCx)
  3538. {
  3539. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOCAL);
  3540. }
  3541. /**
  3542. * @}
  3543. */
  3544. /** @defgroup ADC_LL_EF_IT_Management ADC IT management
  3545. * @{
  3546. */
  3547. /**
  3548. * @brief Enable ADC ready.
  3549. * @rmtoll IER ADRDYIE LL_ADC_EnableIT_ADRDY
  3550. * @param ADCx ADC instance
  3551. * @retval None
  3552. */
  3553. __STATIC_INLINE void LL_ADC_EnableIT_ADRDY(ADC_TypeDef *ADCx)
  3554. {
  3555. SET_BIT(ADCx->IER, LL_ADC_IT_ADRDY);
  3556. }
  3557. /**
  3558. * @brief Enable interruption ADC group regular end of unitary conversion.
  3559. * @rmtoll IER EOCIE LL_ADC_EnableIT_EOC
  3560. * @param ADCx ADC instance
  3561. * @retval None
  3562. */
  3563. __STATIC_INLINE void LL_ADC_EnableIT_EOC(ADC_TypeDef *ADCx)
  3564. {
  3565. SET_BIT(ADCx->IER, LL_ADC_IT_EOC);
  3566. }
  3567. /**
  3568. * @brief Enable interruption ADC group regular end of sequence conversions.
  3569. * @rmtoll IER EOSEQIE LL_ADC_EnableIT_EOS
  3570. * @param ADCx ADC instance
  3571. * @retval None
  3572. */
  3573. __STATIC_INLINE void LL_ADC_EnableIT_EOS(ADC_TypeDef *ADCx)
  3574. {
  3575. SET_BIT(ADCx->IER, LL_ADC_IT_EOS);
  3576. }
  3577. /**
  3578. * @brief Enable ADC group regular interruption overrun.
  3579. * @rmtoll IER OVRIE LL_ADC_EnableIT_OVR
  3580. * @param ADCx ADC instance
  3581. * @retval None
  3582. */
  3583. __STATIC_INLINE void LL_ADC_EnableIT_OVR(ADC_TypeDef *ADCx)
  3584. {
  3585. SET_BIT(ADCx->IER, LL_ADC_IT_OVR);
  3586. }
  3587. /**
  3588. * @brief Enable interruption ADC group regular end of sampling.
  3589. * @rmtoll IER EOSMPIE LL_ADC_EnableIT_EOSMP
  3590. * @param ADCx ADC instance
  3591. * @retval None
  3592. */
  3593. __STATIC_INLINE void LL_ADC_EnableIT_EOSMP(ADC_TypeDef *ADCx)
  3594. {
  3595. SET_BIT(ADCx->IER, LL_ADC_IT_EOSMP);
  3596. }
  3597. /**
  3598. * @brief Enable interruption ADC analog watchdog 1.
  3599. * @rmtoll IER AWDIE LL_ADC_EnableIT_AWD1
  3600. * @param ADCx ADC instance
  3601. * @retval None
  3602. */
  3603. __STATIC_INLINE void LL_ADC_EnableIT_AWD1(ADC_TypeDef *ADCx)
  3604. {
  3605. SET_BIT(ADCx->IER, LL_ADC_IT_AWD1);
  3606. }
  3607. /**
  3608. * @brief Enable interruption ADC end of calibration.
  3609. * @rmtoll IER EOCALIE LL_ADC_EnableIT_EOCAL
  3610. * @param ADCx ADC instance
  3611. * @retval None
  3612. */
  3613. __STATIC_INLINE void LL_ADC_EnableIT_EOCAL(ADC_TypeDef *ADCx)
  3614. {
  3615. SET_BIT(ADCx->IER, LL_ADC_IT_EOCAL);
  3616. }
  3617. /**
  3618. * @brief Disable interruption ADC ready.
  3619. * @rmtoll IER ADRDYIE LL_ADC_DisableIT_ADRDY
  3620. * @param ADCx ADC instance
  3621. * @retval None
  3622. */
  3623. __STATIC_INLINE void LL_ADC_DisableIT_ADRDY(ADC_TypeDef *ADCx)
  3624. {
  3625. CLEAR_BIT(ADCx->IER, LL_ADC_IT_ADRDY);
  3626. }
  3627. /**
  3628. * @brief Disable interruption ADC group regular end of unitary conversion.
  3629. * @rmtoll IER EOCIE LL_ADC_DisableIT_EOC
  3630. * @param ADCx ADC instance
  3631. * @retval None
  3632. */
  3633. __STATIC_INLINE void LL_ADC_DisableIT_EOC(ADC_TypeDef *ADCx)
  3634. {
  3635. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOC);
  3636. }
  3637. /**
  3638. * @brief Disable interruption ADC group regular end of sequence conversions.
  3639. * @rmtoll IER EOSEQIE LL_ADC_DisableIT_EOS
  3640. * @param ADCx ADC instance
  3641. * @retval None
  3642. */
  3643. __STATIC_INLINE void LL_ADC_DisableIT_EOS(ADC_TypeDef *ADCx)
  3644. {
  3645. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOS);
  3646. }
  3647. /**
  3648. * @brief Disable interruption ADC group regular overrun.
  3649. * @rmtoll IER OVRIE LL_ADC_DisableIT_OVR
  3650. * @param ADCx ADC instance
  3651. * @retval None
  3652. */
  3653. __STATIC_INLINE void LL_ADC_DisableIT_OVR(ADC_TypeDef *ADCx)
  3654. {
  3655. CLEAR_BIT(ADCx->IER, LL_ADC_IT_OVR);
  3656. }
  3657. /**
  3658. * @brief Disable interruption ADC group regular end of sampling.
  3659. * @rmtoll IER EOSMPIE LL_ADC_DisableIT_EOSMP
  3660. * @param ADCx ADC instance
  3661. * @retval None
  3662. */
  3663. __STATIC_INLINE void LL_ADC_DisableIT_EOSMP(ADC_TypeDef *ADCx)
  3664. {
  3665. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOSMP);
  3666. }
  3667. /**
  3668. * @brief Disable interruption ADC analog watchdog 1.
  3669. * @rmtoll IER AWDIE LL_ADC_DisableIT_AWD1
  3670. * @param ADCx ADC instance
  3671. * @retval None
  3672. */
  3673. __STATIC_INLINE void LL_ADC_DisableIT_AWD1(ADC_TypeDef *ADCx)
  3674. {
  3675. CLEAR_BIT(ADCx->IER, LL_ADC_IT_AWD1);
  3676. }
  3677. /**
  3678. * @brief Disable interruption ADC end of calibration.
  3679. * @rmtoll IER EOCALIE LL_ADC_DisableIT_EOCAL
  3680. * @param ADCx ADC instance
  3681. * @retval None
  3682. */
  3683. __STATIC_INLINE void LL_ADC_DisableIT_EOCAL(ADC_TypeDef *ADCx)
  3684. {
  3685. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOCAL);
  3686. }
  3687. /**
  3688. * @brief Get state of interruption ADC ready
  3689. * (0: interrupt disabled, 1: interrupt enabled).
  3690. * @rmtoll IER ADRDYIE LL_ADC_IsEnabledIT_ADRDY
  3691. * @param ADCx ADC instance
  3692. * @retval State of bit (1 or 0).
  3693. */
  3694. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_ADRDY(ADC_TypeDef *ADCx)
  3695. {
  3696. return (READ_BIT(ADCx->IER, LL_ADC_IT_ADRDY) == (LL_ADC_IT_ADRDY));
  3697. }
  3698. /**
  3699. * @brief Get state of interruption ADC group regular end of unitary conversion
  3700. * (0: interrupt disabled, 1: interrupt enabled).
  3701. * @rmtoll IER EOCIE LL_ADC_IsEnabledIT_EOC
  3702. * @param ADCx ADC instance
  3703. * @retval State of bit (1 or 0).
  3704. */
  3705. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOC(ADC_TypeDef *ADCx)
  3706. {
  3707. return (READ_BIT(ADCx->IER, LL_ADC_IT_EOC) == (LL_ADC_IT_EOC));
  3708. }
  3709. /**
  3710. * @brief Get state of interruption ADC group regular end of sequence conversions
  3711. * (0: interrupt disabled, 1: interrupt enabled).
  3712. * @rmtoll IER EOSEQIE LL_ADC_IsEnabledIT_EOS
  3713. * @param ADCx ADC instance
  3714. * @retval State of bit (1 or 0).
  3715. */
  3716. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOS(ADC_TypeDef *ADCx)
  3717. {
  3718. return (READ_BIT(ADCx->IER, LL_ADC_IT_EOS) == (LL_ADC_IT_EOS));
  3719. }
  3720. /**
  3721. * @brief Get state of interruption ADC group regular overrun
  3722. * (0: interrupt disabled, 1: interrupt enabled).
  3723. * @rmtoll IER OVRIE LL_ADC_IsEnabledIT_OVR
  3724. * @param ADCx ADC instance
  3725. * @retval State of bit (1 or 0).
  3726. */
  3727. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_OVR(ADC_TypeDef *ADCx)
  3728. {
  3729. return (READ_BIT(ADCx->IER, LL_ADC_IT_OVR) == (LL_ADC_IT_OVR));
  3730. }
  3731. /**
  3732. * @brief Get state of interruption ADC group regular end of sampling
  3733. * (0: interrupt disabled, 1: interrupt enabled).
  3734. * @rmtoll IER EOSMPIE LL_ADC_IsEnabledIT_EOSMP
  3735. * @param ADCx ADC instance
  3736. * @retval State of bit (1 or 0).
  3737. */
  3738. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOSMP(ADC_TypeDef *ADCx)
  3739. {
  3740. return (READ_BIT(ADCx->IER, LL_ADC_IT_EOSMP) == (LL_ADC_IT_EOSMP));
  3741. }
  3742. /**
  3743. * @brief Get state of interruption ADC analog watchdog 1
  3744. * (0: interrupt disabled, 1: interrupt enabled).
  3745. * @rmtoll IER AWDIE LL_ADC_IsEnabledIT_AWD1
  3746. * @param ADCx ADC instance
  3747. * @retval State of bit (1 or 0).
  3748. */
  3749. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_AWD1(ADC_TypeDef *ADCx)
  3750. {
  3751. return (READ_BIT(ADCx->IER, LL_ADC_IT_AWD1) == (LL_ADC_IT_AWD1));
  3752. }
  3753. /**
  3754. * @brief Get state of interruption ADC end of calibration
  3755. * (0: interrupt disabled, 1: interrupt enabled).
  3756. * @rmtoll IER EOCALIE LL_ADC_IsEnabledIT_EOCAL
  3757. * @param ADCx ADC instance
  3758. * @retval State of bit (1 or 0).
  3759. */
  3760. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOCAL(ADC_TypeDef *ADCx)
  3761. {
  3762. return (READ_BIT(ADCx->IER, LL_ADC_IT_EOCAL) == (LL_ADC_IT_EOCAL));
  3763. }
  3764. /**
  3765. * @}
  3766. */
  3767. #if defined(USE_FULL_LL_DRIVER)
  3768. /** @defgroup ADC_LL_EF_Init Initialization and de-initialization functions
  3769. * @{
  3770. */
  3771. /* Initialization of some features of ADC common parameters and multimode */
  3772. ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON);
  3773. ErrorStatus LL_ADC_CommonInit(ADC_Common_TypeDef *ADCxy_COMMON, LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct);
  3774. void LL_ADC_CommonStructInit(LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct);
  3775. /* De-initialization of ADC instance */
  3776. ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx);
  3777. /* Initialization of some features of ADC instance */
  3778. ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct);
  3779. void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct);
  3780. /* Initialization of some features of ADC instance and ADC group regular */
  3781. ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct);
  3782. void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct);
  3783. /**
  3784. * @}
  3785. */
  3786. #endif /* USE_FULL_LL_DRIVER */
  3787. /**
  3788. * @}
  3789. */
  3790. /**
  3791. * @}
  3792. */
  3793. #endif /* ADC1 */
  3794. /**
  3795. * @}
  3796. */
  3797. #ifdef __cplusplus
  3798. }
  3799. #endif
  3800. #endif /* __STM32L0xx_LL_ADC_H */