stm32f1xx_ll_tim.h 160 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_ll_tim.h
  4. * @author MCD Application Team
  5. * @brief Header file of TIM 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 __STM32F1xx_LL_TIM_H
  20. #define __STM32F1xx_LL_TIM_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32f1xx.h"
  26. /** @addtogroup STM32F1xx_LL_Driver
  27. * @{
  28. */
  29. #if defined (TIM1) || defined (TIM2) || defined (TIM3) || defined (TIM4) || defined (TIM5) || defined (TIM6) || defined (TIM7) || defined (TIM8) || defined (TIM9) || defined (TIM10) || defined (TIM11) || defined (TIM12) || defined (TIM13) || defined (TIM14) || defined (TIM15) || defined (TIM16) || defined (TIM17)
  30. /** @defgroup TIM_LL TIM
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /** @defgroup TIM_LL_Private_Variables TIM Private Variables
  36. * @{
  37. */
  38. static const uint8_t OFFSET_TAB_CCMRx[] =
  39. {
  40. 0x00U, /* 0: TIMx_CH1 */
  41. 0x00U, /* 1: TIMx_CH1N */
  42. 0x00U, /* 2: TIMx_CH2 */
  43. 0x00U, /* 3: TIMx_CH2N */
  44. 0x04U, /* 4: TIMx_CH3 */
  45. 0x04U, /* 5: TIMx_CH3N */
  46. 0x04U /* 6: TIMx_CH4 */
  47. };
  48. static const uint8_t SHIFT_TAB_OCxx[] =
  49. {
  50. 0U, /* 0: OC1M, OC1FE, OC1PE */
  51. 0U, /* 1: - NA */
  52. 8U, /* 2: OC2M, OC2FE, OC2PE */
  53. 0U, /* 3: - NA */
  54. 0U, /* 4: OC3M, OC3FE, OC3PE */
  55. 0U, /* 5: - NA */
  56. 8U /* 6: OC4M, OC4FE, OC4PE */
  57. };
  58. static const uint8_t SHIFT_TAB_ICxx[] =
  59. {
  60. 0U, /* 0: CC1S, IC1PSC, IC1F */
  61. 0U, /* 1: - NA */
  62. 8U, /* 2: CC2S, IC2PSC, IC2F */
  63. 0U, /* 3: - NA */
  64. 0U, /* 4: CC3S, IC3PSC, IC3F */
  65. 0U, /* 5: - NA */
  66. 8U /* 6: CC4S, IC4PSC, IC4F */
  67. };
  68. static const uint8_t SHIFT_TAB_CCxP[] =
  69. {
  70. 0U, /* 0: CC1P */
  71. 2U, /* 1: CC1NP */
  72. 4U, /* 2: CC2P */
  73. 6U, /* 3: CC2NP */
  74. 8U, /* 4: CC3P */
  75. 10U, /* 5: CC3NP */
  76. 12U /* 6: CC4P */
  77. };
  78. static const uint8_t SHIFT_TAB_OISx[] =
  79. {
  80. 0U, /* 0: OIS1 */
  81. 1U, /* 1: OIS1N */
  82. 2U, /* 2: OIS2 */
  83. 3U, /* 3: OIS2N */
  84. 4U, /* 4: OIS3 */
  85. 5U, /* 5: OIS3N */
  86. 6U /* 6: OIS4 */
  87. };
  88. /**
  89. * @}
  90. */
  91. /* Private constants ---------------------------------------------------------*/
  92. /** @defgroup TIM_LL_Private_Constants TIM Private Constants
  93. * @{
  94. */
  95. /* Mask used to set the TDG[x:0] of the DTG bits of the TIMx_BDTR register */
  96. #define DT_DELAY_1 ((uint8_t)0x7F)
  97. #define DT_DELAY_2 ((uint8_t)0x3F)
  98. #define DT_DELAY_3 ((uint8_t)0x1F)
  99. #define DT_DELAY_4 ((uint8_t)0x1F)
  100. /* Mask used to set the DTG[7:5] bits of the DTG bits of the TIMx_BDTR register */
  101. #define DT_RANGE_1 ((uint8_t)0x00)
  102. #define DT_RANGE_2 ((uint8_t)0x80)
  103. #define DT_RANGE_3 ((uint8_t)0xC0)
  104. #define DT_RANGE_4 ((uint8_t)0xE0)
  105. /**
  106. * @}
  107. */
  108. /* Private macros ------------------------------------------------------------*/
  109. /** @defgroup TIM_LL_Private_Macros TIM Private Macros
  110. * @{
  111. */
  112. /** @brief Convert channel id into channel index.
  113. * @param __CHANNEL__ This parameter can be one of the following values:
  114. * @arg @ref LL_TIM_CHANNEL_CH1
  115. * @arg @ref LL_TIM_CHANNEL_CH1N
  116. * @arg @ref LL_TIM_CHANNEL_CH2
  117. * @arg @ref LL_TIM_CHANNEL_CH2N
  118. * @arg @ref LL_TIM_CHANNEL_CH3
  119. * @arg @ref LL_TIM_CHANNEL_CH3N
  120. * @arg @ref LL_TIM_CHANNEL_CH4
  121. * @retval none
  122. */
  123. #define TIM_GET_CHANNEL_INDEX( __CHANNEL__) \
  124. (((__CHANNEL__) == LL_TIM_CHANNEL_CH1) ? 0U :\
  125. ((__CHANNEL__) == LL_TIM_CHANNEL_CH1N) ? 1U :\
  126. ((__CHANNEL__) == LL_TIM_CHANNEL_CH2) ? 2U :\
  127. ((__CHANNEL__) == LL_TIM_CHANNEL_CH2N) ? 3U :\
  128. ((__CHANNEL__) == LL_TIM_CHANNEL_CH3) ? 4U :\
  129. ((__CHANNEL__) == LL_TIM_CHANNEL_CH3N) ? 5U : 6U)
  130. /** @brief Calculate the deadtime sampling period(in ps).
  131. * @param __TIMCLK__ timer input clock frequency (in Hz).
  132. * @param __CKD__ This parameter can be one of the following values:
  133. * @arg @ref LL_TIM_CLOCKDIVISION_DIV1
  134. * @arg @ref LL_TIM_CLOCKDIVISION_DIV2
  135. * @arg @ref LL_TIM_CLOCKDIVISION_DIV4
  136. * @retval none
  137. */
  138. #define TIM_CALC_DTS(__TIMCLK__, __CKD__) \
  139. (((__CKD__) == LL_TIM_CLOCKDIVISION_DIV1) ? ((uint64_t)1000000000000U/(__TIMCLK__)) : \
  140. ((__CKD__) == LL_TIM_CLOCKDIVISION_DIV2) ? ((uint64_t)1000000000000U/((__TIMCLK__) >> 1U)) : \
  141. ((uint64_t)1000000000000U/((__TIMCLK__) >> 2U)))
  142. /**
  143. * @}
  144. */
  145. /* Exported types ------------------------------------------------------------*/
  146. #if defined(USE_FULL_LL_DRIVER)
  147. /** @defgroup TIM_LL_ES_INIT TIM Exported Init structure
  148. * @{
  149. */
  150. /**
  151. * @brief TIM Time Base configuration structure definition.
  152. */
  153. typedef struct
  154. {
  155. uint16_t Prescaler; /*!< Specifies the prescaler value used to divide the TIM clock.
  156. This parameter can be a number between Min_Data=0x0000 and Max_Data=0xFFFF.
  157. This feature can be modified afterwards using unitary function
  158. @ref LL_TIM_SetPrescaler().*/
  159. uint32_t CounterMode; /*!< Specifies the counter mode.
  160. This parameter can be a value of @ref TIM_LL_EC_COUNTERMODE.
  161. This feature can be modified afterwards using unitary function
  162. @ref LL_TIM_SetCounterMode().*/
  163. uint32_t Autoreload; /*!< Specifies the auto reload value to be loaded into the active
  164. Auto-Reload Register at the next update event.
  165. This parameter must be a number between Min_Data=0x0000 and Max_Data=0xFFFF.
  166. Some timer instances may support 32 bits counters. In that case this parameter must
  167. be a number between 0x0000 and 0xFFFFFFFF.
  168. This feature can be modified afterwards using unitary function
  169. @ref LL_TIM_SetAutoReload().*/
  170. uint32_t ClockDivision; /*!< Specifies the clock division.
  171. This parameter can be a value of @ref TIM_LL_EC_CLOCKDIVISION.
  172. This feature can be modified afterwards using unitary function
  173. @ref LL_TIM_SetClockDivision().*/
  174. uint32_t RepetitionCounter; /*!< Specifies the repetition counter value. Each time the RCR downcounter
  175. reaches zero, an update event is generated and counting restarts
  176. from the RCR value (N).
  177. This means in PWM mode that (N+1) corresponds to:
  178. - the number of PWM periods in edge-aligned mode
  179. - the number of half PWM period in center-aligned mode
  180. GP timers: this parameter must be a number between Min_Data = 0x00 and
  181. Max_Data = 0xFF.
  182. Advanced timers: this parameter must be a number between Min_Data = 0x0000 and
  183. Max_Data = 0xFFFF.
  184. This feature can be modified afterwards using unitary function
  185. @ref LL_TIM_SetRepetitionCounter().*/
  186. } LL_TIM_InitTypeDef;
  187. /**
  188. * @brief TIM Output Compare configuration structure definition.
  189. */
  190. typedef struct
  191. {
  192. uint32_t OCMode; /*!< Specifies the output mode.
  193. This parameter can be a value of @ref TIM_LL_EC_OCMODE.
  194. This feature can be modified afterwards using unitary function
  195. @ref LL_TIM_OC_SetMode().*/
  196. uint32_t OCState; /*!< Specifies the TIM Output Compare state.
  197. This parameter can be a value of @ref TIM_LL_EC_OCSTATE.
  198. This feature can be modified afterwards using unitary functions
  199. @ref LL_TIM_CC_EnableChannel() or @ref LL_TIM_CC_DisableChannel().*/
  200. uint32_t OCNState; /*!< Specifies the TIM complementary Output Compare state.
  201. This parameter can be a value of @ref TIM_LL_EC_OCSTATE.
  202. This feature can be modified afterwards using unitary functions
  203. @ref LL_TIM_CC_EnableChannel() or @ref LL_TIM_CC_DisableChannel().*/
  204. uint32_t CompareValue; /*!< Specifies the Compare value to be loaded into the Capture Compare Register.
  205. This parameter can be a number between Min_Data=0x0000 and Max_Data=0xFFFF.
  206. This feature can be modified afterwards using unitary function
  207. LL_TIM_OC_SetCompareCHx (x=1..6).*/
  208. uint32_t OCPolarity; /*!< Specifies the output polarity.
  209. This parameter can be a value of @ref TIM_LL_EC_OCPOLARITY.
  210. This feature can be modified afterwards using unitary function
  211. @ref LL_TIM_OC_SetPolarity().*/
  212. uint32_t OCNPolarity; /*!< Specifies the complementary output polarity.
  213. This parameter can be a value of @ref TIM_LL_EC_OCPOLARITY.
  214. This feature can be modified afterwards using unitary function
  215. @ref LL_TIM_OC_SetPolarity().*/
  216. uint32_t OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  217. This parameter can be a value of @ref TIM_LL_EC_OCIDLESTATE.
  218. This feature can be modified afterwards using unitary function
  219. @ref LL_TIM_OC_SetIdleState().*/
  220. uint32_t OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  221. This parameter can be a value of @ref TIM_LL_EC_OCIDLESTATE.
  222. This feature can be modified afterwards using unitary function
  223. @ref LL_TIM_OC_SetIdleState().*/
  224. } LL_TIM_OC_InitTypeDef;
  225. /**
  226. * @brief TIM Input Capture configuration structure definition.
  227. */
  228. typedef struct
  229. {
  230. uint32_t ICPolarity; /*!< Specifies the active edge of the input signal.
  231. This parameter can be a value of @ref TIM_LL_EC_IC_POLARITY.
  232. This feature can be modified afterwards using unitary function
  233. @ref LL_TIM_IC_SetPolarity().*/
  234. uint32_t ICActiveInput; /*!< Specifies the input.
  235. This parameter can be a value of @ref TIM_LL_EC_ACTIVEINPUT.
  236. This feature can be modified afterwards using unitary function
  237. @ref LL_TIM_IC_SetActiveInput().*/
  238. uint32_t ICPrescaler; /*!< Specifies the Input Capture Prescaler.
  239. This parameter can be a value of @ref TIM_LL_EC_ICPSC.
  240. This feature can be modified afterwards using unitary function
  241. @ref LL_TIM_IC_SetPrescaler().*/
  242. uint32_t ICFilter; /*!< Specifies the input capture filter.
  243. This parameter can be a value of @ref TIM_LL_EC_IC_FILTER.
  244. This feature can be modified afterwards using unitary function
  245. @ref LL_TIM_IC_SetFilter().*/
  246. } LL_TIM_IC_InitTypeDef;
  247. /**
  248. * @brief TIM Encoder interface configuration structure definition.
  249. */
  250. typedef struct
  251. {
  252. uint32_t EncoderMode; /*!< Specifies the encoder resolution (x2 or x4).
  253. This parameter can be a value of @ref TIM_LL_EC_ENCODERMODE.
  254. This feature can be modified afterwards using unitary function
  255. @ref LL_TIM_SetEncoderMode().*/
  256. uint32_t IC1Polarity; /*!< Specifies the active edge of TI1 input.
  257. This parameter can be a value of @ref TIM_LL_EC_IC_POLARITY.
  258. This feature can be modified afterwards using unitary function
  259. @ref LL_TIM_IC_SetPolarity().*/
  260. uint32_t IC1ActiveInput; /*!< Specifies the TI1 input source
  261. This parameter can be a value of @ref TIM_LL_EC_ACTIVEINPUT.
  262. This feature can be modified afterwards using unitary function
  263. @ref LL_TIM_IC_SetActiveInput().*/
  264. uint32_t IC1Prescaler; /*!< Specifies the TI1 input prescaler value.
  265. This parameter can be a value of @ref TIM_LL_EC_ICPSC.
  266. This feature can be modified afterwards using unitary function
  267. @ref LL_TIM_IC_SetPrescaler().*/
  268. uint32_t IC1Filter; /*!< Specifies the TI1 input filter.
  269. This parameter can be a value of @ref TIM_LL_EC_IC_FILTER.
  270. This feature can be modified afterwards using unitary function
  271. @ref LL_TIM_IC_SetFilter().*/
  272. uint32_t IC2Polarity; /*!< Specifies the active edge of TI2 input.
  273. This parameter can be a value of @ref TIM_LL_EC_IC_POLARITY.
  274. This feature can be modified afterwards using unitary function
  275. @ref LL_TIM_IC_SetPolarity().*/
  276. uint32_t IC2ActiveInput; /*!< Specifies the TI2 input source
  277. This parameter can be a value of @ref TIM_LL_EC_ACTIVEINPUT.
  278. This feature can be modified afterwards using unitary function
  279. @ref LL_TIM_IC_SetActiveInput().*/
  280. uint32_t IC2Prescaler; /*!< Specifies the TI2 input prescaler value.
  281. This parameter can be a value of @ref TIM_LL_EC_ICPSC.
  282. This feature can be modified afterwards using unitary function
  283. @ref LL_TIM_IC_SetPrescaler().*/
  284. uint32_t IC2Filter; /*!< Specifies the TI2 input filter.
  285. This parameter can be a value of @ref TIM_LL_EC_IC_FILTER.
  286. This feature can be modified afterwards using unitary function
  287. @ref LL_TIM_IC_SetFilter().*/
  288. } LL_TIM_ENCODER_InitTypeDef;
  289. /**
  290. * @brief TIM Hall sensor interface configuration structure definition.
  291. */
  292. typedef struct
  293. {
  294. uint32_t IC1Polarity; /*!< Specifies the active edge of TI1 input.
  295. This parameter can be a value of @ref TIM_LL_EC_IC_POLARITY.
  296. This feature can be modified afterwards using unitary function
  297. @ref LL_TIM_IC_SetPolarity().*/
  298. uint32_t IC1Prescaler; /*!< Specifies the TI1 input prescaler value.
  299. Prescaler must be set to get a maximum counter period longer than the
  300. time interval between 2 consecutive changes on the Hall inputs.
  301. This parameter can be a value of @ref TIM_LL_EC_ICPSC.
  302. This feature can be modified afterwards using unitary function
  303. @ref LL_TIM_IC_SetPrescaler().*/
  304. uint32_t IC1Filter; /*!< Specifies the TI1 input filter.
  305. This parameter can be a value of
  306. @ref TIM_LL_EC_IC_FILTER.
  307. This feature can be modified afterwards using unitary function
  308. @ref LL_TIM_IC_SetFilter().*/
  309. uint32_t CommutationDelay; /*!< Specifies the compare value to be loaded into the Capture Compare Register.
  310. A positive pulse (TRGO event) is generated with a programmable delay every time
  311. a change occurs on the Hall inputs.
  312. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF.
  313. This feature can be modified afterwards using unitary function
  314. @ref LL_TIM_OC_SetCompareCH2().*/
  315. } LL_TIM_HALLSENSOR_InitTypeDef;
  316. /**
  317. * @brief BDTR (Break and Dead Time) structure definition
  318. */
  319. typedef struct
  320. {
  321. uint32_t OSSRState; /*!< Specifies the Off-State selection used in Run mode.
  322. This parameter can be a value of @ref TIM_LL_EC_OSSR
  323. This feature can be modified afterwards using unitary function
  324. @ref LL_TIM_SetOffStates()
  325. @note This bit-field cannot be modified as long as LOCK level 2 has been
  326. programmed. */
  327. uint32_t OSSIState; /*!< Specifies the Off-State used in Idle state.
  328. This parameter can be a value of @ref TIM_LL_EC_OSSI
  329. This feature can be modified afterwards using unitary function
  330. @ref LL_TIM_SetOffStates()
  331. @note This bit-field cannot be modified as long as LOCK level 2 has been
  332. programmed. */
  333. uint32_t LockLevel; /*!< Specifies the LOCK level parameters.
  334. This parameter can be a value of @ref TIM_LL_EC_LOCKLEVEL
  335. @note The LOCK bits can be written only once after the reset. Once the TIMx_BDTR
  336. register has been written, their content is frozen until the next reset.*/
  337. uint8_t DeadTime; /*!< Specifies the delay time between the switching-off and the
  338. switching-on of the outputs.
  339. This parameter can be a number between Min_Data = 0x00 and Max_Data = 0xFF.
  340. This feature can be modified afterwards using unitary function
  341. @ref LL_TIM_OC_SetDeadTime()
  342. @note This bit-field can not be modified as long as LOCK level 1, 2 or 3 has been
  343. programmed. */
  344. uint16_t BreakState; /*!< Specifies whether the TIM Break input is enabled or not.
  345. This parameter can be a value of @ref TIM_LL_EC_BREAK_ENABLE
  346. This feature can be modified afterwards using unitary functions
  347. @ref LL_TIM_EnableBRK() or @ref LL_TIM_DisableBRK()
  348. @note This bit-field can not be modified as long as LOCK level 1 has been
  349. programmed. */
  350. uint32_t BreakPolarity; /*!< Specifies the TIM Break Input pin polarity.
  351. This parameter can be a value of @ref TIM_LL_EC_BREAK_POLARITY
  352. This feature can be modified afterwards using unitary function
  353. @ref LL_TIM_ConfigBRK()
  354. @note This bit-field can not be modified as long as LOCK level 1 has been
  355. programmed. */
  356. uint32_t AutomaticOutput; /*!< Specifies whether the TIM Automatic Output feature is enabled or not.
  357. This parameter can be a value of @ref TIM_LL_EC_AUTOMATICOUTPUT_ENABLE
  358. This feature can be modified afterwards using unitary functions
  359. @ref LL_TIM_EnableAutomaticOutput() or @ref LL_TIM_DisableAutomaticOutput()
  360. @note This bit-field can not be modified as long as LOCK level 1 has been
  361. programmed. */
  362. } LL_TIM_BDTR_InitTypeDef;
  363. /**
  364. * @}
  365. */
  366. #endif /* USE_FULL_LL_DRIVER */
  367. /* Exported constants --------------------------------------------------------*/
  368. /** @defgroup TIM_LL_Exported_Constants TIM Exported Constants
  369. * @{
  370. */
  371. /** @defgroup TIM_LL_EC_GET_FLAG Get Flags Defines
  372. * @brief Flags defines which can be used with LL_TIM_ReadReg function.
  373. * @{
  374. */
  375. #define LL_TIM_SR_UIF TIM_SR_UIF /*!< Update interrupt flag */
  376. #define LL_TIM_SR_CC1IF TIM_SR_CC1IF /*!< Capture/compare 1 interrupt flag */
  377. #define LL_TIM_SR_CC2IF TIM_SR_CC2IF /*!< Capture/compare 2 interrupt flag */
  378. #define LL_TIM_SR_CC3IF TIM_SR_CC3IF /*!< Capture/compare 3 interrupt flag */
  379. #define LL_TIM_SR_CC4IF TIM_SR_CC4IF /*!< Capture/compare 4 interrupt flag */
  380. #define LL_TIM_SR_COMIF TIM_SR_COMIF /*!< COM interrupt flag */
  381. #define LL_TIM_SR_TIF TIM_SR_TIF /*!< Trigger interrupt flag */
  382. #define LL_TIM_SR_BIF TIM_SR_BIF /*!< Break interrupt flag */
  383. #define LL_TIM_SR_CC1OF TIM_SR_CC1OF /*!< Capture/Compare 1 overcapture flag */
  384. #define LL_TIM_SR_CC2OF TIM_SR_CC2OF /*!< Capture/Compare 2 overcapture flag */
  385. #define LL_TIM_SR_CC3OF TIM_SR_CC3OF /*!< Capture/Compare 3 overcapture flag */
  386. #define LL_TIM_SR_CC4OF TIM_SR_CC4OF /*!< Capture/Compare 4 overcapture flag */
  387. /**
  388. * @}
  389. */
  390. #if defined(USE_FULL_LL_DRIVER)
  391. /** @defgroup TIM_LL_EC_BREAK_ENABLE Break Enable
  392. * @{
  393. */
  394. #define LL_TIM_BREAK_DISABLE 0x00000000U /*!< Break function disabled */
  395. #define LL_TIM_BREAK_ENABLE TIM_BDTR_BKE /*!< Break function enabled */
  396. /**
  397. * @}
  398. */
  399. /** @defgroup TIM_LL_EC_AUTOMATICOUTPUT_ENABLE Automatic output enable
  400. * @{
  401. */
  402. #define LL_TIM_AUTOMATICOUTPUT_DISABLE 0x00000000U /*!< MOE can be set only by software */
  403. #define LL_TIM_AUTOMATICOUTPUT_ENABLE TIM_BDTR_AOE /*!< MOE can be set by software or automatically at the next update event */
  404. /**
  405. * @}
  406. */
  407. #endif /* USE_FULL_LL_DRIVER */
  408. /** @defgroup TIM_LL_EC_IT IT Defines
  409. * @brief IT defines which can be used with LL_TIM_ReadReg and LL_TIM_WriteReg functions.
  410. * @{
  411. */
  412. #define LL_TIM_DIER_UIE TIM_DIER_UIE /*!< Update interrupt enable */
  413. #define LL_TIM_DIER_CC1IE TIM_DIER_CC1IE /*!< Capture/compare 1 interrupt enable */
  414. #define LL_TIM_DIER_CC2IE TIM_DIER_CC2IE /*!< Capture/compare 2 interrupt enable */
  415. #define LL_TIM_DIER_CC3IE TIM_DIER_CC3IE /*!< Capture/compare 3 interrupt enable */
  416. #define LL_TIM_DIER_CC4IE TIM_DIER_CC4IE /*!< Capture/compare 4 interrupt enable */
  417. #define LL_TIM_DIER_COMIE TIM_DIER_COMIE /*!< COM interrupt enable */
  418. #define LL_TIM_DIER_TIE TIM_DIER_TIE /*!< Trigger interrupt enable */
  419. #define LL_TIM_DIER_BIE TIM_DIER_BIE /*!< Break interrupt enable */
  420. /**
  421. * @}
  422. */
  423. /** @defgroup TIM_LL_EC_UPDATESOURCE Update Source
  424. * @{
  425. */
  426. #define LL_TIM_UPDATESOURCE_REGULAR 0x00000000U /*!< Counter overflow/underflow, Setting the UG bit or Update generation through the slave mode controller generates an update request */
  427. #define LL_TIM_UPDATESOURCE_COUNTER TIM_CR1_URS /*!< Only counter overflow/underflow generates an update request */
  428. /**
  429. * @}
  430. */
  431. /** @defgroup TIM_LL_EC_ONEPULSEMODE One Pulse Mode
  432. * @{
  433. */
  434. #define LL_TIM_ONEPULSEMODE_SINGLE TIM_CR1_OPM /*!< Counter stops counting at the next update event */
  435. #define LL_TIM_ONEPULSEMODE_REPETITIVE 0x00000000U /*!< Counter is not stopped at update event */
  436. /**
  437. * @}
  438. */
  439. /** @defgroup TIM_LL_EC_COUNTERMODE Counter Mode
  440. * @{
  441. */
  442. #define LL_TIM_COUNTERMODE_UP 0x00000000U /*!< Counter used as upcounter */
  443. #define LL_TIM_COUNTERMODE_DOWN TIM_CR1_DIR /*!< Counter used as downcounter */
  444. #define LL_TIM_COUNTERMODE_CENTER_DOWN TIM_CR1_CMS_0 /*!< The counter counts up and down alternatively. Output compare interrupt flags of output channels are set only when the counter is counting down. */
  445. #define LL_TIM_COUNTERMODE_CENTER_UP TIM_CR1_CMS_1 /*!< The counter counts up and down alternatively. Output compare interrupt flags of output channels are set only when the counter is counting up */
  446. #define LL_TIM_COUNTERMODE_CENTER_UP_DOWN TIM_CR1_CMS /*!< The counter counts up and down alternatively. Output compare interrupt flags of output channels are set only when the counter is counting up or down. */
  447. /**
  448. * @}
  449. */
  450. /** @defgroup TIM_LL_EC_CLOCKDIVISION Clock Division
  451. * @{
  452. */
  453. #define LL_TIM_CLOCKDIVISION_DIV1 0x00000000U /*!< tDTS=tCK_INT */
  454. #define LL_TIM_CLOCKDIVISION_DIV2 TIM_CR1_CKD_0 /*!< tDTS=2*tCK_INT */
  455. #define LL_TIM_CLOCKDIVISION_DIV4 TIM_CR1_CKD_1 /*!< tDTS=4*tCK_INT */
  456. /**
  457. * @}
  458. */
  459. /** @defgroup TIM_LL_EC_COUNTERDIRECTION Counter Direction
  460. * @{
  461. */
  462. #define LL_TIM_COUNTERDIRECTION_UP 0x00000000U /*!< Timer counter counts up */
  463. #define LL_TIM_COUNTERDIRECTION_DOWN TIM_CR1_DIR /*!< Timer counter counts down */
  464. /**
  465. * @}
  466. */
  467. /** @defgroup TIM_LL_EC_CCUPDATESOURCE Capture Compare Update Source
  468. * @{
  469. */
  470. #define LL_TIM_CCUPDATESOURCE_COMG_ONLY 0x00000000U /*!< Capture/compare control bits are updated by setting the COMG bit only */
  471. #define LL_TIM_CCUPDATESOURCE_COMG_AND_TRGI TIM_CR2_CCUS /*!< Capture/compare control bits are updated by setting the COMG bit or when a rising edge occurs on trigger input (TRGI) */
  472. /**
  473. * @}
  474. */
  475. /** @defgroup TIM_LL_EC_CCDMAREQUEST Capture Compare DMA Request
  476. * @{
  477. */
  478. #define LL_TIM_CCDMAREQUEST_CC 0x00000000U /*!< CCx DMA request sent when CCx event occurs */
  479. #define LL_TIM_CCDMAREQUEST_UPDATE TIM_CR2_CCDS /*!< CCx DMA requests sent when update event occurs */
  480. /**
  481. * @}
  482. */
  483. /** @defgroup TIM_LL_EC_LOCKLEVEL Lock Level
  484. * @{
  485. */
  486. #define LL_TIM_LOCKLEVEL_OFF 0x00000000U /*!< LOCK OFF - No bit is write protected */
  487. #define LL_TIM_LOCKLEVEL_1 TIM_BDTR_LOCK_0 /*!< LOCK Level 1 */
  488. #define LL_TIM_LOCKLEVEL_2 TIM_BDTR_LOCK_1 /*!< LOCK Level 2 */
  489. #define LL_TIM_LOCKLEVEL_3 TIM_BDTR_LOCK /*!< LOCK Level 3 */
  490. /**
  491. * @}
  492. */
  493. /** @defgroup TIM_LL_EC_CHANNEL Channel
  494. * @{
  495. */
  496. #define LL_TIM_CHANNEL_CH1 TIM_CCER_CC1E /*!< Timer input/output channel 1 */
  497. #define LL_TIM_CHANNEL_CH1N TIM_CCER_CC1NE /*!< Timer complementary output channel 1 */
  498. #define LL_TIM_CHANNEL_CH2 TIM_CCER_CC2E /*!< Timer input/output channel 2 */
  499. #define LL_TIM_CHANNEL_CH2N TIM_CCER_CC2NE /*!< Timer complementary output channel 2 */
  500. #define LL_TIM_CHANNEL_CH3 TIM_CCER_CC3E /*!< Timer input/output channel 3 */
  501. #define LL_TIM_CHANNEL_CH3N TIM_CCER_CC3NE /*!< Timer complementary output channel 3 */
  502. #define LL_TIM_CHANNEL_CH4 TIM_CCER_CC4E /*!< Timer input/output channel 4 */
  503. /**
  504. * @}
  505. */
  506. #if defined(USE_FULL_LL_DRIVER)
  507. /** @defgroup TIM_LL_EC_OCSTATE Output Configuration State
  508. * @{
  509. */
  510. #define LL_TIM_OCSTATE_DISABLE 0x00000000U /*!< OCx is not active */
  511. #define LL_TIM_OCSTATE_ENABLE TIM_CCER_CC1E /*!< OCx signal is output on the corresponding output pin */
  512. /**
  513. * @}
  514. */
  515. #endif /* USE_FULL_LL_DRIVER */
  516. /** @defgroup TIM_LL_EC_OCMODE Output Configuration Mode
  517. * @{
  518. */
  519. #define LL_TIM_OCMODE_FROZEN 0x00000000U /*!<The comparison between the output compare register TIMx_CCRy and the counter TIMx_CNT has no effect on the output channel level */
  520. #define LL_TIM_OCMODE_ACTIVE TIM_CCMR1_OC1M_0 /*!<OCyREF is forced high on compare match*/
  521. #define LL_TIM_OCMODE_INACTIVE TIM_CCMR1_OC1M_1 /*!<OCyREF is forced low on compare match*/
  522. #define LL_TIM_OCMODE_TOGGLE (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0) /*!<OCyREF toggles on compare match*/
  523. #define LL_TIM_OCMODE_FORCED_INACTIVE TIM_CCMR1_OC1M_2 /*!<OCyREF is forced low*/
  524. #define LL_TIM_OCMODE_FORCED_ACTIVE (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_0) /*!<OCyREF is forced high*/
  525. #define LL_TIM_OCMODE_PWM1 (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1) /*!<In upcounting, channel y is active as long as TIMx_CNT<TIMx_CCRy else inactive. In downcounting, channel y is inactive as long as TIMx_CNT>TIMx_CCRy else active.*/
  526. #define LL_TIM_OCMODE_PWM2 (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0) /*!<In upcounting, channel y is inactive as long as TIMx_CNT<TIMx_CCRy else active. In downcounting, channel y is active as long as TIMx_CNT>TIMx_CCRy else inactive*/
  527. /**
  528. * @}
  529. */
  530. /** @defgroup TIM_LL_EC_OCPOLARITY Output Configuration Polarity
  531. * @{
  532. */
  533. #define LL_TIM_OCPOLARITY_HIGH 0x00000000U /*!< OCxactive high*/
  534. #define LL_TIM_OCPOLARITY_LOW TIM_CCER_CC1P /*!< OCxactive low*/
  535. /**
  536. * @}
  537. */
  538. /** @defgroup TIM_LL_EC_OCIDLESTATE Output Configuration Idle State
  539. * @{
  540. */
  541. #define LL_TIM_OCIDLESTATE_LOW 0x00000000U /*!<OCx=0 (after a dead-time if OC is implemented) when MOE=0*/
  542. #define LL_TIM_OCIDLESTATE_HIGH TIM_CR2_OIS1 /*!<OCx=1 (after a dead-time if OC is implemented) when MOE=0*/
  543. /**
  544. * @}
  545. */
  546. /** @defgroup TIM_LL_EC_ACTIVEINPUT Active Input Selection
  547. * @{
  548. */
  549. #define LL_TIM_ACTIVEINPUT_DIRECTTI (TIM_CCMR1_CC1S_0 << 16U) /*!< ICx is mapped on TIx */
  550. #define LL_TIM_ACTIVEINPUT_INDIRECTTI (TIM_CCMR1_CC1S_1 << 16U) /*!< ICx is mapped on TIy */
  551. #define LL_TIM_ACTIVEINPUT_TRC (TIM_CCMR1_CC1S << 16U) /*!< ICx is mapped on TRC */
  552. /**
  553. * @}
  554. */
  555. /** @defgroup TIM_LL_EC_ICPSC Input Configuration Prescaler
  556. * @{
  557. */
  558. #define LL_TIM_ICPSC_DIV1 0x00000000U /*!< No prescaler, capture is done each time an edge is detected on the capture input */
  559. #define LL_TIM_ICPSC_DIV2 (TIM_CCMR1_IC1PSC_0 << 16U) /*!< Capture is done once every 2 events */
  560. #define LL_TIM_ICPSC_DIV4 (TIM_CCMR1_IC1PSC_1 << 16U) /*!< Capture is done once every 4 events */
  561. #define LL_TIM_ICPSC_DIV8 (TIM_CCMR1_IC1PSC << 16U) /*!< Capture is done once every 8 events */
  562. /**
  563. * @}
  564. */
  565. /** @defgroup TIM_LL_EC_IC_FILTER Input Configuration Filter
  566. * @{
  567. */
  568. #define LL_TIM_IC_FILTER_FDIV1 0x00000000U /*!< No filter, sampling is done at fDTS */
  569. #define LL_TIM_IC_FILTER_FDIV1_N2 (TIM_CCMR1_IC1F_0 << 16U) /*!< fSAMPLING=fCK_INT, N=2 */
  570. #define LL_TIM_IC_FILTER_FDIV1_N4 (TIM_CCMR1_IC1F_1 << 16U) /*!< fSAMPLING=fCK_INT, N=4 */
  571. #define LL_TIM_IC_FILTER_FDIV1_N8 ((TIM_CCMR1_IC1F_1 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fCK_INT, N=8 */
  572. #define LL_TIM_IC_FILTER_FDIV2_N6 (TIM_CCMR1_IC1F_2 << 16U) /*!< fSAMPLING=fDTS/2, N=6 */
  573. #define LL_TIM_IC_FILTER_FDIV2_N8 ((TIM_CCMR1_IC1F_2 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fDTS/2, N=8 */
  574. #define LL_TIM_IC_FILTER_FDIV4_N6 ((TIM_CCMR1_IC1F_2 | TIM_CCMR1_IC1F_1) << 16U) /*!< fSAMPLING=fDTS/4, N=6 */
  575. #define LL_TIM_IC_FILTER_FDIV4_N8 ((TIM_CCMR1_IC1F_2 | TIM_CCMR1_IC1F_1 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fDTS/4, N=8 */
  576. #define LL_TIM_IC_FILTER_FDIV8_N6 (TIM_CCMR1_IC1F_3 << 16U) /*!< fSAMPLING=fDTS/8, N=6 */
  577. #define LL_TIM_IC_FILTER_FDIV8_N8 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fDTS/8, N=8 */
  578. #define LL_TIM_IC_FILTER_FDIV16_N5 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_1) << 16U) /*!< fSAMPLING=fDTS/16, N=5 */
  579. #define LL_TIM_IC_FILTER_FDIV16_N6 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_1 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fDTS/16, N=6 */
  580. #define LL_TIM_IC_FILTER_FDIV16_N8 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_2) << 16U) /*!< fSAMPLING=fDTS/16, N=8 */
  581. #define LL_TIM_IC_FILTER_FDIV32_N5 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_2 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fDTS/32, N=5 */
  582. #define LL_TIM_IC_FILTER_FDIV32_N6 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_2 | TIM_CCMR1_IC1F_1) << 16U) /*!< fSAMPLING=fDTS/32, N=6 */
  583. #define LL_TIM_IC_FILTER_FDIV32_N8 (TIM_CCMR1_IC1F << 16U) /*!< fSAMPLING=fDTS/32, N=8 */
  584. /**
  585. * @}
  586. */
  587. /** @defgroup TIM_LL_EC_IC_POLARITY Input Configuration Polarity
  588. * @{
  589. */
  590. #define LL_TIM_IC_POLARITY_RISING 0x00000000U /*!< The circuit is sensitive to TIxFP1 rising edge, TIxFP1 is not inverted */
  591. #define LL_TIM_IC_POLARITY_FALLING TIM_CCER_CC1P /*!< The circuit is sensitive to TIxFP1 falling edge, TIxFP1 is inverted */
  592. /**
  593. * @}
  594. */
  595. /** @defgroup TIM_LL_EC_CLOCKSOURCE Clock Source
  596. * @{
  597. */
  598. #define LL_TIM_CLOCKSOURCE_INTERNAL 0x00000000U /*!< The timer is clocked by the internal clock provided from the RCC */
  599. #define LL_TIM_CLOCKSOURCE_EXT_MODE1 (TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0) /*!< Counter counts at each rising or falling edge on a selected input*/
  600. #define LL_TIM_CLOCKSOURCE_EXT_MODE2 TIM_SMCR_ECE /*!< Counter counts at each rising or falling edge on the external trigger input ETR */
  601. /**
  602. * @}
  603. */
  604. /** @defgroup TIM_LL_EC_ENCODERMODE Encoder Mode
  605. * @{
  606. */
  607. #define LL_TIM_ENCODERMODE_X2_TI1 TIM_SMCR_SMS_0 /*!< Quadrature encoder mode 1, x2 mode - Counter counts up/down on TI1FP1 edge depending on TI2FP2 level */
  608. #define LL_TIM_ENCODERMODE_X2_TI2 TIM_SMCR_SMS_1 /*!< Quadrature encoder mode 2, x2 mode - Counter counts up/down on TI2FP2 edge depending on TI1FP1 level */
  609. #define LL_TIM_ENCODERMODE_X4_TI12 (TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0) /*!< Quadrature encoder mode 3, x4 mode - Counter counts up/down on both TI1FP1 and TI2FP2 edges depending on the level of the other input */
  610. /**
  611. * @}
  612. */
  613. /** @defgroup TIM_LL_EC_TRGO Trigger Output
  614. * @{
  615. */
  616. #define LL_TIM_TRGO_RESET 0x00000000U /*!< UG bit from the TIMx_EGR register is used as trigger output */
  617. #define LL_TIM_TRGO_ENABLE TIM_CR2_MMS_0 /*!< Counter Enable signal (CNT_EN) is used as trigger output */
  618. #define LL_TIM_TRGO_UPDATE TIM_CR2_MMS_1 /*!< Update event is used as trigger output */
  619. #define LL_TIM_TRGO_CC1IF (TIM_CR2_MMS_1 | TIM_CR2_MMS_0) /*!< CC1 capture or a compare match is used as trigger output */
  620. #define LL_TIM_TRGO_OC1REF TIM_CR2_MMS_2 /*!< OC1REF signal is used as trigger output */
  621. #define LL_TIM_TRGO_OC2REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_0) /*!< OC2REF signal is used as trigger output */
  622. #define LL_TIM_TRGO_OC3REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_1) /*!< OC3REF signal is used as trigger output */
  623. #define LL_TIM_TRGO_OC4REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_1 | TIM_CR2_MMS_0) /*!< OC4REF signal is used as trigger output */
  624. /**
  625. * @}
  626. */
  627. /** @defgroup TIM_LL_EC_SLAVEMODE Slave Mode
  628. * @{
  629. */
  630. #define LL_TIM_SLAVEMODE_DISABLED 0x00000000U /*!< Slave mode disabled */
  631. #define LL_TIM_SLAVEMODE_RESET TIM_SMCR_SMS_2 /*!< Reset Mode - Rising edge of the selected trigger input (TRGI) reinitializes the counter */
  632. #define LL_TIM_SLAVEMODE_GATED (TIM_SMCR_SMS_2 | TIM_SMCR_SMS_0) /*!< Gated Mode - The counter clock is enabled when the trigger input (TRGI) is high */
  633. #define LL_TIM_SLAVEMODE_TRIGGER (TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1) /*!< Trigger Mode - The counter starts at a rising edge of the trigger TRGI */
  634. /**
  635. * @}
  636. */
  637. /** @defgroup TIM_LL_EC_TS Trigger Selection
  638. * @{
  639. */
  640. #define LL_TIM_TS_ITR0 0x00000000U /*!< Internal Trigger 0 (ITR0) is used as trigger input */
  641. #define LL_TIM_TS_ITR1 TIM_SMCR_TS_0 /*!< Internal Trigger 1 (ITR1) is used as trigger input */
  642. #define LL_TIM_TS_ITR2 TIM_SMCR_TS_1 /*!< Internal Trigger 2 (ITR2) is used as trigger input */
  643. #define LL_TIM_TS_ITR3 (TIM_SMCR_TS_0 | TIM_SMCR_TS_1) /*!< Internal Trigger 3 (ITR3) is used as trigger input */
  644. #define LL_TIM_TS_TI1F_ED TIM_SMCR_TS_2 /*!< TI1 Edge Detector (TI1F_ED) is used as trigger input */
  645. #define LL_TIM_TS_TI1FP1 (TIM_SMCR_TS_2 | TIM_SMCR_TS_0) /*!< Filtered Timer Input 1 (TI1FP1) is used as trigger input */
  646. #define LL_TIM_TS_TI2FP2 (TIM_SMCR_TS_2 | TIM_SMCR_TS_1) /*!< Filtered Timer Input 2 (TI12P2) is used as trigger input */
  647. #define LL_TIM_TS_ETRF (TIM_SMCR_TS_2 | TIM_SMCR_TS_1 | TIM_SMCR_TS_0) /*!< Filtered external Trigger (ETRF) is used as trigger input */
  648. /**
  649. * @}
  650. */
  651. /** @defgroup TIM_LL_EC_ETR_POLARITY External Trigger Polarity
  652. * @{
  653. */
  654. #define LL_TIM_ETR_POLARITY_NONINVERTED 0x00000000U /*!< ETR is non-inverted, active at high level or rising edge */
  655. #define LL_TIM_ETR_POLARITY_INVERTED TIM_SMCR_ETP /*!< ETR is inverted, active at low level or falling edge */
  656. /**
  657. * @}
  658. */
  659. /** @defgroup TIM_LL_EC_ETR_PRESCALER External Trigger Prescaler
  660. * @{
  661. */
  662. #define LL_TIM_ETR_PRESCALER_DIV1 0x00000000U /*!< ETR prescaler OFF */
  663. #define LL_TIM_ETR_PRESCALER_DIV2 TIM_SMCR_ETPS_0 /*!< ETR frequency is divided by 2 */
  664. #define LL_TIM_ETR_PRESCALER_DIV4 TIM_SMCR_ETPS_1 /*!< ETR frequency is divided by 4 */
  665. #define LL_TIM_ETR_PRESCALER_DIV8 TIM_SMCR_ETPS /*!< ETR frequency is divided by 8 */
  666. /**
  667. * @}
  668. */
  669. /** @defgroup TIM_LL_EC_ETR_FILTER External Trigger Filter
  670. * @{
  671. */
  672. #define LL_TIM_ETR_FILTER_FDIV1 0x00000000U /*!< No filter, sampling is done at fDTS */
  673. #define LL_TIM_ETR_FILTER_FDIV1_N2 TIM_SMCR_ETF_0 /*!< fSAMPLING=fCK_INT, N=2 */
  674. #define LL_TIM_ETR_FILTER_FDIV1_N4 TIM_SMCR_ETF_1 /*!< fSAMPLING=fCK_INT, N=4 */
  675. #define LL_TIM_ETR_FILTER_FDIV1_N8 (TIM_SMCR_ETF_1 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fCK_INT, N=8 */
  676. #define LL_TIM_ETR_FILTER_FDIV2_N6 TIM_SMCR_ETF_2 /*!< fSAMPLING=fDTS/2, N=6 */
  677. #define LL_TIM_ETR_FILTER_FDIV2_N8 (TIM_SMCR_ETF_2 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/2, N=8 */
  678. #define LL_TIM_ETR_FILTER_FDIV4_N6 (TIM_SMCR_ETF_2 | TIM_SMCR_ETF_1) /*!< fSAMPLING=fDTS/4, N=6 */
  679. #define LL_TIM_ETR_FILTER_FDIV4_N8 (TIM_SMCR_ETF_2 | TIM_SMCR_ETF_1 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/4, N=8 */
  680. #define LL_TIM_ETR_FILTER_FDIV8_N6 TIM_SMCR_ETF_3 /*!< fSAMPLING=fDTS/8, N=6 */
  681. #define LL_TIM_ETR_FILTER_FDIV8_N8 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/16, N=8 */
  682. #define LL_TIM_ETR_FILTER_FDIV16_N5 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_1) /*!< fSAMPLING=fDTS/16, N=5 */
  683. #define LL_TIM_ETR_FILTER_FDIV16_N6 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_1 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/16, N=6 */
  684. #define LL_TIM_ETR_FILTER_FDIV16_N8 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_2) /*!< fSAMPLING=fDTS/16, N=8 */
  685. #define LL_TIM_ETR_FILTER_FDIV32_N5 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_2 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/32, N=5 */
  686. #define LL_TIM_ETR_FILTER_FDIV32_N6 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_2 | TIM_SMCR_ETF_1) /*!< fSAMPLING=fDTS/32, N=6 */
  687. #define LL_TIM_ETR_FILTER_FDIV32_N8 TIM_SMCR_ETF /*!< fSAMPLING=fDTS/32, N=8 */
  688. /**
  689. * @}
  690. */
  691. /** @defgroup TIM_LL_EC_BREAK_POLARITY break polarity
  692. * @{
  693. */
  694. #define LL_TIM_BREAK_POLARITY_LOW 0x00000000U /*!< Break input BRK is active low */
  695. #define LL_TIM_BREAK_POLARITY_HIGH TIM_BDTR_BKP /*!< Break input BRK is active high */
  696. /**
  697. * @}
  698. */
  699. /** @defgroup TIM_LL_EC_OSSI OSSI
  700. * @{
  701. */
  702. #define LL_TIM_OSSI_DISABLE 0x00000000U /*!< When inactive, OCx/OCxN outputs are disabled */
  703. #define LL_TIM_OSSI_ENABLE TIM_BDTR_OSSI /*!< When inactive, OxC/OCxN outputs are first forced with their inactive level then forced to their idle level after the deadtime */
  704. /**
  705. * @}
  706. */
  707. /** @defgroup TIM_LL_EC_OSSR OSSR
  708. * @{
  709. */
  710. #define LL_TIM_OSSR_DISABLE 0x00000000U /*!< When inactive, OCx/OCxN outputs are disabled */
  711. #define LL_TIM_OSSR_ENABLE TIM_BDTR_OSSR /*!< When inactive, OC/OCN outputs are enabled with their inactive level as soon as CCxE=1 or CCxNE=1 */
  712. /**
  713. * @}
  714. */
  715. /** @defgroup TIM_LL_EC_DMABURST_BASEADDR DMA Burst Base Address
  716. * @{
  717. */
  718. #define LL_TIM_DMABURST_BASEADDR_CR1 0x00000000U /*!< TIMx_CR1 register is the DMA base address for DMA burst */
  719. #define LL_TIM_DMABURST_BASEADDR_CR2 TIM_DCR_DBA_0 /*!< TIMx_CR2 register is the DMA base address for DMA burst */
  720. #define LL_TIM_DMABURST_BASEADDR_SMCR TIM_DCR_DBA_1 /*!< TIMx_SMCR register is the DMA base address for DMA burst */
  721. #define LL_TIM_DMABURST_BASEADDR_DIER (TIM_DCR_DBA_1 | TIM_DCR_DBA_0) /*!< TIMx_DIER register is the DMA base address for DMA burst */
  722. #define LL_TIM_DMABURST_BASEADDR_SR TIM_DCR_DBA_2 /*!< TIMx_SR register is the DMA base address for DMA burst */
  723. #define LL_TIM_DMABURST_BASEADDR_EGR (TIM_DCR_DBA_2 | TIM_DCR_DBA_0) /*!< TIMx_EGR register is the DMA base address for DMA burst */
  724. #define LL_TIM_DMABURST_BASEADDR_CCMR1 (TIM_DCR_DBA_2 | TIM_DCR_DBA_1) /*!< TIMx_CCMR1 register is the DMA base address for DMA burst */
  725. #define LL_TIM_DMABURST_BASEADDR_CCMR2 (TIM_DCR_DBA_2 | TIM_DCR_DBA_1 | TIM_DCR_DBA_0) /*!< TIMx_CCMR2 register is the DMA base address for DMA burst */
  726. #define LL_TIM_DMABURST_BASEADDR_CCER TIM_DCR_DBA_3 /*!< TIMx_CCER register is the DMA base address for DMA burst */
  727. #define LL_TIM_DMABURST_BASEADDR_CNT (TIM_DCR_DBA_3 | TIM_DCR_DBA_0) /*!< TIMx_CNT register is the DMA base address for DMA burst */
  728. #define LL_TIM_DMABURST_BASEADDR_PSC (TIM_DCR_DBA_3 | TIM_DCR_DBA_1) /*!< TIMx_PSC register is the DMA base address for DMA burst */
  729. #define LL_TIM_DMABURST_BASEADDR_ARR (TIM_DCR_DBA_3 | TIM_DCR_DBA_1 | TIM_DCR_DBA_0) /*!< TIMx_ARR register is the DMA base address for DMA burst */
  730. #define LL_TIM_DMABURST_BASEADDR_RCR (TIM_DCR_DBA_3 | TIM_DCR_DBA_2) /*!< TIMx_RCR register is the DMA base address for DMA burst */
  731. #define LL_TIM_DMABURST_BASEADDR_CCR1 (TIM_DCR_DBA_3 | TIM_DCR_DBA_2 | TIM_DCR_DBA_0) /*!< TIMx_CCR1 register is the DMA base address for DMA burst */
  732. #define LL_TIM_DMABURST_BASEADDR_CCR2 (TIM_DCR_DBA_3 | TIM_DCR_DBA_2 | TIM_DCR_DBA_1) /*!< TIMx_CCR2 register is the DMA base address for DMA burst */
  733. #define LL_TIM_DMABURST_BASEADDR_CCR3 (TIM_DCR_DBA_3 | TIM_DCR_DBA_2 | TIM_DCR_DBA_1 | TIM_DCR_DBA_0) /*!< TIMx_CCR3 register is the DMA base address for DMA burst */
  734. #define LL_TIM_DMABURST_BASEADDR_CCR4 TIM_DCR_DBA_4 /*!< TIMx_CCR4 register is the DMA base address for DMA burst */
  735. #define LL_TIM_DMABURST_BASEADDR_BDTR (TIM_DCR_DBA_4 | TIM_DCR_DBA_0) /*!< TIMx_BDTR register is the DMA base address for DMA burst */
  736. /**
  737. * @}
  738. */
  739. /** @defgroup TIM_LL_EC_DMABURST_LENGTH DMA Burst Length
  740. * @{
  741. */
  742. #define LL_TIM_DMABURST_LENGTH_1TRANSFER 0x00000000U /*!< Transfer is done to 1 register starting from the DMA burst base address */
  743. #define LL_TIM_DMABURST_LENGTH_2TRANSFERS TIM_DCR_DBL_0 /*!< Transfer is done to 2 registers starting from the DMA burst base address */
  744. #define LL_TIM_DMABURST_LENGTH_3TRANSFERS TIM_DCR_DBL_1 /*!< Transfer is done to 3 registers starting from the DMA burst base address */
  745. #define LL_TIM_DMABURST_LENGTH_4TRANSFERS (TIM_DCR_DBL_1 | TIM_DCR_DBL_0) /*!< Transfer is done to 4 registers starting from the DMA burst base address */
  746. #define LL_TIM_DMABURST_LENGTH_5TRANSFERS TIM_DCR_DBL_2 /*!< Transfer is done to 5 registers starting from the DMA burst base address */
  747. #define LL_TIM_DMABURST_LENGTH_6TRANSFERS (TIM_DCR_DBL_2 | TIM_DCR_DBL_0) /*!< Transfer is done to 6 registers starting from the DMA burst base address */
  748. #define LL_TIM_DMABURST_LENGTH_7TRANSFERS (TIM_DCR_DBL_2 | TIM_DCR_DBL_1) /*!< Transfer is done to 7 registers starting from the DMA burst base address */
  749. #define LL_TIM_DMABURST_LENGTH_8TRANSFERS (TIM_DCR_DBL_2 | TIM_DCR_DBL_1 | TIM_DCR_DBL_0) /*!< Transfer is done to 1 registers starting from the DMA burst base address */
  750. #define LL_TIM_DMABURST_LENGTH_9TRANSFERS TIM_DCR_DBL_3 /*!< Transfer is done to 9 registers starting from the DMA burst base address */
  751. #define LL_TIM_DMABURST_LENGTH_10TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_0) /*!< Transfer is done to 10 registers starting from the DMA burst base address */
  752. #define LL_TIM_DMABURST_LENGTH_11TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_1) /*!< Transfer is done to 11 registers starting from the DMA burst base address */
  753. #define LL_TIM_DMABURST_LENGTH_12TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_1 | TIM_DCR_DBL_0) /*!< Transfer is done to 12 registers starting from the DMA burst base address */
  754. #define LL_TIM_DMABURST_LENGTH_13TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_2) /*!< Transfer is done to 13 registers starting from the DMA burst base address */
  755. #define LL_TIM_DMABURST_LENGTH_14TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_2 | TIM_DCR_DBL_0) /*!< Transfer is done to 14 registers starting from the DMA burst base address */
  756. #define LL_TIM_DMABURST_LENGTH_15TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_2 | TIM_DCR_DBL_1) /*!< Transfer is done to 15 registers starting from the DMA burst base address */
  757. #define LL_TIM_DMABURST_LENGTH_16TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_2 | TIM_DCR_DBL_1 | TIM_DCR_DBL_0) /*!< Transfer is done to 16 registers starting from the DMA burst base address */
  758. #define LL_TIM_DMABURST_LENGTH_17TRANSFERS TIM_DCR_DBL_4 /*!< Transfer is done to 17 registers starting from the DMA burst base address */
  759. #define LL_TIM_DMABURST_LENGTH_18TRANSFERS (TIM_DCR_DBL_4 | TIM_DCR_DBL_0) /*!< Transfer is done to 18 registers starting from the DMA burst base address */
  760. /**
  761. * @}
  762. */
  763. /**
  764. * @}
  765. */
  766. /* Exported macro ------------------------------------------------------------*/
  767. /** @defgroup TIM_LL_Exported_Macros TIM Exported Macros
  768. * @{
  769. */
  770. /** @defgroup TIM_LL_EM_WRITE_READ Common Write and read registers Macros
  771. * @{
  772. */
  773. /**
  774. * @brief Write a value in TIM register.
  775. * @param __INSTANCE__ TIM Instance
  776. * @param __REG__ Register to be written
  777. * @param __VALUE__ Value to be written in the register
  778. * @retval None
  779. */
  780. #define LL_TIM_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
  781. /**
  782. * @brief Read a value in TIM register.
  783. * @param __INSTANCE__ TIM Instance
  784. * @param __REG__ Register to be read
  785. * @retval Register value
  786. */
  787. #define LL_TIM_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
  788. /**
  789. * @}
  790. */
  791. /**
  792. * @brief HELPER macro calculating DTG[0:7] in the TIMx_BDTR register to achieve the requested dead time duration.
  793. * @note ex: @ref __LL_TIM_CALC_DEADTIME (80000000, @ref LL_TIM_GetClockDivision (), 120);
  794. * @param __TIMCLK__ timer input clock frequency (in Hz)
  795. * @param __CKD__ This parameter can be one of the following values:
  796. * @arg @ref LL_TIM_CLOCKDIVISION_DIV1
  797. * @arg @ref LL_TIM_CLOCKDIVISION_DIV2
  798. * @arg @ref LL_TIM_CLOCKDIVISION_DIV4
  799. * @param __DT__ deadtime duration (in ns)
  800. * @retval DTG[0:7]
  801. */
  802. #define __LL_TIM_CALC_DEADTIME(__TIMCLK__, __CKD__, __DT__) \
  803. ( (((uint64_t)((__DT__)*1000U)) < ((DT_DELAY_1+1U) * TIM_CALC_DTS((__TIMCLK__), (__CKD__)))) ? \
  804. (uint8_t)(((uint64_t)((__DT__)*1000U) / TIM_CALC_DTS((__TIMCLK__), (__CKD__))) & DT_DELAY_1) : \
  805. (((uint64_t)((__DT__)*1000U)) < ((64U + (DT_DELAY_2+1U)) * 2U * TIM_CALC_DTS((__TIMCLK__), (__CKD__)))) ? \
  806. (uint8_t)(DT_RANGE_2 | ((uint8_t)((uint8_t)((((uint64_t)((__DT__)*1000U))/ TIM_CALC_DTS((__TIMCLK__), \
  807. (__CKD__))) >> 1U) - (uint8_t) 64) & DT_DELAY_2)) :\
  808. (((uint64_t)((__DT__)*1000U)) < ((32U + (DT_DELAY_3+1U)) * 8U * TIM_CALC_DTS((__TIMCLK__), (__CKD__)))) ? \
  809. (uint8_t)(DT_RANGE_3 | ((uint8_t)((uint8_t)(((((uint64_t)(__DT__)*1000U))/ TIM_CALC_DTS((__TIMCLK__), \
  810. (__CKD__))) >> 3U) - (uint8_t) 32) & DT_DELAY_3)) :\
  811. (((uint64_t)((__DT__)*1000U)) < ((32U + (DT_DELAY_4+1U)) * 16U * TIM_CALC_DTS((__TIMCLK__), (__CKD__)))) ? \
  812. (uint8_t)(DT_RANGE_4 | ((uint8_t)((uint8_t)(((((uint64_t)(__DT__)*1000U))/ TIM_CALC_DTS((__TIMCLK__), \
  813. (__CKD__))) >> 4U) - (uint8_t) 32) & DT_DELAY_4)) :\
  814. 0U)
  815. /**
  816. * @brief HELPER macro calculating the prescaler value to achieve the required counter clock frequency.
  817. * @note ex: @ref __LL_TIM_CALC_PSC (80000000, 1000000);
  818. * @param __TIMCLK__ timer input clock frequency (in Hz)
  819. * @param __CNTCLK__ counter clock frequency (in Hz)
  820. * @retval Prescaler value (between Min_Data=0 and Max_Data=65535)
  821. */
  822. #define __LL_TIM_CALC_PSC(__TIMCLK__, __CNTCLK__) \
  823. (((__TIMCLK__) >= (__CNTCLK__)) ? (uint32_t)((((__TIMCLK__) + (__CNTCLK__)/2U)/(__CNTCLK__)) - 1U) : 0U)
  824. /**
  825. * @brief HELPER macro calculating the auto-reload value to achieve the required output signal frequency.
  826. * @note ex: @ref __LL_TIM_CALC_ARR (1000000, @ref LL_TIM_GetPrescaler (), 10000);
  827. * @param __TIMCLK__ timer input clock frequency (in Hz)
  828. * @param __PSC__ prescaler
  829. * @param __FREQ__ output signal frequency (in Hz)
  830. * @retval Auto-reload value (between Min_Data=0 and Max_Data=65535)
  831. */
  832. #define __LL_TIM_CALC_ARR(__TIMCLK__, __PSC__, __FREQ__) \
  833. ((((__TIMCLK__)/((__PSC__) + 1U)) >= (__FREQ__)) ? (((__TIMCLK__)/((__FREQ__) * ((__PSC__) + 1U))) - 1U) : 0U)
  834. /**
  835. * @brief HELPER macro calculating the compare value required to achieve the required timer output compare
  836. * active/inactive delay.
  837. * @note ex: @ref __LL_TIM_CALC_DELAY (1000000, @ref LL_TIM_GetPrescaler (), 10);
  838. * @param __TIMCLK__ timer input clock frequency (in Hz)
  839. * @param __PSC__ prescaler
  840. * @param __DELAY__ timer output compare active/inactive delay (in us)
  841. * @retval Compare value (between Min_Data=0 and Max_Data=65535)
  842. */
  843. #define __LL_TIM_CALC_DELAY(__TIMCLK__, __PSC__, __DELAY__) \
  844. ((uint32_t)(((uint64_t)(__TIMCLK__) * (uint64_t)(__DELAY__)) \
  845. / ((uint64_t)1000000U * (uint64_t)((__PSC__) + 1U))))
  846. /**
  847. * @brief HELPER macro calculating the auto-reload value to achieve the required pulse duration
  848. * (when the timer operates in one pulse mode).
  849. * @note ex: @ref __LL_TIM_CALC_PULSE (1000000, @ref LL_TIM_GetPrescaler (), 10, 20);
  850. * @param __TIMCLK__ timer input clock frequency (in Hz)
  851. * @param __PSC__ prescaler
  852. * @param __DELAY__ timer output compare active/inactive delay (in us)
  853. * @param __PULSE__ pulse duration (in us)
  854. * @retval Auto-reload value (between Min_Data=0 and Max_Data=65535)
  855. */
  856. #define __LL_TIM_CALC_PULSE(__TIMCLK__, __PSC__, __DELAY__, __PULSE__) \
  857. ((uint32_t)(__LL_TIM_CALC_DELAY((__TIMCLK__), (__PSC__), (__PULSE__)) \
  858. + __LL_TIM_CALC_DELAY((__TIMCLK__), (__PSC__), (__DELAY__))))
  859. /**
  860. * @brief HELPER macro retrieving the ratio of the input capture prescaler
  861. * @note ex: @ref __LL_TIM_GET_ICPSC_RATIO (@ref LL_TIM_IC_GetPrescaler ());
  862. * @param __ICPSC__ This parameter can be one of the following values:
  863. * @arg @ref LL_TIM_ICPSC_DIV1
  864. * @arg @ref LL_TIM_ICPSC_DIV2
  865. * @arg @ref LL_TIM_ICPSC_DIV4
  866. * @arg @ref LL_TIM_ICPSC_DIV8
  867. * @retval Input capture prescaler ratio (1, 2, 4 or 8)
  868. */
  869. #define __LL_TIM_GET_ICPSC_RATIO(__ICPSC__) \
  870. ((uint32_t)(0x01U << (((__ICPSC__) >> 16U) >> TIM_CCMR1_IC1PSC_Pos)))
  871. /**
  872. * @}
  873. */
  874. /* Exported functions --------------------------------------------------------*/
  875. /** @defgroup TIM_LL_Exported_Functions TIM Exported Functions
  876. * @{
  877. */
  878. /** @defgroup TIM_LL_EF_Time_Base Time Base configuration
  879. * @{
  880. */
  881. /**
  882. * @brief Enable timer counter.
  883. * @rmtoll CR1 CEN LL_TIM_EnableCounter
  884. * @param TIMx Timer instance
  885. * @retval None
  886. */
  887. __STATIC_INLINE void LL_TIM_EnableCounter(TIM_TypeDef *TIMx)
  888. {
  889. SET_BIT(TIMx->CR1, TIM_CR1_CEN);
  890. }
  891. /**
  892. * @brief Disable timer counter.
  893. * @rmtoll CR1 CEN LL_TIM_DisableCounter
  894. * @param TIMx Timer instance
  895. * @retval None
  896. */
  897. __STATIC_INLINE void LL_TIM_DisableCounter(TIM_TypeDef *TIMx)
  898. {
  899. CLEAR_BIT(TIMx->CR1, TIM_CR1_CEN);
  900. }
  901. /**
  902. * @brief Indicates whether the timer counter is enabled.
  903. * @rmtoll CR1 CEN LL_TIM_IsEnabledCounter
  904. * @param TIMx Timer instance
  905. * @retval State of bit (1 or 0).
  906. */
  907. __STATIC_INLINE uint32_t LL_TIM_IsEnabledCounter(const TIM_TypeDef *TIMx)
  908. {
  909. return ((READ_BIT(TIMx->CR1, TIM_CR1_CEN) == (TIM_CR1_CEN)) ? 1UL : 0UL);
  910. }
  911. /**
  912. * @brief Enable update event generation.
  913. * @rmtoll CR1 UDIS LL_TIM_EnableUpdateEvent
  914. * @param TIMx Timer instance
  915. * @retval None
  916. */
  917. __STATIC_INLINE void LL_TIM_EnableUpdateEvent(TIM_TypeDef *TIMx)
  918. {
  919. CLEAR_BIT(TIMx->CR1, TIM_CR1_UDIS);
  920. }
  921. /**
  922. * @brief Disable update event generation.
  923. * @rmtoll CR1 UDIS LL_TIM_DisableUpdateEvent
  924. * @param TIMx Timer instance
  925. * @retval None
  926. */
  927. __STATIC_INLINE void LL_TIM_DisableUpdateEvent(TIM_TypeDef *TIMx)
  928. {
  929. SET_BIT(TIMx->CR1, TIM_CR1_UDIS);
  930. }
  931. /**
  932. * @brief Indicates whether update event generation is enabled.
  933. * @rmtoll CR1 UDIS LL_TIM_IsEnabledUpdateEvent
  934. * @param TIMx Timer instance
  935. * @retval Inverted state of bit (0 or 1).
  936. */
  937. __STATIC_INLINE uint32_t LL_TIM_IsEnabledUpdateEvent(const TIM_TypeDef *TIMx)
  938. {
  939. return ((READ_BIT(TIMx->CR1, TIM_CR1_UDIS) == (uint32_t)RESET) ? 1UL : 0UL);
  940. }
  941. /**
  942. * @brief Set update event source
  943. * @note Update event source set to LL_TIM_UPDATESOURCE_REGULAR: any of the following events
  944. * generate an update interrupt or DMA request if enabled:
  945. * - Counter overflow/underflow
  946. * - Setting the UG bit
  947. * - Update generation through the slave mode controller
  948. * @note Update event source set to LL_TIM_UPDATESOURCE_COUNTER: only counter
  949. * overflow/underflow generates an update interrupt or DMA request if enabled.
  950. * @rmtoll CR1 URS LL_TIM_SetUpdateSource
  951. * @param TIMx Timer instance
  952. * @param UpdateSource This parameter can be one of the following values:
  953. * @arg @ref LL_TIM_UPDATESOURCE_REGULAR
  954. * @arg @ref LL_TIM_UPDATESOURCE_COUNTER
  955. * @retval None
  956. */
  957. __STATIC_INLINE void LL_TIM_SetUpdateSource(TIM_TypeDef *TIMx, uint32_t UpdateSource)
  958. {
  959. MODIFY_REG(TIMx->CR1, TIM_CR1_URS, UpdateSource);
  960. }
  961. /**
  962. * @brief Get actual event update source
  963. * @rmtoll CR1 URS LL_TIM_GetUpdateSource
  964. * @param TIMx Timer instance
  965. * @retval Returned value can be one of the following values:
  966. * @arg @ref LL_TIM_UPDATESOURCE_REGULAR
  967. * @arg @ref LL_TIM_UPDATESOURCE_COUNTER
  968. */
  969. __STATIC_INLINE uint32_t LL_TIM_GetUpdateSource(const TIM_TypeDef *TIMx)
  970. {
  971. return (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_URS));
  972. }
  973. /**
  974. * @brief Set one pulse mode (one shot v.s. repetitive).
  975. * @rmtoll CR1 OPM LL_TIM_SetOnePulseMode
  976. * @param TIMx Timer instance
  977. * @param OnePulseMode This parameter can be one of the following values:
  978. * @arg @ref LL_TIM_ONEPULSEMODE_SINGLE
  979. * @arg @ref LL_TIM_ONEPULSEMODE_REPETITIVE
  980. * @retval None
  981. */
  982. __STATIC_INLINE void LL_TIM_SetOnePulseMode(TIM_TypeDef *TIMx, uint32_t OnePulseMode)
  983. {
  984. MODIFY_REG(TIMx->CR1, TIM_CR1_OPM, OnePulseMode);
  985. }
  986. /**
  987. * @brief Get actual one pulse mode.
  988. * @rmtoll CR1 OPM LL_TIM_GetOnePulseMode
  989. * @param TIMx Timer instance
  990. * @retval Returned value can be one of the following values:
  991. * @arg @ref LL_TIM_ONEPULSEMODE_SINGLE
  992. * @arg @ref LL_TIM_ONEPULSEMODE_REPETITIVE
  993. */
  994. __STATIC_INLINE uint32_t LL_TIM_GetOnePulseMode(const TIM_TypeDef *TIMx)
  995. {
  996. return (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_OPM));
  997. }
  998. /**
  999. * @brief Set the timer counter counting mode.
  1000. * @note Macro IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx) can be used to
  1001. * check whether or not the counter mode selection feature is supported
  1002. * by a timer instance.
  1003. * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
  1004. * requires a timer reset to avoid unexpected direction
  1005. * due to DIR bit readonly in center aligned mode.
  1006. * @rmtoll CR1 DIR LL_TIM_SetCounterMode\n
  1007. * CR1 CMS LL_TIM_SetCounterMode
  1008. * @param TIMx Timer instance
  1009. * @param CounterMode This parameter can be one of the following values:
  1010. * @arg @ref LL_TIM_COUNTERMODE_UP
  1011. * @arg @ref LL_TIM_COUNTERMODE_DOWN
  1012. * @arg @ref LL_TIM_COUNTERMODE_CENTER_UP
  1013. * @arg @ref LL_TIM_COUNTERMODE_CENTER_DOWN
  1014. * @arg @ref LL_TIM_COUNTERMODE_CENTER_UP_DOWN
  1015. * @retval None
  1016. */
  1017. __STATIC_INLINE void LL_TIM_SetCounterMode(TIM_TypeDef *TIMx, uint32_t CounterMode)
  1018. {
  1019. MODIFY_REG(TIMx->CR1, (TIM_CR1_DIR | TIM_CR1_CMS), CounterMode);
  1020. }
  1021. /**
  1022. * @brief Get actual counter mode.
  1023. * @note Macro IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx) can be used to
  1024. * check whether or not the counter mode selection feature is supported
  1025. * by a timer instance.
  1026. * @rmtoll CR1 DIR LL_TIM_GetCounterMode\n
  1027. * CR1 CMS LL_TIM_GetCounterMode
  1028. * @param TIMx Timer instance
  1029. * @retval Returned value can be one of the following values:
  1030. * @arg @ref LL_TIM_COUNTERMODE_UP
  1031. * @arg @ref LL_TIM_COUNTERMODE_DOWN
  1032. * @arg @ref LL_TIM_COUNTERMODE_CENTER_UP
  1033. * @arg @ref LL_TIM_COUNTERMODE_CENTER_DOWN
  1034. * @arg @ref LL_TIM_COUNTERMODE_CENTER_UP_DOWN
  1035. */
  1036. __STATIC_INLINE uint32_t LL_TIM_GetCounterMode(const TIM_TypeDef *TIMx)
  1037. {
  1038. uint32_t counter_mode;
  1039. counter_mode = (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_CMS));
  1040. if (counter_mode == 0U)
  1041. {
  1042. counter_mode = (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_DIR));
  1043. }
  1044. return counter_mode;
  1045. }
  1046. /**
  1047. * @brief Enable auto-reload (ARR) preload.
  1048. * @rmtoll CR1 ARPE LL_TIM_EnableARRPreload
  1049. * @param TIMx Timer instance
  1050. * @retval None
  1051. */
  1052. __STATIC_INLINE void LL_TIM_EnableARRPreload(TIM_TypeDef *TIMx)
  1053. {
  1054. SET_BIT(TIMx->CR1, TIM_CR1_ARPE);
  1055. }
  1056. /**
  1057. * @brief Disable auto-reload (ARR) preload.
  1058. * @rmtoll CR1 ARPE LL_TIM_DisableARRPreload
  1059. * @param TIMx Timer instance
  1060. * @retval None
  1061. */
  1062. __STATIC_INLINE void LL_TIM_DisableARRPreload(TIM_TypeDef *TIMx)
  1063. {
  1064. CLEAR_BIT(TIMx->CR1, TIM_CR1_ARPE);
  1065. }
  1066. /**
  1067. * @brief Indicates whether auto-reload (ARR) preload is enabled.
  1068. * @rmtoll CR1 ARPE LL_TIM_IsEnabledARRPreload
  1069. * @param TIMx Timer instance
  1070. * @retval State of bit (1 or 0).
  1071. */
  1072. __STATIC_INLINE uint32_t LL_TIM_IsEnabledARRPreload(const TIM_TypeDef *TIMx)
  1073. {
  1074. return ((READ_BIT(TIMx->CR1, TIM_CR1_ARPE) == (TIM_CR1_ARPE)) ? 1UL : 0UL);
  1075. }
  1076. /**
  1077. * @brief Set the division ratio between the timer clock and the sampling clock used by the dead-time generators
  1078. * (when supported) and the digital filters.
  1079. * @note Macro IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx) can be used to check
  1080. * whether or not the clock division feature is supported by the timer
  1081. * instance.
  1082. * @rmtoll CR1 CKD LL_TIM_SetClockDivision
  1083. * @param TIMx Timer instance
  1084. * @param ClockDivision This parameter can be one of the following values:
  1085. * @arg @ref LL_TIM_CLOCKDIVISION_DIV1
  1086. * @arg @ref LL_TIM_CLOCKDIVISION_DIV2
  1087. * @arg @ref LL_TIM_CLOCKDIVISION_DIV4
  1088. * @retval None
  1089. */
  1090. __STATIC_INLINE void LL_TIM_SetClockDivision(TIM_TypeDef *TIMx, uint32_t ClockDivision)
  1091. {
  1092. MODIFY_REG(TIMx->CR1, TIM_CR1_CKD, ClockDivision);
  1093. }
  1094. /**
  1095. * @brief Get the actual division ratio between the timer clock and the sampling clock used by the dead-time
  1096. * generators (when supported) and the digital filters.
  1097. * @note Macro IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx) can be used to check
  1098. * whether or not the clock division feature is supported by the timer
  1099. * instance.
  1100. * @rmtoll CR1 CKD LL_TIM_GetClockDivision
  1101. * @param TIMx Timer instance
  1102. * @retval Returned value can be one of the following values:
  1103. * @arg @ref LL_TIM_CLOCKDIVISION_DIV1
  1104. * @arg @ref LL_TIM_CLOCKDIVISION_DIV2
  1105. * @arg @ref LL_TIM_CLOCKDIVISION_DIV4
  1106. */
  1107. __STATIC_INLINE uint32_t LL_TIM_GetClockDivision(const TIM_TypeDef *TIMx)
  1108. {
  1109. return (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_CKD));
  1110. }
  1111. /**
  1112. * @brief Set the counter value.
  1113. * @rmtoll CNT CNT LL_TIM_SetCounter
  1114. * @param TIMx Timer instance
  1115. * @param Counter Counter value (between Min_Data=0 and Max_Data=0xFFFF)
  1116. * @retval None
  1117. */
  1118. __STATIC_INLINE void LL_TIM_SetCounter(TIM_TypeDef *TIMx, uint32_t Counter)
  1119. {
  1120. WRITE_REG(TIMx->CNT, Counter);
  1121. }
  1122. /**
  1123. * @brief Get the counter value.
  1124. * @rmtoll CNT CNT LL_TIM_GetCounter
  1125. * @param TIMx Timer instance
  1126. * @retval Counter value (between Min_Data=0 and Max_Data=0xFFFF)
  1127. */
  1128. __STATIC_INLINE uint32_t LL_TIM_GetCounter(const TIM_TypeDef *TIMx)
  1129. {
  1130. return (uint32_t)(READ_REG(TIMx->CNT));
  1131. }
  1132. /**
  1133. * @brief Get the current direction of the counter
  1134. * @rmtoll CR1 DIR LL_TIM_GetDirection
  1135. * @param TIMx Timer instance
  1136. * @retval Returned value can be one of the following values:
  1137. * @arg @ref LL_TIM_COUNTERDIRECTION_UP
  1138. * @arg @ref LL_TIM_COUNTERDIRECTION_DOWN
  1139. */
  1140. __STATIC_INLINE uint32_t LL_TIM_GetDirection(const TIM_TypeDef *TIMx)
  1141. {
  1142. return (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_DIR));
  1143. }
  1144. /**
  1145. * @brief Set the prescaler value.
  1146. * @note The counter clock frequency CK_CNT is equal to fCK_PSC / (PSC[15:0] + 1).
  1147. * @note The prescaler can be changed on the fly as this control register is buffered. The new
  1148. * prescaler ratio is taken into account at the next update event.
  1149. * @note Helper macro @ref __LL_TIM_CALC_PSC can be used to calculate the Prescaler parameter
  1150. * @rmtoll PSC PSC LL_TIM_SetPrescaler
  1151. * @param TIMx Timer instance
  1152. * @param Prescaler between Min_Data=0 and Max_Data=65535
  1153. * @retval None
  1154. */
  1155. __STATIC_INLINE void LL_TIM_SetPrescaler(TIM_TypeDef *TIMx, uint32_t Prescaler)
  1156. {
  1157. WRITE_REG(TIMx->PSC, Prescaler);
  1158. }
  1159. /**
  1160. * @brief Get the prescaler value.
  1161. * @rmtoll PSC PSC LL_TIM_GetPrescaler
  1162. * @param TIMx Timer instance
  1163. * @retval Prescaler value between Min_Data=0 and Max_Data=65535
  1164. */
  1165. __STATIC_INLINE uint32_t LL_TIM_GetPrescaler(const TIM_TypeDef *TIMx)
  1166. {
  1167. return (uint32_t)(READ_REG(TIMx->PSC));
  1168. }
  1169. /**
  1170. * @brief Set the auto-reload value.
  1171. * @note The counter is blocked while the auto-reload value is null.
  1172. * @note Helper macro @ref __LL_TIM_CALC_ARR can be used to calculate the AutoReload parameter
  1173. * @rmtoll ARR ARR LL_TIM_SetAutoReload
  1174. * @param TIMx Timer instance
  1175. * @param AutoReload between Min_Data=0 and Max_Data=65535
  1176. * @retval None
  1177. */
  1178. __STATIC_INLINE void LL_TIM_SetAutoReload(TIM_TypeDef *TIMx, uint32_t AutoReload)
  1179. {
  1180. WRITE_REG(TIMx->ARR, AutoReload);
  1181. }
  1182. /**
  1183. * @brief Get the auto-reload value.
  1184. * @rmtoll ARR ARR LL_TIM_GetAutoReload
  1185. * @param TIMx Timer instance
  1186. * @retval Auto-reload value
  1187. */
  1188. __STATIC_INLINE uint32_t LL_TIM_GetAutoReload(const TIM_TypeDef *TIMx)
  1189. {
  1190. return (uint32_t)(READ_REG(TIMx->ARR));
  1191. }
  1192. /**
  1193. * @brief Set the repetition counter value.
  1194. * @note Macro IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx) can be used to check
  1195. * whether or not a timer instance supports a repetition counter.
  1196. * @rmtoll RCR REP LL_TIM_SetRepetitionCounter
  1197. * @param TIMx Timer instance
  1198. * @param RepetitionCounter between Min_Data=0 and Max_Data=255 or 65535 for advanced timer.
  1199. * @retval None
  1200. */
  1201. __STATIC_INLINE void LL_TIM_SetRepetitionCounter(TIM_TypeDef *TIMx, uint32_t RepetitionCounter)
  1202. {
  1203. WRITE_REG(TIMx->RCR, RepetitionCounter);
  1204. }
  1205. /**
  1206. * @brief Get the repetition counter value.
  1207. * @note Macro IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx) can be used to check
  1208. * whether or not a timer instance supports a repetition counter.
  1209. * @rmtoll RCR REP LL_TIM_GetRepetitionCounter
  1210. * @param TIMx Timer instance
  1211. * @retval Repetition counter value
  1212. */
  1213. __STATIC_INLINE uint32_t LL_TIM_GetRepetitionCounter(const TIM_TypeDef *TIMx)
  1214. {
  1215. return (uint32_t)(READ_REG(TIMx->RCR));
  1216. }
  1217. /**
  1218. * @}
  1219. */
  1220. /** @defgroup TIM_LL_EF_Capture_Compare Capture Compare configuration
  1221. * @{
  1222. */
  1223. /**
  1224. * @brief Enable the capture/compare control bits (CCxE, CCxNE and OCxM) preload.
  1225. * @note CCxE, CCxNE and OCxM bits are preloaded, after having been written,
  1226. * they are updated only when a commutation event (COM) occurs.
  1227. * @note Only on channels that have a complementary output.
  1228. * @note Macro IS_TIM_COMMUTATION_EVENT_INSTANCE(TIMx) can be used to check
  1229. * whether or not a timer instance is able to generate a commutation event.
  1230. * @rmtoll CR2 CCPC LL_TIM_CC_EnablePreload
  1231. * @param TIMx Timer instance
  1232. * @retval None
  1233. */
  1234. __STATIC_INLINE void LL_TIM_CC_EnablePreload(TIM_TypeDef *TIMx)
  1235. {
  1236. SET_BIT(TIMx->CR2, TIM_CR2_CCPC);
  1237. }
  1238. /**
  1239. * @brief Disable the capture/compare control bits (CCxE, CCxNE and OCxM) preload.
  1240. * @note Macro IS_TIM_COMMUTATION_EVENT_INSTANCE(TIMx) can be used to check
  1241. * whether or not a timer instance is able to generate a commutation event.
  1242. * @rmtoll CR2 CCPC LL_TIM_CC_DisablePreload
  1243. * @param TIMx Timer instance
  1244. * @retval None
  1245. */
  1246. __STATIC_INLINE void LL_TIM_CC_DisablePreload(TIM_TypeDef *TIMx)
  1247. {
  1248. CLEAR_BIT(TIMx->CR2, TIM_CR2_CCPC);
  1249. }
  1250. /**
  1251. * @brief Indicates whether the capture/compare control bits (CCxE, CCxNE and OCxM) preload is enabled.
  1252. * @rmtoll CR2 CCPC LL_TIM_CC_IsEnabledPreload
  1253. * @param TIMx Timer instance
  1254. * @retval State of bit (1 or 0).
  1255. */
  1256. __STATIC_INLINE uint32_t LL_TIM_CC_IsEnabledPreload(const TIM_TypeDef *TIMx)
  1257. {
  1258. return ((READ_BIT(TIMx->CR2, TIM_CR2_CCPC) == (TIM_CR2_CCPC)) ? 1UL : 0UL);
  1259. }
  1260. /**
  1261. * @brief Set the updated source of the capture/compare control bits (CCxE, CCxNE and OCxM).
  1262. * @note Macro IS_TIM_COMMUTATION_EVENT_INSTANCE(TIMx) can be used to check
  1263. * whether or not a timer instance is able to generate a commutation event.
  1264. * @rmtoll CR2 CCUS LL_TIM_CC_SetUpdate
  1265. * @param TIMx Timer instance
  1266. * @param CCUpdateSource This parameter can be one of the following values:
  1267. * @arg @ref LL_TIM_CCUPDATESOURCE_COMG_ONLY
  1268. * @arg @ref LL_TIM_CCUPDATESOURCE_COMG_AND_TRGI
  1269. * @retval None
  1270. */
  1271. __STATIC_INLINE void LL_TIM_CC_SetUpdate(TIM_TypeDef *TIMx, uint32_t CCUpdateSource)
  1272. {
  1273. MODIFY_REG(TIMx->CR2, TIM_CR2_CCUS, CCUpdateSource);
  1274. }
  1275. /**
  1276. * @brief Set the trigger of the capture/compare DMA request.
  1277. * @rmtoll CR2 CCDS LL_TIM_CC_SetDMAReqTrigger
  1278. * @param TIMx Timer instance
  1279. * @param DMAReqTrigger This parameter can be one of the following values:
  1280. * @arg @ref LL_TIM_CCDMAREQUEST_CC
  1281. * @arg @ref LL_TIM_CCDMAREQUEST_UPDATE
  1282. * @retval None
  1283. */
  1284. __STATIC_INLINE void LL_TIM_CC_SetDMAReqTrigger(TIM_TypeDef *TIMx, uint32_t DMAReqTrigger)
  1285. {
  1286. MODIFY_REG(TIMx->CR2, TIM_CR2_CCDS, DMAReqTrigger);
  1287. }
  1288. /**
  1289. * @brief Get actual trigger of the capture/compare DMA request.
  1290. * @rmtoll CR2 CCDS LL_TIM_CC_GetDMAReqTrigger
  1291. * @param TIMx Timer instance
  1292. * @retval Returned value can be one of the following values:
  1293. * @arg @ref LL_TIM_CCDMAREQUEST_CC
  1294. * @arg @ref LL_TIM_CCDMAREQUEST_UPDATE
  1295. */
  1296. __STATIC_INLINE uint32_t LL_TIM_CC_GetDMAReqTrigger(const TIM_TypeDef *TIMx)
  1297. {
  1298. return (uint32_t)(READ_BIT(TIMx->CR2, TIM_CR2_CCDS));
  1299. }
  1300. /**
  1301. * @brief Set the lock level to freeze the
  1302. * configuration of several capture/compare parameters.
  1303. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  1304. * the lock mechanism is supported by a timer instance.
  1305. * @rmtoll BDTR LOCK LL_TIM_CC_SetLockLevel
  1306. * @param TIMx Timer instance
  1307. * @param LockLevel This parameter can be one of the following values:
  1308. * @arg @ref LL_TIM_LOCKLEVEL_OFF
  1309. * @arg @ref LL_TIM_LOCKLEVEL_1
  1310. * @arg @ref LL_TIM_LOCKLEVEL_2
  1311. * @arg @ref LL_TIM_LOCKLEVEL_3
  1312. * @retval None
  1313. */
  1314. __STATIC_INLINE void LL_TIM_CC_SetLockLevel(TIM_TypeDef *TIMx, uint32_t LockLevel)
  1315. {
  1316. MODIFY_REG(TIMx->BDTR, TIM_BDTR_LOCK, LockLevel);
  1317. }
  1318. /**
  1319. * @brief Enable capture/compare channels.
  1320. * @rmtoll CCER CC1E LL_TIM_CC_EnableChannel\n
  1321. * CCER CC1NE LL_TIM_CC_EnableChannel\n
  1322. * CCER CC2E LL_TIM_CC_EnableChannel\n
  1323. * CCER CC2NE LL_TIM_CC_EnableChannel\n
  1324. * CCER CC3E LL_TIM_CC_EnableChannel\n
  1325. * CCER CC3NE LL_TIM_CC_EnableChannel\n
  1326. * CCER CC4E LL_TIM_CC_EnableChannel
  1327. * @param TIMx Timer instance
  1328. * @param Channels This parameter can be a combination of the following values:
  1329. * @arg @ref LL_TIM_CHANNEL_CH1
  1330. * @arg @ref LL_TIM_CHANNEL_CH1N
  1331. * @arg @ref LL_TIM_CHANNEL_CH2
  1332. * @arg @ref LL_TIM_CHANNEL_CH2N
  1333. * @arg @ref LL_TIM_CHANNEL_CH3
  1334. * @arg @ref LL_TIM_CHANNEL_CH3N
  1335. * @arg @ref LL_TIM_CHANNEL_CH4
  1336. * @retval None
  1337. */
  1338. __STATIC_INLINE void LL_TIM_CC_EnableChannel(TIM_TypeDef *TIMx, uint32_t Channels)
  1339. {
  1340. SET_BIT(TIMx->CCER, Channels);
  1341. }
  1342. /**
  1343. * @brief Disable capture/compare channels.
  1344. * @rmtoll CCER CC1E LL_TIM_CC_DisableChannel\n
  1345. * CCER CC1NE LL_TIM_CC_DisableChannel\n
  1346. * CCER CC2E LL_TIM_CC_DisableChannel\n
  1347. * CCER CC2NE LL_TIM_CC_DisableChannel\n
  1348. * CCER CC3E LL_TIM_CC_DisableChannel\n
  1349. * CCER CC3NE LL_TIM_CC_DisableChannel\n
  1350. * CCER CC4E LL_TIM_CC_DisableChannel
  1351. * @param TIMx Timer instance
  1352. * @param Channels This parameter can be a combination of the following values:
  1353. * @arg @ref LL_TIM_CHANNEL_CH1
  1354. * @arg @ref LL_TIM_CHANNEL_CH1N
  1355. * @arg @ref LL_TIM_CHANNEL_CH2
  1356. * @arg @ref LL_TIM_CHANNEL_CH2N
  1357. * @arg @ref LL_TIM_CHANNEL_CH3
  1358. * @arg @ref LL_TIM_CHANNEL_CH3N
  1359. * @arg @ref LL_TIM_CHANNEL_CH4
  1360. * @retval None
  1361. */
  1362. __STATIC_INLINE void LL_TIM_CC_DisableChannel(TIM_TypeDef *TIMx, uint32_t Channels)
  1363. {
  1364. CLEAR_BIT(TIMx->CCER, Channels);
  1365. }
  1366. /**
  1367. * @brief Indicate whether channel(s) is(are) enabled.
  1368. * @rmtoll CCER CC1E LL_TIM_CC_IsEnabledChannel\n
  1369. * CCER CC1NE LL_TIM_CC_IsEnabledChannel\n
  1370. * CCER CC2E LL_TIM_CC_IsEnabledChannel\n
  1371. * CCER CC2NE LL_TIM_CC_IsEnabledChannel\n
  1372. * CCER CC3E LL_TIM_CC_IsEnabledChannel\n
  1373. * CCER CC3NE LL_TIM_CC_IsEnabledChannel\n
  1374. * CCER CC4E LL_TIM_CC_IsEnabledChannel
  1375. * @param TIMx Timer instance
  1376. * @param Channels This parameter can be a combination of the following values:
  1377. * @arg @ref LL_TIM_CHANNEL_CH1
  1378. * @arg @ref LL_TIM_CHANNEL_CH1N
  1379. * @arg @ref LL_TIM_CHANNEL_CH2
  1380. * @arg @ref LL_TIM_CHANNEL_CH2N
  1381. * @arg @ref LL_TIM_CHANNEL_CH3
  1382. * @arg @ref LL_TIM_CHANNEL_CH3N
  1383. * @arg @ref LL_TIM_CHANNEL_CH4
  1384. * @retval State of bit (1 or 0).
  1385. */
  1386. __STATIC_INLINE uint32_t LL_TIM_CC_IsEnabledChannel(const TIM_TypeDef *TIMx, uint32_t Channels)
  1387. {
  1388. return ((READ_BIT(TIMx->CCER, Channels) == (Channels)) ? 1UL : 0UL);
  1389. }
  1390. /**
  1391. * @}
  1392. */
  1393. /** @defgroup TIM_LL_EF_Output_Channel Output channel configuration
  1394. * @{
  1395. */
  1396. /**
  1397. * @brief Configure an output channel.
  1398. * @rmtoll CCMR1 CC1S LL_TIM_OC_ConfigOutput\n
  1399. * CCMR1 CC2S LL_TIM_OC_ConfigOutput\n
  1400. * CCMR2 CC3S LL_TIM_OC_ConfigOutput\n
  1401. * CCMR2 CC4S LL_TIM_OC_ConfigOutput\n
  1402. * CCER CC1P LL_TIM_OC_ConfigOutput\n
  1403. * CCER CC2P LL_TIM_OC_ConfigOutput\n
  1404. * CCER CC3P LL_TIM_OC_ConfigOutput\n
  1405. * CCER CC4P LL_TIM_OC_ConfigOutput\n
  1406. * CR2 OIS1 LL_TIM_OC_ConfigOutput\n
  1407. * CR2 OIS2 LL_TIM_OC_ConfigOutput\n
  1408. * CR2 OIS3 LL_TIM_OC_ConfigOutput\n
  1409. * CR2 OIS4 LL_TIM_OC_ConfigOutput
  1410. * @param TIMx Timer instance
  1411. * @param Channel This parameter can be one of the following values:
  1412. * @arg @ref LL_TIM_CHANNEL_CH1
  1413. * @arg @ref LL_TIM_CHANNEL_CH2
  1414. * @arg @ref LL_TIM_CHANNEL_CH3
  1415. * @arg @ref LL_TIM_CHANNEL_CH4
  1416. * @param Configuration This parameter must be a combination of all the following values:
  1417. * @arg @ref LL_TIM_OCPOLARITY_HIGH or @ref LL_TIM_OCPOLARITY_LOW
  1418. * @arg @ref LL_TIM_OCIDLESTATE_LOW or @ref LL_TIM_OCIDLESTATE_HIGH
  1419. * @retval None
  1420. */
  1421. __STATIC_INLINE void LL_TIM_OC_ConfigOutput(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t Configuration)
  1422. {
  1423. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1424. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1425. CLEAR_BIT(*pReg, (TIM_CCMR1_CC1S << SHIFT_TAB_OCxx[iChannel]));
  1426. MODIFY_REG(TIMx->CCER, (TIM_CCER_CC1P << SHIFT_TAB_CCxP[iChannel]),
  1427. (Configuration & TIM_CCER_CC1P) << SHIFT_TAB_CCxP[iChannel]);
  1428. MODIFY_REG(TIMx->CR2, (TIM_CR2_OIS1 << SHIFT_TAB_OISx[iChannel]),
  1429. (Configuration & TIM_CR2_OIS1) << SHIFT_TAB_OISx[iChannel]);
  1430. }
  1431. /**
  1432. * @brief Define the behavior of the output reference signal OCxREF from which
  1433. * OCx and OCxN (when relevant) are derived.
  1434. * @rmtoll CCMR1 OC1M LL_TIM_OC_SetMode\n
  1435. * CCMR1 OC2M LL_TIM_OC_SetMode\n
  1436. * CCMR2 OC3M LL_TIM_OC_SetMode\n
  1437. * CCMR2 OC4M LL_TIM_OC_SetMode
  1438. * @param TIMx Timer instance
  1439. * @param Channel This parameter can be one of the following values:
  1440. * @arg @ref LL_TIM_CHANNEL_CH1
  1441. * @arg @ref LL_TIM_CHANNEL_CH2
  1442. * @arg @ref LL_TIM_CHANNEL_CH3
  1443. * @arg @ref LL_TIM_CHANNEL_CH4
  1444. * @param Mode This parameter can be one of the following values:
  1445. * @arg @ref LL_TIM_OCMODE_FROZEN
  1446. * @arg @ref LL_TIM_OCMODE_ACTIVE
  1447. * @arg @ref LL_TIM_OCMODE_INACTIVE
  1448. * @arg @ref LL_TIM_OCMODE_TOGGLE
  1449. * @arg @ref LL_TIM_OCMODE_FORCED_INACTIVE
  1450. * @arg @ref LL_TIM_OCMODE_FORCED_ACTIVE
  1451. * @arg @ref LL_TIM_OCMODE_PWM1
  1452. * @arg @ref LL_TIM_OCMODE_PWM2
  1453. * @retval None
  1454. */
  1455. __STATIC_INLINE void LL_TIM_OC_SetMode(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t Mode)
  1456. {
  1457. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1458. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1459. MODIFY_REG(*pReg, ((TIM_CCMR1_OC1M | TIM_CCMR1_CC1S) << SHIFT_TAB_OCxx[iChannel]), Mode << SHIFT_TAB_OCxx[iChannel]);
  1460. }
  1461. /**
  1462. * @brief Get the output compare mode of an output channel.
  1463. * @rmtoll CCMR1 OC1M LL_TIM_OC_GetMode\n
  1464. * CCMR1 OC2M LL_TIM_OC_GetMode\n
  1465. * CCMR2 OC3M LL_TIM_OC_GetMode\n
  1466. * CCMR2 OC4M LL_TIM_OC_GetMode
  1467. * @param TIMx Timer instance
  1468. * @param Channel This parameter can be one of the following values:
  1469. * @arg @ref LL_TIM_CHANNEL_CH1
  1470. * @arg @ref LL_TIM_CHANNEL_CH2
  1471. * @arg @ref LL_TIM_CHANNEL_CH3
  1472. * @arg @ref LL_TIM_CHANNEL_CH4
  1473. * @retval Returned value can be one of the following values:
  1474. * @arg @ref LL_TIM_OCMODE_FROZEN
  1475. * @arg @ref LL_TIM_OCMODE_ACTIVE
  1476. * @arg @ref LL_TIM_OCMODE_INACTIVE
  1477. * @arg @ref LL_TIM_OCMODE_TOGGLE
  1478. * @arg @ref LL_TIM_OCMODE_FORCED_INACTIVE
  1479. * @arg @ref LL_TIM_OCMODE_FORCED_ACTIVE
  1480. * @arg @ref LL_TIM_OCMODE_PWM1
  1481. * @arg @ref LL_TIM_OCMODE_PWM2
  1482. */
  1483. __STATIC_INLINE uint32_t LL_TIM_OC_GetMode(const TIM_TypeDef *TIMx, uint32_t Channel)
  1484. {
  1485. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1486. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1487. return (READ_BIT(*pReg, ((TIM_CCMR1_OC1M | TIM_CCMR1_CC1S) << SHIFT_TAB_OCxx[iChannel])) >> SHIFT_TAB_OCxx[iChannel]);
  1488. }
  1489. /**
  1490. * @brief Set the polarity of an output channel.
  1491. * @rmtoll CCER CC1P LL_TIM_OC_SetPolarity\n
  1492. * CCER CC1NP LL_TIM_OC_SetPolarity\n
  1493. * CCER CC2P LL_TIM_OC_SetPolarity\n
  1494. * CCER CC2NP LL_TIM_OC_SetPolarity\n
  1495. * CCER CC3P LL_TIM_OC_SetPolarity\n
  1496. * CCER CC3NP LL_TIM_OC_SetPolarity\n
  1497. * CCER CC4P LL_TIM_OC_SetPolarity
  1498. * @param TIMx Timer instance
  1499. * @param Channel This parameter can be one of the following values:
  1500. * @arg @ref LL_TIM_CHANNEL_CH1
  1501. * @arg @ref LL_TIM_CHANNEL_CH1N
  1502. * @arg @ref LL_TIM_CHANNEL_CH2
  1503. * @arg @ref LL_TIM_CHANNEL_CH2N
  1504. * @arg @ref LL_TIM_CHANNEL_CH3
  1505. * @arg @ref LL_TIM_CHANNEL_CH3N
  1506. * @arg @ref LL_TIM_CHANNEL_CH4
  1507. * @param Polarity This parameter can be one of the following values:
  1508. * @arg @ref LL_TIM_OCPOLARITY_HIGH
  1509. * @arg @ref LL_TIM_OCPOLARITY_LOW
  1510. * @retval None
  1511. */
  1512. __STATIC_INLINE void LL_TIM_OC_SetPolarity(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t Polarity)
  1513. {
  1514. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1515. MODIFY_REG(TIMx->CCER, (TIM_CCER_CC1P << SHIFT_TAB_CCxP[iChannel]), Polarity << SHIFT_TAB_CCxP[iChannel]);
  1516. }
  1517. /**
  1518. * @brief Get the polarity of an output channel.
  1519. * @rmtoll CCER CC1P LL_TIM_OC_GetPolarity\n
  1520. * CCER CC1NP LL_TIM_OC_GetPolarity\n
  1521. * CCER CC2P LL_TIM_OC_GetPolarity\n
  1522. * CCER CC2NP LL_TIM_OC_GetPolarity\n
  1523. * CCER CC3P LL_TIM_OC_GetPolarity\n
  1524. * CCER CC3NP LL_TIM_OC_GetPolarity\n
  1525. * CCER CC4P LL_TIM_OC_GetPolarity
  1526. * @param TIMx Timer instance
  1527. * @param Channel This parameter can be one of the following values:
  1528. * @arg @ref LL_TIM_CHANNEL_CH1
  1529. * @arg @ref LL_TIM_CHANNEL_CH1N
  1530. * @arg @ref LL_TIM_CHANNEL_CH2
  1531. * @arg @ref LL_TIM_CHANNEL_CH2N
  1532. * @arg @ref LL_TIM_CHANNEL_CH3
  1533. * @arg @ref LL_TIM_CHANNEL_CH3N
  1534. * @arg @ref LL_TIM_CHANNEL_CH4
  1535. * @retval Returned value can be one of the following values:
  1536. * @arg @ref LL_TIM_OCPOLARITY_HIGH
  1537. * @arg @ref LL_TIM_OCPOLARITY_LOW
  1538. */
  1539. __STATIC_INLINE uint32_t LL_TIM_OC_GetPolarity(const TIM_TypeDef *TIMx, uint32_t Channel)
  1540. {
  1541. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1542. return (READ_BIT(TIMx->CCER, (TIM_CCER_CC1P << SHIFT_TAB_CCxP[iChannel])) >> SHIFT_TAB_CCxP[iChannel]);
  1543. }
  1544. /**
  1545. * @brief Set the IDLE state of an output channel
  1546. * @note This function is significant only for the timer instances
  1547. * supporting the break feature. Macro IS_TIM_BREAK_INSTANCE(TIMx)
  1548. * can be used to check whether or not a timer instance provides
  1549. * a break input.
  1550. * @rmtoll CR2 OIS1 LL_TIM_OC_SetIdleState\n
  1551. * CR2 OIS1N LL_TIM_OC_SetIdleState\n
  1552. * CR2 OIS2 LL_TIM_OC_SetIdleState\n
  1553. * CR2 OIS2N LL_TIM_OC_SetIdleState\n
  1554. * CR2 OIS3 LL_TIM_OC_SetIdleState\n
  1555. * CR2 OIS3N LL_TIM_OC_SetIdleState\n
  1556. * CR2 OIS4 LL_TIM_OC_SetIdleState
  1557. * @param TIMx Timer instance
  1558. * @param Channel This parameter can be one of the following values:
  1559. * @arg @ref LL_TIM_CHANNEL_CH1
  1560. * @arg @ref LL_TIM_CHANNEL_CH1N
  1561. * @arg @ref LL_TIM_CHANNEL_CH2
  1562. * @arg @ref LL_TIM_CHANNEL_CH2N
  1563. * @arg @ref LL_TIM_CHANNEL_CH3
  1564. * @arg @ref LL_TIM_CHANNEL_CH3N
  1565. * @arg @ref LL_TIM_CHANNEL_CH4
  1566. * @param IdleState This parameter can be one of the following values:
  1567. * @arg @ref LL_TIM_OCIDLESTATE_LOW
  1568. * @arg @ref LL_TIM_OCIDLESTATE_HIGH
  1569. * @retval None
  1570. */
  1571. __STATIC_INLINE void LL_TIM_OC_SetIdleState(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t IdleState)
  1572. {
  1573. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1574. MODIFY_REG(TIMx->CR2, (TIM_CR2_OIS1 << SHIFT_TAB_OISx[iChannel]), IdleState << SHIFT_TAB_OISx[iChannel]);
  1575. }
  1576. /**
  1577. * @brief Get the IDLE state of an output channel
  1578. * @rmtoll CR2 OIS1 LL_TIM_OC_GetIdleState\n
  1579. * CR2 OIS1N LL_TIM_OC_GetIdleState\n
  1580. * CR2 OIS2 LL_TIM_OC_GetIdleState\n
  1581. * CR2 OIS2N LL_TIM_OC_GetIdleState\n
  1582. * CR2 OIS3 LL_TIM_OC_GetIdleState\n
  1583. * CR2 OIS3N LL_TIM_OC_GetIdleState\n
  1584. * CR2 OIS4 LL_TIM_OC_GetIdleState
  1585. * @param TIMx Timer instance
  1586. * @param Channel This parameter can be one of the following values:
  1587. * @arg @ref LL_TIM_CHANNEL_CH1
  1588. * @arg @ref LL_TIM_CHANNEL_CH1N
  1589. * @arg @ref LL_TIM_CHANNEL_CH2
  1590. * @arg @ref LL_TIM_CHANNEL_CH2N
  1591. * @arg @ref LL_TIM_CHANNEL_CH3
  1592. * @arg @ref LL_TIM_CHANNEL_CH3N
  1593. * @arg @ref LL_TIM_CHANNEL_CH4
  1594. * @retval Returned value can be one of the following values:
  1595. * @arg @ref LL_TIM_OCIDLESTATE_LOW
  1596. * @arg @ref LL_TIM_OCIDLESTATE_HIGH
  1597. */
  1598. __STATIC_INLINE uint32_t LL_TIM_OC_GetIdleState(const TIM_TypeDef *TIMx, uint32_t Channel)
  1599. {
  1600. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1601. return (READ_BIT(TIMx->CR2, (TIM_CR2_OIS1 << SHIFT_TAB_OISx[iChannel])) >> SHIFT_TAB_OISx[iChannel]);
  1602. }
  1603. /**
  1604. * @brief Enable fast mode for the output channel.
  1605. * @note Acts only if the channel is configured in PWM1 or PWM2 mode.
  1606. * @rmtoll CCMR1 OC1FE LL_TIM_OC_EnableFast\n
  1607. * CCMR1 OC2FE LL_TIM_OC_EnableFast\n
  1608. * CCMR2 OC3FE LL_TIM_OC_EnableFast\n
  1609. * CCMR2 OC4FE LL_TIM_OC_EnableFast
  1610. * @param TIMx Timer instance
  1611. * @param Channel This parameter can be one of the following values:
  1612. * @arg @ref LL_TIM_CHANNEL_CH1
  1613. * @arg @ref LL_TIM_CHANNEL_CH2
  1614. * @arg @ref LL_TIM_CHANNEL_CH3
  1615. * @arg @ref LL_TIM_CHANNEL_CH4
  1616. * @retval None
  1617. */
  1618. __STATIC_INLINE void LL_TIM_OC_EnableFast(TIM_TypeDef *TIMx, uint32_t Channel)
  1619. {
  1620. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1621. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1622. SET_BIT(*pReg, (TIM_CCMR1_OC1FE << SHIFT_TAB_OCxx[iChannel]));
  1623. }
  1624. /**
  1625. * @brief Disable fast mode for the output channel.
  1626. * @rmtoll CCMR1 OC1FE LL_TIM_OC_DisableFast\n
  1627. * CCMR1 OC2FE LL_TIM_OC_DisableFast\n
  1628. * CCMR2 OC3FE LL_TIM_OC_DisableFast\n
  1629. * CCMR2 OC4FE LL_TIM_OC_DisableFast
  1630. * @param TIMx Timer instance
  1631. * @param Channel This parameter can be one of the following values:
  1632. * @arg @ref LL_TIM_CHANNEL_CH1
  1633. * @arg @ref LL_TIM_CHANNEL_CH2
  1634. * @arg @ref LL_TIM_CHANNEL_CH3
  1635. * @arg @ref LL_TIM_CHANNEL_CH4
  1636. * @retval None
  1637. */
  1638. __STATIC_INLINE void LL_TIM_OC_DisableFast(TIM_TypeDef *TIMx, uint32_t Channel)
  1639. {
  1640. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1641. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1642. CLEAR_BIT(*pReg, (TIM_CCMR1_OC1FE << SHIFT_TAB_OCxx[iChannel]));
  1643. }
  1644. /**
  1645. * @brief Indicates whether fast mode is enabled for the output channel.
  1646. * @rmtoll CCMR1 OC1FE LL_TIM_OC_IsEnabledFast\n
  1647. * CCMR1 OC2FE LL_TIM_OC_IsEnabledFast\n
  1648. * CCMR2 OC3FE LL_TIM_OC_IsEnabledFast\n
  1649. * CCMR2 OC4FE LL_TIM_OC_IsEnabledFast\n
  1650. * @param TIMx Timer instance
  1651. * @param Channel This parameter can be one of the following values:
  1652. * @arg @ref LL_TIM_CHANNEL_CH1
  1653. * @arg @ref LL_TIM_CHANNEL_CH2
  1654. * @arg @ref LL_TIM_CHANNEL_CH3
  1655. * @arg @ref LL_TIM_CHANNEL_CH4
  1656. * @retval State of bit (1 or 0).
  1657. */
  1658. __STATIC_INLINE uint32_t LL_TIM_OC_IsEnabledFast(const TIM_TypeDef *TIMx, uint32_t Channel)
  1659. {
  1660. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1661. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1662. uint32_t bitfield = TIM_CCMR1_OC1FE << SHIFT_TAB_OCxx[iChannel];
  1663. return ((READ_BIT(*pReg, bitfield) == bitfield) ? 1UL : 0UL);
  1664. }
  1665. /**
  1666. * @brief Enable compare register (TIMx_CCRx) preload for the output channel.
  1667. * @rmtoll CCMR1 OC1PE LL_TIM_OC_EnablePreload\n
  1668. * CCMR1 OC2PE LL_TIM_OC_EnablePreload\n
  1669. * CCMR2 OC3PE LL_TIM_OC_EnablePreload\n
  1670. * CCMR2 OC4PE LL_TIM_OC_EnablePreload
  1671. * @param TIMx Timer instance
  1672. * @param Channel This parameter can be one of the following values:
  1673. * @arg @ref LL_TIM_CHANNEL_CH1
  1674. * @arg @ref LL_TIM_CHANNEL_CH2
  1675. * @arg @ref LL_TIM_CHANNEL_CH3
  1676. * @arg @ref LL_TIM_CHANNEL_CH4
  1677. * @retval None
  1678. */
  1679. __STATIC_INLINE void LL_TIM_OC_EnablePreload(TIM_TypeDef *TIMx, uint32_t Channel)
  1680. {
  1681. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1682. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1683. SET_BIT(*pReg, (TIM_CCMR1_OC1PE << SHIFT_TAB_OCxx[iChannel]));
  1684. }
  1685. /**
  1686. * @brief Disable compare register (TIMx_CCRx) preload for the output channel.
  1687. * @rmtoll CCMR1 OC1PE LL_TIM_OC_DisablePreload\n
  1688. * CCMR1 OC2PE LL_TIM_OC_DisablePreload\n
  1689. * CCMR2 OC3PE LL_TIM_OC_DisablePreload\n
  1690. * CCMR2 OC4PE LL_TIM_OC_DisablePreload
  1691. * @param TIMx Timer instance
  1692. * @param Channel This parameter can be one of the following values:
  1693. * @arg @ref LL_TIM_CHANNEL_CH1
  1694. * @arg @ref LL_TIM_CHANNEL_CH2
  1695. * @arg @ref LL_TIM_CHANNEL_CH3
  1696. * @arg @ref LL_TIM_CHANNEL_CH4
  1697. * @retval None
  1698. */
  1699. __STATIC_INLINE void LL_TIM_OC_DisablePreload(TIM_TypeDef *TIMx, uint32_t Channel)
  1700. {
  1701. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1702. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1703. CLEAR_BIT(*pReg, (TIM_CCMR1_OC1PE << SHIFT_TAB_OCxx[iChannel]));
  1704. }
  1705. /**
  1706. * @brief Indicates whether compare register (TIMx_CCRx) preload is enabled for the output channel.
  1707. * @rmtoll CCMR1 OC1PE LL_TIM_OC_IsEnabledPreload\n
  1708. * CCMR1 OC2PE LL_TIM_OC_IsEnabledPreload\n
  1709. * CCMR2 OC3PE LL_TIM_OC_IsEnabledPreload\n
  1710. * CCMR2 OC4PE LL_TIM_OC_IsEnabledPreload\n
  1711. * @param TIMx Timer instance
  1712. * @param Channel This parameter can be one of the following values:
  1713. * @arg @ref LL_TIM_CHANNEL_CH1
  1714. * @arg @ref LL_TIM_CHANNEL_CH2
  1715. * @arg @ref LL_TIM_CHANNEL_CH3
  1716. * @arg @ref LL_TIM_CHANNEL_CH4
  1717. * @retval State of bit (1 or 0).
  1718. */
  1719. __STATIC_INLINE uint32_t LL_TIM_OC_IsEnabledPreload(const TIM_TypeDef *TIMx, uint32_t Channel)
  1720. {
  1721. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1722. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1723. uint32_t bitfield = TIM_CCMR1_OC1PE << SHIFT_TAB_OCxx[iChannel];
  1724. return ((READ_BIT(*pReg, bitfield) == bitfield) ? 1UL : 0UL);
  1725. }
  1726. /**
  1727. * @brief Enable clearing the output channel on an external event.
  1728. * @note This function can only be used in Output compare and PWM modes. It does not work in Forced mode.
  1729. * @note Macro IS_TIM_OCXREF_CLEAR_INSTANCE(TIMx) can be used to check whether
  1730. * or not a timer instance can clear the OCxREF signal on an external event.
  1731. * @rmtoll CCMR1 OC1CE LL_TIM_OC_EnableClear\n
  1732. * CCMR1 OC2CE LL_TIM_OC_EnableClear\n
  1733. * CCMR2 OC3CE LL_TIM_OC_EnableClear\n
  1734. * CCMR2 OC4CE LL_TIM_OC_EnableClear
  1735. * @param TIMx Timer instance
  1736. * @param Channel This parameter can be one of the following values:
  1737. * @arg @ref LL_TIM_CHANNEL_CH1
  1738. * @arg @ref LL_TIM_CHANNEL_CH2
  1739. * @arg @ref LL_TIM_CHANNEL_CH3
  1740. * @arg @ref LL_TIM_CHANNEL_CH4
  1741. * @retval None
  1742. */
  1743. __STATIC_INLINE void LL_TIM_OC_EnableClear(TIM_TypeDef *TIMx, uint32_t Channel)
  1744. {
  1745. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1746. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1747. SET_BIT(*pReg, (TIM_CCMR1_OC1CE << SHIFT_TAB_OCxx[iChannel]));
  1748. }
  1749. /**
  1750. * @brief Disable clearing the output channel on an external event.
  1751. * @note Macro IS_TIM_OCXREF_CLEAR_INSTANCE(TIMx) can be used to check whether
  1752. * or not a timer instance can clear the OCxREF signal on an external event.
  1753. * @rmtoll CCMR1 OC1CE LL_TIM_OC_DisableClear\n
  1754. * CCMR1 OC2CE LL_TIM_OC_DisableClear\n
  1755. * CCMR2 OC3CE LL_TIM_OC_DisableClear\n
  1756. * CCMR2 OC4CE LL_TIM_OC_DisableClear
  1757. * @param TIMx Timer instance
  1758. * @param Channel This parameter can be one of the following values:
  1759. * @arg @ref LL_TIM_CHANNEL_CH1
  1760. * @arg @ref LL_TIM_CHANNEL_CH2
  1761. * @arg @ref LL_TIM_CHANNEL_CH3
  1762. * @arg @ref LL_TIM_CHANNEL_CH4
  1763. * @retval None
  1764. */
  1765. __STATIC_INLINE void LL_TIM_OC_DisableClear(TIM_TypeDef *TIMx, uint32_t Channel)
  1766. {
  1767. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1768. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1769. CLEAR_BIT(*pReg, (TIM_CCMR1_OC1CE << SHIFT_TAB_OCxx[iChannel]));
  1770. }
  1771. /**
  1772. * @brief Indicates clearing the output channel on an external event is enabled for the output channel.
  1773. * @note This function enables clearing the output channel on an external event.
  1774. * @note This function can only be used in Output compare and PWM modes. It does not work in Forced mode.
  1775. * @note Macro IS_TIM_OCXREF_CLEAR_INSTANCE(TIMx) can be used to check whether
  1776. * or not a timer instance can clear the OCxREF signal on an external event.
  1777. * @rmtoll CCMR1 OC1CE LL_TIM_OC_IsEnabledClear\n
  1778. * CCMR1 OC2CE LL_TIM_OC_IsEnabledClear\n
  1779. * CCMR2 OC3CE LL_TIM_OC_IsEnabledClear\n
  1780. * CCMR2 OC4CE LL_TIM_OC_IsEnabledClear\n
  1781. * @param TIMx Timer instance
  1782. * @param Channel This parameter can be one of the following values:
  1783. * @arg @ref LL_TIM_CHANNEL_CH1
  1784. * @arg @ref LL_TIM_CHANNEL_CH2
  1785. * @arg @ref LL_TIM_CHANNEL_CH3
  1786. * @arg @ref LL_TIM_CHANNEL_CH4
  1787. * @retval State of bit (1 or 0).
  1788. */
  1789. __STATIC_INLINE uint32_t LL_TIM_OC_IsEnabledClear(const TIM_TypeDef *TIMx, uint32_t Channel)
  1790. {
  1791. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1792. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1793. uint32_t bitfield = TIM_CCMR1_OC1CE << SHIFT_TAB_OCxx[iChannel];
  1794. return ((READ_BIT(*pReg, bitfield) == bitfield) ? 1UL : 0UL);
  1795. }
  1796. /**
  1797. * @brief Set the dead-time delay (delay inserted between the rising edge of the OCxREF signal and the rising edge of
  1798. * the Ocx and OCxN signals).
  1799. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  1800. * dead-time insertion feature is supported by a timer instance.
  1801. * @note Helper macro @ref __LL_TIM_CALC_DEADTIME can be used to calculate the DeadTime parameter
  1802. * @rmtoll BDTR DTG LL_TIM_OC_SetDeadTime
  1803. * @param TIMx Timer instance
  1804. * @param DeadTime between Min_Data=0 and Max_Data=255
  1805. * @retval None
  1806. */
  1807. __STATIC_INLINE void LL_TIM_OC_SetDeadTime(TIM_TypeDef *TIMx, uint32_t DeadTime)
  1808. {
  1809. MODIFY_REG(TIMx->BDTR, TIM_BDTR_DTG, DeadTime);
  1810. }
  1811. /**
  1812. * @brief Set compare value for output channel 1 (TIMx_CCR1).
  1813. * @note Macro IS_TIM_CC1_INSTANCE(TIMx) can be used to check whether or not
  1814. * output channel 1 is supported by a timer instance.
  1815. * @rmtoll CCR1 CCR1 LL_TIM_OC_SetCompareCH1
  1816. * @param TIMx Timer instance
  1817. * @param CompareValue between Min_Data=0 and Max_Data=65535
  1818. * @retval None
  1819. */
  1820. __STATIC_INLINE void LL_TIM_OC_SetCompareCH1(TIM_TypeDef *TIMx, uint32_t CompareValue)
  1821. {
  1822. WRITE_REG(TIMx->CCR1, CompareValue);
  1823. }
  1824. /**
  1825. * @brief Set compare value for output channel 2 (TIMx_CCR2).
  1826. * @note Macro IS_TIM_CC2_INSTANCE(TIMx) can be used to check whether or not
  1827. * output channel 2 is supported by a timer instance.
  1828. * @rmtoll CCR2 CCR2 LL_TIM_OC_SetCompareCH2
  1829. * @param TIMx Timer instance
  1830. * @param CompareValue between Min_Data=0 and Max_Data=65535
  1831. * @retval None
  1832. */
  1833. __STATIC_INLINE void LL_TIM_OC_SetCompareCH2(TIM_TypeDef *TIMx, uint32_t CompareValue)
  1834. {
  1835. WRITE_REG(TIMx->CCR2, CompareValue);
  1836. }
  1837. /**
  1838. * @brief Set compare value for output channel 3 (TIMx_CCR3).
  1839. * @note Macro IS_TIM_CC3_INSTANCE(TIMx) can be used to check whether or not
  1840. * output channel is supported by a timer instance.
  1841. * @rmtoll CCR3 CCR3 LL_TIM_OC_SetCompareCH3
  1842. * @param TIMx Timer instance
  1843. * @param CompareValue between Min_Data=0 and Max_Data=65535
  1844. * @retval None
  1845. */
  1846. __STATIC_INLINE void LL_TIM_OC_SetCompareCH3(TIM_TypeDef *TIMx, uint32_t CompareValue)
  1847. {
  1848. WRITE_REG(TIMx->CCR3, CompareValue);
  1849. }
  1850. /**
  1851. * @brief Set compare value for output channel 4 (TIMx_CCR4).
  1852. * @note Macro IS_TIM_CC4_INSTANCE(TIMx) can be used to check whether or not
  1853. * output channel 4 is supported by a timer instance.
  1854. * @rmtoll CCR4 CCR4 LL_TIM_OC_SetCompareCH4
  1855. * @param TIMx Timer instance
  1856. * @param CompareValue between Min_Data=0 and Max_Data=65535
  1857. * @retval None
  1858. */
  1859. __STATIC_INLINE void LL_TIM_OC_SetCompareCH4(TIM_TypeDef *TIMx, uint32_t CompareValue)
  1860. {
  1861. WRITE_REG(TIMx->CCR4, CompareValue);
  1862. }
  1863. /**
  1864. * @brief Get compare value (TIMx_CCR1) set for output channel 1.
  1865. * @note Macro IS_TIM_CC1_INSTANCE(TIMx) can be used to check whether or not
  1866. * output channel 1 is supported by a timer instance.
  1867. * @rmtoll CCR1 CCR1 LL_TIM_OC_GetCompareCH1
  1868. * @param TIMx Timer instance
  1869. * @retval CompareValue (between Min_Data=0 and Max_Data=65535)
  1870. */
  1871. __STATIC_INLINE uint32_t LL_TIM_OC_GetCompareCH1(const TIM_TypeDef *TIMx)
  1872. {
  1873. return (uint32_t)(READ_REG(TIMx->CCR1));
  1874. }
  1875. /**
  1876. * @brief Get compare value (TIMx_CCR2) set for output channel 2.
  1877. * @note Macro IS_TIM_CC2_INSTANCE(TIMx) can be used to check whether or not
  1878. * output channel 2 is supported by a timer instance.
  1879. * @rmtoll CCR2 CCR2 LL_TIM_OC_GetCompareCH2
  1880. * @param TIMx Timer instance
  1881. * @retval CompareValue (between Min_Data=0 and Max_Data=65535)
  1882. */
  1883. __STATIC_INLINE uint32_t LL_TIM_OC_GetCompareCH2(const TIM_TypeDef *TIMx)
  1884. {
  1885. return (uint32_t)(READ_REG(TIMx->CCR2));
  1886. }
  1887. /**
  1888. * @brief Get compare value (TIMx_CCR3) set for output channel 3.
  1889. * @note Macro IS_TIM_CC3_INSTANCE(TIMx) can be used to check whether or not
  1890. * output channel 3 is supported by a timer instance.
  1891. * @rmtoll CCR3 CCR3 LL_TIM_OC_GetCompareCH3
  1892. * @param TIMx Timer instance
  1893. * @retval CompareValue (between Min_Data=0 and Max_Data=65535)
  1894. */
  1895. __STATIC_INLINE uint32_t LL_TIM_OC_GetCompareCH3(const TIM_TypeDef *TIMx)
  1896. {
  1897. return (uint32_t)(READ_REG(TIMx->CCR3));
  1898. }
  1899. /**
  1900. * @brief Get compare value (TIMx_CCR4) set for output channel 4.
  1901. * @note Macro IS_TIM_CC4_INSTANCE(TIMx) can be used to check whether or not
  1902. * output channel 4 is supported by a timer instance.
  1903. * @rmtoll CCR4 CCR4 LL_TIM_OC_GetCompareCH4
  1904. * @param TIMx Timer instance
  1905. * @retval CompareValue (between Min_Data=0 and Max_Data=65535)
  1906. */
  1907. __STATIC_INLINE uint32_t LL_TIM_OC_GetCompareCH4(const TIM_TypeDef *TIMx)
  1908. {
  1909. return (uint32_t)(READ_REG(TIMx->CCR4));
  1910. }
  1911. /**
  1912. * @}
  1913. */
  1914. /** @defgroup TIM_LL_EF_Input_Channel Input channel configuration
  1915. * @{
  1916. */
  1917. /**
  1918. * @brief Configure input channel.
  1919. * @rmtoll CCMR1 CC1S LL_TIM_IC_Config\n
  1920. * CCMR1 IC1PSC LL_TIM_IC_Config\n
  1921. * CCMR1 IC1F LL_TIM_IC_Config\n
  1922. * CCMR1 CC2S LL_TIM_IC_Config\n
  1923. * CCMR1 IC2PSC LL_TIM_IC_Config\n
  1924. * CCMR1 IC2F LL_TIM_IC_Config\n
  1925. * CCMR2 CC3S LL_TIM_IC_Config\n
  1926. * CCMR2 IC3PSC LL_TIM_IC_Config\n
  1927. * CCMR2 IC3F LL_TIM_IC_Config\n
  1928. * CCMR2 CC4S LL_TIM_IC_Config\n
  1929. * CCMR2 IC4PSC LL_TIM_IC_Config\n
  1930. * CCMR2 IC4F LL_TIM_IC_Config\n
  1931. * CCER CC1P LL_TIM_IC_Config\n
  1932. * CCER CC1NP LL_TIM_IC_Config\n
  1933. * CCER CC2P LL_TIM_IC_Config\n
  1934. * CCER CC2NP LL_TIM_IC_Config\n
  1935. * CCER CC3P LL_TIM_IC_Config\n
  1936. * CCER CC3NP LL_TIM_IC_Config\n
  1937. * CCER CC4P LL_TIM_IC_Config\n
  1938. * @param TIMx Timer instance
  1939. * @param Channel This parameter can be one of the following values:
  1940. * @arg @ref LL_TIM_CHANNEL_CH1
  1941. * @arg @ref LL_TIM_CHANNEL_CH2
  1942. * @arg @ref LL_TIM_CHANNEL_CH3
  1943. * @arg @ref LL_TIM_CHANNEL_CH4
  1944. * @param Configuration This parameter must be a combination of all the following values:
  1945. * @arg @ref LL_TIM_ACTIVEINPUT_DIRECTTI or @ref LL_TIM_ACTIVEINPUT_INDIRECTTI or @ref LL_TIM_ACTIVEINPUT_TRC
  1946. * @arg @ref LL_TIM_ICPSC_DIV1 or ... or @ref LL_TIM_ICPSC_DIV8
  1947. * @arg @ref LL_TIM_IC_FILTER_FDIV1 or ... or @ref LL_TIM_IC_FILTER_FDIV32_N8
  1948. * @arg @ref LL_TIM_IC_POLARITY_RISING or @ref LL_TIM_IC_POLARITY_FALLING
  1949. * @retval None
  1950. */
  1951. __STATIC_INLINE void LL_TIM_IC_Config(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t Configuration)
  1952. {
  1953. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1954. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1955. MODIFY_REG(*pReg, ((TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC | TIM_CCMR1_CC1S) << SHIFT_TAB_ICxx[iChannel]),
  1956. ((Configuration >> 16U) & (TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC | TIM_CCMR1_CC1S)) \
  1957. << SHIFT_TAB_ICxx[iChannel]);
  1958. MODIFY_REG(TIMx->CCER, ((TIM_CCER_CC1NP | TIM_CCER_CC1P) << SHIFT_TAB_CCxP[iChannel]),
  1959. (Configuration & (TIM_CCER_CC1NP | TIM_CCER_CC1P)) << SHIFT_TAB_CCxP[iChannel]);
  1960. }
  1961. /**
  1962. * @brief Set the active input.
  1963. * @rmtoll CCMR1 CC1S LL_TIM_IC_SetActiveInput\n
  1964. * CCMR1 CC2S LL_TIM_IC_SetActiveInput\n
  1965. * CCMR2 CC3S LL_TIM_IC_SetActiveInput\n
  1966. * CCMR2 CC4S LL_TIM_IC_SetActiveInput
  1967. * @param TIMx Timer instance
  1968. * @param Channel This parameter can be one of the following values:
  1969. * @arg @ref LL_TIM_CHANNEL_CH1
  1970. * @arg @ref LL_TIM_CHANNEL_CH2
  1971. * @arg @ref LL_TIM_CHANNEL_CH3
  1972. * @arg @ref LL_TIM_CHANNEL_CH4
  1973. * @param ICActiveInput This parameter can be one of the following values:
  1974. * @arg @ref LL_TIM_ACTIVEINPUT_DIRECTTI
  1975. * @arg @ref LL_TIM_ACTIVEINPUT_INDIRECTTI
  1976. * @arg @ref LL_TIM_ACTIVEINPUT_TRC
  1977. * @retval None
  1978. */
  1979. __STATIC_INLINE void LL_TIM_IC_SetActiveInput(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ICActiveInput)
  1980. {
  1981. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1982. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1983. MODIFY_REG(*pReg, ((TIM_CCMR1_CC1S) << SHIFT_TAB_ICxx[iChannel]), (ICActiveInput >> 16U) << SHIFT_TAB_ICxx[iChannel]);
  1984. }
  1985. /**
  1986. * @brief Get the current active input.
  1987. * @rmtoll CCMR1 CC1S LL_TIM_IC_GetActiveInput\n
  1988. * CCMR1 CC2S LL_TIM_IC_GetActiveInput\n
  1989. * CCMR2 CC3S LL_TIM_IC_GetActiveInput\n
  1990. * CCMR2 CC4S LL_TIM_IC_GetActiveInput
  1991. * @param TIMx Timer instance
  1992. * @param Channel This parameter can be one of the following values:
  1993. * @arg @ref LL_TIM_CHANNEL_CH1
  1994. * @arg @ref LL_TIM_CHANNEL_CH2
  1995. * @arg @ref LL_TIM_CHANNEL_CH3
  1996. * @arg @ref LL_TIM_CHANNEL_CH4
  1997. * @retval Returned value can be one of the following values:
  1998. * @arg @ref LL_TIM_ACTIVEINPUT_DIRECTTI
  1999. * @arg @ref LL_TIM_ACTIVEINPUT_INDIRECTTI
  2000. * @arg @ref LL_TIM_ACTIVEINPUT_TRC
  2001. */
  2002. __STATIC_INLINE uint32_t LL_TIM_IC_GetActiveInput(const TIM_TypeDef *TIMx, uint32_t Channel)
  2003. {
  2004. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2005. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2006. return ((READ_BIT(*pReg, ((TIM_CCMR1_CC1S) << SHIFT_TAB_ICxx[iChannel])) >> SHIFT_TAB_ICxx[iChannel]) << 16U);
  2007. }
  2008. /**
  2009. * @brief Set the prescaler of input channel.
  2010. * @rmtoll CCMR1 IC1PSC LL_TIM_IC_SetPrescaler\n
  2011. * CCMR1 IC2PSC LL_TIM_IC_SetPrescaler\n
  2012. * CCMR2 IC3PSC LL_TIM_IC_SetPrescaler\n
  2013. * CCMR2 IC4PSC LL_TIM_IC_SetPrescaler
  2014. * @param TIMx Timer instance
  2015. * @param Channel This parameter can be one of the following values:
  2016. * @arg @ref LL_TIM_CHANNEL_CH1
  2017. * @arg @ref LL_TIM_CHANNEL_CH2
  2018. * @arg @ref LL_TIM_CHANNEL_CH3
  2019. * @arg @ref LL_TIM_CHANNEL_CH4
  2020. * @param ICPrescaler This parameter can be one of the following values:
  2021. * @arg @ref LL_TIM_ICPSC_DIV1
  2022. * @arg @ref LL_TIM_ICPSC_DIV2
  2023. * @arg @ref LL_TIM_ICPSC_DIV4
  2024. * @arg @ref LL_TIM_ICPSC_DIV8
  2025. * @retval None
  2026. */
  2027. __STATIC_INLINE void LL_TIM_IC_SetPrescaler(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ICPrescaler)
  2028. {
  2029. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2030. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2031. MODIFY_REG(*pReg, ((TIM_CCMR1_IC1PSC) << SHIFT_TAB_ICxx[iChannel]), (ICPrescaler >> 16U) << SHIFT_TAB_ICxx[iChannel]);
  2032. }
  2033. /**
  2034. * @brief Get the current prescaler value acting on an input channel.
  2035. * @rmtoll CCMR1 IC1PSC LL_TIM_IC_GetPrescaler\n
  2036. * CCMR1 IC2PSC LL_TIM_IC_GetPrescaler\n
  2037. * CCMR2 IC3PSC LL_TIM_IC_GetPrescaler\n
  2038. * CCMR2 IC4PSC LL_TIM_IC_GetPrescaler
  2039. * @param TIMx Timer instance
  2040. * @param Channel This parameter can be one of the following values:
  2041. * @arg @ref LL_TIM_CHANNEL_CH1
  2042. * @arg @ref LL_TIM_CHANNEL_CH2
  2043. * @arg @ref LL_TIM_CHANNEL_CH3
  2044. * @arg @ref LL_TIM_CHANNEL_CH4
  2045. * @retval Returned value can be one of the following values:
  2046. * @arg @ref LL_TIM_ICPSC_DIV1
  2047. * @arg @ref LL_TIM_ICPSC_DIV2
  2048. * @arg @ref LL_TIM_ICPSC_DIV4
  2049. * @arg @ref LL_TIM_ICPSC_DIV8
  2050. */
  2051. __STATIC_INLINE uint32_t LL_TIM_IC_GetPrescaler(const TIM_TypeDef *TIMx, uint32_t Channel)
  2052. {
  2053. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2054. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2055. return ((READ_BIT(*pReg, ((TIM_CCMR1_IC1PSC) << SHIFT_TAB_ICxx[iChannel])) >> SHIFT_TAB_ICxx[iChannel]) << 16U);
  2056. }
  2057. /**
  2058. * @brief Set the input filter duration.
  2059. * @rmtoll CCMR1 IC1F LL_TIM_IC_SetFilter\n
  2060. * CCMR1 IC2F LL_TIM_IC_SetFilter\n
  2061. * CCMR2 IC3F LL_TIM_IC_SetFilter\n
  2062. * CCMR2 IC4F LL_TIM_IC_SetFilter
  2063. * @param TIMx Timer instance
  2064. * @param Channel This parameter can be one of the following values:
  2065. * @arg @ref LL_TIM_CHANNEL_CH1
  2066. * @arg @ref LL_TIM_CHANNEL_CH2
  2067. * @arg @ref LL_TIM_CHANNEL_CH3
  2068. * @arg @ref LL_TIM_CHANNEL_CH4
  2069. * @param ICFilter This parameter can be one of the following values:
  2070. * @arg @ref LL_TIM_IC_FILTER_FDIV1
  2071. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N2
  2072. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N4
  2073. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N8
  2074. * @arg @ref LL_TIM_IC_FILTER_FDIV2_N6
  2075. * @arg @ref LL_TIM_IC_FILTER_FDIV2_N8
  2076. * @arg @ref LL_TIM_IC_FILTER_FDIV4_N6
  2077. * @arg @ref LL_TIM_IC_FILTER_FDIV4_N8
  2078. * @arg @ref LL_TIM_IC_FILTER_FDIV8_N6
  2079. * @arg @ref LL_TIM_IC_FILTER_FDIV8_N8
  2080. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N5
  2081. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N6
  2082. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N8
  2083. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N5
  2084. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N6
  2085. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N8
  2086. * @retval None
  2087. */
  2088. __STATIC_INLINE void LL_TIM_IC_SetFilter(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ICFilter)
  2089. {
  2090. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2091. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2092. MODIFY_REG(*pReg, ((TIM_CCMR1_IC1F) << SHIFT_TAB_ICxx[iChannel]), (ICFilter >> 16U) << SHIFT_TAB_ICxx[iChannel]);
  2093. }
  2094. /**
  2095. * @brief Get the input filter duration.
  2096. * @rmtoll CCMR1 IC1F LL_TIM_IC_GetFilter\n
  2097. * CCMR1 IC2F LL_TIM_IC_GetFilter\n
  2098. * CCMR2 IC3F LL_TIM_IC_GetFilter\n
  2099. * CCMR2 IC4F LL_TIM_IC_GetFilter
  2100. * @param TIMx Timer instance
  2101. * @param Channel This parameter can be one of the following values:
  2102. * @arg @ref LL_TIM_CHANNEL_CH1
  2103. * @arg @ref LL_TIM_CHANNEL_CH2
  2104. * @arg @ref LL_TIM_CHANNEL_CH3
  2105. * @arg @ref LL_TIM_CHANNEL_CH4
  2106. * @retval Returned value can be one of the following values:
  2107. * @arg @ref LL_TIM_IC_FILTER_FDIV1
  2108. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N2
  2109. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N4
  2110. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N8
  2111. * @arg @ref LL_TIM_IC_FILTER_FDIV2_N6
  2112. * @arg @ref LL_TIM_IC_FILTER_FDIV2_N8
  2113. * @arg @ref LL_TIM_IC_FILTER_FDIV4_N6
  2114. * @arg @ref LL_TIM_IC_FILTER_FDIV4_N8
  2115. * @arg @ref LL_TIM_IC_FILTER_FDIV8_N6
  2116. * @arg @ref LL_TIM_IC_FILTER_FDIV8_N8
  2117. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N5
  2118. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N6
  2119. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N8
  2120. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N5
  2121. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N6
  2122. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N8
  2123. */
  2124. __STATIC_INLINE uint32_t LL_TIM_IC_GetFilter(const TIM_TypeDef *TIMx, uint32_t Channel)
  2125. {
  2126. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2127. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2128. return ((READ_BIT(*pReg, ((TIM_CCMR1_IC1F) << SHIFT_TAB_ICxx[iChannel])) >> SHIFT_TAB_ICxx[iChannel]) << 16U);
  2129. }
  2130. /**
  2131. * @brief Set the input channel polarity.
  2132. * @rmtoll CCER CC1P LL_TIM_IC_SetPolarity\n
  2133. * CCER CC1NP LL_TIM_IC_SetPolarity\n
  2134. * CCER CC2P LL_TIM_IC_SetPolarity\n
  2135. * CCER CC2NP LL_TIM_IC_SetPolarity\n
  2136. * CCER CC3P LL_TIM_IC_SetPolarity\n
  2137. * CCER CC3NP LL_TIM_IC_SetPolarity\n
  2138. * CCER CC4P LL_TIM_IC_SetPolarity\n
  2139. * @param TIMx Timer instance
  2140. * @param Channel This parameter can be one of the following values:
  2141. * @arg @ref LL_TIM_CHANNEL_CH1
  2142. * @arg @ref LL_TIM_CHANNEL_CH2
  2143. * @arg @ref LL_TIM_CHANNEL_CH3
  2144. * @arg @ref LL_TIM_CHANNEL_CH4
  2145. * @param ICPolarity This parameter can be one of the following values:
  2146. * @arg @ref LL_TIM_IC_POLARITY_RISING
  2147. * @arg @ref LL_TIM_IC_POLARITY_FALLING
  2148. * @retval None
  2149. */
  2150. __STATIC_INLINE void LL_TIM_IC_SetPolarity(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ICPolarity)
  2151. {
  2152. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2153. MODIFY_REG(TIMx->CCER, ((TIM_CCER_CC1NP | TIM_CCER_CC1P) << SHIFT_TAB_CCxP[iChannel]),
  2154. ICPolarity << SHIFT_TAB_CCxP[iChannel]);
  2155. }
  2156. /**
  2157. * @brief Get the current input channel polarity.
  2158. * @rmtoll CCER CC1P LL_TIM_IC_GetPolarity\n
  2159. * CCER CC1NP LL_TIM_IC_GetPolarity\n
  2160. * CCER CC2P LL_TIM_IC_GetPolarity\n
  2161. * CCER CC2NP LL_TIM_IC_GetPolarity\n
  2162. * CCER CC3P LL_TIM_IC_GetPolarity\n
  2163. * CCER CC3NP LL_TIM_IC_GetPolarity\n
  2164. * CCER CC4P LL_TIM_IC_GetPolarity\n
  2165. * @param TIMx Timer instance
  2166. * @param Channel This parameter can be one of the following values:
  2167. * @arg @ref LL_TIM_CHANNEL_CH1
  2168. * @arg @ref LL_TIM_CHANNEL_CH2
  2169. * @arg @ref LL_TIM_CHANNEL_CH3
  2170. * @arg @ref LL_TIM_CHANNEL_CH4
  2171. * @retval Returned value can be one of the following values:
  2172. * @arg @ref LL_TIM_IC_POLARITY_RISING
  2173. * @arg @ref LL_TIM_IC_POLARITY_FALLING
  2174. */
  2175. __STATIC_INLINE uint32_t LL_TIM_IC_GetPolarity(const TIM_TypeDef *TIMx, uint32_t Channel)
  2176. {
  2177. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2178. return (READ_BIT(TIMx->CCER, ((TIM_CCER_CC1NP | TIM_CCER_CC1P) << SHIFT_TAB_CCxP[iChannel])) >>
  2179. SHIFT_TAB_CCxP[iChannel]);
  2180. }
  2181. /**
  2182. * @brief Connect the TIMx_CH1, CH2 and CH3 pins to the TI1 input (XOR combination).
  2183. * @note Macro IS_TIM_XOR_INSTANCE(TIMx) can be used to check whether or not
  2184. * a timer instance provides an XOR input.
  2185. * @rmtoll CR2 TI1S LL_TIM_IC_EnableXORCombination
  2186. * @param TIMx Timer instance
  2187. * @retval None
  2188. */
  2189. __STATIC_INLINE void LL_TIM_IC_EnableXORCombination(TIM_TypeDef *TIMx)
  2190. {
  2191. SET_BIT(TIMx->CR2, TIM_CR2_TI1S);
  2192. }
  2193. /**
  2194. * @brief Disconnect the TIMx_CH1, CH2 and CH3 pins from the TI1 input.
  2195. * @note Macro IS_TIM_XOR_INSTANCE(TIMx) can be used to check whether or not
  2196. * a timer instance provides an XOR input.
  2197. * @rmtoll CR2 TI1S LL_TIM_IC_DisableXORCombination
  2198. * @param TIMx Timer instance
  2199. * @retval None
  2200. */
  2201. __STATIC_INLINE void LL_TIM_IC_DisableXORCombination(TIM_TypeDef *TIMx)
  2202. {
  2203. CLEAR_BIT(TIMx->CR2, TIM_CR2_TI1S);
  2204. }
  2205. /**
  2206. * @brief Indicates whether the TIMx_CH1, CH2 and CH3 pins are connectected to the TI1 input.
  2207. * @note Macro IS_TIM_XOR_INSTANCE(TIMx) can be used to check whether or not
  2208. * a timer instance provides an XOR input.
  2209. * @rmtoll CR2 TI1S LL_TIM_IC_IsEnabledXORCombination
  2210. * @param TIMx Timer instance
  2211. * @retval State of bit (1 or 0).
  2212. */
  2213. __STATIC_INLINE uint32_t LL_TIM_IC_IsEnabledXORCombination(const TIM_TypeDef *TIMx)
  2214. {
  2215. return ((READ_BIT(TIMx->CR2, TIM_CR2_TI1S) == (TIM_CR2_TI1S)) ? 1UL : 0UL);
  2216. }
  2217. /**
  2218. * @brief Get captured value for input channel 1.
  2219. * @note Macro IS_TIM_CC1_INSTANCE(TIMx) can be used to check whether or not
  2220. * input channel 1 is supported by a timer instance.
  2221. * @rmtoll CCR1 CCR1 LL_TIM_IC_GetCaptureCH1
  2222. * @param TIMx Timer instance
  2223. * @retval CapturedValue (between Min_Data=0 and Max_Data=65535)
  2224. */
  2225. __STATIC_INLINE uint32_t LL_TIM_IC_GetCaptureCH1(const TIM_TypeDef *TIMx)
  2226. {
  2227. return (uint32_t)(READ_REG(TIMx->CCR1));
  2228. }
  2229. /**
  2230. * @brief Get captured value for input channel 2.
  2231. * @note Macro IS_TIM_CC2_INSTANCE(TIMx) can be used to check whether or not
  2232. * input channel 2 is supported by a timer instance.
  2233. * @rmtoll CCR2 CCR2 LL_TIM_IC_GetCaptureCH2
  2234. * @param TIMx Timer instance
  2235. * @retval CapturedValue (between Min_Data=0 and Max_Data=65535)
  2236. */
  2237. __STATIC_INLINE uint32_t LL_TIM_IC_GetCaptureCH2(const TIM_TypeDef *TIMx)
  2238. {
  2239. return (uint32_t)(READ_REG(TIMx->CCR2));
  2240. }
  2241. /**
  2242. * @brief Get captured value for input channel 3.
  2243. * @note Macro IS_TIM_CC3_INSTANCE(TIMx) can be used to check whether or not
  2244. * input channel 3 is supported by a timer instance.
  2245. * @rmtoll CCR3 CCR3 LL_TIM_IC_GetCaptureCH3
  2246. * @param TIMx Timer instance
  2247. * @retval CapturedValue (between Min_Data=0 and Max_Data=65535)
  2248. */
  2249. __STATIC_INLINE uint32_t LL_TIM_IC_GetCaptureCH3(const TIM_TypeDef *TIMx)
  2250. {
  2251. return (uint32_t)(READ_REG(TIMx->CCR3));
  2252. }
  2253. /**
  2254. * @brief Get captured value for input channel 4.
  2255. * @note Macro IS_TIM_CC4_INSTANCE(TIMx) can be used to check whether or not
  2256. * input channel 4 is supported by a timer instance.
  2257. * @rmtoll CCR4 CCR4 LL_TIM_IC_GetCaptureCH4
  2258. * @param TIMx Timer instance
  2259. * @retval CapturedValue (between Min_Data=0 and Max_Data=65535)
  2260. */
  2261. __STATIC_INLINE uint32_t LL_TIM_IC_GetCaptureCH4(const TIM_TypeDef *TIMx)
  2262. {
  2263. return (uint32_t)(READ_REG(TIMx->CCR4));
  2264. }
  2265. /**
  2266. * @}
  2267. */
  2268. /** @defgroup TIM_LL_EF_Clock_Selection Counter clock selection
  2269. * @{
  2270. */
  2271. /**
  2272. * @brief Enable external clock mode 2.
  2273. * @note When external clock mode 2 is enabled the counter is clocked by any active edge on the ETRF signal.
  2274. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(TIMx) can be used to check
  2275. * whether or not a timer instance supports external clock mode2.
  2276. * @rmtoll SMCR ECE LL_TIM_EnableExternalClock
  2277. * @param TIMx Timer instance
  2278. * @retval None
  2279. */
  2280. __STATIC_INLINE void LL_TIM_EnableExternalClock(TIM_TypeDef *TIMx)
  2281. {
  2282. SET_BIT(TIMx->SMCR, TIM_SMCR_ECE);
  2283. }
  2284. /**
  2285. * @brief Disable external clock mode 2.
  2286. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(TIMx) can be used to check
  2287. * whether or not a timer instance supports external clock mode2.
  2288. * @rmtoll SMCR ECE LL_TIM_DisableExternalClock
  2289. * @param TIMx Timer instance
  2290. * @retval None
  2291. */
  2292. __STATIC_INLINE void LL_TIM_DisableExternalClock(TIM_TypeDef *TIMx)
  2293. {
  2294. CLEAR_BIT(TIMx->SMCR, TIM_SMCR_ECE);
  2295. }
  2296. /**
  2297. * @brief Indicate whether external clock mode 2 is enabled.
  2298. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(TIMx) can be used to check
  2299. * whether or not a timer instance supports external clock mode2.
  2300. * @rmtoll SMCR ECE LL_TIM_IsEnabledExternalClock
  2301. * @param TIMx Timer instance
  2302. * @retval State of bit (1 or 0).
  2303. */
  2304. __STATIC_INLINE uint32_t LL_TIM_IsEnabledExternalClock(const TIM_TypeDef *TIMx)
  2305. {
  2306. return ((READ_BIT(TIMx->SMCR, TIM_SMCR_ECE) == (TIM_SMCR_ECE)) ? 1UL : 0UL);
  2307. }
  2308. /**
  2309. * @brief Set the clock source of the counter clock.
  2310. * @note when selected clock source is external clock mode 1, the timer input
  2311. * the external clock is applied is selected by calling the @ref LL_TIM_SetTriggerInput()
  2312. * function. This timer input must be configured by calling
  2313. * the @ref LL_TIM_IC_Config() function.
  2314. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(TIMx) can be used to check
  2315. * whether or not a timer instance supports external clock mode1.
  2316. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(TIMx) can be used to check
  2317. * whether or not a timer instance supports external clock mode2.
  2318. * @rmtoll SMCR SMS LL_TIM_SetClockSource\n
  2319. * SMCR ECE LL_TIM_SetClockSource
  2320. * @param TIMx Timer instance
  2321. * @param ClockSource This parameter can be one of the following values:
  2322. * @arg @ref LL_TIM_CLOCKSOURCE_INTERNAL
  2323. * @arg @ref LL_TIM_CLOCKSOURCE_EXT_MODE1
  2324. * @arg @ref LL_TIM_CLOCKSOURCE_EXT_MODE2
  2325. * @retval None
  2326. */
  2327. __STATIC_INLINE void LL_TIM_SetClockSource(TIM_TypeDef *TIMx, uint32_t ClockSource)
  2328. {
  2329. MODIFY_REG(TIMx->SMCR, TIM_SMCR_SMS | TIM_SMCR_ECE, ClockSource);
  2330. }
  2331. /**
  2332. * @brief Set the encoder interface mode.
  2333. * @note Macro IS_TIM_ENCODER_INTERFACE_INSTANCE(TIMx) can be used to check
  2334. * whether or not a timer instance supports the encoder mode.
  2335. * @rmtoll SMCR SMS LL_TIM_SetEncoderMode
  2336. * @param TIMx Timer instance
  2337. * @param EncoderMode This parameter can be one of the following values:
  2338. * @arg @ref LL_TIM_ENCODERMODE_X2_TI1
  2339. * @arg @ref LL_TIM_ENCODERMODE_X2_TI2
  2340. * @arg @ref LL_TIM_ENCODERMODE_X4_TI12
  2341. * @retval None
  2342. */
  2343. __STATIC_INLINE void LL_TIM_SetEncoderMode(TIM_TypeDef *TIMx, uint32_t EncoderMode)
  2344. {
  2345. MODIFY_REG(TIMx->SMCR, TIM_SMCR_SMS, EncoderMode);
  2346. }
  2347. /**
  2348. * @}
  2349. */
  2350. /** @defgroup TIM_LL_EF_Timer_Synchronization Timer synchronisation configuration
  2351. * @{
  2352. */
  2353. /**
  2354. * @brief Set the trigger output (TRGO) used for timer synchronization .
  2355. * @note Macro IS_TIM_MASTER_INSTANCE(TIMx) can be used to check
  2356. * whether or not a timer instance can operate as a master timer.
  2357. * @rmtoll CR2 MMS LL_TIM_SetTriggerOutput
  2358. * @param TIMx Timer instance
  2359. * @param TimerSynchronization This parameter can be one of the following values:
  2360. * @arg @ref LL_TIM_TRGO_RESET
  2361. * @arg @ref LL_TIM_TRGO_ENABLE
  2362. * @arg @ref LL_TIM_TRGO_UPDATE
  2363. * @arg @ref LL_TIM_TRGO_CC1IF
  2364. * @arg @ref LL_TIM_TRGO_OC1REF
  2365. * @arg @ref LL_TIM_TRGO_OC2REF
  2366. * @arg @ref LL_TIM_TRGO_OC3REF
  2367. * @arg @ref LL_TIM_TRGO_OC4REF
  2368. * @retval None
  2369. */
  2370. __STATIC_INLINE void LL_TIM_SetTriggerOutput(TIM_TypeDef *TIMx, uint32_t TimerSynchronization)
  2371. {
  2372. MODIFY_REG(TIMx->CR2, TIM_CR2_MMS, TimerSynchronization);
  2373. }
  2374. /**
  2375. * @brief Set the synchronization mode of a slave timer.
  2376. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2377. * a timer instance can operate as a slave timer.
  2378. * @rmtoll SMCR SMS LL_TIM_SetSlaveMode
  2379. * @param TIMx Timer instance
  2380. * @param SlaveMode This parameter can be one of the following values:
  2381. * @arg @ref LL_TIM_SLAVEMODE_DISABLED
  2382. * @arg @ref LL_TIM_SLAVEMODE_RESET
  2383. * @arg @ref LL_TIM_SLAVEMODE_GATED
  2384. * @arg @ref LL_TIM_SLAVEMODE_TRIGGER
  2385. * @retval None
  2386. */
  2387. __STATIC_INLINE void LL_TIM_SetSlaveMode(TIM_TypeDef *TIMx, uint32_t SlaveMode)
  2388. {
  2389. MODIFY_REG(TIMx->SMCR, TIM_SMCR_SMS, SlaveMode);
  2390. }
  2391. /**
  2392. * @brief Set the selects the trigger input to be used to synchronize the counter.
  2393. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2394. * a timer instance can operate as a slave timer.
  2395. * @rmtoll SMCR TS LL_TIM_SetTriggerInput
  2396. * @param TIMx Timer instance
  2397. * @param TriggerInput This parameter can be one of the following values:
  2398. * @arg @ref LL_TIM_TS_ITR0
  2399. * @arg @ref LL_TIM_TS_ITR1
  2400. * @arg @ref LL_TIM_TS_ITR2
  2401. * @arg @ref LL_TIM_TS_ITR3
  2402. * @arg @ref LL_TIM_TS_TI1F_ED
  2403. * @arg @ref LL_TIM_TS_TI1FP1
  2404. * @arg @ref LL_TIM_TS_TI2FP2
  2405. * @arg @ref LL_TIM_TS_ETRF
  2406. * @retval None
  2407. */
  2408. __STATIC_INLINE void LL_TIM_SetTriggerInput(TIM_TypeDef *TIMx, uint32_t TriggerInput)
  2409. {
  2410. MODIFY_REG(TIMx->SMCR, TIM_SMCR_TS, TriggerInput);
  2411. }
  2412. /**
  2413. * @brief Enable the Master/Slave mode.
  2414. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2415. * a timer instance can operate as a slave timer.
  2416. * @rmtoll SMCR MSM LL_TIM_EnableMasterSlaveMode
  2417. * @param TIMx Timer instance
  2418. * @retval None
  2419. */
  2420. __STATIC_INLINE void LL_TIM_EnableMasterSlaveMode(TIM_TypeDef *TIMx)
  2421. {
  2422. SET_BIT(TIMx->SMCR, TIM_SMCR_MSM);
  2423. }
  2424. /**
  2425. * @brief Disable the Master/Slave mode.
  2426. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2427. * a timer instance can operate as a slave timer.
  2428. * @rmtoll SMCR MSM LL_TIM_DisableMasterSlaveMode
  2429. * @param TIMx Timer instance
  2430. * @retval None
  2431. */
  2432. __STATIC_INLINE void LL_TIM_DisableMasterSlaveMode(TIM_TypeDef *TIMx)
  2433. {
  2434. CLEAR_BIT(TIMx->SMCR, TIM_SMCR_MSM);
  2435. }
  2436. /**
  2437. * @brief Indicates whether the Master/Slave mode is enabled.
  2438. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2439. * a timer instance can operate as a slave timer.
  2440. * @rmtoll SMCR MSM LL_TIM_IsEnabledMasterSlaveMode
  2441. * @param TIMx Timer instance
  2442. * @retval State of bit (1 or 0).
  2443. */
  2444. __STATIC_INLINE uint32_t LL_TIM_IsEnabledMasterSlaveMode(const TIM_TypeDef *TIMx)
  2445. {
  2446. return ((READ_BIT(TIMx->SMCR, TIM_SMCR_MSM) == (TIM_SMCR_MSM)) ? 1UL : 0UL);
  2447. }
  2448. /**
  2449. * @brief Configure the external trigger (ETR) input.
  2450. * @note Macro IS_TIM_ETR_INSTANCE(TIMx) can be used to check whether or not
  2451. * a timer instance provides an external trigger input.
  2452. * @rmtoll SMCR ETP LL_TIM_ConfigETR\n
  2453. * SMCR ETPS LL_TIM_ConfigETR\n
  2454. * SMCR ETF LL_TIM_ConfigETR
  2455. * @param TIMx Timer instance
  2456. * @param ETRPolarity This parameter can be one of the following values:
  2457. * @arg @ref LL_TIM_ETR_POLARITY_NONINVERTED
  2458. * @arg @ref LL_TIM_ETR_POLARITY_INVERTED
  2459. * @param ETRPrescaler This parameter can be one of the following values:
  2460. * @arg @ref LL_TIM_ETR_PRESCALER_DIV1
  2461. * @arg @ref LL_TIM_ETR_PRESCALER_DIV2
  2462. * @arg @ref LL_TIM_ETR_PRESCALER_DIV4
  2463. * @arg @ref LL_TIM_ETR_PRESCALER_DIV8
  2464. * @param ETRFilter This parameter can be one of the following values:
  2465. * @arg @ref LL_TIM_ETR_FILTER_FDIV1
  2466. * @arg @ref LL_TIM_ETR_FILTER_FDIV1_N2
  2467. * @arg @ref LL_TIM_ETR_FILTER_FDIV1_N4
  2468. * @arg @ref LL_TIM_ETR_FILTER_FDIV1_N8
  2469. * @arg @ref LL_TIM_ETR_FILTER_FDIV2_N6
  2470. * @arg @ref LL_TIM_ETR_FILTER_FDIV2_N8
  2471. * @arg @ref LL_TIM_ETR_FILTER_FDIV4_N6
  2472. * @arg @ref LL_TIM_ETR_FILTER_FDIV4_N8
  2473. * @arg @ref LL_TIM_ETR_FILTER_FDIV8_N6
  2474. * @arg @ref LL_TIM_ETR_FILTER_FDIV8_N8
  2475. * @arg @ref LL_TIM_ETR_FILTER_FDIV16_N5
  2476. * @arg @ref LL_TIM_ETR_FILTER_FDIV16_N6
  2477. * @arg @ref LL_TIM_ETR_FILTER_FDIV16_N8
  2478. * @arg @ref LL_TIM_ETR_FILTER_FDIV32_N5
  2479. * @arg @ref LL_TIM_ETR_FILTER_FDIV32_N6
  2480. * @arg @ref LL_TIM_ETR_FILTER_FDIV32_N8
  2481. * @retval None
  2482. */
  2483. __STATIC_INLINE void LL_TIM_ConfigETR(TIM_TypeDef *TIMx, uint32_t ETRPolarity, uint32_t ETRPrescaler,
  2484. uint32_t ETRFilter)
  2485. {
  2486. MODIFY_REG(TIMx->SMCR, TIM_SMCR_ETP | TIM_SMCR_ETPS | TIM_SMCR_ETF, ETRPolarity | ETRPrescaler | ETRFilter);
  2487. }
  2488. /**
  2489. * @}
  2490. */
  2491. /** @defgroup TIM_LL_EF_Break_Function Break function configuration
  2492. * @{
  2493. */
  2494. /**
  2495. * @brief Enable the break function.
  2496. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2497. * a timer instance provides a break input.
  2498. * @rmtoll BDTR BKE LL_TIM_EnableBRK
  2499. * @param TIMx Timer instance
  2500. * @retval None
  2501. */
  2502. __STATIC_INLINE void LL_TIM_EnableBRK(TIM_TypeDef *TIMx)
  2503. {
  2504. __IO uint32_t tmpreg;
  2505. SET_BIT(TIMx->BDTR, TIM_BDTR_BKE);
  2506. /* Note: Any write operation to this bit takes a delay of 1 APB clock cycle to become effective. */
  2507. tmpreg = READ_REG(TIMx->BDTR);
  2508. (void)(tmpreg);
  2509. }
  2510. /**
  2511. * @brief Disable the break function.
  2512. * @rmtoll BDTR BKE LL_TIM_DisableBRK
  2513. * @param TIMx Timer instance
  2514. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2515. * a timer instance provides a break input.
  2516. * @retval None
  2517. */
  2518. __STATIC_INLINE void LL_TIM_DisableBRK(TIM_TypeDef *TIMx)
  2519. {
  2520. __IO uint32_t tmpreg;
  2521. CLEAR_BIT(TIMx->BDTR, TIM_BDTR_BKE);
  2522. /* Note: Any write operation to this bit takes a delay of 1 APB clock cycle to become effective. */
  2523. tmpreg = READ_REG(TIMx->BDTR);
  2524. (void)(tmpreg);
  2525. }
  2526. /**
  2527. * @brief Configure the break input.
  2528. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2529. * a timer instance provides a break input.
  2530. * @rmtoll BDTR BKP LL_TIM_ConfigBRK
  2531. * @param TIMx Timer instance
  2532. * @param BreakPolarity This parameter can be one of the following values:
  2533. * @arg @ref LL_TIM_BREAK_POLARITY_LOW
  2534. * @arg @ref LL_TIM_BREAK_POLARITY_HIGH
  2535. * @retval None
  2536. */
  2537. __STATIC_INLINE void LL_TIM_ConfigBRK(TIM_TypeDef *TIMx, uint32_t BreakPolarity)
  2538. {
  2539. __IO uint32_t tmpreg;
  2540. MODIFY_REG(TIMx->BDTR, TIM_BDTR_BKP, BreakPolarity);
  2541. /* Note: Any write operation to BKP bit takes a delay of 1 APB clock cycle to become effective. */
  2542. tmpreg = READ_REG(TIMx->BDTR);
  2543. (void)(tmpreg);
  2544. }
  2545. /**
  2546. * @brief Select the outputs off state (enabled v.s. disabled) in Idle and Run modes.
  2547. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2548. * a timer instance provides a break input.
  2549. * @rmtoll BDTR OSSI LL_TIM_SetOffStates\n
  2550. * BDTR OSSR LL_TIM_SetOffStates
  2551. * @param TIMx Timer instance
  2552. * @param OffStateIdle This parameter can be one of the following values:
  2553. * @arg @ref LL_TIM_OSSI_DISABLE
  2554. * @arg @ref LL_TIM_OSSI_ENABLE
  2555. * @param OffStateRun This parameter can be one of the following values:
  2556. * @arg @ref LL_TIM_OSSR_DISABLE
  2557. * @arg @ref LL_TIM_OSSR_ENABLE
  2558. * @retval None
  2559. */
  2560. __STATIC_INLINE void LL_TIM_SetOffStates(TIM_TypeDef *TIMx, uint32_t OffStateIdle, uint32_t OffStateRun)
  2561. {
  2562. MODIFY_REG(TIMx->BDTR, TIM_BDTR_OSSI | TIM_BDTR_OSSR, OffStateIdle | OffStateRun);
  2563. }
  2564. /**
  2565. * @brief Enable automatic output (MOE can be set by software or automatically when a break input is active).
  2566. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2567. * a timer instance provides a break input.
  2568. * @rmtoll BDTR AOE LL_TIM_EnableAutomaticOutput
  2569. * @param TIMx Timer instance
  2570. * @retval None
  2571. */
  2572. __STATIC_INLINE void LL_TIM_EnableAutomaticOutput(TIM_TypeDef *TIMx)
  2573. {
  2574. SET_BIT(TIMx->BDTR, TIM_BDTR_AOE);
  2575. }
  2576. /**
  2577. * @brief Disable automatic output (MOE can be set only by software).
  2578. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2579. * a timer instance provides a break input.
  2580. * @rmtoll BDTR AOE LL_TIM_DisableAutomaticOutput
  2581. * @param TIMx Timer instance
  2582. * @retval None
  2583. */
  2584. __STATIC_INLINE void LL_TIM_DisableAutomaticOutput(TIM_TypeDef *TIMx)
  2585. {
  2586. CLEAR_BIT(TIMx->BDTR, TIM_BDTR_AOE);
  2587. }
  2588. /**
  2589. * @brief Indicate whether automatic output is enabled.
  2590. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2591. * a timer instance provides a break input.
  2592. * @rmtoll BDTR AOE LL_TIM_IsEnabledAutomaticOutput
  2593. * @param TIMx Timer instance
  2594. * @retval State of bit (1 or 0).
  2595. */
  2596. __STATIC_INLINE uint32_t LL_TIM_IsEnabledAutomaticOutput(const TIM_TypeDef *TIMx)
  2597. {
  2598. return ((READ_BIT(TIMx->BDTR, TIM_BDTR_AOE) == (TIM_BDTR_AOE)) ? 1UL : 0UL);
  2599. }
  2600. /**
  2601. * @brief Enable the outputs (set the MOE bit in TIMx_BDTR register).
  2602. * @note The MOE bit in TIMx_BDTR register allows to enable /disable the outputs by
  2603. * software and is reset in case of break or break2 event
  2604. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2605. * a timer instance provides a break input.
  2606. * @rmtoll BDTR MOE LL_TIM_EnableAllOutputs
  2607. * @param TIMx Timer instance
  2608. * @retval None
  2609. */
  2610. __STATIC_INLINE void LL_TIM_EnableAllOutputs(TIM_TypeDef *TIMx)
  2611. {
  2612. SET_BIT(TIMx->BDTR, TIM_BDTR_MOE);
  2613. }
  2614. /**
  2615. * @brief Disable the outputs (reset the MOE bit in TIMx_BDTR register).
  2616. * @note The MOE bit in TIMx_BDTR register allows to enable /disable the outputs by
  2617. * software and is reset in case of break or break2 event.
  2618. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2619. * a timer instance provides a break input.
  2620. * @rmtoll BDTR MOE LL_TIM_DisableAllOutputs
  2621. * @param TIMx Timer instance
  2622. * @retval None
  2623. */
  2624. __STATIC_INLINE void LL_TIM_DisableAllOutputs(TIM_TypeDef *TIMx)
  2625. {
  2626. CLEAR_BIT(TIMx->BDTR, TIM_BDTR_MOE);
  2627. }
  2628. /**
  2629. * @brief Indicates whether outputs are enabled.
  2630. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2631. * a timer instance provides a break input.
  2632. * @rmtoll BDTR MOE LL_TIM_IsEnabledAllOutputs
  2633. * @param TIMx Timer instance
  2634. * @retval State of bit (1 or 0).
  2635. */
  2636. __STATIC_INLINE uint32_t LL_TIM_IsEnabledAllOutputs(const TIM_TypeDef *TIMx)
  2637. {
  2638. return ((READ_BIT(TIMx->BDTR, TIM_BDTR_MOE) == (TIM_BDTR_MOE)) ? 1UL : 0UL);
  2639. }
  2640. /**
  2641. * @}
  2642. */
  2643. /** @defgroup TIM_LL_EF_DMA_Burst_Mode DMA burst mode configuration
  2644. * @{
  2645. */
  2646. /**
  2647. * @brief Configures the timer DMA burst feature.
  2648. * @note Macro IS_TIM_DMABURST_INSTANCE(TIMx) can be used to check whether or
  2649. * not a timer instance supports the DMA burst mode.
  2650. * @rmtoll DCR DBL LL_TIM_ConfigDMABurst\n
  2651. * DCR DBA LL_TIM_ConfigDMABurst
  2652. * @param TIMx Timer instance
  2653. * @param DMABurstBaseAddress This parameter can be one of the following values:
  2654. * @arg @ref LL_TIM_DMABURST_BASEADDR_CR1
  2655. * @arg @ref LL_TIM_DMABURST_BASEADDR_CR2
  2656. * @arg @ref LL_TIM_DMABURST_BASEADDR_SMCR
  2657. * @arg @ref LL_TIM_DMABURST_BASEADDR_DIER
  2658. * @arg @ref LL_TIM_DMABURST_BASEADDR_SR
  2659. * @arg @ref LL_TIM_DMABURST_BASEADDR_EGR
  2660. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCMR1
  2661. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCMR2
  2662. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCER
  2663. * @arg @ref LL_TIM_DMABURST_BASEADDR_CNT
  2664. * @arg @ref LL_TIM_DMABURST_BASEADDR_PSC
  2665. * @arg @ref LL_TIM_DMABURST_BASEADDR_ARR
  2666. * @arg @ref LL_TIM_DMABURST_BASEADDR_RCR
  2667. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCR1
  2668. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCR2
  2669. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCR3
  2670. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCR4
  2671. * @arg @ref LL_TIM_DMABURST_BASEADDR_BDTR
  2672. * @param DMABurstLength This parameter can be one of the following values:
  2673. * @arg @ref LL_TIM_DMABURST_LENGTH_1TRANSFER
  2674. * @arg @ref LL_TIM_DMABURST_LENGTH_2TRANSFERS
  2675. * @arg @ref LL_TIM_DMABURST_LENGTH_3TRANSFERS
  2676. * @arg @ref LL_TIM_DMABURST_LENGTH_4TRANSFERS
  2677. * @arg @ref LL_TIM_DMABURST_LENGTH_5TRANSFERS
  2678. * @arg @ref LL_TIM_DMABURST_LENGTH_6TRANSFERS
  2679. * @arg @ref LL_TIM_DMABURST_LENGTH_7TRANSFERS
  2680. * @arg @ref LL_TIM_DMABURST_LENGTH_8TRANSFERS
  2681. * @arg @ref LL_TIM_DMABURST_LENGTH_9TRANSFERS
  2682. * @arg @ref LL_TIM_DMABURST_LENGTH_10TRANSFERS
  2683. * @arg @ref LL_TIM_DMABURST_LENGTH_11TRANSFERS
  2684. * @arg @ref LL_TIM_DMABURST_LENGTH_12TRANSFERS
  2685. * @arg @ref LL_TIM_DMABURST_LENGTH_13TRANSFERS
  2686. * @arg @ref LL_TIM_DMABURST_LENGTH_14TRANSFERS
  2687. * @arg @ref LL_TIM_DMABURST_LENGTH_15TRANSFERS
  2688. * @arg @ref LL_TIM_DMABURST_LENGTH_16TRANSFERS
  2689. * @arg @ref LL_TIM_DMABURST_LENGTH_17TRANSFERS
  2690. * @arg @ref LL_TIM_DMABURST_LENGTH_18TRANSFERS
  2691. * @retval None
  2692. */
  2693. __STATIC_INLINE void LL_TIM_ConfigDMABurst(TIM_TypeDef *TIMx, uint32_t DMABurstBaseAddress, uint32_t DMABurstLength)
  2694. {
  2695. MODIFY_REG(TIMx->DCR, (TIM_DCR_DBL | TIM_DCR_DBA), (DMABurstBaseAddress | DMABurstLength));
  2696. }
  2697. /**
  2698. * @}
  2699. */
  2700. /** @defgroup TIM_LL_EF_FLAG_Management FLAG-Management
  2701. * @{
  2702. */
  2703. /**
  2704. * @brief Clear the update interrupt flag (UIF).
  2705. * @rmtoll SR UIF LL_TIM_ClearFlag_UPDATE
  2706. * @param TIMx Timer instance
  2707. * @retval None
  2708. */
  2709. __STATIC_INLINE void LL_TIM_ClearFlag_UPDATE(TIM_TypeDef *TIMx)
  2710. {
  2711. WRITE_REG(TIMx->SR, ~(TIM_SR_UIF));
  2712. }
  2713. /**
  2714. * @brief Indicate whether update interrupt flag (UIF) is set (update interrupt is pending).
  2715. * @rmtoll SR UIF LL_TIM_IsActiveFlag_UPDATE
  2716. * @param TIMx Timer instance
  2717. * @retval State of bit (1 or 0).
  2718. */
  2719. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_UPDATE(const TIM_TypeDef *TIMx)
  2720. {
  2721. return ((READ_BIT(TIMx->SR, TIM_SR_UIF) == (TIM_SR_UIF)) ? 1UL : 0UL);
  2722. }
  2723. /**
  2724. * @brief Clear the Capture/Compare 1 interrupt flag (CC1F).
  2725. * @rmtoll SR CC1IF LL_TIM_ClearFlag_CC1
  2726. * @param TIMx Timer instance
  2727. * @retval None
  2728. */
  2729. __STATIC_INLINE void LL_TIM_ClearFlag_CC1(TIM_TypeDef *TIMx)
  2730. {
  2731. WRITE_REG(TIMx->SR, ~(TIM_SR_CC1IF));
  2732. }
  2733. /**
  2734. * @brief Indicate whether Capture/Compare 1 interrupt flag (CC1F) is set (Capture/Compare 1 interrupt is pending).
  2735. * @rmtoll SR CC1IF LL_TIM_IsActiveFlag_CC1
  2736. * @param TIMx Timer instance
  2737. * @retval State of bit (1 or 0).
  2738. */
  2739. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC1(const TIM_TypeDef *TIMx)
  2740. {
  2741. return ((READ_BIT(TIMx->SR, TIM_SR_CC1IF) == (TIM_SR_CC1IF)) ? 1UL : 0UL);
  2742. }
  2743. /**
  2744. * @brief Clear the Capture/Compare 2 interrupt flag (CC2F).
  2745. * @rmtoll SR CC2IF LL_TIM_ClearFlag_CC2
  2746. * @param TIMx Timer instance
  2747. * @retval None
  2748. */
  2749. __STATIC_INLINE void LL_TIM_ClearFlag_CC2(TIM_TypeDef *TIMx)
  2750. {
  2751. WRITE_REG(TIMx->SR, ~(TIM_SR_CC2IF));
  2752. }
  2753. /**
  2754. * @brief Indicate whether Capture/Compare 2 interrupt flag (CC2F) is set (Capture/Compare 2 interrupt is pending).
  2755. * @rmtoll SR CC2IF LL_TIM_IsActiveFlag_CC2
  2756. * @param TIMx Timer instance
  2757. * @retval State of bit (1 or 0).
  2758. */
  2759. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC2(const TIM_TypeDef *TIMx)
  2760. {
  2761. return ((READ_BIT(TIMx->SR, TIM_SR_CC2IF) == (TIM_SR_CC2IF)) ? 1UL : 0UL);
  2762. }
  2763. /**
  2764. * @brief Clear the Capture/Compare 3 interrupt flag (CC3F).
  2765. * @rmtoll SR CC3IF LL_TIM_ClearFlag_CC3
  2766. * @param TIMx Timer instance
  2767. * @retval None
  2768. */
  2769. __STATIC_INLINE void LL_TIM_ClearFlag_CC3(TIM_TypeDef *TIMx)
  2770. {
  2771. WRITE_REG(TIMx->SR, ~(TIM_SR_CC3IF));
  2772. }
  2773. /**
  2774. * @brief Indicate whether Capture/Compare 3 interrupt flag (CC3F) is set (Capture/Compare 3 interrupt is pending).
  2775. * @rmtoll SR CC3IF LL_TIM_IsActiveFlag_CC3
  2776. * @param TIMx Timer instance
  2777. * @retval State of bit (1 or 0).
  2778. */
  2779. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC3(const TIM_TypeDef *TIMx)
  2780. {
  2781. return ((READ_BIT(TIMx->SR, TIM_SR_CC3IF) == (TIM_SR_CC3IF)) ? 1UL : 0UL);
  2782. }
  2783. /**
  2784. * @brief Clear the Capture/Compare 4 interrupt flag (CC4F).
  2785. * @rmtoll SR CC4IF LL_TIM_ClearFlag_CC4
  2786. * @param TIMx Timer instance
  2787. * @retval None
  2788. */
  2789. __STATIC_INLINE void LL_TIM_ClearFlag_CC4(TIM_TypeDef *TIMx)
  2790. {
  2791. WRITE_REG(TIMx->SR, ~(TIM_SR_CC4IF));
  2792. }
  2793. /**
  2794. * @brief Indicate whether Capture/Compare 4 interrupt flag (CC4F) is set (Capture/Compare 4 interrupt is pending).
  2795. * @rmtoll SR CC4IF LL_TIM_IsActiveFlag_CC4
  2796. * @param TIMx Timer instance
  2797. * @retval State of bit (1 or 0).
  2798. */
  2799. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC4(const TIM_TypeDef *TIMx)
  2800. {
  2801. return ((READ_BIT(TIMx->SR, TIM_SR_CC4IF) == (TIM_SR_CC4IF)) ? 1UL : 0UL);
  2802. }
  2803. /**
  2804. * @brief Clear the commutation interrupt flag (COMIF).
  2805. * @rmtoll SR COMIF LL_TIM_ClearFlag_COM
  2806. * @param TIMx Timer instance
  2807. * @retval None
  2808. */
  2809. __STATIC_INLINE void LL_TIM_ClearFlag_COM(TIM_TypeDef *TIMx)
  2810. {
  2811. WRITE_REG(TIMx->SR, ~(TIM_SR_COMIF));
  2812. }
  2813. /**
  2814. * @brief Indicate whether commutation interrupt flag (COMIF) is set (commutation interrupt is pending).
  2815. * @rmtoll SR COMIF LL_TIM_IsActiveFlag_COM
  2816. * @param TIMx Timer instance
  2817. * @retval State of bit (1 or 0).
  2818. */
  2819. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_COM(const TIM_TypeDef *TIMx)
  2820. {
  2821. return ((READ_BIT(TIMx->SR, TIM_SR_COMIF) == (TIM_SR_COMIF)) ? 1UL : 0UL);
  2822. }
  2823. /**
  2824. * @brief Clear the trigger interrupt flag (TIF).
  2825. * @rmtoll SR TIF LL_TIM_ClearFlag_TRIG
  2826. * @param TIMx Timer instance
  2827. * @retval None
  2828. */
  2829. __STATIC_INLINE void LL_TIM_ClearFlag_TRIG(TIM_TypeDef *TIMx)
  2830. {
  2831. WRITE_REG(TIMx->SR, ~(TIM_SR_TIF));
  2832. }
  2833. /**
  2834. * @brief Indicate whether trigger interrupt flag (TIF) is set (trigger interrupt is pending).
  2835. * @rmtoll SR TIF LL_TIM_IsActiveFlag_TRIG
  2836. * @param TIMx Timer instance
  2837. * @retval State of bit (1 or 0).
  2838. */
  2839. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_TRIG(const TIM_TypeDef *TIMx)
  2840. {
  2841. return ((READ_BIT(TIMx->SR, TIM_SR_TIF) == (TIM_SR_TIF)) ? 1UL : 0UL);
  2842. }
  2843. /**
  2844. * @brief Clear the break interrupt flag (BIF).
  2845. * @rmtoll SR BIF LL_TIM_ClearFlag_BRK
  2846. * @param TIMx Timer instance
  2847. * @retval None
  2848. */
  2849. __STATIC_INLINE void LL_TIM_ClearFlag_BRK(TIM_TypeDef *TIMx)
  2850. {
  2851. WRITE_REG(TIMx->SR, ~(TIM_SR_BIF));
  2852. }
  2853. /**
  2854. * @brief Indicate whether break interrupt flag (BIF) is set (break interrupt is pending).
  2855. * @rmtoll SR BIF LL_TIM_IsActiveFlag_BRK
  2856. * @param TIMx Timer instance
  2857. * @retval State of bit (1 or 0).
  2858. */
  2859. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_BRK(const TIM_TypeDef *TIMx)
  2860. {
  2861. return ((READ_BIT(TIMx->SR, TIM_SR_BIF) == (TIM_SR_BIF)) ? 1UL : 0UL);
  2862. }
  2863. /**
  2864. * @brief Clear the Capture/Compare 1 over-capture interrupt flag (CC1OF).
  2865. * @rmtoll SR CC1OF LL_TIM_ClearFlag_CC1OVR
  2866. * @param TIMx Timer instance
  2867. * @retval None
  2868. */
  2869. __STATIC_INLINE void LL_TIM_ClearFlag_CC1OVR(TIM_TypeDef *TIMx)
  2870. {
  2871. WRITE_REG(TIMx->SR, ~(TIM_SR_CC1OF));
  2872. }
  2873. /**
  2874. * @brief Indicate whether Capture/Compare 1 over-capture interrupt flag (CC1OF) is set
  2875. * (Capture/Compare 1 interrupt is pending).
  2876. * @rmtoll SR CC1OF LL_TIM_IsActiveFlag_CC1OVR
  2877. * @param TIMx Timer instance
  2878. * @retval State of bit (1 or 0).
  2879. */
  2880. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC1OVR(const TIM_TypeDef *TIMx)
  2881. {
  2882. return ((READ_BIT(TIMx->SR, TIM_SR_CC1OF) == (TIM_SR_CC1OF)) ? 1UL : 0UL);
  2883. }
  2884. /**
  2885. * @brief Clear the Capture/Compare 2 over-capture interrupt flag (CC2OF).
  2886. * @rmtoll SR CC2OF LL_TIM_ClearFlag_CC2OVR
  2887. * @param TIMx Timer instance
  2888. * @retval None
  2889. */
  2890. __STATIC_INLINE void LL_TIM_ClearFlag_CC2OVR(TIM_TypeDef *TIMx)
  2891. {
  2892. WRITE_REG(TIMx->SR, ~(TIM_SR_CC2OF));
  2893. }
  2894. /**
  2895. * @brief Indicate whether Capture/Compare 2 over-capture interrupt flag (CC2OF) is set
  2896. * (Capture/Compare 2 over-capture interrupt is pending).
  2897. * @rmtoll SR CC2OF LL_TIM_IsActiveFlag_CC2OVR
  2898. * @param TIMx Timer instance
  2899. * @retval State of bit (1 or 0).
  2900. */
  2901. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC2OVR(const TIM_TypeDef *TIMx)
  2902. {
  2903. return ((READ_BIT(TIMx->SR, TIM_SR_CC2OF) == (TIM_SR_CC2OF)) ? 1UL : 0UL);
  2904. }
  2905. /**
  2906. * @brief Clear the Capture/Compare 3 over-capture interrupt flag (CC3OF).
  2907. * @rmtoll SR CC3OF LL_TIM_ClearFlag_CC3OVR
  2908. * @param TIMx Timer instance
  2909. * @retval None
  2910. */
  2911. __STATIC_INLINE void LL_TIM_ClearFlag_CC3OVR(TIM_TypeDef *TIMx)
  2912. {
  2913. WRITE_REG(TIMx->SR, ~(TIM_SR_CC3OF));
  2914. }
  2915. /**
  2916. * @brief Indicate whether Capture/Compare 3 over-capture interrupt flag (CC3OF) is set
  2917. * (Capture/Compare 3 over-capture interrupt is pending).
  2918. * @rmtoll SR CC3OF LL_TIM_IsActiveFlag_CC3OVR
  2919. * @param TIMx Timer instance
  2920. * @retval State of bit (1 or 0).
  2921. */
  2922. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC3OVR(const TIM_TypeDef *TIMx)
  2923. {
  2924. return ((READ_BIT(TIMx->SR, TIM_SR_CC3OF) == (TIM_SR_CC3OF)) ? 1UL : 0UL);
  2925. }
  2926. /**
  2927. * @brief Clear the Capture/Compare 4 over-capture interrupt flag (CC4OF).
  2928. * @rmtoll SR CC4OF LL_TIM_ClearFlag_CC4OVR
  2929. * @param TIMx Timer instance
  2930. * @retval None
  2931. */
  2932. __STATIC_INLINE void LL_TIM_ClearFlag_CC4OVR(TIM_TypeDef *TIMx)
  2933. {
  2934. WRITE_REG(TIMx->SR, ~(TIM_SR_CC4OF));
  2935. }
  2936. /**
  2937. * @brief Indicate whether Capture/Compare 4 over-capture interrupt flag (CC4OF) is set
  2938. * (Capture/Compare 4 over-capture interrupt is pending).
  2939. * @rmtoll SR CC4OF LL_TIM_IsActiveFlag_CC4OVR
  2940. * @param TIMx Timer instance
  2941. * @retval State of bit (1 or 0).
  2942. */
  2943. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC4OVR(const TIM_TypeDef *TIMx)
  2944. {
  2945. return ((READ_BIT(TIMx->SR, TIM_SR_CC4OF) == (TIM_SR_CC4OF)) ? 1UL : 0UL);
  2946. }
  2947. /**
  2948. * @}
  2949. */
  2950. /** @defgroup TIM_LL_EF_IT_Management IT-Management
  2951. * @{
  2952. */
  2953. /**
  2954. * @brief Enable update interrupt (UIE).
  2955. * @rmtoll DIER UIE LL_TIM_EnableIT_UPDATE
  2956. * @param TIMx Timer instance
  2957. * @retval None
  2958. */
  2959. __STATIC_INLINE void LL_TIM_EnableIT_UPDATE(TIM_TypeDef *TIMx)
  2960. {
  2961. SET_BIT(TIMx->DIER, TIM_DIER_UIE);
  2962. }
  2963. /**
  2964. * @brief Disable update interrupt (UIE).
  2965. * @rmtoll DIER UIE LL_TIM_DisableIT_UPDATE
  2966. * @param TIMx Timer instance
  2967. * @retval None
  2968. */
  2969. __STATIC_INLINE void LL_TIM_DisableIT_UPDATE(TIM_TypeDef *TIMx)
  2970. {
  2971. CLEAR_BIT(TIMx->DIER, TIM_DIER_UIE);
  2972. }
  2973. /**
  2974. * @brief Indicates whether the update interrupt (UIE) is enabled.
  2975. * @rmtoll DIER UIE LL_TIM_IsEnabledIT_UPDATE
  2976. * @param TIMx Timer instance
  2977. * @retval State of bit (1 or 0).
  2978. */
  2979. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_UPDATE(const TIM_TypeDef *TIMx)
  2980. {
  2981. return ((READ_BIT(TIMx->DIER, TIM_DIER_UIE) == (TIM_DIER_UIE)) ? 1UL : 0UL);
  2982. }
  2983. /**
  2984. * @brief Enable capture/compare 1 interrupt (CC1IE).
  2985. * @rmtoll DIER CC1IE LL_TIM_EnableIT_CC1
  2986. * @param TIMx Timer instance
  2987. * @retval None
  2988. */
  2989. __STATIC_INLINE void LL_TIM_EnableIT_CC1(TIM_TypeDef *TIMx)
  2990. {
  2991. SET_BIT(TIMx->DIER, TIM_DIER_CC1IE);
  2992. }
  2993. /**
  2994. * @brief Disable capture/compare 1 interrupt (CC1IE).
  2995. * @rmtoll DIER CC1IE LL_TIM_DisableIT_CC1
  2996. * @param TIMx Timer instance
  2997. * @retval None
  2998. */
  2999. __STATIC_INLINE void LL_TIM_DisableIT_CC1(TIM_TypeDef *TIMx)
  3000. {
  3001. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC1IE);
  3002. }
  3003. /**
  3004. * @brief Indicates whether the capture/compare 1 interrupt (CC1IE) is enabled.
  3005. * @rmtoll DIER CC1IE LL_TIM_IsEnabledIT_CC1
  3006. * @param TIMx Timer instance
  3007. * @retval State of bit (1 or 0).
  3008. */
  3009. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_CC1(const TIM_TypeDef *TIMx)
  3010. {
  3011. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC1IE) == (TIM_DIER_CC1IE)) ? 1UL : 0UL);
  3012. }
  3013. /**
  3014. * @brief Enable capture/compare 2 interrupt (CC2IE).
  3015. * @rmtoll DIER CC2IE LL_TIM_EnableIT_CC2
  3016. * @param TIMx Timer instance
  3017. * @retval None
  3018. */
  3019. __STATIC_INLINE void LL_TIM_EnableIT_CC2(TIM_TypeDef *TIMx)
  3020. {
  3021. SET_BIT(TIMx->DIER, TIM_DIER_CC2IE);
  3022. }
  3023. /**
  3024. * @brief Disable capture/compare 2 interrupt (CC2IE).
  3025. * @rmtoll DIER CC2IE LL_TIM_DisableIT_CC2
  3026. * @param TIMx Timer instance
  3027. * @retval None
  3028. */
  3029. __STATIC_INLINE void LL_TIM_DisableIT_CC2(TIM_TypeDef *TIMx)
  3030. {
  3031. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC2IE);
  3032. }
  3033. /**
  3034. * @brief Indicates whether the capture/compare 2 interrupt (CC2IE) is enabled.
  3035. * @rmtoll DIER CC2IE LL_TIM_IsEnabledIT_CC2
  3036. * @param TIMx Timer instance
  3037. * @retval State of bit (1 or 0).
  3038. */
  3039. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_CC2(const TIM_TypeDef *TIMx)
  3040. {
  3041. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC2IE) == (TIM_DIER_CC2IE)) ? 1UL : 0UL);
  3042. }
  3043. /**
  3044. * @brief Enable capture/compare 3 interrupt (CC3IE).
  3045. * @rmtoll DIER CC3IE LL_TIM_EnableIT_CC3
  3046. * @param TIMx Timer instance
  3047. * @retval None
  3048. */
  3049. __STATIC_INLINE void LL_TIM_EnableIT_CC3(TIM_TypeDef *TIMx)
  3050. {
  3051. SET_BIT(TIMx->DIER, TIM_DIER_CC3IE);
  3052. }
  3053. /**
  3054. * @brief Disable capture/compare 3 interrupt (CC3IE).
  3055. * @rmtoll DIER CC3IE LL_TIM_DisableIT_CC3
  3056. * @param TIMx Timer instance
  3057. * @retval None
  3058. */
  3059. __STATIC_INLINE void LL_TIM_DisableIT_CC3(TIM_TypeDef *TIMx)
  3060. {
  3061. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC3IE);
  3062. }
  3063. /**
  3064. * @brief Indicates whether the capture/compare 3 interrupt (CC3IE) is enabled.
  3065. * @rmtoll DIER CC3IE LL_TIM_IsEnabledIT_CC3
  3066. * @param TIMx Timer instance
  3067. * @retval State of bit (1 or 0).
  3068. */
  3069. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_CC3(const TIM_TypeDef *TIMx)
  3070. {
  3071. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC3IE) == (TIM_DIER_CC3IE)) ? 1UL : 0UL);
  3072. }
  3073. /**
  3074. * @brief Enable capture/compare 4 interrupt (CC4IE).
  3075. * @rmtoll DIER CC4IE LL_TIM_EnableIT_CC4
  3076. * @param TIMx Timer instance
  3077. * @retval None
  3078. */
  3079. __STATIC_INLINE void LL_TIM_EnableIT_CC4(TIM_TypeDef *TIMx)
  3080. {
  3081. SET_BIT(TIMx->DIER, TIM_DIER_CC4IE);
  3082. }
  3083. /**
  3084. * @brief Disable capture/compare 4 interrupt (CC4IE).
  3085. * @rmtoll DIER CC4IE LL_TIM_DisableIT_CC4
  3086. * @param TIMx Timer instance
  3087. * @retval None
  3088. */
  3089. __STATIC_INLINE void LL_TIM_DisableIT_CC4(TIM_TypeDef *TIMx)
  3090. {
  3091. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC4IE);
  3092. }
  3093. /**
  3094. * @brief Indicates whether the capture/compare 4 interrupt (CC4IE) is enabled.
  3095. * @rmtoll DIER CC4IE LL_TIM_IsEnabledIT_CC4
  3096. * @param TIMx Timer instance
  3097. * @retval State of bit (1 or 0).
  3098. */
  3099. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_CC4(const TIM_TypeDef *TIMx)
  3100. {
  3101. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC4IE) == (TIM_DIER_CC4IE)) ? 1UL : 0UL);
  3102. }
  3103. /**
  3104. * @brief Enable commutation interrupt (COMIE).
  3105. * @rmtoll DIER COMIE LL_TIM_EnableIT_COM
  3106. * @param TIMx Timer instance
  3107. * @retval None
  3108. */
  3109. __STATIC_INLINE void LL_TIM_EnableIT_COM(TIM_TypeDef *TIMx)
  3110. {
  3111. SET_BIT(TIMx->DIER, TIM_DIER_COMIE);
  3112. }
  3113. /**
  3114. * @brief Disable commutation interrupt (COMIE).
  3115. * @rmtoll DIER COMIE LL_TIM_DisableIT_COM
  3116. * @param TIMx Timer instance
  3117. * @retval None
  3118. */
  3119. __STATIC_INLINE void LL_TIM_DisableIT_COM(TIM_TypeDef *TIMx)
  3120. {
  3121. CLEAR_BIT(TIMx->DIER, TIM_DIER_COMIE);
  3122. }
  3123. /**
  3124. * @brief Indicates whether the commutation interrupt (COMIE) is enabled.
  3125. * @rmtoll DIER COMIE LL_TIM_IsEnabledIT_COM
  3126. * @param TIMx Timer instance
  3127. * @retval State of bit (1 or 0).
  3128. */
  3129. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_COM(const TIM_TypeDef *TIMx)
  3130. {
  3131. return ((READ_BIT(TIMx->DIER, TIM_DIER_COMIE) == (TIM_DIER_COMIE)) ? 1UL : 0UL);
  3132. }
  3133. /**
  3134. * @brief Enable trigger interrupt (TIE).
  3135. * @rmtoll DIER TIE LL_TIM_EnableIT_TRIG
  3136. * @param TIMx Timer instance
  3137. * @retval None
  3138. */
  3139. __STATIC_INLINE void LL_TIM_EnableIT_TRIG(TIM_TypeDef *TIMx)
  3140. {
  3141. SET_BIT(TIMx->DIER, TIM_DIER_TIE);
  3142. }
  3143. /**
  3144. * @brief Disable trigger interrupt (TIE).
  3145. * @rmtoll DIER TIE LL_TIM_DisableIT_TRIG
  3146. * @param TIMx Timer instance
  3147. * @retval None
  3148. */
  3149. __STATIC_INLINE void LL_TIM_DisableIT_TRIG(TIM_TypeDef *TIMx)
  3150. {
  3151. CLEAR_BIT(TIMx->DIER, TIM_DIER_TIE);
  3152. }
  3153. /**
  3154. * @brief Indicates whether the trigger interrupt (TIE) is enabled.
  3155. * @rmtoll DIER TIE LL_TIM_IsEnabledIT_TRIG
  3156. * @param TIMx Timer instance
  3157. * @retval State of bit (1 or 0).
  3158. */
  3159. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_TRIG(const TIM_TypeDef *TIMx)
  3160. {
  3161. return ((READ_BIT(TIMx->DIER, TIM_DIER_TIE) == (TIM_DIER_TIE)) ? 1UL : 0UL);
  3162. }
  3163. /**
  3164. * @brief Enable break interrupt (BIE).
  3165. * @rmtoll DIER BIE LL_TIM_EnableIT_BRK
  3166. * @param TIMx Timer instance
  3167. * @retval None
  3168. */
  3169. __STATIC_INLINE void LL_TIM_EnableIT_BRK(TIM_TypeDef *TIMx)
  3170. {
  3171. SET_BIT(TIMx->DIER, TIM_DIER_BIE);
  3172. }
  3173. /**
  3174. * @brief Disable break interrupt (BIE).
  3175. * @rmtoll DIER BIE LL_TIM_DisableIT_BRK
  3176. * @param TIMx Timer instance
  3177. * @retval None
  3178. */
  3179. __STATIC_INLINE void LL_TIM_DisableIT_BRK(TIM_TypeDef *TIMx)
  3180. {
  3181. CLEAR_BIT(TIMx->DIER, TIM_DIER_BIE);
  3182. }
  3183. /**
  3184. * @brief Indicates whether the break interrupt (BIE) is enabled.
  3185. * @rmtoll DIER BIE LL_TIM_IsEnabledIT_BRK
  3186. * @param TIMx Timer instance
  3187. * @retval State of bit (1 or 0).
  3188. */
  3189. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_BRK(const TIM_TypeDef *TIMx)
  3190. {
  3191. return ((READ_BIT(TIMx->DIER, TIM_DIER_BIE) == (TIM_DIER_BIE)) ? 1UL : 0UL);
  3192. }
  3193. /**
  3194. * @}
  3195. */
  3196. /** @defgroup TIM_LL_EF_DMA_Management DMA Management
  3197. * @{
  3198. */
  3199. /**
  3200. * @brief Enable update DMA request (UDE).
  3201. * @rmtoll DIER UDE LL_TIM_EnableDMAReq_UPDATE
  3202. * @param TIMx Timer instance
  3203. * @retval None
  3204. */
  3205. __STATIC_INLINE void LL_TIM_EnableDMAReq_UPDATE(TIM_TypeDef *TIMx)
  3206. {
  3207. SET_BIT(TIMx->DIER, TIM_DIER_UDE);
  3208. }
  3209. /**
  3210. * @brief Disable update DMA request (UDE).
  3211. * @rmtoll DIER UDE LL_TIM_DisableDMAReq_UPDATE
  3212. * @param TIMx Timer instance
  3213. * @retval None
  3214. */
  3215. __STATIC_INLINE void LL_TIM_DisableDMAReq_UPDATE(TIM_TypeDef *TIMx)
  3216. {
  3217. CLEAR_BIT(TIMx->DIER, TIM_DIER_UDE);
  3218. }
  3219. /**
  3220. * @brief Indicates whether the update DMA request (UDE) is enabled.
  3221. * @rmtoll DIER UDE LL_TIM_IsEnabledDMAReq_UPDATE
  3222. * @param TIMx Timer instance
  3223. * @retval State of bit (1 or 0).
  3224. */
  3225. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_UPDATE(const TIM_TypeDef *TIMx)
  3226. {
  3227. return ((READ_BIT(TIMx->DIER, TIM_DIER_UDE) == (TIM_DIER_UDE)) ? 1UL : 0UL);
  3228. }
  3229. /**
  3230. * @brief Enable capture/compare 1 DMA request (CC1DE).
  3231. * @rmtoll DIER CC1DE LL_TIM_EnableDMAReq_CC1
  3232. * @param TIMx Timer instance
  3233. * @retval None
  3234. */
  3235. __STATIC_INLINE void LL_TIM_EnableDMAReq_CC1(TIM_TypeDef *TIMx)
  3236. {
  3237. SET_BIT(TIMx->DIER, TIM_DIER_CC1DE);
  3238. }
  3239. /**
  3240. * @brief Disable capture/compare 1 DMA request (CC1DE).
  3241. * @rmtoll DIER CC1DE LL_TIM_DisableDMAReq_CC1
  3242. * @param TIMx Timer instance
  3243. * @retval None
  3244. */
  3245. __STATIC_INLINE void LL_TIM_DisableDMAReq_CC1(TIM_TypeDef *TIMx)
  3246. {
  3247. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC1DE);
  3248. }
  3249. /**
  3250. * @brief Indicates whether the capture/compare 1 DMA request (CC1DE) is enabled.
  3251. * @rmtoll DIER CC1DE LL_TIM_IsEnabledDMAReq_CC1
  3252. * @param TIMx Timer instance
  3253. * @retval State of bit (1 or 0).
  3254. */
  3255. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_CC1(const TIM_TypeDef *TIMx)
  3256. {
  3257. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC1DE) == (TIM_DIER_CC1DE)) ? 1UL : 0UL);
  3258. }
  3259. /**
  3260. * @brief Enable capture/compare 2 DMA request (CC2DE).
  3261. * @rmtoll DIER CC2DE LL_TIM_EnableDMAReq_CC2
  3262. * @param TIMx Timer instance
  3263. * @retval None
  3264. */
  3265. __STATIC_INLINE void LL_TIM_EnableDMAReq_CC2(TIM_TypeDef *TIMx)
  3266. {
  3267. SET_BIT(TIMx->DIER, TIM_DIER_CC2DE);
  3268. }
  3269. /**
  3270. * @brief Disable capture/compare 2 DMA request (CC2DE).
  3271. * @rmtoll DIER CC2DE LL_TIM_DisableDMAReq_CC2
  3272. * @param TIMx Timer instance
  3273. * @retval None
  3274. */
  3275. __STATIC_INLINE void LL_TIM_DisableDMAReq_CC2(TIM_TypeDef *TIMx)
  3276. {
  3277. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC2DE);
  3278. }
  3279. /**
  3280. * @brief Indicates whether the capture/compare 2 DMA request (CC2DE) is enabled.
  3281. * @rmtoll DIER CC2DE LL_TIM_IsEnabledDMAReq_CC2
  3282. * @param TIMx Timer instance
  3283. * @retval State of bit (1 or 0).
  3284. */
  3285. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_CC2(const TIM_TypeDef *TIMx)
  3286. {
  3287. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC2DE) == (TIM_DIER_CC2DE)) ? 1UL : 0UL);
  3288. }
  3289. /**
  3290. * @brief Enable capture/compare 3 DMA request (CC3DE).
  3291. * @rmtoll DIER CC3DE LL_TIM_EnableDMAReq_CC3
  3292. * @param TIMx Timer instance
  3293. * @retval None
  3294. */
  3295. __STATIC_INLINE void LL_TIM_EnableDMAReq_CC3(TIM_TypeDef *TIMx)
  3296. {
  3297. SET_BIT(TIMx->DIER, TIM_DIER_CC3DE);
  3298. }
  3299. /**
  3300. * @brief Disable capture/compare 3 DMA request (CC3DE).
  3301. * @rmtoll DIER CC3DE LL_TIM_DisableDMAReq_CC3
  3302. * @param TIMx Timer instance
  3303. * @retval None
  3304. */
  3305. __STATIC_INLINE void LL_TIM_DisableDMAReq_CC3(TIM_TypeDef *TIMx)
  3306. {
  3307. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC3DE);
  3308. }
  3309. /**
  3310. * @brief Indicates whether the capture/compare 3 DMA request (CC3DE) is enabled.
  3311. * @rmtoll DIER CC3DE LL_TIM_IsEnabledDMAReq_CC3
  3312. * @param TIMx Timer instance
  3313. * @retval State of bit (1 or 0).
  3314. */
  3315. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_CC3(const TIM_TypeDef *TIMx)
  3316. {
  3317. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC3DE) == (TIM_DIER_CC3DE)) ? 1UL : 0UL);
  3318. }
  3319. /**
  3320. * @brief Enable capture/compare 4 DMA request (CC4DE).
  3321. * @rmtoll DIER CC4DE LL_TIM_EnableDMAReq_CC4
  3322. * @param TIMx Timer instance
  3323. * @retval None
  3324. */
  3325. __STATIC_INLINE void LL_TIM_EnableDMAReq_CC4(TIM_TypeDef *TIMx)
  3326. {
  3327. SET_BIT(TIMx->DIER, TIM_DIER_CC4DE);
  3328. }
  3329. /**
  3330. * @brief Disable capture/compare 4 DMA request (CC4DE).
  3331. * @rmtoll DIER CC4DE LL_TIM_DisableDMAReq_CC4
  3332. * @param TIMx Timer instance
  3333. * @retval None
  3334. */
  3335. __STATIC_INLINE void LL_TIM_DisableDMAReq_CC4(TIM_TypeDef *TIMx)
  3336. {
  3337. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC4DE);
  3338. }
  3339. /**
  3340. * @brief Indicates whether the capture/compare 4 DMA request (CC4DE) is enabled.
  3341. * @rmtoll DIER CC4DE LL_TIM_IsEnabledDMAReq_CC4
  3342. * @param TIMx Timer instance
  3343. * @retval State of bit (1 or 0).
  3344. */
  3345. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_CC4(const TIM_TypeDef *TIMx)
  3346. {
  3347. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC4DE) == (TIM_DIER_CC4DE)) ? 1UL : 0UL);
  3348. }
  3349. /**
  3350. * @brief Enable commutation DMA request (COMDE).
  3351. * @rmtoll DIER COMDE LL_TIM_EnableDMAReq_COM
  3352. * @param TIMx Timer instance
  3353. * @retval None
  3354. */
  3355. __STATIC_INLINE void LL_TIM_EnableDMAReq_COM(TIM_TypeDef *TIMx)
  3356. {
  3357. SET_BIT(TIMx->DIER, TIM_DIER_COMDE);
  3358. }
  3359. /**
  3360. * @brief Disable commutation DMA request (COMDE).
  3361. * @rmtoll DIER COMDE LL_TIM_DisableDMAReq_COM
  3362. * @param TIMx Timer instance
  3363. * @retval None
  3364. */
  3365. __STATIC_INLINE void LL_TIM_DisableDMAReq_COM(TIM_TypeDef *TIMx)
  3366. {
  3367. CLEAR_BIT(TIMx->DIER, TIM_DIER_COMDE);
  3368. }
  3369. /**
  3370. * @brief Indicates whether the commutation DMA request (COMDE) is enabled.
  3371. * @rmtoll DIER COMDE LL_TIM_IsEnabledDMAReq_COM
  3372. * @param TIMx Timer instance
  3373. * @retval State of bit (1 or 0).
  3374. */
  3375. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_COM(const TIM_TypeDef *TIMx)
  3376. {
  3377. return ((READ_BIT(TIMx->DIER, TIM_DIER_COMDE) == (TIM_DIER_COMDE)) ? 1UL : 0UL);
  3378. }
  3379. /**
  3380. * @brief Enable trigger interrupt (TDE).
  3381. * @rmtoll DIER TDE LL_TIM_EnableDMAReq_TRIG
  3382. * @param TIMx Timer instance
  3383. * @retval None
  3384. */
  3385. __STATIC_INLINE void LL_TIM_EnableDMAReq_TRIG(TIM_TypeDef *TIMx)
  3386. {
  3387. SET_BIT(TIMx->DIER, TIM_DIER_TDE);
  3388. }
  3389. /**
  3390. * @brief Disable trigger interrupt (TDE).
  3391. * @rmtoll DIER TDE LL_TIM_DisableDMAReq_TRIG
  3392. * @param TIMx Timer instance
  3393. * @retval None
  3394. */
  3395. __STATIC_INLINE void LL_TIM_DisableDMAReq_TRIG(TIM_TypeDef *TIMx)
  3396. {
  3397. CLEAR_BIT(TIMx->DIER, TIM_DIER_TDE);
  3398. }
  3399. /**
  3400. * @brief Indicates whether the trigger interrupt (TDE) is enabled.
  3401. * @rmtoll DIER TDE LL_TIM_IsEnabledDMAReq_TRIG
  3402. * @param TIMx Timer instance
  3403. * @retval State of bit (1 or 0).
  3404. */
  3405. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_TRIG(const TIM_TypeDef *TIMx)
  3406. {
  3407. return ((READ_BIT(TIMx->DIER, TIM_DIER_TDE) == (TIM_DIER_TDE)) ? 1UL : 0UL);
  3408. }
  3409. /**
  3410. * @}
  3411. */
  3412. /** @defgroup TIM_LL_EF_EVENT_Management EVENT-Management
  3413. * @{
  3414. */
  3415. /**
  3416. * @brief Generate an update event.
  3417. * @rmtoll EGR UG LL_TIM_GenerateEvent_UPDATE
  3418. * @param TIMx Timer instance
  3419. * @retval None
  3420. */
  3421. __STATIC_INLINE void LL_TIM_GenerateEvent_UPDATE(TIM_TypeDef *TIMx)
  3422. {
  3423. SET_BIT(TIMx->EGR, TIM_EGR_UG);
  3424. }
  3425. /**
  3426. * @brief Generate Capture/Compare 1 event.
  3427. * @rmtoll EGR CC1G LL_TIM_GenerateEvent_CC1
  3428. * @param TIMx Timer instance
  3429. * @retval None
  3430. */
  3431. __STATIC_INLINE void LL_TIM_GenerateEvent_CC1(TIM_TypeDef *TIMx)
  3432. {
  3433. SET_BIT(TIMx->EGR, TIM_EGR_CC1G);
  3434. }
  3435. /**
  3436. * @brief Generate Capture/Compare 2 event.
  3437. * @rmtoll EGR CC2G LL_TIM_GenerateEvent_CC2
  3438. * @param TIMx Timer instance
  3439. * @retval None
  3440. */
  3441. __STATIC_INLINE void LL_TIM_GenerateEvent_CC2(TIM_TypeDef *TIMx)
  3442. {
  3443. SET_BIT(TIMx->EGR, TIM_EGR_CC2G);
  3444. }
  3445. /**
  3446. * @brief Generate Capture/Compare 3 event.
  3447. * @rmtoll EGR CC3G LL_TIM_GenerateEvent_CC3
  3448. * @param TIMx Timer instance
  3449. * @retval None
  3450. */
  3451. __STATIC_INLINE void LL_TIM_GenerateEvent_CC3(TIM_TypeDef *TIMx)
  3452. {
  3453. SET_BIT(TIMx->EGR, TIM_EGR_CC3G);
  3454. }
  3455. /**
  3456. * @brief Generate Capture/Compare 4 event.
  3457. * @rmtoll EGR CC4G LL_TIM_GenerateEvent_CC4
  3458. * @param TIMx Timer instance
  3459. * @retval None
  3460. */
  3461. __STATIC_INLINE void LL_TIM_GenerateEvent_CC4(TIM_TypeDef *TIMx)
  3462. {
  3463. SET_BIT(TIMx->EGR, TIM_EGR_CC4G);
  3464. }
  3465. /**
  3466. * @brief Generate commutation event.
  3467. * @rmtoll EGR COMG LL_TIM_GenerateEvent_COM
  3468. * @param TIMx Timer instance
  3469. * @retval None
  3470. */
  3471. __STATIC_INLINE void LL_TIM_GenerateEvent_COM(TIM_TypeDef *TIMx)
  3472. {
  3473. SET_BIT(TIMx->EGR, TIM_EGR_COMG);
  3474. }
  3475. /**
  3476. * @brief Generate trigger event.
  3477. * @rmtoll EGR TG LL_TIM_GenerateEvent_TRIG
  3478. * @param TIMx Timer instance
  3479. * @retval None
  3480. */
  3481. __STATIC_INLINE void LL_TIM_GenerateEvent_TRIG(TIM_TypeDef *TIMx)
  3482. {
  3483. SET_BIT(TIMx->EGR, TIM_EGR_TG);
  3484. }
  3485. /**
  3486. * @brief Generate break event.
  3487. * @rmtoll EGR BG LL_TIM_GenerateEvent_BRK
  3488. * @param TIMx Timer instance
  3489. * @retval None
  3490. */
  3491. __STATIC_INLINE void LL_TIM_GenerateEvent_BRK(TIM_TypeDef *TIMx)
  3492. {
  3493. SET_BIT(TIMx->EGR, TIM_EGR_BG);
  3494. }
  3495. /**
  3496. * @}
  3497. */
  3498. #if defined(USE_FULL_LL_DRIVER)
  3499. /** @defgroup TIM_LL_EF_Init Initialisation and deinitialisation functions
  3500. * @{
  3501. */
  3502. ErrorStatus LL_TIM_DeInit(const TIM_TypeDef *TIMx);
  3503. void LL_TIM_StructInit(LL_TIM_InitTypeDef *TIM_InitStruct);
  3504. ErrorStatus LL_TIM_Init(TIM_TypeDef *TIMx, const LL_TIM_InitTypeDef *TIM_InitStruct);
  3505. void LL_TIM_OC_StructInit(LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct);
  3506. ErrorStatus LL_TIM_OC_Init(TIM_TypeDef *TIMx, uint32_t Channel, const LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct);
  3507. void LL_TIM_IC_StructInit(LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  3508. ErrorStatus LL_TIM_IC_Init(TIM_TypeDef *TIMx, uint32_t Channel, const LL_TIM_IC_InitTypeDef *TIM_IC_InitStruct);
  3509. void LL_TIM_ENCODER_StructInit(LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct);
  3510. ErrorStatus LL_TIM_ENCODER_Init(TIM_TypeDef *TIMx, const LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct);
  3511. void LL_TIM_HALLSENSOR_StructInit(LL_TIM_HALLSENSOR_InitTypeDef *TIM_HallSensorInitStruct);
  3512. ErrorStatus LL_TIM_HALLSENSOR_Init(TIM_TypeDef *TIMx, const LL_TIM_HALLSENSOR_InitTypeDef *TIM_HallSensorInitStruct);
  3513. void LL_TIM_BDTR_StructInit(LL_TIM_BDTR_InitTypeDef *TIM_BDTRInitStruct);
  3514. ErrorStatus LL_TIM_BDTR_Init(TIM_TypeDef *TIMx, const LL_TIM_BDTR_InitTypeDef *TIM_BDTRInitStruct);
  3515. /**
  3516. * @}
  3517. */
  3518. #endif /* USE_FULL_LL_DRIVER */
  3519. /**
  3520. * @}
  3521. */
  3522. /**
  3523. * @}
  3524. */
  3525. #endif /* TIM1 || TIM2 || TIM3 || TIM4 || TIM5 || TIM6 || TIM7 || TIM8 || TIM9 || TIM10 || TIM11 || TIM12 || TIM13 || TIM14 || TIM15 || TIM16 || TIM17 */
  3526. /**
  3527. * @}
  3528. */
  3529. #ifdef __cplusplus
  3530. }
  3531. #endif
  3532. #endif /* __STM32F1xx_LL_TIM_H */