stm32f1xx_ll_tim.h 160 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905
  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. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __STM32F1xx_LL_TIM_H
  21. #define __STM32F1xx_LL_TIM_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f1xx.h"
  27. /** @addtogroup STM32F1xx_LL_Driver
  28. * @{
  29. */
  30. #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)
  31. /** @defgroup TIM_LL TIM
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /** @defgroup TIM_LL_Private_Variables TIM Private Variables
  37. * @{
  38. */
  39. static const uint8_t OFFSET_TAB_CCMRx[] =
  40. {
  41. 0x00U, /* 0: TIMx_CH1 */
  42. 0x00U, /* 1: TIMx_CH1N */
  43. 0x00U, /* 2: TIMx_CH2 */
  44. 0x00U, /* 3: TIMx_CH2N */
  45. 0x04U, /* 4: TIMx_CH3 */
  46. 0x04U, /* 5: TIMx_CH3N */
  47. 0x04U /* 6: TIMx_CH4 */
  48. };
  49. static const uint8_t SHIFT_TAB_OCxx[] =
  50. {
  51. 0U, /* 0: OC1M, OC1FE, OC1PE */
  52. 0U, /* 1: - NA */
  53. 8U, /* 2: OC2M, OC2FE, OC2PE */
  54. 0U, /* 3: - NA */
  55. 0U, /* 4: OC3M, OC3FE, OC3PE */
  56. 0U, /* 5: - NA */
  57. 8U /* 6: OC4M, OC4FE, OC4PE */
  58. };
  59. static const uint8_t SHIFT_TAB_ICxx[] =
  60. {
  61. 0U, /* 0: CC1S, IC1PSC, IC1F */
  62. 0U, /* 1: - NA */
  63. 8U, /* 2: CC2S, IC2PSC, IC2F */
  64. 0U, /* 3: - NA */
  65. 0U, /* 4: CC3S, IC3PSC, IC3F */
  66. 0U, /* 5: - NA */
  67. 8U /* 6: CC4S, IC4PSC, IC4F */
  68. };
  69. static const uint8_t SHIFT_TAB_CCxP[] =
  70. {
  71. 0U, /* 0: CC1P */
  72. 2U, /* 1: CC1NP */
  73. 4U, /* 2: CC2P */
  74. 6U, /* 3: CC2NP */
  75. 8U, /* 4: CC3P */
  76. 10U, /* 5: CC3NP */
  77. 12U /* 6: CC4P */
  78. };
  79. static const uint8_t SHIFT_TAB_OISx[] =
  80. {
  81. 0U, /* 0: OIS1 */
  82. 1U, /* 1: OIS1N */
  83. 2U, /* 2: OIS2 */
  84. 3U, /* 3: OIS2N */
  85. 4U, /* 4: OIS3 */
  86. 5U, /* 5: OIS3N */
  87. 6U /* 6: OIS4 */
  88. };
  89. /**
  90. * @}
  91. */
  92. /* Private constants ---------------------------------------------------------*/
  93. /** @defgroup TIM_LL_Private_Constants TIM Private Constants
  94. * @{
  95. */
  96. /* Mask used to set the TDG[x:0] of the DTG bits of the TIMx_BDTR register */
  97. #define DT_DELAY_1 ((uint8_t)0x7F)
  98. #define DT_DELAY_2 ((uint8_t)0x3F)
  99. #define DT_DELAY_3 ((uint8_t)0x1F)
  100. #define DT_DELAY_4 ((uint8_t)0x1F)
  101. /* Mask used to set the DTG[7:5] bits of the DTG bits of the TIMx_BDTR register */
  102. #define DT_RANGE_1 ((uint8_t)0x00)
  103. #define DT_RANGE_2 ((uint8_t)0x80)
  104. #define DT_RANGE_3 ((uint8_t)0xC0)
  105. #define DT_RANGE_4 ((uint8_t)0xE0)
  106. /**
  107. * @}
  108. */
  109. /* Private macros ------------------------------------------------------------*/
  110. /** @defgroup TIM_LL_Private_Macros TIM Private Macros
  111. * @{
  112. */
  113. /** @brief Convert channel id into channel index.
  114. * @param __CHANNEL__ This parameter can be one of the following values:
  115. * @arg @ref LL_TIM_CHANNEL_CH1
  116. * @arg @ref LL_TIM_CHANNEL_CH1N
  117. * @arg @ref LL_TIM_CHANNEL_CH2
  118. * @arg @ref LL_TIM_CHANNEL_CH2N
  119. * @arg @ref LL_TIM_CHANNEL_CH3
  120. * @arg @ref LL_TIM_CHANNEL_CH3N
  121. * @arg @ref LL_TIM_CHANNEL_CH4
  122. * @retval none
  123. */
  124. #define TIM_GET_CHANNEL_INDEX( __CHANNEL__) \
  125. (((__CHANNEL__) == LL_TIM_CHANNEL_CH1) ? 0U :\
  126. ((__CHANNEL__) == LL_TIM_CHANNEL_CH1N) ? 1U :\
  127. ((__CHANNEL__) == LL_TIM_CHANNEL_CH2) ? 2U :\
  128. ((__CHANNEL__) == LL_TIM_CHANNEL_CH2N) ? 3U :\
  129. ((__CHANNEL__) == LL_TIM_CHANNEL_CH3) ? 4U :\
  130. ((__CHANNEL__) == LL_TIM_CHANNEL_CH3N) ? 5U : 6U)
  131. /** @brief Calculate the deadtime sampling period(in ps).
  132. * @param __TIMCLK__ timer input clock frequency (in Hz).
  133. * @param __CKD__ This parameter can be one of the following values:
  134. * @arg @ref LL_TIM_CLOCKDIVISION_DIV1
  135. * @arg @ref LL_TIM_CLOCKDIVISION_DIV2
  136. * @arg @ref LL_TIM_CLOCKDIVISION_DIV4
  137. * @retval none
  138. */
  139. #define TIM_CALC_DTS(__TIMCLK__, __CKD__) \
  140. (((__CKD__) == LL_TIM_CLOCKDIVISION_DIV1) ? ((uint64_t)1000000000000U/(__TIMCLK__)) : \
  141. ((__CKD__) == LL_TIM_CLOCKDIVISION_DIV2) ? ((uint64_t)1000000000000U/((__TIMCLK__) >> 1U)) : \
  142. ((uint64_t)1000000000000U/((__TIMCLK__) >> 2U)))
  143. /**
  144. * @}
  145. */
  146. /* Exported types ------------------------------------------------------------*/
  147. #if defined(USE_FULL_LL_DRIVER)
  148. /** @defgroup TIM_LL_ES_INIT TIM Exported Init structure
  149. * @{
  150. */
  151. /**
  152. * @brief TIM Time Base configuration structure definition.
  153. */
  154. typedef struct
  155. {
  156. uint16_t Prescaler; /*!< Specifies the prescaler value used to divide the TIM clock.
  157. This parameter can be a number between Min_Data=0x0000 and Max_Data=0xFFFF.
  158. This feature can be modified afterwards using unitary function
  159. @ref LL_TIM_SetPrescaler().*/
  160. uint32_t CounterMode; /*!< Specifies the counter mode.
  161. This parameter can be a value of @ref TIM_LL_EC_COUNTERMODE.
  162. This feature can be modified afterwards using unitary function
  163. @ref LL_TIM_SetCounterMode().*/
  164. uint32_t Autoreload; /*!< Specifies the auto reload value to be loaded into the active
  165. Auto-Reload Register at the next update event.
  166. This parameter must be a number between Min_Data=0x0000 and Max_Data=0xFFFF.
  167. Some timer instances may support 32 bits counters. In that case this parameter must
  168. be a number between 0x0000 and 0xFFFFFFFF.
  169. This feature can be modified afterwards using unitary function
  170. @ref LL_TIM_SetAutoReload().*/
  171. uint32_t ClockDivision; /*!< Specifies the clock division.
  172. This parameter can be a value of @ref TIM_LL_EC_CLOCKDIVISION.
  173. This feature can be modified afterwards using unitary function
  174. @ref LL_TIM_SetClockDivision().*/
  175. uint32_t RepetitionCounter; /*!< Specifies the repetition counter value. Each time the RCR downcounter
  176. reaches zero, an update event is generated and counting restarts
  177. from the RCR value (N).
  178. This means in PWM mode that (N+1) corresponds to:
  179. - the number of PWM periods in edge-aligned mode
  180. - the number of half PWM period in center-aligned mode
  181. GP timers: this parameter must be a number between Min_Data = 0x00 and
  182. Max_Data = 0xFF.
  183. Advanced timers: this parameter must be a number between Min_Data = 0x0000 and
  184. Max_Data = 0xFFFF.
  185. This feature can be modified afterwards using unitary function
  186. @ref LL_TIM_SetRepetitionCounter().*/
  187. } LL_TIM_InitTypeDef;
  188. /**
  189. * @brief TIM Output Compare configuration structure definition.
  190. */
  191. typedef struct
  192. {
  193. uint32_t OCMode; /*!< Specifies the output mode.
  194. This parameter can be a value of @ref TIM_LL_EC_OCMODE.
  195. This feature can be modified afterwards using unitary function
  196. @ref LL_TIM_OC_SetMode().*/
  197. uint32_t OCState; /*!< Specifies the TIM Output Compare state.
  198. This parameter can be a value of @ref TIM_LL_EC_OCSTATE.
  199. This feature can be modified afterwards using unitary functions
  200. @ref LL_TIM_CC_EnableChannel() or @ref LL_TIM_CC_DisableChannel().*/
  201. uint32_t OCNState; /*!< Specifies the TIM complementary Output Compare state.
  202. This parameter can be a value of @ref TIM_LL_EC_OCSTATE.
  203. This feature can be modified afterwards using unitary functions
  204. @ref LL_TIM_CC_EnableChannel() or @ref LL_TIM_CC_DisableChannel().*/
  205. uint32_t CompareValue; /*!< Specifies the Compare value to be loaded into the Capture Compare Register.
  206. This parameter can be a number between Min_Data=0x0000 and Max_Data=0xFFFF.
  207. This feature can be modified afterwards using unitary function
  208. LL_TIM_OC_SetCompareCHx (x=1..6).*/
  209. uint32_t OCPolarity; /*!< Specifies the output polarity.
  210. This parameter can be a value of @ref TIM_LL_EC_OCPOLARITY.
  211. This feature can be modified afterwards using unitary function
  212. @ref LL_TIM_OC_SetPolarity().*/
  213. uint32_t OCNPolarity; /*!< Specifies the complementary output polarity.
  214. This parameter can be a value of @ref TIM_LL_EC_OCPOLARITY.
  215. This feature can be modified afterwards using unitary function
  216. @ref LL_TIM_OC_SetPolarity().*/
  217. uint32_t OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  218. This parameter can be a value of @ref TIM_LL_EC_OCIDLESTATE.
  219. This feature can be modified afterwards using unitary function
  220. @ref LL_TIM_OC_SetIdleState().*/
  221. uint32_t OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  222. This parameter can be a value of @ref TIM_LL_EC_OCIDLESTATE.
  223. This feature can be modified afterwards using unitary function
  224. @ref LL_TIM_OC_SetIdleState().*/
  225. } LL_TIM_OC_InitTypeDef;
  226. /**
  227. * @brief TIM Input Capture configuration structure definition.
  228. */
  229. typedef struct
  230. {
  231. uint32_t ICPolarity; /*!< Specifies the active edge of the input signal.
  232. This parameter can be a value of @ref TIM_LL_EC_IC_POLARITY.
  233. This feature can be modified afterwards using unitary function
  234. @ref LL_TIM_IC_SetPolarity().*/
  235. uint32_t ICActiveInput; /*!< Specifies the input.
  236. This parameter can be a value of @ref TIM_LL_EC_ACTIVEINPUT.
  237. This feature can be modified afterwards using unitary function
  238. @ref LL_TIM_IC_SetActiveInput().*/
  239. uint32_t ICPrescaler; /*!< Specifies the Input Capture Prescaler.
  240. This parameter can be a value of @ref TIM_LL_EC_ICPSC.
  241. This feature can be modified afterwards using unitary function
  242. @ref LL_TIM_IC_SetPrescaler().*/
  243. uint32_t ICFilter; /*!< Specifies the input capture filter.
  244. This parameter can be a value of @ref TIM_LL_EC_IC_FILTER.
  245. This feature can be modified afterwards using unitary function
  246. @ref LL_TIM_IC_SetFilter().*/
  247. } LL_TIM_IC_InitTypeDef;
  248. /**
  249. * @brief TIM Encoder interface configuration structure definition.
  250. */
  251. typedef struct
  252. {
  253. uint32_t EncoderMode; /*!< Specifies the encoder resolution (x2 or x4).
  254. This parameter can be a value of @ref TIM_LL_EC_ENCODERMODE.
  255. This feature can be modified afterwards using unitary function
  256. @ref LL_TIM_SetEncoderMode().*/
  257. uint32_t IC1Polarity; /*!< Specifies the active edge of TI1 input.
  258. This parameter can be a value of @ref TIM_LL_EC_IC_POLARITY.
  259. This feature can be modified afterwards using unitary function
  260. @ref LL_TIM_IC_SetPolarity().*/
  261. uint32_t IC1ActiveInput; /*!< Specifies the TI1 input source
  262. This parameter can be a value of @ref TIM_LL_EC_ACTIVEINPUT.
  263. This feature can be modified afterwards using unitary function
  264. @ref LL_TIM_IC_SetActiveInput().*/
  265. uint32_t IC1Prescaler; /*!< Specifies the TI1 input prescaler value.
  266. This parameter can be a value of @ref TIM_LL_EC_ICPSC.
  267. This feature can be modified afterwards using unitary function
  268. @ref LL_TIM_IC_SetPrescaler().*/
  269. uint32_t IC1Filter; /*!< Specifies the TI1 input filter.
  270. This parameter can be a value of @ref TIM_LL_EC_IC_FILTER.
  271. This feature can be modified afterwards using unitary function
  272. @ref LL_TIM_IC_SetFilter().*/
  273. uint32_t IC2Polarity; /*!< Specifies the active edge of TI2 input.
  274. This parameter can be a value of @ref TIM_LL_EC_IC_POLARITY.
  275. This feature can be modified afterwards using unitary function
  276. @ref LL_TIM_IC_SetPolarity().*/
  277. uint32_t IC2ActiveInput; /*!< Specifies the TI2 input source
  278. This parameter can be a value of @ref TIM_LL_EC_ACTIVEINPUT.
  279. This feature can be modified afterwards using unitary function
  280. @ref LL_TIM_IC_SetActiveInput().*/
  281. uint32_t IC2Prescaler; /*!< Specifies the TI2 input prescaler value.
  282. This parameter can be a value of @ref TIM_LL_EC_ICPSC.
  283. This feature can be modified afterwards using unitary function
  284. @ref LL_TIM_IC_SetPrescaler().*/
  285. uint32_t IC2Filter; /*!< Specifies the TI2 input filter.
  286. This parameter can be a value of @ref TIM_LL_EC_IC_FILTER.
  287. This feature can be modified afterwards using unitary function
  288. @ref LL_TIM_IC_SetFilter().*/
  289. } LL_TIM_ENCODER_InitTypeDef;
  290. /**
  291. * @brief TIM Hall sensor interface configuration structure definition.
  292. */
  293. typedef struct
  294. {
  295. uint32_t IC1Polarity; /*!< Specifies the active edge of TI1 input.
  296. This parameter can be a value of @ref TIM_LL_EC_IC_POLARITY.
  297. This feature can be modified afterwards using unitary function
  298. @ref LL_TIM_IC_SetPolarity().*/
  299. uint32_t IC1Prescaler; /*!< Specifies the TI1 input prescaler value.
  300. Prescaler must be set to get a maximum counter period longer than the
  301. time interval between 2 consecutive changes on the Hall inputs.
  302. This parameter can be a value of @ref TIM_LL_EC_ICPSC.
  303. This feature can be modified afterwards using unitary function
  304. @ref LL_TIM_IC_SetPrescaler().*/
  305. uint32_t IC1Filter; /*!< Specifies the TI1 input filter.
  306. This parameter can be a value of
  307. @ref TIM_LL_EC_IC_FILTER.
  308. This feature can be modified afterwards using unitary function
  309. @ref LL_TIM_IC_SetFilter().*/
  310. uint32_t CommutationDelay; /*!< Specifies the compare value to be loaded into the Capture Compare Register.
  311. A positive pulse (TRGO event) is generated with a programmable delay every time
  312. a change occurs on the Hall inputs.
  313. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF.
  314. This feature can be modified afterwards using unitary function
  315. @ref LL_TIM_OC_SetCompareCH2().*/
  316. } LL_TIM_HALLSENSOR_InitTypeDef;
  317. /**
  318. * @brief BDTR (Break and Dead Time) structure definition
  319. */
  320. typedef struct
  321. {
  322. uint32_t OSSRState; /*!< Specifies the Off-State selection used in Run mode.
  323. This parameter can be a value of @ref TIM_LL_EC_OSSR
  324. This feature can be modified afterwards using unitary function
  325. @ref LL_TIM_SetOffStates()
  326. @note This bit-field cannot be modified as long as LOCK level 2 has been
  327. programmed. */
  328. uint32_t OSSIState; /*!< Specifies the Off-State used in Idle state.
  329. This parameter can be a value of @ref TIM_LL_EC_OSSI
  330. This feature can be modified afterwards using unitary function
  331. @ref LL_TIM_SetOffStates()
  332. @note This bit-field cannot be modified as long as LOCK level 2 has been
  333. programmed. */
  334. uint32_t LockLevel; /*!< Specifies the LOCK level parameters.
  335. This parameter can be a value of @ref TIM_LL_EC_LOCKLEVEL
  336. @note The LOCK bits can be written only once after the reset. Once the TIMx_BDTR
  337. register has been written, their content is frozen until the next reset.*/
  338. uint8_t DeadTime; /*!< Specifies the delay time between the switching-off and the
  339. switching-on of the outputs.
  340. This parameter can be a number between Min_Data = 0x00 and Max_Data = 0xFF.
  341. This feature can be modified afterwards using unitary function
  342. @ref LL_TIM_OC_SetDeadTime()
  343. @note This bit-field can not be modified as long as LOCK level 1, 2 or 3 has been
  344. programmed. */
  345. uint16_t BreakState; /*!< Specifies whether the TIM Break input is enabled or not.
  346. This parameter can be a value of @ref TIM_LL_EC_BREAK_ENABLE
  347. This feature can be modified afterwards using unitary functions
  348. @ref LL_TIM_EnableBRK() or @ref LL_TIM_DisableBRK()
  349. @note This bit-field can not be modified as long as LOCK level 1 has been
  350. programmed. */
  351. uint32_t BreakPolarity; /*!< Specifies the TIM Break Input pin polarity.
  352. This parameter can be a value of @ref TIM_LL_EC_BREAK_POLARITY
  353. This feature can be modified afterwards using unitary function
  354. @ref LL_TIM_ConfigBRK()
  355. @note This bit-field can not be modified as long as LOCK level 1 has been
  356. programmed. */
  357. uint32_t AutomaticOutput; /*!< Specifies whether the TIM Automatic Output feature is enabled or not.
  358. This parameter can be a value of @ref TIM_LL_EC_AUTOMATICOUTPUT_ENABLE
  359. This feature can be modified afterwards using unitary functions
  360. @ref LL_TIM_EnableAutomaticOutput() or @ref LL_TIM_DisableAutomaticOutput()
  361. @note This bit-field can not be modified as long as LOCK level 1 has been
  362. programmed. */
  363. } LL_TIM_BDTR_InitTypeDef;
  364. /**
  365. * @}
  366. */
  367. #endif /* USE_FULL_LL_DRIVER */
  368. /* Exported constants --------------------------------------------------------*/
  369. /** @defgroup TIM_LL_Exported_Constants TIM Exported Constants
  370. * @{
  371. */
  372. /** @defgroup TIM_LL_EC_GET_FLAG Get Flags Defines
  373. * @brief Flags defines which can be used with LL_TIM_ReadReg function.
  374. * @{
  375. */
  376. #define LL_TIM_SR_UIF TIM_SR_UIF /*!< Update interrupt flag */
  377. #define LL_TIM_SR_CC1IF TIM_SR_CC1IF /*!< Capture/compare 1 interrupt flag */
  378. #define LL_TIM_SR_CC2IF TIM_SR_CC2IF /*!< Capture/compare 2 interrupt flag */
  379. #define LL_TIM_SR_CC3IF TIM_SR_CC3IF /*!< Capture/compare 3 interrupt flag */
  380. #define LL_TIM_SR_CC4IF TIM_SR_CC4IF /*!< Capture/compare 4 interrupt flag */
  381. #define LL_TIM_SR_COMIF TIM_SR_COMIF /*!< COM interrupt flag */
  382. #define LL_TIM_SR_TIF TIM_SR_TIF /*!< Trigger interrupt flag */
  383. #define LL_TIM_SR_BIF TIM_SR_BIF /*!< Break interrupt flag */
  384. #define LL_TIM_SR_CC1OF TIM_SR_CC1OF /*!< Capture/Compare 1 overcapture flag */
  385. #define LL_TIM_SR_CC2OF TIM_SR_CC2OF /*!< Capture/Compare 2 overcapture flag */
  386. #define LL_TIM_SR_CC3OF TIM_SR_CC3OF /*!< Capture/Compare 3 overcapture flag */
  387. #define LL_TIM_SR_CC4OF TIM_SR_CC4OF /*!< Capture/Compare 4 overcapture flag */
  388. /**
  389. * @}
  390. */
  391. #if defined(USE_FULL_LL_DRIVER)
  392. /** @defgroup TIM_LL_EC_BREAK_ENABLE Break Enable
  393. * @{
  394. */
  395. #define LL_TIM_BREAK_DISABLE 0x00000000U /*!< Break function disabled */
  396. #define LL_TIM_BREAK_ENABLE TIM_BDTR_BKE /*!< Break function enabled */
  397. /**
  398. * @}
  399. */
  400. /** @defgroup TIM_LL_EC_AUTOMATICOUTPUT_ENABLE Automatic output enable
  401. * @{
  402. */
  403. #define LL_TIM_AUTOMATICOUTPUT_DISABLE 0x00000000U /*!< MOE can be set only by software */
  404. #define LL_TIM_AUTOMATICOUTPUT_ENABLE TIM_BDTR_AOE /*!< MOE can be set by software or automatically at the next update event */
  405. /**
  406. * @}
  407. */
  408. #endif /* USE_FULL_LL_DRIVER */
  409. /** @defgroup TIM_LL_EC_IT IT Defines
  410. * @brief IT defines which can be used with LL_TIM_ReadReg and LL_TIM_WriteReg functions.
  411. * @{
  412. */
  413. #define LL_TIM_DIER_UIE TIM_DIER_UIE /*!< Update interrupt enable */
  414. #define LL_TIM_DIER_CC1IE TIM_DIER_CC1IE /*!< Capture/compare 1 interrupt enable */
  415. #define LL_TIM_DIER_CC2IE TIM_DIER_CC2IE /*!< Capture/compare 2 interrupt enable */
  416. #define LL_TIM_DIER_CC3IE TIM_DIER_CC3IE /*!< Capture/compare 3 interrupt enable */
  417. #define LL_TIM_DIER_CC4IE TIM_DIER_CC4IE /*!< Capture/compare 4 interrupt enable */
  418. #define LL_TIM_DIER_COMIE TIM_DIER_COMIE /*!< COM interrupt enable */
  419. #define LL_TIM_DIER_TIE TIM_DIER_TIE /*!< Trigger interrupt enable */
  420. #define LL_TIM_DIER_BIE TIM_DIER_BIE /*!< Break interrupt enable */
  421. /**
  422. * @}
  423. */
  424. /** @defgroup TIM_LL_EC_UPDATESOURCE Update Source
  425. * @{
  426. */
  427. #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 */
  428. #define LL_TIM_UPDATESOURCE_COUNTER TIM_CR1_URS /*!< Only counter overflow/underflow generates an update request */
  429. /**
  430. * @}
  431. */
  432. /** @defgroup TIM_LL_EC_ONEPULSEMODE One Pulse Mode
  433. * @{
  434. */
  435. #define LL_TIM_ONEPULSEMODE_SINGLE TIM_CR1_OPM /*!< Counter stops counting at the next update event */
  436. #define LL_TIM_ONEPULSEMODE_REPETITIVE 0x00000000U /*!< Counter is not stopped at update event */
  437. /**
  438. * @}
  439. */
  440. /** @defgroup TIM_LL_EC_COUNTERMODE Counter Mode
  441. * @{
  442. */
  443. #define LL_TIM_COUNTERMODE_UP 0x00000000U /*!<Counter used as upcounter */
  444. #define LL_TIM_COUNTERMODE_DOWN TIM_CR1_DIR /*!< Counter used as downcounter */
  445. #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. */
  446. #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 */
  447. #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. */
  448. /**
  449. * @}
  450. */
  451. /** @defgroup TIM_LL_EC_CLOCKDIVISION Clock Division
  452. * @{
  453. */
  454. #define LL_TIM_CLOCKDIVISION_DIV1 0x00000000U /*!< tDTS=tCK_INT */
  455. #define LL_TIM_CLOCKDIVISION_DIV2 TIM_CR1_CKD_0 /*!< tDTS=2*tCK_INT */
  456. #define LL_TIM_CLOCKDIVISION_DIV4 TIM_CR1_CKD_1 /*!< tDTS=4*tCK_INT */
  457. /**
  458. * @}
  459. */
  460. /** @defgroup TIM_LL_EC_COUNTERDIRECTION Counter Direction
  461. * @{
  462. */
  463. #define LL_TIM_COUNTERDIRECTION_UP 0x00000000U /*!< Timer counter counts up */
  464. #define LL_TIM_COUNTERDIRECTION_DOWN TIM_CR1_DIR /*!< Timer counter counts down */
  465. /**
  466. * @}
  467. */
  468. /** @defgroup TIM_LL_EC_CCUPDATESOURCE Capture Compare Update Source
  469. * @{
  470. */
  471. #define LL_TIM_CCUPDATESOURCE_COMG_ONLY 0x00000000U /*!< Capture/compare control bits are updated by setting the COMG bit only */
  472. #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) */
  473. /**
  474. * @}
  475. */
  476. /** @defgroup TIM_LL_EC_CCDMAREQUEST Capture Compare DMA Request
  477. * @{
  478. */
  479. #define LL_TIM_CCDMAREQUEST_CC 0x00000000U /*!< CCx DMA request sent when CCx event occurs */
  480. #define LL_TIM_CCDMAREQUEST_UPDATE TIM_CR2_CCDS /*!< CCx DMA requests sent when update event occurs */
  481. /**
  482. * @}
  483. */
  484. /** @defgroup TIM_LL_EC_LOCKLEVEL Lock Level
  485. * @{
  486. */
  487. #define LL_TIM_LOCKLEVEL_OFF 0x00000000U /*!< LOCK OFF - No bit is write protected */
  488. #define LL_TIM_LOCKLEVEL_1 TIM_BDTR_LOCK_0 /*!< LOCK Level 1 */
  489. #define LL_TIM_LOCKLEVEL_2 TIM_BDTR_LOCK_1 /*!< LOCK Level 2 */
  490. #define LL_TIM_LOCKLEVEL_3 TIM_BDTR_LOCK /*!< LOCK Level 3 */
  491. /**
  492. * @}
  493. */
  494. /** @defgroup TIM_LL_EC_CHANNEL Channel
  495. * @{
  496. */
  497. #define LL_TIM_CHANNEL_CH1 TIM_CCER_CC1E /*!< Timer input/output channel 1 */
  498. #define LL_TIM_CHANNEL_CH1N TIM_CCER_CC1NE /*!< Timer complementary output channel 1 */
  499. #define LL_TIM_CHANNEL_CH2 TIM_CCER_CC2E /*!< Timer input/output channel 2 */
  500. #define LL_TIM_CHANNEL_CH2N TIM_CCER_CC2NE /*!< Timer complementary output channel 2 */
  501. #define LL_TIM_CHANNEL_CH3 TIM_CCER_CC3E /*!< Timer input/output channel 3 */
  502. #define LL_TIM_CHANNEL_CH3N TIM_CCER_CC3NE /*!< Timer complementary output channel 3 */
  503. #define LL_TIM_CHANNEL_CH4 TIM_CCER_CC4E /*!< Timer input/output channel 4 */
  504. /**
  505. * @}
  506. */
  507. #if defined(USE_FULL_LL_DRIVER)
  508. /** @defgroup TIM_LL_EC_OCSTATE Output Configuration State
  509. * @{
  510. */
  511. #define LL_TIM_OCSTATE_DISABLE 0x00000000U /*!< OCx is not active */
  512. #define LL_TIM_OCSTATE_ENABLE TIM_CCER_CC1E /*!< OCx signal is output on the corresponding output pin */
  513. /**
  514. * @}
  515. */
  516. #endif /* USE_FULL_LL_DRIVER */
  517. /** @defgroup TIM_LL_EC_OCMODE Output Configuration Mode
  518. * @{
  519. */
  520. #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 */
  521. #define LL_TIM_OCMODE_ACTIVE TIM_CCMR1_OC1M_0 /*!<OCyREF is forced high on compare match*/
  522. #define LL_TIM_OCMODE_INACTIVE TIM_CCMR1_OC1M_1 /*!<OCyREF is forced low on compare match*/
  523. #define LL_TIM_OCMODE_TOGGLE (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0) /*!<OCyREF toggles on compare match*/
  524. #define LL_TIM_OCMODE_FORCED_INACTIVE TIM_CCMR1_OC1M_2 /*!<OCyREF is forced low*/
  525. #define LL_TIM_OCMODE_FORCED_ACTIVE (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_0) /*!<OCyREF is forced high*/
  526. #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.*/
  527. #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*/
  528. /**
  529. * @}
  530. */
  531. /** @defgroup TIM_LL_EC_OCPOLARITY Output Configuration Polarity
  532. * @{
  533. */
  534. #define LL_TIM_OCPOLARITY_HIGH 0x00000000U /*!< OCxactive high*/
  535. #define LL_TIM_OCPOLARITY_LOW TIM_CCER_CC1P /*!< OCxactive low*/
  536. /**
  537. * @}
  538. */
  539. /** @defgroup TIM_LL_EC_OCIDLESTATE Output Configuration Idle State
  540. * @{
  541. */
  542. #define LL_TIM_OCIDLESTATE_LOW 0x00000000U /*!<OCx=0 (after a dead-time if OC is implemented) when MOE=0*/
  543. #define LL_TIM_OCIDLESTATE_HIGH TIM_CR2_OIS1 /*!<OCx=1 (after a dead-time if OC is implemented) when MOE=0*/
  544. /**
  545. * @}
  546. */
  547. /** @defgroup TIM_LL_EC_ACTIVEINPUT Active Input Selection
  548. * @{
  549. */
  550. #define LL_TIM_ACTIVEINPUT_DIRECTTI (TIM_CCMR1_CC1S_0 << 16U) /*!< ICx is mapped on TIx */
  551. #define LL_TIM_ACTIVEINPUT_INDIRECTTI (TIM_CCMR1_CC1S_1 << 16U) /*!< ICx is mapped on TIy */
  552. #define LL_TIM_ACTIVEINPUT_TRC (TIM_CCMR1_CC1S << 16U) /*!< ICx is mapped on TRC */
  553. /**
  554. * @}
  555. */
  556. /** @defgroup TIM_LL_EC_ICPSC Input Configuration Prescaler
  557. * @{
  558. */
  559. #define LL_TIM_ICPSC_DIV1 0x00000000U /*!< No prescaler, capture is done each time an edge is detected on the capture input */
  560. #define LL_TIM_ICPSC_DIV2 (TIM_CCMR1_IC1PSC_0 << 16U) /*!< Capture is done once every 2 events */
  561. #define LL_TIM_ICPSC_DIV4 (TIM_CCMR1_IC1PSC_1 << 16U) /*!< Capture is done once every 4 events */
  562. #define LL_TIM_ICPSC_DIV8 (TIM_CCMR1_IC1PSC << 16U) /*!< Capture is done once every 8 events */
  563. /**
  564. * @}
  565. */
  566. /** @defgroup TIM_LL_EC_IC_FILTER Input Configuration Filter
  567. * @{
  568. */
  569. #define LL_TIM_IC_FILTER_FDIV1 0x00000000U /*!< No filter, sampling is done at fDTS */
  570. #define LL_TIM_IC_FILTER_FDIV1_N2 (TIM_CCMR1_IC1F_0 << 16U) /*!< fSAMPLING=fCK_INT, N=2 */
  571. #define LL_TIM_IC_FILTER_FDIV1_N4 (TIM_CCMR1_IC1F_1 << 16U) /*!< fSAMPLING=fCK_INT, N=4 */
  572. #define LL_TIM_IC_FILTER_FDIV1_N8 ((TIM_CCMR1_IC1F_1 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fCK_INT, N=8 */
  573. #define LL_TIM_IC_FILTER_FDIV2_N6 (TIM_CCMR1_IC1F_2 << 16U) /*!< fSAMPLING=fDTS/2, N=6 */
  574. #define LL_TIM_IC_FILTER_FDIV2_N8 ((TIM_CCMR1_IC1F_2 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fDTS/2, N=8 */
  575. #define LL_TIM_IC_FILTER_FDIV4_N6 ((TIM_CCMR1_IC1F_2 | TIM_CCMR1_IC1F_1) << 16U) /*!< fSAMPLING=fDTS/4, N=6 */
  576. #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 */
  577. #define LL_TIM_IC_FILTER_FDIV8_N6 (TIM_CCMR1_IC1F_3 << 16U) /*!< fSAMPLING=fDTS/8, N=6 */
  578. #define LL_TIM_IC_FILTER_FDIV8_N8 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fDTS/8, N=8 */
  579. #define LL_TIM_IC_FILTER_FDIV16_N5 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_1) << 16U) /*!< fSAMPLING=fDTS/16, N=5 */
  580. #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 */
  581. #define LL_TIM_IC_FILTER_FDIV16_N8 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_2) << 16U) /*!< fSAMPLING=fDTS/16, N=8 */
  582. #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 */
  583. #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 */
  584. #define LL_TIM_IC_FILTER_FDIV32_N8 (TIM_CCMR1_IC1F << 16U) /*!< fSAMPLING=fDTS/32, N=8 */
  585. /**
  586. * @}
  587. */
  588. /** @defgroup TIM_LL_EC_IC_POLARITY Input Configuration Polarity
  589. * @{
  590. */
  591. #define LL_TIM_IC_POLARITY_RISING 0x00000000U /*!< The circuit is sensitive to TIxFP1 rising edge, TIxFP1 is not inverted */
  592. #define LL_TIM_IC_POLARITY_FALLING TIM_CCER_CC1P /*!< The circuit is sensitive to TIxFP1 falling edge, TIxFP1 is inverted */
  593. /**
  594. * @}
  595. */
  596. /** @defgroup TIM_LL_EC_CLOCKSOURCE Clock Source
  597. * @{
  598. */
  599. #define LL_TIM_CLOCKSOURCE_INTERNAL 0x00000000U /*!< The timer is clocked by the internal clock provided from the RCC */
  600. #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*/
  601. #define LL_TIM_CLOCKSOURCE_EXT_MODE2 TIM_SMCR_ECE /*!< Counter counts at each rising or falling edge on the external trigger input ETR */
  602. /**
  603. * @}
  604. */
  605. /** @defgroup TIM_LL_EC_ENCODERMODE Encoder Mode
  606. * @{
  607. */
  608. #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 */
  609. #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 */
  610. #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 */
  611. /**
  612. * @}
  613. */
  614. /** @defgroup TIM_LL_EC_TRGO Trigger Output
  615. * @{
  616. */
  617. #define LL_TIM_TRGO_RESET 0x00000000U /*!< UG bit from the TIMx_EGR register is used as trigger output */
  618. #define LL_TIM_TRGO_ENABLE TIM_CR2_MMS_0 /*!< Counter Enable signal (CNT_EN) is used as trigger output */
  619. #define LL_TIM_TRGO_UPDATE TIM_CR2_MMS_1 /*!< Update event is used as trigger output */
  620. #define LL_TIM_TRGO_CC1IF (TIM_CR2_MMS_1 | TIM_CR2_MMS_0) /*!< CC1 capture or a compare match is used as trigger output */
  621. #define LL_TIM_TRGO_OC1REF TIM_CR2_MMS_2 /*!< OC1REF signal is used as trigger output */
  622. #define LL_TIM_TRGO_OC2REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_0) /*!< OC2REF signal is used as trigger output */
  623. #define LL_TIM_TRGO_OC3REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_1) /*!< OC3REF signal is used as trigger output */
  624. #define LL_TIM_TRGO_OC4REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_1 | TIM_CR2_MMS_0) /*!< OC4REF signal is used as trigger output */
  625. /**
  626. * @}
  627. */
  628. /** @defgroup TIM_LL_EC_SLAVEMODE Slave Mode
  629. * @{
  630. */
  631. #define LL_TIM_SLAVEMODE_DISABLED 0x00000000U /*!< Slave mode disabled */
  632. #define LL_TIM_SLAVEMODE_RESET TIM_SMCR_SMS_2 /*!< Reset Mode - Rising edge of the selected trigger input (TRGI) reinitializes the counter */
  633. #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 */
  634. #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 */
  635. /**
  636. * @}
  637. */
  638. /** @defgroup TIM_LL_EC_TS Trigger Selection
  639. * @{
  640. */
  641. #define LL_TIM_TS_ITR0 0x00000000U /*!< Internal Trigger 0 (ITR0) is used as trigger input */
  642. #define LL_TIM_TS_ITR1 TIM_SMCR_TS_0 /*!< Internal Trigger 1 (ITR1) is used as trigger input */
  643. #define LL_TIM_TS_ITR2 TIM_SMCR_TS_1 /*!< Internal Trigger 2 (ITR2) is used as trigger input */
  644. #define LL_TIM_TS_ITR3 (TIM_SMCR_TS_0 | TIM_SMCR_TS_1) /*!< Internal Trigger 3 (ITR3) is used as trigger input */
  645. #define LL_TIM_TS_TI1F_ED TIM_SMCR_TS_2 /*!< TI1 Edge Detector (TI1F_ED) is used as trigger input */
  646. #define LL_TIM_TS_TI1FP1 (TIM_SMCR_TS_2 | TIM_SMCR_TS_0) /*!< Filtered Timer Input 1 (TI1FP1) is used as trigger input */
  647. #define LL_TIM_TS_TI2FP2 (TIM_SMCR_TS_2 | TIM_SMCR_TS_1) /*!< Filtered Timer Input 2 (TI12P2) is used as trigger input */
  648. #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 */
  649. /**
  650. * @}
  651. */
  652. /** @defgroup TIM_LL_EC_ETR_POLARITY External Trigger Polarity
  653. * @{
  654. */
  655. #define LL_TIM_ETR_POLARITY_NONINVERTED 0x00000000U /*!< ETR is non-inverted, active at high level or rising edge */
  656. #define LL_TIM_ETR_POLARITY_INVERTED TIM_SMCR_ETP /*!< ETR is inverted, active at low level or falling edge */
  657. /**
  658. * @}
  659. */
  660. /** @defgroup TIM_LL_EC_ETR_PRESCALER External Trigger Prescaler
  661. * @{
  662. */
  663. #define LL_TIM_ETR_PRESCALER_DIV1 0x00000000U /*!< ETR prescaler OFF */
  664. #define LL_TIM_ETR_PRESCALER_DIV2 TIM_SMCR_ETPS_0 /*!< ETR frequency is divided by 2 */
  665. #define LL_TIM_ETR_PRESCALER_DIV4 TIM_SMCR_ETPS_1 /*!< ETR frequency is divided by 4 */
  666. #define LL_TIM_ETR_PRESCALER_DIV8 TIM_SMCR_ETPS /*!< ETR frequency is divided by 8 */
  667. /**
  668. * @}
  669. */
  670. /** @defgroup TIM_LL_EC_ETR_FILTER External Trigger Filter
  671. * @{
  672. */
  673. #define LL_TIM_ETR_FILTER_FDIV1 0x00000000U /*!< No filter, sampling is done at fDTS */
  674. #define LL_TIM_ETR_FILTER_FDIV1_N2 TIM_SMCR_ETF_0 /*!< fSAMPLING=fCK_INT, N=2 */
  675. #define LL_TIM_ETR_FILTER_FDIV1_N4 TIM_SMCR_ETF_1 /*!< fSAMPLING=fCK_INT, N=4 */
  676. #define LL_TIM_ETR_FILTER_FDIV1_N8 (TIM_SMCR_ETF_1 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fCK_INT, N=8 */
  677. #define LL_TIM_ETR_FILTER_FDIV2_N6 TIM_SMCR_ETF_2 /*!< fSAMPLING=fDTS/2, N=6 */
  678. #define LL_TIM_ETR_FILTER_FDIV2_N8 (TIM_SMCR_ETF_2 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/2, N=8 */
  679. #define LL_TIM_ETR_FILTER_FDIV4_N6 (TIM_SMCR_ETF_2 | TIM_SMCR_ETF_1) /*!< fSAMPLING=fDTS/4, N=6 */
  680. #define LL_TIM_ETR_FILTER_FDIV4_N8 (TIM_SMCR_ETF_2 | TIM_SMCR_ETF_1 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/4, N=8 */
  681. #define LL_TIM_ETR_FILTER_FDIV8_N6 TIM_SMCR_ETF_3 /*!< fSAMPLING=fDTS/8, N=8 */
  682. #define LL_TIM_ETR_FILTER_FDIV8_N8 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/16, N=5 */
  683. #define LL_TIM_ETR_FILTER_FDIV16_N5 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_1) /*!< fSAMPLING=fDTS/16, N=6 */
  684. #define LL_TIM_ETR_FILTER_FDIV16_N6 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_1 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/16, N=8 */
  685. #define LL_TIM_ETR_FILTER_FDIV16_N8 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_2) /*!< fSAMPLING=fDTS/16, N=5 */
  686. #define LL_TIM_ETR_FILTER_FDIV32_N5 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_2 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/32, N=5 */
  687. #define LL_TIM_ETR_FILTER_FDIV32_N6 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_2 | TIM_SMCR_ETF_1) /*!< fSAMPLING=fDTS/32, N=6 */
  688. #define LL_TIM_ETR_FILTER_FDIV32_N8 TIM_SMCR_ETF /*!< fSAMPLING=fDTS/32, N=8 */
  689. /**
  690. * @}
  691. */
  692. /** @defgroup TIM_LL_EC_BREAK_POLARITY break polarity
  693. * @{
  694. */
  695. #define LL_TIM_BREAK_POLARITY_LOW 0x00000000U /*!< Break input BRK is active low */
  696. #define LL_TIM_BREAK_POLARITY_HIGH TIM_BDTR_BKP /*!< Break input BRK is active high */
  697. /**
  698. * @}
  699. */
  700. /** @defgroup TIM_LL_EC_OSSI OSSI
  701. * @{
  702. */
  703. #define LL_TIM_OSSI_DISABLE 0x00000000U /*!< When inactive, OCx/OCxN outputs are disabled */
  704. #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 */
  705. /**
  706. * @}
  707. */
  708. /** @defgroup TIM_LL_EC_OSSR OSSR
  709. * @{
  710. */
  711. #define LL_TIM_OSSR_DISABLE 0x00000000U /*!< When inactive, OCx/OCxN outputs are disabled */
  712. #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 */
  713. /**
  714. * @}
  715. */
  716. /** @defgroup TIM_LL_EC_DMABURST_BASEADDR DMA Burst Base Address
  717. * @{
  718. */
  719. #define LL_TIM_DMABURST_BASEADDR_CR1 0x00000000U /*!< TIMx_CR1 register is the DMA base address for DMA burst */
  720. #define LL_TIM_DMABURST_BASEADDR_CR2 TIM_DCR_DBA_0 /*!< TIMx_CR2 register is the DMA base address for DMA burst */
  721. #define LL_TIM_DMABURST_BASEADDR_SMCR TIM_DCR_DBA_1 /*!< TIMx_SMCR register is the DMA base address for DMA burst */
  722. #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 */
  723. #define LL_TIM_DMABURST_BASEADDR_SR TIM_DCR_DBA_2 /*!< TIMx_SR register is the DMA base address for DMA burst */
  724. #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 */
  725. #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 */
  726. #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 */
  727. #define LL_TIM_DMABURST_BASEADDR_CCER TIM_DCR_DBA_3 /*!< TIMx_CCER register is the DMA base address for DMA burst */
  728. #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 */
  729. #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 */
  730. #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 */
  731. #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 */
  732. #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 */
  733. #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 */
  734. #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 */
  735. #define LL_TIM_DMABURST_BASEADDR_CCR4 TIM_DCR_DBA_4 /*!< TIMx_CCR4 register is the DMA base address for DMA burst */
  736. #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 */
  737. /**
  738. * @}
  739. */
  740. /** @defgroup TIM_LL_EC_DMABURST_LENGTH DMA Burst Length
  741. * @{
  742. */
  743. #define LL_TIM_DMABURST_LENGTH_1TRANSFER 0x00000000U /*!< Transfer is done to 1 register starting from the DMA burst base address */
  744. #define LL_TIM_DMABURST_LENGTH_2TRANSFERS TIM_DCR_DBL_0 /*!< Transfer is done to 2 registers starting from the DMA burst base address */
  745. #define LL_TIM_DMABURST_LENGTH_3TRANSFERS TIM_DCR_DBL_1 /*!< Transfer is done to 3 registers starting from the DMA burst base address */
  746. #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 */
  747. #define LL_TIM_DMABURST_LENGTH_5TRANSFERS TIM_DCR_DBL_2 /*!< Transfer is done to 5 registers starting from the DMA burst base address */
  748. #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 */
  749. #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 */
  750. #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 */
  751. #define LL_TIM_DMABURST_LENGTH_9TRANSFERS TIM_DCR_DBL_3 /*!< Transfer is done to 9 registers starting from the DMA burst base address */
  752. #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 */
  753. #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 */
  754. #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 */
  755. #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 */
  756. #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 */
  757. #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 */
  758. #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 */
  759. #define LL_TIM_DMABURST_LENGTH_17TRANSFERS TIM_DCR_DBL_4 /*!< Transfer is done to 17 registers starting from the DMA burst base address */
  760. #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 */
  761. /**
  762. * @}
  763. */
  764. /**
  765. * @}
  766. */
  767. /* Exported macro ------------------------------------------------------------*/
  768. /** @defgroup TIM_LL_Exported_Macros TIM Exported Macros
  769. * @{
  770. */
  771. /** @defgroup TIM_LL_EM_WRITE_READ Common Write and read registers Macros
  772. * @{
  773. */
  774. /**
  775. * @brief Write a value in TIM register.
  776. * @param __INSTANCE__ TIM Instance
  777. * @param __REG__ Register to be written
  778. * @param __VALUE__ Value to be written in the register
  779. * @retval None
  780. */
  781. #define LL_TIM_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
  782. /**
  783. * @brief Read a value in TIM register.
  784. * @param __INSTANCE__ TIM Instance
  785. * @param __REG__ Register to be read
  786. * @retval Register value
  787. */
  788. #define LL_TIM_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
  789. /**
  790. * @}
  791. */
  792. /** @defgroup TIM_LL_EM_Exported_Macros Exported_Macros
  793. * @{
  794. */
  795. /**
  796. * @brief HELPER macro calculating DTG[0:7] in the TIMx_BDTR register to achieve the requested dead time duration.
  797. * @note ex: @ref __LL_TIM_CALC_DEADTIME (80000000, @ref LL_TIM_GetClockDivision (), 120);
  798. * @param __TIMCLK__ timer input clock frequency (in Hz)
  799. * @param __CKD__ This parameter can be one of the following values:
  800. * @arg @ref LL_TIM_CLOCKDIVISION_DIV1
  801. * @arg @ref LL_TIM_CLOCKDIVISION_DIV2
  802. * @arg @ref LL_TIM_CLOCKDIVISION_DIV4
  803. * @param __DT__ deadtime duration (in ns)
  804. * @retval DTG[0:7]
  805. */
  806. #define __LL_TIM_CALC_DEADTIME(__TIMCLK__, __CKD__, __DT__) \
  807. ( (((uint64_t)((__DT__)*1000U)) < ((DT_DELAY_1+1U) * TIM_CALC_DTS((__TIMCLK__), (__CKD__)))) ? \
  808. (uint8_t)(((uint64_t)((__DT__)*1000U) / TIM_CALC_DTS((__TIMCLK__), (__CKD__))) & DT_DELAY_1) : \
  809. (((uint64_t)((__DT__)*1000U)) < ((64U + (DT_DELAY_2+1U)) * 2U * TIM_CALC_DTS((__TIMCLK__), (__CKD__)))) ? \
  810. (uint8_t)(DT_RANGE_2 | ((uint8_t)((uint8_t)((((uint64_t)((__DT__)*1000U))/ TIM_CALC_DTS((__TIMCLK__), \
  811. (__CKD__))) >> 1U) - (uint8_t) 64) & DT_DELAY_2)) :\
  812. (((uint64_t)((__DT__)*1000U)) < ((32U + (DT_DELAY_3+1U)) * 8U * TIM_CALC_DTS((__TIMCLK__), (__CKD__)))) ? \
  813. (uint8_t)(DT_RANGE_3 | ((uint8_t)((uint8_t)(((((uint64_t)(__DT__)*1000U))/ TIM_CALC_DTS((__TIMCLK__), \
  814. (__CKD__))) >> 3U) - (uint8_t) 32) & DT_DELAY_3)) :\
  815. (((uint64_t)((__DT__)*1000U)) < ((32U + (DT_DELAY_4+1U)) * 16U * TIM_CALC_DTS((__TIMCLK__), (__CKD__)))) ? \
  816. (uint8_t)(DT_RANGE_4 | ((uint8_t)((uint8_t)(((((uint64_t)(__DT__)*1000U))/ TIM_CALC_DTS((__TIMCLK__), \
  817. (__CKD__))) >> 4U) - (uint8_t) 32) & DT_DELAY_4)) :\
  818. 0U)
  819. /**
  820. * @brief HELPER macro calculating the prescaler value to achieve the required counter clock frequency.
  821. * @note ex: @ref __LL_TIM_CALC_PSC (80000000, 1000000);
  822. * @param __TIMCLK__ timer input clock frequency (in Hz)
  823. * @param __CNTCLK__ counter clock frequency (in Hz)
  824. * @retval Prescaler value (between Min_Data=0 and Max_Data=65535)
  825. */
  826. #define __LL_TIM_CALC_PSC(__TIMCLK__, __CNTCLK__) \
  827. (((__TIMCLK__) >= (__CNTCLK__)) ? (uint32_t)(((__TIMCLK__)/(__CNTCLK__)) - 1U) : 0U)
  828. /**
  829. * @brief HELPER macro calculating the auto-reload value to achieve the required output signal frequency.
  830. * @note ex: @ref __LL_TIM_CALC_ARR (1000000, @ref LL_TIM_GetPrescaler (), 10000);
  831. * @param __TIMCLK__ timer input clock frequency (in Hz)
  832. * @param __PSC__ prescaler
  833. * @param __FREQ__ output signal frequency (in Hz)
  834. * @retval Auto-reload value (between Min_Data=0 and Max_Data=65535)
  835. */
  836. #define __LL_TIM_CALC_ARR(__TIMCLK__, __PSC__, __FREQ__) \
  837. ((((__TIMCLK__)/((__PSC__) + 1U)) >= (__FREQ__)) ? (((__TIMCLK__)/((__FREQ__) * ((__PSC__) + 1U))) - 1U) : 0U)
  838. /**
  839. * @brief HELPER macro calculating the compare value required to achieve the required timer output compare
  840. * active/inactive delay.
  841. * @note ex: @ref __LL_TIM_CALC_DELAY (1000000, @ref LL_TIM_GetPrescaler (), 10);
  842. * @param __TIMCLK__ timer input clock frequency (in Hz)
  843. * @param __PSC__ prescaler
  844. * @param __DELAY__ timer output compare active/inactive delay (in us)
  845. * @retval Compare value (between Min_Data=0 and Max_Data=65535)
  846. */
  847. #define __LL_TIM_CALC_DELAY(__TIMCLK__, __PSC__, __DELAY__) \
  848. ((uint32_t)(((uint64_t)(__TIMCLK__) * (uint64_t)(__DELAY__)) \
  849. / ((uint64_t)1000000U * (uint64_t)((__PSC__) + 1U))))
  850. /**
  851. * @brief HELPER macro calculating the auto-reload value to achieve the required pulse duration
  852. * (when the timer operates in one pulse mode).
  853. * @note ex: @ref __LL_TIM_CALC_PULSE (1000000, @ref LL_TIM_GetPrescaler (), 10, 20);
  854. * @param __TIMCLK__ timer input clock frequency (in Hz)
  855. * @param __PSC__ prescaler
  856. * @param __DELAY__ timer output compare active/inactive delay (in us)
  857. * @param __PULSE__ pulse duration (in us)
  858. * @retval Auto-reload value (between Min_Data=0 and Max_Data=65535)
  859. */
  860. #define __LL_TIM_CALC_PULSE(__TIMCLK__, __PSC__, __DELAY__, __PULSE__) \
  861. ((uint32_t)(__LL_TIM_CALC_DELAY((__TIMCLK__), (__PSC__), (__PULSE__)) \
  862. + __LL_TIM_CALC_DELAY((__TIMCLK__), (__PSC__), (__DELAY__))))
  863. /**
  864. * @brief HELPER macro retrieving the ratio of the input capture prescaler
  865. * @note ex: @ref __LL_TIM_GET_ICPSC_RATIO (@ref LL_TIM_IC_GetPrescaler ());
  866. * @param __ICPSC__ This parameter can be one of the following values:
  867. * @arg @ref LL_TIM_ICPSC_DIV1
  868. * @arg @ref LL_TIM_ICPSC_DIV2
  869. * @arg @ref LL_TIM_ICPSC_DIV4
  870. * @arg @ref LL_TIM_ICPSC_DIV8
  871. * @retval Input capture prescaler ratio (1, 2, 4 or 8)
  872. */
  873. #define __LL_TIM_GET_ICPSC_RATIO(__ICPSC__) \
  874. ((uint32_t)(0x01U << (((__ICPSC__) >> 16U) >> TIM_CCMR1_IC1PSC_Pos)))
  875. /**
  876. * @}
  877. */
  878. /**
  879. * @}
  880. */
  881. /* Exported functions --------------------------------------------------------*/
  882. /** @defgroup TIM_LL_Exported_Functions TIM Exported Functions
  883. * @{
  884. */
  885. /** @defgroup TIM_LL_EF_Time_Base Time Base configuration
  886. * @{
  887. */
  888. /**
  889. * @brief Enable timer counter.
  890. * @rmtoll CR1 CEN LL_TIM_EnableCounter
  891. * @param TIMx Timer instance
  892. * @retval None
  893. */
  894. __STATIC_INLINE void LL_TIM_EnableCounter(TIM_TypeDef *TIMx)
  895. {
  896. SET_BIT(TIMx->CR1, TIM_CR1_CEN);
  897. }
  898. /**
  899. * @brief Disable timer counter.
  900. * @rmtoll CR1 CEN LL_TIM_DisableCounter
  901. * @param TIMx Timer instance
  902. * @retval None
  903. */
  904. __STATIC_INLINE void LL_TIM_DisableCounter(TIM_TypeDef *TIMx)
  905. {
  906. CLEAR_BIT(TIMx->CR1, TIM_CR1_CEN);
  907. }
  908. /**
  909. * @brief Indicates whether the timer counter is enabled.
  910. * @rmtoll CR1 CEN LL_TIM_IsEnabledCounter
  911. * @param TIMx Timer instance
  912. * @retval State of bit (1 or 0).
  913. */
  914. __STATIC_INLINE uint32_t LL_TIM_IsEnabledCounter(TIM_TypeDef *TIMx)
  915. {
  916. return ((READ_BIT(TIMx->CR1, TIM_CR1_CEN) == (TIM_CR1_CEN)) ? 1UL : 0UL);
  917. }
  918. /**
  919. * @brief Enable update event generation.
  920. * @rmtoll CR1 UDIS LL_TIM_EnableUpdateEvent
  921. * @param TIMx Timer instance
  922. * @retval None
  923. */
  924. __STATIC_INLINE void LL_TIM_EnableUpdateEvent(TIM_TypeDef *TIMx)
  925. {
  926. CLEAR_BIT(TIMx->CR1, TIM_CR1_UDIS);
  927. }
  928. /**
  929. * @brief Disable update event generation.
  930. * @rmtoll CR1 UDIS LL_TIM_DisableUpdateEvent
  931. * @param TIMx Timer instance
  932. * @retval None
  933. */
  934. __STATIC_INLINE void LL_TIM_DisableUpdateEvent(TIM_TypeDef *TIMx)
  935. {
  936. SET_BIT(TIMx->CR1, TIM_CR1_UDIS);
  937. }
  938. /**
  939. * @brief Indicates whether update event generation is enabled.
  940. * @rmtoll CR1 UDIS LL_TIM_IsEnabledUpdateEvent
  941. * @param TIMx Timer instance
  942. * @retval Inverted state of bit (0 or 1).
  943. */
  944. __STATIC_INLINE uint32_t LL_TIM_IsEnabledUpdateEvent(TIM_TypeDef *TIMx)
  945. {
  946. return ((READ_BIT(TIMx->CR1, TIM_CR1_UDIS) == (uint32_t)RESET) ? 1UL : 0UL);
  947. }
  948. /**
  949. * @brief Set update event source
  950. * @note Update event source set to LL_TIM_UPDATESOURCE_REGULAR: any of the following events
  951. * generate an update interrupt or DMA request if enabled:
  952. * - Counter overflow/underflow
  953. * - Setting the UG bit
  954. * - Update generation through the slave mode controller
  955. * @note Update event source set to LL_TIM_UPDATESOURCE_COUNTER: only counter
  956. * overflow/underflow generates an update interrupt or DMA request if enabled.
  957. * @rmtoll CR1 URS LL_TIM_SetUpdateSource
  958. * @param TIMx Timer instance
  959. * @param UpdateSource This parameter can be one of the following values:
  960. * @arg @ref LL_TIM_UPDATESOURCE_REGULAR
  961. * @arg @ref LL_TIM_UPDATESOURCE_COUNTER
  962. * @retval None
  963. */
  964. __STATIC_INLINE void LL_TIM_SetUpdateSource(TIM_TypeDef *TIMx, uint32_t UpdateSource)
  965. {
  966. MODIFY_REG(TIMx->CR1, TIM_CR1_URS, UpdateSource);
  967. }
  968. /**
  969. * @brief Get actual event update source
  970. * @rmtoll CR1 URS LL_TIM_GetUpdateSource
  971. * @param TIMx Timer instance
  972. * @retval Returned value can be one of the following values:
  973. * @arg @ref LL_TIM_UPDATESOURCE_REGULAR
  974. * @arg @ref LL_TIM_UPDATESOURCE_COUNTER
  975. */
  976. __STATIC_INLINE uint32_t LL_TIM_GetUpdateSource(TIM_TypeDef *TIMx)
  977. {
  978. return (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_URS));
  979. }
  980. /**
  981. * @brief Set one pulse mode (one shot v.s. repetitive).
  982. * @rmtoll CR1 OPM LL_TIM_SetOnePulseMode
  983. * @param TIMx Timer instance
  984. * @param OnePulseMode This parameter can be one of the following values:
  985. * @arg @ref LL_TIM_ONEPULSEMODE_SINGLE
  986. * @arg @ref LL_TIM_ONEPULSEMODE_REPETITIVE
  987. * @retval None
  988. */
  989. __STATIC_INLINE void LL_TIM_SetOnePulseMode(TIM_TypeDef *TIMx, uint32_t OnePulseMode)
  990. {
  991. MODIFY_REG(TIMx->CR1, TIM_CR1_OPM, OnePulseMode);
  992. }
  993. /**
  994. * @brief Get actual one pulse mode.
  995. * @rmtoll CR1 OPM LL_TIM_GetOnePulseMode
  996. * @param TIMx Timer instance
  997. * @retval Returned value can be one of the following values:
  998. * @arg @ref LL_TIM_ONEPULSEMODE_SINGLE
  999. * @arg @ref LL_TIM_ONEPULSEMODE_REPETITIVE
  1000. */
  1001. __STATIC_INLINE uint32_t LL_TIM_GetOnePulseMode(TIM_TypeDef *TIMx)
  1002. {
  1003. return (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_OPM));
  1004. }
  1005. /**
  1006. * @brief Set the timer counter counting mode.
  1007. * @note Macro IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx) can be used to
  1008. * check whether or not the counter mode selection feature is supported
  1009. * by a timer instance.
  1010. * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
  1011. * requires a timer reset to avoid unexpected direction
  1012. * due to DIR bit readonly in center aligned mode.
  1013. * @rmtoll CR1 DIR LL_TIM_SetCounterMode\n
  1014. * CR1 CMS LL_TIM_SetCounterMode
  1015. * @param TIMx Timer instance
  1016. * @param CounterMode This parameter can be one of the following values:
  1017. * @arg @ref LL_TIM_COUNTERMODE_UP
  1018. * @arg @ref LL_TIM_COUNTERMODE_DOWN
  1019. * @arg @ref LL_TIM_COUNTERMODE_CENTER_UP
  1020. * @arg @ref LL_TIM_COUNTERMODE_CENTER_DOWN
  1021. * @arg @ref LL_TIM_COUNTERMODE_CENTER_UP_DOWN
  1022. * @retval None
  1023. */
  1024. __STATIC_INLINE void LL_TIM_SetCounterMode(TIM_TypeDef *TIMx, uint32_t CounterMode)
  1025. {
  1026. MODIFY_REG(TIMx->CR1, (TIM_CR1_DIR | TIM_CR1_CMS), CounterMode);
  1027. }
  1028. /**
  1029. * @brief Get actual counter mode.
  1030. * @note Macro IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx) can be used to
  1031. * check whether or not the counter mode selection feature is supported
  1032. * by a timer instance.
  1033. * @rmtoll CR1 DIR LL_TIM_GetCounterMode\n
  1034. * CR1 CMS LL_TIM_GetCounterMode
  1035. * @param TIMx Timer instance
  1036. * @retval Returned value can be one of the following values:
  1037. * @arg @ref LL_TIM_COUNTERMODE_UP
  1038. * @arg @ref LL_TIM_COUNTERMODE_DOWN
  1039. * @arg @ref LL_TIM_COUNTERMODE_CENTER_UP
  1040. * @arg @ref LL_TIM_COUNTERMODE_CENTER_DOWN
  1041. * @arg @ref LL_TIM_COUNTERMODE_CENTER_UP_DOWN
  1042. */
  1043. __STATIC_INLINE uint32_t LL_TIM_GetCounterMode(TIM_TypeDef *TIMx)
  1044. {
  1045. uint32_t counter_mode;
  1046. counter_mode = (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_CMS));
  1047. if (counter_mode == 0U)
  1048. {
  1049. counter_mode = (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_DIR));
  1050. }
  1051. return counter_mode;
  1052. }
  1053. /**
  1054. * @brief Enable auto-reload (ARR) preload.
  1055. * @rmtoll CR1 ARPE LL_TIM_EnableARRPreload
  1056. * @param TIMx Timer instance
  1057. * @retval None
  1058. */
  1059. __STATIC_INLINE void LL_TIM_EnableARRPreload(TIM_TypeDef *TIMx)
  1060. {
  1061. SET_BIT(TIMx->CR1, TIM_CR1_ARPE);
  1062. }
  1063. /**
  1064. * @brief Disable auto-reload (ARR) preload.
  1065. * @rmtoll CR1 ARPE LL_TIM_DisableARRPreload
  1066. * @param TIMx Timer instance
  1067. * @retval None
  1068. */
  1069. __STATIC_INLINE void LL_TIM_DisableARRPreload(TIM_TypeDef *TIMx)
  1070. {
  1071. CLEAR_BIT(TIMx->CR1, TIM_CR1_ARPE);
  1072. }
  1073. /**
  1074. * @brief Indicates whether auto-reload (ARR) preload is enabled.
  1075. * @rmtoll CR1 ARPE LL_TIM_IsEnabledARRPreload
  1076. * @param TIMx Timer instance
  1077. * @retval State of bit (1 or 0).
  1078. */
  1079. __STATIC_INLINE uint32_t LL_TIM_IsEnabledARRPreload(TIM_TypeDef *TIMx)
  1080. {
  1081. return ((READ_BIT(TIMx->CR1, TIM_CR1_ARPE) == (TIM_CR1_ARPE)) ? 1UL : 0UL);
  1082. }
  1083. /**
  1084. * @brief Set the division ratio between the timer clock and the sampling clock used by the dead-time generators
  1085. * (when supported) and the digital filters.
  1086. * @note Macro IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx) can be used to check
  1087. * whether or not the clock division feature is supported by the timer
  1088. * instance.
  1089. * @rmtoll CR1 CKD LL_TIM_SetClockDivision
  1090. * @param TIMx Timer instance
  1091. * @param ClockDivision This parameter can be one of the following values:
  1092. * @arg @ref LL_TIM_CLOCKDIVISION_DIV1
  1093. * @arg @ref LL_TIM_CLOCKDIVISION_DIV2
  1094. * @arg @ref LL_TIM_CLOCKDIVISION_DIV4
  1095. * @retval None
  1096. */
  1097. __STATIC_INLINE void LL_TIM_SetClockDivision(TIM_TypeDef *TIMx, uint32_t ClockDivision)
  1098. {
  1099. MODIFY_REG(TIMx->CR1, TIM_CR1_CKD, ClockDivision);
  1100. }
  1101. /**
  1102. * @brief Get the actual division ratio between the timer clock and the sampling clock used by the dead-time
  1103. * generators (when supported) and the digital filters.
  1104. * @note Macro IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx) can be used to check
  1105. * whether or not the clock division feature is supported by the timer
  1106. * instance.
  1107. * @rmtoll CR1 CKD LL_TIM_GetClockDivision
  1108. * @param TIMx Timer instance
  1109. * @retval Returned value can be one of the following values:
  1110. * @arg @ref LL_TIM_CLOCKDIVISION_DIV1
  1111. * @arg @ref LL_TIM_CLOCKDIVISION_DIV2
  1112. * @arg @ref LL_TIM_CLOCKDIVISION_DIV4
  1113. */
  1114. __STATIC_INLINE uint32_t LL_TIM_GetClockDivision(TIM_TypeDef *TIMx)
  1115. {
  1116. return (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_CKD));
  1117. }
  1118. /**
  1119. * @brief Set the counter value.
  1120. * @rmtoll CNT CNT LL_TIM_SetCounter
  1121. * @param TIMx Timer instance
  1122. * @param Counter Counter value (between Min_Data=0 and Max_Data=0xFFFF)
  1123. * @retval None
  1124. */
  1125. __STATIC_INLINE void LL_TIM_SetCounter(TIM_TypeDef *TIMx, uint32_t Counter)
  1126. {
  1127. WRITE_REG(TIMx->CNT, Counter);
  1128. }
  1129. /**
  1130. * @brief Get the counter value.
  1131. * @rmtoll CNT CNT LL_TIM_GetCounter
  1132. * @param TIMx Timer instance
  1133. * @retval Counter value (between Min_Data=0 and Max_Data=0xFFFF)
  1134. */
  1135. __STATIC_INLINE uint32_t LL_TIM_GetCounter(TIM_TypeDef *TIMx)
  1136. {
  1137. return (uint32_t)(READ_REG(TIMx->CNT));
  1138. }
  1139. /**
  1140. * @brief Get the current direction of the counter
  1141. * @rmtoll CR1 DIR LL_TIM_GetDirection
  1142. * @param TIMx Timer instance
  1143. * @retval Returned value can be one of the following values:
  1144. * @arg @ref LL_TIM_COUNTERDIRECTION_UP
  1145. * @arg @ref LL_TIM_COUNTERDIRECTION_DOWN
  1146. */
  1147. __STATIC_INLINE uint32_t LL_TIM_GetDirection(TIM_TypeDef *TIMx)
  1148. {
  1149. return (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_DIR));
  1150. }
  1151. /**
  1152. * @brief Set the prescaler value.
  1153. * @note The counter clock frequency CK_CNT is equal to fCK_PSC / (PSC[15:0] + 1).
  1154. * @note The prescaler can be changed on the fly as this control register is buffered. The new
  1155. * prescaler ratio is taken into account at the next update event.
  1156. * @note Helper macro @ref __LL_TIM_CALC_PSC can be used to calculate the Prescaler parameter
  1157. * @rmtoll PSC PSC LL_TIM_SetPrescaler
  1158. * @param TIMx Timer instance
  1159. * @param Prescaler between Min_Data=0 and Max_Data=65535
  1160. * @retval None
  1161. */
  1162. __STATIC_INLINE void LL_TIM_SetPrescaler(TIM_TypeDef *TIMx, uint32_t Prescaler)
  1163. {
  1164. WRITE_REG(TIMx->PSC, Prescaler);
  1165. }
  1166. /**
  1167. * @brief Get the prescaler value.
  1168. * @rmtoll PSC PSC LL_TIM_GetPrescaler
  1169. * @param TIMx Timer instance
  1170. * @retval Prescaler value between Min_Data=0 and Max_Data=65535
  1171. */
  1172. __STATIC_INLINE uint32_t LL_TIM_GetPrescaler(TIM_TypeDef *TIMx)
  1173. {
  1174. return (uint32_t)(READ_REG(TIMx->PSC));
  1175. }
  1176. /**
  1177. * @brief Set the auto-reload value.
  1178. * @note The counter is blocked while the auto-reload value is null.
  1179. * @note Helper macro @ref __LL_TIM_CALC_ARR can be used to calculate the AutoReload parameter
  1180. * @rmtoll ARR ARR LL_TIM_SetAutoReload
  1181. * @param TIMx Timer instance
  1182. * @param AutoReload between Min_Data=0 and Max_Data=65535
  1183. * @retval None
  1184. */
  1185. __STATIC_INLINE void LL_TIM_SetAutoReload(TIM_TypeDef *TIMx, uint32_t AutoReload)
  1186. {
  1187. WRITE_REG(TIMx->ARR, AutoReload);
  1188. }
  1189. /**
  1190. * @brief Get the auto-reload value.
  1191. * @rmtoll ARR ARR LL_TIM_GetAutoReload
  1192. * @param TIMx Timer instance
  1193. * @retval Auto-reload value
  1194. */
  1195. __STATIC_INLINE uint32_t LL_TIM_GetAutoReload(TIM_TypeDef *TIMx)
  1196. {
  1197. return (uint32_t)(READ_REG(TIMx->ARR));
  1198. }
  1199. /**
  1200. * @brief Set the repetition counter value.
  1201. * @note Macro IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx) can be used to check
  1202. * whether or not a timer instance supports a repetition counter.
  1203. * @rmtoll RCR REP LL_TIM_SetRepetitionCounter
  1204. * @param TIMx Timer instance
  1205. * @param RepetitionCounter between Min_Data=0 and Max_Data=255 or 65535 for advanced timer.
  1206. * @retval None
  1207. */
  1208. __STATIC_INLINE void LL_TIM_SetRepetitionCounter(TIM_TypeDef *TIMx, uint32_t RepetitionCounter)
  1209. {
  1210. WRITE_REG(TIMx->RCR, RepetitionCounter);
  1211. }
  1212. /**
  1213. * @brief Get the repetition counter value.
  1214. * @note Macro IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx) can be used to check
  1215. * whether or not a timer instance supports a repetition counter.
  1216. * @rmtoll RCR REP LL_TIM_GetRepetitionCounter
  1217. * @param TIMx Timer instance
  1218. * @retval Repetition counter value
  1219. */
  1220. __STATIC_INLINE uint32_t LL_TIM_GetRepetitionCounter(TIM_TypeDef *TIMx)
  1221. {
  1222. return (uint32_t)(READ_REG(TIMx->RCR));
  1223. }
  1224. /**
  1225. * @}
  1226. */
  1227. /** @defgroup TIM_LL_EF_Capture_Compare Capture Compare configuration
  1228. * @{
  1229. */
  1230. /**
  1231. * @brief Enable the capture/compare control bits (CCxE, CCxNE and OCxM) preload.
  1232. * @note CCxE, CCxNE and OCxM bits are preloaded, after having been written,
  1233. * they are updated only when a commutation event (COM) occurs.
  1234. * @note Only on channels that have a complementary output.
  1235. * @note Macro IS_TIM_COMMUTATION_EVENT_INSTANCE(TIMx) can be used to check
  1236. * whether or not a timer instance is able to generate a commutation event.
  1237. * @rmtoll CR2 CCPC LL_TIM_CC_EnablePreload
  1238. * @param TIMx Timer instance
  1239. * @retval None
  1240. */
  1241. __STATIC_INLINE void LL_TIM_CC_EnablePreload(TIM_TypeDef *TIMx)
  1242. {
  1243. SET_BIT(TIMx->CR2, TIM_CR2_CCPC);
  1244. }
  1245. /**
  1246. * @brief Disable the capture/compare control bits (CCxE, CCxNE and OCxM) preload.
  1247. * @note Macro IS_TIM_COMMUTATION_EVENT_INSTANCE(TIMx) can be used to check
  1248. * whether or not a timer instance is able to generate a commutation event.
  1249. * @rmtoll CR2 CCPC LL_TIM_CC_DisablePreload
  1250. * @param TIMx Timer instance
  1251. * @retval None
  1252. */
  1253. __STATIC_INLINE void LL_TIM_CC_DisablePreload(TIM_TypeDef *TIMx)
  1254. {
  1255. CLEAR_BIT(TIMx->CR2, TIM_CR2_CCPC);
  1256. }
  1257. /**
  1258. * @brief Set the updated source of the capture/compare control bits (CCxE, CCxNE and OCxM).
  1259. * @note Macro IS_TIM_COMMUTATION_EVENT_INSTANCE(TIMx) can be used to check
  1260. * whether or not a timer instance is able to generate a commutation event.
  1261. * @rmtoll CR2 CCUS LL_TIM_CC_SetUpdate
  1262. * @param TIMx Timer instance
  1263. * @param CCUpdateSource This parameter can be one of the following values:
  1264. * @arg @ref LL_TIM_CCUPDATESOURCE_COMG_ONLY
  1265. * @arg @ref LL_TIM_CCUPDATESOURCE_COMG_AND_TRGI
  1266. * @retval None
  1267. */
  1268. __STATIC_INLINE void LL_TIM_CC_SetUpdate(TIM_TypeDef *TIMx, uint32_t CCUpdateSource)
  1269. {
  1270. MODIFY_REG(TIMx->CR2, TIM_CR2_CCUS, CCUpdateSource);
  1271. }
  1272. /**
  1273. * @brief Set the trigger of the capture/compare DMA request.
  1274. * @rmtoll CR2 CCDS LL_TIM_CC_SetDMAReqTrigger
  1275. * @param TIMx Timer instance
  1276. * @param DMAReqTrigger This parameter can be one of the following values:
  1277. * @arg @ref LL_TIM_CCDMAREQUEST_CC
  1278. * @arg @ref LL_TIM_CCDMAREQUEST_UPDATE
  1279. * @retval None
  1280. */
  1281. __STATIC_INLINE void LL_TIM_CC_SetDMAReqTrigger(TIM_TypeDef *TIMx, uint32_t DMAReqTrigger)
  1282. {
  1283. MODIFY_REG(TIMx->CR2, TIM_CR2_CCDS, DMAReqTrigger);
  1284. }
  1285. /**
  1286. * @brief Get actual trigger of the capture/compare DMA request.
  1287. * @rmtoll CR2 CCDS LL_TIM_CC_GetDMAReqTrigger
  1288. * @param TIMx Timer instance
  1289. * @retval Returned value can be one of the following values:
  1290. * @arg @ref LL_TIM_CCDMAREQUEST_CC
  1291. * @arg @ref LL_TIM_CCDMAREQUEST_UPDATE
  1292. */
  1293. __STATIC_INLINE uint32_t LL_TIM_CC_GetDMAReqTrigger(TIM_TypeDef *TIMx)
  1294. {
  1295. return (uint32_t)(READ_BIT(TIMx->CR2, TIM_CR2_CCDS));
  1296. }
  1297. /**
  1298. * @brief Set the lock level to freeze the
  1299. * configuration of several capture/compare parameters.
  1300. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  1301. * the lock mechanism is supported by a timer instance.
  1302. * @rmtoll BDTR LOCK LL_TIM_CC_SetLockLevel
  1303. * @param TIMx Timer instance
  1304. * @param LockLevel This parameter can be one of the following values:
  1305. * @arg @ref LL_TIM_LOCKLEVEL_OFF
  1306. * @arg @ref LL_TIM_LOCKLEVEL_1
  1307. * @arg @ref LL_TIM_LOCKLEVEL_2
  1308. * @arg @ref LL_TIM_LOCKLEVEL_3
  1309. * @retval None
  1310. */
  1311. __STATIC_INLINE void LL_TIM_CC_SetLockLevel(TIM_TypeDef *TIMx, uint32_t LockLevel)
  1312. {
  1313. MODIFY_REG(TIMx->BDTR, TIM_BDTR_LOCK, LockLevel);
  1314. }
  1315. /**
  1316. * @brief Enable capture/compare channels.
  1317. * @rmtoll CCER CC1E LL_TIM_CC_EnableChannel\n
  1318. * CCER CC1NE LL_TIM_CC_EnableChannel\n
  1319. * CCER CC2E LL_TIM_CC_EnableChannel\n
  1320. * CCER CC2NE LL_TIM_CC_EnableChannel\n
  1321. * CCER CC3E LL_TIM_CC_EnableChannel\n
  1322. * CCER CC3NE LL_TIM_CC_EnableChannel\n
  1323. * CCER CC4E LL_TIM_CC_EnableChannel
  1324. * @param TIMx Timer instance
  1325. * @param Channels This parameter can be a combination of the following values:
  1326. * @arg @ref LL_TIM_CHANNEL_CH1
  1327. * @arg @ref LL_TIM_CHANNEL_CH1N
  1328. * @arg @ref LL_TIM_CHANNEL_CH2
  1329. * @arg @ref LL_TIM_CHANNEL_CH2N
  1330. * @arg @ref LL_TIM_CHANNEL_CH3
  1331. * @arg @ref LL_TIM_CHANNEL_CH3N
  1332. * @arg @ref LL_TIM_CHANNEL_CH4
  1333. * @retval None
  1334. */
  1335. __STATIC_INLINE void LL_TIM_CC_EnableChannel(TIM_TypeDef *TIMx, uint32_t Channels)
  1336. {
  1337. SET_BIT(TIMx->CCER, Channels);
  1338. }
  1339. /**
  1340. * @brief Disable capture/compare channels.
  1341. * @rmtoll CCER CC1E LL_TIM_CC_DisableChannel\n
  1342. * CCER CC1NE LL_TIM_CC_DisableChannel\n
  1343. * CCER CC2E LL_TIM_CC_DisableChannel\n
  1344. * CCER CC2NE LL_TIM_CC_DisableChannel\n
  1345. * CCER CC3E LL_TIM_CC_DisableChannel\n
  1346. * CCER CC3NE LL_TIM_CC_DisableChannel\n
  1347. * CCER CC4E LL_TIM_CC_DisableChannel
  1348. * @param TIMx Timer instance
  1349. * @param Channels This parameter can be a combination of the following values:
  1350. * @arg @ref LL_TIM_CHANNEL_CH1
  1351. * @arg @ref LL_TIM_CHANNEL_CH1N
  1352. * @arg @ref LL_TIM_CHANNEL_CH2
  1353. * @arg @ref LL_TIM_CHANNEL_CH2N
  1354. * @arg @ref LL_TIM_CHANNEL_CH3
  1355. * @arg @ref LL_TIM_CHANNEL_CH3N
  1356. * @arg @ref LL_TIM_CHANNEL_CH4
  1357. * @retval None
  1358. */
  1359. __STATIC_INLINE void LL_TIM_CC_DisableChannel(TIM_TypeDef *TIMx, uint32_t Channels)
  1360. {
  1361. CLEAR_BIT(TIMx->CCER, Channels);
  1362. }
  1363. /**
  1364. * @brief Indicate whether channel(s) is(are) enabled.
  1365. * @rmtoll CCER CC1E LL_TIM_CC_IsEnabledChannel\n
  1366. * CCER CC1NE LL_TIM_CC_IsEnabledChannel\n
  1367. * CCER CC2E LL_TIM_CC_IsEnabledChannel\n
  1368. * CCER CC2NE LL_TIM_CC_IsEnabledChannel\n
  1369. * CCER CC3E LL_TIM_CC_IsEnabledChannel\n
  1370. * CCER CC3NE LL_TIM_CC_IsEnabledChannel\n
  1371. * CCER CC4E LL_TIM_CC_IsEnabledChannel
  1372. * @param TIMx Timer instance
  1373. * @param Channels This parameter can be a combination of the following values:
  1374. * @arg @ref LL_TIM_CHANNEL_CH1
  1375. * @arg @ref LL_TIM_CHANNEL_CH1N
  1376. * @arg @ref LL_TIM_CHANNEL_CH2
  1377. * @arg @ref LL_TIM_CHANNEL_CH2N
  1378. * @arg @ref LL_TIM_CHANNEL_CH3
  1379. * @arg @ref LL_TIM_CHANNEL_CH3N
  1380. * @arg @ref LL_TIM_CHANNEL_CH4
  1381. * @retval State of bit (1 or 0).
  1382. */
  1383. __STATIC_INLINE uint32_t LL_TIM_CC_IsEnabledChannel(TIM_TypeDef *TIMx, uint32_t Channels)
  1384. {
  1385. return ((READ_BIT(TIMx->CCER, Channels) == (Channels)) ? 1UL : 0UL);
  1386. }
  1387. /**
  1388. * @}
  1389. */
  1390. /** @defgroup TIM_LL_EF_Output_Channel Output channel configuration
  1391. * @{
  1392. */
  1393. /**
  1394. * @brief Configure an output channel.
  1395. * @rmtoll CCMR1 CC1S LL_TIM_OC_ConfigOutput\n
  1396. * CCMR1 CC2S LL_TIM_OC_ConfigOutput\n
  1397. * CCMR2 CC3S LL_TIM_OC_ConfigOutput\n
  1398. * CCMR2 CC4S LL_TIM_OC_ConfigOutput\n
  1399. * CCER CC1P LL_TIM_OC_ConfigOutput\n
  1400. * CCER CC2P LL_TIM_OC_ConfigOutput\n
  1401. * CCER CC3P LL_TIM_OC_ConfigOutput\n
  1402. * CCER CC4P LL_TIM_OC_ConfigOutput\n
  1403. * CR2 OIS1 LL_TIM_OC_ConfigOutput\n
  1404. * CR2 OIS2 LL_TIM_OC_ConfigOutput\n
  1405. * CR2 OIS3 LL_TIM_OC_ConfigOutput\n
  1406. * CR2 OIS4 LL_TIM_OC_ConfigOutput
  1407. * @param TIMx Timer instance
  1408. * @param Channel This parameter can be one of the following values:
  1409. * @arg @ref LL_TIM_CHANNEL_CH1
  1410. * @arg @ref LL_TIM_CHANNEL_CH2
  1411. * @arg @ref LL_TIM_CHANNEL_CH3
  1412. * @arg @ref LL_TIM_CHANNEL_CH4
  1413. * @param Configuration This parameter must be a combination of all the following values:
  1414. * @arg @ref LL_TIM_OCPOLARITY_HIGH or @ref LL_TIM_OCPOLARITY_LOW
  1415. * @arg @ref LL_TIM_OCIDLESTATE_LOW or @ref LL_TIM_OCIDLESTATE_HIGH
  1416. * @retval None
  1417. */
  1418. __STATIC_INLINE void LL_TIM_OC_ConfigOutput(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t Configuration)
  1419. {
  1420. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1421. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1422. CLEAR_BIT(*pReg, (TIM_CCMR1_CC1S << SHIFT_TAB_OCxx[iChannel]));
  1423. MODIFY_REG(TIMx->CCER, (TIM_CCER_CC1P << SHIFT_TAB_CCxP[iChannel]),
  1424. (Configuration & TIM_CCER_CC1P) << SHIFT_TAB_CCxP[iChannel]);
  1425. MODIFY_REG(TIMx->CR2, (TIM_CR2_OIS1 << SHIFT_TAB_OISx[iChannel]),
  1426. (Configuration & TIM_CR2_OIS1) << SHIFT_TAB_OISx[iChannel]);
  1427. }
  1428. /**
  1429. * @brief Define the behavior of the output reference signal OCxREF from which
  1430. * OCx and OCxN (when relevant) are derived.
  1431. * @rmtoll CCMR1 OC1M LL_TIM_OC_SetMode\n
  1432. * CCMR1 OC2M LL_TIM_OC_SetMode\n
  1433. * CCMR2 OC3M LL_TIM_OC_SetMode\n
  1434. * CCMR2 OC4M LL_TIM_OC_SetMode
  1435. * @param TIMx Timer instance
  1436. * @param Channel This parameter can be one of the following values:
  1437. * @arg @ref LL_TIM_CHANNEL_CH1
  1438. * @arg @ref LL_TIM_CHANNEL_CH2
  1439. * @arg @ref LL_TIM_CHANNEL_CH3
  1440. * @arg @ref LL_TIM_CHANNEL_CH4
  1441. * @param Mode This parameter can be one of the following values:
  1442. * @arg @ref LL_TIM_OCMODE_FROZEN
  1443. * @arg @ref LL_TIM_OCMODE_ACTIVE
  1444. * @arg @ref LL_TIM_OCMODE_INACTIVE
  1445. * @arg @ref LL_TIM_OCMODE_TOGGLE
  1446. * @arg @ref LL_TIM_OCMODE_FORCED_INACTIVE
  1447. * @arg @ref LL_TIM_OCMODE_FORCED_ACTIVE
  1448. * @arg @ref LL_TIM_OCMODE_PWM1
  1449. * @arg @ref LL_TIM_OCMODE_PWM2
  1450. * @retval None
  1451. */
  1452. __STATIC_INLINE void LL_TIM_OC_SetMode(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t Mode)
  1453. {
  1454. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1455. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1456. MODIFY_REG(*pReg, ((TIM_CCMR1_OC1M | TIM_CCMR1_CC1S) << SHIFT_TAB_OCxx[iChannel]), Mode << SHIFT_TAB_OCxx[iChannel]);
  1457. }
  1458. /**
  1459. * @brief Get the output compare mode of an output channel.
  1460. * @rmtoll CCMR1 OC1M LL_TIM_OC_GetMode\n
  1461. * CCMR1 OC2M LL_TIM_OC_GetMode\n
  1462. * CCMR2 OC3M LL_TIM_OC_GetMode\n
  1463. * CCMR2 OC4M LL_TIM_OC_GetMode
  1464. * @param TIMx Timer instance
  1465. * @param Channel This parameter can be one of the following values:
  1466. * @arg @ref LL_TIM_CHANNEL_CH1
  1467. * @arg @ref LL_TIM_CHANNEL_CH2
  1468. * @arg @ref LL_TIM_CHANNEL_CH3
  1469. * @arg @ref LL_TIM_CHANNEL_CH4
  1470. * @retval Returned value can be one of the following values:
  1471. * @arg @ref LL_TIM_OCMODE_FROZEN
  1472. * @arg @ref LL_TIM_OCMODE_ACTIVE
  1473. * @arg @ref LL_TIM_OCMODE_INACTIVE
  1474. * @arg @ref LL_TIM_OCMODE_TOGGLE
  1475. * @arg @ref LL_TIM_OCMODE_FORCED_INACTIVE
  1476. * @arg @ref LL_TIM_OCMODE_FORCED_ACTIVE
  1477. * @arg @ref LL_TIM_OCMODE_PWM1
  1478. * @arg @ref LL_TIM_OCMODE_PWM2
  1479. */
  1480. __STATIC_INLINE uint32_t LL_TIM_OC_GetMode(TIM_TypeDef *TIMx, uint32_t Channel)
  1481. {
  1482. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1483. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1484. return (READ_BIT(*pReg, ((TIM_CCMR1_OC1M | TIM_CCMR1_CC1S) << SHIFT_TAB_OCxx[iChannel])) >> SHIFT_TAB_OCxx[iChannel]);
  1485. }
  1486. /**
  1487. * @brief Set the polarity of an output channel.
  1488. * @rmtoll CCER CC1P LL_TIM_OC_SetPolarity\n
  1489. * CCER CC1NP LL_TIM_OC_SetPolarity\n
  1490. * CCER CC2P LL_TIM_OC_SetPolarity\n
  1491. * CCER CC2NP LL_TIM_OC_SetPolarity\n
  1492. * CCER CC3P LL_TIM_OC_SetPolarity\n
  1493. * CCER CC3NP LL_TIM_OC_SetPolarity\n
  1494. * CCER CC4P LL_TIM_OC_SetPolarity
  1495. * @param TIMx Timer instance
  1496. * @param Channel This parameter can be one of the following values:
  1497. * @arg @ref LL_TIM_CHANNEL_CH1
  1498. * @arg @ref LL_TIM_CHANNEL_CH1N
  1499. * @arg @ref LL_TIM_CHANNEL_CH2
  1500. * @arg @ref LL_TIM_CHANNEL_CH2N
  1501. * @arg @ref LL_TIM_CHANNEL_CH3
  1502. * @arg @ref LL_TIM_CHANNEL_CH3N
  1503. * @arg @ref LL_TIM_CHANNEL_CH4
  1504. * @param Polarity This parameter can be one of the following values:
  1505. * @arg @ref LL_TIM_OCPOLARITY_HIGH
  1506. * @arg @ref LL_TIM_OCPOLARITY_LOW
  1507. * @retval None
  1508. */
  1509. __STATIC_INLINE void LL_TIM_OC_SetPolarity(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t Polarity)
  1510. {
  1511. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1512. MODIFY_REG(TIMx->CCER, (TIM_CCER_CC1P << SHIFT_TAB_CCxP[iChannel]), Polarity << SHIFT_TAB_CCxP[iChannel]);
  1513. }
  1514. /**
  1515. * @brief Get the polarity of an output channel.
  1516. * @rmtoll CCER CC1P LL_TIM_OC_GetPolarity\n
  1517. * CCER CC1NP LL_TIM_OC_GetPolarity\n
  1518. * CCER CC2P LL_TIM_OC_GetPolarity\n
  1519. * CCER CC2NP LL_TIM_OC_GetPolarity\n
  1520. * CCER CC3P LL_TIM_OC_GetPolarity\n
  1521. * CCER CC3NP LL_TIM_OC_GetPolarity\n
  1522. * CCER CC4P LL_TIM_OC_GetPolarity
  1523. * @param TIMx Timer instance
  1524. * @param Channel This parameter can be one of the following values:
  1525. * @arg @ref LL_TIM_CHANNEL_CH1
  1526. * @arg @ref LL_TIM_CHANNEL_CH1N
  1527. * @arg @ref LL_TIM_CHANNEL_CH2
  1528. * @arg @ref LL_TIM_CHANNEL_CH2N
  1529. * @arg @ref LL_TIM_CHANNEL_CH3
  1530. * @arg @ref LL_TIM_CHANNEL_CH3N
  1531. * @arg @ref LL_TIM_CHANNEL_CH4
  1532. * @retval Returned value can be one of the following values:
  1533. * @arg @ref LL_TIM_OCPOLARITY_HIGH
  1534. * @arg @ref LL_TIM_OCPOLARITY_LOW
  1535. */
  1536. __STATIC_INLINE uint32_t LL_TIM_OC_GetPolarity(TIM_TypeDef *TIMx, uint32_t Channel)
  1537. {
  1538. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1539. return (READ_BIT(TIMx->CCER, (TIM_CCER_CC1P << SHIFT_TAB_CCxP[iChannel])) >> SHIFT_TAB_CCxP[iChannel]);
  1540. }
  1541. /**
  1542. * @brief Set the IDLE state of an output channel
  1543. * @note This function is significant only for the timer instances
  1544. * supporting the break feature. Macro IS_TIM_BREAK_INSTANCE(TIMx)
  1545. * can be used to check whether or not a timer instance provides
  1546. * a break input.
  1547. * @rmtoll CR2 OIS1 LL_TIM_OC_SetIdleState\n
  1548. * CR2 OIS1N LL_TIM_OC_SetIdleState\n
  1549. * CR2 OIS2 LL_TIM_OC_SetIdleState\n
  1550. * CR2 OIS2N LL_TIM_OC_SetIdleState\n
  1551. * CR2 OIS3 LL_TIM_OC_SetIdleState\n
  1552. * CR2 OIS3N LL_TIM_OC_SetIdleState\n
  1553. * CR2 OIS4 LL_TIM_OC_SetIdleState
  1554. * @param TIMx Timer instance
  1555. * @param Channel This parameter can be one of the following values:
  1556. * @arg @ref LL_TIM_CHANNEL_CH1
  1557. * @arg @ref LL_TIM_CHANNEL_CH1N
  1558. * @arg @ref LL_TIM_CHANNEL_CH2
  1559. * @arg @ref LL_TIM_CHANNEL_CH2N
  1560. * @arg @ref LL_TIM_CHANNEL_CH3
  1561. * @arg @ref LL_TIM_CHANNEL_CH3N
  1562. * @arg @ref LL_TIM_CHANNEL_CH4
  1563. * @param IdleState This parameter can be one of the following values:
  1564. * @arg @ref LL_TIM_OCIDLESTATE_LOW
  1565. * @arg @ref LL_TIM_OCIDLESTATE_HIGH
  1566. * @retval None
  1567. */
  1568. __STATIC_INLINE void LL_TIM_OC_SetIdleState(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t IdleState)
  1569. {
  1570. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1571. MODIFY_REG(TIMx->CR2, (TIM_CR2_OIS1 << SHIFT_TAB_OISx[iChannel]), IdleState << SHIFT_TAB_OISx[iChannel]);
  1572. }
  1573. /**
  1574. * @brief Get the IDLE state of an output channel
  1575. * @rmtoll CR2 OIS1 LL_TIM_OC_GetIdleState\n
  1576. * CR2 OIS1N LL_TIM_OC_GetIdleState\n
  1577. * CR2 OIS2 LL_TIM_OC_GetIdleState\n
  1578. * CR2 OIS2N LL_TIM_OC_GetIdleState\n
  1579. * CR2 OIS3 LL_TIM_OC_GetIdleState\n
  1580. * CR2 OIS3N LL_TIM_OC_GetIdleState\n
  1581. * CR2 OIS4 LL_TIM_OC_GetIdleState
  1582. * @param TIMx Timer instance
  1583. * @param Channel This parameter can be one of the following values:
  1584. * @arg @ref LL_TIM_CHANNEL_CH1
  1585. * @arg @ref LL_TIM_CHANNEL_CH1N
  1586. * @arg @ref LL_TIM_CHANNEL_CH2
  1587. * @arg @ref LL_TIM_CHANNEL_CH2N
  1588. * @arg @ref LL_TIM_CHANNEL_CH3
  1589. * @arg @ref LL_TIM_CHANNEL_CH3N
  1590. * @arg @ref LL_TIM_CHANNEL_CH4
  1591. * @retval Returned value can be one of the following values:
  1592. * @arg @ref LL_TIM_OCIDLESTATE_LOW
  1593. * @arg @ref LL_TIM_OCIDLESTATE_HIGH
  1594. */
  1595. __STATIC_INLINE uint32_t LL_TIM_OC_GetIdleState(TIM_TypeDef *TIMx, uint32_t Channel)
  1596. {
  1597. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1598. return (READ_BIT(TIMx->CR2, (TIM_CR2_OIS1 << SHIFT_TAB_OISx[iChannel])) >> SHIFT_TAB_OISx[iChannel]);
  1599. }
  1600. /**
  1601. * @brief Enable fast mode for the output channel.
  1602. * @note Acts only if the channel is configured in PWM1 or PWM2 mode.
  1603. * @rmtoll CCMR1 OC1FE LL_TIM_OC_EnableFast\n
  1604. * CCMR1 OC2FE LL_TIM_OC_EnableFast\n
  1605. * CCMR2 OC3FE LL_TIM_OC_EnableFast\n
  1606. * CCMR2 OC4FE LL_TIM_OC_EnableFast
  1607. * @param TIMx Timer instance
  1608. * @param Channel This parameter can be one of the following values:
  1609. * @arg @ref LL_TIM_CHANNEL_CH1
  1610. * @arg @ref LL_TIM_CHANNEL_CH2
  1611. * @arg @ref LL_TIM_CHANNEL_CH3
  1612. * @arg @ref LL_TIM_CHANNEL_CH4
  1613. * @retval None
  1614. */
  1615. __STATIC_INLINE void LL_TIM_OC_EnableFast(TIM_TypeDef *TIMx, uint32_t Channel)
  1616. {
  1617. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1618. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1619. SET_BIT(*pReg, (TIM_CCMR1_OC1FE << SHIFT_TAB_OCxx[iChannel]));
  1620. }
  1621. /**
  1622. * @brief Disable fast mode for the output channel.
  1623. * @rmtoll CCMR1 OC1FE LL_TIM_OC_DisableFast\n
  1624. * CCMR1 OC2FE LL_TIM_OC_DisableFast\n
  1625. * CCMR2 OC3FE LL_TIM_OC_DisableFast\n
  1626. * CCMR2 OC4FE LL_TIM_OC_DisableFast
  1627. * @param TIMx Timer instance
  1628. * @param Channel This parameter can be one of the following values:
  1629. * @arg @ref LL_TIM_CHANNEL_CH1
  1630. * @arg @ref LL_TIM_CHANNEL_CH2
  1631. * @arg @ref LL_TIM_CHANNEL_CH3
  1632. * @arg @ref LL_TIM_CHANNEL_CH4
  1633. * @retval None
  1634. */
  1635. __STATIC_INLINE void LL_TIM_OC_DisableFast(TIM_TypeDef *TIMx, uint32_t Channel)
  1636. {
  1637. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1638. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1639. CLEAR_BIT(*pReg, (TIM_CCMR1_OC1FE << SHIFT_TAB_OCxx[iChannel]));
  1640. }
  1641. /**
  1642. * @brief Indicates whether fast mode is enabled for the output channel.
  1643. * @rmtoll CCMR1 OC1FE LL_TIM_OC_IsEnabledFast\n
  1644. * CCMR1 OC2FE LL_TIM_OC_IsEnabledFast\n
  1645. * CCMR2 OC3FE LL_TIM_OC_IsEnabledFast\n
  1646. * CCMR2 OC4FE LL_TIM_OC_IsEnabledFast\n
  1647. * @param TIMx Timer instance
  1648. * @param Channel This parameter can be one of the following values:
  1649. * @arg @ref LL_TIM_CHANNEL_CH1
  1650. * @arg @ref LL_TIM_CHANNEL_CH2
  1651. * @arg @ref LL_TIM_CHANNEL_CH3
  1652. * @arg @ref LL_TIM_CHANNEL_CH4
  1653. * @retval State of bit (1 or 0).
  1654. */
  1655. __STATIC_INLINE uint32_t LL_TIM_OC_IsEnabledFast(TIM_TypeDef *TIMx, uint32_t Channel)
  1656. {
  1657. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1658. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1659. uint32_t bitfield = TIM_CCMR1_OC1FE << SHIFT_TAB_OCxx[iChannel];
  1660. return ((READ_BIT(*pReg, bitfield) == bitfield) ? 1UL : 0UL);
  1661. }
  1662. /**
  1663. * @brief Enable compare register (TIMx_CCRx) preload for the output channel.
  1664. * @rmtoll CCMR1 OC1PE LL_TIM_OC_EnablePreload\n
  1665. * CCMR1 OC2PE LL_TIM_OC_EnablePreload\n
  1666. * CCMR2 OC3PE LL_TIM_OC_EnablePreload\n
  1667. * CCMR2 OC4PE LL_TIM_OC_EnablePreload
  1668. * @param TIMx Timer instance
  1669. * @param Channel This parameter can be one of the following values:
  1670. * @arg @ref LL_TIM_CHANNEL_CH1
  1671. * @arg @ref LL_TIM_CHANNEL_CH2
  1672. * @arg @ref LL_TIM_CHANNEL_CH3
  1673. * @arg @ref LL_TIM_CHANNEL_CH4
  1674. * @retval None
  1675. */
  1676. __STATIC_INLINE void LL_TIM_OC_EnablePreload(TIM_TypeDef *TIMx, uint32_t Channel)
  1677. {
  1678. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1679. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1680. SET_BIT(*pReg, (TIM_CCMR1_OC1PE << SHIFT_TAB_OCxx[iChannel]));
  1681. }
  1682. /**
  1683. * @brief Disable compare register (TIMx_CCRx) preload for the output channel.
  1684. * @rmtoll CCMR1 OC1PE LL_TIM_OC_DisablePreload\n
  1685. * CCMR1 OC2PE LL_TIM_OC_DisablePreload\n
  1686. * CCMR2 OC3PE LL_TIM_OC_DisablePreload\n
  1687. * CCMR2 OC4PE LL_TIM_OC_DisablePreload
  1688. * @param TIMx Timer instance
  1689. * @param Channel This parameter can be one of the following values:
  1690. * @arg @ref LL_TIM_CHANNEL_CH1
  1691. * @arg @ref LL_TIM_CHANNEL_CH2
  1692. * @arg @ref LL_TIM_CHANNEL_CH3
  1693. * @arg @ref LL_TIM_CHANNEL_CH4
  1694. * @retval None
  1695. */
  1696. __STATIC_INLINE void LL_TIM_OC_DisablePreload(TIM_TypeDef *TIMx, uint32_t Channel)
  1697. {
  1698. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1699. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1700. CLEAR_BIT(*pReg, (TIM_CCMR1_OC1PE << SHIFT_TAB_OCxx[iChannel]));
  1701. }
  1702. /**
  1703. * @brief Indicates whether compare register (TIMx_CCRx) preload is enabled for the output channel.
  1704. * @rmtoll CCMR1 OC1PE LL_TIM_OC_IsEnabledPreload\n
  1705. * CCMR1 OC2PE LL_TIM_OC_IsEnabledPreload\n
  1706. * CCMR2 OC3PE LL_TIM_OC_IsEnabledPreload\n
  1707. * CCMR2 OC4PE LL_TIM_OC_IsEnabledPreload\n
  1708. * @param TIMx Timer instance
  1709. * @param Channel This parameter can be one of the following values:
  1710. * @arg @ref LL_TIM_CHANNEL_CH1
  1711. * @arg @ref LL_TIM_CHANNEL_CH2
  1712. * @arg @ref LL_TIM_CHANNEL_CH3
  1713. * @arg @ref LL_TIM_CHANNEL_CH4
  1714. * @retval State of bit (1 or 0).
  1715. */
  1716. __STATIC_INLINE uint32_t LL_TIM_OC_IsEnabledPreload(TIM_TypeDef *TIMx, uint32_t Channel)
  1717. {
  1718. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1719. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1720. uint32_t bitfield = TIM_CCMR1_OC1PE << SHIFT_TAB_OCxx[iChannel];
  1721. return ((READ_BIT(*pReg, bitfield) == bitfield) ? 1UL : 0UL);
  1722. }
  1723. /**
  1724. * @brief Enable clearing the output channel on an external event.
  1725. * @note This function can only be used in Output compare and PWM modes. It does not work in Forced mode.
  1726. * @note Macro IS_TIM_OCXREF_CLEAR_INSTANCE(TIMx) can be used to check whether
  1727. * or not a timer instance can clear the OCxREF signal on an external event.
  1728. * @rmtoll CCMR1 OC1CE LL_TIM_OC_EnableClear\n
  1729. * CCMR1 OC2CE LL_TIM_OC_EnableClear\n
  1730. * CCMR2 OC3CE LL_TIM_OC_EnableClear\n
  1731. * CCMR2 OC4CE LL_TIM_OC_EnableClear
  1732. * @param TIMx Timer instance
  1733. * @param Channel This parameter can be one of the following values:
  1734. * @arg @ref LL_TIM_CHANNEL_CH1
  1735. * @arg @ref LL_TIM_CHANNEL_CH2
  1736. * @arg @ref LL_TIM_CHANNEL_CH3
  1737. * @arg @ref LL_TIM_CHANNEL_CH4
  1738. * @retval None
  1739. */
  1740. __STATIC_INLINE void LL_TIM_OC_EnableClear(TIM_TypeDef *TIMx, uint32_t Channel)
  1741. {
  1742. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1743. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1744. SET_BIT(*pReg, (TIM_CCMR1_OC1CE << SHIFT_TAB_OCxx[iChannel]));
  1745. }
  1746. /**
  1747. * @brief Disable clearing the output channel on an external event.
  1748. * @note Macro IS_TIM_OCXREF_CLEAR_INSTANCE(TIMx) can be used to check whether
  1749. * or not a timer instance can clear the OCxREF signal on an external event.
  1750. * @rmtoll CCMR1 OC1CE LL_TIM_OC_DisableClear\n
  1751. * CCMR1 OC2CE LL_TIM_OC_DisableClear\n
  1752. * CCMR2 OC3CE LL_TIM_OC_DisableClear\n
  1753. * CCMR2 OC4CE LL_TIM_OC_DisableClear
  1754. * @param TIMx Timer instance
  1755. * @param Channel This parameter can be one of the following values:
  1756. * @arg @ref LL_TIM_CHANNEL_CH1
  1757. * @arg @ref LL_TIM_CHANNEL_CH2
  1758. * @arg @ref LL_TIM_CHANNEL_CH3
  1759. * @arg @ref LL_TIM_CHANNEL_CH4
  1760. * @retval None
  1761. */
  1762. __STATIC_INLINE void LL_TIM_OC_DisableClear(TIM_TypeDef *TIMx, uint32_t Channel)
  1763. {
  1764. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1765. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1766. CLEAR_BIT(*pReg, (TIM_CCMR1_OC1CE << SHIFT_TAB_OCxx[iChannel]));
  1767. }
  1768. /**
  1769. * @brief Indicates clearing the output channel on an external event is enabled for the output channel.
  1770. * @note This function enables clearing the output channel on an external event.
  1771. * @note This function can only be used in Output compare and PWM modes. It does not work in Forced mode.
  1772. * @note Macro IS_TIM_OCXREF_CLEAR_INSTANCE(TIMx) can be used to check whether
  1773. * or not a timer instance can clear the OCxREF signal on an external event.
  1774. * @rmtoll CCMR1 OC1CE LL_TIM_OC_IsEnabledClear\n
  1775. * CCMR1 OC2CE LL_TIM_OC_IsEnabledClear\n
  1776. * CCMR2 OC3CE LL_TIM_OC_IsEnabledClear\n
  1777. * CCMR2 OC4CE LL_TIM_OC_IsEnabledClear\n
  1778. * @param TIMx Timer instance
  1779. * @param Channel This parameter can be one of the following values:
  1780. * @arg @ref LL_TIM_CHANNEL_CH1
  1781. * @arg @ref LL_TIM_CHANNEL_CH2
  1782. * @arg @ref LL_TIM_CHANNEL_CH3
  1783. * @arg @ref LL_TIM_CHANNEL_CH4
  1784. * @retval State of bit (1 or 0).
  1785. */
  1786. __STATIC_INLINE uint32_t LL_TIM_OC_IsEnabledClear(TIM_TypeDef *TIMx, uint32_t Channel)
  1787. {
  1788. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1789. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1790. uint32_t bitfield = TIM_CCMR1_OC1CE << SHIFT_TAB_OCxx[iChannel];
  1791. return ((READ_BIT(*pReg, bitfield) == bitfield) ? 1UL : 0UL);
  1792. }
  1793. /**
  1794. * @brief Set the dead-time delay (delay inserted between the rising edge of the OCxREF signal and the rising edge of
  1795. * the Ocx and OCxN signals).
  1796. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  1797. * dead-time insertion feature is supported by a timer instance.
  1798. * @note Helper macro @ref __LL_TIM_CALC_DEADTIME can be used to calculate the DeadTime parameter
  1799. * @rmtoll BDTR DTG LL_TIM_OC_SetDeadTime
  1800. * @param TIMx Timer instance
  1801. * @param DeadTime between Min_Data=0 and Max_Data=255
  1802. * @retval None
  1803. */
  1804. __STATIC_INLINE void LL_TIM_OC_SetDeadTime(TIM_TypeDef *TIMx, uint32_t DeadTime)
  1805. {
  1806. MODIFY_REG(TIMx->BDTR, TIM_BDTR_DTG, DeadTime);
  1807. }
  1808. /**
  1809. * @brief Set compare value for output channel 1 (TIMx_CCR1).
  1810. * @note Macro IS_TIM_CC1_INSTANCE(TIMx) can be used to check whether or not
  1811. * output channel 1 is supported by a timer instance.
  1812. * @rmtoll CCR1 CCR1 LL_TIM_OC_SetCompareCH1
  1813. * @param TIMx Timer instance
  1814. * @param CompareValue between Min_Data=0 and Max_Data=65535
  1815. * @retval None
  1816. */
  1817. __STATIC_INLINE void LL_TIM_OC_SetCompareCH1(TIM_TypeDef *TIMx, uint32_t CompareValue)
  1818. {
  1819. WRITE_REG(TIMx->CCR1, CompareValue);
  1820. }
  1821. /**
  1822. * @brief Set compare value for output channel 2 (TIMx_CCR2).
  1823. * @note Macro IS_TIM_CC2_INSTANCE(TIMx) can be used to check whether or not
  1824. * output channel 2 is supported by a timer instance.
  1825. * @rmtoll CCR2 CCR2 LL_TIM_OC_SetCompareCH2
  1826. * @param TIMx Timer instance
  1827. * @param CompareValue between Min_Data=0 and Max_Data=65535
  1828. * @retval None
  1829. */
  1830. __STATIC_INLINE void LL_TIM_OC_SetCompareCH2(TIM_TypeDef *TIMx, uint32_t CompareValue)
  1831. {
  1832. WRITE_REG(TIMx->CCR2, CompareValue);
  1833. }
  1834. /**
  1835. * @brief Set compare value for output channel 3 (TIMx_CCR3).
  1836. * @note Macro IS_TIM_CC3_INSTANCE(TIMx) can be used to check whether or not
  1837. * output channel is supported by a timer instance.
  1838. * @rmtoll CCR3 CCR3 LL_TIM_OC_SetCompareCH3
  1839. * @param TIMx Timer instance
  1840. * @param CompareValue between Min_Data=0 and Max_Data=65535
  1841. * @retval None
  1842. */
  1843. __STATIC_INLINE void LL_TIM_OC_SetCompareCH3(TIM_TypeDef *TIMx, uint32_t CompareValue)
  1844. {
  1845. WRITE_REG(TIMx->CCR3, CompareValue);
  1846. }
  1847. /**
  1848. * @brief Set compare value for output channel 4 (TIMx_CCR4).
  1849. * @note Macro IS_TIM_CC4_INSTANCE(TIMx) can be used to check whether or not
  1850. * output channel 4 is supported by a timer instance.
  1851. * @rmtoll CCR4 CCR4 LL_TIM_OC_SetCompareCH4
  1852. * @param TIMx Timer instance
  1853. * @param CompareValue between Min_Data=0 and Max_Data=65535
  1854. * @retval None
  1855. */
  1856. __STATIC_INLINE void LL_TIM_OC_SetCompareCH4(TIM_TypeDef *TIMx, uint32_t CompareValue)
  1857. {
  1858. WRITE_REG(TIMx->CCR4, CompareValue);
  1859. }
  1860. /**
  1861. * @brief Get compare value (TIMx_CCR1) set for output channel 1.
  1862. * @note Macro IS_TIM_CC1_INSTANCE(TIMx) can be used to check whether or not
  1863. * output channel 1 is supported by a timer instance.
  1864. * @rmtoll CCR1 CCR1 LL_TIM_OC_GetCompareCH1
  1865. * @param TIMx Timer instance
  1866. * @retval CompareValue (between Min_Data=0 and Max_Data=65535)
  1867. */
  1868. __STATIC_INLINE uint32_t LL_TIM_OC_GetCompareCH1(TIM_TypeDef *TIMx)
  1869. {
  1870. return (uint32_t)(READ_REG(TIMx->CCR1));
  1871. }
  1872. /**
  1873. * @brief Get compare value (TIMx_CCR2) set for output channel 2.
  1874. * @note Macro IS_TIM_CC2_INSTANCE(TIMx) can be used to check whether or not
  1875. * output channel 2 is supported by a timer instance.
  1876. * @rmtoll CCR2 CCR2 LL_TIM_OC_GetCompareCH2
  1877. * @param TIMx Timer instance
  1878. * @retval CompareValue (between Min_Data=0 and Max_Data=65535)
  1879. */
  1880. __STATIC_INLINE uint32_t LL_TIM_OC_GetCompareCH2(TIM_TypeDef *TIMx)
  1881. {
  1882. return (uint32_t)(READ_REG(TIMx->CCR2));
  1883. }
  1884. /**
  1885. * @brief Get compare value (TIMx_CCR3) set for output channel 3.
  1886. * @note Macro IS_TIM_CC3_INSTANCE(TIMx) can be used to check whether or not
  1887. * output channel 3 is supported by a timer instance.
  1888. * @rmtoll CCR3 CCR3 LL_TIM_OC_GetCompareCH3
  1889. * @param TIMx Timer instance
  1890. * @retval CompareValue (between Min_Data=0 and Max_Data=65535)
  1891. */
  1892. __STATIC_INLINE uint32_t LL_TIM_OC_GetCompareCH3(TIM_TypeDef *TIMx)
  1893. {
  1894. return (uint32_t)(READ_REG(TIMx->CCR3));
  1895. }
  1896. /**
  1897. * @brief Get compare value (TIMx_CCR4) set for output channel 4.
  1898. * @note Macro IS_TIM_CC4_INSTANCE(TIMx) can be used to check whether or not
  1899. * output channel 4 is supported by a timer instance.
  1900. * @rmtoll CCR4 CCR4 LL_TIM_OC_GetCompareCH4
  1901. * @param TIMx Timer instance
  1902. * @retval CompareValue (between Min_Data=0 and Max_Data=65535)
  1903. */
  1904. __STATIC_INLINE uint32_t LL_TIM_OC_GetCompareCH4(TIM_TypeDef *TIMx)
  1905. {
  1906. return (uint32_t)(READ_REG(TIMx->CCR4));
  1907. }
  1908. /**
  1909. * @}
  1910. */
  1911. /** @defgroup TIM_LL_EF_Input_Channel Input channel configuration
  1912. * @{
  1913. */
  1914. /**
  1915. * @brief Configure input channel.
  1916. * @rmtoll CCMR1 CC1S LL_TIM_IC_Config\n
  1917. * CCMR1 IC1PSC LL_TIM_IC_Config\n
  1918. * CCMR1 IC1F LL_TIM_IC_Config\n
  1919. * CCMR1 CC2S LL_TIM_IC_Config\n
  1920. * CCMR1 IC2PSC LL_TIM_IC_Config\n
  1921. * CCMR1 IC2F LL_TIM_IC_Config\n
  1922. * CCMR2 CC3S LL_TIM_IC_Config\n
  1923. * CCMR2 IC3PSC LL_TIM_IC_Config\n
  1924. * CCMR2 IC3F LL_TIM_IC_Config\n
  1925. * CCMR2 CC4S LL_TIM_IC_Config\n
  1926. * CCMR2 IC4PSC LL_TIM_IC_Config\n
  1927. * CCMR2 IC4F LL_TIM_IC_Config\n
  1928. * CCER CC1P LL_TIM_IC_Config\n
  1929. * CCER CC1NP LL_TIM_IC_Config\n
  1930. * CCER CC2P LL_TIM_IC_Config\n
  1931. * CCER CC2NP LL_TIM_IC_Config\n
  1932. * CCER CC3P LL_TIM_IC_Config\n
  1933. * CCER CC3NP LL_TIM_IC_Config\n
  1934. * CCER CC4P LL_TIM_IC_Config\n
  1935. * @param TIMx Timer instance
  1936. * @param Channel This parameter can be one of the following values:
  1937. * @arg @ref LL_TIM_CHANNEL_CH1
  1938. * @arg @ref LL_TIM_CHANNEL_CH2
  1939. * @arg @ref LL_TIM_CHANNEL_CH3
  1940. * @arg @ref LL_TIM_CHANNEL_CH4
  1941. * @param Configuration This parameter must be a combination of all the following values:
  1942. * @arg @ref LL_TIM_ACTIVEINPUT_DIRECTTI or @ref LL_TIM_ACTIVEINPUT_INDIRECTTI or @ref LL_TIM_ACTIVEINPUT_TRC
  1943. * @arg @ref LL_TIM_ICPSC_DIV1 or ... or @ref LL_TIM_ICPSC_DIV8
  1944. * @arg @ref LL_TIM_IC_FILTER_FDIV1 or ... or @ref LL_TIM_IC_FILTER_FDIV32_N8
  1945. * @arg @ref LL_TIM_IC_POLARITY_RISING or @ref LL_TIM_IC_POLARITY_FALLING
  1946. * @retval None
  1947. */
  1948. __STATIC_INLINE void LL_TIM_IC_Config(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t Configuration)
  1949. {
  1950. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1951. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1952. MODIFY_REG(*pReg, ((TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC | TIM_CCMR1_CC1S) << SHIFT_TAB_ICxx[iChannel]),
  1953. ((Configuration >> 16U) & (TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC | TIM_CCMR1_CC1S)) \
  1954. << SHIFT_TAB_ICxx[iChannel]);
  1955. MODIFY_REG(TIMx->CCER, ((TIM_CCER_CC1NP | TIM_CCER_CC1P) << SHIFT_TAB_CCxP[iChannel]),
  1956. (Configuration & (TIM_CCER_CC1NP | TIM_CCER_CC1P)) << SHIFT_TAB_CCxP[iChannel]);
  1957. }
  1958. /**
  1959. * @brief Set the active input.
  1960. * @rmtoll CCMR1 CC1S LL_TIM_IC_SetActiveInput\n
  1961. * CCMR1 CC2S LL_TIM_IC_SetActiveInput\n
  1962. * CCMR2 CC3S LL_TIM_IC_SetActiveInput\n
  1963. * CCMR2 CC4S LL_TIM_IC_SetActiveInput
  1964. * @param TIMx Timer instance
  1965. * @param Channel This parameter can be one of the following values:
  1966. * @arg @ref LL_TIM_CHANNEL_CH1
  1967. * @arg @ref LL_TIM_CHANNEL_CH2
  1968. * @arg @ref LL_TIM_CHANNEL_CH3
  1969. * @arg @ref LL_TIM_CHANNEL_CH4
  1970. * @param ICActiveInput This parameter can be one of the following values:
  1971. * @arg @ref LL_TIM_ACTIVEINPUT_DIRECTTI
  1972. * @arg @ref LL_TIM_ACTIVEINPUT_INDIRECTTI
  1973. * @arg @ref LL_TIM_ACTIVEINPUT_TRC
  1974. * @retval None
  1975. */
  1976. __STATIC_INLINE void LL_TIM_IC_SetActiveInput(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ICActiveInput)
  1977. {
  1978. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1979. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1980. MODIFY_REG(*pReg, ((TIM_CCMR1_CC1S) << SHIFT_TAB_ICxx[iChannel]), (ICActiveInput >> 16U) << SHIFT_TAB_ICxx[iChannel]);
  1981. }
  1982. /**
  1983. * @brief Get the current active input.
  1984. * @rmtoll CCMR1 CC1S LL_TIM_IC_GetActiveInput\n
  1985. * CCMR1 CC2S LL_TIM_IC_GetActiveInput\n
  1986. * CCMR2 CC3S LL_TIM_IC_GetActiveInput\n
  1987. * CCMR2 CC4S LL_TIM_IC_GetActiveInput
  1988. * @param TIMx Timer instance
  1989. * @param Channel This parameter can be one of the following values:
  1990. * @arg @ref LL_TIM_CHANNEL_CH1
  1991. * @arg @ref LL_TIM_CHANNEL_CH2
  1992. * @arg @ref LL_TIM_CHANNEL_CH3
  1993. * @arg @ref LL_TIM_CHANNEL_CH4
  1994. * @retval Returned value can be one of the following values:
  1995. * @arg @ref LL_TIM_ACTIVEINPUT_DIRECTTI
  1996. * @arg @ref LL_TIM_ACTIVEINPUT_INDIRECTTI
  1997. * @arg @ref LL_TIM_ACTIVEINPUT_TRC
  1998. */
  1999. __STATIC_INLINE uint32_t LL_TIM_IC_GetActiveInput(TIM_TypeDef *TIMx, uint32_t Channel)
  2000. {
  2001. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2002. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2003. return ((READ_BIT(*pReg, ((TIM_CCMR1_CC1S) << SHIFT_TAB_ICxx[iChannel])) >> SHIFT_TAB_ICxx[iChannel]) << 16U);
  2004. }
  2005. /**
  2006. * @brief Set the prescaler of input channel.
  2007. * @rmtoll CCMR1 IC1PSC LL_TIM_IC_SetPrescaler\n
  2008. * CCMR1 IC2PSC LL_TIM_IC_SetPrescaler\n
  2009. * CCMR2 IC3PSC LL_TIM_IC_SetPrescaler\n
  2010. * CCMR2 IC4PSC LL_TIM_IC_SetPrescaler
  2011. * @param TIMx Timer instance
  2012. * @param Channel This parameter can be one of the following values:
  2013. * @arg @ref LL_TIM_CHANNEL_CH1
  2014. * @arg @ref LL_TIM_CHANNEL_CH2
  2015. * @arg @ref LL_TIM_CHANNEL_CH3
  2016. * @arg @ref LL_TIM_CHANNEL_CH4
  2017. * @param ICPrescaler This parameter can be one of the following values:
  2018. * @arg @ref LL_TIM_ICPSC_DIV1
  2019. * @arg @ref LL_TIM_ICPSC_DIV2
  2020. * @arg @ref LL_TIM_ICPSC_DIV4
  2021. * @arg @ref LL_TIM_ICPSC_DIV8
  2022. * @retval None
  2023. */
  2024. __STATIC_INLINE void LL_TIM_IC_SetPrescaler(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ICPrescaler)
  2025. {
  2026. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2027. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2028. MODIFY_REG(*pReg, ((TIM_CCMR1_IC1PSC) << SHIFT_TAB_ICxx[iChannel]), (ICPrescaler >> 16U) << SHIFT_TAB_ICxx[iChannel]);
  2029. }
  2030. /**
  2031. * @brief Get the current prescaler value acting on an input channel.
  2032. * @rmtoll CCMR1 IC1PSC LL_TIM_IC_GetPrescaler\n
  2033. * CCMR1 IC2PSC LL_TIM_IC_GetPrescaler\n
  2034. * CCMR2 IC3PSC LL_TIM_IC_GetPrescaler\n
  2035. * CCMR2 IC4PSC LL_TIM_IC_GetPrescaler
  2036. * @param TIMx Timer instance
  2037. * @param Channel This parameter can be one of the following values:
  2038. * @arg @ref LL_TIM_CHANNEL_CH1
  2039. * @arg @ref LL_TIM_CHANNEL_CH2
  2040. * @arg @ref LL_TIM_CHANNEL_CH3
  2041. * @arg @ref LL_TIM_CHANNEL_CH4
  2042. * @retval Returned value can be one of the following values:
  2043. * @arg @ref LL_TIM_ICPSC_DIV1
  2044. * @arg @ref LL_TIM_ICPSC_DIV2
  2045. * @arg @ref LL_TIM_ICPSC_DIV4
  2046. * @arg @ref LL_TIM_ICPSC_DIV8
  2047. */
  2048. __STATIC_INLINE uint32_t LL_TIM_IC_GetPrescaler(TIM_TypeDef *TIMx, uint32_t Channel)
  2049. {
  2050. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2051. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2052. return ((READ_BIT(*pReg, ((TIM_CCMR1_IC1PSC) << SHIFT_TAB_ICxx[iChannel])) >> SHIFT_TAB_ICxx[iChannel]) << 16U);
  2053. }
  2054. /**
  2055. * @brief Set the input filter duration.
  2056. * @rmtoll CCMR1 IC1F LL_TIM_IC_SetFilter\n
  2057. * CCMR1 IC2F LL_TIM_IC_SetFilter\n
  2058. * CCMR2 IC3F LL_TIM_IC_SetFilter\n
  2059. * CCMR2 IC4F LL_TIM_IC_SetFilter
  2060. * @param TIMx Timer instance
  2061. * @param Channel This parameter can be one of the following values:
  2062. * @arg @ref LL_TIM_CHANNEL_CH1
  2063. * @arg @ref LL_TIM_CHANNEL_CH2
  2064. * @arg @ref LL_TIM_CHANNEL_CH3
  2065. * @arg @ref LL_TIM_CHANNEL_CH4
  2066. * @param ICFilter This parameter can be one of the following values:
  2067. * @arg @ref LL_TIM_IC_FILTER_FDIV1
  2068. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N2
  2069. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N4
  2070. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N8
  2071. * @arg @ref LL_TIM_IC_FILTER_FDIV2_N6
  2072. * @arg @ref LL_TIM_IC_FILTER_FDIV2_N8
  2073. * @arg @ref LL_TIM_IC_FILTER_FDIV4_N6
  2074. * @arg @ref LL_TIM_IC_FILTER_FDIV4_N8
  2075. * @arg @ref LL_TIM_IC_FILTER_FDIV8_N6
  2076. * @arg @ref LL_TIM_IC_FILTER_FDIV8_N8
  2077. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N5
  2078. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N6
  2079. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N8
  2080. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N5
  2081. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N6
  2082. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N8
  2083. * @retval None
  2084. */
  2085. __STATIC_INLINE void LL_TIM_IC_SetFilter(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ICFilter)
  2086. {
  2087. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2088. __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2089. MODIFY_REG(*pReg, ((TIM_CCMR1_IC1F) << SHIFT_TAB_ICxx[iChannel]), (ICFilter >> 16U) << SHIFT_TAB_ICxx[iChannel]);
  2090. }
  2091. /**
  2092. * @brief Get the input filter duration.
  2093. * @rmtoll CCMR1 IC1F LL_TIM_IC_GetFilter\n
  2094. * CCMR1 IC2F LL_TIM_IC_GetFilter\n
  2095. * CCMR2 IC3F LL_TIM_IC_GetFilter\n
  2096. * CCMR2 IC4F LL_TIM_IC_GetFilter
  2097. * @param TIMx Timer instance
  2098. * @param Channel This parameter can be one of the following values:
  2099. * @arg @ref LL_TIM_CHANNEL_CH1
  2100. * @arg @ref LL_TIM_CHANNEL_CH2
  2101. * @arg @ref LL_TIM_CHANNEL_CH3
  2102. * @arg @ref LL_TIM_CHANNEL_CH4
  2103. * @retval Returned value can be one of the following values:
  2104. * @arg @ref LL_TIM_IC_FILTER_FDIV1
  2105. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N2
  2106. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N4
  2107. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N8
  2108. * @arg @ref LL_TIM_IC_FILTER_FDIV2_N6
  2109. * @arg @ref LL_TIM_IC_FILTER_FDIV2_N8
  2110. * @arg @ref LL_TIM_IC_FILTER_FDIV4_N6
  2111. * @arg @ref LL_TIM_IC_FILTER_FDIV4_N8
  2112. * @arg @ref LL_TIM_IC_FILTER_FDIV8_N6
  2113. * @arg @ref LL_TIM_IC_FILTER_FDIV8_N8
  2114. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N5
  2115. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N6
  2116. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N8
  2117. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N5
  2118. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N6
  2119. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N8
  2120. */
  2121. __STATIC_INLINE uint32_t LL_TIM_IC_GetFilter(TIM_TypeDef *TIMx, uint32_t Channel)
  2122. {
  2123. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2124. const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2125. return ((READ_BIT(*pReg, ((TIM_CCMR1_IC1F) << SHIFT_TAB_ICxx[iChannel])) >> SHIFT_TAB_ICxx[iChannel]) << 16U);
  2126. }
  2127. /**
  2128. * @brief Set the input channel polarity.
  2129. * @rmtoll CCER CC1P LL_TIM_IC_SetPolarity\n
  2130. * CCER CC1NP LL_TIM_IC_SetPolarity\n
  2131. * CCER CC2P LL_TIM_IC_SetPolarity\n
  2132. * CCER CC2NP LL_TIM_IC_SetPolarity\n
  2133. * CCER CC3P LL_TIM_IC_SetPolarity\n
  2134. * CCER CC3NP LL_TIM_IC_SetPolarity\n
  2135. * CCER CC4P LL_TIM_IC_SetPolarity\n
  2136. * @param TIMx Timer instance
  2137. * @param Channel This parameter can be one of the following values:
  2138. * @arg @ref LL_TIM_CHANNEL_CH1
  2139. * @arg @ref LL_TIM_CHANNEL_CH2
  2140. * @arg @ref LL_TIM_CHANNEL_CH3
  2141. * @arg @ref LL_TIM_CHANNEL_CH4
  2142. * @param ICPolarity This parameter can be one of the following values:
  2143. * @arg @ref LL_TIM_IC_POLARITY_RISING
  2144. * @arg @ref LL_TIM_IC_POLARITY_FALLING
  2145. * @retval None
  2146. */
  2147. __STATIC_INLINE void LL_TIM_IC_SetPolarity(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ICPolarity)
  2148. {
  2149. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2150. MODIFY_REG(TIMx->CCER, ((TIM_CCER_CC1NP | TIM_CCER_CC1P) << SHIFT_TAB_CCxP[iChannel]),
  2151. ICPolarity << SHIFT_TAB_CCxP[iChannel]);
  2152. }
  2153. /**
  2154. * @brief Get the current input channel polarity.
  2155. * @rmtoll CCER CC1P LL_TIM_IC_GetPolarity\n
  2156. * CCER CC1NP LL_TIM_IC_GetPolarity\n
  2157. * CCER CC2P LL_TIM_IC_GetPolarity\n
  2158. * CCER CC2NP LL_TIM_IC_GetPolarity\n
  2159. * CCER CC3P LL_TIM_IC_GetPolarity\n
  2160. * CCER CC3NP LL_TIM_IC_GetPolarity\n
  2161. * CCER CC4P LL_TIM_IC_GetPolarity\n
  2162. * @param TIMx Timer instance
  2163. * @param Channel This parameter can be one of the following values:
  2164. * @arg @ref LL_TIM_CHANNEL_CH1
  2165. * @arg @ref LL_TIM_CHANNEL_CH2
  2166. * @arg @ref LL_TIM_CHANNEL_CH3
  2167. * @arg @ref LL_TIM_CHANNEL_CH4
  2168. * @retval Returned value can be one of the following values:
  2169. * @arg @ref LL_TIM_IC_POLARITY_RISING
  2170. * @arg @ref LL_TIM_IC_POLARITY_FALLING
  2171. */
  2172. __STATIC_INLINE uint32_t LL_TIM_IC_GetPolarity(TIM_TypeDef *TIMx, uint32_t Channel)
  2173. {
  2174. uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2175. return (READ_BIT(TIMx->CCER, ((TIM_CCER_CC1NP | TIM_CCER_CC1P) << SHIFT_TAB_CCxP[iChannel])) >>
  2176. SHIFT_TAB_CCxP[iChannel]);
  2177. }
  2178. /**
  2179. * @brief Connect the TIMx_CH1, CH2 and CH3 pins to the TI1 input (XOR combination).
  2180. * @note Macro IS_TIM_XOR_INSTANCE(TIMx) can be used to check whether or not
  2181. * a timer instance provides an XOR input.
  2182. * @rmtoll CR2 TI1S LL_TIM_IC_EnableXORCombination
  2183. * @param TIMx Timer instance
  2184. * @retval None
  2185. */
  2186. __STATIC_INLINE void LL_TIM_IC_EnableXORCombination(TIM_TypeDef *TIMx)
  2187. {
  2188. SET_BIT(TIMx->CR2, TIM_CR2_TI1S);
  2189. }
  2190. /**
  2191. * @brief Disconnect the TIMx_CH1, CH2 and CH3 pins from the TI1 input.
  2192. * @note Macro IS_TIM_XOR_INSTANCE(TIMx) can be used to check whether or not
  2193. * a timer instance provides an XOR input.
  2194. * @rmtoll CR2 TI1S LL_TIM_IC_DisableXORCombination
  2195. * @param TIMx Timer instance
  2196. * @retval None
  2197. */
  2198. __STATIC_INLINE void LL_TIM_IC_DisableXORCombination(TIM_TypeDef *TIMx)
  2199. {
  2200. CLEAR_BIT(TIMx->CR2, TIM_CR2_TI1S);
  2201. }
  2202. /**
  2203. * @brief Indicates whether the TIMx_CH1, CH2 and CH3 pins are connectected to the TI1 input.
  2204. * @note Macro IS_TIM_XOR_INSTANCE(TIMx) can be used to check whether or not
  2205. * a timer instance provides an XOR input.
  2206. * @rmtoll CR2 TI1S LL_TIM_IC_IsEnabledXORCombination
  2207. * @param TIMx Timer instance
  2208. * @retval State of bit (1 or 0).
  2209. */
  2210. __STATIC_INLINE uint32_t LL_TIM_IC_IsEnabledXORCombination(TIM_TypeDef *TIMx)
  2211. {
  2212. return ((READ_BIT(TIMx->CR2, TIM_CR2_TI1S) == (TIM_CR2_TI1S)) ? 1UL : 0UL);
  2213. }
  2214. /**
  2215. * @brief Get captured value for input channel 1.
  2216. * @note Macro IS_TIM_CC1_INSTANCE(TIMx) can be used to check whether or not
  2217. * input channel 1 is supported by a timer instance.
  2218. * @rmtoll CCR1 CCR1 LL_TIM_IC_GetCaptureCH1
  2219. * @param TIMx Timer instance
  2220. * @retval CapturedValue (between Min_Data=0 and Max_Data=65535)
  2221. */
  2222. __STATIC_INLINE uint32_t LL_TIM_IC_GetCaptureCH1(TIM_TypeDef *TIMx)
  2223. {
  2224. return (uint32_t)(READ_REG(TIMx->CCR1));
  2225. }
  2226. /**
  2227. * @brief Get captured value for input channel 2.
  2228. * @note Macro IS_TIM_CC2_INSTANCE(TIMx) can be used to check whether or not
  2229. * input channel 2 is supported by a timer instance.
  2230. * @rmtoll CCR2 CCR2 LL_TIM_IC_GetCaptureCH2
  2231. * @param TIMx Timer instance
  2232. * @retval CapturedValue (between Min_Data=0 and Max_Data=65535)
  2233. */
  2234. __STATIC_INLINE uint32_t LL_TIM_IC_GetCaptureCH2(TIM_TypeDef *TIMx)
  2235. {
  2236. return (uint32_t)(READ_REG(TIMx->CCR2));
  2237. }
  2238. /**
  2239. * @brief Get captured value for input channel 3.
  2240. * @note Macro IS_TIM_CC3_INSTANCE(TIMx) can be used to check whether or not
  2241. * input channel 3 is supported by a timer instance.
  2242. * @rmtoll CCR3 CCR3 LL_TIM_IC_GetCaptureCH3
  2243. * @param TIMx Timer instance
  2244. * @retval CapturedValue (between Min_Data=0 and Max_Data=65535)
  2245. */
  2246. __STATIC_INLINE uint32_t LL_TIM_IC_GetCaptureCH3(TIM_TypeDef *TIMx)
  2247. {
  2248. return (uint32_t)(READ_REG(TIMx->CCR3));
  2249. }
  2250. /**
  2251. * @brief Get captured value for input channel 4.
  2252. * @note Macro IS_TIM_CC4_INSTANCE(TIMx) can be used to check whether or not
  2253. * input channel 4 is supported by a timer instance.
  2254. * @rmtoll CCR4 CCR4 LL_TIM_IC_GetCaptureCH4
  2255. * @param TIMx Timer instance
  2256. * @retval CapturedValue (between Min_Data=0 and Max_Data=65535)
  2257. */
  2258. __STATIC_INLINE uint32_t LL_TIM_IC_GetCaptureCH4(TIM_TypeDef *TIMx)
  2259. {
  2260. return (uint32_t)(READ_REG(TIMx->CCR4));
  2261. }
  2262. /**
  2263. * @}
  2264. */
  2265. /** @defgroup TIM_LL_EF_Clock_Selection Counter clock selection
  2266. * @{
  2267. */
  2268. /**
  2269. * @brief Enable external clock mode 2.
  2270. * @note When external clock mode 2 is enabled the counter is clocked by any active edge on the ETRF signal.
  2271. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(TIMx) can be used to check
  2272. * whether or not a timer instance supports external clock mode2.
  2273. * @rmtoll SMCR ECE LL_TIM_EnableExternalClock
  2274. * @param TIMx Timer instance
  2275. * @retval None
  2276. */
  2277. __STATIC_INLINE void LL_TIM_EnableExternalClock(TIM_TypeDef *TIMx)
  2278. {
  2279. SET_BIT(TIMx->SMCR, TIM_SMCR_ECE);
  2280. }
  2281. /**
  2282. * @brief Disable external clock mode 2.
  2283. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(TIMx) can be used to check
  2284. * whether or not a timer instance supports external clock mode2.
  2285. * @rmtoll SMCR ECE LL_TIM_DisableExternalClock
  2286. * @param TIMx Timer instance
  2287. * @retval None
  2288. */
  2289. __STATIC_INLINE void LL_TIM_DisableExternalClock(TIM_TypeDef *TIMx)
  2290. {
  2291. CLEAR_BIT(TIMx->SMCR, TIM_SMCR_ECE);
  2292. }
  2293. /**
  2294. * @brief Indicate whether external clock mode 2 is enabled.
  2295. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(TIMx) can be used to check
  2296. * whether or not a timer instance supports external clock mode2.
  2297. * @rmtoll SMCR ECE LL_TIM_IsEnabledExternalClock
  2298. * @param TIMx Timer instance
  2299. * @retval State of bit (1 or 0).
  2300. */
  2301. __STATIC_INLINE uint32_t LL_TIM_IsEnabledExternalClock(TIM_TypeDef *TIMx)
  2302. {
  2303. return ((READ_BIT(TIMx->SMCR, TIM_SMCR_ECE) == (TIM_SMCR_ECE)) ? 1UL : 0UL);
  2304. }
  2305. /**
  2306. * @brief Set the clock source of the counter clock.
  2307. * @note when selected clock source is external clock mode 1, the timer input
  2308. * the external clock is applied is selected by calling the @ref LL_TIM_SetTriggerInput()
  2309. * function. This timer input must be configured by calling
  2310. * the @ref LL_TIM_IC_Config() function.
  2311. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(TIMx) can be used to check
  2312. * whether or not a timer instance supports external clock mode1.
  2313. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(TIMx) can be used to check
  2314. * whether or not a timer instance supports external clock mode2.
  2315. * @rmtoll SMCR SMS LL_TIM_SetClockSource\n
  2316. * SMCR ECE LL_TIM_SetClockSource
  2317. * @param TIMx Timer instance
  2318. * @param ClockSource This parameter can be one of the following values:
  2319. * @arg @ref LL_TIM_CLOCKSOURCE_INTERNAL
  2320. * @arg @ref LL_TIM_CLOCKSOURCE_EXT_MODE1
  2321. * @arg @ref LL_TIM_CLOCKSOURCE_EXT_MODE2
  2322. * @retval None
  2323. */
  2324. __STATIC_INLINE void LL_TIM_SetClockSource(TIM_TypeDef *TIMx, uint32_t ClockSource)
  2325. {
  2326. MODIFY_REG(TIMx->SMCR, TIM_SMCR_SMS | TIM_SMCR_ECE, ClockSource);
  2327. }
  2328. /**
  2329. * @brief Set the encoder interface mode.
  2330. * @note Macro IS_TIM_ENCODER_INTERFACE_INSTANCE(TIMx) can be used to check
  2331. * whether or not a timer instance supports the encoder mode.
  2332. * @rmtoll SMCR SMS LL_TIM_SetEncoderMode
  2333. * @param TIMx Timer instance
  2334. * @param EncoderMode This parameter can be one of the following values:
  2335. * @arg @ref LL_TIM_ENCODERMODE_X2_TI1
  2336. * @arg @ref LL_TIM_ENCODERMODE_X2_TI2
  2337. * @arg @ref LL_TIM_ENCODERMODE_X4_TI12
  2338. * @retval None
  2339. */
  2340. __STATIC_INLINE void LL_TIM_SetEncoderMode(TIM_TypeDef *TIMx, uint32_t EncoderMode)
  2341. {
  2342. MODIFY_REG(TIMx->SMCR, TIM_SMCR_SMS, EncoderMode);
  2343. }
  2344. /**
  2345. * @}
  2346. */
  2347. /** @defgroup TIM_LL_EF_Timer_Synchronization Timer synchronisation configuration
  2348. * @{
  2349. */
  2350. /**
  2351. * @brief Set the trigger output (TRGO) used for timer synchronization .
  2352. * @note Macro IS_TIM_MASTER_INSTANCE(TIMx) can be used to check
  2353. * whether or not a timer instance can operate as a master timer.
  2354. * @rmtoll CR2 MMS LL_TIM_SetTriggerOutput
  2355. * @param TIMx Timer instance
  2356. * @param TimerSynchronization This parameter can be one of the following values:
  2357. * @arg @ref LL_TIM_TRGO_RESET
  2358. * @arg @ref LL_TIM_TRGO_ENABLE
  2359. * @arg @ref LL_TIM_TRGO_UPDATE
  2360. * @arg @ref LL_TIM_TRGO_CC1IF
  2361. * @arg @ref LL_TIM_TRGO_OC1REF
  2362. * @arg @ref LL_TIM_TRGO_OC2REF
  2363. * @arg @ref LL_TIM_TRGO_OC3REF
  2364. * @arg @ref LL_TIM_TRGO_OC4REF
  2365. * @retval None
  2366. */
  2367. __STATIC_INLINE void LL_TIM_SetTriggerOutput(TIM_TypeDef *TIMx, uint32_t TimerSynchronization)
  2368. {
  2369. MODIFY_REG(TIMx->CR2, TIM_CR2_MMS, TimerSynchronization);
  2370. }
  2371. /**
  2372. * @brief Set the synchronization mode of a slave timer.
  2373. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2374. * a timer instance can operate as a slave timer.
  2375. * @rmtoll SMCR SMS LL_TIM_SetSlaveMode
  2376. * @param TIMx Timer instance
  2377. * @param SlaveMode This parameter can be one of the following values:
  2378. * @arg @ref LL_TIM_SLAVEMODE_DISABLED
  2379. * @arg @ref LL_TIM_SLAVEMODE_RESET
  2380. * @arg @ref LL_TIM_SLAVEMODE_GATED
  2381. * @arg @ref LL_TIM_SLAVEMODE_TRIGGER
  2382. * @retval None
  2383. */
  2384. __STATIC_INLINE void LL_TIM_SetSlaveMode(TIM_TypeDef *TIMx, uint32_t SlaveMode)
  2385. {
  2386. MODIFY_REG(TIMx->SMCR, TIM_SMCR_SMS, SlaveMode);
  2387. }
  2388. /**
  2389. * @brief Set the selects the trigger input to be used to synchronize the counter.
  2390. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2391. * a timer instance can operate as a slave timer.
  2392. * @rmtoll SMCR TS LL_TIM_SetTriggerInput
  2393. * @param TIMx Timer instance
  2394. * @param TriggerInput This parameter can be one of the following values:
  2395. * @arg @ref LL_TIM_TS_ITR0
  2396. * @arg @ref LL_TIM_TS_ITR1
  2397. * @arg @ref LL_TIM_TS_ITR2
  2398. * @arg @ref LL_TIM_TS_ITR3
  2399. * @arg @ref LL_TIM_TS_TI1F_ED
  2400. * @arg @ref LL_TIM_TS_TI1FP1
  2401. * @arg @ref LL_TIM_TS_TI2FP2
  2402. * @arg @ref LL_TIM_TS_ETRF
  2403. * @retval None
  2404. */
  2405. __STATIC_INLINE void LL_TIM_SetTriggerInput(TIM_TypeDef *TIMx, uint32_t TriggerInput)
  2406. {
  2407. MODIFY_REG(TIMx->SMCR, TIM_SMCR_TS, TriggerInput);
  2408. }
  2409. /**
  2410. * @brief Enable the Master/Slave mode.
  2411. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2412. * a timer instance can operate as a slave timer.
  2413. * @rmtoll SMCR MSM LL_TIM_EnableMasterSlaveMode
  2414. * @param TIMx Timer instance
  2415. * @retval None
  2416. */
  2417. __STATIC_INLINE void LL_TIM_EnableMasterSlaveMode(TIM_TypeDef *TIMx)
  2418. {
  2419. SET_BIT(TIMx->SMCR, TIM_SMCR_MSM);
  2420. }
  2421. /**
  2422. * @brief Disable the Master/Slave mode.
  2423. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2424. * a timer instance can operate as a slave timer.
  2425. * @rmtoll SMCR MSM LL_TIM_DisableMasterSlaveMode
  2426. * @param TIMx Timer instance
  2427. * @retval None
  2428. */
  2429. __STATIC_INLINE void LL_TIM_DisableMasterSlaveMode(TIM_TypeDef *TIMx)
  2430. {
  2431. CLEAR_BIT(TIMx->SMCR, TIM_SMCR_MSM);
  2432. }
  2433. /**
  2434. * @brief Indicates whether the Master/Slave mode is enabled.
  2435. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2436. * a timer instance can operate as a slave timer.
  2437. * @rmtoll SMCR MSM LL_TIM_IsEnabledMasterSlaveMode
  2438. * @param TIMx Timer instance
  2439. * @retval State of bit (1 or 0).
  2440. */
  2441. __STATIC_INLINE uint32_t LL_TIM_IsEnabledMasterSlaveMode(TIM_TypeDef *TIMx)
  2442. {
  2443. return ((READ_BIT(TIMx->SMCR, TIM_SMCR_MSM) == (TIM_SMCR_MSM)) ? 1UL : 0UL);
  2444. }
  2445. /**
  2446. * @brief Configure the external trigger (ETR) input.
  2447. * @note Macro IS_TIM_ETR_INSTANCE(TIMx) can be used to check whether or not
  2448. * a timer instance provides an external trigger input.
  2449. * @rmtoll SMCR ETP LL_TIM_ConfigETR\n
  2450. * SMCR ETPS LL_TIM_ConfigETR\n
  2451. * SMCR ETF LL_TIM_ConfigETR
  2452. * @param TIMx Timer instance
  2453. * @param ETRPolarity This parameter can be one of the following values:
  2454. * @arg @ref LL_TIM_ETR_POLARITY_NONINVERTED
  2455. * @arg @ref LL_TIM_ETR_POLARITY_INVERTED
  2456. * @param ETRPrescaler This parameter can be one of the following values:
  2457. * @arg @ref LL_TIM_ETR_PRESCALER_DIV1
  2458. * @arg @ref LL_TIM_ETR_PRESCALER_DIV2
  2459. * @arg @ref LL_TIM_ETR_PRESCALER_DIV4
  2460. * @arg @ref LL_TIM_ETR_PRESCALER_DIV8
  2461. * @param ETRFilter This parameter can be one of the following values:
  2462. * @arg @ref LL_TIM_ETR_FILTER_FDIV1
  2463. * @arg @ref LL_TIM_ETR_FILTER_FDIV1_N2
  2464. * @arg @ref LL_TIM_ETR_FILTER_FDIV1_N4
  2465. * @arg @ref LL_TIM_ETR_FILTER_FDIV1_N8
  2466. * @arg @ref LL_TIM_ETR_FILTER_FDIV2_N6
  2467. * @arg @ref LL_TIM_ETR_FILTER_FDIV2_N8
  2468. * @arg @ref LL_TIM_ETR_FILTER_FDIV4_N6
  2469. * @arg @ref LL_TIM_ETR_FILTER_FDIV4_N8
  2470. * @arg @ref LL_TIM_ETR_FILTER_FDIV8_N6
  2471. * @arg @ref LL_TIM_ETR_FILTER_FDIV8_N8
  2472. * @arg @ref LL_TIM_ETR_FILTER_FDIV16_N5
  2473. * @arg @ref LL_TIM_ETR_FILTER_FDIV16_N6
  2474. * @arg @ref LL_TIM_ETR_FILTER_FDIV16_N8
  2475. * @arg @ref LL_TIM_ETR_FILTER_FDIV32_N5
  2476. * @arg @ref LL_TIM_ETR_FILTER_FDIV32_N6
  2477. * @arg @ref LL_TIM_ETR_FILTER_FDIV32_N8
  2478. * @retval None
  2479. */
  2480. __STATIC_INLINE void LL_TIM_ConfigETR(TIM_TypeDef *TIMx, uint32_t ETRPolarity, uint32_t ETRPrescaler,
  2481. uint32_t ETRFilter)
  2482. {
  2483. MODIFY_REG(TIMx->SMCR, TIM_SMCR_ETP | TIM_SMCR_ETPS | TIM_SMCR_ETF, ETRPolarity | ETRPrescaler | ETRFilter);
  2484. }
  2485. /**
  2486. * @}
  2487. */
  2488. /** @defgroup TIM_LL_EF_Break_Function Break function configuration
  2489. * @{
  2490. */
  2491. /**
  2492. * @brief Enable the break function.
  2493. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2494. * a timer instance provides a break input.
  2495. * @rmtoll BDTR BKE LL_TIM_EnableBRK
  2496. * @param TIMx Timer instance
  2497. * @retval None
  2498. */
  2499. __STATIC_INLINE void LL_TIM_EnableBRK(TIM_TypeDef *TIMx)
  2500. {
  2501. __IO uint32_t tmpreg;
  2502. SET_BIT(TIMx->BDTR, TIM_BDTR_BKE);
  2503. /* Note: Any write operation to this bit takes a delay of 1 APB clock cycle to become effective. */
  2504. tmpreg = READ_REG(TIMx->BDTR);
  2505. (void)(tmpreg);
  2506. }
  2507. /**
  2508. * @brief Disable the break function.
  2509. * @rmtoll BDTR BKE LL_TIM_DisableBRK
  2510. * @param TIMx Timer instance
  2511. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2512. * a timer instance provides a break input.
  2513. * @retval None
  2514. */
  2515. __STATIC_INLINE void LL_TIM_DisableBRK(TIM_TypeDef *TIMx)
  2516. {
  2517. __IO uint32_t tmpreg;
  2518. CLEAR_BIT(TIMx->BDTR, TIM_BDTR_BKE);
  2519. /* Note: Any write operation to this bit takes a delay of 1 APB clock cycle to become effective. */
  2520. tmpreg = READ_REG(TIMx->BDTR);
  2521. (void)(tmpreg);
  2522. }
  2523. /**
  2524. * @brief Configure the break input.
  2525. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2526. * a timer instance provides a break input.
  2527. * @rmtoll BDTR BKP LL_TIM_ConfigBRK
  2528. * @param TIMx Timer instance
  2529. * @param BreakPolarity This parameter can be one of the following values:
  2530. * @arg @ref LL_TIM_BREAK_POLARITY_LOW
  2531. * @arg @ref LL_TIM_BREAK_POLARITY_HIGH
  2532. * @retval None
  2533. */
  2534. __STATIC_INLINE void LL_TIM_ConfigBRK(TIM_TypeDef *TIMx, uint32_t BreakPolarity)
  2535. {
  2536. __IO uint32_t tmpreg;
  2537. MODIFY_REG(TIMx->BDTR, TIM_BDTR_BKP, BreakPolarity);
  2538. /* Note: Any write operation to BKP bit takes a delay of 1 APB clock cycle to become effective. */
  2539. tmpreg = READ_REG(TIMx->BDTR);
  2540. (void)(tmpreg);
  2541. }
  2542. /**
  2543. * @brief Select the outputs off state (enabled v.s. disabled) in Idle and Run modes.
  2544. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2545. * a timer instance provides a break input.
  2546. * @rmtoll BDTR OSSI LL_TIM_SetOffStates\n
  2547. * BDTR OSSR LL_TIM_SetOffStates
  2548. * @param TIMx Timer instance
  2549. * @param OffStateIdle This parameter can be one of the following values:
  2550. * @arg @ref LL_TIM_OSSI_DISABLE
  2551. * @arg @ref LL_TIM_OSSI_ENABLE
  2552. * @param OffStateRun This parameter can be one of the following values:
  2553. * @arg @ref LL_TIM_OSSR_DISABLE
  2554. * @arg @ref LL_TIM_OSSR_ENABLE
  2555. * @retval None
  2556. */
  2557. __STATIC_INLINE void LL_TIM_SetOffStates(TIM_TypeDef *TIMx, uint32_t OffStateIdle, uint32_t OffStateRun)
  2558. {
  2559. MODIFY_REG(TIMx->BDTR, TIM_BDTR_OSSI | TIM_BDTR_OSSR, OffStateIdle | OffStateRun);
  2560. }
  2561. /**
  2562. * @brief Enable automatic output (MOE can be set by software or automatically when a break input is active).
  2563. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2564. * a timer instance provides a break input.
  2565. * @rmtoll BDTR AOE LL_TIM_EnableAutomaticOutput
  2566. * @param TIMx Timer instance
  2567. * @retval None
  2568. */
  2569. __STATIC_INLINE void LL_TIM_EnableAutomaticOutput(TIM_TypeDef *TIMx)
  2570. {
  2571. SET_BIT(TIMx->BDTR, TIM_BDTR_AOE);
  2572. }
  2573. /**
  2574. * @brief Disable automatic output (MOE can be set only by software).
  2575. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2576. * a timer instance provides a break input.
  2577. * @rmtoll BDTR AOE LL_TIM_DisableAutomaticOutput
  2578. * @param TIMx Timer instance
  2579. * @retval None
  2580. */
  2581. __STATIC_INLINE void LL_TIM_DisableAutomaticOutput(TIM_TypeDef *TIMx)
  2582. {
  2583. CLEAR_BIT(TIMx->BDTR, TIM_BDTR_AOE);
  2584. }
  2585. /**
  2586. * @brief Indicate whether automatic output is enabled.
  2587. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2588. * a timer instance provides a break input.
  2589. * @rmtoll BDTR AOE LL_TIM_IsEnabledAutomaticOutput
  2590. * @param TIMx Timer instance
  2591. * @retval State of bit (1 or 0).
  2592. */
  2593. __STATIC_INLINE uint32_t LL_TIM_IsEnabledAutomaticOutput(TIM_TypeDef *TIMx)
  2594. {
  2595. return ((READ_BIT(TIMx->BDTR, TIM_BDTR_AOE) == (TIM_BDTR_AOE)) ? 1UL : 0UL);
  2596. }
  2597. /**
  2598. * @brief Enable the outputs (set the MOE bit in TIMx_BDTR register).
  2599. * @note The MOE bit in TIMx_BDTR register allows to enable /disable the outputs by
  2600. * software and is reset in case of break or break2 event
  2601. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2602. * a timer instance provides a break input.
  2603. * @rmtoll BDTR MOE LL_TIM_EnableAllOutputs
  2604. * @param TIMx Timer instance
  2605. * @retval None
  2606. */
  2607. __STATIC_INLINE void LL_TIM_EnableAllOutputs(TIM_TypeDef *TIMx)
  2608. {
  2609. SET_BIT(TIMx->BDTR, TIM_BDTR_MOE);
  2610. }
  2611. /**
  2612. * @brief Disable the outputs (reset the MOE bit in TIMx_BDTR register).
  2613. * @note The MOE bit in TIMx_BDTR register allows to enable /disable the outputs by
  2614. * software and is reset in case of break or break2 event.
  2615. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2616. * a timer instance provides a break input.
  2617. * @rmtoll BDTR MOE LL_TIM_DisableAllOutputs
  2618. * @param TIMx Timer instance
  2619. * @retval None
  2620. */
  2621. __STATIC_INLINE void LL_TIM_DisableAllOutputs(TIM_TypeDef *TIMx)
  2622. {
  2623. CLEAR_BIT(TIMx->BDTR, TIM_BDTR_MOE);
  2624. }
  2625. /**
  2626. * @brief Indicates whether outputs are enabled.
  2627. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2628. * a timer instance provides a break input.
  2629. * @rmtoll BDTR MOE LL_TIM_IsEnabledAllOutputs
  2630. * @param TIMx Timer instance
  2631. * @retval State of bit (1 or 0).
  2632. */
  2633. __STATIC_INLINE uint32_t LL_TIM_IsEnabledAllOutputs(TIM_TypeDef *TIMx)
  2634. {
  2635. return ((READ_BIT(TIMx->BDTR, TIM_BDTR_MOE) == (TIM_BDTR_MOE)) ? 1UL : 0UL);
  2636. }
  2637. /**
  2638. * @}
  2639. */
  2640. /** @defgroup TIM_LL_EF_DMA_Burst_Mode DMA burst mode configuration
  2641. * @{
  2642. */
  2643. /**
  2644. * @brief Configures the timer DMA burst feature.
  2645. * @note Macro IS_TIM_DMABURST_INSTANCE(TIMx) can be used to check whether or
  2646. * not a timer instance supports the DMA burst mode.
  2647. * @rmtoll DCR DBL LL_TIM_ConfigDMABurst\n
  2648. * DCR DBA LL_TIM_ConfigDMABurst
  2649. * @param TIMx Timer instance
  2650. * @param DMABurstBaseAddress This parameter can be one of the following values:
  2651. * @arg @ref LL_TIM_DMABURST_BASEADDR_CR1
  2652. * @arg @ref LL_TIM_DMABURST_BASEADDR_CR2
  2653. * @arg @ref LL_TIM_DMABURST_BASEADDR_SMCR
  2654. * @arg @ref LL_TIM_DMABURST_BASEADDR_DIER
  2655. * @arg @ref LL_TIM_DMABURST_BASEADDR_SR
  2656. * @arg @ref LL_TIM_DMABURST_BASEADDR_EGR
  2657. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCMR1
  2658. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCMR2
  2659. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCER
  2660. * @arg @ref LL_TIM_DMABURST_BASEADDR_CNT
  2661. * @arg @ref LL_TIM_DMABURST_BASEADDR_PSC
  2662. * @arg @ref LL_TIM_DMABURST_BASEADDR_ARR
  2663. * @arg @ref LL_TIM_DMABURST_BASEADDR_RCR
  2664. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCR1
  2665. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCR2
  2666. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCR3
  2667. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCR4
  2668. * @arg @ref LL_TIM_DMABURST_BASEADDR_BDTR
  2669. * @param DMABurstLength This parameter can be one of the following values:
  2670. * @arg @ref LL_TIM_DMABURST_LENGTH_1TRANSFER
  2671. * @arg @ref LL_TIM_DMABURST_LENGTH_2TRANSFERS
  2672. * @arg @ref LL_TIM_DMABURST_LENGTH_3TRANSFERS
  2673. * @arg @ref LL_TIM_DMABURST_LENGTH_4TRANSFERS
  2674. * @arg @ref LL_TIM_DMABURST_LENGTH_5TRANSFERS
  2675. * @arg @ref LL_TIM_DMABURST_LENGTH_6TRANSFERS
  2676. * @arg @ref LL_TIM_DMABURST_LENGTH_7TRANSFERS
  2677. * @arg @ref LL_TIM_DMABURST_LENGTH_8TRANSFERS
  2678. * @arg @ref LL_TIM_DMABURST_LENGTH_9TRANSFERS
  2679. * @arg @ref LL_TIM_DMABURST_LENGTH_10TRANSFERS
  2680. * @arg @ref LL_TIM_DMABURST_LENGTH_11TRANSFERS
  2681. * @arg @ref LL_TIM_DMABURST_LENGTH_12TRANSFERS
  2682. * @arg @ref LL_TIM_DMABURST_LENGTH_13TRANSFERS
  2683. * @arg @ref LL_TIM_DMABURST_LENGTH_14TRANSFERS
  2684. * @arg @ref LL_TIM_DMABURST_LENGTH_15TRANSFERS
  2685. * @arg @ref LL_TIM_DMABURST_LENGTH_16TRANSFERS
  2686. * @arg @ref LL_TIM_DMABURST_LENGTH_17TRANSFERS
  2687. * @arg @ref LL_TIM_DMABURST_LENGTH_18TRANSFERS
  2688. * @retval None
  2689. */
  2690. __STATIC_INLINE void LL_TIM_ConfigDMABurst(TIM_TypeDef *TIMx, uint32_t DMABurstBaseAddress, uint32_t DMABurstLength)
  2691. {
  2692. MODIFY_REG(TIMx->DCR, (TIM_DCR_DBL | TIM_DCR_DBA), (DMABurstBaseAddress | DMABurstLength));
  2693. }
  2694. /**
  2695. * @}
  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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(TIM_TypeDef *TIMx);
  3503. void LL_TIM_StructInit(LL_TIM_InitTypeDef *TIM_InitStruct);
  3504. ErrorStatus LL_TIM_Init(TIM_TypeDef *TIMx, 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, 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, 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, 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, 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, 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 */
  3533. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/