megacode.c 1.0 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385
  1. /**
  2. ******************************************************************************
  3. * @file stm32f10x_tim.h
  4. * @author MCD Application Team
  5. * @version V3.5.0
  6. * @date 11-March-2011
  7. * @brief This file contains all the functions prototypes for the TIM firmware
  8. * library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  20. ******************************************************************************
  21. */
  22. /* Define to prevent recursive inclusion -------------------------------------*/
  23. #ifndef __STM32F10x_TIM_H
  24. #define __STM32F10x_TIM_H
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /* Includes ------------------------------------------------------------------*/
  29. #include "stm32f10x.h"
  30. /** @addtogroup STM32F10x_StdPeriph_Driver
  31. * @{
  32. */
  33. /** @addtogroup TIM
  34. * @{
  35. */
  36. /** @defgroup TIM_Exported_Types
  37. * @{
  38. */
  39. /**
  40. * @brief TIM Time Base Init structure definition
  41. * @note This structure is used with all TIMx except for TIM6 and TIM7.
  42. */
  43. typedef struct
  44. {
  45. uint16_t TIM_Prescaler; /*!< Specifies the prescaler value used to divide the TIM clock.
  46. This parameter can be a number between 0x0000 and 0xFFFF */
  47. uint16_t TIM_CounterMode; /*!< Specifies the counter mode.
  48. This parameter can be a value of @ref TIM_Counter_Mode */
  49. uint16_t TIM_Period; /*!< Specifies the period value to be loaded into the active
  50. Auto-Reload Register at the next update event.
  51. This parameter must be a number between 0x0000 and 0xFFFF. */
  52. uint16_t TIM_ClockDivision; /*!< Specifies the clock division.
  53. This parameter can be a value of @ref TIM_Clock_Division_CKD */
  54. uint8_t TIM_RepetitionCounter; /*!< Specifies the repetition counter value. Each time the RCR downcounter
  55. reaches zero, an update event is generated and counting restarts
  56. from the RCR value (N).
  57. This means in PWM mode that (N+1) corresponds to:
  58. - the number of PWM periods in edge-aligned mode
  59. - the number of half PWM period in center-aligned mode
  60. This parameter must be a number between 0x00 and 0xFF.
  61. @note This parameter is valid only for TIM1 and TIM8. */
  62. } TIM_TimeBaseInitTypeDef;
  63. /**
  64. * @brief TIM Output Compare Init structure definition
  65. */
  66. typedef struct
  67. {
  68. uint16_t TIM_OCMode; /*!< Specifies the TIM mode.
  69. This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */
  70. uint16_t TIM_OutputState; /*!< Specifies the TIM Output Compare state.
  71. This parameter can be a value of @ref TIM_Output_Compare_state */
  72. uint16_t TIM_OutputNState; /*!< Specifies the TIM complementary Output Compare state.
  73. This parameter can be a value of @ref TIM_Output_Compare_N_state
  74. @note This parameter is valid only for TIM1 and TIM8. */
  75. uint16_t TIM_Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
  76. This parameter can be a number between 0x0000 and 0xFFFF */
  77. uint16_t TIM_OCPolarity; /*!< Specifies the output polarity.
  78. This parameter can be a value of @ref TIM_Output_Compare_Polarity */
  79. uint16_t TIM_OCNPolarity; /*!< Specifies the complementary output polarity.
  80. This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
  81. @note This parameter is valid only for TIM1 and TIM8. */
  82. uint16_t TIM_OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  83. This parameter can be a value of @ref TIM_Output_Compare_Idle_State
  84. @note This parameter is valid only for TIM1 and TIM8. */
  85. uint16_t TIM_OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  86. This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
  87. @note This parameter is valid only for TIM1 and TIM8. */
  88. } TIM_OCInitTypeDef;
  89. /**
  90. * @brief TIM Input Capture Init structure definition
  91. */
  92. typedef struct
  93. {
  94. uint16_t TIM_Channel; /*!< Specifies the TIM channel.
  95. This parameter can be a value of @ref TIM_Channel */
  96. uint16_t TIM_ICPolarity; /*!< Specifies the active edge of the input signal.
  97. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  98. uint16_t TIM_ICSelection; /*!< Specifies the input.
  99. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  100. uint16_t TIM_ICPrescaler; /*!< Specifies the Input Capture Prescaler.
  101. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  102. uint16_t TIM_ICFilter; /*!< Specifies the input capture filter.
  103. This parameter can be a number between 0x0 and 0xF */
  104. } TIM_ICInitTypeDef;
  105. /**
  106. * @brief BDTR structure definition
  107. * @note This structure is used only with TIM1 and TIM8.
  108. */
  109. typedef struct
  110. {
  111. uint16_t TIM_OSSRState; /*!< Specifies the Off-State selection used in Run mode.
  112. This parameter can be a value of @ref OSSR_Off_State_Selection_for_Run_mode_state */
  113. uint16_t TIM_OSSIState; /*!< Specifies the Off-State used in Idle state.
  114. This parameter can be a value of @ref OSSI_Off_State_Selection_for_Idle_mode_state */
  115. uint16_t TIM_LOCKLevel; /*!< Specifies the LOCK level parameters.
  116. This parameter can be a value of @ref Lock_level */
  117. uint16_t TIM_DeadTime; /*!< Specifies the delay time between the switching-off and the
  118. switching-on of the outputs.
  119. This parameter can be a number between 0x00 and 0xFF */
  120. uint16_t TIM_Break; /*!< Specifies whether the TIM Break input is enabled or not.
  121. This parameter can be a value of @ref Break_Input_enable_disable */
  122. uint16_t TIM_BreakPolarity; /*!< Specifies the TIM Break Input pin polarity.
  123. This parameter can be a value of @ref Break_Polarity */
  124. uint16_t TIM_AutomaticOutput; /*!< Specifies whether the TIM Automatic Output feature is enabled or not.
  125. This parameter can be a value of @ref TIM_AOE_Bit_Set_Reset */
  126. } TIM_BDTRInitTypeDef;
  127. /** @defgroup TIM_Exported_constants
  128. * @{
  129. */
  130. #define IS_TIM_ALL_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  131. ((PERIPH) == TIM2) || \
  132. ((PERIPH) == TIM3) || \
  133. ((PERIPH) == TIM4) || \
  134. ((PERIPH) == TIM5) || \
  135. ((PERIPH) == TIM6) || \
  136. ((PERIPH) == TIM7) || \
  137. ((PERIPH) == TIM8) || \
  138. ((PERIPH) == TIM9) || \
  139. ((PERIPH) == TIM10)|| \
  140. ((PERIPH) == TIM11)|| \
  141. ((PERIPH) == TIM12)|| \
  142. ((PERIPH) == TIM13)|| \
  143. ((PERIPH) == TIM14)|| \
  144. ((PERIPH) == TIM15)|| \
  145. ((PERIPH) == TIM16)|| \
  146. ((PERIPH) == TIM17))
  147. /* LIST1: TIM 1 and 8 */
  148. #define IS_TIM_LIST1_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  149. ((PERIPH) == TIM8))
  150. /* LIST2: TIM 1, 8, 15 16 and 17 */
  151. #define IS_TIM_LIST2_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  152. ((PERIPH) == TIM8) || \
  153. ((PERIPH) == TIM15)|| \
  154. ((PERIPH) == TIM16)|| \
  155. ((PERIPH) == TIM17))
  156. /* LIST3: TIM 1, 2, 3, 4, 5 and 8 */
  157. #define IS_TIM_LIST3_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  158. ((PERIPH) == TIM2) || \
  159. ((PERIPH) == TIM3) || \
  160. ((PERIPH) == TIM4) || \
  161. ((PERIPH) == TIM5) || \
  162. ((PERIPH) == TIM8))
  163. /* LIST4: TIM 1, 2, 3, 4, 5, 8, 15, 16 and 17 */
  164. #define IS_TIM_LIST4_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  165. ((PERIPH) == TIM2) || \
  166. ((PERIPH) == TIM3) || \
  167. ((PERIPH) == TIM4) || \
  168. ((PERIPH) == TIM5) || \
  169. ((PERIPH) == TIM8) || \
  170. ((PERIPH) == TIM15)|| \
  171. ((PERIPH) == TIM16)|| \
  172. ((PERIPH) == TIM17))
  173. /* LIST5: TIM 1, 2, 3, 4, 5, 8 and 15 */
  174. #define IS_TIM_LIST5_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  175. ((PERIPH) == TIM2) || \
  176. ((PERIPH) == TIM3) || \
  177. ((PERIPH) == TIM4) || \
  178. ((PERIPH) == TIM5) || \
  179. ((PERIPH) == TIM8) || \
  180. ((PERIPH) == TIM15))
  181. /* LIST6: TIM 1, 2, 3, 4, 5, 8, 9, 12 and 15 */
  182. #define IS_TIM_LIST6_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  183. ((PERIPH) == TIM2) || \
  184. ((PERIPH) == TIM3) || \
  185. ((PERIPH) == TIM4) || \
  186. ((PERIPH) == TIM5) || \
  187. ((PERIPH) == TIM8) || \
  188. ((PERIPH) == TIM9) || \
  189. ((PERIPH) == TIM12)|| \
  190. ((PERIPH) == TIM15))
  191. /* LIST7: TIM 1, 2, 3, 4, 5, 6, 7, 8, 9, 12 and 15 */
  192. #define IS_TIM_LIST7_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  193. ((PERIPH) == TIM2) || \
  194. ((PERIPH) == TIM3) || \
  195. ((PERIPH) == TIM4) || \
  196. ((PERIPH) == TIM5) || \
  197. ((PERIPH) == TIM6) || \
  198. ((PERIPH) == TIM7) || \
  199. ((PERIPH) == TIM8) || \
  200. ((PERIPH) == TIM9) || \
  201. ((PERIPH) == TIM12)|| \
  202. ((PERIPH) == TIM15))
  203. /* LIST8: TIM 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16 and 17 */
  204. #define IS_TIM_LIST8_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  205. ((PERIPH) == TIM2) || \
  206. ((PERIPH) == TIM3) || \
  207. ((PERIPH) == TIM4) || \
  208. ((PERIPH) == TIM5) || \
  209. ((PERIPH) == TIM8) || \
  210. ((PERIPH) == TIM9) || \
  211. ((PERIPH) == TIM10)|| \
  212. ((PERIPH) == TIM11)|| \
  213. ((PERIPH) == TIM12)|| \
  214. ((PERIPH) == TIM13)|| \
  215. ((PERIPH) == TIM14)|| \
  216. ((PERIPH) == TIM15)|| \
  217. ((PERIPH) == TIM16)|| \
  218. ((PERIPH) == TIM17))
  219. /* LIST9: TIM 1, 2, 3, 4, 5, 6, 7, 8, 15, 16, and 17 */
  220. #define IS_TIM_LIST9_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  221. ((PERIPH) == TIM2) || \
  222. ((PERIPH) == TIM3) || \
  223. ((PERIPH) == TIM4) || \
  224. ((PERIPH) == TIM5) || \
  225. ((PERIPH) == TIM6) || \
  226. ((PERIPH) == TIM7) || \
  227. ((PERIPH) == TIM8) || \
  228. ((PERIPH) == TIM15)|| \
  229. ((PERIPH) == TIM16)|| \
  230. ((PERIPH) == TIM17))
  231. /**
  232. * @}
  233. */
  234. /** @defgroup TIM_Output_Compare_and_PWM_modes
  235. * @{
  236. */
  237. #define TIM_OCMode_Timing ((uint16_t)0x0000)
  238. #define TIM_OCMode_Active ((uint16_t)0x0010)
  239. #define TIM_OCMode_Inactive ((uint16_t)0x0020)
  240. #define TIM_OCMode_Toggle ((uint16_t)0x0030)
  241. #define TIM_OCMode_PWM1 ((uint16_t)0x0060)
  242. #define TIM_OCMode_PWM2 ((uint16_t)0x0070)
  243. #define IS_TIM_OC_MODE(MODE) (((MODE) == TIM_OCMode_Timing) || \
  244. ((MODE) == TIM_OCMode_Active) || \
  245. ((MODE) == TIM_OCMode_Inactive) || \
  246. ((MODE) == TIM_OCMode_Toggle)|| \
  247. ((MODE) == TIM_OCMode_PWM1) || \
  248. ((MODE) == TIM_OCMode_PWM2))
  249. #define IS_TIM_OCM(MODE) (((MODE) == TIM_OCMode_Timing) || \
  250. ((MODE) == TIM_OCMode_Active) || \
  251. ((MODE) == TIM_OCMode_Inactive) || \
  252. ((MODE) == TIM_OCMode_Toggle)|| \
  253. ((MODE) == TIM_OCMode_PWM1) || \
  254. ((MODE) == TIM_OCMode_PWM2) || \
  255. ((MODE) == TIM_ForcedAction_Active) || \
  256. ((MODE) == TIM_ForcedAction_InActive))
  257. /**
  258. * @}
  259. */
  260. /** @defgroup TIM_One_Pulse_Mode
  261. * @{
  262. */
  263. #define TIM_OPMode_Single ((uint16_t)0x0008)
  264. #define TIM_OPMode_Repetitive ((uint16_t)0x0000)
  265. #define IS_TIM_OPM_MODE(MODE) (((MODE) == TIM_OPMode_Single) || \
  266. ((MODE) == TIM_OPMode_Repetitive))
  267. /**
  268. * @}
  269. */
  270. /** @defgroup TIM_Channel
  271. * @{
  272. */
  273. #define TIM_Channel_1 ((uint16_t)0x0000)
  274. #define TIM_Channel_2 ((uint16_t)0x0004)
  275. #define TIM_Channel_3 ((uint16_t)0x0008)
  276. #define TIM_Channel_4 ((uint16_t)0x000C)
  277. #define IS_TIM_CHANNEL(CHANNEL) (((CHANNEL) == TIM_Channel_1) || \
  278. ((CHANNEL) == TIM_Channel_2) || \
  279. ((CHANNEL) == TIM_Channel_3) || \
  280. ((CHANNEL) == TIM_Channel_4))
  281. #define IS_TIM_PWMI_CHANNEL(CHANNEL) (((CHANNEL) == TIM_Channel_1) || \
  282. ((CHANNEL) == TIM_Channel_2))
  283. #define IS_TIM_COMPLEMENTARY_CHANNEL(CHANNEL) (((CHANNEL) == TIM_Channel_1) || \
  284. ((CHANNEL) == TIM_Channel_2) || \
  285. ((CHANNEL) == TIM_Channel_3))
  286. /**
  287. * @}
  288. */
  289. /** @defgroup TIM_Clock_Division_CKD
  290. * @{
  291. */
  292. #define TIM_CKD_DIV1 ((uint16_t)0x0000)
  293. #define TIM_CKD_DIV2 ((uint16_t)0x0100)
  294. #define TIM_CKD_DIV4 ((uint16_t)0x0200)
  295. #define IS_TIM_CKD_DIV(DIV) (((DIV) == TIM_CKD_DIV1) || \
  296. ((DIV) == TIM_CKD_DIV2) || \
  297. ((DIV) == TIM_CKD_DIV4))
  298. /**
  299. * @}
  300. */
  301. /** @defgroup TIM_Counter_Mode
  302. * @{
  303. */
  304. #define TIM_CounterMode_Up ((uint16_t)0x0000)
  305. #define TIM_CounterMode_Down ((uint16_t)0x0010)
  306. #define TIM_CounterMode_CenterAligned1 ((uint16_t)0x0020)
  307. #define TIM_CounterMode_CenterAligned2 ((uint16_t)0x0040)
  308. #define TIM_CounterMode_CenterAligned3 ((uint16_t)0x0060)
  309. #define IS_TIM_COUNTER_MODE(MODE) (((MODE) == TIM_CounterMode_Up) || \
  310. ((MODE) == TIM_CounterMode_Down) || \
  311. ((MODE) == TIM_CounterMode_CenterAligned1) || \
  312. ((MODE) == TIM_CounterMode_CenterAligned2) || \
  313. ((MODE) == TIM_CounterMode_CenterAligned3))
  314. /**
  315. * @}
  316. */
  317. /** @defgroup TIM_Output_Compare_Polarity
  318. * @{
  319. */
  320. #define TIM_OCPolarity_High ((uint16_t)0x0000)
  321. #define TIM_OCPolarity_Low ((uint16_t)0x0002)
  322. #define IS_TIM_OC_POLARITY(POLARITY) (((POLARITY) == TIM_OCPolarity_High) || \
  323. ((POLARITY) == TIM_OCPolarity_Low))
  324. /**
  325. * @}
  326. */
  327. /** @defgroup TIM_Output_Compare_N_Polarity
  328. * @{
  329. */
  330. #define TIM_OCNPolarity_High ((uint16_t)0x0000)
  331. #define TIM_OCNPolarity_Low ((uint16_t)0x0008)
  332. #define IS_TIM_OCN_POLARITY(POLARITY) (((POLARITY) == TIM_OCNPolarity_High) || \
  333. ((POLARITY) == TIM_OCNPolarity_Low))
  334. /**
  335. * @}
  336. */
  337. /** @defgroup TIM_Output_Compare_state
  338. * @{
  339. */
  340. #define TIM_OutputState_Disable ((uint16_t)0x0000)
  341. #define TIM_OutputState_Enable ((uint16_t)0x0001)
  342. #define IS_TIM_OUTPUT_STATE(STATE) (((STATE) == TIM_OutputState_Disable) || \
  343. ((STATE) == TIM_OutputState_Enable))
  344. /**
  345. * @}
  346. */
  347. /** @defgroup TIM_Output_Compare_N_state
  348. * @{
  349. */
  350. #define TIM_OutputNState_Disable ((uint16_t)0x0000)
  351. #define TIM_OutputNState_Enable ((uint16_t)0x0004)
  352. #define IS_TIM_OUTPUTN_STATE(STATE) (((STATE) == TIM_OutputNState_Disable) || \
  353. ((STATE) == TIM_OutputNState_Enable))
  354. /**
  355. * @}
  356. */
  357. /** @defgroup TIM_Capture_Compare_state
  358. * @{
  359. */
  360. #define TIM_CCx_Enable ((uint16_t)0x0001)
  361. #define TIM_CCx_Disable ((uint16_t)0x0000)
  362. #define IS_TIM_CCX(CCX) (((CCX) == TIM_CCx_Enable) || \
  363. ((CCX) == TIM_CCx_Disable))
  364. /**
  365. * @}
  366. */
  367. /** @defgroup TIM_Capture_Compare_N_state
  368. * @{
  369. */
  370. #define TIM_CCxN_Enable ((uint16_t)0x0004)
  371. #define TIM_CCxN_Disable ((uint16_t)0x0000)
  372. #define IS_TIM_CCXN(CCXN) (((CCXN) == TIM_CCxN_Enable) || \
  373. ((CCXN) == TIM_CCxN_Disable))
  374. /**
  375. * @}
  376. */
  377. /** @defgroup Break_Input_enable_disable
  378. * @{
  379. */
  380. #define TIM_Break_Enable ((uint16_t)0x1000)
  381. #define TIM_Break_Disable ((uint16_t)0x0000)
  382. #define IS_TIM_BREAK_STATE(STATE) (((STATE) == TIM_Break_Enable) || \
  383. ((STATE) == TIM_Break_Disable))
  384. /**
  385. * @}
  386. */
  387. /** @defgroup Break_Polarity
  388. * @{
  389. */
  390. #define TIM_BreakPolarity_Low ((uint16_t)0x0000)
  391. #define TIM_BreakPolarity_High ((uint16_t)0x2000)
  392. #define IS_TIM_BREAK_POLARITY(POLARITY) (((POLARITY) == TIM_BreakPolarity_Low) || \
  393. ((POLARITY) == TIM_BreakPolarity_High))
  394. /**
  395. * @}
  396. */
  397. /** @defgroup TIM_AOE_Bit_Set_Reset
  398. * @{
  399. */
  400. #define TIM_AutomaticOutput_Enable ((uint16_t)0x4000)
  401. #define TIM_AutomaticOutput_Disable ((uint16_t)0x0000)
  402. #define IS_TIM_AUTOMATIC_OUTPUT_STATE(STATE) (((STATE) == TIM_AutomaticOutput_Enable) || \
  403. ((STATE) == TIM_AutomaticOutput_Disable))
  404. /**
  405. * @}
  406. */
  407. /** @defgroup Lock_level
  408. * @{
  409. */
  410. #define TIM_LOCKLevel_OFF ((uint16_t)0x0000)
  411. #define TIM_LOCKLevel_1 ((uint16_t)0x0100)
  412. #define TIM_LOCKLevel_2 ((uint16_t)0x0200)
  413. #define TIM_LOCKLevel_3 ((uint16_t)0x0300)
  414. #define IS_TIM_LOCK_LEVEL(LEVEL) (((LEVEL) == TIM_LOCKLevel_OFF) || \
  415. ((LEVEL) == TIM_LOCKLevel_1) || \
  416. ((LEVEL) == TIM_LOCKLevel_2) || \
  417. ((LEVEL) == TIM_LOCKLevel_3))
  418. /**
  419. * @}
  420. */
  421. /** @defgroup OSSI_Off_State_Selection_for_Idle_mode_state
  422. * @{
  423. */
  424. #define TIM_OSSIState_Enable ((uint16_t)0x0400)
  425. #define TIM_OSSIState_Disable ((uint16_t)0x0000)
  426. #define IS_TIM_OSSI_STATE(STATE) (((STATE) == TIM_OSSIState_Enable) || \
  427. ((STATE) == TIM_OSSIState_Disable))
  428. /**
  429. * @}
  430. */
  431. /** @defgroup OSSR_Off_State_Selection_for_Run_mode_state
  432. * @{
  433. */
  434. #define TIM_OSSRState_Enable ((uint16_t)0x0800)
  435. #define TIM_OSSRState_Disable ((uint16_t)0x0000)
  436. #define IS_TIM_OSSR_STATE(STATE) (((STATE) == TIM_OSSRState_Enable) || \
  437. ((STATE) == TIM_OSSRState_Disable))
  438. /**
  439. * @}
  440. */
  441. /** @defgroup TIM_Output_Compare_Idle_State
  442. * @{
  443. */
  444. #define TIM_OCIdleState_Set ((uint16_t)0x0100)
  445. #define TIM_OCIdleState_Reset ((uint16_t)0x0000)
  446. #define IS_TIM_OCIDLE_STATE(STATE) (((STATE) == TIM_OCIdleState_Set) || \
  447. ((STATE) == TIM_OCIdleState_Reset))
  448. /**
  449. * @}
  450. */
  451. /** @defgroup TIM_Output_Compare_N_Idle_State
  452. * @{
  453. */
  454. #define TIM_OCNIdleState_Set ((uint16_t)0x0200)
  455. #define TIM_OCNIdleState_Reset ((uint16_t)0x0000)
  456. #define IS_TIM_OCNIDLE_STATE(STATE) (((STATE) == TIM_OCNIdleState_Set) || \
  457. ((STATE) == TIM_OCNIdleState_Reset))
  458. /**
  459. * @}
  460. */
  461. /** @defgroup TIM_Input_Capture_Polarity
  462. * @{
  463. */
  464. #define TIM_ICPolarity_Rising ((uint16_t)0x0000)
  465. #define TIM_ICPolarity_Falling ((uint16_t)0x0002)
  466. #define TIM_ICPolarity_BothEdge ((uint16_t)0x000A)
  467. #define IS_TIM_IC_POLARITY(POLARITY) (((POLARITY) == TIM_ICPolarity_Rising) || \
  468. ((POLARITY) == TIM_ICPolarity_Falling))
  469. #define IS_TIM_IC_POLARITY_LITE(POLARITY) (((POLARITY) == TIM_ICPolarity_Rising) || \
  470. ((POLARITY) == TIM_ICPolarity_Falling)|| \
  471. ((POLARITY) == TIM_ICPolarity_BothEdge))
  472. /**
  473. * @}
  474. */
  475. /** @defgroup TIM_Input_Capture_Selection
  476. * @{
  477. */
  478. #define TIM_ICSelection_DirectTI ((uint16_t)0x0001) /*!< TIM Input 1, 2, 3 or 4 is selected to be
  479. connected to IC1, IC2, IC3 or IC4, respectively */
  480. #define TIM_ICSelection_IndirectTI ((uint16_t)0x0002) /*!< TIM Input 1, 2, 3 or 4 is selected to be
  481. connected to IC2, IC1, IC4 or IC3, respectively. */
  482. #define TIM_ICSelection_TRC ((uint16_t)0x0003) /*!< TIM Input 1, 2, 3 or 4 is selected to be connected to TRC. */
  483. #define IS_TIM_IC_SELECTION(SELECTION) (((SELECTION) == TIM_ICSelection_DirectTI) || \
  484. ((SELECTION) == TIM_ICSelection_IndirectTI) || \
  485. ((SELECTION) == TIM_ICSelection_TRC))
  486. /**
  487. * @}
  488. */
  489. /** @defgroup TIM_Input_Capture_Prescaler
  490. * @{
  491. */
  492. #define TIM_ICPSC_DIV1 ((uint16_t)0x0000) /*!< Capture performed each time an edge is detected on the capture input. */
  493. #define TIM_ICPSC_DIV2 ((uint16_t)0x0004) /*!< Capture performed once every 2 events. */
  494. #define TIM_ICPSC_DIV4 ((uint16_t)0x0008) /*!< Capture performed once every 4 events. */
  495. #define TIM_ICPSC_DIV8 ((uint16_t)0x000C) /*!< Capture performed once every 8 events. */
  496. #define IS_TIM_IC_PRESCALER(PRESCALER) (((PRESCALER) == TIM_ICPSC_DIV1) || \
  497. ((PRESCALER) == TIM_ICPSC_DIV2) || \
  498. ((PRESCALER) == TIM_ICPSC_DIV4) || \
  499. ((PRESCALER) == TIM_ICPSC_DIV8))
  500. /**
  501. * @}
  502. */
  503. /** @defgroup TIM_interrupt_sources
  504. * @{
  505. */
  506. #define TIM_IT_Update ((uint16_t)0x0001)
  507. #define TIM_IT_CC1 ((uint16_t)0x0002)
  508. #define TIM_IT_CC2 ((uint16_t)0x0004)
  509. #define TIM_IT_CC3 ((uint16_t)0x0008)
  510. #define TIM_IT_CC4 ((uint16_t)0x0010)
  511. #define TIM_IT_COM ((uint16_t)0x0020)
  512. #define TIM_IT_Trigger ((uint16_t)0x0040)
  513. #define TIM_IT_Break ((uint16_t)0x0080)
  514. #define IS_TIM_IT(IT) ((((IT) & (uint16_t)0xFF00) == 0x0000) && ((IT) != 0x0000))
  515. #define IS_TIM_GET_IT(IT) (((IT) == TIM_IT_Update) || \
  516. ((IT) == TIM_IT_CC1) || \
  517. ((IT) == TIM_IT_CC2) || \
  518. ((IT) == TIM_IT_CC3) || \
  519. ((IT) == TIM_IT_CC4) || \
  520. ((IT) == TIM_IT_COM) || \
  521. ((IT) == TIM_IT_Trigger) || \
  522. ((IT) == TIM_IT_Break))
  523. /**
  524. * @}
  525. */
  526. /** @defgroup TIM_DMA_Base_address
  527. * @{
  528. */
  529. #define TIM_DMABase_CR1 ((uint16_t)0x0000)
  530. #define TIM_DMABase_CR2 ((uint16_t)0x0001)
  531. #define TIM_DMABase_SMCR ((uint16_t)0x0002)
  532. #define TIM_DMABase_DIER ((uint16_t)0x0003)
  533. #define TIM_DMABase_SR ((uint16_t)0x0004)
  534. #define TIM_DMABase_EGR ((uint16_t)0x0005)
  535. #define TIM_DMABase_CCMR1 ((uint16_t)0x0006)
  536. #define TIM_DMABase_CCMR2 ((uint16_t)0x0007)
  537. #define TIM_DMABase_CCER ((uint16_t)0x0008)
  538. #define TIM_DMABase_CNT ((uint16_t)0x0009)
  539. #define TIM_DMABase_PSC ((uint16_t)0x000A)
  540. #define TIM_DMABase_ARR ((uint16_t)0x000B)
  541. #define TIM_DMABase_RCR ((uint16_t)0x000C)
  542. #define TIM_DMABase_CCR1 ((uint16_t)0x000D)
  543. #define TIM_DMABase_CCR2 ((uint16_t)0x000E)
  544. #define TIM_DMABase_CCR3 ((uint16_t)0x000F)
  545. #define TIM_DMABase_CCR4 ((uint16_t)0x0010)
  546. #define TIM_DMABase_BDTR ((uint16_t)0x0011)
  547. #define TIM_DMABase_DCR ((uint16_t)0x0012)
  548. #define IS_TIM_DMA_BASE(BASE) (((BASE) == TIM_DMABase_CR1) || \
  549. ((BASE) == TIM_DMABase_CR2) || \
  550. ((BASE) == TIM_DMABase_SMCR) || \
  551. ((BASE) == TIM_DMABase_DIER) || \
  552. ((BASE) == TIM_DMABase_SR) || \
  553. ((BASE) == TIM_DMABase_EGR) || \
  554. ((BASE) == TIM_DMABase_CCMR1) || \
  555. ((BASE) == TIM_DMABase_CCMR2) || \
  556. ((BASE) == TIM_DMABase_CCER) || \
  557. ((BASE) == TIM_DMABase_CNT) || \
  558. ((BASE) == TIM_DMABase_PSC) || \
  559. ((BASE) == TIM_DMABase_ARR) || \
  560. ((BASE) == TIM_DMABase_RCR) || \
  561. ((BASE) == TIM_DMABase_CCR1) || \
  562. ((BASE) == TIM_DMABase_CCR2) || \
  563. ((BASE) == TIM_DMABase_CCR3) || \
  564. ((BASE) == TIM_DMABase_CCR4) || \
  565. ((BASE) == TIM_DMABase_BDTR) || \
  566. ((BASE) == TIM_DMABase_DCR))
  567. /**
  568. * @}
  569. */
  570. /** @defgroup TIM_DMA_Burst_Length
  571. * @{
  572. */
  573. #define TIM_DMABurstLength_1Transfer ((uint16_t)0x0000)
  574. #define TIM_DMABurstLength_2Transfers ((uint16_t)0x0100)
  575. #define TIM_DMABurstLength_3Transfers ((uint16_t)0x0200)
  576. #define TIM_DMABurstLength_4Transfers ((uint16_t)0x0300)
  577. #define TIM_DMABurstLength_5Transfers ((uint16_t)0x0400)
  578. #define TIM_DMABurstLength_6Transfers ((uint16_t)0x0500)
  579. #define TIM_DMABurstLength_7Transfers ((uint16_t)0x0600)
  580. #define TIM_DMABurstLength_8Transfers ((uint16_t)0x0700)
  581. #define TIM_DMABurstLength_9Transfers ((uint16_t)0x0800)
  582. #define TIM_DMABurstLength_10Transfers ((uint16_t)0x0900)
  583. #define TIM_DMABurstLength_11Transfers ((uint16_t)0x0A00)
  584. #define TIM_DMABurstLength_12Transfers ((uint16_t)0x0B00)
  585. #define TIM_DMABurstLength_13Transfers ((uint16_t)0x0C00)
  586. #define TIM_DMABurstLength_14Transfers ((uint16_t)0x0D00)
  587. #define TIM_DMABurstLength_15Transfers ((uint16_t)0x0E00)
  588. #define TIM_DMABurstLength_16Transfers ((uint16_t)0x0F00)
  589. #define TIM_DMABurstLength_17Transfers ((uint16_t)0x1000)
  590. #define TIM_DMABurstLength_18Transfers ((uint16_t)0x1100)
  591. #define IS_TIM_DMA_LENGTH(LENGTH) (((LENGTH) == TIM_DMABurstLength_1Transfer) || \
  592. ((LENGTH) == TIM_DMABurstLength_2Transfers) || \
  593. ((LENGTH) == TIM_DMABurstLength_3Transfers) || \
  594. ((LENGTH) == TIM_DMABurstLength_4Transfers) || \
  595. ((LENGTH) == TIM_DMABurstLength_5Transfers) || \
  596. ((LENGTH) == TIM_DMABurstLength_6Transfers) || \
  597. ((LENGTH) == TIM_DMABurstLength_7Transfers) || \
  598. ((LENGTH) == TIM_DMABurstLength_8Transfers) || \
  599. ((LENGTH) == TIM_DMABurstLength_9Transfers) || \
  600. ((LENGTH) == TIM_DMABurstLength_10Transfers) || \
  601. ((LENGTH) == TIM_DMABurstLength_11Transfers) || \
  602. ((LENGTH) == TIM_DMABurstLength_12Transfers) || \
  603. ((LENGTH) == TIM_DMABurstLength_13Transfers) || \
  604. ((LENGTH) == TIM_DMABurstLength_14Transfers) || \
  605. ((LENGTH) == TIM_DMABurstLength_15Transfers) || \
  606. ((LENGTH) == TIM_DMABurstLength_16Transfers) || \
  607. ((LENGTH) == TIM_DMABurstLength_17Transfers) || \
  608. ((LENGTH) == TIM_DMABurstLength_18Transfers))
  609. /**
  610. * @}
  611. */
  612. /** @defgroup TIM_DMA_sources
  613. * @{
  614. */
  615. #define TIM_DMA_Update ((uint16_t)0x0100)
  616. #define TIM_DMA_CC1 ((uint16_t)0x0200)
  617. #define TIM_DMA_CC2 ((uint16_t)0x0400)
  618. #define TIM_DMA_CC3 ((uint16_t)0x0800)
  619. #define TIM_DMA_CC4 ((uint16_t)0x1000)
  620. #define TIM_DMA_COM ((uint16_t)0x2000)
  621. #define TIM_DMA_Trigger ((uint16_t)0x4000)
  622. #define IS_TIM_DMA_SOURCE(SOURCE) ((((SOURCE) & (uint16_t)0x80FF) == 0x0000) && ((SOURCE) != 0x0000))
  623. /**
  624. * @}
  625. */
  626. /** @defgroup TIM_External_Trigger_Prescaler
  627. * @{
  628. */
  629. #define TIM_ExtTRGPSC_OFF ((uint16_t)0x0000)
  630. #define TIM_ExtTRGPSC_DIV2 ((uint16_t)0x1000)
  631. #define TIM_ExtTRGPSC_DIV4 ((uint16_t)0x2000)
  632. #define TIM_ExtTRGPSC_DIV8 ((uint16_t)0x3000)
  633. #define IS_TIM_EXT_PRESCALER(PRESCALER) (((PRESCALER) == TIM_ExtTRGPSC_OFF) || \
  634. ((PRESCALER) == TIM_ExtTRGPSC_DIV2) || \
  635. ((PRESCALER) == TIM_ExtTRGPSC_DIV4) || \
  636. ((PRESCALER) == TIM_ExtTRGPSC_DIV8))
  637. /**
  638. * @}
  639. */
  640. /** @defgroup TIM_Internal_Trigger_Selection
  641. * @{
  642. */
  643. #define TIM_TS_ITR0 ((uint16_t)0x0000)
  644. #define TIM_TS_ITR1 ((uint16_t)0x0010)
  645. #define TIM_TS_ITR2 ((uint16_t)0x0020)
  646. #define TIM_TS_ITR3 ((uint16_t)0x0030)
  647. #define TIM_TS_TI1F_ED ((uint16_t)0x0040)
  648. #define TIM_TS_TI1FP1 ((uint16_t)0x0050)
  649. #define TIM_TS_TI2FP2 ((uint16_t)0x0060)
  650. #define TIM_TS_ETRF ((uint16_t)0x0070)
  651. #define IS_TIM_TRIGGER_SELECTION(SELECTION) (((SELECTION) == TIM_TS_ITR0) || \
  652. ((SELECTION) == TIM_TS_ITR1) || \
  653. ((SELECTION) == TIM_TS_ITR2) || \
  654. ((SELECTION) == TIM_TS_ITR3) || \
  655. ((SELECTION) == TIM_TS_TI1F_ED) || \
  656. ((SELECTION) == TIM_TS_TI1FP1) || \
  657. ((SELECTION) == TIM_TS_TI2FP2) || \
  658. ((SELECTION) == TIM_TS_ETRF))
  659. #define IS_TIM_INTERNAL_TRIGGER_SELECTION(SELECTION) (((SELECTION) == TIM_TS_ITR0) || \
  660. ((SELECTION) == TIM_TS_ITR1) || \
  661. ((SELECTION) == TIM_TS_ITR2) || \
  662. ((SELECTION) == TIM_TS_ITR3))
  663. /**
  664. * @}
  665. */
  666. /** @defgroup TIM_TIx_External_Clock_Source
  667. * @{
  668. */
  669. #define TIM_TIxExternalCLK1Source_TI1 ((uint16_t)0x0050)
  670. #define TIM_TIxExternalCLK1Source_TI2 ((uint16_t)0x0060)
  671. #define TIM_TIxExternalCLK1Source_TI1ED ((uint16_t)0x0040)
  672. #define IS_TIM_TIXCLK_SOURCE(SOURCE) (((SOURCE) == TIM_TIxExternalCLK1Source_TI1) || \
  673. ((SOURCE) == TIM_TIxExternalCLK1Source_TI2) || \
  674. ((SOURCE) == TIM_TIxExternalCLK1Source_TI1ED))
  675. /**
  676. * @}
  677. */
  678. /** @defgroup TIM_External_Trigger_Polarity
  679. * @{
  680. */
  681. #define TIM_ExtTRGPolarity_Inverted ((uint16_t)0x8000)
  682. #define TIM_ExtTRGPolarity_NonInverted ((uint16_t)0x0000)
  683. #define IS_TIM_EXT_POLARITY(POLARITY) (((POLARITY) == TIM_ExtTRGPolarity_Inverted) || \
  684. ((POLARITY) == TIM_ExtTRGPolarity_NonInverted))
  685. /**
  686. * @}
  687. */
  688. /** @defgroup TIM_Prescaler_Reload_Mode
  689. * @{
  690. */
  691. #define TIM_PSCReloadMode_Update ((uint16_t)0x0000)
  692. #define TIM_PSCReloadMode_Immediate ((uint16_t)0x0001)
  693. #define IS_TIM_PRESCALER_RELOAD(RELOAD) (((RELOAD) == TIM_PSCReloadMode_Update) || \
  694. ((RELOAD) == TIM_PSCReloadMode_Immediate))
  695. /**
  696. * @}
  697. */
  698. /** @defgroup TIM_Forced_Action
  699. * @{
  700. */
  701. #define TIM_ForcedAction_Active ((uint16_t)0x0050)
  702. #define TIM_ForcedAction_InActive ((uint16_t)0x0040)
  703. #define IS_TIM_FORCED_ACTION(ACTION) (((ACTION) == TIM_ForcedAction_Active) || \
  704. ((ACTION) == TIM_ForcedAction_InActive))
  705. /**
  706. * @}
  707. */
  708. /** @defgroup TIM_Encoder_Mode
  709. * @{
  710. */
  711. #define TIM_EncoderMode_TI1 ((uint16_t)0x0001)
  712. #define TIM_EncoderMode_TI2 ((uint16_t)0x0002)
  713. #define TIM_EncoderMode_TI12 ((uint16_t)0x0003)
  714. #define IS_TIM_ENCODER_MODE(MODE) (((MODE) == TIM_EncoderMode_TI1) || \
  715. ((MODE) == TIM_EncoderMode_TI2) || \
  716. ((MODE) == TIM_EncoderMode_TI12))
  717. /**
  718. * @}
  719. */
  720. /** @defgroup TIM_Event_Source
  721. * @{
  722. */
  723. #define TIM_EventSource_Update ((uint16_t)0x0001)
  724. #define TIM_EventSource_CC1 ((uint16_t)0x0002)
  725. #define TIM_EventSource_CC2 ((uint16_t)0x0004)
  726. #define TIM_EventSource_CC3 ((uint16_t)0x0008)
  727. #define TIM_EventSource_CC4 ((uint16_t)0x0010)
  728. #define TIM_EventSource_COM ((uint16_t)0x0020)
  729. #define TIM_EventSource_Trigger ((uint16_t)0x0040)
  730. #define TIM_EventSource_Break ((uint16_t)0x0080)
  731. #define IS_TIM_EVENT_SOURCE(SOURCE) ((((SOURCE) & (uint16_t)0xFF00) == 0x0000) && ((SOURCE) != 0x0000))
  732. /**
  733. * @}
  734. */
  735. /** @defgroup TIM_Update_Source
  736. * @{
  737. */
  738. #define TIM_UpdateSource_Global ((uint16_t)0x0000) /*!< Source of update is the counter overflow/underflow
  739. or the setting of UG bit, or an update generation
  740. through the slave mode controller. */
  741. #define TIM_UpdateSource_Regular ((uint16_t)0x0001) /*!< Source of update is counter overflow/underflow. */
  742. #define IS_TIM_UPDATE_SOURCE(SOURCE) (((SOURCE) == TIM_UpdateSource_Global) || \
  743. ((SOURCE) == TIM_UpdateSource_Regular))
  744. /**
  745. * @}
  746. */
  747. /** @defgroup TIM_Output_Compare_Preload_State
  748. * @{
  749. */
  750. #define TIM_OCPreload_Enable ((uint16_t)0x0008)
  751. #define TIM_OCPreload_Disable ((uint16_t)0x0000)
  752. #define IS_TIM_OCPRELOAD_STATE(STATE) (((STATE) == TIM_OCPreload_Enable) || \
  753. ((STATE) == TIM_OCPreload_Disable))
  754. /**
  755. * @}
  756. */
  757. /** @defgroup TIM_Output_Compare_Fast_State
  758. * @{
  759. */
  760. #define TIM_OCFast_Enable ((uint16_t)0x0004)
  761. #define TIM_OCFast_Disable ((uint16_t)0x0000)
  762. #define IS_TIM_OCFAST_STATE(STATE) (((STATE) == TIM_OCFast_Enable) || \
  763. ((STATE) == TIM_OCFast_Disable))
  764. /**
  765. * @}
  766. */
  767. /** @defgroup TIM_Output_Compare_Clear_State
  768. * @{
  769. */
  770. #define TIM_OCClear_Enable ((uint16_t)0x0080)
  771. #define TIM_OCClear_Disable ((uint16_t)0x0000)
  772. #define IS_TIM_OCCLEAR_STATE(STATE) (((STATE) == TIM_OCClear_Enable) || \
  773. ((STATE) == TIM_OCClear_Disable))
  774. /**
  775. * @}
  776. */
  777. /** @defgroup TIM_Trigger_Output_Source
  778. * @{
  779. */
  780. #define TIM_TRGOSource_Reset ((uint16_t)0x0000)
  781. #define TIM_TRGOSource_Enable ((uint16_t)0x0010)
  782. #define TIM_TRGOSource_Update ((uint16_t)0x0020)
  783. #define TIM_TRGOSource_OC1 ((uint16_t)0x0030)
  784. #define TIM_TRGOSource_OC1Ref ((uint16_t)0x0040)
  785. #define TIM_TRGOSource_OC2Ref ((uint16_t)0x0050)
  786. #define TIM_TRGOSource_OC3Ref ((uint16_t)0x0060)
  787. #define TIM_TRGOSource_OC4Ref ((uint16_t)0x0070)
  788. #define IS_TIM_TRGO_SOURCE(SOURCE) (((SOURCE) == TIM_TRGOSource_Reset) || \
  789. ((SOURCE) == TIM_TRGOSource_Enable) || \
  790. ((SOURCE) == TIM_TRGOSource_Update) || \
  791. ((SOURCE) == TIM_TRGOSource_OC1) || \
  792. ((SOURCE) == TIM_TRGOSource_OC1Ref) || \
  793. ((SOURCE) == TIM_TRGOSource_OC2Ref) || \
  794. ((SOURCE) == TIM_TRGOSource_OC3Ref) || \
  795. ((SOURCE) == TIM_TRGOSource_OC4Ref))
  796. /**
  797. * @}
  798. */
  799. /** @defgroup TIM_Slave_Mode
  800. * @{
  801. */
  802. #define TIM_SlaveMode_Reset ((uint16_t)0x0004)
  803. #define TIM_SlaveMode_Gated ((uint16_t)0x0005)
  804. #define TIM_SlaveMode_Trigger ((uint16_t)0x0006)
  805. #define TIM_SlaveMode_External1 ((uint16_t)0x0007)
  806. #define IS_TIM_SLAVE_MODE(MODE) (((MODE) == TIM_SlaveMode_Reset) || \
  807. ((MODE) == TIM_SlaveMode_Gated) || \
  808. ((MODE) == TIM_SlaveMode_Trigger) || \
  809. ((MODE) == TIM_SlaveMode_External1))
  810. /**
  811. * @}
  812. */
  813. /** @defgroup TIM_Master_Slave_Mode
  814. * @{
  815. */
  816. #define TIM_MasterSlaveMode_Enable ((uint16_t)0x0080)
  817. #define TIM_MasterSlaveMode_Disable ((uint16_t)0x0000)
  818. #define IS_TIM_MSM_STATE(STATE) (((STATE) == TIM_MasterSlaveMode_Enable) || \
  819. ((STATE) == TIM_MasterSlaveMode_Disable))
  820. /**
  821. * @}
  822. */
  823. /** @defgroup TIM_Flags
  824. * @{
  825. */
  826. #define TIM_FLAG_Update ((uint16_t)0x0001)
  827. #define TIM_FLAG_CC1 ((uint16_t)0x0002)
  828. #define TIM_FLAG_CC2 ((uint16_t)0x0004)
  829. #define TIM_FLAG_CC3 ((uint16_t)0x0008)
  830. #define TIM_FLAG_CC4 ((uint16_t)0x0010)
  831. #define TIM_FLAG_COM ((uint16_t)0x0020)
  832. #define TIM_FLAG_Trigger ((uint16_t)0x0040)
  833. #define TIM_FLAG_Break ((uint16_t)0x0080)
  834. #define TIM_FLAG_CC1OF ((uint16_t)0x0200)
  835. #define TIM_FLAG_CC2OF ((uint16_t)0x0400)
  836. #define TIM_FLAG_CC3OF ((uint16_t)0x0800)
  837. #define TIM_FLAG_CC4OF ((uint16_t)0x1000)
  838. #define IS_TIM_GET_FLAG(FLAG) (((FLAG) == TIM_FLAG_Update) || \
  839. ((FLAG) == TIM_FLAG_CC1) || \
  840. ((FLAG) == TIM_FLAG_CC2) || \
  841. ((FLAG) == TIM_FLAG_CC3) || \
  842. ((FLAG) == TIM_FLAG_CC4) || \
  843. ((FLAG) == TIM_FLAG_COM) || \
  844. ((FLAG) == TIM_FLAG_Trigger) || \
  845. ((FLAG) == TIM_FLAG_Break) || \
  846. ((FLAG) == TIM_FLAG_CC1OF) || \
  847. ((FLAG) == TIM_FLAG_CC2OF) || \
  848. ((FLAG) == TIM_FLAG_CC3OF) || \
  849. ((FLAG) == TIM_FLAG_CC4OF))
  850. #define IS_TIM_CLEAR_FLAG(TIM_FLAG) ((((TIM_FLAG) & (uint16_t)0xE100) == 0x0000) && ((TIM_FLAG) != 0x0000))
  851. /**
  852. * @}
  853. */
  854. /** @defgroup TIM_Input_Capture_Filer_Value
  855. * @{
  856. */
  857. #define IS_TIM_IC_FILTER(ICFILTER) ((ICFILTER) <= 0xF)
  858. /**
  859. * @}
  860. */
  861. /** @defgroup TIM_External_Trigger_Filter
  862. * @{
  863. */
  864. #define IS_TIM_EXT_FILTER(EXTFILTER) ((EXTFILTER) <= 0xF)
  865. /**
  866. * @}
  867. */
  868. /** @defgroup TIM_Legacy
  869. * @{
  870. */
  871. #define TIM_DMABurstLength_1Byte TIM_DMABurstLength_1Transfer
  872. #define TIM_DMABurstLength_2Bytes TIM_DMABurstLength_2Transfers
  873. #define TIM_DMABurstLength_3Bytes TIM_DMABurstLength_3Transfers
  874. #define TIM_DMABurstLength_4Bytes TIM_DMABurstLength_4Transfers
  875. #define TIM_DMABurstLength_5Bytes TIM_DMABurstLength_5Transfers
  876. #define TIM_DMABurstLength_6Bytes TIM_DMABurstLength_6Transfers
  877. #define TIM_DMABurstLength_7Bytes TIM_DMABurstLength_7Transfers
  878. #define TIM_DMABurstLength_8Bytes TIM_DMABurstLength_8Transfers
  879. #define TIM_DMABurstLength_9Bytes TIM_DMABurstLength_9Transfers
  880. #define TIM_DMABurstLength_10Bytes TIM_DMABurstLength_10Transfers
  881. #define TIM_DMABurstLength_11Bytes TIM_DMABurstLength_11Transfers
  882. #define TIM_DMABurstLength_12Bytes TIM_DMABurstLength_12Transfers
  883. #define TIM_DMABurstLength_13Bytes TIM_DMABurstLength_13Transfers
  884. #define TIM_DMABurstLength_14Bytes TIM_DMABurstLength_14Transfers
  885. #define TIM_DMABurstLength_15Bytes TIM_DMABurstLength_15Transfers
  886. #define TIM_DMABurstLength_16Bytes TIM_DMABurstLength_16Transfers
  887. #define TIM_DMABurstLength_17Bytes TIM_DMABurstLength_17Transfers
  888. #define TIM_DMABurstLength_18Bytes TIM_DMABurstLength_18Transfers
  889. /**
  890. * @}
  891. */
  892. /**
  893. * @}
  894. */
  895. /** @defgroup TIM_Exported_Macros
  896. * @{
  897. */
  898. /**
  899. * @}
  900. */
  901. /** @defgroup TIM_Exported_Functions
  902. * @{
  903. */
  904. void TIM_DeInit(TIM_TypeDef* TIMx);
  905. void TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct);
  906. void TIM_OC1Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct);
  907. void TIM_OC2Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct);
  908. void TIM_OC3Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct);
  909. void TIM_OC4Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct);
  910. void TIM_ICInit(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct);
  911. void TIM_PWMIConfig(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct);
  912. void TIM_BDTRConfig(TIM_TypeDef* TIMx, TIM_BDTRInitTypeDef *TIM_BDTRInitStruct);
  913. void TIM_TimeBaseStructInit(TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct);
  914. void TIM_OCStructInit(TIM_OCInitTypeDef* TIM_OCInitStruct);
  915. void TIM_ICStructInit(TIM_ICInitTypeDef* TIM_ICInitStruct);
  916. void TIM_BDTRStructInit(TIM_BDTRInitTypeDef* TIM_BDTRInitStruct);
  917. void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState);
  918. void TIM_CtrlPWMOutputs(TIM_TypeDef* TIMx, FunctionalState NewState);
  919. void TIM_ITConfig(TIM_TypeDef* TIMx, uint16_t TIM_IT, FunctionalState NewState);
  920. void TIM_GenerateEvent(TIM_TypeDef* TIMx, uint16_t TIM_EventSource);
  921. void TIM_DMAConfig(TIM_TypeDef* TIMx, uint16_t TIM_DMABase, uint16_t TIM_DMABurstLength);
  922. void TIM_DMACmd(TIM_TypeDef* TIMx, uint16_t TIM_DMASource, FunctionalState NewState);
  923. void TIM_InternalClockConfig(TIM_TypeDef* TIMx);
  924. void TIM_ITRxExternalClockConfig(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource);
  925. void TIM_TIxExternalClockConfig(TIM_TypeDef* TIMx, uint16_t TIM_TIxExternalCLKSource,
  926. uint16_t TIM_ICPolarity, uint16_t ICFilter);
  927. void TIM_ETRClockMode1Config(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity,
  928. uint16_t ExtTRGFilter);
  929. void TIM_ETRClockMode2Config(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler,
  930. uint16_t TIM_ExtTRGPolarity, uint16_t ExtTRGFilter);
  931. void TIM_ETRConfig(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity,
  932. uint16_t ExtTRGFilter);
  933. void TIM_PrescalerConfig(TIM_TypeDef* TIMx, uint16_t Prescaler, uint16_t TIM_PSCReloadMode);
  934. void TIM_CounterModeConfig(TIM_TypeDef* TIMx, uint16_t TIM_CounterMode);
  935. void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource);
  936. void TIM_EncoderInterfaceConfig(TIM_TypeDef* TIMx, uint16_t TIM_EncoderMode,
  937. uint16_t TIM_IC1Polarity, uint16_t TIM_IC2Polarity);
  938. void TIM_ForcedOC1Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction);
  939. void TIM_ForcedOC2Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction);
  940. void TIM_ForcedOC3Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction);
  941. void TIM_ForcedOC4Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction);
  942. void TIM_ARRPreloadConfig(TIM_TypeDef* TIMx, FunctionalState NewState);
  943. void TIM_SelectCOM(TIM_TypeDef* TIMx, FunctionalState NewState);
  944. void TIM_SelectCCDMA(TIM_TypeDef* TIMx, FunctionalState NewState);
  945. void TIM_CCPreloadControl(TIM_TypeDef* TIMx, FunctionalState NewState);
  946. void TIM_OC1PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload);
  947. void TIM_OC2PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload);
  948. void TIM_OC3PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload);
  949. void TIM_OC4PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload);
  950. void TIM_OC1FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast);
  951. void TIM_OC2FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast);
  952. void TIM_OC3FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast);
  953. void TIM_OC4FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast);
  954. void TIM_ClearOC1Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear);
  955. void TIM_ClearOC2Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear);
  956. void TIM_ClearOC3Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear);
  957. void TIM_ClearOC4Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear);
  958. void TIM_OC1PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity);
  959. void TIM_OC1NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity);
  960. void TIM_OC2PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity);
  961. void TIM_OC2NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity);
  962. void TIM_OC3PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity);
  963. void TIM_OC3NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity);
  964. void TIM_OC4PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity);
  965. void TIM_CCxCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCx);
  966. void TIM_CCxNCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCxN);
  967. void TIM_SelectOCxM(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_OCMode);
  968. void TIM_UpdateDisableConfig(TIM_TypeDef* TIMx, FunctionalState NewState);
  969. void TIM_UpdateRequestConfig(TIM_TypeDef* TIMx, uint16_t TIM_UpdateSource);
  970. void TIM_SelectHallSensor(TIM_TypeDef* TIMx, FunctionalState NewState);
  971. void TIM_SelectOnePulseMode(TIM_TypeDef* TIMx, uint16_t TIM_OPMode);
  972. void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_TRGOSource);
  973. void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_SlaveMode);
  974. void TIM_SelectMasterSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_MasterSlaveMode);
  975. void TIM_SetCounter(TIM_TypeDef* TIMx, uint16_t Counter);
  976. void TIM_SetAutoreload(TIM_TypeDef* TIMx, uint16_t Autoreload);
  977. void TIM_SetCompare1(TIM_TypeDef* TIMx, uint16_t Compare1);
  978. void TIM_SetCompare2(TIM_TypeDef* TIMx, uint16_t Compare2);
  979. void TIM_SetCompare3(TIM_TypeDef* TIMx, uint16_t Compare3);
  980. void TIM_SetCompare4(TIM_TypeDef* TIMx, uint16_t Compare4);
  981. void TIM_SetIC1Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC);
  982. void TIM_SetIC2Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC);
  983. void TIM_SetIC3Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC);
  984. void TIM_SetIC4Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC);
  985. void TIM_SetClockDivision(TIM_TypeDef* TIMx, uint16_t TIM_CKD);
  986. uint16_t TIM_GetCapture1(TIM_TypeDef* TIMx);
  987. uint16_t TIM_GetCapture2(TIM_TypeDef* TIMx);
  988. uint16_t TIM_GetCapture3(TIM_TypeDef* TIMx);
  989. uint16_t TIM_GetCapture4(TIM_TypeDef* TIMx);
  990. uint16_t TIM_GetCounter(TIM_TypeDef* TIMx);
  991. uint16_t TIM_GetPrescaler(TIM_TypeDef* TIMx);
  992. FlagStatus TIM_GetFlagStatus(TIM_TypeDef* TIMx, uint16_t TIM_FLAG);
  993. void TIM_ClearFlag(TIM_TypeDef* TIMx, uint16_t TIM_FLAG);
  994. ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, uint16_t TIM_IT);
  995. void TIM_ClearITPendingBit(TIM_TypeDef* TIMx, uint16_t TIM_IT);
  996. #ifdef __cplusplus
  997. }
  998. #endif
  999. #endif /*__STM32F10x_TIM_H */
  1000. /**
  1001. * @}
  1002. */
  1003. /**
  1004. * @}
  1005. */
  1006. /**
  1007. * @}
  1008. */
  1009. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  1010. /**
  1011. ******************************************************************************
  1012. * @file stm32f10x_i2c.h
  1013. * @author MCD Application Team
  1014. * @version V3.5.0
  1015. * @date 11-March-2011
  1016. * @brief This file contains all the functions prototypes for the I2C firmware
  1017. * library.
  1018. ******************************************************************************
  1019. * @attention
  1020. *
  1021. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  1022. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  1023. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  1024. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  1025. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  1026. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  1027. *
  1028. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  1029. ******************************************************************************
  1030. */
  1031. /* Define to prevent recursive inclusion -------------------------------------*/
  1032. #ifndef __STM32F10x_I2C_H
  1033. #define __STM32F10x_I2C_H
  1034. #ifdef __cplusplus
  1035. extern "C" {
  1036. #endif
  1037. /* Includes ------------------------------------------------------------------*/
  1038. #include "stm32f10x.h"
  1039. /** @addtogroup STM32F10x_StdPeriph_Driver
  1040. * @{
  1041. */
  1042. /** @addtogroup I2C
  1043. * @{
  1044. */
  1045. /** @defgroup I2C_Exported_Types
  1046. * @{
  1047. */
  1048. /**
  1049. * @brief I2C Init structure definition
  1050. */
  1051. typedef struct
  1052. {
  1053. uint32_t I2C_ClockSpeed; /*!< Specifies the clock frequency.
  1054. This parameter must be set to a value lower than 400kHz */
  1055. uint16_t I2C_Mode; /*!< Specifies the I2C mode.
  1056. This parameter can be a value of @ref I2C_mode */
  1057. uint16_t I2C_DutyCycle; /*!< Specifies the I2C fast mode duty cycle.
  1058. This parameter can be a value of @ref I2C_duty_cycle_in_fast_mode */
  1059. uint16_t I2C_OwnAddress1; /*!< Specifies the first device own address.
  1060. This parameter can be a 7-bit or 10-bit address. */
  1061. uint16_t I2C_Ack; /*!< Enables or disables the acknowledgement.
  1062. This parameter can be a value of @ref I2C_acknowledgement */
  1063. uint16_t I2C_AcknowledgedAddress; /*!< Specifies if 7-bit or 10-bit address is acknowledged.
  1064. This parameter can be a value of @ref I2C_acknowledged_address */
  1065. }I2C_InitTypeDef;
  1066. /**
  1067. * @}
  1068. */
  1069. /** @defgroup I2C_Exported_Constants
  1070. * @{
  1071. */
  1072. #define IS_I2C_ALL_PERIPH(PERIPH) (((PERIPH) == I2C1) || \
  1073. ((PERIPH) == I2C2))
  1074. /** @defgroup I2C_mode
  1075. * @{
  1076. */
  1077. #define I2C_Mode_I2C ((uint16_t)0x0000)
  1078. #define I2C_Mode_SMBusDevice ((uint16_t)0x0002)
  1079. #define I2C_Mode_SMBusHost ((uint16_t)0x000A)
  1080. #define IS_I2C_MODE(MODE) (((MODE) == I2C_Mode_I2C) || \
  1081. ((MODE) == I2C_Mode_SMBusDevice) || \
  1082. ((MODE) == I2C_Mode_SMBusHost))
  1083. /**
  1084. * @}
  1085. */
  1086. /** @defgroup I2C_duty_cycle_in_fast_mode
  1087. * @{
  1088. */
  1089. #define I2C_DutyCycle_16_9 ((uint16_t)0x4000) /*!< I2C fast mode Tlow/Thigh = 16/9 */
  1090. #define I2C_DutyCycle_2 ((uint16_t)0xBFFF) /*!< I2C fast mode Tlow/Thigh = 2 */
  1091. #define IS_I2C_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_DutyCycle_16_9) || \
  1092. ((CYCLE) == I2C_DutyCycle_2))
  1093. /**
  1094. * @}
  1095. */
  1096. /** @defgroup I2C_acknowledgement
  1097. * @{
  1098. */
  1099. #define I2C_Ack_Enable ((uint16_t)0x0400)
  1100. #define I2C_Ack_Disable ((uint16_t)0x0000)
  1101. #define IS_I2C_ACK_STATE(STATE) (((STATE) == I2C_Ack_Enable) || \
  1102. ((STATE) == I2C_Ack_Disable))
  1103. /**
  1104. * @}
  1105. */
  1106. /** @defgroup I2C_transfer_direction
  1107. * @{
  1108. */
  1109. #define I2C_Direction_Transmitter ((uint8_t)0x00)
  1110. #define I2C_Direction_Receiver ((uint8_t)0x01)
  1111. #define IS_I2C_DIRECTION(DIRECTION) (((DIRECTION) == I2C_Direction_Transmitter) || \
  1112. ((DIRECTION) == I2C_Direction_Receiver))
  1113. /**
  1114. * @}
  1115. */
  1116. /** @defgroup I2C_acknowledged_address
  1117. * @{
  1118. */
  1119. #define I2C_AcknowledgedAddress_7bit ((uint16_t)0x4000)
  1120. #define I2C_AcknowledgedAddress_10bit ((uint16_t)0xC000)
  1121. #define IS_I2C_ACKNOWLEDGE_ADDRESS(ADDRESS) (((ADDRESS) == I2C_AcknowledgedAddress_7bit) || \
  1122. ((ADDRESS) == I2C_AcknowledgedAddress_10bit))
  1123. /**
  1124. * @}
  1125. */
  1126. /** @defgroup I2C_registers
  1127. * @{
  1128. */
  1129. #define I2C_Register_CR1 ((uint8_t)0x00)
  1130. #define I2C_Register_CR2 ((uint8_t)0x04)
  1131. #define I2C_Register_OAR1 ((uint8_t)0x08)
  1132. #define I2C_Register_OAR2 ((uint8_t)0x0C)
  1133. #define I2C_Register_DR ((uint8_t)0x10)
  1134. #define I2C_Register_SR1 ((uint8_t)0x14)
  1135. #define I2C_Register_SR2 ((uint8_t)0x18)
  1136. #define I2C_Register_CCR ((uint8_t)0x1C)
  1137. #define I2C_Register_TRISE ((uint8_t)0x20)
  1138. #define IS_I2C_REGISTER(REGISTER) (((REGISTER) == I2C_Register_CR1) || \
  1139. ((REGISTER) == I2C_Register_CR2) || \
  1140. ((REGISTER) == I2C_Register_OAR1) || \
  1141. ((REGISTER) == I2C_Register_OAR2) || \
  1142. ((REGISTER) == I2C_Register_DR) || \
  1143. ((REGISTER) == I2C_Register_SR1) || \
  1144. ((REGISTER) == I2C_Register_SR2) || \
  1145. ((REGISTER) == I2C_Register_CCR) || \
  1146. ((REGISTER) == I2C_Register_TRISE))
  1147. /**
  1148. * @}
  1149. */
  1150. /** @defgroup I2C_SMBus_alert_pin_level
  1151. * @{
  1152. */
  1153. #define I2C_SMBusAlert_Low ((uint16_t)0x2000)
  1154. #define I2C_SMBusAlert_High ((uint16_t)0xDFFF)
  1155. #define IS_I2C_SMBUS_ALERT(ALERT) (((ALERT) == I2C_SMBusAlert_Low) || \
  1156. ((ALERT) == I2C_SMBusAlert_High))
  1157. /**
  1158. * @}
  1159. */
  1160. /** @defgroup I2C_PEC_position
  1161. * @{
  1162. */
  1163. #define I2C_PECPosition_Next ((uint16_t)0x0800)
  1164. #define I2C_PECPosition_Current ((uint16_t)0xF7FF)
  1165. #define IS_I2C_PEC_POSITION(POSITION) (((POSITION) == I2C_PECPosition_Next) || \
  1166. ((POSITION) == I2C_PECPosition_Current))
  1167. /**
  1168. * @}
  1169. */
  1170. /** @defgroup I2C_NCAK_position
  1171. * @{
  1172. */
  1173. #define I2C_NACKPosition_Next ((uint16_t)0x0800)
  1174. #define I2C_NACKPosition_Current ((uint16_t)0xF7FF)
  1175. #define IS_I2C_NACK_POSITION(POSITION) (((POSITION) == I2C_NACKPosition_Next) || \
  1176. ((POSITION) == I2C_NACKPosition_Current))
  1177. /**
  1178. * @}
  1179. */
  1180. /** @defgroup I2C_interrupts_definition
  1181. * @{
  1182. */
  1183. #define I2C_IT_BUF ((uint16_t)0x0400)
  1184. #define I2C_IT_EVT ((uint16_t)0x0200)
  1185. #define I2C_IT_ERR ((uint16_t)0x0100)
  1186. #define IS_I2C_CONFIG_IT(IT) ((((IT) & (uint16_t)0xF8FF) == 0x00) && ((IT) != 0x00))
  1187. /**
  1188. * @}
  1189. */
  1190. /** @defgroup I2C_interrupts_definition
  1191. * @{
  1192. */
  1193. #define I2C_IT_SMBALERT ((uint32_t)0x01008000)
  1194. #define I2C_IT_TIMEOUT ((uint32_t)0x01004000)
  1195. #define I2C_IT_PECERR ((uint32_t)0x01001000)
  1196. #define I2C_IT_OVR ((uint32_t)0x01000800)
  1197. #define I2C_IT_AF ((uint32_t)0x01000400)
  1198. #define I2C_IT_ARLO ((uint32_t)0x01000200)
  1199. #define I2C_IT_BERR ((uint32_t)0x01000100)
  1200. #define I2C_IT_TXE ((uint32_t)0x06000080)
  1201. #define I2C_IT_RXNE ((uint32_t)0x06000040)
  1202. #define I2C_IT_STOPF ((uint32_t)0x02000010)
  1203. #define I2C_IT_ADD10 ((uint32_t)0x02000008)
  1204. #define I2C_IT_BTF ((uint32_t)0x02000004)
  1205. #define I2C_IT_ADDR ((uint32_t)0x02000002)
  1206. #define I2C_IT_SB ((uint32_t)0x02000001)
  1207. #define IS_I2C_CLEAR_IT(IT) ((((IT) & (uint16_t)0x20FF) == 0x00) && ((IT) != (uint16_t)0x00))
  1208. #define IS_I2C_GET_IT(IT) (((IT) == I2C_IT_SMBALERT) || ((IT) == I2C_IT_TIMEOUT) || \
  1209. ((IT) == I2C_IT_PECERR) || ((IT) == I2C_IT_OVR) || \
  1210. ((IT) == I2C_IT_AF) || ((IT) == I2C_IT_ARLO) || \
  1211. ((IT) == I2C_IT_BERR) || ((IT) == I2C_IT_TXE) || \
  1212. ((IT) == I2C_IT_RXNE) || ((IT) == I2C_IT_STOPF) || \
  1213. ((IT) == I2C_IT_ADD10) || ((IT) == I2C_IT_BTF) || \
  1214. ((IT) == I2C_IT_ADDR) || ((IT) == I2C_IT_SB))
  1215. /**
  1216. * @}
  1217. */
  1218. /** @defgroup I2C_flags_definition
  1219. * @{
  1220. */
  1221. /**
  1222. * @brief SR2 register flags
  1223. */
  1224. #define I2C_FLAG_DUALF ((uint32_t)0x00800000)
  1225. #define I2C_FLAG_SMBHOST ((uint32_t)0x00400000)
  1226. #define I2C_FLAG_SMBDEFAULT ((uint32_t)0x00200000)
  1227. #define I2C_FLAG_GENCALL ((uint32_t)0x00100000)
  1228. #define I2C_FLAG_TRA ((uint32_t)0x00040000)
  1229. #define I2C_FLAG_BUSY ((uint32_t)0x00020000)
  1230. #define I2C_FLAG_MSL ((uint32_t)0x00010000)
  1231. /**
  1232. * @brief SR1 register flags
  1233. */
  1234. #define I2C_FLAG_SMBALERT ((uint32_t)0x10008000)
  1235. #define I2C_FLAG_TIMEOUT ((uint32_t)0x10004000)
  1236. #define I2C_FLAG_PECERR ((uint32_t)0x10001000)
  1237. #define I2C_FLAG_OVR ((uint32_t)0x10000800)
  1238. #define I2C_FLAG_AF ((uint32_t)0x10000400)
  1239. #define I2C_FLAG_ARLO ((uint32_t)0x10000200)
  1240. #define I2C_FLAG_BERR ((uint32_t)0x10000100)
  1241. #define I2C_FLAG_TXE ((uint32_t)0x10000080)
  1242. #define I2C_FLAG_RXNE ((uint32_t)0x10000040)
  1243. #define I2C_FLAG_STOPF ((uint32_t)0x10000010)
  1244. #define I2C_FLAG_ADD10 ((uint32_t)0x10000008)
  1245. #define I2C_FLAG_BTF ((uint32_t)0x10000004)
  1246. #define I2C_FLAG_ADDR ((uint32_t)0x10000002)
  1247. #define I2C_FLAG_SB ((uint32_t)0x10000001)
  1248. #define IS_I2C_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0x20FF) == 0x00) && ((FLAG) != (uint16_t)0x00))
  1249. #define IS_I2C_GET_FLAG(FLAG) (((FLAG) == I2C_FLAG_DUALF) || ((FLAG) == I2C_FLAG_SMBHOST) || \
  1250. ((FLAG) == I2C_FLAG_SMBDEFAULT) || ((FLAG) == I2C_FLAG_GENCALL) || \
  1251. ((FLAG) == I2C_FLAG_TRA) || ((FLAG) == I2C_FLAG_BUSY) || \
  1252. ((FLAG) == I2C_FLAG_MSL) || ((FLAG) == I2C_FLAG_SMBALERT) || \
  1253. ((FLAG) == I2C_FLAG_TIMEOUT) || ((FLAG) == I2C_FLAG_PECERR) || \
  1254. ((FLAG) == I2C_FLAG_OVR) || ((FLAG) == I2C_FLAG_AF) || \
  1255. ((FLAG) == I2C_FLAG_ARLO) || ((FLAG) == I2C_FLAG_BERR) || \
  1256. ((FLAG) == I2C_FLAG_TXE) || ((FLAG) == I2C_FLAG_RXNE) || \
  1257. ((FLAG) == I2C_FLAG_STOPF) || ((FLAG) == I2C_FLAG_ADD10) || \
  1258. ((FLAG) == I2C_FLAG_BTF) || ((FLAG) == I2C_FLAG_ADDR) || \
  1259. ((FLAG) == I2C_FLAG_SB))
  1260. /**
  1261. * @}
  1262. */
  1263. /** @defgroup I2C_Events
  1264. * @{
  1265. */
  1266. /*========================================
  1267. I2C Master Events (Events grouped in order of communication)
  1268. ==========================================*/
  1269. /**
  1270. * @brief Communication start
  1271. *
  1272. * After sending the START condition (I2C_GenerateSTART() function) the master
  1273. * has to wait for this event. It means that the Start condition has been correctly
  1274. * released on the I2C bus (the bus is free, no other devices is communicating).
  1275. *
  1276. */
  1277. /* --EV5 */
  1278. #define I2C_EVENT_MASTER_MODE_SELECT ((uint32_t)0x00030001) /* BUSY, MSL and SB flag */
  1279. /**
  1280. * @brief Address Acknowledge
  1281. *
  1282. * After checking on EV5 (start condition correctly released on the bus), the
  1283. * master sends the address of the slave(s) with which it will communicate
  1284. * (I2C_Send7bitAddress() function, it also determines the direction of the communication:
  1285. * Master transmitter or Receiver). Then the master has to wait that a slave acknowledges
  1286. * his address. If an acknowledge is sent on the bus, one of the following events will
  1287. * be set:
  1288. *
  1289. * 1) In case of Master Receiver (7-bit addressing): the I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED
  1290. * event is set.
  1291. *
  1292. * 2) In case of Master Transmitter (7-bit addressing): the I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED
  1293. * is set
  1294. *
  1295. * 3) In case of 10-Bit addressing mode, the master (just after generating the START
  1296. * and checking on EV5) has to send the header of 10-bit addressing mode (I2C_SendData()
  1297. * function). Then master should wait on EV9. It means that the 10-bit addressing
  1298. * header has been correctly sent on the bus. Then master should send the second part of
  1299. * the 10-bit address (LSB) using the function I2C_Send7bitAddress(). Then master
  1300. * should wait for event EV6.
  1301. *
  1302. */
  1303. /* --EV6 */
  1304. #define I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED ((uint32_t)0x00070082) /* BUSY, MSL, ADDR, TXE and TRA flags */
  1305. #define I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED ((uint32_t)0x00030002) /* BUSY, MSL and ADDR flags */
  1306. /* --EV9 */
  1307. #define I2C_EVENT_MASTER_MODE_ADDRESS10 ((uint32_t)0x00030008) /* BUSY, MSL and ADD10 flags */
  1308. /**
  1309. * @brief Communication events
  1310. *
  1311. * If a communication is established (START condition generated and slave address
  1312. * acknowledged) then the master has to check on one of the following events for
  1313. * communication procedures:
  1314. *
  1315. * 1) Master Receiver mode: The master has to wait on the event EV7 then to read
  1316. * the data received from the slave (I2C_ReceiveData() function).
  1317. *
  1318. * 2) Master Transmitter mode: The master has to send data (I2C_SendData()
  1319. * function) then to wait on event EV8 or EV8_2.
  1320. * These two events are similar:
  1321. * - EV8 means that the data has been written in the data register and is
  1322. * being shifted out.
  1323. * - EV8_2 means that the data has been physically shifted out and output
  1324. * on the bus.
  1325. * In most cases, using EV8 is sufficient for the application.
  1326. * Using EV8_2 leads to a slower communication but ensure more reliable test.
  1327. * EV8_2 is also more suitable than EV8 for testing on the last data transmission
  1328. * (before Stop condition generation).
  1329. *
  1330. * @note In case the user software does not guarantee that this event EV7 is
  1331. * managed before the current byte end of transfer, then user may check on EV7
  1332. * and BTF flag at the same time (ie. (I2C_EVENT_MASTER_BYTE_RECEIVED | I2C_FLAG_BTF)).
  1333. * In this case the communication may be slower.
  1334. *
  1335. */
  1336. /* Master RECEIVER mode -----------------------------*/
  1337. /* --EV7 */
  1338. #define I2C_EVENT_MASTER_BYTE_RECEIVED ((uint32_t)0x00030040) /* BUSY, MSL and RXNE flags */
  1339. /* Master TRANSMITTER mode --------------------------*/
  1340. /* --EV8 */
  1341. #define I2C_EVENT_MASTER_BYTE_TRANSMITTING ((uint32_t)0x00070080) /* TRA, BUSY, MSL, TXE flags */
  1342. /* --EV8_2 */
  1343. #define I2C_EVENT_MASTER_BYTE_TRANSMITTED ((uint32_t)0x00070084) /* TRA, BUSY, MSL, TXE and BTF flags */
  1344. /*========================================
  1345. I2C Slave Events (Events grouped in order of communication)
  1346. ==========================================*/
  1347. /**
  1348. * @brief Communication start events
  1349. *
  1350. * Wait on one of these events at the start of the communication. It means that
  1351. * the I2C peripheral detected a Start condition on the bus (generated by master
  1352. * device) followed by the peripheral address. The peripheral generates an ACK
  1353. * condition on the bus (if the acknowledge feature is enabled through function
  1354. * I2C_AcknowledgeConfig()) and the events listed above are set :
  1355. *
  1356. * 1) In normal case (only one address managed by the slave), when the address
  1357. * sent by the master matches the own address of the peripheral (configured by
  1358. * I2C_OwnAddress1 field) the I2C_EVENT_SLAVE_XXX_ADDRESS_MATCHED event is set
  1359. * (where XXX could be TRANSMITTER or RECEIVER).
  1360. *
  1361. * 2) In case the address sent by the master matches the second address of the
  1362. * peripheral (configured by the function I2C_OwnAddress2Config() and enabled
  1363. * by the function I2C_DualAddressCmd()) the events I2C_EVENT_SLAVE_XXX_SECONDADDRESS_MATCHED
  1364. * (where XXX could be TRANSMITTER or RECEIVER) are set.
  1365. *
  1366. * 3) In case the address sent by the master is General Call (address 0x00) and
  1367. * if the General Call is enabled for the peripheral (using function I2C_GeneralCallCmd())
  1368. * the following event is set I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED.
  1369. *
  1370. */
  1371. /* --EV1 (all the events below are variants of EV1) */
  1372. /* 1) Case of One Single Address managed by the slave */
  1373. #define I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED ((uint32_t)0x00020002) /* BUSY and ADDR flags */
  1374. #define I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED ((uint32_t)0x00060082) /* TRA, BUSY, TXE and ADDR flags */
  1375. /* 2) Case of Dual address managed by the slave */
  1376. #define I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED ((uint32_t)0x00820000) /* DUALF and BUSY flags */
  1377. #define I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED ((uint32_t)0x00860080) /* DUALF, TRA, BUSY and TXE flags */
  1378. /* 3) Case of General Call enabled for the slave */
  1379. #define I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED ((uint32_t)0x00120000) /* GENCALL and BUSY flags */
  1380. /**
  1381. * @brief Communication events
  1382. *
  1383. * Wait on one of these events when EV1 has already been checked and:
  1384. *
  1385. * - Slave RECEIVER mode:
  1386. * - EV2: When the application is expecting a data byte to be received.
  1387. * - EV4: When the application is expecting the end of the communication: master
  1388. * sends a stop condition and data transmission is stopped.
  1389. *
  1390. * - Slave Transmitter mode:
  1391. * - EV3: When a byte has been transmitted by the slave and the application is expecting
  1392. * the end of the byte transmission. The two events I2C_EVENT_SLAVE_BYTE_TRANSMITTED and
  1393. * I2C_EVENT_SLAVE_BYTE_TRANSMITTING are similar. The second one can optionally be
  1394. * used when the user software doesn't guarantee the EV3 is managed before the
  1395. * current byte end of transfer.
  1396. * - EV3_2: When the master sends a NACK in order to tell slave that data transmission
  1397. * shall end (before sending the STOP condition). In this case slave has to stop sending
  1398. * data bytes and expect a Stop condition on the bus.
  1399. *
  1400. * @note In case the user software does not guarantee that the event EV2 is
  1401. * managed before the current byte end of transfer, then user may check on EV2
  1402. * and BTF flag at the same time (ie. (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_BTF)).
  1403. * In this case the communication may be slower.
  1404. *
  1405. */
  1406. /* Slave RECEIVER mode --------------------------*/
  1407. /* --EV2 */
  1408. #define I2C_EVENT_SLAVE_BYTE_RECEIVED ((uint32_t)0x00020040) /* BUSY and RXNE flags */
  1409. /* --EV4 */
  1410. #define I2C_EVENT_SLAVE_STOP_DETECTED ((uint32_t)0x00000010) /* STOPF flag */
  1411. /* Slave TRANSMITTER mode -----------------------*/
  1412. /* --EV3 */
  1413. #define I2C_EVENT_SLAVE_BYTE_TRANSMITTED ((uint32_t)0x00060084) /* TRA, BUSY, TXE and BTF flags */
  1414. #define I2C_EVENT_SLAVE_BYTE_TRANSMITTING ((uint32_t)0x00060080) /* TRA, BUSY and TXE flags */
  1415. /* --EV3_2 */
  1416. #define I2C_EVENT_SLAVE_ACK_FAILURE ((uint32_t)0x00000400) /* AF flag */
  1417. /*=========================== End of Events Description ==========================================*/
  1418. #define IS_I2C_EVENT(EVENT) (((EVENT) == I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED) || \
  1419. ((EVENT) == I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED) || \
  1420. ((EVENT) == I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED) || \
  1421. ((EVENT) == I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED) || \
  1422. ((EVENT) == I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED) || \
  1423. ((EVENT) == I2C_EVENT_SLAVE_BYTE_RECEIVED) || \
  1424. ((EVENT) == (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_DUALF)) || \
  1425. ((EVENT) == (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_GENCALL)) || \
  1426. ((EVENT) == I2C_EVENT_SLAVE_BYTE_TRANSMITTED) || \
  1427. ((EVENT) == (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_DUALF)) || \
  1428. ((EVENT) == (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_GENCALL)) || \
  1429. ((EVENT) == I2C_EVENT_SLAVE_STOP_DETECTED) || \
  1430. ((EVENT) == I2C_EVENT_MASTER_MODE_SELECT) || \
  1431. ((EVENT) == I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED) || \
  1432. ((EVENT) == I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED) || \
  1433. ((EVENT) == I2C_EVENT_MASTER_BYTE_RECEIVED) || \
  1434. ((EVENT) == I2C_EVENT_MASTER_BYTE_TRANSMITTED) || \
  1435. ((EVENT) == I2C_EVENT_MASTER_BYTE_TRANSMITTING) || \
  1436. ((EVENT) == I2C_EVENT_MASTER_MODE_ADDRESS10) || \
  1437. ((EVENT) == I2C_EVENT_SLAVE_ACK_FAILURE))
  1438. /**
  1439. * @}
  1440. */
  1441. /** @defgroup I2C_own_address1
  1442. * @{
  1443. */
  1444. #define IS_I2C_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= 0x3FF)
  1445. /**
  1446. * @}
  1447. */
  1448. /** @defgroup I2C_clock_speed
  1449. * @{
  1450. */
  1451. #define IS_I2C_CLOCK_SPEED(SPEED) (((SPEED) >= 0x1) && ((SPEED) <= 400000))
  1452. /**
  1453. * @}
  1454. */
  1455. /**
  1456. * @}
  1457. */
  1458. /** @defgroup I2C_Exported_Macros
  1459. * @{
  1460. */
  1461. /**
  1462. * @}
  1463. */
  1464. /** @defgroup I2C_Exported_Functions
  1465. * @{
  1466. */
  1467. void I2C_DeInit(I2C_TypeDef* I2Cx);
  1468. void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct);
  1469. void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct);
  1470. void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
  1471. void I2C_DMACmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
  1472. void I2C_DMALastTransferCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
  1473. void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState);
  1474. void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState);
  1475. void I2C_AcknowledgeConfig(I2C_TypeDef* I2Cx, FunctionalState NewState);
  1476. void I2C_OwnAddress2Config(I2C_TypeDef* I2Cx, uint8_t Address);
  1477. void I2C_DualAddressCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
  1478. void I2C_GeneralCallCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
  1479. void I2C_ITConfig(I2C_TypeDef* I2Cx, uint16_t I2C_IT, FunctionalState NewState);
  1480. void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data);
  1481. uint8_t I2C_ReceiveData(I2C_TypeDef* I2Cx);
  1482. void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, uint8_t Address, uint8_t I2C_Direction);
  1483. uint16_t I2C_ReadRegister(I2C_TypeDef* I2Cx, uint8_t I2C_Register);
  1484. void I2C_SoftwareResetCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
  1485. void I2C_NACKPositionConfig(I2C_TypeDef* I2Cx, uint16_t I2C_NACKPosition);
  1486. void I2C_SMBusAlertConfig(I2C_TypeDef* I2Cx, uint16_t I2C_SMBusAlert);
  1487. void I2C_TransmitPEC(I2C_TypeDef* I2Cx, FunctionalState NewState);
  1488. void I2C_PECPositionConfig(I2C_TypeDef* I2Cx, uint16_t I2C_PECPosition);
  1489. void I2C_CalculatePEC(I2C_TypeDef* I2Cx, FunctionalState NewState);
  1490. uint8_t I2C_GetPEC(I2C_TypeDef* I2Cx);
  1491. void I2C_ARPCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
  1492. void I2C_StretchClockCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
  1493. void I2C_FastModeDutyCycleConfig(I2C_TypeDef* I2Cx, uint16_t I2C_DutyCycle);
  1494. /**
  1495. * @brief
  1496. ****************************************************************************************
  1497. *
  1498. * I2C State Monitoring Functions
  1499. *
  1500. ****************************************************************************************
  1501. * This I2C driver provides three different ways for I2C state monitoring
  1502. * depending on the application requirements and constraints:
  1503. *
  1504. *
  1505. * 1) Basic state monitoring:
  1506. * Using I2C_CheckEvent() function:
  1507. * It compares the status registers (SR1 and SR2) content to a given event
  1508. * (can be the combination of one or more flags).
  1509. * It returns SUCCESS if the current status includes the given flags
  1510. * and returns ERROR if one or more flags are missing in the current status.
  1511. * - When to use:
  1512. * - This function is suitable for most applications as well as for startup
  1513. * activity since the events are fully described in the product reference manual
  1514. * (RM0008).
  1515. * - It is also suitable for users who need to define their own events.
  1516. * - Limitations:
  1517. * - If an error occurs (ie. error flags are set besides to the monitored flags),
  1518. * the I2C_CheckEvent() function may return SUCCESS despite the communication
  1519. * hold or corrupted real state.
  1520. * In this case, it is advised to use error interrupts to monitor the error
  1521. * events and handle them in the interrupt IRQ handler.
  1522. *
  1523. * @note
  1524. * For error management, it is advised to use the following functions:
  1525. * - I2C_ITConfig() to configure and enable the error interrupts (I2C_IT_ERR).
  1526. * - I2Cx_ER_IRQHandler() which is called when the error interrupt occurs.
  1527. * Where x is the peripheral instance (I2C1, I2C2 ...)
  1528. * - I2C_GetFlagStatus() or I2C_GetITStatus() to be called into I2Cx_ER_IRQHandler()
  1529. * in order to determine which error occurred.
  1530. * - I2C_ClearFlag() or I2C_ClearITPendingBit() and/or I2C_SoftwareResetCmd()
  1531. * and/or I2C_GenerateStop() in order to clear the error flag and source,
  1532. * and return to correct communication status.
  1533. *
  1534. *
  1535. * 2) Advanced state monitoring:
  1536. * Using the function I2C_GetLastEvent() which returns the image of both status
  1537. * registers in a single word (uint32_t) (Status Register 2 value is shifted left
  1538. * by 16 bits and concatenated to Status Register 1).
  1539. * - When to use:
  1540. * - This function is suitable for the same applications above but it allows to
  1541. * overcome the limitations of I2C_GetFlagStatus() function (see below).
  1542. * The returned value could be compared to events already defined in the
  1543. * library (stm32f10x_i2c.h) or to custom values defined by user.
  1544. * - This function is suitable when multiple flags are monitored at the same time.
  1545. * - At the opposite of I2C_CheckEvent() function, this function allows user to
  1546. * choose when an event is accepted (when all events flags are set and no
  1547. * other flags are set or just when the needed flags are set like
  1548. * I2C_CheckEvent() function).
  1549. * - Limitations:
  1550. * - User may need to define his own events.
  1551. * - Same remark concerning the error management is applicable for this
  1552. * function if user decides to check only regular communication flags (and
  1553. * ignores error flags).
  1554. *
  1555. *
  1556. * 3) Flag-based state monitoring:
  1557. * Using the function I2C_GetFlagStatus() which simply returns the status of
  1558. * one single flag (ie. I2C_FLAG_RXNE ...).
  1559. * - When to use:
  1560. * - This function could be used for specific applications or in debug phase.
  1561. * - It is suitable when only one flag checking is needed (most I2C events
  1562. * are monitored through multiple flags).
  1563. * - Limitations:
  1564. * - When calling this function, the Status register is accessed. Some flags are
  1565. * cleared when the status register is accessed. So checking the status
  1566. * of one Flag, may clear other ones.
  1567. * - Function may need to be called twice or more in order to monitor one
  1568. * single event.
  1569. *
  1570. */
  1571. /**
  1572. *
  1573. * 1) Basic state monitoring
  1574. *******************************************************************************
  1575. */
  1576. ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, uint32_t I2C_EVENT);
  1577. /**
  1578. *
  1579. * 2) Advanced state monitoring
  1580. *******************************************************************************
  1581. */
  1582. uint32_t I2C_GetLastEvent(I2C_TypeDef* I2Cx);
  1583. /**
  1584. *
  1585. * 3) Flag-based state monitoring
  1586. *******************************************************************************
  1587. */
  1588. FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG);
  1589. /**
  1590. *
  1591. *******************************************************************************
  1592. */
  1593. void I2C_ClearFlag(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG);
  1594. ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, uint32_t I2C_IT);
  1595. void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, uint32_t I2C_IT);
  1596. #ifdef __cplusplus
  1597. }
  1598. #endif
  1599. #endif /*__STM32F10x_I2C_H */
  1600. /**
  1601. * @}
  1602. */
  1603. /**
  1604. * @}
  1605. */
  1606. /**
  1607. * @}
  1608. */
  1609. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  1610. /**
  1611. ******************************************************************************
  1612. * @file stm32f10x_iwdg.h
  1613. * @author MCD Application Team
  1614. * @version V3.5.0
  1615. * @date 11-March-2011
  1616. * @brief This file contains all the functions prototypes for the IWDG
  1617. * firmware library.
  1618. ******************************************************************************
  1619. * @attention
  1620. *
  1621. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  1622. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  1623. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  1624. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  1625. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  1626. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  1627. *
  1628. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  1629. ******************************************************************************
  1630. */
  1631. /* Define to prevent recursive inclusion -------------------------------------*/
  1632. #ifndef __STM32F10x_IWDG_H
  1633. #define __STM32F10x_IWDG_H
  1634. #ifdef __cplusplus
  1635. extern "C" {
  1636. #endif
  1637. /* Includes ------------------------------------------------------------------*/
  1638. #include "stm32f10x.h"
  1639. /** @addtogroup STM32F10x_StdPeriph_Driver
  1640. * @{
  1641. */
  1642. /** @addtogroup IWDG
  1643. * @{
  1644. */
  1645. /** @defgroup IWDG_Exported_Types
  1646. * @{
  1647. */
  1648. /**
  1649. * @}
  1650. */
  1651. /** @defgroup IWDG_Exported_Constants
  1652. * @{
  1653. */
  1654. /** @defgroup IWDG_WriteAccess
  1655. * @{
  1656. */
  1657. #define IWDG_WriteAccess_Enable ((uint16_t)0x5555)
  1658. #define IWDG_WriteAccess_Disable ((uint16_t)0x0000)
  1659. #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \
  1660. ((ACCESS) == IWDG_WriteAccess_Disable))
  1661. /**
  1662. * @}
  1663. */
  1664. /** @defgroup IWDG_prescaler
  1665. * @{
  1666. */
  1667. #define IWDG_Prescaler_4 ((uint8_t)0x00)
  1668. #define IWDG_Prescaler_8 ((uint8_t)0x01)
  1669. #define IWDG_Prescaler_16 ((uint8_t)0x02)
  1670. #define IWDG_Prescaler_32 ((uint8_t)0x03)
  1671. #define IWDG_Prescaler_64 ((uint8_t)0x04)
  1672. #define IWDG_Prescaler_128 ((uint8_t)0x05)
  1673. #define IWDG_Prescaler_256 ((uint8_t)0x06)
  1674. #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \
  1675. ((PRESCALER) == IWDG_Prescaler_8) || \
  1676. ((PRESCALER) == IWDG_Prescaler_16) || \
  1677. ((PRESCALER) == IWDG_Prescaler_32) || \
  1678. ((PRESCALER) == IWDG_Prescaler_64) || \
  1679. ((PRESCALER) == IWDG_Prescaler_128)|| \
  1680. ((PRESCALER) == IWDG_Prescaler_256))
  1681. /**
  1682. * @}
  1683. */
  1684. /** @defgroup IWDG_Flag
  1685. * @{
  1686. */
  1687. #define IWDG_FLAG_PVU ((uint16_t)0x0001)
  1688. #define IWDG_FLAG_RVU ((uint16_t)0x0002)
  1689. #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU))
  1690. #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF)
  1691. /**
  1692. * @}
  1693. */
  1694. /**
  1695. * @}
  1696. */
  1697. /** @defgroup IWDG_Exported_Macros
  1698. * @{
  1699. */
  1700. /**
  1701. * @}
  1702. */
  1703. /** @defgroup IWDG_Exported_Functions
  1704. * @{
  1705. */
  1706. void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess);
  1707. void IWDG_SetPrescaler(uint8_t IWDG_Prescaler);
  1708. void IWDG_SetReload(uint16_t Reload);
  1709. void IWDG_ReloadCounter(void);
  1710. void IWDG_Enable(void);
  1711. FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG);
  1712. #ifdef __cplusplus
  1713. }
  1714. #endif
  1715. #endif /* __STM32F10x_IWDG_H */
  1716. /**
  1717. * @}
  1718. */
  1719. /**
  1720. * @}
  1721. */
  1722. /**
  1723. * @}
  1724. */
  1725. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  1726. /**
  1727. ******************************************************************************
  1728. * @file stm32f10x_exti.h
  1729. * @author MCD Application Team
  1730. * @version V3.5.0
  1731. * @date 11-March-2011
  1732. * @brief This file contains all the functions prototypes for the EXTI firmware
  1733. * library.
  1734. ******************************************************************************
  1735. * @attention
  1736. *
  1737. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  1738. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  1739. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  1740. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  1741. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  1742. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  1743. *
  1744. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  1745. ******************************************************************************
  1746. */
  1747. /* Define to prevent recursive inclusion -------------------------------------*/
  1748. #ifndef __STM32F10x_EXTI_H
  1749. #define __STM32F10x_EXTI_H
  1750. #ifdef __cplusplus
  1751. extern "C" {
  1752. #endif
  1753. /* Includes ------------------------------------------------------------------*/
  1754. #include "stm32f10x.h"
  1755. /** @addtogroup STM32F10x_StdPeriph_Driver
  1756. * @{
  1757. */
  1758. /** @addtogroup EXTI
  1759. * @{
  1760. */
  1761. /** @defgroup EXTI_Exported_Types
  1762. * @{
  1763. */
  1764. /**
  1765. * @brief EXTI mode enumeration
  1766. */
  1767. typedef enum
  1768. {
  1769. EXTI_Mode_Interrupt = 0x00,
  1770. EXTI_Mode_Event = 0x04
  1771. }EXTIMode_TypeDef;
  1772. #define IS_EXTI_MODE(MODE) (((MODE) == EXTI_Mode_Interrupt) || ((MODE) == EXTI_Mode_Event))
  1773. /**
  1774. * @brief EXTI Trigger enumeration
  1775. */
  1776. typedef enum
  1777. {
  1778. EXTI_Trigger_Rising = 0x08,
  1779. EXTI_Trigger_Falling = 0x0C,
  1780. EXTI_Trigger_Rising_Falling = 0x10
  1781. }EXTITrigger_TypeDef;
  1782. #define IS_EXTI_TRIGGER(TRIGGER) (((TRIGGER) == EXTI_Trigger_Rising) || \
  1783. ((TRIGGER) == EXTI_Trigger_Falling) || \
  1784. ((TRIGGER) == EXTI_Trigger_Rising_Falling))
  1785. /**
  1786. * @brief EXTI Init Structure definition
  1787. */
  1788. typedef struct
  1789. {
  1790. uint32_t EXTI_Line; /*!< Specifies the EXTI lines to be enabled or disabled.
  1791. This parameter can be any combination of @ref EXTI_Lines */
  1792. EXTIMode_TypeDef EXTI_Mode; /*!< Specifies the mode for the EXTI lines.
  1793. This parameter can be a value of @ref EXTIMode_TypeDef */
  1794. EXTITrigger_TypeDef EXTI_Trigger; /*!< Specifies the trigger signal active edge for the EXTI lines.
  1795. This parameter can be a value of @ref EXTIMode_TypeDef */
  1796. FunctionalState EXTI_LineCmd; /*!< Specifies the new state of the selected EXTI lines.
  1797. This parameter can be set either to ENABLE or DISABLE */
  1798. }EXTI_InitTypeDef;
  1799. /**
  1800. * @}
  1801. */
  1802. /** @defgroup EXTI_Exported_Constants
  1803. * @{
  1804. */
  1805. /** @defgroup EXTI_Lines
  1806. * @{
  1807. */
  1808. #define EXTI_Line0 ((uint32_t)0x00001) /*!< External interrupt line 0 */
  1809. #define EXTI_Line1 ((uint32_t)0x00002) /*!< External interrupt line 1 */
  1810. #define EXTI_Line2 ((uint32_t)0x00004) /*!< External interrupt line 2 */
  1811. #define EXTI_Line3 ((uint32_t)0x00008) /*!< External interrupt line 3 */
  1812. #define EXTI_Line4 ((uint32_t)0x00010) /*!< External interrupt line 4 */
  1813. #define EXTI_Line5 ((uint32_t)0x00020) /*!< External interrupt line 5 */
  1814. #define EXTI_Line6 ((uint32_t)0x00040) /*!< External interrupt line 6 */
  1815. #define EXTI_Line7 ((uint32_t)0x00080) /*!< External interrupt line 7 */
  1816. #define EXTI_Line8 ((uint32_t)0x00100) /*!< External interrupt line 8 */
  1817. #define EXTI_Line9 ((uint32_t)0x00200) /*!< External interrupt line 9 */
  1818. #define EXTI_Line10 ((uint32_t)0x00400) /*!< External interrupt line 10 */
  1819. #define EXTI_Line11 ((uint32_t)0x00800) /*!< External interrupt line 11 */
  1820. #define EXTI_Line12 ((uint32_t)0x01000) /*!< External interrupt line 12 */
  1821. #define EXTI_Line13 ((uint32_t)0x02000) /*!< External interrupt line 13 */
  1822. #define EXTI_Line14 ((uint32_t)0x04000) /*!< External interrupt line 14 */
  1823. #define EXTI_Line15 ((uint32_t)0x08000) /*!< External interrupt line 15 */
  1824. #define EXTI_Line16 ((uint32_t)0x10000) /*!< External interrupt line 16 Connected to the PVD Output */
  1825. #define EXTI_Line17 ((uint32_t)0x20000) /*!< External interrupt line 17 Connected to the RTC Alarm event */
  1826. #define EXTI_Line18 ((uint32_t)0x40000) /*!< External interrupt line 18 Connected to the USB Device/USB OTG FS
  1827. Wakeup from suspend event */
  1828. #define EXTI_Line19 ((uint32_t)0x80000) /*!< External interrupt line 19 Connected to the Ethernet Wakeup event */
  1829. #define IS_EXTI_LINE(LINE) ((((LINE) & (uint32_t)0xFFF00000) == 0x00) && ((LINE) != (uint16_t)0x00))
  1830. #define IS_GET_EXTI_LINE(LINE) (((LINE) == EXTI_Line0) || ((LINE) == EXTI_Line1) || \
  1831. ((LINE) == EXTI_Line2) || ((LINE) == EXTI_Line3) || \
  1832. ((LINE) == EXTI_Line4) || ((LINE) == EXTI_Line5) || \
  1833. ((LINE) == EXTI_Line6) || ((LINE) == EXTI_Line7) || \
  1834. ((LINE) == EXTI_Line8) || ((LINE) == EXTI_Line9) || \
  1835. ((LINE) == EXTI_Line10) || ((LINE) == EXTI_Line11) || \
  1836. ((LINE) == EXTI_Line12) || ((LINE) == EXTI_Line13) || \
  1837. ((LINE) == EXTI_Line14) || ((LINE) == EXTI_Line15) || \
  1838. ((LINE) == EXTI_Line16) || ((LINE) == EXTI_Line17) || \
  1839. ((LINE) == EXTI_Line18) || ((LINE) == EXTI_Line19))
  1840. /**
  1841. * @}
  1842. */
  1843. /**
  1844. * @}
  1845. */
  1846. /** @defgroup EXTI_Exported_Macros
  1847. * @{
  1848. */
  1849. /**
  1850. * @}
  1851. */
  1852. /** @defgroup EXTI_Exported_Functions
  1853. * @{
  1854. */
  1855. void EXTI_DeInit(void);
  1856. void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct);
  1857. void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct);
  1858. void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line);
  1859. FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line);
  1860. void EXTI_ClearFlag(uint32_t EXTI_Line);
  1861. ITStatus EXTI_GetITStatus(uint32_t EXTI_Line);
  1862. void EXTI_ClearITPendingBit(uint32_t EXTI_Line);
  1863. #ifdef __cplusplus
  1864. }
  1865. #endif
  1866. #endif /* __STM32F10x_EXTI_H */
  1867. /**
  1868. * @}
  1869. */
  1870. /**
  1871. * @}
  1872. */
  1873. /**
  1874. * @}
  1875. */
  1876. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  1877. /**
  1878. ******************************************************************************
  1879. * @file stm32f10x_adc.h
  1880. * @author MCD Application Team
  1881. * @version V3.5.0
  1882. * @date 11-March-2011
  1883. * @brief This file contains all the functions prototypes for the ADC firmware
  1884. * library.
  1885. ******************************************************************************
  1886. * @attention
  1887. *
  1888. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  1889. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  1890. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  1891. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  1892. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  1893. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  1894. *
  1895. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  1896. ******************************************************************************
  1897. */
  1898. /* Define to prevent recursive inclusion -------------------------------------*/
  1899. #ifndef __STM32F10x_ADC_H
  1900. #define __STM32F10x_ADC_H
  1901. #ifdef __cplusplus
  1902. extern "C" {
  1903. #endif
  1904. /* Includes ------------------------------------------------------------------*/
  1905. #include "stm32f10x.h"
  1906. /** @addtogroup STM32F10x_StdPeriph_Driver
  1907. * @{
  1908. */
  1909. /** @addtogroup ADC
  1910. * @{
  1911. */
  1912. /** @defgroup ADC_Exported_Types
  1913. * @{
  1914. */
  1915. /**
  1916. * @brief ADC Init structure definition
  1917. */
  1918. typedef struct
  1919. {
  1920. uint32_t ADC_Mode; /*!< Configures the ADC to operate in independent or
  1921. dual mode.
  1922. This parameter can be a value of @ref ADC_mode */
  1923. FunctionalState ADC_ScanConvMode; /*!< Specifies whether the conversion is performed in
  1924. Scan (multichannels) or Single (one channel) mode.
  1925. This parameter can be set to ENABLE or DISABLE */
  1926. FunctionalState ADC_ContinuousConvMode; /*!< Specifies whether the conversion is performed in
  1927. Continuous or Single mode.
  1928. This parameter can be set to ENABLE or DISABLE. */
  1929. uint32_t ADC_ExternalTrigConv; /*!< Defines the external trigger used to start the analog
  1930. to digital conversion of regular channels. This parameter
  1931. can be a value of @ref ADC_external_trigger_sources_for_regular_channels_conversion */
  1932. uint32_t ADC_DataAlign; /*!< Specifies whether the ADC data alignment is left or right.
  1933. This parameter can be a value of @ref ADC_data_align */
  1934. uint8_t ADC_NbrOfChannel; /*!< Specifies the number of ADC channels that will be converted
  1935. using the sequencer for regular channel group.
  1936. This parameter must range from 1 to 16. */
  1937. }ADC_InitTypeDef;
  1938. /**
  1939. * @}
  1940. */
  1941. /** @defgroup ADC_Exported_Constants
  1942. * @{
  1943. */
  1944. #define IS_ADC_ALL_PERIPH(PERIPH) (((PERIPH) == ADC1) || \
  1945. ((PERIPH) == ADC2) || \
  1946. ((PERIPH) == ADC3))
  1947. #define IS_ADC_DMA_PERIPH(PERIPH) (((PERIPH) == ADC1) || \
  1948. ((PERIPH) == ADC3))
  1949. /** @defgroup ADC_mode
  1950. * @{
  1951. */
  1952. #define ADC_Mode_Independent ((uint32_t)0x00000000)
  1953. #define ADC_Mode_RegInjecSimult ((uint32_t)0x00010000)
  1954. #define ADC_Mode_RegSimult_AlterTrig ((uint32_t)0x00020000)
  1955. #define ADC_Mode_InjecSimult_FastInterl ((uint32_t)0x00030000)
  1956. #define ADC_Mode_InjecSimult_SlowInterl ((uint32_t)0x00040000)
  1957. #define ADC_Mode_InjecSimult ((uint32_t)0x00050000)
  1958. #define ADC_Mode_RegSimult ((uint32_t)0x00060000)
  1959. #define ADC_Mode_FastInterl ((uint32_t)0x00070000)
  1960. #define ADC_Mode_SlowInterl ((uint32_t)0x00080000)
  1961. #define ADC_Mode_AlterTrig ((uint32_t)0x00090000)
  1962. #define IS_ADC_MODE(MODE) (((MODE) == ADC_Mode_Independent) || \
  1963. ((MODE) == ADC_Mode_RegInjecSimult) || \
  1964. ((MODE) == ADC_Mode_RegSimult_AlterTrig) || \
  1965. ((MODE) == ADC_Mode_InjecSimult_FastInterl) || \
  1966. ((MODE) == ADC_Mode_InjecSimult_SlowInterl) || \
  1967. ((MODE) == ADC_Mode_InjecSimult) || \
  1968. ((MODE) == ADC_Mode_RegSimult) || \
  1969. ((MODE) == ADC_Mode_FastInterl) || \
  1970. ((MODE) == ADC_Mode_SlowInterl) || \
  1971. ((MODE) == ADC_Mode_AlterTrig))
  1972. /**
  1973. * @}
  1974. */
  1975. /** @defgroup ADC_external_trigger_sources_for_regular_channels_conversion
  1976. * @{
  1977. */
  1978. #define ADC_ExternalTrigConv_T1_CC1 ((uint32_t)0x00000000) /*!< For ADC1 and ADC2 */
  1979. #define ADC_ExternalTrigConv_T1_CC2 ((uint32_t)0x00020000) /*!< For ADC1 and ADC2 */
  1980. #define ADC_ExternalTrigConv_T2_CC2 ((uint32_t)0x00060000) /*!< For ADC1 and ADC2 */
  1981. #define ADC_ExternalTrigConv_T3_TRGO ((uint32_t)0x00080000) /*!< For ADC1 and ADC2 */
  1982. #define ADC_ExternalTrigConv_T4_CC4 ((uint32_t)0x000A0000) /*!< For ADC1 and ADC2 */
  1983. #define ADC_ExternalTrigConv_Ext_IT11_TIM8_TRGO ((uint32_t)0x000C0000) /*!< For ADC1 and ADC2 */
  1984. #define ADC_ExternalTrigConv_T1_CC3 ((uint32_t)0x00040000) /*!< For ADC1, ADC2 and ADC3 */
  1985. #define ADC_ExternalTrigConv_None ((uint32_t)0x000E0000) /*!< For ADC1, ADC2 and ADC3 */
  1986. #define ADC_ExternalTrigConv_T3_CC1 ((uint32_t)0x00000000) /*!< For ADC3 only */
  1987. #define ADC_ExternalTrigConv_T2_CC3 ((uint32_t)0x00020000) /*!< For ADC3 only */
  1988. #define ADC_ExternalTrigConv_T8_CC1 ((uint32_t)0x00060000) /*!< For ADC3 only */
  1989. #define ADC_ExternalTrigConv_T8_TRGO ((uint32_t)0x00080000) /*!< For ADC3 only */
  1990. #define ADC_ExternalTrigConv_T5_CC1 ((uint32_t)0x000A0000) /*!< For ADC3 only */
  1991. #define ADC_ExternalTrigConv_T5_CC3 ((uint32_t)0x000C0000) /*!< For ADC3 only */
  1992. #define IS_ADC_EXT_TRIG(REGTRIG) (((REGTRIG) == ADC_ExternalTrigConv_T1_CC1) || \
  1993. ((REGTRIG) == ADC_ExternalTrigConv_T1_CC2) || \
  1994. ((REGTRIG) == ADC_ExternalTrigConv_T1_CC3) || \
  1995. ((REGTRIG) == ADC_ExternalTrigConv_T2_CC2) || \
  1996. ((REGTRIG) == ADC_ExternalTrigConv_T3_TRGO) || \
  1997. ((REGTRIG) == ADC_ExternalTrigConv_T4_CC4) || \
  1998. ((REGTRIG) == ADC_ExternalTrigConv_Ext_IT11_TIM8_TRGO) || \
  1999. ((REGTRIG) == ADC_ExternalTrigConv_None) || \
  2000. ((REGTRIG) == ADC_ExternalTrigConv_T3_CC1) || \
  2001. ((REGTRIG) == ADC_ExternalTrigConv_T2_CC3) || \
  2002. ((REGTRIG) == ADC_ExternalTrigConv_T8_CC1) || \
  2003. ((REGTRIG) == ADC_ExternalTrigConv_T8_TRGO) || \
  2004. ((REGTRIG) == ADC_ExternalTrigConv_T5_CC1) || \
  2005. ((REGTRIG) == ADC_ExternalTrigConv_T5_CC3))
  2006. /**
  2007. * @}
  2008. */
  2009. /** @defgroup ADC_data_align
  2010. * @{
  2011. */
  2012. #define ADC_DataAlign_Right ((uint32_t)0x00000000)
  2013. #define ADC_DataAlign_Left ((uint32_t)0x00000800)
  2014. #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DataAlign_Right) || \
  2015. ((ALIGN) == ADC_DataAlign_Left))
  2016. /**
  2017. * @}
  2018. */
  2019. /** @defgroup ADC_channels
  2020. * @{
  2021. */
  2022. #define ADC_Channel_0 ((uint8_t)0x00)
  2023. #define ADC_Channel_1 ((uint8_t)0x01)
  2024. #define ADC_Channel_2 ((uint8_t)0x02)
  2025. #define ADC_Channel_3 ((uint8_t)0x03)
  2026. #define ADC_Channel_4 ((uint8_t)0x04)
  2027. #define ADC_Channel_5 ((uint8_t)0x05)
  2028. #define ADC_Channel_6 ((uint8_t)0x06)
  2029. #define ADC_Channel_7 ((uint8_t)0x07)
  2030. #define ADC_Channel_8 ((uint8_t)0x08)
  2031. #define ADC_Channel_9 ((uint8_t)0x09)
  2032. #define ADC_Channel_10 ((uint8_t)0x0A)
  2033. #define ADC_Channel_11 ((uint8_t)0x0B)
  2034. #define ADC_Channel_12 ((uint8_t)0x0C)
  2035. #define ADC_Channel_13 ((uint8_t)0x0D)
  2036. #define ADC_Channel_14 ((uint8_t)0x0E)
  2037. #define ADC_Channel_15 ((uint8_t)0x0F)
  2038. #define ADC_Channel_16 ((uint8_t)0x10)
  2039. #define ADC_Channel_17 ((uint8_t)0x11)
  2040. #define ADC_Channel_TempSensor ((uint8_t)ADC_Channel_16)
  2041. #define ADC_Channel_Vrefint ((uint8_t)ADC_Channel_17)
  2042. #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_Channel_0) || ((CHANNEL) == ADC_Channel_1) || \
  2043. ((CHANNEL) == ADC_Channel_2) || ((CHANNEL) == ADC_Channel_3) || \
  2044. ((CHANNEL) == ADC_Channel_4) || ((CHANNEL) == ADC_Channel_5) || \
  2045. ((CHANNEL) == ADC_Channel_6) || ((CHANNEL) == ADC_Channel_7) || \
  2046. ((CHANNEL) == ADC_Channel_8) || ((CHANNEL) == ADC_Channel_9) || \
  2047. ((CHANNEL) == ADC_Channel_10) || ((CHANNEL) == ADC_Channel_11) || \
  2048. ((CHANNEL) == ADC_Channel_12) || ((CHANNEL) == ADC_Channel_13) || \
  2049. ((CHANNEL) == ADC_Channel_14) || ((CHANNEL) == ADC_Channel_15) || \
  2050. ((CHANNEL) == ADC_Channel_16) || ((CHANNEL) == ADC_Channel_17))
  2051. /**
  2052. * @}
  2053. */
  2054. /** @defgroup ADC_sampling_time
  2055. * @{
  2056. */
  2057. #define ADC_SampleTime_1Cycles5 ((uint8_t)0x00)
  2058. #define ADC_SampleTime_7Cycles5 ((uint8_t)0x01)
  2059. #define ADC_SampleTime_13Cycles5 ((uint8_t)0x02)
  2060. #define ADC_SampleTime_28Cycles5 ((uint8_t)0x03)
  2061. #define ADC_SampleTime_41Cycles5 ((uint8_t)0x04)
  2062. #define ADC_SampleTime_55Cycles5 ((uint8_t)0x05)
  2063. #define ADC_SampleTime_71Cycles5 ((uint8_t)0x06)
  2064. #define ADC_SampleTime_239Cycles5 ((uint8_t)0x07)
  2065. #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SampleTime_1Cycles5) || \
  2066. ((TIME) == ADC_SampleTime_7Cycles5) || \
  2067. ((TIME) == ADC_SampleTime_13Cycles5) || \
  2068. ((TIME) == ADC_SampleTime_28Cycles5) || \
  2069. ((TIME) == ADC_SampleTime_41Cycles5) || \
  2070. ((TIME) == ADC_SampleTime_55Cycles5) || \
  2071. ((TIME) == ADC_SampleTime_71Cycles5) || \
  2072. ((TIME) == ADC_SampleTime_239Cycles5))
  2073. /**
  2074. * @}
  2075. */
  2076. /** @defgroup ADC_external_trigger_sources_for_injected_channels_conversion
  2077. * @{
  2078. */
  2079. #define ADC_ExternalTrigInjecConv_T2_TRGO ((uint32_t)0x00002000) /*!< For ADC1 and ADC2 */
  2080. #define ADC_ExternalTrigInjecConv_T2_CC1 ((uint32_t)0x00003000) /*!< For ADC1 and ADC2 */
  2081. #define ADC_ExternalTrigInjecConv_T3_CC4 ((uint32_t)0x00004000) /*!< For ADC1 and ADC2 */
  2082. #define ADC_ExternalTrigInjecConv_T4_TRGO ((uint32_t)0x00005000) /*!< For ADC1 and ADC2 */
  2083. #define ADC_ExternalTrigInjecConv_Ext_IT15_TIM8_CC4 ((uint32_t)0x00006000) /*!< For ADC1 and ADC2 */
  2084. #define ADC_ExternalTrigInjecConv_T1_TRGO ((uint32_t)0x00000000) /*!< For ADC1, ADC2 and ADC3 */
  2085. #define ADC_ExternalTrigInjecConv_T1_CC4 ((uint32_t)0x00001000) /*!< For ADC1, ADC2 and ADC3 */
  2086. #define ADC_ExternalTrigInjecConv_None ((uint32_t)0x00007000) /*!< For ADC1, ADC2 and ADC3 */
  2087. #define ADC_ExternalTrigInjecConv_T4_CC3 ((uint32_t)0x00002000) /*!< For ADC3 only */
  2088. #define ADC_ExternalTrigInjecConv_T8_CC2 ((uint32_t)0x00003000) /*!< For ADC3 only */
  2089. #define ADC_ExternalTrigInjecConv_T8_CC4 ((uint32_t)0x00004000) /*!< For ADC3 only */
  2090. #define ADC_ExternalTrigInjecConv_T5_TRGO ((uint32_t)0x00005000) /*!< For ADC3 only */
  2091. #define ADC_ExternalTrigInjecConv_T5_CC4 ((uint32_t)0x00006000) /*!< For ADC3 only */
  2092. #define IS_ADC_EXT_INJEC_TRIG(INJTRIG) (((INJTRIG) == ADC_ExternalTrigInjecConv_T1_TRGO) || \
  2093. ((INJTRIG) == ADC_ExternalTrigInjecConv_T1_CC4) || \
  2094. ((INJTRIG) == ADC_ExternalTrigInjecConv_T2_TRGO) || \
  2095. ((INJTRIG) == ADC_ExternalTrigInjecConv_T2_CC1) || \
  2096. ((INJTRIG) == ADC_ExternalTrigInjecConv_T3_CC4) || \
  2097. ((INJTRIG) == ADC_ExternalTrigInjecConv_T4_TRGO) || \
  2098. ((INJTRIG) == ADC_ExternalTrigInjecConv_Ext_IT15_TIM8_CC4) || \
  2099. ((INJTRIG) == ADC_ExternalTrigInjecConv_None) || \
  2100. ((INJTRIG) == ADC_ExternalTrigInjecConv_T4_CC3) || \
  2101. ((INJTRIG) == ADC_ExternalTrigInjecConv_T8_CC2) || \
  2102. ((INJTRIG) == ADC_ExternalTrigInjecConv_T8_CC4) || \
  2103. ((INJTRIG) == ADC_ExternalTrigInjecConv_T5_TRGO) || \
  2104. ((INJTRIG) == ADC_ExternalTrigInjecConv_T5_CC4))
  2105. /**
  2106. * @}
  2107. */
  2108. /** @defgroup ADC_injected_channel_selection
  2109. * @{
  2110. */
  2111. #define ADC_InjectedChannel_1 ((uint8_t)0x14)
  2112. #define ADC_InjectedChannel_2 ((uint8_t)0x18)
  2113. #define ADC_InjectedChannel_3 ((uint8_t)0x1C)
  2114. #define ADC_InjectedChannel_4 ((uint8_t)0x20)
  2115. #define IS_ADC_INJECTED_CHANNEL(CHANNEL) (((CHANNEL) == ADC_InjectedChannel_1) || \
  2116. ((CHANNEL) == ADC_InjectedChannel_2) || \
  2117. ((CHANNEL) == ADC_InjectedChannel_3) || \
  2118. ((CHANNEL) == ADC_InjectedChannel_4))
  2119. /**
  2120. * @}
  2121. */
  2122. /** @defgroup ADC_analog_watchdog_selection
  2123. * @{
  2124. */
  2125. #define ADC_AnalogWatchdog_SingleRegEnable ((uint32_t)0x00800200)
  2126. #define ADC_AnalogWatchdog_SingleInjecEnable ((uint32_t)0x00400200)
  2127. #define ADC_AnalogWatchdog_SingleRegOrInjecEnable ((uint32_t)0x00C00200)
  2128. #define ADC_AnalogWatchdog_AllRegEnable ((uint32_t)0x00800000)
  2129. #define ADC_AnalogWatchdog_AllInjecEnable ((uint32_t)0x00400000)
  2130. #define ADC_AnalogWatchdog_AllRegAllInjecEnable ((uint32_t)0x00C00000)
  2131. #define ADC_AnalogWatchdog_None ((uint32_t)0x00000000)
  2132. #define IS_ADC_ANALOG_WATCHDOG(WATCHDOG) (((WATCHDOG) == ADC_AnalogWatchdog_SingleRegEnable) || \
  2133. ((WATCHDOG) == ADC_AnalogWatchdog_SingleInjecEnable) || \
  2134. ((WATCHDOG) == ADC_AnalogWatchdog_SingleRegOrInjecEnable) || \
  2135. ((WATCHDOG) == ADC_AnalogWatchdog_AllRegEnable) || \
  2136. ((WATCHDOG) == ADC_AnalogWatchdog_AllInjecEnable) || \
  2137. ((WATCHDOG) == ADC_AnalogWatchdog_AllRegAllInjecEnable) || \
  2138. ((WATCHDOG) == ADC_AnalogWatchdog_None))
  2139. /**
  2140. * @}
  2141. */
  2142. /** @defgroup ADC_interrupts_definition
  2143. * @{
  2144. */
  2145. #define ADC_IT_EOC ((uint16_t)0x0220)
  2146. #define ADC_IT_AWD ((uint16_t)0x0140)
  2147. #define ADC_IT_JEOC ((uint16_t)0x0480)
  2148. #define IS_ADC_IT(IT) ((((IT) & (uint16_t)0xF81F) == 0x00) && ((IT) != 0x00))
  2149. #define IS_ADC_GET_IT(IT) (((IT) == ADC_IT_EOC) || ((IT) == ADC_IT_AWD) || \
  2150. ((IT) == ADC_IT_JEOC))
  2151. /**
  2152. * @}
  2153. */
  2154. /** @defgroup ADC_flags_definition
  2155. * @{
  2156. */
  2157. #define ADC_FLAG_AWD ((uint8_t)0x01)
  2158. #define ADC_FLAG_EOC ((uint8_t)0x02)
  2159. #define ADC_FLAG_JEOC ((uint8_t)0x04)
  2160. #define ADC_FLAG_JSTRT ((uint8_t)0x08)
  2161. #define ADC_FLAG_STRT ((uint8_t)0x10)
  2162. #define IS_ADC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint8_t)0xE0) == 0x00) && ((FLAG) != 0x00))
  2163. #define IS_ADC_GET_FLAG(FLAG) (((FLAG) == ADC_FLAG_AWD) || ((FLAG) == ADC_FLAG_EOC) || \
  2164. ((FLAG) == ADC_FLAG_JEOC) || ((FLAG)== ADC_FLAG_JSTRT) || \
  2165. ((FLAG) == ADC_FLAG_STRT))
  2166. /**
  2167. * @}
  2168. */
  2169. /** @defgroup ADC_thresholds
  2170. * @{
  2171. */
  2172. #define IS_ADC_THRESHOLD(THRESHOLD) ((THRESHOLD) <= 0xFFF)
  2173. /**
  2174. * @}
  2175. */
  2176. /** @defgroup ADC_injected_offset
  2177. * @{
  2178. */
  2179. #define IS_ADC_OFFSET(OFFSET) ((OFFSET) <= 0xFFF)
  2180. /**
  2181. * @}
  2182. */
  2183. /** @defgroup ADC_injected_length
  2184. * @{
  2185. */
  2186. #define IS_ADC_INJECTED_LENGTH(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x4))
  2187. /**
  2188. * @}
  2189. */
  2190. /** @defgroup ADC_injected_rank
  2191. * @{
  2192. */
  2193. #define IS_ADC_INJECTED_RANK(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x4))
  2194. /**
  2195. * @}
  2196. */
  2197. /** @defgroup ADC_regular_length
  2198. * @{
  2199. */
  2200. #define IS_ADC_REGULAR_LENGTH(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x10))
  2201. /**
  2202. * @}
  2203. */
  2204. /** @defgroup ADC_regular_rank
  2205. * @{
  2206. */
  2207. #define IS_ADC_REGULAR_RANK(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x10))
  2208. /**
  2209. * @}
  2210. */
  2211. /** @defgroup ADC_regular_discontinuous_mode_number
  2212. * @{
  2213. */
  2214. #define IS_ADC_REGULAR_DISC_NUMBER(NUMBER) (((NUMBER) >= 0x1) && ((NUMBER) <= 0x8))
  2215. /**
  2216. * @}
  2217. */
  2218. /**
  2219. * @}
  2220. */
  2221. /** @defgroup ADC_Exported_Macros
  2222. * @{
  2223. */
  2224. /**
  2225. * @}
  2226. */
  2227. /** @defgroup ADC_Exported_Functions
  2228. * @{
  2229. */
  2230. void ADC_DeInit(ADC_TypeDef* ADCx);
  2231. void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct);
  2232. void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct);
  2233. void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  2234. void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  2235. void ADC_ITConfig(ADC_TypeDef* ADCx, uint16_t ADC_IT, FunctionalState NewState);
  2236. void ADC_ResetCalibration(ADC_TypeDef* ADCx);
  2237. FlagStatus ADC_GetResetCalibrationStatus(ADC_TypeDef* ADCx);
  2238. void ADC_StartCalibration(ADC_TypeDef* ADCx);
  2239. FlagStatus ADC_GetCalibrationStatus(ADC_TypeDef* ADCx);
  2240. void ADC_SoftwareStartConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  2241. FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef* ADCx);
  2242. void ADC_DiscModeChannelCountConfig(ADC_TypeDef* ADCx, uint8_t Number);
  2243. void ADC_DiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  2244. void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
  2245. void ADC_ExternalTrigConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  2246. uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx);
  2247. uint32_t ADC_GetDualModeConversionValue(void);
  2248. void ADC_AutoInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  2249. void ADC_InjectedDiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  2250. void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef* ADCx, uint32_t ADC_ExternalTrigInjecConv);
  2251. void ADC_ExternalTrigInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  2252. void ADC_SoftwareStartInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  2253. FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef* ADCx);
  2254. void ADC_InjectedChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
  2255. void ADC_InjectedSequencerLengthConfig(ADC_TypeDef* ADCx, uint8_t Length);
  2256. void ADC_SetInjectedOffset(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel, uint16_t Offset);
  2257. uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel);
  2258. void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog);
  2259. void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold, uint16_t LowThreshold);
  2260. void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel);
  2261. void ADC_TempSensorVrefintCmd(FunctionalState NewState);
  2262. FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint8_t ADC_FLAG);
  2263. void ADC_ClearFlag(ADC_TypeDef* ADCx, uint8_t ADC_FLAG);
  2264. ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint16_t ADC_IT);
  2265. void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint16_t ADC_IT);
  2266. #ifdef __cplusplus
  2267. }
  2268. #endif
  2269. #endif /*__STM32F10x_ADC_H */
  2270. /**
  2271. * @}
  2272. */
  2273. /**
  2274. * @}
  2275. */
  2276. /**
  2277. * @}
  2278. */
  2279. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  2280. /**
  2281. ******************************************************************************
  2282. * @file stm32f10x_pwr.h
  2283. * @author MCD Application Team
  2284. * @version V3.5.0
  2285. * @date 11-March-2011
  2286. * @brief This file contains all the functions prototypes for the PWR firmware
  2287. * library.
  2288. ******************************************************************************
  2289. * @attention
  2290. *
  2291. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  2292. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  2293. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  2294. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  2295. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  2296. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  2297. *
  2298. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  2299. ******************************************************************************
  2300. */
  2301. /* Define to prevent recursive inclusion -------------------------------------*/
  2302. #ifndef __STM32F10x_PWR_H
  2303. #define __STM32F10x_PWR_H
  2304. #ifdef __cplusplus
  2305. extern "C" {
  2306. #endif
  2307. /* Includes ------------------------------------------------------------------*/
  2308. #include "stm32f10x.h"
  2309. /** @addtogroup STM32F10x_StdPeriph_Driver
  2310. * @{
  2311. */
  2312. /** @addtogroup PWR
  2313. * @{
  2314. */
  2315. /** @defgroup PWR_Exported_Types
  2316. * @{
  2317. */
  2318. /**
  2319. * @}
  2320. */
  2321. /** @defgroup PWR_Exported_Constants
  2322. * @{
  2323. */
  2324. /** @defgroup PVD_detection_level
  2325. * @{
  2326. */
  2327. #define PWR_PVDLevel_2V2 ((uint32_t)0x00000000)
  2328. #define PWR_PVDLevel_2V3 ((uint32_t)0x00000020)
  2329. #define PWR_PVDLevel_2V4 ((uint32_t)0x00000040)
  2330. #define PWR_PVDLevel_2V5 ((uint32_t)0x00000060)
  2331. #define PWR_PVDLevel_2V6 ((uint32_t)0x00000080)
  2332. #define PWR_PVDLevel_2V7 ((uint32_t)0x000000A0)
  2333. #define PWR_PVDLevel_2V8 ((uint32_t)0x000000C0)
  2334. #define PWR_PVDLevel_2V9 ((uint32_t)0x000000E0)
  2335. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_2V2) || ((LEVEL) == PWR_PVDLevel_2V3)|| \
  2336. ((LEVEL) == PWR_PVDLevel_2V4) || ((LEVEL) == PWR_PVDLevel_2V5)|| \
  2337. ((LEVEL) == PWR_PVDLevel_2V6) || ((LEVEL) == PWR_PVDLevel_2V7)|| \
  2338. ((LEVEL) == PWR_PVDLevel_2V8) || ((LEVEL) == PWR_PVDLevel_2V9))
  2339. /**
  2340. * @}
  2341. */
  2342. /** @defgroup Regulator_state_is_STOP_mode
  2343. * @{
  2344. */
  2345. #define PWR_Regulator_ON ((uint32_t)0x00000000)
  2346. #define PWR_Regulator_LowPower ((uint32_t)0x00000001)
  2347. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \
  2348. ((REGULATOR) == PWR_Regulator_LowPower))
  2349. /**
  2350. * @}
  2351. */
  2352. /** @defgroup STOP_mode_entry
  2353. * @{
  2354. */
  2355. #define PWR_STOPEntry_WFI ((uint8_t)0x01)
  2356. #define PWR_STOPEntry_WFE ((uint8_t)0x02)
  2357. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE))
  2358. /**
  2359. * @}
  2360. */
  2361. /** @defgroup PWR_Flag
  2362. * @{
  2363. */
  2364. #define PWR_FLAG_WU ((uint32_t)0x00000001)
  2365. #define PWR_FLAG_SB ((uint32_t)0x00000002)
  2366. #define PWR_FLAG_PVDO ((uint32_t)0x00000004)
  2367. #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \
  2368. ((FLAG) == PWR_FLAG_PVDO))
  2369. #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB))
  2370. /**
  2371. * @}
  2372. */
  2373. /**
  2374. * @}
  2375. */
  2376. /** @defgroup PWR_Exported_Macros
  2377. * @{
  2378. */
  2379. /**
  2380. * @}
  2381. */
  2382. /** @defgroup PWR_Exported_Functions
  2383. * @{
  2384. */
  2385. void PWR_DeInit(void);
  2386. void PWR_BackupAccessCmd(FunctionalState NewState);
  2387. void PWR_PVDCmd(FunctionalState NewState);
  2388. void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel);
  2389. void PWR_WakeUpPinCmd(FunctionalState NewState);
  2390. void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);
  2391. void PWR_EnterSTANDBYMode(void);
  2392. FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG);
  2393. void PWR_ClearFlag(uint32_t PWR_FLAG);
  2394. #ifdef __cplusplus
  2395. }
  2396. #endif
  2397. #endif /* __STM32F10x_PWR_H */
  2398. /**
  2399. * @}
  2400. */
  2401. /**
  2402. * @}
  2403. */
  2404. /**
  2405. * @}
  2406. */
  2407. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  2408. /**
  2409. ******************************************************************************
  2410. * @file stm32f10x_usart.h
  2411. * @author MCD Application Team
  2412. * @version V3.5.0
  2413. * @date 11-March-2011
  2414. * @brief This file contains all the functions prototypes for the USART
  2415. * firmware library.
  2416. ******************************************************************************
  2417. * @attention
  2418. *
  2419. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  2420. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  2421. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  2422. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  2423. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  2424. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  2425. *
  2426. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  2427. ******************************************************************************
  2428. */
  2429. /* Define to prevent recursive inclusion -------------------------------------*/
  2430. #ifndef __STM32F10x_USART_H
  2431. #define __STM32F10x_USART_H
  2432. #ifdef __cplusplus
  2433. extern "C" {
  2434. #endif
  2435. /* Includes ------------------------------------------------------------------*/
  2436. #include "stm32f10x.h"
  2437. /** @addtogroup STM32F10x_StdPeriph_Driver
  2438. * @{
  2439. */
  2440. /** @addtogroup USART
  2441. * @{
  2442. */
  2443. /** @defgroup USART_Exported_Types
  2444. * @{
  2445. */
  2446. /**
  2447. * @brief USART Init Structure definition
  2448. */
  2449. typedef struct
  2450. {
  2451. uint32_t USART_BaudRate; /*!< This member configures the USART communication baud rate.
  2452. The baud rate is computed using the following formula:
  2453. - IntegerDivider = ((PCLKx) / (16 * (USART_InitStruct->USART_BaudRate)))
  2454. - FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 16) + 0.5 */
  2455. uint16_t USART_WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
  2456. This parameter can be a value of @ref USART_Word_Length */
  2457. uint16_t USART_StopBits; /*!< Specifies the number of stop bits transmitted.
  2458. This parameter can be a value of @ref USART_Stop_Bits */
  2459. uint16_t USART_Parity; /*!< Specifies the parity mode.
  2460. This parameter can be a value of @ref USART_Parity
  2461. @note When parity is enabled, the computed parity is inserted
  2462. at the MSB position of the transmitted data (9th bit when
  2463. the word length is set to 9 data bits; 8th bit when the
  2464. word length is set to 8 data bits). */
  2465. uint16_t USART_Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
  2466. This parameter can be a value of @ref USART_Mode */
  2467. uint16_t USART_HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled
  2468. or disabled.
  2469. This parameter can be a value of @ref USART_Hardware_Flow_Control */
  2470. } USART_InitTypeDef;
  2471. /**
  2472. * @brief USART Clock Init Structure definition
  2473. */
  2474. typedef struct
  2475. {
  2476. uint16_t USART_Clock; /*!< Specifies whether the USART clock is enabled or disabled.
  2477. This parameter can be a value of @ref USART_Clock */
  2478. uint16_t USART_CPOL; /*!< Specifies the steady state value of the serial clock.
  2479. This parameter can be a value of @ref USART_Clock_Polarity */
  2480. uint16_t USART_CPHA; /*!< Specifies the clock transition on which the bit capture is made.
  2481. This parameter can be a value of @ref USART_Clock_Phase */
  2482. uint16_t USART_LastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
  2483. data bit (MSB) has to be output on the SCLK pin in synchronous mode.
  2484. This parameter can be a value of @ref USART_Last_Bit */
  2485. } USART_ClockInitTypeDef;
  2486. /**
  2487. * @}
  2488. */
  2489. /** @defgroup USART_Exported_Constants
  2490. * @{
  2491. */
  2492. #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \
  2493. ((PERIPH) == USART2) || \
  2494. ((PERIPH) == USART3) || \
  2495. ((PERIPH) == UART4) || \
  2496. ((PERIPH) == UART5))
  2497. #define IS_USART_123_PERIPH(PERIPH) (((PERIPH) == USART1) || \
  2498. ((PERIPH) == USART2) || \
  2499. ((PERIPH) == USART3))
  2500. #define IS_USART_1234_PERIPH(PERIPH) (((PERIPH) == USART1) || \
  2501. ((PERIPH) == USART2) || \
  2502. ((PERIPH) == USART3) || \
  2503. ((PERIPH) == UART4))
  2504. /** @defgroup USART_Word_Length
  2505. * @{
  2506. */
  2507. #define USART_WordLength_8b ((uint16_t)0x0000)
  2508. #define USART_WordLength_9b ((uint16_t)0x1000)
  2509. #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \
  2510. ((LENGTH) == USART_WordLength_9b))
  2511. /**
  2512. * @}
  2513. */
  2514. /** @defgroup USART_Stop_Bits
  2515. * @{
  2516. */
  2517. #define USART_StopBits_1 ((uint16_t)0x0000)
  2518. #define USART_StopBits_0_5 ((uint16_t)0x1000)
  2519. #define USART_StopBits_2 ((uint16_t)0x2000)
  2520. #define USART_StopBits_1_5 ((uint16_t)0x3000)
  2521. #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \
  2522. ((STOPBITS) == USART_StopBits_0_5) || \
  2523. ((STOPBITS) == USART_StopBits_2) || \
  2524. ((STOPBITS) == USART_StopBits_1_5))
  2525. /**
  2526. * @}
  2527. */
  2528. /** @defgroup USART_Parity
  2529. * @{
  2530. */
  2531. #define USART_Parity_No ((uint16_t)0x0000)
  2532. #define USART_Parity_Even ((uint16_t)0x0400)
  2533. #define USART_Parity_Odd ((uint16_t)0x0600)
  2534. #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \
  2535. ((PARITY) == USART_Parity_Even) || \
  2536. ((PARITY) == USART_Parity_Odd))
  2537. /**
  2538. * @}
  2539. */
  2540. /** @defgroup USART_Mode
  2541. * @{
  2542. */
  2543. #define USART_Mode_Rx ((uint16_t)0x0004)
  2544. #define USART_Mode_Tx ((uint16_t)0x0008)
  2545. #define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00))
  2546. /**
  2547. * @}
  2548. */
  2549. /** @defgroup USART_Hardware_Flow_Control
  2550. * @{
  2551. */
  2552. #define USART_HardwareFlowControl_None ((uint16_t)0x0000)
  2553. #define USART_HardwareFlowControl_RTS ((uint16_t)0x0100)
  2554. #define USART_HardwareFlowControl_CTS ((uint16_t)0x0200)
  2555. #define USART_HardwareFlowControl_RTS_CTS ((uint16_t)0x0300)
  2556. #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\
  2557. (((CONTROL) == USART_HardwareFlowControl_None) || \
  2558. ((CONTROL) == USART_HardwareFlowControl_RTS) || \
  2559. ((CONTROL) == USART_HardwareFlowControl_CTS) || \
  2560. ((CONTROL) == USART_HardwareFlowControl_RTS_CTS))
  2561. /**
  2562. * @}
  2563. */
  2564. /** @defgroup USART_Clock
  2565. * @{
  2566. */
  2567. #define USART_Clock_Disable ((uint16_t)0x0000)
  2568. #define USART_Clock_Enable ((uint16_t)0x0800)
  2569. #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \
  2570. ((CLOCK) == USART_Clock_Enable))
  2571. /**
  2572. * @}
  2573. */
  2574. /** @defgroup USART_Clock_Polarity
  2575. * @{
  2576. */
  2577. #define USART_CPOL_Low ((uint16_t)0x0000)
  2578. #define USART_CPOL_High ((uint16_t)0x0400)
  2579. #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High))
  2580. /**
  2581. * @}
  2582. */
  2583. /** @defgroup USART_Clock_Phase
  2584. * @{
  2585. */
  2586. #define USART_CPHA_1Edge ((uint16_t)0x0000)
  2587. #define USART_CPHA_2Edge ((uint16_t)0x0200)
  2588. #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge))
  2589. /**
  2590. * @}
  2591. */
  2592. /** @defgroup USART_Last_Bit
  2593. * @{
  2594. */
  2595. #define USART_LastBit_Disable ((uint16_t)0x0000)
  2596. #define USART_LastBit_Enable ((uint16_t)0x0100)
  2597. #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \
  2598. ((LASTBIT) == USART_LastBit_Enable))
  2599. /**
  2600. * @}
  2601. */
  2602. /** @defgroup USART_Interrupt_definition
  2603. * @{
  2604. */
  2605. #define USART_IT_PE ((uint16_t)0x0028)
  2606. #define USART_IT_TXE ((uint16_t)0x0727)
  2607. #define USART_IT_TC ((uint16_t)0x0626)
  2608. #define USART_IT_RXNE ((uint16_t)0x0525)
  2609. #define USART_IT_IDLE ((uint16_t)0x0424)
  2610. #define USART_IT_LBD ((uint16_t)0x0846)
  2611. #define USART_IT_CTS ((uint16_t)0x096A)
  2612. #define USART_IT_ERR ((uint16_t)0x0060)
  2613. #define USART_IT_ORE ((uint16_t)0x0360)
  2614. #define USART_IT_NE ((uint16_t)0x0260)
  2615. #define USART_IT_FE ((uint16_t)0x0160)
  2616. #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
  2617. ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
  2618. ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
  2619. ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR))
  2620. #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
  2621. ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
  2622. ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
  2623. ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \
  2624. ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE))
  2625. #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
  2626. ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS))
  2627. /**
  2628. * @}
  2629. */
  2630. /** @defgroup USART_DMA_Requests
  2631. * @{
  2632. */
  2633. #define USART_DMAReq_Tx ((uint16_t)0x0080)
  2634. #define USART_DMAReq_Rx ((uint16_t)0x0040)
  2635. #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00))
  2636. /**
  2637. * @}
  2638. */
  2639. /** @defgroup USART_WakeUp_methods
  2640. * @{
  2641. */
  2642. #define USART_WakeUp_IdleLine ((uint16_t)0x0000)
  2643. #define USART_WakeUp_AddressMark ((uint16_t)0x0800)
  2644. #define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \
  2645. ((WAKEUP) == USART_WakeUp_AddressMark))
  2646. /**
  2647. * @}
  2648. */
  2649. /** @defgroup USART_LIN_Break_Detection_Length
  2650. * @{
  2651. */
  2652. #define USART_LINBreakDetectLength_10b ((uint16_t)0x0000)
  2653. #define USART_LINBreakDetectLength_11b ((uint16_t)0x0020)
  2654. #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \
  2655. (((LENGTH) == USART_LINBreakDetectLength_10b) || \
  2656. ((LENGTH) == USART_LINBreakDetectLength_11b))
  2657. /**
  2658. * @}
  2659. */
  2660. /** @defgroup USART_IrDA_Low_Power
  2661. * @{
  2662. */
  2663. #define USART_IrDAMode_LowPower ((uint16_t)0x0004)
  2664. #define USART_IrDAMode_Normal ((uint16_t)0x0000)
  2665. #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \
  2666. ((MODE) == USART_IrDAMode_Normal))
  2667. /**
  2668. * @}
  2669. */
  2670. /** @defgroup USART_Flags
  2671. * @{
  2672. */
  2673. #define USART_FLAG_CTS ((uint16_t)0x0200)
  2674. #define USART_FLAG_LBD ((uint16_t)0x0100)
  2675. #define USART_FLAG_TXE ((uint16_t)0x0080)
  2676. #define USART_FLAG_TC ((uint16_t)0x0040)
  2677. #define USART_FLAG_RXNE ((uint16_t)0x0020)
  2678. #define USART_FLAG_IDLE ((uint16_t)0x0010)
  2679. #define USART_FLAG_ORE ((uint16_t)0x0008)
  2680. #define USART_FLAG_NE ((uint16_t)0x0004)
  2681. #define USART_FLAG_FE ((uint16_t)0x0002)
  2682. #define USART_FLAG_PE ((uint16_t)0x0001)
  2683. #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \
  2684. ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \
  2685. ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \
  2686. ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \
  2687. ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE))
  2688. #define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00))
  2689. #define IS_USART_PERIPH_FLAG(PERIPH, USART_FLAG) ((((*(uint32_t*)&(PERIPH)) != UART4_BASE) &&\
  2690. ((*(uint32_t*)&(PERIPH)) != UART5_BASE)) \
  2691. || ((USART_FLAG) != USART_FLAG_CTS))
  2692. #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 0x0044AA21))
  2693. #define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF)
  2694. #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF)
  2695. /**
  2696. * @}
  2697. */
  2698. /**
  2699. * @}
  2700. */
  2701. /** @defgroup USART_Exported_Macros
  2702. * @{
  2703. */
  2704. /**
  2705. * @}
  2706. */
  2707. /** @defgroup USART_Exported_Functions
  2708. * @{
  2709. */
  2710. void USART_DeInit(USART_TypeDef* USARTx);
  2711. void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);
  2712. void USART_StructInit(USART_InitTypeDef* USART_InitStruct);
  2713. void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct);
  2714. void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct);
  2715. void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
  2716. void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState);
  2717. void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState);
  2718. void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address);
  2719. void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp);
  2720. void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  2721. void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength);
  2722. void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  2723. void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);
  2724. uint16_t USART_ReceiveData(USART_TypeDef* USARTx);
  2725. void USART_SendBreak(USART_TypeDef* USARTx);
  2726. void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime);
  2727. void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler);
  2728. void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  2729. void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  2730. void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  2731. void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
  2732. void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  2733. void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode);
  2734. void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState);
  2735. FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);
  2736. void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG);
  2737. ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT);
  2738. void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);
  2739. #ifdef __cplusplus
  2740. }
  2741. #endif
  2742. #endif /* __STM32F10x_USART_H */
  2743. /**
  2744. * @}
  2745. */
  2746. /**
  2747. * @}
  2748. */
  2749. /**
  2750. * @}
  2751. */
  2752. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  2753. /**
  2754. ******************************************************************************
  2755. * @file stm32f10x_dbgmcu.h
  2756. * @author MCD Application Team
  2757. * @version V3.5.0
  2758. * @date 11-March-2011
  2759. * @brief This file contains all the functions prototypes for the DBGMCU
  2760. * firmware library.
  2761. ******************************************************************************
  2762. * @attention
  2763. *
  2764. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  2765. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  2766. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  2767. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  2768. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  2769. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  2770. *
  2771. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  2772. ******************************************************************************
  2773. */
  2774. /* Define to prevent recursive inclusion -------------------------------------*/
  2775. #ifndef __STM32F10x_DBGMCU_H
  2776. #define __STM32F10x_DBGMCU_H
  2777. #ifdef __cplusplus
  2778. extern "C" {
  2779. #endif
  2780. /* Includes ------------------------------------------------------------------*/
  2781. #include "stm32f10x.h"
  2782. /** @addtogroup STM32F10x_StdPeriph_Driver
  2783. * @{
  2784. */
  2785. /** @addtogroup DBGMCU
  2786. * @{
  2787. */
  2788. /** @defgroup DBGMCU_Exported_Types
  2789. * @{
  2790. */
  2791. /**
  2792. * @}
  2793. */
  2794. /** @defgroup DBGMCU_Exported_Constants
  2795. * @{
  2796. */
  2797. #define DBGMCU_SLEEP ((uint32_t)0x00000001)
  2798. #define DBGMCU_STOP ((uint32_t)0x00000002)
  2799. #define DBGMCU_STANDBY ((uint32_t)0x00000004)
  2800. #define DBGMCU_IWDG_STOP ((uint32_t)0x00000100)
  2801. #define DBGMCU_WWDG_STOP ((uint32_t)0x00000200)
  2802. #define DBGMCU_TIM1_STOP ((uint32_t)0x00000400)
  2803. #define DBGMCU_TIM2_STOP ((uint32_t)0x00000800)
  2804. #define DBGMCU_TIM3_STOP ((uint32_t)0x00001000)
  2805. #define DBGMCU_TIM4_STOP ((uint32_t)0x00002000)
  2806. #define DBGMCU_CAN1_STOP ((uint32_t)0x00004000)
  2807. #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00008000)
  2808. #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00010000)
  2809. #define DBGMCU_TIM8_STOP ((uint32_t)0x00020000)
  2810. #define DBGMCU_TIM5_STOP ((uint32_t)0x00040000)
  2811. #define DBGMCU_TIM6_STOP ((uint32_t)0x00080000)
  2812. #define DBGMCU_TIM7_STOP ((uint32_t)0x00100000)
  2813. #define DBGMCU_CAN2_STOP ((uint32_t)0x00200000)
  2814. #define DBGMCU_TIM15_STOP ((uint32_t)0x00400000)
  2815. #define DBGMCU_TIM16_STOP ((uint32_t)0x00800000)
  2816. #define DBGMCU_TIM17_STOP ((uint32_t)0x01000000)
  2817. #define DBGMCU_TIM12_STOP ((uint32_t)0x02000000)
  2818. #define DBGMCU_TIM13_STOP ((uint32_t)0x04000000)
  2819. #define DBGMCU_TIM14_STOP ((uint32_t)0x08000000)
  2820. #define DBGMCU_TIM9_STOP ((uint32_t)0x10000000)
  2821. #define DBGMCU_TIM10_STOP ((uint32_t)0x20000000)
  2822. #define DBGMCU_TIM11_STOP ((uint32_t)0x40000000)
  2823. #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0x800000F8) == 0x00) && ((PERIPH) != 0x00))
  2824. /**
  2825. * @}
  2826. */
  2827. /** @defgroup DBGMCU_Exported_Macros
  2828. * @{
  2829. */
  2830. /**
  2831. * @}
  2832. */
  2833. /** @defgroup DBGMCU_Exported_Functions
  2834. * @{
  2835. */
  2836. uint32_t DBGMCU_GetREVID(void);
  2837. uint32_t DBGMCU_GetDEVID(void);
  2838. void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState);
  2839. #ifdef __cplusplus
  2840. }
  2841. #endif
  2842. #endif /* __STM32F10x_DBGMCU_H */
  2843. /**
  2844. * @}
  2845. */
  2846. /**
  2847. * @}
  2848. */
  2849. /**
  2850. * @}
  2851. */
  2852. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  2853. /**
  2854. ******************************************************************************
  2855. * @file stm32f10x_sdio.h
  2856. * @author MCD Application Team
  2857. * @version V3.5.0
  2858. * @date 11-March-2011
  2859. * @brief This file contains all the functions prototypes for the SDIO firmware
  2860. * library.
  2861. ******************************************************************************
  2862. * @attention
  2863. *
  2864. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  2865. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  2866. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  2867. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  2868. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  2869. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  2870. *
  2871. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  2872. ******************************************************************************
  2873. */
  2874. /* Define to prevent recursive inclusion -------------------------------------*/
  2875. #ifndef __STM32F10x_SDIO_H
  2876. #define __STM32F10x_SDIO_H
  2877. #ifdef __cplusplus
  2878. extern "C" {
  2879. #endif
  2880. /* Includes ------------------------------------------------------------------*/
  2881. #include "stm32f10x.h"
  2882. /** @addtogroup STM32F10x_StdPeriph_Driver
  2883. * @{
  2884. */
  2885. /** @addtogroup SDIO
  2886. * @{
  2887. */
  2888. /** @defgroup SDIO_Exported_Types
  2889. * @{
  2890. */
  2891. typedef struct
  2892. {
  2893. uint32_t SDIO_ClockEdge; /*!< Specifies the clock transition on which the bit capture is made.
  2894. This parameter can be a value of @ref SDIO_Clock_Edge */
  2895. uint32_t SDIO_ClockBypass; /*!< Specifies whether the SDIO Clock divider bypass is
  2896. enabled or disabled.
  2897. This parameter can be a value of @ref SDIO_Clock_Bypass */
  2898. uint32_t SDIO_ClockPowerSave; /*!< Specifies whether SDIO Clock output is enabled or
  2899. disabled when the bus is idle.
  2900. This parameter can be a value of @ref SDIO_Clock_Power_Save */
  2901. uint32_t SDIO_BusWide; /*!< Specifies the SDIO bus width.
  2902. This parameter can be a value of @ref SDIO_Bus_Wide */
  2903. uint32_t SDIO_HardwareFlowControl; /*!< Specifies whether the SDIO hardware flow control is enabled or disabled.
  2904. This parameter can be a value of @ref SDIO_Hardware_Flow_Control */
  2905. uint8_t SDIO_ClockDiv; /*!< Specifies the clock frequency of the SDIO controller.
  2906. This parameter can be a value between 0x00 and 0xFF. */
  2907. } SDIO_InitTypeDef;
  2908. typedef struct
  2909. {
  2910. uint32_t SDIO_Argument; /*!< Specifies the SDIO command argument which is sent
  2911. to a card as part of a command message. If a command
  2912. contains an argument, it must be loaded into this register
  2913. before writing the command to the command register */
  2914. uint32_t SDIO_CmdIndex; /*!< Specifies the SDIO command index. It must be lower than 0x40. */
  2915. uint32_t SDIO_Response; /*!< Specifies the SDIO response type.
  2916. This parameter can be a value of @ref SDIO_Response_Type */
  2917. uint32_t SDIO_Wait; /*!< Specifies whether SDIO wait-for-interrupt request is enabled or disabled.
  2918. This parameter can be a value of @ref SDIO_Wait_Interrupt_State */
  2919. uint32_t SDIO_CPSM; /*!< Specifies whether SDIO Command path state machine (CPSM)
  2920. is enabled or disabled.
  2921. This parameter can be a value of @ref SDIO_CPSM_State */
  2922. } SDIO_CmdInitTypeDef;
  2923. typedef struct
  2924. {
  2925. uint32_t SDIO_DataTimeOut; /*!< Specifies the data timeout period in card bus clock periods. */
  2926. uint32_t SDIO_DataLength; /*!< Specifies the number of data bytes to be transferred. */
  2927. uint32_t SDIO_DataBlockSize; /*!< Specifies the data block size for block transfer.
  2928. This parameter can be a value of @ref SDIO_Data_Block_Size */
  2929. uint32_t SDIO_TransferDir; /*!< Specifies the data transfer direction, whether the transfer
  2930. is a read or write.
  2931. This parameter can be a value of @ref SDIO_Transfer_Direction */
  2932. uint32_t SDIO_TransferMode; /*!< Specifies whether data transfer is in stream or block mode.
  2933. This parameter can be a value of @ref SDIO_Transfer_Type */
  2934. uint32_t SDIO_DPSM; /*!< Specifies whether SDIO Data path state machine (DPSM)
  2935. is enabled or disabled.
  2936. This parameter can be a value of @ref SDIO_DPSM_State */
  2937. } SDIO_DataInitTypeDef;
  2938. /**
  2939. * @}
  2940. */
  2941. /** @defgroup SDIO_Exported_Constants
  2942. * @{
  2943. */
  2944. /** @defgroup SDIO_Clock_Edge
  2945. * @{
  2946. */
  2947. #define SDIO_ClockEdge_Rising ((uint32_t)0x00000000)
  2948. #define SDIO_ClockEdge_Falling ((uint32_t)0x00002000)
  2949. #define IS_SDIO_CLOCK_EDGE(EDGE) (((EDGE) == SDIO_ClockEdge_Rising) || \
  2950. ((EDGE) == SDIO_ClockEdge_Falling))
  2951. /**
  2952. * @}
  2953. */
  2954. /** @defgroup SDIO_Clock_Bypass
  2955. * @{
  2956. */
  2957. #define SDIO_ClockBypass_Disable ((uint32_t)0x00000000)
  2958. #define SDIO_ClockBypass_Enable ((uint32_t)0x00000400)
  2959. #define IS_SDIO_CLOCK_BYPASS(BYPASS) (((BYPASS) == SDIO_ClockBypass_Disable) || \
  2960. ((BYPASS) == SDIO_ClockBypass_Enable))
  2961. /**
  2962. * @}
  2963. */
  2964. /** @defgroup SDIO_Clock_Power_Save
  2965. * @{
  2966. */
  2967. #define SDIO_ClockPowerSave_Disable ((uint32_t)0x00000000)
  2968. #define SDIO_ClockPowerSave_Enable ((uint32_t)0x00000200)
  2969. #define IS_SDIO_CLOCK_POWER_SAVE(SAVE) (((SAVE) == SDIO_ClockPowerSave_Disable) || \
  2970. ((SAVE) == SDIO_ClockPowerSave_Enable))
  2971. /**
  2972. * @}
  2973. */
  2974. /** @defgroup SDIO_Bus_Wide
  2975. * @{
  2976. */
  2977. #define SDIO_BusWide_1b ((uint32_t)0x00000000)
  2978. #define SDIO_BusWide_4b ((uint32_t)0x00000800)
  2979. #define SDIO_BusWide_8b ((uint32_t)0x00001000)
  2980. #define IS_SDIO_BUS_WIDE(WIDE) (((WIDE) == SDIO_BusWide_1b) || ((WIDE) == SDIO_BusWide_4b) || \
  2981. ((WIDE) == SDIO_BusWide_8b))
  2982. /**
  2983. * @}
  2984. */
  2985. /** @defgroup SDIO_Hardware_Flow_Control
  2986. * @{
  2987. */
  2988. #define SDIO_HardwareFlowControl_Disable ((uint32_t)0x00000000)
  2989. #define SDIO_HardwareFlowControl_Enable ((uint32_t)0x00004000)
  2990. #define IS_SDIO_HARDWARE_FLOW_CONTROL(CONTROL) (((CONTROL) == SDIO_HardwareFlowControl_Disable) || \
  2991. ((CONTROL) == SDIO_HardwareFlowControl_Enable))
  2992. /**
  2993. * @}
  2994. */
  2995. /** @defgroup SDIO_Power_State
  2996. * @{
  2997. */
  2998. #define SDIO_PowerState_OFF ((uint32_t)0x00000000)
  2999. #define SDIO_PowerState_ON ((uint32_t)0x00000003)
  3000. #define IS_SDIO_POWER_STATE(STATE) (((STATE) == SDIO_PowerState_OFF) || ((STATE) == SDIO_PowerState_ON))
  3001. /**
  3002. * @}
  3003. */
  3004. /** @defgroup SDIO_Interrupt_sources
  3005. * @{
  3006. */
  3007. #define SDIO_IT_CCRCFAIL ((uint32_t)0x00000001)
  3008. #define SDIO_IT_DCRCFAIL ((uint32_t)0x00000002)
  3009. #define SDIO_IT_CTIMEOUT ((uint32_t)0x00000004)
  3010. #define SDIO_IT_DTIMEOUT ((uint32_t)0x00000008)
  3011. #define SDIO_IT_TXUNDERR ((uint32_t)0x00000010)
  3012. #define SDIO_IT_RXOVERR ((uint32_t)0x00000020)
  3013. #define SDIO_IT_CMDREND ((uint32_t)0x00000040)
  3014. #define SDIO_IT_CMDSENT ((uint32_t)0x00000080)
  3015. #define SDIO_IT_DATAEND ((uint32_t)0x00000100)
  3016. #define SDIO_IT_STBITERR ((uint32_t)0x00000200)
  3017. #define SDIO_IT_DBCKEND ((uint32_t)0x00000400)
  3018. #define SDIO_IT_CMDACT ((uint32_t)0x00000800)
  3019. #define SDIO_IT_TXACT ((uint32_t)0x00001000)
  3020. #define SDIO_IT_RXACT ((uint32_t)0x00002000)
  3021. #define SDIO_IT_TXFIFOHE ((uint32_t)0x00004000)
  3022. #define SDIO_IT_RXFIFOHF ((uint32_t)0x00008000)
  3023. #define SDIO_IT_TXFIFOF ((uint32_t)0x00010000)
  3024. #define SDIO_IT_RXFIFOF ((uint32_t)0x00020000)
  3025. #define SDIO_IT_TXFIFOE ((uint32_t)0x00040000)
  3026. #define SDIO_IT_RXFIFOE ((uint32_t)0x00080000)
  3027. #define SDIO_IT_TXDAVL ((uint32_t)0x00100000)
  3028. #define SDIO_IT_RXDAVL ((uint32_t)0x00200000)
  3029. #define SDIO_IT_SDIOIT ((uint32_t)0x00400000)
  3030. #define SDIO_IT_CEATAEND ((uint32_t)0x00800000)
  3031. #define IS_SDIO_IT(IT) ((((IT) & (uint32_t)0xFF000000) == 0x00) && ((IT) != (uint32_t)0x00))
  3032. /**
  3033. * @}
  3034. */
  3035. /** @defgroup SDIO_Command_Index
  3036. * @{
  3037. */
  3038. #define IS_SDIO_CMD_INDEX(INDEX) ((INDEX) < 0x40)
  3039. /**
  3040. * @}
  3041. */
  3042. /** @defgroup SDIO_Response_Type
  3043. * @{
  3044. */
  3045. #define SDIO_Response_No ((uint32_t)0x00000000)
  3046. #define SDIO_Response_Short ((uint32_t)0x00000040)
  3047. #define SDIO_Response_Long ((uint32_t)0x000000C0)
  3048. #define IS_SDIO_RESPONSE(RESPONSE) (((RESPONSE) == SDIO_Response_No) || \
  3049. ((RESPONSE) == SDIO_Response_Short) || \
  3050. ((RESPONSE) == SDIO_Response_Long))
  3051. /**
  3052. * @}
  3053. */
  3054. /** @defgroup SDIO_Wait_Interrupt_State
  3055. * @{
  3056. */
  3057. #define SDIO_Wait_No ((uint32_t)0x00000000) /*!< SDIO No Wait, TimeOut is enabled */
  3058. #define SDIO_Wait_IT ((uint32_t)0x00000100) /*!< SDIO Wait Interrupt Request */
  3059. #define SDIO_Wait_Pend ((uint32_t)0x00000200) /*!< SDIO Wait End of transfer */
  3060. #define IS_SDIO_WAIT(WAIT) (((WAIT) == SDIO_Wait_No) || ((WAIT) == SDIO_Wait_IT) || \
  3061. ((WAIT) == SDIO_Wait_Pend))
  3062. /**
  3063. * @}
  3064. */
  3065. /** @defgroup SDIO_CPSM_State
  3066. * @{
  3067. */
  3068. #define SDIO_CPSM_Disable ((uint32_t)0x00000000)
  3069. #define SDIO_CPSM_Enable ((uint32_t)0x00000400)
  3070. #define IS_SDIO_CPSM(CPSM) (((CPSM) == SDIO_CPSM_Enable) || ((CPSM) == SDIO_CPSM_Disable))
  3071. /**
  3072. * @}
  3073. */
  3074. /** @defgroup SDIO_Response_Registers
  3075. * @{
  3076. */
  3077. #define SDIO_RESP1 ((uint32_t)0x00000000)
  3078. #define SDIO_RESP2 ((uint32_t)0x00000004)
  3079. #define SDIO_RESP3 ((uint32_t)0x00000008)
  3080. #define SDIO_RESP4 ((uint32_t)0x0000000C)
  3081. #define IS_SDIO_RESP(RESP) (((RESP) == SDIO_RESP1) || ((RESP) == SDIO_RESP2) || \
  3082. ((RESP) == SDIO_RESP3) || ((RESP) == SDIO_RESP4))
  3083. /**
  3084. * @}
  3085. */
  3086. /** @defgroup SDIO_Data_Length
  3087. * @{
  3088. */
  3089. #define IS_SDIO_DATA_LENGTH(LENGTH) ((LENGTH) <= 0x01FFFFFF)
  3090. /**
  3091. * @}
  3092. */
  3093. /** @defgroup SDIO_Data_Block_Size
  3094. * @{
  3095. */
  3096. #define SDIO_DataBlockSize_1b ((uint32_t)0x00000000)
  3097. #define SDIO_DataBlockSize_2b ((uint32_t)0x00000010)
  3098. #define SDIO_DataBlockSize_4b ((uint32_t)0x00000020)
  3099. #define SDIO_DataBlockSize_8b ((uint32_t)0x00000030)
  3100. #define SDIO_DataBlockSize_16b ((uint32_t)0x00000040)
  3101. #define SDIO_DataBlockSize_32b ((uint32_t)0x00000050)
  3102. #define SDIO_DataBlockSize_64b ((uint32_t)0x00000060)
  3103. #define SDIO_DataBlockSize_128b ((uint32_t)0x00000070)
  3104. #define SDIO_DataBlockSize_256b ((uint32_t)0x00000080)
  3105. #define SDIO_DataBlockSize_512b ((uint32_t)0x00000090)
  3106. #define SDIO_DataBlockSize_1024b ((uint32_t)0x000000A0)
  3107. #define SDIO_DataBlockSize_2048b ((uint32_t)0x000000B0)
  3108. #define SDIO_DataBlockSize_4096b ((uint32_t)0x000000C0)
  3109. #define SDIO_DataBlockSize_8192b ((uint32_t)0x000000D0)
  3110. #define SDIO_DataBlockSize_16384b ((uint32_t)0x000000E0)
  3111. #define IS_SDIO_BLOCK_SIZE(SIZE) (((SIZE) == SDIO_DataBlockSize_1b) || \
  3112. ((SIZE) == SDIO_DataBlockSize_2b) || \
  3113. ((SIZE) == SDIO_DataBlockSize_4b) || \
  3114. ((SIZE) == SDIO_DataBlockSize_8b) || \
  3115. ((SIZE) == SDIO_DataBlockSize_16b) || \
  3116. ((SIZE) == SDIO_DataBlockSize_32b) || \
  3117. ((SIZE) == SDIO_DataBlockSize_64b) || \
  3118. ((SIZE) == SDIO_DataBlockSize_128b) || \
  3119. ((SIZE) == SDIO_DataBlockSize_256b) || \
  3120. ((SIZE) == SDIO_DataBlockSize_512b) || \
  3121. ((SIZE) == SDIO_DataBlockSize_1024b) || \
  3122. ((SIZE) == SDIO_DataBlockSize_2048b) || \
  3123. ((SIZE) == SDIO_DataBlockSize_4096b) || \
  3124. ((SIZE) == SDIO_DataBlockSize_8192b) || \
  3125. ((SIZE) == SDIO_DataBlockSize_16384b))
  3126. /**
  3127. * @}
  3128. */
  3129. /** @defgroup SDIO_Transfer_Direction
  3130. * @{
  3131. */
  3132. #define SDIO_TransferDir_ToCard ((uint32_t)0x00000000)
  3133. #define SDIO_TransferDir_ToSDIO ((uint32_t)0x00000002)
  3134. #define IS_SDIO_TRANSFER_DIR(DIR) (((DIR) == SDIO_TransferDir_ToCard) || \
  3135. ((DIR) == SDIO_TransferDir_ToSDIO))
  3136. /**
  3137. * @}
  3138. */
  3139. /** @defgroup SDIO_Transfer_Type
  3140. * @{
  3141. */
  3142. #define SDIO_TransferMode_Block ((uint32_t)0x00000000)
  3143. #define SDIO_TransferMode_Stream ((uint32_t)0x00000004)
  3144. #define IS_SDIO_TRANSFER_MODE(MODE) (((MODE) == SDIO_TransferMode_Stream) || \
  3145. ((MODE) == SDIO_TransferMode_Block))
  3146. /**
  3147. * @}
  3148. */
  3149. /** @defgroup SDIO_DPSM_State
  3150. * @{
  3151. */
  3152. #define SDIO_DPSM_Disable ((uint32_t)0x00000000)
  3153. #define SDIO_DPSM_Enable ((uint32_t)0x00000001)
  3154. #define IS_SDIO_DPSM(DPSM) (((DPSM) == SDIO_DPSM_Enable) || ((DPSM) == SDIO_DPSM_Disable))
  3155. /**
  3156. * @}
  3157. */
  3158. /** @defgroup SDIO_Flags
  3159. * @{
  3160. */
  3161. #define SDIO_FLAG_CCRCFAIL ((uint32_t)0x00000001)
  3162. #define SDIO_FLAG_DCRCFAIL ((uint32_t)0x00000002)
  3163. #define SDIO_FLAG_CTIMEOUT ((uint32_t)0x00000004)
  3164. #define SDIO_FLAG_DTIMEOUT ((uint32_t)0x00000008)
  3165. #define SDIO_FLAG_TXUNDERR ((uint32_t)0x00000010)
  3166. #define SDIO_FLAG_RXOVERR ((uint32_t)0x00000020)
  3167. #define SDIO_FLAG_CMDREND ((uint32_t)0x00000040)
  3168. #define SDIO_FLAG_CMDSENT ((uint32_t)0x00000080)
  3169. #define SDIO_FLAG_DATAEND ((uint32_t)0x00000100)
  3170. #define SDIO_FLAG_STBITERR ((uint32_t)0x00000200)
  3171. #define SDIO_FLAG_DBCKEND ((uint32_t)0x00000400)
  3172. #define SDIO_FLAG_CMDACT ((uint32_t)0x00000800)
  3173. #define SDIO_FLAG_TXACT ((uint32_t)0x00001000)
  3174. #define SDIO_FLAG_RXACT ((uint32_t)0x00002000)
  3175. #define SDIO_FLAG_TXFIFOHE ((uint32_t)0x00004000)
  3176. #define SDIO_FLAG_RXFIFOHF ((uint32_t)0x00008000)
  3177. #define SDIO_FLAG_TXFIFOF ((uint32_t)0x00010000)
  3178. #define SDIO_FLAG_RXFIFOF ((uint32_t)0x00020000)
  3179. #define SDIO_FLAG_TXFIFOE ((uint32_t)0x00040000)
  3180. #define SDIO_FLAG_RXFIFOE ((uint32_t)0x00080000)
  3181. #define SDIO_FLAG_TXDAVL ((uint32_t)0x00100000)
  3182. #define SDIO_FLAG_RXDAVL ((uint32_t)0x00200000)
  3183. #define SDIO_FLAG_SDIOIT ((uint32_t)0x00400000)
  3184. #define SDIO_FLAG_CEATAEND ((uint32_t)0x00800000)
  3185. #define IS_SDIO_FLAG(FLAG) (((FLAG) == SDIO_FLAG_CCRCFAIL) || \
  3186. ((FLAG) == SDIO_FLAG_DCRCFAIL) || \
  3187. ((FLAG) == SDIO_FLAG_CTIMEOUT) || \
  3188. ((FLAG) == SDIO_FLAG_DTIMEOUT) || \
  3189. ((FLAG) == SDIO_FLAG_TXUNDERR) || \
  3190. ((FLAG) == SDIO_FLAG_RXOVERR) || \
  3191. ((FLAG) == SDIO_FLAG_CMDREND) || \
  3192. ((FLAG) == SDIO_FLAG_CMDSENT) || \
  3193. ((FLAG) == SDIO_FLAG_DATAEND) || \
  3194. ((FLAG) == SDIO_FLAG_STBITERR) || \
  3195. ((FLAG) == SDIO_FLAG_DBCKEND) || \
  3196. ((FLAG) == SDIO_FLAG_CMDACT) || \
  3197. ((FLAG) == SDIO_FLAG_TXACT) || \
  3198. ((FLAG) == SDIO_FLAG_RXACT) || \
  3199. ((FLAG) == SDIO_FLAG_TXFIFOHE) || \
  3200. ((FLAG) == SDIO_FLAG_RXFIFOHF) || \
  3201. ((FLAG) == SDIO_FLAG_TXFIFOF) || \
  3202. ((FLAG) == SDIO_FLAG_RXFIFOF) || \
  3203. ((FLAG) == SDIO_FLAG_TXFIFOE) || \
  3204. ((FLAG) == SDIO_FLAG_RXFIFOE) || \
  3205. ((FLAG) == SDIO_FLAG_TXDAVL) || \
  3206. ((FLAG) == SDIO_FLAG_RXDAVL) || \
  3207. ((FLAG) == SDIO_FLAG_SDIOIT) || \
  3208. ((FLAG) == SDIO_FLAG_CEATAEND))
  3209. #define IS_SDIO_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFF3FF800) == 0x00) && ((FLAG) != (uint32_t)0x00))
  3210. #define IS_SDIO_GET_IT(IT) (((IT) == SDIO_IT_CCRCFAIL) || \
  3211. ((IT) == SDIO_IT_DCRCFAIL) || \
  3212. ((IT) == SDIO_IT_CTIMEOUT) || \
  3213. ((IT) == SDIO_IT_DTIMEOUT) || \
  3214. ((IT) == SDIO_IT_TXUNDERR) || \
  3215. ((IT) == SDIO_IT_RXOVERR) || \
  3216. ((IT) == SDIO_IT_CMDREND) || \
  3217. ((IT) == SDIO_IT_CMDSENT) || \
  3218. ((IT) == SDIO_IT_DATAEND) || \
  3219. ((IT) == SDIO_IT_STBITERR) || \
  3220. ((IT) == SDIO_IT_DBCKEND) || \
  3221. ((IT) == SDIO_IT_CMDACT) || \
  3222. ((IT) == SDIO_IT_TXACT) || \
  3223. ((IT) == SDIO_IT_RXACT) || \
  3224. ((IT) == SDIO_IT_TXFIFOHE) || \
  3225. ((IT) == SDIO_IT_RXFIFOHF) || \
  3226. ((IT) == SDIO_IT_TXFIFOF) || \
  3227. ((IT) == SDIO_IT_RXFIFOF) || \
  3228. ((IT) == SDIO_IT_TXFIFOE) || \
  3229. ((IT) == SDIO_IT_RXFIFOE) || \
  3230. ((IT) == SDIO_IT_TXDAVL) || \
  3231. ((IT) == SDIO_IT_RXDAVL) || \
  3232. ((IT) == SDIO_IT_SDIOIT) || \
  3233. ((IT) == SDIO_IT_CEATAEND))
  3234. #define IS_SDIO_CLEAR_IT(IT) ((((IT) & (uint32_t)0xFF3FF800) == 0x00) && ((IT) != (uint32_t)0x00))
  3235. /**
  3236. * @}
  3237. */
  3238. /** @defgroup SDIO_Read_Wait_Mode
  3239. * @{
  3240. */
  3241. #define SDIO_ReadWaitMode_CLK ((uint32_t)0x00000001)
  3242. #define SDIO_ReadWaitMode_DATA2 ((uint32_t)0x00000000)
  3243. #define IS_SDIO_READWAIT_MODE(MODE) (((MODE) == SDIO_ReadWaitMode_CLK) || \
  3244. ((MODE) == SDIO_ReadWaitMode_DATA2))
  3245. /**
  3246. * @}
  3247. */
  3248. /**
  3249. * @}
  3250. */
  3251. /** @defgroup SDIO_Exported_Macros
  3252. * @{
  3253. */
  3254. /**
  3255. * @}
  3256. */
  3257. /** @defgroup SDIO_Exported_Functions
  3258. * @{
  3259. */
  3260. void SDIO_DeInit(void);
  3261. void SDIO_Init(SDIO_InitTypeDef* SDIO_InitStruct);
  3262. void SDIO_StructInit(SDIO_InitTypeDef* SDIO_InitStruct);
  3263. void SDIO_ClockCmd(FunctionalState NewState);
  3264. void SDIO_SetPowerState(uint32_t SDIO_PowerState);
  3265. uint32_t SDIO_GetPowerState(void);
  3266. void SDIO_ITConfig(uint32_t SDIO_IT, FunctionalState NewState);
  3267. void SDIO_DMACmd(FunctionalState NewState);
  3268. void SDIO_SendCommand(SDIO_CmdInitTypeDef *SDIO_CmdInitStruct);
  3269. void SDIO_CmdStructInit(SDIO_CmdInitTypeDef* SDIO_CmdInitStruct);
  3270. uint8_t SDIO_GetCommandResponse(void);
  3271. uint32_t SDIO_GetResponse(uint32_t SDIO_RESP);
  3272. void SDIO_DataConfig(SDIO_DataInitTypeDef* SDIO_DataInitStruct);
  3273. void SDIO_DataStructInit(SDIO_DataInitTypeDef* SDIO_DataInitStruct);
  3274. uint32_t SDIO_GetDataCounter(void);
  3275. uint32_t SDIO_ReadData(void);
  3276. void SDIO_WriteData(uint32_t Data);
  3277. uint32_t SDIO_GetFIFOCount(void);
  3278. void SDIO_StartSDIOReadWait(FunctionalState NewState);
  3279. void SDIO_StopSDIOReadWait(FunctionalState NewState);
  3280. void SDIO_SetSDIOReadWaitMode(uint32_t SDIO_ReadWaitMode);
  3281. void SDIO_SetSDIOOperation(FunctionalState NewState);
  3282. void SDIO_SendSDIOSuspendCmd(FunctionalState NewState);
  3283. void SDIO_CommandCompletionCmd(FunctionalState NewState);
  3284. void SDIO_CEATAITCmd(FunctionalState NewState);
  3285. void SDIO_SendCEATACmd(FunctionalState NewState);
  3286. FlagStatus SDIO_GetFlagStatus(uint32_t SDIO_FLAG);
  3287. void SDIO_ClearFlag(uint32_t SDIO_FLAG);
  3288. ITStatus SDIO_GetITStatus(uint32_t SDIO_IT);
  3289. void SDIO_ClearITPendingBit(uint32_t SDIO_IT);
  3290. #ifdef __cplusplus
  3291. }
  3292. #endif
  3293. #endif /* __STM32F10x_SDIO_H */
  3294. /**
  3295. * @}
  3296. */
  3297. /**
  3298. * @}
  3299. */
  3300. /**
  3301. * @}
  3302. */
  3303. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  3304. /**
  3305. ******************************************************************************
  3306. * @file stm32f10x_rcc.h
  3307. * @author MCD Application Team
  3308. * @version V3.5.0
  3309. * @date 11-March-2011
  3310. * @brief This file contains all the functions prototypes for the RCC firmware
  3311. * library.
  3312. ******************************************************************************
  3313. * @attention
  3314. *
  3315. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  3316. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  3317. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  3318. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  3319. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  3320. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  3321. *
  3322. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  3323. ******************************************************************************
  3324. */
  3325. /* Define to prevent recursive inclusion -------------------------------------*/
  3326. #ifndef __STM32F10x_RCC_H
  3327. #define __STM32F10x_RCC_H
  3328. #ifdef __cplusplus
  3329. extern "C" {
  3330. #endif
  3331. /* Includes ------------------------------------------------------------------*/
  3332. #include "stm32f10x.h"
  3333. /** @addtogroup STM32F10x_StdPeriph_Driver
  3334. * @{
  3335. */
  3336. /** @addtogroup RCC
  3337. * @{
  3338. */
  3339. /** @defgroup RCC_Exported_Types
  3340. * @{
  3341. */
  3342. typedef struct
  3343. {
  3344. uint32_t SYSCLK_Frequency; /*!< returns SYSCLK clock frequency expressed in Hz */
  3345. uint32_t HCLK_Frequency; /*!< returns HCLK clock frequency expressed in Hz */
  3346. uint32_t PCLK1_Frequency; /*!< returns PCLK1 clock frequency expressed in Hz */
  3347. uint32_t PCLK2_Frequency; /*!< returns PCLK2 clock frequency expressed in Hz */
  3348. uint32_t ADCCLK_Frequency; /*!< returns ADCCLK clock frequency expressed in Hz */
  3349. }RCC_ClocksTypeDef;
  3350. /**
  3351. * @}
  3352. */
  3353. /** @defgroup RCC_Exported_Constants
  3354. * @{
  3355. */
  3356. /** @defgroup HSE_configuration
  3357. * @{
  3358. */
  3359. #define RCC_HSE_OFF ((uint32_t)0x00000000)
  3360. #define RCC_HSE_ON ((uint32_t)0x00010000)
  3361. #define RCC_HSE_Bypass ((uint32_t)0x00040000)
  3362. #define IS_RCC_HSE(HSE) (((HSE) == RCC_HSE_OFF) || ((HSE) == RCC_HSE_ON) || \
  3363. ((HSE) == RCC_HSE_Bypass))
  3364. /**
  3365. * @}
  3366. */
  3367. /** @defgroup PLL_entry_clock_source
  3368. * @{
  3369. */
  3370. #define RCC_PLLSource_HSI_Div2 ((uint32_t)0x00000000)
  3371. #if !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD_VL) && !defined (STM32F10X_CL)
  3372. #define RCC_PLLSource_HSE_Div1 ((uint32_t)0x00010000)
  3373. #define RCC_PLLSource_HSE_Div2 ((uint32_t)0x00030000)
  3374. #define IS_RCC_PLL_SOURCE(SOURCE) (((SOURCE) == RCC_PLLSource_HSI_Div2) || \
  3375. ((SOURCE) == RCC_PLLSource_HSE_Div1) || \
  3376. ((SOURCE) == RCC_PLLSource_HSE_Div2))
  3377. #else
  3378. #define RCC_PLLSource_PREDIV1 ((uint32_t)0x00010000)
  3379. #define IS_RCC_PLL_SOURCE(SOURCE) (((SOURCE) == RCC_PLLSource_HSI_Div2) || \
  3380. ((SOURCE) == RCC_PLLSource_PREDIV1))
  3381. #endif /* STM32F10X_CL */
  3382. /**
  3383. * @}
  3384. */
  3385. /** @defgroup PLL_multiplication_factor
  3386. * @{
  3387. */
  3388. #ifndef STM32F10X_CL
  3389. #define RCC_PLLMul_2 ((uint32_t)0x00000000)
  3390. #define RCC_PLLMul_3 ((uint32_t)0x00040000)
  3391. #define RCC_PLLMul_4 ((uint32_t)0x00080000)
  3392. #define RCC_PLLMul_5 ((uint32_t)0x000C0000)
  3393. #define RCC_PLLMul_6 ((uint32_t)0x00100000)
  3394. #define RCC_PLLMul_7 ((uint32_t)0x00140000)
  3395. #define RCC_PLLMul_8 ((uint32_t)0x00180000)
  3396. #define RCC_PLLMul_9 ((uint32_t)0x001C0000)
  3397. #define RCC_PLLMul_10 ((uint32_t)0x00200000)
  3398. #define RCC_PLLMul_11 ((uint32_t)0x00240000)
  3399. #define RCC_PLLMul_12 ((uint32_t)0x00280000)
  3400. #define RCC_PLLMul_13 ((uint32_t)0x002C0000)
  3401. #define RCC_PLLMul_14 ((uint32_t)0x00300000)
  3402. #define RCC_PLLMul_15 ((uint32_t)0x00340000)
  3403. #define RCC_PLLMul_16 ((uint32_t)0x00380000)
  3404. #define IS_RCC_PLL_MUL(MUL) (((MUL) == RCC_PLLMul_2) || ((MUL) == RCC_PLLMul_3) || \
  3405. ((MUL) == RCC_PLLMul_4) || ((MUL) == RCC_PLLMul_5) || \
  3406. ((MUL) == RCC_PLLMul_6) || ((MUL) == RCC_PLLMul_7) || \
  3407. ((MUL) == RCC_PLLMul_8) || ((MUL) == RCC_PLLMul_9) || \
  3408. ((MUL) == RCC_PLLMul_10) || ((MUL) == RCC_PLLMul_11) || \
  3409. ((MUL) == RCC_PLLMul_12) || ((MUL) == RCC_PLLMul_13) || \
  3410. ((MUL) == RCC_PLLMul_14) || ((MUL) == RCC_PLLMul_15) || \
  3411. ((MUL) == RCC_PLLMul_16))
  3412. #else
  3413. #define RCC_PLLMul_4 ((uint32_t)0x00080000)
  3414. #define RCC_PLLMul_5 ((uint32_t)0x000C0000)
  3415. #define RCC_PLLMul_6 ((uint32_t)0x00100000)
  3416. #define RCC_PLLMul_7 ((uint32_t)0x00140000)
  3417. #define RCC_PLLMul_8 ((uint32_t)0x00180000)
  3418. #define RCC_PLLMul_9 ((uint32_t)0x001C0000)
  3419. #define RCC_PLLMul_6_5 ((uint32_t)0x00340000)
  3420. #define IS_RCC_PLL_MUL(MUL) (((MUL) == RCC_PLLMul_4) || ((MUL) == RCC_PLLMul_5) || \
  3421. ((MUL) == RCC_PLLMul_6) || ((MUL) == RCC_PLLMul_7) || \
  3422. ((MUL) == RCC_PLLMul_8) || ((MUL) == RCC_PLLMul_9) || \
  3423. ((MUL) == RCC_PLLMul_6_5))
  3424. #endif /* STM32F10X_CL */
  3425. /**
  3426. * @}
  3427. */
  3428. /** @defgroup PREDIV1_division_factor
  3429. * @{
  3430. */
  3431. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) || defined (STM32F10X_CL)
  3432. #define RCC_PREDIV1_Div1 ((uint32_t)0x00000000)
  3433. #define RCC_PREDIV1_Div2 ((uint32_t)0x00000001)
  3434. #define RCC_PREDIV1_Div3 ((uint32_t)0x00000002)
  3435. #define RCC_PREDIV1_Div4 ((uint32_t)0x00000003)
  3436. #define RCC_PREDIV1_Div5 ((uint32_t)0x00000004)
  3437. #define RCC_PREDIV1_Div6 ((uint32_t)0x00000005)
  3438. #define RCC_PREDIV1_Div7 ((uint32_t)0x00000006)
  3439. #define RCC_PREDIV1_Div8 ((uint32_t)0x00000007)
  3440. #define RCC_PREDIV1_Div9 ((uint32_t)0x00000008)
  3441. #define RCC_PREDIV1_Div10 ((uint32_t)0x00000009)
  3442. #define RCC_PREDIV1_Div11 ((uint32_t)0x0000000A)
  3443. #define RCC_PREDIV1_Div12 ((uint32_t)0x0000000B)
  3444. #define RCC_PREDIV1_Div13 ((uint32_t)0x0000000C)
  3445. #define RCC_PREDIV1_Div14 ((uint32_t)0x0000000D)
  3446. #define RCC_PREDIV1_Div15 ((uint32_t)0x0000000E)
  3447. #define RCC_PREDIV1_Div16 ((uint32_t)0x0000000F)
  3448. #define IS_RCC_PREDIV1(PREDIV1) (((PREDIV1) == RCC_PREDIV1_Div1) || ((PREDIV1) == RCC_PREDIV1_Div2) || \
  3449. ((PREDIV1) == RCC_PREDIV1_Div3) || ((PREDIV1) == RCC_PREDIV1_Div4) || \
  3450. ((PREDIV1) == RCC_PREDIV1_Div5) || ((PREDIV1) == RCC_PREDIV1_Div6) || \
  3451. ((PREDIV1) == RCC_PREDIV1_Div7) || ((PREDIV1) == RCC_PREDIV1_Div8) || \
  3452. ((PREDIV1) == RCC_PREDIV1_Div9) || ((PREDIV1) == RCC_PREDIV1_Div10) || \
  3453. ((PREDIV1) == RCC_PREDIV1_Div11) || ((PREDIV1) == RCC_PREDIV1_Div12) || \
  3454. ((PREDIV1) == RCC_PREDIV1_Div13) || ((PREDIV1) == RCC_PREDIV1_Div14) || \
  3455. ((PREDIV1) == RCC_PREDIV1_Div15) || ((PREDIV1) == RCC_PREDIV1_Div16))
  3456. #endif
  3457. /**
  3458. * @}
  3459. */
  3460. /** @defgroup PREDIV1_clock_source
  3461. * @{
  3462. */
  3463. #ifdef STM32F10X_CL
  3464. /* PREDIV1 clock source (for STM32 connectivity line devices) */
  3465. #define RCC_PREDIV1_Source_HSE ((uint32_t)0x00000000)
  3466. #define RCC_PREDIV1_Source_PLL2 ((uint32_t)0x00010000)
  3467. #define IS_RCC_PREDIV1_SOURCE(SOURCE) (((SOURCE) == RCC_PREDIV1_Source_HSE) || \
  3468. ((SOURCE) == RCC_PREDIV1_Source_PLL2))
  3469. #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  3470. /* PREDIV1 clock source (for STM32 Value line devices) */
  3471. #define RCC_PREDIV1_Source_HSE ((uint32_t)0x00000000)
  3472. #define IS_RCC_PREDIV1_SOURCE(SOURCE) (((SOURCE) == RCC_PREDIV1_Source_HSE))
  3473. #endif
  3474. /**
  3475. * @}
  3476. */
  3477. #ifdef STM32F10X_CL
  3478. /** @defgroup PREDIV2_division_factor
  3479. * @{
  3480. */
  3481. #define RCC_PREDIV2_Div1 ((uint32_t)0x00000000)
  3482. #define RCC_PREDIV2_Div2 ((uint32_t)0x00000010)
  3483. #define RCC_PREDIV2_Div3 ((uint32_t)0x00000020)
  3484. #define RCC_PREDIV2_Div4 ((uint32_t)0x00000030)
  3485. #define RCC_PREDIV2_Div5 ((uint32_t)0x00000040)
  3486. #define RCC_PREDIV2_Div6 ((uint32_t)0x00000050)
  3487. #define RCC_PREDIV2_Div7 ((uint32_t)0x00000060)
  3488. #define RCC_PREDIV2_Div8 ((uint32_t)0x00000070)
  3489. #define RCC_PREDIV2_Div9 ((uint32_t)0x00000080)
  3490. #define RCC_PREDIV2_Div10 ((uint32_t)0x00000090)
  3491. #define RCC_PREDIV2_Div11 ((uint32_t)0x000000A0)
  3492. #define RCC_PREDIV2_Div12 ((uint32_t)0x000000B0)
  3493. #define RCC_PREDIV2_Div13 ((uint32_t)0x000000C0)
  3494. #define RCC_PREDIV2_Div14 ((uint32_t)0x000000D0)
  3495. #define RCC_PREDIV2_Div15 ((uint32_t)0x000000E0)
  3496. #define RCC_PREDIV2_Div16 ((uint32_t)0x000000F0)
  3497. #define IS_RCC_PREDIV2(PREDIV2) (((PREDIV2) == RCC_PREDIV2_Div1) || ((PREDIV2) == RCC_PREDIV2_Div2) || \
  3498. ((PREDIV2) == RCC_PREDIV2_Div3) || ((PREDIV2) == RCC_PREDIV2_Div4) || \
  3499. ((PREDIV2) == RCC_PREDIV2_Div5) || ((PREDIV2) == RCC_PREDIV2_Div6) || \
  3500. ((PREDIV2) == RCC_PREDIV2_Div7) || ((PREDIV2) == RCC_PREDIV2_Div8) || \
  3501. ((PREDIV2) == RCC_PREDIV2_Div9) || ((PREDIV2) == RCC_PREDIV2_Div10) || \
  3502. ((PREDIV2) == RCC_PREDIV2_Div11) || ((PREDIV2) == RCC_PREDIV2_Div12) || \
  3503. ((PREDIV2) == RCC_PREDIV2_Div13) || ((PREDIV2) == RCC_PREDIV2_Div14) || \
  3504. ((PREDIV2) == RCC_PREDIV2_Div15) || ((PREDIV2) == RCC_PREDIV2_Div16))
  3505. /**
  3506. * @}
  3507. */
  3508. /** @defgroup PLL2_multiplication_factor
  3509. * @{
  3510. */
  3511. #define RCC_PLL2Mul_8 ((uint32_t)0x00000600)
  3512. #define RCC_PLL2Mul_9 ((uint32_t)0x00000700)
  3513. #define RCC_PLL2Mul_10 ((uint32_t)0x00000800)
  3514. #define RCC_PLL2Mul_11 ((uint32_t)0x00000900)
  3515. #define RCC_PLL2Mul_12 ((uint32_t)0x00000A00)
  3516. #define RCC_PLL2Mul_13 ((uint32_t)0x00000B00)
  3517. #define RCC_PLL2Mul_14 ((uint32_t)0x00000C00)
  3518. #define RCC_PLL2Mul_16 ((uint32_t)0x00000E00)
  3519. #define RCC_PLL2Mul_20 ((uint32_t)0x00000F00)
  3520. #define IS_RCC_PLL2_MUL(MUL) (((MUL) == RCC_PLL2Mul_8) || ((MUL) == RCC_PLL2Mul_9) || \
  3521. ((MUL) == RCC_PLL2Mul_10) || ((MUL) == RCC_PLL2Mul_11) || \
  3522. ((MUL) == RCC_PLL2Mul_12) || ((MUL) == RCC_PLL2Mul_13) || \
  3523. ((MUL) == RCC_PLL2Mul_14) || ((MUL) == RCC_PLL2Mul_16) || \
  3524. ((MUL) == RCC_PLL2Mul_20))
  3525. /**
  3526. * @}
  3527. */
  3528. /** @defgroup PLL3_multiplication_factor
  3529. * @{
  3530. */
  3531. #define RCC_PLL3Mul_8 ((uint32_t)0x00006000)
  3532. #define RCC_PLL3Mul_9 ((uint32_t)0x00007000)
  3533. #define RCC_PLL3Mul_10 ((uint32_t)0x00008000)
  3534. #define RCC_PLL3Mul_11 ((uint32_t)0x00009000)
  3535. #define RCC_PLL3Mul_12 ((uint32_t)0x0000A000)
  3536. #define RCC_PLL3Mul_13 ((uint32_t)0x0000B000)
  3537. #define RCC_PLL3Mul_14 ((uint32_t)0x0000C000)
  3538. #define RCC_PLL3Mul_16 ((uint32_t)0x0000E000)
  3539. #define RCC_PLL3Mul_20 ((uint32_t)0x0000F000)
  3540. #define IS_RCC_PLL3_MUL(MUL) (((MUL) == RCC_PLL3Mul_8) || ((MUL) == RCC_PLL3Mul_9) || \
  3541. ((MUL) == RCC_PLL3Mul_10) || ((MUL) == RCC_PLL3Mul_11) || \
  3542. ((MUL) == RCC_PLL3Mul_12) || ((MUL) == RCC_PLL3Mul_13) || \
  3543. ((MUL) == RCC_PLL3Mul_14) || ((MUL) == RCC_PLL3Mul_16) || \
  3544. ((MUL) == RCC_PLL3Mul_20))
  3545. /**
  3546. * @}
  3547. */
  3548. #endif /* STM32F10X_CL */
  3549. /** @defgroup System_clock_source
  3550. * @{
  3551. */
  3552. #define RCC_SYSCLKSource_HSI ((uint32_t)0x00000000)
  3553. #define RCC_SYSCLKSource_HSE ((uint32_t)0x00000001)
  3554. #define RCC_SYSCLKSource_PLLCLK ((uint32_t)0x00000002)
  3555. #define IS_RCC_SYSCLK_SOURCE(SOURCE) (((SOURCE) == RCC_SYSCLKSource_HSI) || \
  3556. ((SOURCE) == RCC_SYSCLKSource_HSE) || \
  3557. ((SOURCE) == RCC_SYSCLKSource_PLLCLK))
  3558. /**
  3559. * @}
  3560. */
  3561. /** @defgroup AHB_clock_source
  3562. * @{
  3563. */
  3564. #define RCC_SYSCLK_Div1 ((uint32_t)0x00000000)
  3565. #define RCC_SYSCLK_Div2 ((uint32_t)0x00000080)
  3566. #define RCC_SYSCLK_Div4 ((uint32_t)0x00000090)
  3567. #define RCC_SYSCLK_Div8 ((uint32_t)0x000000A0)
  3568. #define RCC_SYSCLK_Div16 ((uint32_t)0x000000B0)
  3569. #define RCC_SYSCLK_Div64 ((uint32_t)0x000000C0)
  3570. #define RCC_SYSCLK_Div128 ((uint32_t)0x000000D0)
  3571. #define RCC_SYSCLK_Div256 ((uint32_t)0x000000E0)
  3572. #define RCC_SYSCLK_Div512 ((uint32_t)0x000000F0)
  3573. #define IS_RCC_HCLK(HCLK) (((HCLK) == RCC_SYSCLK_Div1) || ((HCLK) == RCC_SYSCLK_Div2) || \
  3574. ((HCLK) == RCC_SYSCLK_Div4) || ((HCLK) == RCC_SYSCLK_Div8) || \
  3575. ((HCLK) == RCC_SYSCLK_Div16) || ((HCLK) == RCC_SYSCLK_Div64) || \
  3576. ((HCLK) == RCC_SYSCLK_Div128) || ((HCLK) == RCC_SYSCLK_Div256) || \
  3577. ((HCLK) == RCC_SYSCLK_Div512))
  3578. /**
  3579. * @}
  3580. */
  3581. /** @defgroup APB1_APB2_clock_source
  3582. * @{
  3583. */
  3584. #define RCC_HCLK_Div1 ((uint32_t)0x00000000)
  3585. #define RCC_HCLK_Div2 ((uint32_t)0x00000400)
  3586. #define RCC_HCLK_Div4 ((uint32_t)0x00000500)
  3587. #define RCC_HCLK_Div8 ((uint32_t)0x00000600)
  3588. #define RCC_HCLK_Div16 ((uint32_t)0x00000700)
  3589. #define IS_RCC_PCLK(PCLK) (((PCLK) == RCC_HCLK_Div1) || ((PCLK) == RCC_HCLK_Div2) || \
  3590. ((PCLK) == RCC_HCLK_Div4) || ((PCLK) == RCC_HCLK_Div8) || \
  3591. ((PCLK) == RCC_HCLK_Div16))
  3592. /**
  3593. * @}
  3594. */
  3595. /** @defgroup RCC_Interrupt_source
  3596. * @{
  3597. */
  3598. #define RCC_IT_LSIRDY ((uint8_t)0x01)
  3599. #define RCC_IT_LSERDY ((uint8_t)0x02)
  3600. #define RCC_IT_HSIRDY ((uint8_t)0x04)
  3601. #define RCC_IT_HSERDY ((uint8_t)0x08)
  3602. #define RCC_IT_PLLRDY ((uint8_t)0x10)
  3603. #define RCC_IT_CSS ((uint8_t)0x80)
  3604. #ifndef STM32F10X_CL
  3605. #define IS_RCC_IT(IT) ((((IT) & (uint8_t)0xE0) == 0x00) && ((IT) != 0x00))
  3606. #define IS_RCC_GET_IT(IT) (((IT) == RCC_IT_LSIRDY) || ((IT) == RCC_IT_LSERDY) || \
  3607. ((IT) == RCC_IT_HSIRDY) || ((IT) == RCC_IT_HSERDY) || \
  3608. ((IT) == RCC_IT_PLLRDY) || ((IT) == RCC_IT_CSS))
  3609. #define IS_RCC_CLEAR_IT(IT) ((((IT) & (uint8_t)0x60) == 0x00) && ((IT) != 0x00))
  3610. #else
  3611. #define RCC_IT_PLL2RDY ((uint8_t)0x20)
  3612. #define RCC_IT_PLL3RDY ((uint8_t)0x40)
  3613. #define IS_RCC_IT(IT) ((((IT) & (uint8_t)0x80) == 0x00) && ((IT) != 0x00))
  3614. #define IS_RCC_GET_IT(IT) (((IT) == RCC_IT_LSIRDY) || ((IT) == RCC_IT_LSERDY) || \
  3615. ((IT) == RCC_IT_HSIRDY) || ((IT) == RCC_IT_HSERDY) || \
  3616. ((IT) == RCC_IT_PLLRDY) || ((IT) == RCC_IT_CSS) || \
  3617. ((IT) == RCC_IT_PLL2RDY) || ((IT) == RCC_IT_PLL3RDY))
  3618. #define IS_RCC_CLEAR_IT(IT) ((IT) != 0x00)
  3619. #endif /* STM32F10X_CL */
  3620. /**
  3621. * @}
  3622. */
  3623. #ifndef STM32F10X_CL
  3624. /** @defgroup USB_Device_clock_source
  3625. * @{
  3626. */
  3627. #define RCC_USBCLKSource_PLLCLK_1Div5 ((uint8_t)0x00)
  3628. #define RCC_USBCLKSource_PLLCLK_Div1 ((uint8_t)0x01)
  3629. #define IS_RCC_USBCLK_SOURCE(SOURCE) (((SOURCE) == RCC_USBCLKSource_PLLCLK_1Div5) || \
  3630. ((SOURCE) == RCC_USBCLKSource_PLLCLK_Div1))
  3631. /**
  3632. * @}
  3633. */
  3634. #else
  3635. /** @defgroup USB_OTG_FS_clock_source
  3636. * @{
  3637. */
  3638. #define RCC_OTGFSCLKSource_PLLVCO_Div3 ((uint8_t)0x00)
  3639. #define RCC_OTGFSCLKSource_PLLVCO_Div2 ((uint8_t)0x01)
  3640. #define IS_RCC_OTGFSCLK_SOURCE(SOURCE) (((SOURCE) == RCC_OTGFSCLKSource_PLLVCO_Div3) || \
  3641. ((SOURCE) == RCC_OTGFSCLKSource_PLLVCO_Div2))
  3642. /**
  3643. * @}
  3644. */
  3645. #endif /* STM32F10X_CL */
  3646. #ifdef STM32F10X_CL
  3647. /** @defgroup I2S2_clock_source
  3648. * @{
  3649. */
  3650. #define RCC_I2S2CLKSource_SYSCLK ((uint8_t)0x00)
  3651. #define RCC_I2S2CLKSource_PLL3_VCO ((uint8_t)0x01)
  3652. #define IS_RCC_I2S2CLK_SOURCE(SOURCE) (((SOURCE) == RCC_I2S2CLKSource_SYSCLK) || \
  3653. ((SOURCE) == RCC_I2S2CLKSource_PLL3_VCO))
  3654. /**
  3655. * @}
  3656. */
  3657. /** @defgroup I2S3_clock_source
  3658. * @{
  3659. */
  3660. #define RCC_I2S3CLKSource_SYSCLK ((uint8_t)0x00)
  3661. #define RCC_I2S3CLKSource_PLL3_VCO ((uint8_t)0x01)
  3662. #define IS_RCC_I2S3CLK_SOURCE(SOURCE) (((SOURCE) == RCC_I2S3CLKSource_SYSCLK) || \
  3663. ((SOURCE) == RCC_I2S3CLKSource_PLL3_VCO))
  3664. /**
  3665. * @}
  3666. */
  3667. #endif /* STM32F10X_CL */
  3668. /** @defgroup ADC_clock_source
  3669. * @{
  3670. */
  3671. #define RCC_PCLK2_Div2 ((uint32_t)0x00000000)
  3672. #define RCC_PCLK2_Div4 ((uint32_t)0x00004000)
  3673. #define RCC_PCLK2_Div6 ((uint32_t)0x00008000)
  3674. #define RCC_PCLK2_Div8 ((uint32_t)0x0000C000)
  3675. #define IS_RCC_ADCCLK(ADCCLK) (((ADCCLK) == RCC_PCLK2_Div2) || ((ADCCLK) == RCC_PCLK2_Div4) || \
  3676. ((ADCCLK) == RCC_PCLK2_Div6) || ((ADCCLK) == RCC_PCLK2_Div8))
  3677. /**
  3678. * @}
  3679. */
  3680. /** @defgroup LSE_configuration
  3681. * @{
  3682. */
  3683. #define RCC_LSE_OFF ((uint8_t)0x00)
  3684. #define RCC_LSE_ON ((uint8_t)0x01)
  3685. #define RCC_LSE_Bypass ((uint8_t)0x04)
  3686. #define IS_RCC_LSE(LSE) (((LSE) == RCC_LSE_OFF) || ((LSE) == RCC_LSE_ON) || \
  3687. ((LSE) == RCC_LSE_Bypass))
  3688. /**
  3689. * @}
  3690. */
  3691. /** @defgroup RTC_clock_source
  3692. * @{
  3693. */
  3694. #define RCC_RTCCLKSource_LSE ((uint32_t)0x00000100)
  3695. #define RCC_RTCCLKSource_LSI ((uint32_t)0x00000200)
  3696. #define RCC_RTCCLKSource_HSE_Div128 ((uint32_t)0x00000300)
  3697. #define IS_RCC_RTCCLK_SOURCE(SOURCE) (((SOURCE) == RCC_RTCCLKSource_LSE) || \
  3698. ((SOURCE) == RCC_RTCCLKSource_LSI) || \
  3699. ((SOURCE) == RCC_RTCCLKSource_HSE_Div128))
  3700. /**
  3701. * @}
  3702. */
  3703. /** @defgroup AHB_peripheral
  3704. * @{
  3705. */
  3706. #define RCC_AHBPeriph_DMA1 ((uint32_t)0x00000001)
  3707. #define RCC_AHBPeriph_DMA2 ((uint32_t)0x00000002)
  3708. #define RCC_AHBPeriph_SRAM ((uint32_t)0x00000004)
  3709. #define RCC_AHBPeriph_FLITF ((uint32_t)0x00000010)
  3710. #define RCC_AHBPeriph_CRC ((uint32_t)0x00000040)
  3711. #ifndef STM32F10X_CL
  3712. #define RCC_AHBPeriph_FSMC ((uint32_t)0x00000100)
  3713. #define RCC_AHBPeriph_SDIO ((uint32_t)0x00000400)
  3714. #define IS_RCC_AHB_PERIPH(PERIPH) ((((PERIPH) & 0xFFFFFAA8) == 0x00) && ((PERIPH) != 0x00))
  3715. #else
  3716. #define RCC_AHBPeriph_OTG_FS ((uint32_t)0x00001000)
  3717. #define RCC_AHBPeriph_ETH_MAC ((uint32_t)0x00004000)
  3718. #define RCC_AHBPeriph_ETH_MAC_Tx ((uint32_t)0x00008000)
  3719. #define RCC_AHBPeriph_ETH_MAC_Rx ((uint32_t)0x00010000)
  3720. #define IS_RCC_AHB_PERIPH(PERIPH) ((((PERIPH) & 0xFFFE2FA8) == 0x00) && ((PERIPH) != 0x00))
  3721. #define IS_RCC_AHB_PERIPH_RESET(PERIPH) ((((PERIPH) & 0xFFFFAFFF) == 0x00) && ((PERIPH) != 0x00))
  3722. #endif /* STM32F10X_CL */
  3723. /**
  3724. * @}
  3725. */
  3726. /** @defgroup APB2_peripheral
  3727. * @{
  3728. */
  3729. #define RCC_APB2Periph_AFIO ((uint32_t)0x00000001)
  3730. #define RCC_APB2Periph_GPIOA ((uint32_t)0x00000004)
  3731. #define RCC_APB2Periph_GPIOB ((uint32_t)0x00000008)
  3732. #define RCC_APB2Periph_GPIOC ((uint32_t)0x00000010)
  3733. #define RCC_APB2Periph_GPIOD ((uint32_t)0x00000020)
  3734. #define RCC_APB2Periph_GPIOE ((uint32_t)0x00000040)
  3735. #define RCC_APB2Periph_GPIOF ((uint32_t)0x00000080)
  3736. #define RCC_APB2Periph_GPIOG ((uint32_t)0x00000100)
  3737. #define RCC_APB2Periph_ADC1 ((uint32_t)0x00000200)
  3738. #define RCC_APB2Periph_ADC2 ((uint32_t)0x00000400)
  3739. #define RCC_APB2Periph_TIM1 ((uint32_t)0x00000800)
  3740. #define RCC_APB2Periph_SPI1 ((uint32_t)0x00001000)
  3741. #define RCC_APB2Periph_TIM8 ((uint32_t)0x00002000)
  3742. #define RCC_APB2Periph_USART1 ((uint32_t)0x00004000)
  3743. #define RCC_APB2Periph_ADC3 ((uint32_t)0x00008000)
  3744. #define RCC_APB2Periph_TIM15 ((uint32_t)0x00010000)
  3745. #define RCC_APB2Periph_TIM16 ((uint32_t)0x00020000)
  3746. #define RCC_APB2Periph_TIM17 ((uint32_t)0x00040000)
  3747. #define RCC_APB2Periph_TIM9 ((uint32_t)0x00080000)
  3748. #define RCC_APB2Periph_TIM10 ((uint32_t)0x00100000)
  3749. #define RCC_APB2Periph_TIM11 ((uint32_t)0x00200000)
  3750. #define IS_RCC_APB2_PERIPH(PERIPH) ((((PERIPH) & 0xFFC00002) == 0x00) && ((PERIPH) != 0x00))
  3751. /**
  3752. * @}
  3753. */
  3754. /** @defgroup APB1_peripheral
  3755. * @{
  3756. */
  3757. #define RCC_APB1Periph_TIM2 ((uint32_t)0x00000001)
  3758. #define RCC_APB1Periph_TIM3 ((uint32_t)0x00000002)
  3759. #define RCC_APB1Periph_TIM4 ((uint32_t)0x00000004)
  3760. #define RCC_APB1Periph_TIM5 ((uint32_t)0x00000008)
  3761. #define RCC_APB1Periph_TIM6 ((uint32_t)0x00000010)
  3762. #define RCC_APB1Periph_TIM7 ((uint32_t)0x00000020)
  3763. #define RCC_APB1Periph_TIM12 ((uint32_t)0x00000040)
  3764. #define RCC_APB1Periph_TIM13 ((uint32_t)0x00000080)
  3765. #define RCC_APB1Periph_TIM14 ((uint32_t)0x00000100)
  3766. #define RCC_APB1Periph_WWDG ((uint32_t)0x00000800)
  3767. #define RCC_APB1Periph_SPI2 ((uint32_t)0x00004000)
  3768. #define RCC_APB1Periph_SPI3 ((uint32_t)0x00008000)
  3769. #define RCC_APB1Periph_USART2 ((uint32_t)0x00020000)
  3770. #define RCC_APB1Periph_USART3 ((uint32_t)0x00040000)
  3771. #define RCC_APB1Periph_UART4 ((uint32_t)0x00080000)
  3772. #define RCC_APB1Periph_UART5 ((uint32_t)0x00100000)
  3773. #define RCC_APB1Periph_I2C1 ((uint32_t)0x00200000)
  3774. #define RCC_APB1Periph_I2C2 ((uint32_t)0x00400000)
  3775. #define RCC_APB1Periph_USB ((uint32_t)0x00800000)
  3776. #define RCC_APB1Periph_CAN1 ((uint32_t)0x02000000)
  3777. #define RCC_APB1Periph_CAN2 ((uint32_t)0x04000000)
  3778. #define RCC_APB1Periph_BKP ((uint32_t)0x08000000)
  3779. #define RCC_APB1Periph_PWR ((uint32_t)0x10000000)
  3780. #define RCC_APB1Periph_DAC ((uint32_t)0x20000000)
  3781. #define RCC_APB1Periph_CEC ((uint32_t)0x40000000)
  3782. #define IS_RCC_APB1_PERIPH(PERIPH) ((((PERIPH) & 0x81013600) == 0x00) && ((PERIPH) != 0x00))
  3783. /**
  3784. * @}
  3785. */
  3786. /** @defgroup Clock_source_to_output_on_MCO_pin
  3787. * @{
  3788. */
  3789. #define RCC_MCO_NoClock ((uint8_t)0x00)
  3790. #define RCC_MCO_SYSCLK ((uint8_t)0x04)
  3791. #define RCC_MCO_HSI ((uint8_t)0x05)
  3792. #define RCC_MCO_HSE ((uint8_t)0x06)
  3793. #define RCC_MCO_PLLCLK_Div2 ((uint8_t)0x07)
  3794. #ifndef STM32F10X_CL
  3795. #define IS_RCC_MCO(MCO) (((MCO) == RCC_MCO_NoClock) || ((MCO) == RCC_MCO_HSI) || \
  3796. ((MCO) == RCC_MCO_SYSCLK) || ((MCO) == RCC_MCO_HSE) || \
  3797. ((MCO) == RCC_MCO_PLLCLK_Div2))
  3798. #else
  3799. #define RCC_MCO_PLL2CLK ((uint8_t)0x08)
  3800. #define RCC_MCO_PLL3CLK_Div2 ((uint8_t)0x09)
  3801. #define RCC_MCO_XT1 ((uint8_t)0x0A)
  3802. #define RCC_MCO_PLL3CLK ((uint8_t)0x0B)
  3803. #define IS_RCC_MCO(MCO) (((MCO) == RCC_MCO_NoClock) || ((MCO) == RCC_MCO_HSI) || \
  3804. ((MCO) == RCC_MCO_SYSCLK) || ((MCO) == RCC_MCO_HSE) || \
  3805. ((MCO) == RCC_MCO_PLLCLK_Div2) || ((MCO) == RCC_MCO_PLL2CLK) || \
  3806. ((MCO) == RCC_MCO_PLL3CLK_Div2) || ((MCO) == RCC_MCO_XT1) || \
  3807. ((MCO) == RCC_MCO_PLL3CLK))
  3808. #endif /* STM32F10X_CL */
  3809. /**
  3810. * @}
  3811. */
  3812. /** @defgroup RCC_Flag
  3813. * @{
  3814. */
  3815. #define RCC_FLAG_HSIRDY ((uint8_t)0x21)
  3816. #define RCC_FLAG_HSERDY ((uint8_t)0x31)
  3817. #define RCC_FLAG_PLLRDY ((uint8_t)0x39)
  3818. #define RCC_FLAG_LSERDY ((uint8_t)0x41)
  3819. #define RCC_FLAG_LSIRDY ((uint8_t)0x61)
  3820. #define RCC_FLAG_PINRST ((uint8_t)0x7A)
  3821. #define RCC_FLAG_PORRST ((uint8_t)0x7B)
  3822. #define RCC_FLAG_SFTRST ((uint8_t)0x7C)
  3823. #define RCC_FLAG_IWDGRST ((uint8_t)0x7D)
  3824. #define RCC_FLAG_WWDGRST ((uint8_t)0x7E)
  3825. #define RCC_FLAG_LPWRRST ((uint8_t)0x7F)
  3826. #ifndef STM32F10X_CL
  3827. #define IS_RCC_FLAG(FLAG) (((FLAG) == RCC_FLAG_HSIRDY) || ((FLAG) == RCC_FLAG_HSERDY) || \
  3828. ((FLAG) == RCC_FLAG_PLLRDY) || ((FLAG) == RCC_FLAG_LSERDY) || \
  3829. ((FLAG) == RCC_FLAG_LSIRDY) || ((FLAG) == RCC_FLAG_PINRST) || \
  3830. ((FLAG) == RCC_FLAG_PORRST) || ((FLAG) == RCC_FLAG_SFTRST) || \
  3831. ((FLAG) == RCC_FLAG_IWDGRST)|| ((FLAG) == RCC_FLAG_WWDGRST)|| \
  3832. ((FLAG) == RCC_FLAG_LPWRRST))
  3833. #else
  3834. #define RCC_FLAG_PLL2RDY ((uint8_t)0x3B)
  3835. #define RCC_FLAG_PLL3RDY ((uint8_t)0x3D)
  3836. #define IS_RCC_FLAG(FLAG) (((FLAG) == RCC_FLAG_HSIRDY) || ((FLAG) == RCC_FLAG_HSERDY) || \
  3837. ((FLAG) == RCC_FLAG_PLLRDY) || ((FLAG) == RCC_FLAG_LSERDY) || \
  3838. ((FLAG) == RCC_FLAG_PLL2RDY) || ((FLAG) == RCC_FLAG_PLL3RDY) || \
  3839. ((FLAG) == RCC_FLAG_LSIRDY) || ((FLAG) == RCC_FLAG_PINRST) || \
  3840. ((FLAG) == RCC_FLAG_PORRST) || ((FLAG) == RCC_FLAG_SFTRST) || \
  3841. ((FLAG) == RCC_FLAG_IWDGRST)|| ((FLAG) == RCC_FLAG_WWDGRST)|| \
  3842. ((FLAG) == RCC_FLAG_LPWRRST))
  3843. #endif /* STM32F10X_CL */
  3844. #define IS_RCC_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x1F)
  3845. /**
  3846. * @}
  3847. */
  3848. /**
  3849. * @}
  3850. */
  3851. /** @defgroup RCC_Exported_Macros
  3852. * @{
  3853. */
  3854. /**
  3855. * @}
  3856. */
  3857. /** @defgroup RCC_Exported_Functions
  3858. * @{
  3859. */
  3860. void RCC_DeInit(void);
  3861. void RCC_HSEConfig(uint32_t RCC_HSE);
  3862. ErrorStatus RCC_WaitForHSEStartUp(void);
  3863. void RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue);
  3864. void RCC_HSICmd(FunctionalState NewState);
  3865. void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t RCC_PLLMul);
  3866. void RCC_PLLCmd(FunctionalState NewState);
  3867. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) || defined (STM32F10X_CL)
  3868. void RCC_PREDIV1Config(uint32_t RCC_PREDIV1_Source, uint32_t RCC_PREDIV1_Div);
  3869. #endif
  3870. #ifdef STM32F10X_CL
  3871. void RCC_PREDIV2Config(uint32_t RCC_PREDIV2_Div);
  3872. void RCC_PLL2Config(uint32_t RCC_PLL2Mul);
  3873. void RCC_PLL2Cmd(FunctionalState NewState);
  3874. void RCC_PLL3Config(uint32_t RCC_PLL3Mul);
  3875. void RCC_PLL3Cmd(FunctionalState NewState);
  3876. #endif /* STM32F10X_CL */
  3877. void RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource);
  3878. uint8_t RCC_GetSYSCLKSource(void);
  3879. void RCC_HCLKConfig(uint32_t RCC_SYSCLK);
  3880. void RCC_PCLK1Config(uint32_t RCC_HCLK);
  3881. void RCC_PCLK2Config(uint32_t RCC_HCLK);
  3882. void RCC_ITConfig(uint8_t RCC_IT, FunctionalState NewState);
  3883. #ifndef STM32F10X_CL
  3884. void RCC_USBCLKConfig(uint32_t RCC_USBCLKSource);
  3885. #else
  3886. void RCC_OTGFSCLKConfig(uint32_t RCC_OTGFSCLKSource);
  3887. #endif /* STM32F10X_CL */
  3888. void RCC_ADCCLKConfig(uint32_t RCC_PCLK2);
  3889. #ifdef STM32F10X_CL
  3890. void RCC_I2S2CLKConfig(uint32_t RCC_I2S2CLKSource);
  3891. void RCC_I2S3CLKConfig(uint32_t RCC_I2S3CLKSource);
  3892. #endif /* STM32F10X_CL */
  3893. void RCC_LSEConfig(uint8_t RCC_LSE);
  3894. void RCC_LSICmd(FunctionalState NewState);
  3895. void RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource);
  3896. void RCC_RTCCLKCmd(FunctionalState NewState);
  3897. void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks);
  3898. void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
  3899. void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
  3900. void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
  3901. #ifdef STM32F10X_CL
  3902. void RCC_AHBPeriphResetCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
  3903. #endif /* STM32F10X_CL */
  3904. void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
  3905. void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
  3906. void RCC_BackupResetCmd(FunctionalState NewState);
  3907. void RCC_ClockSecuritySystemCmd(FunctionalState NewState);
  3908. void RCC_MCOConfig(uint8_t RCC_MCO);
  3909. FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG);
  3910. void RCC_ClearFlag(void);
  3911. ITStatus RCC_GetITStatus(uint8_t RCC_IT);
  3912. void RCC_ClearITPendingBit(uint8_t RCC_IT);
  3913. #ifdef __cplusplus
  3914. }
  3915. #endif
  3916. #endif /* __STM32F10x_RCC_H */
  3917. /**
  3918. * @}
  3919. */
  3920. /**
  3921. * @}
  3922. */
  3923. /**
  3924. * @}
  3925. */
  3926. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  3927. /**
  3928. ******************************************************************************
  3929. * @file stm32f10x_gpio.h
  3930. * @author MCD Application Team
  3931. * @version V3.5.0
  3932. * @date 11-March-2011
  3933. * @brief This file contains all the functions prototypes for the GPIO
  3934. * firmware library.
  3935. ******************************************************************************
  3936. * @attention
  3937. *
  3938. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  3939. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  3940. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  3941. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  3942. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  3943. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  3944. *
  3945. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  3946. ******************************************************************************
  3947. */
  3948. /* Define to prevent recursive inclusion -------------------------------------*/
  3949. #ifndef __STM32F10x_GPIO_H
  3950. #define __STM32F10x_GPIO_H
  3951. #ifdef __cplusplus
  3952. extern "C" {
  3953. #endif
  3954. /* Includes ------------------------------------------------------------------*/
  3955. #include "stm32f10x.h"
  3956. /** @addtogroup STM32F10x_StdPeriph_Driver
  3957. * @{
  3958. */
  3959. /** @addtogroup GPIO
  3960. * @{
  3961. */
  3962. /** @defgroup GPIO_Exported_Types
  3963. * @{
  3964. */
  3965. #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
  3966. ((PERIPH) == GPIOB) || \
  3967. ((PERIPH) == GPIOC) || \
  3968. ((PERIPH) == GPIOD) || \
  3969. ((PERIPH) == GPIOE) || \
  3970. ((PERIPH) == GPIOF) || \
  3971. ((PERIPH) == GPIOG))
  3972. /**
  3973. * @brief Output Maximum frequency selection
  3974. */
  3975. typedef enum
  3976. {
  3977. GPIO_Speed_10MHz = 1,
  3978. GPIO_Speed_2MHz,
  3979. GPIO_Speed_50MHz
  3980. }GPIOSpeed_TypeDef;
  3981. #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_10MHz) || ((SPEED) == GPIO_Speed_2MHz) || \
  3982. ((SPEED) == GPIO_Speed_50MHz))
  3983. /**
  3984. * @brief Configuration Mode enumeration
  3985. */
  3986. typedef enum
  3987. { GPIO_Mode_AIN = 0x0,
  3988. GPIO_Mode_IN_FLOATING = 0x04,
  3989. GPIO_Mode_IPD = 0x28,
  3990. GPIO_Mode_IPU = 0x48,
  3991. GPIO_Mode_Out_OD = 0x14,
  3992. GPIO_Mode_Out_PP = 0x10,
  3993. GPIO_Mode_AF_OD = 0x1C,
  3994. GPIO_Mode_AF_PP = 0x18
  3995. }GPIOMode_TypeDef;
  3996. #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_AIN) || ((MODE) == GPIO_Mode_IN_FLOATING) || \
  3997. ((MODE) == GPIO_Mode_IPD) || ((MODE) == GPIO_Mode_IPU) || \
  3998. ((MODE) == GPIO_Mode_Out_OD) || ((MODE) == GPIO_Mode_Out_PP) || \
  3999. ((MODE) == GPIO_Mode_AF_OD) || ((MODE) == GPIO_Mode_AF_PP))
  4000. /**
  4001. * @brief GPIO Init structure definition
  4002. */
  4003. typedef struct
  4004. {
  4005. uint16_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured.
  4006. This parameter can be any value of @ref GPIO_pins_define */
  4007. GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins.
  4008. This parameter can be a value of @ref GPIOSpeed_TypeDef */
  4009. GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins.
  4010. This parameter can be a value of @ref GPIOMode_TypeDef */
  4011. }GPIO_InitTypeDef;
  4012. /**
  4013. * @brief Bit_SET and Bit_RESET enumeration
  4014. */
  4015. typedef enum
  4016. { Bit_RESET = 0,
  4017. Bit_SET
  4018. }BitAction;
  4019. #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
  4020. /**
  4021. * @}
  4022. */
  4023. /** @defgroup GPIO_Exported_Constants
  4024. * @{
  4025. */
  4026. /** @defgroup GPIO_pins_define
  4027. * @{
  4028. */
  4029. #define GPIO_Pin_0 ((uint16_t)0x0001) /*!< Pin 0 selected */
  4030. #define GPIO_Pin_1 ((uint16_t)0x0002) /*!< Pin 1 selected */
  4031. #define GPIO_Pin_2 ((uint16_t)0x0004) /*!< Pin 2 selected */
  4032. #define GPIO_Pin_3 ((uint16_t)0x0008) /*!< Pin 3 selected */
  4033. #define GPIO_Pin_4 ((uint16_t)0x0010) /*!< Pin 4 selected */
  4034. #define GPIO_Pin_5 ((uint16_t)0x0020) /*!< Pin 5 selected */
  4035. #define GPIO_Pin_6 ((uint16_t)0x0040) /*!< Pin 6 selected */
  4036. #define GPIO_Pin_7 ((uint16_t)0x0080) /*!< Pin 7 selected */
  4037. #define GPIO_Pin_8 ((uint16_t)0x0100) /*!< Pin 8 selected */
  4038. #define GPIO_Pin_9 ((uint16_t)0x0200) /*!< Pin 9 selected */
  4039. #define GPIO_Pin_10 ((uint16_t)0x0400) /*!< Pin 10 selected */
  4040. #define GPIO_Pin_11 ((uint16_t)0x0800) /*!< Pin 11 selected */
  4041. #define GPIO_Pin_12 ((uint16_t)0x1000) /*!< Pin 12 selected */
  4042. #define GPIO_Pin_13 ((uint16_t)0x2000) /*!< Pin 13 selected */
  4043. #define GPIO_Pin_14 ((uint16_t)0x4000) /*!< Pin 14 selected */
  4044. #define GPIO_Pin_15 ((uint16_t)0x8000) /*!< Pin 15 selected */
  4045. #define GPIO_Pin_All ((uint16_t)0xFFFF) /*!< All pins selected */
  4046. #define IS_GPIO_PIN(PIN) ((((PIN) & (uint16_t)0x00) == 0x00) && ((PIN) != (uint16_t)0x00))
  4047. #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
  4048. ((PIN) == GPIO_Pin_1) || \
  4049. ((PIN) == GPIO_Pin_2) || \
  4050. ((PIN) == GPIO_Pin_3) || \
  4051. ((PIN) == GPIO_Pin_4) || \
  4052. ((PIN) == GPIO_Pin_5) || \
  4053. ((PIN) == GPIO_Pin_6) || \
  4054. ((PIN) == GPIO_Pin_7) || \
  4055. ((PIN) == GPIO_Pin_8) || \
  4056. ((PIN) == GPIO_Pin_9) || \
  4057. ((PIN) == GPIO_Pin_10) || \
  4058. ((PIN) == GPIO_Pin_11) || \
  4059. ((PIN) == GPIO_Pin_12) || \
  4060. ((PIN) == GPIO_Pin_13) || \
  4061. ((PIN) == GPIO_Pin_14) || \
  4062. ((PIN) == GPIO_Pin_15))
  4063. /**
  4064. * @}
  4065. */
  4066. /** @defgroup GPIO_Remap_define
  4067. * @{
  4068. */
  4069. #define GPIO_Remap_SPI1 ((uint32_t)0x00000001) /*!< SPI1 Alternate Function mapping */
  4070. #define GPIO_Remap_I2C1 ((uint32_t)0x00000002) /*!< I2C1 Alternate Function mapping */
  4071. #define GPIO_Remap_USART1 ((uint32_t)0x00000004) /*!< USART1 Alternate Function mapping */
  4072. #define GPIO_Remap_USART2 ((uint32_t)0x00000008) /*!< USART2 Alternate Function mapping */
  4073. #define GPIO_PartialRemap_USART3 ((uint32_t)0x00140010) /*!< USART3 Partial Alternate Function mapping */
  4074. #define GPIO_FullRemap_USART3 ((uint32_t)0x00140030) /*!< USART3 Full Alternate Function mapping */
  4075. #define GPIO_PartialRemap_TIM1 ((uint32_t)0x00160040) /*!< TIM1 Partial Alternate Function mapping */
  4076. #define GPIO_FullRemap_TIM1 ((uint32_t)0x001600C0) /*!< TIM1 Full Alternate Function mapping */
  4077. #define GPIO_PartialRemap1_TIM2 ((uint32_t)0x00180100) /*!< TIM2 Partial1 Alternate Function mapping */
  4078. #define GPIO_PartialRemap2_TIM2 ((uint32_t)0x00180200) /*!< TIM2 Partial2 Alternate Function mapping */
  4079. #define GPIO_FullRemap_TIM2 ((uint32_t)0x00180300) /*!< TIM2 Full Alternate Function mapping */
  4080. #define GPIO_PartialRemap_TIM3 ((uint32_t)0x001A0800) /*!< TIM3 Partial Alternate Function mapping */
  4081. #define GPIO_FullRemap_TIM3 ((uint32_t)0x001A0C00) /*!< TIM3 Full Alternate Function mapping */
  4082. #define GPIO_Remap_TIM4 ((uint32_t)0x00001000) /*!< TIM4 Alternate Function mapping */
  4083. #define GPIO_Remap1_CAN1 ((uint32_t)0x001D4000) /*!< CAN1 Alternate Function mapping */
  4084. #define GPIO_Remap2_CAN1 ((uint32_t)0x001D6000) /*!< CAN1 Alternate Function mapping */
  4085. #define GPIO_Remap_PD01 ((uint32_t)0x00008000) /*!< PD01 Alternate Function mapping */
  4086. #define GPIO_Remap_TIM5CH4_LSI ((uint32_t)0x00200001) /*!< LSI connected to TIM5 Channel4 input capture for calibration */
  4087. #define GPIO_Remap_ADC1_ETRGINJ ((uint32_t)0x00200002) /*!< ADC1 External Trigger Injected Conversion remapping */
  4088. #define GPIO_Remap_ADC1_ETRGREG ((uint32_t)0x00200004) /*!< ADC1 External Trigger Regular Conversion remapping */
  4089. #define GPIO_Remap_ADC2_ETRGINJ ((uint32_t)0x00200008) /*!< ADC2 External Trigger Injected Conversion remapping */
  4090. #define GPIO_Remap_ADC2_ETRGREG ((uint32_t)0x00200010) /*!< ADC2 External Trigger Regular Conversion remapping */
  4091. #define GPIO_Remap_ETH ((uint32_t)0x00200020) /*!< Ethernet remapping (only for Connectivity line devices) */
  4092. #define GPIO_Remap_CAN2 ((uint32_t)0x00200040) /*!< CAN2 remapping (only for Connectivity line devices) */
  4093. #define GPIO_Remap_SWJ_NoJTRST ((uint32_t)0x00300100) /*!< Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST */
  4094. #define GPIO_Remap_SWJ_JTAGDisable ((uint32_t)0x00300200) /*!< JTAG-DP Disabled and SW-DP Enabled */
  4095. #define GPIO_Remap_SWJ_Disable ((uint32_t)0x00300400) /*!< Full SWJ Disabled (JTAG-DP + SW-DP) */
  4096. #define GPIO_Remap_SPI3 ((uint32_t)0x00201100) /*!< SPI3/I2S3 Alternate Function mapping (only for Connectivity line devices) */
  4097. #define GPIO_Remap_TIM2ITR1_PTP_SOF ((uint32_t)0x00202000) /*!< Ethernet PTP output or USB OTG SOF (Start of Frame) connected
  4098. to TIM2 Internal Trigger 1 for calibration
  4099. (only for Connectivity line devices) */
  4100. #define GPIO_Remap_PTP_PPS ((uint32_t)0x00204000) /*!< Ethernet MAC PPS_PTS output on PB05 (only for Connectivity line devices) */
  4101. #define GPIO_Remap_TIM15 ((uint32_t)0x80000001) /*!< TIM15 Alternate Function mapping (only for Value line devices) */
  4102. #define GPIO_Remap_TIM16 ((uint32_t)0x80000002) /*!< TIM16 Alternate Function mapping (only for Value line devices) */
  4103. #define GPIO_Remap_TIM17 ((uint32_t)0x80000004) /*!< TIM17 Alternate Function mapping (only for Value line devices) */
  4104. #define GPIO_Remap_CEC ((uint32_t)0x80000008) /*!< CEC Alternate Function mapping (only for Value line devices) */
  4105. #define GPIO_Remap_TIM1_DMA ((uint32_t)0x80000010) /*!< TIM1 DMA requests mapping (only for Value line devices) */
  4106. #define GPIO_Remap_TIM9 ((uint32_t)0x80000020) /*!< TIM9 Alternate Function mapping (only for XL-density devices) */
  4107. #define GPIO_Remap_TIM10 ((uint32_t)0x80000040) /*!< TIM10 Alternate Function mapping (only for XL-density devices) */
  4108. #define GPIO_Remap_TIM11 ((uint32_t)0x80000080) /*!< TIM11 Alternate Function mapping (only for XL-density devices) */
  4109. #define GPIO_Remap_TIM13 ((uint32_t)0x80000100) /*!< TIM13 Alternate Function mapping (only for High density Value line and XL-density devices) */
  4110. #define GPIO_Remap_TIM14 ((uint32_t)0x80000200) /*!< TIM14 Alternate Function mapping (only for High density Value line and XL-density devices) */
  4111. #define GPIO_Remap_FSMC_NADV ((uint32_t)0x80000400) /*!< FSMC_NADV Alternate Function mapping (only for High density Value line and XL-density devices) */
  4112. #define GPIO_Remap_TIM67_DAC_DMA ((uint32_t)0x80000800) /*!< TIM6/TIM7 and DAC DMA requests remapping (only for High density Value line devices) */
  4113. #define GPIO_Remap_TIM12 ((uint32_t)0x80001000) /*!< TIM12 Alternate Function mapping (only for High density Value line devices) */
  4114. #define GPIO_Remap_MISC ((uint32_t)0x80002000) /*!< Miscellaneous Remap (DMA2 Channel5 Position and DAC Trigger remapping,
  4115. only for High density Value line devices) */
  4116. #define IS_GPIO_REMAP(REMAP) (((REMAP) == GPIO_Remap_SPI1) || ((REMAP) == GPIO_Remap_I2C1) || \
  4117. ((REMAP) == GPIO_Remap_USART1) || ((REMAP) == GPIO_Remap_USART2) || \
  4118. ((REMAP) == GPIO_PartialRemap_USART3) || ((REMAP) == GPIO_FullRemap_USART3) || \
  4119. ((REMAP) == GPIO_PartialRemap_TIM1) || ((REMAP) == GPIO_FullRemap_TIM1) || \
  4120. ((REMAP) == GPIO_PartialRemap1_TIM2) || ((REMAP) == GPIO_PartialRemap2_TIM2) || \
  4121. ((REMAP) == GPIO_FullRemap_TIM2) || ((REMAP) == GPIO_PartialRemap_TIM3) || \
  4122. ((REMAP) == GPIO_FullRemap_TIM3) || ((REMAP) == GPIO_Remap_TIM4) || \
  4123. ((REMAP) == GPIO_Remap1_CAN1) || ((REMAP) == GPIO_Remap2_CAN1) || \
  4124. ((REMAP) == GPIO_Remap_PD01) || ((REMAP) == GPIO_Remap_TIM5CH4_LSI) || \
  4125. ((REMAP) == GPIO_Remap_ADC1_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC1_ETRGREG) || \
  4126. ((REMAP) == GPIO_Remap_ADC2_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC2_ETRGREG) || \
  4127. ((REMAP) == GPIO_Remap_ETH) ||((REMAP) == GPIO_Remap_CAN2) || \
  4128. ((REMAP) == GPIO_Remap_SWJ_NoJTRST) || ((REMAP) == GPIO_Remap_SWJ_JTAGDisable) || \
  4129. ((REMAP) == GPIO_Remap_SWJ_Disable)|| ((REMAP) == GPIO_Remap_SPI3) || \
  4130. ((REMAP) == GPIO_Remap_TIM2ITR1_PTP_SOF) || ((REMAP) == GPIO_Remap_PTP_PPS) || \
  4131. ((REMAP) == GPIO_Remap_TIM15) || ((REMAP) == GPIO_Remap_TIM16) || \
  4132. ((REMAP) == GPIO_Remap_TIM17) || ((REMAP) == GPIO_Remap_CEC) || \
  4133. ((REMAP) == GPIO_Remap_TIM1_DMA) || ((REMAP) == GPIO_Remap_TIM9) || \
  4134. ((REMAP) == GPIO_Remap_TIM10) || ((REMAP) == GPIO_Remap_TIM11) || \
  4135. ((REMAP) == GPIO_Remap_TIM13) || ((REMAP) == GPIO_Remap_TIM14) || \
  4136. ((REMAP) == GPIO_Remap_FSMC_NADV) || ((REMAP) == GPIO_Remap_TIM67_DAC_DMA) || \
  4137. ((REMAP) == GPIO_Remap_TIM12) || ((REMAP) == GPIO_Remap_MISC))
  4138. /**
  4139. * @}
  4140. */
  4141. /** @defgroup GPIO_Port_Sources
  4142. * @{
  4143. */
  4144. #define GPIO_PortSourceGPIOA ((uint8_t)0x00)
  4145. #define GPIO_PortSourceGPIOB ((uint8_t)0x01)
  4146. #define GPIO_PortSourceGPIOC ((uint8_t)0x02)
  4147. #define GPIO_PortSourceGPIOD ((uint8_t)0x03)
  4148. #define GPIO_PortSourceGPIOE ((uint8_t)0x04)
  4149. #define GPIO_PortSourceGPIOF ((uint8_t)0x05)
  4150. #define GPIO_PortSourceGPIOG ((uint8_t)0x06)
  4151. #define IS_GPIO_EVENTOUT_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
  4152. ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
  4153. ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
  4154. ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
  4155. ((PORTSOURCE) == GPIO_PortSourceGPIOE))
  4156. #define IS_GPIO_EXTI_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
  4157. ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
  4158. ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
  4159. ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
  4160. ((PORTSOURCE) == GPIO_PortSourceGPIOE) || \
  4161. ((PORTSOURCE) == GPIO_PortSourceGPIOF) || \
  4162. ((PORTSOURCE) == GPIO_PortSourceGPIOG))
  4163. /**
  4164. * @}
  4165. */
  4166. /** @defgroup GPIO_Pin_sources
  4167. * @{
  4168. */
  4169. #define GPIO_PinSource0 ((uint8_t)0x00)
  4170. #define GPIO_PinSource1 ((uint8_t)0x01)
  4171. #define GPIO_PinSource2 ((uint8_t)0x02)
  4172. #define GPIO_PinSource3 ((uint8_t)0x03)
  4173. #define GPIO_PinSource4 ((uint8_t)0x04)
  4174. #define GPIO_PinSource5 ((uint8_t)0x05)
  4175. #define GPIO_PinSource6 ((uint8_t)0x06)
  4176. #define GPIO_PinSource7 ((uint8_t)0x07)
  4177. #define GPIO_PinSource8 ((uint8_t)0x08)
  4178. #define GPIO_PinSource9 ((uint8_t)0x09)
  4179. #define GPIO_PinSource10 ((uint8_t)0x0A)
  4180. #define GPIO_PinSource11 ((uint8_t)0x0B)
  4181. #define GPIO_PinSource12 ((uint8_t)0x0C)
  4182. #define GPIO_PinSource13 ((uint8_t)0x0D)
  4183. #define GPIO_PinSource14 ((uint8_t)0x0E)
  4184. #define GPIO_PinSource15 ((uint8_t)0x0F)
  4185. #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
  4186. ((PINSOURCE) == GPIO_PinSource1) || \
  4187. ((PINSOURCE) == GPIO_PinSource2) || \
  4188. ((PINSOURCE) == GPIO_PinSource3) || \
  4189. ((PINSOURCE) == GPIO_PinSource4) || \
  4190. ((PINSOURCE) == GPIO_PinSource5) || \
  4191. ((PINSOURCE) == GPIO_PinSource6) || \
  4192. ((PINSOURCE) == GPIO_PinSource7) || \
  4193. ((PINSOURCE) == GPIO_PinSource8) || \
  4194. ((PINSOURCE) == GPIO_PinSource9) || \
  4195. ((PINSOURCE) == GPIO_PinSource10) || \
  4196. ((PINSOURCE) == GPIO_PinSource11) || \
  4197. ((PINSOURCE) == GPIO_PinSource12) || \
  4198. ((PINSOURCE) == GPIO_PinSource13) || \
  4199. ((PINSOURCE) == GPIO_PinSource14) || \
  4200. ((PINSOURCE) == GPIO_PinSource15))
  4201. /**
  4202. * @}
  4203. */
  4204. /** @defgroup Ethernet_Media_Interface
  4205. * @{
  4206. */
  4207. #define GPIO_ETH_MediaInterface_MII ((u32)0x00000000)
  4208. #define GPIO_ETH_MediaInterface_RMII ((u32)0x00000001)
  4209. #define IS_GPIO_ETH_MEDIA_INTERFACE(INTERFACE) (((INTERFACE) == GPIO_ETH_MediaInterface_MII) || \
  4210. ((INTERFACE) == GPIO_ETH_MediaInterface_RMII))
  4211. /**
  4212. * @}
  4213. */
  4214. /**
  4215. * @}
  4216. */
  4217. /** @defgroup GPIO_Exported_Macros
  4218. * @{
  4219. */
  4220. /**
  4221. * @}
  4222. */
  4223. /** @defgroup GPIO_Exported_Functions
  4224. * @{
  4225. */
  4226. void GPIO_DeInit(GPIO_TypeDef* GPIOx);
  4227. void GPIO_AFIODeInit(void);
  4228. void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
  4229. void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
  4230. uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  4231. uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
  4232. uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  4233. uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
  4234. void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  4235. void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  4236. void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
  4237. void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
  4238. void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  4239. void GPIO_EventOutputConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
  4240. void GPIO_EventOutputCmd(FunctionalState NewState);
  4241. void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState);
  4242. void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
  4243. void GPIO_ETH_MediaInterfaceConfig(uint32_t GPIO_ETH_MediaInterface);
  4244. #ifdef __cplusplus
  4245. }
  4246. #endif
  4247. #endif /* __STM32F10x_GPIO_H */
  4248. /**
  4249. * @}
  4250. */
  4251. /**
  4252. * @}
  4253. */
  4254. /**
  4255. * @}
  4256. */
  4257. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  4258. /**
  4259. ******************************************************************************
  4260. * @file stm32f10x_crc.h
  4261. * @author MCD Application Team
  4262. * @version V3.5.0
  4263. * @date 11-March-2011
  4264. * @brief This file contains all the functions prototypes for the CRC firmware
  4265. * library.
  4266. ******************************************************************************
  4267. * @attention
  4268. *
  4269. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  4270. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  4271. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  4272. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  4273. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  4274. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  4275. *
  4276. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  4277. ******************************************************************************
  4278. */
  4279. /* Define to prevent recursive inclusion -------------------------------------*/
  4280. #ifndef __STM32F10x_CRC_H
  4281. #define __STM32F10x_CRC_H
  4282. #ifdef __cplusplus
  4283. extern "C" {
  4284. #endif
  4285. /* Includes ------------------------------------------------------------------*/
  4286. #include "stm32f10x.h"
  4287. /** @addtogroup STM32F10x_StdPeriph_Driver
  4288. * @{
  4289. */
  4290. /** @addtogroup CRC
  4291. * @{
  4292. */
  4293. /** @defgroup CRC_Exported_Types
  4294. * @{
  4295. */
  4296. /**
  4297. * @}
  4298. */
  4299. /** @defgroup CRC_Exported_Constants
  4300. * @{
  4301. */
  4302. /**
  4303. * @}
  4304. */
  4305. /** @defgroup CRC_Exported_Macros
  4306. * @{
  4307. */
  4308. /**
  4309. * @}
  4310. */
  4311. /** @defgroup CRC_Exported_Functions
  4312. * @{
  4313. */
  4314. void CRC_ResetDR(void);
  4315. uint32_t CRC_CalcCRC(uint32_t Data);
  4316. uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength);
  4317. uint32_t CRC_GetCRC(void);
  4318. void CRC_SetIDRegister(uint8_t IDValue);
  4319. uint8_t CRC_GetIDRegister(void);
  4320. #ifdef __cplusplus
  4321. }
  4322. #endif
  4323. #endif /* __STM32F10x_CRC_H */
  4324. /**
  4325. * @}
  4326. */
  4327. /**
  4328. * @}
  4329. */
  4330. /**
  4331. * @}
  4332. */
  4333. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  4334. /**
  4335. ******************************************************************************
  4336. * @file stm32f10x_rtc.h
  4337. * @author MCD Application Team
  4338. * @version V3.5.0
  4339. * @date 11-March-2011
  4340. * @brief This file contains all the functions prototypes for the RTC firmware
  4341. * library.
  4342. ******************************************************************************
  4343. * @attention
  4344. *
  4345. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  4346. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  4347. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  4348. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  4349. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  4350. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  4351. *
  4352. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  4353. ******************************************************************************
  4354. */
  4355. /* Define to prevent recursive inclusion -------------------------------------*/
  4356. #ifndef __STM32F10x_RTC_H
  4357. #define __STM32F10x_RTC_H
  4358. #ifdef __cplusplus
  4359. extern "C" {
  4360. #endif
  4361. /* Includes ------------------------------------------------------------------*/
  4362. #include "stm32f10x.h"
  4363. /** @addtogroup STM32F10x_StdPeriph_Driver
  4364. * @{
  4365. */
  4366. /** @addtogroup RTC
  4367. * @{
  4368. */
  4369. /** @defgroup RTC_Exported_Types
  4370. * @{
  4371. */
  4372. /**
  4373. * @}
  4374. */
  4375. /** @defgroup RTC_Exported_Constants
  4376. * @{
  4377. */
  4378. /** @defgroup RTC_interrupts_define
  4379. * @{
  4380. */
  4381. #define RTC_IT_OW ((uint16_t)0x0004) /*!< Overflow interrupt */
  4382. #define RTC_IT_ALR ((uint16_t)0x0002) /*!< Alarm interrupt */
  4383. #define RTC_IT_SEC ((uint16_t)0x0001) /*!< Second interrupt */
  4384. #define IS_RTC_IT(IT) ((((IT) & (uint16_t)0xFFF8) == 0x00) && ((IT) != 0x00))
  4385. #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_OW) || ((IT) == RTC_IT_ALR) || \
  4386. ((IT) == RTC_IT_SEC))
  4387. /**
  4388. * @}
  4389. */
  4390. /** @defgroup RTC_interrupts_flags
  4391. * @{
  4392. */
  4393. #define RTC_FLAG_RTOFF ((uint16_t)0x0020) /*!< RTC Operation OFF flag */
  4394. #define RTC_FLAG_RSF ((uint16_t)0x0008) /*!< Registers Synchronized flag */
  4395. #define RTC_FLAG_OW ((uint16_t)0x0004) /*!< Overflow flag */
  4396. #define RTC_FLAG_ALR ((uint16_t)0x0002) /*!< Alarm flag */
  4397. #define RTC_FLAG_SEC ((uint16_t)0x0001) /*!< Second flag */
  4398. #define IS_RTC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFF0) == 0x00) && ((FLAG) != 0x00))
  4399. #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RTOFF) || ((FLAG) == RTC_FLAG_RSF) || \
  4400. ((FLAG) == RTC_FLAG_OW) || ((FLAG) == RTC_FLAG_ALR) || \
  4401. ((FLAG) == RTC_FLAG_SEC))
  4402. #define IS_RTC_PRESCALER(PRESCALER) ((PRESCALER) <= 0xFFFFF)
  4403. /**
  4404. * @}
  4405. */
  4406. /**
  4407. * @}
  4408. */
  4409. /** @defgroup RTC_Exported_Macros
  4410. * @{
  4411. */
  4412. /**
  4413. * @}
  4414. */
  4415. /** @defgroup RTC_Exported_Functions
  4416. * @{
  4417. */
  4418. void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState);
  4419. void RTC_EnterConfigMode(void);
  4420. void RTC_ExitConfigMode(void);
  4421. uint32_t RTC_GetCounter(void);
  4422. void RTC_SetCounter(uint32_t CounterValue);
  4423. void RTC_SetPrescaler(uint32_t PrescalerValue);
  4424. void RTC_SetAlarm(uint32_t AlarmValue);
  4425. uint32_t RTC_GetDivider(void);
  4426. void RTC_WaitForLastTask(void);
  4427. void RTC_WaitForSynchro(void);
  4428. FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG);
  4429. void RTC_ClearFlag(uint16_t RTC_FLAG);
  4430. ITStatus RTC_GetITStatus(uint16_t RTC_IT);
  4431. void RTC_ClearITPendingBit(uint16_t RTC_IT);
  4432. #ifdef __cplusplus
  4433. }
  4434. #endif
  4435. #endif /* __STM32F10x_RTC_H */
  4436. /**
  4437. * @}
  4438. */
  4439. /**
  4440. * @}
  4441. */
  4442. /**
  4443. * @}
  4444. */
  4445. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  4446. /**
  4447. ******************************************************************************
  4448. * @file stm32f10x_dma.h
  4449. * @author MCD Application Team
  4450. * @version V3.5.0
  4451. * @date 11-March-2011
  4452. * @brief This file contains all the functions prototypes for the DMA firmware
  4453. * library.
  4454. ******************************************************************************
  4455. * @attention
  4456. *
  4457. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  4458. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  4459. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  4460. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  4461. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  4462. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  4463. *
  4464. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  4465. ******************************************************************************
  4466. */
  4467. /* Define to prevent recursive inclusion -------------------------------------*/
  4468. #ifndef __STM32F10x_DMA_H
  4469. #define __STM32F10x_DMA_H
  4470. #ifdef __cplusplus
  4471. extern "C" {
  4472. #endif
  4473. /* Includes ------------------------------------------------------------------*/
  4474. #include "stm32f10x.h"
  4475. /** @addtogroup STM32F10x_StdPeriph_Driver
  4476. * @{
  4477. */
  4478. /** @addtogroup DMA
  4479. * @{
  4480. */
  4481. /** @defgroup DMA_Exported_Types
  4482. * @{
  4483. */
  4484. /**
  4485. * @brief DMA Init structure definition
  4486. */
  4487. typedef struct
  4488. {
  4489. uint32_t DMA_PeripheralBaseAddr; /*!< Specifies the peripheral base address for DMAy Channelx. */
  4490. uint32_t DMA_MemoryBaseAddr; /*!< Specifies the memory base address for DMAy Channelx. */
  4491. uint32_t DMA_DIR; /*!< Specifies if the peripheral is the source or destination.
  4492. This parameter can be a value of @ref DMA_data_transfer_direction */
  4493. uint32_t DMA_BufferSize; /*!< Specifies the buffer size, in data unit, of the specified Channel.
  4494. The data unit is equal to the configuration set in DMA_PeripheralDataSize
  4495. or DMA_MemoryDataSize members depending in the transfer direction. */
  4496. uint32_t DMA_PeripheralInc; /*!< Specifies whether the Peripheral address register is incremented or not.
  4497. This parameter can be a value of @ref DMA_peripheral_incremented_mode */
  4498. uint32_t DMA_MemoryInc; /*!< Specifies whether the memory address register is incremented or not.
  4499. This parameter can be a value of @ref DMA_memory_incremented_mode */
  4500. uint32_t DMA_PeripheralDataSize; /*!< Specifies the Peripheral data width.
  4501. This parameter can be a value of @ref DMA_peripheral_data_size */
  4502. uint32_t DMA_MemoryDataSize; /*!< Specifies the Memory data width.
  4503. This parameter can be a value of @ref DMA_memory_data_size */
  4504. uint32_t DMA_Mode; /*!< Specifies the operation mode of the DMAy Channelx.
  4505. This parameter can be a value of @ref DMA_circular_normal_mode.
  4506. @note: The circular buffer mode cannot be used if the memory-to-memory
  4507. data transfer is configured on the selected Channel */
  4508. uint32_t DMA_Priority; /*!< Specifies the software priority for the DMAy Channelx.
  4509. This parameter can be a value of @ref DMA_priority_level */
  4510. uint32_t DMA_M2M; /*!< Specifies if the DMAy Channelx will be used in memory-to-memory transfer.
  4511. This parameter can be a value of @ref DMA_memory_to_memory */
  4512. }DMA_InitTypeDef;
  4513. /**
  4514. * @}
  4515. */
  4516. /** @defgroup DMA_Exported_Constants
  4517. * @{
  4518. */
  4519. #define IS_DMA_ALL_PERIPH(PERIPH) (((PERIPH) == DMA1_Channel1) || \
  4520. ((PERIPH) == DMA1_Channel2) || \
  4521. ((PERIPH) == DMA1_Channel3) || \
  4522. ((PERIPH) == DMA1_Channel4) || \
  4523. ((PERIPH) == DMA1_Channel5) || \
  4524. ((PERIPH) == DMA1_Channel6) || \
  4525. ((PERIPH) == DMA1_Channel7) || \
  4526. ((PERIPH) == DMA2_Channel1) || \
  4527. ((PERIPH) == DMA2_Channel2) || \
  4528. ((PERIPH) == DMA2_Channel3) || \
  4529. ((PERIPH) == DMA2_Channel4) || \
  4530. ((PERIPH) == DMA2_Channel5))
  4531. /** @defgroup DMA_data_transfer_direction
  4532. * @{
  4533. */
  4534. #define DMA_DIR_PeripheralDST ((uint32_t)0x00000010)
  4535. #define DMA_DIR_PeripheralSRC ((uint32_t)0x00000000)
  4536. #define IS_DMA_DIR(DIR) (((DIR) == DMA_DIR_PeripheralDST) || \
  4537. ((DIR) == DMA_DIR_PeripheralSRC))
  4538. /**
  4539. * @}
  4540. */
  4541. /** @defgroup DMA_peripheral_incremented_mode
  4542. * @{
  4543. */
  4544. #define DMA_PeripheralInc_Enable ((uint32_t)0x00000040)
  4545. #define DMA_PeripheralInc_Disable ((uint32_t)0x00000000)
  4546. #define IS_DMA_PERIPHERAL_INC_STATE(STATE) (((STATE) == DMA_PeripheralInc_Enable) || \
  4547. ((STATE) == DMA_PeripheralInc_Disable))
  4548. /**
  4549. * @}
  4550. */
  4551. /** @defgroup DMA_memory_incremented_mode
  4552. * @{
  4553. */
  4554. #define DMA_MemoryInc_Enable ((uint32_t)0x00000080)
  4555. #define DMA_MemoryInc_Disable ((uint32_t)0x00000000)
  4556. #define IS_DMA_MEMORY_INC_STATE(STATE) (((STATE) == DMA_MemoryInc_Enable) || \
  4557. ((STATE) == DMA_MemoryInc_Disable))
  4558. /**
  4559. * @}
  4560. */
  4561. /** @defgroup DMA_peripheral_data_size
  4562. * @{
  4563. */
  4564. #define DMA_PeripheralDataSize_Byte ((uint32_t)0x00000000)
  4565. #define DMA_PeripheralDataSize_HalfWord ((uint32_t)0x00000100)
  4566. #define DMA_PeripheralDataSize_Word ((uint32_t)0x00000200)
  4567. #define IS_DMA_PERIPHERAL_DATA_SIZE(SIZE) (((SIZE) == DMA_PeripheralDataSize_Byte) || \
  4568. ((SIZE) == DMA_PeripheralDataSize_HalfWord) || \
  4569. ((SIZE) == DMA_PeripheralDataSize_Word))
  4570. /**
  4571. * @}
  4572. */
  4573. /** @defgroup DMA_memory_data_size
  4574. * @{
  4575. */
  4576. #define DMA_MemoryDataSize_Byte ((uint32_t)0x00000000)
  4577. #define DMA_MemoryDataSize_HalfWord ((uint32_t)0x00000400)
  4578. #define DMA_MemoryDataSize_Word ((uint32_t)0x00000800)
  4579. #define IS_DMA_MEMORY_DATA_SIZE(SIZE) (((SIZE) == DMA_MemoryDataSize_Byte) || \
  4580. ((SIZE) == DMA_MemoryDataSize_HalfWord) || \
  4581. ((SIZE) == DMA_MemoryDataSize_Word))
  4582. /**
  4583. * @}
  4584. */
  4585. /** @defgroup DMA_circular_normal_mode
  4586. * @{
  4587. */
  4588. #define DMA_Mode_Circular ((uint32_t)0x00000020)
  4589. #define DMA_Mode_Normal ((uint32_t)0x00000000)
  4590. #define IS_DMA_MODE(MODE) (((MODE) == DMA_Mode_Circular) || ((MODE) == DMA_Mode_Normal))
  4591. /**
  4592. * @}
  4593. */
  4594. /** @defgroup DMA_priority_level
  4595. * @{
  4596. */
  4597. #define DMA_Priority_VeryHigh ((uint32_t)0x00003000)
  4598. #define DMA_Priority_High ((uint32_t)0x00002000)
  4599. #define DMA_Priority_Medium ((uint32_t)0x00001000)
  4600. #define DMA_Priority_Low ((uint32_t)0x00000000)
  4601. #define IS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_Priority_VeryHigh) || \
  4602. ((PRIORITY) == DMA_Priority_High) || \
  4603. ((PRIORITY) == DMA_Priority_Medium) || \
  4604. ((PRIORITY) == DMA_Priority_Low))
  4605. /**
  4606. * @}
  4607. */
  4608. /** @defgroup DMA_memory_to_memory
  4609. * @{
  4610. */
  4611. #define DMA_M2M_Enable ((uint32_t)0x00004000)
  4612. #define DMA_M2M_Disable ((uint32_t)0x00000000)
  4613. #define IS_DMA_M2M_STATE(STATE) (((STATE) == DMA_M2M_Enable) || ((STATE) == DMA_M2M_Disable))
  4614. /**
  4615. * @}
  4616. */
  4617. /** @defgroup DMA_interrupts_definition
  4618. * @{
  4619. */
  4620. #define DMA_IT_TC ((uint32_t)0x00000002)
  4621. #define DMA_IT_HT ((uint32_t)0x00000004)
  4622. #define DMA_IT_TE ((uint32_t)0x00000008)
  4623. #define IS_DMA_CONFIG_IT(IT) ((((IT) & 0xFFFFFFF1) == 0x00) && ((IT) != 0x00))
  4624. #define DMA1_IT_GL1 ((uint32_t)0x00000001)
  4625. #define DMA1_IT_TC1 ((uint32_t)0x00000002)
  4626. #define DMA1_IT_HT1 ((uint32_t)0x00000004)
  4627. #define DMA1_IT_TE1 ((uint32_t)0x00000008)
  4628. #define DMA1_IT_GL2 ((uint32_t)0x00000010)
  4629. #define DMA1_IT_TC2 ((uint32_t)0x00000020)
  4630. #define DMA1_IT_HT2 ((uint32_t)0x00000040)
  4631. #define DMA1_IT_TE2 ((uint32_t)0x00000080)
  4632. #define DMA1_IT_GL3 ((uint32_t)0x00000100)
  4633. #define DMA1_IT_TC3 ((uint32_t)0x00000200)
  4634. #define DMA1_IT_HT3 ((uint32_t)0x00000400)
  4635. #define DMA1_IT_TE3 ((uint32_t)0x00000800)
  4636. #define DMA1_IT_GL4 ((uint32_t)0x00001000)
  4637. #define DMA1_IT_TC4 ((uint32_t)0x00002000)
  4638. #define DMA1_IT_HT4 ((uint32_t)0x00004000)
  4639. #define DMA1_IT_TE4 ((uint32_t)0x00008000)
  4640. #define DMA1_IT_GL5 ((uint32_t)0x00010000)
  4641. #define DMA1_IT_TC5 ((uint32_t)0x00020000)
  4642. #define DMA1_IT_HT5 ((uint32_t)0x00040000)
  4643. #define DMA1_IT_TE5 ((uint32_t)0x00080000)
  4644. #define DMA1_IT_GL6 ((uint32_t)0x00100000)
  4645. #define DMA1_IT_TC6 ((uint32_t)0x00200000)
  4646. #define DMA1_IT_HT6 ((uint32_t)0x00400000)
  4647. #define DMA1_IT_TE6 ((uint32_t)0x00800000)
  4648. #define DMA1_IT_GL7 ((uint32_t)0x01000000)
  4649. #define DMA1_IT_TC7 ((uint32_t)0x02000000)
  4650. #define DMA1_IT_HT7 ((uint32_t)0x04000000)
  4651. #define DMA1_IT_TE7 ((uint32_t)0x08000000)
  4652. #define DMA2_IT_GL1 ((uint32_t)0x10000001)
  4653. #define DMA2_IT_TC1 ((uint32_t)0x10000002)
  4654. #define DMA2_IT_HT1 ((uint32_t)0x10000004)
  4655. #define DMA2_IT_TE1 ((uint32_t)0x10000008)
  4656. #define DMA2_IT_GL2 ((uint32_t)0x10000010)
  4657. #define DMA2_IT_TC2 ((uint32_t)0x10000020)
  4658. #define DMA2_IT_HT2 ((uint32_t)0x10000040)
  4659. #define DMA2_IT_TE2 ((uint32_t)0x10000080)
  4660. #define DMA2_IT_GL3 ((uint32_t)0x10000100)
  4661. #define DMA2_IT_TC3 ((uint32_t)0x10000200)
  4662. #define DMA2_IT_HT3 ((uint32_t)0x10000400)
  4663. #define DMA2_IT_TE3 ((uint32_t)0x10000800)
  4664. #define DMA2_IT_GL4 ((uint32_t)0x10001000)
  4665. #define DMA2_IT_TC4 ((uint32_t)0x10002000)
  4666. #define DMA2_IT_HT4 ((uint32_t)0x10004000)
  4667. #define DMA2_IT_TE4 ((uint32_t)0x10008000)
  4668. #define DMA2_IT_GL5 ((uint32_t)0x10010000)
  4669. #define DMA2_IT_TC5 ((uint32_t)0x10020000)
  4670. #define DMA2_IT_HT5 ((uint32_t)0x10040000)
  4671. #define DMA2_IT_TE5 ((uint32_t)0x10080000)
  4672. #define IS_DMA_CLEAR_IT(IT) (((((IT) & 0xF0000000) == 0x00) || (((IT) & 0xEFF00000) == 0x00)) && ((IT) != 0x00))
  4673. #define IS_DMA_GET_IT(IT) (((IT) == DMA1_IT_GL1) || ((IT) == DMA1_IT_TC1) || \
  4674. ((IT) == DMA1_IT_HT1) || ((IT) == DMA1_IT_TE1) || \
  4675. ((IT) == DMA1_IT_GL2) || ((IT) == DMA1_IT_TC2) || \
  4676. ((IT) == DMA1_IT_HT2) || ((IT) == DMA1_IT_TE2) || \
  4677. ((IT) == DMA1_IT_GL3) || ((IT) == DMA1_IT_TC3) || \
  4678. ((IT) == DMA1_IT_HT3) || ((IT) == DMA1_IT_TE3) || \
  4679. ((IT) == DMA1_IT_GL4) || ((IT) == DMA1_IT_TC4) || \
  4680. ((IT) == DMA1_IT_HT4) || ((IT) == DMA1_IT_TE4) || \
  4681. ((IT) == DMA1_IT_GL5) || ((IT) == DMA1_IT_TC5) || \
  4682. ((IT) == DMA1_IT_HT5) || ((IT) == DMA1_IT_TE5) || \
  4683. ((IT) == DMA1_IT_GL6) || ((IT) == DMA1_IT_TC6) || \
  4684. ((IT) == DMA1_IT_HT6) || ((IT) == DMA1_IT_TE6) || \
  4685. ((IT) == DMA1_IT_GL7) || ((IT) == DMA1_IT_TC7) || \
  4686. ((IT) == DMA1_IT_HT7) || ((IT) == DMA1_IT_TE7) || \
  4687. ((IT) == DMA2_IT_GL1) || ((IT) == DMA2_IT_TC1) || \
  4688. ((IT) == DMA2_IT_HT1) || ((IT) == DMA2_IT_TE1) || \
  4689. ((IT) == DMA2_IT_GL2) || ((IT) == DMA2_IT_TC2) || \
  4690. ((IT) == DMA2_IT_HT2) || ((IT) == DMA2_IT_TE2) || \
  4691. ((IT) == DMA2_IT_GL3) || ((IT) == DMA2_IT_TC3) || \
  4692. ((IT) == DMA2_IT_HT3) || ((IT) == DMA2_IT_TE3) || \
  4693. ((IT) == DMA2_IT_GL4) || ((IT) == DMA2_IT_TC4) || \
  4694. ((IT) == DMA2_IT_HT4) || ((IT) == DMA2_IT_TE4) || \
  4695. ((IT) == DMA2_IT_GL5) || ((IT) == DMA2_IT_TC5) || \
  4696. ((IT) == DMA2_IT_HT5) || ((IT) == DMA2_IT_TE5))
  4697. /**
  4698. * @}
  4699. */
  4700. /** @defgroup DMA_flags_definition
  4701. * @{
  4702. */
  4703. #define DMA1_FLAG_GL1 ((uint32_t)0x00000001)
  4704. #define DMA1_FLAG_TC1 ((uint32_t)0x00000002)
  4705. #define DMA1_FLAG_HT1 ((uint32_t)0x00000004)
  4706. #define DMA1_FLAG_TE1 ((uint32_t)0x00000008)
  4707. #define DMA1_FLAG_GL2 ((uint32_t)0x00000010)
  4708. #define DMA1_FLAG_TC2 ((uint32_t)0x00000020)
  4709. #define DMA1_FLAG_HT2 ((uint32_t)0x00000040)
  4710. #define DMA1_FLAG_TE2 ((uint32_t)0x00000080)
  4711. #define DMA1_FLAG_GL3 ((uint32_t)0x00000100)
  4712. #define DMA1_FLAG_TC3 ((uint32_t)0x00000200)
  4713. #define DMA1_FLAG_HT3 ((uint32_t)0x00000400)
  4714. #define DMA1_FLAG_TE3 ((uint32_t)0x00000800)
  4715. #define DMA1_FLAG_GL4 ((uint32_t)0x00001000)
  4716. #define DMA1_FLAG_TC4 ((uint32_t)0x00002000)
  4717. #define DMA1_FLAG_HT4 ((uint32_t)0x00004000)
  4718. #define DMA1_FLAG_TE4 ((uint32_t)0x00008000)
  4719. #define DMA1_FLAG_GL5 ((uint32_t)0x00010000)
  4720. #define DMA1_FLAG_TC5 ((uint32_t)0x00020000)
  4721. #define DMA1_FLAG_HT5 ((uint32_t)0x00040000)
  4722. #define DMA1_FLAG_TE5 ((uint32_t)0x00080000)
  4723. #define DMA1_FLAG_GL6 ((uint32_t)0x00100000)
  4724. #define DMA1_FLAG_TC6 ((uint32_t)0x00200000)
  4725. #define DMA1_FLAG_HT6 ((uint32_t)0x00400000)
  4726. #define DMA1_FLAG_TE6 ((uint32_t)0x00800000)
  4727. #define DMA1_FLAG_GL7 ((uint32_t)0x01000000)
  4728. #define DMA1_FLAG_TC7 ((uint32_t)0x02000000)
  4729. #define DMA1_FLAG_HT7 ((uint32_t)0x04000000)
  4730. #define DMA1_FLAG_TE7 ((uint32_t)0x08000000)
  4731. #define DMA2_FLAG_GL1 ((uint32_t)0x10000001)
  4732. #define DMA2_FLAG_TC1 ((uint32_t)0x10000002)
  4733. #define DMA2_FLAG_HT1 ((uint32_t)0x10000004)
  4734. #define DMA2_FLAG_TE1 ((uint32_t)0x10000008)
  4735. #define DMA2_FLAG_GL2 ((uint32_t)0x10000010)
  4736. #define DMA2_FLAG_TC2 ((uint32_t)0x10000020)
  4737. #define DMA2_FLAG_HT2 ((uint32_t)0x10000040)
  4738. #define DMA2_FLAG_TE2 ((uint32_t)0x10000080)
  4739. #define DMA2_FLAG_GL3 ((uint32_t)0x10000100)
  4740. #define DMA2_FLAG_TC3 ((uint32_t)0x10000200)
  4741. #define DMA2_FLAG_HT3 ((uint32_t)0x10000400)
  4742. #define DMA2_FLAG_TE3 ((uint32_t)0x10000800)
  4743. #define DMA2_FLAG_GL4 ((uint32_t)0x10001000)
  4744. #define DMA2_FLAG_TC4 ((uint32_t)0x10002000)
  4745. #define DMA2_FLAG_HT4 ((uint32_t)0x10004000)
  4746. #define DMA2_FLAG_TE4 ((uint32_t)0x10008000)
  4747. #define DMA2_FLAG_GL5 ((uint32_t)0x10010000)
  4748. #define DMA2_FLAG_TC5 ((uint32_t)0x10020000)
  4749. #define DMA2_FLAG_HT5 ((uint32_t)0x10040000)
  4750. #define DMA2_FLAG_TE5 ((uint32_t)0x10080000)
  4751. #define IS_DMA_CLEAR_FLAG(FLAG) (((((FLAG) & 0xF0000000) == 0x00) || (((FLAG) & 0xEFF00000) == 0x00)) && ((FLAG) != 0x00))
  4752. #define IS_DMA_GET_FLAG(FLAG) (((FLAG) == DMA1_FLAG_GL1) || ((FLAG) == DMA1_FLAG_TC1) || \
  4753. ((FLAG) == DMA1_FLAG_HT1) || ((FLAG) == DMA1_FLAG_TE1) || \
  4754. ((FLAG) == DMA1_FLAG_GL2) || ((FLAG) == DMA1_FLAG_TC2) || \
  4755. ((FLAG) == DMA1_FLAG_HT2) || ((FLAG) == DMA1_FLAG_TE2) || \
  4756. ((FLAG) == DMA1_FLAG_GL3) || ((FLAG) == DMA1_FLAG_TC3) || \
  4757. ((FLAG) == DMA1_FLAG_HT3) || ((FLAG) == DMA1_FLAG_TE3) || \
  4758. ((FLAG) == DMA1_FLAG_GL4) || ((FLAG) == DMA1_FLAG_TC4) || \
  4759. ((FLAG) == DMA1_FLAG_HT4) || ((FLAG) == DMA1_FLAG_TE4) || \
  4760. ((FLAG) == DMA1_FLAG_GL5) || ((FLAG) == DMA1_FLAG_TC5) || \
  4761. ((FLAG) == DMA1_FLAG_HT5) || ((FLAG) == DMA1_FLAG_TE5) || \
  4762. ((FLAG) == DMA1_FLAG_GL6) || ((FLAG) == DMA1_FLAG_TC6) || \
  4763. ((FLAG) == DMA1_FLAG_HT6) || ((FLAG) == DMA1_FLAG_TE6) || \
  4764. ((FLAG) == DMA1_FLAG_GL7) || ((FLAG) == DMA1_FLAG_TC7) || \
  4765. ((FLAG) == DMA1_FLAG_HT7) || ((FLAG) == DMA1_FLAG_TE7) || \
  4766. ((FLAG) == DMA2_FLAG_GL1) || ((FLAG) == DMA2_FLAG_TC1) || \
  4767. ((FLAG) == DMA2_FLAG_HT1) || ((FLAG) == DMA2_FLAG_TE1) || \
  4768. ((FLAG) == DMA2_FLAG_GL2) || ((FLAG) == DMA2_FLAG_TC2) || \
  4769. ((FLAG) == DMA2_FLAG_HT2) || ((FLAG) == DMA2_FLAG_TE2) || \
  4770. ((FLAG) == DMA2_FLAG_GL3) || ((FLAG) == DMA2_FLAG_TC3) || \
  4771. ((FLAG) == DMA2_FLAG_HT3) || ((FLAG) == DMA2_FLAG_TE3) || \
  4772. ((FLAG) == DMA2_FLAG_GL4) || ((FLAG) == DMA2_FLAG_TC4) || \
  4773. ((FLAG) == DMA2_FLAG_HT4) || ((FLAG) == DMA2_FLAG_TE4) || \
  4774. ((FLAG) == DMA2_FLAG_GL5) || ((FLAG) == DMA2_FLAG_TC5) || \
  4775. ((FLAG) == DMA2_FLAG_HT5) || ((FLAG) == DMA2_FLAG_TE5))
  4776. /**
  4777. * @}
  4778. */
  4779. /** @defgroup DMA_Buffer_Size
  4780. * @{
  4781. */
  4782. #define IS_DMA_BUFFER_SIZE(SIZE) (((SIZE) >= 0x1) && ((SIZE) < 0x10000))
  4783. /**
  4784. * @}
  4785. */
  4786. /**
  4787. * @}
  4788. */
  4789. /** @defgroup DMA_Exported_Macros
  4790. * @{
  4791. */
  4792. /**
  4793. * @}
  4794. */
  4795. /** @defgroup DMA_Exported_Functions
  4796. * @{
  4797. */
  4798. void DMA_DeInit(DMA_Channel_TypeDef* DMAy_Channelx);
  4799. void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx, DMA_InitTypeDef* DMA_InitStruct);
  4800. void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct);
  4801. void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState);
  4802. void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT, FunctionalState NewState);
  4803. void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx, uint16_t DataNumber);
  4804. uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx);
  4805. FlagStatus DMA_GetFlagStatus(uint32_t DMAy_FLAG);
  4806. void DMA_ClearFlag(uint32_t DMAy_FLAG);
  4807. ITStatus DMA_GetITStatus(uint32_t DMAy_IT);
  4808. void DMA_ClearITPendingBit(uint32_t DMAy_IT);
  4809. #ifdef __cplusplus
  4810. }
  4811. #endif
  4812. #endif /*__STM32F10x_DMA_H */
  4813. /**
  4814. * @}
  4815. */
  4816. /**
  4817. * @}
  4818. */
  4819. /**
  4820. * @}
  4821. */
  4822. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  4823. /**
  4824. ******************************************************************************
  4825. * @file stm32f10x_spi.h
  4826. * @author MCD Application Team
  4827. * @version V3.5.0
  4828. * @date 11-March-2011
  4829. * @brief This file contains all the functions prototypes for the SPI firmware
  4830. * library.
  4831. ******************************************************************************
  4832. * @attention
  4833. *
  4834. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  4835. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  4836. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  4837. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  4838. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  4839. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  4840. *
  4841. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  4842. ******************************************************************************
  4843. */
  4844. /* Define to prevent recursive inclusion -------------------------------------*/
  4845. #ifndef __STM32F10x_SPI_H
  4846. #define __STM32F10x_SPI_H
  4847. #ifdef __cplusplus
  4848. extern "C" {
  4849. #endif
  4850. /* Includes ------------------------------------------------------------------*/
  4851. #include "stm32f10x.h"
  4852. /** @addtogroup STM32F10x_StdPeriph_Driver
  4853. * @{
  4854. */
  4855. /** @addtogroup SPI
  4856. * @{
  4857. */
  4858. /** @defgroup SPI_Exported_Types
  4859. * @{
  4860. */
  4861. /**
  4862. * @brief SPI Init structure definition
  4863. */
  4864. typedef struct
  4865. {
  4866. uint16_t SPI_Direction; /*!< Specifies the SPI unidirectional or bidirectional data mode.
  4867. This parameter can be a value of @ref SPI_data_direction */
  4868. uint16_t SPI_Mode; /*!< Specifies the SPI operating mode.
  4869. This parameter can be a value of @ref SPI_mode */
  4870. uint16_t SPI_DataSize; /*!< Specifies the SPI data size.
  4871. This parameter can be a value of @ref SPI_data_size */
  4872. uint16_t SPI_CPOL; /*!< Specifies the serial clock steady state.
  4873. This parameter can be a value of @ref SPI_Clock_Polarity */
  4874. uint16_t SPI_CPHA; /*!< Specifies the clock active edge for the bit capture.
  4875. This parameter can be a value of @ref SPI_Clock_Phase */
  4876. uint16_t SPI_NSS; /*!< Specifies whether the NSS signal is managed by
  4877. hardware (NSS pin) or by software using the SSI bit.
  4878. This parameter can be a value of @ref SPI_Slave_Select_management */
  4879. uint16_t SPI_BaudRatePrescaler; /*!< Specifies the Baud Rate prescaler value which will be
  4880. used to configure the transmit and receive SCK clock.
  4881. This parameter can be a value of @ref SPI_BaudRate_Prescaler.
  4882. @note The communication clock is derived from the master
  4883. clock. The slave clock does not need to be set. */
  4884. uint16_t SPI_FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
  4885. This parameter can be a value of @ref SPI_MSB_LSB_transmission */
  4886. uint16_t SPI_CRCPolynomial; /*!< Specifies the polynomial used for the CRC calculation. */
  4887. }SPI_InitTypeDef;
  4888. /**
  4889. * @brief I2S Init structure definition
  4890. */
  4891. typedef struct
  4892. {
  4893. uint16_t I2S_Mode; /*!< Specifies the I2S operating mode.
  4894. This parameter can be a value of @ref I2S_Mode */
  4895. uint16_t I2S_Standard; /*!< Specifies the standard used for the I2S communication.
  4896. This parameter can be a value of @ref I2S_Standard */
  4897. uint16_t I2S_DataFormat; /*!< Specifies the data format for the I2S communication.
  4898. This parameter can be a value of @ref I2S_Data_Format */
  4899. uint16_t I2S_MCLKOutput; /*!< Specifies whether the I2S MCLK output is enabled or not.
  4900. This parameter can be a value of @ref I2S_MCLK_Output */
  4901. uint32_t I2S_AudioFreq; /*!< Specifies the frequency selected for the I2S communication.
  4902. This parameter can be a value of @ref I2S_Audio_Frequency */
  4903. uint16_t I2S_CPOL; /*!< Specifies the idle state of the I2S clock.
  4904. This parameter can be a value of @ref I2S_Clock_Polarity */
  4905. }I2S_InitTypeDef;
  4906. /**
  4907. * @}
  4908. */
  4909. /** @defgroup SPI_Exported_Constants
  4910. * @{
  4911. */
  4912. #define IS_SPI_ALL_PERIPH(PERIPH) (((PERIPH) == SPI1) || \
  4913. ((PERIPH) == SPI2) || \
  4914. ((PERIPH) == SPI3))
  4915. #define IS_SPI_23_PERIPH(PERIPH) (((PERIPH) == SPI2) || \
  4916. ((PERIPH) == SPI3))
  4917. /** @defgroup SPI_data_direction
  4918. * @{
  4919. */
  4920. #define SPI_Direction_2Lines_FullDuplex ((uint16_t)0x0000)
  4921. #define SPI_Direction_2Lines_RxOnly ((uint16_t)0x0400)
  4922. #define SPI_Direction_1Line_Rx ((uint16_t)0x8000)
  4923. #define SPI_Direction_1Line_Tx ((uint16_t)0xC000)
  4924. #define IS_SPI_DIRECTION_MODE(MODE) (((MODE) == SPI_Direction_2Lines_FullDuplex) || \
  4925. ((MODE) == SPI_Direction_2Lines_RxOnly) || \
  4926. ((MODE) == SPI_Direction_1Line_Rx) || \
  4927. ((MODE) == SPI_Direction_1Line_Tx))
  4928. /**
  4929. * @}
  4930. */
  4931. /** @defgroup SPI_mode
  4932. * @{
  4933. */
  4934. #define SPI_Mode_Master ((uint16_t)0x0104)
  4935. #define SPI_Mode_Slave ((uint16_t)0x0000)
  4936. #define IS_SPI_MODE(MODE) (((MODE) == SPI_Mode_Master) || \
  4937. ((MODE) == SPI_Mode_Slave))
  4938. /**
  4939. * @}
  4940. */
  4941. /** @defgroup SPI_data_size
  4942. * @{
  4943. */
  4944. #define SPI_DataSize_16b ((uint16_t)0x0800)
  4945. #define SPI_DataSize_8b ((uint16_t)0x0000)
  4946. #define IS_SPI_DATASIZE(DATASIZE) (((DATASIZE) == SPI_DataSize_16b) || \
  4947. ((DATASIZE) == SPI_DataSize_8b))
  4948. /**
  4949. * @}
  4950. */
  4951. /** @defgroup SPI_Clock_Polarity
  4952. * @{
  4953. */
  4954. #define SPI_CPOL_Low ((uint16_t)0x0000)
  4955. #define SPI_CPOL_High ((uint16_t)0x0002)
  4956. #define IS_SPI_CPOL(CPOL) (((CPOL) == SPI_CPOL_Low) || \
  4957. ((CPOL) == SPI_CPOL_High))
  4958. /**
  4959. * @}
  4960. */
  4961. /** @defgroup SPI_Clock_Phase
  4962. * @{
  4963. */
  4964. #define SPI_CPHA_1Edge ((uint16_t)0x0000)
  4965. #define SPI_CPHA_2Edge ((uint16_t)0x0001)
  4966. #define IS_SPI_CPHA(CPHA) (((CPHA) == SPI_CPHA_1Edge) || \
  4967. ((CPHA) == SPI_CPHA_2Edge))
  4968. /**
  4969. * @}
  4970. */
  4971. /** @defgroup SPI_Slave_Select_management
  4972. * @{
  4973. */
  4974. #define SPI_NSS_Soft ((uint16_t)0x0200)
  4975. #define SPI_NSS_Hard ((uint16_t)0x0000)
  4976. #define IS_SPI_NSS(NSS) (((NSS) == SPI_NSS_Soft) || \
  4977. ((NSS) == SPI_NSS_Hard))
  4978. /**
  4979. * @}
  4980. */
  4981. /** @defgroup SPI_BaudRate_Prescaler
  4982. * @{
  4983. */
  4984. #define SPI_BaudRatePrescaler_2 ((uint16_t)0x0000)
  4985. #define SPI_BaudRatePrescaler_4 ((uint16_t)0x0008)
  4986. #define SPI_BaudRatePrescaler_8 ((uint16_t)0x0010)
  4987. #define SPI_BaudRatePrescaler_16 ((uint16_t)0x0018)
  4988. #define SPI_BaudRatePrescaler_32 ((uint16_t)0x0020)
  4989. #define SPI_BaudRatePrescaler_64 ((uint16_t)0x0028)
  4990. #define SPI_BaudRatePrescaler_128 ((uint16_t)0x0030)
  4991. #define SPI_BaudRatePrescaler_256 ((uint16_t)0x0038)
  4992. #define IS_SPI_BAUDRATE_PRESCALER(PRESCALER) (((PRESCALER) == SPI_BaudRatePrescaler_2) || \
  4993. ((PRESCALER) == SPI_BaudRatePrescaler_4) || \
  4994. ((PRESCALER) == SPI_BaudRatePrescaler_8) || \
  4995. ((PRESCALER) == SPI_BaudRatePrescaler_16) || \
  4996. ((PRESCALER) == SPI_BaudRatePrescaler_32) || \
  4997. ((PRESCALER) == SPI_BaudRatePrescaler_64) || \
  4998. ((PRESCALER) == SPI_BaudRatePrescaler_128) || \
  4999. ((PRESCALER) == SPI_BaudRatePrescaler_256))
  5000. /**
  5001. * @}
  5002. */
  5003. /** @defgroup SPI_MSB_LSB_transmission
  5004. * @{
  5005. */
  5006. #define SPI_FirstBit_MSB ((uint16_t)0x0000)
  5007. #define SPI_FirstBit_LSB ((uint16_t)0x0080)
  5008. #define IS_SPI_FIRST_BIT(BIT) (((BIT) == SPI_FirstBit_MSB) || \
  5009. ((BIT) == SPI_FirstBit_LSB))
  5010. /**
  5011. * @}
  5012. */
  5013. /** @defgroup I2S_Mode
  5014. * @{
  5015. */
  5016. #define I2S_Mode_SlaveTx ((uint16_t)0x0000)
  5017. #define I2S_Mode_SlaveRx ((uint16_t)0x0100)
  5018. #define I2S_Mode_MasterTx ((uint16_t)0x0200)
  5019. #define I2S_Mode_MasterRx ((uint16_t)0x0300)
  5020. #define IS_I2S_MODE(MODE) (((MODE) == I2S_Mode_SlaveTx) || \
  5021. ((MODE) == I2S_Mode_SlaveRx) || \
  5022. ((MODE) == I2S_Mode_MasterTx) || \
  5023. ((MODE) == I2S_Mode_MasterRx) )
  5024. /**
  5025. * @}
  5026. */
  5027. /** @defgroup I2S_Standard
  5028. * @{
  5029. */
  5030. #define I2S_Standard_Phillips ((uint16_t)0x0000)
  5031. #define I2S_Standard_MSB ((uint16_t)0x0010)
  5032. #define I2S_Standard_LSB ((uint16_t)0x0020)
  5033. #define I2S_Standard_PCMShort ((uint16_t)0x0030)
  5034. #define I2S_Standard_PCMLong ((uint16_t)0x00B0)
  5035. #define IS_I2S_STANDARD(STANDARD) (((STANDARD) == I2S_Standard_Phillips) || \
  5036. ((STANDARD) == I2S_Standard_MSB) || \
  5037. ((STANDARD) == I2S_Standard_LSB) || \
  5038. ((STANDARD) == I2S_Standard_PCMShort) || \
  5039. ((STANDARD) == I2S_Standard_PCMLong))
  5040. /**
  5041. * @}
  5042. */
  5043. /** @defgroup I2S_Data_Format
  5044. * @{
  5045. */
  5046. #define I2S_DataFormat_16b ((uint16_t)0x0000)
  5047. #define I2S_DataFormat_16bextended ((uint16_t)0x0001)
  5048. #define I2S_DataFormat_24b ((uint16_t)0x0003)
  5049. #define I2S_DataFormat_32b ((uint16_t)0x0005)
  5050. #define IS_I2S_DATA_FORMAT(FORMAT) (((FORMAT) == I2S_DataFormat_16b) || \
  5051. ((FORMAT) == I2S_DataFormat_16bextended) || \
  5052. ((FORMAT) == I2S_DataFormat_24b) || \
  5053. ((FORMAT) == I2S_DataFormat_32b))
  5054. /**
  5055. * @}
  5056. */
  5057. /** @defgroup I2S_MCLK_Output
  5058. * @{
  5059. */
  5060. #define I2S_MCLKOutput_Enable ((uint16_t)0x0200)
  5061. #define I2S_MCLKOutput_Disable ((uint16_t)0x0000)
  5062. #define IS_I2S_MCLK_OUTPUT(OUTPUT) (((OUTPUT) == I2S_MCLKOutput_Enable) || \
  5063. ((OUTPUT) == I2S_MCLKOutput_Disable))
  5064. /**
  5065. * @}
  5066. */
  5067. /** @defgroup I2S_Audio_Frequency
  5068. * @{
  5069. */
  5070. #define I2S_AudioFreq_192k ((uint32_t)192000)
  5071. #define I2S_AudioFreq_96k ((uint32_t)96000)
  5072. #define I2S_AudioFreq_48k ((uint32_t)48000)
  5073. #define I2S_AudioFreq_44k ((uint32_t)44100)
  5074. #define I2S_AudioFreq_32k ((uint32_t)32000)
  5075. #define I2S_AudioFreq_22k ((uint32_t)22050)
  5076. #define I2S_AudioFreq_16k ((uint32_t)16000)
  5077. #define I2S_AudioFreq_11k ((uint32_t)11025)
  5078. #define I2S_AudioFreq_8k ((uint32_t)8000)
  5079. #define I2S_AudioFreq_Default ((uint32_t)2)
  5080. #define IS_I2S_AUDIO_FREQ(FREQ) ((((FREQ) >= I2S_AudioFreq_8k) && \
  5081. ((FREQ) <= I2S_AudioFreq_192k)) || \
  5082. ((FREQ) == I2S_AudioFreq_Default))
  5083. /**
  5084. * @}
  5085. */
  5086. /** @defgroup I2S_Clock_Polarity
  5087. * @{
  5088. */
  5089. #define I2S_CPOL_Low ((uint16_t)0x0000)
  5090. #define I2S_CPOL_High ((uint16_t)0x0008)
  5091. #define IS_I2S_CPOL(CPOL) (((CPOL) == I2S_CPOL_Low) || \
  5092. ((CPOL) == I2S_CPOL_High))
  5093. /**
  5094. * @}
  5095. */
  5096. /** @defgroup SPI_I2S_DMA_transfer_requests
  5097. * @{
  5098. */
  5099. #define SPI_I2S_DMAReq_Tx ((uint16_t)0x0002)
  5100. #define SPI_I2S_DMAReq_Rx ((uint16_t)0x0001)
  5101. #define IS_SPI_I2S_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFFFC) == 0x00) && ((DMAREQ) != 0x00))
  5102. /**
  5103. * @}
  5104. */
  5105. /** @defgroup SPI_NSS_internal_software_management
  5106. * @{
  5107. */
  5108. #define SPI_NSSInternalSoft_Set ((uint16_t)0x0100)
  5109. #define SPI_NSSInternalSoft_Reset ((uint16_t)0xFEFF)
  5110. #define IS_SPI_NSS_INTERNAL(INTERNAL) (((INTERNAL) == SPI_NSSInternalSoft_Set) || \
  5111. ((INTERNAL) == SPI_NSSInternalSoft_Reset))
  5112. /**
  5113. * @}
  5114. */
  5115. /** @defgroup SPI_CRC_Transmit_Receive
  5116. * @{
  5117. */
  5118. #define SPI_CRC_Tx ((uint8_t)0x00)
  5119. #define SPI_CRC_Rx ((uint8_t)0x01)
  5120. #define IS_SPI_CRC(CRC) (((CRC) == SPI_CRC_Tx) || ((CRC) == SPI_CRC_Rx))
  5121. /**
  5122. * @}
  5123. */
  5124. /** @defgroup SPI_direction_transmit_receive
  5125. * @{
  5126. */
  5127. #define SPI_Direction_Rx ((uint16_t)0xBFFF)
  5128. #define SPI_Direction_Tx ((uint16_t)0x4000)
  5129. #define IS_SPI_DIRECTION(DIRECTION) (((DIRECTION) == SPI_Direction_Rx) || \
  5130. ((DIRECTION) == SPI_Direction_Tx))
  5131. /**
  5132. * @}
  5133. */
  5134. /** @defgroup SPI_I2S_interrupts_definition
  5135. * @{
  5136. */
  5137. #define SPI_I2S_IT_TXE ((uint8_t)0x71)
  5138. #define SPI_I2S_IT_RXNE ((uint8_t)0x60)
  5139. #define SPI_I2S_IT_ERR ((uint8_t)0x50)
  5140. #define IS_SPI_I2S_CONFIG_IT(IT) (((IT) == SPI_I2S_IT_TXE) || \
  5141. ((IT) == SPI_I2S_IT_RXNE) || \
  5142. ((IT) == SPI_I2S_IT_ERR))
  5143. #define SPI_I2S_IT_OVR ((uint8_t)0x56)
  5144. #define SPI_IT_MODF ((uint8_t)0x55)
  5145. #define SPI_IT_CRCERR ((uint8_t)0x54)
  5146. #define I2S_IT_UDR ((uint8_t)0x53)
  5147. #define IS_SPI_I2S_CLEAR_IT(IT) (((IT) == SPI_IT_CRCERR))
  5148. #define IS_SPI_I2S_GET_IT(IT) (((IT) == SPI_I2S_IT_RXNE) || ((IT) == SPI_I2S_IT_TXE) || \
  5149. ((IT) == I2S_IT_UDR) || ((IT) == SPI_IT_CRCERR) || \
  5150. ((IT) == SPI_IT_MODF) || ((IT) == SPI_I2S_IT_OVR))
  5151. /**
  5152. * @}
  5153. */
  5154. /** @defgroup SPI_I2S_flags_definition
  5155. * @{
  5156. */
  5157. #define SPI_I2S_FLAG_RXNE ((uint16_t)0x0001)
  5158. #define SPI_I2S_FLAG_TXE ((uint16_t)0x0002)
  5159. #define I2S_FLAG_CHSIDE ((uint16_t)0x0004)
  5160. #define I2S_FLAG_UDR ((uint16_t)0x0008)
  5161. #define SPI_FLAG_CRCERR ((uint16_t)0x0010)
  5162. #define SPI_FLAG_MODF ((uint16_t)0x0020)
  5163. #define SPI_I2S_FLAG_OVR ((uint16_t)0x0040)
  5164. #define SPI_I2S_FLAG_BSY ((uint16_t)0x0080)
  5165. #define IS_SPI_I2S_CLEAR_FLAG(FLAG) (((FLAG) == SPI_FLAG_CRCERR))
  5166. #define IS_SPI_I2S_GET_FLAG(FLAG) (((FLAG) == SPI_I2S_FLAG_BSY) || ((FLAG) == SPI_I2S_FLAG_OVR) || \
  5167. ((FLAG) == SPI_FLAG_MODF) || ((FLAG) == SPI_FLAG_CRCERR) || \
  5168. ((FLAG) == I2S_FLAG_UDR) || ((FLAG) == I2S_FLAG_CHSIDE) || \
  5169. ((FLAG) == SPI_I2S_FLAG_TXE) || ((FLAG) == SPI_I2S_FLAG_RXNE))
  5170. /**
  5171. * @}
  5172. */
  5173. /** @defgroup SPI_CRC_polynomial
  5174. * @{
  5175. */
  5176. #define IS_SPI_CRC_POLYNOMIAL(POLYNOMIAL) ((POLYNOMIAL) >= 0x1)
  5177. /**
  5178. * @}
  5179. */
  5180. /**
  5181. * @}
  5182. */
  5183. /** @defgroup SPI_Exported_Macros
  5184. * @{
  5185. */
  5186. /**
  5187. * @}
  5188. */
  5189. /** @defgroup SPI_Exported_Functions
  5190. * @{
  5191. */
  5192. void SPI_I2S_DeInit(SPI_TypeDef* SPIx);
  5193. void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct);
  5194. void I2S_Init(SPI_TypeDef* SPIx, I2S_InitTypeDef* I2S_InitStruct);
  5195. void SPI_StructInit(SPI_InitTypeDef* SPI_InitStruct);
  5196. void I2S_StructInit(I2S_InitTypeDef* I2S_InitStruct);
  5197. void SPI_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState);
  5198. void I2S_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState);
  5199. void SPI_I2S_ITConfig(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState);
  5200. void SPI_I2S_DMACmd(SPI_TypeDef* SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState);
  5201. void SPI_I2S_SendData(SPI_TypeDef* SPIx, uint16_t Data);
  5202. uint16_t SPI_I2S_ReceiveData(SPI_TypeDef* SPIx);
  5203. void SPI_NSSInternalSoftwareConfig(SPI_TypeDef* SPIx, uint16_t SPI_NSSInternalSoft);
  5204. void SPI_SSOutputCmd(SPI_TypeDef* SPIx, FunctionalState NewState);
  5205. void SPI_DataSizeConfig(SPI_TypeDef* SPIx, uint16_t SPI_DataSize);
  5206. void SPI_TransmitCRC(SPI_TypeDef* SPIx);
  5207. void SPI_CalculateCRC(SPI_TypeDef* SPIx, FunctionalState NewState);
  5208. uint16_t SPI_GetCRC(SPI_TypeDef* SPIx, uint8_t SPI_CRC);
  5209. uint16_t SPI_GetCRCPolynomial(SPI_TypeDef* SPIx);
  5210. void SPI_BiDirectionalLineConfig(SPI_TypeDef* SPIx, uint16_t SPI_Direction);
  5211. FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG);
  5212. void SPI_I2S_ClearFlag(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG);
  5213. ITStatus SPI_I2S_GetITStatus(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT);
  5214. void SPI_I2S_ClearITPendingBit(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT);
  5215. #ifdef __cplusplus
  5216. }
  5217. #endif
  5218. #endif /*__STM32F10x_SPI_H */
  5219. /**
  5220. * @}
  5221. */
  5222. /**
  5223. * @}
  5224. */
  5225. /**
  5226. * @}
  5227. */
  5228. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  5229. /**
  5230. ******************************************************************************
  5231. * @file stm32f10x_fsmc.h
  5232. * @author MCD Application Team
  5233. * @version V3.5.0
  5234. * @date 11-March-2011
  5235. * @brief This file contains all the functions prototypes for the FSMC firmware
  5236. * library.
  5237. ******************************************************************************
  5238. * @attention
  5239. *
  5240. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  5241. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  5242. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  5243. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  5244. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  5245. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  5246. *
  5247. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  5248. ******************************************************************************
  5249. */
  5250. /* Define to prevent recursive inclusion -------------------------------------*/
  5251. #ifndef __STM32F10x_FSMC_H
  5252. #define __STM32F10x_FSMC_H
  5253. #ifdef __cplusplus
  5254. extern "C" {
  5255. #endif
  5256. /* Includes ------------------------------------------------------------------*/
  5257. #include "stm32f10x.h"
  5258. /** @addtogroup STM32F10x_StdPeriph_Driver
  5259. * @{
  5260. */
  5261. /** @addtogroup FSMC
  5262. * @{
  5263. */
  5264. /** @defgroup FSMC_Exported_Types
  5265. * @{
  5266. */
  5267. /**
  5268. * @brief Timing parameters For NOR/SRAM Banks
  5269. */
  5270. typedef struct
  5271. {
  5272. uint32_t FSMC_AddressSetupTime; /*!< Defines the number of HCLK cycles to configure
  5273. the duration of the address setup time.
  5274. This parameter can be a value between 0 and 0xF.
  5275. @note: It is not used with synchronous NOR Flash memories. */
  5276. uint32_t FSMC_AddressHoldTime; /*!< Defines the number of HCLK cycles to configure
  5277. the duration of the address hold time.
  5278. This parameter can be a value between 0 and 0xF.
  5279. @note: It is not used with synchronous NOR Flash memories.*/
  5280. uint32_t FSMC_DataSetupTime; /*!< Defines the number of HCLK cycles to configure
  5281. the duration of the data setup time.
  5282. This parameter can be a value between 0 and 0xFF.
  5283. @note: It is used for SRAMs, ROMs and asynchronous multiplexed NOR Flash memories. */
  5284. uint32_t FSMC_BusTurnAroundDuration; /*!< Defines the number of HCLK cycles to configure
  5285. the duration of the bus turnaround.
  5286. This parameter can be a value between 0 and 0xF.
  5287. @note: It is only used for multiplexed NOR Flash memories. */
  5288. uint32_t FSMC_CLKDivision; /*!< Defines the period of CLK clock output signal, expressed in number of HCLK cycles.
  5289. This parameter can be a value between 1 and 0xF.
  5290. @note: This parameter is not used for asynchronous NOR Flash, SRAM or ROM accesses. */
  5291. uint32_t FSMC_DataLatency; /*!< Defines the number of memory clock cycles to issue
  5292. to the memory before getting the first data.
  5293. The value of this parameter depends on the memory type as shown below:
  5294. - It must be set to 0 in case of a CRAM
  5295. - It is don't care in asynchronous NOR, SRAM or ROM accesses
  5296. - It may assume a value between 0 and 0xF in NOR Flash memories
  5297. with synchronous burst mode enable */
  5298. uint32_t FSMC_AccessMode; /*!< Specifies the asynchronous access mode.
  5299. This parameter can be a value of @ref FSMC_Access_Mode */
  5300. }FSMC_NORSRAMTimingInitTypeDef;
  5301. /**
  5302. * @brief FSMC NOR/SRAM Init structure definition
  5303. */
  5304. typedef struct
  5305. {
  5306. uint32_t FSMC_Bank; /*!< Specifies the NOR/SRAM memory bank that will be used.
  5307. This parameter can be a value of @ref FSMC_NORSRAM_Bank */
  5308. uint32_t FSMC_DataAddressMux; /*!< Specifies whether the address and data values are
  5309. multiplexed on the databus or not.
  5310. This parameter can be a value of @ref FSMC_Data_Address_Bus_Multiplexing */
  5311. uint32_t FSMC_MemoryType; /*!< Specifies the type of external memory attached to
  5312. the corresponding memory bank.
  5313. This parameter can be a value of @ref FSMC_Memory_Type */
  5314. uint32_t FSMC_MemoryDataWidth; /*!< Specifies the external memory device width.
  5315. This parameter can be a value of @ref FSMC_Data_Width */
  5316. uint32_t FSMC_BurstAccessMode; /*!< Enables or disables the burst access mode for Flash memory,
  5317. valid only with synchronous burst Flash memories.
  5318. This parameter can be a value of @ref FSMC_Burst_Access_Mode */
  5319. uint32_t FSMC_AsynchronousWait; /*!< Enables or disables wait signal during asynchronous transfers,
  5320. valid only with asynchronous Flash memories.
  5321. This parameter can be a value of @ref FSMC_AsynchronousWait */
  5322. uint32_t FSMC_WaitSignalPolarity; /*!< Specifies the wait signal polarity, valid only when accessing
  5323. the Flash memory in burst mode.
  5324. This parameter can be a value of @ref FSMC_Wait_Signal_Polarity */
  5325. uint32_t FSMC_WrapMode; /*!< Enables or disables the Wrapped burst access mode for Flash
  5326. memory, valid only when accessing Flash memories in burst mode.
  5327. This parameter can be a value of @ref FSMC_Wrap_Mode */
  5328. uint32_t FSMC_WaitSignalActive; /*!< Specifies if the wait signal is asserted by the memory one
  5329. clock cycle before the wait state or during the wait state,
  5330. valid only when accessing memories in burst mode.
  5331. This parameter can be a value of @ref FSMC_Wait_Timing */
  5332. uint32_t FSMC_WriteOperation; /*!< Enables or disables the write operation in the selected bank by the FSMC.
  5333. This parameter can be a value of @ref FSMC_Write_Operation */
  5334. uint32_t FSMC_WaitSignal; /*!< Enables or disables the wait-state insertion via wait
  5335. signal, valid for Flash memory access in burst mode.
  5336. This parameter can be a value of @ref FSMC_Wait_Signal */
  5337. uint32_t FSMC_ExtendedMode; /*!< Enables or disables the extended mode.
  5338. This parameter can be a value of @ref FSMC_Extended_Mode */
  5339. uint32_t FSMC_WriteBurst; /*!< Enables or disables the write burst operation.
  5340. This parameter can be a value of @ref FSMC_Write_Burst */
  5341. FSMC_NORSRAMTimingInitTypeDef* FSMC_ReadWriteTimingStruct; /*!< Timing Parameters for write and read access if the ExtendedMode is not used*/
  5342. FSMC_NORSRAMTimingInitTypeDef* FSMC_WriteTimingStruct; /*!< Timing Parameters for write access if the ExtendedMode is used*/
  5343. }FSMC_NORSRAMInitTypeDef;
  5344. /**
  5345. * @brief Timing parameters For FSMC NAND and PCCARD Banks
  5346. */
  5347. typedef struct
  5348. {
  5349. uint32_t FSMC_SetupTime; /*!< Defines the number of HCLK cycles to setup address before
  5350. the command assertion for NAND-Flash read or write access
  5351. to common/Attribute or I/O memory space (depending on
  5352. the memory space timing to be configured).
  5353. This parameter can be a value between 0 and 0xFF.*/
  5354. uint32_t FSMC_WaitSetupTime; /*!< Defines the minimum number of HCLK cycles to assert the
  5355. command for NAND-Flash read or write access to
  5356. common/Attribute or I/O memory space (depending on the
  5357. memory space timing to be configured).
  5358. This parameter can be a number between 0x00 and 0xFF */
  5359. uint32_t FSMC_HoldSetupTime; /*!< Defines the number of HCLK clock cycles to hold address
  5360. (and data for write access) after the command deassertion
  5361. for NAND-Flash read or write access to common/Attribute
  5362. or I/O memory space (depending on the memory space timing
  5363. to be configured).
  5364. This parameter can be a number between 0x00 and 0xFF */
  5365. uint32_t FSMC_HiZSetupTime; /*!< Defines the number of HCLK clock cycles during which the
  5366. databus is kept in HiZ after the start of a NAND-Flash
  5367. write access to common/Attribute or I/O memory space (depending
  5368. on the memory space timing to be configured).
  5369. This parameter can be a number between 0x00 and 0xFF */
  5370. }FSMC_NAND_PCCARDTimingInitTypeDef;
  5371. /**
  5372. * @brief FSMC NAND Init structure definition
  5373. */
  5374. typedef struct
  5375. {
  5376. uint32_t FSMC_Bank; /*!< Specifies the NAND memory bank that will be used.
  5377. This parameter can be a value of @ref FSMC_NAND_Bank */
  5378. uint32_t FSMC_Waitfeature; /*!< Enables or disables the Wait feature for the NAND Memory Bank.
  5379. This parameter can be any value of @ref FSMC_Wait_feature */
  5380. uint32_t FSMC_MemoryDataWidth; /*!< Specifies the external memory device width.
  5381. This parameter can be any value of @ref FSMC_Data_Width */
  5382. uint32_t FSMC_ECC; /*!< Enables or disables the ECC computation.
  5383. This parameter can be any value of @ref FSMC_ECC */
  5384. uint32_t FSMC_ECCPageSize; /*!< Defines the page size for the extended ECC.
  5385. This parameter can be any value of @ref FSMC_ECC_Page_Size */
  5386. uint32_t FSMC_TCLRSetupTime; /*!< Defines the number of HCLK cycles to configure the
  5387. delay between CLE low and RE low.
  5388. This parameter can be a value between 0 and 0xFF. */
  5389. uint32_t FSMC_TARSetupTime; /*!< Defines the number of HCLK cycles to configure the
  5390. delay between ALE low and RE low.
  5391. This parameter can be a number between 0x0 and 0xFF */
  5392. FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_CommonSpaceTimingStruct; /*!< FSMC Common Space Timing */
  5393. FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_AttributeSpaceTimingStruct; /*!< FSMC Attribute Space Timing */
  5394. }FSMC_NANDInitTypeDef;
  5395. /**
  5396. * @brief FSMC PCCARD Init structure definition
  5397. */
  5398. typedef struct
  5399. {
  5400. uint32_t FSMC_Waitfeature; /*!< Enables or disables the Wait feature for the Memory Bank.
  5401. This parameter can be any value of @ref FSMC_Wait_feature */
  5402. uint32_t FSMC_TCLRSetupTime; /*!< Defines the number of HCLK cycles to configure the
  5403. delay between CLE low and RE low.
  5404. This parameter can be a value between 0 and 0xFF. */
  5405. uint32_t FSMC_TARSetupTime; /*!< Defines the number of HCLK cycles to configure the
  5406. delay between ALE low and RE low.
  5407. This parameter can be a number between 0x0 and 0xFF */
  5408. FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_CommonSpaceTimingStruct; /*!< FSMC Common Space Timing */
  5409. FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_AttributeSpaceTimingStruct; /*!< FSMC Attribute Space Timing */
  5410. FSMC_NAND_PCCARDTimingInitTypeDef* FSMC_IOSpaceTimingStruct; /*!< FSMC IO Space Timing */
  5411. }FSMC_PCCARDInitTypeDef;
  5412. /**
  5413. * @}
  5414. */
  5415. /** @defgroup FSMC_Exported_Constants
  5416. * @{
  5417. */
  5418. /** @defgroup FSMC_NORSRAM_Bank
  5419. * @{
  5420. */
  5421. #define FSMC_Bank1_NORSRAM1 ((uint32_t)0x00000000)
  5422. #define FSMC_Bank1_NORSRAM2 ((uint32_t)0x00000002)
  5423. #define FSMC_Bank1_NORSRAM3 ((uint32_t)0x00000004)
  5424. #define FSMC_Bank1_NORSRAM4 ((uint32_t)0x00000006)
  5425. /**
  5426. * @}
  5427. */
  5428. /** @defgroup FSMC_NAND_Bank
  5429. * @{
  5430. */
  5431. #define FSMC_Bank2_NAND ((uint32_t)0x00000010)
  5432. #define FSMC_Bank3_NAND ((uint32_t)0x00000100)
  5433. /**
  5434. * @}
  5435. */
  5436. /** @defgroup FSMC_PCCARD_Bank
  5437. * @{
  5438. */
  5439. #define FSMC_Bank4_PCCARD ((uint32_t)0x00001000)
  5440. /**
  5441. * @}
  5442. */
  5443. #define IS_FSMC_NORSRAM_BANK(BANK) (((BANK) == FSMC_Bank1_NORSRAM1) || \
  5444. ((BANK) == FSMC_Bank1_NORSRAM2) || \
  5445. ((BANK) == FSMC_Bank1_NORSRAM3) || \
  5446. ((BANK) == FSMC_Bank1_NORSRAM4))
  5447. #define IS_FSMC_NAND_BANK(BANK) (((BANK) == FSMC_Bank2_NAND) || \
  5448. ((BANK) == FSMC_Bank3_NAND))
  5449. #define IS_FSMC_GETFLAG_BANK(BANK) (((BANK) == FSMC_Bank2_NAND) || \
  5450. ((BANK) == FSMC_Bank3_NAND) || \
  5451. ((BANK) == FSMC_Bank4_PCCARD))
  5452. #define IS_FSMC_IT_BANK(BANK) (((BANK) == FSMC_Bank2_NAND) || \
  5453. ((BANK) == FSMC_Bank3_NAND) || \
  5454. ((BANK) == FSMC_Bank4_PCCARD))
  5455. /** @defgroup NOR_SRAM_Controller
  5456. * @{
  5457. */
  5458. /** @defgroup FSMC_Data_Address_Bus_Multiplexing
  5459. * @{
  5460. */
  5461. #define FSMC_DataAddressMux_Disable ((uint32_t)0x00000000)
  5462. #define FSMC_DataAddressMux_Enable ((uint32_t)0x00000002)
  5463. #define IS_FSMC_MUX(MUX) (((MUX) == FSMC_DataAddressMux_Disable) || \
  5464. ((MUX) == FSMC_DataAddressMux_Enable))
  5465. /**
  5466. * @}
  5467. */
  5468. /** @defgroup FSMC_Memory_Type
  5469. * @{
  5470. */
  5471. #define FSMC_MemoryType_SRAM ((uint32_t)0x00000000)
  5472. #define FSMC_MemoryType_PSRAM ((uint32_t)0x00000004)
  5473. #define FSMC_MemoryType_NOR ((uint32_t)0x00000008)
  5474. #define IS_FSMC_MEMORY(MEMORY) (((MEMORY) == FSMC_MemoryType_SRAM) || \
  5475. ((MEMORY) == FSMC_MemoryType_PSRAM)|| \
  5476. ((MEMORY) == FSMC_MemoryType_NOR))
  5477. /**
  5478. * @}
  5479. */
  5480. /** @defgroup FSMC_Data_Width
  5481. * @{
  5482. */
  5483. #define FSMC_MemoryDataWidth_8b ((uint32_t)0x00000000)
  5484. #define FSMC_MemoryDataWidth_16b ((uint32_t)0x00000010)
  5485. #define IS_FSMC_MEMORY_WIDTH(WIDTH) (((WIDTH) == FSMC_MemoryDataWidth_8b) || \
  5486. ((WIDTH) == FSMC_MemoryDataWidth_16b))
  5487. /**
  5488. * @}
  5489. */
  5490. /** @defgroup FSMC_Burst_Access_Mode
  5491. * @{
  5492. */
  5493. #define FSMC_BurstAccessMode_Disable ((uint32_t)0x00000000)
  5494. #define FSMC_BurstAccessMode_Enable ((uint32_t)0x00000100)
  5495. #define IS_FSMC_BURSTMODE(STATE) (((STATE) == FSMC_BurstAccessMode_Disable) || \
  5496. ((STATE) == FSMC_BurstAccessMode_Enable))
  5497. /**
  5498. * @}
  5499. */
  5500. /** @defgroup FSMC_AsynchronousWait
  5501. * @{
  5502. */
  5503. #define FSMC_AsynchronousWait_Disable ((uint32_t)0x00000000)
  5504. #define FSMC_AsynchronousWait_Enable ((uint32_t)0x00008000)
  5505. #define IS_FSMC_ASYNWAIT(STATE) (((STATE) == FSMC_AsynchronousWait_Disable) || \
  5506. ((STATE) == FSMC_AsynchronousWait_Enable))
  5507. /**
  5508. * @}
  5509. */
  5510. /** @defgroup FSMC_Wait_Signal_Polarity
  5511. * @{
  5512. */
  5513. #define FSMC_WaitSignalPolarity_Low ((uint32_t)0x00000000)
  5514. #define FSMC_WaitSignalPolarity_High ((uint32_t)0x00000200)
  5515. #define IS_FSMC_WAIT_POLARITY(POLARITY) (((POLARITY) == FSMC_WaitSignalPolarity_Low) || \
  5516. ((POLARITY) == FSMC_WaitSignalPolarity_High))
  5517. /**
  5518. * @}
  5519. */
  5520. /** @defgroup FSMC_Wrap_Mode
  5521. * @{
  5522. */
  5523. #define FSMC_WrapMode_Disable ((uint32_t)0x00000000)
  5524. #define FSMC_WrapMode_Enable ((uint32_t)0x00000400)
  5525. #define IS_FSMC_WRAP_MODE(MODE) (((MODE) == FSMC_WrapMode_Disable) || \
  5526. ((MODE) == FSMC_WrapMode_Enable))
  5527. /**
  5528. * @}
  5529. */
  5530. /** @defgroup FSMC_Wait_Timing
  5531. * @{
  5532. */
  5533. #define FSMC_WaitSignalActive_BeforeWaitState ((uint32_t)0x00000000)
  5534. #define FSMC_WaitSignalActive_DuringWaitState ((uint32_t)0x00000800)
  5535. #define IS_FSMC_WAIT_SIGNAL_ACTIVE(ACTIVE) (((ACTIVE) == FSMC_WaitSignalActive_BeforeWaitState) || \
  5536. ((ACTIVE) == FSMC_WaitSignalActive_DuringWaitState))
  5537. /**
  5538. * @}
  5539. */
  5540. /** @defgroup FSMC_Write_Operation
  5541. * @{
  5542. */
  5543. #define FSMC_WriteOperation_Disable ((uint32_t)0x00000000)
  5544. #define FSMC_WriteOperation_Enable ((uint32_t)0x00001000)
  5545. #define IS_FSMC_WRITE_OPERATION(OPERATION) (((OPERATION) == FSMC_WriteOperation_Disable) || \
  5546. ((OPERATION) == FSMC_WriteOperation_Enable))
  5547. /**
  5548. * @}
  5549. */
  5550. /** @defgroup FSMC_Wait_Signal
  5551. * @{
  5552. */
  5553. #define FSMC_WaitSignal_Disable ((uint32_t)0x00000000)
  5554. #define FSMC_WaitSignal_Enable ((uint32_t)0x00002000)
  5555. #define IS_FSMC_WAITE_SIGNAL(SIGNAL) (((SIGNAL) == FSMC_WaitSignal_Disable) || \
  5556. ((SIGNAL) == FSMC_WaitSignal_Enable))
  5557. /**
  5558. * @}
  5559. */
  5560. /** @defgroup FSMC_Extended_Mode
  5561. * @{
  5562. */
  5563. #define FSMC_ExtendedMode_Disable ((uint32_t)0x00000000)
  5564. #define FSMC_ExtendedMode_Enable ((uint32_t)0x00004000)
  5565. #define IS_FSMC_EXTENDED_MODE(MODE) (((MODE) == FSMC_ExtendedMode_Disable) || \
  5566. ((MODE) == FSMC_ExtendedMode_Enable))
  5567. /**
  5568. * @}
  5569. */
  5570. /** @defgroup FSMC_Write_Burst
  5571. * @{
  5572. */
  5573. #define FSMC_WriteBurst_Disable ((uint32_t)0x00000000)
  5574. #define FSMC_WriteBurst_Enable ((uint32_t)0x00080000)
  5575. #define IS_FSMC_WRITE_BURST(BURST) (((BURST) == FSMC_WriteBurst_Disable) || \
  5576. ((BURST) == FSMC_WriteBurst_Enable))
  5577. /**
  5578. * @}
  5579. */
  5580. /** @defgroup FSMC_Address_Setup_Time
  5581. * @{
  5582. */
  5583. #define IS_FSMC_ADDRESS_SETUP_TIME(TIME) ((TIME) <= 0xF)
  5584. /**
  5585. * @}
  5586. */
  5587. /** @defgroup FSMC_Address_Hold_Time
  5588. * @{
  5589. */
  5590. #define IS_FSMC_ADDRESS_HOLD_TIME(TIME) ((TIME) <= 0xF)
  5591. /**
  5592. * @}
  5593. */
  5594. /** @defgroup FSMC_Data_Setup_Time
  5595. * @{
  5596. */
  5597. #define IS_FSMC_DATASETUP_TIME(TIME) (((TIME) > 0) && ((TIME) <= 0xFF))
  5598. /**
  5599. * @}
  5600. */
  5601. /** @defgroup FSMC_Bus_Turn_around_Duration
  5602. * @{
  5603. */
  5604. #define IS_FSMC_TURNAROUND_TIME(TIME) ((TIME) <= 0xF)
  5605. /**
  5606. * @}
  5607. */
  5608. /** @defgroup FSMC_CLK_Division
  5609. * @{
  5610. */
  5611. #define IS_FSMC_CLK_DIV(DIV) ((DIV) <= 0xF)
  5612. /**
  5613. * @}
  5614. */
  5615. /** @defgroup FSMC_Data_Latency
  5616. * @{
  5617. */
  5618. #define IS_FSMC_DATA_LATENCY(LATENCY) ((LATENCY) <= 0xF)
  5619. /**
  5620. * @}
  5621. */
  5622. /** @defgroup FSMC_Access_Mode
  5623. * @{
  5624. */
  5625. #define FSMC_AccessMode_A ((uint32_t)0x00000000)
  5626. #define FSMC_AccessMode_B ((uint32_t)0x10000000)
  5627. #define FSMC_AccessMode_C ((uint32_t)0x20000000)
  5628. #define FSMC_AccessMode_D ((uint32_t)0x30000000)
  5629. #define IS_FSMC_ACCESS_MODE(MODE) (((MODE) == FSMC_AccessMode_A) || \
  5630. ((MODE) == FSMC_AccessMode_B) || \
  5631. ((MODE) == FSMC_AccessMode_C) || \
  5632. ((MODE) == FSMC_AccessMode_D))
  5633. /**
  5634. * @}
  5635. */
  5636. /**
  5637. * @}
  5638. */
  5639. /** @defgroup NAND_PCCARD_Controller
  5640. * @{
  5641. */
  5642. /** @defgroup FSMC_Wait_feature
  5643. * @{
  5644. */
  5645. #define FSMC_Waitfeature_Disable ((uint32_t)0x00000000)
  5646. #define FSMC_Waitfeature_Enable ((uint32_t)0x00000002)
  5647. #define IS_FSMC_WAIT_FEATURE(FEATURE) (((FEATURE) == FSMC_Waitfeature_Disable) || \
  5648. ((FEATURE) == FSMC_Waitfeature_Enable))
  5649. /**
  5650. * @}
  5651. */
  5652. /** @defgroup FSMC_ECC
  5653. * @{
  5654. */
  5655. #define FSMC_ECC_Disable ((uint32_t)0x00000000)
  5656. #define FSMC_ECC_Enable ((uint32_t)0x00000040)
  5657. #define IS_FSMC_ECC_STATE(STATE) (((STATE) == FSMC_ECC_Disable) || \
  5658. ((STATE) == FSMC_ECC_Enable))
  5659. /**
  5660. * @}
  5661. */
  5662. /** @defgroup FSMC_ECC_Page_Size
  5663. * @{
  5664. */
  5665. #define FSMC_ECCPageSize_256Bytes ((uint32_t)0x00000000)
  5666. #define FSMC_ECCPageSize_512Bytes ((uint32_t)0x00020000)
  5667. #define FSMC_ECCPageSize_1024Bytes ((uint32_t)0x00040000)
  5668. #define FSMC_ECCPageSize_2048Bytes ((uint32_t)0x00060000)
  5669. #define FSMC_ECCPageSize_4096Bytes ((uint32_t)0x00080000)
  5670. #define FSMC_ECCPageSize_8192Bytes ((uint32_t)0x000A0000)
  5671. #define IS_FSMC_ECCPAGE_SIZE(SIZE) (((SIZE) == FSMC_ECCPageSize_256Bytes) || \
  5672. ((SIZE) == FSMC_ECCPageSize_512Bytes) || \
  5673. ((SIZE) == FSMC_ECCPageSize_1024Bytes) || \
  5674. ((SIZE) == FSMC_ECCPageSize_2048Bytes) || \
  5675. ((SIZE) == FSMC_ECCPageSize_4096Bytes) || \
  5676. ((SIZE) == FSMC_ECCPageSize_8192Bytes))
  5677. /**
  5678. * @}
  5679. */
  5680. /** @defgroup FSMC_TCLR_Setup_Time
  5681. * @{
  5682. */
  5683. #define IS_FSMC_TCLR_TIME(TIME) ((TIME) <= 0xFF)
  5684. /**
  5685. * @}
  5686. */
  5687. /** @defgroup FSMC_TAR_Setup_Time
  5688. * @{
  5689. */
  5690. #define IS_FSMC_TAR_TIME(TIME) ((TIME) <= 0xFF)
  5691. /**
  5692. * @}
  5693. */
  5694. /** @defgroup FSMC_Setup_Time
  5695. * @{
  5696. */
  5697. #define IS_FSMC_SETUP_TIME(TIME) ((TIME) <= 0xFF)
  5698. /**
  5699. * @}
  5700. */
  5701. /** @defgroup FSMC_Wait_Setup_Time
  5702. * @{
  5703. */
  5704. #define IS_FSMC_WAIT_TIME(TIME) ((TIME) <= 0xFF)
  5705. /**
  5706. * @}
  5707. */
  5708. /** @defgroup FSMC_Hold_Setup_Time
  5709. * @{
  5710. */
  5711. #define IS_FSMC_HOLD_TIME(TIME) ((TIME) <= 0xFF)
  5712. /**
  5713. * @}
  5714. */
  5715. /** @defgroup FSMC_HiZ_Setup_Time
  5716. * @{
  5717. */
  5718. #define IS_FSMC_HIZ_TIME(TIME) ((TIME) <= 0xFF)
  5719. /**
  5720. * @}
  5721. */
  5722. /** @defgroup FSMC_Interrupt_sources
  5723. * @{
  5724. */
  5725. #define FSMC_IT_RisingEdge ((uint32_t)0x00000008)
  5726. #define FSMC_IT_Level ((uint32_t)0x00000010)
  5727. #define FSMC_IT_FallingEdge ((uint32_t)0x00000020)
  5728. #define IS_FSMC_IT(IT) ((((IT) & (uint32_t)0xFFFFFFC7) == 0x00000000) && ((IT) != 0x00000000))
  5729. #define IS_FSMC_GET_IT(IT) (((IT) == FSMC_IT_RisingEdge) || \
  5730. ((IT) == FSMC_IT_Level) || \
  5731. ((IT) == FSMC_IT_FallingEdge))
  5732. /**
  5733. * @}
  5734. */
  5735. /** @defgroup FSMC_Flags
  5736. * @{
  5737. */
  5738. #define FSMC_FLAG_RisingEdge ((uint32_t)0x00000001)
  5739. #define FSMC_FLAG_Level ((uint32_t)0x00000002)
  5740. #define FSMC_FLAG_FallingEdge ((uint32_t)0x00000004)
  5741. #define FSMC_FLAG_FEMPT ((uint32_t)0x00000040)
  5742. #define IS_FSMC_GET_FLAG(FLAG) (((FLAG) == FSMC_FLAG_RisingEdge) || \
  5743. ((FLAG) == FSMC_FLAG_Level) || \
  5744. ((FLAG) == FSMC_FLAG_FallingEdge) || \
  5745. ((FLAG) == FSMC_FLAG_FEMPT))
  5746. #define IS_FSMC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFFF8) == 0x00000000) && ((FLAG) != 0x00000000))
  5747. /**
  5748. * @}
  5749. */
  5750. /**
  5751. * @}
  5752. */
  5753. /**
  5754. * @}
  5755. */
  5756. /** @defgroup FSMC_Exported_Macros
  5757. * @{
  5758. */
  5759. /**
  5760. * @}
  5761. */
  5762. /** @defgroup FSMC_Exported_Functions
  5763. * @{
  5764. */
  5765. void FSMC_NORSRAMDeInit(uint32_t FSMC_Bank);
  5766. void FSMC_NANDDeInit(uint32_t FSMC_Bank);
  5767. void FSMC_PCCARDDeInit(void);
  5768. void FSMC_NORSRAMInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct);
  5769. void FSMC_NANDInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct);
  5770. void FSMC_PCCARDInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct);
  5771. void FSMC_NORSRAMStructInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct);
  5772. void FSMC_NANDStructInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct);
  5773. void FSMC_PCCARDStructInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct);
  5774. void FSMC_NORSRAMCmd(uint32_t FSMC_Bank, FunctionalState NewState);
  5775. void FSMC_NANDCmd(uint32_t FSMC_Bank, FunctionalState NewState);
  5776. void FSMC_PCCARDCmd(FunctionalState NewState);
  5777. void FSMC_NANDECCCmd(uint32_t FSMC_Bank, FunctionalState NewState);
  5778. uint32_t FSMC_GetECC(uint32_t FSMC_Bank);
  5779. void FSMC_ITConfig(uint32_t FSMC_Bank, uint32_t FSMC_IT, FunctionalState NewState);
  5780. FlagStatus FSMC_GetFlagStatus(uint32_t FSMC_Bank, uint32_t FSMC_FLAG);
  5781. void FSMC_ClearFlag(uint32_t FSMC_Bank, uint32_t FSMC_FLAG);
  5782. ITStatus FSMC_GetITStatus(uint32_t FSMC_Bank, uint32_t FSMC_IT);
  5783. void FSMC_ClearITPendingBit(uint32_t FSMC_Bank, uint32_t FSMC_IT);
  5784. #ifdef __cplusplus
  5785. }
  5786. #endif
  5787. #endif /*__STM32F10x_FSMC_H */
  5788. /**
  5789. * @}
  5790. */
  5791. /**
  5792. * @}
  5793. */
  5794. /**
  5795. * @}
  5796. */
  5797. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  5798. /**
  5799. ******************************************************************************
  5800. * @file stm32f10x_bkp.h
  5801. * @author MCD Application Team
  5802. * @version V3.5.0
  5803. * @date 11-March-2011
  5804. * @brief This file contains all the functions prototypes for the BKP firmware
  5805. * library.
  5806. ******************************************************************************
  5807. * @attention
  5808. *
  5809. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  5810. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  5811. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  5812. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  5813. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  5814. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  5815. *
  5816. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  5817. ******************************************************************************
  5818. */
  5819. /* Define to prevent recursive inclusion -------------------------------------*/
  5820. #ifndef __STM32F10x_BKP_H
  5821. #define __STM32F10x_BKP_H
  5822. #ifdef __cplusplus
  5823. extern "C" {
  5824. #endif
  5825. /* Includes ------------------------------------------------------------------*/
  5826. #include "stm32f10x.h"
  5827. /** @addtogroup STM32F10x_StdPeriph_Driver
  5828. * @{
  5829. */
  5830. /** @addtogroup BKP
  5831. * @{
  5832. */
  5833. /** @defgroup BKP_Exported_Types
  5834. * @{
  5835. */
  5836. /**
  5837. * @}
  5838. */
  5839. /** @defgroup BKP_Exported_Constants
  5840. * @{
  5841. */
  5842. /** @defgroup Tamper_Pin_active_level
  5843. * @{
  5844. */
  5845. #define BKP_TamperPinLevel_High ((uint16_t)0x0000)
  5846. #define BKP_TamperPinLevel_Low ((uint16_t)0x0001)
  5847. #define IS_BKP_TAMPER_PIN_LEVEL(LEVEL) (((LEVEL) == BKP_TamperPinLevel_High) || \
  5848. ((LEVEL) == BKP_TamperPinLevel_Low))
  5849. /**
  5850. * @}
  5851. */
  5852. /** @defgroup RTC_output_source_to_output_on_the_Tamper_pin
  5853. * @{
  5854. */
  5855. #define BKP_RTCOutputSource_None ((uint16_t)0x0000)
  5856. #define BKP_RTCOutputSource_CalibClock ((uint16_t)0x0080)
  5857. #define BKP_RTCOutputSource_Alarm ((uint16_t)0x0100)
  5858. #define BKP_RTCOutputSource_Second ((uint16_t)0x0300)
  5859. #define IS_BKP_RTC_OUTPUT_SOURCE(SOURCE) (((SOURCE) == BKP_RTCOutputSource_None) || \
  5860. ((SOURCE) == BKP_RTCOutputSource_CalibClock) || \
  5861. ((SOURCE) == BKP_RTCOutputSource_Alarm) || \
  5862. ((SOURCE) == BKP_RTCOutputSource_Second))
  5863. /**
  5864. * @}
  5865. */
  5866. /** @defgroup Data_Backup_Register
  5867. * @{
  5868. */
  5869. #define BKP_DR1 ((uint16_t)0x0004)
  5870. #define BKP_DR2 ((uint16_t)0x0008)
  5871. #define BKP_DR3 ((uint16_t)0x000C)
  5872. #define BKP_DR4 ((uint16_t)0x0010)
  5873. #define BKP_DR5 ((uint16_t)0x0014)
  5874. #define BKP_DR6 ((uint16_t)0x0018)
  5875. #define BKP_DR7 ((uint16_t)0x001C)
  5876. #define BKP_DR8 ((uint16_t)0x0020)
  5877. #define BKP_DR9 ((uint16_t)0x0024)
  5878. #define BKP_DR10 ((uint16_t)0x0028)
  5879. #define BKP_DR11 ((uint16_t)0x0040)
  5880. #define BKP_DR12 ((uint16_t)0x0044)
  5881. #define BKP_DR13 ((uint16_t)0x0048)
  5882. #define BKP_DR14 ((uint16_t)0x004C)
  5883. #define BKP_DR15 ((uint16_t)0x0050)
  5884. #define BKP_DR16 ((uint16_t)0x0054)
  5885. #define BKP_DR17 ((uint16_t)0x0058)
  5886. #define BKP_DR18 ((uint16_t)0x005C)
  5887. #define BKP_DR19 ((uint16_t)0x0060)
  5888. #define BKP_DR20 ((uint16_t)0x0064)
  5889. #define BKP_DR21 ((uint16_t)0x0068)
  5890. #define BKP_DR22 ((uint16_t)0x006C)
  5891. #define BKP_DR23 ((uint16_t)0x0070)
  5892. #define BKP_DR24 ((uint16_t)0x0074)
  5893. #define BKP_DR25 ((uint16_t)0x0078)
  5894. #define BKP_DR26 ((uint16_t)0x007C)
  5895. #define BKP_DR27 ((uint16_t)0x0080)
  5896. #define BKP_DR28 ((uint16_t)0x0084)
  5897. #define BKP_DR29 ((uint16_t)0x0088)
  5898. #define BKP_DR30 ((uint16_t)0x008C)
  5899. #define BKP_DR31 ((uint16_t)0x0090)
  5900. #define BKP_DR32 ((uint16_t)0x0094)
  5901. #define BKP_DR33 ((uint16_t)0x0098)
  5902. #define BKP_DR34 ((uint16_t)0x009C)
  5903. #define BKP_DR35 ((uint16_t)0x00A0)
  5904. #define BKP_DR36 ((uint16_t)0x00A4)
  5905. #define BKP_DR37 ((uint16_t)0x00A8)
  5906. #define BKP_DR38 ((uint16_t)0x00AC)
  5907. #define BKP_DR39 ((uint16_t)0x00B0)
  5908. #define BKP_DR40 ((uint16_t)0x00B4)
  5909. #define BKP_DR41 ((uint16_t)0x00B8)
  5910. #define BKP_DR42 ((uint16_t)0x00BC)
  5911. #define IS_BKP_DR(DR) (((DR) == BKP_DR1) || ((DR) == BKP_DR2) || ((DR) == BKP_DR3) || \
  5912. ((DR) == BKP_DR4) || ((DR) == BKP_DR5) || ((DR) == BKP_DR6) || \
  5913. ((DR) == BKP_DR7) || ((DR) == BKP_DR8) || ((DR) == BKP_DR9) || \
  5914. ((DR) == BKP_DR10) || ((DR) == BKP_DR11) || ((DR) == BKP_DR12) || \
  5915. ((DR) == BKP_DR13) || ((DR) == BKP_DR14) || ((DR) == BKP_DR15) || \
  5916. ((DR) == BKP_DR16) || ((DR) == BKP_DR17) || ((DR) == BKP_DR18) || \
  5917. ((DR) == BKP_DR19) || ((DR) == BKP_DR20) || ((DR) == BKP_DR21) || \
  5918. ((DR) == BKP_DR22) || ((DR) == BKP_DR23) || ((DR) == BKP_DR24) || \
  5919. ((DR) == BKP_DR25) || ((DR) == BKP_DR26) || ((DR) == BKP_DR27) || \
  5920. ((DR) == BKP_DR28) || ((DR) == BKP_DR29) || ((DR) == BKP_DR30) || \
  5921. ((DR) == BKP_DR31) || ((DR) == BKP_DR32) || ((DR) == BKP_DR33) || \
  5922. ((DR) == BKP_DR34) || ((DR) == BKP_DR35) || ((DR) == BKP_DR36) || \
  5923. ((DR) == BKP_DR37) || ((DR) == BKP_DR38) || ((DR) == BKP_DR39) || \
  5924. ((DR) == BKP_DR40) || ((DR) == BKP_DR41) || ((DR) == BKP_DR42))
  5925. #define IS_BKP_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x7F)
  5926. /**
  5927. * @}
  5928. */
  5929. /**
  5930. * @}
  5931. */
  5932. /** @defgroup BKP_Exported_Macros
  5933. * @{
  5934. */
  5935. /**
  5936. * @}
  5937. */
  5938. /** @defgroup BKP_Exported_Functions
  5939. * @{
  5940. */
  5941. void BKP_DeInit(void);
  5942. void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel);
  5943. void BKP_TamperPinCmd(FunctionalState NewState);
  5944. void BKP_ITConfig(FunctionalState NewState);
  5945. void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource);
  5946. void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue);
  5947. void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data);
  5948. uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR);
  5949. FlagStatus BKP_GetFlagStatus(void);
  5950. void BKP_ClearFlag(void);
  5951. ITStatus BKP_GetITStatus(void);
  5952. void BKP_ClearITPendingBit(void);
  5953. #ifdef __cplusplus
  5954. }
  5955. #endif
  5956. #endif /* __STM32F10x_BKP_H */
  5957. /**
  5958. * @}
  5959. */
  5960. /**
  5961. * @}
  5962. */
  5963. /**
  5964. * @}
  5965. */
  5966. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  5967. /**
  5968. ******************************************************************************
  5969. * @file stm32f10x_can.h
  5970. * @author MCD Application Team
  5971. * @version V3.5.0
  5972. * @date 11-March-2011
  5973. * @brief This file contains all the functions prototypes for the CAN firmware
  5974. * library.
  5975. ******************************************************************************
  5976. * @attention
  5977. *
  5978. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  5979. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  5980. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  5981. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  5982. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  5983. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  5984. *
  5985. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  5986. ******************************************************************************
  5987. */
  5988. /* Define to prevent recursive inclusion -------------------------------------*/
  5989. #ifndef __STM32F10x_CAN_H
  5990. #define __STM32F10x_CAN_H
  5991. #ifdef __cplusplus
  5992. extern "C" {
  5993. #endif
  5994. /* Includes ------------------------------------------------------------------*/
  5995. #include "stm32f10x.h"
  5996. /** @addtogroup STM32F10x_StdPeriph_Driver
  5997. * @{
  5998. */
  5999. /** @addtogroup CAN
  6000. * @{
  6001. */
  6002. /** @defgroup CAN_Exported_Types
  6003. * @{
  6004. */
  6005. #define IS_CAN_ALL_PERIPH(PERIPH) (((PERIPH) == CAN1) || \
  6006. ((PERIPH) == CAN2))
  6007. /**
  6008. * @brief CAN init structure definition
  6009. */
  6010. typedef struct
  6011. {
  6012. uint16_t CAN_Prescaler; /*!< Specifies the length of a time quantum.
  6013. It ranges from 1 to 1024. */
  6014. uint8_t CAN_Mode; /*!< Specifies the CAN operating mode.
  6015. This parameter can be a value of
  6016. @ref CAN_operating_mode */
  6017. uint8_t CAN_SJW; /*!< Specifies the maximum number of time quanta
  6018. the CAN hardware is allowed to lengthen or
  6019. shorten a bit to perform resynchronization.
  6020. This parameter can be a value of
  6021. @ref CAN_synchronisation_jump_width */
  6022. uint8_t CAN_BS1; /*!< Specifies the number of time quanta in Bit
  6023. Segment 1. This parameter can be a value of
  6024. @ref CAN_time_quantum_in_bit_segment_1 */
  6025. uint8_t CAN_BS2; /*!< Specifies the number of time quanta in Bit
  6026. Segment 2.
  6027. This parameter can be a value of
  6028. @ref CAN_time_quantum_in_bit_segment_2 */
  6029. FunctionalState CAN_TTCM; /*!< Enable or disable the time triggered
  6030. communication mode. This parameter can be set
  6031. either to ENABLE or DISABLE. */
  6032. FunctionalState CAN_ABOM; /*!< Enable or disable the automatic bus-off
  6033. management. This parameter can be set either
  6034. to ENABLE or DISABLE. */
  6035. FunctionalState CAN_AWUM; /*!< Enable or disable the automatic wake-up mode.
  6036. This parameter can be set either to ENABLE or
  6037. DISABLE. */
  6038. FunctionalState CAN_NART; /*!< Enable or disable the no-automatic
  6039. retransmission mode. This parameter can be
  6040. set either to ENABLE or DISABLE. */
  6041. FunctionalState CAN_RFLM; /*!< Enable or disable the Receive FIFO Locked mode.
  6042. This parameter can be set either to ENABLE
  6043. or DISABLE. */
  6044. FunctionalState CAN_TXFP; /*!< Enable or disable the transmit FIFO priority.
  6045. This parameter can be set either to ENABLE
  6046. or DISABLE. */
  6047. } CAN_InitTypeDef;
  6048. /**
  6049. * @brief CAN filter init structure definition
  6050. */
  6051. typedef struct
  6052. {
  6053. uint16_t CAN_FilterIdHigh; /*!< Specifies the filter identification number (MSBs for a 32-bit
  6054. configuration, first one for a 16-bit configuration).
  6055. This parameter can be a value between 0x0000 and 0xFFFF */
  6056. uint16_t CAN_FilterIdLow; /*!< Specifies the filter identification number (LSBs for a 32-bit
  6057. configuration, second one for a 16-bit configuration).
  6058. This parameter can be a value between 0x0000 and 0xFFFF */
  6059. uint16_t CAN_FilterMaskIdHigh; /*!< Specifies the filter mask number or identification number,
  6060. according to the mode (MSBs for a 32-bit configuration,
  6061. first one for a 16-bit configuration).
  6062. This parameter can be a value between 0x0000 and 0xFFFF */
  6063. uint16_t CAN_FilterMaskIdLow; /*!< Specifies the filter mask number or identification number,
  6064. according to the mode (LSBs for a 32-bit configuration,
  6065. second one for a 16-bit configuration).
  6066. This parameter can be a value between 0x0000 and 0xFFFF */
  6067. uint16_t CAN_FilterFIFOAssignment; /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter.
  6068. This parameter can be a value of @ref CAN_filter_FIFO */
  6069. uint8_t CAN_FilterNumber; /*!< Specifies the filter which will be initialized. It ranges from 0 to 13. */
  6070. uint8_t CAN_FilterMode; /*!< Specifies the filter mode to be initialized.
  6071. This parameter can be a value of @ref CAN_filter_mode */
  6072. uint8_t CAN_FilterScale; /*!< Specifies the filter scale.
  6073. This parameter can be a value of @ref CAN_filter_scale */
  6074. FunctionalState CAN_FilterActivation; /*!< Enable or disable the filter.
  6075. This parameter can be set either to ENABLE or DISABLE. */
  6076. } CAN_FilterInitTypeDef;
  6077. /**
  6078. * @brief CAN Tx message structure definition
  6079. */
  6080. typedef struct
  6081. {
  6082. uint32_t StdId; /*!< Specifies the standard identifier.
  6083. This parameter can be a value between 0 to 0x7FF. */
  6084. uint32_t ExtId; /*!< Specifies the extended identifier.
  6085. This parameter can be a value between 0 to 0x1FFFFFFF. */
  6086. uint8_t IDE; /*!< Specifies the type of identifier for the message that
  6087. will be transmitted. This parameter can be a value
  6088. of @ref CAN_identifier_type */
  6089. uint8_t RTR; /*!< Specifies the type of frame for the message that will
  6090. be transmitted. This parameter can be a value of
  6091. @ref CAN_remote_transmission_request */
  6092. uint8_t DLC; /*!< Specifies the length of the frame that will be
  6093. transmitted. This parameter can be a value between
  6094. 0 to 8 */
  6095. uint8_t Data[8]; /*!< Contains the data to be transmitted. It ranges from 0
  6096. to 0xFF. */
  6097. } CanTxMsg;
  6098. /**
  6099. * @brief CAN Rx message structure definition
  6100. */
  6101. typedef struct
  6102. {
  6103. uint32_t StdId; /*!< Specifies the standard identifier.
  6104. This parameter can be a value between 0 to 0x7FF. */
  6105. uint32_t ExtId; /*!< Specifies the extended identifier.
  6106. This parameter can be a value between 0 to 0x1FFFFFFF. */
  6107. uint8_t IDE; /*!< Specifies the type of identifier for the message that
  6108. will be received. This parameter can be a value of
  6109. @ref CAN_identifier_type */
  6110. uint8_t RTR; /*!< Specifies the type of frame for the received message.
  6111. This parameter can be a value of
  6112. @ref CAN_remote_transmission_request */
  6113. uint8_t DLC; /*!< Specifies the length of the frame that will be received.
  6114. This parameter can be a value between 0 to 8 */
  6115. uint8_t Data[8]; /*!< Contains the data to be received. It ranges from 0 to
  6116. 0xFF. */
  6117. uint8_t FMI; /*!< Specifies the index of the filter the message stored in
  6118. the mailbox passes through. This parameter can be a
  6119. value between 0 to 0xFF */
  6120. } CanRxMsg;
  6121. /**
  6122. * @}
  6123. */
  6124. /** @defgroup CAN_Exported_Constants
  6125. * @{
  6126. */
  6127. /** @defgroup CAN_sleep_constants
  6128. * @{
  6129. */
  6130. #define CAN_InitStatus_Failed ((uint8_t)0x00) /*!< CAN initialization failed */
  6131. #define CAN_InitStatus_Success ((uint8_t)0x01) /*!< CAN initialization OK */
  6132. /**
  6133. * @}
  6134. */
  6135. /** @defgroup CAN_Mode
  6136. * @{
  6137. */
  6138. #define CAN_Mode_Normal ((uint8_t)0x00) /*!< normal mode */
  6139. #define CAN_Mode_LoopBack ((uint8_t)0x01) /*!< loopback mode */
  6140. #define CAN_Mode_Silent ((uint8_t)0x02) /*!< silent mode */
  6141. #define CAN_Mode_Silent_LoopBack ((uint8_t)0x03) /*!< loopback combined with silent mode */
  6142. #define IS_CAN_MODE(MODE) (((MODE) == CAN_Mode_Normal) || \
  6143. ((MODE) == CAN_Mode_LoopBack)|| \
  6144. ((MODE) == CAN_Mode_Silent) || \
  6145. ((MODE) == CAN_Mode_Silent_LoopBack))
  6146. /**
  6147. * @}
  6148. */
  6149. /**
  6150. * @defgroup CAN_Operating_Mode
  6151. * @{
  6152. */
  6153. #define CAN_OperatingMode_Initialization ((uint8_t)0x00) /*!< Initialization mode */
  6154. #define CAN_OperatingMode_Normal ((uint8_t)0x01) /*!< Normal mode */
  6155. #define CAN_OperatingMode_Sleep ((uint8_t)0x02) /*!< sleep mode */
  6156. #define IS_CAN_OPERATING_MODE(MODE) (((MODE) == CAN_OperatingMode_Initialization) ||\
  6157. ((MODE) == CAN_OperatingMode_Normal)|| \
  6158. ((MODE) == CAN_OperatingMode_Sleep))
  6159. /**
  6160. * @}
  6161. */
  6162. /**
  6163. * @defgroup CAN_Mode_Status
  6164. * @{
  6165. */
  6166. #define CAN_ModeStatus_Failed ((uint8_t)0x00) /*!< CAN entering the specific mode failed */
  6167. #define CAN_ModeStatus_Success ((uint8_t)!CAN_ModeStatus_Failed) /*!< CAN entering the specific mode Succeed */
  6168. /**
  6169. * @}
  6170. */
  6171. /** @defgroup CAN_synchronisation_jump_width
  6172. * @{
  6173. */
  6174. #define CAN_SJW_1tq ((uint8_t)0x00) /*!< 1 time quantum */
  6175. #define CAN_SJW_2tq ((uint8_t)0x01) /*!< 2 time quantum */
  6176. #define CAN_SJW_3tq ((uint8_t)0x02) /*!< 3 time quantum */
  6177. #define CAN_SJW_4tq ((uint8_t)0x03) /*!< 4 time quantum */
  6178. #define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1tq) || ((SJW) == CAN_SJW_2tq)|| \
  6179. ((SJW) == CAN_SJW_3tq) || ((SJW) == CAN_SJW_4tq))
  6180. /**
  6181. * @}
  6182. */
  6183. /** @defgroup CAN_time_quantum_in_bit_segment_1
  6184. * @{
  6185. */
  6186. #define CAN_BS1_1tq ((uint8_t)0x00) /*!< 1 time quantum */
  6187. #define CAN_BS1_2tq ((uint8_t)0x01) /*!< 2 time quantum */
  6188. #define CAN_BS1_3tq ((uint8_t)0x02) /*!< 3 time quantum */
  6189. #define CAN_BS1_4tq ((uint8_t)0x03) /*!< 4 time quantum */
  6190. #define CAN_BS1_5tq ((uint8_t)0x04) /*!< 5 time quantum */
  6191. #define CAN_BS1_6tq ((uint8_t)0x05) /*!< 6 time quantum */
  6192. #define CAN_BS1_7tq ((uint8_t)0x06) /*!< 7 time quantum */
  6193. #define CAN_BS1_8tq ((uint8_t)0x07) /*!< 8 time quantum */
  6194. #define CAN_BS1_9tq ((uint8_t)0x08) /*!< 9 time quantum */
  6195. #define CAN_BS1_10tq ((uint8_t)0x09) /*!< 10 time quantum */
  6196. #define CAN_BS1_11tq ((uint8_t)0x0A) /*!< 11 time quantum */
  6197. #define CAN_BS1_12tq ((uint8_t)0x0B) /*!< 12 time quantum */
  6198. #define CAN_BS1_13tq ((uint8_t)0x0C) /*!< 13 time quantum */
  6199. #define CAN_BS1_14tq ((uint8_t)0x0D) /*!< 14 time quantum */
  6200. #define CAN_BS1_15tq ((uint8_t)0x0E) /*!< 15 time quantum */
  6201. #define CAN_BS1_16tq ((uint8_t)0x0F) /*!< 16 time quantum */
  6202. #define IS_CAN_BS1(BS1) ((BS1) <= CAN_BS1_16tq)
  6203. /**
  6204. * @}
  6205. */
  6206. /** @defgroup CAN_time_quantum_in_bit_segment_2
  6207. * @{
  6208. */
  6209. #define CAN_BS2_1tq ((uint8_t)0x00) /*!< 1 time quantum */
  6210. #define CAN_BS2_2tq ((uint8_t)0x01) /*!< 2 time quantum */
  6211. #define CAN_BS2_3tq ((uint8_t)0x02) /*!< 3 time quantum */
  6212. #define CAN_BS2_4tq ((uint8_t)0x03) /*!< 4 time quantum */
  6213. #define CAN_BS2_5tq ((uint8_t)0x04) /*!< 5 time quantum */
  6214. #define CAN_BS2_6tq ((uint8_t)0x05) /*!< 6 time quantum */
  6215. #define CAN_BS2_7tq ((uint8_t)0x06) /*!< 7 time quantum */
  6216. #define CAN_BS2_8tq ((uint8_t)0x07) /*!< 8 time quantum */
  6217. #define IS_CAN_BS2(BS2) ((BS2) <= CAN_BS2_8tq)
  6218. /**
  6219. * @}
  6220. */
  6221. /** @defgroup CAN_clock_prescaler
  6222. * @{
  6223. */
  6224. #define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 1024))
  6225. /**
  6226. * @}
  6227. */
  6228. /** @defgroup CAN_filter_number
  6229. * @{
  6230. */
  6231. #ifndef STM32F10X_CL
  6232. #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 13)
  6233. #else
  6234. #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 27)
  6235. #endif /* STM32F10X_CL */
  6236. /**
  6237. * @}
  6238. */
  6239. /** @defgroup CAN_filter_mode
  6240. * @{
  6241. */
  6242. #define CAN_FilterMode_IdMask ((uint8_t)0x00) /*!< identifier/mask mode */
  6243. #define CAN_FilterMode_IdList ((uint8_t)0x01) /*!< identifier list mode */
  6244. #define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FilterMode_IdMask) || \
  6245. ((MODE) == CAN_FilterMode_IdList))
  6246. /**
  6247. * @}
  6248. */
  6249. /** @defgroup CAN_filter_scale
  6250. * @{
  6251. */
  6252. #define CAN_FilterScale_16bit ((uint8_t)0x00) /*!< Two 16-bit filters */
  6253. #define CAN_FilterScale_32bit ((uint8_t)0x01) /*!< One 32-bit filter */
  6254. #define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FilterScale_16bit) || \
  6255. ((SCALE) == CAN_FilterScale_32bit))
  6256. /**
  6257. * @}
  6258. */
  6259. /** @defgroup CAN_filter_FIFO
  6260. * @{
  6261. */
  6262. #define CAN_Filter_FIFO0 ((uint8_t)0x00) /*!< Filter FIFO 0 assignment for filter x */
  6263. #define CAN_Filter_FIFO1 ((uint8_t)0x01) /*!< Filter FIFO 1 assignment for filter x */
  6264. #define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FilterFIFO0) || \
  6265. ((FIFO) == CAN_FilterFIFO1))
  6266. /**
  6267. * @}
  6268. */
  6269. /** @defgroup Start_bank_filter_for_slave_CAN
  6270. * @{
  6271. */
  6272. #define IS_CAN_BANKNUMBER(BANKNUMBER) (((BANKNUMBER) >= 1) && ((BANKNUMBER) <= 27))
  6273. /**
  6274. * @}
  6275. */
  6276. /** @defgroup CAN_Tx
  6277. * @{
  6278. */
  6279. #define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= ((uint8_t)0x02))
  6280. #define IS_CAN_STDID(STDID) ((STDID) <= ((uint32_t)0x7FF))
  6281. #define IS_CAN_EXTID(EXTID) ((EXTID) <= ((uint32_t)0x1FFFFFFF))
  6282. #define IS_CAN_DLC(DLC) ((DLC) <= ((uint8_t)0x08))
  6283. /**
  6284. * @}
  6285. */
  6286. /** @defgroup CAN_identifier_type
  6287. * @{
  6288. */
  6289. #define CAN_Id_Standard ((uint32_t)0x00000000) /*!< Standard Id */
  6290. #define CAN_Id_Extended ((uint32_t)0x00000004) /*!< Extended Id */
  6291. #define IS_CAN_IDTYPE(IDTYPE) (((IDTYPE) == CAN_Id_Standard) || \
  6292. ((IDTYPE) == CAN_Id_Extended))
  6293. /**
  6294. * @}
  6295. */
  6296. /** @defgroup CAN_remote_transmission_request
  6297. * @{
  6298. */
  6299. #define CAN_RTR_Data ((uint32_t)0x00000000) /*!< Data frame */
  6300. #define CAN_RTR_Remote ((uint32_t)0x00000002) /*!< Remote frame */
  6301. #define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_Data) || ((RTR) == CAN_RTR_Remote))
  6302. /**
  6303. * @}
  6304. */
  6305. /** @defgroup CAN_transmit_constants
  6306. * @{
  6307. */
  6308. #define CAN_TxStatus_Failed ((uint8_t)0x00)/*!< CAN transmission failed */
  6309. #define CAN_TxStatus_Ok ((uint8_t)0x01) /*!< CAN transmission succeeded */
  6310. #define CAN_TxStatus_Pending ((uint8_t)0x02) /*!< CAN transmission pending */
  6311. #define CAN_TxStatus_NoMailBox ((uint8_t)0x04) /*!< CAN cell did not provide an empty mailbox */
  6312. /**
  6313. * @}
  6314. */
  6315. /** @defgroup CAN_receive_FIFO_number_constants
  6316. * @{
  6317. */
  6318. #define CAN_FIFO0 ((uint8_t)0x00) /*!< CAN FIFO 0 used to receive */
  6319. #define CAN_FIFO1 ((uint8_t)0x01) /*!< CAN FIFO 1 used to receive */
  6320. #define IS_CAN_FIFO(FIFO) (((FIFO) == CAN_FIFO0) || ((FIFO) == CAN_FIFO1))
  6321. /**
  6322. * @}
  6323. */
  6324. /** @defgroup CAN_sleep_constants
  6325. * @{
  6326. */
  6327. #define CAN_Sleep_Failed ((uint8_t)0x00) /*!< CAN did not enter the sleep mode */
  6328. #define CAN_Sleep_Ok ((uint8_t)0x01) /*!< CAN entered the sleep mode */
  6329. /**
  6330. * @}
  6331. */
  6332. /** @defgroup CAN_wake_up_constants
  6333. * @{
  6334. */
  6335. #define CAN_WakeUp_Failed ((uint8_t)0x00) /*!< CAN did not leave the sleep mode */
  6336. #define CAN_WakeUp_Ok ((uint8_t)0x01) /*!< CAN leaved the sleep mode */
  6337. /**
  6338. * @}
  6339. */
  6340. /**
  6341. * @defgroup CAN_Error_Code_constants
  6342. * @{
  6343. */
  6344. #define CAN_ErrorCode_NoErr ((uint8_t)0x00) /*!< No Error */
  6345. #define CAN_ErrorCode_StuffErr ((uint8_t)0x10) /*!< Stuff Error */
  6346. #define CAN_ErrorCode_FormErr ((uint8_t)0x20) /*!< Form Error */
  6347. #define CAN_ErrorCode_ACKErr ((uint8_t)0x30) /*!< Acknowledgment Error */
  6348. #define CAN_ErrorCode_BitRecessiveErr ((uint8_t)0x40) /*!< Bit Recessive Error */
  6349. #define CAN_ErrorCode_BitDominantErr ((uint8_t)0x50) /*!< Bit Dominant Error */
  6350. #define CAN_ErrorCode_CRCErr ((uint8_t)0x60) /*!< CRC Error */
  6351. #define CAN_ErrorCode_SoftwareSetErr ((uint8_t)0x70) /*!< Software Set Error */
  6352. /**
  6353. * @}
  6354. */
  6355. /** @defgroup CAN_flags
  6356. * @{
  6357. */
  6358. /* If the flag is 0x3XXXXXXX, it means that it can be used with CAN_GetFlagStatus()
  6359. and CAN_ClearFlag() functions. */
  6360. /* If the flag is 0x1XXXXXXX, it means that it can only be used with CAN_GetFlagStatus() function. */
  6361. /* Transmit Flags */
  6362. #define CAN_FLAG_RQCP0 ((uint32_t)0x38000001) /*!< Request MailBox0 Flag */
  6363. #define CAN_FLAG_RQCP1 ((uint32_t)0x38000100) /*!< Request MailBox1 Flag */
  6364. #define CAN_FLAG_RQCP2 ((uint32_t)0x38010000) /*!< Request MailBox2 Flag */
  6365. /* Receive Flags */
  6366. #define CAN_FLAG_FMP0 ((uint32_t)0x12000003) /*!< FIFO 0 Message Pending Flag */
  6367. #define CAN_FLAG_FF0 ((uint32_t)0x32000008) /*!< FIFO 0 Full Flag */
  6368. #define CAN_FLAG_FOV0 ((uint32_t)0x32000010) /*!< FIFO 0 Overrun Flag */
  6369. #define CAN_FLAG_FMP1 ((uint32_t)0x14000003) /*!< FIFO 1 Message Pending Flag */
  6370. #define CAN_FLAG_FF1 ((uint32_t)0x34000008) /*!< FIFO 1 Full Flag */
  6371. #define CAN_FLAG_FOV1 ((uint32_t)0x34000010) /*!< FIFO 1 Overrun Flag */
  6372. /* Operating Mode Flags */
  6373. #define CAN_FLAG_WKU ((uint32_t)0x31000008) /*!< Wake up Flag */
  6374. #define CAN_FLAG_SLAK ((uint32_t)0x31000012) /*!< Sleep acknowledge Flag */
  6375. /* Note: When SLAK intterupt is disabled (SLKIE=0), no polling on SLAKI is possible.
  6376. In this case the SLAK bit can be polled.*/
  6377. /* Error Flags */
  6378. #define CAN_FLAG_EWG ((uint32_t)0x10F00001) /*!< Error Warning Flag */
  6379. #define CAN_FLAG_EPV ((uint32_t)0x10F00002) /*!< Error Passive Flag */
  6380. #define CAN_FLAG_BOF ((uint32_t)0x10F00004) /*!< Bus-Off Flag */
  6381. #define CAN_FLAG_LEC ((uint32_t)0x30F00070) /*!< Last error code Flag */
  6382. #define IS_CAN_GET_FLAG(FLAG) (((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_BOF) || \
  6383. ((FLAG) == CAN_FLAG_EPV) || ((FLAG) == CAN_FLAG_EWG) || \
  6384. ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_FOV0) || \
  6385. ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FMP0) || \
  6386. ((FLAG) == CAN_FLAG_FOV1) || ((FLAG) == CAN_FLAG_FF1) || \
  6387. ((FLAG) == CAN_FLAG_FMP1) || ((FLAG) == CAN_FLAG_RQCP2) || \
  6388. ((FLAG) == CAN_FLAG_RQCP1)|| ((FLAG) == CAN_FLAG_RQCP0) || \
  6389. ((FLAG) == CAN_FLAG_SLAK ))
  6390. #define IS_CAN_CLEAR_FLAG(FLAG)(((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_RQCP2) || \
  6391. ((FLAG) == CAN_FLAG_RQCP1) || ((FLAG) == CAN_FLAG_RQCP0) || \
  6392. ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FOV0) ||\
  6393. ((FLAG) == CAN_FLAG_FF1) || ((FLAG) == CAN_FLAG_FOV1) || \
  6394. ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_SLAK))
  6395. /**
  6396. * @}
  6397. */
  6398. /** @defgroup CAN_interrupts
  6399. * @{
  6400. */
  6401. #define CAN_IT_TME ((uint32_t)0x00000001) /*!< Transmit mailbox empty Interrupt*/
  6402. /* Receive Interrupts */
  6403. #define CAN_IT_FMP0 ((uint32_t)0x00000002) /*!< FIFO 0 message pending Interrupt*/
  6404. #define CAN_IT_FF0 ((uint32_t)0x00000004) /*!< FIFO 0 full Interrupt*/
  6405. #define CAN_IT_FOV0 ((uint32_t)0x00000008) /*!< FIFO 0 overrun Interrupt*/
  6406. #define CAN_IT_FMP1 ((uint32_t)0x00000010) /*!< FIFO 1 message pending Interrupt*/
  6407. #define CAN_IT_FF1 ((uint32_t)0x00000020) /*!< FIFO 1 full Interrupt*/
  6408. #define CAN_IT_FOV1 ((uint32_t)0x00000040) /*!< FIFO 1 overrun Interrupt*/
  6409. /* Operating Mode Interrupts */
  6410. #define CAN_IT_WKU ((uint32_t)0x00010000) /*!< Wake-up Interrupt*/
  6411. #define CAN_IT_SLK ((uint32_t)0x00020000) /*!< Sleep acknowledge Interrupt*/
  6412. /* Error Interrupts */
  6413. #define CAN_IT_EWG ((uint32_t)0x00000100) /*!< Error warning Interrupt*/
  6414. #define CAN_IT_EPV ((uint32_t)0x00000200) /*!< Error passive Interrupt*/
  6415. #define CAN_IT_BOF ((uint32_t)0x00000400) /*!< Bus-off Interrupt*/
  6416. #define CAN_IT_LEC ((uint32_t)0x00000800) /*!< Last error code Interrupt*/
  6417. #define CAN_IT_ERR ((uint32_t)0x00008000) /*!< Error Interrupt*/
  6418. /* Flags named as Interrupts : kept only for FW compatibility */
  6419. #define CAN_IT_RQCP0 CAN_IT_TME
  6420. #define CAN_IT_RQCP1 CAN_IT_TME
  6421. #define CAN_IT_RQCP2 CAN_IT_TME
  6422. #define IS_CAN_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FMP0) ||\
  6423. ((IT) == CAN_IT_FF0) || ((IT) == CAN_IT_FOV0) ||\
  6424. ((IT) == CAN_IT_FMP1) || ((IT) == CAN_IT_FF1) ||\
  6425. ((IT) == CAN_IT_FOV1) || ((IT) == CAN_IT_EWG) ||\
  6426. ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\
  6427. ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\
  6428. ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK))
  6429. #define IS_CAN_CLEAR_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FF0) ||\
  6430. ((IT) == CAN_IT_FOV0)|| ((IT) == CAN_IT_FF1) ||\
  6431. ((IT) == CAN_IT_FOV1)|| ((IT) == CAN_IT_EWG) ||\
  6432. ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\
  6433. ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\
  6434. ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK))
  6435. /**
  6436. * @}
  6437. */
  6438. /** @defgroup CAN_Legacy
  6439. * @{
  6440. */
  6441. #define CANINITFAILED CAN_InitStatus_Failed
  6442. #define CANINITOK CAN_InitStatus_Success
  6443. #define CAN_FilterFIFO0 CAN_Filter_FIFO0
  6444. #define CAN_FilterFIFO1 CAN_Filter_FIFO1
  6445. #define CAN_ID_STD CAN_Id_Standard
  6446. #define CAN_ID_EXT CAN_Id_Extended
  6447. #define CAN_RTR_DATA CAN_RTR_Data
  6448. #define CAN_RTR_REMOTE CAN_RTR_Remote
  6449. #define CANTXFAILE CAN_TxStatus_Failed
  6450. #define CANTXOK CAN_TxStatus_Ok
  6451. #define CANTXPENDING CAN_TxStatus_Pending
  6452. #define CAN_NO_MB CAN_TxStatus_NoMailBox
  6453. #define CANSLEEPFAILED CAN_Sleep_Failed
  6454. #define CANSLEEPOK CAN_Sleep_Ok
  6455. #define CANWAKEUPFAILED CAN_WakeUp_Failed
  6456. #define CANWAKEUPOK CAN_WakeUp_Ok
  6457. /**
  6458. * @}
  6459. */
  6460. /**
  6461. * @}
  6462. */
  6463. /** @defgroup CAN_Exported_Macros
  6464. * @{
  6465. */
  6466. /**
  6467. * @}
  6468. */
  6469. /** @defgroup CAN_Exported_Functions
  6470. * @{
  6471. */
  6472. /* Function used to set the CAN configuration to the default reset state *****/
  6473. void CAN_DeInit(CAN_TypeDef* CANx);
  6474. /* Initialization and Configuration functions *********************************/
  6475. uint8_t CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct);
  6476. void CAN_FilterInit(CAN_FilterInitTypeDef* CAN_FilterInitStruct);
  6477. void CAN_StructInit(CAN_InitTypeDef* CAN_InitStruct);
  6478. void CAN_SlaveStartBank(uint8_t CAN_BankNumber);
  6479. void CAN_DBGFreeze(CAN_TypeDef* CANx, FunctionalState NewState);
  6480. void CAN_TTComModeCmd(CAN_TypeDef* CANx, FunctionalState NewState);
  6481. /* Transmit functions *********************************************************/
  6482. uint8_t CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage);
  6483. uint8_t CAN_TransmitStatus(CAN_TypeDef* CANx, uint8_t TransmitMailbox);
  6484. void CAN_CancelTransmit(CAN_TypeDef* CANx, uint8_t Mailbox);
  6485. /* Receive functions **********************************************************/
  6486. void CAN_Receive(CAN_TypeDef* CANx, uint8_t FIFONumber, CanRxMsg* RxMessage);
  6487. void CAN_FIFORelease(CAN_TypeDef* CANx, uint8_t FIFONumber);
  6488. uint8_t CAN_MessagePending(CAN_TypeDef* CANx, uint8_t FIFONumber);
  6489. /* Operation modes functions **************************************************/
  6490. uint8_t CAN_OperatingModeRequest(CAN_TypeDef* CANx, uint8_t CAN_OperatingMode);
  6491. uint8_t CAN_Sleep(CAN_TypeDef* CANx);
  6492. uint8_t CAN_WakeUp(CAN_TypeDef* CANx);
  6493. /* Error management functions *************************************************/
  6494. uint8_t CAN_GetLastErrorCode(CAN_TypeDef* CANx);
  6495. uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef* CANx);
  6496. uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef* CANx);
  6497. /* Interrupts and flags management functions **********************************/
  6498. void CAN_ITConfig(CAN_TypeDef* CANx, uint32_t CAN_IT, FunctionalState NewState);
  6499. FlagStatus CAN_GetFlagStatus(CAN_TypeDef* CANx, uint32_t CAN_FLAG);
  6500. void CAN_ClearFlag(CAN_TypeDef* CANx, uint32_t CAN_FLAG);
  6501. ITStatus CAN_GetITStatus(CAN_TypeDef* CANx, uint32_t CAN_IT);
  6502. void CAN_ClearITPendingBit(CAN_TypeDef* CANx, uint32_t CAN_IT);
  6503. #ifdef __cplusplus
  6504. }
  6505. #endif
  6506. #endif /* __STM32F10x_CAN_H */
  6507. /**
  6508. * @}
  6509. */
  6510. /**
  6511. * @}
  6512. */
  6513. /**
  6514. * @}
  6515. */
  6516. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  6517. /**
  6518. ******************************************************************************
  6519. * @file stm32f10x_flash.h
  6520. * @author MCD Application Team
  6521. * @version V3.5.0
  6522. * @date 11-March-2011
  6523. * @brief This file contains all the functions prototypes for the FLASH
  6524. * firmware library.
  6525. ******************************************************************************
  6526. * @attention
  6527. *
  6528. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  6529. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  6530. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  6531. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  6532. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  6533. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  6534. *
  6535. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  6536. ******************************************************************************
  6537. */
  6538. /* Define to prevent recursive inclusion -------------------------------------*/
  6539. #ifndef __STM32F10x_FLASH_H
  6540. #define __STM32F10x_FLASH_H
  6541. #ifdef __cplusplus
  6542. extern "C" {
  6543. #endif
  6544. /* Includes ------------------------------------------------------------------*/
  6545. #include "stm32f10x.h"
  6546. /** @addtogroup STM32F10x_StdPeriph_Driver
  6547. * @{
  6548. */
  6549. /** @addtogroup FLASH
  6550. * @{
  6551. */
  6552. /** @defgroup FLASH_Exported_Types
  6553. * @{
  6554. */
  6555. /**
  6556. * @brief FLASH Status
  6557. */
  6558. typedef enum
  6559. {
  6560. FLASH_BUSY = 1,
  6561. FLASH_ERROR_PG,
  6562. FLASH_ERROR_WRP,
  6563. FLASH_COMPLETE,
  6564. FLASH_TIMEOUT
  6565. }FLASH_Status;
  6566. /**
  6567. * @}
  6568. */
  6569. /** @defgroup FLASH_Exported_Constants
  6570. * @{
  6571. */
  6572. /** @defgroup Flash_Latency
  6573. * @{
  6574. */
  6575. #define FLASH_Latency_0 ((uint32_t)0x00000000) /*!< FLASH Zero Latency cycle */
  6576. #define FLASH_Latency_1 ((uint32_t)0x00000001) /*!< FLASH One Latency cycle */
  6577. #define FLASH_Latency_2 ((uint32_t)0x00000002) /*!< FLASH Two Latency cycles */
  6578. #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_Latency_0) || \
  6579. ((LATENCY) == FLASH_Latency_1) || \
  6580. ((LATENCY) == FLASH_Latency_2))
  6581. /**
  6582. * @}
  6583. */
  6584. /** @defgroup Half_Cycle_Enable_Disable
  6585. * @{
  6586. */
  6587. #define FLASH_HalfCycleAccess_Enable ((uint32_t)0x00000008) /*!< FLASH Half Cycle Enable */
  6588. #define FLASH_HalfCycleAccess_Disable ((uint32_t)0x00000000) /*!< FLASH Half Cycle Disable */
  6589. #define IS_FLASH_HALFCYCLEACCESS_STATE(STATE) (((STATE) == FLASH_HalfCycleAccess_Enable) || \
  6590. ((STATE) == FLASH_HalfCycleAccess_Disable))
  6591. /**
  6592. * @}
  6593. */
  6594. /** @defgroup Prefetch_Buffer_Enable_Disable
  6595. * @{
  6596. */
  6597. #define FLASH_PrefetchBuffer_Enable ((uint32_t)0x00000010) /*!< FLASH Prefetch Buffer Enable */
  6598. #define FLASH_PrefetchBuffer_Disable ((uint32_t)0x00000000) /*!< FLASH Prefetch Buffer Disable */
  6599. #define IS_FLASH_PREFETCHBUFFER_STATE(STATE) (((STATE) == FLASH_PrefetchBuffer_Enable) || \
  6600. ((STATE) == FLASH_PrefetchBuffer_Disable))
  6601. /**
  6602. * @}
  6603. */
  6604. /** @defgroup Option_Bytes_Write_Protection
  6605. * @{
  6606. */
  6607. /* Values to be used with STM32 Low and Medium density devices */
  6608. #define FLASH_WRProt_Pages0to3 ((uint32_t)0x00000001) /*!< STM32 Low and Medium density devices: Write protection of page 0 to 3 */
  6609. #define FLASH_WRProt_Pages4to7 ((uint32_t)0x00000002) /*!< STM32 Low and Medium density devices: Write protection of page 4 to 7 */
  6610. #define FLASH_WRProt_Pages8to11 ((uint32_t)0x00000004) /*!< STM32 Low and Medium density devices: Write protection of page 8 to 11 */
  6611. #define FLASH_WRProt_Pages12to15 ((uint32_t)0x00000008) /*!< STM32 Low and Medium density devices: Write protection of page 12 to 15 */
  6612. #define FLASH_WRProt_Pages16to19 ((uint32_t)0x00000010) /*!< STM32 Low and Medium density devices: Write protection of page 16 to 19 */
  6613. #define FLASH_WRProt_Pages20to23 ((uint32_t)0x00000020) /*!< STM32 Low and Medium density devices: Write protection of page 20 to 23 */
  6614. #define FLASH_WRProt_Pages24to27 ((uint32_t)0x00000040) /*!< STM32 Low and Medium density devices: Write protection of page 24 to 27 */
  6615. #define FLASH_WRProt_Pages28to31 ((uint32_t)0x00000080) /*!< STM32 Low and Medium density devices: Write protection of page 28 to 31 */
  6616. /* Values to be used with STM32 Medium-density devices */
  6617. #define FLASH_WRProt_Pages32to35 ((uint32_t)0x00000100) /*!< STM32 Medium-density devices: Write protection of page 32 to 35 */
  6618. #define FLASH_WRProt_Pages36to39 ((uint32_t)0x00000200) /*!< STM32 Medium-density devices: Write protection of page 36 to 39 */
  6619. #define FLASH_WRProt_Pages40to43 ((uint32_t)0x00000400) /*!< STM32 Medium-density devices: Write protection of page 40 to 43 */
  6620. #define FLASH_WRProt_Pages44to47 ((uint32_t)0x00000800) /*!< STM32 Medium-density devices: Write protection of page 44 to 47 */
  6621. #define FLASH_WRProt_Pages48to51 ((uint32_t)0x00001000) /*!< STM32 Medium-density devices: Write protection of page 48 to 51 */
  6622. #define FLASH_WRProt_Pages52to55 ((uint32_t)0x00002000) /*!< STM32 Medium-density devices: Write protection of page 52 to 55 */
  6623. #define FLASH_WRProt_Pages56to59 ((uint32_t)0x00004000) /*!< STM32 Medium-density devices: Write protection of page 56 to 59 */
  6624. #define FLASH_WRProt_Pages60to63 ((uint32_t)0x00008000) /*!< STM32 Medium-density devices: Write protection of page 60 to 63 */
  6625. #define FLASH_WRProt_Pages64to67 ((uint32_t)0x00010000) /*!< STM32 Medium-density devices: Write protection of page 64 to 67 */
  6626. #define FLASH_WRProt_Pages68to71 ((uint32_t)0x00020000) /*!< STM32 Medium-density devices: Write protection of page 68 to 71 */
  6627. #define FLASH_WRProt_Pages72to75 ((uint32_t)0x00040000) /*!< STM32 Medium-density devices: Write protection of page 72 to 75 */
  6628. #define FLASH_WRProt_Pages76to79 ((uint32_t)0x00080000) /*!< STM32 Medium-density devices: Write protection of page 76 to 79 */
  6629. #define FLASH_WRProt_Pages80to83 ((uint32_t)0x00100000) /*!< STM32 Medium-density devices: Write protection of page 80 to 83 */
  6630. #define FLASH_WRProt_Pages84to87 ((uint32_t)0x00200000) /*!< STM32 Medium-density devices: Write protection of page 84 to 87 */
  6631. #define FLASH_WRProt_Pages88to91 ((uint32_t)0x00400000) /*!< STM32 Medium-density devices: Write protection of page 88 to 91 */
  6632. #define FLASH_WRProt_Pages92to95 ((uint32_t)0x00800000) /*!< STM32 Medium-density devices: Write protection of page 92 to 95 */
  6633. #define FLASH_WRProt_Pages96to99 ((uint32_t)0x01000000) /*!< STM32 Medium-density devices: Write protection of page 96 to 99 */
  6634. #define FLASH_WRProt_Pages100to103 ((uint32_t)0x02000000) /*!< STM32 Medium-density devices: Write protection of page 100 to 103 */
  6635. #define FLASH_WRProt_Pages104to107 ((uint32_t)0x04000000) /*!< STM32 Medium-density devices: Write protection of page 104 to 107 */
  6636. #define FLASH_WRProt_Pages108to111 ((uint32_t)0x08000000) /*!< STM32 Medium-density devices: Write protection of page 108 to 111 */
  6637. #define FLASH_WRProt_Pages112to115 ((uint32_t)0x10000000) /*!< STM32 Medium-density devices: Write protection of page 112 to 115 */
  6638. #define FLASH_WRProt_Pages116to119 ((uint32_t)0x20000000) /*!< STM32 Medium-density devices: Write protection of page 115 to 119 */
  6639. #define FLASH_WRProt_Pages120to123 ((uint32_t)0x40000000) /*!< STM32 Medium-density devices: Write protection of page 120 to 123 */
  6640. #define FLASH_WRProt_Pages124to127 ((uint32_t)0x80000000) /*!< STM32 Medium-density devices: Write protection of page 124 to 127 */
  6641. /* Values to be used with STM32 High-density and STM32F10X Connectivity line devices */
  6642. #define FLASH_WRProt_Pages0to1 ((uint32_t)0x00000001) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6643. Write protection of page 0 to 1 */
  6644. #define FLASH_WRProt_Pages2to3 ((uint32_t)0x00000002) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6645. Write protection of page 2 to 3 */
  6646. #define FLASH_WRProt_Pages4to5 ((uint32_t)0x00000004) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6647. Write protection of page 4 to 5 */
  6648. #define FLASH_WRProt_Pages6to7 ((uint32_t)0x00000008) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6649. Write protection of page 6 to 7 */
  6650. #define FLASH_WRProt_Pages8to9 ((uint32_t)0x00000010) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6651. Write protection of page 8 to 9 */
  6652. #define FLASH_WRProt_Pages10to11 ((uint32_t)0x00000020) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6653. Write protection of page 10 to 11 */
  6654. #define FLASH_WRProt_Pages12to13 ((uint32_t)0x00000040) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6655. Write protection of page 12 to 13 */
  6656. #define FLASH_WRProt_Pages14to15 ((uint32_t)0x00000080) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6657. Write protection of page 14 to 15 */
  6658. #define FLASH_WRProt_Pages16to17 ((uint32_t)0x00000100) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6659. Write protection of page 16 to 17 */
  6660. #define FLASH_WRProt_Pages18to19 ((uint32_t)0x00000200) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6661. Write protection of page 18 to 19 */
  6662. #define FLASH_WRProt_Pages20to21 ((uint32_t)0x00000400) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6663. Write protection of page 20 to 21 */
  6664. #define FLASH_WRProt_Pages22to23 ((uint32_t)0x00000800) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6665. Write protection of page 22 to 23 */
  6666. #define FLASH_WRProt_Pages24to25 ((uint32_t)0x00001000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6667. Write protection of page 24 to 25 */
  6668. #define FLASH_WRProt_Pages26to27 ((uint32_t)0x00002000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6669. Write protection of page 26 to 27 */
  6670. #define FLASH_WRProt_Pages28to29 ((uint32_t)0x00004000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6671. Write protection of page 28 to 29 */
  6672. #define FLASH_WRProt_Pages30to31 ((uint32_t)0x00008000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6673. Write protection of page 30 to 31 */
  6674. #define FLASH_WRProt_Pages32to33 ((uint32_t)0x00010000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6675. Write protection of page 32 to 33 */
  6676. #define FLASH_WRProt_Pages34to35 ((uint32_t)0x00020000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6677. Write protection of page 34 to 35 */
  6678. #define FLASH_WRProt_Pages36to37 ((uint32_t)0x00040000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6679. Write protection of page 36 to 37 */
  6680. #define FLASH_WRProt_Pages38to39 ((uint32_t)0x00080000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6681. Write protection of page 38 to 39 */
  6682. #define FLASH_WRProt_Pages40to41 ((uint32_t)0x00100000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6683. Write protection of page 40 to 41 */
  6684. #define FLASH_WRProt_Pages42to43 ((uint32_t)0x00200000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6685. Write protection of page 42 to 43 */
  6686. #define FLASH_WRProt_Pages44to45 ((uint32_t)0x00400000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6687. Write protection of page 44 to 45 */
  6688. #define FLASH_WRProt_Pages46to47 ((uint32_t)0x00800000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6689. Write protection of page 46 to 47 */
  6690. #define FLASH_WRProt_Pages48to49 ((uint32_t)0x01000000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6691. Write protection of page 48 to 49 */
  6692. #define FLASH_WRProt_Pages50to51 ((uint32_t)0x02000000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6693. Write protection of page 50 to 51 */
  6694. #define FLASH_WRProt_Pages52to53 ((uint32_t)0x04000000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6695. Write protection of page 52 to 53 */
  6696. #define FLASH_WRProt_Pages54to55 ((uint32_t)0x08000000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6697. Write protection of page 54 to 55 */
  6698. #define FLASH_WRProt_Pages56to57 ((uint32_t)0x10000000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6699. Write protection of page 56 to 57 */
  6700. #define FLASH_WRProt_Pages58to59 ((uint32_t)0x20000000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6701. Write protection of page 58 to 59 */
  6702. #define FLASH_WRProt_Pages60to61 ((uint32_t)0x40000000) /*!< STM32 High-density, XL-density and Connectivity line devices:
  6703. Write protection of page 60 to 61 */
  6704. #define FLASH_WRProt_Pages62to127 ((uint32_t)0x80000000) /*!< STM32 Connectivity line devices: Write protection of page 62 to 127 */
  6705. #define FLASH_WRProt_Pages62to255 ((uint32_t)0x80000000) /*!< STM32 Medium-density devices: Write protection of page 62 to 255 */
  6706. #define FLASH_WRProt_Pages62to511 ((uint32_t)0x80000000) /*!< STM32 XL-density devices: Write protection of page 62 to 511 */
  6707. #define FLASH_WRProt_AllPages ((uint32_t)0xFFFFFFFF) /*!< Write protection of all Pages */
  6708. #define IS_FLASH_WRPROT_PAGE(PAGE) (((PAGE) != 0x00000000))
  6709. #define IS_FLASH_ADDRESS(ADDRESS) (((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x080FFFFF))
  6710. #define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == 0x1FFFF804) || ((ADDRESS) == 0x1FFFF806))
  6711. /**
  6712. * @}
  6713. */
  6714. /** @defgroup Option_Bytes_IWatchdog
  6715. * @{
  6716. */
  6717. #define OB_IWDG_SW ((uint16_t)0x0001) /*!< Software IWDG selected */
  6718. #define OB_IWDG_HW ((uint16_t)0x0000) /*!< Hardware IWDG selected */
  6719. #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
  6720. /**
  6721. * @}
  6722. */
  6723. /** @defgroup Option_Bytes_nRST_STOP
  6724. * @{
  6725. */
  6726. #define OB_STOP_NoRST ((uint16_t)0x0002) /*!< No reset generated when entering in STOP */
  6727. #define OB_STOP_RST ((uint16_t)0x0000) /*!< Reset generated when entering in STOP */
  6728. #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NoRST) || ((SOURCE) == OB_STOP_RST))
  6729. /**
  6730. * @}
  6731. */
  6732. /** @defgroup Option_Bytes_nRST_STDBY
  6733. * @{
  6734. */
  6735. #define OB_STDBY_NoRST ((uint16_t)0x0004) /*!< No reset generated when entering in STANDBY */
  6736. #define OB_STDBY_RST ((uint16_t)0x0000) /*!< Reset generated when entering in STANDBY */
  6737. #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NoRST) || ((SOURCE) == OB_STDBY_RST))
  6738. #ifdef STM32F10X_XL
  6739. /**
  6740. * @}
  6741. */
  6742. /** @defgroup FLASH_Boot
  6743. * @{
  6744. */
  6745. #define FLASH_BOOT_Bank1 ((uint16_t)0x0000) /*!< At startup, if boot pins are set in boot from user Flash position
  6746. and this parameter is selected the device will boot from Bank1(Default) */
  6747. #define FLASH_BOOT_Bank2 ((uint16_t)0x0001) /*!< At startup, if boot pins are set in boot from user Flash position
  6748. and this parameter is selected the device will boot from Bank 2 or Bank 1,
  6749. depending on the activation of the bank */
  6750. #define IS_FLASH_BOOT(BOOT) (((BOOT) == FLASH_BOOT_Bank1) || ((BOOT) == FLASH_BOOT_Bank2))
  6751. #endif
  6752. /**
  6753. * @}
  6754. */
  6755. /** @defgroup FLASH_Interrupts
  6756. * @{
  6757. */
  6758. #ifdef STM32F10X_XL
  6759. #define FLASH_IT_BANK2_ERROR ((uint32_t)0x80000400) /*!< FPEC BANK2 error interrupt source */
  6760. #define FLASH_IT_BANK2_EOP ((uint32_t)0x80001000) /*!< End of FLASH BANK2 Operation Interrupt source */
  6761. #define FLASH_IT_BANK1_ERROR FLASH_IT_ERROR /*!< FPEC BANK1 error interrupt source */
  6762. #define FLASH_IT_BANK1_EOP FLASH_IT_EOP /*!< End of FLASH BANK1 Operation Interrupt source */
  6763. #define FLASH_IT_ERROR ((uint32_t)0x00000400) /*!< FPEC BANK1 error interrupt source */
  6764. #define FLASH_IT_EOP ((uint32_t)0x00001000) /*!< End of FLASH BANK1 Operation Interrupt source */
  6765. #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0x7FFFEBFF) == 0x00000000) && (((IT) != 0x00000000)))
  6766. #else
  6767. #define FLASH_IT_ERROR ((uint32_t)0x00000400) /*!< FPEC error interrupt source */
  6768. #define FLASH_IT_EOP ((uint32_t)0x00001000) /*!< End of FLASH Operation Interrupt source */
  6769. #define FLASH_IT_BANK1_ERROR FLASH_IT_ERROR /*!< FPEC BANK1 error interrupt source */
  6770. #define FLASH_IT_BANK1_EOP FLASH_IT_EOP /*!< End of FLASH BANK1 Operation Interrupt source */
  6771. #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0xFFFFEBFF) == 0x00000000) && (((IT) != 0x00000000)))
  6772. #endif
  6773. /**
  6774. * @}
  6775. */
  6776. /** @defgroup FLASH_Flags
  6777. * @{
  6778. */
  6779. #ifdef STM32F10X_XL
  6780. #define FLASH_FLAG_BANK2_BSY ((uint32_t)0x80000001) /*!< FLASH BANK2 Busy flag */
  6781. #define FLASH_FLAG_BANK2_EOP ((uint32_t)0x80000020) /*!< FLASH BANK2 End of Operation flag */
  6782. #define FLASH_FLAG_BANK2_PGERR ((uint32_t)0x80000004) /*!< FLASH BANK2 Program error flag */
  6783. #define FLASH_FLAG_BANK2_WRPRTERR ((uint32_t)0x80000010) /*!< FLASH BANK2 Write protected error flag */
  6784. #define FLASH_FLAG_BANK1_BSY FLASH_FLAG_BSY /*!< FLASH BANK1 Busy flag*/
  6785. #define FLASH_FLAG_BANK1_EOP FLASH_FLAG_EOP /*!< FLASH BANK1 End of Operation flag */
  6786. #define FLASH_FLAG_BANK1_PGERR FLASH_FLAG_PGERR /*!< FLASH BANK1 Program error flag */
  6787. #define FLASH_FLAG_BANK1_WRPRTERR FLASH_FLAG_WRPRTERR /*!< FLASH BANK1 Write protected error flag */
  6788. #define FLASH_FLAG_BSY ((uint32_t)0x00000001) /*!< FLASH Busy flag */
  6789. #define FLASH_FLAG_EOP ((uint32_t)0x00000020) /*!< FLASH End of Operation flag */
  6790. #define FLASH_FLAG_PGERR ((uint32_t)0x00000004) /*!< FLASH Program error flag */
  6791. #define FLASH_FLAG_WRPRTERR ((uint32_t)0x00000010) /*!< FLASH Write protected error flag */
  6792. #define FLASH_FLAG_OPTERR ((uint32_t)0x00000001) /*!< FLASH Option Byte error flag */
  6793. #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0x7FFFFFCA) == 0x00000000) && ((FLAG) != 0x00000000))
  6794. #define IS_FLASH_GET_FLAG(FLAG) (((FLAG) == FLASH_FLAG_BSY) || ((FLAG) == FLASH_FLAG_EOP) || \
  6795. ((FLAG) == FLASH_FLAG_PGERR) || ((FLAG) == FLASH_FLAG_WRPRTERR) || \
  6796. ((FLAG) == FLASH_FLAG_OPTERR)|| \
  6797. ((FLAG) == FLASH_FLAG_BANK1_BSY) || ((FLAG) == FLASH_FLAG_BANK1_EOP) || \
  6798. ((FLAG) == FLASH_FLAG_BANK1_PGERR) || ((FLAG) == FLASH_FLAG_BANK1_WRPRTERR) || \
  6799. ((FLAG) == FLASH_FLAG_BANK2_BSY) || ((FLAG) == FLASH_FLAG_BANK2_EOP) || \
  6800. ((FLAG) == FLASH_FLAG_BANK2_PGERR) || ((FLAG) == FLASH_FLAG_BANK2_WRPRTERR))
  6801. #else
  6802. #define FLASH_FLAG_BSY ((uint32_t)0x00000001) /*!< FLASH Busy flag */
  6803. #define FLASH_FLAG_EOP ((uint32_t)0x00000020) /*!< FLASH End of Operation flag */
  6804. #define FLASH_FLAG_PGERR ((uint32_t)0x00000004) /*!< FLASH Program error flag */
  6805. #define FLASH_FLAG_WRPRTERR ((uint32_t)0x00000010) /*!< FLASH Write protected error flag */
  6806. #define FLASH_FLAG_OPTERR ((uint32_t)0x00000001) /*!< FLASH Option Byte error flag */
  6807. #define FLASH_FLAG_BANK1_BSY FLASH_FLAG_BSY /*!< FLASH BANK1 Busy flag*/
  6808. #define FLASH_FLAG_BANK1_EOP FLASH_FLAG_EOP /*!< FLASH BANK1 End of Operation flag */
  6809. #define FLASH_FLAG_BANK1_PGERR FLASH_FLAG_PGERR /*!< FLASH BANK1 Program error flag */
  6810. #define FLASH_FLAG_BANK1_WRPRTERR FLASH_FLAG_WRPRTERR /*!< FLASH BANK1 Write protected error flag */
  6811. #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFFCA) == 0x00000000) && ((FLAG) != 0x00000000))
  6812. #define IS_FLASH_GET_FLAG(FLAG) (((FLAG) == FLASH_FLAG_BSY) || ((FLAG) == FLASH_FLAG_EOP) || \
  6813. ((FLAG) == FLASH_FLAG_PGERR) || ((FLAG) == FLASH_FLAG_WRPRTERR) || \
  6814. ((FLAG) == FLASH_FLAG_BANK1_BSY) || ((FLAG) == FLASH_FLAG_BANK1_EOP) || \
  6815. ((FLAG) == FLASH_FLAG_BANK1_PGERR) || ((FLAG) == FLASH_FLAG_BANK1_WRPRTERR) || \
  6816. ((FLAG) == FLASH_FLAG_OPTERR))
  6817. #endif
  6818. /**
  6819. * @}
  6820. */
  6821. /**
  6822. * @}
  6823. */
  6824. /** @defgroup FLASH_Exported_Macros
  6825. * @{
  6826. */
  6827. /**
  6828. * @}
  6829. */
  6830. /** @defgroup FLASH_Exported_Functions
  6831. * @{
  6832. */
  6833. /*------------ Functions used for all STM32F10x devices -----*/
  6834. void FLASH_SetLatency(uint32_t FLASH_Latency);
  6835. void FLASH_HalfCycleAccessCmd(uint32_t FLASH_HalfCycleAccess);
  6836. void FLASH_PrefetchBufferCmd(uint32_t FLASH_PrefetchBuffer);
  6837. void FLASH_Unlock(void);
  6838. void FLASH_Lock(void);
  6839. FLASH_Status FLASH_ErasePage(uint32_t Page_Address);
  6840. FLASH_Status FLASH_EraseAllPages(void);
  6841. FLASH_Status FLASH_EraseOptionBytes(void);
  6842. FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);
  6843. FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
  6844. FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data);
  6845. FLASH_Status FLASH_EnableWriteProtection(uint32_t FLASH_Pages);
  6846. FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState);
  6847. FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint16_t OB_STDBY);
  6848. uint32_t FLASH_GetUserOptionByte(void);
  6849. uint32_t FLASH_GetWriteProtectionOptionByte(void);
  6850. FlagStatus FLASH_GetReadOutProtectionStatus(void);
  6851. FlagStatus FLASH_GetPrefetchBufferStatus(void);
  6852. void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);
  6853. FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG);
  6854. void FLASH_ClearFlag(uint32_t FLASH_FLAG);
  6855. FLASH_Status FLASH_GetStatus(void);
  6856. FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout);
  6857. /*------------ New function used for all STM32F10x devices -----*/
  6858. void FLASH_UnlockBank1(void);
  6859. void FLASH_LockBank1(void);
  6860. FLASH_Status FLASH_EraseAllBank1Pages(void);
  6861. FLASH_Status FLASH_GetBank1Status(void);
  6862. FLASH_Status FLASH_WaitForLastBank1Operation(uint32_t Timeout);
  6863. #ifdef STM32F10X_XL
  6864. /*---- New Functions used only with STM32F10x_XL density devices -----*/
  6865. void FLASH_UnlockBank2(void);
  6866. void FLASH_LockBank2(void);
  6867. FLASH_Status FLASH_EraseAllBank2Pages(void);
  6868. FLASH_Status FLASH_GetBank2Status(void);
  6869. FLASH_Status FLASH_WaitForLastBank2Operation(uint32_t Timeout);
  6870. FLASH_Status FLASH_BootConfig(uint16_t FLASH_BOOT);
  6871. #endif
  6872. #ifdef __cplusplus
  6873. }
  6874. #endif
  6875. #endif /* __STM32F10x_FLASH_H */
  6876. /**
  6877. * @}
  6878. */
  6879. /**
  6880. * @}
  6881. */
  6882. /**
  6883. * @}
  6884. */
  6885. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  6886. /**
  6887. ******************************************************************************
  6888. * @file stm32f10x_cec.h
  6889. * @author MCD Application Team
  6890. * @version V3.5.0
  6891. * @date 11-March-2011
  6892. * @brief This file contains all the functions prototypes for the CEC firmware
  6893. * library.
  6894. ******************************************************************************
  6895. * @attention
  6896. *
  6897. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  6898. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  6899. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  6900. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  6901. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  6902. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  6903. *
  6904. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  6905. ******************************************************************************
  6906. */
  6907. /* Define to prevent recursive inclusion -------------------------------------*/
  6908. #ifndef __STM32F10x_CEC_H
  6909. #define __STM32F10x_CEC_H
  6910. #ifdef __cplusplus
  6911. extern "C" {
  6912. #endif
  6913. /* Includes ------------------------------------------------------------------*/
  6914. #include "stm32f10x.h"
  6915. /** @addtogroup STM32F10x_StdPeriph_Driver
  6916. * @{
  6917. */
  6918. /** @addtogroup CEC
  6919. * @{
  6920. */
  6921. /** @defgroup CEC_Exported_Types
  6922. * @{
  6923. */
  6924. /**
  6925. * @brief CEC Init structure definition
  6926. */
  6927. typedef struct
  6928. {
  6929. uint16_t CEC_BitTimingMode; /*!< Configures the CEC Bit Timing Error Mode.
  6930. This parameter can be a value of @ref CEC_BitTiming_Mode */
  6931. uint16_t CEC_BitPeriodMode; /*!< Configures the CEC Bit Period Error Mode.
  6932. This parameter can be a value of @ref CEC_BitPeriod_Mode */
  6933. }CEC_InitTypeDef;
  6934. /**
  6935. * @}
  6936. */
  6937. /** @defgroup CEC_Exported_Constants
  6938. * @{
  6939. */
  6940. /** @defgroup CEC_BitTiming_Mode
  6941. * @{
  6942. */
  6943. #define CEC_BitTimingStdMode ((uint16_t)0x00) /*!< Bit timing error Standard Mode */
  6944. #define CEC_BitTimingErrFreeMode CEC_CFGR_BTEM /*!< Bit timing error Free Mode */
  6945. #define IS_CEC_BIT_TIMING_ERROR_MODE(MODE) (((MODE) == CEC_BitTimingStdMode) || \
  6946. ((MODE) == CEC_BitTimingErrFreeMode))
  6947. /**
  6948. * @}
  6949. */
  6950. /** @defgroup CEC_BitPeriod_Mode
  6951. * @{
  6952. */
  6953. #define CEC_BitPeriodStdMode ((uint16_t)0x00) /*!< Bit period error Standard Mode */
  6954. #define CEC_BitPeriodFlexibleMode CEC_CFGR_BPEM /*!< Bit period error Flexible Mode */
  6955. #define IS_CEC_BIT_PERIOD_ERROR_MODE(MODE) (((MODE) == CEC_BitPeriodStdMode) || \
  6956. ((MODE) == CEC_BitPeriodFlexibleMode))
  6957. /**
  6958. * @}
  6959. */
  6960. /** @defgroup CEC_interrupts_definition
  6961. * @{
  6962. */
  6963. #define CEC_IT_TERR CEC_CSR_TERR
  6964. #define CEC_IT_TBTRF CEC_CSR_TBTRF
  6965. #define CEC_IT_RERR CEC_CSR_RERR
  6966. #define CEC_IT_RBTF CEC_CSR_RBTF
  6967. #define IS_CEC_GET_IT(IT) (((IT) == CEC_IT_TERR) || ((IT) == CEC_IT_TBTRF) || \
  6968. ((IT) == CEC_IT_RERR) || ((IT) == CEC_IT_RBTF))
  6969. /**
  6970. * @}
  6971. */
  6972. /** @defgroup CEC_Own_Address
  6973. * @{
  6974. */
  6975. #define IS_CEC_ADDRESS(ADDRESS) ((ADDRESS) < 0x10)
  6976. /**
  6977. * @}
  6978. */
  6979. /** @defgroup CEC_Prescaler
  6980. * @{
  6981. */
  6982. #define IS_CEC_PRESCALER(PRESCALER) ((PRESCALER) <= 0x3FFF)
  6983. /**
  6984. * @}
  6985. */
  6986. /** @defgroup CEC_flags_definition
  6987. * @{
  6988. */
  6989. /**
  6990. * @brief ESR register flags
  6991. */
  6992. #define CEC_FLAG_BTE ((uint32_t)0x10010000)
  6993. #define CEC_FLAG_BPE ((uint32_t)0x10020000)
  6994. #define CEC_FLAG_RBTFE ((uint32_t)0x10040000)
  6995. #define CEC_FLAG_SBE ((uint32_t)0x10080000)
  6996. #define CEC_FLAG_ACKE ((uint32_t)0x10100000)
  6997. #define CEC_FLAG_LINE ((uint32_t)0x10200000)
  6998. #define CEC_FLAG_TBTFE ((uint32_t)0x10400000)
  6999. /**
  7000. * @brief CSR register flags
  7001. */
  7002. #define CEC_FLAG_TEOM ((uint32_t)0x00000002)
  7003. #define CEC_FLAG_TERR ((uint32_t)0x00000004)
  7004. #define CEC_FLAG_TBTRF ((uint32_t)0x00000008)
  7005. #define CEC_FLAG_RSOM ((uint32_t)0x00000010)
  7006. #define CEC_FLAG_REOM ((uint32_t)0x00000020)
  7007. #define CEC_FLAG_RERR ((uint32_t)0x00000040)
  7008. #define CEC_FLAG_RBTF ((uint32_t)0x00000080)
  7009. #define IS_CEC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFF03) == 0x00) && ((FLAG) != 0x00))
  7010. #define IS_CEC_GET_FLAG(FLAG) (((FLAG) == CEC_FLAG_BTE) || ((FLAG) == CEC_FLAG_BPE) || \
  7011. ((FLAG) == CEC_FLAG_RBTFE) || ((FLAG)== CEC_FLAG_SBE) || \
  7012. ((FLAG) == CEC_FLAG_ACKE) || ((FLAG) == CEC_FLAG_LINE) || \
  7013. ((FLAG) == CEC_FLAG_TBTFE) || ((FLAG) == CEC_FLAG_TEOM) || \
  7014. ((FLAG) == CEC_FLAG_TERR) || ((FLAG) == CEC_FLAG_TBTRF) || \
  7015. ((FLAG) == CEC_FLAG_RSOM) || ((FLAG) == CEC_FLAG_REOM) || \
  7016. ((FLAG) == CEC_FLAG_RERR) || ((FLAG) == CEC_FLAG_RBTF))
  7017. /**
  7018. * @}
  7019. */
  7020. /**
  7021. * @}
  7022. */
  7023. /** @defgroup CEC_Exported_Macros
  7024. * @{
  7025. */
  7026. /**
  7027. * @}
  7028. */
  7029. /** @defgroup CEC_Exported_Functions
  7030. * @{
  7031. */
  7032. void CEC_DeInit(void);
  7033. void CEC_Init(CEC_InitTypeDef* CEC_InitStruct);
  7034. void CEC_Cmd(FunctionalState NewState);
  7035. void CEC_ITConfig(FunctionalState NewState);
  7036. void CEC_OwnAddressConfig(uint8_t CEC_OwnAddress);
  7037. void CEC_SetPrescaler(uint16_t CEC_Prescaler);
  7038. void CEC_SendDataByte(uint8_t Data);
  7039. uint8_t CEC_ReceiveDataByte(void);
  7040. void CEC_StartOfMessage(void);
  7041. void CEC_EndOfMessageCmd(FunctionalState NewState);
  7042. FlagStatus CEC_GetFlagStatus(uint32_t CEC_FLAG);
  7043. void CEC_ClearFlag(uint32_t CEC_FLAG);
  7044. ITStatus CEC_GetITStatus(uint8_t CEC_IT);
  7045. void CEC_ClearITPendingBit(uint16_t CEC_IT);
  7046. #ifdef __cplusplus
  7047. }
  7048. #endif
  7049. #endif /* __STM32F10x_CEC_H */
  7050. /**
  7051. * @}
  7052. */
  7053. /**
  7054. * @}
  7055. */
  7056. /**
  7057. * @}
  7058. */
  7059. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  7060. /**
  7061. ******************************************************************************
  7062. * @file stm32f10x_wwdg.h
  7063. * @author MCD Application Team
  7064. * @version V3.5.0
  7065. * @date 11-March-2011
  7066. * @brief This file contains all the functions prototypes for the WWDG firmware
  7067. * library.
  7068. ******************************************************************************
  7069. * @attention
  7070. *
  7071. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  7072. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  7073. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  7074. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  7075. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  7076. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  7077. *
  7078. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  7079. ******************************************************************************
  7080. */
  7081. /* Define to prevent recursive inclusion -------------------------------------*/
  7082. #ifndef __STM32F10x_WWDG_H
  7083. #define __STM32F10x_WWDG_H
  7084. #ifdef __cplusplus
  7085. extern "C" {
  7086. #endif
  7087. /* Includes ------------------------------------------------------------------*/
  7088. #include "stm32f10x.h"
  7089. /** @addtogroup STM32F10x_StdPeriph_Driver
  7090. * @{
  7091. */
  7092. /** @addtogroup WWDG
  7093. * @{
  7094. */
  7095. /** @defgroup WWDG_Exported_Types
  7096. * @{
  7097. */
  7098. /**
  7099. * @}
  7100. */
  7101. /** @defgroup WWDG_Exported_Constants
  7102. * @{
  7103. */
  7104. /** @defgroup WWDG_Prescaler
  7105. * @{
  7106. */
  7107. #define WWDG_Prescaler_1 ((uint32_t)0x00000000)
  7108. #define WWDG_Prescaler_2 ((uint32_t)0x00000080)
  7109. #define WWDG_Prescaler_4 ((uint32_t)0x00000100)
  7110. #define WWDG_Prescaler_8 ((uint32_t)0x00000180)
  7111. #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \
  7112. ((PRESCALER) == WWDG_Prescaler_2) || \
  7113. ((PRESCALER) == WWDG_Prescaler_4) || \
  7114. ((PRESCALER) == WWDG_Prescaler_8))
  7115. #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F)
  7116. #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F))
  7117. /**
  7118. * @}
  7119. */
  7120. /**
  7121. * @}
  7122. */
  7123. /** @defgroup WWDG_Exported_Macros
  7124. * @{
  7125. */
  7126. /**
  7127. * @}
  7128. */
  7129. /** @defgroup WWDG_Exported_Functions
  7130. * @{
  7131. */
  7132. void WWDG_DeInit(void);
  7133. void WWDG_SetPrescaler(uint32_t WWDG_Prescaler);
  7134. void WWDG_SetWindowValue(uint8_t WindowValue);
  7135. void WWDG_EnableIT(void);
  7136. void WWDG_SetCounter(uint8_t Counter);
  7137. void WWDG_Enable(uint8_t Counter);
  7138. FlagStatus WWDG_GetFlagStatus(void);
  7139. void WWDG_ClearFlag(void);
  7140. #ifdef __cplusplus
  7141. }
  7142. #endif
  7143. #endif /* __STM32F10x_WWDG_H */
  7144. /**
  7145. * @}
  7146. */
  7147. /**
  7148. * @}
  7149. */
  7150. /**
  7151. * @}
  7152. */
  7153. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  7154. /**
  7155. ******************************************************************************
  7156. * @file misc.h
  7157. * @author MCD Application Team
  7158. * @version V3.5.0
  7159. * @date 11-March-2011
  7160. * @brief This file contains all the functions prototypes for the miscellaneous
  7161. * firmware library functions (add-on to CMSIS functions).
  7162. ******************************************************************************
  7163. * @attention
  7164. *
  7165. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  7166. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  7167. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  7168. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  7169. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  7170. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  7171. *
  7172. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  7173. ******************************************************************************
  7174. */
  7175. /* Define to prevent recursive inclusion -------------------------------------*/
  7176. #ifndef __MISC_H
  7177. #define __MISC_H
  7178. #ifdef __cplusplus
  7179. extern "C" {
  7180. #endif
  7181. /* Includes ------------------------------------------------------------------*/
  7182. #include "stm32f10x.h"
  7183. /** @addtogroup STM32F10x_StdPeriph_Driver
  7184. * @{
  7185. */
  7186. /** @addtogroup MISC
  7187. * @{
  7188. */
  7189. /** @defgroup MISC_Exported_Types
  7190. * @{
  7191. */
  7192. /**
  7193. * @brief NVIC Init Structure definition
  7194. */
  7195. typedef struct
  7196. {
  7197. uint8_t NVIC_IRQChannel; /*!< Specifies the IRQ channel to be enabled or disabled.
  7198. This parameter can be a value of @ref IRQn_Type
  7199. (For the complete STM32 Devices IRQ Channels list, please
  7200. refer to stm32f10x.h file) */
  7201. uint8_t NVIC_IRQChannelPreemptionPriority; /*!< Specifies the pre-emption priority for the IRQ channel
  7202. specified in NVIC_IRQChannel. This parameter can be a value
  7203. between 0 and 15 as described in the table @ref NVIC_Priority_Table */
  7204. uint8_t NVIC_IRQChannelSubPriority; /*!< Specifies the subpriority level for the IRQ channel specified
  7205. in NVIC_IRQChannel. This parameter can be a value
  7206. between 0 and 15 as described in the table @ref NVIC_Priority_Table */
  7207. FunctionalState NVIC_IRQChannelCmd; /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel
  7208. will be enabled or disabled.
  7209. This parameter can be set either to ENABLE or DISABLE */
  7210. } NVIC_InitTypeDef;
  7211. /**
  7212. * @}
  7213. */
  7214. /** @defgroup NVIC_Priority_Table
  7215. * @{
  7216. */
  7217. /**
  7218. @code
  7219. The table below gives the allowed values of the pre-emption priority and subpriority according
  7220. to the Priority Grouping configuration performed by NVIC_PriorityGroupConfig function
  7221. ============================================================================================================================
  7222. NVIC_PriorityGroup | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority | Description
  7223. ============================================================================================================================
  7224. NVIC_PriorityGroup_0 | 0 | 0-15 | 0 bits for pre-emption priority
  7225. | | | 4 bits for subpriority
  7226. ----------------------------------------------------------------------------------------------------------------------------
  7227. NVIC_PriorityGroup_1 | 0-1 | 0-7 | 1 bits for pre-emption priority
  7228. | | | 3 bits for subpriority
  7229. ----------------------------------------------------------------------------------------------------------------------------
  7230. NVIC_PriorityGroup_2 | 0-3 | 0-3 | 2 bits for pre-emption priority
  7231. | | | 2 bits for subpriority
  7232. ----------------------------------------------------------------------------------------------------------------------------
  7233. NVIC_PriorityGroup_3 | 0-7 | 0-1 | 3 bits for pre-emption priority
  7234. | | | 1 bits for subpriority
  7235. ----------------------------------------------------------------------------------------------------------------------------
  7236. NVIC_PriorityGroup_4 | 0-15 | 0 | 4 bits for pre-emption priority
  7237. | | | 0 bits for subpriority
  7238. ============================================================================================================================
  7239. @endcode
  7240. */
  7241. /**
  7242. * @}
  7243. */
  7244. /** @defgroup MISC_Exported_Constants
  7245. * @{
  7246. */
  7247. /** @defgroup Vector_Table_Base
  7248. * @{
  7249. */
  7250. #define NVIC_VectTab_RAM ((uint32_t)0x20000000)
  7251. #define NVIC_VectTab_FLASH ((uint32_t)0x08000000)
  7252. #define IS_NVIC_VECTTAB(VECTTAB) (((VECTTAB) == NVIC_VectTab_RAM) || \
  7253. ((VECTTAB) == NVIC_VectTab_FLASH))
  7254. /**
  7255. * @}
  7256. */
  7257. /** @defgroup System_Low_Power
  7258. * @{
  7259. */
  7260. #define NVIC_LP_SEVONPEND ((uint8_t)0x10)
  7261. #define NVIC_LP_SLEEPDEEP ((uint8_t)0x04)
  7262. #define NVIC_LP_SLEEPONEXIT ((uint8_t)0x02)
  7263. #define IS_NVIC_LP(LP) (((LP) == NVIC_LP_SEVONPEND) || \
  7264. ((LP) == NVIC_LP_SLEEPDEEP) || \
  7265. ((LP) == NVIC_LP_SLEEPONEXIT))
  7266. /**
  7267. * @}
  7268. */
  7269. /** @defgroup Preemption_Priority_Group
  7270. * @{
  7271. */
  7272. #define NVIC_PriorityGroup_0 ((uint32_t)0x700) /*!< 0 bits for pre-emption priority
  7273. 4 bits for subpriority */
  7274. #define NVIC_PriorityGroup_1 ((uint32_t)0x600) /*!< 1 bits for pre-emption priority
  7275. 3 bits for subpriority */
  7276. #define NVIC_PriorityGroup_2 ((uint32_t)0x500) /*!< 2 bits for pre-emption priority
  7277. 2 bits for subpriority */
  7278. #define NVIC_PriorityGroup_3 ((uint32_t)0x400) /*!< 3 bits for pre-emption priority
  7279. 1 bits for subpriority */
  7280. #define NVIC_PriorityGroup_4 ((uint32_t)0x300) /*!< 4 bits for pre-emption priority
  7281. 0 bits for subpriority */
  7282. #define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PriorityGroup_0) || \
  7283. ((GROUP) == NVIC_PriorityGroup_1) || \
  7284. ((GROUP) == NVIC_PriorityGroup_2) || \
  7285. ((GROUP) == NVIC_PriorityGroup_3) || \
  7286. ((GROUP) == NVIC_PriorityGroup_4))
  7287. #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10)
  7288. #define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10)
  7289. #define IS_NVIC_OFFSET(OFFSET) ((OFFSET) < 0x000FFFFF)
  7290. /**
  7291. * @}
  7292. */
  7293. /** @defgroup SysTick_clock_source
  7294. * @{
  7295. */
  7296. #define SysTick_CLKSource_HCLK_Div8 ((uint32_t)0xFFFFFFFB)
  7297. #define SysTick_CLKSource_HCLK ((uint32_t)0x00000004)
  7298. #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SysTick_CLKSource_HCLK) || \
  7299. ((SOURCE) == SysTick_CLKSource_HCLK_Div8))
  7300. /**
  7301. * @}
  7302. */
  7303. /**
  7304. * @}
  7305. */
  7306. /** @defgroup MISC_Exported_Macros
  7307. * @{
  7308. */
  7309. /**
  7310. * @}
  7311. */
  7312. /** @defgroup MISC_Exported_Functions
  7313. * @{
  7314. */
  7315. void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup);
  7316. void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct);
  7317. void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset);
  7318. void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState);
  7319. void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource);
  7320. #ifdef __cplusplus
  7321. }
  7322. #endif
  7323. #endif /* __MISC_H */
  7324. /**
  7325. * @}
  7326. */
  7327. /**
  7328. * @}
  7329. */
  7330. /**
  7331. * @}
  7332. */
  7333. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  7334. /**
  7335. ******************************************************************************
  7336. * @file stm32f10x_dac.h
  7337. * @author MCD Application Team
  7338. * @version V3.5.0
  7339. * @date 11-March-2011
  7340. * @brief This file contains all the functions prototypes for the DAC firmware
  7341. * library.
  7342. ******************************************************************************
  7343. * @attention
  7344. *
  7345. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  7346. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  7347. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  7348. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  7349. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  7350. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  7351. *
  7352. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  7353. ******************************************************************************
  7354. */
  7355. /* Define to prevent recursive inclusion -------------------------------------*/
  7356. #ifndef __STM32F10x_DAC_H
  7357. #define __STM32F10x_DAC_H
  7358. #ifdef __cplusplus
  7359. extern "C" {
  7360. #endif
  7361. /* Includes ------------------------------------------------------------------*/
  7362. #include "stm32f10x.h"
  7363. /** @addtogroup STM32F10x_StdPeriph_Driver
  7364. * @{
  7365. */
  7366. /** @addtogroup DAC
  7367. * @{
  7368. */
  7369. /** @defgroup DAC_Exported_Types
  7370. * @{
  7371. */
  7372. /**
  7373. * @brief DAC Init structure definition
  7374. */
  7375. typedef struct
  7376. {
  7377. uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel.
  7378. This parameter can be a value of @ref DAC_trigger_selection */
  7379. uint32_t DAC_WaveGeneration; /*!< Specifies whether DAC channel noise waves or triangle waves
  7380. are generated, or whether no wave is generated.
  7381. This parameter can be a value of @ref DAC_wave_generation */
  7382. uint32_t DAC_LFSRUnmask_TriangleAmplitude; /*!< Specifies the LFSR mask for noise wave generation or
  7383. the maximum amplitude triangle generation for the DAC channel.
  7384. This parameter can be a value of @ref DAC_lfsrunmask_triangleamplitude */
  7385. uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
  7386. This parameter can be a value of @ref DAC_output_buffer */
  7387. }DAC_InitTypeDef;
  7388. /**
  7389. * @}
  7390. */
  7391. /** @defgroup DAC_Exported_Constants
  7392. * @{
  7393. */
  7394. /** @defgroup DAC_trigger_selection
  7395. * @{
  7396. */
  7397. #define DAC_Trigger_None ((uint32_t)0x00000000) /*!< Conversion is automatic once the DAC1_DHRxxxx register
  7398. has been loaded, and not by external trigger */
  7399. #define DAC_Trigger_T6_TRGO ((uint32_t)0x00000004) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */
  7400. #define DAC_Trigger_T8_TRGO ((uint32_t)0x0000000C) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel
  7401. only in High-density devices*/
  7402. #define DAC_Trigger_T3_TRGO ((uint32_t)0x0000000C) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel
  7403. only in Connectivity line, Medium-density and Low-density Value Line devices */
  7404. #define DAC_Trigger_T7_TRGO ((uint32_t)0x00000014) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */
  7405. #define DAC_Trigger_T5_TRGO ((uint32_t)0x0000001C) /*!< TIM5 TRGO selected as external conversion trigger for DAC channel */
  7406. #define DAC_Trigger_T15_TRGO ((uint32_t)0x0000001C) /*!< TIM15 TRGO selected as external conversion trigger for DAC channel
  7407. only in Medium-density and Low-density Value Line devices*/
  7408. #define DAC_Trigger_T2_TRGO ((uint32_t)0x00000024) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */
  7409. #define DAC_Trigger_T4_TRGO ((uint32_t)0x0000002C) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */
  7410. #define DAC_Trigger_Ext_IT9 ((uint32_t)0x00000034) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */
  7411. #define DAC_Trigger_Software ((uint32_t)0x0000003C) /*!< Conversion started by software trigger for DAC channel */
  7412. #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_Trigger_None) || \
  7413. ((TRIGGER) == DAC_Trigger_T6_TRGO) || \
  7414. ((TRIGGER) == DAC_Trigger_T8_TRGO) || \
  7415. ((TRIGGER) == DAC_Trigger_T7_TRGO) || \
  7416. ((TRIGGER) == DAC_Trigger_T5_TRGO) || \
  7417. ((TRIGGER) == DAC_Trigger_T2_TRGO) || \
  7418. ((TRIGGER) == DAC_Trigger_T4_TRGO) || \
  7419. ((TRIGGER) == DAC_Trigger_Ext_IT9) || \
  7420. ((TRIGGER) == DAC_Trigger_Software))
  7421. /**
  7422. * @}
  7423. */
  7424. /** @defgroup DAC_wave_generation
  7425. * @{
  7426. */
  7427. #define DAC_WaveGeneration_None ((uint32_t)0x00000000)
  7428. #define DAC_WaveGeneration_Noise ((uint32_t)0x00000040)
  7429. #define DAC_WaveGeneration_Triangle ((uint32_t)0x00000080)
  7430. #define IS_DAC_GENERATE_WAVE(WAVE) (((WAVE) == DAC_WaveGeneration_None) || \
  7431. ((WAVE) == DAC_WaveGeneration_Noise) || \
  7432. ((WAVE) == DAC_WaveGeneration_Triangle))
  7433. /**
  7434. * @}
  7435. */
  7436. /** @defgroup DAC_lfsrunmask_triangleamplitude
  7437. * @{
  7438. */
  7439. #define DAC_LFSRUnmask_Bit0 ((uint32_t)0x00000000) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
  7440. #define DAC_LFSRUnmask_Bits1_0 ((uint32_t)0x00000100) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */
  7441. #define DAC_LFSRUnmask_Bits2_0 ((uint32_t)0x00000200) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */
  7442. #define DAC_LFSRUnmask_Bits3_0 ((uint32_t)0x00000300) /*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */
  7443. #define DAC_LFSRUnmask_Bits4_0 ((uint32_t)0x00000400) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */
  7444. #define DAC_LFSRUnmask_Bits5_0 ((uint32_t)0x00000500) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */
  7445. #define DAC_LFSRUnmask_Bits6_0 ((uint32_t)0x00000600) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */
  7446. #define DAC_LFSRUnmask_Bits7_0 ((uint32_t)0x00000700) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */
  7447. #define DAC_LFSRUnmask_Bits8_0 ((uint32_t)0x00000800) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */
  7448. #define DAC_LFSRUnmask_Bits9_0 ((uint32_t)0x00000900) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */
  7449. #define DAC_LFSRUnmask_Bits10_0 ((uint32_t)0x00000A00) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */
  7450. #define DAC_LFSRUnmask_Bits11_0 ((uint32_t)0x00000B00) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */
  7451. #define DAC_TriangleAmplitude_1 ((uint32_t)0x00000000) /*!< Select max triangle amplitude of 1 */
  7452. #define DAC_TriangleAmplitude_3 ((uint32_t)0x00000100) /*!< Select max triangle amplitude of 3 */
  7453. #define DAC_TriangleAmplitude_7 ((uint32_t)0x00000200) /*!< Select max triangle amplitude of 7 */
  7454. #define DAC_TriangleAmplitude_15 ((uint32_t)0x00000300) /*!< Select max triangle amplitude of 15 */
  7455. #define DAC_TriangleAmplitude_31 ((uint32_t)0x00000400) /*!< Select max triangle amplitude of 31 */
  7456. #define DAC_TriangleAmplitude_63 ((uint32_t)0x00000500) /*!< Select max triangle amplitude of 63 */
  7457. #define DAC_TriangleAmplitude_127 ((uint32_t)0x00000600) /*!< Select max triangle amplitude of 127 */
  7458. #define DAC_TriangleAmplitude_255 ((uint32_t)0x00000700) /*!< Select max triangle amplitude of 255 */
  7459. #define DAC_TriangleAmplitude_511 ((uint32_t)0x00000800) /*!< Select max triangle amplitude of 511 */
  7460. #define DAC_TriangleAmplitude_1023 ((uint32_t)0x00000900) /*!< Select max triangle amplitude of 1023 */
  7461. #define DAC_TriangleAmplitude_2047 ((uint32_t)0x00000A00) /*!< Select max triangle amplitude of 2047 */
  7462. #define DAC_TriangleAmplitude_4095 ((uint32_t)0x00000B00) /*!< Select max triangle amplitude of 4095 */
  7463. #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUnmask_Bit0) || \
  7464. ((VALUE) == DAC_LFSRUnmask_Bits1_0) || \
  7465. ((VALUE) == DAC_LFSRUnmask_Bits2_0) || \
  7466. ((VALUE) == DAC_LFSRUnmask_Bits3_0) || \
  7467. ((VALUE) == DAC_LFSRUnmask_Bits4_0) || \
  7468. ((VALUE) == DAC_LFSRUnmask_Bits5_0) || \
  7469. ((VALUE) == DAC_LFSRUnmask_Bits6_0) || \
  7470. ((VALUE) == DAC_LFSRUnmask_Bits7_0) || \
  7471. ((VALUE) == DAC_LFSRUnmask_Bits8_0) || \
  7472. ((VALUE) == DAC_LFSRUnmask_Bits9_0) || \
  7473. ((VALUE) == DAC_LFSRUnmask_Bits10_0) || \
  7474. ((VALUE) == DAC_LFSRUnmask_Bits11_0) || \
  7475. ((VALUE) == DAC_TriangleAmplitude_1) || \
  7476. ((VALUE) == DAC_TriangleAmplitude_3) || \
  7477. ((VALUE) == DAC_TriangleAmplitude_7) || \
  7478. ((VALUE) == DAC_TriangleAmplitude_15) || \
  7479. ((VALUE) == DAC_TriangleAmplitude_31) || \
  7480. ((VALUE) == DAC_TriangleAmplitude_63) || \
  7481. ((VALUE) == DAC_TriangleAmplitude_127) || \
  7482. ((VALUE) == DAC_TriangleAmplitude_255) || \
  7483. ((VALUE) == DAC_TriangleAmplitude_511) || \
  7484. ((VALUE) == DAC_TriangleAmplitude_1023) || \
  7485. ((VALUE) == DAC_TriangleAmplitude_2047) || \
  7486. ((VALUE) == DAC_TriangleAmplitude_4095))
  7487. /**
  7488. * @}
  7489. */
  7490. /** @defgroup DAC_output_buffer
  7491. * @{
  7492. */
  7493. #define DAC_OutputBuffer_Enable ((uint32_t)0x00000000)
  7494. #define DAC_OutputBuffer_Disable ((uint32_t)0x00000002)
  7495. #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OutputBuffer_Enable) || \
  7496. ((STATE) == DAC_OutputBuffer_Disable))
  7497. /**
  7498. * @}
  7499. */
  7500. /** @defgroup DAC_Channel_selection
  7501. * @{
  7502. */
  7503. #define DAC_Channel_1 ((uint32_t)0x00000000)
  7504. #define DAC_Channel_2 ((uint32_t)0x00000010)
  7505. #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_Channel_1) || \
  7506. ((CHANNEL) == DAC_Channel_2))
  7507. /**
  7508. * @}
  7509. */
  7510. /** @defgroup DAC_data_alignment
  7511. * @{
  7512. */
  7513. #define DAC_Align_12b_R ((uint32_t)0x00000000)
  7514. #define DAC_Align_12b_L ((uint32_t)0x00000004)
  7515. #define DAC_Align_8b_R ((uint32_t)0x00000008)
  7516. #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_Align_12b_R) || \
  7517. ((ALIGN) == DAC_Align_12b_L) || \
  7518. ((ALIGN) == DAC_Align_8b_R))
  7519. /**
  7520. * @}
  7521. */
  7522. /** @defgroup DAC_wave_generation
  7523. * @{
  7524. */
  7525. #define DAC_Wave_Noise ((uint32_t)0x00000040)
  7526. #define DAC_Wave_Triangle ((uint32_t)0x00000080)
  7527. #define IS_DAC_WAVE(WAVE) (((WAVE) == DAC_Wave_Noise) || \
  7528. ((WAVE) == DAC_Wave_Triangle))
  7529. /**
  7530. * @}
  7531. */
  7532. /** @defgroup DAC_data
  7533. * @{
  7534. */
  7535. #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0)
  7536. /**
  7537. * @}
  7538. */
  7539. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  7540. /** @defgroup DAC_interrupts_definition
  7541. * @{
  7542. */
  7543. #define DAC_IT_DMAUDR ((uint32_t)0x00002000)
  7544. #define IS_DAC_IT(IT) (((IT) == DAC_IT_DMAUDR))
  7545. /**
  7546. * @}
  7547. */
  7548. /** @defgroup DAC_flags_definition
  7549. * @{
  7550. */
  7551. #define DAC_FLAG_DMAUDR ((uint32_t)0x00002000)
  7552. #define IS_DAC_FLAG(FLAG) (((FLAG) == DAC_FLAG_DMAUDR))
  7553. /**
  7554. * @}
  7555. */
  7556. #endif
  7557. /**
  7558. * @}
  7559. */
  7560. /** @defgroup DAC_Exported_Macros
  7561. * @{
  7562. */
  7563. /**
  7564. * @}
  7565. */
  7566. /** @defgroup DAC_Exported_Functions
  7567. * @{
  7568. */
  7569. void DAC_DeInit(void);
  7570. void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct);
  7571. void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct);
  7572. void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState);
  7573. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  7574. void DAC_ITConfig(uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState);
  7575. #endif
  7576. void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState);
  7577. void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState);
  7578. void DAC_DualSoftwareTriggerCmd(FunctionalState NewState);
  7579. void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState);
  7580. void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data);
  7581. void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data);
  7582. void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1);
  7583. uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel);
  7584. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  7585. FlagStatus DAC_GetFlagStatus(uint32_t DAC_Channel, uint32_t DAC_FLAG);
  7586. void DAC_ClearFlag(uint32_t DAC_Channel, uint32_t DAC_FLAG);
  7587. ITStatus DAC_GetITStatus(uint32_t DAC_Channel, uint32_t DAC_IT);
  7588. void DAC_ClearITPendingBit(uint32_t DAC_Channel, uint32_t DAC_IT);
  7589. #endif
  7590. #ifdef __cplusplus
  7591. }
  7592. #endif
  7593. #endif /*__STM32F10x_DAC_H */
  7594. /**
  7595. * @}
  7596. */
  7597. /**
  7598. * @}
  7599. */
  7600. /**
  7601. * @}
  7602. */
  7603. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  7604. /**
  7605. ******************************************************************************
  7606. * @file SPI/SPI_FLASH/stm32f10x_conf.h
  7607. * @author MCD Application Team
  7608. * @version V3.5.0
  7609. * @date 08-April-2011
  7610. * @brief Library configuration file.
  7611. ******************************************************************************
  7612. * @attention
  7613. *
  7614. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  7615. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  7616. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  7617. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  7618. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  7619. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  7620. *
  7621. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  7622. ******************************************************************************
  7623. */
  7624. /* Define to prevent recursive inclusion -------------------------------------*/
  7625. #ifndef __STM32F10x_CONF_H
  7626. #define __STM32F10x_CONF_H
  7627. /* Includes ------------------------------------------------------------------*/
  7628. /* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */
  7629. #include "stm32f10x_adc.h"
  7630. #include "stm32f10x_bkp.h"
  7631. #include "stm32f10x_can.h"
  7632. #include "stm32f10x_cec.h"
  7633. #include "stm32f10x_crc.h"
  7634. #include "stm32f10x_dac.h"
  7635. #include "stm32f10x_dbgmcu.h"
  7636. #include "stm32f10x_dma.h"
  7637. #include "stm32f10x_exti.h"
  7638. #include "stm32f10x_flash.h"
  7639. #include "stm32f10x_fsmc.h"
  7640. #include "stm32f10x_gpio.h"
  7641. #include "stm32f10x_i2c.h"
  7642. #include "stm32f10x_iwdg.h"
  7643. #include "stm32f10x_pwr.h"
  7644. #include "stm32f10x_rcc.h"
  7645. #include "stm32f10x_rtc.h"
  7646. #include "stm32f10x_sdio.h"
  7647. #include "stm32f10x_spi.h"
  7648. #include "stm32f10x_tim.h"
  7649. #include "stm32f10x_usart.h"
  7650. #include "stm32f10x_wwdg.h"
  7651. #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
  7652. /* Exported types ------------------------------------------------------------*/
  7653. /* Exported constants --------------------------------------------------------*/
  7654. /* Uncomment the line below to expanse the "assert_param" macro in the
  7655. Standard Peripheral Library drivers code */
  7656. /* #define USE_FULL_ASSERT 1 */
  7657. /* Exported macro ------------------------------------------------------------*/
  7658. #ifdef USE_FULL_ASSERT
  7659. /**
  7660. * @brief The assert_param macro is used for function's parameters check.
  7661. * @param expr: If expr is false, it calls assert_failed function which reports
  7662. * the name of the source file and the source line number of the call
  7663. * that failed. If expr is true, it returns no value.
  7664. * @retval None
  7665. */
  7666. #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
  7667. /* Exported functions ------------------------------------------------------- */
  7668. void assert_failed(uint8_t* file, uint32_t line);
  7669. #else
  7670. #define assert_param(expr) ((void)0)
  7671. #endif /* USE_FULL_ASSERT */
  7672. #endif /* __STM32F10x_CONF_H */
  7673. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  7674. /**
  7675. ******************************************************************************
  7676. * @file SPI/SPI_MSD/main.h
  7677. * @author MCD Application Team
  7678. * @version V1.0.0
  7679. * @date 18-May-2012
  7680. * @brief Header for main.c module
  7681. ******************************************************************************
  7682. * @attention
  7683. *
  7684. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  7685. *
  7686. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  7687. * You may not use this file except in compliance with the License.
  7688. * You may obtain a copy of the License at:
  7689. *
  7690. * http://www.st.com/software_license_agreement_liberty_v2
  7691. *
  7692. * Unless required by applicable law or agreed to in writing, software
  7693. * distributed under the License is distributed on an "AS IS" BASIS,
  7694. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  7695. * See the License for the specific language governing permissions and
  7696. * limitations under the License.
  7697. *
  7698. ******************************************************************************
  7699. */
  7700. /* Define to prevent recursive inclusion -------------------------------------*/
  7701. #ifndef __MAIN_H
  7702. #define __MAIN_H
  7703. /* Includes ------------------------------------------------------------------*/
  7704. #include <stdint.h>
  7705. #include "stm32f10x_gpio.h"
  7706. #include "stm32f10x_spi.h"
  7707. #include "stm32f10x_rcc.h"
  7708. #include "stm32_eval_spi_sd.h"
  7709. #include "stm32f10x_conf.h"
  7710. #include "stm32f10x_gpio.c"
  7711. #include "stm32f10x_rcc.c"
  7712. #include "stm32f10x_spi.c"
  7713. #include "stm32_eval_spi_sd.c"
  7714. /* Exported types ------------------------------------------------------------*/
  7715. typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
  7716. /* Exported constants --------------------------------------------------------*/
  7717. #define BUFFERSIZE 512
  7718. /* Exported macro ------------------------------------------------------------*/
  7719. /* Exported functions ------------------------------------------------------- */
  7720. #endif /* __MAIN_H */
  7721. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  7722. /**
  7723. ******************************************************************************
  7724. * @file SPI/SPI_FLASH/stm32f10x_it.h
  7725. * @author MCD Application Team
  7726. * @version V3.5.0
  7727. * @date 08-April-2011
  7728. * @brief This file contains the headers of the interrupt handlers.
  7729. ******************************************************************************
  7730. * @attention
  7731. *
  7732. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  7733. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  7734. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  7735. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  7736. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  7737. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  7738. *
  7739. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  7740. ******************************************************************************
  7741. */
  7742. /* Define to prevent recursive inclusion -------------------------------------*/
  7743. #ifndef __STM32F10x_IT_H
  7744. #define __STM32F10x_IT_H
  7745. /* Includes ------------------------------------------------------------------*/
  7746. #include "stm32f10x.h"
  7747. /* Exported types ------------------------------------------------------------*/
  7748. /* Exported constants --------------------------------------------------------*/
  7749. /* Exported macro ------------------------------------------------------------*/
  7750. /* Exported functions ------------------------------------------------------- */
  7751. void NMI_Handler(void);
  7752. void HardFault_Handler(void);
  7753. void MemManage_Handler(void);
  7754. void BusFault_Handler(void);
  7755. void UsageFault_Handler(void);
  7756. void SVC_Handler(void);
  7757. void DebugMon_Handler(void);
  7758. void PendSV_Handler(void);
  7759. void SysTick_Handler(void);
  7760. #endif /* __STM32F10x_IT_H */
  7761. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  7762. /**
  7763. ******************************************************************************
  7764. * @file SPI/SPI_MSD/stm32f0xx_it.h
  7765. * @author MCD Application Team
  7766. * @version V1.0.0
  7767. * @date 18-May-2012
  7768. * @brief This file contains the headers of the interrupt handlers.
  7769. ******************************************************************************
  7770. * @attention
  7771. *
  7772. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  7773. *
  7774. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  7775. * You may not use this file except in compliance with the License.
  7776. * You may obtain a copy of the License at:
  7777. *
  7778. * http://www.st.com/software_license_agreement_liberty_v2
  7779. *
  7780. * Unless required by applicable law or agreed to in writing, software
  7781. * distributed under the License is distributed on an "AS IS" BASIS,
  7782. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  7783. * See the License for the specific language governing permissions and
  7784. * limitations under the License.
  7785. *
  7786. ******************************************************************************
  7787. */
  7788. /* Define to prevent recursive inclusion -------------------------------------*/
  7789. #ifndef __STM32F0XX_IT_H
  7790. #define __STM32F0XX_IT_H
  7791. #ifdef __cplusplus
  7792. extern "C" {
  7793. #endif
  7794. /* Includes ------------------------------------------------------------------*/
  7795. #include "stm32f0xx.h"
  7796. /* Exported types ------------------------------------------------------------*/
  7797. /* Exported constants --------------------------------------------------------*/
  7798. /* Exported macro ------------------------------------------------------------*/
  7799. /* Exported functions ------------------------------------------------------- */
  7800. void NMI_Handler(void);
  7801. void HardFault_Handler(void);
  7802. void SVC_Handler(void);
  7803. void PendSV_Handler(void);
  7804. void SysTick_Handler(void);
  7805. #ifdef __cplusplus
  7806. }
  7807. #endif
  7808. #endif /* __STM32F0XX_IT_H */
  7809. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  7810. /**
  7811. ******************************************************************************
  7812. * @file SPI/SPI_MSD/stm32f0xx_conf.h
  7813. * @author MCD Application Team
  7814. * @version V1.0.0
  7815. * @date 18-May-2012
  7816. * @brief Library configuration file.
  7817. ******************************************************************************
  7818. * @attention
  7819. *
  7820. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  7821. *
  7822. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  7823. * You may not use this file except in compliance with the License.
  7824. * You may obtain a copy of the License at:
  7825. *
  7826. * http://www.st.com/software_license_agreement_liberty_v2
  7827. *
  7828. * Unless required by applicable law or agreed to in writing, software
  7829. * distributed under the License is distributed on an "AS IS" BASIS,
  7830. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  7831. * See the License for the specific language governing permissions and
  7832. * limitations under the License.
  7833. *
  7834. ******************************************************************************
  7835. */
  7836. /* Define to prevent recursive inclusion -------------------------------------*/
  7837. #ifndef __STM32F0XX_CONF_H
  7838. #define __STM32F0XX_CONF_H
  7839. /* Includes ------------------------------------------------------------------*/
  7840. /* Comment the line below to disable peripheral header file inclusion */
  7841. #include "stm32f0xx_adc.h"
  7842. #include "stm32f0xx_cec.h"
  7843. #include "stm32f0xx_crc.h"
  7844. #include "stm32f0xx_comp.h"
  7845. #include "stm32f0xx_dac.h"
  7846. #include "stm32f0xx_dbgmcu.h"
  7847. #include "stm32f0xx_dma.h"
  7848. #include "stm32f0xx_exti.h"
  7849. #include "stm32f0xx_flash.h"
  7850. #include "stm32f0xx_gpio.h"
  7851. #include "stm32f0xx_syscfg.h"
  7852. #include "stm32f0xx_i2c.h"
  7853. #include "stm32f0xx_iwdg.h"
  7854. #include "stm32f0xx_pwr.h"
  7855. #include "stm32f0xx_rcc.h"
  7856. #include "stm32f0xx_rtc.h"
  7857. #include "stm32f0xx_spi.h"
  7858. #include "stm32f0xx_tim.h"
  7859. #include "stm32f0xx_usart.h"
  7860. #include "stm32f0xx_wwdg.h"
  7861. #include "stm32f0xx_misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
  7862. /* Exported types ------------------------------------------------------------*/
  7863. /* Exported constants --------------------------------------------------------*/
  7864. /* Uncomment the line below to expanse the "assert_param" macro in the
  7865. Standard Peripheral Library drivers code */
  7866. /* #define USE_FULL_ASSERT 1 */
  7867. /* Exported macro ------------------------------------------------------------*/
  7868. #ifdef USE_FULL_ASSERT
  7869. /**
  7870. * @brief The assert_param macro is used for function's parameters check.
  7871. * @param expr: If expr is false, it calls assert_failed function which reports
  7872. * the name of the source file and the source line number of the call
  7873. * that failed. If expr is true, it returns no value.
  7874. * @retval None
  7875. */
  7876. #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
  7877. /* Exported functions ------------------------------------------------------- */
  7878. void assert_failed(uint8_t* file, uint32_t line);
  7879. #else
  7880. #define assert_param(expr) ((void)0)
  7881. #endif /* USE_FULL_ASSERT */
  7882. #endif /* __STM32F0XX_CONF_H */
  7883. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  7884. /**
  7885. ******************************************************************************
  7886. * @file SPI/SPI_FLASH/stm32f10x_it.c
  7887. * @author MCD Application Team
  7888. * @version V3.5.0
  7889. * @date 08-April-2011
  7890. * @brief Main Interrupt Service Routines.
  7891. * This file provides template for all exceptions handler and peripherals
  7892. * interrupt service routine.
  7893. ******************************************************************************
  7894. * @attention
  7895. *
  7896. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  7897. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  7898. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  7899. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  7900. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  7901. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  7902. *
  7903. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  7904. ******************************************************************************
  7905. */
  7906. /* Includes ------------------------------------------------------------------*/
  7907. #include "stm32f10x_it.h"
  7908. /** @addtogroup STM32F10x_StdPeriph_Examples
  7909. * @{
  7910. */
  7911. /** @addtogroup SPI_FLASH
  7912. * @{
  7913. */
  7914. /* Private typedef -----------------------------------------------------------*/
  7915. /* Private define ------------------------------------------------------------*/
  7916. /* Private macro -------------------------------------------------------------*/
  7917. /* Private variables ---------------------------------------------------------*/
  7918. /* Private function prototypes -----------------------------------------------*/
  7919. /* Private functions ---------------------------------------------------------*/
  7920. /******************************************************************************/
  7921. /* Cortex-M3 Processor Exceptions Handlers */
  7922. /******************************************************************************/
  7923. /**
  7924. * @brief This function handles NMI exception.
  7925. * @param None
  7926. * @retval None
  7927. */
  7928. void NMI_Handler(void)
  7929. {
  7930. }
  7931. /**
  7932. * @brief This function handles Hard Fault exception.
  7933. * @param None
  7934. * @retval None
  7935. */
  7936. void HardFault_Handler(void)
  7937. {
  7938. /* Go to infinite loop when Hard Fault exception occurs */
  7939. while (1)
  7940. {}
  7941. }
  7942. /**
  7943. * @brief This function handles Memory Manage exception.
  7944. * @param None
  7945. * @retval None
  7946. */
  7947. void MemManage_Handler(void)
  7948. {
  7949. /* Go to infinite loop when Memory Manage exception occurs */
  7950. while (1)
  7951. {}
  7952. }
  7953. /**
  7954. * @brief This function handles Bus Fault exception.
  7955. * @param None
  7956. * @retval None
  7957. */
  7958. void BusFault_Handler(void)
  7959. {
  7960. /* Go to infinite loop when Bus Fault exception occurs */
  7961. while (1)
  7962. {}
  7963. }
  7964. /**
  7965. * @brief This function handles Usage Fault exception.
  7966. * @param None
  7967. * @retval None
  7968. */
  7969. void UsageFault_Handler(void)
  7970. {
  7971. /* Go to infinite loop when Usage Fault exception occurs */
  7972. while (1)
  7973. {}
  7974. }
  7975. /**
  7976. * @brief This function handles Debug Monitor exception.
  7977. * @param None
  7978. * @retval None
  7979. */
  7980. void DebugMon_Handler(void)
  7981. {}
  7982. /**
  7983. * @brief This function handles SVCall exception.
  7984. * @param None
  7985. * @retval None
  7986. */
  7987. void SVC_Handler(void)
  7988. {}
  7989. /**
  7990. * @brief This function handles PendSV_Handler exception.
  7991. * @param None
  7992. * @retval None
  7993. */
  7994. void PendSV_Handler(void)
  7995. {}
  7996. /**
  7997. * @brief This function handles SysTick Handler.
  7998. * @param None
  7999. * @retval None
  8000. */
  8001. void SysTick_Handler(void)
  8002. {}
  8003. /******************************************************************************/
  8004. /* STM32F10x Peripherals Interrupt Handlers */
  8005. /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
  8006. /* available peripheral interrupt handler's name please refer to the startup */
  8007. /* file (startup_stm32f10x_xx.s). */
  8008. /******************************************************************************/
  8009. /**
  8010. * @brief This function handles PPP interrupt request.
  8011. * @param None
  8012. * @retval None
  8013. */
  8014. /*void PPP_IRQHandler(void)
  8015. {
  8016. }*/
  8017. /**
  8018. * @}
  8019. */
  8020. /**
  8021. * @}
  8022. */
  8023. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  8024. /**
  8025. ******************************************************************************
  8026. * @file stm32f10x_can.c
  8027. * @author MCD Application Team
  8028. * @version V3.5.0
  8029. * @date 11-March-2011
  8030. * @brief This file provides all the CAN firmware functions.
  8031. ******************************************************************************
  8032. * @attention
  8033. *
  8034. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  8035. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  8036. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  8037. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  8038. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  8039. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  8040. *
  8041. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  8042. ******************************************************************************
  8043. */
  8044. /* Includes ------------------------------------------------------------------*/
  8045. #include "stm32f10x_can.h"
  8046. #include "stm32f10x_rcc.h"
  8047. /** @addtogroup STM32F10x_StdPeriph_Driver
  8048. * @{
  8049. */
  8050. /** @defgroup CAN
  8051. * @brief CAN driver modules
  8052. * @{
  8053. */
  8054. /** @defgroup CAN_Private_TypesDefinitions
  8055. * @{
  8056. */
  8057. /**
  8058. * @}
  8059. */
  8060. /** @defgroup CAN_Private_Defines
  8061. * @{
  8062. */
  8063. /* CAN Master Control Register bits */
  8064. #define MCR_DBF ((uint32_t)0x00010000) /* software master reset */
  8065. /* CAN Mailbox Transmit Request */
  8066. #define TMIDxR_TXRQ ((uint32_t)0x00000001) /* Transmit mailbox request */
  8067. /* CAN Filter Master Register bits */
  8068. #define FMR_FINIT ((uint32_t)0x00000001) /* Filter init mode */
  8069. /* Time out for INAK bit */
  8070. #define INAK_TIMEOUT ((uint32_t)0x0000FFFF)
  8071. /* Time out for SLAK bit */
  8072. #define SLAK_TIMEOUT ((uint32_t)0x0000FFFF)
  8073. /* Flags in TSR register */
  8074. #define CAN_FLAGS_TSR ((uint32_t)0x08000000)
  8075. /* Flags in RF1R register */
  8076. #define CAN_FLAGS_RF1R ((uint32_t)0x04000000)
  8077. /* Flags in RF0R register */
  8078. #define CAN_FLAGS_RF0R ((uint32_t)0x02000000)
  8079. /* Flags in MSR register */
  8080. #define CAN_FLAGS_MSR ((uint32_t)0x01000000)
  8081. /* Flags in ESR register */
  8082. #define CAN_FLAGS_ESR ((uint32_t)0x00F00000)
  8083. /* Mailboxes definition */
  8084. #define CAN_TXMAILBOX_0 ((uint8_t)0x00)
  8085. #define CAN_TXMAILBOX_1 ((uint8_t)0x01)
  8086. #define CAN_TXMAILBOX_2 ((uint8_t)0x02)
  8087. #define CAN_MODE_MASK ((uint32_t) 0x00000003)
  8088. /**
  8089. * @}
  8090. */
  8091. /** @defgroup CAN_Private_Macros
  8092. * @{
  8093. */
  8094. /**
  8095. * @}
  8096. */
  8097. /** @defgroup CAN_Private_Variables
  8098. * @{
  8099. */
  8100. /**
  8101. * @}
  8102. */
  8103. /** @defgroup CAN_Private_FunctionPrototypes
  8104. * @{
  8105. */
  8106. static ITStatus CheckITStatus(uint32_t CAN_Reg, uint32_t It_Bit);
  8107. /**
  8108. * @}
  8109. */
  8110. /** @defgroup CAN_Private_Functions
  8111. * @{
  8112. */
  8113. /**
  8114. * @brief Deinitializes the CAN peripheral registers to their default reset values.
  8115. * @param CANx: where x can be 1 or 2 to select the CAN peripheral.
  8116. * @retval None.
  8117. */
  8118. void CAN_DeInit(CAN_TypeDef* CANx)
  8119. {
  8120. /* Check the parameters */
  8121. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8122. if (CANx == CAN1)
  8123. {
  8124. /* Enable CAN1 reset state */
  8125. RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN1, ENABLE);
  8126. /* Release CAN1 from reset state */
  8127. RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN1, DISABLE);
  8128. }
  8129. else
  8130. {
  8131. /* Enable CAN2 reset state */
  8132. RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN2, ENABLE);
  8133. /* Release CAN2 from reset state */
  8134. RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN2, DISABLE);
  8135. }
  8136. }
  8137. /**
  8138. * @brief Initializes the CAN peripheral according to the specified
  8139. * parameters in the CAN_InitStruct.
  8140. * @param CANx: where x can be 1 or 2 to to select the CAN
  8141. * peripheral.
  8142. * @param CAN_InitStruct: pointer to a CAN_InitTypeDef structure that
  8143. * contains the configuration information for the
  8144. * CAN peripheral.
  8145. * @retval Constant indicates initialization succeed which will be
  8146. * CAN_InitStatus_Failed or CAN_InitStatus_Success.
  8147. */
  8148. uint8_t CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct)
  8149. {
  8150. uint8_t InitStatus = CAN_InitStatus_Failed;
  8151. uint32_t wait_ack = 0x00000000;
  8152. /* Check the parameters */
  8153. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8154. assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TTCM));
  8155. assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_ABOM));
  8156. assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_AWUM));
  8157. assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_NART));
  8158. assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_RFLM));
  8159. assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TXFP));
  8160. assert_param(IS_CAN_MODE(CAN_InitStruct->CAN_Mode));
  8161. assert_param(IS_CAN_SJW(CAN_InitStruct->CAN_SJW));
  8162. assert_param(IS_CAN_BS1(CAN_InitStruct->CAN_BS1));
  8163. assert_param(IS_CAN_BS2(CAN_InitStruct->CAN_BS2));
  8164. assert_param(IS_CAN_PRESCALER(CAN_InitStruct->CAN_Prescaler));
  8165. /* Exit from sleep mode */
  8166. CANx->MCR &= (~(uint32_t)CAN_MCR_SLEEP);
  8167. /* Request initialisation */
  8168. CANx->MCR |= CAN_MCR_INRQ ;
  8169. /* Wait the acknowledge */
  8170. while (((CANx->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) && (wait_ack != INAK_TIMEOUT))
  8171. {
  8172. wait_ack++;
  8173. }
  8174. /* Check acknowledge */
  8175. if ((CANx->MSR & CAN_MSR_INAK) != CAN_MSR_INAK)
  8176. {
  8177. InitStatus = CAN_InitStatus_Failed;
  8178. }
  8179. else
  8180. {
  8181. /* Set the time triggered communication mode */
  8182. if (CAN_InitStruct->CAN_TTCM == ENABLE)
  8183. {
  8184. CANx->MCR |= CAN_MCR_TTCM;
  8185. }
  8186. else
  8187. {
  8188. CANx->MCR &= ~(uint32_t)CAN_MCR_TTCM;
  8189. }
  8190. /* Set the automatic bus-off management */
  8191. if (CAN_InitStruct->CAN_ABOM == ENABLE)
  8192. {
  8193. CANx->MCR |= CAN_MCR_ABOM;
  8194. }
  8195. else
  8196. {
  8197. CANx->MCR &= ~(uint32_t)CAN_MCR_ABOM;
  8198. }
  8199. /* Set the automatic wake-up mode */
  8200. if (CAN_InitStruct->CAN_AWUM == ENABLE)
  8201. {
  8202. CANx->MCR |= CAN_MCR_AWUM;
  8203. }
  8204. else
  8205. {
  8206. CANx->MCR &= ~(uint32_t)CAN_MCR_AWUM;
  8207. }
  8208. /* Set the no automatic retransmission */
  8209. if (CAN_InitStruct->CAN_NART == ENABLE)
  8210. {
  8211. CANx->MCR |= CAN_MCR_NART;
  8212. }
  8213. else
  8214. {
  8215. CANx->MCR &= ~(uint32_t)CAN_MCR_NART;
  8216. }
  8217. /* Set the receive FIFO locked mode */
  8218. if (CAN_InitStruct->CAN_RFLM == ENABLE)
  8219. {
  8220. CANx->MCR |= CAN_MCR_RFLM;
  8221. }
  8222. else
  8223. {
  8224. CANx->MCR &= ~(uint32_t)CAN_MCR_RFLM;
  8225. }
  8226. /* Set the transmit FIFO priority */
  8227. if (CAN_InitStruct->CAN_TXFP == ENABLE)
  8228. {
  8229. CANx->MCR |= CAN_MCR_TXFP;
  8230. }
  8231. else
  8232. {
  8233. CANx->MCR &= ~(uint32_t)CAN_MCR_TXFP;
  8234. }
  8235. /* Set the bit timing register */
  8236. CANx->BTR = (uint32_t)((uint32_t)CAN_InitStruct->CAN_Mode << 30) | \
  8237. ((uint32_t)CAN_InitStruct->CAN_SJW << 24) | \
  8238. ((uint32_t)CAN_InitStruct->CAN_BS1 << 16) | \
  8239. ((uint32_t)CAN_InitStruct->CAN_BS2 << 20) | \
  8240. ((uint32_t)CAN_InitStruct->CAN_Prescaler - 1);
  8241. /* Request leave initialisation */
  8242. CANx->MCR &= ~(uint32_t)CAN_MCR_INRQ;
  8243. /* Wait the acknowledge */
  8244. wait_ack = 0;
  8245. while (((CANx->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) && (wait_ack != INAK_TIMEOUT))
  8246. {
  8247. wait_ack++;
  8248. }
  8249. /* ...and check acknowledged */
  8250. if ((CANx->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)
  8251. {
  8252. InitStatus = CAN_InitStatus_Failed;
  8253. }
  8254. else
  8255. {
  8256. InitStatus = CAN_InitStatus_Success ;
  8257. }
  8258. }
  8259. /* At this step, return the status of initialization */
  8260. return InitStatus;
  8261. }
  8262. /**
  8263. * @brief Initializes the CAN peripheral according to the specified
  8264. * parameters in the CAN_FilterInitStruct.
  8265. * @param CAN_FilterInitStruct: pointer to a CAN_FilterInitTypeDef
  8266. * structure that contains the configuration
  8267. * information.
  8268. * @retval None.
  8269. */
  8270. void CAN_FilterInit(CAN_FilterInitTypeDef* CAN_FilterInitStruct)
  8271. {
  8272. uint32_t filter_number_bit_pos = 0;
  8273. /* Check the parameters */
  8274. assert_param(IS_CAN_FILTER_NUMBER(CAN_FilterInitStruct->CAN_FilterNumber));
  8275. assert_param(IS_CAN_FILTER_MODE(CAN_FilterInitStruct->CAN_FilterMode));
  8276. assert_param(IS_CAN_FILTER_SCALE(CAN_FilterInitStruct->CAN_FilterScale));
  8277. assert_param(IS_CAN_FILTER_FIFO(CAN_FilterInitStruct->CAN_FilterFIFOAssignment));
  8278. assert_param(IS_FUNCTIONAL_STATE(CAN_FilterInitStruct->CAN_FilterActivation));
  8279. filter_number_bit_pos = ((uint32_t)1) << CAN_FilterInitStruct->CAN_FilterNumber;
  8280. /* Initialisation mode for the filter */
  8281. CAN1->FMR |= FMR_FINIT;
  8282. /* Filter Deactivation */
  8283. CAN1->FA1R &= ~(uint32_t)filter_number_bit_pos;
  8284. /* Filter Scale */
  8285. if (CAN_FilterInitStruct->CAN_FilterScale == CAN_FilterScale_16bit)
  8286. {
  8287. /* 16-bit scale for the filter */
  8288. CAN1->FS1R &= ~(uint32_t)filter_number_bit_pos;
  8289. /* First 16-bit identifier and First 16-bit mask */
  8290. /* Or First 16-bit identifier and Second 16-bit identifier */
  8291. CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR1 =
  8292. ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdLow) << 16) |
  8293. (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdLow);
  8294. /* Second 16-bit identifier and Second 16-bit mask */
  8295. /* Or Third 16-bit identifier and Fourth 16-bit identifier */
  8296. CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR2 =
  8297. ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdHigh) << 16) |
  8298. (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdHigh);
  8299. }
  8300. if (CAN_FilterInitStruct->CAN_FilterScale == CAN_FilterScale_32bit)
  8301. {
  8302. /* 32-bit scale for the filter */
  8303. CAN1->FS1R |= filter_number_bit_pos;
  8304. /* 32-bit identifier or First 32-bit identifier */
  8305. CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR1 =
  8306. ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdHigh) << 16) |
  8307. (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdLow);
  8308. /* 32-bit mask or Second 32-bit identifier */
  8309. CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR2 =
  8310. ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdHigh) << 16) |
  8311. (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdLow);
  8312. }
  8313. /* Filter Mode */
  8314. if (CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdMask)
  8315. {
  8316. /*Id/Mask mode for the filter*/
  8317. CAN1->FM1R &= ~(uint32_t)filter_number_bit_pos;
  8318. }
  8319. else /* CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdList */
  8320. {
  8321. /*Identifier list mode for the filter*/
  8322. CAN1->FM1R |= (uint32_t)filter_number_bit_pos;
  8323. }
  8324. /* Filter FIFO assignment */
  8325. if (CAN_FilterInitStruct->CAN_FilterFIFOAssignment == CAN_Filter_FIFO0)
  8326. {
  8327. /* FIFO 0 assignation for the filter */
  8328. CAN1->FFA1R &= ~(uint32_t)filter_number_bit_pos;
  8329. }
  8330. if (CAN_FilterInitStruct->CAN_FilterFIFOAssignment == CAN_Filter_FIFO1)
  8331. {
  8332. /* FIFO 1 assignation for the filter */
  8333. CAN1->FFA1R |= (uint32_t)filter_number_bit_pos;
  8334. }
  8335. /* Filter activation */
  8336. if (CAN_FilterInitStruct->CAN_FilterActivation == ENABLE)
  8337. {
  8338. CAN1->FA1R |= filter_number_bit_pos;
  8339. }
  8340. /* Leave the initialisation mode for the filter */
  8341. CAN1->FMR &= ~FMR_FINIT;
  8342. }
  8343. /**
  8344. * @brief Fills each CAN_InitStruct member with its default value.
  8345. * @param CAN_InitStruct: pointer to a CAN_InitTypeDef structure which
  8346. * will be initialized.
  8347. * @retval None.
  8348. */
  8349. void CAN_StructInit(CAN_InitTypeDef* CAN_InitStruct)
  8350. {
  8351. /* Reset CAN init structure parameters values */
  8352. /* Initialize the time triggered communication mode */
  8353. CAN_InitStruct->CAN_TTCM = DISABLE;
  8354. /* Initialize the automatic bus-off management */
  8355. CAN_InitStruct->CAN_ABOM = DISABLE;
  8356. /* Initialize the automatic wake-up mode */
  8357. CAN_InitStruct->CAN_AWUM = DISABLE;
  8358. /* Initialize the no automatic retransmission */
  8359. CAN_InitStruct->CAN_NART = DISABLE;
  8360. /* Initialize the receive FIFO locked mode */
  8361. CAN_InitStruct->CAN_RFLM = DISABLE;
  8362. /* Initialize the transmit FIFO priority */
  8363. CAN_InitStruct->CAN_TXFP = DISABLE;
  8364. /* Initialize the CAN_Mode member */
  8365. CAN_InitStruct->CAN_Mode = CAN_Mode_Normal;
  8366. /* Initialize the CAN_SJW member */
  8367. CAN_InitStruct->CAN_SJW = CAN_SJW_1tq;
  8368. /* Initialize the CAN_BS1 member */
  8369. CAN_InitStruct->CAN_BS1 = CAN_BS1_4tq;
  8370. /* Initialize the CAN_BS2 member */
  8371. CAN_InitStruct->CAN_BS2 = CAN_BS2_3tq;
  8372. /* Initialize the CAN_Prescaler member */
  8373. CAN_InitStruct->CAN_Prescaler = 1;
  8374. }
  8375. /**
  8376. * @brief Select the start bank filter for slave CAN.
  8377. * @note This function applies only to STM32 Connectivity line devices.
  8378. * @param CAN_BankNumber: Select the start slave bank filter from 1..27.
  8379. * @retval None.
  8380. */
  8381. void CAN_SlaveStartBank(uint8_t CAN_BankNumber)
  8382. {
  8383. /* Check the parameters */
  8384. assert_param(IS_CAN_BANKNUMBER(CAN_BankNumber));
  8385. /* Enter Initialisation mode for the filter */
  8386. CAN1->FMR |= FMR_FINIT;
  8387. /* Select the start slave bank */
  8388. CAN1->FMR &= (uint32_t)0xFFFFC0F1 ;
  8389. CAN1->FMR |= (uint32_t)(CAN_BankNumber)<<8;
  8390. /* Leave Initialisation mode for the filter */
  8391. CAN1->FMR &= ~FMR_FINIT;
  8392. }
  8393. /**
  8394. * @brief Enables or disables the DBG Freeze for CAN.
  8395. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8396. * @param NewState: new state of the CAN peripheral. This parameter can
  8397. * be: ENABLE or DISABLE.
  8398. * @retval None.
  8399. */
  8400. void CAN_DBGFreeze(CAN_TypeDef* CANx, FunctionalState NewState)
  8401. {
  8402. /* Check the parameters */
  8403. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8404. assert_param(IS_FUNCTIONAL_STATE(NewState));
  8405. if (NewState != DISABLE)
  8406. {
  8407. /* Enable Debug Freeze */
  8408. CANx->MCR |= MCR_DBF;
  8409. }
  8410. else
  8411. {
  8412. /* Disable Debug Freeze */
  8413. CANx->MCR &= ~MCR_DBF;
  8414. }
  8415. }
  8416. /**
  8417. * @brief Enables or disabes the CAN Time TriggerOperation communication mode.
  8418. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8419. * @param NewState : Mode new state , can be one of @ref FunctionalState.
  8420. * @note when enabled, Time stamp (TIME[15:0]) value is sent in the last
  8421. * two data bytes of the 8-byte message: TIME[7:0] in data byte 6
  8422. * and TIME[15:8] in data byte 7
  8423. * @note DLC must be programmed as 8 in order Time Stamp (2 bytes) to be
  8424. * sent over the CAN bus.
  8425. * @retval None
  8426. */
  8427. void CAN_TTComModeCmd(CAN_TypeDef* CANx, FunctionalState NewState)
  8428. {
  8429. /* Check the parameters */
  8430. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8431. assert_param(IS_FUNCTIONAL_STATE(NewState));
  8432. if (NewState != DISABLE)
  8433. {
  8434. /* Enable the TTCM mode */
  8435. CANx->MCR |= CAN_MCR_TTCM;
  8436. /* Set TGT bits */
  8437. CANx->sTxMailBox[0].TDTR |= ((uint32_t)CAN_TDT0R_TGT);
  8438. CANx->sTxMailBox[1].TDTR |= ((uint32_t)CAN_TDT1R_TGT);
  8439. CANx->sTxMailBox[2].TDTR |= ((uint32_t)CAN_TDT2R_TGT);
  8440. }
  8441. else
  8442. {
  8443. /* Disable the TTCM mode */
  8444. CANx->MCR &= (uint32_t)(~(uint32_t)CAN_MCR_TTCM);
  8445. /* Reset TGT bits */
  8446. CANx->sTxMailBox[0].TDTR &= ((uint32_t)~CAN_TDT0R_TGT);
  8447. CANx->sTxMailBox[1].TDTR &= ((uint32_t)~CAN_TDT1R_TGT);
  8448. CANx->sTxMailBox[2].TDTR &= ((uint32_t)~CAN_TDT2R_TGT);
  8449. }
  8450. }
  8451. /**
  8452. * @brief Initiates the transmission of a message.
  8453. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8454. * @param TxMessage: pointer to a structure which contains CAN Id, CAN
  8455. * DLC and CAN data.
  8456. * @retval The number of the mailbox that is used for transmission
  8457. * or CAN_TxStatus_NoMailBox if there is no empty mailbox.
  8458. */
  8459. uint8_t CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage)
  8460. {
  8461. uint8_t transmit_mailbox = 0;
  8462. /* Check the parameters */
  8463. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8464. assert_param(IS_CAN_IDTYPE(TxMessage->IDE));
  8465. assert_param(IS_CAN_RTR(TxMessage->RTR));
  8466. assert_param(IS_CAN_DLC(TxMessage->DLC));
  8467. /* Select one empty transmit mailbox */
  8468. if ((CANx->TSR&CAN_TSR_TME0) == CAN_TSR_TME0)
  8469. {
  8470. transmit_mailbox = 0;
  8471. }
  8472. else if ((CANx->TSR&CAN_TSR_TME1) == CAN_TSR_TME1)
  8473. {
  8474. transmit_mailbox = 1;
  8475. }
  8476. else if ((CANx->TSR&CAN_TSR_TME2) == CAN_TSR_TME2)
  8477. {
  8478. transmit_mailbox = 2;
  8479. }
  8480. else
  8481. {
  8482. transmit_mailbox = CAN_TxStatus_NoMailBox;
  8483. }
  8484. if (transmit_mailbox != CAN_TxStatus_NoMailBox)
  8485. {
  8486. /* Set up the Id */
  8487. CANx->sTxMailBox[transmit_mailbox].TIR &= TMIDxR_TXRQ;
  8488. if (TxMessage->IDE == CAN_Id_Standard)
  8489. {
  8490. assert_param(IS_CAN_STDID(TxMessage->StdId));
  8491. CANx->sTxMailBox[transmit_mailbox].TIR |= ((TxMessage->StdId << 21) | \
  8492. TxMessage->RTR);
  8493. }
  8494. else
  8495. {
  8496. assert_param(IS_CAN_EXTID(TxMessage->ExtId));
  8497. CANx->sTxMailBox[transmit_mailbox].TIR |= ((TxMessage->ExtId << 3) | \
  8498. TxMessage->IDE | \
  8499. TxMessage->RTR);
  8500. }
  8501. /* Set up the DLC */
  8502. TxMessage->DLC &= (uint8_t)0x0000000F;
  8503. CANx->sTxMailBox[transmit_mailbox].TDTR &= (uint32_t)0xFFFFFFF0;
  8504. CANx->sTxMailBox[transmit_mailbox].TDTR |= TxMessage->DLC;
  8505. /* Set up the data field */
  8506. CANx->sTxMailBox[transmit_mailbox].TDLR = (((uint32_t)TxMessage->Data[3] << 24) |
  8507. ((uint32_t)TxMessage->Data[2] << 16) |
  8508. ((uint32_t)TxMessage->Data[1] << 8) |
  8509. ((uint32_t)TxMessage->Data[0]));
  8510. CANx->sTxMailBox[transmit_mailbox].TDHR = (((uint32_t)TxMessage->Data[7] << 24) |
  8511. ((uint32_t)TxMessage->Data[6] << 16) |
  8512. ((uint32_t)TxMessage->Data[5] << 8) |
  8513. ((uint32_t)TxMessage->Data[4]));
  8514. /* Request transmission */
  8515. CANx->sTxMailBox[transmit_mailbox].TIR |= TMIDxR_TXRQ;
  8516. }
  8517. return transmit_mailbox;
  8518. }
  8519. /**
  8520. * @brief Checks the transmission of a message.
  8521. * @param CANx: where x can be 1 or 2 to to select the
  8522. * CAN peripheral.
  8523. * @param TransmitMailbox: the number of the mailbox that is used for
  8524. * transmission.
  8525. * @retval CAN_TxStatus_Ok if the CAN driver transmits the message, CAN_TxStatus_Failed
  8526. * in an other case.
  8527. */
  8528. uint8_t CAN_TransmitStatus(CAN_TypeDef* CANx, uint8_t TransmitMailbox)
  8529. {
  8530. uint32_t state = 0;
  8531. /* Check the parameters */
  8532. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8533. assert_param(IS_CAN_TRANSMITMAILBOX(TransmitMailbox));
  8534. switch (TransmitMailbox)
  8535. {
  8536. case (CAN_TXMAILBOX_0):
  8537. state = CANx->TSR & (CAN_TSR_RQCP0 | CAN_TSR_TXOK0 | CAN_TSR_TME0);
  8538. break;
  8539. case (CAN_TXMAILBOX_1):
  8540. state = CANx->TSR & (CAN_TSR_RQCP1 | CAN_TSR_TXOK1 | CAN_TSR_TME1);
  8541. break;
  8542. case (CAN_TXMAILBOX_2):
  8543. state = CANx->TSR & (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2);
  8544. break;
  8545. default:
  8546. state = CAN_TxStatus_Failed;
  8547. break;
  8548. }
  8549. switch (state)
  8550. {
  8551. /* transmit pending */
  8552. case (0x0): state = CAN_TxStatus_Pending;
  8553. break;
  8554. /* transmit failed */
  8555. case (CAN_TSR_RQCP0 | CAN_TSR_TME0): state = CAN_TxStatus_Failed;
  8556. break;
  8557. case (CAN_TSR_RQCP1 | CAN_TSR_TME1): state = CAN_TxStatus_Failed;
  8558. break;
  8559. case (CAN_TSR_RQCP2 | CAN_TSR_TME2): state = CAN_TxStatus_Failed;
  8560. break;
  8561. /* transmit succeeded */
  8562. case (CAN_TSR_RQCP0 | CAN_TSR_TXOK0 | CAN_TSR_TME0):state = CAN_TxStatus_Ok;
  8563. break;
  8564. case (CAN_TSR_RQCP1 | CAN_TSR_TXOK1 | CAN_TSR_TME1):state = CAN_TxStatus_Ok;
  8565. break;
  8566. case (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2):state = CAN_TxStatus_Ok;
  8567. break;
  8568. default: state = CAN_TxStatus_Failed;
  8569. break;
  8570. }
  8571. return (uint8_t) state;
  8572. }
  8573. /**
  8574. * @brief Cancels a transmit request.
  8575. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8576. * @param Mailbox: Mailbox number.
  8577. * @retval None.
  8578. */
  8579. void CAN_CancelTransmit(CAN_TypeDef* CANx, uint8_t Mailbox)
  8580. {
  8581. /* Check the parameters */
  8582. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8583. assert_param(IS_CAN_TRANSMITMAILBOX(Mailbox));
  8584. /* abort transmission */
  8585. switch (Mailbox)
  8586. {
  8587. case (CAN_TXMAILBOX_0): CANx->TSR |= CAN_TSR_ABRQ0;
  8588. break;
  8589. case (CAN_TXMAILBOX_1): CANx->TSR |= CAN_TSR_ABRQ1;
  8590. break;
  8591. case (CAN_TXMAILBOX_2): CANx->TSR |= CAN_TSR_ABRQ2;
  8592. break;
  8593. default:
  8594. break;
  8595. }
  8596. }
  8597. /**
  8598. * @brief Receives a message.
  8599. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8600. * @param FIFONumber: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
  8601. * @param RxMessage: pointer to a structure receive message which contains
  8602. * CAN Id, CAN DLC, CAN datas and FMI number.
  8603. * @retval None.
  8604. */
  8605. void CAN_Receive(CAN_TypeDef* CANx, uint8_t FIFONumber, CanRxMsg* RxMessage)
  8606. {
  8607. /* Check the parameters */
  8608. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8609. assert_param(IS_CAN_FIFO(FIFONumber));
  8610. /* Get the Id */
  8611. RxMessage->IDE = (uint8_t)0x04 & CANx->sFIFOMailBox[FIFONumber].RIR;
  8612. if (RxMessage->IDE == CAN_Id_Standard)
  8613. {
  8614. RxMessage->StdId = (uint32_t)0x000007FF & (CANx->sFIFOMailBox[FIFONumber].RIR >> 21);
  8615. }
  8616. else
  8617. {
  8618. RxMessage->ExtId = (uint32_t)0x1FFFFFFF & (CANx->sFIFOMailBox[FIFONumber].RIR >> 3);
  8619. }
  8620. RxMessage->RTR = (uint8_t)0x02 & CANx->sFIFOMailBox[FIFONumber].RIR;
  8621. /* Get the DLC */
  8622. RxMessage->DLC = (uint8_t)0x0F & CANx->sFIFOMailBox[FIFONumber].RDTR;
  8623. /* Get the FMI */
  8624. RxMessage->FMI = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDTR >> 8);
  8625. /* Get the data field */
  8626. RxMessage->Data[0] = (uint8_t)0xFF & CANx->sFIFOMailBox[FIFONumber].RDLR;
  8627. RxMessage->Data[1] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDLR >> 8);
  8628. RxMessage->Data[2] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDLR >> 16);
  8629. RxMessage->Data[3] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDLR >> 24);
  8630. RxMessage->Data[4] = (uint8_t)0xFF & CANx->sFIFOMailBox[FIFONumber].RDHR;
  8631. RxMessage->Data[5] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDHR >> 8);
  8632. RxMessage->Data[6] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDHR >> 16);
  8633. RxMessage->Data[7] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDHR >> 24);
  8634. /* Release the FIFO */
  8635. /* Release FIFO0 */
  8636. if (FIFONumber == CAN_FIFO0)
  8637. {
  8638. CANx->RF0R |= CAN_RF0R_RFOM0;
  8639. }
  8640. /* Release FIFO1 */
  8641. else /* FIFONumber == CAN_FIFO1 */
  8642. {
  8643. CANx->RF1R |= CAN_RF1R_RFOM1;
  8644. }
  8645. }
  8646. /**
  8647. * @brief Releases the specified FIFO.
  8648. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8649. * @param FIFONumber: FIFO to release, CAN_FIFO0 or CAN_FIFO1.
  8650. * @retval None.
  8651. */
  8652. void CAN_FIFORelease(CAN_TypeDef* CANx, uint8_t FIFONumber)
  8653. {
  8654. /* Check the parameters */
  8655. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8656. assert_param(IS_CAN_FIFO(FIFONumber));
  8657. /* Release FIFO0 */
  8658. if (FIFONumber == CAN_FIFO0)
  8659. {
  8660. CANx->RF0R |= CAN_RF0R_RFOM0;
  8661. }
  8662. /* Release FIFO1 */
  8663. else /* FIFONumber == CAN_FIFO1 */
  8664. {
  8665. CANx->RF1R |= CAN_RF1R_RFOM1;
  8666. }
  8667. }
  8668. /**
  8669. * @brief Returns the number of pending messages.
  8670. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8671. * @param FIFONumber: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
  8672. * @retval NbMessage : which is the number of pending message.
  8673. */
  8674. uint8_t CAN_MessagePending(CAN_TypeDef* CANx, uint8_t FIFONumber)
  8675. {
  8676. uint8_t message_pending=0;
  8677. /* Check the parameters */
  8678. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8679. assert_param(IS_CAN_FIFO(FIFONumber));
  8680. if (FIFONumber == CAN_FIFO0)
  8681. {
  8682. message_pending = (uint8_t)(CANx->RF0R&(uint32_t)0x03);
  8683. }
  8684. else if (FIFONumber == CAN_FIFO1)
  8685. {
  8686. message_pending = (uint8_t)(CANx->RF1R&(uint32_t)0x03);
  8687. }
  8688. else
  8689. {
  8690. message_pending = 0;
  8691. }
  8692. return message_pending;
  8693. }
  8694. /**
  8695. * @brief Select the CAN Operation mode.
  8696. * @param CAN_OperatingMode : CAN Operating Mode. This parameter can be one
  8697. * of @ref CAN_OperatingMode_TypeDef enumeration.
  8698. * @retval status of the requested mode which can be
  8699. * - CAN_ModeStatus_Failed CAN failed entering the specific mode
  8700. * - CAN_ModeStatus_Success CAN Succeed entering the specific mode
  8701. */
  8702. uint8_t CAN_OperatingModeRequest(CAN_TypeDef* CANx, uint8_t CAN_OperatingMode)
  8703. {
  8704. uint8_t status = CAN_ModeStatus_Failed;
  8705. /* Timeout for INAK or also for SLAK bits*/
  8706. uint32_t timeout = INAK_TIMEOUT;
  8707. /* Check the parameters */
  8708. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8709. assert_param(IS_CAN_OPERATING_MODE(CAN_OperatingMode));
  8710. if (CAN_OperatingMode == CAN_OperatingMode_Initialization)
  8711. {
  8712. /* Request initialisation */
  8713. CANx->MCR = (uint32_t)((CANx->MCR & (uint32_t)(~(uint32_t)CAN_MCR_SLEEP)) | CAN_MCR_INRQ);
  8714. /* Wait the acknowledge */
  8715. while (((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_INAK) && (timeout != 0))
  8716. {
  8717. timeout--;
  8718. }
  8719. if ((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_INAK)
  8720. {
  8721. status = CAN_ModeStatus_Failed;
  8722. }
  8723. else
  8724. {
  8725. status = CAN_ModeStatus_Success;
  8726. }
  8727. }
  8728. else if (CAN_OperatingMode == CAN_OperatingMode_Normal)
  8729. {
  8730. /* Request leave initialisation and sleep mode and enter Normal mode */
  8731. CANx->MCR &= (uint32_t)(~(CAN_MCR_SLEEP|CAN_MCR_INRQ));
  8732. /* Wait the acknowledge */
  8733. while (((CANx->MSR & CAN_MODE_MASK) != 0) && (timeout!=0))
  8734. {
  8735. timeout--;
  8736. }
  8737. if ((CANx->MSR & CAN_MODE_MASK) != 0)
  8738. {
  8739. status = CAN_ModeStatus_Failed;
  8740. }
  8741. else
  8742. {
  8743. status = CAN_ModeStatus_Success;
  8744. }
  8745. }
  8746. else if (CAN_OperatingMode == CAN_OperatingMode_Sleep)
  8747. {
  8748. /* Request Sleep mode */
  8749. CANx->MCR = (uint32_t)((CANx->MCR & (uint32_t)(~(uint32_t)CAN_MCR_INRQ)) | CAN_MCR_SLEEP);
  8750. /* Wait the acknowledge */
  8751. while (((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_SLAK) && (timeout!=0))
  8752. {
  8753. timeout--;
  8754. }
  8755. if ((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_SLAK)
  8756. {
  8757. status = CAN_ModeStatus_Failed;
  8758. }
  8759. else
  8760. {
  8761. status = CAN_ModeStatus_Success;
  8762. }
  8763. }
  8764. else
  8765. {
  8766. status = CAN_ModeStatus_Failed;
  8767. }
  8768. return (uint8_t) status;
  8769. }
  8770. /**
  8771. * @brief Enters the low power mode.
  8772. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8773. * @retval status: CAN_Sleep_Ok if sleep entered, CAN_Sleep_Failed in an
  8774. * other case.
  8775. */
  8776. uint8_t CAN_Sleep(CAN_TypeDef* CANx)
  8777. {
  8778. uint8_t sleepstatus = CAN_Sleep_Failed;
  8779. /* Check the parameters */
  8780. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8781. /* Request Sleep mode */
  8782. CANx->MCR = (((CANx->MCR) & (uint32_t)(~(uint32_t)CAN_MCR_INRQ)) | CAN_MCR_SLEEP);
  8783. /* Sleep mode status */
  8784. if ((CANx->MSR & (CAN_MSR_SLAK|CAN_MSR_INAK)) == CAN_MSR_SLAK)
  8785. {
  8786. /* Sleep mode not entered */
  8787. sleepstatus = CAN_Sleep_Ok;
  8788. }
  8789. /* return sleep mode status */
  8790. return (uint8_t)sleepstatus;
  8791. }
  8792. /**
  8793. * @brief Wakes the CAN up.
  8794. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8795. * @retval status: CAN_WakeUp_Ok if sleep mode left, CAN_WakeUp_Failed in an
  8796. * other case.
  8797. */
  8798. uint8_t CAN_WakeUp(CAN_TypeDef* CANx)
  8799. {
  8800. uint32_t wait_slak = SLAK_TIMEOUT;
  8801. uint8_t wakeupstatus = CAN_WakeUp_Failed;
  8802. /* Check the parameters */
  8803. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8804. /* Wake up request */
  8805. CANx->MCR &= ~(uint32_t)CAN_MCR_SLEEP;
  8806. /* Sleep mode status */
  8807. while(((CANx->MSR & CAN_MSR_SLAK) == CAN_MSR_SLAK)&&(wait_slak!=0x00))
  8808. {
  8809. wait_slak--;
  8810. }
  8811. if((CANx->MSR & CAN_MSR_SLAK) != CAN_MSR_SLAK)
  8812. {
  8813. /* wake up done : Sleep mode exited */
  8814. wakeupstatus = CAN_WakeUp_Ok;
  8815. }
  8816. /* return wakeup status */
  8817. return (uint8_t)wakeupstatus;
  8818. }
  8819. /**
  8820. * @brief Returns the CANx's last error code (LEC).
  8821. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8822. * @retval CAN_ErrorCode: specifies the Error code :
  8823. * - CAN_ERRORCODE_NoErr No Error
  8824. * - CAN_ERRORCODE_StuffErr Stuff Error
  8825. * - CAN_ERRORCODE_FormErr Form Error
  8826. * - CAN_ERRORCODE_ACKErr Acknowledgment Error
  8827. * - CAN_ERRORCODE_BitRecessiveErr Bit Recessive Error
  8828. * - CAN_ERRORCODE_BitDominantErr Bit Dominant Error
  8829. * - CAN_ERRORCODE_CRCErr CRC Error
  8830. * - CAN_ERRORCODE_SoftwareSetErr Software Set Error
  8831. */
  8832. uint8_t CAN_GetLastErrorCode(CAN_TypeDef* CANx)
  8833. {
  8834. uint8_t errorcode=0;
  8835. /* Check the parameters */
  8836. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8837. /* Get the error code*/
  8838. errorcode = (((uint8_t)CANx->ESR) & (uint8_t)CAN_ESR_LEC);
  8839. /* Return the error code*/
  8840. return errorcode;
  8841. }
  8842. /**
  8843. * @brief Returns the CANx Receive Error Counter (REC).
  8844. * @note In case of an error during reception, this counter is incremented
  8845. * by 1 or by 8 depending on the error condition as defined by the CAN
  8846. * standard. After every successful reception, the counter is
  8847. * decremented by 1 or reset to 120 if its value was higher than 128.
  8848. * When the counter value exceeds 127, the CAN controller enters the
  8849. * error passive state.
  8850. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8851. * @retval CAN Receive Error Counter.
  8852. */
  8853. uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef* CANx)
  8854. {
  8855. uint8_t counter=0;
  8856. /* Check the parameters */
  8857. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8858. /* Get the Receive Error Counter*/
  8859. counter = (uint8_t)((CANx->ESR & CAN_ESR_REC)>> 24);
  8860. /* Return the Receive Error Counter*/
  8861. return counter;
  8862. }
  8863. /**
  8864. * @brief Returns the LSB of the 9-bit CANx Transmit Error Counter(TEC).
  8865. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8866. * @retval LSB of the 9-bit CAN Transmit Error Counter.
  8867. */
  8868. uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef* CANx)
  8869. {
  8870. uint8_t counter=0;
  8871. /* Check the parameters */
  8872. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8873. /* Get the LSB of the 9-bit CANx Transmit Error Counter(TEC) */
  8874. counter = (uint8_t)((CANx->ESR & CAN_ESR_TEC)>> 16);
  8875. /* Return the LSB of the 9-bit CANx Transmit Error Counter(TEC) */
  8876. return counter;
  8877. }
  8878. /**
  8879. * @brief Enables or disables the specified CANx interrupts.
  8880. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8881. * @param CAN_IT: specifies the CAN interrupt sources to be enabled or disabled.
  8882. * This parameter can be:
  8883. * - CAN_IT_TME,
  8884. * - CAN_IT_FMP0,
  8885. * - CAN_IT_FF0,
  8886. * - CAN_IT_FOV0,
  8887. * - CAN_IT_FMP1,
  8888. * - CAN_IT_FF1,
  8889. * - CAN_IT_FOV1,
  8890. * - CAN_IT_EWG,
  8891. * - CAN_IT_EPV,
  8892. * - CAN_IT_LEC,
  8893. * - CAN_IT_ERR,
  8894. * - CAN_IT_WKU or
  8895. * - CAN_IT_SLK.
  8896. * @param NewState: new state of the CAN interrupts.
  8897. * This parameter can be: ENABLE or DISABLE.
  8898. * @retval None.
  8899. */
  8900. void CAN_ITConfig(CAN_TypeDef* CANx, uint32_t CAN_IT, FunctionalState NewState)
  8901. {
  8902. /* Check the parameters */
  8903. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8904. assert_param(IS_CAN_IT(CAN_IT));
  8905. assert_param(IS_FUNCTIONAL_STATE(NewState));
  8906. if (NewState != DISABLE)
  8907. {
  8908. /* Enable the selected CANx interrupt */
  8909. CANx->IER |= CAN_IT;
  8910. }
  8911. else
  8912. {
  8913. /* Disable the selected CANx interrupt */
  8914. CANx->IER &= ~CAN_IT;
  8915. }
  8916. }
  8917. /**
  8918. * @brief Checks whether the specified CAN flag is set or not.
  8919. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  8920. * @param CAN_FLAG: specifies the flag to check.
  8921. * This parameter can be one of the following flags:
  8922. * - CAN_FLAG_EWG
  8923. * - CAN_FLAG_EPV
  8924. * - CAN_FLAG_BOF
  8925. * - CAN_FLAG_RQCP0
  8926. * - CAN_FLAG_RQCP1
  8927. * - CAN_FLAG_RQCP2
  8928. * - CAN_FLAG_FMP1
  8929. * - CAN_FLAG_FF1
  8930. * - CAN_FLAG_FOV1
  8931. * - CAN_FLAG_FMP0
  8932. * - CAN_FLAG_FF0
  8933. * - CAN_FLAG_FOV0
  8934. * - CAN_FLAG_WKU
  8935. * - CAN_FLAG_SLAK
  8936. * - CAN_FLAG_LEC
  8937. * @retval The new state of CAN_FLAG (SET or RESET).
  8938. */
  8939. FlagStatus CAN_GetFlagStatus(CAN_TypeDef* CANx, uint32_t CAN_FLAG)
  8940. {
  8941. FlagStatus bitstatus = RESET;
  8942. /* Check the parameters */
  8943. assert_param(IS_CAN_ALL_PERIPH(CANx));
  8944. assert_param(IS_CAN_GET_FLAG(CAN_FLAG));
  8945. if((CAN_FLAG & CAN_FLAGS_ESR) != (uint32_t)RESET)
  8946. {
  8947. /* Check the status of the specified CAN flag */
  8948. if ((CANx->ESR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
  8949. {
  8950. /* CAN_FLAG is set */
  8951. bitstatus = SET;
  8952. }
  8953. else
  8954. {
  8955. /* CAN_FLAG is reset */
  8956. bitstatus = RESET;
  8957. }
  8958. }
  8959. else if((CAN_FLAG & CAN_FLAGS_MSR) != (uint32_t)RESET)
  8960. {
  8961. /* Check the status of the specified CAN flag */
  8962. if ((CANx->MSR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
  8963. {
  8964. /* CAN_FLAG is set */
  8965. bitstatus = SET;
  8966. }
  8967. else
  8968. {
  8969. /* CAN_FLAG is reset */
  8970. bitstatus = RESET;
  8971. }
  8972. }
  8973. else if((CAN_FLAG & CAN_FLAGS_TSR) != (uint32_t)RESET)
  8974. {
  8975. /* Check the status of the specified CAN flag */
  8976. if ((CANx->TSR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
  8977. {
  8978. /* CAN_FLAG is set */
  8979. bitstatus = SET;
  8980. }
  8981. else
  8982. {
  8983. /* CAN_FLAG is reset */
  8984. bitstatus = RESET;
  8985. }
  8986. }
  8987. else if((CAN_FLAG & CAN_FLAGS_RF0R) != (uint32_t)RESET)
  8988. {
  8989. /* Check the status of the specified CAN flag */
  8990. if ((CANx->RF0R & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
  8991. {
  8992. /* CAN_FLAG is set */
  8993. bitstatus = SET;
  8994. }
  8995. else
  8996. {
  8997. /* CAN_FLAG is reset */
  8998. bitstatus = RESET;
  8999. }
  9000. }
  9001. else /* If(CAN_FLAG & CAN_FLAGS_RF1R != (uint32_t)RESET) */
  9002. {
  9003. /* Check the status of the specified CAN flag */
  9004. if ((uint32_t)(CANx->RF1R & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
  9005. {
  9006. /* CAN_FLAG is set */
  9007. bitstatus = SET;
  9008. }
  9009. else
  9010. {
  9011. /* CAN_FLAG is reset */
  9012. bitstatus = RESET;
  9013. }
  9014. }
  9015. /* Return the CAN_FLAG status */
  9016. return bitstatus;
  9017. }
  9018. /**
  9019. * @brief Clears the CAN's pending flags.
  9020. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  9021. * @param CAN_FLAG: specifies the flag to clear.
  9022. * This parameter can be one of the following flags:
  9023. * - CAN_FLAG_RQCP0
  9024. * - CAN_FLAG_RQCP1
  9025. * - CAN_FLAG_RQCP2
  9026. * - CAN_FLAG_FF1
  9027. * - CAN_FLAG_FOV1
  9028. * - CAN_FLAG_FF0
  9029. * - CAN_FLAG_FOV0
  9030. * - CAN_FLAG_WKU
  9031. * - CAN_FLAG_SLAK
  9032. * - CAN_FLAG_LEC
  9033. * @retval None.
  9034. */
  9035. void CAN_ClearFlag(CAN_TypeDef* CANx, uint32_t CAN_FLAG)
  9036. {
  9037. uint32_t flagtmp=0;
  9038. /* Check the parameters */
  9039. assert_param(IS_CAN_ALL_PERIPH(CANx));
  9040. assert_param(IS_CAN_CLEAR_FLAG(CAN_FLAG));
  9041. if (CAN_FLAG == CAN_FLAG_LEC) /* ESR register */
  9042. {
  9043. /* Clear the selected CAN flags */
  9044. CANx->ESR = (uint32_t)RESET;
  9045. }
  9046. else /* MSR or TSR or RF0R or RF1R */
  9047. {
  9048. flagtmp = CAN_FLAG & 0x000FFFFF;
  9049. if ((CAN_FLAG & CAN_FLAGS_RF0R)!=(uint32_t)RESET)
  9050. {
  9051. /* Receive Flags */
  9052. CANx->RF0R = (uint32_t)(flagtmp);
  9053. }
  9054. else if ((CAN_FLAG & CAN_FLAGS_RF1R)!=(uint32_t)RESET)
  9055. {
  9056. /* Receive Flags */
  9057. CANx->RF1R = (uint32_t)(flagtmp);
  9058. }
  9059. else if ((CAN_FLAG & CAN_FLAGS_TSR)!=(uint32_t)RESET)
  9060. {
  9061. /* Transmit Flags */
  9062. CANx->TSR = (uint32_t)(flagtmp);
  9063. }
  9064. else /* If((CAN_FLAG & CAN_FLAGS_MSR)!=(uint32_t)RESET) */
  9065. {
  9066. /* Operating mode Flags */
  9067. CANx->MSR = (uint32_t)(flagtmp);
  9068. }
  9069. }
  9070. }
  9071. /**
  9072. * @brief Checks whether the specified CANx interrupt has occurred or not.
  9073. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  9074. * @param CAN_IT: specifies the CAN interrupt source to check.
  9075. * This parameter can be one of the following flags:
  9076. * - CAN_IT_TME
  9077. * - CAN_IT_FMP0
  9078. * - CAN_IT_FF0
  9079. * - CAN_IT_FOV0
  9080. * - CAN_IT_FMP1
  9081. * - CAN_IT_FF1
  9082. * - CAN_IT_FOV1
  9083. * - CAN_IT_WKU
  9084. * - CAN_IT_SLK
  9085. * - CAN_IT_EWG
  9086. * - CAN_IT_EPV
  9087. * - CAN_IT_BOF
  9088. * - CAN_IT_LEC
  9089. * - CAN_IT_ERR
  9090. * @retval The current state of CAN_IT (SET or RESET).
  9091. */
  9092. ITStatus CAN_GetITStatus(CAN_TypeDef* CANx, uint32_t CAN_IT)
  9093. {
  9094. ITStatus itstatus = RESET;
  9095. /* Check the parameters */
  9096. assert_param(IS_CAN_ALL_PERIPH(CANx));
  9097. assert_param(IS_CAN_IT(CAN_IT));
  9098. /* check the enable interrupt bit */
  9099. if((CANx->IER & CAN_IT) != RESET)
  9100. {
  9101. /* in case the Interrupt is enabled, .... */
  9102. switch (CAN_IT)
  9103. {
  9104. case CAN_IT_TME:
  9105. /* Check CAN_TSR_RQCPx bits */
  9106. itstatus = CheckITStatus(CANx->TSR, CAN_TSR_RQCP0|CAN_TSR_RQCP1|CAN_TSR_RQCP2);
  9107. break;
  9108. case CAN_IT_FMP0:
  9109. /* Check CAN_RF0R_FMP0 bit */
  9110. itstatus = CheckITStatus(CANx->RF0R, CAN_RF0R_FMP0);
  9111. break;
  9112. case CAN_IT_FF0:
  9113. /* Check CAN_RF0R_FULL0 bit */
  9114. itstatus = CheckITStatus(CANx->RF0R, CAN_RF0R_FULL0);
  9115. break;
  9116. case CAN_IT_FOV0:
  9117. /* Check CAN_RF0R_FOVR0 bit */
  9118. itstatus = CheckITStatus(CANx->RF0R, CAN_RF0R_FOVR0);
  9119. break;
  9120. case CAN_IT_FMP1:
  9121. /* Check CAN_RF1R_FMP1 bit */
  9122. itstatus = CheckITStatus(CANx->RF1R, CAN_RF1R_FMP1);
  9123. break;
  9124. case CAN_IT_FF1:
  9125. /* Check CAN_RF1R_FULL1 bit */
  9126. itstatus = CheckITStatus(CANx->RF1R, CAN_RF1R_FULL1);
  9127. break;
  9128. case CAN_IT_FOV1:
  9129. /* Check CAN_RF1R_FOVR1 bit */
  9130. itstatus = CheckITStatus(CANx->RF1R, CAN_RF1R_FOVR1);
  9131. break;
  9132. case CAN_IT_WKU:
  9133. /* Check CAN_MSR_WKUI bit */
  9134. itstatus = CheckITStatus(CANx->MSR, CAN_MSR_WKUI);
  9135. break;
  9136. case CAN_IT_SLK:
  9137. /* Check CAN_MSR_SLAKI bit */
  9138. itstatus = CheckITStatus(CANx->MSR, CAN_MSR_SLAKI);
  9139. break;
  9140. case CAN_IT_EWG:
  9141. /* Check CAN_ESR_EWGF bit */
  9142. itstatus = CheckITStatus(CANx->ESR, CAN_ESR_EWGF);
  9143. break;
  9144. case CAN_IT_EPV:
  9145. /* Check CAN_ESR_EPVF bit */
  9146. itstatus = CheckITStatus(CANx->ESR, CAN_ESR_EPVF);
  9147. break;
  9148. case CAN_IT_BOF:
  9149. /* Check CAN_ESR_BOFF bit */
  9150. itstatus = CheckITStatus(CANx->ESR, CAN_ESR_BOFF);
  9151. break;
  9152. case CAN_IT_LEC:
  9153. /* Check CAN_ESR_LEC bit */
  9154. itstatus = CheckITStatus(CANx->ESR, CAN_ESR_LEC);
  9155. break;
  9156. case CAN_IT_ERR:
  9157. /* Check CAN_MSR_ERRI bit */
  9158. itstatus = CheckITStatus(CANx->MSR, CAN_MSR_ERRI);
  9159. break;
  9160. default :
  9161. /* in case of error, return RESET */
  9162. itstatus = RESET;
  9163. break;
  9164. }
  9165. }
  9166. else
  9167. {
  9168. /* in case the Interrupt is not enabled, return RESET */
  9169. itstatus = RESET;
  9170. }
  9171. /* Return the CAN_IT status */
  9172. return itstatus;
  9173. }
  9174. /**
  9175. * @brief Clears the CANx's interrupt pending bits.
  9176. * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
  9177. * @param CAN_IT: specifies the interrupt pending bit to clear.
  9178. * - CAN_IT_TME
  9179. * - CAN_IT_FF0
  9180. * - CAN_IT_FOV0
  9181. * - CAN_IT_FF1
  9182. * - CAN_IT_FOV1
  9183. * - CAN_IT_WKU
  9184. * - CAN_IT_SLK
  9185. * - CAN_IT_EWG
  9186. * - CAN_IT_EPV
  9187. * - CAN_IT_BOF
  9188. * - CAN_IT_LEC
  9189. * - CAN_IT_ERR
  9190. * @retval None.
  9191. */
  9192. void CAN_ClearITPendingBit(CAN_TypeDef* CANx, uint32_t CAN_IT)
  9193. {
  9194. /* Check the parameters */
  9195. assert_param(IS_CAN_ALL_PERIPH(CANx));
  9196. assert_param(IS_CAN_CLEAR_IT(CAN_IT));
  9197. switch (CAN_IT)
  9198. {
  9199. case CAN_IT_TME:
  9200. /* Clear CAN_TSR_RQCPx (rc_w1)*/
  9201. CANx->TSR = CAN_TSR_RQCP0|CAN_TSR_RQCP1|CAN_TSR_RQCP2;
  9202. break;
  9203. case CAN_IT_FF0:
  9204. /* Clear CAN_RF0R_FULL0 (rc_w1)*/
  9205. CANx->RF0R = CAN_RF0R_FULL0;
  9206. break;
  9207. case CAN_IT_FOV0:
  9208. /* Clear CAN_RF0R_FOVR0 (rc_w1)*/
  9209. CANx->RF0R = CAN_RF0R_FOVR0;
  9210. break;
  9211. case CAN_IT_FF1:
  9212. /* Clear CAN_RF1R_FULL1 (rc_w1)*/
  9213. CANx->RF1R = CAN_RF1R_FULL1;
  9214. break;
  9215. case CAN_IT_FOV1:
  9216. /* Clear CAN_RF1R_FOVR1 (rc_w1)*/
  9217. CANx->RF1R = CAN_RF1R_FOVR1;
  9218. break;
  9219. case CAN_IT_WKU:
  9220. /* Clear CAN_MSR_WKUI (rc_w1)*/
  9221. CANx->MSR = CAN_MSR_WKUI;
  9222. break;
  9223. case CAN_IT_SLK:
  9224. /* Clear CAN_MSR_SLAKI (rc_w1)*/
  9225. CANx->MSR = CAN_MSR_SLAKI;
  9226. break;
  9227. case CAN_IT_EWG:
  9228. /* Clear CAN_MSR_ERRI (rc_w1) */
  9229. CANx->MSR = CAN_MSR_ERRI;
  9230. /* Note : the corresponding Flag is cleared by hardware depending
  9231. of the CAN Bus status*/
  9232. break;
  9233. case CAN_IT_EPV:
  9234. /* Clear CAN_MSR_ERRI (rc_w1) */
  9235. CANx->MSR = CAN_MSR_ERRI;
  9236. /* Note : the corresponding Flag is cleared by hardware depending
  9237. of the CAN Bus status*/
  9238. break;
  9239. case CAN_IT_BOF:
  9240. /* Clear CAN_MSR_ERRI (rc_w1) */
  9241. CANx->MSR = CAN_MSR_ERRI;
  9242. /* Note : the corresponding Flag is cleared by hardware depending
  9243. of the CAN Bus status*/
  9244. break;
  9245. case CAN_IT_LEC:
  9246. /* Clear LEC bits */
  9247. CANx->ESR = RESET;
  9248. /* Clear CAN_MSR_ERRI (rc_w1) */
  9249. CANx->MSR = CAN_MSR_ERRI;
  9250. break;
  9251. case CAN_IT_ERR:
  9252. /*Clear LEC bits */
  9253. CANx->ESR = RESET;
  9254. /* Clear CAN_MSR_ERRI (rc_w1) */
  9255. CANx->MSR = CAN_MSR_ERRI;
  9256. /* Note : BOFF, EPVF and EWGF Flags are cleared by hardware depending
  9257. of the CAN Bus status*/
  9258. break;
  9259. default :
  9260. break;
  9261. }
  9262. }
  9263. /**
  9264. * @brief Checks whether the CAN interrupt has occurred or not.
  9265. * @param CAN_Reg: specifies the CAN interrupt register to check.
  9266. * @param It_Bit: specifies the interrupt source bit to check.
  9267. * @retval The new state of the CAN Interrupt (SET or RESET).
  9268. */
  9269. static ITStatus CheckITStatus(uint32_t CAN_Reg, uint32_t It_Bit)
  9270. {
  9271. ITStatus pendingbitstatus = RESET;
  9272. if ((CAN_Reg & It_Bit) != (uint32_t)RESET)
  9273. {
  9274. /* CAN_IT is set */
  9275. pendingbitstatus = SET;
  9276. }
  9277. else
  9278. {
  9279. /* CAN_IT is reset */
  9280. pendingbitstatus = RESET;
  9281. }
  9282. return pendingbitstatus;
  9283. }
  9284. /**
  9285. * @}
  9286. */
  9287. /**
  9288. * @}
  9289. */
  9290. /**
  9291. * @}
  9292. */
  9293. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  9294. /**
  9295. ******************************************************************************
  9296. * @file stm32f10x_rtc.c
  9297. * @author MCD Application Team
  9298. * @version V3.5.0
  9299. * @date 11-March-2011
  9300. * @brief This file provides all the RTC firmware functions.
  9301. ******************************************************************************
  9302. * @attention
  9303. *
  9304. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  9305. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  9306. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  9307. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  9308. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  9309. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  9310. *
  9311. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  9312. ******************************************************************************
  9313. */
  9314. /* Includes ------------------------------------------------------------------*/
  9315. #include "stm32f10x_rtc.h"
  9316. /** @addtogroup STM32F10x_StdPeriph_Driver
  9317. * @{
  9318. */
  9319. /** @defgroup RTC
  9320. * @brief RTC driver modules
  9321. * @{
  9322. */
  9323. /** @defgroup RTC_Private_TypesDefinitions
  9324. * @{
  9325. */
  9326. /**
  9327. * @}
  9328. */
  9329. /** @defgroup RTC_Private_Defines
  9330. * @{
  9331. */
  9332. #define RTC_LSB_MASK ((uint32_t)0x0000FFFF) /*!< RTC LSB Mask */
  9333. #define PRLH_MSB_MASK ((uint32_t)0x000F0000) /*!< RTC Prescaler MSB Mask */
  9334. /**
  9335. * @}
  9336. */
  9337. /** @defgroup RTC_Private_Macros
  9338. * @{
  9339. */
  9340. /**
  9341. * @}
  9342. */
  9343. /** @defgroup RTC_Private_Variables
  9344. * @{
  9345. */
  9346. /**
  9347. * @}
  9348. */
  9349. /** @defgroup RTC_Private_FunctionPrototypes
  9350. * @{
  9351. */
  9352. /**
  9353. * @}
  9354. */
  9355. /** @defgroup RTC_Private_Functions
  9356. * @{
  9357. */
  9358. /**
  9359. * @brief Enables or disables the specified RTC interrupts.
  9360. * @param RTC_IT: specifies the RTC interrupts sources to be enabled or disabled.
  9361. * This parameter can be any combination of the following values:
  9362. * @arg RTC_IT_OW: Overflow interrupt
  9363. * @arg RTC_IT_ALR: Alarm interrupt
  9364. * @arg RTC_IT_SEC: Second interrupt
  9365. * @param NewState: new state of the specified RTC interrupts.
  9366. * This parameter can be: ENABLE or DISABLE.
  9367. * @retval None
  9368. */
  9369. void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState)
  9370. {
  9371. /* Check the parameters */
  9372. assert_param(IS_RTC_IT(RTC_IT));
  9373. assert_param(IS_FUNCTIONAL_STATE(NewState));
  9374. if (NewState != DISABLE)
  9375. {
  9376. RTC->CRH |= RTC_IT;
  9377. }
  9378. else
  9379. {
  9380. RTC->CRH &= (uint16_t)~RTC_IT;
  9381. }
  9382. }
  9383. /**
  9384. * @brief Enters the RTC configuration mode.
  9385. * @param None
  9386. * @retval None
  9387. */
  9388. void RTC_EnterConfigMode(void)
  9389. {
  9390. /* Set the CNF flag to enter in the Configuration Mode */
  9391. RTC->CRL |= RTC_CRL_CNF;
  9392. }
  9393. /**
  9394. * @brief Exits from the RTC configuration mode.
  9395. * @param None
  9396. * @retval None
  9397. */
  9398. void RTC_ExitConfigMode(void)
  9399. {
  9400. /* Reset the CNF flag to exit from the Configuration Mode */
  9401. RTC->CRL &= (uint16_t)~((uint16_t)RTC_CRL_CNF);
  9402. }
  9403. /**
  9404. * @brief Gets the RTC counter value.
  9405. * @param None
  9406. * @retval RTC counter value.
  9407. */
  9408. uint32_t RTC_GetCounter(void)
  9409. {
  9410. uint16_t tmp = 0;
  9411. tmp = RTC->CNTL;
  9412. return (((uint32_t)RTC->CNTH << 16 ) | tmp) ;
  9413. }
  9414. /**
  9415. * @brief Sets the RTC counter value.
  9416. * @param CounterValue: RTC counter new value.
  9417. * @retval None
  9418. */
  9419. void RTC_SetCounter(uint32_t CounterValue)
  9420. {
  9421. RTC_EnterConfigMode();
  9422. /* Set RTC COUNTER MSB word */
  9423. RTC->CNTH = CounterValue >> 16;
  9424. /* Set RTC COUNTER LSB word */
  9425. RTC->CNTL = (CounterValue & RTC_LSB_MASK);
  9426. RTC_ExitConfigMode();
  9427. }
  9428. /**
  9429. * @brief Sets the RTC prescaler value.
  9430. * @param PrescalerValue: RTC prescaler new value.
  9431. * @retval None
  9432. */
  9433. void RTC_SetPrescaler(uint32_t PrescalerValue)
  9434. {
  9435. /* Check the parameters */
  9436. assert_param(IS_RTC_PRESCALER(PrescalerValue));
  9437. RTC_EnterConfigMode();
  9438. /* Set RTC PRESCALER MSB word */
  9439. RTC->PRLH = (PrescalerValue & PRLH_MSB_MASK) >> 16;
  9440. /* Set RTC PRESCALER LSB word */
  9441. RTC->PRLL = (PrescalerValue & RTC_LSB_MASK);
  9442. RTC_ExitConfigMode();
  9443. }
  9444. /**
  9445. * @brief Sets the RTC alarm value.
  9446. * @param AlarmValue: RTC alarm new value.
  9447. * @retval None
  9448. */
  9449. void RTC_SetAlarm(uint32_t AlarmValue)
  9450. {
  9451. RTC_EnterConfigMode();
  9452. /* Set the ALARM MSB word */
  9453. RTC->ALRH = AlarmValue >> 16;
  9454. /* Set the ALARM LSB word */
  9455. RTC->ALRL = (AlarmValue & RTC_LSB_MASK);
  9456. RTC_ExitConfigMode();
  9457. }
  9458. /**
  9459. * @brief Gets the RTC divider value.
  9460. * @param None
  9461. * @retval RTC Divider value.
  9462. */
  9463. uint32_t RTC_GetDivider(void)
  9464. {
  9465. uint32_t tmp = 0x00;
  9466. tmp = ((uint32_t)RTC->DIVH & (uint32_t)0x000F) << 16;
  9467. tmp |= RTC->DIVL;
  9468. return tmp;
  9469. }
  9470. /**
  9471. * @brief Waits until last write operation on RTC registers has finished.
  9472. * @note This function must be called before any write to RTC registers.
  9473. * @param None
  9474. * @retval None
  9475. */
  9476. void RTC_WaitForLastTask(void)
  9477. {
  9478. /* Loop until RTOFF flag is set */
  9479. while ((RTC->CRL & RTC_FLAG_RTOFF) == (uint16_t)RESET)
  9480. {
  9481. }
  9482. }
  9483. /**
  9484. * @brief Waits until the RTC registers (RTC_CNT, RTC_ALR and RTC_PRL)
  9485. * are synchronized with RTC APB clock.
  9486. * @note This function must be called before any read operation after an APB reset
  9487. * or an APB clock stop.
  9488. * @param None
  9489. * @retval None
  9490. */
  9491. void RTC_WaitForSynchro(void)
  9492. {
  9493. /* Clear RSF flag */
  9494. RTC->CRL &= (uint16_t)~RTC_FLAG_RSF;
  9495. /* Loop until RSF flag is set */
  9496. while ((RTC->CRL & RTC_FLAG_RSF) == (uint16_t)RESET)
  9497. {
  9498. }
  9499. }
  9500. /**
  9501. * @brief Checks whether the specified RTC flag is set or not.
  9502. * @param RTC_FLAG: specifies the flag to check.
  9503. * This parameter can be one the following values:
  9504. * @arg RTC_FLAG_RTOFF: RTC Operation OFF flag
  9505. * @arg RTC_FLAG_RSF: Registers Synchronized flag
  9506. * @arg RTC_FLAG_OW: Overflow flag
  9507. * @arg RTC_FLAG_ALR: Alarm flag
  9508. * @arg RTC_FLAG_SEC: Second flag
  9509. * @retval The new state of RTC_FLAG (SET or RESET).
  9510. */
  9511. FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG)
  9512. {
  9513. FlagStatus bitstatus = RESET;
  9514. /* Check the parameters */
  9515. assert_param(IS_RTC_GET_FLAG(RTC_FLAG));
  9516. if ((RTC->CRL & RTC_FLAG) != (uint16_t)RESET)
  9517. {
  9518. bitstatus = SET;
  9519. }
  9520. else
  9521. {
  9522. bitstatus = RESET;
  9523. }
  9524. return bitstatus;
  9525. }
  9526. /**
  9527. * @brief Clears the RTC's pending flags.
  9528. * @param RTC_FLAG: specifies the flag to clear.
  9529. * This parameter can be any combination of the following values:
  9530. * @arg RTC_FLAG_RSF: Registers Synchronized flag. This flag is cleared only after
  9531. * an APB reset or an APB Clock stop.
  9532. * @arg RTC_FLAG_OW: Overflow flag
  9533. * @arg RTC_FLAG_ALR: Alarm flag
  9534. * @arg RTC_FLAG_SEC: Second flag
  9535. * @retval None
  9536. */
  9537. void RTC_ClearFlag(uint16_t RTC_FLAG)
  9538. {
  9539. /* Check the parameters */
  9540. assert_param(IS_RTC_CLEAR_FLAG(RTC_FLAG));
  9541. /* Clear the corresponding RTC flag */
  9542. RTC->CRL &= (uint16_t)~RTC_FLAG;
  9543. }
  9544. /**
  9545. * @brief Checks whether the specified RTC interrupt has occurred or not.
  9546. * @param RTC_IT: specifies the RTC interrupts sources to check.
  9547. * This parameter can be one of the following values:
  9548. * @arg RTC_IT_OW: Overflow interrupt
  9549. * @arg RTC_IT_ALR: Alarm interrupt
  9550. * @arg RTC_IT_SEC: Second interrupt
  9551. * @retval The new state of the RTC_IT (SET or RESET).
  9552. */
  9553. ITStatus RTC_GetITStatus(uint16_t RTC_IT)
  9554. {
  9555. ITStatus bitstatus = RESET;
  9556. /* Check the parameters */
  9557. assert_param(IS_RTC_GET_IT(RTC_IT));
  9558. bitstatus = (ITStatus)(RTC->CRL & RTC_IT);
  9559. if (((RTC->CRH & RTC_IT) != (uint16_t)RESET) && (bitstatus != (uint16_t)RESET))
  9560. {
  9561. bitstatus = SET;
  9562. }
  9563. else
  9564. {
  9565. bitstatus = RESET;
  9566. }
  9567. return bitstatus;
  9568. }
  9569. /**
  9570. * @brief Clears the RTC's interrupt pending bits.
  9571. * @param RTC_IT: specifies the interrupt pending bit to clear.
  9572. * This parameter can be any combination of the following values:
  9573. * @arg RTC_IT_OW: Overflow interrupt
  9574. * @arg RTC_IT_ALR: Alarm interrupt
  9575. * @arg RTC_IT_SEC: Second interrupt
  9576. * @retval None
  9577. */
  9578. void RTC_ClearITPendingBit(uint16_t RTC_IT)
  9579. {
  9580. /* Check the parameters */
  9581. assert_param(IS_RTC_IT(RTC_IT));
  9582. /* Clear the corresponding RTC pending bit */
  9583. RTC->CRL &= (uint16_t)~RTC_IT;
  9584. }
  9585. /**
  9586. * @}
  9587. */
  9588. /**
  9589. * @}
  9590. */
  9591. /**
  9592. * @}
  9593. */
  9594. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  9595. /**
  9596. ******************************************************************************
  9597. * @file stm32f10x_usart.c
  9598. * @author MCD Application Team
  9599. * @version V3.5.0
  9600. * @date 11-March-2011
  9601. * @brief This file provides all the USART firmware functions.
  9602. ******************************************************************************
  9603. * @attention
  9604. *
  9605. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  9606. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  9607. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  9608. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  9609. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  9610. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  9611. *
  9612. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  9613. ******************************************************************************
  9614. */
  9615. /* Includes ------------------------------------------------------------------*/
  9616. #include "stm32f10x_usart.h"
  9617. #include "stm32f10x_rcc.h"
  9618. /** @addtogroup STM32F10x_StdPeriph_Driver
  9619. * @{
  9620. */
  9621. /** @defgroup USART
  9622. * @brief USART driver modules
  9623. * @{
  9624. */
  9625. /** @defgroup USART_Private_TypesDefinitions
  9626. * @{
  9627. */
  9628. /**
  9629. * @}
  9630. */
  9631. /** @defgroup USART_Private_Defines
  9632. * @{
  9633. */
  9634. #define CR1_UE_Set ((uint16_t)0x2000) /*!< USART Enable Mask */
  9635. #define CR1_UE_Reset ((uint16_t)0xDFFF) /*!< USART Disable Mask */
  9636. #define CR1_WAKE_Mask ((uint16_t)0xF7FF) /*!< USART WakeUp Method Mask */
  9637. #define CR1_RWU_Set ((uint16_t)0x0002) /*!< USART mute mode Enable Mask */
  9638. #define CR1_RWU_Reset ((uint16_t)0xFFFD) /*!< USART mute mode Enable Mask */
  9639. #define CR1_SBK_Set ((uint16_t)0x0001) /*!< USART Break Character send Mask */
  9640. #define CR1_CLEAR_Mask ((uint16_t)0xE9F3) /*!< USART CR1 Mask */
  9641. #define CR2_Address_Mask ((uint16_t)0xFFF0) /*!< USART address Mask */
  9642. #define CR2_LINEN_Set ((uint16_t)0x4000) /*!< USART LIN Enable Mask */
  9643. #define CR2_LINEN_Reset ((uint16_t)0xBFFF) /*!< USART LIN Disable Mask */
  9644. #define CR2_LBDL_Mask ((uint16_t)0xFFDF) /*!< USART LIN Break detection Mask */
  9645. #define CR2_STOP_CLEAR_Mask ((uint16_t)0xCFFF) /*!< USART CR2 STOP Bits Mask */
  9646. #define CR2_CLOCK_CLEAR_Mask ((uint16_t)0xF0FF) /*!< USART CR2 Clock Mask */
  9647. #define CR3_SCEN_Set ((uint16_t)0x0020) /*!< USART SC Enable Mask */
  9648. #define CR3_SCEN_Reset ((uint16_t)0xFFDF) /*!< USART SC Disable Mask */
  9649. #define CR3_NACK_Set ((uint16_t)0x0010) /*!< USART SC NACK Enable Mask */
  9650. #define CR3_NACK_Reset ((uint16_t)0xFFEF) /*!< USART SC NACK Disable Mask */
  9651. #define CR3_HDSEL_Set ((uint16_t)0x0008) /*!< USART Half-Duplex Enable Mask */
  9652. #define CR3_HDSEL_Reset ((uint16_t)0xFFF7) /*!< USART Half-Duplex Disable Mask */
  9653. #define CR3_IRLP_Mask ((uint16_t)0xFFFB) /*!< USART IrDA LowPower mode Mask */
  9654. #define CR3_CLEAR_Mask ((uint16_t)0xFCFF) /*!< USART CR3 Mask */
  9655. #define CR3_IREN_Set ((uint16_t)0x0002) /*!< USART IrDA Enable Mask */
  9656. #define CR3_IREN_Reset ((uint16_t)0xFFFD) /*!< USART IrDA Disable Mask */
  9657. #define GTPR_LSB_Mask ((uint16_t)0x00FF) /*!< Guard Time Register LSB Mask */
  9658. #define GTPR_MSB_Mask ((uint16_t)0xFF00) /*!< Guard Time Register MSB Mask */
  9659. #define IT_Mask ((uint16_t)0x001F) /*!< USART Interrupt Mask */
  9660. /* USART OverSampling-8 Mask */
  9661. #define CR1_OVER8_Set ((u16)0x8000) /* USART OVER8 mode Enable Mask */
  9662. #define CR1_OVER8_Reset ((u16)0x7FFF) /* USART OVER8 mode Disable Mask */
  9663. /* USART One Bit Sampling Mask */
  9664. #define CR3_ONEBITE_Set ((u16)0x0800) /* USART ONEBITE mode Enable Mask */
  9665. #define CR3_ONEBITE_Reset ((u16)0xF7FF) /* USART ONEBITE mode Disable Mask */
  9666. /**
  9667. * @}
  9668. */
  9669. /** @defgroup USART_Private_Macros
  9670. * @{
  9671. */
  9672. /**
  9673. * @}
  9674. */
  9675. /** @defgroup USART_Private_Variables
  9676. * @{
  9677. */
  9678. /**
  9679. * @}
  9680. */
  9681. /** @defgroup USART_Private_FunctionPrototypes
  9682. * @{
  9683. */
  9684. /**
  9685. * @}
  9686. */
  9687. /** @defgroup USART_Private_Functions
  9688. * @{
  9689. */
  9690. /**
  9691. * @brief Deinitializes the USARTx peripheral registers to their default reset values.
  9692. * @param USARTx: Select the USART or the UART peripheral.
  9693. * This parameter can be one of the following values:
  9694. * USART1, USART2, USART3, UART4 or UART5.
  9695. * @retval None
  9696. */
  9697. void USART_DeInit(USART_TypeDef* USARTx)
  9698. {
  9699. /* Check the parameters */
  9700. assert_param(IS_USART_ALL_PERIPH(USARTx));
  9701. if (USARTx == USART1)
  9702. {
  9703. RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
  9704. RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
  9705. }
  9706. else if (USARTx == USART2)
  9707. {
  9708. RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
  9709. RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
  9710. }
  9711. else if (USARTx == USART3)
  9712. {
  9713. RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE);
  9714. RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
  9715. }
  9716. else if (USARTx == UART4)
  9717. {
  9718. RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, ENABLE);
  9719. RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, DISABLE);
  9720. }
  9721. else
  9722. {
  9723. if (USARTx == UART5)
  9724. {
  9725. RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, ENABLE);
  9726. RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, DISABLE);
  9727. }
  9728. }
  9729. }
  9730. /**
  9731. * @brief Initializes the USARTx peripheral according to the specified
  9732. * parameters in the USART_InitStruct .
  9733. * @param USARTx: Select the USART or the UART peripheral.
  9734. * This parameter can be one of the following values:
  9735. * USART1, USART2, USART3, UART4 or UART5.
  9736. * @param USART_InitStruct: pointer to a USART_InitTypeDef structure
  9737. * that contains the configuration information for the specified USART
  9738. * peripheral.
  9739. * @retval None
  9740. */
  9741. void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct)
  9742. {
  9743. uint32_t tmpreg = 0x00, apbclock = 0x00;
  9744. uint32_t integerdivider = 0x00;
  9745. uint32_t fractionaldivider = 0x00;
  9746. uint32_t usartxbase = 0;
  9747. RCC_ClocksTypeDef RCC_ClocksStatus;
  9748. /* Check the parameters */
  9749. assert_param(IS_USART_ALL_PERIPH(USARTx));
  9750. assert_param(IS_USART_BAUDRATE(USART_InitStruct->USART_BaudRate));
  9751. assert_param(IS_USART_WORD_LENGTH(USART_InitStruct->USART_WordLength));
  9752. assert_param(IS_USART_STOPBITS(USART_InitStruct->USART_StopBits));
  9753. assert_param(IS_USART_PARITY(USART_InitStruct->USART_Parity));
  9754. assert_param(IS_USART_MODE(USART_InitStruct->USART_Mode));
  9755. assert_param(IS_USART_HARDWARE_FLOW_CONTROL(USART_InitStruct->USART_HardwareFlowControl));
  9756. /* The hardware flow control is available only for USART1, USART2 and USART3 */
  9757. if (USART_InitStruct->USART_HardwareFlowControl != USART_HardwareFlowControl_None)
  9758. {
  9759. assert_param(IS_USART_123_PERIPH(USARTx));
  9760. }
  9761. usartxbase = (uint32_t)USARTx;
  9762. /*---------------------------- USART CR2 Configuration -----------------------*/
  9763. tmpreg = USARTx->CR2;
  9764. /* Clear STOP[13:12] bits */
  9765. tmpreg &= CR2_STOP_CLEAR_Mask;
  9766. /* Configure the USART Stop Bits, Clock, CPOL, CPHA and LastBit ------------*/
  9767. /* Set STOP[13:12] bits according to USART_StopBits value */
  9768. tmpreg |= (uint32_t)USART_InitStruct->USART_StopBits;
  9769. /* Write to USART CR2 */
  9770. USARTx->CR2 = (uint16_t)tmpreg;
  9771. /*---------------------------- USART CR1 Configuration -----------------------*/
  9772. tmpreg = USARTx->CR1;
  9773. /* Clear M, PCE, PS, TE and RE bits */
  9774. tmpreg &= CR1_CLEAR_Mask;
  9775. /* Configure the USART Word Length, Parity and mode ----------------------- */
  9776. /* Set the M bits according to USART_WordLength value */
  9777. /* Set PCE and PS bits according to USART_Parity value */
  9778. /* Set TE and RE bits according to USART_Mode value */
  9779. tmpreg |= (uint32_t)USART_InitStruct->USART_WordLength | USART_InitStruct->USART_Parity |
  9780. USART_InitStruct->USART_Mode;
  9781. /* Write to USART CR1 */
  9782. USARTx->CR1 = (uint16_t)tmpreg;
  9783. /*---------------------------- USART CR3 Configuration -----------------------*/
  9784. tmpreg = USARTx->CR3;
  9785. /* Clear CTSE and RTSE bits */
  9786. tmpreg &= CR3_CLEAR_Mask;
  9787. /* Configure the USART HFC -------------------------------------------------*/
  9788. /* Set CTSE and RTSE bits according to USART_HardwareFlowControl value */
  9789. tmpreg |= USART_InitStruct->USART_HardwareFlowControl;
  9790. /* Write to USART CR3 */
  9791. USARTx->CR3 = (uint16_t)tmpreg;
  9792. /*---------------------------- USART BRR Configuration -----------------------*/
  9793. /* Configure the USART Baud Rate -------------------------------------------*/
  9794. RCC_GetClocksFreq(&RCC_ClocksStatus);
  9795. if (usartxbase == USART1_BASE)
  9796. {
  9797. apbclock = RCC_ClocksStatus.PCLK2_Frequency;
  9798. }
  9799. else
  9800. {
  9801. apbclock = RCC_ClocksStatus.PCLK1_Frequency;
  9802. }
  9803. /* Determine the integer part */
  9804. if ((USARTx->CR1 & CR1_OVER8_Set) != 0)
  9805. {
  9806. /* Integer part computing in case Oversampling mode is 8 Samples */
  9807. integerdivider = ((25 * apbclock) / (2 * (USART_InitStruct->USART_BaudRate)));
  9808. }
  9809. else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
  9810. {
  9811. /* Integer part computing in case Oversampling mode is 16 Samples */
  9812. integerdivider = ((25 * apbclock) / (4 * (USART_InitStruct->USART_BaudRate)));
  9813. }
  9814. tmpreg = (integerdivider / 100) << 4;
  9815. /* Determine the fractional part */
  9816. fractionaldivider = integerdivider - (100 * (tmpreg >> 4));
  9817. /* Implement the fractional part in the register */
  9818. if ((USARTx->CR1 & CR1_OVER8_Set) != 0)
  9819. {
  9820. tmpreg |= ((((fractionaldivider * 8) + 50) / 100)) & ((uint8_t)0x07);
  9821. }
  9822. else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
  9823. {
  9824. tmpreg |= ((((fractionaldivider * 16) + 50) / 100)) & ((uint8_t)0x0F);
  9825. }
  9826. /* Write to USART BRR */
  9827. USARTx->BRR = (uint16_t)tmpreg;
  9828. }
  9829. /**
  9830. * @brief Fills each USART_InitStruct member with its default value.
  9831. * @param USART_InitStruct: pointer to a USART_InitTypeDef structure
  9832. * which will be initialized.
  9833. * @retval None
  9834. */
  9835. void USART_StructInit(USART_InitTypeDef* USART_InitStruct)
  9836. {
  9837. /* USART_InitStruct members default value */
  9838. USART_InitStruct->USART_BaudRate = 9600;
  9839. USART_InitStruct->USART_WordLength = USART_WordLength_8b;
  9840. USART_InitStruct->USART_StopBits = USART_StopBits_1;
  9841. USART_InitStruct->USART_Parity = USART_Parity_No ;
  9842. USART_InitStruct->USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  9843. USART_InitStruct->USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  9844. }
  9845. /**
  9846. * @brief Initializes the USARTx peripheral Clock according to the
  9847. * specified parameters in the USART_ClockInitStruct .
  9848. * @param USARTx: where x can be 1, 2, 3 to select the USART peripheral.
  9849. * @param USART_ClockInitStruct: pointer to a USART_ClockInitTypeDef
  9850. * structure that contains the configuration information for the specified
  9851. * USART peripheral.
  9852. * @note The Smart Card and Synchronous modes are not available for UART4 and UART5.
  9853. * @retval None
  9854. */
  9855. void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct)
  9856. {
  9857. uint32_t tmpreg = 0x00;
  9858. /* Check the parameters */
  9859. assert_param(IS_USART_123_PERIPH(USARTx));
  9860. assert_param(IS_USART_CLOCK(USART_ClockInitStruct->USART_Clock));
  9861. assert_param(IS_USART_CPOL(USART_ClockInitStruct->USART_CPOL));
  9862. assert_param(IS_USART_CPHA(USART_ClockInitStruct->USART_CPHA));
  9863. assert_param(IS_USART_LASTBIT(USART_ClockInitStruct->USART_LastBit));
  9864. /*---------------------------- USART CR2 Configuration -----------------------*/
  9865. tmpreg = USARTx->CR2;
  9866. /* Clear CLKEN, CPOL, CPHA and LBCL bits */
  9867. tmpreg &= CR2_CLOCK_CLEAR_Mask;
  9868. /* Configure the USART Clock, CPOL, CPHA and LastBit ------------*/
  9869. /* Set CLKEN bit according to USART_Clock value */
  9870. /* Set CPOL bit according to USART_CPOL value */
  9871. /* Set CPHA bit according to USART_CPHA value */
  9872. /* Set LBCL bit according to USART_LastBit value */
  9873. tmpreg |= (uint32_t)USART_ClockInitStruct->USART_Clock | USART_ClockInitStruct->USART_CPOL |
  9874. USART_ClockInitStruct->USART_CPHA | USART_ClockInitStruct->USART_LastBit;
  9875. /* Write to USART CR2 */
  9876. USARTx->CR2 = (uint16_t)tmpreg;
  9877. }
  9878. /**
  9879. * @brief Fills each USART_ClockInitStruct member with its default value.
  9880. * @param USART_ClockInitStruct: pointer to a USART_ClockInitTypeDef
  9881. * structure which will be initialized.
  9882. * @retval None
  9883. */
  9884. void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct)
  9885. {
  9886. /* USART_ClockInitStruct members default value */
  9887. USART_ClockInitStruct->USART_Clock = USART_Clock_Disable;
  9888. USART_ClockInitStruct->USART_CPOL = USART_CPOL_Low;
  9889. USART_ClockInitStruct->USART_CPHA = USART_CPHA_1Edge;
  9890. USART_ClockInitStruct->USART_LastBit = USART_LastBit_Disable;
  9891. }
  9892. /**
  9893. * @brief Enables or disables the specified USART peripheral.
  9894. * @param USARTx: Select the USART or the UART peripheral.
  9895. * This parameter can be one of the following values:
  9896. * USART1, USART2, USART3, UART4 or UART5.
  9897. * @param NewState: new state of the USARTx peripheral.
  9898. * This parameter can be: ENABLE or DISABLE.
  9899. * @retval None
  9900. */
  9901. void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
  9902. {
  9903. /* Check the parameters */
  9904. assert_param(IS_USART_ALL_PERIPH(USARTx));
  9905. assert_param(IS_FUNCTIONAL_STATE(NewState));
  9906. if (NewState != DISABLE)
  9907. {
  9908. /* Enable the selected USART by setting the UE bit in the CR1 register */
  9909. USARTx->CR1 |= CR1_UE_Set;
  9910. }
  9911. else
  9912. {
  9913. /* Disable the selected USART by clearing the UE bit in the CR1 register */
  9914. USARTx->CR1 &= CR1_UE_Reset;
  9915. }
  9916. }
  9917. /**
  9918. * @brief Enables or disables the specified USART interrupts.
  9919. * @param USARTx: Select the USART or the UART peripheral.
  9920. * This parameter can be one of the following values:
  9921. * USART1, USART2, USART3, UART4 or UART5.
  9922. * @param USART_IT: specifies the USART interrupt sources to be enabled or disabled.
  9923. * This parameter can be one of the following values:
  9924. * @arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
  9925. * @arg USART_IT_LBD: LIN Break detection interrupt
  9926. * @arg USART_IT_TXE: Transmit Data Register empty interrupt
  9927. * @arg USART_IT_TC: Transmission complete interrupt
  9928. * @arg USART_IT_RXNE: Receive Data register not empty interrupt
  9929. * @arg USART_IT_IDLE: Idle line detection interrupt
  9930. * @arg USART_IT_PE: Parity Error interrupt
  9931. * @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  9932. * @param NewState: new state of the specified USARTx interrupts.
  9933. * This parameter can be: ENABLE or DISABLE.
  9934. * @retval None
  9935. */
  9936. void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState)
  9937. {
  9938. uint32_t usartreg = 0x00, itpos = 0x00, itmask = 0x00;
  9939. uint32_t usartxbase = 0x00;
  9940. /* Check the parameters */
  9941. assert_param(IS_USART_ALL_PERIPH(USARTx));
  9942. assert_param(IS_USART_CONFIG_IT(USART_IT));
  9943. assert_param(IS_FUNCTIONAL_STATE(NewState));
  9944. /* The CTS interrupt is not available for UART4 and UART5 */
  9945. if (USART_IT == USART_IT_CTS)
  9946. {
  9947. assert_param(IS_USART_123_PERIPH(USARTx));
  9948. }
  9949. usartxbase = (uint32_t)USARTx;
  9950. /* Get the USART register index */
  9951. usartreg = (((uint8_t)USART_IT) >> 0x05);
  9952. /* Get the interrupt position */
  9953. itpos = USART_IT & IT_Mask;
  9954. itmask = (((uint32_t)0x01) << itpos);
  9955. if (usartreg == 0x01) /* The IT is in CR1 register */
  9956. {
  9957. usartxbase += 0x0C;
  9958. }
  9959. else if (usartreg == 0x02) /* The IT is in CR2 register */
  9960. {
  9961. usartxbase += 0x10;
  9962. }
  9963. else /* The IT is in CR3 register */
  9964. {
  9965. usartxbase += 0x14;
  9966. }
  9967. if (NewState != DISABLE)
  9968. {
  9969. *(__IO uint32_t*)usartxbase |= itmask;
  9970. }
  9971. else
  9972. {
  9973. *(__IO uint32_t*)usartxbase &= ~itmask;
  9974. }
  9975. }
  9976. /**
  9977. * @brief Enables or disables the USART’s DMA interface.
  9978. * @param USARTx: Select the USART or the UART peripheral.
  9979. * This parameter can be one of the following values:
  9980. * USART1, USART2, USART3, UART4 or UART5.
  9981. * @param USART_DMAReq: specifies the DMA request.
  9982. * This parameter can be any combination of the following values:
  9983. * @arg USART_DMAReq_Tx: USART DMA transmit request
  9984. * @arg USART_DMAReq_Rx: USART DMA receive request
  9985. * @param NewState: new state of the DMA Request sources.
  9986. * This parameter can be: ENABLE or DISABLE.
  9987. * @note The DMA mode is not available for UART5 except in the STM32
  9988. * High density value line devices(STM32F10X_HD_VL).
  9989. * @retval None
  9990. */
  9991. void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState)
  9992. {
  9993. /* Check the parameters */
  9994. assert_param(IS_USART_ALL_PERIPH(USARTx));
  9995. assert_param(IS_USART_DMAREQ(USART_DMAReq));
  9996. assert_param(IS_FUNCTIONAL_STATE(NewState));
  9997. if (NewState != DISABLE)
  9998. {
  9999. /* Enable the DMA transfer for selected requests by setting the DMAT and/or
  10000. DMAR bits in the USART CR3 register */
  10001. USARTx->CR3 |= USART_DMAReq;
  10002. }
  10003. else
  10004. {
  10005. /* Disable the DMA transfer for selected requests by clearing the DMAT and/or
  10006. DMAR bits in the USART CR3 register */
  10007. USARTx->CR3 &= (uint16_t)~USART_DMAReq;
  10008. }
  10009. }
  10010. /**
  10011. * @brief Sets the address of the USART node.
  10012. * @param USARTx: Select the USART or the UART peripheral.
  10013. * This parameter can be one of the following values:
  10014. * USART1, USART2, USART3, UART4 or UART5.
  10015. * @param USART_Address: Indicates the address of the USART node.
  10016. * @retval None
  10017. */
  10018. void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address)
  10019. {
  10020. /* Check the parameters */
  10021. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10022. assert_param(IS_USART_ADDRESS(USART_Address));
  10023. /* Clear the USART address */
  10024. USARTx->CR2 &= CR2_Address_Mask;
  10025. /* Set the USART address node */
  10026. USARTx->CR2 |= USART_Address;
  10027. }
  10028. /**
  10029. * @brief Selects the USART WakeUp method.
  10030. * @param USARTx: Select the USART or the UART peripheral.
  10031. * This parameter can be one of the following values:
  10032. * USART1, USART2, USART3, UART4 or UART5.
  10033. * @param USART_WakeUp: specifies the USART wakeup method.
  10034. * This parameter can be one of the following values:
  10035. * @arg USART_WakeUp_IdleLine: WakeUp by an idle line detection
  10036. * @arg USART_WakeUp_AddressMark: WakeUp by an address mark
  10037. * @retval None
  10038. */
  10039. void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp)
  10040. {
  10041. /* Check the parameters */
  10042. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10043. assert_param(IS_USART_WAKEUP(USART_WakeUp));
  10044. USARTx->CR1 &= CR1_WAKE_Mask;
  10045. USARTx->CR1 |= USART_WakeUp;
  10046. }
  10047. /**
  10048. * @brief Determines if the USART is in mute mode or not.
  10049. * @param USARTx: Select the USART or the UART peripheral.
  10050. * This parameter can be one of the following values:
  10051. * USART1, USART2, USART3, UART4 or UART5.
  10052. * @param NewState: new state of the USART mute mode.
  10053. * This parameter can be: ENABLE or DISABLE.
  10054. * @retval None
  10055. */
  10056. void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState)
  10057. {
  10058. /* Check the parameters */
  10059. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10060. assert_param(IS_FUNCTIONAL_STATE(NewState));
  10061. if (NewState != DISABLE)
  10062. {
  10063. /* Enable the USART mute mode by setting the RWU bit in the CR1 register */
  10064. USARTx->CR1 |= CR1_RWU_Set;
  10065. }
  10066. else
  10067. {
  10068. /* Disable the USART mute mode by clearing the RWU bit in the CR1 register */
  10069. USARTx->CR1 &= CR1_RWU_Reset;
  10070. }
  10071. }
  10072. /**
  10073. * @brief Sets the USART LIN Break detection length.
  10074. * @param USARTx: Select the USART or the UART peripheral.
  10075. * This parameter can be one of the following values:
  10076. * USART1, USART2, USART3, UART4 or UART5.
  10077. * @param USART_LINBreakDetectLength: specifies the LIN break detection length.
  10078. * This parameter can be one of the following values:
  10079. * @arg USART_LINBreakDetectLength_10b: 10-bit break detection
  10080. * @arg USART_LINBreakDetectLength_11b: 11-bit break detection
  10081. * @retval None
  10082. */
  10083. void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength)
  10084. {
  10085. /* Check the parameters */
  10086. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10087. assert_param(IS_USART_LIN_BREAK_DETECT_LENGTH(USART_LINBreakDetectLength));
  10088. USARTx->CR2 &= CR2_LBDL_Mask;
  10089. USARTx->CR2 |= USART_LINBreakDetectLength;
  10090. }
  10091. /**
  10092. * @brief Enables or disables the USART’s LIN mode.
  10093. * @param USARTx: Select the USART or the UART peripheral.
  10094. * This parameter can be one of the following values:
  10095. * USART1, USART2, USART3, UART4 or UART5.
  10096. * @param NewState: new state of the USART LIN mode.
  10097. * This parameter can be: ENABLE or DISABLE.
  10098. * @retval None
  10099. */
  10100. void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState)
  10101. {
  10102. /* Check the parameters */
  10103. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10104. assert_param(IS_FUNCTIONAL_STATE(NewState));
  10105. if (NewState != DISABLE)
  10106. {
  10107. /* Enable the LIN mode by setting the LINEN bit in the CR2 register */
  10108. USARTx->CR2 |= CR2_LINEN_Set;
  10109. }
  10110. else
  10111. {
  10112. /* Disable the LIN mode by clearing the LINEN bit in the CR2 register */
  10113. USARTx->CR2 &= CR2_LINEN_Reset;
  10114. }
  10115. }
  10116. /**
  10117. * @brief Transmits single data through the USARTx peripheral.
  10118. * @param USARTx: Select the USART or the UART peripheral.
  10119. * This parameter can be one of the following values:
  10120. * USART1, USART2, USART3, UART4 or UART5.
  10121. * @param Data: the data to transmit.
  10122. * @retval None
  10123. */
  10124. void USART_SendData(USART_TypeDef* USARTx, uint16_t Data)
  10125. {
  10126. /* Check the parameters */
  10127. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10128. assert_param(IS_USART_DATA(Data));
  10129. /* Transmit Data */
  10130. USARTx->DR = (Data & (uint16_t)0x01FF);
  10131. }
  10132. /**
  10133. * @brief Returns the most recent received data by the USARTx peripheral.
  10134. * @param USARTx: Select the USART or the UART peripheral.
  10135. * This parameter can be one of the following values:
  10136. * USART1, USART2, USART3, UART4 or UART5.
  10137. * @retval The received data.
  10138. */
  10139. uint16_t USART_ReceiveData(USART_TypeDef* USARTx)
  10140. {
  10141. /* Check the parameters */
  10142. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10143. /* Receive Data */
  10144. return (uint16_t)(USARTx->DR & (uint16_t)0x01FF);
  10145. }
  10146. /**
  10147. * @brief Transmits break characters.
  10148. * @param USARTx: Select the USART or the UART peripheral.
  10149. * This parameter can be one of the following values:
  10150. * USART1, USART2, USART3, UART4 or UART5.
  10151. * @retval None
  10152. */
  10153. void USART_SendBreak(USART_TypeDef* USARTx)
  10154. {
  10155. /* Check the parameters */
  10156. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10157. /* Send break characters */
  10158. USARTx->CR1 |= CR1_SBK_Set;
  10159. }
  10160. /**
  10161. * @brief Sets the specified USART guard time.
  10162. * @param USARTx: where x can be 1, 2 or 3 to select the USART peripheral.
  10163. * @param USART_GuardTime: specifies the guard time.
  10164. * @note The guard time bits are not available for UART4 and UART5.
  10165. * @retval None
  10166. */
  10167. void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime)
  10168. {
  10169. /* Check the parameters */
  10170. assert_param(IS_USART_123_PERIPH(USARTx));
  10171. /* Clear the USART Guard time */
  10172. USARTx->GTPR &= GTPR_LSB_Mask;
  10173. /* Set the USART guard time */
  10174. USARTx->GTPR |= (uint16_t)((uint16_t)USART_GuardTime << 0x08);
  10175. }
  10176. /**
  10177. * @brief Sets the system clock prescaler.
  10178. * @param USARTx: Select the USART or the UART peripheral.
  10179. * This parameter can be one of the following values:
  10180. * USART1, USART2, USART3, UART4 or UART5.
  10181. * @param USART_Prescaler: specifies the prescaler clock.
  10182. * @note The function is used for IrDA mode with UART4 and UART5.
  10183. * @retval None
  10184. */
  10185. void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler)
  10186. {
  10187. /* Check the parameters */
  10188. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10189. /* Clear the USART prescaler */
  10190. USARTx->GTPR &= GTPR_MSB_Mask;
  10191. /* Set the USART prescaler */
  10192. USARTx->GTPR |= USART_Prescaler;
  10193. }
  10194. /**
  10195. * @brief Enables or disables the USART’s Smart Card mode.
  10196. * @param USARTx: where x can be 1, 2 or 3 to select the USART peripheral.
  10197. * @param NewState: new state of the Smart Card mode.
  10198. * This parameter can be: ENABLE or DISABLE.
  10199. * @note The Smart Card mode is not available for UART4 and UART5.
  10200. * @retval None
  10201. */
  10202. void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState)
  10203. {
  10204. /* Check the parameters */
  10205. assert_param(IS_USART_123_PERIPH(USARTx));
  10206. assert_param(IS_FUNCTIONAL_STATE(NewState));
  10207. if (NewState != DISABLE)
  10208. {
  10209. /* Enable the SC mode by setting the SCEN bit in the CR3 register */
  10210. USARTx->CR3 |= CR3_SCEN_Set;
  10211. }
  10212. else
  10213. {
  10214. /* Disable the SC mode by clearing the SCEN bit in the CR3 register */
  10215. USARTx->CR3 &= CR3_SCEN_Reset;
  10216. }
  10217. }
  10218. /**
  10219. * @brief Enables or disables NACK transmission.
  10220. * @param USARTx: where x can be 1, 2 or 3 to select the USART peripheral.
  10221. * @param NewState: new state of the NACK transmission.
  10222. * This parameter can be: ENABLE or DISABLE.
  10223. * @note The Smart Card mode is not available for UART4 and UART5.
  10224. * @retval None
  10225. */
  10226. void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState)
  10227. {
  10228. /* Check the parameters */
  10229. assert_param(IS_USART_123_PERIPH(USARTx));
  10230. assert_param(IS_FUNCTIONAL_STATE(NewState));
  10231. if (NewState != DISABLE)
  10232. {
  10233. /* Enable the NACK transmission by setting the NACK bit in the CR3 register */
  10234. USARTx->CR3 |= CR3_NACK_Set;
  10235. }
  10236. else
  10237. {
  10238. /* Disable the NACK transmission by clearing the NACK bit in the CR3 register */
  10239. USARTx->CR3 &= CR3_NACK_Reset;
  10240. }
  10241. }
  10242. /**
  10243. * @brief Enables or disables the USART’s Half Duplex communication.
  10244. * @param USARTx: Select the USART or the UART peripheral.
  10245. * This parameter can be one of the following values:
  10246. * USART1, USART2, USART3, UART4 or UART5.
  10247. * @param NewState: new state of the USART Communication.
  10248. * This parameter can be: ENABLE or DISABLE.
  10249. * @retval None
  10250. */
  10251. void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState)
  10252. {
  10253. /* Check the parameters */
  10254. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10255. assert_param(IS_FUNCTIONAL_STATE(NewState));
  10256. if (NewState != DISABLE)
  10257. {
  10258. /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
  10259. USARTx->CR3 |= CR3_HDSEL_Set;
  10260. }
  10261. else
  10262. {
  10263. /* Disable the Half-Duplex mode by clearing the HDSEL bit in the CR3 register */
  10264. USARTx->CR3 &= CR3_HDSEL_Reset;
  10265. }
  10266. }
  10267. /**
  10268. * @brief Enables or disables the USART's 8x oversampling mode.
  10269. * @param USARTx: Select the USART or the UART peripheral.
  10270. * This parameter can be one of the following values:
  10271. * USART1, USART2, USART3, UART4 or UART5.
  10272. * @param NewState: new state of the USART one bit sampling method.
  10273. * This parameter can be: ENABLE or DISABLE.
  10274. * @note
  10275. * This function has to be called before calling USART_Init()
  10276. * function in order to have correct baudrate Divider value.
  10277. * @retval None
  10278. */
  10279. void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
  10280. {
  10281. /* Check the parameters */
  10282. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10283. assert_param(IS_FUNCTIONAL_STATE(NewState));
  10284. if (NewState != DISABLE)
  10285. {
  10286. /* Enable the 8x Oversampling mode by setting the OVER8 bit in the CR1 register */
  10287. USARTx->CR1 |= CR1_OVER8_Set;
  10288. }
  10289. else
  10290. {
  10291. /* Disable the 8x Oversampling mode by clearing the OVER8 bit in the CR1 register */
  10292. USARTx->CR1 &= CR1_OVER8_Reset;
  10293. }
  10294. }
  10295. /**
  10296. * @brief Enables or disables the USART's one bit sampling method.
  10297. * @param USARTx: Select the USART or the UART peripheral.
  10298. * This parameter can be one of the following values:
  10299. * USART1, USART2, USART3, UART4 or UART5.
  10300. * @param NewState: new state of the USART one bit sampling method.
  10301. * This parameter can be: ENABLE or DISABLE.
  10302. * @retval None
  10303. */
  10304. void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState)
  10305. {
  10306. /* Check the parameters */
  10307. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10308. assert_param(IS_FUNCTIONAL_STATE(NewState));
  10309. if (NewState != DISABLE)
  10310. {
  10311. /* Enable the one bit method by setting the ONEBITE bit in the CR3 register */
  10312. USARTx->CR3 |= CR3_ONEBITE_Set;
  10313. }
  10314. else
  10315. {
  10316. /* Disable tthe one bit method by clearing the ONEBITE bit in the CR3 register */
  10317. USARTx->CR3 &= CR3_ONEBITE_Reset;
  10318. }
  10319. }
  10320. /**
  10321. * @brief Configures the USART's IrDA interface.
  10322. * @param USARTx: Select the USART or the UART peripheral.
  10323. * This parameter can be one of the following values:
  10324. * USART1, USART2, USART3, UART4 or UART5.
  10325. * @param USART_IrDAMode: specifies the IrDA mode.
  10326. * This parameter can be one of the following values:
  10327. * @arg USART_IrDAMode_LowPower
  10328. * @arg USART_IrDAMode_Normal
  10329. * @retval None
  10330. */
  10331. void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode)
  10332. {
  10333. /* Check the parameters */
  10334. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10335. assert_param(IS_USART_IRDA_MODE(USART_IrDAMode));
  10336. USARTx->CR3 &= CR3_IRLP_Mask;
  10337. USARTx->CR3 |= USART_IrDAMode;
  10338. }
  10339. /**
  10340. * @brief Enables or disables the USART's IrDA interface.
  10341. * @param USARTx: Select the USART or the UART peripheral.
  10342. * This parameter can be one of the following values:
  10343. * USART1, USART2, USART3, UART4 or UART5.
  10344. * @param NewState: new state of the IrDA mode.
  10345. * This parameter can be: ENABLE or DISABLE.
  10346. * @retval None
  10347. */
  10348. void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState)
  10349. {
  10350. /* Check the parameters */
  10351. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10352. assert_param(IS_FUNCTIONAL_STATE(NewState));
  10353. if (NewState != DISABLE)
  10354. {
  10355. /* Enable the IrDA mode by setting the IREN bit in the CR3 register */
  10356. USARTx->CR3 |= CR3_IREN_Set;
  10357. }
  10358. else
  10359. {
  10360. /* Disable the IrDA mode by clearing the IREN bit in the CR3 register */
  10361. USARTx->CR3 &= CR3_IREN_Reset;
  10362. }
  10363. }
  10364. /**
  10365. * @brief Checks whether the specified USART flag is set or not.
  10366. * @param USARTx: Select the USART or the UART peripheral.
  10367. * This parameter can be one of the following values:
  10368. * USART1, USART2, USART3, UART4 or UART5.
  10369. * @param USART_FLAG: specifies the flag to check.
  10370. * This parameter can be one of the following values:
  10371. * @arg USART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5)
  10372. * @arg USART_FLAG_LBD: LIN Break detection flag
  10373. * @arg USART_FLAG_TXE: Transmit data register empty flag
  10374. * @arg USART_FLAG_TC: Transmission Complete flag
  10375. * @arg USART_FLAG_RXNE: Receive data register not empty flag
  10376. * @arg USART_FLAG_IDLE: Idle Line detection flag
  10377. * @arg USART_FLAG_ORE: OverRun Error flag
  10378. * @arg USART_FLAG_NE: Noise Error flag
  10379. * @arg USART_FLAG_FE: Framing Error flag
  10380. * @arg USART_FLAG_PE: Parity Error flag
  10381. * @retval The new state of USART_FLAG (SET or RESET).
  10382. */
  10383. FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG)
  10384. {
  10385. FlagStatus bitstatus = RESET;
  10386. /* Check the parameters */
  10387. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10388. assert_param(IS_USART_FLAG(USART_FLAG));
  10389. /* The CTS flag is not available for UART4 and UART5 */
  10390. if (USART_FLAG == USART_FLAG_CTS)
  10391. {
  10392. assert_param(IS_USART_123_PERIPH(USARTx));
  10393. }
  10394. if ((USARTx->SR & USART_FLAG) != (uint16_t)RESET)
  10395. {
  10396. bitstatus = SET;
  10397. }
  10398. else
  10399. {
  10400. bitstatus = RESET;
  10401. }
  10402. return bitstatus;
  10403. }
  10404. /**
  10405. * @brief Clears the USARTx's pending flags.
  10406. * @param USARTx: Select the USART or the UART peripheral.
  10407. * This parameter can be one of the following values:
  10408. * USART1, USART2, USART3, UART4 or UART5.
  10409. * @param USART_FLAG: specifies the flag to clear.
  10410. * This parameter can be any combination of the following values:
  10411. * @arg USART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5).
  10412. * @arg USART_FLAG_LBD: LIN Break detection flag.
  10413. * @arg USART_FLAG_TC: Transmission Complete flag.
  10414. * @arg USART_FLAG_RXNE: Receive data register not empty flag.
  10415. *
  10416. * @note
  10417. * - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
  10418. * error) and IDLE (Idle line detected) flags are cleared by software
  10419. * sequence: a read operation to USART_SR register (USART_GetFlagStatus())
  10420. * followed by a read operation to USART_DR register (USART_ReceiveData()).
  10421. * - RXNE flag can be also cleared by a read to the USART_DR register
  10422. * (USART_ReceiveData()).
  10423. * - TC flag can be also cleared by software sequence: a read operation to
  10424. * USART_SR register (USART_GetFlagStatus()) followed by a write operation
  10425. * to USART_DR register (USART_SendData()).
  10426. * - TXE flag is cleared only by a write to the USART_DR register
  10427. * (USART_SendData()).
  10428. * @retval None
  10429. */
  10430. void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG)
  10431. {
  10432. /* Check the parameters */
  10433. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10434. assert_param(IS_USART_CLEAR_FLAG(USART_FLAG));
  10435. /* The CTS flag is not available for UART4 and UART5 */
  10436. if ((USART_FLAG & USART_FLAG_CTS) == USART_FLAG_CTS)
  10437. {
  10438. assert_param(IS_USART_123_PERIPH(USARTx));
  10439. }
  10440. USARTx->SR = (uint16_t)~USART_FLAG;
  10441. }
  10442. /**
  10443. * @brief Checks whether the specified USART interrupt has occurred or not.
  10444. * @param USARTx: Select the USART or the UART peripheral.
  10445. * This parameter can be one of the following values:
  10446. * USART1, USART2, USART3, UART4 or UART5.
  10447. * @param USART_IT: specifies the USART interrupt source to check.
  10448. * This parameter can be one of the following values:
  10449. * @arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
  10450. * @arg USART_IT_LBD: LIN Break detection interrupt
  10451. * @arg USART_IT_TXE: Tansmit Data Register empty interrupt
  10452. * @arg USART_IT_TC: Transmission complete interrupt
  10453. * @arg USART_IT_RXNE: Receive Data register not empty interrupt
  10454. * @arg USART_IT_IDLE: Idle line detection interrupt
  10455. * @arg USART_IT_ORE: OverRun Error interrupt
  10456. * @arg USART_IT_NE: Noise Error interrupt
  10457. * @arg USART_IT_FE: Framing Error interrupt
  10458. * @arg USART_IT_PE: Parity Error interrupt
  10459. * @retval The new state of USART_IT (SET or RESET).
  10460. */
  10461. ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT)
  10462. {
  10463. uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
  10464. ITStatus bitstatus = RESET;
  10465. /* Check the parameters */
  10466. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10467. assert_param(IS_USART_GET_IT(USART_IT));
  10468. /* The CTS interrupt is not available for UART4 and UART5 */
  10469. if (USART_IT == USART_IT_CTS)
  10470. {
  10471. assert_param(IS_USART_123_PERIPH(USARTx));
  10472. }
  10473. /* Get the USART register index */
  10474. usartreg = (((uint8_t)USART_IT) >> 0x05);
  10475. /* Get the interrupt position */
  10476. itmask = USART_IT & IT_Mask;
  10477. itmask = (uint32_t)0x01 << itmask;
  10478. if (usartreg == 0x01) /* The IT is in CR1 register */
  10479. {
  10480. itmask &= USARTx->CR1;
  10481. }
  10482. else if (usartreg == 0x02) /* The IT is in CR2 register */
  10483. {
  10484. itmask &= USARTx->CR2;
  10485. }
  10486. else /* The IT is in CR3 register */
  10487. {
  10488. itmask &= USARTx->CR3;
  10489. }
  10490. bitpos = USART_IT >> 0x08;
  10491. bitpos = (uint32_t)0x01 << bitpos;
  10492. bitpos &= USARTx->SR;
  10493. if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET))
  10494. {
  10495. bitstatus = SET;
  10496. }
  10497. else
  10498. {
  10499. bitstatus = RESET;
  10500. }
  10501. return bitstatus;
  10502. }
  10503. /**
  10504. * @brief Clears the USARTx's interrupt pending bits.
  10505. * @param USARTx: Select the USART or the UART peripheral.
  10506. * This parameter can be one of the following values:
  10507. * USART1, USART2, USART3, UART4 or UART5.
  10508. * @param USART_IT: specifies the interrupt pending bit to clear.
  10509. * This parameter can be one of the following values:
  10510. * @arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
  10511. * @arg USART_IT_LBD: LIN Break detection interrupt
  10512. * @arg USART_IT_TC: Transmission complete interrupt.
  10513. * @arg USART_IT_RXNE: Receive Data register not empty interrupt.
  10514. *
  10515. * @note
  10516. * - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
  10517. * error) and IDLE (Idle line detected) pending bits are cleared by
  10518. * software sequence: a read operation to USART_SR register
  10519. * (USART_GetITStatus()) followed by a read operation to USART_DR register
  10520. * (USART_ReceiveData()).
  10521. * - RXNE pending bit can be also cleared by a read to the USART_DR register
  10522. * (USART_ReceiveData()).
  10523. * - TC pending bit can be also cleared by software sequence: a read
  10524. * operation to USART_SR register (USART_GetITStatus()) followed by a write
  10525. * operation to USART_DR register (USART_SendData()).
  10526. * - TXE pending bit is cleared only by a write to the USART_DR register
  10527. * (USART_SendData()).
  10528. * @retval None
  10529. */
  10530. void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT)
  10531. {
  10532. uint16_t bitpos = 0x00, itmask = 0x00;
  10533. /* Check the parameters */
  10534. assert_param(IS_USART_ALL_PERIPH(USARTx));
  10535. assert_param(IS_USART_CLEAR_IT(USART_IT));
  10536. /* The CTS interrupt is not available for UART4 and UART5 */
  10537. if (USART_IT == USART_IT_CTS)
  10538. {
  10539. assert_param(IS_USART_123_PERIPH(USARTx));
  10540. }
  10541. bitpos = USART_IT >> 0x08;
  10542. itmask = ((uint16_t)0x01 << (uint16_t)bitpos);
  10543. USARTx->SR = (uint16_t)~itmask;
  10544. }
  10545. /**
  10546. * @}
  10547. */
  10548. /**
  10549. * @}
  10550. */
  10551. /**
  10552. * @}
  10553. */
  10554. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  10555. /**
  10556. ******************************************************************************
  10557. * @file misc.c
  10558. * @author MCD Application Team
  10559. * @version V3.5.0
  10560. * @date 11-March-2011
  10561. * @brief This file provides all the miscellaneous firmware functions (add-on
  10562. * to CMSIS functions).
  10563. ******************************************************************************
  10564. * @attention
  10565. *
  10566. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  10567. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  10568. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  10569. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  10570. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  10571. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  10572. *
  10573. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  10574. ******************************************************************************
  10575. */
  10576. /* Includes ------------------------------------------------------------------*/
  10577. #include "misc.h"
  10578. /** @addtogroup STM32F10x_StdPeriph_Driver
  10579. * @{
  10580. */
  10581. /** @defgroup MISC
  10582. * @brief MISC driver modules
  10583. * @{
  10584. */
  10585. /** @defgroup MISC_Private_TypesDefinitions
  10586. * @{
  10587. */
  10588. /**
  10589. * @}
  10590. */
  10591. /** @defgroup MISC_Private_Defines
  10592. * @{
  10593. */
  10594. #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
  10595. /**
  10596. * @}
  10597. */
  10598. /** @defgroup MISC_Private_Macros
  10599. * @{
  10600. */
  10601. /**
  10602. * @}
  10603. */
  10604. /** @defgroup MISC_Private_Variables
  10605. * @{
  10606. */
  10607. /**
  10608. * @}
  10609. */
  10610. /** @defgroup MISC_Private_FunctionPrototypes
  10611. * @{
  10612. */
  10613. /**
  10614. * @}
  10615. */
  10616. /** @defgroup MISC_Private_Functions
  10617. * @{
  10618. */
  10619. /**
  10620. * @brief Configures the priority grouping: pre-emption priority and subpriority.
  10621. * @param NVIC_PriorityGroup: specifies the priority grouping bits length.
  10622. * This parameter can be one of the following values:
  10623. * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
  10624. * 4 bits for subpriority
  10625. * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
  10626. * 3 bits for subpriority
  10627. * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
  10628. * 2 bits for subpriority
  10629. * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
  10630. * 1 bits for subpriority
  10631. * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
  10632. * 0 bits for subpriority
  10633. * @retval None
  10634. */
  10635. void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
  10636. {
  10637. /* Check the parameters */
  10638. assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
  10639. /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
  10640. SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
  10641. }
  10642. /**
  10643. * @brief Initializes the NVIC peripheral according to the specified
  10644. * parameters in the NVIC_InitStruct.
  10645. * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
  10646. * the configuration information for the specified NVIC peripheral.
  10647. * @retval None
  10648. */
  10649. void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
  10650. {
  10651. uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
  10652. /* Check the parameters */
  10653. assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
  10654. assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
  10655. assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
  10656. if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
  10657. {
  10658. /* Compute the Corresponding IRQ Priority --------------------------------*/
  10659. tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
  10660. tmppre = (0x4 - tmppriority);
  10661. tmpsub = tmpsub >> tmppriority;
  10662. tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
  10663. tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
  10664. tmppriority = tmppriority << 0x04;
  10665. NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
  10666. /* Enable the Selected IRQ Channels --------------------------------------*/
  10667. NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
  10668. (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
  10669. }
  10670. else
  10671. {
  10672. /* Disable the Selected IRQ Channels -------------------------------------*/
  10673. NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
  10674. (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
  10675. }
  10676. }
  10677. /**
  10678. * @brief Sets the vector table location and Offset.
  10679. * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
  10680. * This parameter can be one of the following values:
  10681. * @arg NVIC_VectTab_RAM
  10682. * @arg NVIC_VectTab_FLASH
  10683. * @param Offset: Vector Table base offset field. This value must be a multiple
  10684. * of 0x200.
  10685. * @retval None
  10686. */
  10687. void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
  10688. {
  10689. /* Check the parameters */
  10690. assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
  10691. assert_param(IS_NVIC_OFFSET(Offset));
  10692. SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
  10693. }
  10694. /**
  10695. * @brief Selects the condition for the system to enter low power mode.
  10696. * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
  10697. * This parameter can be one of the following values:
  10698. * @arg NVIC_LP_SEVONPEND
  10699. * @arg NVIC_LP_SLEEPDEEP
  10700. * @arg NVIC_LP_SLEEPONEXIT
  10701. * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
  10702. * @retval None
  10703. */
  10704. void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
  10705. {
  10706. /* Check the parameters */
  10707. assert_param(IS_NVIC_LP(LowPowerMode));
  10708. assert_param(IS_FUNCTIONAL_STATE(NewState));
  10709. if (NewState != DISABLE)
  10710. {
  10711. SCB->SCR |= LowPowerMode;
  10712. }
  10713. else
  10714. {
  10715. SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
  10716. }
  10717. }
  10718. /**
  10719. * @brief Configures the SysTick clock source.
  10720. * @param SysTick_CLKSource: specifies the SysTick clock source.
  10721. * This parameter can be one of the following values:
  10722. * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
  10723. * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
  10724. * @retval None
  10725. */
  10726. void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
  10727. {
  10728. /* Check the parameters */
  10729. assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
  10730. if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
  10731. {
  10732. SysTick->CTRL |= SysTick_CLKSource_HCLK;
  10733. }
  10734. else
  10735. {
  10736. SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
  10737. }
  10738. }
  10739. /**
  10740. * @}
  10741. */
  10742. /**
  10743. * @}
  10744. */
  10745. /**
  10746. * @}
  10747. */
  10748. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  10749. /**
  10750. ******************************************************************************
  10751. * @file stm32f10x_dac.c
  10752. * @author MCD Application Team
  10753. * @version V3.5.0
  10754. * @date 11-March-2011
  10755. * @brief This file provides all the DAC firmware functions.
  10756. ******************************************************************************
  10757. * @attention
  10758. *
  10759. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  10760. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  10761. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  10762. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  10763. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  10764. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  10765. *
  10766. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  10767. ******************************************************************************
  10768. */
  10769. /* Includes ------------------------------------------------------------------*/
  10770. #include "stm32f10x_dac.h"
  10771. #include "stm32f10x_rcc.h"
  10772. /** @addtogroup STM32F10x_StdPeriph_Driver
  10773. * @{
  10774. */
  10775. /** @defgroup DAC
  10776. * @brief DAC driver modules
  10777. * @{
  10778. */
  10779. /** @defgroup DAC_Private_TypesDefinitions
  10780. * @{
  10781. */
  10782. /**
  10783. * @}
  10784. */
  10785. /** @defgroup DAC_Private_Defines
  10786. * @{
  10787. */
  10788. /* CR register Mask */
  10789. #define CR_CLEAR_MASK ((uint32_t)0x00000FFE)
  10790. /* DAC Dual Channels SWTRIG masks */
  10791. #define DUAL_SWTRIG_SET ((uint32_t)0x00000003)
  10792. #define DUAL_SWTRIG_RESET ((uint32_t)0xFFFFFFFC)
  10793. /* DHR registers offsets */
  10794. #define DHR12R1_OFFSET ((uint32_t)0x00000008)
  10795. #define DHR12R2_OFFSET ((uint32_t)0x00000014)
  10796. #define DHR12RD_OFFSET ((uint32_t)0x00000020)
  10797. /* DOR register offset */
  10798. #define DOR_OFFSET ((uint32_t)0x0000002C)
  10799. /**
  10800. * @}
  10801. */
  10802. /** @defgroup DAC_Private_Macros
  10803. * @{
  10804. */
  10805. /**
  10806. * @}
  10807. */
  10808. /** @defgroup DAC_Private_Variables
  10809. * @{
  10810. */
  10811. /**
  10812. * @}
  10813. */
  10814. /** @defgroup DAC_Private_FunctionPrototypes
  10815. * @{
  10816. */
  10817. /**
  10818. * @}
  10819. */
  10820. /** @defgroup DAC_Private_Functions
  10821. * @{
  10822. */
  10823. /**
  10824. * @brief Deinitializes the DAC peripheral registers to their default reset values.
  10825. * @param None
  10826. * @retval None
  10827. */
  10828. void DAC_DeInit(void)
  10829. {
  10830. /* Enable DAC reset state */
  10831. RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, ENABLE);
  10832. /* Release DAC from reset state */
  10833. RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, DISABLE);
  10834. }
  10835. /**
  10836. * @brief Initializes the DAC peripheral according to the specified
  10837. * parameters in the DAC_InitStruct.
  10838. * @param DAC_Channel: the selected DAC channel.
  10839. * This parameter can be one of the following values:
  10840. * @arg DAC_Channel_1: DAC Channel1 selected
  10841. * @arg DAC_Channel_2: DAC Channel2 selected
  10842. * @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure that
  10843. * contains the configuration information for the specified DAC channel.
  10844. * @retval None
  10845. */
  10846. void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct)
  10847. {
  10848. uint32_t tmpreg1 = 0, tmpreg2 = 0;
  10849. /* Check the DAC parameters */
  10850. assert_param(IS_DAC_TRIGGER(DAC_InitStruct->DAC_Trigger));
  10851. assert_param(IS_DAC_GENERATE_WAVE(DAC_InitStruct->DAC_WaveGeneration));
  10852. assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude));
  10853. assert_param(IS_DAC_OUTPUT_BUFFER_STATE(DAC_InitStruct->DAC_OutputBuffer));
  10854. /*---------------------------- DAC CR Configuration --------------------------*/
  10855. /* Get the DAC CR value */
  10856. tmpreg1 = DAC->CR;
  10857. /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */
  10858. tmpreg1 &= ~(CR_CLEAR_MASK << DAC_Channel);
  10859. /* Configure for the selected DAC channel: buffer output, trigger, wave generation,
  10860. mask/amplitude for wave generation */
  10861. /* Set TSELx and TENx bits according to DAC_Trigger value */
  10862. /* Set WAVEx bits according to DAC_WaveGeneration value */
  10863. /* Set MAMPx bits according to DAC_LFSRUnmask_TriangleAmplitude value */
  10864. /* Set BOFFx bit according to DAC_OutputBuffer value */
  10865. tmpreg2 = (DAC_InitStruct->DAC_Trigger | DAC_InitStruct->DAC_WaveGeneration |
  10866. DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude | DAC_InitStruct->DAC_OutputBuffer);
  10867. /* Calculate CR register value depending on DAC_Channel */
  10868. tmpreg1 |= tmpreg2 << DAC_Channel;
  10869. /* Write to DAC CR */
  10870. DAC->CR = tmpreg1;
  10871. }
  10872. /**
  10873. * @brief Fills each DAC_InitStruct member with its default value.
  10874. * @param DAC_InitStruct : pointer to a DAC_InitTypeDef structure which will
  10875. * be initialized.
  10876. * @retval None
  10877. */
  10878. void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct)
  10879. {
  10880. /*--------------- Reset DAC init structure parameters values -----------------*/
  10881. /* Initialize the DAC_Trigger member */
  10882. DAC_InitStruct->DAC_Trigger = DAC_Trigger_None;
  10883. /* Initialize the DAC_WaveGeneration member */
  10884. DAC_InitStruct->DAC_WaveGeneration = DAC_WaveGeneration_None;
  10885. /* Initialize the DAC_LFSRUnmask_TriangleAmplitude member */
  10886. DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
  10887. /* Initialize the DAC_OutputBuffer member */
  10888. DAC_InitStruct->DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  10889. }
  10890. /**
  10891. * @brief Enables or disables the specified DAC channel.
  10892. * @param DAC_Channel: the selected DAC channel.
  10893. * This parameter can be one of the following values:
  10894. * @arg DAC_Channel_1: DAC Channel1 selected
  10895. * @arg DAC_Channel_2: DAC Channel2 selected
  10896. * @param NewState: new state of the DAC channel.
  10897. * This parameter can be: ENABLE or DISABLE.
  10898. * @retval None
  10899. */
  10900. void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState)
  10901. {
  10902. /* Check the parameters */
  10903. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  10904. assert_param(IS_FUNCTIONAL_STATE(NewState));
  10905. if (NewState != DISABLE)
  10906. {
  10907. /* Enable the selected DAC channel */
  10908. DAC->CR |= (DAC_CR_EN1 << DAC_Channel);
  10909. }
  10910. else
  10911. {
  10912. /* Disable the selected DAC channel */
  10913. DAC->CR &= ~(DAC_CR_EN1 << DAC_Channel);
  10914. }
  10915. }
  10916. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  10917. /**
  10918. * @brief Enables or disables the specified DAC interrupts.
  10919. * @param DAC_Channel: the selected DAC channel.
  10920. * This parameter can be one of the following values:
  10921. * @arg DAC_Channel_1: DAC Channel1 selected
  10922. * @arg DAC_Channel_2: DAC Channel2 selected
  10923. * @param DAC_IT: specifies the DAC interrupt sources to be enabled or disabled.
  10924. * This parameter can be the following values:
  10925. * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
  10926. * @param NewState: new state of the specified DAC interrupts.
  10927. * This parameter can be: ENABLE or DISABLE.
  10928. * @retval None
  10929. */
  10930. void DAC_ITConfig(uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState)
  10931. {
  10932. /* Check the parameters */
  10933. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  10934. assert_param(IS_FUNCTIONAL_STATE(NewState));
  10935. assert_param(IS_DAC_IT(DAC_IT));
  10936. if (NewState != DISABLE)
  10937. {
  10938. /* Enable the selected DAC interrupts */
  10939. DAC->CR |= (DAC_IT << DAC_Channel);
  10940. }
  10941. else
  10942. {
  10943. /* Disable the selected DAC interrupts */
  10944. DAC->CR &= (~(uint32_t)(DAC_IT << DAC_Channel));
  10945. }
  10946. }
  10947. #endif
  10948. /**
  10949. * @brief Enables or disables the specified DAC channel DMA request.
  10950. * @param DAC_Channel: the selected DAC channel.
  10951. * This parameter can be one of the following values:
  10952. * @arg DAC_Channel_1: DAC Channel1 selected
  10953. * @arg DAC_Channel_2: DAC Channel2 selected
  10954. * @param NewState: new state of the selected DAC channel DMA request.
  10955. * This parameter can be: ENABLE or DISABLE.
  10956. * @retval None
  10957. */
  10958. void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState)
  10959. {
  10960. /* Check the parameters */
  10961. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  10962. assert_param(IS_FUNCTIONAL_STATE(NewState));
  10963. if (NewState != DISABLE)
  10964. {
  10965. /* Enable the selected DAC channel DMA request */
  10966. DAC->CR |= (DAC_CR_DMAEN1 << DAC_Channel);
  10967. }
  10968. else
  10969. {
  10970. /* Disable the selected DAC channel DMA request */
  10971. DAC->CR &= ~(DAC_CR_DMAEN1 << DAC_Channel);
  10972. }
  10973. }
  10974. /**
  10975. * @brief Enables or disables the selected DAC channel software trigger.
  10976. * @param DAC_Channel: the selected DAC channel.
  10977. * This parameter can be one of the following values:
  10978. * @arg DAC_Channel_1: DAC Channel1 selected
  10979. * @arg DAC_Channel_2: DAC Channel2 selected
  10980. * @param NewState: new state of the selected DAC channel software trigger.
  10981. * This parameter can be: ENABLE or DISABLE.
  10982. * @retval None
  10983. */
  10984. void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState)
  10985. {
  10986. /* Check the parameters */
  10987. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  10988. assert_param(IS_FUNCTIONAL_STATE(NewState));
  10989. if (NewState != DISABLE)
  10990. {
  10991. /* Enable software trigger for the selected DAC channel */
  10992. DAC->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4);
  10993. }
  10994. else
  10995. {
  10996. /* Disable software trigger for the selected DAC channel */
  10997. DAC->SWTRIGR &= ~((uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4));
  10998. }
  10999. }
  11000. /**
  11001. * @brief Enables or disables simultaneously the two DAC channels software
  11002. * triggers.
  11003. * @param NewState: new state of the DAC channels software triggers.
  11004. * This parameter can be: ENABLE or DISABLE.
  11005. * @retval None
  11006. */
  11007. void DAC_DualSoftwareTriggerCmd(FunctionalState NewState)
  11008. {
  11009. /* Check the parameters */
  11010. assert_param(IS_FUNCTIONAL_STATE(NewState));
  11011. if (NewState != DISABLE)
  11012. {
  11013. /* Enable software trigger for both DAC channels */
  11014. DAC->SWTRIGR |= DUAL_SWTRIG_SET ;
  11015. }
  11016. else
  11017. {
  11018. /* Disable software trigger for both DAC channels */
  11019. DAC->SWTRIGR &= DUAL_SWTRIG_RESET;
  11020. }
  11021. }
  11022. /**
  11023. * @brief Enables or disables the selected DAC channel wave generation.
  11024. * @param DAC_Channel: the selected DAC channel.
  11025. * This parameter can be one of the following values:
  11026. * @arg DAC_Channel_1: DAC Channel1 selected
  11027. * @arg DAC_Channel_2: DAC Channel2 selected
  11028. * @param DAC_Wave: Specifies the wave type to enable or disable.
  11029. * This parameter can be one of the following values:
  11030. * @arg DAC_Wave_Noise: noise wave generation
  11031. * @arg DAC_Wave_Triangle: triangle wave generation
  11032. * @param NewState: new state of the selected DAC channel wave generation.
  11033. * This parameter can be: ENABLE or DISABLE.
  11034. * @retval None
  11035. */
  11036. void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState)
  11037. {
  11038. /* Check the parameters */
  11039. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  11040. assert_param(IS_DAC_WAVE(DAC_Wave));
  11041. assert_param(IS_FUNCTIONAL_STATE(NewState));
  11042. if (NewState != DISABLE)
  11043. {
  11044. /* Enable the selected wave generation for the selected DAC channel */
  11045. DAC->CR |= DAC_Wave << DAC_Channel;
  11046. }
  11047. else
  11048. {
  11049. /* Disable the selected wave generation for the selected DAC channel */
  11050. DAC->CR &= ~(DAC_Wave << DAC_Channel);
  11051. }
  11052. }
  11053. /**
  11054. * @brief Set the specified data holding register value for DAC channel1.
  11055. * @param DAC_Align: Specifies the data alignment for DAC channel1.
  11056. * This parameter can be one of the following values:
  11057. * @arg DAC_Align_8b_R: 8bit right data alignment selected
  11058. * @arg DAC_Align_12b_L: 12bit left data alignment selected
  11059. * @arg DAC_Align_12b_R: 12bit right data alignment selected
  11060. * @param Data : Data to be loaded in the selected data holding register.
  11061. * @retval None
  11062. */
  11063. void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data)
  11064. {
  11065. __IO uint32_t tmp = 0;
  11066. /* Check the parameters */
  11067. assert_param(IS_DAC_ALIGN(DAC_Align));
  11068. assert_param(IS_DAC_DATA(Data));
  11069. tmp = (uint32_t)DAC_BASE;
  11070. tmp += DHR12R1_OFFSET + DAC_Align;
  11071. /* Set the DAC channel1 selected data holding register */
  11072. *(__IO uint32_t *) tmp = Data;
  11073. }
  11074. /**
  11075. * @brief Set the specified data holding register value for DAC channel2.
  11076. * @param DAC_Align: Specifies the data alignment for DAC channel2.
  11077. * This parameter can be one of the following values:
  11078. * @arg DAC_Align_8b_R: 8bit right data alignment selected
  11079. * @arg DAC_Align_12b_L: 12bit left data alignment selected
  11080. * @arg DAC_Align_12b_R: 12bit right data alignment selected
  11081. * @param Data : Data to be loaded in the selected data holding register.
  11082. * @retval None
  11083. */
  11084. void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data)
  11085. {
  11086. __IO uint32_t tmp = 0;
  11087. /* Check the parameters */
  11088. assert_param(IS_DAC_ALIGN(DAC_Align));
  11089. assert_param(IS_DAC_DATA(Data));
  11090. tmp = (uint32_t)DAC_BASE;
  11091. tmp += DHR12R2_OFFSET + DAC_Align;
  11092. /* Set the DAC channel2 selected data holding register */
  11093. *(__IO uint32_t *)tmp = Data;
  11094. }
  11095. /**
  11096. * @brief Set the specified data holding register value for dual channel
  11097. * DAC.
  11098. * @param DAC_Align: Specifies the data alignment for dual channel DAC.
  11099. * This parameter can be one of the following values:
  11100. * @arg DAC_Align_8b_R: 8bit right data alignment selected
  11101. * @arg DAC_Align_12b_L: 12bit left data alignment selected
  11102. * @arg DAC_Align_12b_R: 12bit right data alignment selected
  11103. * @param Data2: Data for DAC Channel2 to be loaded in the selected data
  11104. * holding register.
  11105. * @param Data1: Data for DAC Channel1 to be loaded in the selected data
  11106. * holding register.
  11107. * @retval None
  11108. */
  11109. void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1)
  11110. {
  11111. uint32_t data = 0, tmp = 0;
  11112. /* Check the parameters */
  11113. assert_param(IS_DAC_ALIGN(DAC_Align));
  11114. assert_param(IS_DAC_DATA(Data1));
  11115. assert_param(IS_DAC_DATA(Data2));
  11116. /* Calculate and set dual DAC data holding register value */
  11117. if (DAC_Align == DAC_Align_8b_R)
  11118. {
  11119. data = ((uint32_t)Data2 << 8) | Data1;
  11120. }
  11121. else
  11122. {
  11123. data = ((uint32_t)Data2 << 16) | Data1;
  11124. }
  11125. tmp = (uint32_t)DAC_BASE;
  11126. tmp += DHR12RD_OFFSET + DAC_Align;
  11127. /* Set the dual DAC selected data holding register */
  11128. *(__IO uint32_t *)tmp = data;
  11129. }
  11130. /**
  11131. * @brief Returns the last data output value of the selected DAC channel.
  11132. * @param DAC_Channel: the selected DAC channel.
  11133. * This parameter can be one of the following values:
  11134. * @arg DAC_Channel_1: DAC Channel1 selected
  11135. * @arg DAC_Channel_2: DAC Channel2 selected
  11136. * @retval The selected DAC channel data output value.
  11137. */
  11138. uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel)
  11139. {
  11140. __IO uint32_t tmp = 0;
  11141. /* Check the parameters */
  11142. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  11143. tmp = (uint32_t) DAC_BASE ;
  11144. tmp += DOR_OFFSET + ((uint32_t)DAC_Channel >> 2);
  11145. /* Returns the DAC channel data output register value */
  11146. return (uint16_t) (*(__IO uint32_t*) tmp);
  11147. }
  11148. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  11149. /**
  11150. * @brief Checks whether the specified DAC flag is set or not.
  11151. * @param DAC_Channel: thee selected DAC channel.
  11152. * This parameter can be one of the following values:
  11153. * @arg DAC_Channel_1: DAC Channel1 selected
  11154. * @arg DAC_Channel_2: DAC Channel2 selected
  11155. * @param DAC_FLAG: specifies the flag to check.
  11156. * This parameter can be only of the following value:
  11157. * @arg DAC_FLAG_DMAUDR: DMA underrun flag
  11158. * @retval The new state of DAC_FLAG (SET or RESET).
  11159. */
  11160. FlagStatus DAC_GetFlagStatus(uint32_t DAC_Channel, uint32_t DAC_FLAG)
  11161. {
  11162. FlagStatus bitstatus = RESET;
  11163. /* Check the parameters */
  11164. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  11165. assert_param(IS_DAC_FLAG(DAC_FLAG));
  11166. /* Check the status of the specified DAC flag */
  11167. if ((DAC->SR & (DAC_FLAG << DAC_Channel)) != (uint8_t)RESET)
  11168. {
  11169. /* DAC_FLAG is set */
  11170. bitstatus = SET;
  11171. }
  11172. else
  11173. {
  11174. /* DAC_FLAG is reset */
  11175. bitstatus = RESET;
  11176. }
  11177. /* Return the DAC_FLAG status */
  11178. return bitstatus;
  11179. }
  11180. /**
  11181. * @brief Clears the DAC channelx's pending flags.
  11182. * @param DAC_Channel: the selected DAC channel.
  11183. * This parameter can be one of the following values:
  11184. * @arg DAC_Channel_1: DAC Channel1 selected
  11185. * @arg DAC_Channel_2: DAC Channel2 selected
  11186. * @param DAC_FLAG: specifies the flag to clear.
  11187. * This parameter can be of the following value:
  11188. * @arg DAC_FLAG_DMAUDR: DMA underrun flag
  11189. * @retval None
  11190. */
  11191. void DAC_ClearFlag(uint32_t DAC_Channel, uint32_t DAC_FLAG)
  11192. {
  11193. /* Check the parameters */
  11194. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  11195. assert_param(IS_DAC_FLAG(DAC_FLAG));
  11196. /* Clear the selected DAC flags */
  11197. DAC->SR = (DAC_FLAG << DAC_Channel);
  11198. }
  11199. /**
  11200. * @brief Checks whether the specified DAC interrupt has occurred or not.
  11201. * @param DAC_Channel: the selected DAC channel.
  11202. * This parameter can be one of the following values:
  11203. * @arg DAC_Channel_1: DAC Channel1 selected
  11204. * @arg DAC_Channel_2: DAC Channel2 selected
  11205. * @param DAC_IT: specifies the DAC interrupt source to check.
  11206. * This parameter can be the following values:
  11207. * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
  11208. * @retval The new state of DAC_IT (SET or RESET).
  11209. */
  11210. ITStatus DAC_GetITStatus(uint32_t DAC_Channel, uint32_t DAC_IT)
  11211. {
  11212. ITStatus bitstatus = RESET;
  11213. uint32_t enablestatus = 0;
  11214. /* Check the parameters */
  11215. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  11216. assert_param(IS_DAC_IT(DAC_IT));
  11217. /* Get the DAC_IT enable bit status */
  11218. enablestatus = (DAC->CR & (DAC_IT << DAC_Channel)) ;
  11219. /* Check the status of the specified DAC interrupt */
  11220. if (((DAC->SR & (DAC_IT << DAC_Channel)) != (uint32_t)RESET) && enablestatus)
  11221. {
  11222. /* DAC_IT is set */
  11223. bitstatus = SET;
  11224. }
  11225. else
  11226. {
  11227. /* DAC_IT is reset */
  11228. bitstatus = RESET;
  11229. }
  11230. /* Return the DAC_IT status */
  11231. return bitstatus;
  11232. }
  11233. /**
  11234. * @brief Clears the DAC channelx's interrupt pending bits.
  11235. * @param DAC_Channel: the selected DAC channel.
  11236. * This parameter can be one of the following values:
  11237. * @arg DAC_Channel_1: DAC Channel1 selected
  11238. * @arg DAC_Channel_2: DAC Channel2 selected
  11239. * @param DAC_IT: specifies the DAC interrupt pending bit to clear.
  11240. * This parameter can be the following values:
  11241. * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
  11242. * @retval None
  11243. */
  11244. void DAC_ClearITPendingBit(uint32_t DAC_Channel, uint32_t DAC_IT)
  11245. {
  11246. /* Check the parameters */
  11247. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  11248. assert_param(IS_DAC_IT(DAC_IT));
  11249. /* Clear the selected DAC interrupt pending bits */
  11250. DAC->SR = (DAC_IT << DAC_Channel);
  11251. }
  11252. #endif
  11253. /**
  11254. * @}
  11255. */
  11256. /**
  11257. * @}
  11258. */
  11259. /**
  11260. * @}
  11261. */
  11262. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  11263. /**
  11264. ******************************************************************************
  11265. * @file stm32f10x_sdio.c
  11266. * @author MCD Application Team
  11267. * @version V3.5.0
  11268. * @date 11-March-2011
  11269. * @brief This file provides all the SDIO firmware functions.
  11270. ******************************************************************************
  11271. * @attention
  11272. *
  11273. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  11274. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  11275. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  11276. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  11277. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  11278. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  11279. *
  11280. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  11281. ******************************************************************************
  11282. */
  11283. /* Includes ------------------------------------------------------------------*/
  11284. #include "stm32f10x_sdio.h"
  11285. #include "stm32f10x_rcc.h"
  11286. /** @addtogroup STM32F10x_StdPeriph_Driver
  11287. * @{
  11288. */
  11289. /** @defgroup SDIO
  11290. * @brief SDIO driver modules
  11291. * @{
  11292. */
  11293. /** @defgroup SDIO_Private_TypesDefinitions
  11294. * @{
  11295. */
  11296. /* ------------ SDIO registers bit address in the alias region ----------- */
  11297. #define SDIO_OFFSET (SDIO_BASE - PERIPH_BASE)
  11298. /* --- CLKCR Register ---*/
  11299. /* Alias word address of CLKEN bit */
  11300. #define CLKCR_OFFSET (SDIO_OFFSET + 0x04)
  11301. #define CLKEN_BitNumber 0x08
  11302. #define CLKCR_CLKEN_BB (PERIPH_BB_BASE + (CLKCR_OFFSET * 32) + (CLKEN_BitNumber * 4))
  11303. /* --- CMD Register ---*/
  11304. /* Alias word address of SDIOSUSPEND bit */
  11305. #define CMD_OFFSET (SDIO_OFFSET + 0x0C)
  11306. #define SDIOSUSPEND_BitNumber 0x0B
  11307. #define CMD_SDIOSUSPEND_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (SDIOSUSPEND_BitNumber * 4))
  11308. /* Alias word address of ENCMDCOMPL bit */
  11309. #define ENCMDCOMPL_BitNumber 0x0C
  11310. #define CMD_ENCMDCOMPL_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (ENCMDCOMPL_BitNumber * 4))
  11311. /* Alias word address of NIEN bit */
  11312. #define NIEN_BitNumber 0x0D
  11313. #define CMD_NIEN_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (NIEN_BitNumber * 4))
  11314. /* Alias word address of ATACMD bit */
  11315. #define ATACMD_BitNumber 0x0E
  11316. #define CMD_ATACMD_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (ATACMD_BitNumber * 4))
  11317. /* --- DCTRL Register ---*/
  11318. /* Alias word address of DMAEN bit */
  11319. #define DCTRL_OFFSET (SDIO_OFFSET + 0x2C)
  11320. #define DMAEN_BitNumber 0x03
  11321. #define DCTRL_DMAEN_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (DMAEN_BitNumber * 4))
  11322. /* Alias word address of RWSTART bit */
  11323. #define RWSTART_BitNumber 0x08
  11324. #define DCTRL_RWSTART_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWSTART_BitNumber * 4))
  11325. /* Alias word address of RWSTOP bit */
  11326. #define RWSTOP_BitNumber 0x09
  11327. #define DCTRL_RWSTOP_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWSTOP_BitNumber * 4))
  11328. /* Alias word address of RWMOD bit */
  11329. #define RWMOD_BitNumber 0x0A
  11330. #define DCTRL_RWMOD_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWMOD_BitNumber * 4))
  11331. /* Alias word address of SDIOEN bit */
  11332. #define SDIOEN_BitNumber 0x0B
  11333. #define DCTRL_SDIOEN_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (SDIOEN_BitNumber * 4))
  11334. /* ---------------------- SDIO registers bit mask ------------------------ */
  11335. /* --- CLKCR Register ---*/
  11336. /* CLKCR register clear mask */
  11337. #define CLKCR_CLEAR_MASK ((uint32_t)0xFFFF8100)
  11338. /* --- PWRCTRL Register ---*/
  11339. /* SDIO PWRCTRL Mask */
  11340. #define PWR_PWRCTRL_MASK ((uint32_t)0xFFFFFFFC)
  11341. /* --- DCTRL Register ---*/
  11342. /* SDIO DCTRL Clear Mask */
  11343. #define DCTRL_CLEAR_MASK ((uint32_t)0xFFFFFF08)
  11344. /* --- CMD Register ---*/
  11345. /* CMD Register clear mask */
  11346. #define CMD_CLEAR_MASK ((uint32_t)0xFFFFF800)
  11347. /* SDIO RESP Registers Address */
  11348. #define SDIO_RESP_ADDR ((uint32_t)(SDIO_BASE + 0x14))
  11349. /**
  11350. * @}
  11351. */
  11352. /** @defgroup SDIO_Private_Defines
  11353. * @{
  11354. */
  11355. /**
  11356. * @}
  11357. */
  11358. /** @defgroup SDIO_Private_Macros
  11359. * @{
  11360. */
  11361. /**
  11362. * @}
  11363. */
  11364. /** @defgroup SDIO_Private_Variables
  11365. * @{
  11366. */
  11367. /**
  11368. * @}
  11369. */
  11370. /** @defgroup SDIO_Private_FunctionPrototypes
  11371. * @{
  11372. */
  11373. /**
  11374. * @}
  11375. */
  11376. /** @defgroup SDIO_Private_Functions
  11377. * @{
  11378. */
  11379. /**
  11380. * @brief Deinitializes the SDIO peripheral registers to their default reset values.
  11381. * @param None
  11382. * @retval None
  11383. */
  11384. void SDIO_DeInit(void)
  11385. {
  11386. SDIO->POWER = 0x00000000;
  11387. SDIO->CLKCR = 0x00000000;
  11388. SDIO->ARG = 0x00000000;
  11389. SDIO->CMD = 0x00000000;
  11390. SDIO->DTIMER = 0x00000000;
  11391. SDIO->DLEN = 0x00000000;
  11392. SDIO->DCTRL = 0x00000000;
  11393. SDIO->ICR = 0x00C007FF;
  11394. SDIO->MASK = 0x00000000;
  11395. }
  11396. /**
  11397. * @brief Initializes the SDIO peripheral according to the specified
  11398. * parameters in the SDIO_InitStruct.
  11399. * @param SDIO_InitStruct : pointer to a SDIO_InitTypeDef structure
  11400. * that contains the configuration information for the SDIO peripheral.
  11401. * @retval None
  11402. */
  11403. void SDIO_Init(SDIO_InitTypeDef* SDIO_InitStruct)
  11404. {
  11405. uint32_t tmpreg = 0;
  11406. /* Check the parameters */
  11407. assert_param(IS_SDIO_CLOCK_EDGE(SDIO_InitStruct->SDIO_ClockEdge));
  11408. assert_param(IS_SDIO_CLOCK_BYPASS(SDIO_InitStruct->SDIO_ClockBypass));
  11409. assert_param(IS_SDIO_CLOCK_POWER_SAVE(SDIO_InitStruct->SDIO_ClockPowerSave));
  11410. assert_param(IS_SDIO_BUS_WIDE(SDIO_InitStruct->SDIO_BusWide));
  11411. assert_param(IS_SDIO_HARDWARE_FLOW_CONTROL(SDIO_InitStruct->SDIO_HardwareFlowControl));
  11412. /*---------------------------- SDIO CLKCR Configuration ------------------------*/
  11413. /* Get the SDIO CLKCR value */
  11414. tmpreg = SDIO->CLKCR;
  11415. /* Clear CLKDIV, PWRSAV, BYPASS, WIDBUS, NEGEDGE, HWFC_EN bits */
  11416. tmpreg &= CLKCR_CLEAR_MASK;
  11417. /* Set CLKDIV bits according to SDIO_ClockDiv value */
  11418. /* Set PWRSAV bit according to SDIO_ClockPowerSave value */
  11419. /* Set BYPASS bit according to SDIO_ClockBypass value */
  11420. /* Set WIDBUS bits according to SDIO_BusWide value */
  11421. /* Set NEGEDGE bits according to SDIO_ClockEdge value */
  11422. /* Set HWFC_EN bits according to SDIO_HardwareFlowControl value */
  11423. tmpreg |= (SDIO_InitStruct->SDIO_ClockDiv | SDIO_InitStruct->SDIO_ClockPowerSave |
  11424. SDIO_InitStruct->SDIO_ClockBypass | SDIO_InitStruct->SDIO_BusWide |
  11425. SDIO_InitStruct->SDIO_ClockEdge | SDIO_InitStruct->SDIO_HardwareFlowControl);
  11426. /* Write to SDIO CLKCR */
  11427. SDIO->CLKCR = tmpreg;
  11428. }
  11429. /**
  11430. * @brief Fills each SDIO_InitStruct member with its default value.
  11431. * @param SDIO_InitStruct: pointer to an SDIO_InitTypeDef structure which
  11432. * will be initialized.
  11433. * @retval None
  11434. */
  11435. void SDIO_StructInit(SDIO_InitTypeDef* SDIO_InitStruct)
  11436. {
  11437. /* SDIO_InitStruct members default value */
  11438. SDIO_InitStruct->SDIO_ClockDiv = 0x00;
  11439. SDIO_InitStruct->SDIO_ClockEdge = SDIO_ClockEdge_Rising;
  11440. SDIO_InitStruct->SDIO_ClockBypass = SDIO_ClockBypass_Disable;
  11441. SDIO_InitStruct->SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
  11442. SDIO_InitStruct->SDIO_BusWide = SDIO_BusWide_1b;
  11443. SDIO_InitStruct->SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
  11444. }
  11445. /**
  11446. * @brief Enables or disables the SDIO Clock.
  11447. * @param NewState: new state of the SDIO Clock. This parameter can be: ENABLE or DISABLE.
  11448. * @retval None
  11449. */
  11450. void SDIO_ClockCmd(FunctionalState NewState)
  11451. {
  11452. /* Check the parameters */
  11453. assert_param(IS_FUNCTIONAL_STATE(NewState));
  11454. *(__IO uint32_t *) CLKCR_CLKEN_BB = (uint32_t)NewState;
  11455. }
  11456. /**
  11457. * @brief Sets the power status of the controller.
  11458. * @param SDIO_PowerState: new state of the Power state.
  11459. * This parameter can be one of the following values:
  11460. * @arg SDIO_PowerState_OFF
  11461. * @arg SDIO_PowerState_ON
  11462. * @retval None
  11463. */
  11464. void SDIO_SetPowerState(uint32_t SDIO_PowerState)
  11465. {
  11466. /* Check the parameters */
  11467. assert_param(IS_SDIO_POWER_STATE(SDIO_PowerState));
  11468. SDIO->POWER &= PWR_PWRCTRL_MASK;
  11469. SDIO->POWER |= SDIO_PowerState;
  11470. }
  11471. /**
  11472. * @brief Gets the power status of the controller.
  11473. * @param None
  11474. * @retval Power status of the controller. The returned value can
  11475. * be one of the following:
  11476. * - 0x00: Power OFF
  11477. * - 0x02: Power UP
  11478. * - 0x03: Power ON
  11479. */
  11480. uint32_t SDIO_GetPowerState(void)
  11481. {
  11482. return (SDIO->POWER & (~PWR_PWRCTRL_MASK));
  11483. }
  11484. /**
  11485. * @brief Enables or disables the SDIO interrupts.
  11486. * @param SDIO_IT: specifies the SDIO interrupt sources to be enabled or disabled.
  11487. * This parameter can be one or a combination of the following values:
  11488. * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  11489. * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  11490. * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
  11491. * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
  11492. * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  11493. * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
  11494. * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
  11495. * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
  11496. * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  11497. * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
  11498. * bus mode interrupt
  11499. * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  11500. * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt
  11501. * @arg SDIO_IT_TXACT: Data transmit in progress interrupt
  11502. * @arg SDIO_IT_RXACT: Data receive in progress interrupt
  11503. * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  11504. * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  11505. * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt
  11506. * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
  11507. * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
  11508. * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt
  11509. * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt
  11510. * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt
  11511. * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
  11512. * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61 interrupt
  11513. * @param NewState: new state of the specified SDIO interrupts.
  11514. * This parameter can be: ENABLE or DISABLE.
  11515. * @retval None
  11516. */
  11517. void SDIO_ITConfig(uint32_t SDIO_IT, FunctionalState NewState)
  11518. {
  11519. /* Check the parameters */
  11520. assert_param(IS_SDIO_IT(SDIO_IT));
  11521. assert_param(IS_FUNCTIONAL_STATE(NewState));
  11522. if (NewState != DISABLE)
  11523. {
  11524. /* Enable the SDIO interrupts */
  11525. SDIO->MASK |= SDIO_IT;
  11526. }
  11527. else
  11528. {
  11529. /* Disable the SDIO interrupts */
  11530. SDIO->MASK &= ~SDIO_IT;
  11531. }
  11532. }
  11533. /**
  11534. * @brief Enables or disables the SDIO DMA request.
  11535. * @param NewState: new state of the selected SDIO DMA request.
  11536. * This parameter can be: ENABLE or DISABLE.
  11537. * @retval None
  11538. */
  11539. void SDIO_DMACmd(FunctionalState NewState)
  11540. {
  11541. /* Check the parameters */
  11542. assert_param(IS_FUNCTIONAL_STATE(NewState));
  11543. *(__IO uint32_t *) DCTRL_DMAEN_BB = (uint32_t)NewState;
  11544. }
  11545. /**
  11546. * @brief Initializes the SDIO Command according to the specified
  11547. * parameters in the SDIO_CmdInitStruct and send the command.
  11548. * @param SDIO_CmdInitStruct : pointer to a SDIO_CmdInitTypeDef
  11549. * structure that contains the configuration information for the SDIO command.
  11550. * @retval None
  11551. */
  11552. void SDIO_SendCommand(SDIO_CmdInitTypeDef *SDIO_CmdInitStruct)
  11553. {
  11554. uint32_t tmpreg = 0;
  11555. /* Check the parameters */
  11556. assert_param(IS_SDIO_CMD_INDEX(SDIO_CmdInitStruct->SDIO_CmdIndex));
  11557. assert_param(IS_SDIO_RESPONSE(SDIO_CmdInitStruct->SDIO_Response));
  11558. assert_param(IS_SDIO_WAIT(SDIO_CmdInitStruct->SDIO_Wait));
  11559. assert_param(IS_SDIO_CPSM(SDIO_CmdInitStruct->SDIO_CPSM));
  11560. /*---------------------------- SDIO ARG Configuration ------------------------*/
  11561. /* Set the SDIO Argument value */
  11562. SDIO->ARG = SDIO_CmdInitStruct->SDIO_Argument;
  11563. /*---------------------------- SDIO CMD Configuration ------------------------*/
  11564. /* Get the SDIO CMD value */
  11565. tmpreg = SDIO->CMD;
  11566. /* Clear CMDINDEX, WAITRESP, WAITINT, WAITPEND, CPSMEN bits */
  11567. tmpreg &= CMD_CLEAR_MASK;
  11568. /* Set CMDINDEX bits according to SDIO_CmdIndex value */
  11569. /* Set WAITRESP bits according to SDIO_Response value */
  11570. /* Set WAITINT and WAITPEND bits according to SDIO_Wait value */
  11571. /* Set CPSMEN bits according to SDIO_CPSM value */
  11572. tmpreg |= (uint32_t)SDIO_CmdInitStruct->SDIO_CmdIndex | SDIO_CmdInitStruct->SDIO_Response
  11573. | SDIO_CmdInitStruct->SDIO_Wait | SDIO_CmdInitStruct->SDIO_CPSM;
  11574. /* Write to SDIO CMD */
  11575. SDIO->CMD = tmpreg;
  11576. }
  11577. /**
  11578. * @brief Fills each SDIO_CmdInitStruct member with its default value.
  11579. * @param SDIO_CmdInitStruct: pointer to an SDIO_CmdInitTypeDef
  11580. * structure which will be initialized.
  11581. * @retval None
  11582. */
  11583. void SDIO_CmdStructInit(SDIO_CmdInitTypeDef* SDIO_CmdInitStruct)
  11584. {
  11585. /* SDIO_CmdInitStruct members default value */
  11586. SDIO_CmdInitStruct->SDIO_Argument = 0x00;
  11587. SDIO_CmdInitStruct->SDIO_CmdIndex = 0x00;
  11588. SDIO_CmdInitStruct->SDIO_Response = SDIO_Response_No;
  11589. SDIO_CmdInitStruct->SDIO_Wait = SDIO_Wait_No;
  11590. SDIO_CmdInitStruct->SDIO_CPSM = SDIO_CPSM_Disable;
  11591. }
  11592. /**
  11593. * @brief Returns command index of last command for which response received.
  11594. * @param None
  11595. * @retval Returns the command index of the last command response received.
  11596. */
  11597. uint8_t SDIO_GetCommandResponse(void)
  11598. {
  11599. return (uint8_t)(SDIO->RESPCMD);
  11600. }
  11601. /**
  11602. * @brief Returns response received from the card for the last command.
  11603. * @param SDIO_RESP: Specifies the SDIO response register.
  11604. * This parameter can be one of the following values:
  11605. * @arg SDIO_RESP1: Response Register 1
  11606. * @arg SDIO_RESP2: Response Register 2
  11607. * @arg SDIO_RESP3: Response Register 3
  11608. * @arg SDIO_RESP4: Response Register 4
  11609. * @retval The Corresponding response register value.
  11610. */
  11611. uint32_t SDIO_GetResponse(uint32_t SDIO_RESP)
  11612. {
  11613. __IO uint32_t tmp = 0;
  11614. /* Check the parameters */
  11615. assert_param(IS_SDIO_RESP(SDIO_RESP));
  11616. tmp = SDIO_RESP_ADDR + SDIO_RESP;
  11617. return (*(__IO uint32_t *) tmp);
  11618. }
  11619. /**
  11620. * @brief Initializes the SDIO data path according to the specified
  11621. * parameters in the SDIO_DataInitStruct.
  11622. * @param SDIO_DataInitStruct : pointer to a SDIO_DataInitTypeDef structure that
  11623. * contains the configuration information for the SDIO command.
  11624. * @retval None
  11625. */
  11626. void SDIO_DataConfig(SDIO_DataInitTypeDef* SDIO_DataInitStruct)
  11627. {
  11628. uint32_t tmpreg = 0;
  11629. /* Check the parameters */
  11630. assert_param(IS_SDIO_DATA_LENGTH(SDIO_DataInitStruct->SDIO_DataLength));
  11631. assert_param(IS_SDIO_BLOCK_SIZE(SDIO_DataInitStruct->SDIO_DataBlockSize));
  11632. assert_param(IS_SDIO_TRANSFER_DIR(SDIO_DataInitStruct->SDIO_TransferDir));
  11633. assert_param(IS_SDIO_TRANSFER_MODE(SDIO_DataInitStruct->SDIO_TransferMode));
  11634. assert_param(IS_SDIO_DPSM(SDIO_DataInitStruct->SDIO_DPSM));
  11635. /*---------------------------- SDIO DTIMER Configuration ---------------------*/
  11636. /* Set the SDIO Data TimeOut value */
  11637. SDIO->DTIMER = SDIO_DataInitStruct->SDIO_DataTimeOut;
  11638. /*---------------------------- SDIO DLEN Configuration -----------------------*/
  11639. /* Set the SDIO DataLength value */
  11640. SDIO->DLEN = SDIO_DataInitStruct->SDIO_DataLength;
  11641. /*---------------------------- SDIO DCTRL Configuration ----------------------*/
  11642. /* Get the SDIO DCTRL value */
  11643. tmpreg = SDIO->DCTRL;
  11644. /* Clear DEN, DTMODE, DTDIR and DBCKSIZE bits */
  11645. tmpreg &= DCTRL_CLEAR_MASK;
  11646. /* Set DEN bit according to SDIO_DPSM value */
  11647. /* Set DTMODE bit according to SDIO_TransferMode value */
  11648. /* Set DTDIR bit according to SDIO_TransferDir value */
  11649. /* Set DBCKSIZE bits according to SDIO_DataBlockSize value */
  11650. tmpreg |= (uint32_t)SDIO_DataInitStruct->SDIO_DataBlockSize | SDIO_DataInitStruct->SDIO_TransferDir
  11651. | SDIO_DataInitStruct->SDIO_TransferMode | SDIO_DataInitStruct->SDIO_DPSM;
  11652. /* Write to SDIO DCTRL */
  11653. SDIO->DCTRL = tmpreg;
  11654. }
  11655. /**
  11656. * @brief Fills each SDIO_DataInitStruct member with its default value.
  11657. * @param SDIO_DataInitStruct: pointer to an SDIO_DataInitTypeDef structure which
  11658. * will be initialized.
  11659. * @retval None
  11660. */
  11661. void SDIO_DataStructInit(SDIO_DataInitTypeDef* SDIO_DataInitStruct)
  11662. {
  11663. /* SDIO_DataInitStruct members default value */
  11664. SDIO_DataInitStruct->SDIO_DataTimeOut = 0xFFFFFFFF;
  11665. SDIO_DataInitStruct->SDIO_DataLength = 0x00;
  11666. SDIO_DataInitStruct->SDIO_DataBlockSize = SDIO_DataBlockSize_1b;
  11667. SDIO_DataInitStruct->SDIO_TransferDir = SDIO_TransferDir_ToCard;
  11668. SDIO_DataInitStruct->SDIO_TransferMode = SDIO_TransferMode_Block;
  11669. SDIO_DataInitStruct->SDIO_DPSM = SDIO_DPSM_Disable;
  11670. }
  11671. /**
  11672. * @brief Returns number of remaining data bytes to be transferred.
  11673. * @param None
  11674. * @retval Number of remaining data bytes to be transferred
  11675. */
  11676. uint32_t SDIO_GetDataCounter(void)
  11677. {
  11678. return SDIO->DCOUNT;
  11679. }
  11680. /**
  11681. * @brief Read one data word from Rx FIFO.
  11682. * @param None
  11683. * @retval Data received
  11684. */
  11685. uint32_t SDIO_ReadData(void)
  11686. {
  11687. return SDIO->FIFO;
  11688. }
  11689. /**
  11690. * @brief Write one data word to Tx FIFO.
  11691. * @param Data: 32-bit data word to write.
  11692. * @retval None
  11693. */
  11694. void SDIO_WriteData(uint32_t Data)
  11695. {
  11696. SDIO->FIFO = Data;
  11697. }
  11698. /**
  11699. * @brief Returns the number of words left to be written to or read from FIFO.
  11700. * @param None
  11701. * @retval Remaining number of words.
  11702. */
  11703. uint32_t SDIO_GetFIFOCount(void)
  11704. {
  11705. return SDIO->FIFOCNT;
  11706. }
  11707. /**
  11708. * @brief Starts the SD I/O Read Wait operation.
  11709. * @param NewState: new state of the Start SDIO Read Wait operation.
  11710. * This parameter can be: ENABLE or DISABLE.
  11711. * @retval None
  11712. */
  11713. void SDIO_StartSDIOReadWait(FunctionalState NewState)
  11714. {
  11715. /* Check the parameters */
  11716. assert_param(IS_FUNCTIONAL_STATE(NewState));
  11717. *(__IO uint32_t *) DCTRL_RWSTART_BB = (uint32_t) NewState;
  11718. }
  11719. /**
  11720. * @brief Stops the SD I/O Read Wait operation.
  11721. * @param NewState: new state of the Stop SDIO Read Wait operation.
  11722. * This parameter can be: ENABLE or DISABLE.
  11723. * @retval None
  11724. */
  11725. void SDIO_StopSDIOReadWait(FunctionalState NewState)
  11726. {
  11727. /* Check the parameters */
  11728. assert_param(IS_FUNCTIONAL_STATE(NewState));
  11729. *(__IO uint32_t *) DCTRL_RWSTOP_BB = (uint32_t) NewState;
  11730. }
  11731. /**
  11732. * @brief Sets one of the two options of inserting read wait interval.
  11733. * @param SDIO_ReadWaitMode: SD I/O Read Wait operation mode.
  11734. * This parameter can be:
  11735. * @arg SDIO_ReadWaitMode_CLK: Read Wait control by stopping SDIOCLK
  11736. * @arg SDIO_ReadWaitMode_DATA2: Read Wait control using SDIO_DATA2
  11737. * @retval None
  11738. */
  11739. void SDIO_SetSDIOReadWaitMode(uint32_t SDIO_ReadWaitMode)
  11740. {
  11741. /* Check the parameters */
  11742. assert_param(IS_SDIO_READWAIT_MODE(SDIO_ReadWaitMode));
  11743. *(__IO uint32_t *) DCTRL_RWMOD_BB = SDIO_ReadWaitMode;
  11744. }
  11745. /**
  11746. * @brief Enables or disables the SD I/O Mode Operation.
  11747. * @param NewState: new state of SDIO specific operation.
  11748. * This parameter can be: ENABLE or DISABLE.
  11749. * @retval None
  11750. */
  11751. void SDIO_SetSDIOOperation(FunctionalState NewState)
  11752. {
  11753. /* Check the parameters */
  11754. assert_param(IS_FUNCTIONAL_STATE(NewState));
  11755. *(__IO uint32_t *) DCTRL_SDIOEN_BB = (uint32_t)NewState;
  11756. }
  11757. /**
  11758. * @brief Enables or disables the SD I/O Mode suspend command sending.
  11759. * @param NewState: new state of the SD I/O Mode suspend command.
  11760. * This parameter can be: ENABLE or DISABLE.
  11761. * @retval None
  11762. */
  11763. void SDIO_SendSDIOSuspendCmd(FunctionalState NewState)
  11764. {
  11765. /* Check the parameters */
  11766. assert_param(IS_FUNCTIONAL_STATE(NewState));
  11767. *(__IO uint32_t *) CMD_SDIOSUSPEND_BB = (uint32_t)NewState;
  11768. }
  11769. /**
  11770. * @brief Enables or disables the command completion signal.
  11771. * @param NewState: new state of command completion signal.
  11772. * This parameter can be: ENABLE or DISABLE.
  11773. * @retval None
  11774. */
  11775. void SDIO_CommandCompletionCmd(FunctionalState NewState)
  11776. {
  11777. /* Check the parameters */
  11778. assert_param(IS_FUNCTIONAL_STATE(NewState));
  11779. *(__IO uint32_t *) CMD_ENCMDCOMPL_BB = (uint32_t)NewState;
  11780. }
  11781. /**
  11782. * @brief Enables or disables the CE-ATA interrupt.
  11783. * @param NewState: new state of CE-ATA interrupt. This parameter can be: ENABLE or DISABLE.
  11784. * @retval None
  11785. */
  11786. void SDIO_CEATAITCmd(FunctionalState NewState)
  11787. {
  11788. /* Check the parameters */
  11789. assert_param(IS_FUNCTIONAL_STATE(NewState));
  11790. *(__IO uint32_t *) CMD_NIEN_BB = (uint32_t)((~((uint32_t)NewState)) & ((uint32_t)0x1));
  11791. }
  11792. /**
  11793. * @brief Sends CE-ATA command (CMD61).
  11794. * @param NewState: new state of CE-ATA command. This parameter can be: ENABLE or DISABLE.
  11795. * @retval None
  11796. */
  11797. void SDIO_SendCEATACmd(FunctionalState NewState)
  11798. {
  11799. /* Check the parameters */
  11800. assert_param(IS_FUNCTIONAL_STATE(NewState));
  11801. *(__IO uint32_t *) CMD_ATACMD_BB = (uint32_t)NewState;
  11802. }
  11803. /**
  11804. * @brief Checks whether the specified SDIO flag is set or not.
  11805. * @param SDIO_FLAG: specifies the flag to check.
  11806. * This parameter can be one of the following values:
  11807. * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed)
  11808. * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  11809. * @arg SDIO_FLAG_CTIMEOUT: Command response timeout
  11810. * @arg SDIO_FLAG_DTIMEOUT: Data timeout
  11811. * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error
  11812. * @arg SDIO_FLAG_RXOVERR: Received FIFO overrun error
  11813. * @arg SDIO_FLAG_CMDREND: Command response received (CRC check passed)
  11814. * @arg SDIO_FLAG_CMDSENT: Command sent (no response required)
  11815. * @arg SDIO_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
  11816. * @arg SDIO_FLAG_STBITERR: Start bit not detected on all data signals in wide
  11817. * bus mode.
  11818. * @arg SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  11819. * @arg SDIO_FLAG_CMDACT: Command transfer in progress
  11820. * @arg SDIO_FLAG_TXACT: Data transmit in progress
  11821. * @arg SDIO_FLAG_RXACT: Data receive in progress
  11822. * @arg SDIO_FLAG_TXFIFOHE: Transmit FIFO Half Empty
  11823. * @arg SDIO_FLAG_RXFIFOHF: Receive FIFO Half Full
  11824. * @arg SDIO_FLAG_TXFIFOF: Transmit FIFO full
  11825. * @arg SDIO_FLAG_RXFIFOF: Receive FIFO full
  11826. * @arg SDIO_FLAG_TXFIFOE: Transmit FIFO empty
  11827. * @arg SDIO_FLAG_RXFIFOE: Receive FIFO empty
  11828. * @arg SDIO_FLAG_TXDAVL: Data available in transmit FIFO
  11829. * @arg SDIO_FLAG_RXDAVL: Data available in receive FIFO
  11830. * @arg SDIO_FLAG_SDIOIT: SD I/O interrupt received
  11831. * @arg SDIO_FLAG_CEATAEND: CE-ATA command completion signal received for CMD61
  11832. * @retval The new state of SDIO_FLAG (SET or RESET).
  11833. */
  11834. FlagStatus SDIO_GetFlagStatus(uint32_t SDIO_FLAG)
  11835. {
  11836. FlagStatus bitstatus = RESET;
  11837. /* Check the parameters */
  11838. assert_param(IS_SDIO_FLAG(SDIO_FLAG));
  11839. if ((SDIO->STA & SDIO_FLAG) != (uint32_t)RESET)
  11840. {
  11841. bitstatus = SET;
  11842. }
  11843. else
  11844. {
  11845. bitstatus = RESET;
  11846. }
  11847. return bitstatus;
  11848. }
  11849. /**
  11850. * @brief Clears the SDIO's pending flags.
  11851. * @param SDIO_FLAG: specifies the flag to clear.
  11852. * This parameter can be one or a combination of the following values:
  11853. * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed)
  11854. * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
  11855. * @arg SDIO_FLAG_CTIMEOUT: Command response timeout
  11856. * @arg SDIO_FLAG_DTIMEOUT: Data timeout
  11857. * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error
  11858. * @arg SDIO_FLAG_RXOVERR: Received FIFO overrun error
  11859. * @arg SDIO_FLAG_CMDREND: Command response received (CRC check passed)
  11860. * @arg SDIO_FLAG_CMDSENT: Command sent (no response required)
  11861. * @arg SDIO_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
  11862. * @arg SDIO_FLAG_STBITERR: Start bit not detected on all data signals in wide
  11863. * bus mode
  11864. * @arg SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed)
  11865. * @arg SDIO_FLAG_SDIOIT: SD I/O interrupt received
  11866. * @arg SDIO_FLAG_CEATAEND: CE-ATA command completion signal received for CMD61
  11867. * @retval None
  11868. */
  11869. void SDIO_ClearFlag(uint32_t SDIO_FLAG)
  11870. {
  11871. /* Check the parameters */
  11872. assert_param(IS_SDIO_CLEAR_FLAG(SDIO_FLAG));
  11873. SDIO->ICR = SDIO_FLAG;
  11874. }
  11875. /**
  11876. * @brief Checks whether the specified SDIO interrupt has occurred or not.
  11877. * @param SDIO_IT: specifies the SDIO interrupt source to check.
  11878. * This parameter can be one of the following values:
  11879. * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  11880. * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  11881. * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
  11882. * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
  11883. * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  11884. * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
  11885. * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
  11886. * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
  11887. * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  11888. * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
  11889. * bus mode interrupt
  11890. * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
  11891. * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt
  11892. * @arg SDIO_IT_TXACT: Data transmit in progress interrupt
  11893. * @arg SDIO_IT_RXACT: Data receive in progress interrupt
  11894. * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
  11895. * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
  11896. * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt
  11897. * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
  11898. * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
  11899. * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt
  11900. * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt
  11901. * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt
  11902. * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
  11903. * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61 interrupt
  11904. * @retval The new state of SDIO_IT (SET or RESET).
  11905. */
  11906. ITStatus SDIO_GetITStatus(uint32_t SDIO_IT)
  11907. {
  11908. ITStatus bitstatus = RESET;
  11909. /* Check the parameters */
  11910. assert_param(IS_SDIO_GET_IT(SDIO_IT));
  11911. if ((SDIO->STA & SDIO_IT) != (uint32_t)RESET)
  11912. {
  11913. bitstatus = SET;
  11914. }
  11915. else
  11916. {
  11917. bitstatus = RESET;
  11918. }
  11919. return bitstatus;
  11920. }
  11921. /**
  11922. * @brief Clears the SDIO's interrupt pending bits.
  11923. * @param SDIO_IT: specifies the interrupt pending bit to clear.
  11924. * This parameter can be one or a combination of the following values:
  11925. * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
  11926. * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
  11927. * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
  11928. * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
  11929. * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
  11930. * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
  11931. * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
  11932. * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
  11933. * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
  11934. * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
  11935. * bus mode interrupt
  11936. * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
  11937. * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61
  11938. * @retval None
  11939. */
  11940. void SDIO_ClearITPendingBit(uint32_t SDIO_IT)
  11941. {
  11942. /* Check the parameters */
  11943. assert_param(IS_SDIO_CLEAR_IT(SDIO_IT));
  11944. SDIO->ICR = SDIO_IT;
  11945. }
  11946. /**
  11947. * @}
  11948. */
  11949. /**
  11950. * @}
  11951. */
  11952. /**
  11953. * @}
  11954. */
  11955. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  11956. /**
  11957. ******************************************************************************
  11958. * @file stm32f10x_exti.c
  11959. * @author MCD Application Team
  11960. * @version V3.5.0
  11961. * @date 11-March-2011
  11962. * @brief This file provides all the EXTI firmware functions.
  11963. ******************************************************************************
  11964. * @attention
  11965. *
  11966. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  11967. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  11968. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  11969. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  11970. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  11971. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  11972. *
  11973. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  11974. ******************************************************************************
  11975. */
  11976. /* Includes ------------------------------------------------------------------*/
  11977. #include "stm32f10x_exti.h"
  11978. /** @addtogroup STM32F10x_StdPeriph_Driver
  11979. * @{
  11980. */
  11981. /** @defgroup EXTI
  11982. * @brief EXTI driver modules
  11983. * @{
  11984. */
  11985. /** @defgroup EXTI_Private_TypesDefinitions
  11986. * @{
  11987. */
  11988. /**
  11989. * @}
  11990. */
  11991. /** @defgroup EXTI_Private_Defines
  11992. * @{
  11993. */
  11994. #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */
  11995. /**
  11996. * @}
  11997. */
  11998. /** @defgroup EXTI_Private_Macros
  11999. * @{
  12000. */
  12001. /**
  12002. * @}
  12003. */
  12004. /** @defgroup EXTI_Private_Variables
  12005. * @{
  12006. */
  12007. /**
  12008. * @}
  12009. */
  12010. /** @defgroup EXTI_Private_FunctionPrototypes
  12011. * @{
  12012. */
  12013. /**
  12014. * @}
  12015. */
  12016. /** @defgroup EXTI_Private_Functions
  12017. * @{
  12018. */
  12019. /**
  12020. * @brief Deinitializes the EXTI peripheral registers to their default reset values.
  12021. * @param None
  12022. * @retval None
  12023. */
  12024. void EXTI_DeInit(void)
  12025. {
  12026. EXTI->IMR = 0x00000000;
  12027. EXTI->EMR = 0x00000000;
  12028. EXTI->RTSR = 0x00000000;
  12029. EXTI->FTSR = 0x00000000;
  12030. EXTI->PR = 0x000FFFFF;
  12031. }
  12032. /**
  12033. * @brief Initializes the EXTI peripheral according to the specified
  12034. * parameters in the EXTI_InitStruct.
  12035. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
  12036. * that contains the configuration information for the EXTI peripheral.
  12037. * @retval None
  12038. */
  12039. void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
  12040. {
  12041. uint32_t tmp = 0;
  12042. /* Check the parameters */
  12043. assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
  12044. assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
  12045. assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
  12046. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
  12047. tmp = (uint32_t)EXTI_BASE;
  12048. if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
  12049. {
  12050. /* Clear EXTI line configuration */
  12051. EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
  12052. EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
  12053. tmp += EXTI_InitStruct->EXTI_Mode;
  12054. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  12055. /* Clear Rising Falling edge configuration */
  12056. EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
  12057. EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
  12058. /* Select the trigger for the selected external interrupts */
  12059. if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
  12060. {
  12061. /* Rising Falling edge */
  12062. EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
  12063. EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
  12064. }
  12065. else
  12066. {
  12067. tmp = (uint32_t)EXTI_BASE;
  12068. tmp += EXTI_InitStruct->EXTI_Trigger;
  12069. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  12070. }
  12071. }
  12072. else
  12073. {
  12074. tmp += EXTI_InitStruct->EXTI_Mode;
  12075. /* Disable the selected external lines */
  12076. *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
  12077. }
  12078. }
  12079. /**
  12080. * @brief Fills each EXTI_InitStruct member with its reset value.
  12081. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
  12082. * be initialized.
  12083. * @retval None
  12084. */
  12085. void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
  12086. {
  12087. EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
  12088. EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
  12089. EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
  12090. EXTI_InitStruct->EXTI_LineCmd = DISABLE;
  12091. }
  12092. /**
  12093. * @brief Generates a Software interrupt.
  12094. * @param EXTI_Line: specifies the EXTI lines to be enabled or disabled.
  12095. * This parameter can be any combination of EXTI_Linex where x can be (0..19).
  12096. * @retval None
  12097. */
  12098. void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
  12099. {
  12100. /* Check the parameters */
  12101. assert_param(IS_EXTI_LINE(EXTI_Line));
  12102. EXTI->SWIER |= EXTI_Line;
  12103. }
  12104. /**
  12105. * @brief Checks whether the specified EXTI line flag is set or not.
  12106. * @param EXTI_Line: specifies the EXTI line flag to check.
  12107. * This parameter can be:
  12108. * @arg EXTI_Linex: External interrupt line x where x(0..19)
  12109. * @retval The new state of EXTI_Line (SET or RESET).
  12110. */
  12111. FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
  12112. {
  12113. FlagStatus bitstatus = RESET;
  12114. /* Check the parameters */
  12115. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  12116. if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
  12117. {
  12118. bitstatus = SET;
  12119. }
  12120. else
  12121. {
  12122. bitstatus = RESET;
  12123. }
  12124. return bitstatus;
  12125. }
  12126. /**
  12127. * @brief Clears the EXTI's line pending flags.
  12128. * @param EXTI_Line: specifies the EXTI lines flags to clear.
  12129. * This parameter can be any combination of EXTI_Linex where x can be (0..19).
  12130. * @retval None
  12131. */
  12132. void EXTI_ClearFlag(uint32_t EXTI_Line)
  12133. {
  12134. /* Check the parameters */
  12135. assert_param(IS_EXTI_LINE(EXTI_Line));
  12136. EXTI->PR = EXTI_Line;
  12137. }
  12138. /**
  12139. * @brief Checks whether the specified EXTI line is asserted or not.
  12140. * @param EXTI_Line: specifies the EXTI line to check.
  12141. * This parameter can be:
  12142. * @arg EXTI_Linex: External interrupt line x where x(0..19)
  12143. * @retval The new state of EXTI_Line (SET or RESET).
  12144. */
  12145. ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
  12146. {
  12147. ITStatus bitstatus = RESET;
  12148. uint32_t enablestatus = 0;
  12149. /* Check the parameters */
  12150. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  12151. enablestatus = EXTI->IMR & EXTI_Line;
  12152. if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
  12153. {
  12154. bitstatus = SET;
  12155. }
  12156. else
  12157. {
  12158. bitstatus = RESET;
  12159. }
  12160. return bitstatus;
  12161. }
  12162. /**
  12163. * @brief Clears the EXTI's line pending bits.
  12164. * @param EXTI_Line: specifies the EXTI lines to clear.
  12165. * This parameter can be any combination of EXTI_Linex where x can be (0..19).
  12166. * @retval None
  12167. */
  12168. void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
  12169. {
  12170. /* Check the parameters */
  12171. assert_param(IS_EXTI_LINE(EXTI_Line));
  12172. EXTI->PR = EXTI_Line;
  12173. }
  12174. /**
  12175. * @}
  12176. */
  12177. /**
  12178. * @}
  12179. */
  12180. /**
  12181. * @}
  12182. */
  12183. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  12184. /**
  12185. ******************************************************************************
  12186. * @file stm32f10x_adc.c
  12187. * @author MCD Application Team
  12188. * @version V3.5.0
  12189. * @date 11-March-2011
  12190. * @brief This file provides all the ADC firmware functions.
  12191. ******************************************************************************
  12192. * @attention
  12193. *
  12194. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12195. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  12196. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  12197. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  12198. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  12199. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  12200. *
  12201. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  12202. ******************************************************************************
  12203. */
  12204. /* Includes ------------------------------------------------------------------*/
  12205. #include "stm32f10x_adc.h"
  12206. #include "stm32f10x_rcc.h"
  12207. /** @addtogroup STM32F10x_StdPeriph_Driver
  12208. * @{
  12209. */
  12210. /** @defgroup ADC
  12211. * @brief ADC driver modules
  12212. * @{
  12213. */
  12214. /** @defgroup ADC_Private_TypesDefinitions
  12215. * @{
  12216. */
  12217. /**
  12218. * @}
  12219. */
  12220. /** @defgroup ADC_Private_Defines
  12221. * @{
  12222. */
  12223. /* ADC DISCNUM mask */
  12224. #define CR1_DISCNUM_Reset ((uint32_t)0xFFFF1FFF)
  12225. /* ADC DISCEN mask */
  12226. #define CR1_DISCEN_Set ((uint32_t)0x00000800)
  12227. #define CR1_DISCEN_Reset ((uint32_t)0xFFFFF7FF)
  12228. /* ADC JAUTO mask */
  12229. #define CR1_JAUTO_Set ((uint32_t)0x00000400)
  12230. #define CR1_JAUTO_Reset ((uint32_t)0xFFFFFBFF)
  12231. /* ADC JDISCEN mask */
  12232. #define CR1_JDISCEN_Set ((uint32_t)0x00001000)
  12233. #define CR1_JDISCEN_Reset ((uint32_t)0xFFFFEFFF)
  12234. /* ADC AWDCH mask */
  12235. #define CR1_AWDCH_Reset ((uint32_t)0xFFFFFFE0)
  12236. /* ADC Analog watchdog enable mode mask */
  12237. #define CR1_AWDMode_Reset ((uint32_t)0xFF3FFDFF)
  12238. /* CR1 register Mask */
  12239. #define CR1_CLEAR_Mask ((uint32_t)0xFFF0FEFF)
  12240. /* ADC ADON mask */
  12241. #define CR2_ADON_Set ((uint32_t)0x00000001)
  12242. #define CR2_ADON_Reset ((uint32_t)0xFFFFFFFE)
  12243. /* ADC DMA mask */
  12244. #define CR2_DMA_Set ((uint32_t)0x00000100)
  12245. #define CR2_DMA_Reset ((uint32_t)0xFFFFFEFF)
  12246. /* ADC RSTCAL mask */
  12247. #define CR2_RSTCAL_Set ((uint32_t)0x00000008)
  12248. /* ADC CAL mask */
  12249. #define CR2_CAL_Set ((uint32_t)0x00000004)
  12250. /* ADC SWSTART mask */
  12251. #define CR2_SWSTART_Set ((uint32_t)0x00400000)
  12252. /* ADC EXTTRIG mask */
  12253. #define CR2_EXTTRIG_Set ((uint32_t)0x00100000)
  12254. #define CR2_EXTTRIG_Reset ((uint32_t)0xFFEFFFFF)
  12255. /* ADC Software start mask */
  12256. #define CR2_EXTTRIG_SWSTART_Set ((uint32_t)0x00500000)
  12257. #define CR2_EXTTRIG_SWSTART_Reset ((uint32_t)0xFFAFFFFF)
  12258. /* ADC JEXTSEL mask */
  12259. #define CR2_JEXTSEL_Reset ((uint32_t)0xFFFF8FFF)
  12260. /* ADC JEXTTRIG mask */
  12261. #define CR2_JEXTTRIG_Set ((uint32_t)0x00008000)
  12262. #define CR2_JEXTTRIG_Reset ((uint32_t)0xFFFF7FFF)
  12263. /* ADC JSWSTART mask */
  12264. #define CR2_JSWSTART_Set ((uint32_t)0x00200000)
  12265. /* ADC injected software start mask */
  12266. #define CR2_JEXTTRIG_JSWSTART_Set ((uint32_t)0x00208000)
  12267. #define CR2_JEXTTRIG_JSWSTART_Reset ((uint32_t)0xFFDF7FFF)
  12268. /* ADC TSPD mask */
  12269. #define CR2_TSVREFE_Set ((uint32_t)0x00800000)
  12270. #define CR2_TSVREFE_Reset ((uint32_t)0xFF7FFFFF)
  12271. /* CR2 register Mask */
  12272. #define CR2_CLEAR_Mask ((uint32_t)0xFFF1F7FD)
  12273. /* ADC SQx mask */
  12274. #define SQR3_SQ_Set ((uint32_t)0x0000001F)
  12275. #define SQR2_SQ_Set ((uint32_t)0x0000001F)
  12276. #define SQR1_SQ_Set ((uint32_t)0x0000001F)
  12277. /* SQR1 register Mask */
  12278. #define SQR1_CLEAR_Mask ((uint32_t)0xFF0FFFFF)
  12279. /* ADC JSQx mask */
  12280. #define JSQR_JSQ_Set ((uint32_t)0x0000001F)
  12281. /* ADC JL mask */
  12282. #define JSQR_JL_Set ((uint32_t)0x00300000)
  12283. #define JSQR_JL_Reset ((uint32_t)0xFFCFFFFF)
  12284. /* ADC SMPx mask */
  12285. #define SMPR1_SMP_Set ((uint32_t)0x00000007)
  12286. #define SMPR2_SMP_Set ((uint32_t)0x00000007)
  12287. /* ADC JDRx registers offset */
  12288. #define JDR_Offset ((uint8_t)0x28)
  12289. /* ADC1 DR register base address */
  12290. #define DR_ADDRESS ((uint32_t)0x4001244C)
  12291. /**
  12292. * @}
  12293. */
  12294. /** @defgroup ADC_Private_Macros
  12295. * @{
  12296. */
  12297. /**
  12298. * @}
  12299. */
  12300. /** @defgroup ADC_Private_Variables
  12301. * @{
  12302. */
  12303. /**
  12304. * @}
  12305. */
  12306. /** @defgroup ADC_Private_FunctionPrototypes
  12307. * @{
  12308. */
  12309. /**
  12310. * @}
  12311. */
  12312. /** @defgroup ADC_Private_Functions
  12313. * @{
  12314. */
  12315. /**
  12316. * @brief Deinitializes the ADCx peripheral registers to their default reset values.
  12317. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12318. * @retval None
  12319. */
  12320. void ADC_DeInit(ADC_TypeDef* ADCx)
  12321. {
  12322. /* Check the parameters */
  12323. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12324. if (ADCx == ADC1)
  12325. {
  12326. /* Enable ADC1 reset state */
  12327. RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, ENABLE);
  12328. /* Release ADC1 from reset state */
  12329. RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, DISABLE);
  12330. }
  12331. else if (ADCx == ADC2)
  12332. {
  12333. /* Enable ADC2 reset state */
  12334. RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2, ENABLE);
  12335. /* Release ADC2 from reset state */
  12336. RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2, DISABLE);
  12337. }
  12338. else
  12339. {
  12340. if (ADCx == ADC3)
  12341. {
  12342. /* Enable ADC3 reset state */
  12343. RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3, ENABLE);
  12344. /* Release ADC3 from reset state */
  12345. RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3, DISABLE);
  12346. }
  12347. }
  12348. }
  12349. /**
  12350. * @brief Initializes the ADCx peripheral according to the specified parameters
  12351. * in the ADC_InitStruct.
  12352. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12353. * @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure that contains
  12354. * the configuration information for the specified ADC peripheral.
  12355. * @retval None
  12356. */
  12357. void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct)
  12358. {
  12359. uint32_t tmpreg1 = 0;
  12360. uint8_t tmpreg2 = 0;
  12361. /* Check the parameters */
  12362. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12363. assert_param(IS_ADC_MODE(ADC_InitStruct->ADC_Mode));
  12364. assert_param(IS_FUNCTIONAL_STATE(ADC_InitStruct->ADC_ScanConvMode));
  12365. assert_param(IS_FUNCTIONAL_STATE(ADC_InitStruct->ADC_ContinuousConvMode));
  12366. assert_param(IS_ADC_EXT_TRIG(ADC_InitStruct->ADC_ExternalTrigConv));
  12367. assert_param(IS_ADC_DATA_ALIGN(ADC_InitStruct->ADC_DataAlign));
  12368. assert_param(IS_ADC_REGULAR_LENGTH(ADC_InitStruct->ADC_NbrOfChannel));
  12369. /*---------------------------- ADCx CR1 Configuration -----------------*/
  12370. /* Get the ADCx CR1 value */
  12371. tmpreg1 = ADCx->CR1;
  12372. /* Clear DUALMOD and SCAN bits */
  12373. tmpreg1 &= CR1_CLEAR_Mask;
  12374. /* Configure ADCx: Dual mode and scan conversion mode */
  12375. /* Set DUALMOD bits according to ADC_Mode value */
  12376. /* Set SCAN bit according to ADC_ScanConvMode value */
  12377. tmpreg1 |= (uint32_t)(ADC_InitStruct->ADC_Mode | ((uint32_t)ADC_InitStruct->ADC_ScanConvMode << 8));
  12378. /* Write to ADCx CR1 */
  12379. ADCx->CR1 = tmpreg1;
  12380. /*---------------------------- ADCx CR2 Configuration -----------------*/
  12381. /* Get the ADCx CR2 value */
  12382. tmpreg1 = ADCx->CR2;
  12383. /* Clear CONT, ALIGN and EXTSEL bits */
  12384. tmpreg1 &= CR2_CLEAR_Mask;
  12385. /* Configure ADCx: external trigger event and continuous conversion mode */
  12386. /* Set ALIGN bit according to ADC_DataAlign value */
  12387. /* Set EXTSEL bits according to ADC_ExternalTrigConv value */
  12388. /* Set CONT bit according to ADC_ContinuousConvMode value */
  12389. tmpreg1 |= (uint32_t)(ADC_InitStruct->ADC_DataAlign | ADC_InitStruct->ADC_ExternalTrigConv |
  12390. ((uint32_t)ADC_InitStruct->ADC_ContinuousConvMode << 1));
  12391. /* Write to ADCx CR2 */
  12392. ADCx->CR2 = tmpreg1;
  12393. /*---------------------------- ADCx SQR1 Configuration -----------------*/
  12394. /* Get the ADCx SQR1 value */
  12395. tmpreg1 = ADCx->SQR1;
  12396. /* Clear L bits */
  12397. tmpreg1 &= SQR1_CLEAR_Mask;
  12398. /* Configure ADCx: regular channel sequence length */
  12399. /* Set L bits according to ADC_NbrOfChannel value */
  12400. tmpreg2 |= (uint8_t) (ADC_InitStruct->ADC_NbrOfChannel - (uint8_t)1);
  12401. tmpreg1 |= (uint32_t)tmpreg2 << 20;
  12402. /* Write to ADCx SQR1 */
  12403. ADCx->SQR1 = tmpreg1;
  12404. }
  12405. /**
  12406. * @brief Fills each ADC_InitStruct member with its default value.
  12407. * @param ADC_InitStruct : pointer to an ADC_InitTypeDef structure which will be initialized.
  12408. * @retval None
  12409. */
  12410. void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct)
  12411. {
  12412. /* Reset ADC init structure parameters values */
  12413. /* Initialize the ADC_Mode member */
  12414. ADC_InitStruct->ADC_Mode = ADC_Mode_Independent;
  12415. /* initialize the ADC_ScanConvMode member */
  12416. ADC_InitStruct->ADC_ScanConvMode = DISABLE;
  12417. /* Initialize the ADC_ContinuousConvMode member */
  12418. ADC_InitStruct->ADC_ContinuousConvMode = DISABLE;
  12419. /* Initialize the ADC_ExternalTrigConv member */
  12420. ADC_InitStruct->ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
  12421. /* Initialize the ADC_DataAlign member */
  12422. ADC_InitStruct->ADC_DataAlign = ADC_DataAlign_Right;
  12423. /* Initialize the ADC_NbrOfChannel member */
  12424. ADC_InitStruct->ADC_NbrOfChannel = 1;
  12425. }
  12426. /**
  12427. * @brief Enables or disables the specified ADC peripheral.
  12428. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12429. * @param NewState: new state of the ADCx peripheral.
  12430. * This parameter can be: ENABLE or DISABLE.
  12431. * @retval None
  12432. */
  12433. void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
  12434. {
  12435. /* Check the parameters */
  12436. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12437. assert_param(IS_FUNCTIONAL_STATE(NewState));
  12438. if (NewState != DISABLE)
  12439. {
  12440. /* Set the ADON bit to wake up the ADC from power down mode */
  12441. ADCx->CR2 |= CR2_ADON_Set;
  12442. }
  12443. else
  12444. {
  12445. /* Disable the selected ADC peripheral */
  12446. ADCx->CR2 &= CR2_ADON_Reset;
  12447. }
  12448. }
  12449. /**
  12450. * @brief Enables or disables the specified ADC DMA request.
  12451. * @param ADCx: where x can be 1 or 3 to select the ADC peripheral.
  12452. * Note: ADC2 hasn't a DMA capability.
  12453. * @param NewState: new state of the selected ADC DMA transfer.
  12454. * This parameter can be: ENABLE or DISABLE.
  12455. * @retval None
  12456. */
  12457. void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState)
  12458. {
  12459. /* Check the parameters */
  12460. assert_param(IS_ADC_DMA_PERIPH(ADCx));
  12461. assert_param(IS_FUNCTIONAL_STATE(NewState));
  12462. if (NewState != DISABLE)
  12463. {
  12464. /* Enable the selected ADC DMA request */
  12465. ADCx->CR2 |= CR2_DMA_Set;
  12466. }
  12467. else
  12468. {
  12469. /* Disable the selected ADC DMA request */
  12470. ADCx->CR2 &= CR2_DMA_Reset;
  12471. }
  12472. }
  12473. /**
  12474. * @brief Enables or disables the specified ADC interrupts.
  12475. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12476. * @param ADC_IT: specifies the ADC interrupt sources to be enabled or disabled.
  12477. * This parameter can be any combination of the following values:
  12478. * @arg ADC_IT_EOC: End of conversion interrupt mask
  12479. * @arg ADC_IT_AWD: Analog watchdog interrupt mask
  12480. * @arg ADC_IT_JEOC: End of injected conversion interrupt mask
  12481. * @param NewState: new state of the specified ADC interrupts.
  12482. * This parameter can be: ENABLE or DISABLE.
  12483. * @retval None
  12484. */
  12485. void ADC_ITConfig(ADC_TypeDef* ADCx, uint16_t ADC_IT, FunctionalState NewState)
  12486. {
  12487. uint8_t itmask = 0;
  12488. /* Check the parameters */
  12489. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12490. assert_param(IS_FUNCTIONAL_STATE(NewState));
  12491. assert_param(IS_ADC_IT(ADC_IT));
  12492. /* Get the ADC IT index */
  12493. itmask = (uint8_t)ADC_IT;
  12494. if (NewState != DISABLE)
  12495. {
  12496. /* Enable the selected ADC interrupts */
  12497. ADCx->CR1 |= itmask;
  12498. }
  12499. else
  12500. {
  12501. /* Disable the selected ADC interrupts */
  12502. ADCx->CR1 &= (~(uint32_t)itmask);
  12503. }
  12504. }
  12505. /**
  12506. * @brief Resets the selected ADC calibration registers.
  12507. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12508. * @retval None
  12509. */
  12510. void ADC_ResetCalibration(ADC_TypeDef* ADCx)
  12511. {
  12512. /* Check the parameters */
  12513. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12514. /* Resets the selected ADC calibration registers */
  12515. ADCx->CR2 |= CR2_RSTCAL_Set;
  12516. }
  12517. /**
  12518. * @brief Gets the selected ADC reset calibration registers status.
  12519. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12520. * @retval The new state of ADC reset calibration registers (SET or RESET).
  12521. */
  12522. FlagStatus ADC_GetResetCalibrationStatus(ADC_TypeDef* ADCx)
  12523. {
  12524. FlagStatus bitstatus = RESET;
  12525. /* Check the parameters */
  12526. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12527. /* Check the status of RSTCAL bit */
  12528. if ((ADCx->CR2 & CR2_RSTCAL_Set) != (uint32_t)RESET)
  12529. {
  12530. /* RSTCAL bit is set */
  12531. bitstatus = SET;
  12532. }
  12533. else
  12534. {
  12535. /* RSTCAL bit is reset */
  12536. bitstatus = RESET;
  12537. }
  12538. /* Return the RSTCAL bit status */
  12539. return bitstatus;
  12540. }
  12541. /**
  12542. * @brief Starts the selected ADC calibration process.
  12543. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12544. * @retval None
  12545. */
  12546. void ADC_StartCalibration(ADC_TypeDef* ADCx)
  12547. {
  12548. /* Check the parameters */
  12549. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12550. /* Enable the selected ADC calibration process */
  12551. ADCx->CR2 |= CR2_CAL_Set;
  12552. }
  12553. /**
  12554. * @brief Gets the selected ADC calibration status.
  12555. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12556. * @retval The new state of ADC calibration (SET or RESET).
  12557. */
  12558. FlagStatus ADC_GetCalibrationStatus(ADC_TypeDef* ADCx)
  12559. {
  12560. FlagStatus bitstatus = RESET;
  12561. /* Check the parameters */
  12562. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12563. /* Check the status of CAL bit */
  12564. if ((ADCx->CR2 & CR2_CAL_Set) != (uint32_t)RESET)
  12565. {
  12566. /* CAL bit is set: calibration on going */
  12567. bitstatus = SET;
  12568. }
  12569. else
  12570. {
  12571. /* CAL bit is reset: end of calibration */
  12572. bitstatus = RESET;
  12573. }
  12574. /* Return the CAL bit status */
  12575. return bitstatus;
  12576. }
  12577. /**
  12578. * @brief Enables or disables the selected ADC software start conversion .
  12579. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12580. * @param NewState: new state of the selected ADC software start conversion.
  12581. * This parameter can be: ENABLE or DISABLE.
  12582. * @retval None
  12583. */
  12584. void ADC_SoftwareStartConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
  12585. {
  12586. /* Check the parameters */
  12587. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12588. assert_param(IS_FUNCTIONAL_STATE(NewState));
  12589. if (NewState != DISABLE)
  12590. {
  12591. /* Enable the selected ADC conversion on external event and start the selected
  12592. ADC conversion */
  12593. ADCx->CR2 |= CR2_EXTTRIG_SWSTART_Set;
  12594. }
  12595. else
  12596. {
  12597. /* Disable the selected ADC conversion on external event and stop the selected
  12598. ADC conversion */
  12599. ADCx->CR2 &= CR2_EXTTRIG_SWSTART_Reset;
  12600. }
  12601. }
  12602. /**
  12603. * @brief Gets the selected ADC Software start conversion Status.
  12604. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12605. * @retval The new state of ADC software start conversion (SET or RESET).
  12606. */
  12607. FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef* ADCx)
  12608. {
  12609. FlagStatus bitstatus = RESET;
  12610. /* Check the parameters */
  12611. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12612. /* Check the status of SWSTART bit */
  12613. if ((ADCx->CR2 & CR2_SWSTART_Set) != (uint32_t)RESET)
  12614. {
  12615. /* SWSTART bit is set */
  12616. bitstatus = SET;
  12617. }
  12618. else
  12619. {
  12620. /* SWSTART bit is reset */
  12621. bitstatus = RESET;
  12622. }
  12623. /* Return the SWSTART bit status */
  12624. return bitstatus;
  12625. }
  12626. /**
  12627. * @brief Configures the discontinuous mode for the selected ADC regular
  12628. * group channel.
  12629. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12630. * @param Number: specifies the discontinuous mode regular channel
  12631. * count value. This number must be between 1 and 8.
  12632. * @retval None
  12633. */
  12634. void ADC_DiscModeChannelCountConfig(ADC_TypeDef* ADCx, uint8_t Number)
  12635. {
  12636. uint32_t tmpreg1 = 0;
  12637. uint32_t tmpreg2 = 0;
  12638. /* Check the parameters */
  12639. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12640. assert_param(IS_ADC_REGULAR_DISC_NUMBER(Number));
  12641. /* Get the old register value */
  12642. tmpreg1 = ADCx->CR1;
  12643. /* Clear the old discontinuous mode channel count */
  12644. tmpreg1 &= CR1_DISCNUM_Reset;
  12645. /* Set the discontinuous mode channel count */
  12646. tmpreg2 = Number - 1;
  12647. tmpreg1 |= tmpreg2 << 13;
  12648. /* Store the new register value */
  12649. ADCx->CR1 = tmpreg1;
  12650. }
  12651. /**
  12652. * @brief Enables or disables the discontinuous mode on regular group
  12653. * channel for the specified ADC
  12654. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12655. * @param NewState: new state of the selected ADC discontinuous mode
  12656. * on regular group channel.
  12657. * This parameter can be: ENABLE or DISABLE.
  12658. * @retval None
  12659. */
  12660. void ADC_DiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
  12661. {
  12662. /* Check the parameters */
  12663. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12664. assert_param(IS_FUNCTIONAL_STATE(NewState));
  12665. if (NewState != DISABLE)
  12666. {
  12667. /* Enable the selected ADC regular discontinuous mode */
  12668. ADCx->CR1 |= CR1_DISCEN_Set;
  12669. }
  12670. else
  12671. {
  12672. /* Disable the selected ADC regular discontinuous mode */
  12673. ADCx->CR1 &= CR1_DISCEN_Reset;
  12674. }
  12675. }
  12676. /**
  12677. * @brief Configures for the selected ADC regular channel its corresponding
  12678. * rank in the sequencer and its sample time.
  12679. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12680. * @param ADC_Channel: the ADC channel to configure.
  12681. * This parameter can be one of the following values:
  12682. * @arg ADC_Channel_0: ADC Channel0 selected
  12683. * @arg ADC_Channel_1: ADC Channel1 selected
  12684. * @arg ADC_Channel_2: ADC Channel2 selected
  12685. * @arg ADC_Channel_3: ADC Channel3 selected
  12686. * @arg ADC_Channel_4: ADC Channel4 selected
  12687. * @arg ADC_Channel_5: ADC Channel5 selected
  12688. * @arg ADC_Channel_6: ADC Channel6 selected
  12689. * @arg ADC_Channel_7: ADC Channel7 selected
  12690. * @arg ADC_Channel_8: ADC Channel8 selected
  12691. * @arg ADC_Channel_9: ADC Channel9 selected
  12692. * @arg ADC_Channel_10: ADC Channel10 selected
  12693. * @arg ADC_Channel_11: ADC Channel11 selected
  12694. * @arg ADC_Channel_12: ADC Channel12 selected
  12695. * @arg ADC_Channel_13: ADC Channel13 selected
  12696. * @arg ADC_Channel_14: ADC Channel14 selected
  12697. * @arg ADC_Channel_15: ADC Channel15 selected
  12698. * @arg ADC_Channel_16: ADC Channel16 selected
  12699. * @arg ADC_Channel_17: ADC Channel17 selected
  12700. * @param Rank: The rank in the regular group sequencer. This parameter must be between 1 to 16.
  12701. * @param ADC_SampleTime: The sample time value to be set for the selected channel.
  12702. * This parameter can be one of the following values:
  12703. * @arg ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles
  12704. * @arg ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles
  12705. * @arg ADC_SampleTime_13Cycles5: Sample time equal to 13.5 cycles
  12706. * @arg ADC_SampleTime_28Cycles5: Sample time equal to 28.5 cycles
  12707. * @arg ADC_SampleTime_41Cycles5: Sample time equal to 41.5 cycles
  12708. * @arg ADC_SampleTime_55Cycles5: Sample time equal to 55.5 cycles
  12709. * @arg ADC_SampleTime_71Cycles5: Sample time equal to 71.5 cycles
  12710. * @arg ADC_SampleTime_239Cycles5: Sample time equal to 239.5 cycles
  12711. * @retval None
  12712. */
  12713. void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)
  12714. {
  12715. uint32_t tmpreg1 = 0, tmpreg2 = 0;
  12716. /* Check the parameters */
  12717. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12718. assert_param(IS_ADC_CHANNEL(ADC_Channel));
  12719. assert_param(IS_ADC_REGULAR_RANK(Rank));
  12720. assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
  12721. /* if ADC_Channel_10 ... ADC_Channel_17 is selected */
  12722. if (ADC_Channel > ADC_Channel_9)
  12723. {
  12724. /* Get the old register value */
  12725. tmpreg1 = ADCx->SMPR1;
  12726. /* Calculate the mask to clear */
  12727. tmpreg2 = SMPR1_SMP_Set << (3 * (ADC_Channel - 10));
  12728. /* Clear the old channel sample time */
  12729. tmpreg1 &= ~tmpreg2;
  12730. /* Calculate the mask to set */
  12731. tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 10));
  12732. /* Set the new channel sample time */
  12733. tmpreg1 |= tmpreg2;
  12734. /* Store the new register value */
  12735. ADCx->SMPR1 = tmpreg1;
  12736. }
  12737. else /* ADC_Channel include in ADC_Channel_[0..9] */
  12738. {
  12739. /* Get the old register value */
  12740. tmpreg1 = ADCx->SMPR2;
  12741. /* Calculate the mask to clear */
  12742. tmpreg2 = SMPR2_SMP_Set << (3 * ADC_Channel);
  12743. /* Clear the old channel sample time */
  12744. tmpreg1 &= ~tmpreg2;
  12745. /* Calculate the mask to set */
  12746. tmpreg2 = (uint32_t)ADC_SampleTime << (3 * ADC_Channel);
  12747. /* Set the new channel sample time */
  12748. tmpreg1 |= tmpreg2;
  12749. /* Store the new register value */
  12750. ADCx->SMPR2 = tmpreg1;
  12751. }
  12752. /* For Rank 1 to 6 */
  12753. if (Rank < 7)
  12754. {
  12755. /* Get the old register value */
  12756. tmpreg1 = ADCx->SQR3;
  12757. /* Calculate the mask to clear */
  12758. tmpreg2 = SQR3_SQ_Set << (5 * (Rank - 1));
  12759. /* Clear the old SQx bits for the selected rank */
  12760. tmpreg1 &= ~tmpreg2;
  12761. /* Calculate the mask to set */
  12762. tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 1));
  12763. /* Set the SQx bits for the selected rank */
  12764. tmpreg1 |= tmpreg2;
  12765. /* Store the new register value */
  12766. ADCx->SQR3 = tmpreg1;
  12767. }
  12768. /* For Rank 7 to 12 */
  12769. else if (Rank < 13)
  12770. {
  12771. /* Get the old register value */
  12772. tmpreg1 = ADCx->SQR2;
  12773. /* Calculate the mask to clear */
  12774. tmpreg2 = SQR2_SQ_Set << (5 * (Rank - 7));
  12775. /* Clear the old SQx bits for the selected rank */
  12776. tmpreg1 &= ~tmpreg2;
  12777. /* Calculate the mask to set */
  12778. tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 7));
  12779. /* Set the SQx bits for the selected rank */
  12780. tmpreg1 |= tmpreg2;
  12781. /* Store the new register value */
  12782. ADCx->SQR2 = tmpreg1;
  12783. }
  12784. /* For Rank 13 to 16 */
  12785. else
  12786. {
  12787. /* Get the old register value */
  12788. tmpreg1 = ADCx->SQR1;
  12789. /* Calculate the mask to clear */
  12790. tmpreg2 = SQR1_SQ_Set << (5 * (Rank - 13));
  12791. /* Clear the old SQx bits for the selected rank */
  12792. tmpreg1 &= ~tmpreg2;
  12793. /* Calculate the mask to set */
  12794. tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 13));
  12795. /* Set the SQx bits for the selected rank */
  12796. tmpreg1 |= tmpreg2;
  12797. /* Store the new register value */
  12798. ADCx->SQR1 = tmpreg1;
  12799. }
  12800. }
  12801. /**
  12802. * @brief Enables or disables the ADCx conversion through external trigger.
  12803. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12804. * @param NewState: new state of the selected ADC external trigger start of conversion.
  12805. * This parameter can be: ENABLE or DISABLE.
  12806. * @retval None
  12807. */
  12808. void ADC_ExternalTrigConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
  12809. {
  12810. /* Check the parameters */
  12811. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12812. assert_param(IS_FUNCTIONAL_STATE(NewState));
  12813. if (NewState != DISABLE)
  12814. {
  12815. /* Enable the selected ADC conversion on external event */
  12816. ADCx->CR2 |= CR2_EXTTRIG_Set;
  12817. }
  12818. else
  12819. {
  12820. /* Disable the selected ADC conversion on external event */
  12821. ADCx->CR2 &= CR2_EXTTRIG_Reset;
  12822. }
  12823. }
  12824. /**
  12825. * @brief Returns the last ADCx conversion result data for regular channel.
  12826. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12827. * @retval The Data conversion value.
  12828. */
  12829. uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx)
  12830. {
  12831. /* Check the parameters */
  12832. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12833. /* Return the selected ADC conversion value */
  12834. return (uint16_t) ADCx->DR;
  12835. }
  12836. /**
  12837. * @brief Returns the last ADC1 and ADC2 conversion result data in dual mode.
  12838. * @retval The Data conversion value.
  12839. */
  12840. uint32_t ADC_GetDualModeConversionValue(void)
  12841. {
  12842. /* Return the dual mode conversion value */
  12843. return (*(__IO uint32_t *) DR_ADDRESS);
  12844. }
  12845. /**
  12846. * @brief Enables or disables the selected ADC automatic injected group
  12847. * conversion after regular one.
  12848. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12849. * @param NewState: new state of the selected ADC auto injected conversion
  12850. * This parameter can be: ENABLE or DISABLE.
  12851. * @retval None
  12852. */
  12853. void ADC_AutoInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
  12854. {
  12855. /* Check the parameters */
  12856. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12857. assert_param(IS_FUNCTIONAL_STATE(NewState));
  12858. if (NewState != DISABLE)
  12859. {
  12860. /* Enable the selected ADC automatic injected group conversion */
  12861. ADCx->CR1 |= CR1_JAUTO_Set;
  12862. }
  12863. else
  12864. {
  12865. /* Disable the selected ADC automatic injected group conversion */
  12866. ADCx->CR1 &= CR1_JAUTO_Reset;
  12867. }
  12868. }
  12869. /**
  12870. * @brief Enables or disables the discontinuous mode for injected group
  12871. * channel for the specified ADC
  12872. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12873. * @param NewState: new state of the selected ADC discontinuous mode
  12874. * on injected group channel.
  12875. * This parameter can be: ENABLE or DISABLE.
  12876. * @retval None
  12877. */
  12878. void ADC_InjectedDiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
  12879. {
  12880. /* Check the parameters */
  12881. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12882. assert_param(IS_FUNCTIONAL_STATE(NewState));
  12883. if (NewState != DISABLE)
  12884. {
  12885. /* Enable the selected ADC injected discontinuous mode */
  12886. ADCx->CR1 |= CR1_JDISCEN_Set;
  12887. }
  12888. else
  12889. {
  12890. /* Disable the selected ADC injected discontinuous mode */
  12891. ADCx->CR1 &= CR1_JDISCEN_Reset;
  12892. }
  12893. }
  12894. /**
  12895. * @brief Configures the ADCx external trigger for injected channels conversion.
  12896. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12897. * @param ADC_ExternalTrigInjecConv: specifies the ADC trigger to start injected conversion.
  12898. * This parameter can be one of the following values:
  12899. * @arg ADC_ExternalTrigInjecConv_T1_TRGO: Timer1 TRGO event selected (for ADC1, ADC2 and ADC3)
  12900. * @arg ADC_ExternalTrigInjecConv_T1_CC4: Timer1 capture compare4 selected (for ADC1, ADC2 and ADC3)
  12901. * @arg ADC_ExternalTrigInjecConv_T2_TRGO: Timer2 TRGO event selected (for ADC1 and ADC2)
  12902. * @arg ADC_ExternalTrigInjecConv_T2_CC1: Timer2 capture compare1 selected (for ADC1 and ADC2)
  12903. * @arg ADC_ExternalTrigInjecConv_T3_CC4: Timer3 capture compare4 selected (for ADC1 and ADC2)
  12904. * @arg ADC_ExternalTrigInjecConv_T4_TRGO: Timer4 TRGO event selected (for ADC1 and ADC2)
  12905. * @arg ADC_ExternalTrigInjecConv_Ext_IT15_TIM8_CC4: External interrupt line 15 or Timer8
  12906. * capture compare4 event selected (for ADC1 and ADC2)
  12907. * @arg ADC_ExternalTrigInjecConv_T4_CC3: Timer4 capture compare3 selected (for ADC3 only)
  12908. * @arg ADC_ExternalTrigInjecConv_T8_CC2: Timer8 capture compare2 selected (for ADC3 only)
  12909. * @arg ADC_ExternalTrigInjecConv_T8_CC4: Timer8 capture compare4 selected (for ADC3 only)
  12910. * @arg ADC_ExternalTrigInjecConv_T5_TRGO: Timer5 TRGO event selected (for ADC3 only)
  12911. * @arg ADC_ExternalTrigInjecConv_T5_CC4: Timer5 capture compare4 selected (for ADC3 only)
  12912. * @arg ADC_ExternalTrigInjecConv_None: Injected conversion started by software and not
  12913. * by external trigger (for ADC1, ADC2 and ADC3)
  12914. * @retval None
  12915. */
  12916. void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef* ADCx, uint32_t ADC_ExternalTrigInjecConv)
  12917. {
  12918. uint32_t tmpreg = 0;
  12919. /* Check the parameters */
  12920. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12921. assert_param(IS_ADC_EXT_INJEC_TRIG(ADC_ExternalTrigInjecConv));
  12922. /* Get the old register value */
  12923. tmpreg = ADCx->CR2;
  12924. /* Clear the old external event selection for injected group */
  12925. tmpreg &= CR2_JEXTSEL_Reset;
  12926. /* Set the external event selection for injected group */
  12927. tmpreg |= ADC_ExternalTrigInjecConv;
  12928. /* Store the new register value */
  12929. ADCx->CR2 = tmpreg;
  12930. }
  12931. /**
  12932. * @brief Enables or disables the ADCx injected channels conversion through
  12933. * external trigger
  12934. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12935. * @param NewState: new state of the selected ADC external trigger start of
  12936. * injected conversion.
  12937. * This parameter can be: ENABLE or DISABLE.
  12938. * @retval None
  12939. */
  12940. void ADC_ExternalTrigInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
  12941. {
  12942. /* Check the parameters */
  12943. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12944. assert_param(IS_FUNCTIONAL_STATE(NewState));
  12945. if (NewState != DISABLE)
  12946. {
  12947. /* Enable the selected ADC external event selection for injected group */
  12948. ADCx->CR2 |= CR2_JEXTTRIG_Set;
  12949. }
  12950. else
  12951. {
  12952. /* Disable the selected ADC external event selection for injected group */
  12953. ADCx->CR2 &= CR2_JEXTTRIG_Reset;
  12954. }
  12955. }
  12956. /**
  12957. * @brief Enables or disables the selected ADC start of the injected
  12958. * channels conversion.
  12959. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12960. * @param NewState: new state of the selected ADC software start injected conversion.
  12961. * This parameter can be: ENABLE or DISABLE.
  12962. * @retval None
  12963. */
  12964. void ADC_SoftwareStartInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
  12965. {
  12966. /* Check the parameters */
  12967. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12968. assert_param(IS_FUNCTIONAL_STATE(NewState));
  12969. if (NewState != DISABLE)
  12970. {
  12971. /* Enable the selected ADC conversion for injected group on external event and start the selected
  12972. ADC injected conversion */
  12973. ADCx->CR2 |= CR2_JEXTTRIG_JSWSTART_Set;
  12974. }
  12975. else
  12976. {
  12977. /* Disable the selected ADC conversion on external event for injected group and stop the selected
  12978. ADC injected conversion */
  12979. ADCx->CR2 &= CR2_JEXTTRIG_JSWSTART_Reset;
  12980. }
  12981. }
  12982. /**
  12983. * @brief Gets the selected ADC Software start injected conversion Status.
  12984. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  12985. * @retval The new state of ADC software start injected conversion (SET or RESET).
  12986. */
  12987. FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef* ADCx)
  12988. {
  12989. FlagStatus bitstatus = RESET;
  12990. /* Check the parameters */
  12991. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  12992. /* Check the status of JSWSTART bit */
  12993. if ((ADCx->CR2 & CR2_JSWSTART_Set) != (uint32_t)RESET)
  12994. {
  12995. /* JSWSTART bit is set */
  12996. bitstatus = SET;
  12997. }
  12998. else
  12999. {
  13000. /* JSWSTART bit is reset */
  13001. bitstatus = RESET;
  13002. }
  13003. /* Return the JSWSTART bit status */
  13004. return bitstatus;
  13005. }
  13006. /**
  13007. * @brief Configures for the selected ADC injected channel its corresponding
  13008. * rank in the sequencer and its sample time.
  13009. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  13010. * @param ADC_Channel: the ADC channel to configure.
  13011. * This parameter can be one of the following values:
  13012. * @arg ADC_Channel_0: ADC Channel0 selected
  13013. * @arg ADC_Channel_1: ADC Channel1 selected
  13014. * @arg ADC_Channel_2: ADC Channel2 selected
  13015. * @arg ADC_Channel_3: ADC Channel3 selected
  13016. * @arg ADC_Channel_4: ADC Channel4 selected
  13017. * @arg ADC_Channel_5: ADC Channel5 selected
  13018. * @arg ADC_Channel_6: ADC Channel6 selected
  13019. * @arg ADC_Channel_7: ADC Channel7 selected
  13020. * @arg ADC_Channel_8: ADC Channel8 selected
  13021. * @arg ADC_Channel_9: ADC Channel9 selected
  13022. * @arg ADC_Channel_10: ADC Channel10 selected
  13023. * @arg ADC_Channel_11: ADC Channel11 selected
  13024. * @arg ADC_Channel_12: ADC Channel12 selected
  13025. * @arg ADC_Channel_13: ADC Channel13 selected
  13026. * @arg ADC_Channel_14: ADC Channel14 selected
  13027. * @arg ADC_Channel_15: ADC Channel15 selected
  13028. * @arg ADC_Channel_16: ADC Channel16 selected
  13029. * @arg ADC_Channel_17: ADC Channel17 selected
  13030. * @param Rank: The rank in the injected group sequencer. This parameter must be between 1 and 4.
  13031. * @param ADC_SampleTime: The sample time value to be set for the selected channel.
  13032. * This parameter can be one of the following values:
  13033. * @arg ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles
  13034. * @arg ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles
  13035. * @arg ADC_SampleTime_13Cycles5: Sample time equal to 13.5 cycles
  13036. * @arg ADC_SampleTime_28Cycles5: Sample time equal to 28.5 cycles
  13037. * @arg ADC_SampleTime_41Cycles5: Sample time equal to 41.5 cycles
  13038. * @arg ADC_SampleTime_55Cycles5: Sample time equal to 55.5 cycles
  13039. * @arg ADC_SampleTime_71Cycles5: Sample time equal to 71.5 cycles
  13040. * @arg ADC_SampleTime_239Cycles5: Sample time equal to 239.5 cycles
  13041. * @retval None
  13042. */
  13043. void ADC_InjectedChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)
  13044. {
  13045. uint32_t tmpreg1 = 0, tmpreg2 = 0, tmpreg3 = 0;
  13046. /* Check the parameters */
  13047. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  13048. assert_param(IS_ADC_CHANNEL(ADC_Channel));
  13049. assert_param(IS_ADC_INJECTED_RANK(Rank));
  13050. assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
  13051. /* if ADC_Channel_10 ... ADC_Channel_17 is selected */
  13052. if (ADC_Channel > ADC_Channel_9)
  13053. {
  13054. /* Get the old register value */
  13055. tmpreg1 = ADCx->SMPR1;
  13056. /* Calculate the mask to clear */
  13057. tmpreg2 = SMPR1_SMP_Set << (3*(ADC_Channel - 10));
  13058. /* Clear the old channel sample time */
  13059. tmpreg1 &= ~tmpreg2;
  13060. /* Calculate the mask to set */
  13061. tmpreg2 = (uint32_t)ADC_SampleTime << (3*(ADC_Channel - 10));
  13062. /* Set the new channel sample time */
  13063. tmpreg1 |= tmpreg2;
  13064. /* Store the new register value */
  13065. ADCx->SMPR1 = tmpreg1;
  13066. }
  13067. else /* ADC_Channel include in ADC_Channel_[0..9] */
  13068. {
  13069. /* Get the old register value */
  13070. tmpreg1 = ADCx->SMPR2;
  13071. /* Calculate the mask to clear */
  13072. tmpreg2 = SMPR2_SMP_Set << (3 * ADC_Channel);
  13073. /* Clear the old channel sample time */
  13074. tmpreg1 &= ~tmpreg2;
  13075. /* Calculate the mask to set */
  13076. tmpreg2 = (uint32_t)ADC_SampleTime << (3 * ADC_Channel);
  13077. /* Set the new channel sample time */
  13078. tmpreg1 |= tmpreg2;
  13079. /* Store the new register value */
  13080. ADCx->SMPR2 = tmpreg1;
  13081. }
  13082. /* Rank configuration */
  13083. /* Get the old register value */
  13084. tmpreg1 = ADCx->JSQR;
  13085. /* Get JL value: Number = JL+1 */
  13086. tmpreg3 = (tmpreg1 & JSQR_JL_Set)>> 20;
  13087. /* Calculate the mask to clear: ((Rank-1)+(4-JL-1)) */
  13088. tmpreg2 = JSQR_JSQ_Set << (5 * (uint8_t)((Rank + 3) - (tmpreg3 + 1)));
  13089. /* Clear the old JSQx bits for the selected rank */
  13090. tmpreg1 &= ~tmpreg2;
  13091. /* Calculate the mask to set: ((Rank-1)+(4-JL-1)) */
  13092. tmpreg2 = (uint32_t)ADC_Channel << (5 * (uint8_t)((Rank + 3) - (tmpreg3 + 1)));
  13093. /* Set the JSQx bits for the selected rank */
  13094. tmpreg1 |= tmpreg2;
  13095. /* Store the new register value */
  13096. ADCx->JSQR = tmpreg1;
  13097. }
  13098. /**
  13099. * @brief Configures the sequencer length for injected channels
  13100. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  13101. * @param Length: The sequencer length.
  13102. * This parameter must be a number between 1 to 4.
  13103. * @retval None
  13104. */
  13105. void ADC_InjectedSequencerLengthConfig(ADC_TypeDef* ADCx, uint8_t Length)
  13106. {
  13107. uint32_t tmpreg1 = 0;
  13108. uint32_t tmpreg2 = 0;
  13109. /* Check the parameters */
  13110. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  13111. assert_param(IS_ADC_INJECTED_LENGTH(Length));
  13112. /* Get the old register value */
  13113. tmpreg1 = ADCx->JSQR;
  13114. /* Clear the old injected sequnence lenght JL bits */
  13115. tmpreg1 &= JSQR_JL_Reset;
  13116. /* Set the injected sequnence lenght JL bits */
  13117. tmpreg2 = Length - 1;
  13118. tmpreg1 |= tmpreg2 << 20;
  13119. /* Store the new register value */
  13120. ADCx->JSQR = tmpreg1;
  13121. }
  13122. /**
  13123. * @brief Set the injected channels conversion value offset
  13124. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  13125. * @param ADC_InjectedChannel: the ADC injected channel to set its offset.
  13126. * This parameter can be one of the following values:
  13127. * @arg ADC_InjectedChannel_1: Injected Channel1 selected
  13128. * @arg ADC_InjectedChannel_2: Injected Channel2 selected
  13129. * @arg ADC_InjectedChannel_3: Injected Channel3 selected
  13130. * @arg ADC_InjectedChannel_4: Injected Channel4 selected
  13131. * @param Offset: the offset value for the selected ADC injected channel
  13132. * This parameter must be a 12bit value.
  13133. * @retval None
  13134. */
  13135. void ADC_SetInjectedOffset(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel, uint16_t Offset)
  13136. {
  13137. __IO uint32_t tmp = 0;
  13138. /* Check the parameters */
  13139. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  13140. assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
  13141. assert_param(IS_ADC_OFFSET(Offset));
  13142. tmp = (uint32_t)ADCx;
  13143. tmp += ADC_InjectedChannel;
  13144. /* Set the selected injected channel data offset */
  13145. *(__IO uint32_t *) tmp = (uint32_t)Offset;
  13146. }
  13147. /**
  13148. * @brief Returns the ADC injected channel conversion result
  13149. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  13150. * @param ADC_InjectedChannel: the converted ADC injected channel.
  13151. * This parameter can be one of the following values:
  13152. * @arg ADC_InjectedChannel_1: Injected Channel1 selected
  13153. * @arg ADC_InjectedChannel_2: Injected Channel2 selected
  13154. * @arg ADC_InjectedChannel_3: Injected Channel3 selected
  13155. * @arg ADC_InjectedChannel_4: Injected Channel4 selected
  13156. * @retval The Data conversion value.
  13157. */
  13158. uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel)
  13159. {
  13160. __IO uint32_t tmp = 0;
  13161. /* Check the parameters */
  13162. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  13163. assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
  13164. tmp = (uint32_t)ADCx;
  13165. tmp += ADC_InjectedChannel + JDR_Offset;
  13166. /* Returns the selected injected channel conversion data value */
  13167. return (uint16_t) (*(__IO uint32_t*) tmp);
  13168. }
  13169. /**
  13170. * @brief Enables or disables the analog watchdog on single/all regular
  13171. * or injected channels
  13172. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  13173. * @param ADC_AnalogWatchdog: the ADC analog watchdog configuration.
  13174. * This parameter can be one of the following values:
  13175. * @arg ADC_AnalogWatchdog_SingleRegEnable: Analog watchdog on a single regular channel
  13176. * @arg ADC_AnalogWatchdog_SingleInjecEnable: Analog watchdog on a single injected channel
  13177. * @arg ADC_AnalogWatchdog_SingleRegOrInjecEnable: Analog watchdog on a single regular or injected channel
  13178. * @arg ADC_AnalogWatchdog_AllRegEnable: Analog watchdog on all regular channel
  13179. * @arg ADC_AnalogWatchdog_AllInjecEnable: Analog watchdog on all injected channel
  13180. * @arg ADC_AnalogWatchdog_AllRegAllInjecEnable: Analog watchdog on all regular and injected channels
  13181. * @arg ADC_AnalogWatchdog_None: No channel guarded by the analog watchdog
  13182. * @retval None
  13183. */
  13184. void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog)
  13185. {
  13186. uint32_t tmpreg = 0;
  13187. /* Check the parameters */
  13188. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  13189. assert_param(IS_ADC_ANALOG_WATCHDOG(ADC_AnalogWatchdog));
  13190. /* Get the old register value */
  13191. tmpreg = ADCx->CR1;
  13192. /* Clear AWDEN, AWDENJ and AWDSGL bits */
  13193. tmpreg &= CR1_AWDMode_Reset;
  13194. /* Set the analog watchdog enable mode */
  13195. tmpreg |= ADC_AnalogWatchdog;
  13196. /* Store the new register value */
  13197. ADCx->CR1 = tmpreg;
  13198. }
  13199. /**
  13200. * @brief Configures the high and low thresholds of the analog watchdog.
  13201. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  13202. * @param HighThreshold: the ADC analog watchdog High threshold value.
  13203. * This parameter must be a 12bit value.
  13204. * @param LowThreshold: the ADC analog watchdog Low threshold value.
  13205. * This parameter must be a 12bit value.
  13206. * @retval None
  13207. */
  13208. void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold,
  13209. uint16_t LowThreshold)
  13210. {
  13211. /* Check the parameters */
  13212. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  13213. assert_param(IS_ADC_THRESHOLD(HighThreshold));
  13214. assert_param(IS_ADC_THRESHOLD(LowThreshold));
  13215. /* Set the ADCx high threshold */
  13216. ADCx->HTR = HighThreshold;
  13217. /* Set the ADCx low threshold */
  13218. ADCx->LTR = LowThreshold;
  13219. }
  13220. /**
  13221. * @brief Configures the analog watchdog guarded single channel
  13222. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  13223. * @param ADC_Channel: the ADC channel to configure for the analog watchdog.
  13224. * This parameter can be one of the following values:
  13225. * @arg ADC_Channel_0: ADC Channel0 selected
  13226. * @arg ADC_Channel_1: ADC Channel1 selected
  13227. * @arg ADC_Channel_2: ADC Channel2 selected
  13228. * @arg ADC_Channel_3: ADC Channel3 selected
  13229. * @arg ADC_Channel_4: ADC Channel4 selected
  13230. * @arg ADC_Channel_5: ADC Channel5 selected
  13231. * @arg ADC_Channel_6: ADC Channel6 selected
  13232. * @arg ADC_Channel_7: ADC Channel7 selected
  13233. * @arg ADC_Channel_8: ADC Channel8 selected
  13234. * @arg ADC_Channel_9: ADC Channel9 selected
  13235. * @arg ADC_Channel_10: ADC Channel10 selected
  13236. * @arg ADC_Channel_11: ADC Channel11 selected
  13237. * @arg ADC_Channel_12: ADC Channel12 selected
  13238. * @arg ADC_Channel_13: ADC Channel13 selected
  13239. * @arg ADC_Channel_14: ADC Channel14 selected
  13240. * @arg ADC_Channel_15: ADC Channel15 selected
  13241. * @arg ADC_Channel_16: ADC Channel16 selected
  13242. * @arg ADC_Channel_17: ADC Channel17 selected
  13243. * @retval None
  13244. */
  13245. void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel)
  13246. {
  13247. uint32_t tmpreg = 0;
  13248. /* Check the parameters */
  13249. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  13250. assert_param(IS_ADC_CHANNEL(ADC_Channel));
  13251. /* Get the old register value */
  13252. tmpreg = ADCx->CR1;
  13253. /* Clear the Analog watchdog channel select bits */
  13254. tmpreg &= CR1_AWDCH_Reset;
  13255. /* Set the Analog watchdog channel */
  13256. tmpreg |= ADC_Channel;
  13257. /* Store the new register value */
  13258. ADCx->CR1 = tmpreg;
  13259. }
  13260. /**
  13261. * @brief Enables or disables the temperature sensor and Vrefint channel.
  13262. * @param NewState: new state of the temperature sensor.
  13263. * This parameter can be: ENABLE or DISABLE.
  13264. * @retval None
  13265. */
  13266. void ADC_TempSensorVrefintCmd(FunctionalState NewState)
  13267. {
  13268. /* Check the parameters */
  13269. assert_param(IS_FUNCTIONAL_STATE(NewState));
  13270. if (NewState != DISABLE)
  13271. {
  13272. /* Enable the temperature sensor and Vrefint channel*/
  13273. ADC1->CR2 |= CR2_TSVREFE_Set;
  13274. }
  13275. else
  13276. {
  13277. /* Disable the temperature sensor and Vrefint channel*/
  13278. ADC1->CR2 &= CR2_TSVREFE_Reset;
  13279. }
  13280. }
  13281. /**
  13282. * @brief Checks whether the specified ADC flag is set or not.
  13283. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  13284. * @param ADC_FLAG: specifies the flag to check.
  13285. * This parameter can be one of the following values:
  13286. * @arg ADC_FLAG_AWD: Analog watchdog flag
  13287. * @arg ADC_FLAG_EOC: End of conversion flag
  13288. * @arg ADC_FLAG_JEOC: End of injected group conversion flag
  13289. * @arg ADC_FLAG_JSTRT: Start of injected group conversion flag
  13290. * @arg ADC_FLAG_STRT: Start of regular group conversion flag
  13291. * @retval The new state of ADC_FLAG (SET or RESET).
  13292. */
  13293. FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint8_t ADC_FLAG)
  13294. {
  13295. FlagStatus bitstatus = RESET;
  13296. /* Check the parameters */
  13297. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  13298. assert_param(IS_ADC_GET_FLAG(ADC_FLAG));
  13299. /* Check the status of the specified ADC flag */
  13300. if ((ADCx->SR & ADC_FLAG) != (uint8_t)RESET)
  13301. {
  13302. /* ADC_FLAG is set */
  13303. bitstatus = SET;
  13304. }
  13305. else
  13306. {
  13307. /* ADC_FLAG is reset */
  13308. bitstatus = RESET;
  13309. }
  13310. /* Return the ADC_FLAG status */
  13311. return bitstatus;
  13312. }
  13313. /**
  13314. * @brief Clears the ADCx's pending flags.
  13315. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  13316. * @param ADC_FLAG: specifies the flag to clear.
  13317. * This parameter can be any combination of the following values:
  13318. * @arg ADC_FLAG_AWD: Analog watchdog flag
  13319. * @arg ADC_FLAG_EOC: End of conversion flag
  13320. * @arg ADC_FLAG_JEOC: End of injected group conversion flag
  13321. * @arg ADC_FLAG_JSTRT: Start of injected group conversion flag
  13322. * @arg ADC_FLAG_STRT: Start of regular group conversion flag
  13323. * @retval None
  13324. */
  13325. void ADC_ClearFlag(ADC_TypeDef* ADCx, uint8_t ADC_FLAG)
  13326. {
  13327. /* Check the parameters */
  13328. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  13329. assert_param(IS_ADC_CLEAR_FLAG(ADC_FLAG));
  13330. /* Clear the selected ADC flags */
  13331. ADCx->SR = ~(uint32_t)ADC_FLAG;
  13332. }
  13333. /**
  13334. * @brief Checks whether the specified ADC interrupt has occurred or not.
  13335. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  13336. * @param ADC_IT: specifies the ADC interrupt source to check.
  13337. * This parameter can be one of the following values:
  13338. * @arg ADC_IT_EOC: End of conversion interrupt mask
  13339. * @arg ADC_IT_AWD: Analog watchdog interrupt mask
  13340. * @arg ADC_IT_JEOC: End of injected conversion interrupt mask
  13341. * @retval The new state of ADC_IT (SET or RESET).
  13342. */
  13343. ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint16_t ADC_IT)
  13344. {
  13345. ITStatus bitstatus = RESET;
  13346. uint32_t itmask = 0, enablestatus = 0;
  13347. /* Check the parameters */
  13348. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  13349. assert_param(IS_ADC_GET_IT(ADC_IT));
  13350. /* Get the ADC IT index */
  13351. itmask = ADC_IT >> 8;
  13352. /* Get the ADC_IT enable bit status */
  13353. enablestatus = (ADCx->CR1 & (uint8_t)ADC_IT) ;
  13354. /* Check the status of the specified ADC interrupt */
  13355. if (((ADCx->SR & itmask) != (uint32_t)RESET) && enablestatus)
  13356. {
  13357. /* ADC_IT is set */
  13358. bitstatus = SET;
  13359. }
  13360. else
  13361. {
  13362. /* ADC_IT is reset */
  13363. bitstatus = RESET;
  13364. }
  13365. /* Return the ADC_IT status */
  13366. return bitstatus;
  13367. }
  13368. /**
  13369. * @brief Clears the ADCx's interrupt pending bits.
  13370. * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
  13371. * @param ADC_IT: specifies the ADC interrupt pending bit to clear.
  13372. * This parameter can be any combination of the following values:
  13373. * @arg ADC_IT_EOC: End of conversion interrupt mask
  13374. * @arg ADC_IT_AWD: Analog watchdog interrupt mask
  13375. * @arg ADC_IT_JEOC: End of injected conversion interrupt mask
  13376. * @retval None
  13377. */
  13378. void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint16_t ADC_IT)
  13379. {
  13380. uint8_t itmask = 0;
  13381. /* Check the parameters */
  13382. assert_param(IS_ADC_ALL_PERIPH(ADCx));
  13383. assert_param(IS_ADC_IT(ADC_IT));
  13384. /* Get the ADC IT index */
  13385. itmask = (uint8_t)(ADC_IT >> 8);
  13386. /* Clear the selected ADC interrupt pending bits */
  13387. ADCx->SR = ~(uint32_t)itmask;
  13388. }
  13389. /**
  13390. * @}
  13391. */
  13392. /**
  13393. * @}
  13394. */
  13395. /**
  13396. * @}
  13397. */
  13398. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  13399. /**
  13400. ******************************************************************************
  13401. * @file stm32f10x_rcc.c
  13402. * @author MCD Application Team
  13403. * @version V3.5.0
  13404. * @date 11-March-2011
  13405. * @brief This file provides all the RCC firmware functions.
  13406. ******************************************************************************
  13407. * @attention
  13408. *
  13409. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13410. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13411. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  13412. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  13413. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  13414. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  13415. *
  13416. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  13417. ******************************************************************************
  13418. */
  13419. /* Includes ------------------------------------------------------------------*/
  13420. #include "stm32f10x_rcc.h"
  13421. /** @addtogroup STM32F10x_StdPeriph_Driver
  13422. * @{
  13423. */
  13424. /** @defgroup RCC
  13425. * @brief RCC driver modules
  13426. * @{
  13427. */
  13428. /** @defgroup RCC_Private_TypesDefinitions
  13429. * @{
  13430. */
  13431. /**
  13432. * @}
  13433. */
  13434. /** @defgroup RCC_Private_Defines
  13435. * @{
  13436. */
  13437. /* ------------ RCC registers bit address in the alias region ----------- */
  13438. #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
  13439. /* --- CR Register ---*/
  13440. /* Alias word address of HSION bit */
  13441. #define CR_OFFSET (RCC_OFFSET + 0x00)
  13442. #define HSION_BitNumber 0x00
  13443. #define CR_HSION_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (HSION_BitNumber * 4))
  13444. /* Alias word address of PLLON bit */
  13445. #define PLLON_BitNumber 0x18
  13446. #define CR_PLLON_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLLON_BitNumber * 4))
  13447. #ifdef STM32F10X_CL
  13448. /* Alias word address of PLL2ON bit */
  13449. #define PLL2ON_BitNumber 0x1A
  13450. #define CR_PLL2ON_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLL2ON_BitNumber * 4))
  13451. /* Alias word address of PLL3ON bit */
  13452. #define PLL3ON_BitNumber 0x1C
  13453. #define CR_PLL3ON_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLL3ON_BitNumber * 4))
  13454. #endif /* STM32F10X_CL */
  13455. /* Alias word address of CSSON bit */
  13456. #define CSSON_BitNumber 0x13
  13457. #define CR_CSSON_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (CSSON_BitNumber * 4))
  13458. /* --- CFGR Register ---*/
  13459. /* Alias word address of USBPRE bit */
  13460. #define CFGR_OFFSET (RCC_OFFSET + 0x04)
  13461. #ifndef STM32F10X_CL
  13462. #define USBPRE_BitNumber 0x16
  13463. #define CFGR_USBPRE_BB (PERIPH_BB_BASE + (CFGR_OFFSET * 32) + (USBPRE_BitNumber * 4))
  13464. #else
  13465. #define OTGFSPRE_BitNumber 0x16
  13466. #define CFGR_OTGFSPRE_BB (PERIPH_BB_BASE + (CFGR_OFFSET * 32) + (OTGFSPRE_BitNumber * 4))
  13467. #endif /* STM32F10X_CL */
  13468. /* --- BDCR Register ---*/
  13469. /* Alias word address of RTCEN bit */
  13470. #define BDCR_OFFSET (RCC_OFFSET + 0x20)
  13471. #define RTCEN_BitNumber 0x0F
  13472. #define BDCR_RTCEN_BB (PERIPH_BB_BASE + (BDCR_OFFSET * 32) + (RTCEN_BitNumber * 4))
  13473. /* Alias word address of BDRST bit */
  13474. #define BDRST_BitNumber 0x10
  13475. #define BDCR_BDRST_BB (PERIPH_BB_BASE + (BDCR_OFFSET * 32) + (BDRST_BitNumber * 4))
  13476. /* --- CSR Register ---*/
  13477. /* Alias word address of LSION bit */
  13478. #define CSR_OFFSET (RCC_OFFSET + 0x24)
  13479. #define LSION_BitNumber 0x00
  13480. #define CSR_LSION_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (LSION_BitNumber * 4))
  13481. #ifdef STM32F10X_CL
  13482. /* --- CFGR2 Register ---*/
  13483. /* Alias word address of I2S2SRC bit */
  13484. #define CFGR2_OFFSET (RCC_OFFSET + 0x2C)
  13485. #define I2S2SRC_BitNumber 0x11
  13486. #define CFGR2_I2S2SRC_BB (PERIPH_BB_BASE + (CFGR2_OFFSET * 32) + (I2S2SRC_BitNumber * 4))
  13487. /* Alias word address of I2S3SRC bit */
  13488. #define I2S3SRC_BitNumber 0x12
  13489. #define CFGR2_I2S3SRC_BB (PERIPH_BB_BASE + (CFGR2_OFFSET * 32) + (I2S3SRC_BitNumber * 4))
  13490. #endif /* STM32F10X_CL */
  13491. /* ---------------------- RCC registers bit mask ------------------------ */
  13492. /* CR register bit mask */
  13493. #define CR_HSEBYP_Reset ((uint32_t)0xFFFBFFFF)
  13494. #define CR_HSEBYP_Set ((uint32_t)0x00040000)
  13495. #define CR_HSEON_Reset ((uint32_t)0xFFFEFFFF)
  13496. #define CR_HSEON_Set ((uint32_t)0x00010000)
  13497. #define CR_HSITRIM_Mask ((uint32_t)0xFFFFFF07)
  13498. /* CFGR register bit mask */
  13499. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) || defined (STM32F10X_CL)
  13500. #define CFGR_PLL_Mask ((uint32_t)0xFFC2FFFF)
  13501. #else
  13502. #define CFGR_PLL_Mask ((uint32_t)0xFFC0FFFF)
  13503. #endif /* STM32F10X_CL */
  13504. #define CFGR_PLLMull_Mask ((uint32_t)0x003C0000)
  13505. #define CFGR_PLLSRC_Mask ((uint32_t)0x00010000)
  13506. #define CFGR_PLLXTPRE_Mask ((uint32_t)0x00020000)
  13507. #define CFGR_SWS_Mask ((uint32_t)0x0000000C)
  13508. #define CFGR_SW_Mask ((uint32_t)0xFFFFFFFC)
  13509. #define CFGR_HPRE_Reset_Mask ((uint32_t)0xFFFFFF0F)
  13510. #define CFGR_HPRE_Set_Mask ((uint32_t)0x000000F0)
  13511. #define CFGR_PPRE1_Reset_Mask ((uint32_t)0xFFFFF8FF)
  13512. #define CFGR_PPRE1_Set_Mask ((uint32_t)0x00000700)
  13513. #define CFGR_PPRE2_Reset_Mask ((uint32_t)0xFFFFC7FF)
  13514. #define CFGR_PPRE2_Set_Mask ((uint32_t)0x00003800)
  13515. #define CFGR_ADCPRE_Reset_Mask ((uint32_t)0xFFFF3FFF)
  13516. #define CFGR_ADCPRE_Set_Mask ((uint32_t)0x0000C000)
  13517. /* CSR register bit mask */
  13518. #define CSR_RMVF_Set ((uint32_t)0x01000000)
  13519. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) || defined (STM32F10X_CL)
  13520. /* CFGR2 register bit mask */
  13521. #define CFGR2_PREDIV1SRC ((uint32_t)0x00010000)
  13522. #define CFGR2_PREDIV1 ((uint32_t)0x0000000F)
  13523. #endif
  13524. #ifdef STM32F10X_CL
  13525. #define CFGR2_PREDIV2 ((uint32_t)0x000000F0)
  13526. #define CFGR2_PLL2MUL ((uint32_t)0x00000F00)
  13527. #define CFGR2_PLL3MUL ((uint32_t)0x0000F000)
  13528. #endif /* STM32F10X_CL */
  13529. /* RCC Flag Mask */
  13530. #define FLAG_Mask ((uint8_t)0x1F)
  13531. /* CIR register byte 2 (Bits[15:8]) base address */
  13532. #define CIR_BYTE2_ADDRESS ((uint32_t)0x40021009)
  13533. /* CIR register byte 3 (Bits[23:16]) base address */
  13534. #define CIR_BYTE3_ADDRESS ((uint32_t)0x4002100A)
  13535. /* CFGR register byte 4 (Bits[31:24]) base address */
  13536. #define CFGR_BYTE4_ADDRESS ((uint32_t)0x40021007)
  13537. /* BDCR register base address */
  13538. #define BDCR_ADDRESS (PERIPH_BASE + BDCR_OFFSET)
  13539. /**
  13540. * @}
  13541. */
  13542. /** @defgroup RCC_Private_Macros
  13543. * @{
  13544. */
  13545. /**
  13546. * @}
  13547. */
  13548. /** @defgroup RCC_Private_Variables
  13549. * @{
  13550. */
  13551. static __I uint8_t APBAHBPrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
  13552. static __I uint8_t ADCPrescTable[4] = {2, 4, 6, 8};
  13553. /**
  13554. * @}
  13555. */
  13556. /** @defgroup RCC_Private_FunctionPrototypes
  13557. * @{
  13558. */
  13559. /**
  13560. * @}
  13561. */
  13562. /** @defgroup RCC_Private_Functions
  13563. * @{
  13564. */
  13565. /**
  13566. * @brief Resets the RCC clock configuration to the default reset state.
  13567. * @param None
  13568. * @retval None
  13569. */
  13570. void RCC_DeInit(void)
  13571. {
  13572. /* Set HSION bit */
  13573. RCC->CR |= (uint32_t)0x00000001;
  13574. /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
  13575. #ifndef STM32F10X_CL
  13576. RCC->CFGR &= (uint32_t)0xF8FF0000;
  13577. #else
  13578. RCC->CFGR &= (uint32_t)0xF0FF0000;
  13579. #endif /* STM32F10X_CL */
  13580. /* Reset HSEON, CSSON and PLLON bits */
  13581. RCC->CR &= (uint32_t)0xFEF6FFFF;
  13582. /* Reset HSEBYP bit */
  13583. RCC->CR &= (uint32_t)0xFFFBFFFF;
  13584. /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
  13585. RCC->CFGR &= (uint32_t)0xFF80FFFF;
  13586. #ifdef STM32F10X_CL
  13587. /* Reset PLL2ON and PLL3ON bits */
  13588. RCC->CR &= (uint32_t)0xEBFFFFFF;
  13589. /* Disable all interrupts and clear pending bits */
  13590. RCC->CIR = 0x00FF0000;
  13591. /* Reset CFGR2 register */
  13592. RCC->CFGR2 = 0x00000000;
  13593. #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  13594. /* Disable all interrupts and clear pending bits */
  13595. RCC->CIR = 0x009F0000;
  13596. /* Reset CFGR2 register */
  13597. RCC->CFGR2 = 0x00000000;
  13598. #else
  13599. /* Disable all interrupts and clear pending bits */
  13600. RCC->CIR = 0x009F0000;
  13601. #endif /* STM32F10X_CL */
  13602. }
  13603. /**
  13604. * @brief Configures the External High Speed oscillator (HSE).
  13605. * @note HSE can not be stopped if it is used directly or through the PLL as system clock.
  13606. * @param RCC_HSE: specifies the new state of the HSE.
  13607. * This parameter can be one of the following values:
  13608. * @arg RCC_HSE_OFF: HSE oscillator OFF
  13609. * @arg RCC_HSE_ON: HSE oscillator ON
  13610. * @arg RCC_HSE_Bypass: HSE oscillator bypassed with external clock
  13611. * @retval None
  13612. */
  13613. void RCC_HSEConfig(uint32_t RCC_HSE)
  13614. {
  13615. /* Check the parameters */
  13616. assert_param(IS_RCC_HSE(RCC_HSE));
  13617. /* Reset HSEON and HSEBYP bits before configuring the HSE ------------------*/
  13618. /* Reset HSEON bit */
  13619. RCC->CR &= CR_HSEON_Reset;
  13620. /* Reset HSEBYP bit */
  13621. RCC->CR &= CR_HSEBYP_Reset;
  13622. /* Configure HSE (RCC_HSE_OFF is already covered by the code section above) */
  13623. switch(RCC_HSE)
  13624. {
  13625. case RCC_HSE_ON:
  13626. /* Set HSEON bit */
  13627. RCC->CR |= CR_HSEON_Set;
  13628. break;
  13629. case RCC_HSE_Bypass:
  13630. /* Set HSEBYP and HSEON bits */
  13631. RCC->CR |= CR_HSEBYP_Set | CR_HSEON_Set;
  13632. break;
  13633. default:
  13634. break;
  13635. }
  13636. }
  13637. /**
  13638. * @brief Waits for HSE start-up.
  13639. * @param None
  13640. * @retval An ErrorStatus enumuration value:
  13641. * - SUCCESS: HSE oscillator is stable and ready to use
  13642. * - ERROR: HSE oscillator not yet ready
  13643. */
  13644. ErrorStatus RCC_WaitForHSEStartUp(void)
  13645. {
  13646. __IO uint32_t StartUpCounter = 0;
  13647. ErrorStatus status = ERROR;
  13648. FlagStatus HSEStatus = RESET;
  13649. /* Wait till HSE is ready and if Time out is reached exit */
  13650. do
  13651. {
  13652. HSEStatus = RCC_GetFlagStatus(RCC_FLAG_HSERDY);
  13653. StartUpCounter++;
  13654. } while((StartUpCounter != HSE_STARTUP_TIMEOUT) && (HSEStatus == RESET));
  13655. if (RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET)
  13656. {
  13657. status = SUCCESS;
  13658. }
  13659. else
  13660. {
  13661. status = ERROR;
  13662. }
  13663. return (status);
  13664. }
  13665. /**
  13666. * @brief Adjusts the Internal High Speed oscillator (HSI) calibration value.
  13667. * @param HSICalibrationValue: specifies the calibration trimming value.
  13668. * This parameter must be a number between 0 and 0x1F.
  13669. * @retval None
  13670. */
  13671. void RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue)
  13672. {
  13673. uint32_t tmpreg = 0;
  13674. /* Check the parameters */
  13675. assert_param(IS_RCC_CALIBRATION_VALUE(HSICalibrationValue));
  13676. tmpreg = RCC->CR;
  13677. /* Clear HSITRIM[4:0] bits */
  13678. tmpreg &= CR_HSITRIM_Mask;
  13679. /* Set the HSITRIM[4:0] bits according to HSICalibrationValue value */
  13680. tmpreg |= (uint32_t)HSICalibrationValue << 3;
  13681. /* Store the new value */
  13682. RCC->CR = tmpreg;
  13683. }
  13684. /**
  13685. * @brief Enables or disables the Internal High Speed oscillator (HSI).
  13686. * @note HSI can not be stopped if it is used directly or through the PLL as system clock.
  13687. * @param NewState: new state of the HSI. This parameter can be: ENABLE or DISABLE.
  13688. * @retval None
  13689. */
  13690. void RCC_HSICmd(FunctionalState NewState)
  13691. {
  13692. /* Check the parameters */
  13693. assert_param(IS_FUNCTIONAL_STATE(NewState));
  13694. *(__IO uint32_t *) CR_HSION_BB = (uint32_t)NewState;
  13695. }
  13696. /**
  13697. * @brief Configures the PLL clock source and multiplication factor.
  13698. * @note This function must be used only when the PLL is disabled.
  13699. * @param RCC_PLLSource: specifies the PLL entry clock source.
  13700. * For @b STM32_Connectivity_line_devices or @b STM32_Value_line_devices,
  13701. * this parameter can be one of the following values:
  13702. * @arg RCC_PLLSource_HSI_Div2: HSI oscillator clock divided by 2 selected as PLL clock entry
  13703. * @arg RCC_PLLSource_PREDIV1: PREDIV1 clock selected as PLL clock entry
  13704. * For @b other_STM32_devices, this parameter can be one of the following values:
  13705. * @arg RCC_PLLSource_HSI_Div2: HSI oscillator clock divided by 2 selected as PLL clock entry
  13706. * @arg RCC_PLLSource_HSE_Div1: HSE oscillator clock selected as PLL clock entry
  13707. * @arg RCC_PLLSource_HSE_Div2: HSE oscillator clock divided by 2 selected as PLL clock entry
  13708. * @param RCC_PLLMul: specifies the PLL multiplication factor.
  13709. * For @b STM32_Connectivity_line_devices, this parameter can be RCC_PLLMul_x where x:{[4,9], 6_5}
  13710. * For @b other_STM32_devices, this parameter can be RCC_PLLMul_x where x:[2,16]
  13711. * @retval None
  13712. */
  13713. void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t RCC_PLLMul)
  13714. {
  13715. uint32_t tmpreg = 0;
  13716. /* Check the parameters */
  13717. assert_param(IS_RCC_PLL_SOURCE(RCC_PLLSource));
  13718. assert_param(IS_RCC_PLL_MUL(RCC_PLLMul));
  13719. tmpreg = RCC->CFGR;
  13720. /* Clear PLLSRC, PLLXTPRE and PLLMUL[3:0] bits */
  13721. tmpreg &= CFGR_PLL_Mask;
  13722. /* Set the PLL configuration bits */
  13723. tmpreg |= RCC_PLLSource | RCC_PLLMul;
  13724. /* Store the new value */
  13725. RCC->CFGR = tmpreg;
  13726. }
  13727. /**
  13728. * @brief Enables or disables the PLL.
  13729. * @note The PLL can not be disabled if it is used as system clock.
  13730. * @param NewState: new state of the PLL. This parameter can be: ENABLE or DISABLE.
  13731. * @retval None
  13732. */
  13733. void RCC_PLLCmd(FunctionalState NewState)
  13734. {
  13735. /* Check the parameters */
  13736. assert_param(IS_FUNCTIONAL_STATE(NewState));
  13737. *(__IO uint32_t *) CR_PLLON_BB = (uint32_t)NewState;
  13738. }
  13739. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL) || defined (STM32F10X_CL)
  13740. /**
  13741. * @brief Configures the PREDIV1 division factor.
  13742. * @note
  13743. * - This function must be used only when the PLL is disabled.
  13744. * - This function applies only to STM32 Connectivity line and Value line
  13745. * devices.
  13746. * @param RCC_PREDIV1_Source: specifies the PREDIV1 clock source.
  13747. * This parameter can be one of the following values:
  13748. * @arg RCC_PREDIV1_Source_HSE: HSE selected as PREDIV1 clock
  13749. * @arg RCC_PREDIV1_Source_PLL2: PLL2 selected as PREDIV1 clock
  13750. * @note
  13751. * For @b STM32_Value_line_devices this parameter is always RCC_PREDIV1_Source_HSE
  13752. * @param RCC_PREDIV1_Div: specifies the PREDIV1 clock division factor.
  13753. * This parameter can be RCC_PREDIV1_Divx where x:[1,16]
  13754. * @retval None
  13755. */
  13756. void RCC_PREDIV1Config(uint32_t RCC_PREDIV1_Source, uint32_t RCC_PREDIV1_Div)
  13757. {
  13758. uint32_t tmpreg = 0;
  13759. /* Check the parameters */
  13760. assert_param(IS_RCC_PREDIV1_SOURCE(RCC_PREDIV1_Source));
  13761. assert_param(IS_RCC_PREDIV1(RCC_PREDIV1_Div));
  13762. tmpreg = RCC->CFGR2;
  13763. /* Clear PREDIV1[3:0] and PREDIV1SRC bits */
  13764. tmpreg &= ~(CFGR2_PREDIV1 | CFGR2_PREDIV1SRC);
  13765. /* Set the PREDIV1 clock source and division factor */
  13766. tmpreg |= RCC_PREDIV1_Source | RCC_PREDIV1_Div ;
  13767. /* Store the new value */
  13768. RCC->CFGR2 = tmpreg;
  13769. }
  13770. #endif
  13771. #ifdef STM32F10X_CL
  13772. /**
  13773. * @brief Configures the PREDIV2 division factor.
  13774. * @note
  13775. * - This function must be used only when both PLL2 and PLL3 are disabled.
  13776. * - This function applies only to STM32 Connectivity line devices.
  13777. * @param RCC_PREDIV2_Div: specifies the PREDIV2 clock division factor.
  13778. * This parameter can be RCC_PREDIV2_Divx where x:[1,16]
  13779. * @retval None
  13780. */
  13781. void RCC_PREDIV2Config(uint32_t RCC_PREDIV2_Div)
  13782. {
  13783. uint32_t tmpreg = 0;
  13784. /* Check the parameters */
  13785. assert_param(IS_RCC_PREDIV2(RCC_PREDIV2_Div));
  13786. tmpreg = RCC->CFGR2;
  13787. /* Clear PREDIV2[3:0] bits */
  13788. tmpreg &= ~CFGR2_PREDIV2;
  13789. /* Set the PREDIV2 division factor */
  13790. tmpreg |= RCC_PREDIV2_Div;
  13791. /* Store the new value */
  13792. RCC->CFGR2 = tmpreg;
  13793. }
  13794. /**
  13795. * @brief Configures the PLL2 multiplication factor.
  13796. * @note
  13797. * - This function must be used only when the PLL2 is disabled.
  13798. * - This function applies only to STM32 Connectivity line devices.
  13799. * @param RCC_PLL2Mul: specifies the PLL2 multiplication factor.
  13800. * This parameter can be RCC_PLL2Mul_x where x:{[8,14], 16, 20}
  13801. * @retval None
  13802. */
  13803. void RCC_PLL2Config(uint32_t RCC_PLL2Mul)
  13804. {
  13805. uint32_t tmpreg = 0;
  13806. /* Check the parameters */
  13807. assert_param(IS_RCC_PLL2_MUL(RCC_PLL2Mul));
  13808. tmpreg = RCC->CFGR2;
  13809. /* Clear PLL2Mul[3:0] bits */
  13810. tmpreg &= ~CFGR2_PLL2MUL;
  13811. /* Set the PLL2 configuration bits */
  13812. tmpreg |= RCC_PLL2Mul;
  13813. /* Store the new value */
  13814. RCC->CFGR2 = tmpreg;
  13815. }
  13816. /**
  13817. * @brief Enables or disables the PLL2.
  13818. * @note
  13819. * - The PLL2 can not be disabled if it is used indirectly as system clock
  13820. * (i.e. it is used as PLL clock entry that is used as System clock).
  13821. * - This function applies only to STM32 Connectivity line devices.
  13822. * @param NewState: new state of the PLL2. This parameter can be: ENABLE or DISABLE.
  13823. * @retval None
  13824. */
  13825. void RCC_PLL2Cmd(FunctionalState NewState)
  13826. {
  13827. /* Check the parameters */
  13828. assert_param(IS_FUNCTIONAL_STATE(NewState));
  13829. *(__IO uint32_t *) CR_PLL2ON_BB = (uint32_t)NewState;
  13830. }
  13831. /**
  13832. * @brief Configures the PLL3 multiplication factor.
  13833. * @note
  13834. * - This function must be used only when the PLL3 is disabled.
  13835. * - This function applies only to STM32 Connectivity line devices.
  13836. * @param RCC_PLL3Mul: specifies the PLL3 multiplication factor.
  13837. * This parameter can be RCC_PLL3Mul_x where x:{[8,14], 16, 20}
  13838. * @retval None
  13839. */
  13840. void RCC_PLL3Config(uint32_t RCC_PLL3Mul)
  13841. {
  13842. uint32_t tmpreg = 0;
  13843. /* Check the parameters */
  13844. assert_param(IS_RCC_PLL3_MUL(RCC_PLL3Mul));
  13845. tmpreg = RCC->CFGR2;
  13846. /* Clear PLL3Mul[3:0] bits */
  13847. tmpreg &= ~CFGR2_PLL3MUL;
  13848. /* Set the PLL3 configuration bits */
  13849. tmpreg |= RCC_PLL3Mul;
  13850. /* Store the new value */
  13851. RCC->CFGR2 = tmpreg;
  13852. }
  13853. /**
  13854. * @brief Enables or disables the PLL3.
  13855. * @note This function applies only to STM32 Connectivity line devices.
  13856. * @param NewState: new state of the PLL3. This parameter can be: ENABLE or DISABLE.
  13857. * @retval None
  13858. */
  13859. void RCC_PLL3Cmd(FunctionalState NewState)
  13860. {
  13861. /* Check the parameters */
  13862. assert_param(IS_FUNCTIONAL_STATE(NewState));
  13863. *(__IO uint32_t *) CR_PLL3ON_BB = (uint32_t)NewState;
  13864. }
  13865. #endif /* STM32F10X_CL */
  13866. /**
  13867. * @brief Configures the system clock (SYSCLK).
  13868. * @param RCC_SYSCLKSource: specifies the clock source used as system clock.
  13869. * This parameter can be one of the following values:
  13870. * @arg RCC_SYSCLKSource_HSI: HSI selected as system clock
  13871. * @arg RCC_SYSCLKSource_HSE: HSE selected as system clock
  13872. * @arg RCC_SYSCLKSource_PLLCLK: PLL selected as system clock
  13873. * @retval None
  13874. */
  13875. void RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource)
  13876. {
  13877. uint32_t tmpreg = 0;
  13878. /* Check the parameters */
  13879. assert_param(IS_RCC_SYSCLK_SOURCE(RCC_SYSCLKSource));
  13880. tmpreg = RCC->CFGR;
  13881. /* Clear SW[1:0] bits */
  13882. tmpreg &= CFGR_SW_Mask;
  13883. /* Set SW[1:0] bits according to RCC_SYSCLKSource value */
  13884. tmpreg |= RCC_SYSCLKSource;
  13885. /* Store the new value */
  13886. RCC->CFGR = tmpreg;
  13887. }
  13888. /**
  13889. * @brief Returns the clock source used as system clock.
  13890. * @param None
  13891. * @retval The clock source used as system clock. The returned value can
  13892. * be one of the following:
  13893. * - 0x00: HSI used as system clock
  13894. * - 0x04: HSE used as system clock
  13895. * - 0x08: PLL used as system clock
  13896. */
  13897. uint8_t RCC_GetSYSCLKSource(void)
  13898. {
  13899. return ((uint8_t)(RCC->CFGR & CFGR_SWS_Mask));
  13900. }
  13901. /**
  13902. * @brief Configures the AHB clock (HCLK).
  13903. * @param RCC_SYSCLK: defines the AHB clock divider. This clock is derived from
  13904. * the system clock (SYSCLK).
  13905. * This parameter can be one of the following values:
  13906. * @arg RCC_SYSCLK_Div1: AHB clock = SYSCLK
  13907. * @arg RCC_SYSCLK_Div2: AHB clock = SYSCLK/2
  13908. * @arg RCC_SYSCLK_Div4: AHB clock = SYSCLK/4
  13909. * @arg RCC_SYSCLK_Div8: AHB clock = SYSCLK/8
  13910. * @arg RCC_SYSCLK_Div16: AHB clock = SYSCLK/16
  13911. * @arg RCC_SYSCLK_Div64: AHB clock = SYSCLK/64
  13912. * @arg RCC_SYSCLK_Div128: AHB clock = SYSCLK/128
  13913. * @arg RCC_SYSCLK_Div256: AHB clock = SYSCLK/256
  13914. * @arg RCC_SYSCLK_Div512: AHB clock = SYSCLK/512
  13915. * @retval None
  13916. */
  13917. void RCC_HCLKConfig(uint32_t RCC_SYSCLK)
  13918. {
  13919. uint32_t tmpreg = 0;
  13920. /* Check the parameters */
  13921. assert_param(IS_RCC_HCLK(RCC_SYSCLK));
  13922. tmpreg = RCC->CFGR;
  13923. /* Clear HPRE[3:0] bits */
  13924. tmpreg &= CFGR_HPRE_Reset_Mask;
  13925. /* Set HPRE[3:0] bits according to RCC_SYSCLK value */
  13926. tmpreg |= RCC_SYSCLK;
  13927. /* Store the new value */
  13928. RCC->CFGR = tmpreg;
  13929. }
  13930. /**
  13931. * @brief Configures the Low Speed APB clock (PCLK1).
  13932. * @param RCC_HCLK: defines the APB1 clock divider. This clock is derived from
  13933. * the AHB clock (HCLK).
  13934. * This parameter can be one of the following values:
  13935. * @arg RCC_HCLK_Div1: APB1 clock = HCLK
  13936. * @arg RCC_HCLK_Div2: APB1 clock = HCLK/2
  13937. * @arg RCC_HCLK_Div4: APB1 clock = HCLK/4
  13938. * @arg RCC_HCLK_Div8: APB1 clock = HCLK/8
  13939. * @arg RCC_HCLK_Div16: APB1 clock = HCLK/16
  13940. * @retval None
  13941. */
  13942. void RCC_PCLK1Config(uint32_t RCC_HCLK)
  13943. {
  13944. uint32_t tmpreg = 0;
  13945. /* Check the parameters */
  13946. assert_param(IS_RCC_PCLK(RCC_HCLK));
  13947. tmpreg = RCC->CFGR;
  13948. /* Clear PPRE1[2:0] bits */
  13949. tmpreg &= CFGR_PPRE1_Reset_Mask;
  13950. /* Set PPRE1[2:0] bits according to RCC_HCLK value */
  13951. tmpreg |= RCC_HCLK;
  13952. /* Store the new value */
  13953. RCC->CFGR = tmpreg;
  13954. }
  13955. /**
  13956. * @brief Configures the High Speed APB clock (PCLK2).
  13957. * @param RCC_HCLK: defines the APB2 clock divider. This clock is derived from
  13958. * the AHB clock (HCLK).
  13959. * This parameter can be one of the following values:
  13960. * @arg RCC_HCLK_Div1: APB2 clock = HCLK
  13961. * @arg RCC_HCLK_Div2: APB2 clock = HCLK/2
  13962. * @arg RCC_HCLK_Div4: APB2 clock = HCLK/4
  13963. * @arg RCC_HCLK_Div8: APB2 clock = HCLK/8
  13964. * @arg RCC_HCLK_Div16: APB2 clock = HCLK/16
  13965. * @retval None
  13966. */
  13967. void RCC_PCLK2Config(uint32_t RCC_HCLK)
  13968. {
  13969. uint32_t tmpreg = 0;
  13970. /* Check the parameters */
  13971. assert_param(IS_RCC_PCLK(RCC_HCLK));
  13972. tmpreg = RCC->CFGR;
  13973. /* Clear PPRE2[2:0] bits */
  13974. tmpreg &= CFGR_PPRE2_Reset_Mask;
  13975. /* Set PPRE2[2:0] bits according to RCC_HCLK value */
  13976. tmpreg |= RCC_HCLK << 3;
  13977. /* Store the new value */
  13978. RCC->CFGR = tmpreg;
  13979. }
  13980. /**
  13981. * @brief Enables or disables the specified RCC interrupts.
  13982. * @param RCC_IT: specifies the RCC interrupt sources to be enabled or disabled.
  13983. *
  13984. * For @b STM32_Connectivity_line_devices, this parameter can be any combination
  13985. * of the following values
  13986. * @arg RCC_IT_LSIRDY: LSI ready interrupt
  13987. * @arg RCC_IT_LSERDY: LSE ready interrupt
  13988. * @arg RCC_IT_HSIRDY: HSI ready interrupt
  13989. * @arg RCC_IT_HSERDY: HSE ready interrupt
  13990. * @arg RCC_IT_PLLRDY: PLL ready interrupt
  13991. * @arg RCC_IT_PLL2RDY: PLL2 ready interrupt
  13992. * @arg RCC_IT_PLL3RDY: PLL3 ready interrupt
  13993. *
  13994. * For @b other_STM32_devices, this parameter can be any combination of the
  13995. * following values
  13996. * @arg RCC_IT_LSIRDY: LSI ready interrupt
  13997. * @arg RCC_IT_LSERDY: LSE ready interrupt
  13998. * @arg RCC_IT_HSIRDY: HSI ready interrupt
  13999. * @arg RCC_IT_HSERDY: HSE ready interrupt
  14000. * @arg RCC_IT_PLLRDY: PLL ready interrupt
  14001. *
  14002. * @param NewState: new state of the specified RCC interrupts.
  14003. * This parameter can be: ENABLE or DISABLE.
  14004. * @retval None
  14005. */
  14006. void RCC_ITConfig(uint8_t RCC_IT, FunctionalState NewState)
  14007. {
  14008. /* Check the parameters */
  14009. assert_param(IS_RCC_IT(RCC_IT));
  14010. assert_param(IS_FUNCTIONAL_STATE(NewState));
  14011. if (NewState != DISABLE)
  14012. {
  14013. /* Perform Byte access to RCC_CIR bits to enable the selected interrupts */
  14014. *(__IO uint8_t *) CIR_BYTE2_ADDRESS |= RCC_IT;
  14015. }
  14016. else
  14017. {
  14018. /* Perform Byte access to RCC_CIR bits to disable the selected interrupts */
  14019. *(__IO uint8_t *) CIR_BYTE2_ADDRESS &= (uint8_t)~RCC_IT;
  14020. }
  14021. }
  14022. #ifndef STM32F10X_CL
  14023. /**
  14024. * @brief Configures the USB clock (USBCLK).
  14025. * @param RCC_USBCLKSource: specifies the USB clock source. This clock is
  14026. * derived from the PLL output.
  14027. * This parameter can be one of the following values:
  14028. * @arg RCC_USBCLKSource_PLLCLK_1Div5: PLL clock divided by 1,5 selected as USB
  14029. * clock source
  14030. * @arg RCC_USBCLKSource_PLLCLK_Div1: PLL clock selected as USB clock source
  14031. * @retval None
  14032. */
  14033. void RCC_USBCLKConfig(uint32_t RCC_USBCLKSource)
  14034. {
  14035. /* Check the parameters */
  14036. assert_param(IS_RCC_USBCLK_SOURCE(RCC_USBCLKSource));
  14037. *(__IO uint32_t *) CFGR_USBPRE_BB = RCC_USBCLKSource;
  14038. }
  14039. #else
  14040. /**
  14041. * @brief Configures the USB OTG FS clock (OTGFSCLK).
  14042. * This function applies only to STM32 Connectivity line devices.
  14043. * @param RCC_OTGFSCLKSource: specifies the USB OTG FS clock source.
  14044. * This clock is derived from the PLL output.
  14045. * This parameter can be one of the following values:
  14046. * @arg RCC_OTGFSCLKSource_PLLVCO_Div3: PLL VCO clock divided by 2 selected as USB OTG FS clock source
  14047. * @arg RCC_OTGFSCLKSource_PLLVCO_Div2: PLL VCO clock divided by 2 selected as USB OTG FS clock source
  14048. * @retval None
  14049. */
  14050. void RCC_OTGFSCLKConfig(uint32_t RCC_OTGFSCLKSource)
  14051. {
  14052. /* Check the parameters */
  14053. assert_param(IS_RCC_OTGFSCLK_SOURCE(RCC_OTGFSCLKSource));
  14054. *(__IO uint32_t *) CFGR_OTGFSPRE_BB = RCC_OTGFSCLKSource;
  14055. }
  14056. #endif /* STM32F10X_CL */
  14057. /**
  14058. * @brief Configures the ADC clock (ADCCLK).
  14059. * @param RCC_PCLK2: defines the ADC clock divider. This clock is derived from
  14060. * the APB2 clock (PCLK2).
  14061. * This parameter can be one of the following values:
  14062. * @arg RCC_PCLK2_Div2: ADC clock = PCLK2/2
  14063. * @arg RCC_PCLK2_Div4: ADC clock = PCLK2/4
  14064. * @arg RCC_PCLK2_Div6: ADC clock = PCLK2/6
  14065. * @arg RCC_PCLK2_Div8: ADC clock = PCLK2/8
  14066. * @retval None
  14067. */
  14068. void RCC_ADCCLKConfig(uint32_t RCC_PCLK2)
  14069. {
  14070. uint32_t tmpreg = 0;
  14071. /* Check the parameters */
  14072. assert_param(IS_RCC_ADCCLK(RCC_PCLK2));
  14073. tmpreg = RCC->CFGR;
  14074. /* Clear ADCPRE[1:0] bits */
  14075. tmpreg &= CFGR_ADCPRE_Reset_Mask;
  14076. /* Set ADCPRE[1:0] bits according to RCC_PCLK2 value */
  14077. tmpreg |= RCC_PCLK2;
  14078. /* Store the new value */
  14079. RCC->CFGR = tmpreg;
  14080. }
  14081. #ifdef STM32F10X_CL
  14082. /**
  14083. * @brief Configures the I2S2 clock source(I2S2CLK).
  14084. * @note
  14085. * - This function must be called before enabling I2S2 APB clock.
  14086. * - This function applies only to STM32 Connectivity line devices.
  14087. * @param RCC_I2S2CLKSource: specifies the I2S2 clock source.
  14088. * This parameter can be one of the following values:
  14089. * @arg RCC_I2S2CLKSource_SYSCLK: system clock selected as I2S2 clock entry
  14090. * @arg RCC_I2S2CLKSource_PLL3_VCO: PLL3 VCO clock selected as I2S2 clock entry
  14091. * @retval None
  14092. */
  14093. void RCC_I2S2CLKConfig(uint32_t RCC_I2S2CLKSource)
  14094. {
  14095. /* Check the parameters */
  14096. assert_param(IS_RCC_I2S2CLK_SOURCE(RCC_I2S2CLKSource));
  14097. *(__IO uint32_t *) CFGR2_I2S2SRC_BB = RCC_I2S2CLKSource;
  14098. }
  14099. /**
  14100. * @brief Configures the I2S3 clock source(I2S2CLK).
  14101. * @note
  14102. * - This function must be called before enabling I2S3 APB clock.
  14103. * - This function applies only to STM32 Connectivity line devices.
  14104. * @param RCC_I2S3CLKSource: specifies the I2S3 clock source.
  14105. * This parameter can be one of the following values:
  14106. * @arg RCC_I2S3CLKSource_SYSCLK: system clock selected as I2S3 clock entry
  14107. * @arg RCC_I2S3CLKSource_PLL3_VCO: PLL3 VCO clock selected as I2S3 clock entry
  14108. * @retval None
  14109. */
  14110. void RCC_I2S3CLKConfig(uint32_t RCC_I2S3CLKSource)
  14111. {
  14112. /* Check the parameters */
  14113. assert_param(IS_RCC_I2S3CLK_SOURCE(RCC_I2S3CLKSource));
  14114. *(__IO uint32_t *) CFGR2_I2S3SRC_BB = RCC_I2S3CLKSource;
  14115. }
  14116. #endif /* STM32F10X_CL */
  14117. /**
  14118. * @brief Configures the External Low Speed oscillator (LSE).
  14119. * @param RCC_LSE: specifies the new state of the LSE.
  14120. * This parameter can be one of the following values:
  14121. * @arg RCC_LSE_OFF: LSE oscillator OFF
  14122. * @arg RCC_LSE_ON: LSE oscillator ON
  14123. * @arg RCC_LSE_Bypass: LSE oscillator bypassed with external clock
  14124. * @retval None
  14125. */
  14126. void RCC_LSEConfig(uint8_t RCC_LSE)
  14127. {
  14128. /* Check the parameters */
  14129. assert_param(IS_RCC_LSE(RCC_LSE));
  14130. /* Reset LSEON and LSEBYP bits before configuring the LSE ------------------*/
  14131. /* Reset LSEON bit */
  14132. *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_OFF;
  14133. /* Reset LSEBYP bit */
  14134. *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_OFF;
  14135. /* Configure LSE (RCC_LSE_OFF is already covered by the code section above) */
  14136. switch(RCC_LSE)
  14137. {
  14138. case RCC_LSE_ON:
  14139. /* Set LSEON bit */
  14140. *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_ON;
  14141. break;
  14142. case RCC_LSE_Bypass:
  14143. /* Set LSEBYP and LSEON bits */
  14144. *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_Bypass | RCC_LSE_ON;
  14145. break;
  14146. default:
  14147. break;
  14148. }
  14149. }
  14150. /**
  14151. * @brief Enables or disables the Internal Low Speed oscillator (LSI).
  14152. * @note LSI can not be disabled if the IWDG is running.
  14153. * @param NewState: new state of the LSI. This parameter can be: ENABLE or DISABLE.
  14154. * @retval None
  14155. */
  14156. void RCC_LSICmd(FunctionalState NewState)
  14157. {
  14158. /* Check the parameters */
  14159. assert_param(IS_FUNCTIONAL_STATE(NewState));
  14160. *(__IO uint32_t *) CSR_LSION_BB = (uint32_t)NewState;
  14161. }
  14162. /**
  14163. * @brief Configures the RTC clock (RTCCLK).
  14164. * @note Once the RTC clock is selected it can't be changed unless the Backup domain is reset.
  14165. * @param RCC_RTCCLKSource: specifies the RTC clock source.
  14166. * This parameter can be one of the following values:
  14167. * @arg RCC_RTCCLKSource_LSE: LSE selected as RTC clock
  14168. * @arg RCC_RTCCLKSource_LSI: LSI selected as RTC clock
  14169. * @arg RCC_RTCCLKSource_HSE_Div128: HSE clock divided by 128 selected as RTC clock
  14170. * @retval None
  14171. */
  14172. void RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource)
  14173. {
  14174. /* Check the parameters */
  14175. assert_param(IS_RCC_RTCCLK_SOURCE(RCC_RTCCLKSource));
  14176. /* Select the RTC clock source */
  14177. RCC->BDCR |= RCC_RTCCLKSource;
  14178. }
  14179. /**
  14180. * @brief Enables or disables the RTC clock.
  14181. * @note This function must be used only after the RTC clock was selected using the RCC_RTCCLKConfig function.
  14182. * @param NewState: new state of the RTC clock. This parameter can be: ENABLE or DISABLE.
  14183. * @retval None
  14184. */
  14185. void RCC_RTCCLKCmd(FunctionalState NewState)
  14186. {
  14187. /* Check the parameters */
  14188. assert_param(IS_FUNCTIONAL_STATE(NewState));
  14189. *(__IO uint32_t *) BDCR_RTCEN_BB = (uint32_t)NewState;
  14190. }
  14191. /**
  14192. * @brief Returns the frequencies of different on chip clocks.
  14193. * @param RCC_Clocks: pointer to a RCC_ClocksTypeDef structure which will hold
  14194. * the clocks frequencies.
  14195. * @note The result of this function could be not correct when using
  14196. * fractional value for HSE crystal.
  14197. * @retval None
  14198. */
  14199. void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks)
  14200. {
  14201. uint32_t tmp = 0, pllmull = 0, pllsource = 0, presc = 0;
  14202. #ifdef STM32F10X_CL
  14203. uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor = 0, pll2mull = 0;
  14204. #endif /* STM32F10X_CL */
  14205. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  14206. uint32_t prediv1factor = 0;
  14207. #endif
  14208. /* Get SYSCLK source -------------------------------------------------------*/
  14209. tmp = RCC->CFGR & CFGR_SWS_Mask;
  14210. switch (tmp)
  14211. {
  14212. case 0x00: /* HSI used as system clock */
  14213. RCC_Clocks->SYSCLK_Frequency = HSI_VALUE;
  14214. break;
  14215. case 0x04: /* HSE used as system clock */
  14216. RCC_Clocks->SYSCLK_Frequency = HSE_VALUE;
  14217. break;
  14218. case 0x08: /* PLL used as system clock */
  14219. /* Get PLL clock source and multiplication factor ----------------------*/
  14220. pllmull = RCC->CFGR & CFGR_PLLMull_Mask;
  14221. pllsource = RCC->CFGR & CFGR_PLLSRC_Mask;
  14222. #ifndef STM32F10X_CL
  14223. pllmull = ( pllmull >> 18) + 2;
  14224. if (pllsource == 0x00)
  14225. {/* HSI oscillator clock divided by 2 selected as PLL clock entry */
  14226. RCC_Clocks->SYSCLK_Frequency = (HSI_VALUE >> 1) * pllmull;
  14227. }
  14228. else
  14229. {
  14230. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  14231. prediv1factor = (RCC->CFGR2 & CFGR2_PREDIV1) + 1;
  14232. /* HSE oscillator clock selected as PREDIV1 clock entry */
  14233. RCC_Clocks->SYSCLK_Frequency = (HSE_VALUE / prediv1factor) * pllmull;
  14234. #else
  14235. /* HSE selected as PLL clock entry */
  14236. if ((RCC->CFGR & CFGR_PLLXTPRE_Mask) != (uint32_t)RESET)
  14237. {/* HSE oscillator clock divided by 2 */
  14238. RCC_Clocks->SYSCLK_Frequency = (HSE_VALUE >> 1) * pllmull;
  14239. }
  14240. else
  14241. {
  14242. RCC_Clocks->SYSCLK_Frequency = HSE_VALUE * pllmull;
  14243. }
  14244. #endif
  14245. }
  14246. #else
  14247. pllmull = pllmull >> 18;
  14248. if (pllmull != 0x0D)
  14249. {
  14250. pllmull += 2;
  14251. }
  14252. else
  14253. { /* PLL multiplication factor = PLL input clock * 6.5 */
  14254. pllmull = 13 / 2;
  14255. }
  14256. if (pllsource == 0x00)
  14257. {/* HSI oscillator clock divided by 2 selected as PLL clock entry */
  14258. RCC_Clocks->SYSCLK_Frequency = (HSI_VALUE >> 1) * pllmull;
  14259. }
  14260. else
  14261. {/* PREDIV1 selected as PLL clock entry */
  14262. /* Get PREDIV1 clock source and division factor */
  14263. prediv1source = RCC->CFGR2 & CFGR2_PREDIV1SRC;
  14264. prediv1factor = (RCC->CFGR2 & CFGR2_PREDIV1) + 1;
  14265. if (prediv1source == 0)
  14266. { /* HSE oscillator clock selected as PREDIV1 clock entry */
  14267. RCC_Clocks->SYSCLK_Frequency = (HSE_VALUE / prediv1factor) * pllmull;
  14268. }
  14269. else
  14270. {/* PLL2 clock selected as PREDIV1 clock entry */
  14271. /* Get PREDIV2 division factor and PLL2 multiplication factor */
  14272. prediv2factor = ((RCC->CFGR2 & CFGR2_PREDIV2) >> 4) + 1;
  14273. pll2mull = ((RCC->CFGR2 & CFGR2_PLL2MUL) >> 8 ) + 2;
  14274. RCC_Clocks->SYSCLK_Frequency = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;
  14275. }
  14276. }
  14277. #endif /* STM32F10X_CL */
  14278. break;
  14279. default:
  14280. RCC_Clocks->SYSCLK_Frequency = HSI_VALUE;
  14281. break;
  14282. }
  14283. /* Compute HCLK, PCLK1, PCLK2 and ADCCLK clocks frequencies ----------------*/
  14284. /* Get HCLK prescaler */
  14285. tmp = RCC->CFGR & CFGR_HPRE_Set_Mask;
  14286. tmp = tmp >> 4;
  14287. presc = APBAHBPrescTable[tmp];
  14288. /* HCLK clock frequency */
  14289. RCC_Clocks->HCLK_Frequency = RCC_Clocks->SYSCLK_Frequency >> presc;
  14290. /* Get PCLK1 prescaler */
  14291. tmp = RCC->CFGR & CFGR_PPRE1_Set_Mask;
  14292. tmp = tmp >> 8;
  14293. presc = APBAHBPrescTable[tmp];
  14294. /* PCLK1 clock frequency */
  14295. RCC_Clocks->PCLK1_Frequency = RCC_Clocks->HCLK_Frequency >> presc;
  14296. /* Get PCLK2 prescaler */
  14297. tmp = RCC->CFGR & CFGR_PPRE2_Set_Mask;
  14298. tmp = tmp >> 11;
  14299. presc = APBAHBPrescTable[tmp];
  14300. /* PCLK2 clock frequency */
  14301. RCC_Clocks->PCLK2_Frequency = RCC_Clocks->HCLK_Frequency >> presc;
  14302. /* Get ADCCLK prescaler */
  14303. tmp = RCC->CFGR & CFGR_ADCPRE_Set_Mask;
  14304. tmp = tmp >> 14;
  14305. presc = ADCPrescTable[tmp];
  14306. /* ADCCLK clock frequency */
  14307. RCC_Clocks->ADCCLK_Frequency = RCC_Clocks->PCLK2_Frequency / presc;
  14308. }
  14309. /**
  14310. * @brief Enables or disables the AHB peripheral clock.
  14311. * @param RCC_AHBPeriph: specifies the AHB peripheral to gates its clock.
  14312. *
  14313. * For @b STM32_Connectivity_line_devices, this parameter can be any combination
  14314. * of the following values:
  14315. * @arg RCC_AHBPeriph_DMA1
  14316. * @arg RCC_AHBPeriph_DMA2
  14317. * @arg RCC_AHBPeriph_SRAM
  14318. * @arg RCC_AHBPeriph_FLITF
  14319. * @arg RCC_AHBPeriph_CRC
  14320. * @arg RCC_AHBPeriph_OTG_FS
  14321. * @arg RCC_AHBPeriph_ETH_MAC
  14322. * @arg RCC_AHBPeriph_ETH_MAC_Tx
  14323. * @arg RCC_AHBPeriph_ETH_MAC_Rx
  14324. *
  14325. * For @b other_STM32_devices, this parameter can be any combination of the
  14326. * following values:
  14327. * @arg RCC_AHBPeriph_DMA1
  14328. * @arg RCC_AHBPeriph_DMA2
  14329. * @arg RCC_AHBPeriph_SRAM
  14330. * @arg RCC_AHBPeriph_FLITF
  14331. * @arg RCC_AHBPeriph_CRC
  14332. * @arg RCC_AHBPeriph_FSMC
  14333. * @arg RCC_AHBPeriph_SDIO
  14334. *
  14335. * @note SRAM and FLITF clock can be disabled only during sleep mode.
  14336. * @param NewState: new state of the specified peripheral clock.
  14337. * This parameter can be: ENABLE or DISABLE.
  14338. * @retval None
  14339. */
  14340. void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)
  14341. {
  14342. /* Check the parameters */
  14343. assert_param(IS_RCC_AHB_PERIPH(RCC_AHBPeriph));
  14344. assert_param(IS_FUNCTIONAL_STATE(NewState));
  14345. if (NewState != DISABLE)
  14346. {
  14347. RCC->AHBENR |= RCC_AHBPeriph;
  14348. }
  14349. else
  14350. {
  14351. RCC->AHBENR &= ~RCC_AHBPeriph;
  14352. }
  14353. }
  14354. /**
  14355. * @brief Enables or disables the High Speed APB (APB2) peripheral clock.
  14356. * @param RCC_APB2Periph: specifies the APB2 peripheral to gates its clock.
  14357. * This parameter can be any combination of the following values:
  14358. * @arg RCC_APB2Periph_AFIO, RCC_APB2Periph_GPIOA, RCC_APB2Periph_GPIOB,
  14359. * RCC_APB2Periph_GPIOC, RCC_APB2Periph_GPIOD, RCC_APB2Periph_GPIOE,
  14360. * RCC_APB2Periph_GPIOF, RCC_APB2Periph_GPIOG, RCC_APB2Periph_ADC1,
  14361. * RCC_APB2Periph_ADC2, RCC_APB2Periph_TIM1, RCC_APB2Periph_SPI1,
  14362. * RCC_APB2Periph_TIM8, RCC_APB2Periph_USART1, RCC_APB2Periph_ADC3,
  14363. * RCC_APB2Periph_TIM15, RCC_APB2Periph_TIM16, RCC_APB2Periph_TIM17,
  14364. * RCC_APB2Periph_TIM9, RCC_APB2Periph_TIM10, RCC_APB2Periph_TIM11
  14365. * @param NewState: new state of the specified peripheral clock.
  14366. * This parameter can be: ENABLE or DISABLE.
  14367. * @retval None
  14368. */
  14369. void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
  14370. {
  14371. /* Check the parameters */
  14372. assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
  14373. assert_param(IS_FUNCTIONAL_STATE(NewState));
  14374. if (NewState != DISABLE)
  14375. {
  14376. RCC->APB2ENR |= RCC_APB2Periph;
  14377. }
  14378. else
  14379. {
  14380. RCC->APB2ENR &= ~RCC_APB2Periph;
  14381. }
  14382. }
  14383. /**
  14384. * @brief Enables or disables the Low Speed APB (APB1) peripheral clock.
  14385. * @param RCC_APB1Periph: specifies the APB1 peripheral to gates its clock.
  14386. * This parameter can be any combination of the following values:
  14387. * @arg RCC_APB1Periph_TIM2, RCC_APB1Periph_TIM3, RCC_APB1Periph_TIM4,
  14388. * RCC_APB1Periph_TIM5, RCC_APB1Periph_TIM6, RCC_APB1Periph_TIM7,
  14389. * RCC_APB1Periph_WWDG, RCC_APB1Periph_SPI2, RCC_APB1Periph_SPI3,
  14390. * RCC_APB1Periph_USART2, RCC_APB1Periph_USART3, RCC_APB1Periph_USART4,
  14391. * RCC_APB1Periph_USART5, RCC_APB1Periph_I2C1, RCC_APB1Periph_I2C2,
  14392. * RCC_APB1Periph_USB, RCC_APB1Periph_CAN1, RCC_APB1Periph_BKP,
  14393. * RCC_APB1Periph_PWR, RCC_APB1Periph_DAC, RCC_APB1Periph_CEC,
  14394. * RCC_APB1Periph_TIM12, RCC_APB1Periph_TIM13, RCC_APB1Periph_TIM14
  14395. * @param NewState: new state of the specified peripheral clock.
  14396. * This parameter can be: ENABLE or DISABLE.
  14397. * @retval None
  14398. */
  14399. void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
  14400. {
  14401. /* Check the parameters */
  14402. assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
  14403. assert_param(IS_FUNCTIONAL_STATE(NewState));
  14404. if (NewState != DISABLE)
  14405. {
  14406. RCC->APB1ENR |= RCC_APB1Periph;
  14407. }
  14408. else
  14409. {
  14410. RCC->APB1ENR &= ~RCC_APB1Periph;
  14411. }
  14412. }
  14413. #ifdef STM32F10X_CL
  14414. /**
  14415. * @brief Forces or releases AHB peripheral reset.
  14416. * @note This function applies only to STM32 Connectivity line devices.
  14417. * @param RCC_AHBPeriph: specifies the AHB peripheral to reset.
  14418. * This parameter can be any combination of the following values:
  14419. * @arg RCC_AHBPeriph_OTG_FS
  14420. * @arg RCC_AHBPeriph_ETH_MAC
  14421. * @param NewState: new state of the specified peripheral reset.
  14422. * This parameter can be: ENABLE or DISABLE.
  14423. * @retval None
  14424. */
  14425. void RCC_AHBPeriphResetCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)
  14426. {
  14427. /* Check the parameters */
  14428. assert_param(IS_RCC_AHB_PERIPH_RESET(RCC_AHBPeriph));
  14429. assert_param(IS_FUNCTIONAL_STATE(NewState));
  14430. if (NewState != DISABLE)
  14431. {
  14432. RCC->AHBRSTR |= RCC_AHBPeriph;
  14433. }
  14434. else
  14435. {
  14436. RCC->AHBRSTR &= ~RCC_AHBPeriph;
  14437. }
  14438. }
  14439. #endif /* STM32F10X_CL */
  14440. /**
  14441. * @brief Forces or releases High Speed APB (APB2) peripheral reset.
  14442. * @param RCC_APB2Periph: specifies the APB2 peripheral to reset.
  14443. * This parameter can be any combination of the following values:
  14444. * @arg RCC_APB2Periph_AFIO, RCC_APB2Periph_GPIOA, RCC_APB2Periph_GPIOB,
  14445. * RCC_APB2Periph_GPIOC, RCC_APB2Periph_GPIOD, RCC_APB2Periph_GPIOE,
  14446. * RCC_APB2Periph_GPIOF, RCC_APB2Periph_GPIOG, RCC_APB2Periph_ADC1,
  14447. * RCC_APB2Periph_ADC2, RCC_APB2Periph_TIM1, RCC_APB2Periph_SPI1,
  14448. * RCC_APB2Periph_TIM8, RCC_APB2Periph_USART1, RCC_APB2Periph_ADC3,
  14449. * RCC_APB2Periph_TIM15, RCC_APB2Periph_TIM16, RCC_APB2Periph_TIM17,
  14450. * RCC_APB2Periph_TIM9, RCC_APB2Periph_TIM10, RCC_APB2Periph_TIM11
  14451. * @param NewState: new state of the specified peripheral reset.
  14452. * This parameter can be: ENABLE or DISABLE.
  14453. * @retval None
  14454. */
  14455. void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
  14456. {
  14457. /* Check the parameters */
  14458. assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
  14459. assert_param(IS_FUNCTIONAL_STATE(NewState));
  14460. if (NewState != DISABLE)
  14461. {
  14462. RCC->APB2RSTR |= RCC_APB2Periph;
  14463. }
  14464. else
  14465. {
  14466. RCC->APB2RSTR &= ~RCC_APB2Periph;
  14467. }
  14468. }
  14469. /**
  14470. * @brief Forces or releases Low Speed APB (APB1) peripheral reset.
  14471. * @param RCC_APB1Periph: specifies the APB1 peripheral to reset.
  14472. * This parameter can be any combination of the following values:
  14473. * @arg RCC_APB1Periph_TIM2, RCC_APB1Periph_TIM3, RCC_APB1Periph_TIM4,
  14474. * RCC_APB1Periph_TIM5, RCC_APB1Periph_TIM6, RCC_APB1Periph_TIM7,
  14475. * RCC_APB1Periph_WWDG, RCC_APB1Periph_SPI2, RCC_APB1Periph_SPI3,
  14476. * RCC_APB1Periph_USART2, RCC_APB1Periph_USART3, RCC_APB1Periph_USART4,
  14477. * RCC_APB1Periph_USART5, RCC_APB1Periph_I2C1, RCC_APB1Periph_I2C2,
  14478. * RCC_APB1Periph_USB, RCC_APB1Periph_CAN1, RCC_APB1Periph_BKP,
  14479. * RCC_APB1Periph_PWR, RCC_APB1Periph_DAC, RCC_APB1Periph_CEC,
  14480. * RCC_APB1Periph_TIM12, RCC_APB1Periph_TIM13, RCC_APB1Periph_TIM14
  14481. * @param NewState: new state of the specified peripheral clock.
  14482. * This parameter can be: ENABLE or DISABLE.
  14483. * @retval None
  14484. */
  14485. void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
  14486. {
  14487. /* Check the parameters */
  14488. assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
  14489. assert_param(IS_FUNCTIONAL_STATE(NewState));
  14490. if (NewState != DISABLE)
  14491. {
  14492. RCC->APB1RSTR |= RCC_APB1Periph;
  14493. }
  14494. else
  14495. {
  14496. RCC->APB1RSTR &= ~RCC_APB1Periph;
  14497. }
  14498. }
  14499. /**
  14500. * @brief Forces or releases the Backup domain reset.
  14501. * @param NewState: new state of the Backup domain reset.
  14502. * This parameter can be: ENABLE or DISABLE.
  14503. * @retval None
  14504. */
  14505. void RCC_BackupResetCmd(FunctionalState NewState)
  14506. {
  14507. /* Check the parameters */
  14508. assert_param(IS_FUNCTIONAL_STATE(NewState));
  14509. *(__IO uint32_t *) BDCR_BDRST_BB = (uint32_t)NewState;
  14510. }
  14511. /**
  14512. * @brief Enables or disables the Clock Security System.
  14513. * @param NewState: new state of the Clock Security System..
  14514. * This parameter can be: ENABLE or DISABLE.
  14515. * @retval None
  14516. */
  14517. void RCC_ClockSecuritySystemCmd(FunctionalState NewState)
  14518. {
  14519. /* Check the parameters */
  14520. assert_param(IS_FUNCTIONAL_STATE(NewState));
  14521. *(__IO uint32_t *) CR_CSSON_BB = (uint32_t)NewState;
  14522. }
  14523. /**
  14524. * @brief Selects the clock source to output on MCO pin.
  14525. * @param RCC_MCO: specifies the clock source to output.
  14526. *
  14527. * For @b STM32_Connectivity_line_devices, this parameter can be one of the
  14528. * following values:
  14529. * @arg RCC_MCO_NoClock: No clock selected
  14530. * @arg RCC_MCO_SYSCLK: System clock selected
  14531. * @arg RCC_MCO_HSI: HSI oscillator clock selected
  14532. * @arg RCC_MCO_HSE: HSE oscillator clock selected
  14533. * @arg RCC_MCO_PLLCLK_Div2: PLL clock divided by 2 selected
  14534. * @arg RCC_MCO_PLL2CLK: PLL2 clock selected
  14535. * @arg RCC_MCO_PLL3CLK_Div2: PLL3 clock divided by 2 selected
  14536. * @arg RCC_MCO_XT1: External 3-25 MHz oscillator clock selected
  14537. * @arg RCC_MCO_PLL3CLK: PLL3 clock selected
  14538. *
  14539. * For @b other_STM32_devices, this parameter can be one of the following values:
  14540. * @arg RCC_MCO_NoClock: No clock selected
  14541. * @arg RCC_MCO_SYSCLK: System clock selected
  14542. * @arg RCC_MCO_HSI: HSI oscillator clock selected
  14543. * @arg RCC_MCO_HSE: HSE oscillator clock selected
  14544. * @arg RCC_MCO_PLLCLK_Div2: PLL clock divided by 2 selected
  14545. *
  14546. * @retval None
  14547. */
  14548. void RCC_MCOConfig(uint8_t RCC_MCO)
  14549. {
  14550. /* Check the parameters */
  14551. assert_param(IS_RCC_MCO(RCC_MCO));
  14552. /* Perform Byte access to MCO bits to select the MCO source */
  14553. *(__IO uint8_t *) CFGR_BYTE4_ADDRESS = RCC_MCO;
  14554. }
  14555. /**
  14556. * @brief Checks whether the specified RCC flag is set or not.
  14557. * @param RCC_FLAG: specifies the flag to check.
  14558. *
  14559. * For @b STM32_Connectivity_line_devices, this parameter can be one of the
  14560. * following values:
  14561. * @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready
  14562. * @arg RCC_FLAG_HSERDY: HSE oscillator clock ready
  14563. * @arg RCC_FLAG_PLLRDY: PLL clock ready
  14564. * @arg RCC_FLAG_PLL2RDY: PLL2 clock ready
  14565. * @arg RCC_FLAG_PLL3RDY: PLL3 clock ready
  14566. * @arg RCC_FLAG_LSERDY: LSE oscillator clock ready
  14567. * @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready
  14568. * @arg RCC_FLAG_PINRST: Pin reset
  14569. * @arg RCC_FLAG_PORRST: POR/PDR reset
  14570. * @arg RCC_FLAG_SFTRST: Software reset
  14571. * @arg RCC_FLAG_IWDGRST: Independent Watchdog reset
  14572. * @arg RCC_FLAG_WWDGRST: Window Watchdog reset
  14573. * @arg RCC_FLAG_LPWRRST: Low Power reset
  14574. *
  14575. * For @b other_STM32_devices, this parameter can be one of the following values:
  14576. * @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready
  14577. * @arg RCC_FLAG_HSERDY: HSE oscillator clock ready
  14578. * @arg RCC_FLAG_PLLRDY: PLL clock ready
  14579. * @arg RCC_FLAG_LSERDY: LSE oscillator clock ready
  14580. * @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready
  14581. * @arg RCC_FLAG_PINRST: Pin reset
  14582. * @arg RCC_FLAG_PORRST: POR/PDR reset
  14583. * @arg RCC_FLAG_SFTRST: Software reset
  14584. * @arg RCC_FLAG_IWDGRST: Independent Watchdog reset
  14585. * @arg RCC_FLAG_WWDGRST: Window Watchdog reset
  14586. * @arg RCC_FLAG_LPWRRST: Low Power reset
  14587. *
  14588. * @retval The new state of RCC_FLAG (SET or RESET).
  14589. */
  14590. FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG)
  14591. {
  14592. uint32_t tmp = 0;
  14593. uint32_t statusreg = 0;
  14594. FlagStatus bitstatus = RESET;
  14595. /* Check the parameters */
  14596. assert_param(IS_RCC_FLAG(RCC_FLAG));
  14597. /* Get the RCC register index */
  14598. tmp = RCC_FLAG >> 5;
  14599. if (tmp == 1) /* The flag to check is in CR register */
  14600. {
  14601. statusreg = RCC->CR;
  14602. }
  14603. else if (tmp == 2) /* The flag to check is in BDCR register */
  14604. {
  14605. statusreg = RCC->BDCR;
  14606. }
  14607. else /* The flag to check is in CSR register */
  14608. {
  14609. statusreg = RCC->CSR;
  14610. }
  14611. /* Get the flag position */
  14612. tmp = RCC_FLAG & FLAG_Mask;
  14613. if ((statusreg & ((uint32_t)1 << tmp)) != (uint32_t)RESET)
  14614. {
  14615. bitstatus = SET;
  14616. }
  14617. else
  14618. {
  14619. bitstatus = RESET;
  14620. }
  14621. /* Return the flag status */
  14622. return bitstatus;
  14623. }
  14624. /**
  14625. * @brief Clears the RCC reset flags.
  14626. * @note The reset flags are: RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,
  14627. * RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
  14628. * @param None
  14629. * @retval None
  14630. */
  14631. void RCC_ClearFlag(void)
  14632. {
  14633. /* Set RMVF bit to clear the reset flags */
  14634. RCC->CSR |= CSR_RMVF_Set;
  14635. }
  14636. /**
  14637. * @brief Checks whether the specified RCC interrupt has occurred or not.
  14638. * @param RCC_IT: specifies the RCC interrupt source to check.
  14639. *
  14640. * For @b STM32_Connectivity_line_devices, this parameter can be one of the
  14641. * following values:
  14642. * @arg RCC_IT_LSIRDY: LSI ready interrupt
  14643. * @arg RCC_IT_LSERDY: LSE ready interrupt
  14644. * @arg RCC_IT_HSIRDY: HSI ready interrupt
  14645. * @arg RCC_IT_HSERDY: HSE ready interrupt
  14646. * @arg RCC_IT_PLLRDY: PLL ready interrupt
  14647. * @arg RCC_IT_PLL2RDY: PLL2 ready interrupt
  14648. * @arg RCC_IT_PLL3RDY: PLL3 ready interrupt
  14649. * @arg RCC_IT_CSS: Clock Security System interrupt
  14650. *
  14651. * For @b other_STM32_devices, this parameter can be one of the following values:
  14652. * @arg RCC_IT_LSIRDY: LSI ready interrupt
  14653. * @arg RCC_IT_LSERDY: LSE ready interrupt
  14654. * @arg RCC_IT_HSIRDY: HSI ready interrupt
  14655. * @arg RCC_IT_HSERDY: HSE ready interrupt
  14656. * @arg RCC_IT_PLLRDY: PLL ready interrupt
  14657. * @arg RCC_IT_CSS: Clock Security System interrupt
  14658. *
  14659. * @retval The new state of RCC_IT (SET or RESET).
  14660. */
  14661. ITStatus RCC_GetITStatus(uint8_t RCC_IT)
  14662. {
  14663. ITStatus bitstatus = RESET;
  14664. /* Check the parameters */
  14665. assert_param(IS_RCC_GET_IT(RCC_IT));
  14666. /* Check the status of the specified RCC interrupt */
  14667. if ((RCC->CIR & RCC_IT) != (uint32_t)RESET)
  14668. {
  14669. bitstatus = SET;
  14670. }
  14671. else
  14672. {
  14673. bitstatus = RESET;
  14674. }
  14675. /* Return the RCC_IT status */
  14676. return bitstatus;
  14677. }
  14678. /**
  14679. * @brief Clears the RCC's interrupt pending bits.
  14680. * @param RCC_IT: specifies the interrupt pending bit to clear.
  14681. *
  14682. * For @b STM32_Connectivity_line_devices, this parameter can be any combination
  14683. * of the following values:
  14684. * @arg RCC_IT_LSIRDY: LSI ready interrupt
  14685. * @arg RCC_IT_LSERDY: LSE ready interrupt
  14686. * @arg RCC_IT_HSIRDY: HSI ready interrupt
  14687. * @arg RCC_IT_HSERDY: HSE ready interrupt
  14688. * @arg RCC_IT_PLLRDY: PLL ready interrupt
  14689. * @arg RCC_IT_PLL2RDY: PLL2 ready interrupt
  14690. * @arg RCC_IT_PLL3RDY: PLL3 ready interrupt
  14691. * @arg RCC_IT_CSS: Clock Security System interrupt
  14692. *
  14693. * For @b other_STM32_devices, this parameter can be any combination of the
  14694. * following values:
  14695. * @arg RCC_IT_LSIRDY: LSI ready interrupt
  14696. * @arg RCC_IT_LSERDY: LSE ready interrupt
  14697. * @arg RCC_IT_HSIRDY: HSI ready interrupt
  14698. * @arg RCC_IT_HSERDY: HSE ready interrupt
  14699. * @arg RCC_IT_PLLRDY: PLL ready interrupt
  14700. *
  14701. * @arg RCC_IT_CSS: Clock Security System interrupt
  14702. * @retval None
  14703. */
  14704. void RCC_ClearITPendingBit(uint8_t RCC_IT)
  14705. {
  14706. /* Check the parameters */
  14707. assert_param(IS_RCC_CLEAR_IT(RCC_IT));
  14708. /* Perform Byte access to RCC_CIR[23:16] bits to clear the selected interrupt
  14709. pending bits */
  14710. *(__IO uint8_t *) CIR_BYTE3_ADDRESS = RCC_IT;
  14711. }
  14712. /**
  14713. * @}
  14714. */
  14715. /**
  14716. * @}
  14717. */
  14718. /**
  14719. * @}
  14720. */
  14721. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  14722. /**
  14723. ******************************************************************************
  14724. * @file stm32f10x_tim.c
  14725. * @author MCD Application Team
  14726. * @version V3.5.0
  14727. * @date 11-March-2011
  14728. * @brief This file provides all the TIM firmware functions.
  14729. ******************************************************************************
  14730. * @attention
  14731. *
  14732. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  14733. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14734. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  14735. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  14736. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  14737. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  14738. *
  14739. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  14740. ******************************************************************************
  14741. */
  14742. /* Includes ------------------------------------------------------------------*/
  14743. #include "stm32f10x_tim.h"
  14744. #include "stm32f10x_rcc.h"
  14745. /** @addtogroup STM32F10x_StdPeriph_Driver
  14746. * @{
  14747. */
  14748. /** @defgroup TIM
  14749. * @brief TIM driver modules
  14750. * @{
  14751. */
  14752. /** @defgroup TIM_Private_TypesDefinitions
  14753. * @{
  14754. */
  14755. /**
  14756. * @}
  14757. */
  14758. /** @defgroup TIM_Private_Defines
  14759. * @{
  14760. */
  14761. /* ---------------------- TIM registers bit mask ------------------------ */
  14762. #define SMCR_ETR_Mask ((uint16_t)0x00FF)
  14763. #define CCMR_Offset ((uint16_t)0x0018)
  14764. #define CCER_CCE_Set ((uint16_t)0x0001)
  14765. #define CCER_CCNE_Set ((uint16_t)0x0004)
  14766. /**
  14767. * @}
  14768. */
  14769. /** @defgroup TIM_Private_Macros
  14770. * @{
  14771. */
  14772. /**
  14773. * @}
  14774. */
  14775. /** @defgroup TIM_Private_Variables
  14776. * @{
  14777. */
  14778. /**
  14779. * @}
  14780. */
  14781. /** @defgroup TIM_Private_FunctionPrototypes
  14782. * @{
  14783. */
  14784. static void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
  14785. uint16_t TIM_ICFilter);
  14786. static void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
  14787. uint16_t TIM_ICFilter);
  14788. static void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
  14789. uint16_t TIM_ICFilter);
  14790. static void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
  14791. uint16_t TIM_ICFilter);
  14792. /**
  14793. * @}
  14794. */
  14795. /** @defgroup TIM_Private_Macros
  14796. * @{
  14797. */
  14798. /**
  14799. * @}
  14800. */
  14801. /** @defgroup TIM_Private_Variables
  14802. * @{
  14803. */
  14804. /**
  14805. * @}
  14806. */
  14807. /** @defgroup TIM_Private_FunctionPrototypes
  14808. * @{
  14809. */
  14810. /**
  14811. * @}
  14812. */
  14813. /** @defgroup TIM_Private_Functions
  14814. * @{
  14815. */
  14816. /**
  14817. * @brief Deinitializes the TIMx peripheral registers to their default reset values.
  14818. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  14819. * @retval None
  14820. */
  14821. void TIM_DeInit(TIM_TypeDef* TIMx)
  14822. {
  14823. /* Check the parameters */
  14824. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  14825. if (TIMx == TIM1)
  14826. {
  14827. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1, ENABLE);
  14828. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1, DISABLE);
  14829. }
  14830. else if (TIMx == TIM2)
  14831. {
  14832. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, ENABLE);
  14833. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE);
  14834. }
  14835. else if (TIMx == TIM3)
  14836. {
  14837. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, ENABLE);
  14838. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, DISABLE);
  14839. }
  14840. else if (TIMx == TIM4)
  14841. {
  14842. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, ENABLE);
  14843. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, DISABLE);
  14844. }
  14845. else if (TIMx == TIM5)
  14846. {
  14847. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM5, ENABLE);
  14848. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM5, DISABLE);
  14849. }
  14850. else if (TIMx == TIM6)
  14851. {
  14852. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6, ENABLE);
  14853. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6, DISABLE);
  14854. }
  14855. else if (TIMx == TIM7)
  14856. {
  14857. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM7, ENABLE);
  14858. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM7, DISABLE);
  14859. }
  14860. else if (TIMx == TIM8)
  14861. {
  14862. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM8, ENABLE);
  14863. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM8, DISABLE);
  14864. }
  14865. else if (TIMx == TIM9)
  14866. {
  14867. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM9, ENABLE);
  14868. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM9, DISABLE);
  14869. }
  14870. else if (TIMx == TIM10)
  14871. {
  14872. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM10, ENABLE);
  14873. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM10, DISABLE);
  14874. }
  14875. else if (TIMx == TIM11)
  14876. {
  14877. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM11, ENABLE);
  14878. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM11, DISABLE);
  14879. }
  14880. else if (TIMx == TIM12)
  14881. {
  14882. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM12, ENABLE);
  14883. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM12, DISABLE);
  14884. }
  14885. else if (TIMx == TIM13)
  14886. {
  14887. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM13, ENABLE);
  14888. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM13, DISABLE);
  14889. }
  14890. else if (TIMx == TIM14)
  14891. {
  14892. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM14, ENABLE);
  14893. RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM14, DISABLE);
  14894. }
  14895. else if (TIMx == TIM15)
  14896. {
  14897. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM15, ENABLE);
  14898. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM15, DISABLE);
  14899. }
  14900. else if (TIMx == TIM16)
  14901. {
  14902. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM16, ENABLE);
  14903. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM16, DISABLE);
  14904. }
  14905. else
  14906. {
  14907. if (TIMx == TIM17)
  14908. {
  14909. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM17, ENABLE);
  14910. RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM17, DISABLE);
  14911. }
  14912. }
  14913. }
  14914. /**
  14915. * @brief Initializes the TIMx Time Base Unit peripheral according to
  14916. * the specified parameters in the TIM_TimeBaseInitStruct.
  14917. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  14918. * @param TIM_TimeBaseInitStruct: pointer to a TIM_TimeBaseInitTypeDef
  14919. * structure that contains the configuration information for the
  14920. * specified TIM peripheral.
  14921. * @retval None
  14922. */
  14923. void TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct)
  14924. {
  14925. uint16_t tmpcr1 = 0;
  14926. /* Check the parameters */
  14927. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  14928. assert_param(IS_TIM_COUNTER_MODE(TIM_TimeBaseInitStruct->TIM_CounterMode));
  14929. assert_param(IS_TIM_CKD_DIV(TIM_TimeBaseInitStruct->TIM_ClockDivision));
  14930. tmpcr1 = TIMx->CR1;
  14931. if((TIMx == TIM1) || (TIMx == TIM8)|| (TIMx == TIM2) || (TIMx == TIM3)||
  14932. (TIMx == TIM4) || (TIMx == TIM5))
  14933. {
  14934. /* Select the Counter Mode */
  14935. tmpcr1 &= (uint16_t)(~((uint16_t)(TIM_CR1_DIR | TIM_CR1_CMS)));
  14936. tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_CounterMode;
  14937. }
  14938. if((TIMx != TIM6) && (TIMx != TIM7))
  14939. {
  14940. /* Set the clock division */
  14941. tmpcr1 &= (uint16_t)(~((uint16_t)TIM_CR1_CKD));
  14942. tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_ClockDivision;
  14943. }
  14944. TIMx->CR1 = tmpcr1;
  14945. /* Set the Autoreload value */
  14946. TIMx->ARR = TIM_TimeBaseInitStruct->TIM_Period ;
  14947. /* Set the Prescaler value */
  14948. TIMx->PSC = TIM_TimeBaseInitStruct->TIM_Prescaler;
  14949. if ((TIMx == TIM1) || (TIMx == TIM8)|| (TIMx == TIM15)|| (TIMx == TIM16) || (TIMx == TIM17))
  14950. {
  14951. /* Set the Repetition Counter value */
  14952. TIMx->RCR = TIM_TimeBaseInitStruct->TIM_RepetitionCounter;
  14953. }
  14954. /* Generate an update event to reload the Prescaler and the Repetition counter
  14955. values immediately */
  14956. TIMx->EGR = TIM_PSCReloadMode_Immediate;
  14957. }
  14958. /**
  14959. * @brief Initializes the TIMx Channel1 according to the specified
  14960. * parameters in the TIM_OCInitStruct.
  14961. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.
  14962. * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure
  14963. * that contains the configuration information for the specified TIM peripheral.
  14964. * @retval None
  14965. */
  14966. void TIM_OC1Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)
  14967. {
  14968. uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
  14969. /* Check the parameters */
  14970. assert_param(IS_TIM_LIST8_PERIPH(TIMx));
  14971. assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));
  14972. assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState));
  14973. assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));
  14974. /* Disable the Channel 1: Reset the CC1E Bit */
  14975. TIMx->CCER &= (uint16_t)(~(uint16_t)TIM_CCER_CC1E);
  14976. /* Get the TIMx CCER register value */
  14977. tmpccer = TIMx->CCER;
  14978. /* Get the TIMx CR2 register value */
  14979. tmpcr2 = TIMx->CR2;
  14980. /* Get the TIMx CCMR1 register value */
  14981. tmpccmrx = TIMx->CCMR1;
  14982. /* Reset the Output Compare Mode Bits */
  14983. tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR1_OC1M));
  14984. tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR1_CC1S));
  14985. /* Select the Output Compare Mode */
  14986. tmpccmrx |= TIM_OCInitStruct->TIM_OCMode;
  14987. /* Reset the Output Polarity level */
  14988. tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC1P));
  14989. /* Set the Output Compare Polarity */
  14990. tmpccer |= TIM_OCInitStruct->TIM_OCPolarity;
  14991. /* Set the Output State */
  14992. tmpccer |= TIM_OCInitStruct->TIM_OutputState;
  14993. if((TIMx == TIM1) || (TIMx == TIM8)|| (TIMx == TIM15)||
  14994. (TIMx == TIM16)|| (TIMx == TIM17))
  14995. {
  14996. assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct->TIM_OutputNState));
  14997. assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct->TIM_OCNPolarity));
  14998. assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct->TIM_OCNIdleState));
  14999. assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState));
  15000. /* Reset the Output N Polarity level */
  15001. tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC1NP));
  15002. /* Set the Output N Polarity */
  15003. tmpccer |= TIM_OCInitStruct->TIM_OCNPolarity;
  15004. /* Reset the Output N State */
  15005. tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC1NE));
  15006. /* Set the Output N State */
  15007. tmpccer |= TIM_OCInitStruct->TIM_OutputNState;
  15008. /* Reset the Output Compare and Output Compare N IDLE State */
  15009. tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS1));
  15010. tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS1N));
  15011. /* Set the Output Idle state */
  15012. tmpcr2 |= TIM_OCInitStruct->TIM_OCIdleState;
  15013. /* Set the Output N Idle state */
  15014. tmpcr2 |= TIM_OCInitStruct->TIM_OCNIdleState;
  15015. }
  15016. /* Write to TIMx CR2 */
  15017. TIMx->CR2 = tmpcr2;
  15018. /* Write to TIMx CCMR1 */
  15019. TIMx->CCMR1 = tmpccmrx;
  15020. /* Set the Capture Compare Register value */
  15021. TIMx->CCR1 = TIM_OCInitStruct->TIM_Pulse;
  15022. /* Write to TIMx CCER */
  15023. TIMx->CCER = tmpccer;
  15024. }
  15025. /**
  15026. * @brief Initializes the TIMx Channel2 according to the specified
  15027. * parameters in the TIM_OCInitStruct.
  15028. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select
  15029. * the TIM peripheral.
  15030. * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure
  15031. * that contains the configuration information for the specified TIM peripheral.
  15032. * @retval None
  15033. */
  15034. void TIM_OC2Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)
  15035. {
  15036. uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
  15037. /* Check the parameters */
  15038. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  15039. assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));
  15040. assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState));
  15041. assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));
  15042. /* Disable the Channel 2: Reset the CC2E Bit */
  15043. TIMx->CCER &= (uint16_t)(~((uint16_t)TIM_CCER_CC2E));
  15044. /* Get the TIMx CCER register value */
  15045. tmpccer = TIMx->CCER;
  15046. /* Get the TIMx CR2 register value */
  15047. tmpcr2 = TIMx->CR2;
  15048. /* Get the TIMx CCMR1 register value */
  15049. tmpccmrx = TIMx->CCMR1;
  15050. /* Reset the Output Compare mode and Capture/Compare selection Bits */
  15051. tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR1_OC2M));
  15052. tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR1_CC2S));
  15053. /* Select the Output Compare Mode */
  15054. tmpccmrx |= (uint16_t)(TIM_OCInitStruct->TIM_OCMode << 8);
  15055. /* Reset the Output Polarity level */
  15056. tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC2P));
  15057. /* Set the Output Compare Polarity */
  15058. tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCPolarity << 4);
  15059. /* Set the Output State */
  15060. tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputState << 4);
  15061. if((TIMx == TIM1) || (TIMx == TIM8))
  15062. {
  15063. assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct->TIM_OutputNState));
  15064. assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct->TIM_OCNPolarity));
  15065. assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct->TIM_OCNIdleState));
  15066. assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState));
  15067. /* Reset the Output N Polarity level */
  15068. tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC2NP));
  15069. /* Set the Output N Polarity */
  15070. tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCNPolarity << 4);
  15071. /* Reset the Output N State */
  15072. tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC2NE));
  15073. /* Set the Output N State */
  15074. tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputNState << 4);
  15075. /* Reset the Output Compare and Output Compare N IDLE State */
  15076. tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS2));
  15077. tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS2N));
  15078. /* Set the Output Idle state */
  15079. tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCIdleState << 2);
  15080. /* Set the Output N Idle state */
  15081. tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCNIdleState << 2);
  15082. }
  15083. /* Write to TIMx CR2 */
  15084. TIMx->CR2 = tmpcr2;
  15085. /* Write to TIMx CCMR1 */
  15086. TIMx->CCMR1 = tmpccmrx;
  15087. /* Set the Capture Compare Register value */
  15088. TIMx->CCR2 = TIM_OCInitStruct->TIM_Pulse;
  15089. /* Write to TIMx CCER */
  15090. TIMx->CCER = tmpccer;
  15091. }
  15092. /**
  15093. * @brief Initializes the TIMx Channel3 according to the specified
  15094. * parameters in the TIM_OCInitStruct.
  15095. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  15096. * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure
  15097. * that contains the configuration information for the specified TIM peripheral.
  15098. * @retval None
  15099. */
  15100. void TIM_OC3Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)
  15101. {
  15102. uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
  15103. /* Check the parameters */
  15104. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  15105. assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));
  15106. assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState));
  15107. assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));
  15108. /* Disable the Channel 2: Reset the CC2E Bit */
  15109. TIMx->CCER &= (uint16_t)(~((uint16_t)TIM_CCER_CC3E));
  15110. /* Get the TIMx CCER register value */
  15111. tmpccer = TIMx->CCER;
  15112. /* Get the TIMx CR2 register value */
  15113. tmpcr2 = TIMx->CR2;
  15114. /* Get the TIMx CCMR2 register value */
  15115. tmpccmrx = TIMx->CCMR2;
  15116. /* Reset the Output Compare mode and Capture/Compare selection Bits */
  15117. tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR2_OC3M));
  15118. tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR2_CC3S));
  15119. /* Select the Output Compare Mode */
  15120. tmpccmrx |= TIM_OCInitStruct->TIM_OCMode;
  15121. /* Reset the Output Polarity level */
  15122. tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC3P));
  15123. /* Set the Output Compare Polarity */
  15124. tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCPolarity << 8);
  15125. /* Set the Output State */
  15126. tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputState << 8);
  15127. if((TIMx == TIM1) || (TIMx == TIM8))
  15128. {
  15129. assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct->TIM_OutputNState));
  15130. assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct->TIM_OCNPolarity));
  15131. assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct->TIM_OCNIdleState));
  15132. assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState));
  15133. /* Reset the Output N Polarity level */
  15134. tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC3NP));
  15135. /* Set the Output N Polarity */
  15136. tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCNPolarity << 8);
  15137. /* Reset the Output N State */
  15138. tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC3NE));
  15139. /* Set the Output N State */
  15140. tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputNState << 8);
  15141. /* Reset the Output Compare and Output Compare N IDLE State */
  15142. tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS3));
  15143. tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS3N));
  15144. /* Set the Output Idle state */
  15145. tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCIdleState << 4);
  15146. /* Set the Output N Idle state */
  15147. tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCNIdleState << 4);
  15148. }
  15149. /* Write to TIMx CR2 */
  15150. TIMx->CR2 = tmpcr2;
  15151. /* Write to TIMx CCMR2 */
  15152. TIMx->CCMR2 = tmpccmrx;
  15153. /* Set the Capture Compare Register value */
  15154. TIMx->CCR3 = TIM_OCInitStruct->TIM_Pulse;
  15155. /* Write to TIMx CCER */
  15156. TIMx->CCER = tmpccer;
  15157. }
  15158. /**
  15159. * @brief Initializes the TIMx Channel4 according to the specified
  15160. * parameters in the TIM_OCInitStruct.
  15161. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  15162. * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure
  15163. * that contains the configuration information for the specified TIM peripheral.
  15164. * @retval None
  15165. */
  15166. void TIM_OC4Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)
  15167. {
  15168. uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
  15169. /* Check the parameters */
  15170. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  15171. assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));
  15172. assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState));
  15173. assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));
  15174. /* Disable the Channel 2: Reset the CC4E Bit */
  15175. TIMx->CCER &= (uint16_t)(~((uint16_t)TIM_CCER_CC4E));
  15176. /* Get the TIMx CCER register value */
  15177. tmpccer = TIMx->CCER;
  15178. /* Get the TIMx CR2 register value */
  15179. tmpcr2 = TIMx->CR2;
  15180. /* Get the TIMx CCMR2 register value */
  15181. tmpccmrx = TIMx->CCMR2;
  15182. /* Reset the Output Compare mode and Capture/Compare selection Bits */
  15183. tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR2_OC4M));
  15184. tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR2_CC4S));
  15185. /* Select the Output Compare Mode */
  15186. tmpccmrx |= (uint16_t)(TIM_OCInitStruct->TIM_OCMode << 8);
  15187. /* Reset the Output Polarity level */
  15188. tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC4P));
  15189. /* Set the Output Compare Polarity */
  15190. tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCPolarity << 12);
  15191. /* Set the Output State */
  15192. tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputState << 12);
  15193. if((TIMx == TIM1) || (TIMx == TIM8))
  15194. {
  15195. assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState));
  15196. /* Reset the Output Compare IDLE State */
  15197. tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS4));
  15198. /* Set the Output Idle state */
  15199. tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCIdleState << 6);
  15200. }
  15201. /* Write to TIMx CR2 */
  15202. TIMx->CR2 = tmpcr2;
  15203. /* Write to TIMx CCMR2 */
  15204. TIMx->CCMR2 = tmpccmrx;
  15205. /* Set the Capture Compare Register value */
  15206. TIMx->CCR4 = TIM_OCInitStruct->TIM_Pulse;
  15207. /* Write to TIMx CCER */
  15208. TIMx->CCER = tmpccer;
  15209. }
  15210. /**
  15211. * @brief Initializes the TIM peripheral according to the specified
  15212. * parameters in the TIM_ICInitStruct.
  15213. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.
  15214. * @param TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure
  15215. * that contains the configuration information for the specified TIM peripheral.
  15216. * @retval None
  15217. */
  15218. void TIM_ICInit(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct)
  15219. {
  15220. /* Check the parameters */
  15221. assert_param(IS_TIM_CHANNEL(TIM_ICInitStruct->TIM_Channel));
  15222. assert_param(IS_TIM_IC_SELECTION(TIM_ICInitStruct->TIM_ICSelection));
  15223. assert_param(IS_TIM_IC_PRESCALER(TIM_ICInitStruct->TIM_ICPrescaler));
  15224. assert_param(IS_TIM_IC_FILTER(TIM_ICInitStruct->TIM_ICFilter));
  15225. if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM2) || (TIMx == TIM3) ||
  15226. (TIMx == TIM4) ||(TIMx == TIM5))
  15227. {
  15228. assert_param(IS_TIM_IC_POLARITY(TIM_ICInitStruct->TIM_ICPolarity));
  15229. }
  15230. else
  15231. {
  15232. assert_param(IS_TIM_IC_POLARITY_LITE(TIM_ICInitStruct->TIM_ICPolarity));
  15233. }
  15234. if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1)
  15235. {
  15236. assert_param(IS_TIM_LIST8_PERIPH(TIMx));
  15237. /* TI1 Configuration */
  15238. TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
  15239. TIM_ICInitStruct->TIM_ICSelection,
  15240. TIM_ICInitStruct->TIM_ICFilter);
  15241. /* Set the Input Capture Prescaler value */
  15242. TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
  15243. }
  15244. else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_2)
  15245. {
  15246. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  15247. /* TI2 Configuration */
  15248. TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
  15249. TIM_ICInitStruct->TIM_ICSelection,
  15250. TIM_ICInitStruct->TIM_ICFilter);
  15251. /* Set the Input Capture Prescaler value */
  15252. TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
  15253. }
  15254. else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_3)
  15255. {
  15256. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  15257. /* TI3 Configuration */
  15258. TI3_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
  15259. TIM_ICInitStruct->TIM_ICSelection,
  15260. TIM_ICInitStruct->TIM_ICFilter);
  15261. /* Set the Input Capture Prescaler value */
  15262. TIM_SetIC3Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
  15263. }
  15264. else
  15265. {
  15266. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  15267. /* TI4 Configuration */
  15268. TI4_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
  15269. TIM_ICInitStruct->TIM_ICSelection,
  15270. TIM_ICInitStruct->TIM_ICFilter);
  15271. /* Set the Input Capture Prescaler value */
  15272. TIM_SetIC4Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
  15273. }
  15274. }
  15275. /**
  15276. * @brief Configures the TIM peripheral according to the specified
  15277. * parameters in the TIM_ICInitStruct to measure an external PWM signal.
  15278. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.
  15279. * @param TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure
  15280. * that contains the configuration information for the specified TIM peripheral.
  15281. * @retval None
  15282. */
  15283. void TIM_PWMIConfig(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct)
  15284. {
  15285. uint16_t icoppositepolarity = TIM_ICPolarity_Rising;
  15286. uint16_t icoppositeselection = TIM_ICSelection_DirectTI;
  15287. /* Check the parameters */
  15288. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  15289. /* Select the Opposite Input Polarity */
  15290. if (TIM_ICInitStruct->TIM_ICPolarity == TIM_ICPolarity_Rising)
  15291. {
  15292. icoppositepolarity = TIM_ICPolarity_Falling;
  15293. }
  15294. else
  15295. {
  15296. icoppositepolarity = TIM_ICPolarity_Rising;
  15297. }
  15298. /* Select the Opposite Input */
  15299. if (TIM_ICInitStruct->TIM_ICSelection == TIM_ICSelection_DirectTI)
  15300. {
  15301. icoppositeselection = TIM_ICSelection_IndirectTI;
  15302. }
  15303. else
  15304. {
  15305. icoppositeselection = TIM_ICSelection_DirectTI;
  15306. }
  15307. if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1)
  15308. {
  15309. /* TI1 Configuration */
  15310. TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,
  15311. TIM_ICInitStruct->TIM_ICFilter);
  15312. /* Set the Input Capture Prescaler value */
  15313. TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
  15314. /* TI2 Configuration */
  15315. TI2_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);
  15316. /* Set the Input Capture Prescaler value */
  15317. TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
  15318. }
  15319. else
  15320. {
  15321. /* TI2 Configuration */
  15322. TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,
  15323. TIM_ICInitStruct->TIM_ICFilter);
  15324. /* Set the Input Capture Prescaler value */
  15325. TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
  15326. /* TI1 Configuration */
  15327. TI1_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);
  15328. /* Set the Input Capture Prescaler value */
  15329. TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
  15330. }
  15331. }
  15332. /**
  15333. * @brief Configures the: Break feature, dead time, Lock level, the OSSI,
  15334. * the OSSR State and the AOE(automatic output enable).
  15335. * @param TIMx: where x can be 1 or 8 to select the TIM
  15336. * @param TIM_BDTRInitStruct: pointer to a TIM_BDTRInitTypeDef structure that
  15337. * contains the BDTR Register configuration information for the TIM peripheral.
  15338. * @retval None
  15339. */
  15340. void TIM_BDTRConfig(TIM_TypeDef* TIMx, TIM_BDTRInitTypeDef *TIM_BDTRInitStruct)
  15341. {
  15342. /* Check the parameters */
  15343. assert_param(IS_TIM_LIST2_PERIPH(TIMx));
  15344. assert_param(IS_TIM_OSSR_STATE(TIM_BDTRInitStruct->TIM_OSSRState));
  15345. assert_param(IS_TIM_OSSI_STATE(TIM_BDTRInitStruct->TIM_OSSIState));
  15346. assert_param(IS_TIM_LOCK_LEVEL(TIM_BDTRInitStruct->TIM_LOCKLevel));
  15347. assert_param(IS_TIM_BREAK_STATE(TIM_BDTRInitStruct->TIM_Break));
  15348. assert_param(IS_TIM_BREAK_POLARITY(TIM_BDTRInitStruct->TIM_BreakPolarity));
  15349. assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(TIM_BDTRInitStruct->TIM_AutomaticOutput));
  15350. /* Set the Lock level, the Break enable Bit and the Ploarity, the OSSR State,
  15351. the OSSI State, the dead time value and the Automatic Output Enable Bit */
  15352. TIMx->BDTR = (uint32_t)TIM_BDTRInitStruct->TIM_OSSRState | TIM_BDTRInitStruct->TIM_OSSIState |
  15353. TIM_BDTRInitStruct->TIM_LOCKLevel | TIM_BDTRInitStruct->TIM_DeadTime |
  15354. TIM_BDTRInitStruct->TIM_Break | TIM_BDTRInitStruct->TIM_BreakPolarity |
  15355. TIM_BDTRInitStruct->TIM_AutomaticOutput;
  15356. }
  15357. /**
  15358. * @brief Fills each TIM_TimeBaseInitStruct member with its default value.
  15359. * @param TIM_TimeBaseInitStruct : pointer to a TIM_TimeBaseInitTypeDef
  15360. * structure which will be initialized.
  15361. * @retval None
  15362. */
  15363. void TIM_TimeBaseStructInit(TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct)
  15364. {
  15365. /* Set the default configuration */
  15366. TIM_TimeBaseInitStruct->TIM_Period = 0xFFFF;
  15367. TIM_TimeBaseInitStruct->TIM_Prescaler = 0x0000;
  15368. TIM_TimeBaseInitStruct->TIM_ClockDivision = TIM_CKD_DIV1;
  15369. TIM_TimeBaseInitStruct->TIM_CounterMode = TIM_CounterMode_Up;
  15370. TIM_TimeBaseInitStruct->TIM_RepetitionCounter = 0x0000;
  15371. }
  15372. /**
  15373. * @brief Fills each TIM_OCInitStruct member with its default value.
  15374. * @param TIM_OCInitStruct : pointer to a TIM_OCInitTypeDef structure which will
  15375. * be initialized.
  15376. * @retval None
  15377. */
  15378. void TIM_OCStructInit(TIM_OCInitTypeDef* TIM_OCInitStruct)
  15379. {
  15380. /* Set the default configuration */
  15381. TIM_OCInitStruct->TIM_OCMode = TIM_OCMode_Timing;
  15382. TIM_OCInitStruct->TIM_OutputState = TIM_OutputState_Disable;
  15383. TIM_OCInitStruct->TIM_OutputNState = TIM_OutputNState_Disable;
  15384. TIM_OCInitStruct->TIM_Pulse = 0x0000;
  15385. TIM_OCInitStruct->TIM_OCPolarity = TIM_OCPolarity_High;
  15386. TIM_OCInitStruct->TIM_OCNPolarity = TIM_OCPolarity_High;
  15387. TIM_OCInitStruct->TIM_OCIdleState = TIM_OCIdleState_Reset;
  15388. TIM_OCInitStruct->TIM_OCNIdleState = TIM_OCNIdleState_Reset;
  15389. }
  15390. /**
  15391. * @brief Fills each TIM_ICInitStruct member with its default value.
  15392. * @param TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure which will
  15393. * be initialized.
  15394. * @retval None
  15395. */
  15396. void TIM_ICStructInit(TIM_ICInitTypeDef* TIM_ICInitStruct)
  15397. {
  15398. /* Set the default configuration */
  15399. TIM_ICInitStruct->TIM_Channel = TIM_Channel_1;
  15400. TIM_ICInitStruct->TIM_ICPolarity = TIM_ICPolarity_Rising;
  15401. TIM_ICInitStruct->TIM_ICSelection = TIM_ICSelection_DirectTI;
  15402. TIM_ICInitStruct->TIM_ICPrescaler = TIM_ICPSC_DIV1;
  15403. TIM_ICInitStruct->TIM_ICFilter = 0x00;
  15404. }
  15405. /**
  15406. * @brief Fills each TIM_BDTRInitStruct member with its default value.
  15407. * @param TIM_BDTRInitStruct: pointer to a TIM_BDTRInitTypeDef structure which
  15408. * will be initialized.
  15409. * @retval None
  15410. */
  15411. void TIM_BDTRStructInit(TIM_BDTRInitTypeDef* TIM_BDTRInitStruct)
  15412. {
  15413. /* Set the default configuration */
  15414. TIM_BDTRInitStruct->TIM_OSSRState = TIM_OSSRState_Disable;
  15415. TIM_BDTRInitStruct->TIM_OSSIState = TIM_OSSIState_Disable;
  15416. TIM_BDTRInitStruct->TIM_LOCKLevel = TIM_LOCKLevel_OFF;
  15417. TIM_BDTRInitStruct->TIM_DeadTime = 0x00;
  15418. TIM_BDTRInitStruct->TIM_Break = TIM_Break_Disable;
  15419. TIM_BDTRInitStruct->TIM_BreakPolarity = TIM_BreakPolarity_Low;
  15420. TIM_BDTRInitStruct->TIM_AutomaticOutput = TIM_AutomaticOutput_Disable;
  15421. }
  15422. /**
  15423. * @brief Enables or disables the specified TIM peripheral.
  15424. * @param TIMx: where x can be 1 to 17 to select the TIMx peripheral.
  15425. * @param NewState: new state of the TIMx peripheral.
  15426. * This parameter can be: ENABLE or DISABLE.
  15427. * @retval None
  15428. */
  15429. void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState)
  15430. {
  15431. /* Check the parameters */
  15432. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  15433. assert_param(IS_FUNCTIONAL_STATE(NewState));
  15434. if (NewState != DISABLE)
  15435. {
  15436. /* Enable the TIM Counter */
  15437. TIMx->CR1 |= TIM_CR1_CEN;
  15438. }
  15439. else
  15440. {
  15441. /* Disable the TIM Counter */
  15442. TIMx->CR1 &= (uint16_t)(~((uint16_t)TIM_CR1_CEN));
  15443. }
  15444. }
  15445. /**
  15446. * @brief Enables or disables the TIM peripheral Main Outputs.
  15447. * @param TIMx: where x can be 1, 8, 15, 16 or 17 to select the TIMx peripheral.
  15448. * @param NewState: new state of the TIM peripheral Main Outputs.
  15449. * This parameter can be: ENABLE or DISABLE.
  15450. * @retval None
  15451. */
  15452. void TIM_CtrlPWMOutputs(TIM_TypeDef* TIMx, FunctionalState NewState)
  15453. {
  15454. /* Check the parameters */
  15455. assert_param(IS_TIM_LIST2_PERIPH(TIMx));
  15456. assert_param(IS_FUNCTIONAL_STATE(NewState));
  15457. if (NewState != DISABLE)
  15458. {
  15459. /* Enable the TIM Main Output */
  15460. TIMx->BDTR |= TIM_BDTR_MOE;
  15461. }
  15462. else
  15463. {
  15464. /* Disable the TIM Main Output */
  15465. TIMx->BDTR &= (uint16_t)(~((uint16_t)TIM_BDTR_MOE));
  15466. }
  15467. }
  15468. /**
  15469. * @brief Enables or disables the specified TIM interrupts.
  15470. * @param TIMx: where x can be 1 to 17 to select the TIMx peripheral.
  15471. * @param TIM_IT: specifies the TIM interrupts sources to be enabled or disabled.
  15472. * This parameter can be any combination of the following values:
  15473. * @arg TIM_IT_Update: TIM update Interrupt source
  15474. * @arg TIM_IT_CC1: TIM Capture Compare 1 Interrupt source
  15475. * @arg TIM_IT_CC2: TIM Capture Compare 2 Interrupt source
  15476. * @arg TIM_IT_CC3: TIM Capture Compare 3 Interrupt source
  15477. * @arg TIM_IT_CC4: TIM Capture Compare 4 Interrupt source
  15478. * @arg TIM_IT_COM: TIM Commutation Interrupt source
  15479. * @arg TIM_IT_Trigger: TIM Trigger Interrupt source
  15480. * @arg TIM_IT_Break: TIM Break Interrupt source
  15481. * @note
  15482. * - TIM6 and TIM7 can only generate an update interrupt.
  15483. * - TIM9, TIM12 and TIM15 can have only TIM_IT_Update, TIM_IT_CC1,
  15484. * TIM_IT_CC2 or TIM_IT_Trigger.
  15485. * - TIM10, TIM11, TIM13, TIM14, TIM16 and TIM17 can have TIM_IT_Update or TIM_IT_CC1.
  15486. * - TIM_IT_Break is used only with TIM1, TIM8 and TIM15.
  15487. * - TIM_IT_COM is used only with TIM1, TIM8, TIM15, TIM16 and TIM17.
  15488. * @param NewState: new state of the TIM interrupts.
  15489. * This parameter can be: ENABLE or DISABLE.
  15490. * @retval None
  15491. */
  15492. void TIM_ITConfig(TIM_TypeDef* TIMx, uint16_t TIM_IT, FunctionalState NewState)
  15493. {
  15494. /* Check the parameters */
  15495. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  15496. assert_param(IS_TIM_IT(TIM_IT));
  15497. assert_param(IS_FUNCTIONAL_STATE(NewState));
  15498. if (NewState != DISABLE)
  15499. {
  15500. /* Enable the Interrupt sources */
  15501. TIMx->DIER |= TIM_IT;
  15502. }
  15503. else
  15504. {
  15505. /* Disable the Interrupt sources */
  15506. TIMx->DIER &= (uint16_t)~TIM_IT;
  15507. }
  15508. }
  15509. /**
  15510. * @brief Configures the TIMx event to be generate by software.
  15511. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  15512. * @param TIM_EventSource: specifies the event source.
  15513. * This parameter can be one or more of the following values:
  15514. * @arg TIM_EventSource_Update: Timer update Event source
  15515. * @arg TIM_EventSource_CC1: Timer Capture Compare 1 Event source
  15516. * @arg TIM_EventSource_CC2: Timer Capture Compare 2 Event source
  15517. * @arg TIM_EventSource_CC3: Timer Capture Compare 3 Event source
  15518. * @arg TIM_EventSource_CC4: Timer Capture Compare 4 Event source
  15519. * @arg TIM_EventSource_COM: Timer COM event source
  15520. * @arg TIM_EventSource_Trigger: Timer Trigger Event source
  15521. * @arg TIM_EventSource_Break: Timer Break event source
  15522. * @note
  15523. * - TIM6 and TIM7 can only generate an update event.
  15524. * - TIM_EventSource_COM and TIM_EventSource_Break are used only with TIM1 and TIM8.
  15525. * @retval None
  15526. */
  15527. void TIM_GenerateEvent(TIM_TypeDef* TIMx, uint16_t TIM_EventSource)
  15528. {
  15529. /* Check the parameters */
  15530. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  15531. assert_param(IS_TIM_EVENT_SOURCE(TIM_EventSource));
  15532. /* Set the event sources */
  15533. TIMx->EGR = TIM_EventSource;
  15534. }
  15535. /**
  15536. * @brief Configures the TIMx's DMA interface.
  15537. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 15, 16 or 17 to select
  15538. * the TIM peripheral.
  15539. * @param TIM_DMABase: DMA Base address.
  15540. * This parameter can be one of the following values:
  15541. * @arg TIM_DMABase_CR, TIM_DMABase_CR2, TIM_DMABase_SMCR,
  15542. * TIM_DMABase_DIER, TIM1_DMABase_SR, TIM_DMABase_EGR,
  15543. * TIM_DMABase_CCMR1, TIM_DMABase_CCMR2, TIM_DMABase_CCER,
  15544. * TIM_DMABase_CNT, TIM_DMABase_PSC, TIM_DMABase_ARR,
  15545. * TIM_DMABase_RCR, TIM_DMABase_CCR1, TIM_DMABase_CCR2,
  15546. * TIM_DMABase_CCR3, TIM_DMABase_CCR4, TIM_DMABase_BDTR,
  15547. * TIM_DMABase_DCR.
  15548. * @param TIM_DMABurstLength: DMA Burst length.
  15549. * This parameter can be one value between:
  15550. * TIM_DMABurstLength_1Transfer and TIM_DMABurstLength_18Transfers.
  15551. * @retval None
  15552. */
  15553. void TIM_DMAConfig(TIM_TypeDef* TIMx, uint16_t TIM_DMABase, uint16_t TIM_DMABurstLength)
  15554. {
  15555. /* Check the parameters */
  15556. assert_param(IS_TIM_LIST4_PERIPH(TIMx));
  15557. assert_param(IS_TIM_DMA_BASE(TIM_DMABase));
  15558. assert_param(IS_TIM_DMA_LENGTH(TIM_DMABurstLength));
  15559. /* Set the DMA Base and the DMA Burst Length */
  15560. TIMx->DCR = TIM_DMABase | TIM_DMABurstLength;
  15561. }
  15562. /**
  15563. * @brief Enables or disables the TIMx's DMA Requests.
  15564. * @param TIMx: where x can be 1, 2, 3, 4, 5, 6, 7, 8, 15, 16 or 17
  15565. * to select the TIM peripheral.
  15566. * @param TIM_DMASource: specifies the DMA Request sources.
  15567. * This parameter can be any combination of the following values:
  15568. * @arg TIM_DMA_Update: TIM update Interrupt source
  15569. * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
  15570. * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
  15571. * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
  15572. * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
  15573. * @arg TIM_DMA_COM: TIM Commutation DMA source
  15574. * @arg TIM_DMA_Trigger: TIM Trigger DMA source
  15575. * @param NewState: new state of the DMA Request sources.
  15576. * This parameter can be: ENABLE or DISABLE.
  15577. * @retval None
  15578. */
  15579. void TIM_DMACmd(TIM_TypeDef* TIMx, uint16_t TIM_DMASource, FunctionalState NewState)
  15580. {
  15581. /* Check the parameters */
  15582. assert_param(IS_TIM_LIST9_PERIPH(TIMx));
  15583. assert_param(IS_TIM_DMA_SOURCE(TIM_DMASource));
  15584. assert_param(IS_FUNCTIONAL_STATE(NewState));
  15585. if (NewState != DISABLE)
  15586. {
  15587. /* Enable the DMA sources */
  15588. TIMx->DIER |= TIM_DMASource;
  15589. }
  15590. else
  15591. {
  15592. /* Disable the DMA sources */
  15593. TIMx->DIER &= (uint16_t)~TIM_DMASource;
  15594. }
  15595. }
  15596. /**
  15597. * @brief Configures the TIMx internal Clock
  15598. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15
  15599. * to select the TIM peripheral.
  15600. * @retval None
  15601. */
  15602. void TIM_InternalClockConfig(TIM_TypeDef* TIMx)
  15603. {
  15604. /* Check the parameters */
  15605. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  15606. /* Disable slave mode to clock the prescaler directly with the internal clock */
  15607. TIMx->SMCR &= (uint16_t)(~((uint16_t)TIM_SMCR_SMS));
  15608. }
  15609. /**
  15610. * @brief Configures the TIMx Internal Trigger as External Clock
  15611. * @param TIMx: where x can be 1, 2, 3, 4, 5, 9, 12 or 15 to select the TIM peripheral.
  15612. * @param TIM_ITRSource: Trigger source.
  15613. * This parameter can be one of the following values:
  15614. * @param TIM_TS_ITR0: Internal Trigger 0
  15615. * @param TIM_TS_ITR1: Internal Trigger 1
  15616. * @param TIM_TS_ITR2: Internal Trigger 2
  15617. * @param TIM_TS_ITR3: Internal Trigger 3
  15618. * @retval None
  15619. */
  15620. void TIM_ITRxExternalClockConfig(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource)
  15621. {
  15622. /* Check the parameters */
  15623. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  15624. assert_param(IS_TIM_INTERNAL_TRIGGER_SELECTION(TIM_InputTriggerSource));
  15625. /* Select the Internal Trigger */
  15626. TIM_SelectInputTrigger(TIMx, TIM_InputTriggerSource);
  15627. /* Select the External clock mode1 */
  15628. TIMx->SMCR |= TIM_SlaveMode_External1;
  15629. }
  15630. /**
  15631. * @brief Configures the TIMx Trigger as External Clock
  15632. * @param TIMx: where x can be 1, 2, 3, 4, 5, 9, 12 or 15 to select the TIM peripheral.
  15633. * @param TIM_TIxExternalCLKSource: Trigger source.
  15634. * This parameter can be one of the following values:
  15635. * @arg TIM_TIxExternalCLK1Source_TI1ED: TI1 Edge Detector
  15636. * @arg TIM_TIxExternalCLK1Source_TI1: Filtered Timer Input 1
  15637. * @arg TIM_TIxExternalCLK1Source_TI2: Filtered Timer Input 2
  15638. * @param TIM_ICPolarity: specifies the TIx Polarity.
  15639. * This parameter can be one of the following values:
  15640. * @arg TIM_ICPolarity_Rising
  15641. * @arg TIM_ICPolarity_Falling
  15642. * @param ICFilter : specifies the filter value.
  15643. * This parameter must be a value between 0x0 and 0xF.
  15644. * @retval None
  15645. */
  15646. void TIM_TIxExternalClockConfig(TIM_TypeDef* TIMx, uint16_t TIM_TIxExternalCLKSource,
  15647. uint16_t TIM_ICPolarity, uint16_t ICFilter)
  15648. {
  15649. /* Check the parameters */
  15650. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  15651. assert_param(IS_TIM_TIXCLK_SOURCE(TIM_TIxExternalCLKSource));
  15652. assert_param(IS_TIM_IC_POLARITY(TIM_ICPolarity));
  15653. assert_param(IS_TIM_IC_FILTER(ICFilter));
  15654. /* Configure the Timer Input Clock Source */
  15655. if (TIM_TIxExternalCLKSource == TIM_TIxExternalCLK1Source_TI2)
  15656. {
  15657. TI2_Config(TIMx, TIM_ICPolarity, TIM_ICSelection_DirectTI, ICFilter);
  15658. }
  15659. else
  15660. {
  15661. TI1_Config(TIMx, TIM_ICPolarity, TIM_ICSelection_DirectTI, ICFilter);
  15662. }
  15663. /* Select the Trigger source */
  15664. TIM_SelectInputTrigger(TIMx, TIM_TIxExternalCLKSource);
  15665. /* Select the External clock mode1 */
  15666. TIMx->SMCR |= TIM_SlaveMode_External1;
  15667. }
  15668. /**
  15669. * @brief Configures the External clock Mode1
  15670. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  15671. * @param TIM_ExtTRGPrescaler: The external Trigger Prescaler.
  15672. * This parameter can be one of the following values:
  15673. * @arg TIM_ExtTRGPSC_OFF: ETRP Prescaler OFF.
  15674. * @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.
  15675. * @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.
  15676. * @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.
  15677. * @param TIM_ExtTRGPolarity: The external Trigger Polarity.
  15678. * This parameter can be one of the following values:
  15679. * @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.
  15680. * @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.
  15681. * @param ExtTRGFilter: External Trigger Filter.
  15682. * This parameter must be a value between 0x00 and 0x0F
  15683. * @retval None
  15684. */
  15685. void TIM_ETRClockMode1Config(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity,
  15686. uint16_t ExtTRGFilter)
  15687. {
  15688. uint16_t tmpsmcr = 0;
  15689. /* Check the parameters */
  15690. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  15691. assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler));
  15692. assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity));
  15693. assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter));
  15694. /* Configure the ETR Clock source */
  15695. TIM_ETRConfig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter);
  15696. /* Get the TIMx SMCR register value */
  15697. tmpsmcr = TIMx->SMCR;
  15698. /* Reset the SMS Bits */
  15699. tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCR_SMS));
  15700. /* Select the External clock mode1 */
  15701. tmpsmcr |= TIM_SlaveMode_External1;
  15702. /* Select the Trigger selection : ETRF */
  15703. tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCR_TS));
  15704. tmpsmcr |= TIM_TS_ETRF;
  15705. /* Write to TIMx SMCR */
  15706. TIMx->SMCR = tmpsmcr;
  15707. }
  15708. /**
  15709. * @brief Configures the External clock Mode2
  15710. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  15711. * @param TIM_ExtTRGPrescaler: The external Trigger Prescaler.
  15712. * This parameter can be one of the following values:
  15713. * @arg TIM_ExtTRGPSC_OFF: ETRP Prescaler OFF.
  15714. * @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.
  15715. * @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.
  15716. * @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.
  15717. * @param TIM_ExtTRGPolarity: The external Trigger Polarity.
  15718. * This parameter can be one of the following values:
  15719. * @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.
  15720. * @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.
  15721. * @param ExtTRGFilter: External Trigger Filter.
  15722. * This parameter must be a value between 0x00 and 0x0F
  15723. * @retval None
  15724. */
  15725. void TIM_ETRClockMode2Config(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler,
  15726. uint16_t TIM_ExtTRGPolarity, uint16_t ExtTRGFilter)
  15727. {
  15728. /* Check the parameters */
  15729. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  15730. assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler));
  15731. assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity));
  15732. assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter));
  15733. /* Configure the ETR Clock source */
  15734. TIM_ETRConfig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter);
  15735. /* Enable the External clock mode2 */
  15736. TIMx->SMCR |= TIM_SMCR_ECE;
  15737. }
  15738. /**
  15739. * @brief Configures the TIMx External Trigger (ETR).
  15740. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  15741. * @param TIM_ExtTRGPrescaler: The external Trigger Prescaler.
  15742. * This parameter can be one of the following values:
  15743. * @arg TIM_ExtTRGPSC_OFF: ETRP Prescaler OFF.
  15744. * @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.
  15745. * @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.
  15746. * @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.
  15747. * @param TIM_ExtTRGPolarity: The external Trigger Polarity.
  15748. * This parameter can be one of the following values:
  15749. * @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.
  15750. * @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.
  15751. * @param ExtTRGFilter: External Trigger Filter.
  15752. * This parameter must be a value between 0x00 and 0x0F
  15753. * @retval None
  15754. */
  15755. void TIM_ETRConfig(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity,
  15756. uint16_t ExtTRGFilter)
  15757. {
  15758. uint16_t tmpsmcr = 0;
  15759. /* Check the parameters */
  15760. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  15761. assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler));
  15762. assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity));
  15763. assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter));
  15764. tmpsmcr = TIMx->SMCR;
  15765. /* Reset the ETR Bits */
  15766. tmpsmcr &= SMCR_ETR_Mask;
  15767. /* Set the Prescaler, the Filter value and the Polarity */
  15768. tmpsmcr |= (uint16_t)(TIM_ExtTRGPrescaler | (uint16_t)(TIM_ExtTRGPolarity | (uint16_t)(ExtTRGFilter << (uint16_t)8)));
  15769. /* Write to TIMx SMCR */
  15770. TIMx->SMCR = tmpsmcr;
  15771. }
  15772. /**
  15773. * @brief Configures the TIMx Prescaler.
  15774. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  15775. * @param Prescaler: specifies the Prescaler Register value
  15776. * @param TIM_PSCReloadMode: specifies the TIM Prescaler Reload mode
  15777. * This parameter can be one of the following values:
  15778. * @arg TIM_PSCReloadMode_Update: The Prescaler is loaded at the update event.
  15779. * @arg TIM_PSCReloadMode_Immediate: The Prescaler is loaded immediately.
  15780. * @retval None
  15781. */
  15782. void TIM_PrescalerConfig(TIM_TypeDef* TIMx, uint16_t Prescaler, uint16_t TIM_PSCReloadMode)
  15783. {
  15784. /* Check the parameters */
  15785. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  15786. assert_param(IS_TIM_PRESCALER_RELOAD(TIM_PSCReloadMode));
  15787. /* Set the Prescaler value */
  15788. TIMx->PSC = Prescaler;
  15789. /* Set or reset the UG Bit */
  15790. TIMx->EGR = TIM_PSCReloadMode;
  15791. }
  15792. /**
  15793. * @brief Specifies the TIMx Counter Mode to be used.
  15794. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  15795. * @param TIM_CounterMode: specifies the Counter Mode to be used
  15796. * This parameter can be one of the following values:
  15797. * @arg TIM_CounterMode_Up: TIM Up Counting Mode
  15798. * @arg TIM_CounterMode_Down: TIM Down Counting Mode
  15799. * @arg TIM_CounterMode_CenterAligned1: TIM Center Aligned Mode1
  15800. * @arg TIM_CounterMode_CenterAligned2: TIM Center Aligned Mode2
  15801. * @arg TIM_CounterMode_CenterAligned3: TIM Center Aligned Mode3
  15802. * @retval None
  15803. */
  15804. void TIM_CounterModeConfig(TIM_TypeDef* TIMx, uint16_t TIM_CounterMode)
  15805. {
  15806. uint16_t tmpcr1 = 0;
  15807. /* Check the parameters */
  15808. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  15809. assert_param(IS_TIM_COUNTER_MODE(TIM_CounterMode));
  15810. tmpcr1 = TIMx->CR1;
  15811. /* Reset the CMS and DIR Bits */
  15812. tmpcr1 &= (uint16_t)(~((uint16_t)(TIM_CR1_DIR | TIM_CR1_CMS)));
  15813. /* Set the Counter Mode */
  15814. tmpcr1 |= TIM_CounterMode;
  15815. /* Write to TIMx CR1 register */
  15816. TIMx->CR1 = tmpcr1;
  15817. }
  15818. /**
  15819. * @brief Selects the Input Trigger source
  15820. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.
  15821. * @param TIM_InputTriggerSource: The Input Trigger source.
  15822. * This parameter can be one of the following values:
  15823. * @arg TIM_TS_ITR0: Internal Trigger 0
  15824. * @arg TIM_TS_ITR1: Internal Trigger 1
  15825. * @arg TIM_TS_ITR2: Internal Trigger 2
  15826. * @arg TIM_TS_ITR3: Internal Trigger 3
  15827. * @arg TIM_TS_TI1F_ED: TI1 Edge Detector
  15828. * @arg TIM_TS_TI1FP1: Filtered Timer Input 1
  15829. * @arg TIM_TS_TI2FP2: Filtered Timer Input 2
  15830. * @arg TIM_TS_ETRF: External Trigger input
  15831. * @retval None
  15832. */
  15833. void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource)
  15834. {
  15835. uint16_t tmpsmcr = 0;
  15836. /* Check the parameters */
  15837. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  15838. assert_param(IS_TIM_TRIGGER_SELECTION(TIM_InputTriggerSource));
  15839. /* Get the TIMx SMCR register value */
  15840. tmpsmcr = TIMx->SMCR;
  15841. /* Reset the TS Bits */
  15842. tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCR_TS));
  15843. /* Set the Input Trigger source */
  15844. tmpsmcr |= TIM_InputTriggerSource;
  15845. /* Write to TIMx SMCR */
  15846. TIMx->SMCR = tmpsmcr;
  15847. }
  15848. /**
  15849. * @brief Configures the TIMx Encoder Interface.
  15850. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  15851. * @param TIM_EncoderMode: specifies the TIMx Encoder Mode.
  15852. * This parameter can be one of the following values:
  15853. * @arg TIM_EncoderMode_TI1: Counter counts on TI1FP1 edge depending on TI2FP2 level.
  15854. * @arg TIM_EncoderMode_TI2: Counter counts on TI2FP2 edge depending on TI1FP1 level.
  15855. * @arg TIM_EncoderMode_TI12: Counter counts on both TI1FP1 and TI2FP2 edges depending
  15856. * on the level of the other input.
  15857. * @param TIM_IC1Polarity: specifies the IC1 Polarity
  15858. * This parameter can be one of the following values:
  15859. * @arg TIM_ICPolarity_Falling: IC Falling edge.
  15860. * @arg TIM_ICPolarity_Rising: IC Rising edge.
  15861. * @param TIM_IC2Polarity: specifies the IC2 Polarity
  15862. * This parameter can be one of the following values:
  15863. * @arg TIM_ICPolarity_Falling: IC Falling edge.
  15864. * @arg TIM_ICPolarity_Rising: IC Rising edge.
  15865. * @retval None
  15866. */
  15867. void TIM_EncoderInterfaceConfig(TIM_TypeDef* TIMx, uint16_t TIM_EncoderMode,
  15868. uint16_t TIM_IC1Polarity, uint16_t TIM_IC2Polarity)
  15869. {
  15870. uint16_t tmpsmcr = 0;
  15871. uint16_t tmpccmr1 = 0;
  15872. uint16_t tmpccer = 0;
  15873. /* Check the parameters */
  15874. assert_param(IS_TIM_LIST5_PERIPH(TIMx));
  15875. assert_param(IS_TIM_ENCODER_MODE(TIM_EncoderMode));
  15876. assert_param(IS_TIM_IC_POLARITY(TIM_IC1Polarity));
  15877. assert_param(IS_TIM_IC_POLARITY(TIM_IC2Polarity));
  15878. /* Get the TIMx SMCR register value */
  15879. tmpsmcr = TIMx->SMCR;
  15880. /* Get the TIMx CCMR1 register value */
  15881. tmpccmr1 = TIMx->CCMR1;
  15882. /* Get the TIMx CCER register value */
  15883. tmpccer = TIMx->CCER;
  15884. /* Set the encoder Mode */
  15885. tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCR_SMS));
  15886. tmpsmcr |= TIM_EncoderMode;
  15887. /* Select the Capture Compare 1 and the Capture Compare 2 as input */
  15888. tmpccmr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR1_CC1S)) & (uint16_t)(~((uint16_t)TIM_CCMR1_CC2S)));
  15889. tmpccmr1 |= TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_0;
  15890. /* Set the TI1 and the TI2 Polarities */
  15891. tmpccer &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCER_CC1P)) & ((uint16_t)~((uint16_t)TIM_CCER_CC2P)));
  15892. tmpccer |= (uint16_t)(TIM_IC1Polarity | (uint16_t)(TIM_IC2Polarity << (uint16_t)4));
  15893. /* Write to TIMx SMCR */
  15894. TIMx->SMCR = tmpsmcr;
  15895. /* Write to TIMx CCMR1 */
  15896. TIMx->CCMR1 = tmpccmr1;
  15897. /* Write to TIMx CCER */
  15898. TIMx->CCER = tmpccer;
  15899. }
  15900. /**
  15901. * @brief Forces the TIMx output 1 waveform to active or inactive level.
  15902. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.
  15903. * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
  15904. * This parameter can be one of the following values:
  15905. * @arg TIM_ForcedAction_Active: Force active level on OC1REF
  15906. * @arg TIM_ForcedAction_InActive: Force inactive level on OC1REF.
  15907. * @retval None
  15908. */
  15909. void TIM_ForcedOC1Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction)
  15910. {
  15911. uint16_t tmpccmr1 = 0;
  15912. /* Check the parameters */
  15913. assert_param(IS_TIM_LIST8_PERIPH(TIMx));
  15914. assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
  15915. tmpccmr1 = TIMx->CCMR1;
  15916. /* Reset the OC1M Bits */
  15917. tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC1M);
  15918. /* Configure The Forced output Mode */
  15919. tmpccmr1 |= TIM_ForcedAction;
  15920. /* Write to TIMx CCMR1 register */
  15921. TIMx->CCMR1 = tmpccmr1;
  15922. }
  15923. /**
  15924. * @brief Forces the TIMx output 2 waveform to active or inactive level.
  15925. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.
  15926. * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
  15927. * This parameter can be one of the following values:
  15928. * @arg TIM_ForcedAction_Active: Force active level on OC2REF
  15929. * @arg TIM_ForcedAction_InActive: Force inactive level on OC2REF.
  15930. * @retval None
  15931. */
  15932. void TIM_ForcedOC2Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction)
  15933. {
  15934. uint16_t tmpccmr1 = 0;
  15935. /* Check the parameters */
  15936. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  15937. assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
  15938. tmpccmr1 = TIMx->CCMR1;
  15939. /* Reset the OC2M Bits */
  15940. tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC2M);
  15941. /* Configure The Forced output Mode */
  15942. tmpccmr1 |= (uint16_t)(TIM_ForcedAction << 8);
  15943. /* Write to TIMx CCMR1 register */
  15944. TIMx->CCMR1 = tmpccmr1;
  15945. }
  15946. /**
  15947. * @brief Forces the TIMx output 3 waveform to active or inactive level.
  15948. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  15949. * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
  15950. * This parameter can be one of the following values:
  15951. * @arg TIM_ForcedAction_Active: Force active level on OC3REF
  15952. * @arg TIM_ForcedAction_InActive: Force inactive level on OC3REF.
  15953. * @retval None
  15954. */
  15955. void TIM_ForcedOC3Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction)
  15956. {
  15957. uint16_t tmpccmr2 = 0;
  15958. /* Check the parameters */
  15959. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  15960. assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
  15961. tmpccmr2 = TIMx->CCMR2;
  15962. /* Reset the OC1M Bits */
  15963. tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC3M);
  15964. /* Configure The Forced output Mode */
  15965. tmpccmr2 |= TIM_ForcedAction;
  15966. /* Write to TIMx CCMR2 register */
  15967. TIMx->CCMR2 = tmpccmr2;
  15968. }
  15969. /**
  15970. * @brief Forces the TIMx output 4 waveform to active or inactive level.
  15971. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  15972. * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
  15973. * This parameter can be one of the following values:
  15974. * @arg TIM_ForcedAction_Active: Force active level on OC4REF
  15975. * @arg TIM_ForcedAction_InActive: Force inactive level on OC4REF.
  15976. * @retval None
  15977. */
  15978. void TIM_ForcedOC4Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction)
  15979. {
  15980. uint16_t tmpccmr2 = 0;
  15981. /* Check the parameters */
  15982. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  15983. assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
  15984. tmpccmr2 = TIMx->CCMR2;
  15985. /* Reset the OC2M Bits */
  15986. tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC4M);
  15987. /* Configure The Forced output Mode */
  15988. tmpccmr2 |= (uint16_t)(TIM_ForcedAction << 8);
  15989. /* Write to TIMx CCMR2 register */
  15990. TIMx->CCMR2 = tmpccmr2;
  15991. }
  15992. /**
  15993. * @brief Enables or disables TIMx peripheral Preload register on ARR.
  15994. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  15995. * @param NewState: new state of the TIMx peripheral Preload register
  15996. * This parameter can be: ENABLE or DISABLE.
  15997. * @retval None
  15998. */
  15999. void TIM_ARRPreloadConfig(TIM_TypeDef* TIMx, FunctionalState NewState)
  16000. {
  16001. /* Check the parameters */
  16002. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  16003. assert_param(IS_FUNCTIONAL_STATE(NewState));
  16004. if (NewState != DISABLE)
  16005. {
  16006. /* Set the ARR Preload Bit */
  16007. TIMx->CR1 |= TIM_CR1_ARPE;
  16008. }
  16009. else
  16010. {
  16011. /* Reset the ARR Preload Bit */
  16012. TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_ARPE);
  16013. }
  16014. }
  16015. /**
  16016. * @brief Selects the TIM peripheral Commutation event.
  16017. * @param TIMx: where x can be 1, 8, 15, 16 or 17 to select the TIMx peripheral
  16018. * @param NewState: new state of the Commutation event.
  16019. * This parameter can be: ENABLE or DISABLE.
  16020. * @retval None
  16021. */
  16022. void TIM_SelectCOM(TIM_TypeDef* TIMx, FunctionalState NewState)
  16023. {
  16024. /* Check the parameters */
  16025. assert_param(IS_TIM_LIST2_PERIPH(TIMx));
  16026. assert_param(IS_FUNCTIONAL_STATE(NewState));
  16027. if (NewState != DISABLE)
  16028. {
  16029. /* Set the COM Bit */
  16030. TIMx->CR2 |= TIM_CR2_CCUS;
  16031. }
  16032. else
  16033. {
  16034. /* Reset the COM Bit */
  16035. TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_CCUS);
  16036. }
  16037. }
  16038. /**
  16039. * @brief Selects the TIMx peripheral Capture Compare DMA source.
  16040. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 15, 16 or 17 to select
  16041. * the TIM peripheral.
  16042. * @param NewState: new state of the Capture Compare DMA source
  16043. * This parameter can be: ENABLE or DISABLE.
  16044. * @retval None
  16045. */
  16046. void TIM_SelectCCDMA(TIM_TypeDef* TIMx, FunctionalState NewState)
  16047. {
  16048. /* Check the parameters */
  16049. assert_param(IS_TIM_LIST4_PERIPH(TIMx));
  16050. assert_param(IS_FUNCTIONAL_STATE(NewState));
  16051. if (NewState != DISABLE)
  16052. {
  16053. /* Set the CCDS Bit */
  16054. TIMx->CR2 |= TIM_CR2_CCDS;
  16055. }
  16056. else
  16057. {
  16058. /* Reset the CCDS Bit */
  16059. TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_CCDS);
  16060. }
  16061. }
  16062. /**
  16063. * @brief Sets or Resets the TIM peripheral Capture Compare Preload Control bit.
  16064. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8 or 15
  16065. * to select the TIMx peripheral
  16066. * @param NewState: new state of the Capture Compare Preload Control bit
  16067. * This parameter can be: ENABLE or DISABLE.
  16068. * @retval None
  16069. */
  16070. void TIM_CCPreloadControl(TIM_TypeDef* TIMx, FunctionalState NewState)
  16071. {
  16072. /* Check the parameters */
  16073. assert_param(IS_TIM_LIST5_PERIPH(TIMx));
  16074. assert_param(IS_FUNCTIONAL_STATE(NewState));
  16075. if (NewState != DISABLE)
  16076. {
  16077. /* Set the CCPC Bit */
  16078. TIMx->CR2 |= TIM_CR2_CCPC;
  16079. }
  16080. else
  16081. {
  16082. /* Reset the CCPC Bit */
  16083. TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_CCPC);
  16084. }
  16085. }
  16086. /**
  16087. * @brief Enables or disables the TIMx peripheral Preload register on CCR1.
  16088. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.
  16089. * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
  16090. * This parameter can be one of the following values:
  16091. * @arg TIM_OCPreload_Enable
  16092. * @arg TIM_OCPreload_Disable
  16093. * @retval None
  16094. */
  16095. void TIM_OC1PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload)
  16096. {
  16097. uint16_t tmpccmr1 = 0;
  16098. /* Check the parameters */
  16099. assert_param(IS_TIM_LIST8_PERIPH(TIMx));
  16100. assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
  16101. tmpccmr1 = TIMx->CCMR1;
  16102. /* Reset the OC1PE Bit */
  16103. tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC1PE);
  16104. /* Enable or Disable the Output Compare Preload feature */
  16105. tmpccmr1 |= TIM_OCPreload;
  16106. /* Write to TIMx CCMR1 register */
  16107. TIMx->CCMR1 = tmpccmr1;
  16108. }
  16109. /**
  16110. * @brief Enables or disables the TIMx peripheral Preload register on CCR2.
  16111. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select
  16112. * the TIM peripheral.
  16113. * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
  16114. * This parameter can be one of the following values:
  16115. * @arg TIM_OCPreload_Enable
  16116. * @arg TIM_OCPreload_Disable
  16117. * @retval None
  16118. */
  16119. void TIM_OC2PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload)
  16120. {
  16121. uint16_t tmpccmr1 = 0;
  16122. /* Check the parameters */
  16123. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  16124. assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
  16125. tmpccmr1 = TIMx->CCMR1;
  16126. /* Reset the OC2PE Bit */
  16127. tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC2PE);
  16128. /* Enable or Disable the Output Compare Preload feature */
  16129. tmpccmr1 |= (uint16_t)(TIM_OCPreload << 8);
  16130. /* Write to TIMx CCMR1 register */
  16131. TIMx->CCMR1 = tmpccmr1;
  16132. }
  16133. /**
  16134. * @brief Enables or disables the TIMx peripheral Preload register on CCR3.
  16135. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16136. * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
  16137. * This parameter can be one of the following values:
  16138. * @arg TIM_OCPreload_Enable
  16139. * @arg TIM_OCPreload_Disable
  16140. * @retval None
  16141. */
  16142. void TIM_OC3PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload)
  16143. {
  16144. uint16_t tmpccmr2 = 0;
  16145. /* Check the parameters */
  16146. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16147. assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
  16148. tmpccmr2 = TIMx->CCMR2;
  16149. /* Reset the OC3PE Bit */
  16150. tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC3PE);
  16151. /* Enable or Disable the Output Compare Preload feature */
  16152. tmpccmr2 |= TIM_OCPreload;
  16153. /* Write to TIMx CCMR2 register */
  16154. TIMx->CCMR2 = tmpccmr2;
  16155. }
  16156. /**
  16157. * @brief Enables or disables the TIMx peripheral Preload register on CCR4.
  16158. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16159. * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
  16160. * This parameter can be one of the following values:
  16161. * @arg TIM_OCPreload_Enable
  16162. * @arg TIM_OCPreload_Disable
  16163. * @retval None
  16164. */
  16165. void TIM_OC4PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload)
  16166. {
  16167. uint16_t tmpccmr2 = 0;
  16168. /* Check the parameters */
  16169. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16170. assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
  16171. tmpccmr2 = TIMx->CCMR2;
  16172. /* Reset the OC4PE Bit */
  16173. tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC4PE);
  16174. /* Enable or Disable the Output Compare Preload feature */
  16175. tmpccmr2 |= (uint16_t)(TIM_OCPreload << 8);
  16176. /* Write to TIMx CCMR2 register */
  16177. TIMx->CCMR2 = tmpccmr2;
  16178. }
  16179. /**
  16180. * @brief Configures the TIMx Output Compare 1 Fast feature.
  16181. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.
  16182. * @param TIM_OCFast: new state of the Output Compare Fast Enable Bit.
  16183. * This parameter can be one of the following values:
  16184. * @arg TIM_OCFast_Enable: TIM output compare fast enable
  16185. * @arg TIM_OCFast_Disable: TIM output compare fast disable
  16186. * @retval None
  16187. */
  16188. void TIM_OC1FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast)
  16189. {
  16190. uint16_t tmpccmr1 = 0;
  16191. /* Check the parameters */
  16192. assert_param(IS_TIM_LIST8_PERIPH(TIMx));
  16193. assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast));
  16194. /* Get the TIMx CCMR1 register value */
  16195. tmpccmr1 = TIMx->CCMR1;
  16196. /* Reset the OC1FE Bit */
  16197. tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC1FE);
  16198. /* Enable or Disable the Output Compare Fast Bit */
  16199. tmpccmr1 |= TIM_OCFast;
  16200. /* Write to TIMx CCMR1 */
  16201. TIMx->CCMR1 = tmpccmr1;
  16202. }
  16203. /**
  16204. * @brief Configures the TIMx Output Compare 2 Fast feature.
  16205. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select
  16206. * the TIM peripheral.
  16207. * @param TIM_OCFast: new state of the Output Compare Fast Enable Bit.
  16208. * This parameter can be one of the following values:
  16209. * @arg TIM_OCFast_Enable: TIM output compare fast enable
  16210. * @arg TIM_OCFast_Disable: TIM output compare fast disable
  16211. * @retval None
  16212. */
  16213. void TIM_OC2FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast)
  16214. {
  16215. uint16_t tmpccmr1 = 0;
  16216. /* Check the parameters */
  16217. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  16218. assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast));
  16219. /* Get the TIMx CCMR1 register value */
  16220. tmpccmr1 = TIMx->CCMR1;
  16221. /* Reset the OC2FE Bit */
  16222. tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC2FE);
  16223. /* Enable or Disable the Output Compare Fast Bit */
  16224. tmpccmr1 |= (uint16_t)(TIM_OCFast << 8);
  16225. /* Write to TIMx CCMR1 */
  16226. TIMx->CCMR1 = tmpccmr1;
  16227. }
  16228. /**
  16229. * @brief Configures the TIMx Output Compare 3 Fast feature.
  16230. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16231. * @param TIM_OCFast: new state of the Output Compare Fast Enable Bit.
  16232. * This parameter can be one of the following values:
  16233. * @arg TIM_OCFast_Enable: TIM output compare fast enable
  16234. * @arg TIM_OCFast_Disable: TIM output compare fast disable
  16235. * @retval None
  16236. */
  16237. void TIM_OC3FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast)
  16238. {
  16239. uint16_t tmpccmr2 = 0;
  16240. /* Check the parameters */
  16241. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16242. assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast));
  16243. /* Get the TIMx CCMR2 register value */
  16244. tmpccmr2 = TIMx->CCMR2;
  16245. /* Reset the OC3FE Bit */
  16246. tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC3FE);
  16247. /* Enable or Disable the Output Compare Fast Bit */
  16248. tmpccmr2 |= TIM_OCFast;
  16249. /* Write to TIMx CCMR2 */
  16250. TIMx->CCMR2 = tmpccmr2;
  16251. }
  16252. /**
  16253. * @brief Configures the TIMx Output Compare 4 Fast feature.
  16254. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16255. * @param TIM_OCFast: new state of the Output Compare Fast Enable Bit.
  16256. * This parameter can be one of the following values:
  16257. * @arg TIM_OCFast_Enable: TIM output compare fast enable
  16258. * @arg TIM_OCFast_Disable: TIM output compare fast disable
  16259. * @retval None
  16260. */
  16261. void TIM_OC4FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast)
  16262. {
  16263. uint16_t tmpccmr2 = 0;
  16264. /* Check the parameters */
  16265. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16266. assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast));
  16267. /* Get the TIMx CCMR2 register value */
  16268. tmpccmr2 = TIMx->CCMR2;
  16269. /* Reset the OC4FE Bit */
  16270. tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC4FE);
  16271. /* Enable or Disable the Output Compare Fast Bit */
  16272. tmpccmr2 |= (uint16_t)(TIM_OCFast << 8);
  16273. /* Write to TIMx CCMR2 */
  16274. TIMx->CCMR2 = tmpccmr2;
  16275. }
  16276. /**
  16277. * @brief Clears or safeguards the OCREF1 signal on an external event
  16278. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16279. * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
  16280. * This parameter can be one of the following values:
  16281. * @arg TIM_OCClear_Enable: TIM Output clear enable
  16282. * @arg TIM_OCClear_Disable: TIM Output clear disable
  16283. * @retval None
  16284. */
  16285. void TIM_ClearOC1Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear)
  16286. {
  16287. uint16_t tmpccmr1 = 0;
  16288. /* Check the parameters */
  16289. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16290. assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));
  16291. tmpccmr1 = TIMx->CCMR1;
  16292. /* Reset the OC1CE Bit */
  16293. tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC1CE);
  16294. /* Enable or Disable the Output Compare Clear Bit */
  16295. tmpccmr1 |= TIM_OCClear;
  16296. /* Write to TIMx CCMR1 register */
  16297. TIMx->CCMR1 = tmpccmr1;
  16298. }
  16299. /**
  16300. * @brief Clears or safeguards the OCREF2 signal on an external event
  16301. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16302. * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
  16303. * This parameter can be one of the following values:
  16304. * @arg TIM_OCClear_Enable: TIM Output clear enable
  16305. * @arg TIM_OCClear_Disable: TIM Output clear disable
  16306. * @retval None
  16307. */
  16308. void TIM_ClearOC2Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear)
  16309. {
  16310. uint16_t tmpccmr1 = 0;
  16311. /* Check the parameters */
  16312. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16313. assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));
  16314. tmpccmr1 = TIMx->CCMR1;
  16315. /* Reset the OC2CE Bit */
  16316. tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC2CE);
  16317. /* Enable or Disable the Output Compare Clear Bit */
  16318. tmpccmr1 |= (uint16_t)(TIM_OCClear << 8);
  16319. /* Write to TIMx CCMR1 register */
  16320. TIMx->CCMR1 = tmpccmr1;
  16321. }
  16322. /**
  16323. * @brief Clears or safeguards the OCREF3 signal on an external event
  16324. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16325. * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
  16326. * This parameter can be one of the following values:
  16327. * @arg TIM_OCClear_Enable: TIM Output clear enable
  16328. * @arg TIM_OCClear_Disable: TIM Output clear disable
  16329. * @retval None
  16330. */
  16331. void TIM_ClearOC3Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear)
  16332. {
  16333. uint16_t tmpccmr2 = 0;
  16334. /* Check the parameters */
  16335. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16336. assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));
  16337. tmpccmr2 = TIMx->CCMR2;
  16338. /* Reset the OC3CE Bit */
  16339. tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC3CE);
  16340. /* Enable or Disable the Output Compare Clear Bit */
  16341. tmpccmr2 |= TIM_OCClear;
  16342. /* Write to TIMx CCMR2 register */
  16343. TIMx->CCMR2 = tmpccmr2;
  16344. }
  16345. /**
  16346. * @brief Clears or safeguards the OCREF4 signal on an external event
  16347. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16348. * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
  16349. * This parameter can be one of the following values:
  16350. * @arg TIM_OCClear_Enable: TIM Output clear enable
  16351. * @arg TIM_OCClear_Disable: TIM Output clear disable
  16352. * @retval None
  16353. */
  16354. void TIM_ClearOC4Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear)
  16355. {
  16356. uint16_t tmpccmr2 = 0;
  16357. /* Check the parameters */
  16358. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16359. assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));
  16360. tmpccmr2 = TIMx->CCMR2;
  16361. /* Reset the OC4CE Bit */
  16362. tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC4CE);
  16363. /* Enable or Disable the Output Compare Clear Bit */
  16364. tmpccmr2 |= (uint16_t)(TIM_OCClear << 8);
  16365. /* Write to TIMx CCMR2 register */
  16366. TIMx->CCMR2 = tmpccmr2;
  16367. }
  16368. /**
  16369. * @brief Configures the TIMx channel 1 polarity.
  16370. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.
  16371. * @param TIM_OCPolarity: specifies the OC1 Polarity
  16372. * This parameter can be one of the following values:
  16373. * @arg TIM_OCPolarity_High: Output Compare active high
  16374. * @arg TIM_OCPolarity_Low: Output Compare active low
  16375. * @retval None
  16376. */
  16377. void TIM_OC1PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity)
  16378. {
  16379. uint16_t tmpccer = 0;
  16380. /* Check the parameters */
  16381. assert_param(IS_TIM_LIST8_PERIPH(TIMx));
  16382. assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));
  16383. tmpccer = TIMx->CCER;
  16384. /* Set or Reset the CC1P Bit */
  16385. tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC1P);
  16386. tmpccer |= TIM_OCPolarity;
  16387. /* Write to TIMx CCER register */
  16388. TIMx->CCER = tmpccer;
  16389. }
  16390. /**
  16391. * @brief Configures the TIMx Channel 1N polarity.
  16392. * @param TIMx: where x can be 1, 8, 15, 16 or 17 to select the TIM peripheral.
  16393. * @param TIM_OCNPolarity: specifies the OC1N Polarity
  16394. * This parameter can be one of the following values:
  16395. * @arg TIM_OCNPolarity_High: Output Compare active high
  16396. * @arg TIM_OCNPolarity_Low: Output Compare active low
  16397. * @retval None
  16398. */
  16399. void TIM_OC1NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity)
  16400. {
  16401. uint16_t tmpccer = 0;
  16402. /* Check the parameters */
  16403. assert_param(IS_TIM_LIST2_PERIPH(TIMx));
  16404. assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity));
  16405. tmpccer = TIMx->CCER;
  16406. /* Set or Reset the CC1NP Bit */
  16407. tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC1NP);
  16408. tmpccer |= TIM_OCNPolarity;
  16409. /* Write to TIMx CCER register */
  16410. TIMx->CCER = tmpccer;
  16411. }
  16412. /**
  16413. * @brief Configures the TIMx channel 2 polarity.
  16414. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.
  16415. * @param TIM_OCPolarity: specifies the OC2 Polarity
  16416. * This parameter can be one of the following values:
  16417. * @arg TIM_OCPolarity_High: Output Compare active high
  16418. * @arg TIM_OCPolarity_Low: Output Compare active low
  16419. * @retval None
  16420. */
  16421. void TIM_OC2PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity)
  16422. {
  16423. uint16_t tmpccer = 0;
  16424. /* Check the parameters */
  16425. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  16426. assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));
  16427. tmpccer = TIMx->CCER;
  16428. /* Set or Reset the CC2P Bit */
  16429. tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC2P);
  16430. tmpccer |= (uint16_t)(TIM_OCPolarity << 4);
  16431. /* Write to TIMx CCER register */
  16432. TIMx->CCER = tmpccer;
  16433. }
  16434. /**
  16435. * @brief Configures the TIMx Channel 2N polarity.
  16436. * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
  16437. * @param TIM_OCNPolarity: specifies the OC2N Polarity
  16438. * This parameter can be one of the following values:
  16439. * @arg TIM_OCNPolarity_High: Output Compare active high
  16440. * @arg TIM_OCNPolarity_Low: Output Compare active low
  16441. * @retval None
  16442. */
  16443. void TIM_OC2NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity)
  16444. {
  16445. uint16_t tmpccer = 0;
  16446. /* Check the parameters */
  16447. assert_param(IS_TIM_LIST1_PERIPH(TIMx));
  16448. assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity));
  16449. tmpccer = TIMx->CCER;
  16450. /* Set or Reset the CC2NP Bit */
  16451. tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC2NP);
  16452. tmpccer |= (uint16_t)(TIM_OCNPolarity << 4);
  16453. /* Write to TIMx CCER register */
  16454. TIMx->CCER = tmpccer;
  16455. }
  16456. /**
  16457. * @brief Configures the TIMx channel 3 polarity.
  16458. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16459. * @param TIM_OCPolarity: specifies the OC3 Polarity
  16460. * This parameter can be one of the following values:
  16461. * @arg TIM_OCPolarity_High: Output Compare active high
  16462. * @arg TIM_OCPolarity_Low: Output Compare active low
  16463. * @retval None
  16464. */
  16465. void TIM_OC3PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity)
  16466. {
  16467. uint16_t tmpccer = 0;
  16468. /* Check the parameters */
  16469. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16470. assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));
  16471. tmpccer = TIMx->CCER;
  16472. /* Set or Reset the CC3P Bit */
  16473. tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC3P);
  16474. tmpccer |= (uint16_t)(TIM_OCPolarity << 8);
  16475. /* Write to TIMx CCER register */
  16476. TIMx->CCER = tmpccer;
  16477. }
  16478. /**
  16479. * @brief Configures the TIMx Channel 3N polarity.
  16480. * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
  16481. * @param TIM_OCNPolarity: specifies the OC3N Polarity
  16482. * This parameter can be one of the following values:
  16483. * @arg TIM_OCNPolarity_High: Output Compare active high
  16484. * @arg TIM_OCNPolarity_Low: Output Compare active low
  16485. * @retval None
  16486. */
  16487. void TIM_OC3NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity)
  16488. {
  16489. uint16_t tmpccer = 0;
  16490. /* Check the parameters */
  16491. assert_param(IS_TIM_LIST1_PERIPH(TIMx));
  16492. assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity));
  16493. tmpccer = TIMx->CCER;
  16494. /* Set or Reset the CC3NP Bit */
  16495. tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC3NP);
  16496. tmpccer |= (uint16_t)(TIM_OCNPolarity << 8);
  16497. /* Write to TIMx CCER register */
  16498. TIMx->CCER = tmpccer;
  16499. }
  16500. /**
  16501. * @brief Configures the TIMx channel 4 polarity.
  16502. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16503. * @param TIM_OCPolarity: specifies the OC4 Polarity
  16504. * This parameter can be one of the following values:
  16505. * @arg TIM_OCPolarity_High: Output Compare active high
  16506. * @arg TIM_OCPolarity_Low: Output Compare active low
  16507. * @retval None
  16508. */
  16509. void TIM_OC4PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity)
  16510. {
  16511. uint16_t tmpccer = 0;
  16512. /* Check the parameters */
  16513. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16514. assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));
  16515. tmpccer = TIMx->CCER;
  16516. /* Set or Reset the CC4P Bit */
  16517. tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC4P);
  16518. tmpccer |= (uint16_t)(TIM_OCPolarity << 12);
  16519. /* Write to TIMx CCER register */
  16520. TIMx->CCER = tmpccer;
  16521. }
  16522. /**
  16523. * @brief Enables or disables the TIM Capture Compare Channel x.
  16524. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.
  16525. * @param TIM_Channel: specifies the TIM Channel
  16526. * This parameter can be one of the following values:
  16527. * @arg TIM_Channel_1: TIM Channel 1
  16528. * @arg TIM_Channel_2: TIM Channel 2
  16529. * @arg TIM_Channel_3: TIM Channel 3
  16530. * @arg TIM_Channel_4: TIM Channel 4
  16531. * @param TIM_CCx: specifies the TIM Channel CCxE bit new state.
  16532. * This parameter can be: TIM_CCx_Enable or TIM_CCx_Disable.
  16533. * @retval None
  16534. */
  16535. void TIM_CCxCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCx)
  16536. {
  16537. uint16_t tmp = 0;
  16538. /* Check the parameters */
  16539. assert_param(IS_TIM_LIST8_PERIPH(TIMx));
  16540. assert_param(IS_TIM_CHANNEL(TIM_Channel));
  16541. assert_param(IS_TIM_CCX(TIM_CCx));
  16542. tmp = CCER_CCE_Set << TIM_Channel;
  16543. /* Reset the CCxE Bit */
  16544. TIMx->CCER &= (uint16_t)~ tmp;
  16545. /* Set or reset the CCxE Bit */
  16546. TIMx->CCER |= (uint16_t)(TIM_CCx << TIM_Channel);
  16547. }
  16548. /**
  16549. * @brief Enables or disables the TIM Capture Compare Channel xN.
  16550. * @param TIMx: where x can be 1, 8, 15, 16 or 17 to select the TIM peripheral.
  16551. * @param TIM_Channel: specifies the TIM Channel
  16552. * This parameter can be one of the following values:
  16553. * @arg TIM_Channel_1: TIM Channel 1
  16554. * @arg TIM_Channel_2: TIM Channel 2
  16555. * @arg TIM_Channel_3: TIM Channel 3
  16556. * @param TIM_CCxN: specifies the TIM Channel CCxNE bit new state.
  16557. * This parameter can be: TIM_CCxN_Enable or TIM_CCxN_Disable.
  16558. * @retval None
  16559. */
  16560. void TIM_CCxNCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCxN)
  16561. {
  16562. uint16_t tmp = 0;
  16563. /* Check the parameters */
  16564. assert_param(IS_TIM_LIST2_PERIPH(TIMx));
  16565. assert_param(IS_TIM_COMPLEMENTARY_CHANNEL(TIM_Channel));
  16566. assert_param(IS_TIM_CCXN(TIM_CCxN));
  16567. tmp = CCER_CCNE_Set << TIM_Channel;
  16568. /* Reset the CCxNE Bit */
  16569. TIMx->CCER &= (uint16_t) ~tmp;
  16570. /* Set or reset the CCxNE Bit */
  16571. TIMx->CCER |= (uint16_t)(TIM_CCxN << TIM_Channel);
  16572. }
  16573. /**
  16574. * @brief Selects the TIM Output Compare Mode.
  16575. * @note This function disables the selected channel before changing the Output
  16576. * Compare Mode.
  16577. * User has to enable this channel using TIM_CCxCmd and TIM_CCxNCmd functions.
  16578. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.
  16579. * @param TIM_Channel: specifies the TIM Channel
  16580. * This parameter can be one of the following values:
  16581. * @arg TIM_Channel_1: TIM Channel 1
  16582. * @arg TIM_Channel_2: TIM Channel 2
  16583. * @arg TIM_Channel_3: TIM Channel 3
  16584. * @arg TIM_Channel_4: TIM Channel 4
  16585. * @param TIM_OCMode: specifies the TIM Output Compare Mode.
  16586. * This parameter can be one of the following values:
  16587. * @arg TIM_OCMode_Timing
  16588. * @arg TIM_OCMode_Active
  16589. * @arg TIM_OCMode_Toggle
  16590. * @arg TIM_OCMode_PWM1
  16591. * @arg TIM_OCMode_PWM2
  16592. * @arg TIM_ForcedAction_Active
  16593. * @arg TIM_ForcedAction_InActive
  16594. * @retval None
  16595. */
  16596. void TIM_SelectOCxM(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_OCMode)
  16597. {
  16598. uint32_t tmp = 0;
  16599. uint16_t tmp1 = 0;
  16600. /* Check the parameters */
  16601. assert_param(IS_TIM_LIST8_PERIPH(TIMx));
  16602. assert_param(IS_TIM_CHANNEL(TIM_Channel));
  16603. assert_param(IS_TIM_OCM(TIM_OCMode));
  16604. tmp = (uint32_t) TIMx;
  16605. tmp += CCMR_Offset;
  16606. tmp1 = CCER_CCE_Set << (uint16_t)TIM_Channel;
  16607. /* Disable the Channel: Reset the CCxE Bit */
  16608. TIMx->CCER &= (uint16_t) ~tmp1;
  16609. if((TIM_Channel == TIM_Channel_1) ||(TIM_Channel == TIM_Channel_3))
  16610. {
  16611. tmp += (TIM_Channel>>1);
  16612. /* Reset the OCxM bits in the CCMRx register */
  16613. *(__IO uint32_t *) tmp &= (uint32_t)~((uint32_t)TIM_CCMR1_OC1M);
  16614. /* Configure the OCxM bits in the CCMRx register */
  16615. *(__IO uint32_t *) tmp |= TIM_OCMode;
  16616. }
  16617. else
  16618. {
  16619. tmp += (uint16_t)(TIM_Channel - (uint16_t)4)>> (uint16_t)1;
  16620. /* Reset the OCxM bits in the CCMRx register */
  16621. *(__IO uint32_t *) tmp &= (uint32_t)~((uint32_t)TIM_CCMR1_OC2M);
  16622. /* Configure the OCxM bits in the CCMRx register */
  16623. *(__IO uint32_t *) tmp |= (uint16_t)(TIM_OCMode << 8);
  16624. }
  16625. }
  16626. /**
  16627. * @brief Enables or Disables the TIMx Update event.
  16628. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  16629. * @param NewState: new state of the TIMx UDIS bit
  16630. * This parameter can be: ENABLE or DISABLE.
  16631. * @retval None
  16632. */
  16633. void TIM_UpdateDisableConfig(TIM_TypeDef* TIMx, FunctionalState NewState)
  16634. {
  16635. /* Check the parameters */
  16636. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  16637. assert_param(IS_FUNCTIONAL_STATE(NewState));
  16638. if (NewState != DISABLE)
  16639. {
  16640. /* Set the Update Disable Bit */
  16641. TIMx->CR1 |= TIM_CR1_UDIS;
  16642. }
  16643. else
  16644. {
  16645. /* Reset the Update Disable Bit */
  16646. TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_UDIS);
  16647. }
  16648. }
  16649. /**
  16650. * @brief Configures the TIMx Update Request Interrupt source.
  16651. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  16652. * @param TIM_UpdateSource: specifies the Update source.
  16653. * This parameter can be one of the following values:
  16654. * @arg TIM_UpdateSource_Regular: Source of update is the counter overflow/underflow
  16655. or the setting of UG bit, or an update generation
  16656. through the slave mode controller.
  16657. * @arg TIM_UpdateSource_Global: Source of update is counter overflow/underflow.
  16658. * @retval None
  16659. */
  16660. void TIM_UpdateRequestConfig(TIM_TypeDef* TIMx, uint16_t TIM_UpdateSource)
  16661. {
  16662. /* Check the parameters */
  16663. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  16664. assert_param(IS_TIM_UPDATE_SOURCE(TIM_UpdateSource));
  16665. if (TIM_UpdateSource != TIM_UpdateSource_Global)
  16666. {
  16667. /* Set the URS Bit */
  16668. TIMx->CR1 |= TIM_CR1_URS;
  16669. }
  16670. else
  16671. {
  16672. /* Reset the URS Bit */
  16673. TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_URS);
  16674. }
  16675. }
  16676. /**
  16677. * @brief Enables or disables the TIMx's Hall sensor interface.
  16678. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16679. * @param NewState: new state of the TIMx Hall sensor interface.
  16680. * This parameter can be: ENABLE or DISABLE.
  16681. * @retval None
  16682. */
  16683. void TIM_SelectHallSensor(TIM_TypeDef* TIMx, FunctionalState NewState)
  16684. {
  16685. /* Check the parameters */
  16686. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  16687. assert_param(IS_FUNCTIONAL_STATE(NewState));
  16688. if (NewState != DISABLE)
  16689. {
  16690. /* Set the TI1S Bit */
  16691. TIMx->CR2 |= TIM_CR2_TI1S;
  16692. }
  16693. else
  16694. {
  16695. /* Reset the TI1S Bit */
  16696. TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_TI1S);
  16697. }
  16698. }
  16699. /**
  16700. * @brief Selects the TIMx's One Pulse Mode.
  16701. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  16702. * @param TIM_OPMode: specifies the OPM Mode to be used.
  16703. * This parameter can be one of the following values:
  16704. * @arg TIM_OPMode_Single
  16705. * @arg TIM_OPMode_Repetitive
  16706. * @retval None
  16707. */
  16708. void TIM_SelectOnePulseMode(TIM_TypeDef* TIMx, uint16_t TIM_OPMode)
  16709. {
  16710. /* Check the parameters */
  16711. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  16712. assert_param(IS_TIM_OPM_MODE(TIM_OPMode));
  16713. /* Reset the OPM Bit */
  16714. TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_OPM);
  16715. /* Configure the OPM Mode */
  16716. TIMx->CR1 |= TIM_OPMode;
  16717. }
  16718. /**
  16719. * @brief Selects the TIMx Trigger Output Mode.
  16720. * @param TIMx: where x can be 1, 2, 3, 4, 5, 6, 7, 8, 9, 12 or 15 to select the TIM peripheral.
  16721. * @param TIM_TRGOSource: specifies the Trigger Output source.
  16722. * This paramter can be one of the following values:
  16723. *
  16724. * - For all TIMx
  16725. * @arg TIM_TRGOSource_Reset: The UG bit in the TIM_EGR register is used as the trigger output (TRGO).
  16726. * @arg TIM_TRGOSource_Enable: The Counter Enable CEN is used as the trigger output (TRGO).
  16727. * @arg TIM_TRGOSource_Update: The update event is selected as the trigger output (TRGO).
  16728. *
  16729. * - For all TIMx except TIM6 and TIM7
  16730. * @arg TIM_TRGOSource_OC1: The trigger output sends a positive pulse when the CC1IF flag
  16731. * is to be set, as soon as a capture or compare match occurs (TRGO).
  16732. * @arg TIM_TRGOSource_OC1Ref: OC1REF signal is used as the trigger output (TRGO).
  16733. * @arg TIM_TRGOSource_OC2Ref: OC2REF signal is used as the trigger output (TRGO).
  16734. * @arg TIM_TRGOSource_OC3Ref: OC3REF signal is used as the trigger output (TRGO).
  16735. * @arg TIM_TRGOSource_OC4Ref: OC4REF signal is used as the trigger output (TRGO).
  16736. *
  16737. * @retval None
  16738. */
  16739. void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_TRGOSource)
  16740. {
  16741. /* Check the parameters */
  16742. assert_param(IS_TIM_LIST7_PERIPH(TIMx));
  16743. assert_param(IS_TIM_TRGO_SOURCE(TIM_TRGOSource));
  16744. /* Reset the MMS Bits */
  16745. TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_MMS);
  16746. /* Select the TRGO source */
  16747. TIMx->CR2 |= TIM_TRGOSource;
  16748. }
  16749. /**
  16750. * @brief Selects the TIMx Slave Mode.
  16751. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.
  16752. * @param TIM_SlaveMode: specifies the Timer Slave Mode.
  16753. * This parameter can be one of the following values:
  16754. * @arg TIM_SlaveMode_Reset: Rising edge of the selected trigger signal (TRGI) re-initializes
  16755. * the counter and triggers an update of the registers.
  16756. * @arg TIM_SlaveMode_Gated: The counter clock is enabled when the trigger signal (TRGI) is high.
  16757. * @arg TIM_SlaveMode_Trigger: The counter starts at a rising edge of the trigger TRGI.
  16758. * @arg TIM_SlaveMode_External1: Rising edges of the selected trigger (TRGI) clock the counter.
  16759. * @retval None
  16760. */
  16761. void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_SlaveMode)
  16762. {
  16763. /* Check the parameters */
  16764. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  16765. assert_param(IS_TIM_SLAVE_MODE(TIM_SlaveMode));
  16766. /* Reset the SMS Bits */
  16767. TIMx->SMCR &= (uint16_t)~((uint16_t)TIM_SMCR_SMS);
  16768. /* Select the Slave Mode */
  16769. TIMx->SMCR |= TIM_SlaveMode;
  16770. }
  16771. /**
  16772. * @brief Sets or Resets the TIMx Master/Slave Mode.
  16773. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.
  16774. * @param TIM_MasterSlaveMode: specifies the Timer Master Slave Mode.
  16775. * This parameter can be one of the following values:
  16776. * @arg TIM_MasterSlaveMode_Enable: synchronization between the current timer
  16777. * and its slaves (through TRGO).
  16778. * @arg TIM_MasterSlaveMode_Disable: No action
  16779. * @retval None
  16780. */
  16781. void TIM_SelectMasterSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_MasterSlaveMode)
  16782. {
  16783. /* Check the parameters */
  16784. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  16785. assert_param(IS_TIM_MSM_STATE(TIM_MasterSlaveMode));
  16786. /* Reset the MSM Bit */
  16787. TIMx->SMCR &= (uint16_t)~((uint16_t)TIM_SMCR_MSM);
  16788. /* Set or Reset the MSM Bit */
  16789. TIMx->SMCR |= TIM_MasterSlaveMode;
  16790. }
  16791. /**
  16792. * @brief Sets the TIMx Counter Register value
  16793. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  16794. * @param Counter: specifies the Counter register new value.
  16795. * @retval None
  16796. */
  16797. void TIM_SetCounter(TIM_TypeDef* TIMx, uint16_t Counter)
  16798. {
  16799. /* Check the parameters */
  16800. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  16801. /* Set the Counter Register value */
  16802. TIMx->CNT = Counter;
  16803. }
  16804. /**
  16805. * @brief Sets the TIMx Autoreload Register value
  16806. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  16807. * @param Autoreload: specifies the Autoreload register new value.
  16808. * @retval None
  16809. */
  16810. void TIM_SetAutoreload(TIM_TypeDef* TIMx, uint16_t Autoreload)
  16811. {
  16812. /* Check the parameters */
  16813. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  16814. /* Set the Autoreload Register value */
  16815. TIMx->ARR = Autoreload;
  16816. }
  16817. /**
  16818. * @brief Sets the TIMx Capture Compare1 Register value
  16819. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.
  16820. * @param Compare1: specifies the Capture Compare1 register new value.
  16821. * @retval None
  16822. */
  16823. void TIM_SetCompare1(TIM_TypeDef* TIMx, uint16_t Compare1)
  16824. {
  16825. /* Check the parameters */
  16826. assert_param(IS_TIM_LIST8_PERIPH(TIMx));
  16827. /* Set the Capture Compare1 Register value */
  16828. TIMx->CCR1 = Compare1;
  16829. }
  16830. /**
  16831. * @brief Sets the TIMx Capture Compare2 Register value
  16832. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.
  16833. * @param Compare2: specifies the Capture Compare2 register new value.
  16834. * @retval None
  16835. */
  16836. void TIM_SetCompare2(TIM_TypeDef* TIMx, uint16_t Compare2)
  16837. {
  16838. /* Check the parameters */
  16839. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  16840. /* Set the Capture Compare2 Register value */
  16841. TIMx->CCR2 = Compare2;
  16842. }
  16843. /**
  16844. * @brief Sets the TIMx Capture Compare3 Register value
  16845. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16846. * @param Compare3: specifies the Capture Compare3 register new value.
  16847. * @retval None
  16848. */
  16849. void TIM_SetCompare3(TIM_TypeDef* TIMx, uint16_t Compare3)
  16850. {
  16851. /* Check the parameters */
  16852. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16853. /* Set the Capture Compare3 Register value */
  16854. TIMx->CCR3 = Compare3;
  16855. }
  16856. /**
  16857. * @brief Sets the TIMx Capture Compare4 Register value
  16858. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16859. * @param Compare4: specifies the Capture Compare4 register new value.
  16860. * @retval None
  16861. */
  16862. void TIM_SetCompare4(TIM_TypeDef* TIMx, uint16_t Compare4)
  16863. {
  16864. /* Check the parameters */
  16865. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16866. /* Set the Capture Compare4 Register value */
  16867. TIMx->CCR4 = Compare4;
  16868. }
  16869. /**
  16870. * @brief Sets the TIMx Input Capture 1 prescaler.
  16871. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.
  16872. * @param TIM_ICPSC: specifies the Input Capture1 prescaler new value.
  16873. * This parameter can be one of the following values:
  16874. * @arg TIM_ICPSC_DIV1: no prescaler
  16875. * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
  16876. * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
  16877. * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
  16878. * @retval None
  16879. */
  16880. void TIM_SetIC1Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC)
  16881. {
  16882. /* Check the parameters */
  16883. assert_param(IS_TIM_LIST8_PERIPH(TIMx));
  16884. assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC));
  16885. /* Reset the IC1PSC Bits */
  16886. TIMx->CCMR1 &= (uint16_t)~((uint16_t)TIM_CCMR1_IC1PSC);
  16887. /* Set the IC1PSC value */
  16888. TIMx->CCMR1 |= TIM_ICPSC;
  16889. }
  16890. /**
  16891. * @brief Sets the TIMx Input Capture 2 prescaler.
  16892. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.
  16893. * @param TIM_ICPSC: specifies the Input Capture2 prescaler new value.
  16894. * This parameter can be one of the following values:
  16895. * @arg TIM_ICPSC_DIV1: no prescaler
  16896. * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
  16897. * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
  16898. * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
  16899. * @retval None
  16900. */
  16901. void TIM_SetIC2Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC)
  16902. {
  16903. /* Check the parameters */
  16904. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  16905. assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC));
  16906. /* Reset the IC2PSC Bits */
  16907. TIMx->CCMR1 &= (uint16_t)~((uint16_t)TIM_CCMR1_IC2PSC);
  16908. /* Set the IC2PSC value */
  16909. TIMx->CCMR1 |= (uint16_t)(TIM_ICPSC << 8);
  16910. }
  16911. /**
  16912. * @brief Sets the TIMx Input Capture 3 prescaler.
  16913. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16914. * @param TIM_ICPSC: specifies the Input Capture3 prescaler new value.
  16915. * This parameter can be one of the following values:
  16916. * @arg TIM_ICPSC_DIV1: no prescaler
  16917. * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
  16918. * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
  16919. * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
  16920. * @retval None
  16921. */
  16922. void TIM_SetIC3Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC)
  16923. {
  16924. /* Check the parameters */
  16925. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16926. assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC));
  16927. /* Reset the IC3PSC Bits */
  16928. TIMx->CCMR2 &= (uint16_t)~((uint16_t)TIM_CCMR2_IC3PSC);
  16929. /* Set the IC3PSC value */
  16930. TIMx->CCMR2 |= TIM_ICPSC;
  16931. }
  16932. /**
  16933. * @brief Sets the TIMx Input Capture 4 prescaler.
  16934. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  16935. * @param TIM_ICPSC: specifies the Input Capture4 prescaler new value.
  16936. * This parameter can be one of the following values:
  16937. * @arg TIM_ICPSC_DIV1: no prescaler
  16938. * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
  16939. * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
  16940. * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
  16941. * @retval None
  16942. */
  16943. void TIM_SetIC4Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC)
  16944. {
  16945. /* Check the parameters */
  16946. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  16947. assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC));
  16948. /* Reset the IC4PSC Bits */
  16949. TIMx->CCMR2 &= (uint16_t)~((uint16_t)TIM_CCMR2_IC4PSC);
  16950. /* Set the IC4PSC value */
  16951. TIMx->CCMR2 |= (uint16_t)(TIM_ICPSC << 8);
  16952. }
  16953. /**
  16954. * @brief Sets the TIMx Clock Division value.
  16955. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select
  16956. * the TIM peripheral.
  16957. * @param TIM_CKD: specifies the clock division value.
  16958. * This parameter can be one of the following value:
  16959. * @arg TIM_CKD_DIV1: TDTS = Tck_tim
  16960. * @arg TIM_CKD_DIV2: TDTS = 2*Tck_tim
  16961. * @arg TIM_CKD_DIV4: TDTS = 4*Tck_tim
  16962. * @retval None
  16963. */
  16964. void TIM_SetClockDivision(TIM_TypeDef* TIMx, uint16_t TIM_CKD)
  16965. {
  16966. /* Check the parameters */
  16967. assert_param(IS_TIM_LIST8_PERIPH(TIMx));
  16968. assert_param(IS_TIM_CKD_DIV(TIM_CKD));
  16969. /* Reset the CKD Bits */
  16970. TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_CKD);
  16971. /* Set the CKD value */
  16972. TIMx->CR1 |= TIM_CKD;
  16973. }
  16974. /**
  16975. * @brief Gets the TIMx Input Capture 1 value.
  16976. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.
  16977. * @retval Capture Compare 1 Register value.
  16978. */
  16979. uint16_t TIM_GetCapture1(TIM_TypeDef* TIMx)
  16980. {
  16981. /* Check the parameters */
  16982. assert_param(IS_TIM_LIST8_PERIPH(TIMx));
  16983. /* Get the Capture 1 Register value */
  16984. return TIMx->CCR1;
  16985. }
  16986. /**
  16987. * @brief Gets the TIMx Input Capture 2 value.
  16988. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.
  16989. * @retval Capture Compare 2 Register value.
  16990. */
  16991. uint16_t TIM_GetCapture2(TIM_TypeDef* TIMx)
  16992. {
  16993. /* Check the parameters */
  16994. assert_param(IS_TIM_LIST6_PERIPH(TIMx));
  16995. /* Get the Capture 2 Register value */
  16996. return TIMx->CCR2;
  16997. }
  16998. /**
  16999. * @brief Gets the TIMx Input Capture 3 value.
  17000. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  17001. * @retval Capture Compare 3 Register value.
  17002. */
  17003. uint16_t TIM_GetCapture3(TIM_TypeDef* TIMx)
  17004. {
  17005. /* Check the parameters */
  17006. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  17007. /* Get the Capture 3 Register value */
  17008. return TIMx->CCR3;
  17009. }
  17010. /**
  17011. * @brief Gets the TIMx Input Capture 4 value.
  17012. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  17013. * @retval Capture Compare 4 Register value.
  17014. */
  17015. uint16_t TIM_GetCapture4(TIM_TypeDef* TIMx)
  17016. {
  17017. /* Check the parameters */
  17018. assert_param(IS_TIM_LIST3_PERIPH(TIMx));
  17019. /* Get the Capture 4 Register value */
  17020. return TIMx->CCR4;
  17021. }
  17022. /**
  17023. * @brief Gets the TIMx Counter value.
  17024. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  17025. * @retval Counter Register value.
  17026. */
  17027. uint16_t TIM_GetCounter(TIM_TypeDef* TIMx)
  17028. {
  17029. /* Check the parameters */
  17030. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  17031. /* Get the Counter Register value */
  17032. return TIMx->CNT;
  17033. }
  17034. /**
  17035. * @brief Gets the TIMx Prescaler value.
  17036. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  17037. * @retval Prescaler Register value.
  17038. */
  17039. uint16_t TIM_GetPrescaler(TIM_TypeDef* TIMx)
  17040. {
  17041. /* Check the parameters */
  17042. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  17043. /* Get the Prescaler Register value */
  17044. return TIMx->PSC;
  17045. }
  17046. /**
  17047. * @brief Checks whether the specified TIM flag is set or not.
  17048. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  17049. * @param TIM_FLAG: specifies the flag to check.
  17050. * This parameter can be one of the following values:
  17051. * @arg TIM_FLAG_Update: TIM update Flag
  17052. * @arg TIM_FLAG_CC1: TIM Capture Compare 1 Flag
  17053. * @arg TIM_FLAG_CC2: TIM Capture Compare 2 Flag
  17054. * @arg TIM_FLAG_CC3: TIM Capture Compare 3 Flag
  17055. * @arg TIM_FLAG_CC4: TIM Capture Compare 4 Flag
  17056. * @arg TIM_FLAG_COM: TIM Commutation Flag
  17057. * @arg TIM_FLAG_Trigger: TIM Trigger Flag
  17058. * @arg TIM_FLAG_Break: TIM Break Flag
  17059. * @arg TIM_FLAG_CC1OF: TIM Capture Compare 1 overcapture Flag
  17060. * @arg TIM_FLAG_CC2OF: TIM Capture Compare 2 overcapture Flag
  17061. * @arg TIM_FLAG_CC3OF: TIM Capture Compare 3 overcapture Flag
  17062. * @arg TIM_FLAG_CC4OF: TIM Capture Compare 4 overcapture Flag
  17063. * @note
  17064. * - TIM6 and TIM7 can have only one update flag.
  17065. * - TIM9, TIM12 and TIM15 can have only TIM_FLAG_Update, TIM_FLAG_CC1,
  17066. * TIM_FLAG_CC2 or TIM_FLAG_Trigger.
  17067. * - TIM10, TIM11, TIM13, TIM14, TIM16 and TIM17 can have TIM_FLAG_Update or TIM_FLAG_CC1.
  17068. * - TIM_FLAG_Break is used only with TIM1, TIM8 and TIM15.
  17069. * - TIM_FLAG_COM is used only with TIM1, TIM8, TIM15, TIM16 and TIM17.
  17070. * @retval The new state of TIM_FLAG (SET or RESET).
  17071. */
  17072. FlagStatus TIM_GetFlagStatus(TIM_TypeDef* TIMx, uint16_t TIM_FLAG)
  17073. {
  17074. ITStatus bitstatus = RESET;
  17075. /* Check the parameters */
  17076. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  17077. assert_param(IS_TIM_GET_FLAG(TIM_FLAG));
  17078. if ((TIMx->SR & TIM_FLAG) != (uint16_t)RESET)
  17079. {
  17080. bitstatus = SET;
  17081. }
  17082. else
  17083. {
  17084. bitstatus = RESET;
  17085. }
  17086. return bitstatus;
  17087. }
  17088. /**
  17089. * @brief Clears the TIMx's pending flags.
  17090. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  17091. * @param TIM_FLAG: specifies the flag bit to clear.
  17092. * This parameter can be any combination of the following values:
  17093. * @arg TIM_FLAG_Update: TIM update Flag
  17094. * @arg TIM_FLAG_CC1: TIM Capture Compare 1 Flag
  17095. * @arg TIM_FLAG_CC2: TIM Capture Compare 2 Flag
  17096. * @arg TIM_FLAG_CC3: TIM Capture Compare 3 Flag
  17097. * @arg TIM_FLAG_CC4: TIM Capture Compare 4 Flag
  17098. * @arg TIM_FLAG_COM: TIM Commutation Flag
  17099. * @arg TIM_FLAG_Trigger: TIM Trigger Flag
  17100. * @arg TIM_FLAG_Break: TIM Break Flag
  17101. * @arg TIM_FLAG_CC1OF: TIM Capture Compare 1 overcapture Flag
  17102. * @arg TIM_FLAG_CC2OF: TIM Capture Compare 2 overcapture Flag
  17103. * @arg TIM_FLAG_CC3OF: TIM Capture Compare 3 overcapture Flag
  17104. * @arg TIM_FLAG_CC4OF: TIM Capture Compare 4 overcapture Flag
  17105. * @note
  17106. * - TIM6 and TIM7 can have only one update flag.
  17107. * - TIM9, TIM12 and TIM15 can have only TIM_FLAG_Update, TIM_FLAG_CC1,
  17108. * TIM_FLAG_CC2 or TIM_FLAG_Trigger.
  17109. * - TIM10, TIM11, TIM13, TIM14, TIM16 and TIM17 can have TIM_FLAG_Update or TIM_FLAG_CC1.
  17110. * - TIM_FLAG_Break is used only with TIM1, TIM8 and TIM15.
  17111. * - TIM_FLAG_COM is used only with TIM1, TIM8, TIM15, TIM16 and TIM17.
  17112. * @retval None
  17113. */
  17114. void TIM_ClearFlag(TIM_TypeDef* TIMx, uint16_t TIM_FLAG)
  17115. {
  17116. /* Check the parameters */
  17117. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  17118. assert_param(IS_TIM_CLEAR_FLAG(TIM_FLAG));
  17119. /* Clear the flags */
  17120. TIMx->SR = (uint16_t)~TIM_FLAG;
  17121. }
  17122. /**
  17123. * @brief Checks whether the TIM interrupt has occurred or not.
  17124. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  17125. * @param TIM_IT: specifies the TIM interrupt source to check.
  17126. * This parameter can be one of the following values:
  17127. * @arg TIM_IT_Update: TIM update Interrupt source
  17128. * @arg TIM_IT_CC1: TIM Capture Compare 1 Interrupt source
  17129. * @arg TIM_IT_CC2: TIM Capture Compare 2 Interrupt source
  17130. * @arg TIM_IT_CC3: TIM Capture Compare 3 Interrupt source
  17131. * @arg TIM_IT_CC4: TIM Capture Compare 4 Interrupt source
  17132. * @arg TIM_IT_COM: TIM Commutation Interrupt source
  17133. * @arg TIM_IT_Trigger: TIM Trigger Interrupt source
  17134. * @arg TIM_IT_Break: TIM Break Interrupt source
  17135. * @note
  17136. * - TIM6 and TIM7 can generate only an update interrupt.
  17137. * - TIM9, TIM12 and TIM15 can have only TIM_IT_Update, TIM_IT_CC1,
  17138. * TIM_IT_CC2 or TIM_IT_Trigger.
  17139. * - TIM10, TIM11, TIM13, TIM14, TIM16 and TIM17 can have TIM_IT_Update or TIM_IT_CC1.
  17140. * - TIM_IT_Break is used only with TIM1, TIM8 and TIM15.
  17141. * - TIM_IT_COM is used only with TIM1, TIM8, TIM15, TIM16 and TIM17.
  17142. * @retval The new state of the TIM_IT(SET or RESET).
  17143. */
  17144. ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, uint16_t TIM_IT)
  17145. {
  17146. ITStatus bitstatus = RESET;
  17147. uint16_t itstatus = 0x0, itenable = 0x0;
  17148. /* Check the parameters */
  17149. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  17150. assert_param(IS_TIM_GET_IT(TIM_IT));
  17151. itstatus = TIMx->SR & TIM_IT;
  17152. itenable = TIMx->DIER & TIM_IT;
  17153. if ((itstatus != (uint16_t)RESET) && (itenable != (uint16_t)RESET))
  17154. {
  17155. bitstatus = SET;
  17156. }
  17157. else
  17158. {
  17159. bitstatus = RESET;
  17160. }
  17161. return bitstatus;
  17162. }
  17163. /**
  17164. * @brief Clears the TIMx's interrupt pending bits.
  17165. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral.
  17166. * @param TIM_IT: specifies the pending bit to clear.
  17167. * This parameter can be any combination of the following values:
  17168. * @arg TIM_IT_Update: TIM1 update Interrupt source
  17169. * @arg TIM_IT_CC1: TIM Capture Compare 1 Interrupt source
  17170. * @arg TIM_IT_CC2: TIM Capture Compare 2 Interrupt source
  17171. * @arg TIM_IT_CC3: TIM Capture Compare 3 Interrupt source
  17172. * @arg TIM_IT_CC4: TIM Capture Compare 4 Interrupt source
  17173. * @arg TIM_IT_COM: TIM Commutation Interrupt source
  17174. * @arg TIM_IT_Trigger: TIM Trigger Interrupt source
  17175. * @arg TIM_IT_Break: TIM Break Interrupt source
  17176. * @note
  17177. * - TIM6 and TIM7 can generate only an update interrupt.
  17178. * - TIM9, TIM12 and TIM15 can have only TIM_IT_Update, TIM_IT_CC1,
  17179. * TIM_IT_CC2 or TIM_IT_Trigger.
  17180. * - TIM10, TIM11, TIM13, TIM14, TIM16 and TIM17 can have TIM_IT_Update or TIM_IT_CC1.
  17181. * - TIM_IT_Break is used only with TIM1, TIM8 and TIM15.
  17182. * - TIM_IT_COM is used only with TIM1, TIM8, TIM15, TIM16 and TIM17.
  17183. * @retval None
  17184. */
  17185. void TIM_ClearITPendingBit(TIM_TypeDef* TIMx, uint16_t TIM_IT)
  17186. {
  17187. /* Check the parameters */
  17188. assert_param(IS_TIM_ALL_PERIPH(TIMx));
  17189. assert_param(IS_TIM_IT(TIM_IT));
  17190. /* Clear the IT pending Bit */
  17191. TIMx->SR = (uint16_t)~TIM_IT;
  17192. }
  17193. /**
  17194. * @brief Configure the TI1 as Input.
  17195. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.
  17196. * @param TIM_ICPolarity : The Input Polarity.
  17197. * This parameter can be one of the following values:
  17198. * @arg TIM_ICPolarity_Rising
  17199. * @arg TIM_ICPolarity_Falling
  17200. * @param TIM_ICSelection: specifies the input to be used.
  17201. * This parameter can be one of the following values:
  17202. * @arg TIM_ICSelection_DirectTI: TIM Input 1 is selected to be connected to IC1.
  17203. * @arg TIM_ICSelection_IndirectTI: TIM Input 1 is selected to be connected to IC2.
  17204. * @arg TIM_ICSelection_TRC: TIM Input 1 is selected to be connected to TRC.
  17205. * @param TIM_ICFilter: Specifies the Input Capture Filter.
  17206. * This parameter must be a value between 0x00 and 0x0F.
  17207. * @retval None
  17208. */
  17209. static void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
  17210. uint16_t TIM_ICFilter)
  17211. {
  17212. uint16_t tmpccmr1 = 0, tmpccer = 0;
  17213. /* Disable the Channel 1: Reset the CC1E Bit */
  17214. TIMx->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC1E);
  17215. tmpccmr1 = TIMx->CCMR1;
  17216. tmpccer = TIMx->CCER;
  17217. /* Select the Input and set the filter */
  17218. tmpccmr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR1_CC1S)) & ((uint16_t)~((uint16_t)TIM_CCMR1_IC1F)));
  17219. tmpccmr1 |= (uint16_t)(TIM_ICSelection | (uint16_t)(TIM_ICFilter << (uint16_t)4));
  17220. if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM2) || (TIMx == TIM3) ||
  17221. (TIMx == TIM4) ||(TIMx == TIM5))
  17222. {
  17223. /* Select the Polarity and set the CC1E Bit */
  17224. tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC1P));
  17225. tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC1E);
  17226. }
  17227. else
  17228. {
  17229. /* Select the Polarity and set the CC1E Bit */
  17230. tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC1P | TIM_CCER_CC1NP));
  17231. tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC1E);
  17232. }
  17233. /* Write to TIMx CCMR1 and CCER registers */
  17234. TIMx->CCMR1 = tmpccmr1;
  17235. TIMx->CCER = tmpccer;
  17236. }
  17237. /**
  17238. * @brief Configure the TI2 as Input.
  17239. * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.
  17240. * @param TIM_ICPolarity : The Input Polarity.
  17241. * This parameter can be one of the following values:
  17242. * @arg TIM_ICPolarity_Rising
  17243. * @arg TIM_ICPolarity_Falling
  17244. * @param TIM_ICSelection: specifies the input to be used.
  17245. * This parameter can be one of the following values:
  17246. * @arg TIM_ICSelection_DirectTI: TIM Input 2 is selected to be connected to IC2.
  17247. * @arg TIM_ICSelection_IndirectTI: TIM Input 2 is selected to be connected to IC1.
  17248. * @arg TIM_ICSelection_TRC: TIM Input 2 is selected to be connected to TRC.
  17249. * @param TIM_ICFilter: Specifies the Input Capture Filter.
  17250. * This parameter must be a value between 0x00 and 0x0F.
  17251. * @retval None
  17252. */
  17253. static void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
  17254. uint16_t TIM_ICFilter)
  17255. {
  17256. uint16_t tmpccmr1 = 0, tmpccer = 0, tmp = 0;
  17257. /* Disable the Channel 2: Reset the CC2E Bit */
  17258. TIMx->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC2E);
  17259. tmpccmr1 = TIMx->CCMR1;
  17260. tmpccer = TIMx->CCER;
  17261. tmp = (uint16_t)(TIM_ICPolarity << 4);
  17262. /* Select the Input and set the filter */
  17263. tmpccmr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR1_CC2S)) & ((uint16_t)~((uint16_t)TIM_CCMR1_IC2F)));
  17264. tmpccmr1 |= (uint16_t)(TIM_ICFilter << 12);
  17265. tmpccmr1 |= (uint16_t)(TIM_ICSelection << 8);
  17266. if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM2) || (TIMx == TIM3) ||
  17267. (TIMx == TIM4) ||(TIMx == TIM5))
  17268. {
  17269. /* Select the Polarity and set the CC2E Bit */
  17270. tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC2P));
  17271. tmpccer |= (uint16_t)(tmp | (uint16_t)TIM_CCER_CC2E);
  17272. }
  17273. else
  17274. {
  17275. /* Select the Polarity and set the CC2E Bit */
  17276. tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC2P | TIM_CCER_CC2NP));
  17277. tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC2E);
  17278. }
  17279. /* Write to TIMx CCMR1 and CCER registers */
  17280. TIMx->CCMR1 = tmpccmr1 ;
  17281. TIMx->CCER = tmpccer;
  17282. }
  17283. /**
  17284. * @brief Configure the TI3 as Input.
  17285. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  17286. * @param TIM_ICPolarity : The Input Polarity.
  17287. * This parameter can be one of the following values:
  17288. * @arg TIM_ICPolarity_Rising
  17289. * @arg TIM_ICPolarity_Falling
  17290. * @param TIM_ICSelection: specifies the input to be used.
  17291. * This parameter can be one of the following values:
  17292. * @arg TIM_ICSelection_DirectTI: TIM Input 3 is selected to be connected to IC3.
  17293. * @arg TIM_ICSelection_IndirectTI: TIM Input 3 is selected to be connected to IC4.
  17294. * @arg TIM_ICSelection_TRC: TIM Input 3 is selected to be connected to TRC.
  17295. * @param TIM_ICFilter: Specifies the Input Capture Filter.
  17296. * This parameter must be a value between 0x00 and 0x0F.
  17297. * @retval None
  17298. */
  17299. static void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
  17300. uint16_t TIM_ICFilter)
  17301. {
  17302. uint16_t tmpccmr2 = 0, tmpccer = 0, tmp = 0;
  17303. /* Disable the Channel 3: Reset the CC3E Bit */
  17304. TIMx->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC3E);
  17305. tmpccmr2 = TIMx->CCMR2;
  17306. tmpccer = TIMx->CCER;
  17307. tmp = (uint16_t)(TIM_ICPolarity << 8);
  17308. /* Select the Input and set the filter */
  17309. tmpccmr2 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR2_CC3S)) & ((uint16_t)~((uint16_t)TIM_CCMR2_IC3F)));
  17310. tmpccmr2 |= (uint16_t)(TIM_ICSelection | (uint16_t)(TIM_ICFilter << (uint16_t)4));
  17311. if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM2) || (TIMx == TIM3) ||
  17312. (TIMx == TIM4) ||(TIMx == TIM5))
  17313. {
  17314. /* Select the Polarity and set the CC3E Bit */
  17315. tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC3P));
  17316. tmpccer |= (uint16_t)(tmp | (uint16_t)TIM_CCER_CC3E);
  17317. }
  17318. else
  17319. {
  17320. /* Select the Polarity and set the CC3E Bit */
  17321. tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC3P | TIM_CCER_CC3NP));
  17322. tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC3E);
  17323. }
  17324. /* Write to TIMx CCMR2 and CCER registers */
  17325. TIMx->CCMR2 = tmpccmr2;
  17326. TIMx->CCER = tmpccer;
  17327. }
  17328. /**
  17329. * @brief Configure the TI4 as Input.
  17330. * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  17331. * @param TIM_ICPolarity : The Input Polarity.
  17332. * This parameter can be one of the following values:
  17333. * @arg TIM_ICPolarity_Rising
  17334. * @arg TIM_ICPolarity_Falling
  17335. * @param TIM_ICSelection: specifies the input to be used.
  17336. * This parameter can be one of the following values:
  17337. * @arg TIM_ICSelection_DirectTI: TIM Input 4 is selected to be connected to IC4.
  17338. * @arg TIM_ICSelection_IndirectTI: TIM Input 4 is selected to be connected to IC3.
  17339. * @arg TIM_ICSelection_TRC: TIM Input 4 is selected to be connected to TRC.
  17340. * @param TIM_ICFilter: Specifies the Input Capture Filter.
  17341. * This parameter must be a value between 0x00 and 0x0F.
  17342. * @retval None
  17343. */
  17344. static void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
  17345. uint16_t TIM_ICFilter)
  17346. {
  17347. uint16_t tmpccmr2 = 0, tmpccer = 0, tmp = 0;
  17348. /* Disable the Channel 4: Reset the CC4E Bit */
  17349. TIMx->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC4E);
  17350. tmpccmr2 = TIMx->CCMR2;
  17351. tmpccer = TIMx->CCER;
  17352. tmp = (uint16_t)(TIM_ICPolarity << 12);
  17353. /* Select the Input and set the filter */
  17354. tmpccmr2 &= (uint16_t)((uint16_t)(~(uint16_t)TIM_CCMR2_CC4S) & ((uint16_t)~((uint16_t)TIM_CCMR2_IC4F)));
  17355. tmpccmr2 |= (uint16_t)(TIM_ICSelection << 8);
  17356. tmpccmr2 |= (uint16_t)(TIM_ICFilter << 12);
  17357. if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM2) || (TIMx == TIM3) ||
  17358. (TIMx == TIM4) ||(TIMx == TIM5))
  17359. {
  17360. /* Select the Polarity and set the CC4E Bit */
  17361. tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC4P));
  17362. tmpccer |= (uint16_t)(tmp | (uint16_t)TIM_CCER_CC4E);
  17363. }
  17364. else
  17365. {
  17366. /* Select the Polarity and set the CC4E Bit */
  17367. tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC3P | TIM_CCER_CC4NP));
  17368. tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC4E);
  17369. }
  17370. /* Write to TIMx CCMR2 and CCER registers */
  17371. TIMx->CCMR2 = tmpccmr2;
  17372. TIMx->CCER = tmpccer;
  17373. }
  17374. /**
  17375. * @}
  17376. */
  17377. /**
  17378. * @}
  17379. */
  17380. /**
  17381. * @}
  17382. */
  17383. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  17384. /**
  17385. ******************************************************************************
  17386. * @file stm32f10x_wwdg.c
  17387. * @author MCD Application Team
  17388. * @version V3.5.0
  17389. * @date 11-March-2011
  17390. * @brief This file provides all the WWDG firmware functions.
  17391. ******************************************************************************
  17392. * @attention
  17393. *
  17394. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  17395. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  17396. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  17397. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  17398. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17399. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17400. *
  17401. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  17402. ******************************************************************************
  17403. */
  17404. /* Includes ------------------------------------------------------------------*/
  17405. #include "stm32f10x_wwdg.h"
  17406. #include "stm32f10x_rcc.h"
  17407. /** @addtogroup STM32F10x_StdPeriph_Driver
  17408. * @{
  17409. */
  17410. /** @defgroup WWDG
  17411. * @brief WWDG driver modules
  17412. * @{
  17413. */
  17414. /** @defgroup WWDG_Private_TypesDefinitions
  17415. * @{
  17416. */
  17417. /**
  17418. * @}
  17419. */
  17420. /** @defgroup WWDG_Private_Defines
  17421. * @{
  17422. */
  17423. /* ----------- WWDG registers bit address in the alias region ----------- */
  17424. #define WWDG_OFFSET (WWDG_BASE - PERIPH_BASE)
  17425. /* Alias word address of EWI bit */
  17426. #define CFR_OFFSET (WWDG_OFFSET + 0x04)
  17427. #define EWI_BitNumber 0x09
  17428. #define CFR_EWI_BB (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4))
  17429. /* --------------------- WWDG registers bit mask ------------------------ */
  17430. /* CR register bit mask */
  17431. #define CR_WDGA_Set ((uint32_t)0x00000080)
  17432. /* CFR register bit mask */
  17433. #define CFR_WDGTB_Mask ((uint32_t)0xFFFFFE7F)
  17434. #define CFR_W_Mask ((uint32_t)0xFFFFFF80)
  17435. #define BIT_Mask ((uint8_t)0x7F)
  17436. /**
  17437. * @}
  17438. */
  17439. /** @defgroup WWDG_Private_Macros
  17440. * @{
  17441. */
  17442. /**
  17443. * @}
  17444. */
  17445. /** @defgroup WWDG_Private_Variables
  17446. * @{
  17447. */
  17448. /**
  17449. * @}
  17450. */
  17451. /** @defgroup WWDG_Private_FunctionPrototypes
  17452. * @{
  17453. */
  17454. /**
  17455. * @}
  17456. */
  17457. /** @defgroup WWDG_Private_Functions
  17458. * @{
  17459. */
  17460. /**
  17461. * @brief Deinitializes the WWDG peripheral registers to their default reset values.
  17462. * @param None
  17463. * @retval None
  17464. */
  17465. void WWDG_DeInit(void)
  17466. {
  17467. RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE);
  17468. RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
  17469. }
  17470. /**
  17471. * @brief Sets the WWDG Prescaler.
  17472. * @param WWDG_Prescaler: specifies the WWDG Prescaler.
  17473. * This parameter can be one of the following values:
  17474. * @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1
  17475. * @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2
  17476. * @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4
  17477. * @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8
  17478. * @retval None
  17479. */
  17480. void WWDG_SetPrescaler(uint32_t WWDG_Prescaler)
  17481. {
  17482. uint32_t tmpreg = 0;
  17483. /* Check the parameters */
  17484. assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler));
  17485. /* Clear WDGTB[1:0] bits */
  17486. tmpreg = WWDG->CFR & CFR_WDGTB_Mask;
  17487. /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */
  17488. tmpreg |= WWDG_Prescaler;
  17489. /* Store the new value */
  17490. WWDG->CFR = tmpreg;
  17491. }
  17492. /**
  17493. * @brief Sets the WWDG window value.
  17494. * @param WindowValue: specifies the window value to be compared to the downcounter.
  17495. * This parameter value must be lower than 0x80.
  17496. * @retval None
  17497. */
  17498. void WWDG_SetWindowValue(uint8_t WindowValue)
  17499. {
  17500. __IO uint32_t tmpreg = 0;
  17501. /* Check the parameters */
  17502. assert_param(IS_WWDG_WINDOW_VALUE(WindowValue));
  17503. /* Clear W[6:0] bits */
  17504. tmpreg = WWDG->CFR & CFR_W_Mask;
  17505. /* Set W[6:0] bits according to WindowValue value */
  17506. tmpreg |= WindowValue & (uint32_t) BIT_Mask;
  17507. /* Store the new value */
  17508. WWDG->CFR = tmpreg;
  17509. }
  17510. /**
  17511. * @brief Enables the WWDG Early Wakeup interrupt(EWI).
  17512. * @param None
  17513. * @retval None
  17514. */
  17515. void WWDG_EnableIT(void)
  17516. {
  17517. *(__IO uint32_t *) CFR_EWI_BB = (uint32_t)ENABLE;
  17518. }
  17519. /**
  17520. * @brief Sets the WWDG counter value.
  17521. * @param Counter: specifies the watchdog counter value.
  17522. * This parameter must be a number between 0x40 and 0x7F.
  17523. * @retval None
  17524. */
  17525. void WWDG_SetCounter(uint8_t Counter)
  17526. {
  17527. /* Check the parameters */
  17528. assert_param(IS_WWDG_COUNTER(Counter));
  17529. /* Write to T[6:0] bits to configure the counter value, no need to do
  17530. a read-modify-write; writing a 0 to WDGA bit does nothing */
  17531. WWDG->CR = Counter & BIT_Mask;
  17532. }
  17533. /**
  17534. * @brief Enables WWDG and load the counter value.
  17535. * @param Counter: specifies the watchdog counter value.
  17536. * This parameter must be a number between 0x40 and 0x7F.
  17537. * @retval None
  17538. */
  17539. void WWDG_Enable(uint8_t Counter)
  17540. {
  17541. /* Check the parameters */
  17542. assert_param(IS_WWDG_COUNTER(Counter));
  17543. WWDG->CR = CR_WDGA_Set | Counter;
  17544. }
  17545. /**
  17546. * @brief Checks whether the Early Wakeup interrupt flag is set or not.
  17547. * @param None
  17548. * @retval The new state of the Early Wakeup interrupt flag (SET or RESET)
  17549. */
  17550. FlagStatus WWDG_GetFlagStatus(void)
  17551. {
  17552. return (FlagStatus)(WWDG->SR);
  17553. }
  17554. /**
  17555. * @brief Clears Early Wakeup interrupt flag.
  17556. * @param None
  17557. * @retval None
  17558. */
  17559. void WWDG_ClearFlag(void)
  17560. {
  17561. WWDG->SR = (uint32_t)RESET;
  17562. }
  17563. /**
  17564. * @}
  17565. */
  17566. /**
  17567. * @}
  17568. */
  17569. /**
  17570. * @}
  17571. */
  17572. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  17573. /**
  17574. ******************************************************************************
  17575. * @file stm32f10x_dma.c
  17576. * @author MCD Application Team
  17577. * @version V3.5.0
  17578. * @date 11-March-2011
  17579. * @brief This file provides all the DMA firmware functions.
  17580. ******************************************************************************
  17581. * @attention
  17582. *
  17583. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  17584. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  17585. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  17586. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  17587. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17588. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17589. *
  17590. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  17591. ******************************************************************************
  17592. */
  17593. /* Includes ------------------------------------------------------------------*/
  17594. #include "stm32f10x_dma.h"
  17595. #include "stm32f10x_rcc.h"
  17596. /** @addtogroup STM32F10x_StdPeriph_Driver
  17597. * @{
  17598. */
  17599. /** @defgroup DMA
  17600. * @brief DMA driver modules
  17601. * @{
  17602. */
  17603. /** @defgroup DMA_Private_TypesDefinitions
  17604. * @{
  17605. */
  17606. /**
  17607. * @}
  17608. */
  17609. /** @defgroup DMA_Private_Defines
  17610. * @{
  17611. */
  17612. /* DMA1 Channelx interrupt pending bit masks */
  17613. #define DMA1_Channel1_IT_Mask ((uint32_t)(DMA_ISR_GIF1 | DMA_ISR_TCIF1 | DMA_ISR_HTIF1 | DMA_ISR_TEIF1))
  17614. #define DMA1_Channel2_IT_Mask ((uint32_t)(DMA_ISR_GIF2 | DMA_ISR_TCIF2 | DMA_ISR_HTIF2 | DMA_ISR_TEIF2))
  17615. #define DMA1_Channel3_IT_Mask ((uint32_t)(DMA_ISR_GIF3 | DMA_ISR_TCIF3 | DMA_ISR_HTIF3 | DMA_ISR_TEIF3))
  17616. #define DMA1_Channel4_IT_Mask ((uint32_t)(DMA_ISR_GIF4 | DMA_ISR_TCIF4 | DMA_ISR_HTIF4 | DMA_ISR_TEIF4))
  17617. #define DMA1_Channel5_IT_Mask ((uint32_t)(DMA_ISR_GIF5 | DMA_ISR_TCIF5 | DMA_ISR_HTIF5 | DMA_ISR_TEIF5))
  17618. #define DMA1_Channel6_IT_Mask ((uint32_t)(DMA_ISR_GIF6 | DMA_ISR_TCIF6 | DMA_ISR_HTIF6 | DMA_ISR_TEIF6))
  17619. #define DMA1_Channel7_IT_Mask ((uint32_t)(DMA_ISR_GIF7 | DMA_ISR_TCIF7 | DMA_ISR_HTIF7 | DMA_ISR_TEIF7))
  17620. /* DMA2 Channelx interrupt pending bit masks */
  17621. #define DMA2_Channel1_IT_Mask ((uint32_t)(DMA_ISR_GIF1 | DMA_ISR_TCIF1 | DMA_ISR_HTIF1 | DMA_ISR_TEIF1))
  17622. #define DMA2_Channel2_IT_Mask ((uint32_t)(DMA_ISR_GIF2 | DMA_ISR_TCIF2 | DMA_ISR_HTIF2 | DMA_ISR_TEIF2))
  17623. #define DMA2_Channel3_IT_Mask ((uint32_t)(DMA_ISR_GIF3 | DMA_ISR_TCIF3 | DMA_ISR_HTIF3 | DMA_ISR_TEIF3))
  17624. #define DMA2_Channel4_IT_Mask ((uint32_t)(DMA_ISR_GIF4 | DMA_ISR_TCIF4 | DMA_ISR_HTIF4 | DMA_ISR_TEIF4))
  17625. #define DMA2_Channel5_IT_Mask ((uint32_t)(DMA_ISR_GIF5 | DMA_ISR_TCIF5 | DMA_ISR_HTIF5 | DMA_ISR_TEIF5))
  17626. /* DMA2 FLAG mask */
  17627. #define FLAG_Mask ((uint32_t)0x10000000)
  17628. /* DMA registers Masks */
  17629. #define CCR_CLEAR_Mask ((uint32_t)0xFFFF800F)
  17630. /**
  17631. * @}
  17632. */
  17633. /** @defgroup DMA_Private_Macros
  17634. * @{
  17635. */
  17636. /**
  17637. * @}
  17638. */
  17639. /** @defgroup DMA_Private_Variables
  17640. * @{
  17641. */
  17642. /**
  17643. * @}
  17644. */
  17645. /** @defgroup DMA_Private_FunctionPrototypes
  17646. * @{
  17647. */
  17648. /**
  17649. * @}
  17650. */
  17651. /** @defgroup DMA_Private_Functions
  17652. * @{
  17653. */
  17654. /**
  17655. * @brief Deinitializes the DMAy Channelx registers to their default reset
  17656. * values.
  17657. * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
  17658. * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
  17659. * @retval None
  17660. */
  17661. void DMA_DeInit(DMA_Channel_TypeDef* DMAy_Channelx)
  17662. {
  17663. /* Check the parameters */
  17664. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  17665. /* Disable the selected DMAy Channelx */
  17666. DMAy_Channelx->CCR &= (uint16_t)(~DMA_CCR1_EN);
  17667. /* Reset DMAy Channelx control register */
  17668. DMAy_Channelx->CCR = 0;
  17669. /* Reset DMAy Channelx remaining bytes register */
  17670. DMAy_Channelx->CNDTR = 0;
  17671. /* Reset DMAy Channelx peripheral address register */
  17672. DMAy_Channelx->CPAR = 0;
  17673. /* Reset DMAy Channelx memory address register */
  17674. DMAy_Channelx->CMAR = 0;
  17675. if (DMAy_Channelx == DMA1_Channel1)
  17676. {
  17677. /* Reset interrupt pending bits for DMA1 Channel1 */
  17678. DMA1->IFCR |= DMA1_Channel1_IT_Mask;
  17679. }
  17680. else if (DMAy_Channelx == DMA1_Channel2)
  17681. {
  17682. /* Reset interrupt pending bits for DMA1 Channel2 */
  17683. DMA1->IFCR |= DMA1_Channel2_IT_Mask;
  17684. }
  17685. else if (DMAy_Channelx == DMA1_Channel3)
  17686. {
  17687. /* Reset interrupt pending bits for DMA1 Channel3 */
  17688. DMA1->IFCR |= DMA1_Channel3_IT_Mask;
  17689. }
  17690. else if (DMAy_Channelx == DMA1_Channel4)
  17691. {
  17692. /* Reset interrupt pending bits for DMA1 Channel4 */
  17693. DMA1->IFCR |= DMA1_Channel4_IT_Mask;
  17694. }
  17695. else if (DMAy_Channelx == DMA1_Channel5)
  17696. {
  17697. /* Reset interrupt pending bits for DMA1 Channel5 */
  17698. DMA1->IFCR |= DMA1_Channel5_IT_Mask;
  17699. }
  17700. else if (DMAy_Channelx == DMA1_Channel6)
  17701. {
  17702. /* Reset interrupt pending bits for DMA1 Channel6 */
  17703. DMA1->IFCR |= DMA1_Channel6_IT_Mask;
  17704. }
  17705. else if (DMAy_Channelx == DMA1_Channel7)
  17706. {
  17707. /* Reset interrupt pending bits for DMA1 Channel7 */
  17708. DMA1->IFCR |= DMA1_Channel7_IT_Mask;
  17709. }
  17710. else if (DMAy_Channelx == DMA2_Channel1)
  17711. {
  17712. /* Reset interrupt pending bits for DMA2 Channel1 */
  17713. DMA2->IFCR |= DMA2_Channel1_IT_Mask;
  17714. }
  17715. else if (DMAy_Channelx == DMA2_Channel2)
  17716. {
  17717. /* Reset interrupt pending bits for DMA2 Channel2 */
  17718. DMA2->IFCR |= DMA2_Channel2_IT_Mask;
  17719. }
  17720. else if (DMAy_Channelx == DMA2_Channel3)
  17721. {
  17722. /* Reset interrupt pending bits for DMA2 Channel3 */
  17723. DMA2->IFCR |= DMA2_Channel3_IT_Mask;
  17724. }
  17725. else if (DMAy_Channelx == DMA2_Channel4)
  17726. {
  17727. /* Reset interrupt pending bits for DMA2 Channel4 */
  17728. DMA2->IFCR |= DMA2_Channel4_IT_Mask;
  17729. }
  17730. else
  17731. {
  17732. if (DMAy_Channelx == DMA2_Channel5)
  17733. {
  17734. /* Reset interrupt pending bits for DMA2 Channel5 */
  17735. DMA2->IFCR |= DMA2_Channel5_IT_Mask;
  17736. }
  17737. }
  17738. }
  17739. /**
  17740. * @brief Initializes the DMAy Channelx according to the specified
  17741. * parameters in the DMA_InitStruct.
  17742. * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
  17743. * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
  17744. * @param DMA_InitStruct: pointer to a DMA_InitTypeDef structure that
  17745. * contains the configuration information for the specified DMA Channel.
  17746. * @retval None
  17747. */
  17748. void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx, DMA_InitTypeDef* DMA_InitStruct)
  17749. {
  17750. uint32_t tmpreg = 0;
  17751. /* Check the parameters */
  17752. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  17753. assert_param(IS_DMA_DIR(DMA_InitStruct->DMA_DIR));
  17754. assert_param(IS_DMA_BUFFER_SIZE(DMA_InitStruct->DMA_BufferSize));
  17755. assert_param(IS_DMA_PERIPHERAL_INC_STATE(DMA_InitStruct->DMA_PeripheralInc));
  17756. assert_param(IS_DMA_MEMORY_INC_STATE(DMA_InitStruct->DMA_MemoryInc));
  17757. assert_param(IS_DMA_PERIPHERAL_DATA_SIZE(DMA_InitStruct->DMA_PeripheralDataSize));
  17758. assert_param(IS_DMA_MEMORY_DATA_SIZE(DMA_InitStruct->DMA_MemoryDataSize));
  17759. assert_param(IS_DMA_MODE(DMA_InitStruct->DMA_Mode));
  17760. assert_param(IS_DMA_PRIORITY(DMA_InitStruct->DMA_Priority));
  17761. assert_param(IS_DMA_M2M_STATE(DMA_InitStruct->DMA_M2M));
  17762. /*--------------------------- DMAy Channelx CCR Configuration -----------------*/
  17763. /* Get the DMAy_Channelx CCR value */
  17764. tmpreg = DMAy_Channelx->CCR;
  17765. /* Clear MEM2MEM, PL, MSIZE, PSIZE, MINC, PINC, CIRC and DIR bits */
  17766. tmpreg &= CCR_CLEAR_Mask;
  17767. /* Configure DMAy Channelx: data transfer, data size, priority level and mode */
  17768. /* Set DIR bit according to DMA_DIR value */
  17769. /* Set CIRC bit according to DMA_Mode value */
  17770. /* Set PINC bit according to DMA_PeripheralInc value */
  17771. /* Set MINC bit according to DMA_MemoryInc value */
  17772. /* Set PSIZE bits according to DMA_PeripheralDataSize value */
  17773. /* Set MSIZE bits according to DMA_MemoryDataSize value */
  17774. /* Set PL bits according to DMA_Priority value */
  17775. /* Set the MEM2MEM bit according to DMA_M2M value */
  17776. tmpreg |= DMA_InitStruct->DMA_DIR | DMA_InitStruct->DMA_Mode |
  17777. DMA_InitStruct->DMA_PeripheralInc | DMA_InitStruct->DMA_MemoryInc |
  17778. DMA_InitStruct->DMA_PeripheralDataSize | DMA_InitStruct->DMA_MemoryDataSize |
  17779. DMA_InitStruct->DMA_Priority | DMA_InitStruct->DMA_M2M;
  17780. /* Write to DMAy Channelx CCR */
  17781. DMAy_Channelx->CCR = tmpreg;
  17782. /*--------------------------- DMAy Channelx CNDTR Configuration ---------------*/
  17783. /* Write to DMAy Channelx CNDTR */
  17784. DMAy_Channelx->CNDTR = DMA_InitStruct->DMA_BufferSize;
  17785. /*--------------------------- DMAy Channelx CPAR Configuration ----------------*/
  17786. /* Write to DMAy Channelx CPAR */
  17787. DMAy_Channelx->CPAR = DMA_InitStruct->DMA_PeripheralBaseAddr;
  17788. /*--------------------------- DMAy Channelx CMAR Configuration ----------------*/
  17789. /* Write to DMAy Channelx CMAR */
  17790. DMAy_Channelx->CMAR = DMA_InitStruct->DMA_MemoryBaseAddr;
  17791. }
  17792. /**
  17793. * @brief Fills each DMA_InitStruct member with its default value.
  17794. * @param DMA_InitStruct : pointer to a DMA_InitTypeDef structure which will
  17795. * be initialized.
  17796. * @retval None
  17797. */
  17798. void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct)
  17799. {
  17800. /*-------------- Reset DMA init structure parameters values ------------------*/
  17801. /* Initialize the DMA_PeripheralBaseAddr member */
  17802. DMA_InitStruct->DMA_PeripheralBaseAddr = 0;
  17803. /* Initialize the DMA_MemoryBaseAddr member */
  17804. DMA_InitStruct->DMA_MemoryBaseAddr = 0;
  17805. /* Initialize the DMA_DIR member */
  17806. DMA_InitStruct->DMA_DIR = DMA_DIR_PeripheralSRC;
  17807. /* Initialize the DMA_BufferSize member */
  17808. DMA_InitStruct->DMA_BufferSize = 0;
  17809. /* Initialize the DMA_PeripheralInc member */
  17810. DMA_InitStruct->DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  17811. /* Initialize the DMA_MemoryInc member */
  17812. DMA_InitStruct->DMA_MemoryInc = DMA_MemoryInc_Disable;
  17813. /* Initialize the DMA_PeripheralDataSize member */
  17814. DMA_InitStruct->DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
  17815. /* Initialize the DMA_MemoryDataSize member */
  17816. DMA_InitStruct->DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
  17817. /* Initialize the DMA_Mode member */
  17818. DMA_InitStruct->DMA_Mode = DMA_Mode_Normal;
  17819. /* Initialize the DMA_Priority member */
  17820. DMA_InitStruct->DMA_Priority = DMA_Priority_Low;
  17821. /* Initialize the DMA_M2M member */
  17822. DMA_InitStruct->DMA_M2M = DMA_M2M_Disable;
  17823. }
  17824. /**
  17825. * @brief Enables or disables the specified DMAy Channelx.
  17826. * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
  17827. * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
  17828. * @param NewState: new state of the DMAy Channelx.
  17829. * This parameter can be: ENABLE or DISABLE.
  17830. * @retval None
  17831. */
  17832. void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState)
  17833. {
  17834. /* Check the parameters */
  17835. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  17836. assert_param(IS_FUNCTIONAL_STATE(NewState));
  17837. if (NewState != DISABLE)
  17838. {
  17839. /* Enable the selected DMAy Channelx */
  17840. DMAy_Channelx->CCR |= DMA_CCR1_EN;
  17841. }
  17842. else
  17843. {
  17844. /* Disable the selected DMAy Channelx */
  17845. DMAy_Channelx->CCR &= (uint16_t)(~DMA_CCR1_EN);
  17846. }
  17847. }
  17848. /**
  17849. * @brief Enables or disables the specified DMAy Channelx interrupts.
  17850. * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
  17851. * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
  17852. * @param DMA_IT: specifies the DMA interrupts sources to be enabled
  17853. * or disabled.
  17854. * This parameter can be any combination of the following values:
  17855. * @arg DMA_IT_TC: Transfer complete interrupt mask
  17856. * @arg DMA_IT_HT: Half transfer interrupt mask
  17857. * @arg DMA_IT_TE: Transfer error interrupt mask
  17858. * @param NewState: new state of the specified DMA interrupts.
  17859. * This parameter can be: ENABLE or DISABLE.
  17860. * @retval None
  17861. */
  17862. void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT, FunctionalState NewState)
  17863. {
  17864. /* Check the parameters */
  17865. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  17866. assert_param(IS_DMA_CONFIG_IT(DMA_IT));
  17867. assert_param(IS_FUNCTIONAL_STATE(NewState));
  17868. if (NewState != DISABLE)
  17869. {
  17870. /* Enable the selected DMA interrupts */
  17871. DMAy_Channelx->CCR |= DMA_IT;
  17872. }
  17873. else
  17874. {
  17875. /* Disable the selected DMA interrupts */
  17876. DMAy_Channelx->CCR &= ~DMA_IT;
  17877. }
  17878. }
  17879. /**
  17880. * @brief Sets the number of data units in the current DMAy Channelx transfer.
  17881. * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
  17882. * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
  17883. * @param DataNumber: The number of data units in the current DMAy Channelx
  17884. * transfer.
  17885. * @note This function can only be used when the DMAy_Channelx is disabled.
  17886. * @retval None.
  17887. */
  17888. void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx, uint16_t DataNumber)
  17889. {
  17890. /* Check the parameters */
  17891. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  17892. /*--------------------------- DMAy Channelx CNDTR Configuration ---------------*/
  17893. /* Write to DMAy Channelx CNDTR */
  17894. DMAy_Channelx->CNDTR = DataNumber;
  17895. }
  17896. /**
  17897. * @brief Returns the number of remaining data units in the current
  17898. * DMAy Channelx transfer.
  17899. * @param DMAy_Channelx: where y can be 1 or 2 to select the DMA and
  17900. * x can be 1 to 7 for DMA1 and 1 to 5 for DMA2 to select the DMA Channel.
  17901. * @retval The number of remaining data units in the current DMAy Channelx
  17902. * transfer.
  17903. */
  17904. uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx)
  17905. {
  17906. /* Check the parameters */
  17907. assert_param(IS_DMA_ALL_PERIPH(DMAy_Channelx));
  17908. /* Return the number of remaining data units for DMAy Channelx */
  17909. return ((uint16_t)(DMAy_Channelx->CNDTR));
  17910. }
  17911. /**
  17912. * @brief Checks whether the specified DMAy Channelx flag is set or not.
  17913. * @param DMAy_FLAG: specifies the flag to check.
  17914. * This parameter can be one of the following values:
  17915. * @arg DMA1_FLAG_GL1: DMA1 Channel1 global flag.
  17916. * @arg DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.
  17917. * @arg DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.
  17918. * @arg DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.
  17919. * @arg DMA1_FLAG_GL2: DMA1 Channel2 global flag.
  17920. * @arg DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.
  17921. * @arg DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.
  17922. * @arg DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.
  17923. * @arg DMA1_FLAG_GL3: DMA1 Channel3 global flag.
  17924. * @arg DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.
  17925. * @arg DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.
  17926. * @arg DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.
  17927. * @arg DMA1_FLAG_GL4: DMA1 Channel4 global flag.
  17928. * @arg DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.
  17929. * @arg DMA1_FLAG_HT4: DMA1 Channel4 half transfer flag.
  17930. * @arg DMA1_FLAG_TE4: DMA1 Channel4 transfer error flag.
  17931. * @arg DMA1_FLAG_GL5: DMA1 Channel5 global flag.
  17932. * @arg DMA1_FLAG_TC5: DMA1 Channel5 transfer complete flag.
  17933. * @arg DMA1_FLAG_HT5: DMA1 Channel5 half transfer flag.
  17934. * @arg DMA1_FLAG_TE5: DMA1 Channel5 transfer error flag.
  17935. * @arg DMA1_FLAG_GL6: DMA1 Channel6 global flag.
  17936. * @arg DMA1_FLAG_TC6: DMA1 Channel6 transfer complete flag.
  17937. * @arg DMA1_FLAG_HT6: DMA1 Channel6 half transfer flag.
  17938. * @arg DMA1_FLAG_TE6: DMA1 Channel6 transfer error flag.
  17939. * @arg DMA1_FLAG_GL7: DMA1 Channel7 global flag.
  17940. * @arg DMA1_FLAG_TC7: DMA1 Channel7 transfer complete flag.
  17941. * @arg DMA1_FLAG_HT7: DMA1 Channel7 half transfer flag.
  17942. * @arg DMA1_FLAG_TE7: DMA1 Channel7 transfer error flag.
  17943. * @arg DMA2_FLAG_GL1: DMA2 Channel1 global flag.
  17944. * @arg DMA2_FLAG_TC1: DMA2 Channel1 transfer complete flag.
  17945. * @arg DMA2_FLAG_HT1: DMA2 Channel1 half transfer flag.
  17946. * @arg DMA2_FLAG_TE1: DMA2 Channel1 transfer error flag.
  17947. * @arg DMA2_FLAG_GL2: DMA2 Channel2 global flag.
  17948. * @arg DMA2_FLAG_TC2: DMA2 Channel2 transfer complete flag.
  17949. * @arg DMA2_FLAG_HT2: DMA2 Channel2 half transfer flag.
  17950. * @arg DMA2_FLAG_TE2: DMA2 Channel2 transfer error flag.
  17951. * @arg DMA2_FLAG_GL3: DMA2 Channel3 global flag.
  17952. * @arg DMA2_FLAG_TC3: DMA2 Channel3 transfer complete flag.
  17953. * @arg DMA2_FLAG_HT3: DMA2 Channel3 half transfer flag.
  17954. * @arg DMA2_FLAG_TE3: DMA2 Channel3 transfer error flag.
  17955. * @arg DMA2_FLAG_GL4: DMA2 Channel4 global flag.
  17956. * @arg DMA2_FLAG_TC4: DMA2 Channel4 transfer complete flag.
  17957. * @arg DMA2_FLAG_HT4: DMA2 Channel4 half transfer flag.
  17958. * @arg DMA2_FLAG_TE4: DMA2 Channel4 transfer error flag.
  17959. * @arg DMA2_FLAG_GL5: DMA2 Channel5 global flag.
  17960. * @arg DMA2_FLAG_TC5: DMA2 Channel5 transfer complete flag.
  17961. * @arg DMA2_FLAG_HT5: DMA2 Channel5 half transfer flag.
  17962. * @arg DMA2_FLAG_TE5: DMA2 Channel5 transfer error flag.
  17963. * @retval The new state of DMAy_FLAG (SET or RESET).
  17964. */
  17965. FlagStatus DMA_GetFlagStatus(uint32_t DMAy_FLAG)
  17966. {
  17967. FlagStatus bitstatus = RESET;
  17968. uint32_t tmpreg = 0;
  17969. /* Check the parameters */
  17970. assert_param(IS_DMA_GET_FLAG(DMAy_FLAG));
  17971. /* Calculate the used DMAy */
  17972. if ((DMAy_FLAG & FLAG_Mask) != (uint32_t)RESET)
  17973. {
  17974. /* Get DMA2 ISR register value */
  17975. tmpreg = DMA2->ISR ;
  17976. }
  17977. else
  17978. {
  17979. /* Get DMA1 ISR register value */
  17980. tmpreg = DMA1->ISR ;
  17981. }
  17982. /* Check the status of the specified DMAy flag */
  17983. if ((tmpreg & DMAy_FLAG) != (uint32_t)RESET)
  17984. {
  17985. /* DMAy_FLAG is set */
  17986. bitstatus = SET;
  17987. }
  17988. else
  17989. {
  17990. /* DMAy_FLAG is reset */
  17991. bitstatus = RESET;
  17992. }
  17993. /* Return the DMAy_FLAG status */
  17994. return bitstatus;
  17995. }
  17996. /**
  17997. * @brief Clears the DMAy Channelx's pending flags.
  17998. * @param DMAy_FLAG: specifies the flag to clear.
  17999. * This parameter can be any combination (for the same DMA) of the following values:
  18000. * @arg DMA1_FLAG_GL1: DMA1 Channel1 global flag.
  18001. * @arg DMA1_FLAG_TC1: DMA1 Channel1 transfer complete flag.
  18002. * @arg DMA1_FLAG_HT1: DMA1 Channel1 half transfer flag.
  18003. * @arg DMA1_FLAG_TE1: DMA1 Channel1 transfer error flag.
  18004. * @arg DMA1_FLAG_GL2: DMA1 Channel2 global flag.
  18005. * @arg DMA1_FLAG_TC2: DMA1 Channel2 transfer complete flag.
  18006. * @arg DMA1_FLAG_HT2: DMA1 Channel2 half transfer flag.
  18007. * @arg DMA1_FLAG_TE2: DMA1 Channel2 transfer error flag.
  18008. * @arg DMA1_FLAG_GL3: DMA1 Channel3 global flag.
  18009. * @arg DMA1_FLAG_TC3: DMA1 Channel3 transfer complete flag.
  18010. * @arg DMA1_FLAG_HT3: DMA1 Channel3 half transfer flag.
  18011. * @arg DMA1_FLAG_TE3: DMA1 Channel3 transfer error flag.
  18012. * @arg DMA1_FLAG_GL4: DMA1 Channel4 global flag.
  18013. * @arg DMA1_FLAG_TC4: DMA1 Channel4 transfer complete flag.
  18014. * @arg DMA1_FLAG_HT4: DMA1 Channel4 half transfer flag.
  18015. * @arg DMA1_FLAG_TE4: DMA1 Channel4 transfer error flag.
  18016. * @arg DMA1_FLAG_GL5: DMA1 Channel5 global flag.
  18017. * @arg DMA1_FLAG_TC5: DMA1 Channel5 transfer complete flag.
  18018. * @arg DMA1_FLAG_HT5: DMA1 Channel5 half transfer flag.
  18019. * @arg DMA1_FLAG_TE5: DMA1 Channel5 transfer error flag.
  18020. * @arg DMA1_FLAG_GL6: DMA1 Channel6 global flag.
  18021. * @arg DMA1_FLAG_TC6: DMA1 Channel6 transfer complete flag.
  18022. * @arg DMA1_FLAG_HT6: DMA1 Channel6 half transfer flag.
  18023. * @arg DMA1_FLAG_TE6: DMA1 Channel6 transfer error flag.
  18024. * @arg DMA1_FLAG_GL7: DMA1 Channel7 global flag.
  18025. * @arg DMA1_FLAG_TC7: DMA1 Channel7 transfer complete flag.
  18026. * @arg DMA1_FLAG_HT7: DMA1 Channel7 half transfer flag.
  18027. * @arg DMA1_FLAG_TE7: DMA1 Channel7 transfer error flag.
  18028. * @arg DMA2_FLAG_GL1: DMA2 Channel1 global flag.
  18029. * @arg DMA2_FLAG_TC1: DMA2 Channel1 transfer complete flag.
  18030. * @arg DMA2_FLAG_HT1: DMA2 Channel1 half transfer flag.
  18031. * @arg DMA2_FLAG_TE1: DMA2 Channel1 transfer error flag.
  18032. * @arg DMA2_FLAG_GL2: DMA2 Channel2 global flag.
  18033. * @arg DMA2_FLAG_TC2: DMA2 Channel2 transfer complete flag.
  18034. * @arg DMA2_FLAG_HT2: DMA2 Channel2 half transfer flag.
  18035. * @arg DMA2_FLAG_TE2: DMA2 Channel2 transfer error flag.
  18036. * @arg DMA2_FLAG_GL3: DMA2 Channel3 global flag.
  18037. * @arg DMA2_FLAG_TC3: DMA2 Channel3 transfer complete flag.
  18038. * @arg DMA2_FLAG_HT3: DMA2 Channel3 half transfer flag.
  18039. * @arg DMA2_FLAG_TE3: DMA2 Channel3 transfer error flag.
  18040. * @arg DMA2_FLAG_GL4: DMA2 Channel4 global flag.
  18041. * @arg DMA2_FLAG_TC4: DMA2 Channel4 transfer complete flag.
  18042. * @arg DMA2_FLAG_HT4: DMA2 Channel4 half transfer flag.
  18043. * @arg DMA2_FLAG_TE4: DMA2 Channel4 transfer error flag.
  18044. * @arg DMA2_FLAG_GL5: DMA2 Channel5 global flag.
  18045. * @arg DMA2_FLAG_TC5: DMA2 Channel5 transfer complete flag.
  18046. * @arg DMA2_FLAG_HT5: DMA2 Channel5 half transfer flag.
  18047. * @arg DMA2_FLAG_TE5: DMA2 Channel5 transfer error flag.
  18048. * @retval None
  18049. */
  18050. void DMA_ClearFlag(uint32_t DMAy_FLAG)
  18051. {
  18052. /* Check the parameters */
  18053. assert_param(IS_DMA_CLEAR_FLAG(DMAy_FLAG));
  18054. /* Calculate the used DMAy */
  18055. if ((DMAy_FLAG & FLAG_Mask) != (uint32_t)RESET)
  18056. {
  18057. /* Clear the selected DMAy flags */
  18058. DMA2->IFCR = DMAy_FLAG;
  18059. }
  18060. else
  18061. {
  18062. /* Clear the selected DMAy flags */
  18063. DMA1->IFCR = DMAy_FLAG;
  18064. }
  18065. }
  18066. /**
  18067. * @brief Checks whether the specified DMAy Channelx interrupt has occurred or not.
  18068. * @param DMAy_IT: specifies the DMAy interrupt source to check.
  18069. * This parameter can be one of the following values:
  18070. * @arg DMA1_IT_GL1: DMA1 Channel1 global interrupt.
  18071. * @arg DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.
  18072. * @arg DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt.
  18073. * @arg DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.
  18074. * @arg DMA1_IT_GL2: DMA1 Channel2 global interrupt.
  18075. * @arg DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.
  18076. * @arg DMA1_IT_HT2: DMA1 Channel2 half transfer interrupt.
  18077. * @arg DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.
  18078. * @arg DMA1_IT_GL3: DMA1 Channel3 global interrupt.
  18079. * @arg DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.
  18080. * @arg DMA1_IT_HT3: DMA1 Channel3 half transfer interrupt.
  18081. * @arg DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.
  18082. * @arg DMA1_IT_GL4: DMA1 Channel4 global interrupt.
  18083. * @arg DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.
  18084. * @arg DMA1_IT_HT4: DMA1 Channel4 half transfer interrupt.
  18085. * @arg DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.
  18086. * @arg DMA1_IT_GL5: DMA1 Channel5 global interrupt.
  18087. * @arg DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.
  18088. * @arg DMA1_IT_HT5: DMA1 Channel5 half transfer interrupt.
  18089. * @arg DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.
  18090. * @arg DMA1_IT_GL6: DMA1 Channel6 global interrupt.
  18091. * @arg DMA1_IT_TC6: DMA1 Channel6 transfer complete interrupt.
  18092. * @arg DMA1_IT_HT6: DMA1 Channel6 half transfer interrupt.
  18093. * @arg DMA1_IT_TE6: DMA1 Channel6 transfer error interrupt.
  18094. * @arg DMA1_IT_GL7: DMA1 Channel7 global interrupt.
  18095. * @arg DMA1_IT_TC7: DMA1 Channel7 transfer complete interrupt.
  18096. * @arg DMA1_IT_HT7: DMA1 Channel7 half transfer interrupt.
  18097. * @arg DMA1_IT_TE7: DMA1 Channel7 transfer error interrupt.
  18098. * @arg DMA2_IT_GL1: DMA2 Channel1 global interrupt.
  18099. * @arg DMA2_IT_TC1: DMA2 Channel1 transfer complete interrupt.
  18100. * @arg DMA2_IT_HT1: DMA2 Channel1 half transfer interrupt.
  18101. * @arg DMA2_IT_TE1: DMA2 Channel1 transfer error interrupt.
  18102. * @arg DMA2_IT_GL2: DMA2 Channel2 global interrupt.
  18103. * @arg DMA2_IT_TC2: DMA2 Channel2 transfer complete interrupt.
  18104. * @arg DMA2_IT_HT2: DMA2 Channel2 half transfer interrupt.
  18105. * @arg DMA2_IT_TE2: DMA2 Channel2 transfer error interrupt.
  18106. * @arg DMA2_IT_GL3: DMA2 Channel3 global interrupt.
  18107. * @arg DMA2_IT_TC3: DMA2 Channel3 transfer complete interrupt.
  18108. * @arg DMA2_IT_HT3: DMA2 Channel3 half transfer interrupt.
  18109. * @arg DMA2_IT_TE3: DMA2 Channel3 transfer error interrupt.
  18110. * @arg DMA2_IT_GL4: DMA2 Channel4 global interrupt.
  18111. * @arg DMA2_IT_TC4: DMA2 Channel4 transfer complete interrupt.
  18112. * @arg DMA2_IT_HT4: DMA2 Channel4 half transfer interrupt.
  18113. * @arg DMA2_IT_TE4: DMA2 Channel4 transfer error interrupt.
  18114. * @arg DMA2_IT_GL5: DMA2 Channel5 global interrupt.
  18115. * @arg DMA2_IT_TC5: DMA2 Channel5 transfer complete interrupt.
  18116. * @arg DMA2_IT_HT5: DMA2 Channel5 half transfer interrupt.
  18117. * @arg DMA2_IT_TE5: DMA2 Channel5 transfer error interrupt.
  18118. * @retval The new state of DMAy_IT (SET or RESET).
  18119. */
  18120. ITStatus DMA_GetITStatus(uint32_t DMAy_IT)
  18121. {
  18122. ITStatus bitstatus = RESET;
  18123. uint32_t tmpreg = 0;
  18124. /* Check the parameters */
  18125. assert_param(IS_DMA_GET_IT(DMAy_IT));
  18126. /* Calculate the used DMA */
  18127. if ((DMAy_IT & FLAG_Mask) != (uint32_t)RESET)
  18128. {
  18129. /* Get DMA2 ISR register value */
  18130. tmpreg = DMA2->ISR;
  18131. }
  18132. else
  18133. {
  18134. /* Get DMA1 ISR register value */
  18135. tmpreg = DMA1->ISR;
  18136. }
  18137. /* Check the status of the specified DMAy interrupt */
  18138. if ((tmpreg & DMAy_IT) != (uint32_t)RESET)
  18139. {
  18140. /* DMAy_IT is set */
  18141. bitstatus = SET;
  18142. }
  18143. else
  18144. {
  18145. /* DMAy_IT is reset */
  18146. bitstatus = RESET;
  18147. }
  18148. /* Return the DMA_IT status */
  18149. return bitstatus;
  18150. }
  18151. /**
  18152. * @brief Clears the DMAy Channelx's interrupt pending bits.
  18153. * @param DMAy_IT: specifies the DMAy interrupt pending bit to clear.
  18154. * This parameter can be any combination (for the same DMA) of the following values:
  18155. * @arg DMA1_IT_GL1: DMA1 Channel1 global interrupt.
  18156. * @arg DMA1_IT_TC1: DMA1 Channel1 transfer complete interrupt.
  18157. * @arg DMA1_IT_HT1: DMA1 Channel1 half transfer interrupt.
  18158. * @arg DMA1_IT_TE1: DMA1 Channel1 transfer error interrupt.
  18159. * @arg DMA1_IT_GL2: DMA1 Channel2 global interrupt.
  18160. * @arg DMA1_IT_TC2: DMA1 Channel2 transfer complete interrupt.
  18161. * @arg DMA1_IT_HT2: DMA1 Channel2 half transfer interrupt.
  18162. * @arg DMA1_IT_TE2: DMA1 Channel2 transfer error interrupt.
  18163. * @arg DMA1_IT_GL3: DMA1 Channel3 global interrupt.
  18164. * @arg DMA1_IT_TC3: DMA1 Channel3 transfer complete interrupt.
  18165. * @arg DMA1_IT_HT3: DMA1 Channel3 half transfer interrupt.
  18166. * @arg DMA1_IT_TE3: DMA1 Channel3 transfer error interrupt.
  18167. * @arg DMA1_IT_GL4: DMA1 Channel4 global interrupt.
  18168. * @arg DMA1_IT_TC4: DMA1 Channel4 transfer complete interrupt.
  18169. * @arg DMA1_IT_HT4: DMA1 Channel4 half transfer interrupt.
  18170. * @arg DMA1_IT_TE4: DMA1 Channel4 transfer error interrupt.
  18171. * @arg DMA1_IT_GL5: DMA1 Channel5 global interrupt.
  18172. * @arg DMA1_IT_TC5: DMA1 Channel5 transfer complete interrupt.
  18173. * @arg DMA1_IT_HT5: DMA1 Channel5 half transfer interrupt.
  18174. * @arg DMA1_IT_TE5: DMA1 Channel5 transfer error interrupt.
  18175. * @arg DMA1_IT_GL6: DMA1 Channel6 global interrupt.
  18176. * @arg DMA1_IT_TC6: DMA1 Channel6 transfer complete interrupt.
  18177. * @arg DMA1_IT_HT6: DMA1 Channel6 half transfer interrupt.
  18178. * @arg DMA1_IT_TE6: DMA1 Channel6 transfer error interrupt.
  18179. * @arg DMA1_IT_GL7: DMA1 Channel7 global interrupt.
  18180. * @arg DMA1_IT_TC7: DMA1 Channel7 transfer complete interrupt.
  18181. * @arg DMA1_IT_HT7: DMA1 Channel7 half transfer interrupt.
  18182. * @arg DMA1_IT_TE7: DMA1 Channel7 transfer error interrupt.
  18183. * @arg DMA2_IT_GL1: DMA2 Channel1 global interrupt.
  18184. * @arg DMA2_IT_TC1: DMA2 Channel1 transfer complete interrupt.
  18185. * @arg DMA2_IT_HT1: DMA2 Channel1 half transfer interrupt.
  18186. * @arg DMA2_IT_TE1: DMA2 Channel1 transfer error interrupt.
  18187. * @arg DMA2_IT_GL2: DMA2 Channel2 global interrupt.
  18188. * @arg DMA2_IT_TC2: DMA2 Channel2 transfer complete interrupt.
  18189. * @arg DMA2_IT_HT2: DMA2 Channel2 half transfer interrupt.
  18190. * @arg DMA2_IT_TE2: DMA2 Channel2 transfer error interrupt.
  18191. * @arg DMA2_IT_GL3: DMA2 Channel3 global interrupt.
  18192. * @arg DMA2_IT_TC3: DMA2 Channel3 transfer complete interrupt.
  18193. * @arg DMA2_IT_HT3: DMA2 Channel3 half transfer interrupt.
  18194. * @arg DMA2_IT_TE3: DMA2 Channel3 transfer error interrupt.
  18195. * @arg DMA2_IT_GL4: DMA2 Channel4 global interrupt.
  18196. * @arg DMA2_IT_TC4: DMA2 Channel4 transfer complete interrupt.
  18197. * @arg DMA2_IT_HT4: DMA2 Channel4 half transfer interrupt.
  18198. * @arg DMA2_IT_TE4: DMA2 Channel4 transfer error interrupt.
  18199. * @arg DMA2_IT_GL5: DMA2 Channel5 global interrupt.
  18200. * @arg DMA2_IT_TC5: DMA2 Channel5 transfer complete interrupt.
  18201. * @arg DMA2_IT_HT5: DMA2 Channel5 half transfer interrupt.
  18202. * @arg DMA2_IT_TE5: DMA2 Channel5 transfer error interrupt.
  18203. * @retval None
  18204. */
  18205. void DMA_ClearITPendingBit(uint32_t DMAy_IT)
  18206. {
  18207. /* Check the parameters */
  18208. assert_param(IS_DMA_CLEAR_IT(DMAy_IT));
  18209. /* Calculate the used DMAy */
  18210. if ((DMAy_IT & FLAG_Mask) != (uint32_t)RESET)
  18211. {
  18212. /* Clear the selected DMAy interrupt pending bits */
  18213. DMA2->IFCR = DMAy_IT;
  18214. }
  18215. else
  18216. {
  18217. /* Clear the selected DMAy interrupt pending bits */
  18218. DMA1->IFCR = DMAy_IT;
  18219. }
  18220. }
  18221. /**
  18222. * @}
  18223. */
  18224. /**
  18225. * @}
  18226. */
  18227. /**
  18228. * @}
  18229. */
  18230. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  18231. /**
  18232. ******************************************************************************
  18233. * @file stm32f10x_crc.c
  18234. * @author MCD Application Team
  18235. * @version V3.5.0
  18236. * @date 11-March-2011
  18237. * @brief This file provides all the CRC firmware functions.
  18238. ******************************************************************************
  18239. * @attention
  18240. *
  18241. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  18242. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  18243. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  18244. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  18245. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  18246. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18247. *
  18248. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  18249. ******************************************************************************
  18250. */
  18251. /* Includes ------------------------------------------------------------------*/
  18252. #include "stm32f10x_crc.h"
  18253. /** @addtogroup STM32F10x_StdPeriph_Driver
  18254. * @{
  18255. */
  18256. /** @defgroup CRC
  18257. * @brief CRC driver modules
  18258. * @{
  18259. */
  18260. /** @defgroup CRC_Private_TypesDefinitions
  18261. * @{
  18262. */
  18263. /**
  18264. * @}
  18265. */
  18266. /** @defgroup CRC_Private_Defines
  18267. * @{
  18268. */
  18269. /**
  18270. * @}
  18271. */
  18272. /** @defgroup CRC_Private_Macros
  18273. * @{
  18274. */
  18275. /**
  18276. * @}
  18277. */
  18278. /** @defgroup CRC_Private_Variables
  18279. * @{
  18280. */
  18281. /**
  18282. * @}
  18283. */
  18284. /** @defgroup CRC_Private_FunctionPrototypes
  18285. * @{
  18286. */
  18287. /**
  18288. * @}
  18289. */
  18290. /** @defgroup CRC_Private_Functions
  18291. * @{
  18292. */
  18293. /**
  18294. * @brief Resets the CRC Data register (DR).
  18295. * @param None
  18296. * @retval None
  18297. */
  18298. void CRC_ResetDR(void)
  18299. {
  18300. /* Reset CRC generator */
  18301. CRC->CR = CRC_CR_RESET;
  18302. }
  18303. /**
  18304. * @brief Computes the 32-bit CRC of a given data word(32-bit).
  18305. * @param Data: data word(32-bit) to compute its CRC
  18306. * @retval 32-bit CRC
  18307. */
  18308. uint32_t CRC_CalcCRC(uint32_t Data)
  18309. {
  18310. CRC->DR = Data;
  18311. return (CRC->DR);
  18312. }
  18313. /**
  18314. * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit).
  18315. * @param pBuffer: pointer to the buffer containing the data to be computed
  18316. * @param BufferLength: length of the buffer to be computed
  18317. * @retval 32-bit CRC
  18318. */
  18319. uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength)
  18320. {
  18321. uint32_t index = 0;
  18322. for(index = 0; index < BufferLength; index++)
  18323. {
  18324. CRC->DR = pBuffer[index];
  18325. }
  18326. return (CRC->DR);
  18327. }
  18328. /**
  18329. * @brief Returns the current CRC value.
  18330. * @param None
  18331. * @retval 32-bit CRC
  18332. */
  18333. uint32_t CRC_GetCRC(void)
  18334. {
  18335. return (CRC->DR);
  18336. }
  18337. /**
  18338. * @brief Stores a 8-bit data in the Independent Data(ID) register.
  18339. * @param IDValue: 8-bit value to be stored in the ID register
  18340. * @retval None
  18341. */
  18342. void CRC_SetIDRegister(uint8_t IDValue)
  18343. {
  18344. CRC->IDR = IDValue;
  18345. }
  18346. /**
  18347. * @brief Returns the 8-bit data stored in the Independent Data(ID) register
  18348. * @param None
  18349. * @retval 8-bit value of the ID register
  18350. */
  18351. uint8_t CRC_GetIDRegister(void)
  18352. {
  18353. return (CRC->IDR);
  18354. }
  18355. /**
  18356. * @}
  18357. */
  18358. /**
  18359. * @}
  18360. */
  18361. /**
  18362. * @}
  18363. */
  18364. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  18365. /**
  18366. ******************************************************************************
  18367. * @file stm32f10x_pwr.c
  18368. * @author MCD Application Team
  18369. * @version V3.5.0
  18370. * @date 11-March-2011
  18371. * @brief This file provides all the PWR firmware functions.
  18372. ******************************************************************************
  18373. * @attention
  18374. *
  18375. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  18376. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  18377. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  18378. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  18379. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  18380. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18381. *
  18382. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  18383. ******************************************************************************
  18384. */
  18385. /* Includes ------------------------------------------------------------------*/
  18386. #include "stm32f10x_pwr.h"
  18387. #include "stm32f10x_rcc.h"
  18388. /** @addtogroup STM32F10x_StdPeriph_Driver
  18389. * @{
  18390. */
  18391. /** @defgroup PWR
  18392. * @brief PWR driver modules
  18393. * @{
  18394. */
  18395. /** @defgroup PWR_Private_TypesDefinitions
  18396. * @{
  18397. */
  18398. /**
  18399. * @}
  18400. */
  18401. /** @defgroup PWR_Private_Defines
  18402. * @{
  18403. */
  18404. /* --------- PWR registers bit address in the alias region ---------- */
  18405. #define PWR_OFFSET (PWR_BASE - PERIPH_BASE)
  18406. /* --- CR Register ---*/
  18407. /* Alias word address of DBP bit */
  18408. #define CR_OFFSET (PWR_OFFSET + 0x00)
  18409. #define DBP_BitNumber 0x08
  18410. #define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))
  18411. /* Alias word address of PVDE bit */
  18412. #define PVDE_BitNumber 0x04
  18413. #define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4))
  18414. /* --- CSR Register ---*/
  18415. /* Alias word address of EWUP bit */
  18416. #define CSR_OFFSET (PWR_OFFSET + 0x04)
  18417. #define EWUP_BitNumber 0x08
  18418. #define CSR_EWUP_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4))
  18419. /* ------------------ PWR registers bit mask ------------------------ */
  18420. /* CR register bit mask */
  18421. #define CR_DS_MASK ((uint32_t)0xFFFFFFFC)
  18422. #define CR_PLS_MASK ((uint32_t)0xFFFFFF1F)
  18423. /**
  18424. * @}
  18425. */
  18426. /** @defgroup PWR_Private_Macros
  18427. * @{
  18428. */
  18429. /**
  18430. * @}
  18431. */
  18432. /** @defgroup PWR_Private_Variables
  18433. * @{
  18434. */
  18435. /**
  18436. * @}
  18437. */
  18438. /** @defgroup PWR_Private_FunctionPrototypes
  18439. * @{
  18440. */
  18441. /**
  18442. * @}
  18443. */
  18444. /** @defgroup PWR_Private_Functions
  18445. * @{
  18446. */
  18447. /**
  18448. * @brief Deinitializes the PWR peripheral registers to their default reset values.
  18449. * @param None
  18450. * @retval None
  18451. */
  18452. void PWR_DeInit(void)
  18453. {
  18454. RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
  18455. RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
  18456. }
  18457. /**
  18458. * @brief Enables or disables access to the RTC and backup registers.
  18459. * @param NewState: new state of the access to the RTC and backup registers.
  18460. * This parameter can be: ENABLE or DISABLE.
  18461. * @retval None
  18462. */
  18463. void PWR_BackupAccessCmd(FunctionalState NewState)
  18464. {
  18465. /* Check the parameters */
  18466. assert_param(IS_FUNCTIONAL_STATE(NewState));
  18467. *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState;
  18468. }
  18469. /**
  18470. * @brief Enables or disables the Power Voltage Detector(PVD).
  18471. * @param NewState: new state of the PVD.
  18472. * This parameter can be: ENABLE or DISABLE.
  18473. * @retval None
  18474. */
  18475. void PWR_PVDCmd(FunctionalState NewState)
  18476. {
  18477. /* Check the parameters */
  18478. assert_param(IS_FUNCTIONAL_STATE(NewState));
  18479. *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState;
  18480. }
  18481. /**
  18482. * @brief Configures the voltage threshold detected by the Power Voltage Detector(PVD).
  18483. * @param PWR_PVDLevel: specifies the PVD detection level
  18484. * This parameter can be one of the following values:
  18485. * @arg PWR_PVDLevel_2V2: PVD detection level set to 2.2V
  18486. * @arg PWR_PVDLevel_2V3: PVD detection level set to 2.3V
  18487. * @arg PWR_PVDLevel_2V4: PVD detection level set to 2.4V
  18488. * @arg PWR_PVDLevel_2V5: PVD detection level set to 2.5V
  18489. * @arg PWR_PVDLevel_2V6: PVD detection level set to 2.6V
  18490. * @arg PWR_PVDLevel_2V7: PVD detection level set to 2.7V
  18491. * @arg PWR_PVDLevel_2V8: PVD detection level set to 2.8V
  18492. * @arg PWR_PVDLevel_2V9: PVD detection level set to 2.9V
  18493. * @retval None
  18494. */
  18495. void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel)
  18496. {
  18497. uint32_t tmpreg = 0;
  18498. /* Check the parameters */
  18499. assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel));
  18500. tmpreg = PWR->CR;
  18501. /* Clear PLS[7:5] bits */
  18502. tmpreg &= CR_PLS_MASK;
  18503. /* Set PLS[7:5] bits according to PWR_PVDLevel value */
  18504. tmpreg |= PWR_PVDLevel;
  18505. /* Store the new value */
  18506. PWR->CR = tmpreg;
  18507. }
  18508. /**
  18509. * @brief Enables or disables the WakeUp Pin functionality.
  18510. * @param NewState: new state of the WakeUp Pin functionality.
  18511. * This parameter can be: ENABLE or DISABLE.
  18512. * @retval None
  18513. */
  18514. void PWR_WakeUpPinCmd(FunctionalState NewState)
  18515. {
  18516. /* Check the parameters */
  18517. assert_param(IS_FUNCTIONAL_STATE(NewState));
  18518. *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)NewState;
  18519. }
  18520. /**
  18521. * @brief Enters STOP mode.
  18522. * @param PWR_Regulator: specifies the regulator state in STOP mode.
  18523. * This parameter can be one of the following values:
  18524. * @arg PWR_Regulator_ON: STOP mode with regulator ON
  18525. * @arg PWR_Regulator_LowPower: STOP mode with regulator in low power mode
  18526. * @param PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.
  18527. * This parameter can be one of the following values:
  18528. * @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
  18529. * @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
  18530. * @retval None
  18531. */
  18532. void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
  18533. {
  18534. uint32_t tmpreg = 0;
  18535. /* Check the parameters */
  18536. assert_param(IS_PWR_REGULATOR(PWR_Regulator));
  18537. assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
  18538. /* Select the regulator state in STOP mode ---------------------------------*/
  18539. tmpreg = PWR->CR;
  18540. /* Clear PDDS and LPDS bits */
  18541. tmpreg &= CR_DS_MASK;
  18542. /* Set LPDS bit according to PWR_Regulator value */
  18543. tmpreg |= PWR_Regulator;
  18544. /* Store the new value */
  18545. PWR->CR = tmpreg;
  18546. /* Set SLEEPDEEP bit of Cortex System Control Register */
  18547. SCB->SCR |= SCB_SCR_SLEEPDEEP;
  18548. /* Select STOP mode entry --------------------------------------------------*/
  18549. if(PWR_STOPEntry == PWR_STOPEntry_WFI)
  18550. {
  18551. /* Request Wait For Interrupt */
  18552. __WFI();
  18553. }
  18554. else
  18555. {
  18556. /* Request Wait For Event */
  18557. __WFE();
  18558. }
  18559. /* Reset SLEEPDEEP bit of Cortex System Control Register */
  18560. SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP);
  18561. }
  18562. /**
  18563. * @brief Enters STANDBY mode.
  18564. * @param None
  18565. * @retval None
  18566. */
  18567. void PWR_EnterSTANDBYMode(void)
  18568. {
  18569. /* Clear Wake-up flag */
  18570. PWR->CR |= PWR_CR_CWUF;
  18571. /* Select STANDBY mode */
  18572. PWR->CR |= PWR_CR_PDDS;
  18573. /* Set SLEEPDEEP bit of Cortex System Control Register */
  18574. SCB->SCR |= SCB_SCR_SLEEPDEEP;
  18575. /* This option is used to ensure that store operations are completed */
  18576. #if defined ( __CC_ARM )
  18577. __force_stores();
  18578. #endif
  18579. /* Request Wait For Interrupt */
  18580. __WFI();
  18581. }
  18582. /**
  18583. * @brief Checks whether the specified PWR flag is set or not.
  18584. * @param PWR_FLAG: specifies the flag to check.
  18585. * This parameter can be one of the following values:
  18586. * @arg PWR_FLAG_WU: Wake Up flag
  18587. * @arg PWR_FLAG_SB: StandBy flag
  18588. * @arg PWR_FLAG_PVDO: PVD Output
  18589. * @retval The new state of PWR_FLAG (SET or RESET).
  18590. */
  18591. FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG)
  18592. {
  18593. FlagStatus bitstatus = RESET;
  18594. /* Check the parameters */
  18595. assert_param(IS_PWR_GET_FLAG(PWR_FLAG));
  18596. if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET)
  18597. {
  18598. bitstatus = SET;
  18599. }
  18600. else
  18601. {
  18602. bitstatus = RESET;
  18603. }
  18604. /* Return the flag status */
  18605. return bitstatus;
  18606. }
  18607. /**
  18608. * @brief Clears the PWR's pending flags.
  18609. * @param PWR_FLAG: specifies the flag to clear.
  18610. * This parameter can be one of the following values:
  18611. * @arg PWR_FLAG_WU: Wake Up flag
  18612. * @arg PWR_FLAG_SB: StandBy flag
  18613. * @retval None
  18614. */
  18615. void PWR_ClearFlag(uint32_t PWR_FLAG)
  18616. {
  18617. /* Check the parameters */
  18618. assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG));
  18619. PWR->CR |= PWR_FLAG << 2;
  18620. }
  18621. /**
  18622. * @}
  18623. */
  18624. /**
  18625. * @}
  18626. */
  18627. /**
  18628. * @}
  18629. */
  18630. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  18631. /**
  18632. ******************************************************************************
  18633. * @file stm32f10x_spi.c
  18634. * @author MCD Application Team
  18635. * @version V3.5.0
  18636. * @date 11-March-2011
  18637. * @brief This file provides all the SPI firmware functions.
  18638. ******************************************************************************
  18639. * @attention
  18640. *
  18641. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  18642. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  18643. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  18644. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  18645. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  18646. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18647. *
  18648. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  18649. ******************************************************************************
  18650. */
  18651. /* Includes ------------------------------------------------------------------*/
  18652. #include "stm32f10x_spi.h"
  18653. #include "stm32f10x_rcc.h"
  18654. /** @addtogroup STM32F10x_StdPeriph_Driver
  18655. * @{
  18656. */
  18657. /** @defgroup SPI
  18658. * @brief SPI driver modules
  18659. * @{
  18660. */
  18661. /** @defgroup SPI_Private_TypesDefinitions
  18662. * @{
  18663. */
  18664. /**
  18665. * @}
  18666. */
  18667. /** @defgroup SPI_Private_Defines
  18668. * @{
  18669. */
  18670. /* SPI SPE mask */
  18671. #define CR1_SPE_Set ((uint16_t)0x0040)
  18672. #define CR1_SPE_Reset ((uint16_t)0xFFBF)
  18673. /* I2S I2SE mask */
  18674. #define I2SCFGR_I2SE_Set ((uint16_t)0x0400)
  18675. #define I2SCFGR_I2SE_Reset ((uint16_t)0xFBFF)
  18676. /* SPI CRCNext mask */
  18677. #define CR1_CRCNext_Set ((uint16_t)0x1000)
  18678. /* SPI CRCEN mask */
  18679. #define CR1_CRCEN_Set ((uint16_t)0x2000)
  18680. #define CR1_CRCEN_Reset ((uint16_t)0xDFFF)
  18681. /* SPI SSOE mask */
  18682. #define CR2_SSOE_Set ((uint16_t)0x0004)
  18683. #define CR2_SSOE_Reset ((uint16_t)0xFFFB)
  18684. /* SPI registers Masks */
  18685. #define CR1_CLEAR_Mask ((uint16_t)0x3040)
  18686. #define I2SCFGR_CLEAR_Mask ((uint16_t)0xF040)
  18687. /* SPI or I2S mode selection masks */
  18688. #define SPI_Mode_Select ((uint16_t)0xF7FF)
  18689. #define I2S_Mode_Select ((uint16_t)0x0800)
  18690. /* I2S clock source selection masks */
  18691. #define I2S2_CLOCK_SRC ((uint32_t)(0x00020000))
  18692. #define I2S3_CLOCK_SRC ((uint32_t)(0x00040000))
  18693. #define I2S_MUL_MASK ((uint32_t)(0x0000F000))
  18694. #define I2S_DIV_MASK ((uint32_t)(0x000000F0))
  18695. /**
  18696. * @}
  18697. */
  18698. /** @defgroup SPI_Private_Macros
  18699. * @{
  18700. */
  18701. /**
  18702. * @}
  18703. */
  18704. /** @defgroup SPI_Private_Variables
  18705. * @{
  18706. */
  18707. /**
  18708. * @}
  18709. */
  18710. /** @defgroup SPI_Private_FunctionPrototypes
  18711. * @{
  18712. */
  18713. /**
  18714. * @}
  18715. */
  18716. /** @defgroup SPI_Private_Functions
  18717. * @{
  18718. */
  18719. /**
  18720. * @brief Deinitializes the SPIx peripheral registers to their default
  18721. * reset values (Affects also the I2Ss).
  18722. * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
  18723. * @retval None
  18724. */
  18725. void SPI_I2S_DeInit(SPI_TypeDef* SPIx)
  18726. {
  18727. /* Check the parameters */
  18728. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  18729. if (SPIx == SPI1)
  18730. {
  18731. /* Enable SPI1 reset state */
  18732. RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
  18733. /* Release SPI1 from reset state */
  18734. RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
  18735. }
  18736. else if (SPIx == SPI2)
  18737. {
  18738. /* Enable SPI2 reset state */
  18739. RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
  18740. /* Release SPI2 from reset state */
  18741. RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
  18742. }
  18743. else
  18744. {
  18745. if (SPIx == SPI3)
  18746. {
  18747. /* Enable SPI3 reset state */
  18748. RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
  18749. /* Release SPI3 from reset state */
  18750. RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);
  18751. }
  18752. }
  18753. }
  18754. /**
  18755. * @brief Initializes the SPIx peripheral according to the specified
  18756. * parameters in the SPI_InitStruct.
  18757. * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
  18758. * @param SPI_InitStruct: pointer to a SPI_InitTypeDef structure that
  18759. * contains the configuration information for the specified SPI peripheral.
  18760. * @retval None
  18761. */
  18762. void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct)
  18763. {
  18764. uint16_t tmpreg = 0;
  18765. /* check the parameters */
  18766. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  18767. /* Check the SPI parameters */
  18768. assert_param(IS_SPI_DIRECTION_MODE(SPI_InitStruct->SPI_Direction));
  18769. assert_param(IS_SPI_MODE(SPI_InitStruct->SPI_Mode));
  18770. assert_param(IS_SPI_DATASIZE(SPI_InitStruct->SPI_DataSize));
  18771. assert_param(IS_SPI_CPOL(SPI_InitStruct->SPI_CPOL));
  18772. assert_param(IS_SPI_CPHA(SPI_InitStruct->SPI_CPHA));
  18773. assert_param(IS_SPI_NSS(SPI_InitStruct->SPI_NSS));
  18774. assert_param(IS_SPI_BAUDRATE_PRESCALER(SPI_InitStruct->SPI_BaudRatePrescaler));
  18775. assert_param(IS_SPI_FIRST_BIT(SPI_InitStruct->SPI_FirstBit));
  18776. assert_param(IS_SPI_CRC_POLYNOMIAL(SPI_InitStruct->SPI_CRCPolynomial));
  18777. /*---------------------------- SPIx CR1 Configuration ------------------------*/
  18778. /* Get the SPIx CR1 value */
  18779. tmpreg = SPIx->CR1;
  18780. /* Clear BIDIMode, BIDIOE, RxONLY, SSM, SSI, LSBFirst, BR, MSTR, CPOL and CPHA bits */
  18781. tmpreg &= CR1_CLEAR_Mask;
  18782. /* Configure SPIx: direction, NSS management, first transmitted bit, BaudRate prescaler
  18783. master/salve mode, CPOL and CPHA */
  18784. /* Set BIDImode, BIDIOE and RxONLY bits according to SPI_Direction value */
  18785. /* Set SSM, SSI and MSTR bits according to SPI_Mode and SPI_NSS values */
  18786. /* Set LSBFirst bit according to SPI_FirstBit value */
  18787. /* Set BR bits according to SPI_BaudRatePrescaler value */
  18788. /* Set CPOL bit according to SPI_CPOL value */
  18789. /* Set CPHA bit according to SPI_CPHA value */
  18790. tmpreg |= (uint16_t)((uint32_t)SPI_InitStruct->SPI_Direction | SPI_InitStruct->SPI_Mode |
  18791. SPI_InitStruct->SPI_DataSize | SPI_InitStruct->SPI_CPOL |
  18792. SPI_InitStruct->SPI_CPHA | SPI_InitStruct->SPI_NSS |
  18793. SPI_InitStruct->SPI_BaudRatePrescaler | SPI_InitStruct->SPI_FirstBit);
  18794. /* Write to SPIx CR1 */
  18795. SPIx->CR1 = tmpreg;
  18796. /* Activate the SPI mode (Reset I2SMOD bit in I2SCFGR register) */
  18797. SPIx->I2SCFGR &= SPI_Mode_Select;
  18798. /*---------------------------- SPIx CRCPOLY Configuration --------------------*/
  18799. /* Write to SPIx CRCPOLY */
  18800. SPIx->CRCPR = SPI_InitStruct->SPI_CRCPolynomial;
  18801. }
  18802. /**
  18803. * @brief Initializes the SPIx peripheral according to the specified
  18804. * parameters in the I2S_InitStruct.
  18805. * @param SPIx: where x can be 2 or 3 to select the SPI peripheral
  18806. * (configured in I2S mode).
  18807. * @param I2S_InitStruct: pointer to an I2S_InitTypeDef structure that
  18808. * contains the configuration information for the specified SPI peripheral
  18809. * configured in I2S mode.
  18810. * @note
  18811. * The function calculates the optimal prescaler needed to obtain the most
  18812. * accurate audio frequency (depending on the I2S clock source, the PLL values
  18813. * and the product configuration). But in case the prescaler value is greater
  18814. * than 511, the default value (0x02) will be configured instead. *
  18815. * @retval None
  18816. */
  18817. void I2S_Init(SPI_TypeDef* SPIx, I2S_InitTypeDef* I2S_InitStruct)
  18818. {
  18819. uint16_t tmpreg = 0, i2sdiv = 2, i2sodd = 0, packetlength = 1;
  18820. uint32_t tmp = 0;
  18821. RCC_ClocksTypeDef RCC_Clocks;
  18822. uint32_t sourceclock = 0;
  18823. /* Check the I2S parameters */
  18824. assert_param(IS_SPI_23_PERIPH(SPIx));
  18825. assert_param(IS_I2S_MODE(I2S_InitStruct->I2S_Mode));
  18826. assert_param(IS_I2S_STANDARD(I2S_InitStruct->I2S_Standard));
  18827. assert_param(IS_I2S_DATA_FORMAT(I2S_InitStruct->I2S_DataFormat));
  18828. assert_param(IS_I2S_MCLK_OUTPUT(I2S_InitStruct->I2S_MCLKOutput));
  18829. assert_param(IS_I2S_AUDIO_FREQ(I2S_InitStruct->I2S_AudioFreq));
  18830. assert_param(IS_I2S_CPOL(I2S_InitStruct->I2S_CPOL));
  18831. /*----------------------- SPIx I2SCFGR & I2SPR Configuration -----------------*/
  18832. /* Clear I2SMOD, I2SE, I2SCFG, PCMSYNC, I2SSTD, CKPOL, DATLEN and CHLEN bits */
  18833. SPIx->I2SCFGR &= I2SCFGR_CLEAR_Mask;
  18834. SPIx->I2SPR = 0x0002;
  18835. /* Get the I2SCFGR register value */
  18836. tmpreg = SPIx->I2SCFGR;
  18837. /* If the default value has to be written, reinitialize i2sdiv and i2sodd*/
  18838. if(I2S_InitStruct->I2S_AudioFreq == I2S_AudioFreq_Default)
  18839. {
  18840. i2sodd = (uint16_t)0;
  18841. i2sdiv = (uint16_t)2;
  18842. }
  18843. /* If the requested audio frequency is not the default, compute the prescaler */
  18844. else
  18845. {
  18846. /* Check the frame length (For the Prescaler computing) */
  18847. if(I2S_InitStruct->I2S_DataFormat == I2S_DataFormat_16b)
  18848. {
  18849. /* Packet length is 16 bits */
  18850. packetlength = 1;
  18851. }
  18852. else
  18853. {
  18854. /* Packet length is 32 bits */
  18855. packetlength = 2;
  18856. }
  18857. /* Get the I2S clock source mask depending on the peripheral number */
  18858. if(((uint32_t)SPIx) == SPI2_BASE)
  18859. {
  18860. /* The mask is relative to I2S2 */
  18861. tmp = I2S2_CLOCK_SRC;
  18862. }
  18863. else
  18864. {
  18865. /* The mask is relative to I2S3 */
  18866. tmp = I2S3_CLOCK_SRC;
  18867. }
  18868. /* Check the I2S clock source configuration depending on the Device:
  18869. Only Connectivity line devices have the PLL3 VCO clock */
  18870. #ifdef STM32F10X_CL
  18871. if((RCC->CFGR2 & tmp) != 0)
  18872. {
  18873. /* Get the configuration bits of RCC PLL3 multiplier */
  18874. tmp = (uint32_t)((RCC->CFGR2 & I2S_MUL_MASK) >> 12);
  18875. /* Get the value of the PLL3 multiplier */
  18876. if((tmp > 5) && (tmp < 15))
  18877. {
  18878. /* Multiplier is between 8 and 14 (value 15 is forbidden) */
  18879. tmp += 2;
  18880. }
  18881. else
  18882. {
  18883. if (tmp == 15)
  18884. {
  18885. /* Multiplier is 20 */
  18886. tmp = 20;
  18887. }
  18888. }
  18889. /* Get the PREDIV2 value */
  18890. sourceclock = (uint32_t)(((RCC->CFGR2 & I2S_DIV_MASK) >> 4) + 1);
  18891. /* Calculate the Source Clock frequency based on PLL3 and PREDIV2 values */
  18892. sourceclock = (uint32_t) ((HSE_Value / sourceclock) * tmp * 2);
  18893. }
  18894. else
  18895. {
  18896. /* I2S Clock source is System clock: Get System Clock frequency */
  18897. RCC_GetClocksFreq(&RCC_Clocks);
  18898. /* Get the source clock value: based on System Clock value */
  18899. sourceclock = RCC_Clocks.SYSCLK_Frequency;
  18900. }
  18901. #else /* STM32F10X_HD */
  18902. /* I2S Clock source is System clock: Get System Clock frequency */
  18903. RCC_GetClocksFreq(&RCC_Clocks);
  18904. /* Get the source clock value: based on System Clock value */
  18905. sourceclock = RCC_Clocks.SYSCLK_Frequency;
  18906. #endif /* STM32F10X_CL */
  18907. /* Compute the Real divider depending on the MCLK output state with a floating point */
  18908. if(I2S_InitStruct->I2S_MCLKOutput == I2S_MCLKOutput_Enable)
  18909. {
  18910. /* MCLK output is enabled */
  18911. tmp = (uint16_t)(((((sourceclock / 256) * 10) / I2S_InitStruct->I2S_AudioFreq)) + 5);
  18912. }
  18913. else
  18914. {
  18915. /* MCLK output is disabled */
  18916. tmp = (uint16_t)(((((sourceclock / (32 * packetlength)) *10 ) / I2S_InitStruct->I2S_AudioFreq)) + 5);
  18917. }
  18918. /* Remove the floating point */
  18919. tmp = tmp / 10;
  18920. /* Check the parity of the divider */
  18921. i2sodd = (uint16_t)(tmp & (uint16_t)0x0001);
  18922. /* Compute the i2sdiv prescaler */
  18923. i2sdiv = (uint16_t)((tmp - i2sodd) / 2);
  18924. /* Get the Mask for the Odd bit (SPI_I2SPR[8]) register */
  18925. i2sodd = (uint16_t) (i2sodd << 8);
  18926. }
  18927. /* Test if the divider is 1 or 0 or greater than 0xFF */
  18928. if ((i2sdiv < 2) || (i2sdiv > 0xFF))
  18929. {
  18930. /* Set the default values */
  18931. i2sdiv = 2;
  18932. i2sodd = 0;
  18933. }
  18934. /* Write to SPIx I2SPR register the computed value */
  18935. SPIx->I2SPR = (uint16_t)(i2sdiv | (uint16_t)(i2sodd | (uint16_t)I2S_InitStruct->I2S_MCLKOutput));
  18936. /* Configure the I2S with the SPI_InitStruct values */
  18937. tmpreg |= (uint16_t)(I2S_Mode_Select | (uint16_t)(I2S_InitStruct->I2S_Mode | \
  18938. (uint16_t)(I2S_InitStruct->I2S_Standard | (uint16_t)(I2S_InitStruct->I2S_DataFormat | \
  18939. (uint16_t)I2S_InitStruct->I2S_CPOL))));
  18940. /* Write to SPIx I2SCFGR */
  18941. SPIx->I2SCFGR = tmpreg;
  18942. }
  18943. /**
  18944. * @brief Fills each SPI_InitStruct member with its default value.
  18945. * @param SPI_InitStruct : pointer to a SPI_InitTypeDef structure which will be initialized.
  18946. * @retval None
  18947. */
  18948. void SPI_StructInit(SPI_InitTypeDef* SPI_InitStruct)
  18949. {
  18950. /*--------------- Reset SPI init structure parameters values -----------------*/
  18951. /* Initialize the SPI_Direction member */
  18952. SPI_InitStruct->SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  18953. /* initialize the SPI_Mode member */
  18954. SPI_InitStruct->SPI_Mode = SPI_Mode_Slave;
  18955. /* initialize the SPI_DataSize member */
  18956. SPI_InitStruct->SPI_DataSize = SPI_DataSize_8b;
  18957. /* Initialize the SPI_CPOL member */
  18958. SPI_InitStruct->SPI_CPOL = SPI_CPOL_Low;
  18959. /* Initialize the SPI_CPHA member */
  18960. SPI_InitStruct->SPI_CPHA = SPI_CPHA_1Edge;
  18961. /* Initialize the SPI_NSS member */
  18962. SPI_InitStruct->SPI_NSS = SPI_NSS_Hard;
  18963. /* Initialize the SPI_BaudRatePrescaler member */
  18964. SPI_InitStruct->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
  18965. /* Initialize the SPI_FirstBit member */
  18966. SPI_InitStruct->SPI_FirstBit = SPI_FirstBit_MSB;
  18967. /* Initialize the SPI_CRCPolynomial member */
  18968. SPI_InitStruct->SPI_CRCPolynomial = 7;
  18969. }
  18970. /**
  18971. * @brief Fills each I2S_InitStruct member with its default value.
  18972. * @param I2S_InitStruct : pointer to a I2S_InitTypeDef structure which will be initialized.
  18973. * @retval None
  18974. */
  18975. void I2S_StructInit(I2S_InitTypeDef* I2S_InitStruct)
  18976. {
  18977. /*--------------- Reset I2S init structure parameters values -----------------*/
  18978. /* Initialize the I2S_Mode member */
  18979. I2S_InitStruct->I2S_Mode = I2S_Mode_SlaveTx;
  18980. /* Initialize the I2S_Standard member */
  18981. I2S_InitStruct->I2S_Standard = I2S_Standard_Phillips;
  18982. /* Initialize the I2S_DataFormat member */
  18983. I2S_InitStruct->I2S_DataFormat = I2S_DataFormat_16b;
  18984. /* Initialize the I2S_MCLKOutput member */
  18985. I2S_InitStruct->I2S_MCLKOutput = I2S_MCLKOutput_Disable;
  18986. /* Initialize the I2S_AudioFreq member */
  18987. I2S_InitStruct->I2S_AudioFreq = I2S_AudioFreq_Default;
  18988. /* Initialize the I2S_CPOL member */
  18989. I2S_InitStruct->I2S_CPOL = I2S_CPOL_Low;
  18990. }
  18991. /**
  18992. * @brief Enables or disables the specified SPI peripheral.
  18993. * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
  18994. * @param NewState: new state of the SPIx peripheral.
  18995. * This parameter can be: ENABLE or DISABLE.
  18996. * @retval None
  18997. */
  18998. void SPI_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
  18999. {
  19000. /* Check the parameters */
  19001. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19002. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19003. if (NewState != DISABLE)
  19004. {
  19005. /* Enable the selected SPI peripheral */
  19006. SPIx->CR1 |= CR1_SPE_Set;
  19007. }
  19008. else
  19009. {
  19010. /* Disable the selected SPI peripheral */
  19011. SPIx->CR1 &= CR1_SPE_Reset;
  19012. }
  19013. }
  19014. /**
  19015. * @brief Enables or disables the specified SPI peripheral (in I2S mode).
  19016. * @param SPIx: where x can be 2 or 3 to select the SPI peripheral.
  19017. * @param NewState: new state of the SPIx peripheral.
  19018. * This parameter can be: ENABLE or DISABLE.
  19019. * @retval None
  19020. */
  19021. void I2S_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
  19022. {
  19023. /* Check the parameters */
  19024. assert_param(IS_SPI_23_PERIPH(SPIx));
  19025. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19026. if (NewState != DISABLE)
  19027. {
  19028. /* Enable the selected SPI peripheral (in I2S mode) */
  19029. SPIx->I2SCFGR |= I2SCFGR_I2SE_Set;
  19030. }
  19031. else
  19032. {
  19033. /* Disable the selected SPI peripheral (in I2S mode) */
  19034. SPIx->I2SCFGR &= I2SCFGR_I2SE_Reset;
  19035. }
  19036. }
  19037. /**
  19038. * @brief Enables or disables the specified SPI/I2S interrupts.
  19039. * @param SPIx: where x can be
  19040. * - 1, 2 or 3 in SPI mode
  19041. * - 2 or 3 in I2S mode
  19042. * @param SPI_I2S_IT: specifies the SPI/I2S interrupt source to be enabled or disabled.
  19043. * This parameter can be one of the following values:
  19044. * @arg SPI_I2S_IT_TXE: Tx buffer empty interrupt mask
  19045. * @arg SPI_I2S_IT_RXNE: Rx buffer not empty interrupt mask
  19046. * @arg SPI_I2S_IT_ERR: Error interrupt mask
  19047. * @param NewState: new state of the specified SPI/I2S interrupt.
  19048. * This parameter can be: ENABLE or DISABLE.
  19049. * @retval None
  19050. */
  19051. void SPI_I2S_ITConfig(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState)
  19052. {
  19053. uint16_t itpos = 0, itmask = 0 ;
  19054. /* Check the parameters */
  19055. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19056. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19057. assert_param(IS_SPI_I2S_CONFIG_IT(SPI_I2S_IT));
  19058. /* Get the SPI/I2S IT index */
  19059. itpos = SPI_I2S_IT >> 4;
  19060. /* Set the IT mask */
  19061. itmask = (uint16_t)1 << (uint16_t)itpos;
  19062. if (NewState != DISABLE)
  19063. {
  19064. /* Enable the selected SPI/I2S interrupt */
  19065. SPIx->CR2 |= itmask;
  19066. }
  19067. else
  19068. {
  19069. /* Disable the selected SPI/I2S interrupt */
  19070. SPIx->CR2 &= (uint16_t)~itmask;
  19071. }
  19072. }
  19073. /**
  19074. * @brief Enables or disables the SPIx/I2Sx DMA interface.
  19075. * @param SPIx: where x can be
  19076. * - 1, 2 or 3 in SPI mode
  19077. * - 2 or 3 in I2S mode
  19078. * @param SPI_I2S_DMAReq: specifies the SPI/I2S DMA transfer request to be enabled or disabled.
  19079. * This parameter can be any combination of the following values:
  19080. * @arg SPI_I2S_DMAReq_Tx: Tx buffer DMA transfer request
  19081. * @arg SPI_I2S_DMAReq_Rx: Rx buffer DMA transfer request
  19082. * @param NewState: new state of the selected SPI/I2S DMA transfer request.
  19083. * This parameter can be: ENABLE or DISABLE.
  19084. * @retval None
  19085. */
  19086. void SPI_I2S_DMACmd(SPI_TypeDef* SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState)
  19087. {
  19088. /* Check the parameters */
  19089. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19090. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19091. assert_param(IS_SPI_I2S_DMAREQ(SPI_I2S_DMAReq));
  19092. if (NewState != DISABLE)
  19093. {
  19094. /* Enable the selected SPI/I2S DMA requests */
  19095. SPIx->CR2 |= SPI_I2S_DMAReq;
  19096. }
  19097. else
  19098. {
  19099. /* Disable the selected SPI/I2S DMA requests */
  19100. SPIx->CR2 &= (uint16_t)~SPI_I2S_DMAReq;
  19101. }
  19102. }
  19103. /**
  19104. * @brief Transmits a Data through the SPIx/I2Sx peripheral.
  19105. * @param SPIx: where x can be
  19106. * - 1, 2 or 3 in SPI mode
  19107. * - 2 or 3 in I2S mode
  19108. * @param Data : Data to be transmitted.
  19109. * @retval None
  19110. */
  19111. void SPI_I2S_SendData(SPI_TypeDef* SPIx, uint16_t Data)
  19112. {
  19113. /* Check the parameters */
  19114. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19115. /* Write in the DR register the data to be sent */
  19116. SPIx->DR = Data;
  19117. }
  19118. /**
  19119. * @brief Returns the most recent received data by the SPIx/I2Sx peripheral.
  19120. * @param SPIx: where x can be
  19121. * - 1, 2 or 3 in SPI mode
  19122. * - 2 or 3 in I2S mode
  19123. * @retval The value of the received data.
  19124. */
  19125. uint16_t SPI_I2S_ReceiveData(SPI_TypeDef* SPIx)
  19126. {
  19127. /* Check the parameters */
  19128. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19129. /* Return the data in the DR register */
  19130. return SPIx->DR;
  19131. }
  19132. /**
  19133. * @brief Configures internally by software the NSS pin for the selected SPI.
  19134. * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
  19135. * @param SPI_NSSInternalSoft: specifies the SPI NSS internal state.
  19136. * This parameter can be one of the following values:
  19137. * @arg SPI_NSSInternalSoft_Set: Set NSS pin internally
  19138. * @arg SPI_NSSInternalSoft_Reset: Reset NSS pin internally
  19139. * @retval None
  19140. */
  19141. void SPI_NSSInternalSoftwareConfig(SPI_TypeDef* SPIx, uint16_t SPI_NSSInternalSoft)
  19142. {
  19143. /* Check the parameters */
  19144. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19145. assert_param(IS_SPI_NSS_INTERNAL(SPI_NSSInternalSoft));
  19146. if (SPI_NSSInternalSoft != SPI_NSSInternalSoft_Reset)
  19147. {
  19148. /* Set NSS pin internally by software */
  19149. SPIx->CR1 |= SPI_NSSInternalSoft_Set;
  19150. }
  19151. else
  19152. {
  19153. /* Reset NSS pin internally by software */
  19154. SPIx->CR1 &= SPI_NSSInternalSoft_Reset;
  19155. }
  19156. }
  19157. /**
  19158. * @brief Enables or disables the SS output for the selected SPI.
  19159. * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
  19160. * @param NewState: new state of the SPIx SS output.
  19161. * This parameter can be: ENABLE or DISABLE.
  19162. * @retval None
  19163. */
  19164. void SPI_SSOutputCmd(SPI_TypeDef* SPIx, FunctionalState NewState)
  19165. {
  19166. /* Check the parameters */
  19167. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19168. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19169. if (NewState != DISABLE)
  19170. {
  19171. /* Enable the selected SPI SS output */
  19172. SPIx->CR2 |= CR2_SSOE_Set;
  19173. }
  19174. else
  19175. {
  19176. /* Disable the selected SPI SS output */
  19177. SPIx->CR2 &= CR2_SSOE_Reset;
  19178. }
  19179. }
  19180. /**
  19181. * @brief Configures the data size for the selected SPI.
  19182. * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
  19183. * @param SPI_DataSize: specifies the SPI data size.
  19184. * This parameter can be one of the following values:
  19185. * @arg SPI_DataSize_16b: Set data frame format to 16bit
  19186. * @arg SPI_DataSize_8b: Set data frame format to 8bit
  19187. * @retval None
  19188. */
  19189. void SPI_DataSizeConfig(SPI_TypeDef* SPIx, uint16_t SPI_DataSize)
  19190. {
  19191. /* Check the parameters */
  19192. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19193. assert_param(IS_SPI_DATASIZE(SPI_DataSize));
  19194. /* Clear DFF bit */
  19195. SPIx->CR1 &= (uint16_t)~SPI_DataSize_16b;
  19196. /* Set new DFF bit value */
  19197. SPIx->CR1 |= SPI_DataSize;
  19198. }
  19199. /**
  19200. * @brief Transmit the SPIx CRC value.
  19201. * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
  19202. * @retval None
  19203. */
  19204. void SPI_TransmitCRC(SPI_TypeDef* SPIx)
  19205. {
  19206. /* Check the parameters */
  19207. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19208. /* Enable the selected SPI CRC transmission */
  19209. SPIx->CR1 |= CR1_CRCNext_Set;
  19210. }
  19211. /**
  19212. * @brief Enables or disables the CRC value calculation of the transferred bytes.
  19213. * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
  19214. * @param NewState: new state of the SPIx CRC value calculation.
  19215. * This parameter can be: ENABLE or DISABLE.
  19216. * @retval None
  19217. */
  19218. void SPI_CalculateCRC(SPI_TypeDef* SPIx, FunctionalState NewState)
  19219. {
  19220. /* Check the parameters */
  19221. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19222. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19223. if (NewState != DISABLE)
  19224. {
  19225. /* Enable the selected SPI CRC calculation */
  19226. SPIx->CR1 |= CR1_CRCEN_Set;
  19227. }
  19228. else
  19229. {
  19230. /* Disable the selected SPI CRC calculation */
  19231. SPIx->CR1 &= CR1_CRCEN_Reset;
  19232. }
  19233. }
  19234. /**
  19235. * @brief Returns the transmit or the receive CRC register value for the specified SPI.
  19236. * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
  19237. * @param SPI_CRC: specifies the CRC register to be read.
  19238. * This parameter can be one of the following values:
  19239. * @arg SPI_CRC_Tx: Selects Tx CRC register
  19240. * @arg SPI_CRC_Rx: Selects Rx CRC register
  19241. * @retval The selected CRC register value..
  19242. */
  19243. uint16_t SPI_GetCRC(SPI_TypeDef* SPIx, uint8_t SPI_CRC)
  19244. {
  19245. uint16_t crcreg = 0;
  19246. /* Check the parameters */
  19247. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19248. assert_param(IS_SPI_CRC(SPI_CRC));
  19249. if (SPI_CRC != SPI_CRC_Rx)
  19250. {
  19251. /* Get the Tx CRC register */
  19252. crcreg = SPIx->TXCRCR;
  19253. }
  19254. else
  19255. {
  19256. /* Get the Rx CRC register */
  19257. crcreg = SPIx->RXCRCR;
  19258. }
  19259. /* Return the selected CRC register */
  19260. return crcreg;
  19261. }
  19262. /**
  19263. * @brief Returns the CRC Polynomial register value for the specified SPI.
  19264. * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
  19265. * @retval The CRC Polynomial register value.
  19266. */
  19267. uint16_t SPI_GetCRCPolynomial(SPI_TypeDef* SPIx)
  19268. {
  19269. /* Check the parameters */
  19270. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19271. /* Return the CRC polynomial register */
  19272. return SPIx->CRCPR;
  19273. }
  19274. /**
  19275. * @brief Selects the data transfer direction in bi-directional mode for the specified SPI.
  19276. * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
  19277. * @param SPI_Direction: specifies the data transfer direction in bi-directional mode.
  19278. * This parameter can be one of the following values:
  19279. * @arg SPI_Direction_Tx: Selects Tx transmission direction
  19280. * @arg SPI_Direction_Rx: Selects Rx receive direction
  19281. * @retval None
  19282. */
  19283. void SPI_BiDirectionalLineConfig(SPI_TypeDef* SPIx, uint16_t SPI_Direction)
  19284. {
  19285. /* Check the parameters */
  19286. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19287. assert_param(IS_SPI_DIRECTION(SPI_Direction));
  19288. if (SPI_Direction == SPI_Direction_Tx)
  19289. {
  19290. /* Set the Tx only mode */
  19291. SPIx->CR1 |= SPI_Direction_Tx;
  19292. }
  19293. else
  19294. {
  19295. /* Set the Rx only mode */
  19296. SPIx->CR1 &= SPI_Direction_Rx;
  19297. }
  19298. }
  19299. /**
  19300. * @brief Checks whether the specified SPI/I2S flag is set or not.
  19301. * @param SPIx: where x can be
  19302. * - 1, 2 or 3 in SPI mode
  19303. * - 2 or 3 in I2S mode
  19304. * @param SPI_I2S_FLAG: specifies the SPI/I2S flag to check.
  19305. * This parameter can be one of the following values:
  19306. * @arg SPI_I2S_FLAG_TXE: Transmit buffer empty flag.
  19307. * @arg SPI_I2S_FLAG_RXNE: Receive buffer not empty flag.
  19308. * @arg SPI_I2S_FLAG_BSY: Busy flag.
  19309. * @arg SPI_I2S_FLAG_OVR: Overrun flag.
  19310. * @arg SPI_FLAG_MODF: Mode Fault flag.
  19311. * @arg SPI_FLAG_CRCERR: CRC Error flag.
  19312. * @arg I2S_FLAG_UDR: Underrun Error flag.
  19313. * @arg I2S_FLAG_CHSIDE: Channel Side flag.
  19314. * @retval The new state of SPI_I2S_FLAG (SET or RESET).
  19315. */
  19316. FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG)
  19317. {
  19318. FlagStatus bitstatus = RESET;
  19319. /* Check the parameters */
  19320. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19321. assert_param(IS_SPI_I2S_GET_FLAG(SPI_I2S_FLAG));
  19322. /* Check the status of the specified SPI/I2S flag */
  19323. if ((SPIx->SR & SPI_I2S_FLAG) != (uint16_t)RESET)
  19324. {
  19325. /* SPI_I2S_FLAG is set */
  19326. bitstatus = SET;
  19327. }
  19328. else
  19329. {
  19330. /* SPI_I2S_FLAG is reset */
  19331. bitstatus = RESET;
  19332. }
  19333. /* Return the SPI_I2S_FLAG status */
  19334. return bitstatus;
  19335. }
  19336. /**
  19337. * @brief Clears the SPIx CRC Error (CRCERR) flag.
  19338. * @param SPIx: where x can be
  19339. * - 1, 2 or 3 in SPI mode
  19340. * @param SPI_I2S_FLAG: specifies the SPI flag to clear.
  19341. * This function clears only CRCERR flag.
  19342. * @note
  19343. * - OVR (OverRun error) flag is cleared by software sequence: a read
  19344. * operation to SPI_DR register (SPI_I2S_ReceiveData()) followed by a read
  19345. * operation to SPI_SR register (SPI_I2S_GetFlagStatus()).
  19346. * - UDR (UnderRun error) flag is cleared by a read operation to
  19347. * SPI_SR register (SPI_I2S_GetFlagStatus()).
  19348. * - MODF (Mode Fault) flag is cleared by software sequence: a read/write
  19349. * operation to SPI_SR register (SPI_I2S_GetFlagStatus()) followed by a
  19350. * write operation to SPI_CR1 register (SPI_Cmd() to enable the SPI).
  19351. * @retval None
  19352. */
  19353. void SPI_I2S_ClearFlag(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG)
  19354. {
  19355. /* Check the parameters */
  19356. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19357. assert_param(IS_SPI_I2S_CLEAR_FLAG(SPI_I2S_FLAG));
  19358. /* Clear the selected SPI CRC Error (CRCERR) flag */
  19359. SPIx->SR = (uint16_t)~SPI_I2S_FLAG;
  19360. }
  19361. /**
  19362. * @brief Checks whether the specified SPI/I2S interrupt has occurred or not.
  19363. * @param SPIx: where x can be
  19364. * - 1, 2 or 3 in SPI mode
  19365. * - 2 or 3 in I2S mode
  19366. * @param SPI_I2S_IT: specifies the SPI/I2S interrupt source to check.
  19367. * This parameter can be one of the following values:
  19368. * @arg SPI_I2S_IT_TXE: Transmit buffer empty interrupt.
  19369. * @arg SPI_I2S_IT_RXNE: Receive buffer not empty interrupt.
  19370. * @arg SPI_I2S_IT_OVR: Overrun interrupt.
  19371. * @arg SPI_IT_MODF: Mode Fault interrupt.
  19372. * @arg SPI_IT_CRCERR: CRC Error interrupt.
  19373. * @arg I2S_IT_UDR: Underrun Error interrupt.
  19374. * @retval The new state of SPI_I2S_IT (SET or RESET).
  19375. */
  19376. ITStatus SPI_I2S_GetITStatus(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT)
  19377. {
  19378. ITStatus bitstatus = RESET;
  19379. uint16_t itpos = 0, itmask = 0, enablestatus = 0;
  19380. /* Check the parameters */
  19381. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19382. assert_param(IS_SPI_I2S_GET_IT(SPI_I2S_IT));
  19383. /* Get the SPI/I2S IT index */
  19384. itpos = 0x01 << (SPI_I2S_IT & 0x0F);
  19385. /* Get the SPI/I2S IT mask */
  19386. itmask = SPI_I2S_IT >> 4;
  19387. /* Set the IT mask */
  19388. itmask = 0x01 << itmask;
  19389. /* Get the SPI_I2S_IT enable bit status */
  19390. enablestatus = (SPIx->CR2 & itmask) ;
  19391. /* Check the status of the specified SPI/I2S interrupt */
  19392. if (((SPIx->SR & itpos) != (uint16_t)RESET) && enablestatus)
  19393. {
  19394. /* SPI_I2S_IT is set */
  19395. bitstatus = SET;
  19396. }
  19397. else
  19398. {
  19399. /* SPI_I2S_IT is reset */
  19400. bitstatus = RESET;
  19401. }
  19402. /* Return the SPI_I2S_IT status */
  19403. return bitstatus;
  19404. }
  19405. /**
  19406. * @brief Clears the SPIx CRC Error (CRCERR) interrupt pending bit.
  19407. * @param SPIx: where x can be
  19408. * - 1, 2 or 3 in SPI mode
  19409. * @param SPI_I2S_IT: specifies the SPI interrupt pending bit to clear.
  19410. * This function clears only CRCERR interrupt pending bit.
  19411. * @note
  19412. * - OVR (OverRun Error) interrupt pending bit is cleared by software
  19413. * sequence: a read operation to SPI_DR register (SPI_I2S_ReceiveData())
  19414. * followed by a read operation to SPI_SR register (SPI_I2S_GetITStatus()).
  19415. * - UDR (UnderRun Error) interrupt pending bit is cleared by a read
  19416. * operation to SPI_SR register (SPI_I2S_GetITStatus()).
  19417. * - MODF (Mode Fault) interrupt pending bit is cleared by software sequence:
  19418. * a read/write operation to SPI_SR register (SPI_I2S_GetITStatus())
  19419. * followed by a write operation to SPI_CR1 register (SPI_Cmd() to enable
  19420. * the SPI).
  19421. * @retval None
  19422. */
  19423. void SPI_I2S_ClearITPendingBit(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT)
  19424. {
  19425. uint16_t itpos = 0;
  19426. /* Check the parameters */
  19427. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  19428. assert_param(IS_SPI_I2S_CLEAR_IT(SPI_I2S_IT));
  19429. /* Get the SPI IT index */
  19430. itpos = 0x01 << (SPI_I2S_IT & 0x0F);
  19431. /* Clear the selected SPI CRC Error (CRCERR) interrupt pending bit */
  19432. SPIx->SR = (uint16_t)~itpos;
  19433. }
  19434. /**
  19435. * @}
  19436. */
  19437. /**
  19438. * @}
  19439. */
  19440. /**
  19441. * @}
  19442. */
  19443. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  19444. /**
  19445. ******************************************************************************
  19446. * @file stm32f10x_i2c.c
  19447. * @author MCD Application Team
  19448. * @version V3.5.0
  19449. * @date 11-March-2011
  19450. * @brief This file provides all the I2C firmware functions.
  19451. ******************************************************************************
  19452. * @attention
  19453. *
  19454. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  19455. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  19456. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  19457. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  19458. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  19459. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  19460. *
  19461. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  19462. ******************************************************************************
  19463. */
  19464. /* Includes ------------------------------------------------------------------*/
  19465. #include "stm32f10x_i2c.h"
  19466. #include "stm32f10x_rcc.h"
  19467. /** @addtogroup STM32F10x_StdPeriph_Driver
  19468. * @{
  19469. */
  19470. /** @defgroup I2C
  19471. * @brief I2C driver modules
  19472. * @{
  19473. */
  19474. /** @defgroup I2C_Private_TypesDefinitions
  19475. * @{
  19476. */
  19477. /**
  19478. * @}
  19479. */
  19480. /** @defgroup I2C_Private_Defines
  19481. * @{
  19482. */
  19483. /* I2C SPE mask */
  19484. #define CR1_PE_Set ((uint16_t)0x0001)
  19485. #define CR1_PE_Reset ((uint16_t)0xFFFE)
  19486. /* I2C START mask */
  19487. #define CR1_START_Set ((uint16_t)0x0100)
  19488. #define CR1_START_Reset ((uint16_t)0xFEFF)
  19489. /* I2C STOP mask */
  19490. #define CR1_STOP_Set ((uint16_t)0x0200)
  19491. #define CR1_STOP_Reset ((uint16_t)0xFDFF)
  19492. /* I2C ACK mask */
  19493. #define CR1_ACK_Set ((uint16_t)0x0400)
  19494. #define CR1_ACK_Reset ((uint16_t)0xFBFF)
  19495. /* I2C ENGC mask */
  19496. #define CR1_ENGC_Set ((uint16_t)0x0040)
  19497. #define CR1_ENGC_Reset ((uint16_t)0xFFBF)
  19498. /* I2C SWRST mask */
  19499. #define CR1_SWRST_Set ((uint16_t)0x8000)
  19500. #define CR1_SWRST_Reset ((uint16_t)0x7FFF)
  19501. /* I2C PEC mask */
  19502. #define CR1_PEC_Set ((uint16_t)0x1000)
  19503. #define CR1_PEC_Reset ((uint16_t)0xEFFF)
  19504. /* I2C ENPEC mask */
  19505. #define CR1_ENPEC_Set ((uint16_t)0x0020)
  19506. #define CR1_ENPEC_Reset ((uint16_t)0xFFDF)
  19507. /* I2C ENARP mask */
  19508. #define CR1_ENARP_Set ((uint16_t)0x0010)
  19509. #define CR1_ENARP_Reset ((uint16_t)0xFFEF)
  19510. /* I2C NOSTRETCH mask */
  19511. #define CR1_NOSTRETCH_Set ((uint16_t)0x0080)
  19512. #define CR1_NOSTRETCH_Reset ((uint16_t)0xFF7F)
  19513. /* I2C registers Masks */
  19514. #define CR1_CLEAR_Mask ((uint16_t)0xFBF5)
  19515. /* I2C DMAEN mask */
  19516. #define CR2_DMAEN_Set ((uint16_t)0x0800)
  19517. #define CR2_DMAEN_Reset ((uint16_t)0xF7FF)
  19518. /* I2C LAST mask */
  19519. #define CR2_LAST_Set ((uint16_t)0x1000)
  19520. #define CR2_LAST_Reset ((uint16_t)0xEFFF)
  19521. /* I2C FREQ mask */
  19522. #define CR2_FREQ_Reset ((uint16_t)0xFFC0)
  19523. /* I2C ADD0 mask */
  19524. #define OAR1_ADD0_Set ((uint16_t)0x0001)
  19525. #define OAR1_ADD0_Reset ((uint16_t)0xFFFE)
  19526. /* I2C ENDUAL mask */
  19527. #define OAR2_ENDUAL_Set ((uint16_t)0x0001)
  19528. #define OAR2_ENDUAL_Reset ((uint16_t)0xFFFE)
  19529. /* I2C ADD2 mask */
  19530. #define OAR2_ADD2_Reset ((uint16_t)0xFF01)
  19531. /* I2C F/S mask */
  19532. #define CCR_FS_Set ((uint16_t)0x8000)
  19533. /* I2C CCR mask */
  19534. #define CCR_CCR_Set ((uint16_t)0x0FFF)
  19535. /* I2C FLAG mask */
  19536. #define FLAG_Mask ((uint32_t)0x00FFFFFF)
  19537. /* I2C Interrupt Enable mask */
  19538. #define ITEN_Mask ((uint32_t)0x07000000)
  19539. /**
  19540. * @}
  19541. */
  19542. /** @defgroup I2C_Private_Macros
  19543. * @{
  19544. */
  19545. /**
  19546. * @}
  19547. */
  19548. /** @defgroup I2C_Private_Variables
  19549. * @{
  19550. */
  19551. /**
  19552. * @}
  19553. */
  19554. /** @defgroup I2C_Private_FunctionPrototypes
  19555. * @{
  19556. */
  19557. /**
  19558. * @}
  19559. */
  19560. /** @defgroup I2C_Private_Functions
  19561. * @{
  19562. */
  19563. /**
  19564. * @brief Deinitializes the I2Cx peripheral registers to their default reset values.
  19565. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19566. * @retval None
  19567. */
  19568. void I2C_DeInit(I2C_TypeDef* I2Cx)
  19569. {
  19570. /* Check the parameters */
  19571. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19572. if (I2Cx == I2C1)
  19573. {
  19574. /* Enable I2C1 reset state */
  19575. RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
  19576. /* Release I2C1 from reset state */
  19577. RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);
  19578. }
  19579. else
  19580. {
  19581. /* Enable I2C2 reset state */
  19582. RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE);
  19583. /* Release I2C2 from reset state */
  19584. RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, DISABLE);
  19585. }
  19586. }
  19587. /**
  19588. * @brief Initializes the I2Cx peripheral according to the specified
  19589. * parameters in the I2C_InitStruct.
  19590. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19591. * @param I2C_InitStruct: pointer to a I2C_InitTypeDef structure that
  19592. * contains the configuration information for the specified I2C peripheral.
  19593. * @retval None
  19594. */
  19595. void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct)
  19596. {
  19597. uint16_t tmpreg = 0, freqrange = 0;
  19598. uint16_t result = 0x04;
  19599. uint32_t pclk1 = 8000000;
  19600. RCC_ClocksTypeDef rcc_clocks;
  19601. /* Check the parameters */
  19602. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19603. assert_param(IS_I2C_CLOCK_SPEED(I2C_InitStruct->I2C_ClockSpeed));
  19604. assert_param(IS_I2C_MODE(I2C_InitStruct->I2C_Mode));
  19605. assert_param(IS_I2C_DUTY_CYCLE(I2C_InitStruct->I2C_DutyCycle));
  19606. assert_param(IS_I2C_OWN_ADDRESS1(I2C_InitStruct->I2C_OwnAddress1));
  19607. assert_param(IS_I2C_ACK_STATE(I2C_InitStruct->I2C_Ack));
  19608. assert_param(IS_I2C_ACKNOWLEDGE_ADDRESS(I2C_InitStruct->I2C_AcknowledgedAddress));
  19609. /*---------------------------- I2Cx CR2 Configuration ------------------------*/
  19610. /* Get the I2Cx CR2 value */
  19611. tmpreg = I2Cx->CR2;
  19612. /* Clear frequency FREQ[5:0] bits */
  19613. tmpreg &= CR2_FREQ_Reset;
  19614. /* Get pclk1 frequency value */
  19615. RCC_GetClocksFreq(&rcc_clocks);
  19616. pclk1 = rcc_clocks.PCLK1_Frequency;
  19617. /* Set frequency bits depending on pclk1 value */
  19618. freqrange = (uint16_t)(pclk1 / 1000000);
  19619. tmpreg |= freqrange;
  19620. /* Write to I2Cx CR2 */
  19621. I2Cx->CR2 = tmpreg;
  19622. /*---------------------------- I2Cx CCR Configuration ------------------------*/
  19623. /* Disable the selected I2C peripheral to configure TRISE */
  19624. I2Cx->CR1 &= CR1_PE_Reset;
  19625. /* Reset tmpreg value */
  19626. /* Clear F/S, DUTY and CCR[11:0] bits */
  19627. tmpreg = 0;
  19628. /* Configure speed in standard mode */
  19629. if (I2C_InitStruct->I2C_ClockSpeed <= 100000)
  19630. {
  19631. /* Standard mode speed calculate */
  19632. result = (uint16_t)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed << 1));
  19633. /* Test if CCR value is under 0x4*/
  19634. if (result < 0x04)
  19635. {
  19636. /* Set minimum allowed value */
  19637. result = 0x04;
  19638. }
  19639. /* Set speed value for standard mode */
  19640. tmpreg |= result;
  19641. /* Set Maximum Rise Time for standard mode */
  19642. I2Cx->TRISE = freqrange + 1;
  19643. }
  19644. /* Configure speed in fast mode */
  19645. else /*(I2C_InitStruct->I2C_ClockSpeed <= 400000)*/
  19646. {
  19647. if (I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_2)
  19648. {
  19649. /* Fast mode speed calculate: Tlow/Thigh = 2 */
  19650. result = (uint16_t)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed * 3));
  19651. }
  19652. else /*I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_16_9*/
  19653. {
  19654. /* Fast mode speed calculate: Tlow/Thigh = 16/9 */
  19655. result = (uint16_t)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed * 25));
  19656. /* Set DUTY bit */
  19657. result |= I2C_DutyCycle_16_9;
  19658. }
  19659. /* Test if CCR value is under 0x1*/
  19660. if ((result & CCR_CCR_Set) == 0)
  19661. {
  19662. /* Set minimum allowed value */
  19663. result |= (uint16_t)0x0001;
  19664. }
  19665. /* Set speed value and set F/S bit for fast mode */
  19666. tmpreg |= (uint16_t)(result | CCR_FS_Set);
  19667. /* Set Maximum Rise Time for fast mode */
  19668. I2Cx->TRISE = (uint16_t)(((freqrange * (uint16_t)300) / (uint16_t)1000) + (uint16_t)1);
  19669. }
  19670. /* Write to I2Cx CCR */
  19671. I2Cx->CCR = tmpreg;
  19672. /* Enable the selected I2C peripheral */
  19673. I2Cx->CR1 |= CR1_PE_Set;
  19674. /*---------------------------- I2Cx CR1 Configuration ------------------------*/
  19675. /* Get the I2Cx CR1 value */
  19676. tmpreg = I2Cx->CR1;
  19677. /* Clear ACK, SMBTYPE and SMBUS bits */
  19678. tmpreg &= CR1_CLEAR_Mask;
  19679. /* Configure I2Cx: mode and acknowledgement */
  19680. /* Set SMBTYPE and SMBUS bits according to I2C_Mode value */
  19681. /* Set ACK bit according to I2C_Ack value */
  19682. tmpreg |= (uint16_t)((uint32_t)I2C_InitStruct->I2C_Mode | I2C_InitStruct->I2C_Ack);
  19683. /* Write to I2Cx CR1 */
  19684. I2Cx->CR1 = tmpreg;
  19685. /*---------------------------- I2Cx OAR1 Configuration -----------------------*/
  19686. /* Set I2Cx Own Address1 and acknowledged address */
  19687. I2Cx->OAR1 = (I2C_InitStruct->I2C_AcknowledgedAddress | I2C_InitStruct->I2C_OwnAddress1);
  19688. }
  19689. /**
  19690. * @brief Fills each I2C_InitStruct member with its default value.
  19691. * @param I2C_InitStruct: pointer to an I2C_InitTypeDef structure which will be initialized.
  19692. * @retval None
  19693. */
  19694. void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct)
  19695. {
  19696. /*---------------- Reset I2C init structure parameters values ----------------*/
  19697. /* initialize the I2C_ClockSpeed member */
  19698. I2C_InitStruct->I2C_ClockSpeed = 5000;
  19699. /* Initialize the I2C_Mode member */
  19700. I2C_InitStruct->I2C_Mode = I2C_Mode_I2C;
  19701. /* Initialize the I2C_DutyCycle member */
  19702. I2C_InitStruct->I2C_DutyCycle = I2C_DutyCycle_2;
  19703. /* Initialize the I2C_OwnAddress1 member */
  19704. I2C_InitStruct->I2C_OwnAddress1 = 0;
  19705. /* Initialize the I2C_Ack member */
  19706. I2C_InitStruct->I2C_Ack = I2C_Ack_Disable;
  19707. /* Initialize the I2C_AcknowledgedAddress member */
  19708. I2C_InitStruct->I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  19709. }
  19710. /**
  19711. * @brief Enables or disables the specified I2C peripheral.
  19712. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19713. * @param NewState: new state of the I2Cx peripheral.
  19714. * This parameter can be: ENABLE or DISABLE.
  19715. * @retval None
  19716. */
  19717. void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
  19718. {
  19719. /* Check the parameters */
  19720. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19721. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19722. if (NewState != DISABLE)
  19723. {
  19724. /* Enable the selected I2C peripheral */
  19725. I2Cx->CR1 |= CR1_PE_Set;
  19726. }
  19727. else
  19728. {
  19729. /* Disable the selected I2C peripheral */
  19730. I2Cx->CR1 &= CR1_PE_Reset;
  19731. }
  19732. }
  19733. /**
  19734. * @brief Enables or disables the specified I2C DMA requests.
  19735. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19736. * @param NewState: new state of the I2C DMA transfer.
  19737. * This parameter can be: ENABLE or DISABLE.
  19738. * @retval None
  19739. */
  19740. void I2C_DMACmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
  19741. {
  19742. /* Check the parameters */
  19743. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19744. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19745. if (NewState != DISABLE)
  19746. {
  19747. /* Enable the selected I2C DMA requests */
  19748. I2Cx->CR2 |= CR2_DMAEN_Set;
  19749. }
  19750. else
  19751. {
  19752. /* Disable the selected I2C DMA requests */
  19753. I2Cx->CR2 &= CR2_DMAEN_Reset;
  19754. }
  19755. }
  19756. /**
  19757. * @brief Specifies if the next DMA transfer will be the last one.
  19758. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19759. * @param NewState: new state of the I2C DMA last transfer.
  19760. * This parameter can be: ENABLE or DISABLE.
  19761. * @retval None
  19762. */
  19763. void I2C_DMALastTransferCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
  19764. {
  19765. /* Check the parameters */
  19766. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19767. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19768. if (NewState != DISABLE)
  19769. {
  19770. /* Next DMA transfer is the last transfer */
  19771. I2Cx->CR2 |= CR2_LAST_Set;
  19772. }
  19773. else
  19774. {
  19775. /* Next DMA transfer is not the last transfer */
  19776. I2Cx->CR2 &= CR2_LAST_Reset;
  19777. }
  19778. }
  19779. /**
  19780. * @brief Generates I2Cx communication START condition.
  19781. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19782. * @param NewState: new state of the I2C START condition generation.
  19783. * This parameter can be: ENABLE or DISABLE.
  19784. * @retval None.
  19785. */
  19786. void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState)
  19787. {
  19788. /* Check the parameters */
  19789. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19790. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19791. if (NewState != DISABLE)
  19792. {
  19793. /* Generate a START condition */
  19794. I2Cx->CR1 |= CR1_START_Set;
  19795. }
  19796. else
  19797. {
  19798. /* Disable the START condition generation */
  19799. I2Cx->CR1 &= CR1_START_Reset;
  19800. }
  19801. }
  19802. /**
  19803. * @brief Generates I2Cx communication STOP condition.
  19804. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19805. * @param NewState: new state of the I2C STOP condition generation.
  19806. * This parameter can be: ENABLE or DISABLE.
  19807. * @retval None.
  19808. */
  19809. void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState)
  19810. {
  19811. /* Check the parameters */
  19812. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19813. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19814. if (NewState != DISABLE)
  19815. {
  19816. /* Generate a STOP condition */
  19817. I2Cx->CR1 |= CR1_STOP_Set;
  19818. }
  19819. else
  19820. {
  19821. /* Disable the STOP condition generation */
  19822. I2Cx->CR1 &= CR1_STOP_Reset;
  19823. }
  19824. }
  19825. /**
  19826. * @brief Enables or disables the specified I2C acknowledge feature.
  19827. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19828. * @param NewState: new state of the I2C Acknowledgement.
  19829. * This parameter can be: ENABLE or DISABLE.
  19830. * @retval None.
  19831. */
  19832. void I2C_AcknowledgeConfig(I2C_TypeDef* I2Cx, FunctionalState NewState)
  19833. {
  19834. /* Check the parameters */
  19835. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19836. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19837. if (NewState != DISABLE)
  19838. {
  19839. /* Enable the acknowledgement */
  19840. I2Cx->CR1 |= CR1_ACK_Set;
  19841. }
  19842. else
  19843. {
  19844. /* Disable the acknowledgement */
  19845. I2Cx->CR1 &= CR1_ACK_Reset;
  19846. }
  19847. }
  19848. /**
  19849. * @brief Configures the specified I2C own address2.
  19850. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19851. * @param Address: specifies the 7bit I2C own address2.
  19852. * @retval None.
  19853. */
  19854. void I2C_OwnAddress2Config(I2C_TypeDef* I2Cx, uint8_t Address)
  19855. {
  19856. uint16_t tmpreg = 0;
  19857. /* Check the parameters */
  19858. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19859. /* Get the old register value */
  19860. tmpreg = I2Cx->OAR2;
  19861. /* Reset I2Cx Own address2 bit [7:1] */
  19862. tmpreg &= OAR2_ADD2_Reset;
  19863. /* Set I2Cx Own address2 */
  19864. tmpreg |= (uint16_t)((uint16_t)Address & (uint16_t)0x00FE);
  19865. /* Store the new register value */
  19866. I2Cx->OAR2 = tmpreg;
  19867. }
  19868. /**
  19869. * @brief Enables or disables the specified I2C dual addressing mode.
  19870. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19871. * @param NewState: new state of the I2C dual addressing mode.
  19872. * This parameter can be: ENABLE or DISABLE.
  19873. * @retval None
  19874. */
  19875. void I2C_DualAddressCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
  19876. {
  19877. /* Check the parameters */
  19878. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19879. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19880. if (NewState != DISABLE)
  19881. {
  19882. /* Enable dual addressing mode */
  19883. I2Cx->OAR2 |= OAR2_ENDUAL_Set;
  19884. }
  19885. else
  19886. {
  19887. /* Disable dual addressing mode */
  19888. I2Cx->OAR2 &= OAR2_ENDUAL_Reset;
  19889. }
  19890. }
  19891. /**
  19892. * @brief Enables or disables the specified I2C general call feature.
  19893. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19894. * @param NewState: new state of the I2C General call.
  19895. * This parameter can be: ENABLE or DISABLE.
  19896. * @retval None
  19897. */
  19898. void I2C_GeneralCallCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
  19899. {
  19900. /* Check the parameters */
  19901. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19902. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19903. if (NewState != DISABLE)
  19904. {
  19905. /* Enable generall call */
  19906. I2Cx->CR1 |= CR1_ENGC_Set;
  19907. }
  19908. else
  19909. {
  19910. /* Disable generall call */
  19911. I2Cx->CR1 &= CR1_ENGC_Reset;
  19912. }
  19913. }
  19914. /**
  19915. * @brief Enables or disables the specified I2C interrupts.
  19916. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19917. * @param I2C_IT: specifies the I2C interrupts sources to be enabled or disabled.
  19918. * This parameter can be any combination of the following values:
  19919. * @arg I2C_IT_BUF: Buffer interrupt mask
  19920. * @arg I2C_IT_EVT: Event interrupt mask
  19921. * @arg I2C_IT_ERR: Error interrupt mask
  19922. * @param NewState: new state of the specified I2C interrupts.
  19923. * This parameter can be: ENABLE or DISABLE.
  19924. * @retval None
  19925. */
  19926. void I2C_ITConfig(I2C_TypeDef* I2Cx, uint16_t I2C_IT, FunctionalState NewState)
  19927. {
  19928. /* Check the parameters */
  19929. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19930. assert_param(IS_FUNCTIONAL_STATE(NewState));
  19931. assert_param(IS_I2C_CONFIG_IT(I2C_IT));
  19932. if (NewState != DISABLE)
  19933. {
  19934. /* Enable the selected I2C interrupts */
  19935. I2Cx->CR2 |= I2C_IT;
  19936. }
  19937. else
  19938. {
  19939. /* Disable the selected I2C interrupts */
  19940. I2Cx->CR2 &= (uint16_t)~I2C_IT;
  19941. }
  19942. }
  19943. /**
  19944. * @brief Sends a data byte through the I2Cx peripheral.
  19945. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19946. * @param Data: Byte to be transmitted..
  19947. * @retval None
  19948. */
  19949. void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data)
  19950. {
  19951. /* Check the parameters */
  19952. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19953. /* Write in the DR register the data to be sent */
  19954. I2Cx->DR = Data;
  19955. }
  19956. /**
  19957. * @brief Returns the most recent received data by the I2Cx peripheral.
  19958. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19959. * @retval The value of the received data.
  19960. */
  19961. uint8_t I2C_ReceiveData(I2C_TypeDef* I2Cx)
  19962. {
  19963. /* Check the parameters */
  19964. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19965. /* Return the data in the DR register */
  19966. return (uint8_t)I2Cx->DR;
  19967. }
  19968. /**
  19969. * @brief Transmits the address byte to select the slave device.
  19970. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  19971. * @param Address: specifies the slave address which will be transmitted
  19972. * @param I2C_Direction: specifies whether the I2C device will be a
  19973. * Transmitter or a Receiver. This parameter can be one of the following values
  19974. * @arg I2C_Direction_Transmitter: Transmitter mode
  19975. * @arg I2C_Direction_Receiver: Receiver mode
  19976. * @retval None.
  19977. */
  19978. void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, uint8_t Address, uint8_t I2C_Direction)
  19979. {
  19980. /* Check the parameters */
  19981. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  19982. assert_param(IS_I2C_DIRECTION(I2C_Direction));
  19983. /* Test on the direction to set/reset the read/write bit */
  19984. if (I2C_Direction != I2C_Direction_Transmitter)
  19985. {
  19986. /* Set the address bit0 for read */
  19987. Address |= OAR1_ADD0_Set;
  19988. }
  19989. else
  19990. {
  19991. /* Reset the address bit0 for write */
  19992. Address &= OAR1_ADD0_Reset;
  19993. }
  19994. /* Send the address */
  19995. I2Cx->DR = Address;
  19996. }
  19997. /**
  19998. * @brief Reads the specified I2C register and returns its value.
  19999. * @param I2C_Register: specifies the register to read.
  20000. * This parameter can be one of the following values:
  20001. * @arg I2C_Register_CR1: CR1 register.
  20002. * @arg I2C_Register_CR2: CR2 register.
  20003. * @arg I2C_Register_OAR1: OAR1 register.
  20004. * @arg I2C_Register_OAR2: OAR2 register.
  20005. * @arg I2C_Register_DR: DR register.
  20006. * @arg I2C_Register_SR1: SR1 register.
  20007. * @arg I2C_Register_SR2: SR2 register.
  20008. * @arg I2C_Register_CCR: CCR register.
  20009. * @arg I2C_Register_TRISE: TRISE register.
  20010. * @retval The value of the read register.
  20011. */
  20012. uint16_t I2C_ReadRegister(I2C_TypeDef* I2Cx, uint8_t I2C_Register)
  20013. {
  20014. __IO uint32_t tmp = 0;
  20015. /* Check the parameters */
  20016. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20017. assert_param(IS_I2C_REGISTER(I2C_Register));
  20018. tmp = (uint32_t) I2Cx;
  20019. tmp += I2C_Register;
  20020. /* Return the selected register value */
  20021. return (*(__IO uint16_t *) tmp);
  20022. }
  20023. /**
  20024. * @brief Enables or disables the specified I2C software reset.
  20025. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20026. * @param NewState: new state of the I2C software reset.
  20027. * This parameter can be: ENABLE or DISABLE.
  20028. * @retval None
  20029. */
  20030. void I2C_SoftwareResetCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
  20031. {
  20032. /* Check the parameters */
  20033. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20034. assert_param(IS_FUNCTIONAL_STATE(NewState));
  20035. if (NewState != DISABLE)
  20036. {
  20037. /* Peripheral under reset */
  20038. I2Cx->CR1 |= CR1_SWRST_Set;
  20039. }
  20040. else
  20041. {
  20042. /* Peripheral not under reset */
  20043. I2Cx->CR1 &= CR1_SWRST_Reset;
  20044. }
  20045. }
  20046. /**
  20047. * @brief Selects the specified I2C NACK position in master receiver mode.
  20048. * This function is useful in I2C Master Receiver mode when the number
  20049. * of data to be received is equal to 2. In this case, this function
  20050. * should be called (with parameter I2C_NACKPosition_Next) before data
  20051. * reception starts,as described in the 2-byte reception procedure
  20052. * recommended in Reference Manual in Section: Master receiver.
  20053. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20054. * @param I2C_NACKPosition: specifies the NACK position.
  20055. * This parameter can be one of the following values:
  20056. * @arg I2C_NACKPosition_Next: indicates that the next byte will be the last
  20057. * received byte.
  20058. * @arg I2C_NACKPosition_Current: indicates that current byte is the last
  20059. * received byte.
  20060. *
  20061. * @note This function configures the same bit (POS) as I2C_PECPositionConfig()
  20062. * but is intended to be used in I2C mode while I2C_PECPositionConfig()
  20063. * is intended to used in SMBUS mode.
  20064. *
  20065. * @retval None
  20066. */
  20067. void I2C_NACKPositionConfig(I2C_TypeDef* I2Cx, uint16_t I2C_NACKPosition)
  20068. {
  20069. /* Check the parameters */
  20070. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20071. assert_param(IS_I2C_NACK_POSITION(I2C_NACKPosition));
  20072. /* Check the input parameter */
  20073. if (I2C_NACKPosition == I2C_NACKPosition_Next)
  20074. {
  20075. /* Next byte in shift register is the last received byte */
  20076. I2Cx->CR1 |= I2C_NACKPosition_Next;
  20077. }
  20078. else
  20079. {
  20080. /* Current byte in shift register is the last received byte */
  20081. I2Cx->CR1 &= I2C_NACKPosition_Current;
  20082. }
  20083. }
  20084. /**
  20085. * @brief Drives the SMBusAlert pin high or low for the specified I2C.
  20086. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20087. * @param I2C_SMBusAlert: specifies SMBAlert pin level.
  20088. * This parameter can be one of the following values:
  20089. * @arg I2C_SMBusAlert_Low: SMBAlert pin driven low
  20090. * @arg I2C_SMBusAlert_High: SMBAlert pin driven high
  20091. * @retval None
  20092. */
  20093. void I2C_SMBusAlertConfig(I2C_TypeDef* I2Cx, uint16_t I2C_SMBusAlert)
  20094. {
  20095. /* Check the parameters */
  20096. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20097. assert_param(IS_I2C_SMBUS_ALERT(I2C_SMBusAlert));
  20098. if (I2C_SMBusAlert == I2C_SMBusAlert_Low)
  20099. {
  20100. /* Drive the SMBusAlert pin Low */
  20101. I2Cx->CR1 |= I2C_SMBusAlert_Low;
  20102. }
  20103. else
  20104. {
  20105. /* Drive the SMBusAlert pin High */
  20106. I2Cx->CR1 &= I2C_SMBusAlert_High;
  20107. }
  20108. }
  20109. /**
  20110. * @brief Enables or disables the specified I2C PEC transfer.
  20111. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20112. * @param NewState: new state of the I2C PEC transmission.
  20113. * This parameter can be: ENABLE or DISABLE.
  20114. * @retval None
  20115. */
  20116. void I2C_TransmitPEC(I2C_TypeDef* I2Cx, FunctionalState NewState)
  20117. {
  20118. /* Check the parameters */
  20119. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20120. assert_param(IS_FUNCTIONAL_STATE(NewState));
  20121. if (NewState != DISABLE)
  20122. {
  20123. /* Enable the selected I2C PEC transmission */
  20124. I2Cx->CR1 |= CR1_PEC_Set;
  20125. }
  20126. else
  20127. {
  20128. /* Disable the selected I2C PEC transmission */
  20129. I2Cx->CR1 &= CR1_PEC_Reset;
  20130. }
  20131. }
  20132. /**
  20133. * @brief Selects the specified I2C PEC position.
  20134. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20135. * @param I2C_PECPosition: specifies the PEC position.
  20136. * This parameter can be one of the following values:
  20137. * @arg I2C_PECPosition_Next: indicates that the next byte is PEC
  20138. * @arg I2C_PECPosition_Current: indicates that current byte is PEC
  20139. *
  20140. * @note This function configures the same bit (POS) as I2C_NACKPositionConfig()
  20141. * but is intended to be used in SMBUS mode while I2C_NACKPositionConfig()
  20142. * is intended to used in I2C mode.
  20143. *
  20144. * @retval None
  20145. */
  20146. void I2C_PECPositionConfig(I2C_TypeDef* I2Cx, uint16_t I2C_PECPosition)
  20147. {
  20148. /* Check the parameters */
  20149. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20150. assert_param(IS_I2C_PEC_POSITION(I2C_PECPosition));
  20151. if (I2C_PECPosition == I2C_PECPosition_Next)
  20152. {
  20153. /* Next byte in shift register is PEC */
  20154. I2Cx->CR1 |= I2C_PECPosition_Next;
  20155. }
  20156. else
  20157. {
  20158. /* Current byte in shift register is PEC */
  20159. I2Cx->CR1 &= I2C_PECPosition_Current;
  20160. }
  20161. }
  20162. /**
  20163. * @brief Enables or disables the PEC value calculation of the transferred bytes.
  20164. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20165. * @param NewState: new state of the I2Cx PEC value calculation.
  20166. * This parameter can be: ENABLE or DISABLE.
  20167. * @retval None
  20168. */
  20169. void I2C_CalculatePEC(I2C_TypeDef* I2Cx, FunctionalState NewState)
  20170. {
  20171. /* Check the parameters */
  20172. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20173. assert_param(IS_FUNCTIONAL_STATE(NewState));
  20174. if (NewState != DISABLE)
  20175. {
  20176. /* Enable the selected I2C PEC calculation */
  20177. I2Cx->CR1 |= CR1_ENPEC_Set;
  20178. }
  20179. else
  20180. {
  20181. /* Disable the selected I2C PEC calculation */
  20182. I2Cx->CR1 &= CR1_ENPEC_Reset;
  20183. }
  20184. }
  20185. /**
  20186. * @brief Returns the PEC value for the specified I2C.
  20187. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20188. * @retval The PEC value.
  20189. */
  20190. uint8_t I2C_GetPEC(I2C_TypeDef* I2Cx)
  20191. {
  20192. /* Check the parameters */
  20193. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20194. /* Return the selected I2C PEC value */
  20195. return ((I2Cx->SR2) >> 8);
  20196. }
  20197. /**
  20198. * @brief Enables or disables the specified I2C ARP.
  20199. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20200. * @param NewState: new state of the I2Cx ARP.
  20201. * This parameter can be: ENABLE or DISABLE.
  20202. * @retval None
  20203. */
  20204. void I2C_ARPCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
  20205. {
  20206. /* Check the parameters */
  20207. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20208. assert_param(IS_FUNCTIONAL_STATE(NewState));
  20209. if (NewState != DISABLE)
  20210. {
  20211. /* Enable the selected I2C ARP */
  20212. I2Cx->CR1 |= CR1_ENARP_Set;
  20213. }
  20214. else
  20215. {
  20216. /* Disable the selected I2C ARP */
  20217. I2Cx->CR1 &= CR1_ENARP_Reset;
  20218. }
  20219. }
  20220. /**
  20221. * @brief Enables or disables the specified I2C Clock stretching.
  20222. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20223. * @param NewState: new state of the I2Cx Clock stretching.
  20224. * This parameter can be: ENABLE or DISABLE.
  20225. * @retval None
  20226. */
  20227. void I2C_StretchClockCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
  20228. {
  20229. /* Check the parameters */
  20230. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20231. assert_param(IS_FUNCTIONAL_STATE(NewState));
  20232. if (NewState == DISABLE)
  20233. {
  20234. /* Enable the selected I2C Clock stretching */
  20235. I2Cx->CR1 |= CR1_NOSTRETCH_Set;
  20236. }
  20237. else
  20238. {
  20239. /* Disable the selected I2C Clock stretching */
  20240. I2Cx->CR1 &= CR1_NOSTRETCH_Reset;
  20241. }
  20242. }
  20243. /**
  20244. * @brief Selects the specified I2C fast mode duty cycle.
  20245. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20246. * @param I2C_DutyCycle: specifies the fast mode duty cycle.
  20247. * This parameter can be one of the following values:
  20248. * @arg I2C_DutyCycle_2: I2C fast mode Tlow/Thigh = 2
  20249. * @arg I2C_DutyCycle_16_9: I2C fast mode Tlow/Thigh = 16/9
  20250. * @retval None
  20251. */
  20252. void I2C_FastModeDutyCycleConfig(I2C_TypeDef* I2Cx, uint16_t I2C_DutyCycle)
  20253. {
  20254. /* Check the parameters */
  20255. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20256. assert_param(IS_I2C_DUTY_CYCLE(I2C_DutyCycle));
  20257. if (I2C_DutyCycle != I2C_DutyCycle_16_9)
  20258. {
  20259. /* I2C fast mode Tlow/Thigh=2 */
  20260. I2Cx->CCR &= I2C_DutyCycle_2;
  20261. }
  20262. else
  20263. {
  20264. /* I2C fast mode Tlow/Thigh=16/9 */
  20265. I2Cx->CCR |= I2C_DutyCycle_16_9;
  20266. }
  20267. }
  20268. /**
  20269. * @brief
  20270. ****************************************************************************************
  20271. *
  20272. * I2C State Monitoring Functions
  20273. *
  20274. ****************************************************************************************
  20275. * This I2C driver provides three different ways for I2C state monitoring
  20276. * depending on the application requirements and constraints:
  20277. *
  20278. *
  20279. * 1) Basic state monitoring:
  20280. * Using I2C_CheckEvent() function:
  20281. * It compares the status registers (SR1 and SR2) content to a given event
  20282. * (can be the combination of one or more flags).
  20283. * It returns SUCCESS if the current status includes the given flags
  20284. * and returns ERROR if one or more flags are missing in the current status.
  20285. * - When to use:
  20286. * - This function is suitable for most applications as well as for startup
  20287. * activity since the events are fully described in the product reference manual
  20288. * (RM0008).
  20289. * - It is also suitable for users who need to define their own events.
  20290. * - Limitations:
  20291. * - If an error occurs (ie. error flags are set besides to the monitored flags),
  20292. * the I2C_CheckEvent() function may return SUCCESS despite the communication
  20293. * hold or corrupted real state.
  20294. * In this case, it is advised to use error interrupts to monitor the error
  20295. * events and handle them in the interrupt IRQ handler.
  20296. *
  20297. * @note
  20298. * For error management, it is advised to use the following functions:
  20299. * - I2C_ITConfig() to configure and enable the error interrupts (I2C_IT_ERR).
  20300. * - I2Cx_ER_IRQHandler() which is called when the error interrupt occurs.
  20301. * Where x is the peripheral instance (I2C1, I2C2 ...)
  20302. * - I2C_GetFlagStatus() or I2C_GetITStatus() to be called into I2Cx_ER_IRQHandler()
  20303. * in order to determine which error occured.
  20304. * - I2C_ClearFlag() or I2C_ClearITPendingBit() and/or I2C_SoftwareResetCmd()
  20305. * and/or I2C_GenerateStop() in order to clear the error flag and source,
  20306. * and return to correct communication status.
  20307. *
  20308. *
  20309. * 2) Advanced state monitoring:
  20310. * Using the function I2C_GetLastEvent() which returns the image of both status
  20311. * registers in a single word (uint32_t) (Status Register 2 value is shifted left
  20312. * by 16 bits and concatenated to Status Register 1).
  20313. * - When to use:
  20314. * - This function is suitable for the same applications above but it allows to
  20315. * overcome the mentioned limitation of I2C_GetFlagStatus() function.
  20316. * The returned value could be compared to events already defined in the
  20317. * library (stm32f10x_i2c.h) or to custom values defined by user.
  20318. * - This function is suitable when multiple flags are monitored at the same time.
  20319. * - At the opposite of I2C_CheckEvent() function, this function allows user to
  20320. * choose when an event is accepted (when all events flags are set and no
  20321. * other flags are set or just when the needed flags are set like
  20322. * I2C_CheckEvent() function).
  20323. * - Limitations:
  20324. * - User may need to define his own events.
  20325. * - Same remark concerning the error management is applicable for this
  20326. * function if user decides to check only regular communication flags (and
  20327. * ignores error flags).
  20328. *
  20329. *
  20330. * 3) Flag-based state monitoring:
  20331. * Using the function I2C_GetFlagStatus() which simply returns the status of
  20332. * one single flag (ie. I2C_FLAG_RXNE ...).
  20333. * - When to use:
  20334. * - This function could be used for specific applications or in debug phase.
  20335. * - It is suitable when only one flag checking is needed (most I2C events
  20336. * are monitored through multiple flags).
  20337. * - Limitations:
  20338. * - When calling this function, the Status register is accessed. Some flags are
  20339. * cleared when the status register is accessed. So checking the status
  20340. * of one Flag, may clear other ones.
  20341. * - Function may need to be called twice or more in order to monitor one
  20342. * single event.
  20343. *
  20344. * For detailed description of Events, please refer to section I2C_Events in
  20345. * stm32f10x_i2c.h file.
  20346. *
  20347. */
  20348. /**
  20349. *
  20350. * 1) Basic state monitoring
  20351. *******************************************************************************
  20352. */
  20353. /**
  20354. * @brief Checks whether the last I2Cx Event is equal to the one passed
  20355. * as parameter.
  20356. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20357. * @param I2C_EVENT: specifies the event to be checked.
  20358. * This parameter can be one of the following values:
  20359. * @arg I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED : EV1
  20360. * @arg I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED : EV1
  20361. * @arg I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED : EV1
  20362. * @arg I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED : EV1
  20363. * @arg I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED : EV1
  20364. * @arg I2C_EVENT_SLAVE_BYTE_RECEIVED : EV2
  20365. * @arg (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_DUALF) : EV2
  20366. * @arg (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_GENCALL) : EV2
  20367. * @arg I2C_EVENT_SLAVE_BYTE_TRANSMITTED : EV3
  20368. * @arg (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_DUALF) : EV3
  20369. * @arg (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_GENCALL) : EV3
  20370. * @arg I2C_EVENT_SLAVE_ACK_FAILURE : EV3_2
  20371. * @arg I2C_EVENT_SLAVE_STOP_DETECTED : EV4
  20372. * @arg I2C_EVENT_MASTER_MODE_SELECT : EV5
  20373. * @arg I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED : EV6
  20374. * @arg I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED : EV6
  20375. * @arg I2C_EVENT_MASTER_BYTE_RECEIVED : EV7
  20376. * @arg I2C_EVENT_MASTER_BYTE_TRANSMITTING : EV8
  20377. * @arg I2C_EVENT_MASTER_BYTE_TRANSMITTED : EV8_2
  20378. * @arg I2C_EVENT_MASTER_MODE_ADDRESS10 : EV9
  20379. *
  20380. * @note: For detailed description of Events, please refer to section
  20381. * I2C_Events in stm32f10x_i2c.h file.
  20382. *
  20383. * @retval An ErrorStatus enumeration value:
  20384. * - SUCCESS: Last event is equal to the I2C_EVENT
  20385. * - ERROR: Last event is different from the I2C_EVENT
  20386. */
  20387. ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, uint32_t I2C_EVENT)
  20388. {
  20389. uint32_t lastevent = 0;
  20390. uint32_t flag1 = 0, flag2 = 0;
  20391. ErrorStatus status = ERROR;
  20392. /* Check the parameters */
  20393. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20394. assert_param(IS_I2C_EVENT(I2C_EVENT));
  20395. /* Read the I2Cx status register */
  20396. flag1 = I2Cx->SR1;
  20397. flag2 = I2Cx->SR2;
  20398. flag2 = flag2 << 16;
  20399. /* Get the last event value from I2C status register */
  20400. lastevent = (flag1 | flag2) & FLAG_Mask;
  20401. /* Check whether the last event contains the I2C_EVENT */
  20402. if ((lastevent & I2C_EVENT) == I2C_EVENT)
  20403. {
  20404. /* SUCCESS: last event is equal to I2C_EVENT */
  20405. status = SUCCESS;
  20406. }
  20407. else
  20408. {
  20409. /* ERROR: last event is different from I2C_EVENT */
  20410. status = ERROR;
  20411. }
  20412. /* Return status */
  20413. return status;
  20414. }
  20415. /**
  20416. *
  20417. * 2) Advanced state monitoring
  20418. *******************************************************************************
  20419. */
  20420. /**
  20421. * @brief Returns the last I2Cx Event.
  20422. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20423. *
  20424. * @note: For detailed description of Events, please refer to section
  20425. * I2C_Events in stm32f10x_i2c.h file.
  20426. *
  20427. * @retval The last event
  20428. */
  20429. uint32_t I2C_GetLastEvent(I2C_TypeDef* I2Cx)
  20430. {
  20431. uint32_t lastevent = 0;
  20432. uint32_t flag1 = 0, flag2 = 0;
  20433. /* Check the parameters */
  20434. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20435. /* Read the I2Cx status register */
  20436. flag1 = I2Cx->SR1;
  20437. flag2 = I2Cx->SR2;
  20438. flag2 = flag2 << 16;
  20439. /* Get the last event value from I2C status register */
  20440. lastevent = (flag1 | flag2) & FLAG_Mask;
  20441. /* Return status */
  20442. return lastevent;
  20443. }
  20444. /**
  20445. *
  20446. * 3) Flag-based state monitoring
  20447. *******************************************************************************
  20448. */
  20449. /**
  20450. * @brief Checks whether the specified I2C flag is set or not.
  20451. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20452. * @param I2C_FLAG: specifies the flag to check.
  20453. * This parameter can be one of the following values:
  20454. * @arg I2C_FLAG_DUALF: Dual flag (Slave mode)
  20455. * @arg I2C_FLAG_SMBHOST: SMBus host header (Slave mode)
  20456. * @arg I2C_FLAG_SMBDEFAULT: SMBus default header (Slave mode)
  20457. * @arg I2C_FLAG_GENCALL: General call header flag (Slave mode)
  20458. * @arg I2C_FLAG_TRA: Transmitter/Receiver flag
  20459. * @arg I2C_FLAG_BUSY: Bus busy flag
  20460. * @arg I2C_FLAG_MSL: Master/Slave flag
  20461. * @arg I2C_FLAG_SMBALERT: SMBus Alert flag
  20462. * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
  20463. * @arg I2C_FLAG_PECERR: PEC error in reception flag
  20464. * @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
  20465. * @arg I2C_FLAG_AF: Acknowledge failure flag
  20466. * @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
  20467. * @arg I2C_FLAG_BERR: Bus error flag
  20468. * @arg I2C_FLAG_TXE: Data register empty flag (Transmitter)
  20469. * @arg I2C_FLAG_RXNE: Data register not empty (Receiver) flag
  20470. * @arg I2C_FLAG_STOPF: Stop detection flag (Slave mode)
  20471. * @arg I2C_FLAG_ADD10: 10-bit header sent flag (Master mode)
  20472. * @arg I2C_FLAG_BTF: Byte transfer finished flag
  20473. * @arg I2C_FLAG_ADDR: Address sent flag (Master mode) "ADSL"
  20474. * Address matched flag (Slave mode)"ENDA"
  20475. * @arg I2C_FLAG_SB: Start bit flag (Master mode)
  20476. * @retval The new state of I2C_FLAG (SET or RESET).
  20477. */
  20478. FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG)
  20479. {
  20480. FlagStatus bitstatus = RESET;
  20481. __IO uint32_t i2creg = 0, i2cxbase = 0;
  20482. /* Check the parameters */
  20483. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20484. assert_param(IS_I2C_GET_FLAG(I2C_FLAG));
  20485. /* Get the I2Cx peripheral base address */
  20486. i2cxbase = (uint32_t)I2Cx;
  20487. /* Read flag register index */
  20488. i2creg = I2C_FLAG >> 28;
  20489. /* Get bit[23:0] of the flag */
  20490. I2C_FLAG &= FLAG_Mask;
  20491. if(i2creg != 0)
  20492. {
  20493. /* Get the I2Cx SR1 register address */
  20494. i2cxbase += 0x14;
  20495. }
  20496. else
  20497. {
  20498. /* Flag in I2Cx SR2 Register */
  20499. I2C_FLAG = (uint32_t)(I2C_FLAG >> 16);
  20500. /* Get the I2Cx SR2 register address */
  20501. i2cxbase += 0x18;
  20502. }
  20503. if(((*(__IO uint32_t *)i2cxbase) & I2C_FLAG) != (uint32_t)RESET)
  20504. {
  20505. /* I2C_FLAG is set */
  20506. bitstatus = SET;
  20507. }
  20508. else
  20509. {
  20510. /* I2C_FLAG is reset */
  20511. bitstatus = RESET;
  20512. }
  20513. /* Return the I2C_FLAG status */
  20514. return bitstatus;
  20515. }
  20516. /**
  20517. * @brief Clears the I2Cx's pending flags.
  20518. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20519. * @param I2C_FLAG: specifies the flag to clear.
  20520. * This parameter can be any combination of the following values:
  20521. * @arg I2C_FLAG_SMBALERT: SMBus Alert flag
  20522. * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
  20523. * @arg I2C_FLAG_PECERR: PEC error in reception flag
  20524. * @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
  20525. * @arg I2C_FLAG_AF: Acknowledge failure flag
  20526. * @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
  20527. * @arg I2C_FLAG_BERR: Bus error flag
  20528. *
  20529. * @note
  20530. * - STOPF (STOP detection) is cleared by software sequence: a read operation
  20531. * to I2C_SR1 register (I2C_GetFlagStatus()) followed by a write operation
  20532. * to I2C_CR1 register (I2C_Cmd() to re-enable the I2C peripheral).
  20533. * - ADD10 (10-bit header sent) is cleared by software sequence: a read
  20534. * operation to I2C_SR1 (I2C_GetFlagStatus()) followed by writing the
  20535. * second byte of the address in DR register.
  20536. * - BTF (Byte Transfer Finished) is cleared by software sequence: a read
  20537. * operation to I2C_SR1 register (I2C_GetFlagStatus()) followed by a
  20538. * read/write to I2C_DR register (I2C_SendData()).
  20539. * - ADDR (Address sent) is cleared by software sequence: a read operation to
  20540. * I2C_SR1 register (I2C_GetFlagStatus()) followed by a read operation to
  20541. * I2C_SR2 register ((void)(I2Cx->SR2)).
  20542. * - SB (Start Bit) is cleared software sequence: a read operation to I2C_SR1
  20543. * register (I2C_GetFlagStatus()) followed by a write operation to I2C_DR
  20544. * register (I2C_SendData()).
  20545. * @retval None
  20546. */
  20547. void I2C_ClearFlag(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG)
  20548. {
  20549. uint32_t flagpos = 0;
  20550. /* Check the parameters */
  20551. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20552. assert_param(IS_I2C_CLEAR_FLAG(I2C_FLAG));
  20553. /* Get the I2C flag position */
  20554. flagpos = I2C_FLAG & FLAG_Mask;
  20555. /* Clear the selected I2C flag */
  20556. I2Cx->SR1 = (uint16_t)~flagpos;
  20557. }
  20558. /**
  20559. * @brief Checks whether the specified I2C interrupt has occurred or not.
  20560. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20561. * @param I2C_IT: specifies the interrupt source to check.
  20562. * This parameter can be one of the following values:
  20563. * @arg I2C_IT_SMBALERT: SMBus Alert flag
  20564. * @arg I2C_IT_TIMEOUT: Timeout or Tlow error flag
  20565. * @arg I2C_IT_PECERR: PEC error in reception flag
  20566. * @arg I2C_IT_OVR: Overrun/Underrun flag (Slave mode)
  20567. * @arg I2C_IT_AF: Acknowledge failure flag
  20568. * @arg I2C_IT_ARLO: Arbitration lost flag (Master mode)
  20569. * @arg I2C_IT_BERR: Bus error flag
  20570. * @arg I2C_IT_TXE: Data register empty flag (Transmitter)
  20571. * @arg I2C_IT_RXNE: Data register not empty (Receiver) flag
  20572. * @arg I2C_IT_STOPF: Stop detection flag (Slave mode)
  20573. * @arg I2C_IT_ADD10: 10-bit header sent flag (Master mode)
  20574. * @arg I2C_IT_BTF: Byte transfer finished flag
  20575. * @arg I2C_IT_ADDR: Address sent flag (Master mode) "ADSL"
  20576. * Address matched flag (Slave mode)"ENDAD"
  20577. * @arg I2C_IT_SB: Start bit flag (Master mode)
  20578. * @retval The new state of I2C_IT (SET or RESET).
  20579. */
  20580. ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, uint32_t I2C_IT)
  20581. {
  20582. ITStatus bitstatus = RESET;
  20583. uint32_t enablestatus = 0;
  20584. /* Check the parameters */
  20585. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20586. assert_param(IS_I2C_GET_IT(I2C_IT));
  20587. /* Check if the interrupt source is enabled or not */
  20588. enablestatus = (uint32_t)(((I2C_IT & ITEN_Mask) >> 16) & (I2Cx->CR2)) ;
  20589. /* Get bit[23:0] of the flag */
  20590. I2C_IT &= FLAG_Mask;
  20591. /* Check the status of the specified I2C flag */
  20592. if (((I2Cx->SR1 & I2C_IT) != (uint32_t)RESET) && enablestatus)
  20593. {
  20594. /* I2C_IT is set */
  20595. bitstatus = SET;
  20596. }
  20597. else
  20598. {
  20599. /* I2C_IT is reset */
  20600. bitstatus = RESET;
  20601. }
  20602. /* Return the I2C_IT status */
  20603. return bitstatus;
  20604. }
  20605. /**
  20606. * @brief Clears the I2Cx’s interrupt pending bits.
  20607. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  20608. * @param I2C_IT: specifies the interrupt pending bit to clear.
  20609. * This parameter can be any combination of the following values:
  20610. * @arg I2C_IT_SMBALERT: SMBus Alert interrupt
  20611. * @arg I2C_IT_TIMEOUT: Timeout or Tlow error interrupt
  20612. * @arg I2C_IT_PECERR: PEC error in reception interrupt
  20613. * @arg I2C_IT_OVR: Overrun/Underrun interrupt (Slave mode)
  20614. * @arg I2C_IT_AF: Acknowledge failure interrupt
  20615. * @arg I2C_IT_ARLO: Arbitration lost interrupt (Master mode)
  20616. * @arg I2C_IT_BERR: Bus error interrupt
  20617. *
  20618. * @note
  20619. * - STOPF (STOP detection) is cleared by software sequence: a read operation
  20620. * to I2C_SR1 register (I2C_GetITStatus()) followed by a write operation to
  20621. * I2C_CR1 register (I2C_Cmd() to re-enable the I2C peripheral).
  20622. * - ADD10 (10-bit header sent) is cleared by software sequence: a read
  20623. * operation to I2C_SR1 (I2C_GetITStatus()) followed by writing the second
  20624. * byte of the address in I2C_DR register.
  20625. * - BTF (Byte Transfer Finished) is cleared by software sequence: a read
  20626. * operation to I2C_SR1 register (I2C_GetITStatus()) followed by a
  20627. * read/write to I2C_DR register (I2C_SendData()).
  20628. * - ADDR (Address sent) is cleared by software sequence: a read operation to
  20629. * I2C_SR1 register (I2C_GetITStatus()) followed by a read operation to
  20630. * I2C_SR2 register ((void)(I2Cx->SR2)).
  20631. * - SB (Start Bit) is cleared by software sequence: a read operation to
  20632. * I2C_SR1 register (I2C_GetITStatus()) followed by a write operation to
  20633. * I2C_DR register (I2C_SendData()).
  20634. * @retval None
  20635. */
  20636. void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, uint32_t I2C_IT)
  20637. {
  20638. uint32_t flagpos = 0;
  20639. /* Check the parameters */
  20640. assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  20641. assert_param(IS_I2C_CLEAR_IT(I2C_IT));
  20642. /* Get the I2C flag position */
  20643. flagpos = I2C_IT & FLAG_Mask;
  20644. /* Clear the selected I2C flag */
  20645. I2Cx->SR1 = (uint16_t)~flagpos;
  20646. }
  20647. /**
  20648. * @}
  20649. */
  20650. /**
  20651. * @}
  20652. */
  20653. /**
  20654. * @}
  20655. */
  20656. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  20657. /**
  20658. ******************************************************************************
  20659. * @file stm32f10x_flash.c
  20660. * @author MCD Application Team
  20661. * @version V3.5.0
  20662. * @date 11-March-2011
  20663. * @brief This file provides all the FLASH firmware functions.
  20664. ******************************************************************************
  20665. * @attention
  20666. *
  20667. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  20668. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  20669. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  20670. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  20671. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  20672. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  20673. *
  20674. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  20675. ******************************************************************************
  20676. */
  20677. /* Includes ------------------------------------------------------------------*/
  20678. #include "stm32f10x_flash.h"
  20679. /** @addtogroup STM32F10x_StdPeriph_Driver
  20680. * @{
  20681. */
  20682. /** @defgroup FLASH
  20683. * @brief FLASH driver modules
  20684. * @{
  20685. */
  20686. /** @defgroup FLASH_Private_TypesDefinitions
  20687. * @{
  20688. */
  20689. /**
  20690. * @}
  20691. */
  20692. /** @defgroup FLASH_Private_Defines
  20693. * @{
  20694. */
  20695. /* Flash Access Control Register bits */
  20696. #define ACR_LATENCY_Mask ((uint32_t)0x00000038)
  20697. #define ACR_HLFCYA_Mask ((uint32_t)0xFFFFFFF7)
  20698. #define ACR_PRFTBE_Mask ((uint32_t)0xFFFFFFEF)
  20699. /* Flash Access Control Register bits */
  20700. #define ACR_PRFTBS_Mask ((uint32_t)0x00000020)
  20701. /* Flash Control Register bits */
  20702. #define CR_PG_Set ((uint32_t)0x00000001)
  20703. #define CR_PG_Reset ((uint32_t)0x00001FFE)
  20704. #define CR_PER_Set ((uint32_t)0x00000002)
  20705. #define CR_PER_Reset ((uint32_t)0x00001FFD)
  20706. #define CR_MER_Set ((uint32_t)0x00000004)
  20707. #define CR_MER_Reset ((uint32_t)0x00001FFB)
  20708. #define CR_OPTPG_Set ((uint32_t)0x00000010)
  20709. #define CR_OPTPG_Reset ((uint32_t)0x00001FEF)
  20710. #define CR_OPTER_Set ((uint32_t)0x00000020)
  20711. #define CR_OPTER_Reset ((uint32_t)0x00001FDF)
  20712. #define CR_STRT_Set ((uint32_t)0x00000040)
  20713. #define CR_LOCK_Set ((uint32_t)0x00000080)
  20714. /* FLASH Mask */
  20715. #define RDPRT_Mask ((uint32_t)0x00000002)
  20716. #define WRP0_Mask ((uint32_t)0x000000FF)
  20717. #define WRP1_Mask ((uint32_t)0x0000FF00)
  20718. #define WRP2_Mask ((uint32_t)0x00FF0000)
  20719. #define WRP3_Mask ((uint32_t)0xFF000000)
  20720. #define OB_USER_BFB2 ((uint16_t)0x0008)
  20721. /* FLASH Keys */
  20722. #define RDP_Key ((uint16_t)0x00A5)
  20723. #define FLASH_KEY1 ((uint32_t)0x45670123)
  20724. #define FLASH_KEY2 ((uint32_t)0xCDEF89AB)
  20725. /* FLASH BANK address */
  20726. #define FLASH_BANK1_END_ADDRESS ((uint32_t)0x807FFFF)
  20727. /* Delay definition */
  20728. #define EraseTimeout ((uint32_t)0x000B0000)
  20729. #define ProgramTimeout ((uint32_t)0x00002000)
  20730. /**
  20731. * @}
  20732. */
  20733. /** @defgroup FLASH_Private_Macros
  20734. * @{
  20735. */
  20736. /**
  20737. * @}
  20738. */
  20739. /** @defgroup FLASH_Private_Variables
  20740. * @{
  20741. */
  20742. /**
  20743. * @}
  20744. */
  20745. /** @defgroup FLASH_Private_FunctionPrototypes
  20746. * @{
  20747. */
  20748. /**
  20749. * @}
  20750. */
  20751. /** @defgroup FLASH_Private_Functions
  20752. * @{
  20753. */
  20754. /**
  20755. @code
  20756. This driver provides functions to configure and program the Flash memory of all STM32F10x devices,
  20757. including the latest STM32F10x_XL density devices.
  20758. STM32F10x_XL devices feature up to 1 Mbyte with dual bank architecture for read-while-write (RWW) capability:
  20759. - bank1: fixed size of 512 Kbytes (256 pages of 2Kbytes each)
  20760. - bank2: up to 512 Kbytes (up to 256 pages of 2Kbytes each)
  20761. While other STM32F10x devices features only one bank with memory up to 512 Kbytes.
  20762. In version V3.3.0, some functions were updated and new ones were added to support
  20763. STM32F10x_XL devices. Thus some functions manages all devices, while other are
  20764. dedicated for XL devices only.
  20765. The table below presents the list of available functions depending on the used STM32F10x devices.
  20766. ***************************************************
  20767. * Legacy functions used for all STM32F10x devices *
  20768. ***************************************************
  20769. +----------------------------------------------------------------------------------------------------------------------------------+
  20770. | Functions prototypes |STM32F10x_XL|Other STM32F10x| Comments |
  20771. | | devices | devices | |
  20772. |----------------------------------------------------------------------------------------------------------------------------------|
  20773. |FLASH_SetLatency | Yes | Yes | No change |
  20774. |----------------------------------------------------------------------------------------------------------------------------------|
  20775. |FLASH_HalfCycleAccessCmd | Yes | Yes | No change |
  20776. |----------------------------------------------------------------------------------------------------------------------------------|
  20777. |FLASH_PrefetchBufferCmd | Yes | Yes | No change |
  20778. |----------------------------------------------------------------------------------------------------------------------------------|
  20779. |FLASH_Unlock | Yes | Yes | - For STM32F10X_XL devices: unlock Bank1 and Bank2. |
  20780. | | | | - For other devices: unlock Bank1 and it is equivalent |
  20781. | | | | to FLASH_UnlockBank1 function. |
  20782. |----------------------------------------------------------------------------------------------------------------------------------|
  20783. |FLASH_Lock | Yes | Yes | - For STM32F10X_XL devices: lock Bank1 and Bank2. |
  20784. | | | | - For other devices: lock Bank1 and it is equivalent |
  20785. | | | | to FLASH_LockBank1 function. |
  20786. |----------------------------------------------------------------------------------------------------------------------------------|
  20787. |FLASH_ErasePage | Yes | Yes | - For STM32F10x_XL devices: erase a page in Bank1 and Bank2 |
  20788. | | | | - For other devices: erase a page in Bank1 |
  20789. |----------------------------------------------------------------------------------------------------------------------------------|
  20790. |FLASH_EraseAllPages | Yes | Yes | - For STM32F10x_XL devices: erase all pages in Bank1 and Bank2 |
  20791. | | | | - For other devices: erase all pages in Bank1 |
  20792. |----------------------------------------------------------------------------------------------------------------------------------|
  20793. |FLASH_EraseOptionBytes | Yes | Yes | No change |
  20794. |----------------------------------------------------------------------------------------------------------------------------------|
  20795. |FLASH_ProgramWord | Yes | Yes | Updated to program up to 1MByte (depending on the used device) |
  20796. |----------------------------------------------------------------------------------------------------------------------------------|
  20797. |FLASH_ProgramHalfWord | Yes | Yes | Updated to program up to 1MByte (depending on the used device) |
  20798. |----------------------------------------------------------------------------------------------------------------------------------|
  20799. |FLASH_ProgramOptionByteData | Yes | Yes | No change |
  20800. |----------------------------------------------------------------------------------------------------------------------------------|
  20801. |FLASH_EnableWriteProtection | Yes | Yes | No change |
  20802. |----------------------------------------------------------------------------------------------------------------------------------|
  20803. |FLASH_ReadOutProtection | Yes | Yes | No change |
  20804. |----------------------------------------------------------------------------------------------------------------------------------|
  20805. |FLASH_UserOptionByteConfig | Yes | Yes | No change |
  20806. |----------------------------------------------------------------------------------------------------------------------------------|
  20807. |FLASH_GetUserOptionByte | Yes | Yes | No change |
  20808. |----------------------------------------------------------------------------------------------------------------------------------|
  20809. |FLASH_GetWriteProtectionOptionByte | Yes | Yes | No change |
  20810. |----------------------------------------------------------------------------------------------------------------------------------|
  20811. |FLASH_GetReadOutProtectionStatus | Yes | Yes | No change |
  20812. |----------------------------------------------------------------------------------------------------------------------------------|
  20813. |FLASH_GetPrefetchBufferStatus | Yes | Yes | No change |
  20814. |----------------------------------------------------------------------------------------------------------------------------------|
  20815. |FLASH_ITConfig | Yes | Yes | - For STM32F10x_XL devices: enable Bank1 and Bank2's interrupts|
  20816. | | | | - For other devices: enable Bank1's interrupts |
  20817. |----------------------------------------------------------------------------------------------------------------------------------|
  20818. |FLASH_GetFlagStatus | Yes | Yes | - For STM32F10x_XL devices: return Bank1 and Bank2's flag status|
  20819. | | | | - For other devices: return Bank1's flag status |
  20820. |----------------------------------------------------------------------------------------------------------------------------------|
  20821. |FLASH_ClearFlag | Yes | Yes | - For STM32F10x_XL devices: clear Bank1 and Bank2's flag |
  20822. | | | | - For other devices: clear Bank1's flag |
  20823. |----------------------------------------------------------------------------------------------------------------------------------|
  20824. |FLASH_GetStatus | Yes | Yes | - Return the status of Bank1 (for all devices) |
  20825. | | | | equivalent to FLASH_GetBank1Status function |
  20826. |----------------------------------------------------------------------------------------------------------------------------------|
  20827. |FLASH_WaitForLastOperation | Yes | Yes | - Wait for Bank1 last operation (for all devices) |
  20828. | | | | equivalent to: FLASH_WaitForLastBank1Operation function |
  20829. +----------------------------------------------------------------------------------------------------------------------------------+
  20830. ************************************************************************************************************************
  20831. * New functions used for all STM32F10x devices to manage Bank1: *
  20832. * - These functions are mainly useful for STM32F10x_XL density devices, to have separate control for Bank1 and bank2 *
  20833. * - For other devices, these functions are optional (covered by functions listed above) *
  20834. ************************************************************************************************************************
  20835. +----------------------------------------------------------------------------------------------------------------------------------+
  20836. | Functions prototypes |STM32F10x_XL|Other STM32F10x| Comments |
  20837. | | devices | devices | |
  20838. |----------------------------------------------------------------------------------------------------------------------------------|
  20839. | FLASH_UnlockBank1 | Yes | Yes | - Unlock Bank1 |
  20840. |----------------------------------------------------------------------------------------------------------------------------------|
  20841. |FLASH_LockBank1 | Yes | Yes | - Lock Bank1 |
  20842. |----------------------------------------------------------------------------------------------------------------------------------|
  20843. | FLASH_EraseAllBank1Pages | Yes | Yes | - Erase all pages in Bank1 |
  20844. |----------------------------------------------------------------------------------------------------------------------------------|
  20845. | FLASH_GetBank1Status | Yes | Yes | - Return the status of Bank1 |
  20846. |----------------------------------------------------------------------------------------------------------------------------------|
  20847. | FLASH_WaitForLastBank1Operation | Yes | Yes | - Wait for Bank1 last operation |
  20848. +----------------------------------------------------------------------------------------------------------------------------------+
  20849. *****************************************************************************
  20850. * New Functions used only with STM32F10x_XL density devices to manage Bank2 *
  20851. *****************************************************************************
  20852. +----------------------------------------------------------------------------------------------------------------------------------+
  20853. | Functions prototypes |STM32F10x_XL|Other STM32F10x| Comments |
  20854. | | devices | devices | |
  20855. |----------------------------------------------------------------------------------------------------------------------------------|
  20856. | FLASH_UnlockBank2 | Yes | No | - Unlock Bank2 |
  20857. |----------------------------------------------------------------------------------------------------------------------------------|
  20858. |FLASH_LockBank2 | Yes | No | - Lock Bank2 |
  20859. |----------------------------------------------------------------------------------------------------------------------------------|
  20860. | FLASH_EraseAllBank2Pages | Yes | No | - Erase all pages in Bank2 |
  20861. |----------------------------------------------------------------------------------------------------------------------------------|
  20862. | FLASH_GetBank2Status | Yes | No | - Return the status of Bank2 |
  20863. |----------------------------------------------------------------------------------------------------------------------------------|
  20864. | FLASH_WaitForLastBank2Operation | Yes | No | - Wait for Bank2 last operation |
  20865. |----------------------------------------------------------------------------------------------------------------------------------|
  20866. | FLASH_BootConfig | Yes | No | - Configure to boot from Bank1 or Bank2 |
  20867. +----------------------------------------------------------------------------------------------------------------------------------+
  20868. @endcode
  20869. */
  20870. /**
  20871. * @brief Sets the code latency value.
  20872. * @note This function can be used for all STM32F10x devices.
  20873. * @param FLASH_Latency: specifies the FLASH Latency value.
  20874. * This parameter can be one of the following values:
  20875. * @arg FLASH_Latency_0: FLASH Zero Latency cycle
  20876. * @arg FLASH_Latency_1: FLASH One Latency cycle
  20877. * @arg FLASH_Latency_2: FLASH Two Latency cycles
  20878. * @retval None
  20879. */
  20880. void FLASH_SetLatency(uint32_t FLASH_Latency)
  20881. {
  20882. uint32_t tmpreg = 0;
  20883. /* Check the parameters */
  20884. assert_param(IS_FLASH_LATENCY(FLASH_Latency));
  20885. /* Read the ACR register */
  20886. tmpreg = FLASH->ACR;
  20887. /* Sets the Latency value */
  20888. tmpreg &= ACR_LATENCY_Mask;
  20889. tmpreg |= FLASH_Latency;
  20890. /* Write the ACR register */
  20891. FLASH->ACR = tmpreg;
  20892. }
  20893. /**
  20894. * @brief Enables or disables the Half cycle flash access.
  20895. * @note This function can be used for all STM32F10x devices.
  20896. * @param FLASH_HalfCycleAccess: specifies the FLASH Half cycle Access mode.
  20897. * This parameter can be one of the following values:
  20898. * @arg FLASH_HalfCycleAccess_Enable: FLASH Half Cycle Enable
  20899. * @arg FLASH_HalfCycleAccess_Disable: FLASH Half Cycle Disable
  20900. * @retval None
  20901. */
  20902. void FLASH_HalfCycleAccessCmd(uint32_t FLASH_HalfCycleAccess)
  20903. {
  20904. /* Check the parameters */
  20905. assert_param(IS_FLASH_HALFCYCLEACCESS_STATE(FLASH_HalfCycleAccess));
  20906. /* Enable or disable the Half cycle access */
  20907. FLASH->ACR &= ACR_HLFCYA_Mask;
  20908. FLASH->ACR |= FLASH_HalfCycleAccess;
  20909. }
  20910. /**
  20911. * @brief Enables or disables the Prefetch Buffer.
  20912. * @note This function can be used for all STM32F10x devices.
  20913. * @param FLASH_PrefetchBuffer: specifies the Prefetch buffer status.
  20914. * This parameter can be one of the following values:
  20915. * @arg FLASH_PrefetchBuffer_Enable: FLASH Prefetch Buffer Enable
  20916. * @arg FLASH_PrefetchBuffer_Disable: FLASH Prefetch Buffer Disable
  20917. * @retval None
  20918. */
  20919. void FLASH_PrefetchBufferCmd(uint32_t FLASH_PrefetchBuffer)
  20920. {
  20921. /* Check the parameters */
  20922. assert_param(IS_FLASH_PREFETCHBUFFER_STATE(FLASH_PrefetchBuffer));
  20923. /* Enable or disable the Prefetch Buffer */
  20924. FLASH->ACR &= ACR_PRFTBE_Mask;
  20925. FLASH->ACR |= FLASH_PrefetchBuffer;
  20926. }
  20927. /**
  20928. * @brief Unlocks the FLASH Program Erase Controller.
  20929. * @note This function can be used for all STM32F10x devices.
  20930. * - For STM32F10X_XL devices this function unlocks Bank1 and Bank2.
  20931. * - For all other devices it unlocks Bank1 and it is equivalent
  20932. * to FLASH_UnlockBank1 function..
  20933. * @param None
  20934. * @retval None
  20935. */
  20936. void FLASH_Unlock(void)
  20937. {
  20938. /* Authorize the FPEC of Bank1 Access */
  20939. FLASH->KEYR = FLASH_KEY1;
  20940. FLASH->KEYR = FLASH_KEY2;
  20941. #ifdef STM32F10X_XL
  20942. /* Authorize the FPEC of Bank2 Access */
  20943. FLASH->KEYR2 = FLASH_KEY1;
  20944. FLASH->KEYR2 = FLASH_KEY2;
  20945. #endif /* STM32F10X_XL */
  20946. }
  20947. /**
  20948. * @brief Unlocks the FLASH Bank1 Program Erase Controller.
  20949. * @note This function can be used for all STM32F10x devices.
  20950. * - For STM32F10X_XL devices this function unlocks Bank1.
  20951. * - For all other devices it unlocks Bank1 and it is
  20952. * equivalent to FLASH_Unlock function.
  20953. * @param None
  20954. * @retval None
  20955. */
  20956. void FLASH_UnlockBank1(void)
  20957. {
  20958. /* Authorize the FPEC of Bank1 Access */
  20959. FLASH->KEYR = FLASH_KEY1;
  20960. FLASH->KEYR = FLASH_KEY2;
  20961. }
  20962. #ifdef STM32F10X_XL
  20963. /**
  20964. * @brief Unlocks the FLASH Bank2 Program Erase Controller.
  20965. * @note This function can be used only for STM32F10X_XL density devices.
  20966. * @param None
  20967. * @retval None
  20968. */
  20969. void FLASH_UnlockBank2(void)
  20970. {
  20971. /* Authorize the FPEC of Bank2 Access */
  20972. FLASH->KEYR2 = FLASH_KEY1;
  20973. FLASH->KEYR2 = FLASH_KEY2;
  20974. }
  20975. #endif /* STM32F10X_XL */
  20976. /**
  20977. * @brief Locks the FLASH Program Erase Controller.
  20978. * @note This function can be used for all STM32F10x devices.
  20979. * - For STM32F10X_XL devices this function Locks Bank1 and Bank2.
  20980. * - For all other devices it Locks Bank1 and it is equivalent
  20981. * to FLASH_LockBank1 function.
  20982. * @param None
  20983. * @retval None
  20984. */
  20985. void FLASH_Lock(void)
  20986. {
  20987. /* Set the Lock Bit to lock the FPEC and the CR of Bank1 */
  20988. FLASH->CR |= CR_LOCK_Set;
  20989. #ifdef STM32F10X_XL
  20990. /* Set the Lock Bit to lock the FPEC and the CR of Bank2 */
  20991. FLASH->CR2 |= CR_LOCK_Set;
  20992. #endif /* STM32F10X_XL */
  20993. }
  20994. /**
  20995. * @brief Locks the FLASH Bank1 Program Erase Controller.
  20996. * @note this function can be used for all STM32F10x devices.
  20997. * - For STM32F10X_XL devices this function Locks Bank1.
  20998. * - For all other devices it Locks Bank1 and it is equivalent
  20999. * to FLASH_Lock function.
  21000. * @param None
  21001. * @retval None
  21002. */
  21003. void FLASH_LockBank1(void)
  21004. {
  21005. /* Set the Lock Bit to lock the FPEC and the CR of Bank1 */
  21006. FLASH->CR |= CR_LOCK_Set;
  21007. }
  21008. #ifdef STM32F10X_XL
  21009. /**
  21010. * @brief Locks the FLASH Bank2 Program Erase Controller.
  21011. * @note This function can be used only for STM32F10X_XL density devices.
  21012. * @param None
  21013. * @retval None
  21014. */
  21015. void FLASH_LockBank2(void)
  21016. {
  21017. /* Set the Lock Bit to lock the FPEC and the CR of Bank2 */
  21018. FLASH->CR2 |= CR_LOCK_Set;
  21019. }
  21020. #endif /* STM32F10X_XL */
  21021. /**
  21022. * @brief Erases a specified FLASH page.
  21023. * @note This function can be used for all STM32F10x devices.
  21024. * @param Page_Address: The page address to be erased.
  21025. * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
  21026. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  21027. */
  21028. FLASH_Status FLASH_ErasePage(uint32_t Page_Address)
  21029. {
  21030. FLASH_Status status = FLASH_COMPLETE;
  21031. /* Check the parameters */
  21032. assert_param(IS_FLASH_ADDRESS(Page_Address));
  21033. #ifdef STM32F10X_XL
  21034. if(Page_Address < FLASH_BANK1_END_ADDRESS)
  21035. {
  21036. /* Wait for last operation to be completed */
  21037. status = FLASH_WaitForLastBank1Operation(EraseTimeout);
  21038. if(status == FLASH_COMPLETE)
  21039. {
  21040. /* if the previous operation is completed, proceed to erase the page */
  21041. FLASH->CR|= CR_PER_Set;
  21042. FLASH->AR = Page_Address;
  21043. FLASH->CR|= CR_STRT_Set;
  21044. /* Wait for last operation to be completed */
  21045. status = FLASH_WaitForLastBank1Operation(EraseTimeout);
  21046. /* Disable the PER Bit */
  21047. FLASH->CR &= CR_PER_Reset;
  21048. }
  21049. }
  21050. else
  21051. {
  21052. /* Wait for last operation to be completed */
  21053. status = FLASH_WaitForLastBank2Operation(EraseTimeout);
  21054. if(status == FLASH_COMPLETE)
  21055. {
  21056. /* if the previous operation is completed, proceed to erase the page */
  21057. FLASH->CR2|= CR_PER_Set;
  21058. FLASH->AR2 = Page_Address;
  21059. FLASH->CR2|= CR_STRT_Set;
  21060. /* Wait for last operation to be completed */
  21061. status = FLASH_WaitForLastBank2Operation(EraseTimeout);
  21062. /* Disable the PER Bit */
  21063. FLASH->CR2 &= CR_PER_Reset;
  21064. }
  21065. }
  21066. #else
  21067. /* Wait for last operation to be completed */
  21068. status = FLASH_WaitForLastOperation(EraseTimeout);
  21069. if(status == FLASH_COMPLETE)
  21070. {
  21071. /* if the previous operation is completed, proceed to erase the page */
  21072. FLASH->CR|= CR_PER_Set;
  21073. FLASH->AR = Page_Address;
  21074. FLASH->CR|= CR_STRT_Set;
  21075. /* Wait for last operation to be completed */
  21076. status = FLASH_WaitForLastOperation(EraseTimeout);
  21077. /* Disable the PER Bit */
  21078. FLASH->CR &= CR_PER_Reset;
  21079. }
  21080. #endif /* STM32F10X_XL */
  21081. /* Return the Erase Status */
  21082. return status;
  21083. }
  21084. /**
  21085. * @brief Erases all FLASH pages.
  21086. * @note This function can be used for all STM32F10x devices.
  21087. * @param None
  21088. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  21089. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  21090. */
  21091. FLASH_Status FLASH_EraseAllPages(void)
  21092. {
  21093. FLASH_Status status = FLASH_COMPLETE;
  21094. #ifdef STM32F10X_XL
  21095. /* Wait for last operation to be completed */
  21096. status = FLASH_WaitForLastBank1Operation(EraseTimeout);
  21097. if(status == FLASH_COMPLETE)
  21098. {
  21099. /* if the previous operation is completed, proceed to erase all pages */
  21100. FLASH->CR |= CR_MER_Set;
  21101. FLASH->CR |= CR_STRT_Set;
  21102. /* Wait for last operation to be completed */
  21103. status = FLASH_WaitForLastBank1Operation(EraseTimeout);
  21104. /* Disable the MER Bit */
  21105. FLASH->CR &= CR_MER_Reset;
  21106. }
  21107. if(status == FLASH_COMPLETE)
  21108. {
  21109. /* if the previous operation is completed, proceed to erase all pages */
  21110. FLASH->CR2 |= CR_MER_Set;
  21111. FLASH->CR2 |= CR_STRT_Set;
  21112. /* Wait for last operation to be completed */
  21113. status = FLASH_WaitForLastBank2Operation(EraseTimeout);
  21114. /* Disable the MER Bit */
  21115. FLASH->CR2 &= CR_MER_Reset;
  21116. }
  21117. #else
  21118. /* Wait for last operation to be completed */
  21119. status = FLASH_WaitForLastOperation(EraseTimeout);
  21120. if(status == FLASH_COMPLETE)
  21121. {
  21122. /* if the previous operation is completed, proceed to erase all pages */
  21123. FLASH->CR |= CR_MER_Set;
  21124. FLASH->CR |= CR_STRT_Set;
  21125. /* Wait for last operation to be completed */
  21126. status = FLASH_WaitForLastOperation(EraseTimeout);
  21127. /* Disable the MER Bit */
  21128. FLASH->CR &= CR_MER_Reset;
  21129. }
  21130. #endif /* STM32F10X_XL */
  21131. /* Return the Erase Status */
  21132. return status;
  21133. }
  21134. /**
  21135. * @brief Erases all Bank1 FLASH pages.
  21136. * @note This function can be used for all STM32F10x devices.
  21137. * - For STM32F10X_XL devices this function erases all Bank1 pages.
  21138. * - For all other devices it erases all Bank1 pages and it is equivalent
  21139. * to FLASH_EraseAllPages function.
  21140. * @param None
  21141. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  21142. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  21143. */
  21144. FLASH_Status FLASH_EraseAllBank1Pages(void)
  21145. {
  21146. FLASH_Status status = FLASH_COMPLETE;
  21147. /* Wait for last operation to be completed */
  21148. status = FLASH_WaitForLastBank1Operation(EraseTimeout);
  21149. if(status == FLASH_COMPLETE)
  21150. {
  21151. /* if the previous operation is completed, proceed to erase all pages */
  21152. FLASH->CR |= CR_MER_Set;
  21153. FLASH->CR |= CR_STRT_Set;
  21154. /* Wait for last operation to be completed */
  21155. status = FLASH_WaitForLastBank1Operation(EraseTimeout);
  21156. /* Disable the MER Bit */
  21157. FLASH->CR &= CR_MER_Reset;
  21158. }
  21159. /* Return the Erase Status */
  21160. return status;
  21161. }
  21162. #ifdef STM32F10X_XL
  21163. /**
  21164. * @brief Erases all Bank2 FLASH pages.
  21165. * @note This function can be used only for STM32F10x_XL density devices.
  21166. * @param None
  21167. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  21168. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  21169. */
  21170. FLASH_Status FLASH_EraseAllBank2Pages(void)
  21171. {
  21172. FLASH_Status status = FLASH_COMPLETE;
  21173. /* Wait for last operation to be completed */
  21174. status = FLASH_WaitForLastBank2Operation(EraseTimeout);
  21175. if(status == FLASH_COMPLETE)
  21176. {
  21177. /* if the previous operation is completed, proceed to erase all pages */
  21178. FLASH->CR2 |= CR_MER_Set;
  21179. FLASH->CR2 |= CR_STRT_Set;
  21180. /* Wait for last operation to be completed */
  21181. status = FLASH_WaitForLastBank2Operation(EraseTimeout);
  21182. /* Disable the MER Bit */
  21183. FLASH->CR2 &= CR_MER_Reset;
  21184. }
  21185. /* Return the Erase Status */
  21186. return status;
  21187. }
  21188. #endif /* STM32F10X_XL */
  21189. /**
  21190. * @brief Erases the FLASH option bytes.
  21191. * @note This functions erases all option bytes except the Read protection (RDP).
  21192. * @note This function can be used for all STM32F10x devices.
  21193. * @param None
  21194. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  21195. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  21196. */
  21197. FLASH_Status FLASH_EraseOptionBytes(void)
  21198. {
  21199. uint16_t rdptmp = RDP_Key;
  21200. FLASH_Status status = FLASH_COMPLETE;
  21201. /* Get the actual read protection Option Byte value */
  21202. if(FLASH_GetReadOutProtectionStatus() != RESET)
  21203. {
  21204. rdptmp = 0x00;
  21205. }
  21206. /* Wait for last operation to be completed */
  21207. status = FLASH_WaitForLastOperation(EraseTimeout);
  21208. if(status == FLASH_COMPLETE)
  21209. {
  21210. /* Authorize the small information block programming */
  21211. FLASH->OPTKEYR = FLASH_KEY1;
  21212. FLASH->OPTKEYR = FLASH_KEY2;
  21213. /* if the previous operation is completed, proceed to erase the option bytes */
  21214. FLASH->CR |= CR_OPTER_Set;
  21215. FLASH->CR |= CR_STRT_Set;
  21216. /* Wait for last operation to be completed */
  21217. status = FLASH_WaitForLastOperation(EraseTimeout);
  21218. if(status == FLASH_COMPLETE)
  21219. {
  21220. /* if the erase operation is completed, disable the OPTER Bit */
  21221. FLASH->CR &= CR_OPTER_Reset;
  21222. /* Enable the Option Bytes Programming operation */
  21223. FLASH->CR |= CR_OPTPG_Set;
  21224. /* Restore the last read protection Option Byte value */
  21225. OB->RDP = (uint16_t)rdptmp;
  21226. /* Wait for last operation to be completed */
  21227. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21228. if(status != FLASH_TIMEOUT)
  21229. {
  21230. /* if the program operation is completed, disable the OPTPG Bit */
  21231. FLASH->CR &= CR_OPTPG_Reset;
  21232. }
  21233. }
  21234. else
  21235. {
  21236. if (status != FLASH_TIMEOUT)
  21237. {
  21238. /* Disable the OPTPG Bit */
  21239. FLASH->CR &= CR_OPTPG_Reset;
  21240. }
  21241. }
  21242. }
  21243. /* Return the erase status */
  21244. return status;
  21245. }
  21246. /**
  21247. * @brief Programs a word at a specified address.
  21248. * @note This function can be used for all STM32F10x devices.
  21249. * @param Address: specifies the address to be programmed.
  21250. * @param Data: specifies the data to be programmed.
  21251. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  21252. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  21253. */
  21254. FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
  21255. {
  21256. FLASH_Status status = FLASH_COMPLETE;
  21257. __IO uint32_t tmp = 0;
  21258. /* Check the parameters */
  21259. assert_param(IS_FLASH_ADDRESS(Address));
  21260. #ifdef STM32F10X_XL
  21261. if(Address < FLASH_BANK1_END_ADDRESS - 2)
  21262. {
  21263. /* Wait for last operation to be completed */
  21264. status = FLASH_WaitForLastBank1Operation(ProgramTimeout);
  21265. if(status == FLASH_COMPLETE)
  21266. {
  21267. /* if the previous operation is completed, proceed to program the new first
  21268. half word */
  21269. FLASH->CR |= CR_PG_Set;
  21270. *(__IO uint16_t*)Address = (uint16_t)Data;
  21271. /* Wait for last operation to be completed */
  21272. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21273. if(status == FLASH_COMPLETE)
  21274. {
  21275. /* if the previous operation is completed, proceed to program the new second
  21276. half word */
  21277. tmp = Address + 2;
  21278. *(__IO uint16_t*) tmp = Data >> 16;
  21279. /* Wait for last operation to be completed */
  21280. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21281. /* Disable the PG Bit */
  21282. FLASH->CR &= CR_PG_Reset;
  21283. }
  21284. else
  21285. {
  21286. /* Disable the PG Bit */
  21287. FLASH->CR &= CR_PG_Reset;
  21288. }
  21289. }
  21290. }
  21291. else if(Address == (FLASH_BANK1_END_ADDRESS - 1))
  21292. {
  21293. /* Wait for last operation to be completed */
  21294. status = FLASH_WaitForLastBank1Operation(ProgramTimeout);
  21295. if(status == FLASH_COMPLETE)
  21296. {
  21297. /* if the previous operation is completed, proceed to program the new first
  21298. half word */
  21299. FLASH->CR |= CR_PG_Set;
  21300. *(__IO uint16_t*)Address = (uint16_t)Data;
  21301. /* Wait for last operation to be completed */
  21302. status = FLASH_WaitForLastBank1Operation(ProgramTimeout);
  21303. /* Disable the PG Bit */
  21304. FLASH->CR &= CR_PG_Reset;
  21305. }
  21306. else
  21307. {
  21308. /* Disable the PG Bit */
  21309. FLASH->CR &= CR_PG_Reset;
  21310. }
  21311. /* Wait for last operation to be completed */
  21312. status = FLASH_WaitForLastBank2Operation(ProgramTimeout);
  21313. if(status == FLASH_COMPLETE)
  21314. {
  21315. /* if the previous operation is completed, proceed to program the new second
  21316. half word */
  21317. FLASH->CR2 |= CR_PG_Set;
  21318. tmp = Address + 2;
  21319. *(__IO uint16_t*) tmp = Data >> 16;
  21320. /* Wait for last operation to be completed */
  21321. status = FLASH_WaitForLastBank2Operation(ProgramTimeout);
  21322. /* Disable the PG Bit */
  21323. FLASH->CR2 &= CR_PG_Reset;
  21324. }
  21325. else
  21326. {
  21327. /* Disable the PG Bit */
  21328. FLASH->CR2 &= CR_PG_Reset;
  21329. }
  21330. }
  21331. else
  21332. {
  21333. /* Wait for last operation to be completed */
  21334. status = FLASH_WaitForLastBank2Operation(ProgramTimeout);
  21335. if(status == FLASH_COMPLETE)
  21336. {
  21337. /* if the previous operation is completed, proceed to program the new first
  21338. half word */
  21339. FLASH->CR2 |= CR_PG_Set;
  21340. *(__IO uint16_t*)Address = (uint16_t)Data;
  21341. /* Wait for last operation to be completed */
  21342. status = FLASH_WaitForLastBank2Operation(ProgramTimeout);
  21343. if(status == FLASH_COMPLETE)
  21344. {
  21345. /* if the previous operation is completed, proceed to program the new second
  21346. half word */
  21347. tmp = Address + 2;
  21348. *(__IO uint16_t*) tmp = Data >> 16;
  21349. /* Wait for last operation to be completed */
  21350. status = FLASH_WaitForLastBank2Operation(ProgramTimeout);
  21351. /* Disable the PG Bit */
  21352. FLASH->CR2 &= CR_PG_Reset;
  21353. }
  21354. else
  21355. {
  21356. /* Disable the PG Bit */
  21357. FLASH->CR2 &= CR_PG_Reset;
  21358. }
  21359. }
  21360. }
  21361. #else
  21362. /* Wait for last operation to be completed */
  21363. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21364. if(status == FLASH_COMPLETE)
  21365. {
  21366. /* if the previous operation is completed, proceed to program the new first
  21367. half word */
  21368. FLASH->CR |= CR_PG_Set;
  21369. *(__IO uint16_t*)Address = (uint16_t)Data;
  21370. /* Wait for last operation to be completed */
  21371. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21372. if(status == FLASH_COMPLETE)
  21373. {
  21374. /* if the previous operation is completed, proceed to program the new second
  21375. half word */
  21376. tmp = Address + 2;
  21377. *(__IO uint16_t*) tmp = Data >> 16;
  21378. /* Wait for last operation to be completed */
  21379. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21380. /* Disable the PG Bit */
  21381. FLASH->CR &= CR_PG_Reset;
  21382. }
  21383. else
  21384. {
  21385. /* Disable the PG Bit */
  21386. FLASH->CR &= CR_PG_Reset;
  21387. }
  21388. }
  21389. #endif /* STM32F10X_XL */
  21390. /* Return the Program Status */
  21391. return status;
  21392. }
  21393. /**
  21394. * @brief Programs a half word at a specified address.
  21395. * @note This function can be used for all STM32F10x devices.
  21396. * @param Address: specifies the address to be programmed.
  21397. * @param Data: specifies the data to be programmed.
  21398. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  21399. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  21400. */
  21401. FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
  21402. {
  21403. FLASH_Status status = FLASH_COMPLETE;
  21404. /* Check the parameters */
  21405. assert_param(IS_FLASH_ADDRESS(Address));
  21406. #ifdef STM32F10X_XL
  21407. /* Wait for last operation to be completed */
  21408. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21409. if(Address < FLASH_BANK1_END_ADDRESS)
  21410. {
  21411. if(status == FLASH_COMPLETE)
  21412. {
  21413. /* if the previous operation is completed, proceed to program the new data */
  21414. FLASH->CR |= CR_PG_Set;
  21415. *(__IO uint16_t*)Address = Data;
  21416. /* Wait for last operation to be completed */
  21417. status = FLASH_WaitForLastBank1Operation(ProgramTimeout);
  21418. /* Disable the PG Bit */
  21419. FLASH->CR &= CR_PG_Reset;
  21420. }
  21421. }
  21422. else
  21423. {
  21424. if(status == FLASH_COMPLETE)
  21425. {
  21426. /* if the previous operation is completed, proceed to program the new data */
  21427. FLASH->CR2 |= CR_PG_Set;
  21428. *(__IO uint16_t*)Address = Data;
  21429. /* Wait for last operation to be completed */
  21430. status = FLASH_WaitForLastBank2Operation(ProgramTimeout);
  21431. /* Disable the PG Bit */
  21432. FLASH->CR2 &= CR_PG_Reset;
  21433. }
  21434. }
  21435. #else
  21436. /* Wait for last operation to be completed */
  21437. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21438. if(status == FLASH_COMPLETE)
  21439. {
  21440. /* if the previous operation is completed, proceed to program the new data */
  21441. FLASH->CR |= CR_PG_Set;
  21442. *(__IO uint16_t*)Address = Data;
  21443. /* Wait for last operation to be completed */
  21444. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21445. /* Disable the PG Bit */
  21446. FLASH->CR &= CR_PG_Reset;
  21447. }
  21448. #endif /* STM32F10X_XL */
  21449. /* Return the Program Status */
  21450. return status;
  21451. }
  21452. /**
  21453. * @brief Programs a half word at a specified Option Byte Data address.
  21454. * @note This function can be used for all STM32F10x devices.
  21455. * @param Address: specifies the address to be programmed.
  21456. * This parameter can be 0x1FFFF804 or 0x1FFFF806.
  21457. * @param Data: specifies the data to be programmed.
  21458. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  21459. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  21460. */
  21461. FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data)
  21462. {
  21463. FLASH_Status status = FLASH_COMPLETE;
  21464. /* Check the parameters */
  21465. assert_param(IS_OB_DATA_ADDRESS(Address));
  21466. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21467. if(status == FLASH_COMPLETE)
  21468. {
  21469. /* Authorize the small information block programming */
  21470. FLASH->OPTKEYR = FLASH_KEY1;
  21471. FLASH->OPTKEYR = FLASH_KEY2;
  21472. /* Enables the Option Bytes Programming operation */
  21473. FLASH->CR |= CR_OPTPG_Set;
  21474. *(__IO uint16_t*)Address = Data;
  21475. /* Wait for last operation to be completed */
  21476. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21477. if(status != FLASH_TIMEOUT)
  21478. {
  21479. /* if the program operation is completed, disable the OPTPG Bit */
  21480. FLASH->CR &= CR_OPTPG_Reset;
  21481. }
  21482. }
  21483. /* Return the Option Byte Data Program Status */
  21484. return status;
  21485. }
  21486. /**
  21487. * @brief Write protects the desired pages
  21488. * @note This function can be used for all STM32F10x devices.
  21489. * @param FLASH_Pages: specifies the address of the pages to be write protected.
  21490. * This parameter can be:
  21491. * @arg For @b STM32_Low-density_devices: value between FLASH_WRProt_Pages0to3 and FLASH_WRProt_Pages28to31
  21492. * @arg For @b STM32_Medium-density_devices: value between FLASH_WRProt_Pages0to3
  21493. * and FLASH_WRProt_Pages124to127
  21494. * @arg For @b STM32_High-density_devices: value between FLASH_WRProt_Pages0to1 and
  21495. * FLASH_WRProt_Pages60to61 or FLASH_WRProt_Pages62to255
  21496. * @arg For @b STM32_Connectivity_line_devices: value between FLASH_WRProt_Pages0to1 and
  21497. * FLASH_WRProt_Pages60to61 or FLASH_WRProt_Pages62to127
  21498. * @arg For @b STM32_XL-density_devices: value between FLASH_WRProt_Pages0to1 and
  21499. * FLASH_WRProt_Pages60to61 or FLASH_WRProt_Pages62to511
  21500. * @arg FLASH_WRProt_AllPages
  21501. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  21502. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  21503. */
  21504. FLASH_Status FLASH_EnableWriteProtection(uint32_t FLASH_Pages)
  21505. {
  21506. uint16_t WRP0_Data = 0xFFFF, WRP1_Data = 0xFFFF, WRP2_Data = 0xFFFF, WRP3_Data = 0xFFFF;
  21507. FLASH_Status status = FLASH_COMPLETE;
  21508. /* Check the parameters */
  21509. assert_param(IS_FLASH_WRPROT_PAGE(FLASH_Pages));
  21510. FLASH_Pages = (uint32_t)(~FLASH_Pages);
  21511. WRP0_Data = (uint16_t)(FLASH_Pages & WRP0_Mask);
  21512. WRP1_Data = (uint16_t)((FLASH_Pages & WRP1_Mask) >> 8);
  21513. WRP2_Data = (uint16_t)((FLASH_Pages & WRP2_Mask) >> 16);
  21514. WRP3_Data = (uint16_t)((FLASH_Pages & WRP3_Mask) >> 24);
  21515. /* Wait for last operation to be completed */
  21516. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21517. if(status == FLASH_COMPLETE)
  21518. {
  21519. /* Authorizes the small information block programming */
  21520. FLASH->OPTKEYR = FLASH_KEY1;
  21521. FLASH->OPTKEYR = FLASH_KEY2;
  21522. FLASH->CR |= CR_OPTPG_Set;
  21523. if(WRP0_Data != 0xFF)
  21524. {
  21525. OB->WRP0 = WRP0_Data;
  21526. /* Wait for last operation to be completed */
  21527. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21528. }
  21529. if((status == FLASH_COMPLETE) && (WRP1_Data != 0xFF))
  21530. {
  21531. OB->WRP1 = WRP1_Data;
  21532. /* Wait for last operation to be completed */
  21533. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21534. }
  21535. if((status == FLASH_COMPLETE) && (WRP2_Data != 0xFF))
  21536. {
  21537. OB->WRP2 = WRP2_Data;
  21538. /* Wait for last operation to be completed */
  21539. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21540. }
  21541. if((status == FLASH_COMPLETE)&& (WRP3_Data != 0xFF))
  21542. {
  21543. OB->WRP3 = WRP3_Data;
  21544. /* Wait for last operation to be completed */
  21545. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21546. }
  21547. if(status != FLASH_TIMEOUT)
  21548. {
  21549. /* if the program operation is completed, disable the OPTPG Bit */
  21550. FLASH->CR &= CR_OPTPG_Reset;
  21551. }
  21552. }
  21553. /* Return the write protection operation Status */
  21554. return status;
  21555. }
  21556. /**
  21557. * @brief Enables or disables the read out protection.
  21558. * @note If the user has already programmed the other option bytes before calling
  21559. * this function, he must re-program them since this function erases all option bytes.
  21560. * @note This function can be used for all STM32F10x devices.
  21561. * @param Newstate: new state of the ReadOut Protection.
  21562. * This parameter can be: ENABLE or DISABLE.
  21563. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  21564. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  21565. */
  21566. FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState)
  21567. {
  21568. FLASH_Status status = FLASH_COMPLETE;
  21569. /* Check the parameters */
  21570. assert_param(IS_FUNCTIONAL_STATE(NewState));
  21571. status = FLASH_WaitForLastOperation(EraseTimeout);
  21572. if(status == FLASH_COMPLETE)
  21573. {
  21574. /* Authorizes the small information block programming */
  21575. FLASH->OPTKEYR = FLASH_KEY1;
  21576. FLASH->OPTKEYR = FLASH_KEY2;
  21577. FLASH->CR |= CR_OPTER_Set;
  21578. FLASH->CR |= CR_STRT_Set;
  21579. /* Wait for last operation to be completed */
  21580. status = FLASH_WaitForLastOperation(EraseTimeout);
  21581. if(status == FLASH_COMPLETE)
  21582. {
  21583. /* if the erase operation is completed, disable the OPTER Bit */
  21584. FLASH->CR &= CR_OPTER_Reset;
  21585. /* Enable the Option Bytes Programming operation */
  21586. FLASH->CR |= CR_OPTPG_Set;
  21587. if(NewState != DISABLE)
  21588. {
  21589. OB->RDP = 0x00;
  21590. }
  21591. else
  21592. {
  21593. OB->RDP = RDP_Key;
  21594. }
  21595. /* Wait for last operation to be completed */
  21596. status = FLASH_WaitForLastOperation(EraseTimeout);
  21597. if(status != FLASH_TIMEOUT)
  21598. {
  21599. /* if the program operation is completed, disable the OPTPG Bit */
  21600. FLASH->CR &= CR_OPTPG_Reset;
  21601. }
  21602. }
  21603. else
  21604. {
  21605. if(status != FLASH_TIMEOUT)
  21606. {
  21607. /* Disable the OPTER Bit */
  21608. FLASH->CR &= CR_OPTER_Reset;
  21609. }
  21610. }
  21611. }
  21612. /* Return the protection operation Status */
  21613. return status;
  21614. }
  21615. /**
  21616. * @brief Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
  21617. * @note This function can be used for all STM32F10x devices.
  21618. * @param OB_IWDG: Selects the IWDG mode
  21619. * This parameter can be one of the following values:
  21620. * @arg OB_IWDG_SW: Software IWDG selected
  21621. * @arg OB_IWDG_HW: Hardware IWDG selected
  21622. * @param OB_STOP: Reset event when entering STOP mode.
  21623. * This parameter can be one of the following values:
  21624. * @arg OB_STOP_NoRST: No reset generated when entering in STOP
  21625. * @arg OB_STOP_RST: Reset generated when entering in STOP
  21626. * @param OB_STDBY: Reset event when entering Standby mode.
  21627. * This parameter can be one of the following values:
  21628. * @arg OB_STDBY_NoRST: No reset generated when entering in STANDBY
  21629. * @arg OB_STDBY_RST: Reset generated when entering in STANDBY
  21630. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  21631. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  21632. */
  21633. FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint16_t OB_STDBY)
  21634. {
  21635. FLASH_Status status = FLASH_COMPLETE;
  21636. /* Check the parameters */
  21637. assert_param(IS_OB_IWDG_SOURCE(OB_IWDG));
  21638. assert_param(IS_OB_STOP_SOURCE(OB_STOP));
  21639. assert_param(IS_OB_STDBY_SOURCE(OB_STDBY));
  21640. /* Authorize the small information block programming */
  21641. FLASH->OPTKEYR = FLASH_KEY1;
  21642. FLASH->OPTKEYR = FLASH_KEY2;
  21643. /* Wait for last operation to be completed */
  21644. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21645. if(status == FLASH_COMPLETE)
  21646. {
  21647. /* Enable the Option Bytes Programming operation */
  21648. FLASH->CR |= CR_OPTPG_Set;
  21649. OB->USER = OB_IWDG | (uint16_t)(OB_STOP | (uint16_t)(OB_STDBY | ((uint16_t)0xF8)));
  21650. /* Wait for last operation to be completed */
  21651. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21652. if(status != FLASH_TIMEOUT)
  21653. {
  21654. /* if the program operation is completed, disable the OPTPG Bit */
  21655. FLASH->CR &= CR_OPTPG_Reset;
  21656. }
  21657. }
  21658. /* Return the Option Byte program Status */
  21659. return status;
  21660. }
  21661. #ifdef STM32F10X_XL
  21662. /**
  21663. * @brief Configures to boot from Bank1 or Bank2.
  21664. * @note This function can be used only for STM32F10x_XL density devices.
  21665. * @param FLASH_BOOT: select the FLASH Bank to boot from.
  21666. * This parameter can be one of the following values:
  21667. * @arg FLASH_BOOT_Bank1: At startup, if boot pins are set in boot from user Flash
  21668. * position and this parameter is selected the device will boot from Bank1(Default).
  21669. * @arg FLASH_BOOT_Bank2: At startup, if boot pins are set in boot from user Flash
  21670. * position and this parameter is selected the device will boot from Bank2 or Bank1,
  21671. * depending on the activation of the bank. The active banks are checked in
  21672. * the following order: Bank2, followed by Bank1.
  21673. * The active bank is recognized by the value programmed at the base address
  21674. * of the respective bank (corresponding to the initial stack pointer value
  21675. * in the interrupt vector table).
  21676. * For more information, please refer to AN2606 from www.st.com.
  21677. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  21678. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  21679. */
  21680. FLASH_Status FLASH_BootConfig(uint16_t FLASH_BOOT)
  21681. {
  21682. FLASH_Status status = FLASH_COMPLETE;
  21683. assert_param(IS_FLASH_BOOT(FLASH_BOOT));
  21684. /* Authorize the small information block programming */
  21685. FLASH->OPTKEYR = FLASH_KEY1;
  21686. FLASH->OPTKEYR = FLASH_KEY2;
  21687. /* Wait for last operation to be completed */
  21688. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21689. if(status == FLASH_COMPLETE)
  21690. {
  21691. /* Enable the Option Bytes Programming operation */
  21692. FLASH->CR |= CR_OPTPG_Set;
  21693. if(FLASH_BOOT == FLASH_BOOT_Bank1)
  21694. {
  21695. OB->USER |= OB_USER_BFB2;
  21696. }
  21697. else
  21698. {
  21699. OB->USER &= (uint16_t)(~(uint16_t)(OB_USER_BFB2));
  21700. }
  21701. /* Wait for last operation to be completed */
  21702. status = FLASH_WaitForLastOperation(ProgramTimeout);
  21703. if(status != FLASH_TIMEOUT)
  21704. {
  21705. /* if the program operation is completed, disable the OPTPG Bit */
  21706. FLASH->CR &= CR_OPTPG_Reset;
  21707. }
  21708. }
  21709. /* Return the Option Byte program Status */
  21710. return status;
  21711. }
  21712. #endif /* STM32F10X_XL */
  21713. /**
  21714. * @brief Returns the FLASH User Option Bytes values.
  21715. * @note This function can be used for all STM32F10x devices.
  21716. * @param None
  21717. * @retval The FLASH User Option Bytes values:IWDG_SW(Bit0), RST_STOP(Bit1)
  21718. * and RST_STDBY(Bit2).
  21719. */
  21720. uint32_t FLASH_GetUserOptionByte(void)
  21721. {
  21722. /* Return the User Option Byte */
  21723. return (uint32_t)(FLASH->OBR >> 2);
  21724. }
  21725. /**
  21726. * @brief Returns the FLASH Write Protection Option Bytes Register value.
  21727. * @note This function can be used for all STM32F10x devices.
  21728. * @param None
  21729. * @retval The FLASH Write Protection Option Bytes Register value
  21730. */
  21731. uint32_t FLASH_GetWriteProtectionOptionByte(void)
  21732. {
  21733. /* Return the Flash write protection Register value */
  21734. return (uint32_t)(FLASH->WRPR);
  21735. }
  21736. /**
  21737. * @brief Checks whether the FLASH Read Out Protection Status is set or not.
  21738. * @note This function can be used for all STM32F10x devices.
  21739. * @param None
  21740. * @retval FLASH ReadOut Protection Status(SET or RESET)
  21741. */
  21742. FlagStatus FLASH_GetReadOutProtectionStatus(void)
  21743. {
  21744. FlagStatus readoutstatus = RESET;
  21745. if ((FLASH->OBR & RDPRT_Mask) != (uint32_t)RESET)
  21746. {
  21747. readoutstatus = SET;
  21748. }
  21749. else
  21750. {
  21751. readoutstatus = RESET;
  21752. }
  21753. return readoutstatus;
  21754. }
  21755. /**
  21756. * @brief Checks whether the FLASH Prefetch Buffer status is set or not.
  21757. * @note This function can be used for all STM32F10x devices.
  21758. * @param None
  21759. * @retval FLASH Prefetch Buffer Status (SET or RESET).
  21760. */
  21761. FlagStatus FLASH_GetPrefetchBufferStatus(void)
  21762. {
  21763. FlagStatus bitstatus = RESET;
  21764. if ((FLASH->ACR & ACR_PRFTBS_Mask) != (uint32_t)RESET)
  21765. {
  21766. bitstatus = SET;
  21767. }
  21768. else
  21769. {
  21770. bitstatus = RESET;
  21771. }
  21772. /* Return the new state of FLASH Prefetch Buffer Status (SET or RESET) */
  21773. return bitstatus;
  21774. }
  21775. /**
  21776. * @brief Enables or disables the specified FLASH interrupts.
  21777. * @note This function can be used for all STM32F10x devices.
  21778. * - For STM32F10X_XL devices, enables or disables the specified FLASH interrupts
  21779. for Bank1 and Bank2.
  21780. * - For other devices it enables or disables the specified FLASH interrupts for Bank1.
  21781. * @param FLASH_IT: specifies the FLASH interrupt sources to be enabled or disabled.
  21782. * This parameter can be any combination of the following values:
  21783. * @arg FLASH_IT_ERROR: FLASH Error Interrupt
  21784. * @arg FLASH_IT_EOP: FLASH end of operation Interrupt
  21785. * @param NewState: new state of the specified Flash interrupts.
  21786. * This parameter can be: ENABLE or DISABLE.
  21787. * @retval None
  21788. */
  21789. void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState)
  21790. {
  21791. #ifdef STM32F10X_XL
  21792. /* Check the parameters */
  21793. assert_param(IS_FLASH_IT(FLASH_IT));
  21794. assert_param(IS_FUNCTIONAL_STATE(NewState));
  21795. if((FLASH_IT & 0x80000000) != 0x0)
  21796. {
  21797. if(NewState != DISABLE)
  21798. {
  21799. /* Enable the interrupt sources */
  21800. FLASH->CR2 |= (FLASH_IT & 0x7FFFFFFF);
  21801. }
  21802. else
  21803. {
  21804. /* Disable the interrupt sources */
  21805. FLASH->CR2 &= ~(uint32_t)(FLASH_IT & 0x7FFFFFFF);
  21806. }
  21807. }
  21808. else
  21809. {
  21810. if(NewState != DISABLE)
  21811. {
  21812. /* Enable the interrupt sources */
  21813. FLASH->CR |= FLASH_IT;
  21814. }
  21815. else
  21816. {
  21817. /* Disable the interrupt sources */
  21818. FLASH->CR &= ~(uint32_t)FLASH_IT;
  21819. }
  21820. }
  21821. #else
  21822. /* Check the parameters */
  21823. assert_param(IS_FLASH_IT(FLASH_IT));
  21824. assert_param(IS_FUNCTIONAL_STATE(NewState));
  21825. if(NewState != DISABLE)
  21826. {
  21827. /* Enable the interrupt sources */
  21828. FLASH->CR |= FLASH_IT;
  21829. }
  21830. else
  21831. {
  21832. /* Disable the interrupt sources */
  21833. FLASH->CR &= ~(uint32_t)FLASH_IT;
  21834. }
  21835. #endif /* STM32F10X_XL */
  21836. }
  21837. /**
  21838. * @brief Checks whether the specified FLASH flag is set or not.
  21839. * @note This function can be used for all STM32F10x devices.
  21840. * - For STM32F10X_XL devices, this function checks whether the specified
  21841. * Bank1 or Bank2 flag is set or not.
  21842. * - For other devices, it checks whether the specified Bank1 flag is
  21843. * set or not.
  21844. * @param FLASH_FLAG: specifies the FLASH flag to check.
  21845. * This parameter can be one of the following values:
  21846. * @arg FLASH_FLAG_BSY: FLASH Busy flag
  21847. * @arg FLASH_FLAG_PGERR: FLASH Program error flag
  21848. * @arg FLASH_FLAG_WRPRTERR: FLASH Write protected error flag
  21849. * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
  21850. * @arg FLASH_FLAG_OPTERR: FLASH Option Byte error flag
  21851. * @retval The new state of FLASH_FLAG (SET or RESET).
  21852. */
  21853. FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG)
  21854. {
  21855. FlagStatus bitstatus = RESET;
  21856. #ifdef STM32F10X_XL
  21857. /* Check the parameters */
  21858. assert_param(IS_FLASH_GET_FLAG(FLASH_FLAG)) ;
  21859. if(FLASH_FLAG == FLASH_FLAG_OPTERR)
  21860. {
  21861. if((FLASH->OBR & FLASH_FLAG_OPTERR) != (uint32_t)RESET)
  21862. {
  21863. bitstatus = SET;
  21864. }
  21865. else
  21866. {
  21867. bitstatus = RESET;
  21868. }
  21869. }
  21870. else
  21871. {
  21872. if((FLASH_FLAG & 0x80000000) != 0x0)
  21873. {
  21874. if((FLASH->SR2 & FLASH_FLAG) != (uint32_t)RESET)
  21875. {
  21876. bitstatus = SET;
  21877. }
  21878. else
  21879. {
  21880. bitstatus = RESET;
  21881. }
  21882. }
  21883. else
  21884. {
  21885. if((FLASH->SR & FLASH_FLAG) != (uint32_t)RESET)
  21886. {
  21887. bitstatus = SET;
  21888. }
  21889. else
  21890. {
  21891. bitstatus = RESET;
  21892. }
  21893. }
  21894. }
  21895. #else
  21896. /* Check the parameters */
  21897. assert_param(IS_FLASH_GET_FLAG(FLASH_FLAG)) ;
  21898. if(FLASH_FLAG == FLASH_FLAG_OPTERR)
  21899. {
  21900. if((FLASH->OBR & FLASH_FLAG_OPTERR) != (uint32_t)RESET)
  21901. {
  21902. bitstatus = SET;
  21903. }
  21904. else
  21905. {
  21906. bitstatus = RESET;
  21907. }
  21908. }
  21909. else
  21910. {
  21911. if((FLASH->SR & FLASH_FLAG) != (uint32_t)RESET)
  21912. {
  21913. bitstatus = SET;
  21914. }
  21915. else
  21916. {
  21917. bitstatus = RESET;
  21918. }
  21919. }
  21920. #endif /* STM32F10X_XL */
  21921. /* Return the new state of FLASH_FLAG (SET or RESET) */
  21922. return bitstatus;
  21923. }
  21924. /**
  21925. * @brief Clears the FLASH's pending flags.
  21926. * @note This function can be used for all STM32F10x devices.
  21927. * - For STM32F10X_XL devices, this function clears Bank1 or Bank2’s pending flags
  21928. * - For other devices, it clears Bank1’s pending flags.
  21929. * @param FLASH_FLAG: specifies the FLASH flags to clear.
  21930. * This parameter can be any combination of the following values:
  21931. * @arg FLASH_FLAG_PGERR: FLASH Program error flag
  21932. * @arg FLASH_FLAG_WRPRTERR: FLASH Write protected error flag
  21933. * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
  21934. * @retval None
  21935. */
  21936. void FLASH_ClearFlag(uint32_t FLASH_FLAG)
  21937. {
  21938. #ifdef STM32F10X_XL
  21939. /* Check the parameters */
  21940. assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG)) ;
  21941. if((FLASH_FLAG & 0x80000000) != 0x0)
  21942. {
  21943. /* Clear the flags */
  21944. FLASH->SR2 = FLASH_FLAG;
  21945. }
  21946. else
  21947. {
  21948. /* Clear the flags */
  21949. FLASH->SR = FLASH_FLAG;
  21950. }
  21951. #else
  21952. /* Check the parameters */
  21953. assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG)) ;
  21954. /* Clear the flags */
  21955. FLASH->SR = FLASH_FLAG;
  21956. #endif /* STM32F10X_XL */
  21957. }
  21958. /**
  21959. * @brief Returns the FLASH Status.
  21960. * @note This function can be used for all STM32F10x devices, it is equivalent
  21961. * to FLASH_GetBank1Status function.
  21962. * @param None
  21963. * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
  21964. * FLASH_ERROR_WRP or FLASH_COMPLETE
  21965. */
  21966. FLASH_Status FLASH_GetStatus(void)
  21967. {
  21968. FLASH_Status flashstatus = FLASH_COMPLETE;
  21969. if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY)
  21970. {
  21971. flashstatus = FLASH_BUSY;
  21972. }
  21973. else
  21974. {
  21975. if((FLASH->SR & FLASH_FLAG_PGERR) != 0)
  21976. {
  21977. flashstatus = FLASH_ERROR_PG;
  21978. }
  21979. else
  21980. {
  21981. if((FLASH->SR & FLASH_FLAG_WRPRTERR) != 0 )
  21982. {
  21983. flashstatus = FLASH_ERROR_WRP;
  21984. }
  21985. else
  21986. {
  21987. flashstatus = FLASH_COMPLETE;
  21988. }
  21989. }
  21990. }
  21991. /* Return the Flash Status */
  21992. return flashstatus;
  21993. }
  21994. /**
  21995. * @brief Returns the FLASH Bank1 Status.
  21996. * @note This function can be used for all STM32F10x devices, it is equivalent
  21997. * to FLASH_GetStatus function.
  21998. * @param None
  21999. * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
  22000. * FLASH_ERROR_WRP or FLASH_COMPLETE
  22001. */
  22002. FLASH_Status FLASH_GetBank1Status(void)
  22003. {
  22004. FLASH_Status flashstatus = FLASH_COMPLETE;
  22005. if((FLASH->SR & FLASH_FLAG_BANK1_BSY) == FLASH_FLAG_BSY)
  22006. {
  22007. flashstatus = FLASH_BUSY;
  22008. }
  22009. else
  22010. {
  22011. if((FLASH->SR & FLASH_FLAG_BANK1_PGERR) != 0)
  22012. {
  22013. flashstatus = FLASH_ERROR_PG;
  22014. }
  22015. else
  22016. {
  22017. if((FLASH->SR & FLASH_FLAG_BANK1_WRPRTERR) != 0 )
  22018. {
  22019. flashstatus = FLASH_ERROR_WRP;
  22020. }
  22021. else
  22022. {
  22023. flashstatus = FLASH_COMPLETE;
  22024. }
  22025. }
  22026. }
  22027. /* Return the Flash Status */
  22028. return flashstatus;
  22029. }
  22030. #ifdef STM32F10X_XL
  22031. /**
  22032. * @brief Returns the FLASH Bank2 Status.
  22033. * @note This function can be used for STM32F10x_XL density devices.
  22034. * @param None
  22035. * @retval FLASH Status: The returned value can be: FLASH_BUSY, FLASH_ERROR_PG,
  22036. * FLASH_ERROR_WRP or FLASH_COMPLETE
  22037. */
  22038. FLASH_Status FLASH_GetBank2Status(void)
  22039. {
  22040. FLASH_Status flashstatus = FLASH_COMPLETE;
  22041. if((FLASH->SR2 & (FLASH_FLAG_BANK2_BSY & 0x7FFFFFFF)) == (FLASH_FLAG_BANK2_BSY & 0x7FFFFFFF))
  22042. {
  22043. flashstatus = FLASH_BUSY;
  22044. }
  22045. else
  22046. {
  22047. if((FLASH->SR2 & (FLASH_FLAG_BANK2_PGERR & 0x7FFFFFFF)) != 0)
  22048. {
  22049. flashstatus = FLASH_ERROR_PG;
  22050. }
  22051. else
  22052. {
  22053. if((FLASH->SR2 & (FLASH_FLAG_BANK2_WRPRTERR & 0x7FFFFFFF)) != 0 )
  22054. {
  22055. flashstatus = FLASH_ERROR_WRP;
  22056. }
  22057. else
  22058. {
  22059. flashstatus = FLASH_COMPLETE;
  22060. }
  22061. }
  22062. }
  22063. /* Return the Flash Status */
  22064. return flashstatus;
  22065. }
  22066. #endif /* STM32F10X_XL */
  22067. /**
  22068. * @brief Waits for a Flash operation to complete or a TIMEOUT to occur.
  22069. * @note This function can be used for all STM32F10x devices,
  22070. * it is equivalent to FLASH_WaitForLastBank1Operation.
  22071. * - For STM32F10X_XL devices this function waits for a Bank1 Flash operation
  22072. * to complete or a TIMEOUT to occur.
  22073. * - For all other devices it waits for a Flash operation to complete
  22074. * or a TIMEOUT to occur.
  22075. * @param Timeout: FLASH programming Timeout
  22076. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  22077. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  22078. */
  22079. FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout)
  22080. {
  22081. FLASH_Status status = FLASH_COMPLETE;
  22082. /* Check for the Flash Status */
  22083. status = FLASH_GetBank1Status();
  22084. /* Wait for a Flash operation to complete or a TIMEOUT to occur */
  22085. while((status == FLASH_BUSY) && (Timeout != 0x00))
  22086. {
  22087. status = FLASH_GetBank1Status();
  22088. Timeout--;
  22089. }
  22090. if(Timeout == 0x00 )
  22091. {
  22092. status = FLASH_TIMEOUT;
  22093. }
  22094. /* Return the operation status */
  22095. return status;
  22096. }
  22097. /**
  22098. * @brief Waits for a Flash operation on Bank1 to complete or a TIMEOUT to occur.
  22099. * @note This function can be used for all STM32F10x devices,
  22100. * it is equivalent to FLASH_WaitForLastOperation.
  22101. * @param Timeout: FLASH programming Timeout
  22102. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  22103. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  22104. */
  22105. FLASH_Status FLASH_WaitForLastBank1Operation(uint32_t Timeout)
  22106. {
  22107. FLASH_Status status = FLASH_COMPLETE;
  22108. /* Check for the Flash Status */
  22109. status = FLASH_GetBank1Status();
  22110. /* Wait for a Flash operation to complete or a TIMEOUT to occur */
  22111. while((status == FLASH_FLAG_BANK1_BSY) && (Timeout != 0x00))
  22112. {
  22113. status = FLASH_GetBank1Status();
  22114. Timeout--;
  22115. }
  22116. if(Timeout == 0x00 )
  22117. {
  22118. status = FLASH_TIMEOUT;
  22119. }
  22120. /* Return the operation status */
  22121. return status;
  22122. }
  22123. #ifdef STM32F10X_XL
  22124. /**
  22125. * @brief Waits for a Flash operation on Bank2 to complete or a TIMEOUT to occur.
  22126. * @note This function can be used only for STM32F10x_XL density devices.
  22127. * @param Timeout: FLASH programming Timeout
  22128. * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  22129. * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT.
  22130. */
  22131. FLASH_Status FLASH_WaitForLastBank2Operation(uint32_t Timeout)
  22132. {
  22133. FLASH_Status status = FLASH_COMPLETE;
  22134. /* Check for the Flash Status */
  22135. status = FLASH_GetBank2Status();
  22136. /* Wait for a Flash operation to complete or a TIMEOUT to occur */
  22137. while((status == (FLASH_FLAG_BANK2_BSY & 0x7FFFFFFF)) && (Timeout != 0x00))
  22138. {
  22139. status = FLASH_GetBank2Status();
  22140. Timeout--;
  22141. }
  22142. if(Timeout == 0x00 )
  22143. {
  22144. status = FLASH_TIMEOUT;
  22145. }
  22146. /* Return the operation status */
  22147. return status;
  22148. }
  22149. #endif /* STM32F10X_XL */
  22150. /**
  22151. * @}
  22152. */
  22153. /**
  22154. * @}
  22155. */
  22156. /**
  22157. * @}
  22158. */
  22159. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  22160. /**
  22161. ******************************************************************************
  22162. * @file stm32f10x_cec.c
  22163. * @author MCD Application Team
  22164. * @version V3.5.0
  22165. * @date 11-March-2011
  22166. * @brief This file provides all the CEC firmware functions.
  22167. ******************************************************************************
  22168. * @attention
  22169. *
  22170. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  22171. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  22172. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  22173. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  22174. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  22175. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  22176. *
  22177. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  22178. ******************************************************************************
  22179. */
  22180. /* Includes ------------------------------------------------------------------*/
  22181. #include "stm32f10x_cec.h"
  22182. #include "stm32f10x_rcc.h"
  22183. /** @addtogroup STM32F10x_StdPeriph_Driver
  22184. * @{
  22185. */
  22186. /** @defgroup CEC
  22187. * @brief CEC driver modules
  22188. * @{
  22189. */
  22190. /** @defgroup CEC_Private_TypesDefinitions
  22191. * @{
  22192. */
  22193. /**
  22194. * @}
  22195. */
  22196. /** @defgroup CEC_Private_Defines
  22197. * @{
  22198. */
  22199. /* ------------ CEC registers bit address in the alias region ----------- */
  22200. #define CEC_OFFSET (CEC_BASE - PERIPH_BASE)
  22201. /* --- CFGR Register ---*/
  22202. /* Alias word address of PE bit */
  22203. #define CFGR_OFFSET (CEC_OFFSET + 0x00)
  22204. #define PE_BitNumber 0x00
  22205. #define CFGR_PE_BB (PERIPH_BB_BASE + (CFGR_OFFSET * 32) + (PE_BitNumber * 4))
  22206. /* Alias word address of IE bit */
  22207. #define IE_BitNumber 0x01
  22208. #define CFGR_IE_BB (PERIPH_BB_BASE + (CFGR_OFFSET * 32) + (IE_BitNumber * 4))
  22209. /* --- CSR Register ---*/
  22210. /* Alias word address of TSOM bit */
  22211. #define CSR_OFFSET (CEC_OFFSET + 0x10)
  22212. #define TSOM_BitNumber 0x00
  22213. #define CSR_TSOM_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TSOM_BitNumber * 4))
  22214. /* Alias word address of TEOM bit */
  22215. #define TEOM_BitNumber 0x01
  22216. #define CSR_TEOM_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEOM_BitNumber * 4))
  22217. #define CFGR_CLEAR_Mask (uint8_t)(0xF3) /* CFGR register Mask */
  22218. #define FLAG_Mask ((uint32_t)0x00FFFFFF) /* CEC FLAG mask */
  22219. /**
  22220. * @}
  22221. */
  22222. /** @defgroup CEC_Private_Macros
  22223. * @{
  22224. */
  22225. /**
  22226. * @}
  22227. */
  22228. /** @defgroup CEC_Private_Variables
  22229. * @{
  22230. */
  22231. /**
  22232. * @}
  22233. */
  22234. /** @defgroup CEC_Private_FunctionPrototypes
  22235. * @{
  22236. */
  22237. /**
  22238. * @}
  22239. */
  22240. /** @defgroup CEC_Private_Functions
  22241. * @{
  22242. */
  22243. /**
  22244. * @brief Deinitializes the CEC peripheral registers to their default reset
  22245. * values.
  22246. * @param None
  22247. * @retval None
  22248. */
  22249. void CEC_DeInit(void)
  22250. {
  22251. /* Enable CEC reset state */
  22252. RCC_APB1PeriphResetCmd(RCC_APB1Periph_CEC, ENABLE);
  22253. /* Release CEC from reset state */
  22254. RCC_APB1PeriphResetCmd(RCC_APB1Periph_CEC, DISABLE);
  22255. }
  22256. /**
  22257. * @brief Initializes the CEC peripheral according to the specified
  22258. * parameters in the CEC_InitStruct.
  22259. * @param CEC_InitStruct: pointer to an CEC_InitTypeDef structure that
  22260. * contains the configuration information for the specified
  22261. * CEC peripheral.
  22262. * @retval None
  22263. */
  22264. void CEC_Init(CEC_InitTypeDef* CEC_InitStruct)
  22265. {
  22266. uint16_t tmpreg = 0;
  22267. /* Check the parameters */
  22268. assert_param(IS_CEC_BIT_TIMING_ERROR_MODE(CEC_InitStruct->CEC_BitTimingMode));
  22269. assert_param(IS_CEC_BIT_PERIOD_ERROR_MODE(CEC_InitStruct->CEC_BitPeriodMode));
  22270. /*---------------------------- CEC CFGR Configuration -----------------*/
  22271. /* Get the CEC CFGR value */
  22272. tmpreg = CEC->CFGR;
  22273. /* Clear BTEM and BPEM bits */
  22274. tmpreg &= CFGR_CLEAR_Mask;
  22275. /* Configure CEC: Bit Timing Error and Bit Period Error */
  22276. tmpreg |= (uint16_t)(CEC_InitStruct->CEC_BitTimingMode | CEC_InitStruct->CEC_BitPeriodMode);
  22277. /* Write to CEC CFGR register*/
  22278. CEC->CFGR = tmpreg;
  22279. }
  22280. /**
  22281. * @brief Enables or disables the specified CEC peripheral.
  22282. * @param NewState: new state of the CEC peripheral.
  22283. * This parameter can be: ENABLE or DISABLE.
  22284. * @retval None
  22285. */
  22286. void CEC_Cmd(FunctionalState NewState)
  22287. {
  22288. /* Check the parameters */
  22289. assert_param(IS_FUNCTIONAL_STATE(NewState));
  22290. *(__IO uint32_t *) CFGR_PE_BB = (uint32_t)NewState;
  22291. if(NewState == DISABLE)
  22292. {
  22293. /* Wait until the PE bit is cleared by hardware (Idle Line detected) */
  22294. while((CEC->CFGR & CEC_CFGR_PE) != (uint32_t)RESET)
  22295. {
  22296. }
  22297. }
  22298. }
  22299. /**
  22300. * @brief Enables or disables the CEC interrupt.
  22301. * @param NewState: new state of the CEC interrupt.
  22302. * This parameter can be: ENABLE or DISABLE.
  22303. * @retval None
  22304. */
  22305. void CEC_ITConfig(FunctionalState NewState)
  22306. {
  22307. /* Check the parameters */
  22308. assert_param(IS_FUNCTIONAL_STATE(NewState));
  22309. *(__IO uint32_t *) CFGR_IE_BB = (uint32_t)NewState;
  22310. }
  22311. /**
  22312. * @brief Defines the Own Address of the CEC device.
  22313. * @param CEC_OwnAddress: The CEC own address
  22314. * @retval None
  22315. */
  22316. void CEC_OwnAddressConfig(uint8_t CEC_OwnAddress)
  22317. {
  22318. /* Check the parameters */
  22319. assert_param(IS_CEC_ADDRESS(CEC_OwnAddress));
  22320. /* Set the CEC own address */
  22321. CEC->OAR = CEC_OwnAddress;
  22322. }
  22323. /**
  22324. * @brief Sets the CEC prescaler value.
  22325. * @param CEC_Prescaler: CEC prescaler new value
  22326. * @retval None
  22327. */
  22328. void CEC_SetPrescaler(uint16_t CEC_Prescaler)
  22329. {
  22330. /* Check the parameters */
  22331. assert_param(IS_CEC_PRESCALER(CEC_Prescaler));
  22332. /* Set the Prescaler value*/
  22333. CEC->PRES = CEC_Prescaler;
  22334. }
  22335. /**
  22336. * @brief Transmits single data through the CEC peripheral.
  22337. * @param Data: the data to transmit.
  22338. * @retval None
  22339. */
  22340. void CEC_SendDataByte(uint8_t Data)
  22341. {
  22342. /* Transmit Data */
  22343. CEC->TXD = Data ;
  22344. }
  22345. /**
  22346. * @brief Returns the most recent received data by the CEC peripheral.
  22347. * @param None
  22348. * @retval The received data.
  22349. */
  22350. uint8_t CEC_ReceiveDataByte(void)
  22351. {
  22352. /* Receive Data */
  22353. return (uint8_t)(CEC->RXD);
  22354. }
  22355. /**
  22356. * @brief Starts a new message.
  22357. * @param None
  22358. * @retval None
  22359. */
  22360. void CEC_StartOfMessage(void)
  22361. {
  22362. /* Starts of new message */
  22363. *(__IO uint32_t *) CSR_TSOM_BB = (uint32_t)0x1;
  22364. }
  22365. /**
  22366. * @brief Transmits message with or without an EOM bit.
  22367. * @param NewState: new state of the CEC Tx End Of Message.
  22368. * This parameter can be: ENABLE or DISABLE.
  22369. * @retval None
  22370. */
  22371. void CEC_EndOfMessageCmd(FunctionalState NewState)
  22372. {
  22373. /* Check the parameters */
  22374. assert_param(IS_FUNCTIONAL_STATE(NewState));
  22375. /* The data byte will be transmitted with or without an EOM bit*/
  22376. *(__IO uint32_t *) CSR_TEOM_BB = (uint32_t)NewState;
  22377. }
  22378. /**
  22379. * @brief Gets the CEC flag status
  22380. * @param CEC_FLAG: specifies the CEC flag to check.
  22381. * This parameter can be one of the following values:
  22382. * @arg CEC_FLAG_BTE: Bit Timing Error
  22383. * @arg CEC_FLAG_BPE: Bit Period Error
  22384. * @arg CEC_FLAG_RBTFE: Rx Block Transfer Finished Error
  22385. * @arg CEC_FLAG_SBE: Start Bit Error
  22386. * @arg CEC_FLAG_ACKE: Block Acknowledge Error
  22387. * @arg CEC_FLAG_LINE: Line Error
  22388. * @arg CEC_FLAG_TBTFE: Tx Block Transfer Finished Error
  22389. * @arg CEC_FLAG_TEOM: Tx End Of Message
  22390. * @arg CEC_FLAG_TERR: Tx Error
  22391. * @arg CEC_FLAG_TBTRF: Tx Byte Transfer Request or Block Transfer Finished
  22392. * @arg CEC_FLAG_RSOM: Rx Start Of Message
  22393. * @arg CEC_FLAG_REOM: Rx End Of Message
  22394. * @arg CEC_FLAG_RERR: Rx Error
  22395. * @arg CEC_FLAG_RBTF: Rx Byte/Block Transfer Finished
  22396. * @retval The new state of CEC_FLAG (SET or RESET)
  22397. */
  22398. FlagStatus CEC_GetFlagStatus(uint32_t CEC_FLAG)
  22399. {
  22400. FlagStatus bitstatus = RESET;
  22401. uint32_t cecreg = 0, cecbase = 0;
  22402. /* Check the parameters */
  22403. assert_param(IS_CEC_GET_FLAG(CEC_FLAG));
  22404. /* Get the CEC peripheral base address */
  22405. cecbase = (uint32_t)(CEC_BASE);
  22406. /* Read flag register index */
  22407. cecreg = CEC_FLAG >> 28;
  22408. /* Get bit[23:0] of the flag */
  22409. CEC_FLAG &= FLAG_Mask;
  22410. if(cecreg != 0)
  22411. {
  22412. /* Flag in CEC ESR Register */
  22413. CEC_FLAG = (uint32_t)(CEC_FLAG >> 16);
  22414. /* Get the CEC ESR register address */
  22415. cecbase += 0xC;
  22416. }
  22417. else
  22418. {
  22419. /* Get the CEC CSR register address */
  22420. cecbase += 0x10;
  22421. }
  22422. if(((*(__IO uint32_t *)cecbase) & CEC_FLAG) != (uint32_t)RESET)
  22423. {
  22424. /* CEC_FLAG is set */
  22425. bitstatus = SET;
  22426. }
  22427. else
  22428. {
  22429. /* CEC_FLAG is reset */
  22430. bitstatus = RESET;
  22431. }
  22432. /* Return the CEC_FLAG status */
  22433. return bitstatus;
  22434. }
  22435. /**
  22436. * @brief Clears the CEC's pending flags.
  22437. * @param CEC_FLAG: specifies the flag to clear.
  22438. * This parameter can be any combination of the following values:
  22439. * @arg CEC_FLAG_TERR: Tx Error
  22440. * @arg CEC_FLAG_TBTRF: Tx Byte Transfer Request or Block Transfer Finished
  22441. * @arg CEC_FLAG_RSOM: Rx Start Of Message
  22442. * @arg CEC_FLAG_REOM: Rx End Of Message
  22443. * @arg CEC_FLAG_RERR: Rx Error
  22444. * @arg CEC_FLAG_RBTF: Rx Byte/Block Transfer Finished
  22445. * @retval None
  22446. */
  22447. void CEC_ClearFlag(uint32_t CEC_FLAG)
  22448. {
  22449. uint32_t tmp = 0x0;
  22450. /* Check the parameters */
  22451. assert_param(IS_CEC_CLEAR_FLAG(CEC_FLAG));
  22452. tmp = CEC->CSR & 0x2;
  22453. /* Clear the selected CEC flags */
  22454. CEC->CSR &= (uint32_t)(((~(uint32_t)CEC_FLAG) & 0xFFFFFFFC) | tmp);
  22455. }
  22456. /**
  22457. * @brief Checks whether the specified CEC interrupt has occurred or not.
  22458. * @param CEC_IT: specifies the CEC interrupt source to check.
  22459. * This parameter can be one of the following values:
  22460. * @arg CEC_IT_TERR: Tx Error
  22461. * @arg CEC_IT_TBTF: Tx Block Transfer Finished
  22462. * @arg CEC_IT_RERR: Rx Error
  22463. * @arg CEC_IT_RBTF: Rx Block Transfer Finished
  22464. * @retval The new state of CEC_IT (SET or RESET).
  22465. */
  22466. ITStatus CEC_GetITStatus(uint8_t CEC_IT)
  22467. {
  22468. ITStatus bitstatus = RESET;
  22469. uint32_t enablestatus = 0;
  22470. /* Check the parameters */
  22471. assert_param(IS_CEC_GET_IT(CEC_IT));
  22472. /* Get the CEC IT enable bit status */
  22473. enablestatus = (CEC->CFGR & (uint8_t)CEC_CFGR_IE) ;
  22474. /* Check the status of the specified CEC interrupt */
  22475. if (((CEC->CSR & CEC_IT) != (uint32_t)RESET) && enablestatus)
  22476. {
  22477. /* CEC_IT is set */
  22478. bitstatus = SET;
  22479. }
  22480. else
  22481. {
  22482. /* CEC_IT is reset */
  22483. bitstatus = RESET;
  22484. }
  22485. /* Return the CEC_IT status */
  22486. return bitstatus;
  22487. }
  22488. /**
  22489. * @brief Clears the CEC's interrupt pending bits.
  22490. * @param CEC_IT: specifies the CEC interrupt pending bit to clear.
  22491. * This parameter can be any combination of the following values:
  22492. * @arg CEC_IT_TERR: Tx Error
  22493. * @arg CEC_IT_TBTF: Tx Block Transfer Finished
  22494. * @arg CEC_IT_RERR: Rx Error
  22495. * @arg CEC_IT_RBTF: Rx Block Transfer Finished
  22496. * @retval None
  22497. */
  22498. void CEC_ClearITPendingBit(uint16_t CEC_IT)
  22499. {
  22500. uint32_t tmp = 0x0;
  22501. /* Check the parameters */
  22502. assert_param(IS_CEC_GET_IT(CEC_IT));
  22503. tmp = CEC->CSR & 0x2;
  22504. /* Clear the selected CEC interrupt pending bits */
  22505. CEC->CSR &= (uint32_t)(((~(uint32_t)CEC_IT) & 0xFFFFFFFC) | tmp);
  22506. }
  22507. /**
  22508. * @}
  22509. */
  22510. /**
  22511. * @}
  22512. */
  22513. /**
  22514. * @}
  22515. */
  22516. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  22517. /**
  22518. ******************************************************************************
  22519. * @file stm32f10x_bkp.c
  22520. * @author MCD Application Team
  22521. * @version V3.5.0
  22522. * @date 11-March-2011
  22523. * @brief This file provides all the BKP firmware functions.
  22524. ******************************************************************************
  22525. * @attention
  22526. *
  22527. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  22528. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  22529. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  22530. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  22531. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  22532. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  22533. *
  22534. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  22535. ******************************************************************************
  22536. */
  22537. /* Includes ------------------------------------------------------------------*/
  22538. #include "stm32f10x_bkp.h"
  22539. #include "stm32f10x_rcc.h"
  22540. /** @addtogroup STM32F10x_StdPeriph_Driver
  22541. * @{
  22542. */
  22543. /** @defgroup BKP
  22544. * @brief BKP driver modules
  22545. * @{
  22546. */
  22547. /** @defgroup BKP_Private_TypesDefinitions
  22548. * @{
  22549. */
  22550. /**
  22551. * @}
  22552. */
  22553. /** @defgroup BKP_Private_Defines
  22554. * @{
  22555. */
  22556. /* ------------ BKP registers bit address in the alias region --------------- */
  22557. #define BKP_OFFSET (BKP_BASE - PERIPH_BASE)
  22558. /* --- CR Register ----*/
  22559. /* Alias word address of TPAL bit */
  22560. #define CR_OFFSET (BKP_OFFSET + 0x30)
  22561. #define TPAL_BitNumber 0x01
  22562. #define CR_TPAL_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4))
  22563. /* Alias word address of TPE bit */
  22564. #define TPE_BitNumber 0x00
  22565. #define CR_TPE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_BitNumber * 4))
  22566. /* --- CSR Register ---*/
  22567. /* Alias word address of TPIE bit */
  22568. #define CSR_OFFSET (BKP_OFFSET + 0x34)
  22569. #define TPIE_BitNumber 0x02
  22570. #define CSR_TPIE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4))
  22571. /* Alias word address of TIF bit */
  22572. #define TIF_BitNumber 0x09
  22573. #define CSR_TIF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4))
  22574. /* Alias word address of TEF bit */
  22575. #define TEF_BitNumber 0x08
  22576. #define CSR_TEF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4))
  22577. /* ---------------------- BKP registers bit mask ------------------------ */
  22578. /* RTCCR register bit mask */
  22579. #define RTCCR_CAL_MASK ((uint16_t)0xFF80)
  22580. #define RTCCR_MASK ((uint16_t)0xFC7F)
  22581. /**
  22582. * @}
  22583. */
  22584. /** @defgroup BKP_Private_Macros
  22585. * @{
  22586. */
  22587. /**
  22588. * @}
  22589. */
  22590. /** @defgroup BKP_Private_Variables
  22591. * @{
  22592. */
  22593. /**
  22594. * @}
  22595. */
  22596. /** @defgroup BKP_Private_FunctionPrototypes
  22597. * @{
  22598. */
  22599. /**
  22600. * @}
  22601. */
  22602. /** @defgroup BKP_Private_Functions
  22603. * @{
  22604. */
  22605. /**
  22606. * @brief Deinitializes the BKP peripheral registers to their default reset values.
  22607. * @param None
  22608. * @retval None
  22609. */
  22610. void BKP_DeInit(void)
  22611. {
  22612. RCC_BackupResetCmd(ENABLE);
  22613. RCC_BackupResetCmd(DISABLE);
  22614. }
  22615. /**
  22616. * @brief Configures the Tamper Pin active level.
  22617. * @param BKP_TamperPinLevel: specifies the Tamper Pin active level.
  22618. * This parameter can be one of the following values:
  22619. * @arg BKP_TamperPinLevel_High: Tamper pin active on high level
  22620. * @arg BKP_TamperPinLevel_Low: Tamper pin active on low level
  22621. * @retval None
  22622. */
  22623. void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel)
  22624. {
  22625. /* Check the parameters */
  22626. assert_param(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel));
  22627. *(__IO uint32_t *) CR_TPAL_BB = BKP_TamperPinLevel;
  22628. }
  22629. /**
  22630. * @brief Enables or disables the Tamper Pin activation.
  22631. * @param NewState: new state of the Tamper Pin activation.
  22632. * This parameter can be: ENABLE or DISABLE.
  22633. * @retval None
  22634. */
  22635. void BKP_TamperPinCmd(FunctionalState NewState)
  22636. {
  22637. /* Check the parameters */
  22638. assert_param(IS_FUNCTIONAL_STATE(NewState));
  22639. *(__IO uint32_t *) CR_TPE_BB = (uint32_t)NewState;
  22640. }
  22641. /**
  22642. * @brief Enables or disables the Tamper Pin Interrupt.
  22643. * @param NewState: new state of the Tamper Pin Interrupt.
  22644. * This parameter can be: ENABLE or DISABLE.
  22645. * @retval None
  22646. */
  22647. void BKP_ITConfig(FunctionalState NewState)
  22648. {
  22649. /* Check the parameters */
  22650. assert_param(IS_FUNCTIONAL_STATE(NewState));
  22651. *(__IO uint32_t *) CSR_TPIE_BB = (uint32_t)NewState;
  22652. }
  22653. /**
  22654. * @brief Select the RTC output source to output on the Tamper pin.
  22655. * @param BKP_RTCOutputSource: specifies the RTC output source.
  22656. * This parameter can be one of the following values:
  22657. * @arg BKP_RTCOutputSource_None: no RTC output on the Tamper pin.
  22658. * @arg BKP_RTCOutputSource_CalibClock: output the RTC clock with frequency
  22659. * divided by 64 on the Tamper pin.
  22660. * @arg BKP_RTCOutputSource_Alarm: output the RTC Alarm pulse signal on
  22661. * the Tamper pin.
  22662. * @arg BKP_RTCOutputSource_Second: output the RTC Second pulse signal on
  22663. * the Tamper pin.
  22664. * @retval None
  22665. */
  22666. void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource)
  22667. {
  22668. uint16_t tmpreg = 0;
  22669. /* Check the parameters */
  22670. assert_param(IS_BKP_RTC_OUTPUT_SOURCE(BKP_RTCOutputSource));
  22671. tmpreg = BKP->RTCCR;
  22672. /* Clear CCO, ASOE and ASOS bits */
  22673. tmpreg &= RTCCR_MASK;
  22674. /* Set CCO, ASOE and ASOS bits according to BKP_RTCOutputSource value */
  22675. tmpreg |= BKP_RTCOutputSource;
  22676. /* Store the new value */
  22677. BKP->RTCCR = tmpreg;
  22678. }
  22679. /**
  22680. * @brief Sets RTC Clock Calibration value.
  22681. * @param CalibrationValue: specifies the RTC Clock Calibration value.
  22682. * This parameter must be a number between 0 and 0x7F.
  22683. * @retval None
  22684. */
  22685. void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue)
  22686. {
  22687. uint16_t tmpreg = 0;
  22688. /* Check the parameters */
  22689. assert_param(IS_BKP_CALIBRATION_VALUE(CalibrationValue));
  22690. tmpreg = BKP->RTCCR;
  22691. /* Clear CAL[6:0] bits */
  22692. tmpreg &= RTCCR_CAL_MASK;
  22693. /* Set CAL[6:0] bits according to CalibrationValue value */
  22694. tmpreg |= CalibrationValue;
  22695. /* Store the new value */
  22696. BKP->RTCCR = tmpreg;
  22697. }
  22698. /**
  22699. * @brief Writes user data to the specified Data Backup Register.
  22700. * @param BKP_DR: specifies the Data Backup Register.
  22701. * This parameter can be BKP_DRx where x:[1, 42]
  22702. * @param Data: data to write
  22703. * @retval None
  22704. */
  22705. void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data)
  22706. {
  22707. __IO uint32_t tmp = 0;
  22708. /* Check the parameters */
  22709. assert_param(IS_BKP_DR(BKP_DR));
  22710. tmp = (uint32_t)BKP_BASE;
  22711. tmp += BKP_DR;
  22712. *(__IO uint32_t *) tmp = Data;
  22713. }
  22714. /**
  22715. * @brief Reads data from the specified Data Backup Register.
  22716. * @param BKP_DR: specifies the Data Backup Register.
  22717. * This parameter can be BKP_DRx where x:[1, 42]
  22718. * @retval The content of the specified Data Backup Register
  22719. */
  22720. uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR)
  22721. {
  22722. __IO uint32_t tmp = 0;
  22723. /* Check the parameters */
  22724. assert_param(IS_BKP_DR(BKP_DR));
  22725. tmp = (uint32_t)BKP_BASE;
  22726. tmp += BKP_DR;
  22727. return (*(__IO uint16_t *) tmp);
  22728. }
  22729. /**
  22730. * @brief Checks whether the Tamper Pin Event flag is set or not.
  22731. * @param None
  22732. * @retval The new state of the Tamper Pin Event flag (SET or RESET).
  22733. */
  22734. FlagStatus BKP_GetFlagStatus(void)
  22735. {
  22736. return (FlagStatus)(*(__IO uint32_t *) CSR_TEF_BB);
  22737. }
  22738. /**
  22739. * @brief Clears Tamper Pin Event pending flag.
  22740. * @param None
  22741. * @retval None
  22742. */
  22743. void BKP_ClearFlag(void)
  22744. {
  22745. /* Set CTE bit to clear Tamper Pin Event flag */
  22746. BKP->CSR |= BKP_CSR_CTE;
  22747. }
  22748. /**
  22749. * @brief Checks whether the Tamper Pin Interrupt has occurred or not.
  22750. * @param None
  22751. * @retval The new state of the Tamper Pin Interrupt (SET or RESET).
  22752. */
  22753. ITStatus BKP_GetITStatus(void)
  22754. {
  22755. return (ITStatus)(*(__IO uint32_t *) CSR_TIF_BB);
  22756. }
  22757. /**
  22758. * @brief Clears Tamper Pin Interrupt pending bit.
  22759. * @param None
  22760. * @retval None
  22761. */
  22762. void BKP_ClearITPendingBit(void)
  22763. {
  22764. /* Set CTI bit to clear Tamper Pin Interrupt pending bit */
  22765. BKP->CSR |= BKP_CSR_CTI;
  22766. }
  22767. /**
  22768. * @}
  22769. */
  22770. /**
  22771. * @}
  22772. */
  22773. /**
  22774. * @}
  22775. */
  22776. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  22777. /**
  22778. ******************************************************************************
  22779. * @file stm32f10x_dbgmcu.c
  22780. * @author MCD Application Team
  22781. * @version V3.5.0
  22782. * @date 11-March-2011
  22783. * @brief This file provides all the DBGMCU firmware functions.
  22784. ******************************************************************************
  22785. * @attention
  22786. *
  22787. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  22788. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  22789. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  22790. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  22791. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  22792. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  22793. *
  22794. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  22795. ******************************************************************************
  22796. */
  22797. /* Includes ------------------------------------------------------------------*/
  22798. #include "stm32f10x_dbgmcu.h"
  22799. /** @addtogroup STM32F10x_StdPeriph_Driver
  22800. * @{
  22801. */
  22802. /** @defgroup DBGMCU
  22803. * @brief DBGMCU driver modules
  22804. * @{
  22805. */
  22806. /** @defgroup DBGMCU_Private_TypesDefinitions
  22807. * @{
  22808. */
  22809. /**
  22810. * @}
  22811. */
  22812. /** @defgroup DBGMCU_Private_Defines
  22813. * @{
  22814. */
  22815. #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF)
  22816. /**
  22817. * @}
  22818. */
  22819. /** @defgroup DBGMCU_Private_Macros
  22820. * @{
  22821. */
  22822. /**
  22823. * @}
  22824. */
  22825. /** @defgroup DBGMCU_Private_Variables
  22826. * @{
  22827. */
  22828. /**
  22829. * @}
  22830. */
  22831. /** @defgroup DBGMCU_Private_FunctionPrototypes
  22832. * @{
  22833. */
  22834. /**
  22835. * @}
  22836. */
  22837. /** @defgroup DBGMCU_Private_Functions
  22838. * @{
  22839. */
  22840. /**
  22841. * @brief Returns the device revision identifier.
  22842. * @param None
  22843. * @retval Device revision identifier
  22844. */
  22845. uint32_t DBGMCU_GetREVID(void)
  22846. {
  22847. return(DBGMCU->IDCODE >> 16);
  22848. }
  22849. /**
  22850. * @brief Returns the device identifier.
  22851. * @param None
  22852. * @retval Device identifier
  22853. */
  22854. uint32_t DBGMCU_GetDEVID(void)
  22855. {
  22856. return(DBGMCU->IDCODE & IDCODE_DEVID_MASK);
  22857. }
  22858. /**
  22859. * @brief Configures the specified peripheral and low power mode behavior
  22860. * when the MCU under Debug mode.
  22861. * @param DBGMCU_Periph: specifies the peripheral and low power mode.
  22862. * This parameter can be any combination of the following values:
  22863. * @arg DBGMCU_SLEEP: Keep debugger connection during SLEEP mode
  22864. * @arg DBGMCU_STOP: Keep debugger connection during STOP mode
  22865. * @arg DBGMCU_STANDBY: Keep debugger connection during STANDBY mode
  22866. * @arg DBGMCU_IWDG_STOP: Debug IWDG stopped when Core is halted
  22867. * @arg DBGMCU_WWDG_STOP: Debug WWDG stopped when Core is halted
  22868. * @arg DBGMCU_TIM1_STOP: TIM1 counter stopped when Core is halted
  22869. * @arg DBGMCU_TIM2_STOP: TIM2 counter stopped when Core is halted
  22870. * @arg DBGMCU_TIM3_STOP: TIM3 counter stopped when Core is halted
  22871. * @arg DBGMCU_TIM4_STOP: TIM4 counter stopped when Core is halted
  22872. * @arg DBGMCU_CAN1_STOP: Debug CAN2 stopped when Core is halted
  22873. * @arg DBGMCU_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted
  22874. * @arg DBGMCU_I2C2_SMBUS_TIMEOUT: I2C2 SMBUS timeout mode stopped when Core is halted
  22875. * @arg DBGMCU_TIM5_STOP: TIM5 counter stopped when Core is halted
  22876. * @arg DBGMCU_TIM6_STOP: TIM6 counter stopped when Core is halted
  22877. * @arg DBGMCU_TIM7_STOP: TIM7 counter stopped when Core is halted
  22878. * @arg DBGMCU_TIM8_STOP: TIM8 counter stopped when Core is halted
  22879. * @arg DBGMCU_CAN2_STOP: Debug CAN2 stopped when Core is halted
  22880. * @arg DBGMCU_TIM15_STOP: TIM15 counter stopped when Core is halted
  22881. * @arg DBGMCU_TIM16_STOP: TIM16 counter stopped when Core is halted
  22882. * @arg DBGMCU_TIM17_STOP: TIM17 counter stopped when Core is halted
  22883. * @arg DBGMCU_TIM9_STOP: TIM9 counter stopped when Core is halted
  22884. * @arg DBGMCU_TIM10_STOP: TIM10 counter stopped when Core is halted
  22885. * @arg DBGMCU_TIM11_STOP: TIM11 counter stopped when Core is halted
  22886. * @arg DBGMCU_TIM12_STOP: TIM12 counter stopped when Core is halted
  22887. * @arg DBGMCU_TIM13_STOP: TIM13 counter stopped when Core is halted
  22888. * @arg DBGMCU_TIM14_STOP: TIM14 counter stopped when Core is halted
  22889. * @param NewState: new state of the specified peripheral in Debug mode.
  22890. * This parameter can be: ENABLE or DISABLE.
  22891. * @retval None
  22892. */
  22893. void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState)
  22894. {
  22895. /* Check the parameters */
  22896. assert_param(IS_DBGMCU_PERIPH(DBGMCU_Periph));
  22897. assert_param(IS_FUNCTIONAL_STATE(NewState));
  22898. if (NewState != DISABLE)
  22899. {
  22900. DBGMCU->CR |= DBGMCU_Periph;
  22901. }
  22902. else
  22903. {
  22904. DBGMCU->CR &= ~DBGMCU_Periph;
  22905. }
  22906. }
  22907. /**
  22908. * @}
  22909. */
  22910. /**
  22911. * @}
  22912. */
  22913. /**
  22914. * @}
  22915. */
  22916. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  22917. /**
  22918. ******************************************************************************
  22919. * @file stm32f10x_iwdg.c
  22920. * @author MCD Application Team
  22921. * @version V3.5.0
  22922. * @date 11-March-2011
  22923. * @brief This file provides all the IWDG firmware functions.
  22924. ******************************************************************************
  22925. * @attention
  22926. *
  22927. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  22928. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  22929. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  22930. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  22931. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  22932. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  22933. *
  22934. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  22935. ******************************************************************************
  22936. */
  22937. /* Includes ------------------------------------------------------------------*/
  22938. #include "stm32f10x_iwdg.h"
  22939. /** @addtogroup STM32F10x_StdPeriph_Driver
  22940. * @{
  22941. */
  22942. /** @defgroup IWDG
  22943. * @brief IWDG driver modules
  22944. * @{
  22945. */
  22946. /** @defgroup IWDG_Private_TypesDefinitions
  22947. * @{
  22948. */
  22949. /**
  22950. * @}
  22951. */
  22952. /** @defgroup IWDG_Private_Defines
  22953. * @{
  22954. */
  22955. /* ---------------------- IWDG registers bit mask ----------------------------*/
  22956. /* KR register bit mask */
  22957. #define KR_KEY_Reload ((uint16_t)0xAAAA)
  22958. #define KR_KEY_Enable ((uint16_t)0xCCCC)
  22959. /**
  22960. * @}
  22961. */
  22962. /** @defgroup IWDG_Private_Macros
  22963. * @{
  22964. */
  22965. /**
  22966. * @}
  22967. */
  22968. /** @defgroup IWDG_Private_Variables
  22969. * @{
  22970. */
  22971. /**
  22972. * @}
  22973. */
  22974. /** @defgroup IWDG_Private_FunctionPrototypes
  22975. * @{
  22976. */
  22977. /**
  22978. * @}
  22979. */
  22980. /** @defgroup IWDG_Private_Functions
  22981. * @{
  22982. */
  22983. /**
  22984. * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers.
  22985. * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers.
  22986. * This parameter can be one of the following values:
  22987. * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers
  22988. * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers
  22989. * @retval None
  22990. */
  22991. void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess)
  22992. {
  22993. /* Check the parameters */
  22994. assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess));
  22995. IWDG->KR = IWDG_WriteAccess;
  22996. }
  22997. /**
  22998. * @brief Sets IWDG Prescaler value.
  22999. * @param IWDG_Prescaler: specifies the IWDG Prescaler value.
  23000. * This parameter can be one of the following values:
  23001. * @arg IWDG_Prescaler_4: IWDG prescaler set to 4
  23002. * @arg IWDG_Prescaler_8: IWDG prescaler set to 8
  23003. * @arg IWDG_Prescaler_16: IWDG prescaler set to 16
  23004. * @arg IWDG_Prescaler_32: IWDG prescaler set to 32
  23005. * @arg IWDG_Prescaler_64: IWDG prescaler set to 64
  23006. * @arg IWDG_Prescaler_128: IWDG prescaler set to 128
  23007. * @arg IWDG_Prescaler_256: IWDG prescaler set to 256
  23008. * @retval None
  23009. */
  23010. void IWDG_SetPrescaler(uint8_t IWDG_Prescaler)
  23011. {
  23012. /* Check the parameters */
  23013. assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler));
  23014. IWDG->PR = IWDG_Prescaler;
  23015. }
  23016. /**
  23017. * @brief Sets IWDG Reload value.
  23018. * @param Reload: specifies the IWDG Reload value.
  23019. * This parameter must be a number between 0 and 0x0FFF.
  23020. * @retval None
  23021. */
  23022. void IWDG_SetReload(uint16_t Reload)
  23023. {
  23024. /* Check the parameters */
  23025. assert_param(IS_IWDG_RELOAD(Reload));
  23026. IWDG->RLR = Reload;
  23027. }
  23028. /**
  23029. * @brief Reloads IWDG counter with value defined in the reload register
  23030. * (write access to IWDG_PR and IWDG_RLR registers disabled).
  23031. * @param None
  23032. * @retval None
  23033. */
  23034. void IWDG_ReloadCounter(void)
  23035. {
  23036. IWDG->KR = KR_KEY_Reload;
  23037. }
  23038. /**
  23039. * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled).
  23040. * @param None
  23041. * @retval None
  23042. */
  23043. void IWDG_Enable(void)
  23044. {
  23045. IWDG->KR = KR_KEY_Enable;
  23046. }
  23047. /**
  23048. * @brief Checks whether the specified IWDG flag is set or not.
  23049. * @param IWDG_FLAG: specifies the flag to check.
  23050. * This parameter can be one of the following values:
  23051. * @arg IWDG_FLAG_PVU: Prescaler Value Update on going
  23052. * @arg IWDG_FLAG_RVU: Reload Value Update on going
  23053. * @retval The new state of IWDG_FLAG (SET or RESET).
  23054. */
  23055. FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG)
  23056. {
  23057. FlagStatus bitstatus = RESET;
  23058. /* Check the parameters */
  23059. assert_param(IS_IWDG_FLAG(IWDG_FLAG));
  23060. if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET)
  23061. {
  23062. bitstatus = SET;
  23063. }
  23064. else
  23065. {
  23066. bitstatus = RESET;
  23067. }
  23068. /* Return the flag status */
  23069. return bitstatus;
  23070. }
  23071. /**
  23072. * @}
  23073. */
  23074. /**
  23075. * @}
  23076. */
  23077. /**
  23078. * @}
  23079. */
  23080. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  23081. /**
  23082. ******************************************************************************
  23083. * @file stm32f10x_gpio.c
  23084. * @author MCD Application Team
  23085. * @version V3.5.0
  23086. * @date 11-March-2011
  23087. * @brief This file provides all the GPIO firmware functions.
  23088. ******************************************************************************
  23089. * @attention
  23090. *
  23091. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  23092. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  23093. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  23094. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  23095. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  23096. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  23097. *
  23098. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  23099. ******************************************************************************
  23100. */
  23101. /* Includes ------------------------------------------------------------------*/
  23102. #include "stm32f10x_gpio.h"
  23103. #include "stm32f10x_rcc.h"
  23104. /** @addtogroup STM32F10x_StdPeriph_Driver
  23105. * @{
  23106. */
  23107. /** @defgroup GPIO
  23108. * @brief GPIO driver modules
  23109. * @{
  23110. */
  23111. /** @defgroup GPIO_Private_TypesDefinitions
  23112. * @{
  23113. */
  23114. /**
  23115. * @}
  23116. */
  23117. /** @defgroup GPIO_Private_Defines
  23118. * @{
  23119. */
  23120. /* ------------ RCC registers bit address in the alias region ----------------*/
  23121. #define AFIO_OFFSET (AFIO_BASE - PERIPH_BASE)
  23122. /* --- EVENTCR Register -----*/
  23123. /* Alias word address of EVOE bit */
  23124. #define EVCR_OFFSET (AFIO_OFFSET + 0x00)
  23125. #define EVOE_BitNumber ((uint8_t)0x07)
  23126. #define EVCR_EVOE_BB (PERIPH_BB_BASE + (EVCR_OFFSET * 32) + (EVOE_BitNumber * 4))
  23127. /* --- MAPR Register ---*/
  23128. /* Alias word address of MII_RMII_SEL bit */
  23129. #define MAPR_OFFSET (AFIO_OFFSET + 0x04)
  23130. #define MII_RMII_SEL_BitNumber ((u8)0x17)
  23131. #define MAPR_MII_RMII_SEL_BB (PERIPH_BB_BASE + (MAPR_OFFSET * 32) + (MII_RMII_SEL_BitNumber * 4))
  23132. #define EVCR_PORTPINCONFIG_MASK ((uint16_t)0xFF80)
  23133. #define LSB_MASK ((uint16_t)0xFFFF)
  23134. #define DBGAFR_POSITION_MASK ((uint32_t)0x000F0000)
  23135. #define DBGAFR_SWJCFG_MASK ((uint32_t)0xF0FFFFFF)
  23136. #define DBGAFR_LOCATION_MASK ((uint32_t)0x00200000)
  23137. #define DBGAFR_NUMBITS_MASK ((uint32_t)0x00100000)
  23138. /**
  23139. * @}
  23140. */
  23141. /** @defgroup GPIO_Private_Macros
  23142. * @{
  23143. */
  23144. /**
  23145. * @}
  23146. */
  23147. /** @defgroup GPIO_Private_Variables
  23148. * @{
  23149. */
  23150. /**
  23151. * @}
  23152. */
  23153. /** @defgroup GPIO_Private_FunctionPrototypes
  23154. * @{
  23155. */
  23156. /**
  23157. * @}
  23158. */
  23159. /** @defgroup GPIO_Private_Functions
  23160. * @{
  23161. */
  23162. /**
  23163. * @brief Deinitializes the GPIOx peripheral registers to their default reset values.
  23164. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
  23165. * @retval None
  23166. */
  23167. void GPIO_DeInit(GPIO_TypeDef* GPIOx)
  23168. {
  23169. /* Check the parameters */
  23170. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  23171. if (GPIOx == GPIOA)
  23172. {
  23173. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, ENABLE);
  23174. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, DISABLE);
  23175. }
  23176. else if (GPIOx == GPIOB)
  23177. {
  23178. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, ENABLE);
  23179. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, DISABLE);
  23180. }
  23181. else if (GPIOx == GPIOC)
  23182. {
  23183. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, ENABLE);
  23184. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, DISABLE);
  23185. }
  23186. else if (GPIOx == GPIOD)
  23187. {
  23188. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, ENABLE);
  23189. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOD, DISABLE);
  23190. }
  23191. else if (GPIOx == GPIOE)
  23192. {
  23193. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, ENABLE);
  23194. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, DISABLE);
  23195. }
  23196. else if (GPIOx == GPIOF)
  23197. {
  23198. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOF, ENABLE);
  23199. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOF, DISABLE);
  23200. }
  23201. else
  23202. {
  23203. if (GPIOx == GPIOG)
  23204. {
  23205. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOG, ENABLE);
  23206. RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOG, DISABLE);
  23207. }
  23208. }
  23209. }
  23210. /**
  23211. * @brief Deinitializes the Alternate Functions (remap, event control
  23212. * and EXTI configuration) registers to their default reset values.
  23213. * @param None
  23214. * @retval None
  23215. */
  23216. void GPIO_AFIODeInit(void)
  23217. {
  23218. RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, ENABLE);
  23219. RCC_APB2PeriphResetCmd(RCC_APB2Periph_AFIO, DISABLE);
  23220. }
  23221. /**
  23222. * @brief Initializes the GPIOx peripheral according to the specified
  23223. * parameters in the GPIO_InitStruct.
  23224. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
  23225. * @param GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that
  23226. * contains the configuration information for the specified GPIO peripheral.
  23227. * @retval None
  23228. */
  23229. void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
  23230. {
  23231. uint32_t currentmode = 0x00, currentpin = 0x00, pinpos = 0x00, pos = 0x00;
  23232. uint32_t tmpreg = 0x00, pinmask = 0x00;
  23233. /* Check the parameters */
  23234. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  23235. assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
  23236. assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
  23237. /*---------------------------- GPIO Mode Configuration -----------------------*/
  23238. currentmode = ((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x0F);
  23239. if ((((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x10)) != 0x00)
  23240. {
  23241. /* Check the parameters */
  23242. assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
  23243. /* Output mode */
  23244. currentmode |= (uint32_t)GPIO_InitStruct->GPIO_Speed;
  23245. }
  23246. /*---------------------------- GPIO CRL Configuration ------------------------*/
  23247. /* Configure the eight low port pins */
  23248. if (((uint32_t)GPIO_InitStruct->GPIO_Pin & ((uint32_t)0x00FF)) != 0x00)
  23249. {
  23250. tmpreg = GPIOx->CRL;
  23251. for (pinpos = 0x00; pinpos < 0x08; pinpos++)
  23252. {
  23253. pos = ((uint32_t)0x01) << pinpos;
  23254. /* Get the port pins position */
  23255. currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
  23256. if (currentpin == pos)
  23257. {
  23258. pos = pinpos << 2;
  23259. /* Clear the corresponding low control register bits */
  23260. pinmask = ((uint32_t)0x0F) << pos;
  23261. tmpreg &= ~pinmask;
  23262. /* Write the mode configuration in the corresponding bits */
  23263. tmpreg |= (currentmode << pos);
  23264. /* Reset the corresponding ODR bit */
  23265. if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
  23266. {
  23267. GPIOx->BRR = (((uint32_t)0x01) << pinpos);
  23268. }
  23269. else
  23270. {
  23271. /* Set the corresponding ODR bit */
  23272. if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
  23273. {
  23274. GPIOx->BSRR = (((uint32_t)0x01) << pinpos);
  23275. }
  23276. }
  23277. }
  23278. }
  23279. GPIOx->CRL = tmpreg;
  23280. }
  23281. /*---------------------------- GPIO CRH Configuration ------------------------*/
  23282. /* Configure the eight high port pins */
  23283. if (GPIO_InitStruct->GPIO_Pin > 0x00FF)
  23284. {
  23285. tmpreg = GPIOx->CRH;
  23286. for (pinpos = 0x00; pinpos < 0x08; pinpos++)
  23287. {
  23288. pos = (((uint32_t)0x01) << (pinpos + 0x08));
  23289. /* Get the port pins position */
  23290. currentpin = ((GPIO_InitStruct->GPIO_Pin) & pos);
  23291. if (currentpin == pos)
  23292. {
  23293. pos = pinpos << 2;
  23294. /* Clear the corresponding high control register bits */
  23295. pinmask = ((uint32_t)0x0F) << pos;
  23296. tmpreg &= ~pinmask;
  23297. /* Write the mode configuration in the corresponding bits */
  23298. tmpreg |= (currentmode << pos);
  23299. /* Reset the corresponding ODR bit */
  23300. if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
  23301. {
  23302. GPIOx->BRR = (((uint32_t)0x01) << (pinpos + 0x08));
  23303. }
  23304. /* Set the corresponding ODR bit */
  23305. if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
  23306. {
  23307. GPIOx->BSRR = (((uint32_t)0x01) << (pinpos + 0x08));
  23308. }
  23309. }
  23310. }
  23311. GPIOx->CRH = tmpreg;
  23312. }
  23313. }
  23314. /**
  23315. * @brief Fills each GPIO_InitStruct member with its default value.
  23316. * @param GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure which will
  23317. * be initialized.
  23318. * @retval None
  23319. */
  23320. void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
  23321. {
  23322. /* Reset GPIO init structure parameters values */
  23323. GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
  23324. GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
  23325. GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN_FLOATING;
  23326. }
  23327. /**
  23328. * @brief Reads the specified input port pin.
  23329. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
  23330. * @param GPIO_Pin: specifies the port bit to read.
  23331. * This parameter can be GPIO_Pin_x where x can be (0..15).
  23332. * @retval The input port pin value.
  23333. */
  23334. uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  23335. {
  23336. uint8_t bitstatus = 0x00;
  23337. /* Check the parameters */
  23338. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  23339. assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
  23340. if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)
  23341. {
  23342. bitstatus = (uint8_t)Bit_SET;
  23343. }
  23344. else
  23345. {
  23346. bitstatus = (uint8_t)Bit_RESET;
  23347. }
  23348. return bitstatus;
  23349. }
  23350. /**
  23351. * @brief Reads the specified GPIO input data port.
  23352. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
  23353. * @retval GPIO input data port value.
  23354. */
  23355. uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
  23356. {
  23357. /* Check the parameters */
  23358. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  23359. return ((uint16_t)GPIOx->IDR);
  23360. }
  23361. /**
  23362. * @brief Reads the specified output data port bit.
  23363. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
  23364. * @param GPIO_Pin: specifies the port bit to read.
  23365. * This parameter can be GPIO_Pin_x where x can be (0..15).
  23366. * @retval The output port pin value.
  23367. */
  23368. uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  23369. {
  23370. uint8_t bitstatus = 0x00;
  23371. /* Check the parameters */
  23372. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  23373. assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
  23374. if ((GPIOx->ODR & GPIO_Pin) != (uint32_t)Bit_RESET)
  23375. {
  23376. bitstatus = (uint8_t)Bit_SET;
  23377. }
  23378. else
  23379. {
  23380. bitstatus = (uint8_t)Bit_RESET;
  23381. }
  23382. return bitstatus;
  23383. }
  23384. /**
  23385. * @brief Reads the specified GPIO output data port.
  23386. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
  23387. * @retval GPIO output data port value.
  23388. */
  23389. uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
  23390. {
  23391. /* Check the parameters */
  23392. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  23393. return ((uint16_t)GPIOx->ODR);
  23394. }
  23395. /**
  23396. * @brief Sets the selected data port bits.
  23397. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
  23398. * @param GPIO_Pin: specifies the port bits to be written.
  23399. * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  23400. * @retval None
  23401. */
  23402. void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  23403. {
  23404. /* Check the parameters */
  23405. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  23406. assert_param(IS_GPIO_PIN(GPIO_Pin));
  23407. GPIOx->BSRR = GPIO_Pin;
  23408. }
  23409. /**
  23410. * @brief Clears the selected data port bits.
  23411. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
  23412. * @param GPIO_Pin: specifies the port bits to be written.
  23413. * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  23414. * @retval None
  23415. */
  23416. void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  23417. {
  23418. /* Check the parameters */
  23419. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  23420. assert_param(IS_GPIO_PIN(GPIO_Pin));
  23421. GPIOx->BRR = GPIO_Pin;
  23422. }
  23423. /**
  23424. * @brief Sets or clears the selected data port bit.
  23425. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
  23426. * @param GPIO_Pin: specifies the port bit to be written.
  23427. * This parameter can be one of GPIO_Pin_x where x can be (0..15).
  23428. * @param BitVal: specifies the value to be written to the selected bit.
  23429. * This parameter can be one of the BitAction enum values:
  23430. * @arg Bit_RESET: to clear the port pin
  23431. * @arg Bit_SET: to set the port pin
  23432. * @retval None
  23433. */
  23434. void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
  23435. {
  23436. /* Check the parameters */
  23437. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  23438. assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
  23439. assert_param(IS_GPIO_BIT_ACTION(BitVal));
  23440. if (BitVal != Bit_RESET)
  23441. {
  23442. GPIOx->BSRR = GPIO_Pin;
  23443. }
  23444. else
  23445. {
  23446. GPIOx->BRR = GPIO_Pin;
  23447. }
  23448. }
  23449. /**
  23450. * @brief Writes data to the specified GPIO data port.
  23451. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
  23452. * @param PortVal: specifies the value to be written to the port output data register.
  23453. * @retval None
  23454. */
  23455. void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)
  23456. {
  23457. /* Check the parameters */
  23458. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  23459. GPIOx->ODR = PortVal;
  23460. }
  23461. /**
  23462. * @brief Locks GPIO Pins configuration registers.
  23463. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
  23464. * @param GPIO_Pin: specifies the port bit to be written.
  23465. * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  23466. * @retval None
  23467. */
  23468. void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  23469. {
  23470. uint32_t tmp = 0x00010000;
  23471. /* Check the parameters */
  23472. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  23473. assert_param(IS_GPIO_PIN(GPIO_Pin));
  23474. tmp |= GPIO_Pin;
  23475. /* Set LCKK bit */
  23476. GPIOx->LCKR = tmp;
  23477. /* Reset LCKK bit */
  23478. GPIOx->LCKR = GPIO_Pin;
  23479. /* Set LCKK bit */
  23480. GPIOx->LCKR = tmp;
  23481. /* Read LCKK bit*/
  23482. tmp = GPIOx->LCKR;
  23483. /* Read LCKK bit*/
  23484. tmp = GPIOx->LCKR;
  23485. }
  23486. /**
  23487. * @brief Selects the GPIO pin used as Event output.
  23488. * @param GPIO_PortSource: selects the GPIO port to be used as source
  23489. * for Event output.
  23490. * This parameter can be GPIO_PortSourceGPIOx where x can be (A..E).
  23491. * @param GPIO_PinSource: specifies the pin for the Event output.
  23492. * This parameter can be GPIO_PinSourcex where x can be (0..15).
  23493. * @retval None
  23494. */
  23495. void GPIO_EventOutputConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)
  23496. {
  23497. uint32_t tmpreg = 0x00;
  23498. /* Check the parameters */
  23499. assert_param(IS_GPIO_EVENTOUT_PORT_SOURCE(GPIO_PortSource));
  23500. assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
  23501. tmpreg = AFIO->EVCR;
  23502. /* Clear the PORT[6:4] and PIN[3:0] bits */
  23503. tmpreg &= EVCR_PORTPINCONFIG_MASK;
  23504. tmpreg |= (uint32_t)GPIO_PortSource << 0x04;
  23505. tmpreg |= GPIO_PinSource;
  23506. AFIO->EVCR = tmpreg;
  23507. }
  23508. /**
  23509. * @brief Enables or disables the Event Output.
  23510. * @param NewState: new state of the Event output.
  23511. * This parameter can be: ENABLE or DISABLE.
  23512. * @retval None
  23513. */
  23514. void GPIO_EventOutputCmd(FunctionalState NewState)
  23515. {
  23516. /* Check the parameters */
  23517. assert_param(IS_FUNCTIONAL_STATE(NewState));
  23518. *(__IO uint32_t *) EVCR_EVOE_BB = (uint32_t)NewState;
  23519. }
  23520. /**
  23521. * @brief Changes the mapping of the specified pin.
  23522. * @param GPIO_Remap: selects the pin to remap.
  23523. * This parameter can be one of the following values:
  23524. * @arg GPIO_Remap_SPI1 : SPI1 Alternate Function mapping
  23525. * @arg GPIO_Remap_I2C1 : I2C1 Alternate Function mapping
  23526. * @arg GPIO_Remap_USART1 : USART1 Alternate Function mapping
  23527. * @arg GPIO_Remap_USART2 : USART2 Alternate Function mapping
  23528. * @arg GPIO_PartialRemap_USART3 : USART3 Partial Alternate Function mapping
  23529. * @arg GPIO_FullRemap_USART3 : USART3 Full Alternate Function mapping
  23530. * @arg GPIO_PartialRemap_TIM1 : TIM1 Partial Alternate Function mapping
  23531. * @arg GPIO_FullRemap_TIM1 : TIM1 Full Alternate Function mapping
  23532. * @arg GPIO_PartialRemap1_TIM2 : TIM2 Partial1 Alternate Function mapping
  23533. * @arg GPIO_PartialRemap2_TIM2 : TIM2 Partial2 Alternate Function mapping
  23534. * @arg GPIO_FullRemap_TIM2 : TIM2 Full Alternate Function mapping
  23535. * @arg GPIO_PartialRemap_TIM3 : TIM3 Partial Alternate Function mapping
  23536. * @arg GPIO_FullRemap_TIM3 : TIM3 Full Alternate Function mapping
  23537. * @arg GPIO_Remap_TIM4 : TIM4 Alternate Function mapping
  23538. * @arg GPIO_Remap1_CAN1 : CAN1 Alternate Function mapping
  23539. * @arg GPIO_Remap2_CAN1 : CAN1 Alternate Function mapping
  23540. * @arg GPIO_Remap_PD01 : PD01 Alternate Function mapping
  23541. * @arg GPIO_Remap_TIM5CH4_LSI : LSI connected to TIM5 Channel4 input capture for calibration
  23542. * @arg GPIO_Remap_ADC1_ETRGINJ : ADC1 External Trigger Injected Conversion remapping
  23543. * @arg GPIO_Remap_ADC1_ETRGREG : ADC1 External Trigger Regular Conversion remapping
  23544. * @arg GPIO_Remap_ADC2_ETRGINJ : ADC2 External Trigger Injected Conversion remapping
  23545. * @arg GPIO_Remap_ADC2_ETRGREG : ADC2 External Trigger Regular Conversion remapping
  23546. * @arg GPIO_Remap_ETH : Ethernet remapping (only for Connectivity line devices)
  23547. * @arg GPIO_Remap_CAN2 : CAN2 remapping (only for Connectivity line devices)
  23548. * @arg GPIO_Remap_SWJ_NoJTRST : Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST
  23549. * @arg GPIO_Remap_SWJ_JTAGDisable : JTAG-DP Disabled and SW-DP Enabled
  23550. * @arg GPIO_Remap_SWJ_Disable : Full SWJ Disabled (JTAG-DP + SW-DP)
  23551. * @arg GPIO_Remap_SPI3 : SPI3/I2S3 Alternate Function mapping (only for Connectivity line devices)
  23552. * When the SPI3/I2S3 is remapped using this function, the SWJ is configured
  23553. * to Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST.
  23554. * @arg GPIO_Remap_TIM2ITR1_PTP_SOF : Ethernet PTP output or USB OTG SOF (Start of Frame) connected
  23555. * to TIM2 Internal Trigger 1 for calibration (only for Connectivity line devices)
  23556. * If the GPIO_Remap_TIM2ITR1_PTP_SOF is enabled the TIM2 ITR1 is connected to
  23557. * Ethernet PTP output. When Reset TIM2 ITR1 is connected to USB OTG SOF output.
  23558. * @arg GPIO_Remap_PTP_PPS : Ethernet MAC PPS_PTS output on PB05 (only for Connectivity line devices)
  23559. * @arg GPIO_Remap_TIM15 : TIM15 Alternate Function mapping (only for Value line devices)
  23560. * @arg GPIO_Remap_TIM16 : TIM16 Alternate Function mapping (only for Value line devices)
  23561. * @arg GPIO_Remap_TIM17 : TIM17 Alternate Function mapping (only for Value line devices)
  23562. * @arg GPIO_Remap_CEC : CEC Alternate Function mapping (only for Value line devices)
  23563. * @arg GPIO_Remap_TIM1_DMA : TIM1 DMA requests mapping (only for Value line devices)
  23564. * @arg GPIO_Remap_TIM9 : TIM9 Alternate Function mapping (only for XL-density devices)
  23565. * @arg GPIO_Remap_TIM10 : TIM10 Alternate Function mapping (only for XL-density devices)
  23566. * @arg GPIO_Remap_TIM11 : TIM11 Alternate Function mapping (only for XL-density devices)
  23567. * @arg GPIO_Remap_TIM13 : TIM13 Alternate Function mapping (only for High density Value line and XL-density devices)
  23568. * @arg GPIO_Remap_TIM14 : TIM14 Alternate Function mapping (only for High density Value line and XL-density devices)
  23569. * @arg GPIO_Remap_FSMC_NADV : FSMC_NADV Alternate Function mapping (only for High density Value line and XL-density devices)
  23570. * @arg GPIO_Remap_TIM67_DAC_DMA : TIM6/TIM7 and DAC DMA requests remapping (only for High density Value line devices)
  23571. * @arg GPIO_Remap_TIM12 : TIM12 Alternate Function mapping (only for High density Value line devices)
  23572. * @arg GPIO_Remap_MISC : Miscellaneous Remap (DMA2 Channel5 Position and DAC Trigger remapping,
  23573. * only for High density Value line devices)
  23574. * @param NewState: new state of the port pin remapping.
  23575. * This parameter can be: ENABLE or DISABLE.
  23576. * @retval None
  23577. */
  23578. void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState)
  23579. {
  23580. uint32_t tmp = 0x00, tmp1 = 0x00, tmpreg = 0x00, tmpmask = 0x00;
  23581. /* Check the parameters */
  23582. assert_param(IS_GPIO_REMAP(GPIO_Remap));
  23583. assert_param(IS_FUNCTIONAL_STATE(NewState));
  23584. if((GPIO_Remap & 0x80000000) == 0x80000000)
  23585. {
  23586. tmpreg = AFIO->MAPR2;
  23587. }
  23588. else
  23589. {
  23590. tmpreg = AFIO->MAPR;
  23591. }
  23592. tmpmask = (GPIO_Remap & DBGAFR_POSITION_MASK) >> 0x10;
  23593. tmp = GPIO_Remap & LSB_MASK;
  23594. if ((GPIO_Remap & (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK)) == (DBGAFR_LOCATION_MASK | DBGAFR_NUMBITS_MASK))
  23595. {
  23596. tmpreg &= DBGAFR_SWJCFG_MASK;
  23597. AFIO->MAPR &= DBGAFR_SWJCFG_MASK;
  23598. }
  23599. else if ((GPIO_Remap & DBGAFR_NUMBITS_MASK) == DBGAFR_NUMBITS_MASK)
  23600. {
  23601. tmp1 = ((uint32_t)0x03) << tmpmask;
  23602. tmpreg &= ~tmp1;
  23603. tmpreg |= ~DBGAFR_SWJCFG_MASK;
  23604. }
  23605. else
  23606. {
  23607. tmpreg &= ~(tmp << ((GPIO_Remap >> 0x15)*0x10));
  23608. tmpreg |= ~DBGAFR_SWJCFG_MASK;
  23609. }
  23610. if (NewState != DISABLE)
  23611. {
  23612. tmpreg |= (tmp << ((GPIO_Remap >> 0x15)*0x10));
  23613. }
  23614. if((GPIO_Remap & 0x80000000) == 0x80000000)
  23615. {
  23616. AFIO->MAPR2 = tmpreg;
  23617. }
  23618. else
  23619. {
  23620. AFIO->MAPR = tmpreg;
  23621. }
  23622. }
  23623. /**
  23624. * @brief Selects the GPIO pin used as EXTI Line.
  23625. * @param GPIO_PortSource: selects the GPIO port to be used as source for EXTI lines.
  23626. * This parameter can be GPIO_PortSourceGPIOx where x can be (A..G).
  23627. * @param GPIO_PinSource: specifies the EXTI line to be configured.
  23628. * This parameter can be GPIO_PinSourcex where x can be (0..15).
  23629. * @retval None
  23630. */
  23631. void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)
  23632. {
  23633. uint32_t tmp = 0x00;
  23634. /* Check the parameters */
  23635. assert_param(IS_GPIO_EXTI_PORT_SOURCE(GPIO_PortSource));
  23636. assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
  23637. tmp = ((uint32_t)0x0F) << (0x04 * (GPIO_PinSource & (uint8_t)0x03));
  23638. AFIO->EXTICR[GPIO_PinSource >> 0x02] &= ~tmp;
  23639. AFIO->EXTICR[GPIO_PinSource >> 0x02] |= (((uint32_t)GPIO_PortSource) << (0x04 * (GPIO_PinSource & (uint8_t)0x03)));
  23640. }
  23641. /**
  23642. * @brief Selects the Ethernet media interface.
  23643. * @note This function applies only to STM32 Connectivity line devices.
  23644. * @param GPIO_ETH_MediaInterface: specifies the Media Interface mode.
  23645. * This parameter can be one of the following values:
  23646. * @arg GPIO_ETH_MediaInterface_MII: MII mode
  23647. * @arg GPIO_ETH_MediaInterface_RMII: RMII mode
  23648. * @retval None
  23649. */
  23650. void GPIO_ETH_MediaInterfaceConfig(uint32_t GPIO_ETH_MediaInterface)
  23651. {
  23652. assert_param(IS_GPIO_ETH_MEDIA_INTERFACE(GPIO_ETH_MediaInterface));
  23653. /* Configure MII_RMII selection bit */
  23654. *(__IO uint32_t *) MAPR_MII_RMII_SEL_BB = GPIO_ETH_MediaInterface;
  23655. }
  23656. /**
  23657. * @}
  23658. */
  23659. /**
  23660. * @}
  23661. */
  23662. /**
  23663. * @}
  23664. */
  23665. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  23666. /**
  23667. ******************************************************************************
  23668. * @file stm32f10x_fsmc.c
  23669. * @author MCD Application Team
  23670. * @version V3.5.0
  23671. * @date 11-March-2011
  23672. * @brief This file provides all the FSMC firmware functions.
  23673. ******************************************************************************
  23674. * @attention
  23675. *
  23676. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  23677. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  23678. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  23679. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  23680. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  23681. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  23682. *
  23683. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  23684. ******************************************************************************
  23685. */
  23686. /* Includes ------------------------------------------------------------------*/
  23687. #include "stm32f10x_fsmc.h"
  23688. #include "stm32f10x_rcc.h"
  23689. /** @addtogroup STM32F10x_StdPeriph_Driver
  23690. * @{
  23691. */
  23692. /** @defgroup FSMC
  23693. * @brief FSMC driver modules
  23694. * @{
  23695. */
  23696. /** @defgroup FSMC_Private_TypesDefinitions
  23697. * @{
  23698. */
  23699. /**
  23700. * @}
  23701. */
  23702. /** @defgroup FSMC_Private_Defines
  23703. * @{
  23704. */
  23705. /* --------------------- FSMC registers bit mask ---------------------------- */
  23706. /* FSMC BCRx Mask */
  23707. #define BCR_MBKEN_Set ((uint32_t)0x00000001)
  23708. #define BCR_MBKEN_Reset ((uint32_t)0x000FFFFE)
  23709. #define BCR_FACCEN_Set ((uint32_t)0x00000040)
  23710. /* FSMC PCRx Mask */
  23711. #define PCR_PBKEN_Set ((uint32_t)0x00000004)
  23712. #define PCR_PBKEN_Reset ((uint32_t)0x000FFFFB)
  23713. #define PCR_ECCEN_Set ((uint32_t)0x00000040)
  23714. #define PCR_ECCEN_Reset ((uint32_t)0x000FFFBF)
  23715. #define PCR_MemoryType_NAND ((uint32_t)0x00000008)
  23716. /**
  23717. * @}
  23718. */
  23719. /** @defgroup FSMC_Private_Macros
  23720. * @{
  23721. */
  23722. /**
  23723. * @}
  23724. */
  23725. /** @defgroup FSMC_Private_Variables
  23726. * @{
  23727. */
  23728. /**
  23729. * @}
  23730. */
  23731. /** @defgroup FSMC_Private_FunctionPrototypes
  23732. * @{
  23733. */
  23734. /**
  23735. * @}
  23736. */
  23737. /** @defgroup FSMC_Private_Functions
  23738. * @{
  23739. */
  23740. /**
  23741. * @brief Deinitializes the FSMC NOR/SRAM Banks registers to their default
  23742. * reset values.
  23743. * @param FSMC_Bank: specifies the FSMC Bank to be used
  23744. * This parameter can be one of the following values:
  23745. * @arg FSMC_Bank1_NORSRAM1: FSMC Bank1 NOR/SRAM1
  23746. * @arg FSMC_Bank1_NORSRAM2: FSMC Bank1 NOR/SRAM2
  23747. * @arg FSMC_Bank1_NORSRAM3: FSMC Bank1 NOR/SRAM3
  23748. * @arg FSMC_Bank1_NORSRAM4: FSMC Bank1 NOR/SRAM4
  23749. * @retval None
  23750. */
  23751. void FSMC_NORSRAMDeInit(uint32_t FSMC_Bank)
  23752. {
  23753. /* Check the parameter */
  23754. assert_param(IS_FSMC_NORSRAM_BANK(FSMC_Bank));
  23755. /* FSMC_Bank1_NORSRAM1 */
  23756. if(FSMC_Bank == FSMC_Bank1_NORSRAM1)
  23757. {
  23758. FSMC_Bank1->BTCR[FSMC_Bank] = 0x000030DB;
  23759. }
  23760. /* FSMC_Bank1_NORSRAM2, FSMC_Bank1_NORSRAM3 or FSMC_Bank1_NORSRAM4 */
  23761. else
  23762. {
  23763. FSMC_Bank1->BTCR[FSMC_Bank] = 0x000030D2;
  23764. }
  23765. FSMC_Bank1->BTCR[FSMC_Bank + 1] = 0x0FFFFFFF;
  23766. FSMC_Bank1E->BWTR[FSMC_Bank] = 0x0FFFFFFF;
  23767. }
  23768. /**
  23769. * @brief Deinitializes the FSMC NAND Banks registers to their default reset values.
  23770. * @param FSMC_Bank: specifies the FSMC Bank to be used
  23771. * This parameter can be one of the following values:
  23772. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  23773. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  23774. * @retval None
  23775. */
  23776. void FSMC_NANDDeInit(uint32_t FSMC_Bank)
  23777. {
  23778. /* Check the parameter */
  23779. assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
  23780. if(FSMC_Bank == FSMC_Bank2_NAND)
  23781. {
  23782. /* Set the FSMC_Bank2 registers to their reset values */
  23783. FSMC_Bank2->PCR2 = 0x00000018;
  23784. FSMC_Bank2->SR2 = 0x00000040;
  23785. FSMC_Bank2->PMEM2 = 0xFCFCFCFC;
  23786. FSMC_Bank2->PATT2 = 0xFCFCFCFC;
  23787. }
  23788. /* FSMC_Bank3_NAND */
  23789. else
  23790. {
  23791. /* Set the FSMC_Bank3 registers to their reset values */
  23792. FSMC_Bank3->PCR3 = 0x00000018;
  23793. FSMC_Bank3->SR3 = 0x00000040;
  23794. FSMC_Bank3->PMEM3 = 0xFCFCFCFC;
  23795. FSMC_Bank3->PATT3 = 0xFCFCFCFC;
  23796. }
  23797. }
  23798. /**
  23799. * @brief Deinitializes the FSMC PCCARD Bank registers to their default reset values.
  23800. * @param None
  23801. * @retval None
  23802. */
  23803. void FSMC_PCCARDDeInit(void)
  23804. {
  23805. /* Set the FSMC_Bank4 registers to their reset values */
  23806. FSMC_Bank4->PCR4 = 0x00000018;
  23807. FSMC_Bank4->SR4 = 0x00000000;
  23808. FSMC_Bank4->PMEM4 = 0xFCFCFCFC;
  23809. FSMC_Bank4->PATT4 = 0xFCFCFCFC;
  23810. FSMC_Bank4->PIO4 = 0xFCFCFCFC;
  23811. }
  23812. /**
  23813. * @brief Initializes the FSMC NOR/SRAM Banks according to the specified
  23814. * parameters in the FSMC_NORSRAMInitStruct.
  23815. * @param FSMC_NORSRAMInitStruct : pointer to a FSMC_NORSRAMInitTypeDef
  23816. * structure that contains the configuration information for
  23817. * the FSMC NOR/SRAM specified Banks.
  23818. * @retval None
  23819. */
  23820. void FSMC_NORSRAMInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct)
  23821. {
  23822. /* Check the parameters */
  23823. assert_param(IS_FSMC_NORSRAM_BANK(FSMC_NORSRAMInitStruct->FSMC_Bank));
  23824. assert_param(IS_FSMC_MUX(FSMC_NORSRAMInitStruct->FSMC_DataAddressMux));
  23825. assert_param(IS_FSMC_MEMORY(FSMC_NORSRAMInitStruct->FSMC_MemoryType));
  23826. assert_param(IS_FSMC_MEMORY_WIDTH(FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth));
  23827. assert_param(IS_FSMC_BURSTMODE(FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode));
  23828. assert_param(IS_FSMC_ASYNWAIT(FSMC_NORSRAMInitStruct->FSMC_AsynchronousWait));
  23829. assert_param(IS_FSMC_WAIT_POLARITY(FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity));
  23830. assert_param(IS_FSMC_WRAP_MODE(FSMC_NORSRAMInitStruct->FSMC_WrapMode));
  23831. assert_param(IS_FSMC_WAIT_SIGNAL_ACTIVE(FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive));
  23832. assert_param(IS_FSMC_WRITE_OPERATION(FSMC_NORSRAMInitStruct->FSMC_WriteOperation));
  23833. assert_param(IS_FSMC_WAITE_SIGNAL(FSMC_NORSRAMInitStruct->FSMC_WaitSignal));
  23834. assert_param(IS_FSMC_EXTENDED_MODE(FSMC_NORSRAMInitStruct->FSMC_ExtendedMode));
  23835. assert_param(IS_FSMC_WRITE_BURST(FSMC_NORSRAMInitStruct->FSMC_WriteBurst));
  23836. assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime));
  23837. assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime));
  23838. assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime));
  23839. assert_param(IS_FSMC_TURNAROUND_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration));
  23840. assert_param(IS_FSMC_CLK_DIV(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision));
  23841. assert_param(IS_FSMC_DATA_LATENCY(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency));
  23842. assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode));
  23843. /* Bank1 NOR/SRAM control register configuration */
  23844. FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank] =
  23845. (uint32_t)FSMC_NORSRAMInitStruct->FSMC_DataAddressMux |
  23846. FSMC_NORSRAMInitStruct->FSMC_MemoryType |
  23847. FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth |
  23848. FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode |
  23849. FSMC_NORSRAMInitStruct->FSMC_AsynchronousWait |
  23850. FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity |
  23851. FSMC_NORSRAMInitStruct->FSMC_WrapMode |
  23852. FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive |
  23853. FSMC_NORSRAMInitStruct->FSMC_WriteOperation |
  23854. FSMC_NORSRAMInitStruct->FSMC_WaitSignal |
  23855. FSMC_NORSRAMInitStruct->FSMC_ExtendedMode |
  23856. FSMC_NORSRAMInitStruct->FSMC_WriteBurst;
  23857. if(FSMC_NORSRAMInitStruct->FSMC_MemoryType == FSMC_MemoryType_NOR)
  23858. {
  23859. FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank] |= (uint32_t)BCR_FACCEN_Set;
  23860. }
  23861. /* Bank1 NOR/SRAM timing register configuration */
  23862. FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank+1] =
  23863. (uint32_t)FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime |
  23864. (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime << 4) |
  23865. (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime << 8) |
  23866. (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration << 16) |
  23867. (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision << 20) |
  23868. (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency << 24) |
  23869. FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode;
  23870. /* Bank1 NOR/SRAM timing register for write configuration, if extended mode is used */
  23871. if(FSMC_NORSRAMInitStruct->FSMC_ExtendedMode == FSMC_ExtendedMode_Enable)
  23872. {
  23873. assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime));
  23874. assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime));
  23875. assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime));
  23876. assert_param(IS_FSMC_CLK_DIV(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision));
  23877. assert_param(IS_FSMC_DATA_LATENCY(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency));
  23878. assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode));
  23879. FSMC_Bank1E->BWTR[FSMC_NORSRAMInitStruct->FSMC_Bank] =
  23880. (uint32_t)FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime |
  23881. (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime << 4 )|
  23882. (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime << 8) |
  23883. (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision << 20) |
  23884. (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency << 24) |
  23885. FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode;
  23886. }
  23887. else
  23888. {
  23889. FSMC_Bank1E->BWTR[FSMC_NORSRAMInitStruct->FSMC_Bank] = 0x0FFFFFFF;
  23890. }
  23891. }
  23892. /**
  23893. * @brief Initializes the FSMC NAND Banks according to the specified
  23894. * parameters in the FSMC_NANDInitStruct.
  23895. * @param FSMC_NANDInitStruct : pointer to a FSMC_NANDInitTypeDef
  23896. * structure that contains the configuration information for the FSMC
  23897. * NAND specified Banks.
  23898. * @retval None
  23899. */
  23900. void FSMC_NANDInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct)
  23901. {
  23902. uint32_t tmppcr = 0x00000000, tmppmem = 0x00000000, tmppatt = 0x00000000;
  23903. /* Check the parameters */
  23904. assert_param( IS_FSMC_NAND_BANK(FSMC_NANDInitStruct->FSMC_Bank));
  23905. assert_param( IS_FSMC_WAIT_FEATURE(FSMC_NANDInitStruct->FSMC_Waitfeature));
  23906. assert_param( IS_FSMC_MEMORY_WIDTH(FSMC_NANDInitStruct->FSMC_MemoryDataWidth));
  23907. assert_param( IS_FSMC_ECC_STATE(FSMC_NANDInitStruct->FSMC_ECC));
  23908. assert_param( IS_FSMC_ECCPAGE_SIZE(FSMC_NANDInitStruct->FSMC_ECCPageSize));
  23909. assert_param( IS_FSMC_TCLR_TIME(FSMC_NANDInitStruct->FSMC_TCLRSetupTime));
  23910. assert_param( IS_FSMC_TAR_TIME(FSMC_NANDInitStruct->FSMC_TARSetupTime));
  23911. assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime));
  23912. assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime));
  23913. assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime));
  23914. assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime));
  23915. assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime));
  23916. assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime));
  23917. assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime));
  23918. assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime));
  23919. /* Set the tmppcr value according to FSMC_NANDInitStruct parameters */
  23920. tmppcr = (uint32_t)FSMC_NANDInitStruct->FSMC_Waitfeature |
  23921. PCR_MemoryType_NAND |
  23922. FSMC_NANDInitStruct->FSMC_MemoryDataWidth |
  23923. FSMC_NANDInitStruct->FSMC_ECC |
  23924. FSMC_NANDInitStruct->FSMC_ECCPageSize |
  23925. (FSMC_NANDInitStruct->FSMC_TCLRSetupTime << 9 )|
  23926. (FSMC_NANDInitStruct->FSMC_TARSetupTime << 13);
  23927. /* Set tmppmem value according to FSMC_CommonSpaceTimingStructure parameters */
  23928. tmppmem = (uint32_t)FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime |
  23929. (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  23930. (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  23931. (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  23932. /* Set tmppatt value according to FSMC_AttributeSpaceTimingStructure parameters */
  23933. tmppatt = (uint32_t)FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime |
  23934. (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  23935. (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  23936. (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  23937. if(FSMC_NANDInitStruct->FSMC_Bank == FSMC_Bank2_NAND)
  23938. {
  23939. /* FSMC_Bank2_NAND registers configuration */
  23940. FSMC_Bank2->PCR2 = tmppcr;
  23941. FSMC_Bank2->PMEM2 = tmppmem;
  23942. FSMC_Bank2->PATT2 = tmppatt;
  23943. }
  23944. else
  23945. {
  23946. /* FSMC_Bank3_NAND registers configuration */
  23947. FSMC_Bank3->PCR3 = tmppcr;
  23948. FSMC_Bank3->PMEM3 = tmppmem;
  23949. FSMC_Bank3->PATT3 = tmppatt;
  23950. }
  23951. }
  23952. /**
  23953. * @brief Initializes the FSMC PCCARD Bank according to the specified
  23954. * parameters in the FSMC_PCCARDInitStruct.
  23955. * @param FSMC_PCCARDInitStruct : pointer to a FSMC_PCCARDInitTypeDef
  23956. * structure that contains the configuration information for the FSMC
  23957. * PCCARD Bank.
  23958. * @retval None
  23959. */
  23960. void FSMC_PCCARDInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct)
  23961. {
  23962. /* Check the parameters */
  23963. assert_param(IS_FSMC_WAIT_FEATURE(FSMC_PCCARDInitStruct->FSMC_Waitfeature));
  23964. assert_param(IS_FSMC_TCLR_TIME(FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime));
  23965. assert_param(IS_FSMC_TAR_TIME(FSMC_PCCARDInitStruct->FSMC_TARSetupTime));
  23966. assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime));
  23967. assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime));
  23968. assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime));
  23969. assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime));
  23970. assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime));
  23971. assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime));
  23972. assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime));
  23973. assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime));
  23974. assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime));
  23975. assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime));
  23976. assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime));
  23977. assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime));
  23978. /* Set the PCR4 register value according to FSMC_PCCARDInitStruct parameters */
  23979. FSMC_Bank4->PCR4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_Waitfeature |
  23980. FSMC_MemoryDataWidth_16b |
  23981. (FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime << 9) |
  23982. (FSMC_PCCARDInitStruct->FSMC_TARSetupTime << 13);
  23983. /* Set PMEM4 register value according to FSMC_CommonSpaceTimingStructure parameters */
  23984. FSMC_Bank4->PMEM4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime |
  23985. (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  23986. (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  23987. (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  23988. /* Set PATT4 register value according to FSMC_AttributeSpaceTimingStructure parameters */
  23989. FSMC_Bank4->PATT4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime |
  23990. (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  23991. (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  23992. (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  23993. /* Set PIO4 register value according to FSMC_IOSpaceTimingStructure parameters */
  23994. FSMC_Bank4->PIO4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime |
  23995. (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
  23996. (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
  23997. (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime << 24);
  23998. }
  23999. /**
  24000. * @brief Fills each FSMC_NORSRAMInitStruct member with its default value.
  24001. * @param FSMC_NORSRAMInitStruct: pointer to a FSMC_NORSRAMInitTypeDef
  24002. * structure which will be initialized.
  24003. * @retval None
  24004. */
  24005. void FSMC_NORSRAMStructInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct)
  24006. {
  24007. /* Reset NOR/SRAM Init structure parameters values */
  24008. FSMC_NORSRAMInitStruct->FSMC_Bank = FSMC_Bank1_NORSRAM1;
  24009. FSMC_NORSRAMInitStruct->FSMC_DataAddressMux = FSMC_DataAddressMux_Enable;
  24010. FSMC_NORSRAMInitStruct->FSMC_MemoryType = FSMC_MemoryType_SRAM;
  24011. FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
  24012. FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
  24013. FSMC_NORSRAMInitStruct->FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
  24014. FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
  24015. FSMC_NORSRAMInitStruct->FSMC_WrapMode = FSMC_WrapMode_Disable;
  24016. FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
  24017. FSMC_NORSRAMInitStruct->FSMC_WriteOperation = FSMC_WriteOperation_Enable;
  24018. FSMC_NORSRAMInitStruct->FSMC_WaitSignal = FSMC_WaitSignal_Enable;
  24019. FSMC_NORSRAMInitStruct->FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
  24020. FSMC_NORSRAMInitStruct->FSMC_WriteBurst = FSMC_WriteBurst_Disable;
  24021. FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime = 0xF;
  24022. FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime = 0xF;
  24023. FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime = 0xFF;
  24024. FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration = 0xF;
  24025. FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision = 0xF;
  24026. FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency = 0xF;
  24027. FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode = FSMC_AccessMode_A;
  24028. FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime = 0xF;
  24029. FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime = 0xF;
  24030. FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime = 0xFF;
  24031. FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_BusTurnAroundDuration = 0xF;
  24032. FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision = 0xF;
  24033. FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency = 0xF;
  24034. FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode = FSMC_AccessMode_A;
  24035. }
  24036. /**
  24037. * @brief Fills each FSMC_NANDInitStruct member with its default value.
  24038. * @param FSMC_NANDInitStruct: pointer to a FSMC_NANDInitTypeDef
  24039. * structure which will be initialized.
  24040. * @retval None
  24041. */
  24042. void FSMC_NANDStructInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct)
  24043. {
  24044. /* Reset NAND Init structure parameters values */
  24045. FSMC_NANDInitStruct->FSMC_Bank = FSMC_Bank2_NAND;
  24046. FSMC_NANDInitStruct->FSMC_Waitfeature = FSMC_Waitfeature_Disable;
  24047. FSMC_NANDInitStruct->FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
  24048. FSMC_NANDInitStruct->FSMC_ECC = FSMC_ECC_Disable;
  24049. FSMC_NANDInitStruct->FSMC_ECCPageSize = FSMC_ECCPageSize_256Bytes;
  24050. FSMC_NANDInitStruct->FSMC_TCLRSetupTime = 0x0;
  24051. FSMC_NANDInitStruct->FSMC_TARSetupTime = 0x0;
  24052. FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  24053. FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  24054. FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  24055. FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  24056. FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  24057. FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  24058. FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  24059. FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  24060. }
  24061. /**
  24062. * @brief Fills each FSMC_PCCARDInitStruct member with its default value.
  24063. * @param FSMC_PCCARDInitStruct: pointer to a FSMC_PCCARDInitTypeDef
  24064. * structure which will be initialized.
  24065. * @retval None
  24066. */
  24067. void FSMC_PCCARDStructInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct)
  24068. {
  24069. /* Reset PCCARD Init structure parameters values */
  24070. FSMC_PCCARDInitStruct->FSMC_Waitfeature = FSMC_Waitfeature_Disable;
  24071. FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime = 0x0;
  24072. FSMC_PCCARDInitStruct->FSMC_TARSetupTime = 0x0;
  24073. FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  24074. FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  24075. FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  24076. FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  24077. FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  24078. FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  24079. FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  24080. FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  24081. FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime = 0xFC;
  24082. FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
  24083. FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
  24084. FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
  24085. }
  24086. /**
  24087. * @brief Enables or disables the specified NOR/SRAM Memory Bank.
  24088. * @param FSMC_Bank: specifies the FSMC Bank to be used
  24089. * This parameter can be one of the following values:
  24090. * @arg FSMC_Bank1_NORSRAM1: FSMC Bank1 NOR/SRAM1
  24091. * @arg FSMC_Bank1_NORSRAM2: FSMC Bank1 NOR/SRAM2
  24092. * @arg FSMC_Bank1_NORSRAM3: FSMC Bank1 NOR/SRAM3
  24093. * @arg FSMC_Bank1_NORSRAM4: FSMC Bank1 NOR/SRAM4
  24094. * @param NewState: new state of the FSMC_Bank. This parameter can be: ENABLE or DISABLE.
  24095. * @retval None
  24096. */
  24097. void FSMC_NORSRAMCmd(uint32_t FSMC_Bank, FunctionalState NewState)
  24098. {
  24099. assert_param(IS_FSMC_NORSRAM_BANK(FSMC_Bank));
  24100. assert_param(IS_FUNCTIONAL_STATE(NewState));
  24101. if (NewState != DISABLE)
  24102. {
  24103. /* Enable the selected NOR/SRAM Bank by setting the PBKEN bit in the BCRx register */
  24104. FSMC_Bank1->BTCR[FSMC_Bank] |= BCR_MBKEN_Set;
  24105. }
  24106. else
  24107. {
  24108. /* Disable the selected NOR/SRAM Bank by clearing the PBKEN bit in the BCRx register */
  24109. FSMC_Bank1->BTCR[FSMC_Bank] &= BCR_MBKEN_Reset;
  24110. }
  24111. }
  24112. /**
  24113. * @brief Enables or disables the specified NAND Memory Bank.
  24114. * @param FSMC_Bank: specifies the FSMC Bank to be used
  24115. * This parameter can be one of the following values:
  24116. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  24117. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  24118. * @param NewState: new state of the FSMC_Bank. This parameter can be: ENABLE or DISABLE.
  24119. * @retval None
  24120. */
  24121. void FSMC_NANDCmd(uint32_t FSMC_Bank, FunctionalState NewState)
  24122. {
  24123. assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
  24124. assert_param(IS_FUNCTIONAL_STATE(NewState));
  24125. if (NewState != DISABLE)
  24126. {
  24127. /* Enable the selected NAND Bank by setting the PBKEN bit in the PCRx register */
  24128. if(FSMC_Bank == FSMC_Bank2_NAND)
  24129. {
  24130. FSMC_Bank2->PCR2 |= PCR_PBKEN_Set;
  24131. }
  24132. else
  24133. {
  24134. FSMC_Bank3->PCR3 |= PCR_PBKEN_Set;
  24135. }
  24136. }
  24137. else
  24138. {
  24139. /* Disable the selected NAND Bank by clearing the PBKEN bit in the PCRx register */
  24140. if(FSMC_Bank == FSMC_Bank2_NAND)
  24141. {
  24142. FSMC_Bank2->PCR2 &= PCR_PBKEN_Reset;
  24143. }
  24144. else
  24145. {
  24146. FSMC_Bank3->PCR3 &= PCR_PBKEN_Reset;
  24147. }
  24148. }
  24149. }
  24150. /**
  24151. * @brief Enables or disables the PCCARD Memory Bank.
  24152. * @param NewState: new state of the PCCARD Memory Bank.
  24153. * This parameter can be: ENABLE or DISABLE.
  24154. * @retval None
  24155. */
  24156. void FSMC_PCCARDCmd(FunctionalState NewState)
  24157. {
  24158. assert_param(IS_FUNCTIONAL_STATE(NewState));
  24159. if (NewState != DISABLE)
  24160. {
  24161. /* Enable the PCCARD Bank by setting the PBKEN bit in the PCR4 register */
  24162. FSMC_Bank4->PCR4 |= PCR_PBKEN_Set;
  24163. }
  24164. else
  24165. {
  24166. /* Disable the PCCARD Bank by clearing the PBKEN bit in the PCR4 register */
  24167. FSMC_Bank4->PCR4 &= PCR_PBKEN_Reset;
  24168. }
  24169. }
  24170. /**
  24171. * @brief Enables or disables the FSMC NAND ECC feature.
  24172. * @param FSMC_Bank: specifies the FSMC Bank to be used
  24173. * This parameter can be one of the following values:
  24174. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  24175. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  24176. * @param NewState: new state of the FSMC NAND ECC feature.
  24177. * This parameter can be: ENABLE or DISABLE.
  24178. * @retval None
  24179. */
  24180. void FSMC_NANDECCCmd(uint32_t FSMC_Bank, FunctionalState NewState)
  24181. {
  24182. assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
  24183. assert_param(IS_FUNCTIONAL_STATE(NewState));
  24184. if (NewState != DISABLE)
  24185. {
  24186. /* Enable the selected NAND Bank ECC function by setting the ECCEN bit in the PCRx register */
  24187. if(FSMC_Bank == FSMC_Bank2_NAND)
  24188. {
  24189. FSMC_Bank2->PCR2 |= PCR_ECCEN_Set;
  24190. }
  24191. else
  24192. {
  24193. FSMC_Bank3->PCR3 |= PCR_ECCEN_Set;
  24194. }
  24195. }
  24196. else
  24197. {
  24198. /* Disable the selected NAND Bank ECC function by clearing the ECCEN bit in the PCRx register */
  24199. if(FSMC_Bank == FSMC_Bank2_NAND)
  24200. {
  24201. FSMC_Bank2->PCR2 &= PCR_ECCEN_Reset;
  24202. }
  24203. else
  24204. {
  24205. FSMC_Bank3->PCR3 &= PCR_ECCEN_Reset;
  24206. }
  24207. }
  24208. }
  24209. /**
  24210. * @brief Returns the error correction code register value.
  24211. * @param FSMC_Bank: specifies the FSMC Bank to be used
  24212. * This parameter can be one of the following values:
  24213. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  24214. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  24215. * @retval The Error Correction Code (ECC) value.
  24216. */
  24217. uint32_t FSMC_GetECC(uint32_t FSMC_Bank)
  24218. {
  24219. uint32_t eccval = 0x00000000;
  24220. if(FSMC_Bank == FSMC_Bank2_NAND)
  24221. {
  24222. /* Get the ECCR2 register value */
  24223. eccval = FSMC_Bank2->ECCR2;
  24224. }
  24225. else
  24226. {
  24227. /* Get the ECCR3 register value */
  24228. eccval = FSMC_Bank3->ECCR3;
  24229. }
  24230. /* Return the error correction code value */
  24231. return(eccval);
  24232. }
  24233. /**
  24234. * @brief Enables or disables the specified FSMC interrupts.
  24235. * @param FSMC_Bank: specifies the FSMC Bank to be used
  24236. * This parameter can be one of the following values:
  24237. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  24238. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  24239. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  24240. * @param FSMC_IT: specifies the FSMC interrupt sources to be enabled or disabled.
  24241. * This parameter can be any combination of the following values:
  24242. * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
  24243. * @arg FSMC_IT_Level: Level edge detection interrupt.
  24244. * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
  24245. * @param NewState: new state of the specified FSMC interrupts.
  24246. * This parameter can be: ENABLE or DISABLE.
  24247. * @retval None
  24248. */
  24249. void FSMC_ITConfig(uint32_t FSMC_Bank, uint32_t FSMC_IT, FunctionalState NewState)
  24250. {
  24251. assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  24252. assert_param(IS_FSMC_IT(FSMC_IT));
  24253. assert_param(IS_FUNCTIONAL_STATE(NewState));
  24254. if (NewState != DISABLE)
  24255. {
  24256. /* Enable the selected FSMC_Bank2 interrupts */
  24257. if(FSMC_Bank == FSMC_Bank2_NAND)
  24258. {
  24259. FSMC_Bank2->SR2 |= FSMC_IT;
  24260. }
  24261. /* Enable the selected FSMC_Bank3 interrupts */
  24262. else if (FSMC_Bank == FSMC_Bank3_NAND)
  24263. {
  24264. FSMC_Bank3->SR3 |= FSMC_IT;
  24265. }
  24266. /* Enable the selected FSMC_Bank4 interrupts */
  24267. else
  24268. {
  24269. FSMC_Bank4->SR4 |= FSMC_IT;
  24270. }
  24271. }
  24272. else
  24273. {
  24274. /* Disable the selected FSMC_Bank2 interrupts */
  24275. if(FSMC_Bank == FSMC_Bank2_NAND)
  24276. {
  24277. FSMC_Bank2->SR2 &= (uint32_t)~FSMC_IT;
  24278. }
  24279. /* Disable the selected FSMC_Bank3 interrupts */
  24280. else if (FSMC_Bank == FSMC_Bank3_NAND)
  24281. {
  24282. FSMC_Bank3->SR3 &= (uint32_t)~FSMC_IT;
  24283. }
  24284. /* Disable the selected FSMC_Bank4 interrupts */
  24285. else
  24286. {
  24287. FSMC_Bank4->SR4 &= (uint32_t)~FSMC_IT;
  24288. }
  24289. }
  24290. }
  24291. /**
  24292. * @brief Checks whether the specified FSMC flag is set or not.
  24293. * @param FSMC_Bank: specifies the FSMC Bank to be used
  24294. * This parameter can be one of the following values:
  24295. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  24296. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  24297. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  24298. * @param FSMC_FLAG: specifies the flag to check.
  24299. * This parameter can be one of the following values:
  24300. * @arg FSMC_FLAG_RisingEdge: Rising egde detection Flag.
  24301. * @arg FSMC_FLAG_Level: Level detection Flag.
  24302. * @arg FSMC_FLAG_FallingEdge: Falling egde detection Flag.
  24303. * @arg FSMC_FLAG_FEMPT: Fifo empty Flag.
  24304. * @retval The new state of FSMC_FLAG (SET or RESET).
  24305. */
  24306. FlagStatus FSMC_GetFlagStatus(uint32_t FSMC_Bank, uint32_t FSMC_FLAG)
  24307. {
  24308. FlagStatus bitstatus = RESET;
  24309. uint32_t tmpsr = 0x00000000;
  24310. /* Check the parameters */
  24311. assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
  24312. assert_param(IS_FSMC_GET_FLAG(FSMC_FLAG));
  24313. if(FSMC_Bank == FSMC_Bank2_NAND)
  24314. {
  24315. tmpsr = FSMC_Bank2->SR2;
  24316. }
  24317. else if(FSMC_Bank == FSMC_Bank3_NAND)
  24318. {
  24319. tmpsr = FSMC_Bank3->SR3;
  24320. }
  24321. /* FSMC_Bank4_PCCARD*/
  24322. else
  24323. {
  24324. tmpsr = FSMC_Bank4->SR4;
  24325. }
  24326. /* Get the flag status */
  24327. if ((tmpsr & FSMC_FLAG) != (uint16_t)RESET )
  24328. {
  24329. bitstatus = SET;
  24330. }
  24331. else
  24332. {
  24333. bitstatus = RESET;
  24334. }
  24335. /* Return the flag status */
  24336. return bitstatus;
  24337. }
  24338. /**
  24339. * @brief Clears the FSMC's pending flags.
  24340. * @param FSMC_Bank: specifies the FSMC Bank to be used
  24341. * This parameter can be one of the following values:
  24342. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  24343. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  24344. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  24345. * @param FSMC_FLAG: specifies the flag to clear.
  24346. * This parameter can be any combination of the following values:
  24347. * @arg FSMC_FLAG_RisingEdge: Rising egde detection Flag.
  24348. * @arg FSMC_FLAG_Level: Level detection Flag.
  24349. * @arg FSMC_FLAG_FallingEdge: Falling egde detection Flag.
  24350. * @retval None
  24351. */
  24352. void FSMC_ClearFlag(uint32_t FSMC_Bank, uint32_t FSMC_FLAG)
  24353. {
  24354. /* Check the parameters */
  24355. assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
  24356. assert_param(IS_FSMC_CLEAR_FLAG(FSMC_FLAG)) ;
  24357. if(FSMC_Bank == FSMC_Bank2_NAND)
  24358. {
  24359. FSMC_Bank2->SR2 &= ~FSMC_FLAG;
  24360. }
  24361. else if(FSMC_Bank == FSMC_Bank3_NAND)
  24362. {
  24363. FSMC_Bank3->SR3 &= ~FSMC_FLAG;
  24364. }
  24365. /* FSMC_Bank4_PCCARD*/
  24366. else
  24367. {
  24368. FSMC_Bank4->SR4 &= ~FSMC_FLAG;
  24369. }
  24370. }
  24371. /**
  24372. * @brief Checks whether the specified FSMC interrupt has occurred or not.
  24373. * @param FSMC_Bank: specifies the FSMC Bank to be used
  24374. * This parameter can be one of the following values:
  24375. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  24376. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  24377. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  24378. * @param FSMC_IT: specifies the FSMC interrupt source to check.
  24379. * This parameter can be one of the following values:
  24380. * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
  24381. * @arg FSMC_IT_Level: Level edge detection interrupt.
  24382. * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
  24383. * @retval The new state of FSMC_IT (SET or RESET).
  24384. */
  24385. ITStatus FSMC_GetITStatus(uint32_t FSMC_Bank, uint32_t FSMC_IT)
  24386. {
  24387. ITStatus bitstatus = RESET;
  24388. uint32_t tmpsr = 0x0, itstatus = 0x0, itenable = 0x0;
  24389. /* Check the parameters */
  24390. assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  24391. assert_param(IS_FSMC_GET_IT(FSMC_IT));
  24392. if(FSMC_Bank == FSMC_Bank2_NAND)
  24393. {
  24394. tmpsr = FSMC_Bank2->SR2;
  24395. }
  24396. else if(FSMC_Bank == FSMC_Bank3_NAND)
  24397. {
  24398. tmpsr = FSMC_Bank3->SR3;
  24399. }
  24400. /* FSMC_Bank4_PCCARD*/
  24401. else
  24402. {
  24403. tmpsr = FSMC_Bank4->SR4;
  24404. }
  24405. itstatus = tmpsr & FSMC_IT;
  24406. itenable = tmpsr & (FSMC_IT >> 3);
  24407. if ((itstatus != (uint32_t)RESET) && (itenable != (uint32_t)RESET))
  24408. {
  24409. bitstatus = SET;
  24410. }
  24411. else
  24412. {
  24413. bitstatus = RESET;
  24414. }
  24415. return bitstatus;
  24416. }
  24417. /**
  24418. * @brief Clears the FSMC's interrupt pending bits.
  24419. * @param FSMC_Bank: specifies the FSMC Bank to be used
  24420. * This parameter can be one of the following values:
  24421. * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
  24422. * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
  24423. * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
  24424. * @param FSMC_IT: specifies the interrupt pending bit to clear.
  24425. * This parameter can be any combination of the following values:
  24426. * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
  24427. * @arg FSMC_IT_Level: Level edge detection interrupt.
  24428. * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
  24429. * @retval None
  24430. */
  24431. void FSMC_ClearITPendingBit(uint32_t FSMC_Bank, uint32_t FSMC_IT)
  24432. {
  24433. /* Check the parameters */
  24434. assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  24435. assert_param(IS_FSMC_IT(FSMC_IT));
  24436. if(FSMC_Bank == FSMC_Bank2_NAND)
  24437. {
  24438. FSMC_Bank2->SR2 &= ~(FSMC_IT >> 3);
  24439. }
  24440. else if(FSMC_Bank == FSMC_Bank3_NAND)
  24441. {
  24442. FSMC_Bank3->SR3 &= ~(FSMC_IT >> 3);
  24443. }
  24444. /* FSMC_Bank4_PCCARD*/
  24445. else
  24446. {
  24447. FSMC_Bank4->SR4 &= ~(FSMC_IT >> 3);
  24448. }
  24449. }
  24450. /**
  24451. * @}
  24452. */
  24453. /**
  24454. * @}
  24455. */
  24456. /**
  24457. * @}
  24458. */
  24459. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
  24460. /**
  24461. ******************************************************************************
  24462. * @file SPI/SPI_MSD/stm32f0xx_it.c
  24463. * @author MCD Application Team
  24464. * @version V1.0.0
  24465. * @date 18-May-2012
  24466. * @brief Main Interrupt Service Routines.
  24467. * This file provides template for all exceptions handler and
  24468. * peripherals interrupt service routine.
  24469. ******************************************************************************
  24470. * @attention
  24471. *
  24472. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  24473. *
  24474. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  24475. * You may not use this file except in compliance with the License.
  24476. * You may obtain a copy of the License at:
  24477. *
  24478. * http://www.st.com/software_license_agreement_liberty_v2
  24479. *
  24480. * Unless required by applicable law or agreed to in writing, software
  24481. * distributed under the License is distributed on an "AS IS" BASIS,
  24482. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  24483. * See the License for the specific language governing permissions and
  24484. * limitations under the License.
  24485. *
  24486. ******************************************************************************
  24487. */
  24488. /* Includes ------------------------------------------------------------------*/
  24489. #include "stm32f0xx_it.h"
  24490. /** @addtogroup STM32F0xx_StdPeriph_Examples
  24491. * @{
  24492. */
  24493. /** @addtogroup SPI_MSD
  24494. * @{
  24495. */
  24496. /* Private typedef -----------------------------------------------------------*/
  24497. /* Private define ------------------------------------------------------------*/
  24498. /* Private macro -------------------------------------------------------------*/
  24499. /* Private variables ---------------------------------------------------------*/
  24500. /* Private function prototypes -----------------------------------------------*/
  24501. /* Private functions ---------------------------------------------------------*/
  24502. /******************************************************************************/
  24503. /* Cortex-M0 Processor Exceptions Handlers */
  24504. /******************************************************************************/
  24505. /**
  24506. * @brief This function handles NMI exception.
  24507. * @param None
  24508. * @retval None
  24509. */
  24510. void NMI_Handler(void)
  24511. {
  24512. }
  24513. /**
  24514. * @brief This function handles Hard Fault exception.
  24515. * @param None
  24516. * @retval None
  24517. */
  24518. void HardFault_Handler(void)
  24519. {
  24520. /* Go to infinite loop when Hard Fault exception occurs */
  24521. while (1)
  24522. {
  24523. }
  24524. }
  24525. /**
  24526. * @brief This function handles SVCall exception.
  24527. * @param None
  24528. * @retval None
  24529. */
  24530. void SVC_Handler(void)
  24531. {
  24532. }
  24533. /**
  24534. * @brief This function handles PendSVC exception.
  24535. * @param None
  24536. * @retval None
  24537. */
  24538. void PendSV_Handler(void)
  24539. {
  24540. }
  24541. /**
  24542. * @brief This function handles SysTick Handler.
  24543. * @param None
  24544. * @retval None
  24545. */
  24546. void SysTick_Handler(void)
  24547. {
  24548. }
  24549. /******************************************************************************/
  24550. /* STM32F0xx Peripherals Interrupt Handlers */
  24551. /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
  24552. /* available peripheral interrupt handler's name please refer to the startup */
  24553. /* file (startup_stm32f0xx.s). */
  24554. /******************************************************************************/
  24555. /**
  24556. * @brief This function handles PPP interrupt request.
  24557. * @param None
  24558. * @retval None
  24559. */
  24560. /*void PPP_IRQHandler(void)
  24561. {
  24562. }*/
  24563. /**
  24564. * @}
  24565. */
  24566. /**
  24567. * @}
  24568. */
  24569. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  24570. /**
  24571. ******************************************************************************
  24572. * @file system_stm32f0xx.c
  24573. * @author MCD Application Team
  24574. * @version V1.0.0
  24575. * @date 18-May-2012
  24576. * @brief CMSIS Cortex-M0 Device Peripheral Access Layer System Source File.
  24577. * This file contains the system clock configuration for STM32F0xx devices,
  24578. * and is generated by the clock configuration tool
  24579. * STM32F0xx_Clock_Configuration_V1.0.1.xls
  24580. *
  24581. * 1. This file provides two functions and one global variable to be called from
  24582. * user application:
  24583. * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
  24584. * and Divider factors, AHB/APBx prescalers and Flash settings),
  24585. * depending on the configuration made in the clock xls tool.
  24586. * This function is called at startup just after reset and
  24587. * before branch to main program. This call is made inside
  24588. * the "startup_stm32f0xx.s" file.
  24589. *
  24590. * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
  24591. * by the user application to setup the SysTick
  24592. * timer or configure other parameters.
  24593. *
  24594. * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
  24595. * be called whenever the core clock is changed
  24596. * during program execution.
  24597. *
  24598. * 2. After each device reset the HSI (8 MHz Range) is used as system clock source.
  24599. * Then SystemInit() function is called, in "startup_stm32f0xx.s" file, to
  24600. * configure the system clock before to branch to main program.
  24601. *
  24602. * 3. If the system clock source selected by user fails to startup, the SystemInit()
  24603. * function will do nothing and HSI still used as system clock source. User can
  24604. * add some code to deal with this issue inside the SetSysClock() function.
  24605. *
  24606. * 4. The default value of HSE crystal is set to 8MHz, refer to "HSE_VALUE" define
  24607. * in "stm32f0xx.h" file. When HSE is used as system clock source, directly or
  24608. * through PLL, and you are using different crystal you have to adapt the HSE
  24609. * value to your own configuration.
  24610. *
  24611. * 5. This file configures the system clock as follows:
  24612. *=============================================================================
  24613. *=============================================================================
  24614. * System Clock source | PLL(HSE)
  24615. *-----------------------------------------------------------------------------
  24616. * SYSCLK(Hz) | 48000000
  24617. *-----------------------------------------------------------------------------
  24618. * HCLK(Hz) | 48000000
  24619. *-----------------------------------------------------------------------------
  24620. * AHB Prescaler | 1
  24621. *-----------------------------------------------------------------------------
  24622. * APB Prescaler | 1
  24623. *-----------------------------------------------------------------------------
  24624. * HSE Frequency(Hz) | 8000000
  24625. *----------------------------------------------------------------------------
  24626. * PLLMUL | 6
  24627. *-----------------------------------------------------------------------------
  24628. * PREDIV | 1
  24629. *-----------------------------------------------------------------------------
  24630. * Flash Latency(WS) | 1
  24631. *-----------------------------------------------------------------------------
  24632. * Prefetch Buffer | ON
  24633. *-----------------------------------------------------------------------------
  24634. ******************************************************************************
  24635. * @attention
  24636. *
  24637. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  24638. *
  24639. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  24640. * You may not use this file except in compliance with the License.
  24641. * You may obtain a copy of the License at:
  24642. *
  24643. * http://www.st.com/software_license_agreement_liberty_v2
  24644. *
  24645. * Unless required by applicable law or agreed to in writing, software
  24646. * distributed under the License is distributed on an "AS IS" BASIS,
  24647. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  24648. * See the License for the specific language governing permissions and
  24649. * limitations under the License.
  24650. *
  24651. ******************************************************************************
  24652. */
  24653. /** @addtogroup CMSIS
  24654. * @{
  24655. */
  24656. /** @addtogroup stm32f0xx_system
  24657. * @{
  24658. */
  24659. /** @addtogroup STM32F0xx_System_Private_Includes
  24660. * @{
  24661. */
  24662. #include "stm32f0xx.h"
  24663. /**
  24664. * @}
  24665. */
  24666. /** @addtogroup STM32F0xx_System_Private_TypesDefinitions
  24667. * @{
  24668. */
  24669. /**
  24670. * @}
  24671. */
  24672. /** @addtogroup STM32F0xx_System_Private_Defines
  24673. * @{
  24674. */
  24675. /**
  24676. * @}
  24677. */
  24678. /** @addtogroup STM32F0xx_System_Private_Macros
  24679. * @{
  24680. */
  24681. /**
  24682. * @}
  24683. */
  24684. /** @addtogroup STM32F0xx_System_Private_Variables
  24685. * @{
  24686. */
  24687. uint32_t SystemCoreClock = 48000000;
  24688. __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
  24689. /**
  24690. * @}
  24691. */
  24692. /** @addtogroup STM32F0xx_System_Private_FunctionPrototypes
  24693. * @{
  24694. */
  24695. static void SetSysClock(void);
  24696. /**
  24697. * @}
  24698. */
  24699. /** @addtogroup STM32F0xx_System_Private_Functions
  24700. * @{
  24701. */
  24702. /**
  24703. * @brief Setup the microcontroller system.
  24704. * Initialize the Embedded Flash Interface, the PLL and update the
  24705. * SystemCoreClock variable.
  24706. * @param None
  24707. * @retval None
  24708. */
  24709. void SystemInit (void)
  24710. {
  24711. /* Set HSION bit */
  24712. RCC->CR |= (uint32_t)0x00000001;
  24713. /* Reset SW[1:0], HPRE[3:0], PPRE[2:0], ADCPRE and MCOSEL[2:0] bits */
  24714. RCC->CFGR &= (uint32_t)0xF8FFB80C;
  24715. /* Reset HSEON, CSSON and PLLON bits */
  24716. RCC->CR &= (uint32_t)0xFEF6FFFF;
  24717. /* Reset HSEBYP bit */
  24718. RCC->CR &= (uint32_t)0xFFFBFFFF;
  24719. /* Reset PLLSRC, PLLXTPRE and PLLMUL[3:0] bits */
  24720. RCC->CFGR &= (uint32_t)0xFFC0FFFF;
  24721. /* Reset PREDIV1[3:0] bits */
  24722. RCC->CFGR2 &= (uint32_t)0xFFFFFFF0;
  24723. /* Reset USARTSW[1:0], I2CSW, CECSW and ADCSW bits */
  24724. RCC->CFGR3 &= (uint32_t)0xFFFFFEAC;
  24725. /* Reset HSI14 bit */
  24726. RCC->CR2 &= (uint32_t)0xFFFFFFFE;
  24727. /* Disable all interrupts */
  24728. RCC->CIR = 0x00000000;
  24729. /* Configure the System clock frequency, AHB/APBx prescalers and Flash settings */
  24730. SetSysClock();
  24731. }
  24732. /**
  24733. * @brief Update SystemCoreClock according to Clock Register Values
  24734. * The SystemCoreClock variable contains the core clock (HCLK), it can
  24735. * be used by the user application to setup the SysTick timer or configure
  24736. * other parameters.
  24737. *
  24738. * @note Each time the core clock (HCLK) changes, this function must be called
  24739. * to update SystemCoreClock variable value. Otherwise, any configuration
  24740. * based on this variable will be incorrect.
  24741. *
  24742. * @note - The system frequency computed by this function is not the real
  24743. * frequency in the chip. It is calculated based on the predefined
  24744. * constant and the selected clock source:
  24745. *
  24746. * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
  24747. *
  24748. * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
  24749. *
  24750. * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
  24751. * or HSI_VALUE(*) multiplied/divided by the PLL factors.
  24752. *
  24753. * (*) HSI_VALUE is a constant defined in stm32f0xx.h file (default value
  24754. * 8 MHz) but the real value may vary depending on the variations
  24755. * in voltage and temperature.
  24756. *
  24757. * (**) HSE_VALUE is a constant defined in stm32f0xx.h file (default value
  24758. * 8 MHz), user has to ensure that HSE_VALUE is same as the real
  24759. * frequency of the crystal used. Otherwise, this function may
  24760. * have wrong result.
  24761. *
  24762. * - The result of this function could be not correct when using fractional
  24763. * value for HSE crystal.
  24764. * @param None
  24765. * @retval None
  24766. */
  24767. void SystemCoreClockUpdate (void)
  24768. {
  24769. uint32_t tmp = 0, pllmull = 0, pllsource = 0, prediv1factor = 0;
  24770. /* Get SYSCLK source -------------------------------------------------------*/
  24771. tmp = RCC->CFGR & RCC_CFGR_SWS;
  24772. switch (tmp)
  24773. {
  24774. case 0x00: /* HSI used as system clock */
  24775. SystemCoreClock = HSI_VALUE;
  24776. break;
  24777. case 0x04: /* HSE used as system clock */
  24778. SystemCoreClock = HSE_VALUE;
  24779. break;
  24780. case 0x08: /* PLL used as system clock */
  24781. /* Get PLL clock source and multiplication factor ----------------------*/
  24782. pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
  24783. pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
  24784. pllmull = ( pllmull >> 18) + 2;
  24785. if (pllsource == 0x00)
  24786. {
  24787. /* HSI oscillator clock divided by 2 selected as PLL clock entry */
  24788. SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
  24789. }
  24790. else
  24791. {
  24792. prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
  24793. /* HSE oscillator clock selected as PREDIV1 clock entry */
  24794. SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
  24795. }
  24796. break;
  24797. default: /* HSI used as system clock */
  24798. SystemCoreClock = HSI_VALUE;
  24799. break;
  24800. }
  24801. /* Compute HCLK clock frequency ----------------*/
  24802. /* Get HCLK prescaler */
  24803. tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
  24804. /* HCLK clock frequency */
  24805. SystemCoreClock >>= tmp;
  24806. }
  24807. /**
  24808. * @brief Configures the System clock frequency, AHB/APBx prescalers and Flash
  24809. * settings.
  24810. * @note This function should be called only once the RCC clock configuration
  24811. * is reset to the default reset state (done in SystemInit() function).
  24812. * @param None
  24813. * @retval None
  24814. */
  24815. static void SetSysClock(void)
  24816. {
  24817. __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
  24818. /******************************************************************************/
  24819. /* PLL (clocked by HSE) used as System clock source */
  24820. /******************************************************************************/
  24821. /* SYSCLK, HCLK, PCLK configuration ----------------------------------------*/
  24822. /* Enable HSE */
  24823. RCC->CR |= ((uint32_t)RCC_CR_HSEON);
  24824. /* Wait till HSE is ready and if Time out is reached exit */
  24825. do
  24826. {
  24827. HSEStatus = RCC->CR & RCC_CR_HSERDY;
  24828. StartUpCounter++;
  24829. } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
  24830. if ((RCC->CR & RCC_CR_HSERDY) != RESET)
  24831. {
  24832. HSEStatus = (uint32_t)0x01;
  24833. }
  24834. else
  24835. {
  24836. HSEStatus = (uint32_t)0x00;
  24837. }
  24838. if (HSEStatus == (uint32_t)0x01)
  24839. {
  24840. /* Enable Prefetch Buffer and set Flash Latency */
  24841. FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY;
  24842. /* HCLK = SYSCLK */
  24843. RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
  24844. /* PCLK = HCLK */
  24845. RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE_DIV1;
  24846. /* PLL configuration */
  24847. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
  24848. RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL6);
  24849. /* Enable PLL */
  24850. RCC->CR |= RCC_CR_PLLON;
  24851. /* Wait till PLL is ready */
  24852. while((RCC->CR & RCC_CR_PLLRDY) == 0)
  24853. {
  24854. }
  24855. /* Select PLL as system clock source */
  24856. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
  24857. RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
  24858. /* Wait till PLL is used as system clock source */
  24859. while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL)
  24860. {
  24861. }
  24862. }
  24863. else
  24864. { /* If HSE fails to start-up, the application will have wrong clock
  24865. configuration. User can add here some code to deal with this error */
  24866. }
  24867. }
  24868. /**
  24869. * @}
  24870. */
  24871. /**
  24872. * @}
  24873. */
  24874. /**
  24875. * @}
  24876. */
  24877. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  24878. /**
  24879. ******************************************************************************
  24880. * @file SPI/SPI_FLASH/system_stm32f10x.c
  24881. * @author MCD Application Team
  24882. * @version V3.5.0
  24883. * @date 08-April-2011
  24884. * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
  24885. *
  24886. * 1. This file provides two functions and one global variable to be called from
  24887. * user application:
  24888. * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
  24889. * factors, AHB/APBx prescalers and Flash settings).
  24890. * This function is called at startup just after reset and
  24891. * before branch to main program. This call is made inside
  24892. * the "startup_stm32f10x_xx.s" file.
  24893. *
  24894. * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
  24895. * by the user application to setup the SysTick
  24896. * timer or configure other parameters.
  24897. *
  24898. * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
  24899. * be called whenever the core clock is changed
  24900. * during program execution.
  24901. *
  24902. * 2. After each device reset the HSI (8 MHz) is used as system clock source.
  24903. * Then SystemInit() function is called, in "startup_stm32f10x_xx.s" file, to
  24904. * configure the system clock before to branch to main program.
  24905. *
  24906. * 3. If the system clock source selected by user fails to startup, the SystemInit()
  24907. * function will do nothing and HSI still used as system clock source. User can
  24908. * add some code to deal with this issue inside the SetSysClock() function.
  24909. *
  24910. * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depedning on
  24911. * the product used), refer to "HSE_VALUE" define in "stm32f10x.h" file.
  24912. * When HSE is used as system clock source, directly or through PLL, and you
  24913. * are using different crystal you have to adapt the HSE value to your own
  24914. * configuration.
  24915. *
  24916. ******************************************************************************
  24917. * @attention
  24918. *
  24919. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  24920. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  24921. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  24922. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  24923. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  24924. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  24925. *
  24926. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  24927. ******************************************************************************
  24928. */
  24929. /** @addtogroup CMSIS
  24930. * @{
  24931. */
  24932. /** @addtogroup stm32f10x_system
  24933. * @{
  24934. */
  24935. /** @addtogroup STM32F10x_System_Private_Includes
  24936. * @{
  24937. */
  24938. #include "stm32f10x.h"
  24939. /**
  24940. * @}
  24941. */
  24942. /** @addtogroup STM32F10x_System_Private_TypesDefinitions
  24943. * @{
  24944. */
  24945. /**
  24946. * @}
  24947. */
  24948. /** @addtogroup STM32F10x_System_Private_Defines
  24949. * @{
  24950. */
  24951. /*!< Uncomment the line corresponding to the desired System clock (SYSCLK)
  24952. frequency (after reset the HSI is used as SYSCLK source)
  24953. IMPORTANT NOTE:
  24954. ==============
  24955. 1. After each device reset the HSI is used as System clock source.
  24956. 2. Please make sure that the selected System clock doesn't exceed your device's
  24957. maximum frequency.
  24958. 3. If none of the define below is enabled, the HSI is used as System clock
  24959. source.
  24960. 4. The System clock configuration functions provided within this file assume that:
  24961. - For Low, Medium and High density Value line devices an external 8MHz
  24962. crystal is used to drive the System clock.
  24963. - For Low, Medium and High density devices an external 8MHz crystal is
  24964. used to drive the System clock.
  24965. - For Connectivity line devices an external 25MHz crystal is used to drive
  24966. the System clock.
  24967. If you are using different crystal you have to adapt those functions accordingly.
  24968. */
  24969. #if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
  24970. /* #define SYSCLK_FREQ_HSE HSE_VALUE */
  24971. #define SYSCLK_FREQ_24MHz 24000000
  24972. #else
  24973. /* #define SYSCLK_FREQ_HSE HSE_VALUE */
  24974. /* #define SYSCLK_FREQ_24MHz 24000000 */
  24975. /* #define SYSCLK_FREQ_36MHz 36000000 */
  24976. /* #define SYSCLK_FREQ_48MHz 48000000 */
  24977. /* #define SYSCLK_FREQ_56MHz 56000000 */
  24978. #define SYSCLK_FREQ_72MHz 72000000
  24979. #endif
  24980. /*!< Uncomment the following line if you need to use external SRAM mounted
  24981. on STM3210E-EVAL board (STM32 High density and XL-density devices) or on
  24982. STM32100E-EVAL board (STM32 High-density value line devices) as data memory */
  24983. #if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL)
  24984. /* #define DATA_IN_ExtSRAM */
  24985. #endif
  24986. /*!< Uncomment the following line if you need to relocate your vector Table in
  24987. Internal SRAM. */
  24988. /* #define VECT_TAB_SRAM */
  24989. #define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field.
  24990. This value must be a multiple of 0x200. */
  24991. /**
  24992. * @}
  24993. */
  24994. /** @addtogroup STM32F10x_System_Private_Macros
  24995. * @{
  24996. */
  24997. /**
  24998. * @}
  24999. */
  25000. /** @addtogroup STM32F10x_System_Private_Variables
  25001. * @{
  25002. */
  25003. /*******************************************************************************
  25004. * Clock Definitions
  25005. *******************************************************************************/
  25006. #ifdef SYSCLK_FREQ_HSE
  25007. uint32_t SystemCoreClock = SYSCLK_FREQ_HSE; /*!< System Clock Frequency (Core Clock) */
  25008. #elif defined SYSCLK_FREQ_24MHz
  25009. uint32_t SystemCoreClock = SYSCLK_FREQ_24MHz; /*!< System Clock Frequency (Core Clock) */
  25010. #elif defined SYSCLK_FREQ_36MHz
  25011. uint32_t SystemCoreClock = SYSCLK_FREQ_36MHz; /*!< System Clock Frequency (Core Clock) */
  25012. #elif defined SYSCLK_FREQ_48MHz
  25013. uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz; /*!< System Clock Frequency (Core Clock) */
  25014. #elif defined SYSCLK_FREQ_56MHz
  25015. uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz; /*!< System Clock Frequency (Core Clock) */
  25016. #elif defined SYSCLK_FREQ_72MHz
  25017. uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz; /*!< System Clock Frequency (Core Clock) */
  25018. #else /*!< HSI Selected as System Clock source */
  25019. uint32_t SystemCoreClock = HSI_VALUE; /*!< System Clock Frequency (Core Clock) */
  25020. #endif
  25021. __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
  25022. /**
  25023. * @}
  25024. */
  25025. /** @addtogroup STM32F10x_System_Private_FunctionPrototypes
  25026. * @{
  25027. */
  25028. static void SetSysClock(void);
  25029. #ifdef SYSCLK_FREQ_HSE
  25030. static void SetSysClockToHSE(void);
  25031. #elif defined SYSCLK_FREQ_24MHz
  25032. static void SetSysClockTo24(void);
  25033. #elif defined SYSCLK_FREQ_36MHz
  25034. static void SetSysClockTo36(void);
  25035. #elif defined SYSCLK_FREQ_48MHz
  25036. static void SetSysClockTo48(void);
  25037. #elif defined SYSCLK_FREQ_56MHz
  25038. static void SetSysClockTo56(void);
  25039. #elif defined SYSCLK_FREQ_72MHz
  25040. static void SetSysClockTo72(void);
  25041. #endif
  25042. #ifdef DATA_IN_ExtSRAM
  25043. static void SystemInit_ExtMemCtl(void);
  25044. #endif /* DATA_IN_ExtSRAM */
  25045. /**
  25046. * @}
  25047. */
  25048. /** @addtogroup STM32F10x_System_Private_Functions
  25049. * @{
  25050. */
  25051. /**
  25052. * @brief Setup the microcontroller system
  25053. * Initialize the Embedded Flash Interface, the PLL and update the
  25054. * SystemCoreClock variable.
  25055. * @note This function should be used only after reset.
  25056. * @param None
  25057. * @retval None
  25058. */
  25059. void SystemInit (void)
  25060. {
  25061. /* Reset the RCC clock configuration to the default reset state(for debug purpose) */
  25062. /* Set HSION bit */
  25063. RCC->CR |= (uint32_t)0x00000001;
  25064. /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
  25065. #ifndef STM32F10X_CL
  25066. RCC->CFGR &= (uint32_t)0xF8FF0000;
  25067. #else
  25068. RCC->CFGR &= (uint32_t)0xF0FF0000;
  25069. #endif /* STM32F10X_CL */
  25070. /* Reset HSEON, CSSON and PLLON bits */
  25071. RCC->CR &= (uint32_t)0xFEF6FFFF;
  25072. /* Reset HSEBYP bit */
  25073. RCC->CR &= (uint32_t)0xFFFBFFFF;
  25074. /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
  25075. RCC->CFGR &= (uint32_t)0xFF80FFFF;
  25076. #ifdef STM32F10X_CL
  25077. /* Reset PLL2ON and PLL3ON bits */
  25078. RCC->CR &= (uint32_t)0xEBFFFFFF;
  25079. /* Disable all interrupts and clear pending bits */
  25080. RCC->CIR = 0x00FF0000;
  25081. /* Reset CFGR2 register */
  25082. RCC->CFGR2 = 0x00000000;
  25083. #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
  25084. /* Disable all interrupts and clear pending bits */
  25085. RCC->CIR = 0x009F0000;
  25086. /* Reset CFGR2 register */
  25087. RCC->CFGR2 = 0x00000000;
  25088. #else
  25089. /* Disable all interrupts and clear pending bits */
  25090. RCC->CIR = 0x009F0000;
  25091. #endif /* STM32F10X_CL */
  25092. #if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL)
  25093. #ifdef DATA_IN_ExtSRAM
  25094. SystemInit_ExtMemCtl();
  25095. #endif /* DATA_IN_ExtSRAM */
  25096. #endif
  25097. /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */
  25098. /* Configure the Flash Latency cycles and enable prefetch buffer */
  25099. SetSysClock();
  25100. #ifdef VECT_TAB_SRAM
  25101. SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
  25102. #else
  25103. SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
  25104. #endif
  25105. }
  25106. /**
  25107. * @brief Update SystemCoreClock variable according to Clock Register Values.
  25108. * The SystemCoreClock variable contains the core clock (HCLK), it can
  25109. * be used by the user application to setup the SysTick timer or configure
  25110. * other parameters.
  25111. *
  25112. * @note Each time the core clock (HCLK) changes, this function must be called
  25113. * to update SystemCoreClock variable value. Otherwise, any configuration
  25114. * based on this variable will be incorrect.
  25115. *
  25116. * @note - The system frequency computed by this function is not the real
  25117. * frequency in the chip. It is calculated based on the predefined
  25118. * constant and the selected clock source:
  25119. *
  25120. * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
  25121. *
  25122. * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
  25123. *
  25124. * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
  25125. * or HSI_VALUE(*) multiplied by the PLL factors.
  25126. *
  25127. * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value
  25128. * 8 MHz) but the real value may vary depending on the variations
  25129. * in voltage and temperature.
  25130. *
  25131. * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value
  25132. * 8 MHz or 25 MHz, depedning on the product used), user has to ensure
  25133. * that HSE_VALUE is same as the real frequency of the crystal used.
  25134. * Otherwise, this function may have wrong result.
  25135. *
  25136. * - The result of this function could be not correct when using fractional
  25137. * value for HSE crystal.
  25138. * @param None
  25139. * @retval None
  25140. */
  25141. void SystemCoreClockUpdate (void)
  25142. {
  25143. uint32_t tmp = 0, pllmull = 0, pllsource = 0;
  25144. #ifdef STM32F10X_CL
  25145. uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor = 0, pll2mull = 0;
  25146. #endif /* STM32F10X_CL */
  25147. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
  25148. uint32_t prediv1factor = 0;
  25149. #endif /* STM32F10X_LD_VL or STM32F10X_MD_VL or STM32F10X_HD_VL */
  25150. /* Get SYSCLK source -------------------------------------------------------*/
  25151. tmp = RCC->CFGR & RCC_CFGR_SWS;
  25152. switch (tmp)
  25153. {
  25154. case 0x00: /* HSI used as system clock */
  25155. SystemCoreClock = HSI_VALUE;
  25156. break;
  25157. case 0x04: /* HSE used as system clock */
  25158. SystemCoreClock = HSE_VALUE;
  25159. break;
  25160. case 0x08: /* PLL used as system clock */
  25161. /* Get PLL clock source and multiplication factor ----------------------*/
  25162. pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
  25163. pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
  25164. #ifndef STM32F10X_CL
  25165. pllmull = ( pllmull >> 18) + 2;
  25166. if (pllsource == 0x00)
  25167. {
  25168. /* HSI oscillator clock divided by 2 selected as PLL clock entry */
  25169. SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
  25170. }
  25171. else
  25172. {
  25173. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
  25174. prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
  25175. /* HSE oscillator clock selected as PREDIV1 clock entry */
  25176. SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
  25177. #else
  25178. /* HSE selected as PLL clock entry */
  25179. if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)
  25180. {/* HSE oscillator clock divided by 2 */
  25181. SystemCoreClock = (HSE_VALUE >> 1) * pllmull;
  25182. }
  25183. else
  25184. {
  25185. SystemCoreClock = HSE_VALUE * pllmull;
  25186. }
  25187. #endif
  25188. }
  25189. #else
  25190. pllmull = pllmull >> 18;
  25191. if (pllmull != 0x0D)
  25192. {
  25193. pllmull += 2;
  25194. }
  25195. else
  25196. { /* PLL multiplication factor = PLL input clock * 6.5 */
  25197. pllmull = 13 / 2;
  25198. }
  25199. if (pllsource == 0x00)
  25200. {
  25201. /* HSI oscillator clock divided by 2 selected as PLL clock entry */
  25202. SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
  25203. }
  25204. else
  25205. {/* PREDIV1 selected as PLL clock entry */
  25206. /* Get PREDIV1 clock source and division factor */
  25207. prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
  25208. prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
  25209. if (prediv1source == 0)
  25210. {
  25211. /* HSE oscillator clock selected as PREDIV1 clock entry */
  25212. SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
  25213. }
  25214. else
  25215. {/* PLL2 clock selected as PREDIV1 clock entry */
  25216. /* Get PREDIV2 division factor and PLL2 multiplication factor */
  25217. prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4) + 1;
  25218. pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8 ) + 2;
  25219. SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;
  25220. }
  25221. }
  25222. #endif /* STM32F10X_CL */
  25223. break;
  25224. default:
  25225. SystemCoreClock = HSI_VALUE;
  25226. break;
  25227. }
  25228. /* Compute HCLK clock frequency ----------------*/
  25229. /* Get HCLK prescaler */
  25230. tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
  25231. /* HCLK clock frequency */
  25232. SystemCoreClock >>= tmp;
  25233. }
  25234. /**
  25235. * @brief Configures the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers.
  25236. * @param None
  25237. * @retval None
  25238. */
  25239. static void SetSysClock(void)
  25240. {
  25241. #ifdef SYSCLK_FREQ_HSE
  25242. SetSysClockToHSE();
  25243. #elif defined SYSCLK_FREQ_24MHz
  25244. SetSysClockTo24();
  25245. #elif defined SYSCLK_FREQ_36MHz
  25246. SetSysClockTo36();
  25247. #elif defined SYSCLK_FREQ_48MHz
  25248. SetSysClockTo48();
  25249. #elif defined SYSCLK_FREQ_56MHz
  25250. SetSysClockTo56();
  25251. #elif defined SYSCLK_FREQ_72MHz
  25252. SetSysClockTo72();
  25253. #endif
  25254. /* If none of the define above is enabled, the HSI is used as System clock
  25255. source (default after reset) */
  25256. }
  25257. /**
  25258. * @brief Setup the external memory controller. Called in startup_stm32f10x.s
  25259. * before jump to __main
  25260. * @param None
  25261. * @retval None
  25262. */
  25263. #ifdef DATA_IN_ExtSRAM
  25264. /**
  25265. * @brief Setup the external memory controller.
  25266. * Called in startup_stm32f10x_xx.s/.c before jump to main.
  25267. * This function configures the external SRAM mounted on STM3210E-EVAL
  25268. * board (STM32 High density devices). This SRAM will be used as program
  25269. * data memory (including heap and stack).
  25270. * @param None
  25271. * @retval None
  25272. */
  25273. void SystemInit_ExtMemCtl(void)
  25274. {
  25275. /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
  25276. required, then adjust the Register Addresses */
  25277. /* Enable FSMC clock */
  25278. RCC->AHBENR = 0x00000114;
  25279. /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
  25280. RCC->APB2ENR = 0x000001E0;
  25281. /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
  25282. /*---------------- SRAM Address lines configuration -------------------------*/
  25283. /*---------------- NOE and NWE configuration --------------------------------*/
  25284. /*---------------- NE3 configuration ----------------------------------------*/
  25285. /*---------------- NBL0, NBL1 configuration ---------------------------------*/
  25286. GPIOD->CRL = 0x44BB44BB;
  25287. GPIOD->CRH = 0xBBBBBBBB;
  25288. GPIOE->CRL = 0xB44444BB;
  25289. GPIOE->CRH = 0xBBBBBBBB;
  25290. GPIOF->CRL = 0x44BBBBBB;
  25291. GPIOF->CRH = 0xBBBB4444;
  25292. GPIOG->CRL = 0x44BBBBBB;
  25293. GPIOG->CRH = 0x44444B44;
  25294. /*---------------- FSMC Configuration ---------------------------------------*/
  25295. /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
  25296. FSMC_Bank1->BTCR[4] = 0x00001011;
  25297. FSMC_Bank1->BTCR[5] = 0x00000200;
  25298. }
  25299. #endif /* DATA_IN_ExtSRAM */
  25300. #ifdef SYSCLK_FREQ_HSE
  25301. /**
  25302. * @brief Selects HSE as System clock source and configure HCLK, PCLK2
  25303. * and PCLK1 prescalers.
  25304. * @note This function should be used only after reset.
  25305. * @param None
  25306. * @retval None
  25307. */
  25308. static void SetSysClockToHSE(void)
  25309. {
  25310. __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
  25311. /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/
  25312. /* Enable HSE */
  25313. RCC->CR |= ((uint32_t)RCC_CR_HSEON);
  25314. /* Wait till HSE is ready and if Time out is reached exit */
  25315. do
  25316. {
  25317. HSEStatus = RCC->CR & RCC_CR_HSERDY;
  25318. StartUpCounter++;
  25319. } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
  25320. if ((RCC->CR & RCC_CR_HSERDY) != RESET)
  25321. {
  25322. HSEStatus = (uint32_t)0x01;
  25323. }
  25324. else
  25325. {
  25326. HSEStatus = (uint32_t)0x00;
  25327. }
  25328. if (HSEStatus == (uint32_t)0x01)
  25329. {
  25330. #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL
  25331. /* Enable Prefetch Buffer */
  25332. FLASH->ACR |= FLASH_ACR_PRFTBE;
  25333. /* Flash 0 wait state */
  25334. FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);
  25335. #ifndef STM32F10X_CL
  25336. FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_0;
  25337. #else
  25338. if (HSE_VALUE <= 24000000)
  25339. {
  25340. FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_0;
  25341. }
  25342. else
  25343. {
  25344. FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1;
  25345. }
  25346. #endif /* STM32F10X_CL */
  25347. #endif
  25348. /* HCLK = SYSCLK */
  25349. RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
  25350. /* PCLK2 = HCLK */
  25351. RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
  25352. /* PCLK1 = HCLK */
  25353. RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;
  25354. /* Select HSE as system clock source */
  25355. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
  25356. RCC->CFGR |= (uint32_t)RCC_CFGR_SW_HSE;
  25357. /* Wait till HSE is used as system clock source */
  25358. while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x04)
  25359. {
  25360. }
  25361. }
  25362. else
  25363. { /* If HSE fails to start-up, the application will have wrong clock
  25364. configuration. User can add here some code to deal with this error */
  25365. }
  25366. }
  25367. #elif defined SYSCLK_FREQ_24MHz
  25368. /**
  25369. * @brief Sets System clock frequency to 24MHz and configure HCLK, PCLK2
  25370. * and PCLK1 prescalers.
  25371. * @note This function should be used only after reset.
  25372. * @param None
  25373. * @retval None
  25374. */
  25375. static void SetSysClockTo24(void)
  25376. {
  25377. __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
  25378. /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/
  25379. /* Enable HSE */
  25380. RCC->CR |= ((uint32_t)RCC_CR_HSEON);
  25381. /* Wait till HSE is ready and if Time out is reached exit */
  25382. do
  25383. {
  25384. HSEStatus = RCC->CR & RCC_CR_HSERDY;
  25385. StartUpCounter++;
  25386. } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
  25387. if ((RCC->CR & RCC_CR_HSERDY) != RESET)
  25388. {
  25389. HSEStatus = (uint32_t)0x01;
  25390. }
  25391. else
  25392. {
  25393. HSEStatus = (uint32_t)0x00;
  25394. }
  25395. if (HSEStatus == (uint32_t)0x01)
  25396. {
  25397. #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL
  25398. /* Enable Prefetch Buffer */
  25399. FLASH->ACR |= FLASH_ACR_PRFTBE;
  25400. /* Flash 0 wait state */
  25401. FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);
  25402. FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_0;
  25403. #endif
  25404. /* HCLK = SYSCLK */
  25405. RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
  25406. /* PCLK2 = HCLK */
  25407. RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
  25408. /* PCLK1 = HCLK */
  25409. RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;
  25410. #ifdef STM32F10X_CL
  25411. /* Configure PLLs ------------------------------------------------------*/
  25412. /* PLL configuration: PLLCLK = PREDIV1 * 6 = 24 MHz */
  25413. RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);
  25414. RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
  25415. RCC_CFGR_PLLMULL6);
  25416. /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
  25417. /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 10 = 4 MHz */
  25418. RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
  25419. RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
  25420. RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
  25421. RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10);
  25422. /* Enable PLL2 */
  25423. RCC->CR |= RCC_CR_PLL2ON;
  25424. /* Wait till PLL2 is ready */
  25425. while((RCC->CR & RCC_CR_PLL2RDY) == 0)
  25426. {
  25427. }
  25428. #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  25429. /* PLL configuration: = (HSE / 2) * 6 = 24 MHz */
  25430. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
  25431. RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1_Div2 | RCC_CFGR_PLLMULL6);
  25432. #else
  25433. /* PLL configuration: = (HSE / 2) * 6 = 24 MHz */
  25434. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
  25435. RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | RCC_CFGR_PLLMULL6);
  25436. #endif /* STM32F10X_CL */
  25437. /* Enable PLL */
  25438. RCC->CR |= RCC_CR_PLLON;
  25439. /* Wait till PLL is ready */
  25440. while((RCC->CR & RCC_CR_PLLRDY) == 0)
  25441. {
  25442. }
  25443. /* Select PLL as system clock source */
  25444. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
  25445. RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
  25446. /* Wait till PLL is used as system clock source */
  25447. while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
  25448. {
  25449. }
  25450. }
  25451. else
  25452. { /* If HSE fails to start-up, the application will have wrong clock
  25453. configuration. User can add here some code to deal with this error */
  25454. }
  25455. }
  25456. #elif defined SYSCLK_FREQ_36MHz
  25457. /**
  25458. * @brief Sets System clock frequency to 36MHz and configure HCLK, PCLK2
  25459. * and PCLK1 prescalers.
  25460. * @note This function should be used only after reset.
  25461. * @param None
  25462. * @retval None
  25463. */
  25464. static void SetSysClockTo36(void)
  25465. {
  25466. __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
  25467. /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/
  25468. /* Enable HSE */
  25469. RCC->CR |= ((uint32_t)RCC_CR_HSEON);
  25470. /* Wait till HSE is ready and if Time out is reached exit */
  25471. do
  25472. {
  25473. HSEStatus = RCC->CR & RCC_CR_HSERDY;
  25474. StartUpCounter++;
  25475. } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
  25476. if ((RCC->CR & RCC_CR_HSERDY) != RESET)
  25477. {
  25478. HSEStatus = (uint32_t)0x01;
  25479. }
  25480. else
  25481. {
  25482. HSEStatus = (uint32_t)0x00;
  25483. }
  25484. if (HSEStatus == (uint32_t)0x01)
  25485. {
  25486. /* Enable Prefetch Buffer */
  25487. FLASH->ACR |= FLASH_ACR_PRFTBE;
  25488. /* Flash 1 wait state */
  25489. FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);
  25490. FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1;
  25491. /* HCLK = SYSCLK */
  25492. RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
  25493. /* PCLK2 = HCLK */
  25494. RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
  25495. /* PCLK1 = HCLK */
  25496. RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;
  25497. #ifdef STM32F10X_CL
  25498. /* Configure PLLs ------------------------------------------------------*/
  25499. /* PLL configuration: PLLCLK = PREDIV1 * 9 = 36 MHz */
  25500. RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);
  25501. RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
  25502. RCC_CFGR_PLLMULL9);
  25503. /*!< PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
  25504. /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 10 = 4 MHz */
  25505. RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
  25506. RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
  25507. RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
  25508. RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10);
  25509. /* Enable PLL2 */
  25510. RCC->CR |= RCC_CR_PLL2ON;
  25511. /* Wait till PLL2 is ready */
  25512. while((RCC->CR & RCC_CR_PLL2RDY) == 0)
  25513. {
  25514. }
  25515. #else
  25516. /* PLL configuration: PLLCLK = (HSE / 2) * 9 = 36 MHz */
  25517. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
  25518. RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | RCC_CFGR_PLLMULL9);
  25519. #endif /* STM32F10X_CL */
  25520. /* Enable PLL */
  25521. RCC->CR |= RCC_CR_PLLON;
  25522. /* Wait till PLL is ready */
  25523. while((RCC->CR & RCC_CR_PLLRDY) == 0)
  25524. {
  25525. }
  25526. /* Select PLL as system clock source */
  25527. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
  25528. RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
  25529. /* Wait till PLL is used as system clock source */
  25530. while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
  25531. {
  25532. }
  25533. }
  25534. else
  25535. { /* If HSE fails to start-up, the application will have wrong clock
  25536. configuration. User can add here some code to deal with this error */
  25537. }
  25538. }
  25539. #elif defined SYSCLK_FREQ_48MHz
  25540. /**
  25541. * @brief Sets System clock frequency to 48MHz and configure HCLK, PCLK2
  25542. * and PCLK1 prescalers.
  25543. * @note This function should be used only after reset.
  25544. * @param None
  25545. * @retval None
  25546. */
  25547. static void SetSysClockTo48(void)
  25548. {
  25549. __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
  25550. /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/
  25551. /* Enable HSE */
  25552. RCC->CR |= ((uint32_t)RCC_CR_HSEON);
  25553. /* Wait till HSE is ready and if Time out is reached exit */
  25554. do
  25555. {
  25556. HSEStatus = RCC->CR & RCC_CR_HSERDY;
  25557. StartUpCounter++;
  25558. } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
  25559. if ((RCC->CR & RCC_CR_HSERDY) != RESET)
  25560. {
  25561. HSEStatus = (uint32_t)0x01;
  25562. }
  25563. else
  25564. {
  25565. HSEStatus = (uint32_t)0x00;
  25566. }
  25567. if (HSEStatus == (uint32_t)0x01)
  25568. {
  25569. /* Enable Prefetch Buffer */
  25570. FLASH->ACR |= FLASH_ACR_PRFTBE;
  25571. /* Flash 1 wait state */
  25572. FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);
  25573. FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1;
  25574. /* HCLK = SYSCLK */
  25575. RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
  25576. /* PCLK2 = HCLK */
  25577. RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
  25578. /* PCLK1 = HCLK */
  25579. RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;
  25580. #ifdef STM32F10X_CL
  25581. /* Configure PLLs ------------------------------------------------------*/
  25582. /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
  25583. /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */
  25584. RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
  25585. RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
  25586. RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
  25587. RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);
  25588. /* Enable PLL2 */
  25589. RCC->CR |= RCC_CR_PLL2ON;
  25590. /* Wait till PLL2 is ready */
  25591. while((RCC->CR & RCC_CR_PLL2RDY) == 0)
  25592. {
  25593. }
  25594. /* PLL configuration: PLLCLK = PREDIV1 * 6 = 48 MHz */
  25595. RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);
  25596. RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
  25597. RCC_CFGR_PLLMULL6);
  25598. #else
  25599. /* PLL configuration: PLLCLK = HSE * 6 = 48 MHz */
  25600. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
  25601. RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL6);
  25602. #endif /* STM32F10X_CL */
  25603. /* Enable PLL */
  25604. RCC->CR |= RCC_CR_PLLON;
  25605. /* Wait till PLL is ready */
  25606. while((RCC->CR & RCC_CR_PLLRDY) == 0)
  25607. {
  25608. }
  25609. /* Select PLL as system clock source */
  25610. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
  25611. RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
  25612. /* Wait till PLL is used as system clock source */
  25613. while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
  25614. {
  25615. }
  25616. }
  25617. else
  25618. { /* If HSE fails to start-up, the application will have wrong clock
  25619. configuration. User can add here some code to deal with this error */
  25620. }
  25621. }
  25622. #elif defined SYSCLK_FREQ_56MHz
  25623. /**
  25624. * @brief Sets System clock frequency to 56MHz and configure HCLK, PCLK2
  25625. * and PCLK1 prescalers.
  25626. * @note This function should be used only after reset.
  25627. * @param None
  25628. * @retval None
  25629. */
  25630. static void SetSysClockTo56(void)
  25631. {
  25632. __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
  25633. /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/
  25634. /* Enable HSE */
  25635. RCC->CR |= ((uint32_t)RCC_CR_HSEON);
  25636. /* Wait till HSE is ready and if Time out is reached exit */
  25637. do
  25638. {
  25639. HSEStatus = RCC->CR & RCC_CR_HSERDY;
  25640. StartUpCounter++;
  25641. } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
  25642. if ((RCC->CR & RCC_CR_HSERDY) != RESET)
  25643. {
  25644. HSEStatus = (uint32_t)0x01;
  25645. }
  25646. else
  25647. {
  25648. HSEStatus = (uint32_t)0x00;
  25649. }
  25650. if (HSEStatus == (uint32_t)0x01)
  25651. {
  25652. /* Enable Prefetch Buffer */
  25653. FLASH->ACR |= FLASH_ACR_PRFTBE;
  25654. /* Flash 2 wait state */
  25655. FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);
  25656. FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_2;
  25657. /* HCLK = SYSCLK */
  25658. RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
  25659. /* PCLK2 = HCLK */
  25660. RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
  25661. /* PCLK1 = HCLK */
  25662. RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;
  25663. #ifdef STM32F10X_CL
  25664. /* Configure PLLs ------------------------------------------------------*/
  25665. /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
  25666. /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */
  25667. RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
  25668. RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
  25669. RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
  25670. RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);
  25671. /* Enable PLL2 */
  25672. RCC->CR |= RCC_CR_PLL2ON;
  25673. /* Wait till PLL2 is ready */
  25674. while((RCC->CR & RCC_CR_PLL2RDY) == 0)
  25675. {
  25676. }
  25677. /* PLL configuration: PLLCLK = PREDIV1 * 7 = 56 MHz */
  25678. RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);
  25679. RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
  25680. RCC_CFGR_PLLMULL7);
  25681. #else
  25682. /* PLL configuration: PLLCLK = HSE * 7 = 56 MHz */
  25683. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
  25684. RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL7);
  25685. #endif /* STM32F10X_CL */
  25686. /* Enable PLL */
  25687. RCC->CR |= RCC_CR_PLLON;
  25688. /* Wait till PLL is ready */
  25689. while((RCC->CR & RCC_CR_PLLRDY) == 0)
  25690. {
  25691. }
  25692. /* Select PLL as system clock source */
  25693. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
  25694. RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
  25695. /* Wait till PLL is used as system clock source */
  25696. while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
  25697. {
  25698. }
  25699. }
  25700. else
  25701. { /* If HSE fails to start-up, the application will have wrong clock
  25702. configuration. User can add here some code to deal with this error */
  25703. }
  25704. }
  25705. #elif defined SYSCLK_FREQ_72MHz
  25706. /**
  25707. * @brief Sets System clock frequency to 72MHz and configure HCLK, PCLK2
  25708. * and PCLK1 prescalers.
  25709. * @note This function should be used only after reset.
  25710. * @param None
  25711. * @retval None
  25712. */
  25713. static void SetSysClockTo72(void)
  25714. {
  25715. __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
  25716. /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/
  25717. /* Enable HSE */
  25718. RCC->CR |= ((uint32_t)RCC_CR_HSEON);
  25719. /* Wait till HSE is ready and if Time out is reached exit */
  25720. do
  25721. {
  25722. HSEStatus = RCC->CR & RCC_CR_HSERDY;
  25723. StartUpCounter++;
  25724. } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
  25725. if ((RCC->CR & RCC_CR_HSERDY) != RESET)
  25726. {
  25727. HSEStatus = (uint32_t)0x01;
  25728. }
  25729. else
  25730. {
  25731. HSEStatus = (uint32_t)0x00;
  25732. }
  25733. if (HSEStatus == (uint32_t)0x01)
  25734. {
  25735. /* Enable Prefetch Buffer */
  25736. FLASH->ACR |= FLASH_ACR_PRFTBE;
  25737. /* Flash 2 wait state */
  25738. FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);
  25739. FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_2;
  25740. /* HCLK = SYSCLK */
  25741. RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
  25742. /* PCLK2 = HCLK */
  25743. RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
  25744. /* PCLK1 = HCLK */
  25745. RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;
  25746. #ifdef STM32F10X_CL
  25747. /* Configure PLLs ------------------------------------------------------*/
  25748. /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
  25749. /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */
  25750. RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |
  25751. RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);
  25752. RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |
  25753. RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);
  25754. /* Enable PLL2 */
  25755. RCC->CR |= RCC_CR_PLL2ON;
  25756. /* Wait till PLL2 is ready */
  25757. while((RCC->CR & RCC_CR_PLL2RDY) == 0)
  25758. {
  25759. }
  25760. /* PLL configuration: PLLCLK = PREDIV1 * 9 = 72 MHz */
  25761. RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);
  25762. RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 |
  25763. RCC_CFGR_PLLMULL9);
  25764. #else
  25765. /* PLL configuration: PLLCLK = HSE * 9 = 72 MHz */
  25766. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |
  25767. RCC_CFGR_PLLMULL));
  25768. RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9);
  25769. #endif /* STM32F10X_CL */
  25770. /* Enable PLL */
  25771. RCC->CR |= RCC_CR_PLLON;
  25772. /* Wait till PLL is ready */
  25773. while((RCC->CR & RCC_CR_PLLRDY) == 0)
  25774. {
  25775. }
  25776. /* Select PLL as system clock source */
  25777. RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
  25778. RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
  25779. /* Wait till PLL is used as system clock source */
  25780. while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
  25781. {
  25782. }
  25783. }
  25784. else
  25785. { /* If HSE fails to start-up, the application will have wrong clock
  25786. configuration. User can add here some code to deal with this error */
  25787. }
  25788. }
  25789. #endif
  25790. /**
  25791. * @}
  25792. */
  25793. /**
  25794. * @}
  25795. */
  25796. /**
  25797. * @}
  25798. */
  25799. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/