stm32f3xx_hal_tim.c 248 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_hal_tim.c
  4. * @author MCD Application Team
  5. * @brief TIM HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Timer (TIM) peripheral:
  8. * + TIM Time Base Initialization
  9. * + TIM Time Base Start
  10. * + TIM Time Base Start Interruption
  11. * + TIM Time Base Start DMA
  12. * + TIM Output Compare/PWM Initialization
  13. * + TIM Output Compare/PWM Channel Configuration
  14. * + TIM Output Compare/PWM Start
  15. * + TIM Output Compare/PWM Start Interruption
  16. * + TIM Output Compare/PWM Start DMA
  17. * + TIM Input Capture Initialization
  18. * + TIM Input Capture Channel Configuration
  19. * + TIM Input Capture Start
  20. * + TIM Input Capture Start Interruption
  21. * + TIM Input Capture Start DMA
  22. * + TIM One Pulse Initialization
  23. * + TIM One Pulse Channel Configuration
  24. * + TIM One Pulse Start
  25. * + TIM Encoder Interface Initialization
  26. * + TIM Encoder Interface Start
  27. * + TIM Encoder Interface Start Interruption
  28. * + TIM Encoder Interface Start DMA
  29. * + Commutation Event configuration with Interruption and DMA
  30. * + TIM OCRef clear configuration
  31. * + TIM External Clock configuration
  32. ******************************************************************************
  33. * @attention
  34. *
  35. * Copyright (c) 2016 STMicroelectronics.
  36. * All rights reserved.
  37. *
  38. * This software is licensed under terms that can be found in the LICENSE file
  39. * in the root directory of this software component.
  40. * If no LICENSE file comes with this software, it is provided AS-IS.
  41. *
  42. ******************************************************************************
  43. @verbatim
  44. ==============================================================================
  45. ##### TIMER Generic features #####
  46. ==============================================================================
  47. [..] The Timer features include:
  48. (#) 16-bit up, down, up/down auto-reload counter.
  49. (#) 16-bit programmable prescaler allowing dividing (also on the fly) the
  50. counter clock frequency either by any factor between 1 and 65536.
  51. (#) Up to 4 independent channels for:
  52. (++) Input Capture
  53. (++) Output Compare
  54. (++) PWM generation (Edge and Center-aligned Mode)
  55. (++) One-pulse mode output
  56. (#) Synchronization circuit to control the timer with external signals and to interconnect
  57. several timers together.
  58. (#) Supports incremental encoder for positioning purposes
  59. ##### How to use this driver #####
  60. ==============================================================================
  61. [..]
  62. (#) Initialize the TIM low level resources by implementing the following functions
  63. depending on the selected feature:
  64. (++) Time Base : HAL_TIM_Base_MspInit()
  65. (++) Input Capture : HAL_TIM_IC_MspInit()
  66. (++) Output Compare : HAL_TIM_OC_MspInit()
  67. (++) PWM generation : HAL_TIM_PWM_MspInit()
  68. (++) One-pulse mode output : HAL_TIM_OnePulse_MspInit()
  69. (++) Encoder mode output : HAL_TIM_Encoder_MspInit()
  70. (#) Initialize the TIM low level resources :
  71. (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE();
  72. (##) TIM pins configuration
  73. (+++) Enable the clock for the TIM GPIOs using the following function:
  74. __HAL_RCC_GPIOx_CLK_ENABLE();
  75. (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
  76. (#) The external Clock can be configured, if needed (the default clock is the
  77. internal clock from the APBx), using the following function:
  78. HAL_TIM_ConfigClockSource, the clock configuration should be done before
  79. any start function.
  80. (#) Configure the TIM in the desired functioning mode using one of the
  81. Initialization function of this driver:
  82. (++) HAL_TIM_Base_Init: to use the Timer to generate a simple time base
  83. (++) HAL_TIM_OC_Init and HAL_TIM_OC_ConfigChannel: to use the Timer to generate an
  84. Output Compare signal.
  85. (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a
  86. PWM signal.
  87. (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an
  88. external signal.
  89. (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer
  90. in One Pulse Mode.
  91. (++) HAL_TIM_Encoder_Init: to use the Timer Encoder Interface.
  92. (#) Activate the TIM peripheral using one of the start functions depending from the feature used:
  93. (++) Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), HAL_TIM_Base_Start_IT()
  94. (++) Input Capture : HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), HAL_TIM_IC_Start_IT()
  95. (++) Output Compare : HAL_TIM_OC_Start(), HAL_TIM_OC_Start_DMA(), HAL_TIM_OC_Start_IT()
  96. (++) PWM generation : HAL_TIM_PWM_Start(), HAL_TIM_PWM_Start_DMA(), HAL_TIM_PWM_Start_IT()
  97. (++) One-pulse mode output : HAL_TIM_OnePulse_Start(), HAL_TIM_OnePulse_Start_IT()
  98. (++) Encoder mode output : HAL_TIM_Encoder_Start(), HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT().
  99. (#) The DMA Burst is managed with the two following functions:
  100. HAL_TIM_DMABurst_WriteStart()
  101. HAL_TIM_DMABurst_ReadStart()
  102. *** Callback registration ***
  103. =============================================
  104. [..]
  105. The compilation define USE_HAL_TIM_REGISTER_CALLBACKS when set to 1
  106. allows the user to configure dynamically the driver callbacks.
  107. [..]
  108. Use Function HAL_TIM_RegisterCallback() to register a callback.
  109. HAL_TIM_RegisterCallback() takes as parameters the HAL peripheral handle,
  110. the Callback ID and a pointer to the user callback function.
  111. [..]
  112. Use function HAL_TIM_UnRegisterCallback() to reset a callback to the default
  113. weak function.
  114. HAL_TIM_UnRegisterCallback takes as parameters the HAL peripheral handle,
  115. and the Callback ID.
  116. [..]
  117. These functions allow to register/unregister following callbacks:
  118. (+) Base_MspInitCallback : TIM Base Msp Init Callback.
  119. (+) Base_MspDeInitCallback : TIM Base Msp DeInit Callback.
  120. (+) IC_MspInitCallback : TIM IC Msp Init Callback.
  121. (+) IC_MspDeInitCallback : TIM IC Msp DeInit Callback.
  122. (+) OC_MspInitCallback : TIM OC Msp Init Callback.
  123. (+) OC_MspDeInitCallback : TIM OC Msp DeInit Callback.
  124. (+) PWM_MspInitCallback : TIM PWM Msp Init Callback.
  125. (+) PWM_MspDeInitCallback : TIM PWM Msp DeInit Callback.
  126. (+) OnePulse_MspInitCallback : TIM One Pulse Msp Init Callback.
  127. (+) OnePulse_MspDeInitCallback : TIM One Pulse Msp DeInit Callback.
  128. (+) Encoder_MspInitCallback : TIM Encoder Msp Init Callback.
  129. (+) Encoder_MspDeInitCallback : TIM Encoder Msp DeInit Callback.
  130. (+) HallSensor_MspInitCallback : TIM Hall Sensor Msp Init Callback.
  131. (+) HallSensor_MspDeInitCallback : TIM Hall Sensor Msp DeInit Callback.
  132. (+) PeriodElapsedCallback : TIM Period Elapsed Callback.
  133. (+) PeriodElapsedHalfCpltCallback : TIM Period Elapsed half complete Callback.
  134. (+) TriggerCallback : TIM Trigger Callback.
  135. (+) TriggerHalfCpltCallback : TIM Trigger half complete Callback.
  136. (+) IC_CaptureCallback : TIM Input Capture Callback.
  137. (+) IC_CaptureHalfCpltCallback : TIM Input Capture half complete Callback.
  138. (+) OC_DelayElapsedCallback : TIM Output Compare Delay Elapsed Callback.
  139. (+) PWM_PulseFinishedCallback : TIM PWM Pulse Finished Callback.
  140. (+) PWM_PulseFinishedHalfCpltCallback : TIM PWM Pulse Finished half complete Callback.
  141. (+) ErrorCallback : TIM Error Callback.
  142. (+) CommutationCallback : TIM Commutation Callback.
  143. (+) CommutationHalfCpltCallback : TIM Commutation half complete Callback.
  144. (+) BreakCallback : TIM Break Callback.
  145. (+) Break2Callback : TIM Break2 Callback (when supported).
  146. [..]
  147. By default, after the Init and when the state is HAL_TIM_STATE_RESET
  148. all interrupt callbacks are set to the corresponding weak functions:
  149. examples HAL_TIM_TriggerCallback(), HAL_TIM_ErrorCallback().
  150. [..]
  151. Exception done for MspInit and MspDeInit functions that are reset to the legacy weak
  152. functionalities in the Init / DeInit only when these callbacks are null
  153. (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init / DeInit
  154. keep and use the user MspInit / MspDeInit callbacks(registered beforehand)
  155. [..]
  156. Callbacks can be registered / unregistered in HAL_TIM_STATE_READY state only.
  157. Exception done MspInit / MspDeInit that can be registered / unregistered
  158. in HAL_TIM_STATE_READY or HAL_TIM_STATE_RESET state,
  159. thus registered(user) MspInit / DeInit callbacks can be used during the Init / DeInit.
  160. In that case first register the MspInit/MspDeInit user callbacks
  161. using HAL_TIM_RegisterCallback() before calling DeInit or Init function.
  162. [..]
  163. When The compilation define USE_HAL_TIM_REGISTER_CALLBACKS is set to 0 or
  164. not defined, the callback registration feature is not available and all callbacks
  165. are set to the corresponding weak functions.
  166. @endverbatim
  167. ******************************************************************************
  168. */
  169. /* Includes ------------------------------------------------------------------*/
  170. #include "stm32f3xx_hal.h"
  171. /** @addtogroup STM32F3xx_HAL_Driver
  172. * @{
  173. */
  174. /** @defgroup TIM TIM
  175. * @brief TIM HAL module driver
  176. * @{
  177. */
  178. #ifdef HAL_TIM_MODULE_ENABLED
  179. /* Private typedef -----------------------------------------------------------*/
  180. /* Private define ------------------------------------------------------------*/
  181. /* Private macros ------------------------------------------------------------*/
  182. /* Private variables ---------------------------------------------------------*/
  183. /* Private function prototypes -----------------------------------------------*/
  184. /** @addtogroup TIM_Private_Functions
  185. * @{
  186. */
  187. static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config);
  188. static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config);
  189. static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config);
  190. #if defined(TIM_CCER_CC5E)
  191. static void TIM_OC5_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config);
  192. #endif /* TIM_CCER_CC5E */
  193. #if defined(TIM_CCER_CC6E)
  194. static void TIM_OC6_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config);
  195. #endif /* TIM_CCER_CC6E */
  196. static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
  197. static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  198. uint32_t TIM_ICFilter);
  199. static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
  200. static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  201. uint32_t TIM_ICFilter);
  202. static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  203. uint32_t TIM_ICFilter);
  204. static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource);
  205. static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma);
  206. static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma);
  207. static void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma);
  208. static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma);
  209. static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma);
  210. static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
  211. const TIM_SlaveConfigTypeDef *sSlaveConfig);
  212. /**
  213. * @}
  214. */
  215. /* Exported functions --------------------------------------------------------*/
  216. /** @defgroup TIM_Exported_Functions TIM Exported Functions
  217. * @{
  218. */
  219. /** @defgroup TIM_Exported_Functions_Group1 TIM Time Base functions
  220. * @brief Time Base functions
  221. *
  222. @verbatim
  223. ==============================================================================
  224. ##### Time Base functions #####
  225. ==============================================================================
  226. [..]
  227. This section provides functions allowing to:
  228. (+) Initialize and configure the TIM base.
  229. (+) De-initialize the TIM base.
  230. (+) Start the Time Base.
  231. (+) Stop the Time Base.
  232. (+) Start the Time Base and enable interrupt.
  233. (+) Stop the Time Base and disable interrupt.
  234. (+) Start the Time Base and enable DMA transfer.
  235. (+) Stop the Time Base and disable DMA transfer.
  236. @endverbatim
  237. * @{
  238. */
  239. /**
  240. * @brief Initializes the TIM Time base Unit according to the specified
  241. * parameters in the TIM_HandleTypeDef and initialize the associated handle.
  242. * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
  243. * requires a timer reset to avoid unexpected direction
  244. * due to DIR bit readonly in center aligned mode.
  245. * Ex: call @ref HAL_TIM_Base_DeInit() before HAL_TIM_Base_Init()
  246. * @param htim TIM Base handle
  247. * @retval HAL status
  248. */
  249. HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
  250. {
  251. /* Check the TIM handle allocation */
  252. if (htim == NULL)
  253. {
  254. return HAL_ERROR;
  255. }
  256. /* Check the parameters */
  257. assert_param(IS_TIM_INSTANCE(htim->Instance));
  258. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  259. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  260. assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
  261. assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
  262. if (htim->State == HAL_TIM_STATE_RESET)
  263. {
  264. /* Allocate lock resource and initialize it */
  265. htim->Lock = HAL_UNLOCKED;
  266. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  267. /* Reset interrupt callbacks to legacy weak callbacks */
  268. TIM_ResetCallback(htim);
  269. if (htim->Base_MspInitCallback == NULL)
  270. {
  271. htim->Base_MspInitCallback = HAL_TIM_Base_MspInit;
  272. }
  273. /* Init the low level hardware : GPIO, CLOCK, NVIC */
  274. htim->Base_MspInitCallback(htim);
  275. #else
  276. /* Init the low level hardware : GPIO, CLOCK, NVIC */
  277. HAL_TIM_Base_MspInit(htim);
  278. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  279. }
  280. /* Set the TIM state */
  281. htim->State = HAL_TIM_STATE_BUSY;
  282. /* Set the Time Base configuration */
  283. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  284. /* Initialize the DMA burst operation state */
  285. htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
  286. /* Initialize the TIM channels state */
  287. TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
  288. TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
  289. /* Initialize the TIM state*/
  290. htim->State = HAL_TIM_STATE_READY;
  291. return HAL_OK;
  292. }
  293. /**
  294. * @brief DeInitializes the TIM Base peripheral
  295. * @param htim TIM Base handle
  296. * @retval HAL status
  297. */
  298. HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim)
  299. {
  300. /* Check the parameters */
  301. assert_param(IS_TIM_INSTANCE(htim->Instance));
  302. htim->State = HAL_TIM_STATE_BUSY;
  303. /* Disable the TIM Peripheral Clock */
  304. __HAL_TIM_DISABLE(htim);
  305. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  306. if (htim->Base_MspDeInitCallback == NULL)
  307. {
  308. htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit;
  309. }
  310. /* DeInit the low level hardware */
  311. htim->Base_MspDeInitCallback(htim);
  312. #else
  313. /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
  314. HAL_TIM_Base_MspDeInit(htim);
  315. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  316. /* Change the DMA burst operation state */
  317. htim->DMABurstState = HAL_DMA_BURST_STATE_RESET;
  318. /* Change the TIM channels state */
  319. TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
  320. TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
  321. /* Change TIM state */
  322. htim->State = HAL_TIM_STATE_RESET;
  323. /* Release Lock */
  324. __HAL_UNLOCK(htim);
  325. return HAL_OK;
  326. }
  327. /**
  328. * @brief Initializes the TIM Base MSP.
  329. * @param htim TIM Base handle
  330. * @retval None
  331. */
  332. __weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
  333. {
  334. /* Prevent unused argument(s) compilation warning */
  335. UNUSED(htim);
  336. /* NOTE : This function should not be modified, when the callback is needed,
  337. the HAL_TIM_Base_MspInit could be implemented in the user file
  338. */
  339. }
  340. /**
  341. * @brief DeInitializes TIM Base MSP.
  342. * @param htim TIM Base handle
  343. * @retval None
  344. */
  345. __weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim)
  346. {
  347. /* Prevent unused argument(s) compilation warning */
  348. UNUSED(htim);
  349. /* NOTE : This function should not be modified, when the callback is needed,
  350. the HAL_TIM_Base_MspDeInit could be implemented in the user file
  351. */
  352. }
  353. /**
  354. * @brief Starts the TIM Base generation.
  355. * @param htim TIM Base handle
  356. * @retval HAL status
  357. */
  358. HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim)
  359. {
  360. uint32_t tmpsmcr;
  361. /* Check the parameters */
  362. assert_param(IS_TIM_INSTANCE(htim->Instance));
  363. /* Check the TIM state */
  364. if (htim->State != HAL_TIM_STATE_READY)
  365. {
  366. return HAL_ERROR;
  367. }
  368. /* Set the TIM state */
  369. htim->State = HAL_TIM_STATE_BUSY;
  370. /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
  371. if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
  372. {
  373. tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
  374. if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
  375. {
  376. __HAL_TIM_ENABLE(htim);
  377. }
  378. }
  379. else
  380. {
  381. __HAL_TIM_ENABLE(htim);
  382. }
  383. /* Return function status */
  384. return HAL_OK;
  385. }
  386. /**
  387. * @brief Stops the TIM Base generation.
  388. * @param htim TIM Base handle
  389. * @retval HAL status
  390. */
  391. HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim)
  392. {
  393. /* Check the parameters */
  394. assert_param(IS_TIM_INSTANCE(htim->Instance));
  395. /* Disable the Peripheral */
  396. __HAL_TIM_DISABLE(htim);
  397. /* Set the TIM state */
  398. htim->State = HAL_TIM_STATE_READY;
  399. /* Return function status */
  400. return HAL_OK;
  401. }
  402. /**
  403. * @brief Starts the TIM Base generation in interrupt mode.
  404. * @param htim TIM Base handle
  405. * @retval HAL status
  406. */
  407. HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
  408. {
  409. uint32_t tmpsmcr;
  410. /* Check the parameters */
  411. assert_param(IS_TIM_INSTANCE(htim->Instance));
  412. /* Check the TIM state */
  413. if (htim->State != HAL_TIM_STATE_READY)
  414. {
  415. return HAL_ERROR;
  416. }
  417. /* Set the TIM state */
  418. htim->State = HAL_TIM_STATE_BUSY;
  419. /* Enable the TIM Update interrupt */
  420. __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE);
  421. /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
  422. if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
  423. {
  424. tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
  425. if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
  426. {
  427. __HAL_TIM_ENABLE(htim);
  428. }
  429. }
  430. else
  431. {
  432. __HAL_TIM_ENABLE(htim);
  433. }
  434. /* Return function status */
  435. return HAL_OK;
  436. }
  437. /**
  438. * @brief Stops the TIM Base generation in interrupt mode.
  439. * @param htim TIM Base handle
  440. * @retval HAL status
  441. */
  442. HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim)
  443. {
  444. /* Check the parameters */
  445. assert_param(IS_TIM_INSTANCE(htim->Instance));
  446. /* Disable the TIM Update interrupt */
  447. __HAL_TIM_DISABLE_IT(htim, TIM_IT_UPDATE);
  448. /* Disable the Peripheral */
  449. __HAL_TIM_DISABLE(htim);
  450. /* Set the TIM state */
  451. htim->State = HAL_TIM_STATE_READY;
  452. /* Return function status */
  453. return HAL_OK;
  454. }
  455. /**
  456. * @brief Starts the TIM Base generation in DMA mode.
  457. * @param htim TIM Base handle
  458. * @param pData The source Buffer address.
  459. * @param Length The length of data to be transferred from memory to peripheral.
  460. * @retval HAL status
  461. */
  462. HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, const uint32_t *pData, uint16_t Length)
  463. {
  464. uint32_t tmpsmcr;
  465. /* Check the parameters */
  466. assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
  467. /* Set the TIM state */
  468. if (htim->State == HAL_TIM_STATE_BUSY)
  469. {
  470. return HAL_BUSY;
  471. }
  472. else if (htim->State == HAL_TIM_STATE_READY)
  473. {
  474. if ((pData == NULL) || (Length == 0U))
  475. {
  476. return HAL_ERROR;
  477. }
  478. else
  479. {
  480. htim->State = HAL_TIM_STATE_BUSY;
  481. }
  482. }
  483. else
  484. {
  485. return HAL_ERROR;
  486. }
  487. /* Set the DMA Period elapsed callbacks */
  488. htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
  489. htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
  490. /* Set the DMA error callback */
  491. htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
  492. /* Enable the DMA channel */
  493. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR,
  494. Length) != HAL_OK)
  495. {
  496. /* Return error status */
  497. return HAL_ERROR;
  498. }
  499. /* Enable the TIM Update DMA request */
  500. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_UPDATE);
  501. /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
  502. if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
  503. {
  504. tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
  505. if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
  506. {
  507. __HAL_TIM_ENABLE(htim);
  508. }
  509. }
  510. else
  511. {
  512. __HAL_TIM_ENABLE(htim);
  513. }
  514. /* Return function status */
  515. return HAL_OK;
  516. }
  517. /**
  518. * @brief Stops the TIM Base generation in DMA mode.
  519. * @param htim TIM Base handle
  520. * @retval HAL status
  521. */
  522. HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim)
  523. {
  524. /* Check the parameters */
  525. assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
  526. /* Disable the TIM Update DMA request */
  527. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_UPDATE);
  528. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]);
  529. /* Disable the Peripheral */
  530. __HAL_TIM_DISABLE(htim);
  531. /* Set the TIM state */
  532. htim->State = HAL_TIM_STATE_READY;
  533. /* Return function status */
  534. return HAL_OK;
  535. }
  536. /**
  537. * @}
  538. */
  539. /** @defgroup TIM_Exported_Functions_Group2 TIM Output Compare functions
  540. * @brief TIM Output Compare functions
  541. *
  542. @verbatim
  543. ==============================================================================
  544. ##### TIM Output Compare functions #####
  545. ==============================================================================
  546. [..]
  547. This section provides functions allowing to:
  548. (+) Initialize and configure the TIM Output Compare.
  549. (+) De-initialize the TIM Output Compare.
  550. (+) Start the TIM Output Compare.
  551. (+) Stop the TIM Output Compare.
  552. (+) Start the TIM Output Compare and enable interrupt.
  553. (+) Stop the TIM Output Compare and disable interrupt.
  554. (+) Start the TIM Output Compare and enable DMA transfer.
  555. (+) Stop the TIM Output Compare and disable DMA transfer.
  556. @endverbatim
  557. * @{
  558. */
  559. /**
  560. * @brief Initializes the TIM Output Compare according to the specified
  561. * parameters in the TIM_HandleTypeDef and initializes the associated handle.
  562. * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
  563. * requires a timer reset to avoid unexpected direction
  564. * due to DIR bit readonly in center aligned mode.
  565. * Ex: call @ref HAL_TIM_OC_DeInit() before HAL_TIM_OC_Init()
  566. * @param htim TIM Output Compare handle
  567. * @retval HAL status
  568. */
  569. HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim)
  570. {
  571. /* Check the TIM handle allocation */
  572. if (htim == NULL)
  573. {
  574. return HAL_ERROR;
  575. }
  576. /* Check the parameters */
  577. assert_param(IS_TIM_INSTANCE(htim->Instance));
  578. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  579. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  580. assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
  581. assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
  582. if (htim->State == HAL_TIM_STATE_RESET)
  583. {
  584. /* Allocate lock resource and initialize it */
  585. htim->Lock = HAL_UNLOCKED;
  586. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  587. /* Reset interrupt callbacks to legacy weak callbacks */
  588. TIM_ResetCallback(htim);
  589. if (htim->OC_MspInitCallback == NULL)
  590. {
  591. htim->OC_MspInitCallback = HAL_TIM_OC_MspInit;
  592. }
  593. /* Init the low level hardware : GPIO, CLOCK, NVIC */
  594. htim->OC_MspInitCallback(htim);
  595. #else
  596. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  597. HAL_TIM_OC_MspInit(htim);
  598. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  599. }
  600. /* Set the TIM state */
  601. htim->State = HAL_TIM_STATE_BUSY;
  602. /* Init the base time for the Output Compare */
  603. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  604. /* Initialize the DMA burst operation state */
  605. htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
  606. /* Initialize the TIM channels state */
  607. TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
  608. TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
  609. /* Initialize the TIM state*/
  610. htim->State = HAL_TIM_STATE_READY;
  611. return HAL_OK;
  612. }
  613. /**
  614. * @brief DeInitializes the TIM peripheral
  615. * @param htim TIM Output Compare handle
  616. * @retval HAL status
  617. */
  618. HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim)
  619. {
  620. /* Check the parameters */
  621. assert_param(IS_TIM_INSTANCE(htim->Instance));
  622. htim->State = HAL_TIM_STATE_BUSY;
  623. /* Disable the TIM Peripheral Clock */
  624. __HAL_TIM_DISABLE(htim);
  625. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  626. if (htim->OC_MspDeInitCallback == NULL)
  627. {
  628. htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit;
  629. }
  630. /* DeInit the low level hardware */
  631. htim->OC_MspDeInitCallback(htim);
  632. #else
  633. /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
  634. HAL_TIM_OC_MspDeInit(htim);
  635. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  636. /* Change the DMA burst operation state */
  637. htim->DMABurstState = HAL_DMA_BURST_STATE_RESET;
  638. /* Change the TIM channels state */
  639. TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
  640. TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
  641. /* Change TIM state */
  642. htim->State = HAL_TIM_STATE_RESET;
  643. /* Release Lock */
  644. __HAL_UNLOCK(htim);
  645. return HAL_OK;
  646. }
  647. /**
  648. * @brief Initializes the TIM Output Compare MSP.
  649. * @param htim TIM Output Compare handle
  650. * @retval None
  651. */
  652. __weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim)
  653. {
  654. /* Prevent unused argument(s) compilation warning */
  655. UNUSED(htim);
  656. /* NOTE : This function should not be modified, when the callback is needed,
  657. the HAL_TIM_OC_MspInit could be implemented in the user file
  658. */
  659. }
  660. /**
  661. * @brief DeInitializes TIM Output Compare MSP.
  662. * @param htim TIM Output Compare handle
  663. * @retval None
  664. */
  665. __weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim)
  666. {
  667. /* Prevent unused argument(s) compilation warning */
  668. UNUSED(htim);
  669. /* NOTE : This function should not be modified, when the callback is needed,
  670. the HAL_TIM_OC_MspDeInit could be implemented in the user file
  671. */
  672. }
  673. /**
  674. * @brief Starts the TIM Output Compare signal generation.
  675. * @param htim TIM Output Compare handle
  676. * @param Channel TIM Channel to be enabled
  677. * This parameter can be one of the following values:
  678. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  679. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  680. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  681. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  682. * @arg TIM_CHANNEL_5: TIM Channel 5 selected (*)
  683. * @arg TIM_CHANNEL_6: TIM Channel 6 selected (*)
  684. * (*) Value not defined for all devices
  685. * @retval HAL status
  686. */
  687. HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
  688. {
  689. uint32_t tmpsmcr;
  690. /* Check the parameters */
  691. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  692. /* Check the TIM channel state */
  693. if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
  694. {
  695. return HAL_ERROR;
  696. }
  697. /* Set the TIM channel state */
  698. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
  699. /* Enable the Output compare channel */
  700. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  701. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  702. {
  703. /* Enable the main output */
  704. __HAL_TIM_MOE_ENABLE(htim);
  705. }
  706. /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
  707. if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
  708. {
  709. tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
  710. if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
  711. {
  712. __HAL_TIM_ENABLE(htim);
  713. }
  714. }
  715. else
  716. {
  717. __HAL_TIM_ENABLE(htim);
  718. }
  719. /* Return function status */
  720. return HAL_OK;
  721. }
  722. /**
  723. * @brief Stops the TIM Output Compare signal generation.
  724. * @param htim TIM Output Compare handle
  725. * @param Channel TIM Channel to be disabled
  726. * This parameter can be one of the following values:
  727. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  728. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  729. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  730. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  731. * @arg TIM_CHANNEL_5: TIM Channel 5 selected (*)
  732. * @arg TIM_CHANNEL_6: TIM Channel 6 selected (*)
  733. * (*) Value not defined for all devices
  734. * @retval HAL status
  735. */
  736. HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
  737. {
  738. /* Check the parameters */
  739. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  740. /* Disable the Output compare channel */
  741. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  742. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  743. {
  744. /* Disable the Main Output */
  745. __HAL_TIM_MOE_DISABLE(htim);
  746. }
  747. /* Disable the Peripheral */
  748. __HAL_TIM_DISABLE(htim);
  749. /* Set the TIM channel state */
  750. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  751. /* Return function status */
  752. return HAL_OK;
  753. }
  754. /**
  755. * @brief Starts the TIM Output Compare signal generation in interrupt mode.
  756. * @param htim TIM Output Compare handle
  757. * @param Channel TIM Channel to be enabled
  758. * This parameter can be one of the following values:
  759. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  760. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  761. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  762. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  763. * @retval HAL status
  764. */
  765. HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  766. {
  767. HAL_StatusTypeDef status = HAL_OK;
  768. uint32_t tmpsmcr;
  769. /* Check the parameters */
  770. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  771. /* Check the TIM channel state */
  772. if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
  773. {
  774. return HAL_ERROR;
  775. }
  776. /* Set the TIM channel state */
  777. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
  778. switch (Channel)
  779. {
  780. case TIM_CHANNEL_1:
  781. {
  782. /* Enable the TIM Capture/Compare 1 interrupt */
  783. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  784. break;
  785. }
  786. case TIM_CHANNEL_2:
  787. {
  788. /* Enable the TIM Capture/Compare 2 interrupt */
  789. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  790. break;
  791. }
  792. case TIM_CHANNEL_3:
  793. {
  794. /* Enable the TIM Capture/Compare 3 interrupt */
  795. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
  796. break;
  797. }
  798. case TIM_CHANNEL_4:
  799. {
  800. /* Enable the TIM Capture/Compare 4 interrupt */
  801. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
  802. break;
  803. }
  804. default:
  805. status = HAL_ERROR;
  806. break;
  807. }
  808. if (status == HAL_OK)
  809. {
  810. /* Enable the Output compare channel */
  811. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  812. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  813. {
  814. /* Enable the main output */
  815. __HAL_TIM_MOE_ENABLE(htim);
  816. }
  817. /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
  818. if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
  819. {
  820. tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
  821. if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
  822. {
  823. __HAL_TIM_ENABLE(htim);
  824. }
  825. }
  826. else
  827. {
  828. __HAL_TIM_ENABLE(htim);
  829. }
  830. }
  831. /* Return function status */
  832. return status;
  833. }
  834. /**
  835. * @brief Stops the TIM Output Compare signal generation in interrupt mode.
  836. * @param htim TIM Output Compare handle
  837. * @param Channel TIM Channel to be disabled
  838. * This parameter can be one of the following values:
  839. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  840. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  841. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  842. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  843. * @retval HAL status
  844. */
  845. HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  846. {
  847. HAL_StatusTypeDef status = HAL_OK;
  848. /* Check the parameters */
  849. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  850. switch (Channel)
  851. {
  852. case TIM_CHANNEL_1:
  853. {
  854. /* Disable the TIM Capture/Compare 1 interrupt */
  855. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  856. break;
  857. }
  858. case TIM_CHANNEL_2:
  859. {
  860. /* Disable the TIM Capture/Compare 2 interrupt */
  861. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  862. break;
  863. }
  864. case TIM_CHANNEL_3:
  865. {
  866. /* Disable the TIM Capture/Compare 3 interrupt */
  867. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
  868. break;
  869. }
  870. case TIM_CHANNEL_4:
  871. {
  872. /* Disable the TIM Capture/Compare 4 interrupt */
  873. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
  874. break;
  875. }
  876. default:
  877. status = HAL_ERROR;
  878. break;
  879. }
  880. if (status == HAL_OK)
  881. {
  882. /* Disable the Output compare channel */
  883. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  884. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  885. {
  886. /* Disable the Main Output */
  887. __HAL_TIM_MOE_DISABLE(htim);
  888. }
  889. /* Disable the Peripheral */
  890. __HAL_TIM_DISABLE(htim);
  891. /* Set the TIM channel state */
  892. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  893. }
  894. /* Return function status */
  895. return status;
  896. }
  897. /**
  898. * @brief Starts the TIM Output Compare signal generation in DMA mode.
  899. * @param htim TIM Output Compare handle
  900. * @param Channel TIM Channel to be enabled
  901. * This parameter can be one of the following values:
  902. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  903. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  904. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  905. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  906. * @param pData The source Buffer address.
  907. * @param Length The length of data to be transferred from memory to TIM peripheral
  908. * @retval HAL status
  909. */
  910. HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
  911. uint16_t Length)
  912. {
  913. HAL_StatusTypeDef status = HAL_OK;
  914. uint32_t tmpsmcr;
  915. /* Check the parameters */
  916. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  917. /* Set the TIM channel state */
  918. if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_BUSY)
  919. {
  920. return HAL_BUSY;
  921. }
  922. else if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY)
  923. {
  924. if ((pData == NULL) || (Length == 0U))
  925. {
  926. return HAL_ERROR;
  927. }
  928. else
  929. {
  930. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
  931. }
  932. }
  933. else
  934. {
  935. return HAL_ERROR;
  936. }
  937. switch (Channel)
  938. {
  939. case TIM_CHANNEL_1:
  940. {
  941. /* Set the DMA compare callbacks */
  942. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
  943. htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
  944. /* Set the DMA error callback */
  945. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
  946. /* Enable the DMA channel */
  947. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1,
  948. Length) != HAL_OK)
  949. {
  950. /* Return error status */
  951. return HAL_ERROR;
  952. }
  953. /* Enable the TIM Capture/Compare 1 DMA request */
  954. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  955. break;
  956. }
  957. case TIM_CHANNEL_2:
  958. {
  959. /* Set the DMA compare callbacks */
  960. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
  961. htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
  962. /* Set the DMA error callback */
  963. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
  964. /* Enable the DMA channel */
  965. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2,
  966. Length) != HAL_OK)
  967. {
  968. /* Return error status */
  969. return HAL_ERROR;
  970. }
  971. /* Enable the TIM Capture/Compare 2 DMA request */
  972. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  973. break;
  974. }
  975. case TIM_CHANNEL_3:
  976. {
  977. /* Set the DMA compare callbacks */
  978. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
  979. htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
  980. /* Set the DMA error callback */
  981. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
  982. /* Enable the DMA channel */
  983. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,
  984. Length) != HAL_OK)
  985. {
  986. /* Return error status */
  987. return HAL_ERROR;
  988. }
  989. /* Enable the TIM Capture/Compare 3 DMA request */
  990. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
  991. break;
  992. }
  993. case TIM_CHANNEL_4:
  994. {
  995. /* Set the DMA compare callbacks */
  996. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
  997. htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
  998. /* Set the DMA error callback */
  999. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
  1000. /* Enable the DMA channel */
  1001. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4,
  1002. Length) != HAL_OK)
  1003. {
  1004. /* Return error status */
  1005. return HAL_ERROR;
  1006. }
  1007. /* Enable the TIM Capture/Compare 4 DMA request */
  1008. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
  1009. break;
  1010. }
  1011. default:
  1012. status = HAL_ERROR;
  1013. break;
  1014. }
  1015. if (status == HAL_OK)
  1016. {
  1017. /* Enable the Output compare channel */
  1018. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  1019. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  1020. {
  1021. /* Enable the main output */
  1022. __HAL_TIM_MOE_ENABLE(htim);
  1023. }
  1024. /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
  1025. if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
  1026. {
  1027. tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
  1028. if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
  1029. {
  1030. __HAL_TIM_ENABLE(htim);
  1031. }
  1032. }
  1033. else
  1034. {
  1035. __HAL_TIM_ENABLE(htim);
  1036. }
  1037. }
  1038. /* Return function status */
  1039. return status;
  1040. }
  1041. /**
  1042. * @brief Stops the TIM Output Compare signal generation in DMA mode.
  1043. * @param htim TIM Output Compare handle
  1044. * @param Channel TIM Channel to be disabled
  1045. * This parameter can be one of the following values:
  1046. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1047. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1048. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1049. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1050. * @retval HAL status
  1051. */
  1052. HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
  1053. {
  1054. HAL_StatusTypeDef status = HAL_OK;
  1055. /* Check the parameters */
  1056. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  1057. switch (Channel)
  1058. {
  1059. case TIM_CHANNEL_1:
  1060. {
  1061. /* Disable the TIM Capture/Compare 1 DMA request */
  1062. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  1063. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
  1064. break;
  1065. }
  1066. case TIM_CHANNEL_2:
  1067. {
  1068. /* Disable the TIM Capture/Compare 2 DMA request */
  1069. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  1070. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
  1071. break;
  1072. }
  1073. case TIM_CHANNEL_3:
  1074. {
  1075. /* Disable the TIM Capture/Compare 3 DMA request */
  1076. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
  1077. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
  1078. break;
  1079. }
  1080. case TIM_CHANNEL_4:
  1081. {
  1082. /* Disable the TIM Capture/Compare 4 interrupt */
  1083. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
  1084. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
  1085. break;
  1086. }
  1087. default:
  1088. status = HAL_ERROR;
  1089. break;
  1090. }
  1091. if (status == HAL_OK)
  1092. {
  1093. /* Disable the Output compare channel */
  1094. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  1095. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  1096. {
  1097. /* Disable the Main Output */
  1098. __HAL_TIM_MOE_DISABLE(htim);
  1099. }
  1100. /* Disable the Peripheral */
  1101. __HAL_TIM_DISABLE(htim);
  1102. /* Set the TIM channel state */
  1103. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  1104. }
  1105. /* Return function status */
  1106. return status;
  1107. }
  1108. /**
  1109. * @}
  1110. */
  1111. /** @defgroup TIM_Exported_Functions_Group3 TIM PWM functions
  1112. * @brief TIM PWM functions
  1113. *
  1114. @verbatim
  1115. ==============================================================================
  1116. ##### TIM PWM functions #####
  1117. ==============================================================================
  1118. [..]
  1119. This section provides functions allowing to:
  1120. (+) Initialize and configure the TIM PWM.
  1121. (+) De-initialize the TIM PWM.
  1122. (+) Start the TIM PWM.
  1123. (+) Stop the TIM PWM.
  1124. (+) Start the TIM PWM and enable interrupt.
  1125. (+) Stop the TIM PWM and disable interrupt.
  1126. (+) Start the TIM PWM and enable DMA transfer.
  1127. (+) Stop the TIM PWM and disable DMA transfer.
  1128. @endverbatim
  1129. * @{
  1130. */
  1131. /**
  1132. * @brief Initializes the TIM PWM Time Base according to the specified
  1133. * parameters in the TIM_HandleTypeDef and initializes the associated handle.
  1134. * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
  1135. * requires a timer reset to avoid unexpected direction
  1136. * due to DIR bit readonly in center aligned mode.
  1137. * Ex: call @ref HAL_TIM_PWM_DeInit() before HAL_TIM_PWM_Init()
  1138. * @param htim TIM PWM handle
  1139. * @retval HAL status
  1140. */
  1141. HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim)
  1142. {
  1143. /* Check the TIM handle allocation */
  1144. if (htim == NULL)
  1145. {
  1146. return HAL_ERROR;
  1147. }
  1148. /* Check the parameters */
  1149. assert_param(IS_TIM_INSTANCE(htim->Instance));
  1150. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  1151. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  1152. assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
  1153. assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
  1154. if (htim->State == HAL_TIM_STATE_RESET)
  1155. {
  1156. /* Allocate lock resource and initialize it */
  1157. htim->Lock = HAL_UNLOCKED;
  1158. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  1159. /* Reset interrupt callbacks to legacy weak callbacks */
  1160. TIM_ResetCallback(htim);
  1161. if (htim->PWM_MspInitCallback == NULL)
  1162. {
  1163. htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit;
  1164. }
  1165. /* Init the low level hardware : GPIO, CLOCK, NVIC */
  1166. htim->PWM_MspInitCallback(htim);
  1167. #else
  1168. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  1169. HAL_TIM_PWM_MspInit(htim);
  1170. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  1171. }
  1172. /* Set the TIM state */
  1173. htim->State = HAL_TIM_STATE_BUSY;
  1174. /* Init the base time for the PWM */
  1175. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  1176. /* Initialize the DMA burst operation state */
  1177. htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
  1178. /* Initialize the TIM channels state */
  1179. TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
  1180. TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
  1181. /* Initialize the TIM state*/
  1182. htim->State = HAL_TIM_STATE_READY;
  1183. return HAL_OK;
  1184. }
  1185. /**
  1186. * @brief DeInitializes the TIM peripheral
  1187. * @param htim TIM PWM handle
  1188. * @retval HAL status
  1189. */
  1190. HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim)
  1191. {
  1192. /* Check the parameters */
  1193. assert_param(IS_TIM_INSTANCE(htim->Instance));
  1194. htim->State = HAL_TIM_STATE_BUSY;
  1195. /* Disable the TIM Peripheral Clock */
  1196. __HAL_TIM_DISABLE(htim);
  1197. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  1198. if (htim->PWM_MspDeInitCallback == NULL)
  1199. {
  1200. htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit;
  1201. }
  1202. /* DeInit the low level hardware */
  1203. htim->PWM_MspDeInitCallback(htim);
  1204. #else
  1205. /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
  1206. HAL_TIM_PWM_MspDeInit(htim);
  1207. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  1208. /* Change the DMA burst operation state */
  1209. htim->DMABurstState = HAL_DMA_BURST_STATE_RESET;
  1210. /* Change the TIM channels state */
  1211. TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
  1212. TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
  1213. /* Change TIM state */
  1214. htim->State = HAL_TIM_STATE_RESET;
  1215. /* Release Lock */
  1216. __HAL_UNLOCK(htim);
  1217. return HAL_OK;
  1218. }
  1219. /**
  1220. * @brief Initializes the TIM PWM MSP.
  1221. * @param htim TIM PWM handle
  1222. * @retval None
  1223. */
  1224. __weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
  1225. {
  1226. /* Prevent unused argument(s) compilation warning */
  1227. UNUSED(htim);
  1228. /* NOTE : This function should not be modified, when the callback is needed,
  1229. the HAL_TIM_PWM_MspInit could be implemented in the user file
  1230. */
  1231. }
  1232. /**
  1233. * @brief DeInitializes TIM PWM MSP.
  1234. * @param htim TIM PWM handle
  1235. * @retval None
  1236. */
  1237. __weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim)
  1238. {
  1239. /* Prevent unused argument(s) compilation warning */
  1240. UNUSED(htim);
  1241. /* NOTE : This function should not be modified, when the callback is needed,
  1242. the HAL_TIM_PWM_MspDeInit could be implemented in the user file
  1243. */
  1244. }
  1245. /**
  1246. * @brief Starts the PWM signal generation.
  1247. * @param htim TIM handle
  1248. * @param Channel TIM Channels to be enabled
  1249. * This parameter can be one of the following values:
  1250. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1251. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1252. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1253. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1254. * @arg TIM_CHANNEL_5: TIM Channel 5 selected (*)
  1255. * @arg TIM_CHANNEL_6: TIM Channel 6 selected (*)
  1256. * (*) Value not defined for all devices
  1257. * @retval HAL status
  1258. */
  1259. HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
  1260. {
  1261. uint32_t tmpsmcr;
  1262. /* Check the parameters */
  1263. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  1264. /* Check the TIM channel state */
  1265. if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
  1266. {
  1267. return HAL_ERROR;
  1268. }
  1269. /* Set the TIM channel state */
  1270. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
  1271. /* Enable the Capture compare channel */
  1272. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  1273. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  1274. {
  1275. /* Enable the main output */
  1276. __HAL_TIM_MOE_ENABLE(htim);
  1277. }
  1278. /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
  1279. if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
  1280. {
  1281. tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
  1282. if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
  1283. {
  1284. __HAL_TIM_ENABLE(htim);
  1285. }
  1286. }
  1287. else
  1288. {
  1289. __HAL_TIM_ENABLE(htim);
  1290. }
  1291. /* Return function status */
  1292. return HAL_OK;
  1293. }
  1294. /**
  1295. * @brief Stops the PWM signal generation.
  1296. * @param htim TIM PWM handle
  1297. * @param Channel TIM Channels to be disabled
  1298. * This parameter can be one of the following values:
  1299. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1300. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1301. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1302. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1303. * @arg TIM_CHANNEL_5: TIM Channel 5 selected (*)
  1304. * @arg TIM_CHANNEL_6: TIM Channel 6 selected (*)
  1305. * (*) Value not defined for all devices
  1306. * @retval HAL status
  1307. */
  1308. HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
  1309. {
  1310. /* Check the parameters */
  1311. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  1312. /* Disable the Capture compare channel */
  1313. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  1314. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  1315. {
  1316. /* Disable the Main Output */
  1317. __HAL_TIM_MOE_DISABLE(htim);
  1318. }
  1319. /* Disable the Peripheral */
  1320. __HAL_TIM_DISABLE(htim);
  1321. /* Set the TIM channel state */
  1322. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  1323. /* Return function status */
  1324. return HAL_OK;
  1325. }
  1326. /**
  1327. * @brief Starts the PWM signal generation in interrupt mode.
  1328. * @param htim TIM PWM handle
  1329. * @param Channel TIM Channel to be enabled
  1330. * This parameter can be one of the following values:
  1331. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1332. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1333. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1334. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1335. * @retval HAL status
  1336. */
  1337. HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  1338. {
  1339. HAL_StatusTypeDef status = HAL_OK;
  1340. uint32_t tmpsmcr;
  1341. /* Check the parameters */
  1342. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  1343. /* Check the TIM channel state */
  1344. if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
  1345. {
  1346. return HAL_ERROR;
  1347. }
  1348. /* Set the TIM channel state */
  1349. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
  1350. switch (Channel)
  1351. {
  1352. case TIM_CHANNEL_1:
  1353. {
  1354. /* Enable the TIM Capture/Compare 1 interrupt */
  1355. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  1356. break;
  1357. }
  1358. case TIM_CHANNEL_2:
  1359. {
  1360. /* Enable the TIM Capture/Compare 2 interrupt */
  1361. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  1362. break;
  1363. }
  1364. case TIM_CHANNEL_3:
  1365. {
  1366. /* Enable the TIM Capture/Compare 3 interrupt */
  1367. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
  1368. break;
  1369. }
  1370. case TIM_CHANNEL_4:
  1371. {
  1372. /* Enable the TIM Capture/Compare 4 interrupt */
  1373. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
  1374. break;
  1375. }
  1376. default:
  1377. status = HAL_ERROR;
  1378. break;
  1379. }
  1380. if (status == HAL_OK)
  1381. {
  1382. /* Enable the Capture compare channel */
  1383. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  1384. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  1385. {
  1386. /* Enable the main output */
  1387. __HAL_TIM_MOE_ENABLE(htim);
  1388. }
  1389. /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
  1390. if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
  1391. {
  1392. tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
  1393. if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
  1394. {
  1395. __HAL_TIM_ENABLE(htim);
  1396. }
  1397. }
  1398. else
  1399. {
  1400. __HAL_TIM_ENABLE(htim);
  1401. }
  1402. }
  1403. /* Return function status */
  1404. return status;
  1405. }
  1406. /**
  1407. * @brief Stops the PWM signal generation in interrupt mode.
  1408. * @param htim TIM PWM handle
  1409. * @param Channel TIM Channels to be disabled
  1410. * This parameter can be one of the following values:
  1411. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1412. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1413. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1414. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1415. * @retval HAL status
  1416. */
  1417. HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  1418. {
  1419. HAL_StatusTypeDef status = HAL_OK;
  1420. /* Check the parameters */
  1421. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  1422. switch (Channel)
  1423. {
  1424. case TIM_CHANNEL_1:
  1425. {
  1426. /* Disable the TIM Capture/Compare 1 interrupt */
  1427. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  1428. break;
  1429. }
  1430. case TIM_CHANNEL_2:
  1431. {
  1432. /* Disable the TIM Capture/Compare 2 interrupt */
  1433. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  1434. break;
  1435. }
  1436. case TIM_CHANNEL_3:
  1437. {
  1438. /* Disable the TIM Capture/Compare 3 interrupt */
  1439. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
  1440. break;
  1441. }
  1442. case TIM_CHANNEL_4:
  1443. {
  1444. /* Disable the TIM Capture/Compare 4 interrupt */
  1445. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
  1446. break;
  1447. }
  1448. default:
  1449. status = HAL_ERROR;
  1450. break;
  1451. }
  1452. if (status == HAL_OK)
  1453. {
  1454. /* Disable the Capture compare channel */
  1455. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  1456. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  1457. {
  1458. /* Disable the Main Output */
  1459. __HAL_TIM_MOE_DISABLE(htim);
  1460. }
  1461. /* Disable the Peripheral */
  1462. __HAL_TIM_DISABLE(htim);
  1463. /* Set the TIM channel state */
  1464. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  1465. }
  1466. /* Return function status */
  1467. return status;
  1468. }
  1469. /**
  1470. * @brief Starts the TIM PWM signal generation in DMA mode.
  1471. * @param htim TIM PWM handle
  1472. * @param Channel TIM Channels to be enabled
  1473. * This parameter can be one of the following values:
  1474. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1475. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1476. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1477. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1478. * @param pData The source Buffer address.
  1479. * @param Length The length of data to be transferred from memory to TIM peripheral
  1480. * @retval HAL status
  1481. */
  1482. HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
  1483. uint16_t Length)
  1484. {
  1485. HAL_StatusTypeDef status = HAL_OK;
  1486. uint32_t tmpsmcr;
  1487. /* Check the parameters */
  1488. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  1489. /* Set the TIM channel state */
  1490. if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_BUSY)
  1491. {
  1492. return HAL_BUSY;
  1493. }
  1494. else if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY)
  1495. {
  1496. if ((pData == NULL) || (Length == 0U))
  1497. {
  1498. return HAL_ERROR;
  1499. }
  1500. else
  1501. {
  1502. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
  1503. }
  1504. }
  1505. else
  1506. {
  1507. return HAL_ERROR;
  1508. }
  1509. switch (Channel)
  1510. {
  1511. case TIM_CHANNEL_1:
  1512. {
  1513. /* Set the DMA compare callbacks */
  1514. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
  1515. htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
  1516. /* Set the DMA error callback */
  1517. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
  1518. /* Enable the DMA channel */
  1519. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1,
  1520. Length) != HAL_OK)
  1521. {
  1522. /* Return error status */
  1523. return HAL_ERROR;
  1524. }
  1525. /* Enable the TIM Capture/Compare 1 DMA request */
  1526. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  1527. break;
  1528. }
  1529. case TIM_CHANNEL_2:
  1530. {
  1531. /* Set the DMA compare callbacks */
  1532. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
  1533. htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
  1534. /* Set the DMA error callback */
  1535. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
  1536. /* Enable the DMA channel */
  1537. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2,
  1538. Length) != HAL_OK)
  1539. {
  1540. /* Return error status */
  1541. return HAL_ERROR;
  1542. }
  1543. /* Enable the TIM Capture/Compare 2 DMA request */
  1544. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  1545. break;
  1546. }
  1547. case TIM_CHANNEL_3:
  1548. {
  1549. /* Set the DMA compare callbacks */
  1550. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
  1551. htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
  1552. /* Set the DMA error callback */
  1553. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
  1554. /* Enable the DMA channel */
  1555. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,
  1556. Length) != HAL_OK)
  1557. {
  1558. /* Return error status */
  1559. return HAL_ERROR;
  1560. }
  1561. /* Enable the TIM Output Capture/Compare 3 request */
  1562. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
  1563. break;
  1564. }
  1565. case TIM_CHANNEL_4:
  1566. {
  1567. /* Set the DMA compare callbacks */
  1568. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
  1569. htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
  1570. /* Set the DMA error callback */
  1571. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
  1572. /* Enable the DMA channel */
  1573. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4,
  1574. Length) != HAL_OK)
  1575. {
  1576. /* Return error status */
  1577. return HAL_ERROR;
  1578. }
  1579. /* Enable the TIM Capture/Compare 4 DMA request */
  1580. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
  1581. break;
  1582. }
  1583. default:
  1584. status = HAL_ERROR;
  1585. break;
  1586. }
  1587. if (status == HAL_OK)
  1588. {
  1589. /* Enable the Capture compare channel */
  1590. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  1591. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  1592. {
  1593. /* Enable the main output */
  1594. __HAL_TIM_MOE_ENABLE(htim);
  1595. }
  1596. /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
  1597. if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
  1598. {
  1599. tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
  1600. if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
  1601. {
  1602. __HAL_TIM_ENABLE(htim);
  1603. }
  1604. }
  1605. else
  1606. {
  1607. __HAL_TIM_ENABLE(htim);
  1608. }
  1609. }
  1610. /* Return function status */
  1611. return status;
  1612. }
  1613. /**
  1614. * @brief Stops the TIM PWM signal generation in DMA mode.
  1615. * @param htim TIM PWM handle
  1616. * @param Channel TIM Channels to be disabled
  1617. * This parameter can be one of the following values:
  1618. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1619. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1620. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1621. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1622. * @retval HAL status
  1623. */
  1624. HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
  1625. {
  1626. HAL_StatusTypeDef status = HAL_OK;
  1627. /* Check the parameters */
  1628. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  1629. switch (Channel)
  1630. {
  1631. case TIM_CHANNEL_1:
  1632. {
  1633. /* Disable the TIM Capture/Compare 1 DMA request */
  1634. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  1635. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
  1636. break;
  1637. }
  1638. case TIM_CHANNEL_2:
  1639. {
  1640. /* Disable the TIM Capture/Compare 2 DMA request */
  1641. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  1642. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
  1643. break;
  1644. }
  1645. case TIM_CHANNEL_3:
  1646. {
  1647. /* Disable the TIM Capture/Compare 3 DMA request */
  1648. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
  1649. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
  1650. break;
  1651. }
  1652. case TIM_CHANNEL_4:
  1653. {
  1654. /* Disable the TIM Capture/Compare 4 interrupt */
  1655. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
  1656. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
  1657. break;
  1658. }
  1659. default:
  1660. status = HAL_ERROR;
  1661. break;
  1662. }
  1663. if (status == HAL_OK)
  1664. {
  1665. /* Disable the Capture compare channel */
  1666. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  1667. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  1668. {
  1669. /* Disable the Main Output */
  1670. __HAL_TIM_MOE_DISABLE(htim);
  1671. }
  1672. /* Disable the Peripheral */
  1673. __HAL_TIM_DISABLE(htim);
  1674. /* Set the TIM channel state */
  1675. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  1676. }
  1677. /* Return function status */
  1678. return status;
  1679. }
  1680. /**
  1681. * @}
  1682. */
  1683. /** @defgroup TIM_Exported_Functions_Group4 TIM Input Capture functions
  1684. * @brief TIM Input Capture functions
  1685. *
  1686. @verbatim
  1687. ==============================================================================
  1688. ##### TIM Input Capture functions #####
  1689. ==============================================================================
  1690. [..]
  1691. This section provides functions allowing to:
  1692. (+) Initialize and configure the TIM Input Capture.
  1693. (+) De-initialize the TIM Input Capture.
  1694. (+) Start the TIM Input Capture.
  1695. (+) Stop the TIM Input Capture.
  1696. (+) Start the TIM Input Capture and enable interrupt.
  1697. (+) Stop the TIM Input Capture and disable interrupt.
  1698. (+) Start the TIM Input Capture and enable DMA transfer.
  1699. (+) Stop the TIM Input Capture and disable DMA transfer.
  1700. @endverbatim
  1701. * @{
  1702. */
  1703. /**
  1704. * @brief Initializes the TIM Input Capture Time base according to the specified
  1705. * parameters in the TIM_HandleTypeDef and initializes the associated handle.
  1706. * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
  1707. * requires a timer reset to avoid unexpected direction
  1708. * due to DIR bit readonly in center aligned mode.
  1709. * Ex: call @ref HAL_TIM_IC_DeInit() before HAL_TIM_IC_Init()
  1710. * @param htim TIM Input Capture handle
  1711. * @retval HAL status
  1712. */
  1713. HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim)
  1714. {
  1715. /* Check the TIM handle allocation */
  1716. if (htim == NULL)
  1717. {
  1718. return HAL_ERROR;
  1719. }
  1720. /* Check the parameters */
  1721. assert_param(IS_TIM_INSTANCE(htim->Instance));
  1722. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  1723. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  1724. assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
  1725. assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
  1726. if (htim->State == HAL_TIM_STATE_RESET)
  1727. {
  1728. /* Allocate lock resource and initialize it */
  1729. htim->Lock = HAL_UNLOCKED;
  1730. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  1731. /* Reset interrupt callbacks to legacy weak callbacks */
  1732. TIM_ResetCallback(htim);
  1733. if (htim->IC_MspInitCallback == NULL)
  1734. {
  1735. htim->IC_MspInitCallback = HAL_TIM_IC_MspInit;
  1736. }
  1737. /* Init the low level hardware : GPIO, CLOCK, NVIC */
  1738. htim->IC_MspInitCallback(htim);
  1739. #else
  1740. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  1741. HAL_TIM_IC_MspInit(htim);
  1742. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  1743. }
  1744. /* Set the TIM state */
  1745. htim->State = HAL_TIM_STATE_BUSY;
  1746. /* Init the base time for the input capture */
  1747. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  1748. /* Initialize the DMA burst operation state */
  1749. htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
  1750. /* Initialize the TIM channels state */
  1751. TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
  1752. TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
  1753. /* Initialize the TIM state*/
  1754. htim->State = HAL_TIM_STATE_READY;
  1755. return HAL_OK;
  1756. }
  1757. /**
  1758. * @brief DeInitializes the TIM peripheral
  1759. * @param htim TIM Input Capture handle
  1760. * @retval HAL status
  1761. */
  1762. HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim)
  1763. {
  1764. /* Check the parameters */
  1765. assert_param(IS_TIM_INSTANCE(htim->Instance));
  1766. htim->State = HAL_TIM_STATE_BUSY;
  1767. /* Disable the TIM Peripheral Clock */
  1768. __HAL_TIM_DISABLE(htim);
  1769. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  1770. if (htim->IC_MspDeInitCallback == NULL)
  1771. {
  1772. htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit;
  1773. }
  1774. /* DeInit the low level hardware */
  1775. htim->IC_MspDeInitCallback(htim);
  1776. #else
  1777. /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
  1778. HAL_TIM_IC_MspDeInit(htim);
  1779. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  1780. /* Change the DMA burst operation state */
  1781. htim->DMABurstState = HAL_DMA_BURST_STATE_RESET;
  1782. /* Change the TIM channels state */
  1783. TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
  1784. TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
  1785. /* Change TIM state */
  1786. htim->State = HAL_TIM_STATE_RESET;
  1787. /* Release Lock */
  1788. __HAL_UNLOCK(htim);
  1789. return HAL_OK;
  1790. }
  1791. /**
  1792. * @brief Initializes the TIM Input Capture MSP.
  1793. * @param htim TIM Input Capture handle
  1794. * @retval None
  1795. */
  1796. __weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim)
  1797. {
  1798. /* Prevent unused argument(s) compilation warning */
  1799. UNUSED(htim);
  1800. /* NOTE : This function should not be modified, when the callback is needed,
  1801. the HAL_TIM_IC_MspInit could be implemented in the user file
  1802. */
  1803. }
  1804. /**
  1805. * @brief DeInitializes TIM Input Capture MSP.
  1806. * @param htim TIM handle
  1807. * @retval None
  1808. */
  1809. __weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim)
  1810. {
  1811. /* Prevent unused argument(s) compilation warning */
  1812. UNUSED(htim);
  1813. /* NOTE : This function should not be modified, when the callback is needed,
  1814. the HAL_TIM_IC_MspDeInit could be implemented in the user file
  1815. */
  1816. }
  1817. /**
  1818. * @brief Starts the TIM Input Capture measurement.
  1819. * @param htim TIM Input Capture handle
  1820. * @param Channel TIM Channels to be enabled
  1821. * This parameter can be one of the following values:
  1822. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1823. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1824. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1825. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1826. * @retval HAL status
  1827. */
  1828. HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
  1829. {
  1830. uint32_t tmpsmcr;
  1831. HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
  1832. HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel);
  1833. /* Check the parameters */
  1834. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  1835. /* Check the TIM channel state */
  1836. if ((channel_state != HAL_TIM_CHANNEL_STATE_READY)
  1837. || (complementary_channel_state != HAL_TIM_CHANNEL_STATE_READY))
  1838. {
  1839. return HAL_ERROR;
  1840. }
  1841. /* Set the TIM channel state */
  1842. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
  1843. TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
  1844. /* Enable the Input Capture channel */
  1845. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  1846. /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
  1847. if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
  1848. {
  1849. tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
  1850. if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
  1851. {
  1852. __HAL_TIM_ENABLE(htim);
  1853. }
  1854. }
  1855. else
  1856. {
  1857. __HAL_TIM_ENABLE(htim);
  1858. }
  1859. /* Return function status */
  1860. return HAL_OK;
  1861. }
  1862. /**
  1863. * @brief Stops the TIM Input Capture measurement.
  1864. * @param htim TIM Input Capture handle
  1865. * @param Channel TIM Channels to be disabled
  1866. * This parameter can be one of the following values:
  1867. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1868. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1869. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1870. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1871. * @retval HAL status
  1872. */
  1873. HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
  1874. {
  1875. /* Check the parameters */
  1876. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  1877. /* Disable the Input Capture channel */
  1878. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  1879. /* Disable the Peripheral */
  1880. __HAL_TIM_DISABLE(htim);
  1881. /* Set the TIM channel state */
  1882. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  1883. TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  1884. /* Return function status */
  1885. return HAL_OK;
  1886. }
  1887. /**
  1888. * @brief Starts the TIM Input Capture measurement in interrupt mode.
  1889. * @param htim TIM Input Capture handle
  1890. * @param Channel TIM Channels to be enabled
  1891. * This parameter can be one of the following values:
  1892. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1893. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1894. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1895. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1896. * @retval HAL status
  1897. */
  1898. HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  1899. {
  1900. HAL_StatusTypeDef status = HAL_OK;
  1901. uint32_t tmpsmcr;
  1902. HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
  1903. HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel);
  1904. /* Check the parameters */
  1905. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  1906. /* Check the TIM channel state */
  1907. if ((channel_state != HAL_TIM_CHANNEL_STATE_READY)
  1908. || (complementary_channel_state != HAL_TIM_CHANNEL_STATE_READY))
  1909. {
  1910. return HAL_ERROR;
  1911. }
  1912. /* Set the TIM channel state */
  1913. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
  1914. TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
  1915. switch (Channel)
  1916. {
  1917. case TIM_CHANNEL_1:
  1918. {
  1919. /* Enable the TIM Capture/Compare 1 interrupt */
  1920. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  1921. break;
  1922. }
  1923. case TIM_CHANNEL_2:
  1924. {
  1925. /* Enable the TIM Capture/Compare 2 interrupt */
  1926. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  1927. break;
  1928. }
  1929. case TIM_CHANNEL_3:
  1930. {
  1931. /* Enable the TIM Capture/Compare 3 interrupt */
  1932. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
  1933. break;
  1934. }
  1935. case TIM_CHANNEL_4:
  1936. {
  1937. /* Enable the TIM Capture/Compare 4 interrupt */
  1938. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
  1939. break;
  1940. }
  1941. default:
  1942. status = HAL_ERROR;
  1943. break;
  1944. }
  1945. if (status == HAL_OK)
  1946. {
  1947. /* Enable the Input Capture channel */
  1948. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  1949. /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
  1950. if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
  1951. {
  1952. tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
  1953. if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
  1954. {
  1955. __HAL_TIM_ENABLE(htim);
  1956. }
  1957. }
  1958. else
  1959. {
  1960. __HAL_TIM_ENABLE(htim);
  1961. }
  1962. }
  1963. /* Return function status */
  1964. return status;
  1965. }
  1966. /**
  1967. * @brief Stops the TIM Input Capture measurement in interrupt mode.
  1968. * @param htim TIM Input Capture handle
  1969. * @param Channel TIM Channels to be disabled
  1970. * This parameter can be one of the following values:
  1971. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1972. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1973. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1974. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1975. * @retval HAL status
  1976. */
  1977. HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  1978. {
  1979. HAL_StatusTypeDef status = HAL_OK;
  1980. /* Check the parameters */
  1981. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  1982. switch (Channel)
  1983. {
  1984. case TIM_CHANNEL_1:
  1985. {
  1986. /* Disable the TIM Capture/Compare 1 interrupt */
  1987. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  1988. break;
  1989. }
  1990. case TIM_CHANNEL_2:
  1991. {
  1992. /* Disable the TIM Capture/Compare 2 interrupt */
  1993. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  1994. break;
  1995. }
  1996. case TIM_CHANNEL_3:
  1997. {
  1998. /* Disable the TIM Capture/Compare 3 interrupt */
  1999. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
  2000. break;
  2001. }
  2002. case TIM_CHANNEL_4:
  2003. {
  2004. /* Disable the TIM Capture/Compare 4 interrupt */
  2005. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
  2006. break;
  2007. }
  2008. default:
  2009. status = HAL_ERROR;
  2010. break;
  2011. }
  2012. if (status == HAL_OK)
  2013. {
  2014. /* Disable the Input Capture channel */
  2015. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  2016. /* Disable the Peripheral */
  2017. __HAL_TIM_DISABLE(htim);
  2018. /* Set the TIM channel state */
  2019. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  2020. TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  2021. }
  2022. /* Return function status */
  2023. return status;
  2024. }
  2025. /**
  2026. * @brief Starts the TIM Input Capture measurement in DMA mode.
  2027. * @param htim TIM Input Capture handle
  2028. * @param Channel TIM Channels to be enabled
  2029. * This parameter can be one of the following values:
  2030. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2031. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2032. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  2033. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  2034. * @param pData The destination Buffer address.
  2035. * @param Length The length of data to be transferred from TIM peripheral to memory.
  2036. * @retval HAL status
  2037. */
  2038. HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
  2039. {
  2040. HAL_StatusTypeDef status = HAL_OK;
  2041. uint32_t tmpsmcr;
  2042. HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
  2043. HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel);
  2044. /* Check the parameters */
  2045. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  2046. assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
  2047. /* Set the TIM channel state */
  2048. if ((channel_state == HAL_TIM_CHANNEL_STATE_BUSY)
  2049. || (complementary_channel_state == HAL_TIM_CHANNEL_STATE_BUSY))
  2050. {
  2051. return HAL_BUSY;
  2052. }
  2053. else if ((channel_state == HAL_TIM_CHANNEL_STATE_READY)
  2054. && (complementary_channel_state == HAL_TIM_CHANNEL_STATE_READY))
  2055. {
  2056. if ((pData == NULL) || (Length == 0U))
  2057. {
  2058. return HAL_ERROR;
  2059. }
  2060. else
  2061. {
  2062. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
  2063. TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
  2064. }
  2065. }
  2066. else
  2067. {
  2068. return HAL_ERROR;
  2069. }
  2070. /* Enable the Input Capture channel */
  2071. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  2072. switch (Channel)
  2073. {
  2074. case TIM_CHANNEL_1:
  2075. {
  2076. /* Set the DMA capture callbacks */
  2077. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
  2078. htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
  2079. /* Set the DMA error callback */
  2080. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
  2081. /* Enable the DMA channel */
  2082. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData,
  2083. Length) != HAL_OK)
  2084. {
  2085. /* Return error status */
  2086. return HAL_ERROR;
  2087. }
  2088. /* Enable the TIM Capture/Compare 1 DMA request */
  2089. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  2090. break;
  2091. }
  2092. case TIM_CHANNEL_2:
  2093. {
  2094. /* Set the DMA capture callbacks */
  2095. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
  2096. htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
  2097. /* Set the DMA error callback */
  2098. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
  2099. /* Enable the DMA channel */
  2100. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData,
  2101. Length) != HAL_OK)
  2102. {
  2103. /* Return error status */
  2104. return HAL_ERROR;
  2105. }
  2106. /* Enable the TIM Capture/Compare 2 DMA request */
  2107. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  2108. break;
  2109. }
  2110. case TIM_CHANNEL_3:
  2111. {
  2112. /* Set the DMA capture callbacks */
  2113. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt;
  2114. htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
  2115. /* Set the DMA error callback */
  2116. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
  2117. /* Enable the DMA channel */
  2118. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData,
  2119. Length) != HAL_OK)
  2120. {
  2121. /* Return error status */
  2122. return HAL_ERROR;
  2123. }
  2124. /* Enable the TIM Capture/Compare 3 DMA request */
  2125. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
  2126. break;
  2127. }
  2128. case TIM_CHANNEL_4:
  2129. {
  2130. /* Set the DMA capture callbacks */
  2131. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt;
  2132. htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
  2133. /* Set the DMA error callback */
  2134. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
  2135. /* Enable the DMA channel */
  2136. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData,
  2137. Length) != HAL_OK)
  2138. {
  2139. /* Return error status */
  2140. return HAL_ERROR;
  2141. }
  2142. /* Enable the TIM Capture/Compare 4 DMA request */
  2143. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
  2144. break;
  2145. }
  2146. default:
  2147. status = HAL_ERROR;
  2148. break;
  2149. }
  2150. /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
  2151. if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
  2152. {
  2153. tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
  2154. if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
  2155. {
  2156. __HAL_TIM_ENABLE(htim);
  2157. }
  2158. }
  2159. else
  2160. {
  2161. __HAL_TIM_ENABLE(htim);
  2162. }
  2163. /* Return function status */
  2164. return status;
  2165. }
  2166. /**
  2167. * @brief Stops the TIM Input Capture measurement in DMA mode.
  2168. * @param htim TIM Input Capture handle
  2169. * @param Channel TIM Channels to be disabled
  2170. * This parameter can be one of the following values:
  2171. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2172. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2173. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  2174. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  2175. * @retval HAL status
  2176. */
  2177. HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
  2178. {
  2179. HAL_StatusTypeDef status = HAL_OK;
  2180. /* Check the parameters */
  2181. assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
  2182. assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
  2183. /* Disable the Input Capture channel */
  2184. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  2185. switch (Channel)
  2186. {
  2187. case TIM_CHANNEL_1:
  2188. {
  2189. /* Disable the TIM Capture/Compare 1 DMA request */
  2190. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  2191. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
  2192. break;
  2193. }
  2194. case TIM_CHANNEL_2:
  2195. {
  2196. /* Disable the TIM Capture/Compare 2 DMA request */
  2197. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  2198. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
  2199. break;
  2200. }
  2201. case TIM_CHANNEL_3:
  2202. {
  2203. /* Disable the TIM Capture/Compare 3 DMA request */
  2204. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
  2205. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
  2206. break;
  2207. }
  2208. case TIM_CHANNEL_4:
  2209. {
  2210. /* Disable the TIM Capture/Compare 4 DMA request */
  2211. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
  2212. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
  2213. break;
  2214. }
  2215. default:
  2216. status = HAL_ERROR;
  2217. break;
  2218. }
  2219. if (status == HAL_OK)
  2220. {
  2221. /* Disable the Peripheral */
  2222. __HAL_TIM_DISABLE(htim);
  2223. /* Set the TIM channel state */
  2224. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  2225. TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  2226. }
  2227. /* Return function status */
  2228. return status;
  2229. }
  2230. /**
  2231. * @}
  2232. */
  2233. /** @defgroup TIM_Exported_Functions_Group5 TIM One Pulse functions
  2234. * @brief TIM One Pulse functions
  2235. *
  2236. @verbatim
  2237. ==============================================================================
  2238. ##### TIM One Pulse functions #####
  2239. ==============================================================================
  2240. [..]
  2241. This section provides functions allowing to:
  2242. (+) Initialize and configure the TIM One Pulse.
  2243. (+) De-initialize the TIM One Pulse.
  2244. (+) Start the TIM One Pulse.
  2245. (+) Stop the TIM One Pulse.
  2246. (+) Start the TIM One Pulse and enable interrupt.
  2247. (+) Stop the TIM One Pulse and disable interrupt.
  2248. (+) Start the TIM One Pulse and enable DMA transfer.
  2249. (+) Stop the TIM One Pulse and disable DMA transfer.
  2250. @endverbatim
  2251. * @{
  2252. */
  2253. /**
  2254. * @brief Initializes the TIM One Pulse Time Base according to the specified
  2255. * parameters in the TIM_HandleTypeDef and initializes the associated handle.
  2256. * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
  2257. * requires a timer reset to avoid unexpected direction
  2258. * due to DIR bit readonly in center aligned mode.
  2259. * Ex: call @ref HAL_TIM_OnePulse_DeInit() before HAL_TIM_OnePulse_Init()
  2260. * @note When the timer instance is initialized in One Pulse mode, timer
  2261. * channels 1 and channel 2 are reserved and cannot be used for other
  2262. * purpose.
  2263. * @param htim TIM One Pulse handle
  2264. * @param OnePulseMode Select the One pulse mode.
  2265. * This parameter can be one of the following values:
  2266. * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated.
  2267. * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses will be generated.
  2268. * @retval HAL status
  2269. */
  2270. HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode)
  2271. {
  2272. /* Check the TIM handle allocation */
  2273. if (htim == NULL)
  2274. {
  2275. return HAL_ERROR;
  2276. }
  2277. /* Check the parameters */
  2278. assert_param(IS_TIM_INSTANCE(htim->Instance));
  2279. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  2280. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  2281. assert_param(IS_TIM_OPM_MODE(OnePulseMode));
  2282. assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
  2283. assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
  2284. if (htim->State == HAL_TIM_STATE_RESET)
  2285. {
  2286. /* Allocate lock resource and initialize it */
  2287. htim->Lock = HAL_UNLOCKED;
  2288. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  2289. /* Reset interrupt callbacks to legacy weak callbacks */
  2290. TIM_ResetCallback(htim);
  2291. if (htim->OnePulse_MspInitCallback == NULL)
  2292. {
  2293. htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit;
  2294. }
  2295. /* Init the low level hardware : GPIO, CLOCK, NVIC */
  2296. htim->OnePulse_MspInitCallback(htim);
  2297. #else
  2298. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  2299. HAL_TIM_OnePulse_MspInit(htim);
  2300. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  2301. }
  2302. /* Set the TIM state */
  2303. htim->State = HAL_TIM_STATE_BUSY;
  2304. /* Configure the Time base in the One Pulse Mode */
  2305. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  2306. /* Reset the OPM Bit */
  2307. htim->Instance->CR1 &= ~TIM_CR1_OPM;
  2308. /* Configure the OPM Mode */
  2309. htim->Instance->CR1 |= OnePulseMode;
  2310. /* Initialize the DMA burst operation state */
  2311. htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
  2312. /* Initialize the TIM channels state */
  2313. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  2314. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  2315. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  2316. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  2317. /* Initialize the TIM state*/
  2318. htim->State = HAL_TIM_STATE_READY;
  2319. return HAL_OK;
  2320. }
  2321. /**
  2322. * @brief DeInitializes the TIM One Pulse
  2323. * @param htim TIM One Pulse handle
  2324. * @retval HAL status
  2325. */
  2326. HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim)
  2327. {
  2328. /* Check the parameters */
  2329. assert_param(IS_TIM_INSTANCE(htim->Instance));
  2330. htim->State = HAL_TIM_STATE_BUSY;
  2331. /* Disable the TIM Peripheral Clock */
  2332. __HAL_TIM_DISABLE(htim);
  2333. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  2334. if (htim->OnePulse_MspDeInitCallback == NULL)
  2335. {
  2336. htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit;
  2337. }
  2338. /* DeInit the low level hardware */
  2339. htim->OnePulse_MspDeInitCallback(htim);
  2340. #else
  2341. /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
  2342. HAL_TIM_OnePulse_MspDeInit(htim);
  2343. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  2344. /* Change the DMA burst operation state */
  2345. htim->DMABurstState = HAL_DMA_BURST_STATE_RESET;
  2346. /* Set the TIM channel state */
  2347. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET);
  2348. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET);
  2349. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET);
  2350. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET);
  2351. /* Change TIM state */
  2352. htim->State = HAL_TIM_STATE_RESET;
  2353. /* Release Lock */
  2354. __HAL_UNLOCK(htim);
  2355. return HAL_OK;
  2356. }
  2357. /**
  2358. * @brief Initializes the TIM One Pulse MSP.
  2359. * @param htim TIM One Pulse handle
  2360. * @retval None
  2361. */
  2362. __weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim)
  2363. {
  2364. /* Prevent unused argument(s) compilation warning */
  2365. UNUSED(htim);
  2366. /* NOTE : This function should not be modified, when the callback is needed,
  2367. the HAL_TIM_OnePulse_MspInit could be implemented in the user file
  2368. */
  2369. }
  2370. /**
  2371. * @brief DeInitializes TIM One Pulse MSP.
  2372. * @param htim TIM One Pulse handle
  2373. * @retval None
  2374. */
  2375. __weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim)
  2376. {
  2377. /* Prevent unused argument(s) compilation warning */
  2378. UNUSED(htim);
  2379. /* NOTE : This function should not be modified, when the callback is needed,
  2380. the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file
  2381. */
  2382. }
  2383. /**
  2384. * @brief Starts the TIM One Pulse signal generation.
  2385. * @note Though OutputChannel parameter is deprecated and ignored by the function
  2386. * it has been kept to avoid HAL_TIM API compatibility break.
  2387. * @note The pulse output channel is determined when calling
  2388. * @ref HAL_TIM_OnePulse_ConfigChannel().
  2389. * @param htim TIM One Pulse handle
  2390. * @param OutputChannel See note above
  2391. * @retval HAL status
  2392. */
  2393. HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  2394. {
  2395. HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
  2396. HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
  2397. HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
  2398. HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
  2399. /* Prevent unused argument(s) compilation warning */
  2400. UNUSED(OutputChannel);
  2401. /* Check the TIM channels state */
  2402. if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
  2403. || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
  2404. || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
  2405. || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
  2406. {
  2407. return HAL_ERROR;
  2408. }
  2409. /* Set the TIM channels state */
  2410. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  2411. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  2412. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  2413. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  2414. /* Enable the Capture compare and the Input Capture channels
  2415. (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
  2416. if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
  2417. if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
  2418. whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
  2419. No need to enable the counter, it's enabled automatically by hardware
  2420. (the counter starts in response to a stimulus and generate a pulse */
  2421. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  2422. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  2423. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  2424. {
  2425. /* Enable the main output */
  2426. __HAL_TIM_MOE_ENABLE(htim);
  2427. }
  2428. /* Return function status */
  2429. return HAL_OK;
  2430. }
  2431. /**
  2432. * @brief Stops the TIM One Pulse signal generation.
  2433. * @note Though OutputChannel parameter is deprecated and ignored by the function
  2434. * it has been kept to avoid HAL_TIM API compatibility break.
  2435. * @note The pulse output channel is determined when calling
  2436. * @ref HAL_TIM_OnePulse_ConfigChannel().
  2437. * @param htim TIM One Pulse handle
  2438. * @param OutputChannel See note above
  2439. * @retval HAL status
  2440. */
  2441. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  2442. {
  2443. /* Prevent unused argument(s) compilation warning */
  2444. UNUSED(OutputChannel);
  2445. /* Disable the Capture compare and the Input Capture channels
  2446. (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
  2447. if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
  2448. if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
  2449. whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
  2450. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  2451. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  2452. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  2453. {
  2454. /* Disable the Main Output */
  2455. __HAL_TIM_MOE_DISABLE(htim);
  2456. }
  2457. /* Disable the Peripheral */
  2458. __HAL_TIM_DISABLE(htim);
  2459. /* Set the TIM channels state */
  2460. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  2461. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  2462. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  2463. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  2464. /* Return function status */
  2465. return HAL_OK;
  2466. }
  2467. /**
  2468. * @brief Starts the TIM One Pulse signal generation in interrupt mode.
  2469. * @note Though OutputChannel parameter is deprecated and ignored by the function
  2470. * it has been kept to avoid HAL_TIM API compatibility break.
  2471. * @note The pulse output channel is determined when calling
  2472. * @ref HAL_TIM_OnePulse_ConfigChannel().
  2473. * @param htim TIM One Pulse handle
  2474. * @param OutputChannel See note above
  2475. * @retval HAL status
  2476. */
  2477. HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  2478. {
  2479. HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
  2480. HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
  2481. HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
  2482. HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
  2483. /* Prevent unused argument(s) compilation warning */
  2484. UNUSED(OutputChannel);
  2485. /* Check the TIM channels state */
  2486. if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
  2487. || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
  2488. || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
  2489. || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
  2490. {
  2491. return HAL_ERROR;
  2492. }
  2493. /* Set the TIM channels state */
  2494. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  2495. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  2496. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  2497. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  2498. /* Enable the Capture compare and the Input Capture channels
  2499. (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
  2500. if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
  2501. if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
  2502. whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
  2503. No need to enable the counter, it's enabled automatically by hardware
  2504. (the counter starts in response to a stimulus and generate a pulse */
  2505. /* Enable the TIM Capture/Compare 1 interrupt */
  2506. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  2507. /* Enable the TIM Capture/Compare 2 interrupt */
  2508. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  2509. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  2510. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  2511. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  2512. {
  2513. /* Enable the main output */
  2514. __HAL_TIM_MOE_ENABLE(htim);
  2515. }
  2516. /* Return function status */
  2517. return HAL_OK;
  2518. }
  2519. /**
  2520. * @brief Stops the TIM One Pulse signal generation in interrupt mode.
  2521. * @note Though OutputChannel parameter is deprecated and ignored by the function
  2522. * it has been kept to avoid HAL_TIM API compatibility break.
  2523. * @note The pulse output channel is determined when calling
  2524. * @ref HAL_TIM_OnePulse_ConfigChannel().
  2525. * @param htim TIM One Pulse handle
  2526. * @param OutputChannel See note above
  2527. * @retval HAL status
  2528. */
  2529. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  2530. {
  2531. /* Prevent unused argument(s) compilation warning */
  2532. UNUSED(OutputChannel);
  2533. /* Disable the TIM Capture/Compare 1 interrupt */
  2534. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  2535. /* Disable the TIM Capture/Compare 2 interrupt */
  2536. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  2537. /* Disable the Capture compare and the Input Capture channels
  2538. (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
  2539. if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
  2540. if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
  2541. whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
  2542. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  2543. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  2544. if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
  2545. {
  2546. /* Disable the Main Output */
  2547. __HAL_TIM_MOE_DISABLE(htim);
  2548. }
  2549. /* Disable the Peripheral */
  2550. __HAL_TIM_DISABLE(htim);
  2551. /* Set the TIM channels state */
  2552. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  2553. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  2554. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  2555. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  2556. /* Return function status */
  2557. return HAL_OK;
  2558. }
  2559. /**
  2560. * @}
  2561. */
  2562. /** @defgroup TIM_Exported_Functions_Group6 TIM Encoder functions
  2563. * @brief TIM Encoder functions
  2564. *
  2565. @verbatim
  2566. ==============================================================================
  2567. ##### TIM Encoder functions #####
  2568. ==============================================================================
  2569. [..]
  2570. This section provides functions allowing to:
  2571. (+) Initialize and configure the TIM Encoder.
  2572. (+) De-initialize the TIM Encoder.
  2573. (+) Start the TIM Encoder.
  2574. (+) Stop the TIM Encoder.
  2575. (+) Start the TIM Encoder and enable interrupt.
  2576. (+) Stop the TIM Encoder and disable interrupt.
  2577. (+) Start the TIM Encoder and enable DMA transfer.
  2578. (+) Stop the TIM Encoder and disable DMA transfer.
  2579. @endverbatim
  2580. * @{
  2581. */
  2582. /**
  2583. * @brief Initializes the TIM Encoder Interface and initialize the associated handle.
  2584. * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
  2585. * requires a timer reset to avoid unexpected direction
  2586. * due to DIR bit readonly in center aligned mode.
  2587. * Ex: call @ref HAL_TIM_Encoder_DeInit() before HAL_TIM_Encoder_Init()
  2588. * @note Encoder mode and External clock mode 2 are not compatible and must not be selected together
  2589. * Ex: A call for @ref HAL_TIM_Encoder_Init will erase the settings of @ref HAL_TIM_ConfigClockSource
  2590. * using TIM_CLOCKSOURCE_ETRMODE2 and vice versa
  2591. * @note When the timer instance is initialized in Encoder mode, timer
  2592. * channels 1 and channel 2 are reserved and cannot be used for other
  2593. * purpose.
  2594. * @param htim TIM Encoder Interface handle
  2595. * @param sConfig TIM Encoder Interface configuration structure
  2596. * @retval HAL status
  2597. */
  2598. HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, const TIM_Encoder_InitTypeDef *sConfig)
  2599. {
  2600. uint32_t tmpsmcr;
  2601. uint32_t tmpccmr1;
  2602. uint32_t tmpccer;
  2603. /* Check the TIM handle allocation */
  2604. if (htim == NULL)
  2605. {
  2606. return HAL_ERROR;
  2607. }
  2608. /* Check the parameters */
  2609. assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
  2610. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  2611. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  2612. assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
  2613. assert_param(IS_TIM_ENCODER_MODE(sConfig->EncoderMode));
  2614. assert_param(IS_TIM_IC_SELECTION(sConfig->IC1Selection));
  2615. assert_param(IS_TIM_IC_SELECTION(sConfig->IC2Selection));
  2616. assert_param(IS_TIM_ENCODERINPUT_POLARITY(sConfig->IC1Polarity));
  2617. assert_param(IS_TIM_ENCODERINPUT_POLARITY(sConfig->IC2Polarity));
  2618. assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
  2619. assert_param(IS_TIM_IC_PRESCALER(sConfig->IC2Prescaler));
  2620. assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
  2621. assert_param(IS_TIM_IC_FILTER(sConfig->IC2Filter));
  2622. assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
  2623. if (htim->State == HAL_TIM_STATE_RESET)
  2624. {
  2625. /* Allocate lock resource and initialize it */
  2626. htim->Lock = HAL_UNLOCKED;
  2627. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  2628. /* Reset interrupt callbacks to legacy weak callbacks */
  2629. TIM_ResetCallback(htim);
  2630. if (htim->Encoder_MspInitCallback == NULL)
  2631. {
  2632. htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit;
  2633. }
  2634. /* Init the low level hardware : GPIO, CLOCK, NVIC */
  2635. htim->Encoder_MspInitCallback(htim);
  2636. #else
  2637. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  2638. HAL_TIM_Encoder_MspInit(htim);
  2639. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  2640. }
  2641. /* Set the TIM state */
  2642. htim->State = HAL_TIM_STATE_BUSY;
  2643. /* Reset the SMS and ECE bits */
  2644. htim->Instance->SMCR &= ~(TIM_SMCR_SMS | TIM_SMCR_ECE);
  2645. /* Configure the Time base in the Encoder Mode */
  2646. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  2647. /* Get the TIMx SMCR register value */
  2648. tmpsmcr = htim->Instance->SMCR;
  2649. /* Get the TIMx CCMR1 register value */
  2650. tmpccmr1 = htim->Instance->CCMR1;
  2651. /* Get the TIMx CCER register value */
  2652. tmpccer = htim->Instance->CCER;
  2653. /* Set the encoder Mode */
  2654. tmpsmcr |= sConfig->EncoderMode;
  2655. /* Select the Capture Compare 1 and the Capture Compare 2 as input */
  2656. tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S);
  2657. tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8U));
  2658. /* Set the Capture Compare 1 and the Capture Compare 2 prescalers and filters */
  2659. tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC);
  2660. tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F);
  2661. tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8U);
  2662. tmpccmr1 |= (sConfig->IC1Filter << 4U) | (sConfig->IC2Filter << 12U);
  2663. /* Set the TI1 and the TI2 Polarities */
  2664. tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P);
  2665. tmpccer &= ~(TIM_CCER_CC1NP | TIM_CCER_CC2NP);
  2666. tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4U);
  2667. /* Write to TIMx SMCR */
  2668. htim->Instance->SMCR = tmpsmcr;
  2669. /* Write to TIMx CCMR1 */
  2670. htim->Instance->CCMR1 = tmpccmr1;
  2671. /* Write to TIMx CCER */
  2672. htim->Instance->CCER = tmpccer;
  2673. /* Initialize the DMA burst operation state */
  2674. htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
  2675. /* Set the TIM channels state */
  2676. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  2677. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  2678. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  2679. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  2680. /* Initialize the TIM state*/
  2681. htim->State = HAL_TIM_STATE_READY;
  2682. return HAL_OK;
  2683. }
  2684. /**
  2685. * @brief DeInitializes the TIM Encoder interface
  2686. * @param htim TIM Encoder Interface handle
  2687. * @retval HAL status
  2688. */
  2689. HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim)
  2690. {
  2691. /* Check the parameters */
  2692. assert_param(IS_TIM_INSTANCE(htim->Instance));
  2693. htim->State = HAL_TIM_STATE_BUSY;
  2694. /* Disable the TIM Peripheral Clock */
  2695. __HAL_TIM_DISABLE(htim);
  2696. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  2697. if (htim->Encoder_MspDeInitCallback == NULL)
  2698. {
  2699. htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit;
  2700. }
  2701. /* DeInit the low level hardware */
  2702. htim->Encoder_MspDeInitCallback(htim);
  2703. #else
  2704. /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
  2705. HAL_TIM_Encoder_MspDeInit(htim);
  2706. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  2707. /* Change the DMA burst operation state */
  2708. htim->DMABurstState = HAL_DMA_BURST_STATE_RESET;
  2709. /* Set the TIM channels state */
  2710. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET);
  2711. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET);
  2712. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET);
  2713. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET);
  2714. /* Change TIM state */
  2715. htim->State = HAL_TIM_STATE_RESET;
  2716. /* Release Lock */
  2717. __HAL_UNLOCK(htim);
  2718. return HAL_OK;
  2719. }
  2720. /**
  2721. * @brief Initializes the TIM Encoder Interface MSP.
  2722. * @param htim TIM Encoder Interface handle
  2723. * @retval None
  2724. */
  2725. __weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
  2726. {
  2727. /* Prevent unused argument(s) compilation warning */
  2728. UNUSED(htim);
  2729. /* NOTE : This function should not be modified, when the callback is needed,
  2730. the HAL_TIM_Encoder_MspInit could be implemented in the user file
  2731. */
  2732. }
  2733. /**
  2734. * @brief DeInitializes TIM Encoder Interface MSP.
  2735. * @param htim TIM Encoder Interface handle
  2736. * @retval None
  2737. */
  2738. __weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim)
  2739. {
  2740. /* Prevent unused argument(s) compilation warning */
  2741. UNUSED(htim);
  2742. /* NOTE : This function should not be modified, when the callback is needed,
  2743. the HAL_TIM_Encoder_MspDeInit could be implemented in the user file
  2744. */
  2745. }
  2746. /**
  2747. * @brief Starts the TIM Encoder Interface.
  2748. * @param htim TIM Encoder Interface handle
  2749. * @param Channel TIM Channels to be enabled
  2750. * This parameter can be one of the following values:
  2751. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2752. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2753. * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
  2754. * @retval HAL status
  2755. */
  2756. HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
  2757. {
  2758. HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
  2759. HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
  2760. HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
  2761. HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
  2762. /* Check the parameters */
  2763. assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
  2764. /* Set the TIM channel(s) state */
  2765. if (Channel == TIM_CHANNEL_1)
  2766. {
  2767. if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
  2768. || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY))
  2769. {
  2770. return HAL_ERROR;
  2771. }
  2772. else
  2773. {
  2774. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  2775. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  2776. }
  2777. }
  2778. else if (Channel == TIM_CHANNEL_2)
  2779. {
  2780. if ((channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
  2781. || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
  2782. {
  2783. return HAL_ERROR;
  2784. }
  2785. else
  2786. {
  2787. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  2788. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  2789. }
  2790. }
  2791. else
  2792. {
  2793. if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
  2794. || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
  2795. || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
  2796. || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
  2797. {
  2798. return HAL_ERROR;
  2799. }
  2800. else
  2801. {
  2802. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  2803. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  2804. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  2805. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  2806. }
  2807. }
  2808. /* Enable the encoder interface channels */
  2809. switch (Channel)
  2810. {
  2811. case TIM_CHANNEL_1:
  2812. {
  2813. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  2814. break;
  2815. }
  2816. case TIM_CHANNEL_2:
  2817. {
  2818. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  2819. break;
  2820. }
  2821. default :
  2822. {
  2823. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  2824. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  2825. break;
  2826. }
  2827. }
  2828. /* Enable the Peripheral */
  2829. __HAL_TIM_ENABLE(htim);
  2830. /* Return function status */
  2831. return HAL_OK;
  2832. }
  2833. /**
  2834. * @brief Stops the TIM Encoder Interface.
  2835. * @param htim TIM Encoder Interface handle
  2836. * @param Channel TIM Channels to be disabled
  2837. * This parameter can be one of the following values:
  2838. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2839. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2840. * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
  2841. * @retval HAL status
  2842. */
  2843. HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
  2844. {
  2845. /* Check the parameters */
  2846. assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
  2847. /* Disable the Input Capture channels 1 and 2
  2848. (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
  2849. switch (Channel)
  2850. {
  2851. case TIM_CHANNEL_1:
  2852. {
  2853. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  2854. break;
  2855. }
  2856. case TIM_CHANNEL_2:
  2857. {
  2858. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  2859. break;
  2860. }
  2861. default :
  2862. {
  2863. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  2864. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  2865. break;
  2866. }
  2867. }
  2868. /* Disable the Peripheral */
  2869. __HAL_TIM_DISABLE(htim);
  2870. /* Set the TIM channel(s) state */
  2871. if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2))
  2872. {
  2873. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  2874. TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  2875. }
  2876. else
  2877. {
  2878. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  2879. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  2880. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  2881. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  2882. }
  2883. /* Return function status */
  2884. return HAL_OK;
  2885. }
  2886. /**
  2887. * @brief Starts the TIM Encoder Interface in interrupt mode.
  2888. * @param htim TIM Encoder Interface handle
  2889. * @param Channel TIM Channels to be enabled
  2890. * This parameter can be one of the following values:
  2891. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2892. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2893. * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
  2894. * @retval HAL status
  2895. */
  2896. HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  2897. {
  2898. HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
  2899. HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
  2900. HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
  2901. HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
  2902. /* Check the parameters */
  2903. assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
  2904. /* Set the TIM channel(s) state */
  2905. if (Channel == TIM_CHANNEL_1)
  2906. {
  2907. if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
  2908. || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY))
  2909. {
  2910. return HAL_ERROR;
  2911. }
  2912. else
  2913. {
  2914. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  2915. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  2916. }
  2917. }
  2918. else if (Channel == TIM_CHANNEL_2)
  2919. {
  2920. if ((channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
  2921. || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
  2922. {
  2923. return HAL_ERROR;
  2924. }
  2925. else
  2926. {
  2927. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  2928. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  2929. }
  2930. }
  2931. else
  2932. {
  2933. if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
  2934. || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
  2935. || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
  2936. || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
  2937. {
  2938. return HAL_ERROR;
  2939. }
  2940. else
  2941. {
  2942. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  2943. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  2944. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  2945. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  2946. }
  2947. }
  2948. /* Enable the encoder interface channels */
  2949. /* Enable the capture compare Interrupts 1 and/or 2 */
  2950. switch (Channel)
  2951. {
  2952. case TIM_CHANNEL_1:
  2953. {
  2954. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  2955. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  2956. break;
  2957. }
  2958. case TIM_CHANNEL_2:
  2959. {
  2960. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  2961. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  2962. break;
  2963. }
  2964. default :
  2965. {
  2966. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  2967. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  2968. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  2969. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  2970. break;
  2971. }
  2972. }
  2973. /* Enable the Peripheral */
  2974. __HAL_TIM_ENABLE(htim);
  2975. /* Return function status */
  2976. return HAL_OK;
  2977. }
  2978. /**
  2979. * @brief Stops the TIM Encoder Interface in interrupt mode.
  2980. * @param htim TIM Encoder Interface handle
  2981. * @param Channel TIM Channels to be disabled
  2982. * This parameter can be one of the following values:
  2983. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2984. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2985. * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
  2986. * @retval HAL status
  2987. */
  2988. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  2989. {
  2990. /* Check the parameters */
  2991. assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
  2992. /* Disable the Input Capture channels 1 and 2
  2993. (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
  2994. if (Channel == TIM_CHANNEL_1)
  2995. {
  2996. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  2997. /* Disable the capture compare Interrupts 1 */
  2998. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  2999. }
  3000. else if (Channel == TIM_CHANNEL_2)
  3001. {
  3002. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  3003. /* Disable the capture compare Interrupts 2 */
  3004. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  3005. }
  3006. else
  3007. {
  3008. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  3009. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  3010. /* Disable the capture compare Interrupts 1 and 2 */
  3011. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  3012. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  3013. }
  3014. /* Disable the Peripheral */
  3015. __HAL_TIM_DISABLE(htim);
  3016. /* Set the TIM channel(s) state */
  3017. if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2))
  3018. {
  3019. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  3020. TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  3021. }
  3022. else
  3023. {
  3024. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  3025. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  3026. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  3027. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  3028. }
  3029. /* Return function status */
  3030. return HAL_OK;
  3031. }
  3032. /**
  3033. * @brief Starts the TIM Encoder Interface in DMA mode.
  3034. * @param htim TIM Encoder Interface handle
  3035. * @param Channel TIM Channels to be enabled
  3036. * This parameter can be one of the following values:
  3037. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  3038. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  3039. * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
  3040. * @param pData1 The destination Buffer address for IC1.
  3041. * @param pData2 The destination Buffer address for IC2.
  3042. * @param Length The length of data to be transferred from TIM peripheral to memory.
  3043. * @retval HAL status
  3044. */
  3045. HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1,
  3046. uint32_t *pData2, uint16_t Length)
  3047. {
  3048. HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
  3049. HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
  3050. HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
  3051. HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
  3052. /* Check the parameters */
  3053. assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
  3054. /* Set the TIM channel(s) state */
  3055. if (Channel == TIM_CHANNEL_1)
  3056. {
  3057. if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
  3058. || (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY))
  3059. {
  3060. return HAL_BUSY;
  3061. }
  3062. else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
  3063. && (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_READY))
  3064. {
  3065. if ((pData1 == NULL) || (Length == 0U))
  3066. {
  3067. return HAL_ERROR;
  3068. }
  3069. else
  3070. {
  3071. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  3072. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  3073. }
  3074. }
  3075. else
  3076. {
  3077. return HAL_ERROR;
  3078. }
  3079. }
  3080. else if (Channel == TIM_CHANNEL_2)
  3081. {
  3082. if ((channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY)
  3083. || (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY))
  3084. {
  3085. return HAL_BUSY;
  3086. }
  3087. else if ((channel_2_state == HAL_TIM_CHANNEL_STATE_READY)
  3088. && (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_READY))
  3089. {
  3090. if ((pData2 == NULL) || (Length == 0U))
  3091. {
  3092. return HAL_ERROR;
  3093. }
  3094. else
  3095. {
  3096. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  3097. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  3098. }
  3099. }
  3100. else
  3101. {
  3102. return HAL_ERROR;
  3103. }
  3104. }
  3105. else
  3106. {
  3107. if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
  3108. || (channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY)
  3109. || (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
  3110. || (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY))
  3111. {
  3112. return HAL_BUSY;
  3113. }
  3114. else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
  3115. && (channel_2_state == HAL_TIM_CHANNEL_STATE_READY)
  3116. && (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
  3117. && (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_READY))
  3118. {
  3119. if ((((pData1 == NULL) || (pData2 == NULL))) || (Length == 0U))
  3120. {
  3121. return HAL_ERROR;
  3122. }
  3123. else
  3124. {
  3125. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  3126. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  3127. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
  3128. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
  3129. }
  3130. }
  3131. else
  3132. {
  3133. return HAL_ERROR;
  3134. }
  3135. }
  3136. switch (Channel)
  3137. {
  3138. case TIM_CHANNEL_1:
  3139. {
  3140. /* Set the DMA capture callbacks */
  3141. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
  3142. htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
  3143. /* Set the DMA error callback */
  3144. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
  3145. /* Enable the DMA channel */
  3146. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1,
  3147. Length) != HAL_OK)
  3148. {
  3149. /* Return error status */
  3150. return HAL_ERROR;
  3151. }
  3152. /* Enable the TIM Input Capture DMA request */
  3153. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  3154. /* Enable the Capture compare channel */
  3155. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  3156. /* Enable the Peripheral */
  3157. __HAL_TIM_ENABLE(htim);
  3158. break;
  3159. }
  3160. case TIM_CHANNEL_2:
  3161. {
  3162. /* Set the DMA capture callbacks */
  3163. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
  3164. htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
  3165. /* Set the DMA error callback */
  3166. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError;
  3167. /* Enable the DMA channel */
  3168. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2,
  3169. Length) != HAL_OK)
  3170. {
  3171. /* Return error status */
  3172. return HAL_ERROR;
  3173. }
  3174. /* Enable the TIM Input Capture DMA request */
  3175. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  3176. /* Enable the Capture compare channel */
  3177. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  3178. /* Enable the Peripheral */
  3179. __HAL_TIM_ENABLE(htim);
  3180. break;
  3181. }
  3182. default:
  3183. {
  3184. /* Set the DMA capture callbacks */
  3185. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
  3186. htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
  3187. /* Set the DMA error callback */
  3188. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
  3189. /* Enable the DMA channel */
  3190. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1,
  3191. Length) != HAL_OK)
  3192. {
  3193. /* Return error status */
  3194. return HAL_ERROR;
  3195. }
  3196. /* Set the DMA capture callbacks */
  3197. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
  3198. htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
  3199. /* Set the DMA error callback */
  3200. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
  3201. /* Enable the DMA channel */
  3202. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2,
  3203. Length) != HAL_OK)
  3204. {
  3205. /* Return error status */
  3206. return HAL_ERROR;
  3207. }
  3208. /* Enable the TIM Input Capture DMA request */
  3209. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  3210. /* Enable the TIM Input Capture DMA request */
  3211. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  3212. /* Enable the Capture compare channel */
  3213. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  3214. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  3215. /* Enable the Peripheral */
  3216. __HAL_TIM_ENABLE(htim);
  3217. break;
  3218. }
  3219. }
  3220. /* Return function status */
  3221. return HAL_OK;
  3222. }
  3223. /**
  3224. * @brief Stops the TIM Encoder Interface in DMA mode.
  3225. * @param htim TIM Encoder Interface handle
  3226. * @param Channel TIM Channels to be enabled
  3227. * This parameter can be one of the following values:
  3228. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  3229. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  3230. * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
  3231. * @retval HAL status
  3232. */
  3233. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
  3234. {
  3235. /* Check the parameters */
  3236. assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
  3237. /* Disable the Input Capture channels 1 and 2
  3238. (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
  3239. if (Channel == TIM_CHANNEL_1)
  3240. {
  3241. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  3242. /* Disable the capture compare DMA Request 1 */
  3243. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  3244. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
  3245. }
  3246. else if (Channel == TIM_CHANNEL_2)
  3247. {
  3248. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  3249. /* Disable the capture compare DMA Request 2 */
  3250. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  3251. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
  3252. }
  3253. else
  3254. {
  3255. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  3256. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  3257. /* Disable the capture compare DMA Request 1 and 2 */
  3258. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  3259. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  3260. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
  3261. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
  3262. }
  3263. /* Disable the Peripheral */
  3264. __HAL_TIM_DISABLE(htim);
  3265. /* Set the TIM channel(s) state */
  3266. if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2))
  3267. {
  3268. TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  3269. TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
  3270. }
  3271. else
  3272. {
  3273. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  3274. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  3275. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  3276. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  3277. }
  3278. /* Return function status */
  3279. return HAL_OK;
  3280. }
  3281. /**
  3282. * @}
  3283. */
  3284. /** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management
  3285. * @brief TIM IRQ handler management
  3286. *
  3287. @verbatim
  3288. ==============================================================================
  3289. ##### IRQ handler management #####
  3290. ==============================================================================
  3291. [..]
  3292. This section provides Timer IRQ handler function.
  3293. @endverbatim
  3294. * @{
  3295. */
  3296. /**
  3297. * @brief This function handles TIM interrupts requests.
  3298. * @param htim TIM handle
  3299. * @retval None
  3300. */
  3301. void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim)
  3302. {
  3303. uint32_t itsource = htim->Instance->DIER;
  3304. uint32_t itflag = htim->Instance->SR;
  3305. /* Capture compare 1 event */
  3306. if ((itflag & (TIM_FLAG_CC1)) == (TIM_FLAG_CC1))
  3307. {
  3308. if ((itsource & (TIM_IT_CC1)) == (TIM_IT_CC1))
  3309. {
  3310. {
  3311. __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_CC1);
  3312. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
  3313. /* Input capture event */
  3314. if ((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00U)
  3315. {
  3316. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  3317. htim->IC_CaptureCallback(htim);
  3318. #else
  3319. HAL_TIM_IC_CaptureCallback(htim);
  3320. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  3321. }
  3322. /* Output compare event */
  3323. else
  3324. {
  3325. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  3326. htim->OC_DelayElapsedCallback(htim);
  3327. htim->PWM_PulseFinishedCallback(htim);
  3328. #else
  3329. HAL_TIM_OC_DelayElapsedCallback(htim);
  3330. HAL_TIM_PWM_PulseFinishedCallback(htim);
  3331. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  3332. }
  3333. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  3334. }
  3335. }
  3336. }
  3337. /* Capture compare 2 event */
  3338. if ((itflag & (TIM_FLAG_CC2)) == (TIM_FLAG_CC2))
  3339. {
  3340. if ((itsource & (TIM_IT_CC2)) == (TIM_IT_CC2))
  3341. {
  3342. __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_CC2);
  3343. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
  3344. /* Input capture event */
  3345. if ((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U)
  3346. {
  3347. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  3348. htim->IC_CaptureCallback(htim);
  3349. #else
  3350. HAL_TIM_IC_CaptureCallback(htim);
  3351. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  3352. }
  3353. /* Output compare event */
  3354. else
  3355. {
  3356. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  3357. htim->OC_DelayElapsedCallback(htim);
  3358. htim->PWM_PulseFinishedCallback(htim);
  3359. #else
  3360. HAL_TIM_OC_DelayElapsedCallback(htim);
  3361. HAL_TIM_PWM_PulseFinishedCallback(htim);
  3362. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  3363. }
  3364. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  3365. }
  3366. }
  3367. /* Capture compare 3 event */
  3368. if ((itflag & (TIM_FLAG_CC3)) == (TIM_FLAG_CC3))
  3369. {
  3370. if ((itsource & (TIM_IT_CC3)) == (TIM_IT_CC3))
  3371. {
  3372. __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_CC3);
  3373. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
  3374. /* Input capture event */
  3375. if ((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00U)
  3376. {
  3377. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  3378. htim->IC_CaptureCallback(htim);
  3379. #else
  3380. HAL_TIM_IC_CaptureCallback(htim);
  3381. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  3382. }
  3383. /* Output compare event */
  3384. else
  3385. {
  3386. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  3387. htim->OC_DelayElapsedCallback(htim);
  3388. htim->PWM_PulseFinishedCallback(htim);
  3389. #else
  3390. HAL_TIM_OC_DelayElapsedCallback(htim);
  3391. HAL_TIM_PWM_PulseFinishedCallback(htim);
  3392. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  3393. }
  3394. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  3395. }
  3396. }
  3397. /* Capture compare 4 event */
  3398. if ((itflag & (TIM_FLAG_CC4)) == (TIM_FLAG_CC4))
  3399. {
  3400. if ((itsource & (TIM_IT_CC4)) == (TIM_IT_CC4))
  3401. {
  3402. __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_CC4);
  3403. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
  3404. /* Input capture event */
  3405. if ((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00U)
  3406. {
  3407. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  3408. htim->IC_CaptureCallback(htim);
  3409. #else
  3410. HAL_TIM_IC_CaptureCallback(htim);
  3411. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  3412. }
  3413. /* Output compare event */
  3414. else
  3415. {
  3416. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  3417. htim->OC_DelayElapsedCallback(htim);
  3418. htim->PWM_PulseFinishedCallback(htim);
  3419. #else
  3420. HAL_TIM_OC_DelayElapsedCallback(htim);
  3421. HAL_TIM_PWM_PulseFinishedCallback(htim);
  3422. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  3423. }
  3424. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  3425. }
  3426. }
  3427. /* TIM Update event */
  3428. if ((itflag & (TIM_FLAG_UPDATE)) == (TIM_FLAG_UPDATE))
  3429. {
  3430. if ((itsource & (TIM_IT_UPDATE)) == (TIM_IT_UPDATE))
  3431. {
  3432. __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_UPDATE);
  3433. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  3434. htim->PeriodElapsedCallback(htim);
  3435. #else
  3436. HAL_TIM_PeriodElapsedCallback(htim);
  3437. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  3438. }
  3439. }
  3440. /* TIM Break input event */
  3441. if ((itflag & (TIM_FLAG_BREAK)) == (TIM_FLAG_BREAK))
  3442. {
  3443. if ((itsource & (TIM_IT_BREAK)) == (TIM_IT_BREAK))
  3444. {
  3445. __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_BREAK);
  3446. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  3447. htim->BreakCallback(htim);
  3448. #else
  3449. HAL_TIMEx_BreakCallback(htim);
  3450. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  3451. }
  3452. }
  3453. #if defined(TIM_BDTR_BK2E)
  3454. /* TIM Break2 input event */
  3455. if ((itflag & (TIM_FLAG_BREAK2)) == (TIM_FLAG_BREAK2))
  3456. {
  3457. if ((itsource & (TIM_IT_BREAK)) == (TIM_IT_BREAK))
  3458. {
  3459. __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_BREAK2);
  3460. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  3461. htim->Break2Callback(htim);
  3462. #else
  3463. HAL_TIMEx_Break2Callback(htim);
  3464. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  3465. }
  3466. }
  3467. #endif /* TIM_BDTR_BK2E */
  3468. /* TIM Trigger detection event */
  3469. if ((itflag & (TIM_FLAG_TRIGGER)) == (TIM_FLAG_TRIGGER))
  3470. {
  3471. if ((itsource & (TIM_IT_TRIGGER)) == (TIM_IT_TRIGGER))
  3472. {
  3473. __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_TRIGGER);
  3474. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  3475. htim->TriggerCallback(htim);
  3476. #else
  3477. HAL_TIM_TriggerCallback(htim);
  3478. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  3479. }
  3480. }
  3481. /* TIM commutation event */
  3482. if ((itflag & (TIM_FLAG_COM)) == (TIM_FLAG_COM))
  3483. {
  3484. if ((itsource & (TIM_IT_COM)) == (TIM_IT_COM))
  3485. {
  3486. __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_COM);
  3487. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  3488. htim->CommutationCallback(htim);
  3489. #else
  3490. HAL_TIMEx_CommutCallback(htim);
  3491. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  3492. }
  3493. }
  3494. }
  3495. /**
  3496. * @}
  3497. */
  3498. /** @defgroup TIM_Exported_Functions_Group8 TIM Peripheral Control functions
  3499. * @brief TIM Peripheral Control functions
  3500. *
  3501. @verbatim
  3502. ==============================================================================
  3503. ##### Peripheral Control functions #####
  3504. ==============================================================================
  3505. [..]
  3506. This section provides functions allowing to:
  3507. (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode.
  3508. (+) Configure External Clock source.
  3509. (+) Configure Complementary channels, break features and dead time.
  3510. (+) Configure Master and the Slave synchronization.
  3511. (+) Configure the DMA Burst Mode.
  3512. @endverbatim
  3513. * @{
  3514. */
  3515. /**
  3516. * @brief Initializes the TIM Output Compare Channels according to the specified
  3517. * parameters in the TIM_OC_InitTypeDef.
  3518. * @param htim TIM Output Compare handle
  3519. * @param sConfig TIM Output Compare configuration structure
  3520. * @param Channel TIM Channels to configure
  3521. * This parameter can be one of the following values:
  3522. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  3523. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  3524. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  3525. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  3526. * @arg TIM_CHANNEL_5: TIM Channel 5 selected (*)
  3527. * @arg TIM_CHANNEL_6: TIM Channel 6 selected (*)
  3528. * (*) Value not defined for all devices
  3529. * @retval HAL status
  3530. */
  3531. HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim,
  3532. const TIM_OC_InitTypeDef *sConfig,
  3533. uint32_t Channel)
  3534. {
  3535. HAL_StatusTypeDef status = HAL_OK;
  3536. /* Check the parameters */
  3537. assert_param(IS_TIM_CHANNELS(Channel));
  3538. assert_param(IS_TIM_OC_MODE(sConfig->OCMode));
  3539. assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
  3540. /* Process Locked */
  3541. __HAL_LOCK(htim);
  3542. switch (Channel)
  3543. {
  3544. case TIM_CHANNEL_1:
  3545. {
  3546. /* Check the parameters */
  3547. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  3548. /* Configure the TIM Channel 1 in Output Compare */
  3549. TIM_OC1_SetConfig(htim->Instance, sConfig);
  3550. break;
  3551. }
  3552. case TIM_CHANNEL_2:
  3553. {
  3554. /* Check the parameters */
  3555. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  3556. /* Configure the TIM Channel 2 in Output Compare */
  3557. TIM_OC2_SetConfig(htim->Instance, sConfig);
  3558. break;
  3559. }
  3560. case TIM_CHANNEL_3:
  3561. {
  3562. /* Check the parameters */
  3563. assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
  3564. /* Configure the TIM Channel 3 in Output Compare */
  3565. TIM_OC3_SetConfig(htim->Instance, sConfig);
  3566. break;
  3567. }
  3568. case TIM_CHANNEL_4:
  3569. {
  3570. /* Check the parameters */
  3571. assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
  3572. /* Configure the TIM Channel 4 in Output Compare */
  3573. TIM_OC4_SetConfig(htim->Instance, sConfig);
  3574. break;
  3575. }
  3576. #if defined(TIM_CCER_CC5E)
  3577. case TIM_CHANNEL_5:
  3578. {
  3579. /* Check the parameters */
  3580. assert_param(IS_TIM_CC5_INSTANCE(htim->Instance));
  3581. /* Configure the TIM Channel 5 in Output Compare */
  3582. TIM_OC5_SetConfig(htim->Instance, sConfig);
  3583. break;
  3584. }
  3585. #endif /* TIM_CCER_CC5E */
  3586. #if defined(TIM_CCER_CC6E)
  3587. case TIM_CHANNEL_6:
  3588. {
  3589. /* Check the parameters */
  3590. assert_param(IS_TIM_CC6_INSTANCE(htim->Instance));
  3591. /* Configure the TIM Channel 6 in Output Compare */
  3592. TIM_OC6_SetConfig(htim->Instance, sConfig);
  3593. break;
  3594. }
  3595. #endif /* TIM_CCER_CC6E */
  3596. default:
  3597. status = HAL_ERROR;
  3598. break;
  3599. }
  3600. __HAL_UNLOCK(htim);
  3601. return status;
  3602. }
  3603. /**
  3604. * @brief Initializes the TIM Input Capture Channels according to the specified
  3605. * parameters in the TIM_IC_InitTypeDef.
  3606. * @param htim TIM IC handle
  3607. * @param sConfig TIM Input Capture configuration structure
  3608. * @param Channel TIM Channel to configure
  3609. * This parameter can be one of the following values:
  3610. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  3611. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  3612. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  3613. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  3614. * @retval HAL status
  3615. */
  3616. HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, const TIM_IC_InitTypeDef *sConfig, uint32_t Channel)
  3617. {
  3618. HAL_StatusTypeDef status = HAL_OK;
  3619. /* Check the parameters */
  3620. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  3621. assert_param(IS_TIM_IC_POLARITY(sConfig->ICPolarity));
  3622. assert_param(IS_TIM_IC_SELECTION(sConfig->ICSelection));
  3623. assert_param(IS_TIM_IC_PRESCALER(sConfig->ICPrescaler));
  3624. assert_param(IS_TIM_IC_FILTER(sConfig->ICFilter));
  3625. /* Process Locked */
  3626. __HAL_LOCK(htim);
  3627. if (Channel == TIM_CHANNEL_1)
  3628. {
  3629. /* TI1 Configuration */
  3630. TIM_TI1_SetConfig(htim->Instance,
  3631. sConfig->ICPolarity,
  3632. sConfig->ICSelection,
  3633. sConfig->ICFilter);
  3634. /* Reset the IC1PSC Bits */
  3635. htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
  3636. /* Set the IC1PSC value */
  3637. htim->Instance->CCMR1 |= sConfig->ICPrescaler;
  3638. }
  3639. else if (Channel == TIM_CHANNEL_2)
  3640. {
  3641. /* TI2 Configuration */
  3642. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  3643. TIM_TI2_SetConfig(htim->Instance,
  3644. sConfig->ICPolarity,
  3645. sConfig->ICSelection,
  3646. sConfig->ICFilter);
  3647. /* Reset the IC2PSC Bits */
  3648. htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
  3649. /* Set the IC2PSC value */
  3650. htim->Instance->CCMR1 |= (sConfig->ICPrescaler << 8U);
  3651. }
  3652. else if (Channel == TIM_CHANNEL_3)
  3653. {
  3654. /* TI3 Configuration */
  3655. assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
  3656. TIM_TI3_SetConfig(htim->Instance,
  3657. sConfig->ICPolarity,
  3658. sConfig->ICSelection,
  3659. sConfig->ICFilter);
  3660. /* Reset the IC3PSC Bits */
  3661. htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC;
  3662. /* Set the IC3PSC value */
  3663. htim->Instance->CCMR2 |= sConfig->ICPrescaler;
  3664. }
  3665. else if (Channel == TIM_CHANNEL_4)
  3666. {
  3667. /* TI4 Configuration */
  3668. assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
  3669. TIM_TI4_SetConfig(htim->Instance,
  3670. sConfig->ICPolarity,
  3671. sConfig->ICSelection,
  3672. sConfig->ICFilter);
  3673. /* Reset the IC4PSC Bits */
  3674. htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC;
  3675. /* Set the IC4PSC value */
  3676. htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8U);
  3677. }
  3678. else
  3679. {
  3680. status = HAL_ERROR;
  3681. }
  3682. __HAL_UNLOCK(htim);
  3683. return status;
  3684. }
  3685. /**
  3686. * @brief Initializes the TIM PWM channels according to the specified
  3687. * parameters in the TIM_OC_InitTypeDef.
  3688. * @param htim TIM PWM handle
  3689. * @param sConfig TIM PWM configuration structure
  3690. * @param Channel TIM Channels to be configured
  3691. * This parameter can be one of the following values:
  3692. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  3693. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  3694. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  3695. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  3696. * @arg TIM_CHANNEL_5: TIM Channel 5 selected (*)
  3697. * @arg TIM_CHANNEL_6: TIM Channel 6 selected (*)
  3698. * (*) Value not defined for all devices
  3699. * @retval HAL status
  3700. */
  3701. HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim,
  3702. const TIM_OC_InitTypeDef *sConfig,
  3703. uint32_t Channel)
  3704. {
  3705. HAL_StatusTypeDef status = HAL_OK;
  3706. /* Check the parameters */
  3707. assert_param(IS_TIM_CHANNELS(Channel));
  3708. assert_param(IS_TIM_PWM_MODE(sConfig->OCMode));
  3709. assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
  3710. assert_param(IS_TIM_FAST_STATE(sConfig->OCFastMode));
  3711. /* Process Locked */
  3712. __HAL_LOCK(htim);
  3713. switch (Channel)
  3714. {
  3715. case TIM_CHANNEL_1:
  3716. {
  3717. /* Check the parameters */
  3718. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  3719. /* Configure the Channel 1 in PWM mode */
  3720. TIM_OC1_SetConfig(htim->Instance, sConfig);
  3721. /* Set the Preload enable bit for channel1 */
  3722. htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE;
  3723. /* Configure the Output Fast mode */
  3724. htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE;
  3725. htim->Instance->CCMR1 |= sConfig->OCFastMode;
  3726. break;
  3727. }
  3728. case TIM_CHANNEL_2:
  3729. {
  3730. /* Check the parameters */
  3731. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  3732. /* Configure the Channel 2 in PWM mode */
  3733. TIM_OC2_SetConfig(htim->Instance, sConfig);
  3734. /* Set the Preload enable bit for channel2 */
  3735. htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE;
  3736. /* Configure the Output Fast mode */
  3737. htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE;
  3738. htim->Instance->CCMR1 |= sConfig->OCFastMode << 8U;
  3739. break;
  3740. }
  3741. case TIM_CHANNEL_3:
  3742. {
  3743. /* Check the parameters */
  3744. assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
  3745. /* Configure the Channel 3 in PWM mode */
  3746. TIM_OC3_SetConfig(htim->Instance, sConfig);
  3747. /* Set the Preload enable bit for channel3 */
  3748. htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE;
  3749. /* Configure the Output Fast mode */
  3750. htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE;
  3751. htim->Instance->CCMR2 |= sConfig->OCFastMode;
  3752. break;
  3753. }
  3754. case TIM_CHANNEL_4:
  3755. {
  3756. /* Check the parameters */
  3757. assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
  3758. /* Configure the Channel 4 in PWM mode */
  3759. TIM_OC4_SetConfig(htim->Instance, sConfig);
  3760. /* Set the Preload enable bit for channel4 */
  3761. htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE;
  3762. /* Configure the Output Fast mode */
  3763. htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE;
  3764. htim->Instance->CCMR2 |= sConfig->OCFastMode << 8U;
  3765. break;
  3766. }
  3767. #if defined(TIM_CCER_CC5E)
  3768. case TIM_CHANNEL_5:
  3769. {
  3770. /* Check the parameters */
  3771. assert_param(IS_TIM_CC5_INSTANCE(htim->Instance));
  3772. /* Configure the Channel 5 in PWM mode */
  3773. TIM_OC5_SetConfig(htim->Instance, sConfig);
  3774. /* Set the Preload enable bit for channel5*/
  3775. htim->Instance->CCMR3 |= TIM_CCMR3_OC5PE;
  3776. /* Configure the Output Fast mode */
  3777. htim->Instance->CCMR3 &= ~TIM_CCMR3_OC5FE;
  3778. htim->Instance->CCMR3 |= sConfig->OCFastMode;
  3779. break;
  3780. }
  3781. #endif /* TIM_CCER_CC5E */
  3782. #if defined(TIM_CCER_CC6E)
  3783. case TIM_CHANNEL_6:
  3784. {
  3785. /* Check the parameters */
  3786. assert_param(IS_TIM_CC6_INSTANCE(htim->Instance));
  3787. /* Configure the Channel 6 in PWM mode */
  3788. TIM_OC6_SetConfig(htim->Instance, sConfig);
  3789. /* Set the Preload enable bit for channel6 */
  3790. htim->Instance->CCMR3 |= TIM_CCMR3_OC6PE;
  3791. /* Configure the Output Fast mode */
  3792. htim->Instance->CCMR3 &= ~TIM_CCMR3_OC6FE;
  3793. htim->Instance->CCMR3 |= sConfig->OCFastMode << 8U;
  3794. break;
  3795. }
  3796. #endif /* TIM_CCER_CC6E */
  3797. default:
  3798. status = HAL_ERROR;
  3799. break;
  3800. }
  3801. __HAL_UNLOCK(htim);
  3802. return status;
  3803. }
  3804. /**
  3805. * @brief Initializes the TIM One Pulse Channels according to the specified
  3806. * parameters in the TIM_OnePulse_InitTypeDef.
  3807. * @param htim TIM One Pulse handle
  3808. * @param sConfig TIM One Pulse configuration structure
  3809. * @param OutputChannel TIM output channel to configure
  3810. * This parameter can be one of the following values:
  3811. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  3812. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  3813. * @param InputChannel TIM input Channel to configure
  3814. * This parameter can be one of the following values:
  3815. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  3816. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  3817. * @note To output a waveform with a minimum delay user can enable the fast
  3818. * mode by calling the @ref __HAL_TIM_ENABLE_OCxFAST macro. Then CCx
  3819. * output is forced in response to the edge detection on TIx input,
  3820. * without taking in account the comparison.
  3821. * @retval HAL status
  3822. */
  3823. HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef *sConfig,
  3824. uint32_t OutputChannel, uint32_t InputChannel)
  3825. {
  3826. HAL_StatusTypeDef status = HAL_OK;
  3827. TIM_OC_InitTypeDef temp1;
  3828. /* Check the parameters */
  3829. assert_param(IS_TIM_OPM_CHANNELS(OutputChannel));
  3830. assert_param(IS_TIM_OPM_CHANNELS(InputChannel));
  3831. if (OutputChannel != InputChannel)
  3832. {
  3833. /* Process Locked */
  3834. __HAL_LOCK(htim);
  3835. htim->State = HAL_TIM_STATE_BUSY;
  3836. /* Extract the Output compare configuration from sConfig structure */
  3837. temp1.OCMode = sConfig->OCMode;
  3838. temp1.Pulse = sConfig->Pulse;
  3839. temp1.OCPolarity = sConfig->OCPolarity;
  3840. temp1.OCNPolarity = sConfig->OCNPolarity;
  3841. temp1.OCIdleState = sConfig->OCIdleState;
  3842. temp1.OCNIdleState = sConfig->OCNIdleState;
  3843. switch (OutputChannel)
  3844. {
  3845. case TIM_CHANNEL_1:
  3846. {
  3847. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  3848. TIM_OC1_SetConfig(htim->Instance, &temp1);
  3849. break;
  3850. }
  3851. case TIM_CHANNEL_2:
  3852. {
  3853. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  3854. TIM_OC2_SetConfig(htim->Instance, &temp1);
  3855. break;
  3856. }
  3857. default:
  3858. status = HAL_ERROR;
  3859. break;
  3860. }
  3861. if (status == HAL_OK)
  3862. {
  3863. switch (InputChannel)
  3864. {
  3865. case TIM_CHANNEL_1:
  3866. {
  3867. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  3868. TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity,
  3869. sConfig->ICSelection, sConfig->ICFilter);
  3870. /* Reset the IC1PSC Bits */
  3871. htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
  3872. /* Select the Trigger source */
  3873. htim->Instance->SMCR &= ~TIM_SMCR_TS;
  3874. htim->Instance->SMCR |= TIM_TS_TI1FP1;
  3875. /* Select the Slave Mode */
  3876. htim->Instance->SMCR &= ~TIM_SMCR_SMS;
  3877. htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
  3878. break;
  3879. }
  3880. case TIM_CHANNEL_2:
  3881. {
  3882. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  3883. TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity,
  3884. sConfig->ICSelection, sConfig->ICFilter);
  3885. /* Reset the IC2PSC Bits */
  3886. htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
  3887. /* Select the Trigger source */
  3888. htim->Instance->SMCR &= ~TIM_SMCR_TS;
  3889. htim->Instance->SMCR |= TIM_TS_TI2FP2;
  3890. /* Select the Slave Mode */
  3891. htim->Instance->SMCR &= ~TIM_SMCR_SMS;
  3892. htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
  3893. break;
  3894. }
  3895. default:
  3896. status = HAL_ERROR;
  3897. break;
  3898. }
  3899. }
  3900. htim->State = HAL_TIM_STATE_READY;
  3901. __HAL_UNLOCK(htim);
  3902. return status;
  3903. }
  3904. else
  3905. {
  3906. return HAL_ERROR;
  3907. }
  3908. }
  3909. /**
  3910. * @brief Configure the DMA Burst to transfer Data from the memory to the TIM peripheral
  3911. * @param htim TIM handle
  3912. * @param BurstBaseAddress TIM Base address from where the DMA will start the Data write
  3913. * This parameter can be one of the following values:
  3914. * @arg TIM_DMABASE_CR1
  3915. * @arg TIM_DMABASE_CR2
  3916. * @arg TIM_DMABASE_SMCR
  3917. * @arg TIM_DMABASE_DIER
  3918. * @arg TIM_DMABASE_SR
  3919. * @arg TIM_DMABASE_EGR
  3920. * @arg TIM_DMABASE_CCMR1
  3921. * @arg TIM_DMABASE_CCMR2
  3922. * @arg TIM_DMABASE_CCER
  3923. * @arg TIM_DMABASE_CNT
  3924. * @arg TIM_DMABASE_PSC
  3925. * @arg TIM_DMABASE_ARR
  3926. * @arg TIM_DMABASE_RCR
  3927. * @arg TIM_DMABASE_CCR1
  3928. * @arg TIM_DMABASE_CCR2
  3929. * @arg TIM_DMABASE_CCR3
  3930. * @arg TIM_DMABASE_CCR4
  3931. * @arg TIM_DMABASE_BDTR
  3932. * @arg TIM_DMABASE_OR
  3933. * @arg TIM_DMABASE_CCMR3 (*)
  3934. * @arg TIM_DMABASE_CCR5 (*)
  3935. * @arg TIM_DMABASE_CCR6 (*)
  3936. * (*) value not defined in all devices
  3937. * @param BurstRequestSrc TIM DMA Request sources
  3938. * This parameter can be one of the following values:
  3939. * @arg TIM_DMA_UPDATE: TIM update Interrupt source
  3940. * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
  3941. * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
  3942. * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
  3943. * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
  3944. * @arg TIM_DMA_COM: TIM Commutation DMA source
  3945. * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
  3946. * @param BurstBuffer The Buffer address.
  3947. * @param BurstLength DMA Burst length. This parameter can be one value
  3948. * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
  3949. * @note This function should be used only when BurstLength is equal to DMA data transfer length.
  3950. * @retval HAL status
  3951. */
  3952. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
  3953. uint32_t BurstRequestSrc, const uint32_t *BurstBuffer,
  3954. uint32_t BurstLength)
  3955. {
  3956. HAL_StatusTypeDef status;
  3957. status = HAL_TIM_DMABurst_MultiWriteStart(htim, BurstBaseAddress, BurstRequestSrc, BurstBuffer, BurstLength,
  3958. ((BurstLength) >> 8U) + 1U);
  3959. return status;
  3960. }
  3961. /**
  3962. * @brief Configure the DMA Burst to transfer multiple Data from the memory to the TIM peripheral
  3963. * @param htim TIM handle
  3964. * @param BurstBaseAddress TIM Base address from where the DMA will start the Data write
  3965. * This parameter can be one of the following values:
  3966. * @arg TIM_DMABASE_CR1
  3967. * @arg TIM_DMABASE_CR2
  3968. * @arg TIM_DMABASE_SMCR
  3969. * @arg TIM_DMABASE_DIER
  3970. * @arg TIM_DMABASE_SR
  3971. * @arg TIM_DMABASE_EGR
  3972. * @arg TIM_DMABASE_CCMR1
  3973. * @arg TIM_DMABASE_CCMR2
  3974. * @arg TIM_DMABASE_CCER
  3975. * @arg TIM_DMABASE_CNT
  3976. * @arg TIM_DMABASE_PSC
  3977. * @arg TIM_DMABASE_ARR
  3978. * @arg TIM_DMABASE_RCR
  3979. * @arg TIM_DMABASE_CCR1
  3980. * @arg TIM_DMABASE_CCR2
  3981. * @arg TIM_DMABASE_CCR3
  3982. * @arg TIM_DMABASE_CCR4
  3983. * @arg TIM_DMABASE_BDTR
  3984. * @arg TIM_DMABASE_OR
  3985. * @arg TIM_DMABASE_CCMR3 (*)
  3986. * @arg TIM_DMABASE_CCR5 (*)
  3987. * @arg TIM_DMABASE_CCR6 (*)
  3988. * (*) value not defined in all devices
  3989. * @param BurstRequestSrc TIM DMA Request sources
  3990. * This parameter can be one of the following values:
  3991. * @arg TIM_DMA_UPDATE: TIM update Interrupt source
  3992. * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
  3993. * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
  3994. * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
  3995. * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
  3996. * @arg TIM_DMA_COM: TIM Commutation DMA source
  3997. * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
  3998. * @param BurstBuffer The Buffer address.
  3999. * @param BurstLength DMA Burst length. This parameter can be one value
  4000. * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
  4001. * @param DataLength Data length. This parameter can be one value
  4002. * between 1 and 0xFFFF.
  4003. * @retval HAL status
  4004. */
  4005. HAL_StatusTypeDef HAL_TIM_DMABurst_MultiWriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
  4006. uint32_t BurstRequestSrc, const uint32_t *BurstBuffer,
  4007. uint32_t BurstLength, uint32_t DataLength)
  4008. {
  4009. HAL_StatusTypeDef status = HAL_OK;
  4010. /* Check the parameters */
  4011. assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
  4012. assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
  4013. assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
  4014. assert_param(IS_TIM_DMA_LENGTH(BurstLength));
  4015. assert_param(IS_TIM_DMA_DATA_LENGTH(DataLength));
  4016. if (htim->DMABurstState == HAL_DMA_BURST_STATE_BUSY)
  4017. {
  4018. return HAL_BUSY;
  4019. }
  4020. else if (htim->DMABurstState == HAL_DMA_BURST_STATE_READY)
  4021. {
  4022. if ((BurstBuffer == NULL) && (BurstLength > 0U))
  4023. {
  4024. return HAL_ERROR;
  4025. }
  4026. else
  4027. {
  4028. htim->DMABurstState = HAL_DMA_BURST_STATE_BUSY;
  4029. }
  4030. }
  4031. else
  4032. {
  4033. /* nothing to do */
  4034. }
  4035. switch (BurstRequestSrc)
  4036. {
  4037. case TIM_DMA_UPDATE:
  4038. {
  4039. /* Set the DMA Period elapsed callbacks */
  4040. htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
  4041. htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
  4042. /* Set the DMA error callback */
  4043. htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
  4044. /* Enable the DMA channel */
  4045. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer,
  4046. (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
  4047. {
  4048. /* Return error status */
  4049. return HAL_ERROR;
  4050. }
  4051. break;
  4052. }
  4053. case TIM_DMA_CC1:
  4054. {
  4055. /* Set the DMA compare callbacks */
  4056. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
  4057. htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
  4058. /* Set the DMA error callback */
  4059. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
  4060. /* Enable the DMA channel */
  4061. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer,
  4062. (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
  4063. {
  4064. /* Return error status */
  4065. return HAL_ERROR;
  4066. }
  4067. break;
  4068. }
  4069. case TIM_DMA_CC2:
  4070. {
  4071. /* Set the DMA compare callbacks */
  4072. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
  4073. htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
  4074. /* Set the DMA error callback */
  4075. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
  4076. /* Enable the DMA channel */
  4077. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer,
  4078. (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
  4079. {
  4080. /* Return error status */
  4081. return HAL_ERROR;
  4082. }
  4083. break;
  4084. }
  4085. case TIM_DMA_CC3:
  4086. {
  4087. /* Set the DMA compare callbacks */
  4088. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
  4089. htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
  4090. /* Set the DMA error callback */
  4091. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
  4092. /* Enable the DMA channel */
  4093. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer,
  4094. (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
  4095. {
  4096. /* Return error status */
  4097. return HAL_ERROR;
  4098. }
  4099. break;
  4100. }
  4101. case TIM_DMA_CC4:
  4102. {
  4103. /* Set the DMA compare callbacks */
  4104. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
  4105. htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
  4106. /* Set the DMA error callback */
  4107. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
  4108. /* Enable the DMA channel */
  4109. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer,
  4110. (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
  4111. {
  4112. /* Return error status */
  4113. return HAL_ERROR;
  4114. }
  4115. break;
  4116. }
  4117. case TIM_DMA_COM:
  4118. {
  4119. /* Set the DMA commutation callbacks */
  4120. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
  4121. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback = TIMEx_DMACommutationHalfCplt;
  4122. /* Set the DMA error callback */
  4123. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ;
  4124. /* Enable the DMA channel */
  4125. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)BurstBuffer,
  4126. (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
  4127. {
  4128. /* Return error status */
  4129. return HAL_ERROR;
  4130. }
  4131. break;
  4132. }
  4133. case TIM_DMA_TRIGGER:
  4134. {
  4135. /* Set the DMA trigger callbacks */
  4136. htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
  4137. htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt;
  4138. /* Set the DMA error callback */
  4139. htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ;
  4140. /* Enable the DMA channel */
  4141. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer,
  4142. (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
  4143. {
  4144. /* Return error status */
  4145. return HAL_ERROR;
  4146. }
  4147. break;
  4148. }
  4149. default:
  4150. status = HAL_ERROR;
  4151. break;
  4152. }
  4153. if (status == HAL_OK)
  4154. {
  4155. /* Configure the DMA Burst Mode */
  4156. htim->Instance->DCR = (BurstBaseAddress | BurstLength);
  4157. /* Enable the TIM DMA Request */
  4158. __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
  4159. }
  4160. /* Return function status */
  4161. return status;
  4162. }
  4163. /**
  4164. * @brief Stops the TIM DMA Burst mode
  4165. * @param htim TIM handle
  4166. * @param BurstRequestSrc TIM DMA Request sources to disable
  4167. * @retval HAL status
  4168. */
  4169. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
  4170. {
  4171. HAL_StatusTypeDef status = HAL_OK;
  4172. /* Check the parameters */
  4173. assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
  4174. /* Abort the DMA transfer (at least disable the DMA channel) */
  4175. switch (BurstRequestSrc)
  4176. {
  4177. case TIM_DMA_UPDATE:
  4178. {
  4179. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]);
  4180. break;
  4181. }
  4182. case TIM_DMA_CC1:
  4183. {
  4184. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
  4185. break;
  4186. }
  4187. case TIM_DMA_CC2:
  4188. {
  4189. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
  4190. break;
  4191. }
  4192. case TIM_DMA_CC3:
  4193. {
  4194. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
  4195. break;
  4196. }
  4197. case TIM_DMA_CC4:
  4198. {
  4199. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
  4200. break;
  4201. }
  4202. case TIM_DMA_COM:
  4203. {
  4204. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_COMMUTATION]);
  4205. break;
  4206. }
  4207. case TIM_DMA_TRIGGER:
  4208. {
  4209. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_TRIGGER]);
  4210. break;
  4211. }
  4212. default:
  4213. status = HAL_ERROR;
  4214. break;
  4215. }
  4216. if (status == HAL_OK)
  4217. {
  4218. /* Disable the TIM Update DMA request */
  4219. __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
  4220. /* Change the DMA burst operation state */
  4221. htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
  4222. }
  4223. /* Return function status */
  4224. return status;
  4225. }
  4226. /**
  4227. * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory
  4228. * @param htim TIM handle
  4229. * @param BurstBaseAddress TIM Base address from where the DMA will start the Data read
  4230. * This parameter can be one of the following values:
  4231. * @arg TIM_DMABASE_CR1
  4232. * @arg TIM_DMABASE_CR2
  4233. * @arg TIM_DMABASE_SMCR
  4234. * @arg TIM_DMABASE_DIER
  4235. * @arg TIM_DMABASE_SR
  4236. * @arg TIM_DMABASE_EGR
  4237. * @arg TIM_DMABASE_CCMR1
  4238. * @arg TIM_DMABASE_CCMR2
  4239. * @arg TIM_DMABASE_CCER
  4240. * @arg TIM_DMABASE_CNT
  4241. * @arg TIM_DMABASE_PSC
  4242. * @arg TIM_DMABASE_ARR
  4243. * @arg TIM_DMABASE_RCR
  4244. * @arg TIM_DMABASE_CCR1
  4245. * @arg TIM_DMABASE_CCR2
  4246. * @arg TIM_DMABASE_CCR3
  4247. * @arg TIM_DMABASE_CCR4
  4248. * @arg TIM_DMABASE_BDTR
  4249. * @arg TIM_DMABASE_OR
  4250. * @arg TIM_DMABASE_CCMR3 (*)
  4251. * @arg TIM_DMABASE_CCR5 (*)
  4252. * @arg TIM_DMABASE_CCR6 (*)
  4253. * (*) value not defined in all devices
  4254. * @param BurstRequestSrc TIM DMA Request sources
  4255. * This parameter can be one of the following values:
  4256. * @arg TIM_DMA_UPDATE: TIM update Interrupt source
  4257. * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
  4258. * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
  4259. * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
  4260. * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
  4261. * @arg TIM_DMA_COM: TIM Commutation DMA source
  4262. * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
  4263. * @param BurstBuffer The Buffer address.
  4264. * @param BurstLength DMA Burst length. This parameter can be one value
  4265. * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
  4266. * @note This function should be used only when BurstLength is equal to DMA data transfer length.
  4267. * @retval HAL status
  4268. */
  4269. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
  4270. uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength)
  4271. {
  4272. HAL_StatusTypeDef status;
  4273. status = HAL_TIM_DMABurst_MultiReadStart(htim, BurstBaseAddress, BurstRequestSrc, BurstBuffer, BurstLength,
  4274. ((BurstLength) >> 8U) + 1U);
  4275. return status;
  4276. }
  4277. /**
  4278. * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory
  4279. * @param htim TIM handle
  4280. * @param BurstBaseAddress TIM Base address from where the DMA will start the Data read
  4281. * This parameter can be one of the following values:
  4282. * @arg TIM_DMABASE_CR1
  4283. * @arg TIM_DMABASE_CR2
  4284. * @arg TIM_DMABASE_SMCR
  4285. * @arg TIM_DMABASE_DIER
  4286. * @arg TIM_DMABASE_SR
  4287. * @arg TIM_DMABASE_EGR
  4288. * @arg TIM_DMABASE_CCMR1
  4289. * @arg TIM_DMABASE_CCMR2
  4290. * @arg TIM_DMABASE_CCER
  4291. * @arg TIM_DMABASE_CNT
  4292. * @arg TIM_DMABASE_PSC
  4293. * @arg TIM_DMABASE_ARR
  4294. * @arg TIM_DMABASE_RCR
  4295. * @arg TIM_DMABASE_CCR1
  4296. * @arg TIM_DMABASE_CCR2
  4297. * @arg TIM_DMABASE_CCR3
  4298. * @arg TIM_DMABASE_CCR4
  4299. * @arg TIM_DMABASE_BDTR
  4300. * @arg TIM_DMABASE_OR
  4301. * @arg TIM_DMABASE_CCMR3 (*)
  4302. * @arg TIM_DMABASE_CCR5 (*)
  4303. * @arg TIM_DMABASE_CCR6 (*)
  4304. * (*) value not defined in all devices
  4305. * @param BurstRequestSrc TIM DMA Request sources
  4306. * This parameter can be one of the following values:
  4307. * @arg TIM_DMA_UPDATE: TIM update Interrupt source
  4308. * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
  4309. * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
  4310. * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
  4311. * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
  4312. * @arg TIM_DMA_COM: TIM Commutation DMA source
  4313. * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
  4314. * @param BurstBuffer The Buffer address.
  4315. * @param BurstLength DMA Burst length. This parameter can be one value
  4316. * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
  4317. * @param DataLength Data length. This parameter can be one value
  4318. * between 1 and 0xFFFF.
  4319. * @retval HAL status
  4320. */
  4321. HAL_StatusTypeDef HAL_TIM_DMABurst_MultiReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
  4322. uint32_t BurstRequestSrc, uint32_t *BurstBuffer,
  4323. uint32_t BurstLength, uint32_t DataLength)
  4324. {
  4325. HAL_StatusTypeDef status = HAL_OK;
  4326. /* Check the parameters */
  4327. assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
  4328. assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
  4329. assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
  4330. assert_param(IS_TIM_DMA_LENGTH(BurstLength));
  4331. assert_param(IS_TIM_DMA_DATA_LENGTH(DataLength));
  4332. if (htim->DMABurstState == HAL_DMA_BURST_STATE_BUSY)
  4333. {
  4334. return HAL_BUSY;
  4335. }
  4336. else if (htim->DMABurstState == HAL_DMA_BURST_STATE_READY)
  4337. {
  4338. if ((BurstBuffer == NULL) && (BurstLength > 0U))
  4339. {
  4340. return HAL_ERROR;
  4341. }
  4342. else
  4343. {
  4344. htim->DMABurstState = HAL_DMA_BURST_STATE_BUSY;
  4345. }
  4346. }
  4347. else
  4348. {
  4349. /* nothing to do */
  4350. }
  4351. switch (BurstRequestSrc)
  4352. {
  4353. case TIM_DMA_UPDATE:
  4354. {
  4355. /* Set the DMA Period elapsed callbacks */
  4356. htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
  4357. htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
  4358. /* Set the DMA error callback */
  4359. htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
  4360. /* Enable the DMA channel */
  4361. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
  4362. DataLength) != HAL_OK)
  4363. {
  4364. /* Return error status */
  4365. return HAL_ERROR;
  4366. }
  4367. break;
  4368. }
  4369. case TIM_DMA_CC1:
  4370. {
  4371. /* Set the DMA capture callbacks */
  4372. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
  4373. htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
  4374. /* Set the DMA error callback */
  4375. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
  4376. /* Enable the DMA channel */
  4377. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
  4378. DataLength) != HAL_OK)
  4379. {
  4380. /* Return error status */
  4381. return HAL_ERROR;
  4382. }
  4383. break;
  4384. }
  4385. case TIM_DMA_CC2:
  4386. {
  4387. /* Set the DMA capture callbacks */
  4388. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
  4389. htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
  4390. /* Set the DMA error callback */
  4391. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
  4392. /* Enable the DMA channel */
  4393. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
  4394. DataLength) != HAL_OK)
  4395. {
  4396. /* Return error status */
  4397. return HAL_ERROR;
  4398. }
  4399. break;
  4400. }
  4401. case TIM_DMA_CC3:
  4402. {
  4403. /* Set the DMA capture callbacks */
  4404. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt;
  4405. htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
  4406. /* Set the DMA error callback */
  4407. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
  4408. /* Enable the DMA channel */
  4409. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
  4410. DataLength) != HAL_OK)
  4411. {
  4412. /* Return error status */
  4413. return HAL_ERROR;
  4414. }
  4415. break;
  4416. }
  4417. case TIM_DMA_CC4:
  4418. {
  4419. /* Set the DMA capture callbacks */
  4420. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt;
  4421. htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
  4422. /* Set the DMA error callback */
  4423. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
  4424. /* Enable the DMA channel */
  4425. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
  4426. DataLength) != HAL_OK)
  4427. {
  4428. /* Return error status */
  4429. return HAL_ERROR;
  4430. }
  4431. break;
  4432. }
  4433. case TIM_DMA_COM:
  4434. {
  4435. /* Set the DMA commutation callbacks */
  4436. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
  4437. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback = TIMEx_DMACommutationHalfCplt;
  4438. /* Set the DMA error callback */
  4439. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ;
  4440. /* Enable the DMA channel */
  4441. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
  4442. DataLength) != HAL_OK)
  4443. {
  4444. /* Return error status */
  4445. return HAL_ERROR;
  4446. }
  4447. break;
  4448. }
  4449. case TIM_DMA_TRIGGER:
  4450. {
  4451. /* Set the DMA trigger callbacks */
  4452. htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
  4453. htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt;
  4454. /* Set the DMA error callback */
  4455. htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ;
  4456. /* Enable the DMA channel */
  4457. if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
  4458. DataLength) != HAL_OK)
  4459. {
  4460. /* Return error status */
  4461. return HAL_ERROR;
  4462. }
  4463. break;
  4464. }
  4465. default:
  4466. status = HAL_ERROR;
  4467. break;
  4468. }
  4469. if (status == HAL_OK)
  4470. {
  4471. /* Configure the DMA Burst Mode */
  4472. htim->Instance->DCR = (BurstBaseAddress | BurstLength);
  4473. /* Enable the TIM DMA Request */
  4474. __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
  4475. }
  4476. /* Return function status */
  4477. return status;
  4478. }
  4479. /**
  4480. * @brief Stop the DMA burst reading
  4481. * @param htim TIM handle
  4482. * @param BurstRequestSrc TIM DMA Request sources to disable.
  4483. * @retval HAL status
  4484. */
  4485. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
  4486. {
  4487. HAL_StatusTypeDef status = HAL_OK;
  4488. /* Check the parameters */
  4489. assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
  4490. /* Abort the DMA transfer (at least disable the DMA channel) */
  4491. switch (BurstRequestSrc)
  4492. {
  4493. case TIM_DMA_UPDATE:
  4494. {
  4495. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]);
  4496. break;
  4497. }
  4498. case TIM_DMA_CC1:
  4499. {
  4500. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
  4501. break;
  4502. }
  4503. case TIM_DMA_CC2:
  4504. {
  4505. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
  4506. break;
  4507. }
  4508. case TIM_DMA_CC3:
  4509. {
  4510. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
  4511. break;
  4512. }
  4513. case TIM_DMA_CC4:
  4514. {
  4515. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
  4516. break;
  4517. }
  4518. case TIM_DMA_COM:
  4519. {
  4520. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_COMMUTATION]);
  4521. break;
  4522. }
  4523. case TIM_DMA_TRIGGER:
  4524. {
  4525. (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_TRIGGER]);
  4526. break;
  4527. }
  4528. default:
  4529. status = HAL_ERROR;
  4530. break;
  4531. }
  4532. if (status == HAL_OK)
  4533. {
  4534. /* Disable the TIM Update DMA request */
  4535. __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
  4536. /* Change the DMA burst operation state */
  4537. htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
  4538. }
  4539. /* Return function status */
  4540. return status;
  4541. }
  4542. /**
  4543. * @brief Generate a software event
  4544. * @param htim TIM handle
  4545. * @param EventSource specifies the event source.
  4546. * This parameter can be one of the following values:
  4547. * @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source
  4548. * @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source
  4549. * @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source
  4550. * @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source
  4551. * @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source
  4552. * @arg TIM_EVENTSOURCE_COM: Timer COM event source
  4553. * @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source
  4554. * @arg TIM_EVENTSOURCE_BREAK: Timer Break event source
  4555. * @arg TIM_EVENTSOURCE_BREAK2: Timer Break2 event source
  4556. * @note Basic timers can only generate an update event.
  4557. * @note TIM_EVENTSOURCE_COM is relevant only with advanced timer instances.
  4558. * @note TIM_EVENTSOURCE_BREAK are relevant only for timer instances
  4559. * supporting a break input.
  4560. * @retval HAL status
  4561. */
  4562. HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource)
  4563. {
  4564. /* Check the parameters */
  4565. assert_param(IS_TIM_INSTANCE(htim->Instance));
  4566. assert_param(IS_TIM_EVENT_SOURCE(EventSource));
  4567. /* Process Locked */
  4568. __HAL_LOCK(htim);
  4569. /* Change the TIM state */
  4570. htim->State = HAL_TIM_STATE_BUSY;
  4571. /* Set the event sources */
  4572. htim->Instance->EGR = EventSource;
  4573. /* Change the TIM state */
  4574. htim->State = HAL_TIM_STATE_READY;
  4575. __HAL_UNLOCK(htim);
  4576. /* Return function status */
  4577. return HAL_OK;
  4578. }
  4579. /**
  4580. * @brief Configures the OCRef clear feature
  4581. * @param htim TIM handle
  4582. * @param sClearInputConfig pointer to a TIM_ClearInputConfigTypeDef structure that
  4583. * contains the OCREF clear feature and parameters for the TIM peripheral.
  4584. * @param Channel specifies the TIM Channel
  4585. * This parameter can be one of the following values:
  4586. * @arg TIM_CHANNEL_1: TIM Channel 1
  4587. * @arg TIM_CHANNEL_2: TIM Channel 2
  4588. * @arg TIM_CHANNEL_3: TIM Channel 3
  4589. * @arg TIM_CHANNEL_4: TIM Channel 4
  4590. * @arg TIM_CHANNEL_5: TIM Channel 5 (*)
  4591. * @arg TIM_CHANNEL_6: TIM Channel 6 (*)
  4592. * (*) Value not defined for all devices
  4593. * @retval HAL status
  4594. */
  4595. HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim,
  4596. const TIM_ClearInputConfigTypeDef *sClearInputConfig,
  4597. uint32_t Channel)
  4598. {
  4599. HAL_StatusTypeDef status = HAL_OK;
  4600. /* Check the parameters */
  4601. assert_param(IS_TIM_OCXREF_CLEAR_INSTANCE(htim->Instance));
  4602. assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource));
  4603. /* Process Locked */
  4604. __HAL_LOCK(htim);
  4605. htim->State = HAL_TIM_STATE_BUSY;
  4606. switch (sClearInputConfig->ClearInputSource)
  4607. {
  4608. case TIM_CLEARINPUTSOURCE_NONE:
  4609. {
  4610. /* Clear the OCREF clear selection bit and the the ETR Bits */
  4611. #if defined(TIM_SMCR_OCCS)
  4612. CLEAR_BIT(htim->Instance->SMCR, (TIM_SMCR_OCCS | TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP));
  4613. #else
  4614. CLEAR_BIT(htim->Instance->SMCR, (TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP));
  4615. #endif /* TIM_SMCR_OCCS */
  4616. break;
  4617. }
  4618. #if defined(TIM_SMCR_OCCS)
  4619. case TIM_CLEARINPUTSOURCE_OCREFCLR:
  4620. {
  4621. /* Clear the OCREF clear selection bit */
  4622. CLEAR_BIT(htim->Instance->SMCR, TIM_SMCR_OCCS);
  4623. break;
  4624. }
  4625. #endif /* TIM_SMCR_OCCS */
  4626. case TIM_CLEARINPUTSOURCE_ETR:
  4627. {
  4628. /* Check the parameters */
  4629. assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity));
  4630. assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler));
  4631. assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter));
  4632. /* When OCRef clear feature is used with ETR source, ETR prescaler must be off */
  4633. if (sClearInputConfig->ClearInputPrescaler != TIM_CLEARINPUTPRESCALER_DIV1)
  4634. {
  4635. htim->State = HAL_TIM_STATE_READY;
  4636. __HAL_UNLOCK(htim);
  4637. return HAL_ERROR;
  4638. }
  4639. TIM_ETR_SetConfig(htim->Instance,
  4640. sClearInputConfig->ClearInputPrescaler,
  4641. sClearInputConfig->ClearInputPolarity,
  4642. sClearInputConfig->ClearInputFilter);
  4643. #if defined(TIM_SMCR_OCCS)
  4644. /* Set the OCREF clear selection bit */
  4645. SET_BIT(htim->Instance->SMCR, TIM_SMCR_OCCS);
  4646. #endif /* TIM_SMCR_OCCS */
  4647. break;
  4648. }
  4649. default:
  4650. status = HAL_ERROR;
  4651. break;
  4652. }
  4653. if (status == HAL_OK)
  4654. {
  4655. switch (Channel)
  4656. {
  4657. case TIM_CHANNEL_1:
  4658. {
  4659. if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
  4660. {
  4661. /* Enable the OCREF clear feature for Channel 1 */
  4662. SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE);
  4663. }
  4664. else
  4665. {
  4666. /* Disable the OCREF clear feature for Channel 1 */
  4667. CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE);
  4668. }
  4669. break;
  4670. }
  4671. case TIM_CHANNEL_2:
  4672. {
  4673. if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
  4674. {
  4675. /* Enable the OCREF clear feature for Channel 2 */
  4676. SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE);
  4677. }
  4678. else
  4679. {
  4680. /* Disable the OCREF clear feature for Channel 2 */
  4681. CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE);
  4682. }
  4683. break;
  4684. }
  4685. case TIM_CHANNEL_3:
  4686. {
  4687. if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
  4688. {
  4689. /* Enable the OCREF clear feature for Channel 3 */
  4690. SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE);
  4691. }
  4692. else
  4693. {
  4694. /* Disable the OCREF clear feature for Channel 3 */
  4695. CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE);
  4696. }
  4697. break;
  4698. }
  4699. case TIM_CHANNEL_4:
  4700. {
  4701. if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
  4702. {
  4703. /* Enable the OCREF clear feature for Channel 4 */
  4704. SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE);
  4705. }
  4706. else
  4707. {
  4708. /* Disable the OCREF clear feature for Channel 4 */
  4709. CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE);
  4710. }
  4711. break;
  4712. }
  4713. #if defined(TIM_CCER_CC5E)
  4714. case TIM_CHANNEL_5:
  4715. {
  4716. if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
  4717. {
  4718. /* Enable the OCREF clear feature for Channel 5 */
  4719. SET_BIT(htim->Instance->CCMR3, TIM_CCMR3_OC5CE);
  4720. }
  4721. else
  4722. {
  4723. /* Disable the OCREF clear feature for Channel 5 */
  4724. CLEAR_BIT(htim->Instance->CCMR3, TIM_CCMR3_OC5CE);
  4725. }
  4726. break;
  4727. }
  4728. #endif /* TIM_CCER_CC5E */
  4729. #if defined(TIM_CCER_CC6E)
  4730. case TIM_CHANNEL_6:
  4731. {
  4732. if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
  4733. {
  4734. /* Enable the OCREF clear feature for Channel 6 */
  4735. SET_BIT(htim->Instance->CCMR3, TIM_CCMR3_OC6CE);
  4736. }
  4737. else
  4738. {
  4739. /* Disable the OCREF clear feature for Channel 6 */
  4740. CLEAR_BIT(htim->Instance->CCMR3, TIM_CCMR3_OC6CE);
  4741. }
  4742. break;
  4743. }
  4744. #endif /* TIM_CCER_CC6E */
  4745. default:
  4746. break;
  4747. }
  4748. }
  4749. htim->State = HAL_TIM_STATE_READY;
  4750. __HAL_UNLOCK(htim);
  4751. return status;
  4752. }
  4753. /**
  4754. * @brief Configures the clock source to be used
  4755. * @param htim TIM handle
  4756. * @param sClockSourceConfig pointer to a TIM_ClockConfigTypeDef structure that
  4757. * contains the clock source information for the TIM peripheral.
  4758. * @retval HAL status
  4759. */
  4760. HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, const TIM_ClockConfigTypeDef *sClockSourceConfig)
  4761. {
  4762. HAL_StatusTypeDef status = HAL_OK;
  4763. uint32_t tmpsmcr;
  4764. /* Process Locked */
  4765. __HAL_LOCK(htim);
  4766. htim->State = HAL_TIM_STATE_BUSY;
  4767. /* Check the parameters */
  4768. assert_param(IS_TIM_CLOCKSOURCE(sClockSourceConfig->ClockSource));
  4769. /* Reset the SMS, TS, ECE, ETPS and ETRF bits */
  4770. tmpsmcr = htim->Instance->SMCR;
  4771. tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
  4772. tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
  4773. htim->Instance->SMCR = tmpsmcr;
  4774. switch (sClockSourceConfig->ClockSource)
  4775. {
  4776. case TIM_CLOCKSOURCE_INTERNAL:
  4777. {
  4778. assert_param(IS_TIM_INSTANCE(htim->Instance));
  4779. break;
  4780. }
  4781. case TIM_CLOCKSOURCE_ETRMODE1:
  4782. {
  4783. /* Check whether or not the timer instance supports external trigger input mode 1 (ETRF)*/
  4784. assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance));
  4785. /* Check ETR input conditioning related parameters */
  4786. assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
  4787. assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
  4788. assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
  4789. /* Configure the ETR Clock source */
  4790. TIM_ETR_SetConfig(htim->Instance,
  4791. sClockSourceConfig->ClockPrescaler,
  4792. sClockSourceConfig->ClockPolarity,
  4793. sClockSourceConfig->ClockFilter);
  4794. /* Select the External clock mode1 and the ETRF trigger */
  4795. tmpsmcr = htim->Instance->SMCR;
  4796. tmpsmcr |= (TIM_SLAVEMODE_EXTERNAL1 | TIM_CLOCKSOURCE_ETRMODE1);
  4797. /* Write to TIMx SMCR */
  4798. htim->Instance->SMCR = tmpsmcr;
  4799. break;
  4800. }
  4801. case TIM_CLOCKSOURCE_ETRMODE2:
  4802. {
  4803. /* Check whether or not the timer instance supports external trigger input mode 2 (ETRF)*/
  4804. assert_param(IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(htim->Instance));
  4805. /* Check ETR input conditioning related parameters */
  4806. assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
  4807. assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
  4808. assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
  4809. /* Configure the ETR Clock source */
  4810. TIM_ETR_SetConfig(htim->Instance,
  4811. sClockSourceConfig->ClockPrescaler,
  4812. sClockSourceConfig->ClockPolarity,
  4813. sClockSourceConfig->ClockFilter);
  4814. /* Enable the External clock mode2 */
  4815. htim->Instance->SMCR |= TIM_SMCR_ECE;
  4816. break;
  4817. }
  4818. case TIM_CLOCKSOURCE_TI1:
  4819. {
  4820. /* Check whether or not the timer instance supports external clock mode 1 */
  4821. assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
  4822. /* Check TI1 input conditioning related parameters */
  4823. assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
  4824. assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
  4825. TIM_TI1_ConfigInputStage(htim->Instance,
  4826. sClockSourceConfig->ClockPolarity,
  4827. sClockSourceConfig->ClockFilter);
  4828. TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1);
  4829. break;
  4830. }
  4831. case TIM_CLOCKSOURCE_TI2:
  4832. {
  4833. /* Check whether or not the timer instance supports external clock mode 1 (ETRF)*/
  4834. assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
  4835. /* Check TI2 input conditioning related parameters */
  4836. assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
  4837. assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
  4838. TIM_TI2_ConfigInputStage(htim->Instance,
  4839. sClockSourceConfig->ClockPolarity,
  4840. sClockSourceConfig->ClockFilter);
  4841. TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2);
  4842. break;
  4843. }
  4844. case TIM_CLOCKSOURCE_TI1ED:
  4845. {
  4846. /* Check whether or not the timer instance supports external clock mode 1 */
  4847. assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
  4848. /* Check TI1 input conditioning related parameters */
  4849. assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
  4850. assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
  4851. TIM_TI1_ConfigInputStage(htim->Instance,
  4852. sClockSourceConfig->ClockPolarity,
  4853. sClockSourceConfig->ClockFilter);
  4854. TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED);
  4855. break;
  4856. }
  4857. case TIM_CLOCKSOURCE_ITR0:
  4858. case TIM_CLOCKSOURCE_ITR1:
  4859. case TIM_CLOCKSOURCE_ITR2:
  4860. case TIM_CLOCKSOURCE_ITR3:
  4861. {
  4862. /* Check whether or not the timer instance supports internal trigger input */
  4863. assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
  4864. TIM_ITRx_SetConfig(htim->Instance, sClockSourceConfig->ClockSource);
  4865. break;
  4866. }
  4867. default:
  4868. status = HAL_ERROR;
  4869. break;
  4870. }
  4871. htim->State = HAL_TIM_STATE_READY;
  4872. __HAL_UNLOCK(htim);
  4873. return status;
  4874. }
  4875. /**
  4876. * @brief Selects the signal connected to the TI1 input: direct from CH1_input
  4877. * or a XOR combination between CH1_input, CH2_input & CH3_input
  4878. * @param htim TIM handle.
  4879. * @param TI1_Selection Indicate whether or not channel 1 is connected to the
  4880. * output of a XOR gate.
  4881. * This parameter can be one of the following values:
  4882. * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input
  4883. * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3
  4884. * pins are connected to the TI1 input (XOR combination)
  4885. * @retval HAL status
  4886. */
  4887. HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection)
  4888. {
  4889. uint32_t tmpcr2;
  4890. /* Check the parameters */
  4891. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  4892. assert_param(IS_TIM_TI1SELECTION(TI1_Selection));
  4893. /* Get the TIMx CR2 register value */
  4894. tmpcr2 = htim->Instance->CR2;
  4895. /* Reset the TI1 selection */
  4896. tmpcr2 &= ~TIM_CR2_TI1S;
  4897. /* Set the TI1 selection */
  4898. tmpcr2 |= TI1_Selection;
  4899. /* Write to TIMxCR2 */
  4900. htim->Instance->CR2 = tmpcr2;
  4901. return HAL_OK;
  4902. }
  4903. /**
  4904. * @brief Configures the TIM in Slave mode
  4905. * @param htim TIM handle.
  4906. * @param sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that
  4907. * contains the selected trigger (internal trigger input, filtered
  4908. * timer input or external trigger input) and the Slave mode
  4909. * (Disable, Reset, Gated, Trigger, External clock mode 1).
  4910. * @retval HAL status
  4911. */
  4912. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro(TIM_HandleTypeDef *htim, const TIM_SlaveConfigTypeDef *sSlaveConfig)
  4913. {
  4914. /* Check the parameters */
  4915. assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
  4916. assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
  4917. assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
  4918. __HAL_LOCK(htim);
  4919. htim->State = HAL_TIM_STATE_BUSY;
  4920. if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK)
  4921. {
  4922. htim->State = HAL_TIM_STATE_READY;
  4923. __HAL_UNLOCK(htim);
  4924. return HAL_ERROR;
  4925. }
  4926. /* Disable Trigger Interrupt */
  4927. __HAL_TIM_DISABLE_IT(htim, TIM_IT_TRIGGER);
  4928. /* Disable Trigger DMA request */
  4929. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER);
  4930. htim->State = HAL_TIM_STATE_READY;
  4931. __HAL_UNLOCK(htim);
  4932. return HAL_OK;
  4933. }
  4934. /**
  4935. * @brief Configures the TIM in Slave mode in interrupt mode
  4936. * @param htim TIM handle.
  4937. * @param sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that
  4938. * contains the selected trigger (internal trigger input, filtered
  4939. * timer input or external trigger input) and the Slave mode
  4940. * (Disable, Reset, Gated, Trigger, External clock mode 1).
  4941. * @retval HAL status
  4942. */
  4943. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro_IT(TIM_HandleTypeDef *htim,
  4944. const TIM_SlaveConfigTypeDef *sSlaveConfig)
  4945. {
  4946. /* Check the parameters */
  4947. assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
  4948. assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
  4949. assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
  4950. __HAL_LOCK(htim);
  4951. htim->State = HAL_TIM_STATE_BUSY;
  4952. if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK)
  4953. {
  4954. htim->State = HAL_TIM_STATE_READY;
  4955. __HAL_UNLOCK(htim);
  4956. return HAL_ERROR;
  4957. }
  4958. /* Enable Trigger Interrupt */
  4959. __HAL_TIM_ENABLE_IT(htim, TIM_IT_TRIGGER);
  4960. /* Disable Trigger DMA request */
  4961. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER);
  4962. htim->State = HAL_TIM_STATE_READY;
  4963. __HAL_UNLOCK(htim);
  4964. return HAL_OK;
  4965. }
  4966. /**
  4967. * @brief Read the captured value from Capture Compare unit
  4968. * @param htim TIM handle.
  4969. * @param Channel TIM Channels to be enabled
  4970. * This parameter can be one of the following values:
  4971. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  4972. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  4973. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  4974. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  4975. * @retval Captured value
  4976. */
  4977. uint32_t HAL_TIM_ReadCapturedValue(const TIM_HandleTypeDef *htim, uint32_t Channel)
  4978. {
  4979. uint32_t tmpreg = 0U;
  4980. switch (Channel)
  4981. {
  4982. case TIM_CHANNEL_1:
  4983. {
  4984. /* Check the parameters */
  4985. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  4986. /* Return the capture 1 value */
  4987. tmpreg = htim->Instance->CCR1;
  4988. break;
  4989. }
  4990. case TIM_CHANNEL_2:
  4991. {
  4992. /* Check the parameters */
  4993. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  4994. /* Return the capture 2 value */
  4995. tmpreg = htim->Instance->CCR2;
  4996. break;
  4997. }
  4998. case TIM_CHANNEL_3:
  4999. {
  5000. /* Check the parameters */
  5001. assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
  5002. /* Return the capture 3 value */
  5003. tmpreg = htim->Instance->CCR3;
  5004. break;
  5005. }
  5006. case TIM_CHANNEL_4:
  5007. {
  5008. /* Check the parameters */
  5009. assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
  5010. /* Return the capture 4 value */
  5011. tmpreg = htim->Instance->CCR4;
  5012. break;
  5013. }
  5014. default:
  5015. break;
  5016. }
  5017. return tmpreg;
  5018. }
  5019. /**
  5020. * @}
  5021. */
  5022. /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions
  5023. * @brief TIM Callbacks functions
  5024. *
  5025. @verbatim
  5026. ==============================================================================
  5027. ##### TIM Callbacks functions #####
  5028. ==============================================================================
  5029. [..]
  5030. This section provides TIM callback functions:
  5031. (+) TIM Period elapsed callback
  5032. (+) TIM Output Compare callback
  5033. (+) TIM Input capture callback
  5034. (+) TIM Trigger callback
  5035. (+) TIM Error callback
  5036. @endverbatim
  5037. * @{
  5038. */
  5039. /**
  5040. * @brief Period elapsed callback in non-blocking mode
  5041. * @param htim TIM handle
  5042. * @retval None
  5043. */
  5044. __weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  5045. {
  5046. /* Prevent unused argument(s) compilation warning */
  5047. UNUSED(htim);
  5048. /* NOTE : This function should not be modified, when the callback is needed,
  5049. the HAL_TIM_PeriodElapsedCallback could be implemented in the user file
  5050. */
  5051. }
  5052. /**
  5053. * @brief Period elapsed half complete callback in non-blocking mode
  5054. * @param htim TIM handle
  5055. * @retval None
  5056. */
  5057. __weak void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef *htim)
  5058. {
  5059. /* Prevent unused argument(s) compilation warning */
  5060. UNUSED(htim);
  5061. /* NOTE : This function should not be modified, when the callback is needed,
  5062. the HAL_TIM_PeriodElapsedHalfCpltCallback could be implemented in the user file
  5063. */
  5064. }
  5065. /**
  5066. * @brief Output Compare callback in non-blocking mode
  5067. * @param htim TIM OC handle
  5068. * @retval None
  5069. */
  5070. __weak void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
  5071. {
  5072. /* Prevent unused argument(s) compilation warning */
  5073. UNUSED(htim);
  5074. /* NOTE : This function should not be modified, when the callback is needed,
  5075. the HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file
  5076. */
  5077. }
  5078. /**
  5079. * @brief Input Capture callback in non-blocking mode
  5080. * @param htim TIM IC handle
  5081. * @retval None
  5082. */
  5083. __weak void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
  5084. {
  5085. /* Prevent unused argument(s) compilation warning */
  5086. UNUSED(htim);
  5087. /* NOTE : This function should not be modified, when the callback is needed,
  5088. the HAL_TIM_IC_CaptureCallback could be implemented in the user file
  5089. */
  5090. }
  5091. /**
  5092. * @brief Input Capture half complete callback in non-blocking mode
  5093. * @param htim TIM IC handle
  5094. * @retval None
  5095. */
  5096. __weak void HAL_TIM_IC_CaptureHalfCpltCallback(TIM_HandleTypeDef *htim)
  5097. {
  5098. /* Prevent unused argument(s) compilation warning */
  5099. UNUSED(htim);
  5100. /* NOTE : This function should not be modified, when the callback is needed,
  5101. the HAL_TIM_IC_CaptureHalfCpltCallback could be implemented in the user file
  5102. */
  5103. }
  5104. /**
  5105. * @brief PWM Pulse finished callback in non-blocking mode
  5106. * @param htim TIM handle
  5107. * @retval None
  5108. */
  5109. __weak void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
  5110. {
  5111. /* Prevent unused argument(s) compilation warning */
  5112. UNUSED(htim);
  5113. /* NOTE : This function should not be modified, when the callback is needed,
  5114. the HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file
  5115. */
  5116. }
  5117. /**
  5118. * @brief PWM Pulse finished half complete callback in non-blocking mode
  5119. * @param htim TIM handle
  5120. * @retval None
  5121. */
  5122. __weak void HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef *htim)
  5123. {
  5124. /* Prevent unused argument(s) compilation warning */
  5125. UNUSED(htim);
  5126. /* NOTE : This function should not be modified, when the callback is needed,
  5127. the HAL_TIM_PWM_PulseFinishedHalfCpltCallback could be implemented in the user file
  5128. */
  5129. }
  5130. /**
  5131. * @brief Hall Trigger detection callback in non-blocking mode
  5132. * @param htim TIM handle
  5133. * @retval None
  5134. */
  5135. __weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim)
  5136. {
  5137. /* Prevent unused argument(s) compilation warning */
  5138. UNUSED(htim);
  5139. /* NOTE : This function should not be modified, when the callback is needed,
  5140. the HAL_TIM_TriggerCallback could be implemented in the user file
  5141. */
  5142. }
  5143. /**
  5144. * @brief Hall Trigger detection half complete callback in non-blocking mode
  5145. * @param htim TIM handle
  5146. * @retval None
  5147. */
  5148. __weak void HAL_TIM_TriggerHalfCpltCallback(TIM_HandleTypeDef *htim)
  5149. {
  5150. /* Prevent unused argument(s) compilation warning */
  5151. UNUSED(htim);
  5152. /* NOTE : This function should not be modified, when the callback is needed,
  5153. the HAL_TIM_TriggerHalfCpltCallback could be implemented in the user file
  5154. */
  5155. }
  5156. /**
  5157. * @brief Timer error callback in non-blocking mode
  5158. * @param htim TIM handle
  5159. * @retval None
  5160. */
  5161. __weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim)
  5162. {
  5163. /* Prevent unused argument(s) compilation warning */
  5164. UNUSED(htim);
  5165. /* NOTE : This function should not be modified, when the callback is needed,
  5166. the HAL_TIM_ErrorCallback could be implemented in the user file
  5167. */
  5168. }
  5169. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  5170. /**
  5171. * @brief Register a User TIM callback to be used instead of the weak predefined callback
  5172. * @param htim tim handle
  5173. * @param CallbackID ID of the callback to be registered
  5174. * This parameter can be one of the following values:
  5175. * @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID
  5176. * @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID
  5177. * @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID
  5178. * @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID
  5179. * @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID
  5180. * @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID
  5181. * @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID
  5182. * @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID
  5183. * @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID
  5184. * @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID
  5185. * @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID
  5186. * @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID
  5187. * @arg @ref HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID Hall Sensor MspInit Callback ID
  5188. * @arg @ref HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID Hall Sensor MspDeInit Callback ID
  5189. * @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID
  5190. * @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID
  5191. * @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID
  5192. * @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID
  5193. * @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID
  5194. * @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID
  5195. * @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID
  5196. * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID
  5197. * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID
  5198. * @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID
  5199. * @arg @ref HAL_TIM_COMMUTATION_CB_ID Commutation Callback ID
  5200. * @arg @ref HAL_TIM_COMMUTATION_HALF_CB_ID Commutation half complete Callback ID
  5201. * @arg @ref HAL_TIM_BREAK_CB_ID Break Callback ID
  5202. #if defined(TIM_BDTR_BK2E)
  5203. * @arg @ref HAL_TIM_BREAK2_CB_ID Break2 Callback ID
  5204. #endif
  5205. * @param pCallback pointer to the callback function
  5206. * @retval status
  5207. */
  5208. HAL_StatusTypeDef HAL_TIM_RegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID,
  5209. pTIM_CallbackTypeDef pCallback)
  5210. {
  5211. HAL_StatusTypeDef status = HAL_OK;
  5212. if (pCallback == NULL)
  5213. {
  5214. return HAL_ERROR;
  5215. }
  5216. if (htim->State == HAL_TIM_STATE_READY)
  5217. {
  5218. switch (CallbackID)
  5219. {
  5220. case HAL_TIM_BASE_MSPINIT_CB_ID :
  5221. htim->Base_MspInitCallback = pCallback;
  5222. break;
  5223. case HAL_TIM_BASE_MSPDEINIT_CB_ID :
  5224. htim->Base_MspDeInitCallback = pCallback;
  5225. break;
  5226. case HAL_TIM_IC_MSPINIT_CB_ID :
  5227. htim->IC_MspInitCallback = pCallback;
  5228. break;
  5229. case HAL_TIM_IC_MSPDEINIT_CB_ID :
  5230. htim->IC_MspDeInitCallback = pCallback;
  5231. break;
  5232. case HAL_TIM_OC_MSPINIT_CB_ID :
  5233. htim->OC_MspInitCallback = pCallback;
  5234. break;
  5235. case HAL_TIM_OC_MSPDEINIT_CB_ID :
  5236. htim->OC_MspDeInitCallback = pCallback;
  5237. break;
  5238. case HAL_TIM_PWM_MSPINIT_CB_ID :
  5239. htim->PWM_MspInitCallback = pCallback;
  5240. break;
  5241. case HAL_TIM_PWM_MSPDEINIT_CB_ID :
  5242. htim->PWM_MspDeInitCallback = pCallback;
  5243. break;
  5244. case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
  5245. htim->OnePulse_MspInitCallback = pCallback;
  5246. break;
  5247. case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
  5248. htim->OnePulse_MspDeInitCallback = pCallback;
  5249. break;
  5250. case HAL_TIM_ENCODER_MSPINIT_CB_ID :
  5251. htim->Encoder_MspInitCallback = pCallback;
  5252. break;
  5253. case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
  5254. htim->Encoder_MspDeInitCallback = pCallback;
  5255. break;
  5256. case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
  5257. htim->HallSensor_MspInitCallback = pCallback;
  5258. break;
  5259. case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
  5260. htim->HallSensor_MspDeInitCallback = pCallback;
  5261. break;
  5262. case HAL_TIM_PERIOD_ELAPSED_CB_ID :
  5263. htim->PeriodElapsedCallback = pCallback;
  5264. break;
  5265. case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID :
  5266. htim->PeriodElapsedHalfCpltCallback = pCallback;
  5267. break;
  5268. case HAL_TIM_TRIGGER_CB_ID :
  5269. htim->TriggerCallback = pCallback;
  5270. break;
  5271. case HAL_TIM_TRIGGER_HALF_CB_ID :
  5272. htim->TriggerHalfCpltCallback = pCallback;
  5273. break;
  5274. case HAL_TIM_IC_CAPTURE_CB_ID :
  5275. htim->IC_CaptureCallback = pCallback;
  5276. break;
  5277. case HAL_TIM_IC_CAPTURE_HALF_CB_ID :
  5278. htim->IC_CaptureHalfCpltCallback = pCallback;
  5279. break;
  5280. case HAL_TIM_OC_DELAY_ELAPSED_CB_ID :
  5281. htim->OC_DelayElapsedCallback = pCallback;
  5282. break;
  5283. case HAL_TIM_PWM_PULSE_FINISHED_CB_ID :
  5284. htim->PWM_PulseFinishedCallback = pCallback;
  5285. break;
  5286. case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID :
  5287. htim->PWM_PulseFinishedHalfCpltCallback = pCallback;
  5288. break;
  5289. case HAL_TIM_ERROR_CB_ID :
  5290. htim->ErrorCallback = pCallback;
  5291. break;
  5292. case HAL_TIM_COMMUTATION_CB_ID :
  5293. htim->CommutationCallback = pCallback;
  5294. break;
  5295. case HAL_TIM_COMMUTATION_HALF_CB_ID :
  5296. htim->CommutationHalfCpltCallback = pCallback;
  5297. break;
  5298. case HAL_TIM_BREAK_CB_ID :
  5299. htim->BreakCallback = pCallback;
  5300. break;
  5301. #if defined(TIM_BDTR_BK2E)
  5302. case HAL_TIM_BREAK2_CB_ID :
  5303. htim->Break2Callback = pCallback;
  5304. break;
  5305. #endif /* TIM_BDTR_BK2E */
  5306. default :
  5307. /* Return error status */
  5308. status = HAL_ERROR;
  5309. break;
  5310. }
  5311. }
  5312. else if (htim->State == HAL_TIM_STATE_RESET)
  5313. {
  5314. switch (CallbackID)
  5315. {
  5316. case HAL_TIM_BASE_MSPINIT_CB_ID :
  5317. htim->Base_MspInitCallback = pCallback;
  5318. break;
  5319. case HAL_TIM_BASE_MSPDEINIT_CB_ID :
  5320. htim->Base_MspDeInitCallback = pCallback;
  5321. break;
  5322. case HAL_TIM_IC_MSPINIT_CB_ID :
  5323. htim->IC_MspInitCallback = pCallback;
  5324. break;
  5325. case HAL_TIM_IC_MSPDEINIT_CB_ID :
  5326. htim->IC_MspDeInitCallback = pCallback;
  5327. break;
  5328. case HAL_TIM_OC_MSPINIT_CB_ID :
  5329. htim->OC_MspInitCallback = pCallback;
  5330. break;
  5331. case HAL_TIM_OC_MSPDEINIT_CB_ID :
  5332. htim->OC_MspDeInitCallback = pCallback;
  5333. break;
  5334. case HAL_TIM_PWM_MSPINIT_CB_ID :
  5335. htim->PWM_MspInitCallback = pCallback;
  5336. break;
  5337. case HAL_TIM_PWM_MSPDEINIT_CB_ID :
  5338. htim->PWM_MspDeInitCallback = pCallback;
  5339. break;
  5340. case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
  5341. htim->OnePulse_MspInitCallback = pCallback;
  5342. break;
  5343. case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
  5344. htim->OnePulse_MspDeInitCallback = pCallback;
  5345. break;
  5346. case HAL_TIM_ENCODER_MSPINIT_CB_ID :
  5347. htim->Encoder_MspInitCallback = pCallback;
  5348. break;
  5349. case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
  5350. htim->Encoder_MspDeInitCallback = pCallback;
  5351. break;
  5352. case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
  5353. htim->HallSensor_MspInitCallback = pCallback;
  5354. break;
  5355. case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
  5356. htim->HallSensor_MspDeInitCallback = pCallback;
  5357. break;
  5358. default :
  5359. /* Return error status */
  5360. status = HAL_ERROR;
  5361. break;
  5362. }
  5363. }
  5364. else
  5365. {
  5366. /* Return error status */
  5367. status = HAL_ERROR;
  5368. }
  5369. return status;
  5370. }
  5371. /**
  5372. * @brief Unregister a TIM callback
  5373. * TIM callback is redirected to the weak predefined callback
  5374. * @param htim tim handle
  5375. * @param CallbackID ID of the callback to be unregistered
  5376. * This parameter can be one of the following values:
  5377. * @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID
  5378. * @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID
  5379. * @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID
  5380. * @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID
  5381. * @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID
  5382. * @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID
  5383. * @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID
  5384. * @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID
  5385. * @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID
  5386. * @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID
  5387. * @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID
  5388. * @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID
  5389. * @arg @ref HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID Hall Sensor MspInit Callback ID
  5390. * @arg @ref HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID Hall Sensor MspDeInit Callback ID
  5391. * @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID
  5392. * @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID
  5393. * @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID
  5394. * @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID
  5395. * @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID
  5396. * @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID
  5397. * @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID
  5398. * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID
  5399. * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID
  5400. * @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID
  5401. * @arg @ref HAL_TIM_COMMUTATION_CB_ID Commutation Callback ID
  5402. * @arg @ref HAL_TIM_COMMUTATION_HALF_CB_ID Commutation half complete Callback ID
  5403. * @arg @ref HAL_TIM_BREAK_CB_ID Break Callback ID
  5404. #if defined(TIM_BDTR_BK2E)
  5405. * @arg @ref HAL_TIM_BREAK2_CB_ID Break2 Callback ID
  5406. #endif
  5407. * @retval status
  5408. */
  5409. HAL_StatusTypeDef HAL_TIM_UnRegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID)
  5410. {
  5411. HAL_StatusTypeDef status = HAL_OK;
  5412. if (htim->State == HAL_TIM_STATE_READY)
  5413. {
  5414. switch (CallbackID)
  5415. {
  5416. case HAL_TIM_BASE_MSPINIT_CB_ID :
  5417. /* Legacy weak Base MspInit Callback */
  5418. htim->Base_MspInitCallback = HAL_TIM_Base_MspInit;
  5419. break;
  5420. case HAL_TIM_BASE_MSPDEINIT_CB_ID :
  5421. /* Legacy weak Base Msp DeInit Callback */
  5422. htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit;
  5423. break;
  5424. case HAL_TIM_IC_MSPINIT_CB_ID :
  5425. /* Legacy weak IC Msp Init Callback */
  5426. htim->IC_MspInitCallback = HAL_TIM_IC_MspInit;
  5427. break;
  5428. case HAL_TIM_IC_MSPDEINIT_CB_ID :
  5429. /* Legacy weak IC Msp DeInit Callback */
  5430. htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit;
  5431. break;
  5432. case HAL_TIM_OC_MSPINIT_CB_ID :
  5433. /* Legacy weak OC Msp Init Callback */
  5434. htim->OC_MspInitCallback = HAL_TIM_OC_MspInit;
  5435. break;
  5436. case HAL_TIM_OC_MSPDEINIT_CB_ID :
  5437. /* Legacy weak OC Msp DeInit Callback */
  5438. htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit;
  5439. break;
  5440. case HAL_TIM_PWM_MSPINIT_CB_ID :
  5441. /* Legacy weak PWM Msp Init Callback */
  5442. htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit;
  5443. break;
  5444. case HAL_TIM_PWM_MSPDEINIT_CB_ID :
  5445. /* Legacy weak PWM Msp DeInit Callback */
  5446. htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit;
  5447. break;
  5448. case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
  5449. /* Legacy weak One Pulse Msp Init Callback */
  5450. htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit;
  5451. break;
  5452. case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
  5453. /* Legacy weak One Pulse Msp DeInit Callback */
  5454. htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit;
  5455. break;
  5456. case HAL_TIM_ENCODER_MSPINIT_CB_ID :
  5457. /* Legacy weak Encoder Msp Init Callback */
  5458. htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit;
  5459. break;
  5460. case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
  5461. /* Legacy weak Encoder Msp DeInit Callback */
  5462. htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit;
  5463. break;
  5464. case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
  5465. /* Legacy weak Hall Sensor Msp Init Callback */
  5466. htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit;
  5467. break;
  5468. case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
  5469. /* Legacy weak Hall Sensor Msp DeInit Callback */
  5470. htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit;
  5471. break;
  5472. case HAL_TIM_PERIOD_ELAPSED_CB_ID :
  5473. /* Legacy weak Period Elapsed Callback */
  5474. htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback;
  5475. break;
  5476. case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID :
  5477. /* Legacy weak Period Elapsed half complete Callback */
  5478. htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback;
  5479. break;
  5480. case HAL_TIM_TRIGGER_CB_ID :
  5481. /* Legacy weak Trigger Callback */
  5482. htim->TriggerCallback = HAL_TIM_TriggerCallback;
  5483. break;
  5484. case HAL_TIM_TRIGGER_HALF_CB_ID :
  5485. /* Legacy weak Trigger half complete Callback */
  5486. htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback;
  5487. break;
  5488. case HAL_TIM_IC_CAPTURE_CB_ID :
  5489. /* Legacy weak IC Capture Callback */
  5490. htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback;
  5491. break;
  5492. case HAL_TIM_IC_CAPTURE_HALF_CB_ID :
  5493. /* Legacy weak IC Capture half complete Callback */
  5494. htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback;
  5495. break;
  5496. case HAL_TIM_OC_DELAY_ELAPSED_CB_ID :
  5497. /* Legacy weak OC Delay Elapsed Callback */
  5498. htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback;
  5499. break;
  5500. case HAL_TIM_PWM_PULSE_FINISHED_CB_ID :
  5501. /* Legacy weak PWM Pulse Finished Callback */
  5502. htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback;
  5503. break;
  5504. case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID :
  5505. /* Legacy weak PWM Pulse Finished half complete Callback */
  5506. htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback;
  5507. break;
  5508. case HAL_TIM_ERROR_CB_ID :
  5509. /* Legacy weak Error Callback */
  5510. htim->ErrorCallback = HAL_TIM_ErrorCallback;
  5511. break;
  5512. case HAL_TIM_COMMUTATION_CB_ID :
  5513. /* Legacy weak Commutation Callback */
  5514. htim->CommutationCallback = HAL_TIMEx_CommutCallback;
  5515. break;
  5516. case HAL_TIM_COMMUTATION_HALF_CB_ID :
  5517. /* Legacy weak Commutation half complete Callback */
  5518. htim->CommutationHalfCpltCallback = HAL_TIMEx_CommutHalfCpltCallback;
  5519. break;
  5520. case HAL_TIM_BREAK_CB_ID :
  5521. /* Legacy weak Break Callback */
  5522. htim->BreakCallback = HAL_TIMEx_BreakCallback;
  5523. break;
  5524. #if defined(TIM_BDTR_BK2E)
  5525. case HAL_TIM_BREAK2_CB_ID :
  5526. /* Legacy weak Break2 Callback */
  5527. htim->Break2Callback = HAL_TIMEx_Break2Callback;
  5528. break;
  5529. #endif /* TIM_BDTR_BK2E */
  5530. default :
  5531. /* Return error status */
  5532. status = HAL_ERROR;
  5533. break;
  5534. }
  5535. }
  5536. else if (htim->State == HAL_TIM_STATE_RESET)
  5537. {
  5538. switch (CallbackID)
  5539. {
  5540. case HAL_TIM_BASE_MSPINIT_CB_ID :
  5541. /* Legacy weak Base MspInit Callback */
  5542. htim->Base_MspInitCallback = HAL_TIM_Base_MspInit;
  5543. break;
  5544. case HAL_TIM_BASE_MSPDEINIT_CB_ID :
  5545. /* Legacy weak Base Msp DeInit Callback */
  5546. htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit;
  5547. break;
  5548. case HAL_TIM_IC_MSPINIT_CB_ID :
  5549. /* Legacy weak IC Msp Init Callback */
  5550. htim->IC_MspInitCallback = HAL_TIM_IC_MspInit;
  5551. break;
  5552. case HAL_TIM_IC_MSPDEINIT_CB_ID :
  5553. /* Legacy weak IC Msp DeInit Callback */
  5554. htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit;
  5555. break;
  5556. case HAL_TIM_OC_MSPINIT_CB_ID :
  5557. /* Legacy weak OC Msp Init Callback */
  5558. htim->OC_MspInitCallback = HAL_TIM_OC_MspInit;
  5559. break;
  5560. case HAL_TIM_OC_MSPDEINIT_CB_ID :
  5561. /* Legacy weak OC Msp DeInit Callback */
  5562. htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit;
  5563. break;
  5564. case HAL_TIM_PWM_MSPINIT_CB_ID :
  5565. /* Legacy weak PWM Msp Init Callback */
  5566. htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit;
  5567. break;
  5568. case HAL_TIM_PWM_MSPDEINIT_CB_ID :
  5569. /* Legacy weak PWM Msp DeInit Callback */
  5570. htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit;
  5571. break;
  5572. case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
  5573. /* Legacy weak One Pulse Msp Init Callback */
  5574. htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit;
  5575. break;
  5576. case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
  5577. /* Legacy weak One Pulse Msp DeInit Callback */
  5578. htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit;
  5579. break;
  5580. case HAL_TIM_ENCODER_MSPINIT_CB_ID :
  5581. /* Legacy weak Encoder Msp Init Callback */
  5582. htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit;
  5583. break;
  5584. case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
  5585. /* Legacy weak Encoder Msp DeInit Callback */
  5586. htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit;
  5587. break;
  5588. case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
  5589. /* Legacy weak Hall Sensor Msp Init Callback */
  5590. htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit;
  5591. break;
  5592. case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
  5593. /* Legacy weak Hall Sensor Msp DeInit Callback */
  5594. htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit;
  5595. break;
  5596. default :
  5597. /* Return error status */
  5598. status = HAL_ERROR;
  5599. break;
  5600. }
  5601. }
  5602. else
  5603. {
  5604. /* Return error status */
  5605. status = HAL_ERROR;
  5606. }
  5607. return status;
  5608. }
  5609. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  5610. /**
  5611. * @}
  5612. */
  5613. /** @defgroup TIM_Exported_Functions_Group10 TIM Peripheral State functions
  5614. * @brief TIM Peripheral State functions
  5615. *
  5616. @verbatim
  5617. ==============================================================================
  5618. ##### Peripheral State functions #####
  5619. ==============================================================================
  5620. [..]
  5621. This subsection permits to get in run-time the status of the peripheral
  5622. and the data flow.
  5623. @endverbatim
  5624. * @{
  5625. */
  5626. /**
  5627. * @brief Return the TIM Base handle state.
  5628. * @param htim TIM Base handle
  5629. * @retval HAL state
  5630. */
  5631. HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(const TIM_HandleTypeDef *htim)
  5632. {
  5633. return htim->State;
  5634. }
  5635. /**
  5636. * @brief Return the TIM OC handle state.
  5637. * @param htim TIM Output Compare handle
  5638. * @retval HAL state
  5639. */
  5640. HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(const TIM_HandleTypeDef *htim)
  5641. {
  5642. return htim->State;
  5643. }
  5644. /**
  5645. * @brief Return the TIM PWM handle state.
  5646. * @param htim TIM handle
  5647. * @retval HAL state
  5648. */
  5649. HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(const TIM_HandleTypeDef *htim)
  5650. {
  5651. return htim->State;
  5652. }
  5653. /**
  5654. * @brief Return the TIM Input Capture handle state.
  5655. * @param htim TIM IC handle
  5656. * @retval HAL state
  5657. */
  5658. HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(const TIM_HandleTypeDef *htim)
  5659. {
  5660. return htim->State;
  5661. }
  5662. /**
  5663. * @brief Return the TIM One Pulse Mode handle state.
  5664. * @param htim TIM OPM handle
  5665. * @retval HAL state
  5666. */
  5667. HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(const TIM_HandleTypeDef *htim)
  5668. {
  5669. return htim->State;
  5670. }
  5671. /**
  5672. * @brief Return the TIM Encoder Mode handle state.
  5673. * @param htim TIM Encoder Interface handle
  5674. * @retval HAL state
  5675. */
  5676. HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(const TIM_HandleTypeDef *htim)
  5677. {
  5678. return htim->State;
  5679. }
  5680. /**
  5681. * @brief Return the TIM Encoder Mode handle state.
  5682. * @param htim TIM handle
  5683. * @retval Active channel
  5684. */
  5685. HAL_TIM_ActiveChannel HAL_TIM_GetActiveChannel(const TIM_HandleTypeDef *htim)
  5686. {
  5687. return htim->Channel;
  5688. }
  5689. /**
  5690. * @brief Return actual state of the TIM channel.
  5691. * @param htim TIM handle
  5692. * @param Channel TIM Channel
  5693. * This parameter can be one of the following values:
  5694. * @arg TIM_CHANNEL_1: TIM Channel 1
  5695. * @arg TIM_CHANNEL_2: TIM Channel 2
  5696. * @arg TIM_CHANNEL_3: TIM Channel 3
  5697. * @arg TIM_CHANNEL_4: TIM Channel 4
  5698. * @arg TIM_CHANNEL_5: TIM Channel 5
  5699. * @arg TIM_CHANNEL_6: TIM Channel 6
  5700. * @retval TIM Channel state
  5701. */
  5702. HAL_TIM_ChannelStateTypeDef HAL_TIM_GetChannelState(const TIM_HandleTypeDef *htim, uint32_t Channel)
  5703. {
  5704. HAL_TIM_ChannelStateTypeDef channel_state;
  5705. /* Check the parameters */
  5706. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  5707. channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
  5708. return channel_state;
  5709. }
  5710. /**
  5711. * @brief Return actual state of a DMA burst operation.
  5712. * @param htim TIM handle
  5713. * @retval DMA burst state
  5714. */
  5715. HAL_TIM_DMABurstStateTypeDef HAL_TIM_DMABurstState(const TIM_HandleTypeDef *htim)
  5716. {
  5717. /* Check the parameters */
  5718. assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
  5719. return htim->DMABurstState;
  5720. }
  5721. /**
  5722. * @}
  5723. */
  5724. /**
  5725. * @}
  5726. */
  5727. /** @defgroup TIM_Private_Functions TIM Private Functions
  5728. * @{
  5729. */
  5730. /**
  5731. * @brief TIM DMA error callback
  5732. * @param hdma pointer to DMA handle.
  5733. * @retval None
  5734. */
  5735. void TIM_DMAError(DMA_HandleTypeDef *hdma)
  5736. {
  5737. TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  5738. if (hdma == htim->hdma[TIM_DMA_ID_CC1])
  5739. {
  5740. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
  5741. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  5742. }
  5743. else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
  5744. {
  5745. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
  5746. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  5747. }
  5748. else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
  5749. {
  5750. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
  5751. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY);
  5752. }
  5753. else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
  5754. {
  5755. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
  5756. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY);
  5757. }
  5758. else
  5759. {
  5760. htim->State = HAL_TIM_STATE_READY;
  5761. }
  5762. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  5763. htim->ErrorCallback(htim);
  5764. #else
  5765. HAL_TIM_ErrorCallback(htim);
  5766. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  5767. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  5768. }
  5769. /**
  5770. * @brief TIM DMA Delay Pulse complete callback.
  5771. * @param hdma pointer to DMA handle.
  5772. * @retval None
  5773. */
  5774. static void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma)
  5775. {
  5776. TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  5777. if (hdma == htim->hdma[TIM_DMA_ID_CC1])
  5778. {
  5779. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
  5780. if (hdma->Init.Mode == DMA_NORMAL)
  5781. {
  5782. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  5783. }
  5784. }
  5785. else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
  5786. {
  5787. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
  5788. if (hdma->Init.Mode == DMA_NORMAL)
  5789. {
  5790. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  5791. }
  5792. }
  5793. else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
  5794. {
  5795. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
  5796. if (hdma->Init.Mode == DMA_NORMAL)
  5797. {
  5798. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY);
  5799. }
  5800. }
  5801. else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
  5802. {
  5803. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
  5804. if (hdma->Init.Mode == DMA_NORMAL)
  5805. {
  5806. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY);
  5807. }
  5808. }
  5809. else
  5810. {
  5811. /* nothing to do */
  5812. }
  5813. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  5814. htim->PWM_PulseFinishedCallback(htim);
  5815. #else
  5816. HAL_TIM_PWM_PulseFinishedCallback(htim);
  5817. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  5818. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  5819. }
  5820. /**
  5821. * @brief TIM DMA Delay Pulse half complete callback.
  5822. * @param hdma pointer to DMA handle.
  5823. * @retval None
  5824. */
  5825. void TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef *hdma)
  5826. {
  5827. TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  5828. if (hdma == htim->hdma[TIM_DMA_ID_CC1])
  5829. {
  5830. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
  5831. }
  5832. else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
  5833. {
  5834. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
  5835. }
  5836. else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
  5837. {
  5838. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
  5839. }
  5840. else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
  5841. {
  5842. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
  5843. }
  5844. else
  5845. {
  5846. /* nothing to do */
  5847. }
  5848. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  5849. htim->PWM_PulseFinishedHalfCpltCallback(htim);
  5850. #else
  5851. HAL_TIM_PWM_PulseFinishedHalfCpltCallback(htim);
  5852. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  5853. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  5854. }
  5855. /**
  5856. * @brief TIM DMA Capture complete callback.
  5857. * @param hdma pointer to DMA handle.
  5858. * @retval None
  5859. */
  5860. void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma)
  5861. {
  5862. TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  5863. if (hdma == htim->hdma[TIM_DMA_ID_CC1])
  5864. {
  5865. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
  5866. if (hdma->Init.Mode == DMA_NORMAL)
  5867. {
  5868. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  5869. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
  5870. }
  5871. }
  5872. else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
  5873. {
  5874. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
  5875. if (hdma->Init.Mode == DMA_NORMAL)
  5876. {
  5877. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  5878. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
  5879. }
  5880. }
  5881. else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
  5882. {
  5883. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
  5884. if (hdma->Init.Mode == DMA_NORMAL)
  5885. {
  5886. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY);
  5887. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY);
  5888. }
  5889. }
  5890. else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
  5891. {
  5892. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
  5893. if (hdma->Init.Mode == DMA_NORMAL)
  5894. {
  5895. TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY);
  5896. TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY);
  5897. }
  5898. }
  5899. else
  5900. {
  5901. /* nothing to do */
  5902. }
  5903. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  5904. htim->IC_CaptureCallback(htim);
  5905. #else
  5906. HAL_TIM_IC_CaptureCallback(htim);
  5907. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  5908. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  5909. }
  5910. /**
  5911. * @brief TIM DMA Capture half complete callback.
  5912. * @param hdma pointer to DMA handle.
  5913. * @retval None
  5914. */
  5915. void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef *hdma)
  5916. {
  5917. TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  5918. if (hdma == htim->hdma[TIM_DMA_ID_CC1])
  5919. {
  5920. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
  5921. }
  5922. else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
  5923. {
  5924. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
  5925. }
  5926. else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
  5927. {
  5928. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
  5929. }
  5930. else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
  5931. {
  5932. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
  5933. }
  5934. else
  5935. {
  5936. /* nothing to do */
  5937. }
  5938. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  5939. htim->IC_CaptureHalfCpltCallback(htim);
  5940. #else
  5941. HAL_TIM_IC_CaptureHalfCpltCallback(htim);
  5942. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  5943. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  5944. }
  5945. /**
  5946. * @brief TIM DMA Period Elapse complete callback.
  5947. * @param hdma pointer to DMA handle.
  5948. * @retval None
  5949. */
  5950. static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma)
  5951. {
  5952. TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  5953. if (htim->hdma[TIM_DMA_ID_UPDATE]->Init.Mode == DMA_NORMAL)
  5954. {
  5955. htim->State = HAL_TIM_STATE_READY;
  5956. }
  5957. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  5958. htim->PeriodElapsedCallback(htim);
  5959. #else
  5960. HAL_TIM_PeriodElapsedCallback(htim);
  5961. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  5962. }
  5963. /**
  5964. * @brief TIM DMA Period Elapse half complete callback.
  5965. * @param hdma pointer to DMA handle.
  5966. * @retval None
  5967. */
  5968. static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma)
  5969. {
  5970. TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  5971. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  5972. htim->PeriodElapsedHalfCpltCallback(htim);
  5973. #else
  5974. HAL_TIM_PeriodElapsedHalfCpltCallback(htim);
  5975. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  5976. }
  5977. /**
  5978. * @brief TIM DMA Trigger callback.
  5979. * @param hdma pointer to DMA handle.
  5980. * @retval None
  5981. */
  5982. static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma)
  5983. {
  5984. TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  5985. if (htim->hdma[TIM_DMA_ID_TRIGGER]->Init.Mode == DMA_NORMAL)
  5986. {
  5987. htim->State = HAL_TIM_STATE_READY;
  5988. }
  5989. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  5990. htim->TriggerCallback(htim);
  5991. #else
  5992. HAL_TIM_TriggerCallback(htim);
  5993. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  5994. }
  5995. /**
  5996. * @brief TIM DMA Trigger half complete callback.
  5997. * @param hdma pointer to DMA handle.
  5998. * @retval None
  5999. */
  6000. static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma)
  6001. {
  6002. TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  6003. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  6004. htim->TriggerHalfCpltCallback(htim);
  6005. #else
  6006. HAL_TIM_TriggerHalfCpltCallback(htim);
  6007. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  6008. }
  6009. /**
  6010. * @brief Time Base configuration
  6011. * @param TIMx TIM peripheral
  6012. * @param Structure TIM Base configuration structure
  6013. * @retval None
  6014. */
  6015. void TIM_Base_SetConfig(TIM_TypeDef *TIMx, const TIM_Base_InitTypeDef *Structure)
  6016. {
  6017. uint32_t tmpcr1;
  6018. tmpcr1 = TIMx->CR1;
  6019. /* Set TIM Time Base Unit parameters ---------------------------------------*/
  6020. if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx))
  6021. {
  6022. /* Select the Counter Mode */
  6023. tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);
  6024. tmpcr1 |= Structure->CounterMode;
  6025. }
  6026. if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx))
  6027. {
  6028. /* Set the clock division */
  6029. tmpcr1 &= ~TIM_CR1_CKD;
  6030. tmpcr1 |= (uint32_t)Structure->ClockDivision;
  6031. }
  6032. /* Set the auto-reload preload */
  6033. MODIFY_REG(tmpcr1, TIM_CR1_ARPE, Structure->AutoReloadPreload);
  6034. TIMx->CR1 = tmpcr1;
  6035. /* Set the Autoreload value */
  6036. TIMx->ARR = (uint32_t)Structure->Period ;
  6037. /* Set the Prescaler value */
  6038. TIMx->PSC = Structure->Prescaler;
  6039. if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx))
  6040. {
  6041. /* Set the Repetition Counter value */
  6042. TIMx->RCR = Structure->RepetitionCounter;
  6043. }
  6044. /* Generate an update event to reload the Prescaler
  6045. and the repetition counter (only for advanced timer) value immediately */
  6046. TIMx->EGR = TIM_EGR_UG;
  6047. /* Check if the update flag is set after the Update Generation, if so clear the UIF flag */
  6048. if (HAL_IS_BIT_SET(TIMx->SR, TIM_FLAG_UPDATE))
  6049. {
  6050. /* Clear the update flag */
  6051. CLEAR_BIT(TIMx->SR, TIM_FLAG_UPDATE);
  6052. }
  6053. }
  6054. /**
  6055. * @brief Timer Output Compare 1 configuration
  6056. * @param TIMx to select the TIM peripheral
  6057. * @param OC_Config The output configuration structure
  6058. * @retval None
  6059. */
  6060. static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
  6061. {
  6062. uint32_t tmpccmrx;
  6063. uint32_t tmpccer;
  6064. uint32_t tmpcr2;
  6065. /* Get the TIMx CCER register value */
  6066. tmpccer = TIMx->CCER;
  6067. /* Disable the Channel 1: Reset the CC1E Bit */
  6068. TIMx->CCER &= ~TIM_CCER_CC1E;
  6069. /* Get the TIMx CR2 register value */
  6070. tmpcr2 = TIMx->CR2;
  6071. /* Get the TIMx CCMR1 register value */
  6072. tmpccmrx = TIMx->CCMR1;
  6073. /* Reset the Output Compare Mode Bits */
  6074. tmpccmrx &= ~TIM_CCMR1_OC1M;
  6075. tmpccmrx &= ~TIM_CCMR1_CC1S;
  6076. /* Select the Output Compare Mode */
  6077. tmpccmrx |= OC_Config->OCMode;
  6078. /* Reset the Output Polarity level */
  6079. tmpccer &= ~TIM_CCER_CC1P;
  6080. /* Set the Output Compare Polarity */
  6081. tmpccer |= OC_Config->OCPolarity;
  6082. if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_1))
  6083. {
  6084. /* Check parameters */
  6085. assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
  6086. /* Reset the Output N Polarity level */
  6087. tmpccer &= ~TIM_CCER_CC1NP;
  6088. /* Set the Output N Polarity */
  6089. tmpccer |= OC_Config->OCNPolarity;
  6090. /* Reset the Output N State */
  6091. tmpccer &= ~TIM_CCER_CC1NE;
  6092. }
  6093. if (IS_TIM_BREAK_INSTANCE(TIMx))
  6094. {
  6095. /* Check parameters */
  6096. assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
  6097. assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
  6098. /* Reset the Output Compare and Output Compare N IDLE State */
  6099. tmpcr2 &= ~TIM_CR2_OIS1;
  6100. tmpcr2 &= ~TIM_CR2_OIS1N;
  6101. /* Set the Output Idle state */
  6102. tmpcr2 |= OC_Config->OCIdleState;
  6103. /* Set the Output N Idle state */
  6104. tmpcr2 |= OC_Config->OCNIdleState;
  6105. }
  6106. /* Write to TIMx CR2 */
  6107. TIMx->CR2 = tmpcr2;
  6108. /* Write to TIMx CCMR1 */
  6109. TIMx->CCMR1 = tmpccmrx;
  6110. /* Set the Capture Compare Register value */
  6111. TIMx->CCR1 = OC_Config->Pulse;
  6112. /* Write to TIMx CCER */
  6113. TIMx->CCER = tmpccer;
  6114. }
  6115. /**
  6116. * @brief Timer Output Compare 2 configuration
  6117. * @param TIMx to select the TIM peripheral
  6118. * @param OC_Config The output configuration structure
  6119. * @retval None
  6120. */
  6121. void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
  6122. {
  6123. uint32_t tmpccmrx;
  6124. uint32_t tmpccer;
  6125. uint32_t tmpcr2;
  6126. /* Get the TIMx CCER register value */
  6127. tmpccer = TIMx->CCER;
  6128. /* Disable the Channel 2: Reset the CC2E Bit */
  6129. TIMx->CCER &= ~TIM_CCER_CC2E;
  6130. /* Get the TIMx CR2 register value */
  6131. tmpcr2 = TIMx->CR2;
  6132. /* Get the TIMx CCMR1 register value */
  6133. tmpccmrx = TIMx->CCMR1;
  6134. /* Reset the Output Compare mode and Capture/Compare selection Bits */
  6135. tmpccmrx &= ~TIM_CCMR1_OC2M;
  6136. tmpccmrx &= ~TIM_CCMR1_CC2S;
  6137. /* Select the Output Compare Mode */
  6138. tmpccmrx |= (OC_Config->OCMode << 8U);
  6139. /* Reset the Output Polarity level */
  6140. tmpccer &= ~TIM_CCER_CC2P;
  6141. /* Set the Output Compare Polarity */
  6142. tmpccer |= (OC_Config->OCPolarity << 4U);
  6143. if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_2))
  6144. {
  6145. assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
  6146. /* Reset the Output N Polarity level */
  6147. tmpccer &= ~TIM_CCER_CC2NP;
  6148. /* Set the Output N Polarity */
  6149. tmpccer |= (OC_Config->OCNPolarity << 4U);
  6150. /* Reset the Output N State */
  6151. tmpccer &= ~TIM_CCER_CC2NE;
  6152. }
  6153. if (IS_TIM_BREAK_INSTANCE(TIMx))
  6154. {
  6155. /* Check parameters */
  6156. assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
  6157. assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
  6158. /* Reset the Output Compare and Output Compare N IDLE State */
  6159. tmpcr2 &= ~TIM_CR2_OIS2;
  6160. #if defined(TIM_CR2_OIS2N)
  6161. tmpcr2 &= ~TIM_CR2_OIS2N;
  6162. #endif /* TIM_CR2_OIS2N */
  6163. /* Set the Output Idle state */
  6164. tmpcr2 |= (OC_Config->OCIdleState << 2U);
  6165. /* Set the Output N Idle state */
  6166. tmpcr2 |= (OC_Config->OCNIdleState << 2U);
  6167. }
  6168. /* Write to TIMx CR2 */
  6169. TIMx->CR2 = tmpcr2;
  6170. /* Write to TIMx CCMR1 */
  6171. TIMx->CCMR1 = tmpccmrx;
  6172. /* Set the Capture Compare Register value */
  6173. TIMx->CCR2 = OC_Config->Pulse;
  6174. /* Write to TIMx CCER */
  6175. TIMx->CCER = tmpccer;
  6176. }
  6177. /**
  6178. * @brief Timer Output Compare 3 configuration
  6179. * @param TIMx to select the TIM peripheral
  6180. * @param OC_Config The output configuration structure
  6181. * @retval None
  6182. */
  6183. static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
  6184. {
  6185. uint32_t tmpccmrx;
  6186. uint32_t tmpccer;
  6187. uint32_t tmpcr2;
  6188. /* Get the TIMx CCER register value */
  6189. tmpccer = TIMx->CCER;
  6190. /* Disable the Channel 3: Reset the CC2E Bit */
  6191. TIMx->CCER &= ~TIM_CCER_CC3E;
  6192. /* Get the TIMx CR2 register value */
  6193. tmpcr2 = TIMx->CR2;
  6194. /* Get the TIMx CCMR2 register value */
  6195. tmpccmrx = TIMx->CCMR2;
  6196. /* Reset the Output Compare mode and Capture/Compare selection Bits */
  6197. tmpccmrx &= ~TIM_CCMR2_OC3M;
  6198. tmpccmrx &= ~TIM_CCMR2_CC3S;
  6199. /* Select the Output Compare Mode */
  6200. tmpccmrx |= OC_Config->OCMode;
  6201. /* Reset the Output Polarity level */
  6202. tmpccer &= ~TIM_CCER_CC3P;
  6203. /* Set the Output Compare Polarity */
  6204. tmpccer |= (OC_Config->OCPolarity << 8U);
  6205. if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_3))
  6206. {
  6207. assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
  6208. /* Reset the Output N Polarity level */
  6209. tmpccer &= ~TIM_CCER_CC3NP;
  6210. /* Set the Output N Polarity */
  6211. tmpccer |= (OC_Config->OCNPolarity << 8U);
  6212. /* Reset the Output N State */
  6213. tmpccer &= ~TIM_CCER_CC3NE;
  6214. }
  6215. #if defined(TIM_CR2_OIS3)
  6216. if (IS_TIM_BREAK_INSTANCE(TIMx))
  6217. {
  6218. /* Check parameters */
  6219. assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
  6220. assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
  6221. /* Reset the Output Compare and Output Compare N IDLE State */
  6222. tmpcr2 &= ~TIM_CR2_OIS3;
  6223. tmpcr2 &= ~TIM_CR2_OIS3N;
  6224. /* Set the Output Idle state */
  6225. tmpcr2 |= (OC_Config->OCIdleState << 4U);
  6226. /* Set the Output N Idle state */
  6227. tmpcr2 |= (OC_Config->OCNIdleState << 4U);
  6228. }
  6229. #endif /* TIM_CR2_OIS3 */
  6230. /* Write to TIMx CR2 */
  6231. TIMx->CR2 = tmpcr2;
  6232. /* Write to TIMx CCMR2 */
  6233. TIMx->CCMR2 = tmpccmrx;
  6234. /* Set the Capture Compare Register value */
  6235. TIMx->CCR3 = OC_Config->Pulse;
  6236. /* Write to TIMx CCER */
  6237. TIMx->CCER = tmpccer;
  6238. }
  6239. /**
  6240. * @brief Timer Output Compare 4 configuration
  6241. * @param TIMx to select the TIM peripheral
  6242. * @param OC_Config The output configuration structure
  6243. * @retval None
  6244. */
  6245. static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
  6246. {
  6247. uint32_t tmpccmrx;
  6248. uint32_t tmpccer;
  6249. uint32_t tmpcr2;
  6250. /* Get the TIMx CCER register value */
  6251. tmpccer = TIMx->CCER;
  6252. /* Disable the Channel 4: Reset the CC4E Bit */
  6253. TIMx->CCER &= ~TIM_CCER_CC4E;
  6254. /* Get the TIMx CR2 register value */
  6255. tmpcr2 = TIMx->CR2;
  6256. /* Get the TIMx CCMR2 register value */
  6257. tmpccmrx = TIMx->CCMR2;
  6258. /* Reset the Output Compare mode and Capture/Compare selection Bits */
  6259. tmpccmrx &= ~TIM_CCMR2_OC4M;
  6260. tmpccmrx &= ~TIM_CCMR2_CC4S;
  6261. /* Select the Output Compare Mode */
  6262. tmpccmrx |= (OC_Config->OCMode << 8U);
  6263. /* Reset the Output Polarity level */
  6264. tmpccer &= ~TIM_CCER_CC4P;
  6265. /* Set the Output Compare Polarity */
  6266. tmpccer |= (OC_Config->OCPolarity << 12U);
  6267. #if defined(TIM_CR2_OIS4)
  6268. if (IS_TIM_BREAK_INSTANCE(TIMx))
  6269. {
  6270. /* Check parameters */
  6271. assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
  6272. /* Reset the Output Compare IDLE State */
  6273. tmpcr2 &= ~TIM_CR2_OIS4;
  6274. /* Set the Output Idle state */
  6275. tmpcr2 |= (OC_Config->OCIdleState << 6U);
  6276. }
  6277. #endif /* TIM_CR2_OIS4 */
  6278. /* Write to TIMx CR2 */
  6279. TIMx->CR2 = tmpcr2;
  6280. /* Write to TIMx CCMR2 */
  6281. TIMx->CCMR2 = tmpccmrx;
  6282. /* Set the Capture Compare Register value */
  6283. TIMx->CCR4 = OC_Config->Pulse;
  6284. /* Write to TIMx CCER */
  6285. TIMx->CCER = tmpccer;
  6286. }
  6287. #if defined(TIM_CCER_CC5E)
  6288. /**
  6289. * @brief Timer Output Compare 5 configuration
  6290. * @param TIMx to select the TIM peripheral
  6291. * @param OC_Config The output configuration structure
  6292. * @retval None
  6293. */
  6294. static void TIM_OC5_SetConfig(TIM_TypeDef *TIMx,
  6295. const TIM_OC_InitTypeDef *OC_Config)
  6296. {
  6297. uint32_t tmpccmrx;
  6298. uint32_t tmpccer;
  6299. uint32_t tmpcr2;
  6300. /* Get the TIMx CCER register value */
  6301. tmpccer = TIMx->CCER;
  6302. /* Disable the output: Reset the CCxE Bit */
  6303. TIMx->CCER &= ~TIM_CCER_CC5E;
  6304. /* Get the TIMx CR2 register value */
  6305. tmpcr2 = TIMx->CR2;
  6306. /* Get the TIMx CCMR1 register value */
  6307. tmpccmrx = TIMx->CCMR3;
  6308. /* Reset the Output Compare Mode Bits */
  6309. tmpccmrx &= ~(TIM_CCMR3_OC5M);
  6310. /* Select the Output Compare Mode */
  6311. tmpccmrx |= OC_Config->OCMode;
  6312. /* Reset the Output Polarity level */
  6313. tmpccer &= ~TIM_CCER_CC5P;
  6314. /* Set the Output Compare Polarity */
  6315. tmpccer |= (OC_Config->OCPolarity << 16U);
  6316. if (IS_TIM_BREAK_INSTANCE(TIMx))
  6317. {
  6318. /* Reset the Output Compare IDLE State */
  6319. tmpcr2 &= ~TIM_CR2_OIS5;
  6320. /* Set the Output Idle state */
  6321. tmpcr2 |= (OC_Config->OCIdleState << 8U);
  6322. }
  6323. /* Write to TIMx CR2 */
  6324. TIMx->CR2 = tmpcr2;
  6325. /* Write to TIMx CCMR3 */
  6326. TIMx->CCMR3 = tmpccmrx;
  6327. /* Set the Capture Compare Register value */
  6328. TIMx->CCR5 = OC_Config->Pulse;
  6329. /* Write to TIMx CCER */
  6330. TIMx->CCER = tmpccer;
  6331. }
  6332. #endif /* TIM_CCER_CC5E */
  6333. #if defined(TIM_CCER_CC6E)
  6334. /**
  6335. * @brief Timer Output Compare 6 configuration
  6336. * @param TIMx to select the TIM peripheral
  6337. * @param OC_Config The output configuration structure
  6338. * @retval None
  6339. */
  6340. static void TIM_OC6_SetConfig(TIM_TypeDef *TIMx,
  6341. const TIM_OC_InitTypeDef *OC_Config)
  6342. {
  6343. uint32_t tmpccmrx;
  6344. uint32_t tmpccer;
  6345. uint32_t tmpcr2;
  6346. /* Get the TIMx CCER register value */
  6347. tmpccer = TIMx->CCER;
  6348. /* Disable the output: Reset the CCxE Bit */
  6349. TIMx->CCER &= ~TIM_CCER_CC6E;
  6350. /* Get the TIMx CR2 register value */
  6351. tmpcr2 = TIMx->CR2;
  6352. /* Get the TIMx CCMR1 register value */
  6353. tmpccmrx = TIMx->CCMR3;
  6354. /* Reset the Output Compare Mode Bits */
  6355. tmpccmrx &= ~(TIM_CCMR3_OC6M);
  6356. /* Select the Output Compare Mode */
  6357. tmpccmrx |= (OC_Config->OCMode << 8U);
  6358. /* Reset the Output Polarity level */
  6359. tmpccer &= (uint32_t)~TIM_CCER_CC6P;
  6360. /* Set the Output Compare Polarity */
  6361. tmpccer |= (OC_Config->OCPolarity << 20U);
  6362. if (IS_TIM_BREAK_INSTANCE(TIMx))
  6363. {
  6364. /* Reset the Output Compare IDLE State */
  6365. tmpcr2 &= ~TIM_CR2_OIS6;
  6366. /* Set the Output Idle state */
  6367. tmpcr2 |= (OC_Config->OCIdleState << 10U);
  6368. }
  6369. /* Write to TIMx CR2 */
  6370. TIMx->CR2 = tmpcr2;
  6371. /* Write to TIMx CCMR3 */
  6372. TIMx->CCMR3 = tmpccmrx;
  6373. /* Set the Capture Compare Register value */
  6374. TIMx->CCR6 = OC_Config->Pulse;
  6375. /* Write to TIMx CCER */
  6376. TIMx->CCER = tmpccer;
  6377. }
  6378. #endif /* TIM_CCER_CC6E */
  6379. /**
  6380. * @brief Slave Timer configuration function
  6381. * @param htim TIM handle
  6382. * @param sSlaveConfig Slave timer configuration
  6383. * @retval None
  6384. */
  6385. static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
  6386. const TIM_SlaveConfigTypeDef *sSlaveConfig)
  6387. {
  6388. HAL_StatusTypeDef status = HAL_OK;
  6389. uint32_t tmpsmcr;
  6390. uint32_t tmpccmr1;
  6391. uint32_t tmpccer;
  6392. /* Get the TIMx SMCR register value */
  6393. tmpsmcr = htim->Instance->SMCR;
  6394. /* Reset the Trigger Selection Bits */
  6395. tmpsmcr &= ~TIM_SMCR_TS;
  6396. /* Set the Input Trigger source */
  6397. tmpsmcr |= sSlaveConfig->InputTrigger;
  6398. /* Reset the slave mode Bits */
  6399. tmpsmcr &= ~TIM_SMCR_SMS;
  6400. /* Set the slave mode */
  6401. tmpsmcr |= sSlaveConfig->SlaveMode;
  6402. /* Write to TIMx SMCR */
  6403. htim->Instance->SMCR = tmpsmcr;
  6404. /* Configure the trigger prescaler, filter, and polarity */
  6405. switch (sSlaveConfig->InputTrigger)
  6406. {
  6407. case TIM_TS_ETRF:
  6408. {
  6409. /* Check the parameters */
  6410. assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance));
  6411. assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler));
  6412. assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
  6413. assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
  6414. /* Configure the ETR Trigger source */
  6415. TIM_ETR_SetConfig(htim->Instance,
  6416. sSlaveConfig->TriggerPrescaler,
  6417. sSlaveConfig->TriggerPolarity,
  6418. sSlaveConfig->TriggerFilter);
  6419. break;
  6420. }
  6421. case TIM_TS_TI1F_ED:
  6422. {
  6423. /* Check the parameters */
  6424. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  6425. assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
  6426. if (sSlaveConfig->SlaveMode == TIM_SLAVEMODE_GATED)
  6427. {
  6428. return HAL_ERROR;
  6429. }
  6430. /* Disable the Channel 1: Reset the CC1E Bit */
  6431. tmpccer = htim->Instance->CCER;
  6432. htim->Instance->CCER &= ~TIM_CCER_CC1E;
  6433. tmpccmr1 = htim->Instance->CCMR1;
  6434. /* Set the filter */
  6435. tmpccmr1 &= ~TIM_CCMR1_IC1F;
  6436. tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4U);
  6437. /* Write to TIMx CCMR1 and CCER registers */
  6438. htim->Instance->CCMR1 = tmpccmr1;
  6439. htim->Instance->CCER = tmpccer;
  6440. break;
  6441. }
  6442. case TIM_TS_TI1FP1:
  6443. {
  6444. /* Check the parameters */
  6445. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  6446. assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
  6447. assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
  6448. /* Configure TI1 Filter and Polarity */
  6449. TIM_TI1_ConfigInputStage(htim->Instance,
  6450. sSlaveConfig->TriggerPolarity,
  6451. sSlaveConfig->TriggerFilter);
  6452. break;
  6453. }
  6454. case TIM_TS_TI2FP2:
  6455. {
  6456. /* Check the parameters */
  6457. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  6458. assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
  6459. assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
  6460. /* Configure TI2 Filter and Polarity */
  6461. TIM_TI2_ConfigInputStage(htim->Instance,
  6462. sSlaveConfig->TriggerPolarity,
  6463. sSlaveConfig->TriggerFilter);
  6464. break;
  6465. }
  6466. case TIM_TS_ITR0:
  6467. case TIM_TS_ITR1:
  6468. case TIM_TS_ITR2:
  6469. case TIM_TS_ITR3:
  6470. {
  6471. /* Check the parameter */
  6472. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  6473. break;
  6474. }
  6475. default:
  6476. status = HAL_ERROR;
  6477. break;
  6478. }
  6479. return status;
  6480. }
  6481. /**
  6482. * @brief Configure the TI1 as Input.
  6483. * @param TIMx to select the TIM peripheral.
  6484. * @param TIM_ICPolarity The Input Polarity.
  6485. * This parameter can be one of the following values:
  6486. * @arg TIM_ICPOLARITY_RISING
  6487. * @arg TIM_ICPOLARITY_FALLING
  6488. * @arg TIM_ICPOLARITY_BOTHEDGE
  6489. * @param TIM_ICSelection specifies the input to be used.
  6490. * This parameter can be one of the following values:
  6491. * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 1 is selected to be connected to IC1.
  6492. * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 1 is selected to be connected to IC2.
  6493. * @arg TIM_ICSELECTION_TRC: TIM Input 1 is selected to be connected to TRC.
  6494. * @param TIM_ICFilter Specifies the Input Capture Filter.
  6495. * This parameter must be a value between 0x00 and 0x0F.
  6496. * @retval None
  6497. * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1
  6498. * (on channel2 path) is used as the input signal. Therefore CCMR1 must be
  6499. * protected against un-initialized filter and polarity values.
  6500. */
  6501. void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  6502. uint32_t TIM_ICFilter)
  6503. {
  6504. uint32_t tmpccmr1;
  6505. uint32_t tmpccer;
  6506. /* Disable the Channel 1: Reset the CC1E Bit */
  6507. tmpccer = TIMx->CCER;
  6508. TIMx->CCER &= ~TIM_CCER_CC1E;
  6509. tmpccmr1 = TIMx->CCMR1;
  6510. /* Select the Input */
  6511. if (IS_TIM_CC2_INSTANCE(TIMx) != RESET)
  6512. {
  6513. tmpccmr1 &= ~TIM_CCMR1_CC1S;
  6514. tmpccmr1 |= TIM_ICSelection;
  6515. }
  6516. else
  6517. {
  6518. tmpccmr1 |= TIM_CCMR1_CC1S_0;
  6519. }
  6520. /* Set the filter */
  6521. tmpccmr1 &= ~TIM_CCMR1_IC1F;
  6522. tmpccmr1 |= ((TIM_ICFilter << 4U) & TIM_CCMR1_IC1F);
  6523. /* Select the Polarity and set the CC1E Bit */
  6524. tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
  6525. tmpccer |= (TIM_ICPolarity & (TIM_CCER_CC1P | TIM_CCER_CC1NP));
  6526. /* Write to TIMx CCMR1 and CCER registers */
  6527. TIMx->CCMR1 = tmpccmr1;
  6528. TIMx->CCER = tmpccer;
  6529. }
  6530. /**
  6531. * @brief Configure the Polarity and Filter for TI1.
  6532. * @param TIMx to select the TIM peripheral.
  6533. * @param TIM_ICPolarity The Input Polarity.
  6534. * This parameter can be one of the following values:
  6535. * @arg TIM_ICPOLARITY_RISING
  6536. * @arg TIM_ICPOLARITY_FALLING
  6537. * @arg TIM_ICPOLARITY_BOTHEDGE
  6538. * @param TIM_ICFilter Specifies the Input Capture Filter.
  6539. * This parameter must be a value between 0x00 and 0x0F.
  6540. * @retval None
  6541. */
  6542. static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
  6543. {
  6544. uint32_t tmpccmr1;
  6545. uint32_t tmpccer;
  6546. /* Disable the Channel 1: Reset the CC1E Bit */
  6547. tmpccer = TIMx->CCER;
  6548. TIMx->CCER &= ~TIM_CCER_CC1E;
  6549. tmpccmr1 = TIMx->CCMR1;
  6550. /* Set the filter */
  6551. tmpccmr1 &= ~TIM_CCMR1_IC1F;
  6552. tmpccmr1 |= (TIM_ICFilter << 4U);
  6553. /* Select the Polarity and set the CC1E Bit */
  6554. tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
  6555. tmpccer |= TIM_ICPolarity;
  6556. /* Write to TIMx CCMR1 and CCER registers */
  6557. TIMx->CCMR1 = tmpccmr1;
  6558. TIMx->CCER = tmpccer;
  6559. }
  6560. /**
  6561. * @brief Configure the TI2 as Input.
  6562. * @param TIMx to select the TIM peripheral
  6563. * @param TIM_ICPolarity The Input Polarity.
  6564. * This parameter can be one of the following values:
  6565. * @arg TIM_ICPOLARITY_RISING
  6566. * @arg TIM_ICPOLARITY_FALLING
  6567. * @arg TIM_ICPOLARITY_BOTHEDGE
  6568. * @param TIM_ICSelection specifies the input to be used.
  6569. * This parameter can be one of the following values:
  6570. * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 2 is selected to be connected to IC2.
  6571. * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 2 is selected to be connected to IC1.
  6572. * @arg TIM_ICSELECTION_TRC: TIM Input 2 is selected to be connected to TRC.
  6573. * @param TIM_ICFilter Specifies the Input Capture Filter.
  6574. * This parameter must be a value between 0x00 and 0x0F.
  6575. * @retval None
  6576. * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2
  6577. * (on channel1 path) is used as the input signal. Therefore CCMR1 must be
  6578. * protected against un-initialized filter and polarity values.
  6579. */
  6580. static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  6581. uint32_t TIM_ICFilter)
  6582. {
  6583. uint32_t tmpccmr1;
  6584. uint32_t tmpccer;
  6585. /* Disable the Channel 2: Reset the CC2E Bit */
  6586. tmpccer = TIMx->CCER;
  6587. TIMx->CCER &= ~TIM_CCER_CC2E;
  6588. tmpccmr1 = TIMx->CCMR1;
  6589. /* Select the Input */
  6590. tmpccmr1 &= ~TIM_CCMR1_CC2S;
  6591. tmpccmr1 |= (TIM_ICSelection << 8U);
  6592. /* Set the filter */
  6593. tmpccmr1 &= ~TIM_CCMR1_IC2F;
  6594. tmpccmr1 |= ((TIM_ICFilter << 12U) & TIM_CCMR1_IC2F);
  6595. /* Select the Polarity and set the CC2E Bit */
  6596. tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
  6597. tmpccer |= ((TIM_ICPolarity << 4U) & (TIM_CCER_CC2P | TIM_CCER_CC2NP));
  6598. /* Write to TIMx CCMR1 and CCER registers */
  6599. TIMx->CCMR1 = tmpccmr1 ;
  6600. TIMx->CCER = tmpccer;
  6601. }
  6602. /**
  6603. * @brief Configure the Polarity and Filter for TI2.
  6604. * @param TIMx to select the TIM peripheral.
  6605. * @param TIM_ICPolarity The Input Polarity.
  6606. * This parameter can be one of the following values:
  6607. * @arg TIM_ICPOLARITY_RISING
  6608. * @arg TIM_ICPOLARITY_FALLING
  6609. * @arg TIM_ICPOLARITY_BOTHEDGE
  6610. * @param TIM_ICFilter Specifies the Input Capture Filter.
  6611. * This parameter must be a value between 0x00 and 0x0F.
  6612. * @retval None
  6613. */
  6614. static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
  6615. {
  6616. uint32_t tmpccmr1;
  6617. uint32_t tmpccer;
  6618. /* Disable the Channel 2: Reset the CC2E Bit */
  6619. tmpccer = TIMx->CCER;
  6620. TIMx->CCER &= ~TIM_CCER_CC2E;
  6621. tmpccmr1 = TIMx->CCMR1;
  6622. /* Set the filter */
  6623. tmpccmr1 &= ~TIM_CCMR1_IC2F;
  6624. tmpccmr1 |= (TIM_ICFilter << 12U);
  6625. /* Select the Polarity and set the CC2E Bit */
  6626. tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
  6627. tmpccer |= (TIM_ICPolarity << 4U);
  6628. /* Write to TIMx CCMR1 and CCER registers */
  6629. TIMx->CCMR1 = tmpccmr1 ;
  6630. TIMx->CCER = tmpccer;
  6631. }
  6632. /**
  6633. * @brief Configure the TI3 as Input.
  6634. * @param TIMx to select the TIM peripheral
  6635. * @param TIM_ICPolarity The Input Polarity.
  6636. * This parameter can be one of the following values:
  6637. * @arg TIM_ICPOLARITY_RISING
  6638. * @arg TIM_ICPOLARITY_FALLING
  6639. * @arg TIM_ICPOLARITY_BOTHEDGE
  6640. * @param TIM_ICSelection specifies the input to be used.
  6641. * This parameter can be one of the following values:
  6642. * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 3 is selected to be connected to IC3.
  6643. * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 3 is selected to be connected to IC4.
  6644. * @arg TIM_ICSELECTION_TRC: TIM Input 3 is selected to be connected to TRC.
  6645. * @param TIM_ICFilter Specifies the Input Capture Filter.
  6646. * This parameter must be a value between 0x00 and 0x0F.
  6647. * @retval None
  6648. * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4
  6649. * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
  6650. * protected against un-initialized filter and polarity values.
  6651. */
  6652. static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  6653. uint32_t TIM_ICFilter)
  6654. {
  6655. uint32_t tmpccmr2;
  6656. uint32_t tmpccer;
  6657. /* Disable the Channel 3: Reset the CC3E Bit */
  6658. tmpccer = TIMx->CCER;
  6659. TIMx->CCER &= ~TIM_CCER_CC3E;
  6660. tmpccmr2 = TIMx->CCMR2;
  6661. /* Select the Input */
  6662. tmpccmr2 &= ~TIM_CCMR2_CC3S;
  6663. tmpccmr2 |= TIM_ICSelection;
  6664. /* Set the filter */
  6665. tmpccmr2 &= ~TIM_CCMR2_IC3F;
  6666. tmpccmr2 |= ((TIM_ICFilter << 4U) & TIM_CCMR2_IC3F);
  6667. /* Select the Polarity and set the CC3E Bit */
  6668. tmpccer &= ~(TIM_CCER_CC3P | TIM_CCER_CC3NP);
  6669. tmpccer |= ((TIM_ICPolarity << 8U) & (TIM_CCER_CC3P | TIM_CCER_CC3NP));
  6670. /* Write to TIMx CCMR2 and CCER registers */
  6671. TIMx->CCMR2 = tmpccmr2;
  6672. TIMx->CCER = tmpccer;
  6673. }
  6674. /**
  6675. * @brief Configure the TI4 as Input.
  6676. * @param TIMx to select the TIM peripheral
  6677. * @param TIM_ICPolarity The Input Polarity.
  6678. * This parameter can be one of the following values:
  6679. * @arg TIM_ICPOLARITY_RISING
  6680. * @arg TIM_ICPOLARITY_FALLING
  6681. * @arg TIM_ICPOLARITY_BOTHEDGE
  6682. * @param TIM_ICSelection specifies the input to be used.
  6683. * This parameter can be one of the following values:
  6684. * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 4 is selected to be connected to IC4.
  6685. * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 4 is selected to be connected to IC3.
  6686. * @arg TIM_ICSELECTION_TRC: TIM Input 4 is selected to be connected to TRC.
  6687. * @param TIM_ICFilter Specifies the Input Capture Filter.
  6688. * This parameter must be a value between 0x00 and 0x0F.
  6689. * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3
  6690. * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
  6691. * protected against un-initialized filter and polarity values.
  6692. * @retval None
  6693. */
  6694. static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  6695. uint32_t TIM_ICFilter)
  6696. {
  6697. uint32_t tmpccmr2;
  6698. uint32_t tmpccer;
  6699. /* Disable the Channel 4: Reset the CC4E Bit */
  6700. tmpccer = TIMx->CCER;
  6701. TIMx->CCER &= ~TIM_CCER_CC4E;
  6702. tmpccmr2 = TIMx->CCMR2;
  6703. /* Select the Input */
  6704. tmpccmr2 &= ~TIM_CCMR2_CC4S;
  6705. tmpccmr2 |= (TIM_ICSelection << 8U);
  6706. /* Set the filter */
  6707. tmpccmr2 &= ~TIM_CCMR2_IC4F;
  6708. tmpccmr2 |= ((TIM_ICFilter << 12U) & TIM_CCMR2_IC4F);
  6709. /* Select the Polarity and set the CC4E Bit */
  6710. tmpccer &= ~(TIM_CCER_CC4P | TIM_CCER_CC4NP);
  6711. tmpccer |= ((TIM_ICPolarity << 12U) & (TIM_CCER_CC4P | TIM_CCER_CC4NP));
  6712. /* Write to TIMx CCMR2 and CCER registers */
  6713. TIMx->CCMR2 = tmpccmr2;
  6714. TIMx->CCER = tmpccer ;
  6715. }
  6716. /**
  6717. * @brief Selects the Input Trigger source
  6718. * @param TIMx to select the TIM peripheral
  6719. * @param InputTriggerSource The Input Trigger source.
  6720. * This parameter can be one of the following values:
  6721. * @arg TIM_TS_ITR0: Internal Trigger 0
  6722. * @arg TIM_TS_ITR1: Internal Trigger 1
  6723. * @arg TIM_TS_ITR2: Internal Trigger 2
  6724. * @arg TIM_TS_ITR3: Internal Trigger 3
  6725. * @arg TIM_TS_TI1F_ED: TI1 Edge Detector
  6726. * @arg TIM_TS_TI1FP1: Filtered Timer Input 1
  6727. * @arg TIM_TS_TI2FP2: Filtered Timer Input 2
  6728. * @arg TIM_TS_ETRF: External Trigger input
  6729. * @retval None
  6730. */
  6731. static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource)
  6732. {
  6733. uint32_t tmpsmcr;
  6734. /* Get the TIMx SMCR register value */
  6735. tmpsmcr = TIMx->SMCR;
  6736. /* Reset the TS Bits */
  6737. tmpsmcr &= ~TIM_SMCR_TS;
  6738. /* Set the Input Trigger source and the slave mode*/
  6739. tmpsmcr |= (InputTriggerSource | TIM_SLAVEMODE_EXTERNAL1);
  6740. /* Write to TIMx SMCR */
  6741. TIMx->SMCR = tmpsmcr;
  6742. }
  6743. /**
  6744. * @brief Configures the TIMx External Trigger (ETR).
  6745. * @param TIMx to select the TIM peripheral
  6746. * @param TIM_ExtTRGPrescaler The external Trigger Prescaler.
  6747. * This parameter can be one of the following values:
  6748. * @arg TIM_ETRPRESCALER_DIV1: ETRP Prescaler OFF.
  6749. * @arg TIM_ETRPRESCALER_DIV2: ETRP frequency divided by 2.
  6750. * @arg TIM_ETRPRESCALER_DIV4: ETRP frequency divided by 4.
  6751. * @arg TIM_ETRPRESCALER_DIV8: ETRP frequency divided by 8.
  6752. * @param TIM_ExtTRGPolarity The external Trigger Polarity.
  6753. * This parameter can be one of the following values:
  6754. * @arg TIM_ETRPOLARITY_INVERTED: active low or falling edge active.
  6755. * @arg TIM_ETRPOLARITY_NONINVERTED: active high or rising edge active.
  6756. * @param ExtTRGFilter External Trigger Filter.
  6757. * This parameter must be a value between 0x00 and 0x0F
  6758. * @retval None
  6759. */
  6760. void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler,
  6761. uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter)
  6762. {
  6763. uint32_t tmpsmcr;
  6764. tmpsmcr = TIMx->SMCR;
  6765. /* Reset the ETR Bits */
  6766. tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
  6767. /* Set the Prescaler, the Filter value and the Polarity */
  6768. tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8U)));
  6769. /* Write to TIMx SMCR */
  6770. TIMx->SMCR = tmpsmcr;
  6771. }
  6772. /**
  6773. * @brief Enables or disables the TIM Capture Compare Channel x.
  6774. * @param TIMx to select the TIM peripheral
  6775. * @param Channel specifies the TIM Channel
  6776. * This parameter can be one of the following values:
  6777. * @arg TIM_CHANNEL_1: TIM Channel 1
  6778. * @arg TIM_CHANNEL_2: TIM Channel 2
  6779. * @arg TIM_CHANNEL_3: TIM Channel 3
  6780. * @arg TIM_CHANNEL_4: TIM Channel 4
  6781. * @arg TIM_CHANNEL_5: TIM Channel 5 selected
  6782. * @arg TIM_CHANNEL_6: TIM Channel 6 selected
  6783. * @param ChannelState specifies the TIM Channel CCxE bit new state.
  6784. * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_DISABLE.
  6785. * @retval None
  6786. */
  6787. void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
  6788. {
  6789. uint32_t tmp;
  6790. /* Check the parameters */
  6791. assert_param(IS_TIM_CC1_INSTANCE(TIMx));
  6792. assert_param(IS_TIM_CHANNELS(Channel));
  6793. tmp = TIM_CCER_CC1E << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */
  6794. /* Reset the CCxE Bit */
  6795. TIMx->CCER &= ~tmp;
  6796. /* Set or reset the CCxE Bit */
  6797. TIMx->CCER |= (uint32_t)(ChannelState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */
  6798. }
  6799. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  6800. /**
  6801. * @brief Reset interrupt callbacks to the legacy weak callbacks.
  6802. * @param htim pointer to a TIM_HandleTypeDef structure that contains
  6803. * the configuration information for TIM module.
  6804. * @retval None
  6805. */
  6806. void TIM_ResetCallback(TIM_HandleTypeDef *htim)
  6807. {
  6808. /* Reset the TIM callback to the legacy weak callbacks */
  6809. htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback;
  6810. htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback;
  6811. htim->TriggerCallback = HAL_TIM_TriggerCallback;
  6812. htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback;
  6813. htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback;
  6814. htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback;
  6815. htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback;
  6816. htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback;
  6817. htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback;
  6818. htim->ErrorCallback = HAL_TIM_ErrorCallback;
  6819. htim->CommutationCallback = HAL_TIMEx_CommutCallback;
  6820. htim->CommutationHalfCpltCallback = HAL_TIMEx_CommutHalfCpltCallback;
  6821. htim->BreakCallback = HAL_TIMEx_BreakCallback;
  6822. #if defined(TIM_BDTR_BK2E)
  6823. htim->Break2Callback = HAL_TIMEx_Break2Callback;
  6824. #endif /* TIM_BDTR_BK2E */
  6825. }
  6826. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  6827. /**
  6828. * @}
  6829. */
  6830. #endif /* HAL_TIM_MODULE_ENABLED */
  6831. /**
  6832. * @}
  6833. */
  6834. /**
  6835. * @}
  6836. */