Inlined STM8S SPL (STM8S103) for use with SDCC

stm8s.h 117KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867
  1. /**
  2. ******************************************************************************
  3. * @file stm8s.h
  4. * @author MCD Application Team
  5. * @version V2.2.0
  6. * @date 30-September-2014
  7. * @brief This file contains all HW registers definitions and memory mapping.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  12. *
  13. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14. * You may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at:
  16. *
  17. * http://www.st.com/software_license_agreement_liberty_v2
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *
  25. ******************************************************************************
  26. */
  27. /* Define to prevent recursive inclusion -------------------------------------*/
  28. #ifndef __STM8S_H
  29. #define __STM8S_H
  30. /** @addtogroup STM8S_StdPeriph_Driver
  31. * @{
  32. */
  33. /* Uncomment the line below according to the target STM8S or STM8A device used in your
  34. application. */
  35. /* #define STM8S208 */ /*!< STM8S High density devices with CAN */
  36. /* #define STM8S207 */ /*!< STM8S High density devices without CAN */
  37. /* #define STM8S007 */ /*!< STM8S Value Line High density devices */
  38. /* #define STM8AF52Ax */ /*!< STM8A High density devices with CAN */
  39. /* #define STM8AF62Ax */ /*!< STM8A High density devices without CAN */
  40. /* #define STM8S105 */ /*!< STM8S Medium density devices */
  41. /* #define STM8S005 */ /*!< STM8S Value Line Medium density devices */
  42. /* #define STM8AF626x */ /*!< STM8A Medium density devices */
  43. /* #define STM8AF622x */ /*!< STM8A Low density devices */
  44. /* #define STM8S103 */ /*!< STM8S Low density devices */
  45. /* #define STM8S003 */ /*!< STM8S Value Line Low density devices */
  46. /* #define STM8S903 */ /*!< STM8S Low density devices */
  47. /* Tip: To avoid modifying this file each time you need to switch between these
  48. devices, you can define the device in your toolchain compiler preprocessor.
  49. - High-Density STM8A devices are the STM8AF52xx STM8AF6269/8x/Ax,
  50. STM8AF51xx, and STM8AF6169/7x/8x/9x/Ax microcontrollers where the Flash memory
  51. density ranges between 32 to 128 Kbytes
  52. - Medium-Density STM8A devices are the STM8AF622x/4x, STM8AF6266/68,
  53. STM8AF612x/4x, and STM8AF6166/68 microcontrollers where the Flash memory
  54. density ranges between 8 to 32 Kbytes
  55. - High-Density STM8S devices are the STM8S207xx, STM8S007 and STM8S208xx microcontrollers
  56. where the Flash memory density ranges between 32 to 128 Kbytes.
  57. - Medium-Density STM8S devices are the STM8S105x and STM8S005 microcontrollers
  58. where the Flash memory density ranges between 16 to 32-Kbytes.
  59. - Low-Density STM8A devices are the STM8AF622x microcontrollers where the Flash
  60. density is 8 Kbytes.
  61. - Low-Density STM8S devices are the STM8S103xx, STM8S003 and STM8S903xx microcontrollers
  62. where the Flash density is 8 Kbytes. */
  63. #if !defined (STM8S208) && !defined (STM8S207) && !defined (STM8S105) && \
  64. !defined (STM8S103) && !defined (STM8S903) && !defined (STM8AF52Ax) && \
  65. !defined (STM8AF62Ax) && !defined (STM8AF626x) && !defined (STM8S007) && \
  66. !defined (STM8S003)&& !defined (STM8S005) && !defined (STM8AF622x)
  67. #error "Please select first the target STM8S/A device used in your application (in stm8s.h file)"
  68. #endif
  69. /******************************************************************************/
  70. /* Library configuration section */
  71. /******************************************************************************/
  72. /* Check the used compiler */
  73. #if defined(__CSMC__)
  74. #define _COSMIC_
  75. #elif defined(__RCST7__)
  76. #define _RAISONANCE_
  77. #elif defined(__ICCSTM8__)
  78. #define _IAR_
  79. #elif defined(__SDCC) // SDCC patch: add compiler
  80. #define _SDCC_
  81. #else
  82. #error "Unsupported Compiler!" /* Compiler defines not found */
  83. #endif
  84. #if !defined USE_STDPERIPH_DRIVER
  85. /* Comment the line below if you will not use the peripherals drivers.
  86. In this case, these drivers will not be included and the application code will be
  87. based on direct access to peripherals registers */
  88. #define USE_STDPERIPH_DRIVER
  89. #endif
  90. /**
  91. * @brief In the following line adjust the value of External High Speed oscillator (HSE)
  92. used in your application
  93. Tip: To avoid modifying this file each time you need to use different HSE, you
  94. can define the HSE value in your toolchain compiler preprocessor.
  95. */
  96. #if !defined HSE_Value
  97. #if defined (STM8S208) || defined (STM8S207) || defined (STM8S007) || defined (STM8AF52Ax) || \
  98. defined (STM8AF62Ax) || defined (STM8AF622x)
  99. #define HSE_VALUE ((uint32_t)24000000) /* Value of the External oscillator in Hz*/
  100. #else
  101. #define HSE_VALUE ((uint32_t)16000000) /* Value of the External oscillator in Hz*/
  102. #endif /* STM8S208 || STM8S207 || STM8S007 || STM8AF62Ax || STM8AF52Ax || STM8AF622x */
  103. #endif /* HSE_Value */
  104. /**
  105. * @brief Definition of Device on-chip RC oscillator frequencies
  106. */
  107. #define HSI_VALUE ((uint32_t)16000000) /*!< Typical Value of the HSI in Hz */
  108. #define LSI_VALUE ((uint32_t)128000) /*!< Typical Value of the LSI in Hz */
  109. #ifdef _COSMIC_
  110. #define FAR @far
  111. #define NEAR @near
  112. #define TINY @tiny
  113. #define EEPROM @eeprom
  114. #define CONST const
  115. #elif defined (_RAISONANCE_) /* __RCST7__ */
  116. #define FAR far
  117. #define NEAR data
  118. #define TINY page0
  119. #define EEPROM eeprom
  120. #define CONST code
  121. #if defined (STM8S208) || defined (STM8S207) || defined (STM8S007) || defined (STM8AF52Ax) || \
  122. defined (STM8AF62Ax)
  123. /*!< Used with memory Models for code higher than 64K */
  124. #define MEMCPY fmemcpy
  125. #else /* STM8S903, STM8S103, STM8S003, STM8S105, STM8AF626x, STM8AF622x */
  126. /*!< Used with memory Models for code less than 64K */
  127. #define MEMCPY memcpy
  128. #endif /* STM8S208 or STM8S207 or STM8S007 or STM8AF62Ax or STM8AF52Ax */
  129. #elif defined (_SDCC_) // SDCC patch: mostly not required / not supported
  130. #define FAR
  131. #define NEAR
  132. #define TINY
  133. #define EEPROM
  134. #define CONST const
  135. #else /*_IAR_*/
  136. #define FAR __far
  137. #define NEAR __near
  138. #define TINY __tiny
  139. #define EEPROM __eeprom
  140. #define CONST const
  141. #endif /* __CSMC__ */
  142. /* For FLASH routines, select whether pointer will be declared as near (2 bytes,
  143. to handle code smaller than 64KB) or far (3 bytes, to handle code larger
  144. than 64K) */
  145. #if defined (STM8S105) || defined (STM8S005) || defined (STM8S103) || defined (STM8S003) || \
  146. defined (STM8S903) || defined (STM8AF626x) || defined (STM8AF622x)
  147. /*!< Used with memory Models for code smaller than 64K */
  148. #define PointerAttr NEAR
  149. #define MemoryAddressCast uint16_t
  150. #else /* STM8S208 or STM8S207 or STM8AF62Ax or STM8AF52Ax */
  151. /*!< Used with memory Models for code higher than 64K */
  152. #define PointerAttr FAR
  153. #define MemoryAddressCast uint32_t
  154. #endif /* STM8S105 or STM8S103 or STM8S003 or STM8S903 or STM8AF626x or STM8AF622x */
  155. /* Uncomment the line below to enable the FLASH functions execution from RAM */
  156. #if !defined (RAM_EXECUTION)
  157. /* #define RAM_EXECUTION (1) */
  158. #endif /* RAM_EXECUTION */
  159. #ifdef RAM_EXECUTION
  160. #ifdef _COSMIC_
  161. #define IN_RAM(a) a
  162. #elif defined (_RAISONANCE_) /* __RCST7__ */
  163. #define IN_RAM(a) a inram
  164. #elif defined (_SDCC_) // SDCC patch: code in RAM not yet patched
  165. #define IN_RAM(a) a
  166. #else /*_IAR_*/
  167. #define IN_RAM(a) __ramfunc a
  168. #endif /* _COSMIC_ */
  169. #else
  170. #define IN_RAM(a) a
  171. #endif /* RAM_EXECUTION */
  172. /*!< [31:16] STM8S Standard Peripheral Library main version V2.2.0*/
  173. #define __STM8S_STDPERIPH_VERSION_MAIN ((uint8_t)0x02) /*!< [31:24] main version */
  174. #define __STM8S_STDPERIPH_VERSION_SUB1 ((uint8_t)0x02) /*!< [23:16] sub1 version */
  175. #define __STM8S_STDPERIPH_VERSION_SUB2 ((uint8_t)0x00) /*!< [15:8] sub2 version */
  176. #define __STM8S_STDPERIPH_VERSION_RC ((uint8_t)0x00) /*!< [7:0] release candidate */
  177. #define __STM8S_STDPERIPH_VERSION ( (__STM8S_STDPERIPH_VERSION_MAIN << 24)\
  178. |(__STM8S_STDPERIPH_VERSION_SUB1 << 16)\
  179. |(__STM8S_STDPERIPH_VERSION_SUB2 << 8)\
  180. |(__STM8S_STDPERIPH_VERSION_RC))
  181. /******************************************************************************/
  182. /* Includes ------------------------------------------------------------------*/
  183. /* Exported types and constants ----------------------------------------------*/
  184. /** @addtogroup Exported_types
  185. * @{
  186. */
  187. /**
  188. * IO definitions
  189. *
  190. * define access restrictions to peripheral registers
  191. */
  192. #define __I volatile const /*!< defines 'read only' permissions */
  193. #define __O volatile /*!< defines 'write only' permissions */
  194. #define __IO volatile /*!< defines 'read / write' permissions */
  195. /*!< Signed integer types */
  196. typedef signed char int8_t;
  197. typedef signed short int16_t;
  198. typedef signed long int32_t;
  199. /*!< Unsigned integer types */
  200. typedef unsigned char uint8_t;
  201. typedef unsigned short uint16_t;
  202. typedef unsigned long uint32_t;
  203. /*!< STM8 Standard Peripheral Library old types (maintained for legacy purpose) */
  204. typedef int32_t s32;
  205. typedef int16_t s16;
  206. typedef int8_t s8;
  207. typedef uint32_t u32;
  208. typedef uint16_t u16;
  209. typedef uint8_t u8;
  210. typedef enum {
  211. FALSE = 0, TRUE = !FALSE
  212. } bool;
  213. //#include <stdbool.h>
  214. //#define TRUE true
  215. //#define FALSE false
  216. typedef enum {
  217. RESET = 0, SET = !RESET
  218. } FlagStatus, ITStatus, BitStatus, BitAction;
  219. typedef enum {
  220. DISABLE = 0, ENABLE = !DISABLE
  221. } FunctionalState;
  222. #define IS_FUNCTIONALSTATE_OK(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
  223. typedef enum {
  224. ERROR = 0, SUCCESS = !ERROR
  225. } ErrorStatus;
  226. #define U8_MAX (255)
  227. #define S8_MAX (127)
  228. #define S8_MIN (-128)
  229. #define U16_MAX (65535u)
  230. #define S16_MAX (32767)
  231. #define S16_MIN (-32768)
  232. #define U32_MAX (4294967295uL)
  233. #define S32_MAX (2147483647)
  234. #define S32_MIN (-2147483648uL)
  235. #ifdef USE_FULL_ASSERT
  236. /**
  237. * @brief The assert_param macro is used for function's parameters check.
  238. * @param expr: If expr is false, it calls assert_failed function
  239. * which reports the name of the source file and the source
  240. * line number of the call that failed.
  241. * If expr is true, it returns no value.
  242. * @retval : None
  243. */
  244. #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
  245. /* Exported functions ------------------------------------------------------- */
  246. void assert_failed(uint8_t *file, uint32_t line);
  247. #else
  248. #define assert_param(expr) ((void)0)
  249. #endif /* USE_FULL_ASSERT */
  250. /**
  251. * @}
  252. */
  253. /** @addtogroup MAP_FILE_Exported_Types_and_Constants
  254. * @{
  255. */
  256. /******************************************************************************/
  257. /* IP registers structures */
  258. /******************************************************************************/
  259. /**
  260. * @brief General Purpose I/Os (GPIO)
  261. */
  262. typedef struct GPIO_struct {
  263. __IO uint8_t ODR; /*!< Output Data Register */
  264. __IO uint8_t IDR; /*!< Input Data Register */
  265. __IO uint8_t DDR; /*!< Data Direction Register */
  266. __IO uint8_t CR1; /*!< Configuration Register 1 */
  267. __IO uint8_t CR2; /*!< Configuration Register 2 */
  268. }
  269. GPIO_TypeDef;
  270. /** @addtogroup GPIO_Registers_Reset_Value
  271. * @{
  272. */
  273. #define GPIO_ODR_RESET_VALUE ((uint8_t)0x00)
  274. #define GPIO_DDR_RESET_VALUE ((uint8_t)0x00)
  275. #define GPIO_CR1_RESET_VALUE ((uint8_t)0x00)
  276. #define GPIO_CR2_RESET_VALUE ((uint8_t)0x00)
  277. /**
  278. * @}
  279. */
  280. /*----------------------------------------------------------------------------*/
  281. #if defined(STM8S105) || defined(STM8S005) || defined(STM8S103) || defined(STM8S003) || \
  282. defined(STM8S903) || defined(STM8AF626x) || defined(STM8AF622x)
  283. /**
  284. * @brief Analog to Digital Converter (ADC1)
  285. */
  286. typedef struct ADC1_struct {
  287. __IO uint8_t DB0RH; /*!< ADC1 Data Buffer Register (MSB) */
  288. __IO uint8_t DB0RL; /*!< ADC1 Data Buffer Register (LSB) */
  289. __IO uint8_t DB1RH; /*!< ADC1 Data Buffer Register (MSB) */
  290. __IO uint8_t DB1RL; /*!< ADC1 Data Buffer Register (LSB) */
  291. __IO uint8_t DB2RH; /*!< ADC1 Data Buffer Register (MSB) */
  292. __IO uint8_t DB2RL; /*!< ADC1 Data Buffer Register (LSB) */
  293. __IO uint8_t DB3RH; /*!< ADC1 Data Buffer Register (MSB) */
  294. __IO uint8_t DB3RL; /*!< ADC1 Data Buffer Register (LSB) */
  295. __IO uint8_t DB4RH; /*!< ADC1 Data Buffer Register (MSB) */
  296. __IO uint8_t DB4RL; /*!< ADC1 Data Buffer Register (LSB) */
  297. __IO uint8_t DB5RH; /*!< ADC1 Data Buffer Register (MSB) */
  298. __IO uint8_t DB5RL; /*!< ADC1 Data Buffer Register (LSB) */
  299. __IO uint8_t DB6RH; /*!< ADC1 Data Buffer Register (MSB) */
  300. __IO uint8_t DB6RL; /*!< ADC1 Data Buffer Register (LSB) */
  301. __IO uint8_t DB7RH; /*!< ADC1 Data Buffer Register (MSB) */
  302. __IO uint8_t DB7RL; /*!< ADC1 Data Buffer Register (LSB) */
  303. __IO uint8_t DB8RH; /*!< ADC1 Data Buffer Register (MSB) */
  304. __IO uint8_t DB8RL; /*!< ADC1 Data Buffer Register (LSB) */
  305. __IO uint8_t DB9RH; /*!< ADC1 Data Buffer Register (MSB) */
  306. __IO uint8_t DB9RL; /*!< ADC1 Data Buffer Register (LSB) */
  307. uint8_t RESERVED[12]; /*!< Reserved byte */
  308. __IO uint8_t CSR; /*!< ADC1 control status register */
  309. __IO uint8_t CR1; /*!< ADC1 configuration register 1 */
  310. __IO uint8_t CR2; /*!< ADC1 configuration register 2 */
  311. __IO uint8_t CR3; /*!< ADC1 configuration register 3 */
  312. __IO uint8_t DRH; /*!< ADC1 Data high */
  313. __IO uint8_t DRL; /*!< ADC1 Data low */
  314. __IO uint8_t TDRH; /*!< ADC1 Schmitt trigger disable register high */
  315. __IO uint8_t TDRL; /*!< ADC1 Schmitt trigger disable register low */
  316. __IO uint8_t HTRH; /*!< ADC1 high threshold register High*/
  317. __IO uint8_t HTRL; /*!< ADC1 high threshold register Low*/
  318. __IO uint8_t LTRH; /*!< ADC1 low threshold register high */
  319. __IO uint8_t LTRL; /*!< ADC1 low threshold register low */
  320. __IO uint8_t AWSRH; /*!< ADC1 watchdog status register high */
  321. __IO uint8_t AWSRL; /*!< ADC1 watchdog status register low */
  322. __IO uint8_t AWCRH; /*!< ADC1 watchdog control register high */
  323. __IO uint8_t AWCRL; /*!< ADC1 watchdog control register low */
  324. }
  325. ADC1_TypeDef;
  326. /** @addtogroup ADC1_Registers_Reset_Value
  327. * @{
  328. */
  329. #define ADC1_CSR_RESET_VALUE ((uint8_t)0x00)
  330. #define ADC1_CR1_RESET_VALUE ((uint8_t)0x00)
  331. #define ADC1_CR2_RESET_VALUE ((uint8_t)0x00)
  332. #define ADC1_CR3_RESET_VALUE ((uint8_t)0x00)
  333. #define ADC1_TDRL_RESET_VALUE ((uint8_t)0x00)
  334. #define ADC1_TDRH_RESET_VALUE ((uint8_t)0x00)
  335. #define ADC1_HTRL_RESET_VALUE ((uint8_t)0x03)
  336. #define ADC1_HTRH_RESET_VALUE ((uint8_t)0xFF)
  337. #define ADC1_LTRH_RESET_VALUE ((uint8_t)0x00)
  338. #define ADC1_LTRL_RESET_VALUE ((uint8_t)0x00)
  339. #define ADC1_AWCRH_RESET_VALUE ((uint8_t)0x00)
  340. #define ADC1_AWCRL_RESET_VALUE ((uint8_t)0x00)
  341. /**
  342. * @}
  343. */
  344. /** @addtogroup ADC1_Registers_Bits_Definition
  345. * @{
  346. */
  347. #define ADC1_CSR_EOC ((uint8_t)0x80) /*!< End of Conversion mask */
  348. #define ADC1_CSR_AWD ((uint8_t)0x40) /*!< Analog Watch Dog Status mask */
  349. #define ADC1_CSR_EOCIE ((uint8_t)0x20) /*!< Interrupt Enable for EOC mask */
  350. #define ADC1_CSR_AWDIE ((uint8_t)0x10) /*!< Analog Watchdog interrupt enable mask */
  351. #define ADC1_CSR_CH ((uint8_t)0x0F) /*!< Channel selection bits mask */
  352. #define ADC1_CR1_SPSEL ((uint8_t)0x70) /*!< Prescaler selection mask */
  353. #define ADC1_CR1_CONT ((uint8_t)0x02) /*!< Continuous conversion mask */
  354. #define ADC1_CR1_ADON ((uint8_t)0x01) /*!< A/D Converter on/off mask */
  355. #define ADC1_CR2_EXTTRIG ((uint8_t)0x40) /*!< External trigger enable mask */
  356. #define ADC1_CR2_EXTSEL ((uint8_t)0x30) /*!< External event selection mask */
  357. #define ADC1_CR2_ALIGN ((uint8_t)0x08) /*!< Data Alignment mask */
  358. #define ADC1_CR2_SCAN ((uint8_t)0x02) /*!< Scan mode mask */
  359. #define ADC1_CR3_DBUF ((uint8_t)0x80) /*!< Data Buffer Enable mask */
  360. #define ADC1_CR3_OVR ((uint8_t)0x40) /*!< Overrun Status Flag mask */
  361. #endif /* (STM8S105) ||(STM8S103) || (STM8S005) ||(STM8S003) || (STM8S903) || (STM8AF626x) || (STM8AF622x) */
  362. /**
  363. * @}
  364. */
  365. /*----------------------------------------------------------------------------*/
  366. /**
  367. * @brief Analog to Digital Converter (ADC2)
  368. */
  369. #if defined(STM8S208) || defined(STM8S207) || defined (STM8S007) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
  370. typedef struct ADC2_struct
  371. {
  372. __IO uint8_t CSR; /*!< ADC2 control status register */
  373. __IO uint8_t CR1; /*!< ADC2 configuration register 1 */
  374. __IO uint8_t CR2; /*!< ADC2 configuration register 2 */
  375. uint8_t RESERVED; /*!< Reserved byte */
  376. __IO uint8_t DRH; /*!< ADC2 Data high */
  377. __IO uint8_t DRL; /*!< ADC2 Data low */
  378. __IO uint8_t TDRH; /*!< ADC2 Schmitt trigger disable register high */
  379. __IO uint8_t TDRL; /*!< ADC2 Schmitt trigger disable register low */
  380. }
  381. ADC2_TypeDef;
  382. /** @addtogroup ADC2_Registers_Reset_Value
  383. * @{
  384. */
  385. #define ADC2_CSR_RESET_VALUE ((uint8_t)0x00)
  386. #define ADC2_CR1_RESET_VALUE ((uint8_t)0x00)
  387. #define ADC2_CR2_RESET_VALUE ((uint8_t)0x00)
  388. #define ADC2_TDRL_RESET_VALUE ((uint8_t)0x00)
  389. #define ADC2_TDRH_RESET_VALUE ((uint8_t)0x00)
  390. /**
  391. * @}
  392. */
  393. /** @addtogroup ADC2_Registers_Bits_Definition
  394. * @{
  395. */
  396. #define ADC2_CSR_EOC ((uint8_t)0x80) /*!< End of Conversion mask */
  397. #define ADC2_CSR_EOCIE ((uint8_t)0x20) /*!< Interrupt Enable for EOC mask */
  398. #define ADC2_CSR_CH ((uint8_t)0x0F) /*!< Channel selection bits mask */
  399. #define ADC2_CR1_SPSEL ((uint8_t)0x70) /*!< Prescaler selection mask */
  400. #define ADC2_CR1_CONT ((uint8_t)0x02) /*!< Continuous conversion mask */
  401. #define ADC2_CR1_ADON ((uint8_t)0x01) /*!< A/D Converter on/off mask */
  402. #define ADC2_CR2_EXTTRIG ((uint8_t)0x40) /*!< External trigger enable mask */
  403. #define ADC2_CR2_EXTSEL ((uint8_t)0x30) /*!< External event selection mask */
  404. #define ADC2_CR2_ALIGN ((uint8_t)0x08) /*!< Data Alignment mask */
  405. #endif /* (STM8S208) ||(STM8S207) || defined (STM8S007) || (STM8AF62Ax) || (STM8AF52Ax) */
  406. /**
  407. * @}
  408. */
  409. /*----------------------------------------------------------------------------*/
  410. /**
  411. * @brief Auto Wake Up (AWU) peripheral registers.
  412. */
  413. typedef struct AWU_struct {
  414. __IO uint8_t CSR; /*!< AWU Control status register */
  415. __IO uint8_t APR; /*!< AWU Asynchronous prescaler buffer */
  416. __IO uint8_t TBR; /*!< AWU Time base selection register */
  417. }
  418. AWU_TypeDef;
  419. /** @addtogroup AWU_Registers_Reset_Value
  420. * @{
  421. */
  422. #define AWU_CSR_RESET_VALUE ((uint8_t)0x00)
  423. #define AWU_APR_RESET_VALUE ((uint8_t)0x3F)
  424. #define AWU_TBR_RESET_VALUE ((uint8_t)0x00)
  425. /**
  426. * @}
  427. */
  428. /** @addtogroup AWU_Registers_Bits_Definition
  429. * @{
  430. */
  431. #define AWU_CSR_AWUF ((uint8_t)0x20) /*!< Interrupt flag mask */
  432. #define AWU_CSR_AWUEN ((uint8_t)0x10) /*!< Auto Wake-up enable mask */
  433. #define AWU_CSR_MSR ((uint8_t)0x01) /*!< LSI Measurement enable mask */
  434. #define AWU_APR_APR ((uint8_t)0x3F) /*!< Asynchronous Prescaler divider mask */
  435. #define AWU_TBR_AWUTB ((uint8_t)0x0F) /*!< Timebase selection mask */
  436. /**
  437. * @}
  438. */
  439. /*----------------------------------------------------------------------------*/
  440. /**
  441. * @brief Beeper (BEEP) peripheral registers.
  442. */
  443. typedef struct BEEP_struct {
  444. __IO uint8_t CSR; /*!< BEEP Control status register */
  445. }
  446. BEEP_TypeDef;
  447. /** @addtogroup BEEP_Registers_Reset_Value
  448. * @{
  449. */
  450. #define BEEP_CSR_RESET_VALUE ((uint8_t)0x1F)
  451. /**
  452. * @}
  453. */
  454. /** @addtogroup BEEP_Registers_Bits_Definition
  455. * @{
  456. */
  457. #define BEEP_CSR_BEEPSEL ((uint8_t)0xC0) /*!< Beeper frequency selection mask */
  458. #define BEEP_CSR_BEEPEN ((uint8_t)0x20) /*!< Beeper enable mask */
  459. #define BEEP_CSR_BEEPDIV ((uint8_t)0x1F) /*!< Beeper Divider prescalar mask */
  460. /**
  461. * @}
  462. */
  463. /*----------------------------------------------------------------------------*/
  464. /**
  465. * @brief Clock Controller (CLK)
  466. */
  467. typedef struct CLK_struct {
  468. __IO uint8_t ICKR; /*!< Internal Clocks Control Register */
  469. __IO uint8_t ECKR; /*!< External Clocks Control Register */
  470. uint8_t RESERVED; /*!< Reserved byte */
  471. __IO uint8_t CMSR; /*!< Clock Master Status Register */
  472. __IO uint8_t SWR; /*!< Clock Master Switch Register */
  473. __IO uint8_t SWCR; /*!< Switch Control Register */
  474. __IO uint8_t CKDIVR; /*!< Clock Divider Register */
  475. __IO uint8_t PCKENR1; /*!< Peripheral Clock Gating Register 1 */
  476. __IO uint8_t CSSR; /*!< Clock Security System Register */
  477. __IO uint8_t CCOR; /*!< Configurable Clock Output Register */
  478. __IO uint8_t PCKENR2; /*!< Peripheral Clock Gating Register 2 */
  479. uint8_t RESERVED1; /*!< Reserved byte */
  480. __IO uint8_t HSITRIMR; /*!< HSI Calibration Trimmer Register */
  481. __IO uint8_t SWIMCCR; /*!< SWIM clock control register */
  482. } CLK_TypeDef;
  483. /** @addtogroup CLK_Registers_Reset_Value
  484. * @{
  485. */
  486. #define CLK_ICKR_RESET_VALUE ((uint8_t)0x01)
  487. #define CLK_ECKR_RESET_VALUE ((uint8_t)0x00)
  488. #define CLK_CMSR_RESET_VALUE ((uint8_t)0xE1)
  489. #define CLK_SWR_RESET_VALUE ((uint8_t)0xE1)
  490. #define CLK_SWCR_RESET_VALUE ((uint8_t)0x00)
  491. #define CLK_CKDIVR_RESET_VALUE ((uint8_t)0x18)
  492. #define CLK_PCKENR1_RESET_VALUE ((uint8_t)0xFF)
  493. #define CLK_PCKENR2_RESET_VALUE ((uint8_t)0xFF)
  494. #define CLK_CSSR_RESET_VALUE ((uint8_t)0x00)
  495. #define CLK_CCOR_RESET_VALUE ((uint8_t)0x00)
  496. #define CLK_HSITRIMR_RESET_VALUE ((uint8_t)0x00)
  497. #define CLK_SWIMCCR_RESET_VALUE ((uint8_t)0x00)
  498. /**
  499. * @}
  500. */
  501. /** @addtogroup CLK_Registers_Bits_Definition
  502. * @{
  503. */
  504. #define CLK_ICKR_SWUAH ((uint8_t)0x20) /*!< Slow Wake-up from Active Halt/Halt modes */
  505. #define CLK_ICKR_LSIRDY ((uint8_t)0x10) /*!< Low speed internal oscillator ready */
  506. #define CLK_ICKR_LSIEN ((uint8_t)0x08) /*!< Low speed internal RC oscillator enable */
  507. #define CLK_ICKR_FHWU ((uint8_t)0x04) /*!< Fast Wake-up from Active Halt/Halt mode */
  508. #define CLK_ICKR_HSIRDY ((uint8_t)0x02) /*!< High speed internal RC oscillator ready */
  509. #define CLK_ICKR_HSIEN ((uint8_t)0x01) /*!< High speed internal RC oscillator enable */
  510. #define CLK_ECKR_HSERDY ((uint8_t)0x02) /*!< High speed external crystal oscillator ready */
  511. #define CLK_ECKR_HSEEN ((uint8_t)0x01) /*!< High speed external crystal oscillator enable */
  512. #define CLK_CMSR_CKM ((uint8_t)0xFF) /*!< Clock master status bits */
  513. #define CLK_SWR_SWI ((uint8_t)0xFF) /*!< Clock master selection bits */
  514. #define CLK_SWCR_SWIF ((uint8_t)0x08) /*!< Clock switch interrupt flag */
  515. #define CLK_SWCR_SWIEN ((uint8_t)0x04) /*!< Clock switch interrupt enable */
  516. #define CLK_SWCR_SWEN ((uint8_t)0x02) /*!< Switch start/stop */
  517. #define CLK_SWCR_SWBSY ((uint8_t)0x01) /*!< Switch busy flag*/
  518. #define CLK_CKDIVR_HSIDIV ((uint8_t)0x18) /*!< High speed internal clock prescaler */
  519. #define CLK_CKDIVR_CPUDIV ((uint8_t)0x07) /*!< CPU clock prescaler */
  520. #define CLK_PCKENR1_TIM1 ((uint8_t)0x80) /*!< Timer 1 clock enable */
  521. #define CLK_PCKENR1_TIM3 ((uint8_t)0x40) /*!< Timer 3 clock enable */
  522. #define CLK_PCKENR1_TIM2 ((uint8_t)0x20) /*!< Timer 2 clock enable */
  523. #define CLK_PCKENR1_TIM5 ((uint8_t)0x20) /*!< Timer 5 clock enable */
  524. #define CLK_PCKENR1_TIM4 ((uint8_t)0x10) /*!< Timer 4 clock enable */
  525. #define CLK_PCKENR1_TIM6 ((uint8_t)0x10) /*!< Timer 6 clock enable */
  526. #define CLK_PCKENR1_UART3 ((uint8_t)0x08) /*!< UART3 clock enable */
  527. #define CLK_PCKENR1_UART2 ((uint8_t)0x08) /*!< UART2 clock enable */
  528. #define CLK_PCKENR1_UART1 ((uint8_t)0x04) /*!< UART1 clock enable */
  529. #define CLK_PCKENR1_SPI ((uint8_t)0x02) /*!< SPI clock enable */
  530. #define CLK_PCKENR1_I2C ((uint8_t)0x01) /*!< I2C clock enable */
  531. #define CLK_PCKENR2_CAN ((uint8_t)0x80) /*!< CAN clock enable */
  532. #define CLK_PCKENR2_ADC ((uint8_t)0x08) /*!< ADC clock enable */
  533. #define CLK_PCKENR2_AWU ((uint8_t)0x04) /*!< AWU clock enable */
  534. #define CLK_CSSR_CSSD ((uint8_t)0x08) /*!< Clock security system detection */
  535. #define CLK_CSSR_CSSDIE ((uint8_t)0x04) /*!< Clock security system detection interrupt enable */
  536. #define CLK_CSSR_AUX ((uint8_t)0x02) /*!< Auxiliary oscillator connected to master clock */
  537. #define CLK_CSSR_CSSEN ((uint8_t)0x01) /*!< Clock security system enable */
  538. #define CLK_CCOR_CCOBSY ((uint8_t)0x40) /*!< Configurable clock output busy */
  539. #define CLK_CCOR_CCORDY ((uint8_t)0x20) /*!< Configurable clock output ready */
  540. #define CLK_CCOR_CCOSEL ((uint8_t)0x1E) /*!< Configurable clock output selection */
  541. #define CLK_CCOR_CCOEN ((uint8_t)0x01) /*!< Configurable clock output enable */
  542. #define CLK_HSITRIMR_HSITRIM ((uint8_t)0x07) /*!< High speed internal oscillator trimmer */
  543. #define CLK_SWIMCCR_SWIMDIV ((uint8_t)0x01) /*!< SWIM Clock Dividing Factor */
  544. /**
  545. * @}
  546. */
  547. /*----------------------------------------------------------------------------*/
  548. /**
  549. * @brief 16-bit timer with complementary PWM outputs (TIM1)
  550. */
  551. typedef struct TIM1_struct {
  552. __IO uint8_t CR1; /*!< control register 1 */
  553. __IO uint8_t CR2; /*!< control register 2 */
  554. __IO uint8_t SMCR; /*!< Synchro mode control register */
  555. __IO uint8_t ETR; /*!< external trigger register */
  556. __IO uint8_t IER; /*!< interrupt enable register*/
  557. __IO uint8_t SR1; /*!< status register 1 */
  558. __IO uint8_t SR2; /*!< status register 2 */
  559. __IO uint8_t EGR; /*!< event generation register */
  560. __IO uint8_t CCMR1; /*!< CC mode register 1 */
  561. __IO uint8_t CCMR2; /*!< CC mode register 2 */
  562. __IO uint8_t CCMR3; /*!< CC mode register 3 */
  563. __IO uint8_t CCMR4; /*!< CC mode register 4 */
  564. __IO uint8_t CCER1; /*!< CC enable register 1 */
  565. __IO uint8_t CCER2; /*!< CC enable register 2 */
  566. __IO uint8_t CNTRH; /*!< counter high */
  567. __IO uint8_t CNTRL; /*!< counter low */
  568. __IO uint8_t PSCRH; /*!< prescaler high */
  569. __IO uint8_t PSCRL; /*!< prescaler low */
  570. __IO uint8_t ARRH; /*!< auto-reload register high */
  571. __IO uint8_t ARRL; /*!< auto-reload register low */
  572. __IO uint8_t RCR; /*!< Repetition Counter register */
  573. __IO uint8_t CCR1H; /*!< capture/compare register 1 high */
  574. __IO uint8_t CCR1L; /*!< capture/compare register 1 low */
  575. __IO uint8_t CCR2H; /*!< capture/compare register 2 high */
  576. __IO uint8_t CCR2L; /*!< capture/compare register 2 low */
  577. __IO uint8_t CCR3H; /*!< capture/compare register 3 high */
  578. __IO uint8_t CCR3L; /*!< capture/compare register 3 low */
  579. __IO uint8_t CCR4H; /*!< capture/compare register 3 high */
  580. __IO uint8_t CCR4L; /*!< capture/compare register 3 low */
  581. __IO uint8_t BKR; /*!< Break Register */
  582. __IO uint8_t DTR; /*!< dead-time register */
  583. __IO uint8_t OISR; /*!< Output idle register */
  584. }
  585. TIM1_TypeDef;
  586. /** @addtogroup TIM1_Registers_Reset_Value
  587. * @{
  588. */
  589. #define TIM1_CR1_RESET_VALUE ((uint8_t)0x00)
  590. #define TIM1_CR2_RESET_VALUE ((uint8_t)0x00)
  591. #define TIM1_SMCR_RESET_VALUE ((uint8_t)0x00)
  592. #define TIM1_ETR_RESET_VALUE ((uint8_t)0x00)
  593. #define TIM1_IER_RESET_VALUE ((uint8_t)0x00)
  594. #define TIM1_SR1_RESET_VALUE ((uint8_t)0x00)
  595. #define TIM1_SR2_RESET_VALUE ((uint8_t)0x00)
  596. #define TIM1_EGR_RESET_VALUE ((uint8_t)0x00)
  597. #define TIM1_CCMR1_RESET_VALUE ((uint8_t)0x00)
  598. #define TIM1_CCMR2_RESET_VALUE ((uint8_t)0x00)
  599. #define TIM1_CCMR3_RESET_VALUE ((uint8_t)0x00)
  600. #define TIM1_CCMR4_RESET_VALUE ((uint8_t)0x00)
  601. #define TIM1_CCER1_RESET_VALUE ((uint8_t)0x00)
  602. #define TIM1_CCER2_RESET_VALUE ((uint8_t)0x00)
  603. #define TIM1_CNTRH_RESET_VALUE ((uint8_t)0x00)
  604. #define TIM1_CNTRL_RESET_VALUE ((uint8_t)0x00)
  605. #define TIM1_PSCRH_RESET_VALUE ((uint8_t)0x00)
  606. #define TIM1_PSCRL_RESET_VALUE ((uint8_t)0x00)
  607. #define TIM1_ARRH_RESET_VALUE ((uint8_t)0xFF)
  608. #define TIM1_ARRL_RESET_VALUE ((uint8_t)0xFF)
  609. #define TIM1_RCR_RESET_VALUE ((uint8_t)0x00)
  610. #define TIM1_CCR1H_RESET_VALUE ((uint8_t)0x00)
  611. #define TIM1_CCR1L_RESET_VALUE ((uint8_t)0x00)
  612. #define TIM1_CCR2H_RESET_VALUE ((uint8_t)0x00)
  613. #define TIM1_CCR2L_RESET_VALUE ((uint8_t)0x00)
  614. #define TIM1_CCR3H_RESET_VALUE ((uint8_t)0x00)
  615. #define TIM1_CCR3L_RESET_VALUE ((uint8_t)0x00)
  616. #define TIM1_CCR4H_RESET_VALUE ((uint8_t)0x00)
  617. #define TIM1_CCR4L_RESET_VALUE ((uint8_t)0x00)
  618. #define TIM1_BKR_RESET_VALUE ((uint8_t)0x00)
  619. #define TIM1_DTR_RESET_VALUE ((uint8_t)0x00)
  620. #define TIM1_OISR_RESET_VALUE ((uint8_t)0x00)
  621. /**
  622. * @}
  623. */
  624. /** @addtogroup TIM1_Registers_Bits_Definition
  625. * @{
  626. */
  627. /* CR1*/
  628. #define TIM1_CR1_ARPE ((uint8_t)0x80) /*!< Auto-Reload Preload Enable mask. */
  629. #define TIM1_CR1_CMS ((uint8_t)0x60) /*!< Center-aligned Mode Selection mask. */
  630. #define TIM1_CR1_DIR ((uint8_t)0x10) /*!< Direction mask. */
  631. #define TIM1_CR1_OPM ((uint8_t)0x08) /*!< One Pulse Mode mask. */
  632. #define TIM1_CR1_URS ((uint8_t)0x04) /*!< Update Request Source mask. */
  633. #define TIM1_CR1_UDIS ((uint8_t)0x02) /*!< Update DIsable mask. */
  634. #define TIM1_CR1_CEN ((uint8_t)0x01) /*!< Counter Enable mask. */
  635. /* CR2*/
  636. #define TIM1_CR2_TI1S ((uint8_t)0x80) /*!< TI1S Selection mask. */
  637. #define TIM1_CR2_MMS ((uint8_t)0x70) /*!< MMS Selection mask. */
  638. #define TIM1_CR2_COMS ((uint8_t)0x04) /*!< Capture/Compare Control Update Selection mask. */
  639. #define TIM1_CR2_CCPC ((uint8_t)0x01) /*!< Capture/Compare Preloaded Control mask. */
  640. /* SMCR*/
  641. #define TIM1_SMCR_MSM ((uint8_t)0x80) /*!< Master/Slave Mode mask. */
  642. #define TIM1_SMCR_TS ((uint8_t)0x70) /*!< Trigger Selection mask. */
  643. #define TIM1_SMCR_SMS ((uint8_t)0x07) /*!< Slave Mode Selection mask. */
  644. /*ETR*/
  645. #define TIM1_ETR_ETP ((uint8_t)0x80) /*!< External Trigger Polarity mask. */
  646. #define TIM1_ETR_ECE ((uint8_t)0x40)/*!< External Clock mask. */
  647. #define TIM1_ETR_ETPS ((uint8_t)0x30) /*!< External Trigger Prescaler mask. */
  648. #define TIM1_ETR_ETF ((uint8_t)0x0F) /*!< External Trigger Filter mask. */
  649. /*IER*/
  650. #define TIM1_IER_BIE ((uint8_t)0x80) /*!< Break Interrupt Enable mask. */
  651. #define TIM1_IER_TIE ((uint8_t)0x40) /*!< Trigger Interrupt Enable mask. */
  652. #define TIM1_IER_COMIE ((uint8_t)0x20) /*!< Commutation Interrupt Enable mask.*/
  653. #define TIM1_IER_CC4IE ((uint8_t)0x10) /*!< Capture/Compare 4 Interrupt Enable mask. */
  654. #define TIM1_IER_CC3IE ((uint8_t)0x08) /*!< Capture/Compare 3 Interrupt Enable mask. */
  655. #define TIM1_IER_CC2IE ((uint8_t)0x04) /*!< Capture/Compare 2 Interrupt Enable mask. */
  656. #define TIM1_IER_CC1IE ((uint8_t)0x02) /*!< Capture/Compare 1 Interrupt Enable mask. */
  657. #define TIM1_IER_UIE ((uint8_t)0x01) /*!< Update Interrupt Enable mask. */
  658. /*SR1*/
  659. #define TIM1_SR1_BIF ((uint8_t)0x80) /*!< Break Interrupt Flag mask. */
  660. #define TIM1_SR1_TIF ((uint8_t)0x40) /*!< Trigger Interrupt Flag mask. */
  661. #define TIM1_SR1_COMIF ((uint8_t)0x20) /*!< Commutation Interrupt Flag mask. */
  662. #define TIM1_SR1_CC4IF ((uint8_t)0x10) /*!< Capture/Compare 4 Interrupt Flag mask. */
  663. #define TIM1_SR1_CC3IF ((uint8_t)0x08) /*!< Capture/Compare 3 Interrupt Flag mask. */
  664. #define TIM1_SR1_CC2IF ((uint8_t)0x04) /*!< Capture/Compare 2 Interrupt Flag mask. */
  665. #define TIM1_SR1_CC1IF ((uint8_t)0x02) /*!< Capture/Compare 1 Interrupt Flag mask. */
  666. #define TIM1_SR1_UIF ((uint8_t)0x01) /*!< Update Interrupt Flag mask. */
  667. /*SR2*/
  668. #define TIM1_SR2_CC4OF ((uint8_t)0x10) /*!< Capture/Compare 4 Overcapture Flag mask. */
  669. #define TIM1_SR2_CC3OF ((uint8_t)0x08) /*!< Capture/Compare 3 Overcapture Flag mask. */
  670. #define TIM1_SR2_CC2OF ((uint8_t)0x04) /*!< Capture/Compare 2 Overcapture Flag mask. */
  671. #define TIM1_SR2_CC1OF ((uint8_t)0x02) /*!< Capture/Compare 1 Overcapture Flag mask. */
  672. /*EGR*/
  673. #define TIM1_EGR_BG ((uint8_t)0x80) /*!< Break Generation mask. */
  674. #define TIM1_EGR_TG ((uint8_t)0x40) /*!< Trigger Generation mask. */
  675. #define TIM1_EGR_COMG ((uint8_t)0x20) /*!< Capture/Compare Control Update Generation mask. */
  676. #define TIM1_EGR_CC4G ((uint8_t)0x10) /*!< Capture/Compare 4 Generation mask. */
  677. #define TIM1_EGR_CC3G ((uint8_t)0x08) /*!< Capture/Compare 3 Generation mask. */
  678. #define TIM1_EGR_CC2G ((uint8_t)0x04) /*!< Capture/Compare 2 Generation mask. */
  679. #define TIM1_EGR_CC1G ((uint8_t)0x02) /*!< Capture/Compare 1 Generation mask. */
  680. #define TIM1_EGR_UG ((uint8_t)0x01) /*!< Update Generation mask. */
  681. /*CCMR*/
  682. #define TIM1_CCMR_ICxPSC ((uint8_t)0x0C) /*!< Input Capture x Prescaler mask. */
  683. #define TIM1_CCMR_ICxF ((uint8_t)0xF0) /*!< Input Capture x Filter mask. */
  684. #define TIM1_CCMR_OCM ((uint8_t)0x70) /*!< Output Compare x Mode mask. */
  685. #define TIM1_CCMR_OCxPE ((uint8_t)0x08) /*!< Output Compare x Preload Enable mask. */
  686. #define TIM1_CCMR_OCxFE ((uint8_t)0x04) /*!< Output Compare x Fast Enable mask. */
  687. #define TIM1_CCMR_CCxS ((uint8_t)0x03) /*!< Capture/Compare x Selection mask. */
  688. #define CCMR_TIxDirect_Set ((uint8_t)0x01)
  689. /*CCER1*/
  690. #define TIM1_CCER1_CC2NP ((uint8_t)0x80) /*!< Capture/Compare 2 Complementary output Polarity mask. */
  691. #define TIM1_CCER1_CC2NE ((uint8_t)0x40) /*!< Capture/Compare 2 Complementary output enable mask. */
  692. #define TIM1_CCER1_CC2P ((uint8_t)0x20) /*!< Capture/Compare 2 output Polarity mask. */
  693. #define TIM1_CCER1_CC2E ((uint8_t)0x10) /*!< Capture/Compare 2 output enable mask. */
  694. #define TIM1_CCER1_CC1NP ((uint8_t)0x08) /*!< Capture/Compare 1 Complementary output Polarity mask. */
  695. #define TIM1_CCER1_CC1NE ((uint8_t)0x04) /*!< Capture/Compare 1 Complementary output enable mask. */
  696. #define TIM1_CCER1_CC1P ((uint8_t)0x02) /*!< Capture/Compare 1 output Polarity mask. */
  697. #define TIM1_CCER1_CC1E ((uint8_t)0x01) /*!< Capture/Compare 1 output enable mask. */
  698. /*CCER2*/
  699. #define TIM1_CCER2_CC4P ((uint8_t)0x20) /*!< Capture/Compare 4 output Polarity mask. */
  700. #define TIM1_CCER2_CC4E ((uint8_t)0x10) /*!< Capture/Compare 4 output enable mask. */
  701. #define TIM1_CCER2_CC3NP ((uint8_t)0x08) /*!< Capture/Compare 3 Complementary output Polarity mask. */
  702. #define TIM1_CCER2_CC3NE ((uint8_t)0x04) /*!< Capture/Compare 3 Complementary output enable mask. */
  703. #define TIM1_CCER2_CC3P ((uint8_t)0x02) /*!< Capture/Compare 3 output Polarity mask. */
  704. #define TIM1_CCER2_CC3E ((uint8_t)0x01) /*!< Capture/Compare 3 output enable mask. */
  705. /*CNTRH*/
  706. #define TIM1_CNTRH_CNT ((uint8_t)0xFF) /*!< Counter Value (MSB) mask. */
  707. /*CNTRL*/
  708. #define TIM1_CNTRL_CNT ((uint8_t)0xFF) /*!< Counter Value (LSB) mask. */
  709. /*PSCH*/
  710. #define TIM1_PSCH_PSC ((uint8_t)0xFF) /*!< Prescaler Value (MSB) mask. */
  711. /*PSCL*/
  712. #define TIM1_PSCL_PSC ((uint8_t)0xFF) /*!< Prescaler Value (LSB) mask. */
  713. /*ARR*/
  714. #define TIM1_ARRH_ARR ((uint8_t)0xFF) /*!< Autoreload Value (MSB) mask. */
  715. #define TIM1_ARRL_ARR ((uint8_t)0xFF) /*!< Autoreload Value (LSB) mask. */
  716. /*RCR*/
  717. #define TIM1_RCR_REP ((uint8_t)0xFF) /*!< Repetition Counter Value mask. */
  718. /*CCR1*/
  719. #define TIM1_CCR1H_CCR1 ((uint8_t)0xFF) /*!< Capture/Compare 1 Value (MSB) mask. */
  720. #define TIM1_CCR1L_CCR1 ((uint8_t)0xFF) /*!< Capture/Compare 1 Value (LSB) mask. */
  721. /*CCR2*/
  722. #define TIM1_CCR2H_CCR2 ((uint8_t)0xFF) /*!< Capture/Compare 2 Value (MSB) mask. */
  723. #define TIM1_CCR2L_CCR2 ((uint8_t)0xFF) /*!< Capture/Compare 2 Value (LSB) mask. */
  724. /*CCR3*/
  725. #define TIM1_CCR3H_CCR3 ((uint8_t)0xFF) /*!< Capture/Compare 3 Value (MSB) mask. */
  726. #define TIM1_CCR3L_CCR3 ((uint8_t)0xFF) /*!< Capture/Compare 3 Value (LSB) mask. */
  727. /*CCR4*/
  728. #define TIM1_CCR4H_CCR4 ((uint8_t)0xFF) /*!< Capture/Compare 4 Value (MSB) mask. */
  729. #define TIM1_CCR4L_CCR4 ((uint8_t)0xFF) /*!< Capture/Compare 4 Value (LSB) mask. */
  730. /*BKR*/
  731. #define TIM1_BKR_MOE ((uint8_t)0x80) /*!< Main Output Enable mask. */
  732. #define TIM1_BKR_AOE ((uint8_t)0x40) /*!< Automatic Output Enable mask. */
  733. #define TIM1_BKR_BKP ((uint8_t)0x20) /*!< Break Polarity mask. */
  734. #define TIM1_BKR_BKE ((uint8_t)0x10) /*!< Break Enable mask. */
  735. #define TIM1_BKR_OSSR ((uint8_t)0x08) /*!< Off-State Selection for Run mode mask. */
  736. #define TIM1_BKR_OSSI ((uint8_t)0x04) /*!< Off-State Selection for Idle mode mask. */
  737. #define TIM1_BKR_LOCK ((uint8_t)0x03) /*!< Lock Configuration mask. */
  738. /*DTR*/
  739. #define TIM1_DTR_DTG ((uint8_t)0xFF) /*!< Dead-Time Generator set-up mask. */
  740. /*OISR*/
  741. #define TIM1_OISR_OIS4 ((uint8_t)0x40) /*!< Output Idle state 4 (OC4 output) mask. */
  742. #define TIM1_OISR_OIS3N ((uint8_t)0x20) /*!< Output Idle state 3 (OC3N output) mask. */
  743. #define TIM1_OISR_OIS3 ((uint8_t)0x10) /*!< Output Idle state 3 (OC3 output) mask. */
  744. #define TIM1_OISR_OIS2N ((uint8_t)0x08) /*!< Output Idle state 2 (OC2N output) mask. */
  745. #define TIM1_OISR_OIS2 ((uint8_t)0x04) /*!< Output Idle state 2 (OC2 output) mask. */
  746. #define TIM1_OISR_OIS1N ((uint8_t)0x02) /*!< Output Idle state 1 (OC1N output) mask. */
  747. #define TIM1_OISR_OIS1 ((uint8_t)0x01) /*!< Output Idle state 1 (OC1 output) mask. */
  748. /**
  749. * @}
  750. */
  751. /*----------------------------------------------------------------------------*/
  752. /**
  753. * @brief 16-bit timer (TIM2)
  754. */
  755. typedef struct TIM2_struct {
  756. __IO uint8_t CR1; /*!< control register 1 */
  757. #if defined(STM8S103) || defined(STM8S003)
  758. uint8_t RESERVED1; /*!< Reserved register */
  759. uint8_t RESERVED2; /*!< Reserved register */
  760. #endif
  761. __IO uint8_t IER; /*!< interrupt enable register */
  762. __IO uint8_t SR1; /*!< status register 1 */
  763. __IO uint8_t SR2; /*!< status register 2 */
  764. __IO uint8_t EGR; /*!< event generation register */
  765. __IO uint8_t CCMR1; /*!< CC mode register 1 */
  766. __IO uint8_t CCMR2; /*!< CC mode register 2 */
  767. __IO uint8_t CCMR3; /*!< CC mode register 3 */
  768. __IO uint8_t CCER1; /*!< CC enable register 1 */
  769. __IO uint8_t CCER2; /*!< CC enable register 2 */
  770. __IO uint8_t CNTRH; /*!< counter high */
  771. __IO uint8_t CNTRL; /*!< counter low */
  772. __IO uint8_t PSCR; /*!< prescaler register */
  773. __IO uint8_t ARRH; /*!< auto-reload register high */
  774. __IO uint8_t ARRL; /*!< auto-reload register low */
  775. __IO uint8_t CCR1H; /*!< capture/compare register 1 high */
  776. __IO uint8_t CCR1L; /*!< capture/compare register 1 low */
  777. __IO uint8_t CCR2H; /*!< capture/compare register 2 high */
  778. __IO uint8_t CCR2L; /*!< capture/compare register 2 low */
  779. __IO uint8_t CCR3H; /*!< capture/compare register 3 high */
  780. __IO uint8_t CCR3L; /*!< capture/compare register 3 low */
  781. }
  782. TIM2_TypeDef;
  783. /** @addtogroup TIM2_Registers_Reset_Value
  784. * @{
  785. */
  786. #define TIM2_CR1_RESET_VALUE ((uint8_t)0x00)
  787. #define TIM2_IER_RESET_VALUE ((uint8_t)0x00)
  788. #define TIM2_SR1_RESET_VALUE ((uint8_t)0x00)
  789. #define TIM2_SR2_RESET_VALUE ((uint8_t)0x00)
  790. #define TIM2_EGR_RESET_VALUE ((uint8_t)0x00)
  791. #define TIM2_CCMR1_RESET_VALUE ((uint8_t)0x00)
  792. #define TIM2_CCMR2_RESET_VALUE ((uint8_t)0x00)
  793. #define TIM2_CCMR3_RESET_VALUE ((uint8_t)0x00)
  794. #define TIM2_CCER1_RESET_VALUE ((uint8_t)0x00)
  795. #define TIM2_CCER2_RESET_VALUE ((uint8_t)0x00)
  796. #define TIM2_CNTRH_RESET_VALUE ((uint8_t)0x00)
  797. #define TIM2_CNTRL_RESET_VALUE ((uint8_t)0x00)
  798. #define TIM2_PSCR_RESET_VALUE ((uint8_t)0x00)
  799. #define TIM2_ARRH_RESET_VALUE ((uint8_t)0xFF)
  800. #define TIM2_ARRL_RESET_VALUE ((uint8_t)0xFF)
  801. #define TIM2_CCR1H_RESET_VALUE ((uint8_t)0x00)
  802. #define TIM2_CCR1L_RESET_VALUE ((uint8_t)0x00)
  803. #define TIM2_CCR2H_RESET_VALUE ((uint8_t)0x00)
  804. #define TIM2_CCR2L_RESET_VALUE ((uint8_t)0x00)
  805. #define TIM2_CCR3H_RESET_VALUE ((uint8_t)0x00)
  806. #define TIM2_CCR3L_RESET_VALUE ((uint8_t)0x00)
  807. /**
  808. * @}
  809. */
  810. /** @addtogroup TIM2_Registers_Bits_Definition
  811. * @{
  812. */
  813. /*CR1*/
  814. #define TIM2_CR1_ARPE ((uint8_t)0x80) /*!< Auto-Reload Preload Enable mask. */
  815. #define TIM2_CR1_OPM ((uint8_t)0x08) /*!< One Pulse Mode mask. */
  816. #define TIM2_CR1_URS ((uint8_t)0x04) /*!< Update Request Source mask. */
  817. #define TIM2_CR1_UDIS ((uint8_t)0x02) /*!< Update DIsable mask. */
  818. #define TIM2_CR1_CEN ((uint8_t)0x01) /*!< Counter Enable mask. */
  819. /*IER*/
  820. #define TIM2_IER_CC3IE ((uint8_t)0x08) /*!< Capture/Compare 3 Interrupt Enable mask. */
  821. #define TIM2_IER_CC2IE ((uint8_t)0x04) /*!< Capture/Compare 2 Interrupt Enable mask. */
  822. #define TIM2_IER_CC1IE ((uint8_t)0x02) /*!< Capture/Compare 1 Interrupt Enable mask. */
  823. #define TIM2_IER_UIE ((uint8_t)0x01) /*!< Update Interrupt Enable mask. */
  824. /*SR1*/
  825. #define TIM2_SR1_CC3IF ((uint8_t)0x08) /*!< Capture/Compare 3 Interrupt Flag mask. */
  826. #define TIM2_SR1_CC2IF ((uint8_t)0x04) /*!< Capture/Compare 2 Interrupt Flag mask. */
  827. #define TIM2_SR1_CC1IF ((uint8_t)0x02) /*!< Capture/Compare 1 Interrupt Flag mask. */
  828. #define TIM2_SR1_UIF ((uint8_t)0x01) /*!< Update Interrupt Flag mask. */
  829. /*SR2*/
  830. #define TIM2_SR2_CC3OF ((uint8_t)0x08) /*!< Capture/Compare 3 Overcapture Flag mask. */
  831. #define TIM2_SR2_CC2OF ((uint8_t)0x04) /*!< Capture/Compare 2 Overcapture Flag mask. */
  832. #define TIM2_SR2_CC1OF ((uint8_t)0x02) /*!< Capture/Compare 1 Overcapture Flag mask. */
  833. /*EGR*/
  834. #define TIM2_EGR_CC3G ((uint8_t)0x08) /*!< Capture/Compare 3 Generation mask. */
  835. #define TIM2_EGR_CC2G ((uint8_t)0x04) /*!< Capture/Compare 2 Generation mask. */
  836. #define TIM2_EGR_CC1G ((uint8_t)0x02) /*!< Capture/Compare 1 Generation mask. */
  837. #define TIM2_EGR_UG ((uint8_t)0x01) /*!< Update Generation mask. */
  838. /*CCMR*/
  839. #define TIM2_CCMR_ICxPSC ((uint8_t)0x0C) /*!< Input Capture x Prescaler mask. */
  840. #define TIM2_CCMR_ICxF ((uint8_t)0xF0) /*!< Input Capture x Filter mask. */
  841. #define TIM2_CCMR_OCM ((uint8_t)0x70) /*!< Output Compare x Mode mask. */
  842. #define TIM2_CCMR_OCxPE ((uint8_t)0x08) /*!< Output Compare x Preload Enable mask. */
  843. #define TIM2_CCMR_CCxS ((uint8_t)0x03) /*!< Capture/Compare x Selection mask. */
  844. /*CCER1*/
  845. #define TIM2_CCER1_CC2P ((uint8_t)0x20) /*!< Capture/Compare 2 output Polarity mask. */
  846. #define TIM2_CCER1_CC2E ((uint8_t)0x10) /*!< Capture/Compare 2 output enable mask. */
  847. #define TIM2_CCER1_CC1P ((uint8_t)0x02) /*!< Capture/Compare 1 output Polarity mask. */
  848. #define TIM2_CCER1_CC1E ((uint8_t)0x01) /*!< Capture/Compare 1 output enable mask. */
  849. /*CCER2*/
  850. #define TIM2_CCER2_CC3P ((uint8_t)0x02) /*!< Capture/Compare 3 output Polarity mask. */
  851. #define TIM2_CCER2_CC3E ((uint8_t)0x01) /*!< Capture/Compare 3 output enable mask. */
  852. /*CNTR*/
  853. #define TIM2_CNTRH_CNT ((uint8_t)0xFF) /*!< Counter Value (MSB) mask. */
  854. #define TIM2_CNTRL_CNT ((uint8_t)0xFF) /*!< Counter Value (LSB) mask. */
  855. /*PSCR*/
  856. #define TIM2_PSCR_PSC ((uint8_t)0xFF) /*!< Prescaler Value (MSB) mask. */
  857. /*ARR*/
  858. #define TIM2_ARRH_ARR ((uint8_t)0xFF) /*!< Autoreload Value (MSB) mask. */
  859. #define TIM2_ARRL_ARR ((uint8_t)0xFF) /*!< Autoreload Value (LSB) mask. */
  860. /*CCR1*/
  861. #define TIM2_CCR1H_CCR1 ((uint8_t)0xFF) /*!< Capture/Compare 1 Value (MSB) mask. */
  862. #define TIM2_CCR1L_CCR1 ((uint8_t)0xFF) /*!< Capture/Compare 1 Value (LSB) mask. */
  863. /*CCR2*/
  864. #define TIM2_CCR2H_CCR2 ((uint8_t)0xFF) /*!< Capture/Compare 2 Value (MSB) mask. */
  865. #define TIM2_CCR2L_CCR2 ((uint8_t)0xFF) /*!< Capture/Compare 2 Value (LSB) mask. */
  866. /*CCR3*/
  867. #define TIM2_CCR3H_CCR3 ((uint8_t)0xFF) /*!< Capture/Compare 3 Value (MSB) mask. */
  868. #define TIM2_CCR3L_CCR3 ((uint8_t)0xFF) /*!< Capture/Compare 3 Value (LSB) mask. */
  869. /**
  870. * @}
  871. */
  872. /*----------------------------------------------------------------------------*/
  873. /**
  874. * @brief 16-bit timer (TIM3)
  875. */
  876. typedef struct TIM3_struct {
  877. __IO uint8_t CR1; /*!< control register 1 */
  878. __IO uint8_t IER; /*!< interrupt enable register */
  879. __IO uint8_t SR1; /*!< status register 1 */
  880. __IO uint8_t SR2; /*!< status register 2 */
  881. __IO uint8_t EGR; /*!< event generation register */
  882. __IO uint8_t CCMR1; /*!< CC mode register 1 */
  883. __IO uint8_t CCMR2; /*!< CC mode register 2 */
  884. __IO uint8_t CCER1; /*!< CC enable register 1 */
  885. __IO uint8_t CNTRH; /*!< counter high */
  886. __IO uint8_t CNTRL; /*!< counter low */
  887. __IO uint8_t PSCR; /*!< prescaler register */
  888. __IO uint8_t ARRH; /*!< auto-reload register high */
  889. __IO uint8_t ARRL; /*!< auto-reload register low */
  890. __IO uint8_t CCR1H; /*!< capture/compare register 1 high */
  891. __IO uint8_t CCR1L; /*!< capture/compare register 1 low */
  892. __IO uint8_t CCR2H; /*!< capture/compare register 2 high */
  893. __IO uint8_t CCR2L; /*!< capture/compare register 2 low */
  894. }
  895. TIM3_TypeDef;
  896. /** @addtogroup TIM3_Registers_Reset_Value
  897. * @{
  898. */
  899. #define TIM3_CR1_RESET_VALUE ((uint8_t)0x00)
  900. #define TIM3_IER_RESET_VALUE ((uint8_t)0x00)
  901. #define TIM3_SR1_RESET_VALUE ((uint8_t)0x00)
  902. #define TIM3_SR2_RESET_VALUE ((uint8_t)0x00)
  903. #define TIM3_EGR_RESET_VALUE ((uint8_t)0x00)
  904. #define TIM3_CCMR1_RESET_VALUE ((uint8_t)0x00)
  905. #define TIM3_CCMR2_RESET_VALUE ((uint8_t)0x00)
  906. #define TIM3_CCER1_RESET_VALUE ((uint8_t)0x00)
  907. #define TIM3_CNTRH_RESET_VALUE ((uint8_t)0x00)
  908. #define TIM3_CNTRL_RESET_VALUE ((uint8_t)0x00)
  909. #define TIM3_PSCR_RESET_VALUE ((uint8_t)0x00)
  910. #define TIM3_ARRH_RESET_VALUE ((uint8_t)0xFF)
  911. #define TIM3_ARRL_RESET_VALUE ((uint8_t)0xFF)
  912. #define TIM3_CCR1H_RESET_VALUE ((uint8_t)0x00)
  913. #define TIM3_CCR1L_RESET_VALUE ((uint8_t)0x00)
  914. #define TIM3_CCR2H_RESET_VALUE ((uint8_t)0x00)
  915. #define TIM3_CCR2L_RESET_VALUE ((uint8_t)0x00)
  916. /**
  917. * @}
  918. */
  919. /** @addtogroup TIM3_Registers_Bits_Definition
  920. * @{
  921. */
  922. /*CR1*/
  923. #define TIM3_CR1_ARPE ((uint8_t)0x80) /*!< Auto-Reload Preload Enable mask. */
  924. #define TIM3_CR1_OPM ((uint8_t)0x08) /*!< One Pulse Mode mask. */
  925. #define TIM3_CR1_URS ((uint8_t)0x04) /*!< Update Request Source mask. */
  926. #define TIM3_CR1_UDIS ((uint8_t)0x02) /*!< Update DIsable mask. */
  927. #define TIM3_CR1_CEN ((uint8_t)0x01) /*!< Counter Enable mask. */
  928. /*IER*/
  929. #define TIM3_IER_CC2IE ((uint8_t)0x04) /*!< Capture/Compare 2 Interrupt Enable mask. */
  930. #define TIM3_IER_CC1IE ((uint8_t)0x02) /*!< Capture/Compare 1 Interrupt Enable mask. */
  931. #define TIM3_IER_UIE ((uint8_t)0x01) /*!< Update Interrupt Enable mask. */
  932. /*SR1*/
  933. #define TIM3_SR1_CC2IF ((uint8_t)0x04) /*!< Capture/Compare 2 Interrupt Flag mask. */
  934. #define TIM3_SR1_CC1IF ((uint8_t)0x02) /*!< Capture/Compare 1 Interrupt Flag mask. */
  935. #define TIM3_SR1_UIF ((uint8_t)0x01) /*!< Update Interrupt Flag mask. */
  936. /*SR2*/
  937. #define TIM3_SR2_CC2OF ((uint8_t)0x04) /*!< Capture/Compare 2 Overcapture Flag mask. */
  938. #define TIM3_SR2_CC1OF ((uint8_t)0x02) /*!< Capture/Compare 1 Overcapture Flag mask. */
  939. /*EGR*/
  940. #define TIM3_EGR_CC2G ((uint8_t)0x04) /*!< Capture/Compare 2 Generation mask. */
  941. #define TIM3_EGR_CC1G ((uint8_t)0x02) /*!< Capture/Compare 1 Generation mask. */
  942. #define TIM3_EGR_UG ((uint8_t)0x01) /*!< Update Generation mask. */
  943. /*CCMR*/
  944. #define TIM3_CCMR_ICxPSC ((uint8_t)0x0C) /*!< Input Capture x Prescaler mask. */
  945. #define TIM3_CCMR_ICxF ((uint8_t)0xF0) /*!< Input Capture x Filter mask. */
  946. #define TIM3_CCMR_OCM ((uint8_t)0x70) /*!< Output Compare x Mode mask. */
  947. #define TIM3_CCMR_OCxPE ((uint8_t)0x08) /*!< Output Compare x Preload Enable mask. */
  948. #define TIM3_CCMR_CCxS ((uint8_t)0x03) /*!< Capture/Compare x Selection mask. */
  949. /*CCER1*/
  950. #define TIM3_CCER1_CC2P ((uint8_t)0x20) /*!< Capture/Compare 2 output Polarity mask. */
  951. #define TIM3_CCER1_CC2E ((uint8_t)0x10) /*!< Capture/Compare 2 output enable mask. */
  952. #define TIM3_CCER1_CC1P ((uint8_t)0x02) /*!< Capture/Compare 1 output Polarity mask. */
  953. #define TIM3_CCER1_CC1E ((uint8_t)0x01) /*!< Capture/Compare 1 output enable mask. */
  954. /*CNTR*/
  955. #define TIM3_CNTRH_CNT ((uint8_t)0xFF) /*!< Counter Value (MSB) mask. */
  956. #define TIM3_CNTRL_CNT ((uint8_t)0xFF) /*!< Counter Value (LSB) mask. */
  957. /*PSCR*/
  958. #define TIM3_PSCR_PSC ((uint8_t)0xFF) /*!< Prescaler Value (MSB) mask. */
  959. /*ARR*/
  960. #define TIM3_ARRH_ARR ((uint8_t)0xFF) /*!< Autoreload Value (MSB) mask. */
  961. #define TIM3_ARRL_ARR ((uint8_t)0xFF) /*!< Autoreload Value (LSB) mask. */
  962. /*CCR1*/
  963. #define TIM3_CCR1H_CCR1 ((uint8_t)0xFF) /*!< Capture/Compare 1 Value (MSB) mask. */
  964. #define TIM3_CCR1L_CCR1 ((uint8_t)0xFF) /*!< Capture/Compare 1 Value (LSB) mask. */
  965. /*CCR2*/
  966. #define TIM3_CCR2H_CCR2 ((uint8_t)0xFF) /*!< Capture/Compare 2 Value (MSB) mask. */
  967. #define TIM3_CCR2L_CCR2 ((uint8_t)0xFF) /*!< Capture/Compare 2 Value (LSB) mask. */
  968. /**
  969. * @}
  970. */
  971. /*----------------------------------------------------------------------------*/
  972. /**
  973. * @brief 8-bit system timer (TIM4)
  974. */
  975. typedef struct TIM4_struct {
  976. __IO uint8_t CR1; /*!< control register 1 */
  977. #if defined(STM8S103) || defined(STM8S003)
  978. uint8_t RESERVED1; /*!< Reserved register */
  979. uint8_t RESERVED2; /*!< Reserved register */
  980. #endif
  981. __IO uint8_t IER; /*!< interrupt enable register */
  982. __IO uint8_t SR1; /*!< status register 1 */
  983. __IO uint8_t EGR; /*!< event generation register */
  984. __IO uint8_t CNTR; /*!< counter register */
  985. __IO uint8_t PSCR; /*!< prescaler register */
  986. __IO uint8_t ARR; /*!< auto-reload register */
  987. }
  988. TIM4_TypeDef;
  989. /** @addtogroup TIM4_Registers_Reset_Value
  990. * @{
  991. */
  992. #define TIM4_CR1_RESET_VALUE ((uint8_t)0x00)
  993. #define TIM4_IER_RESET_VALUE ((uint8_t)0x00)
  994. #define TIM4_SR1_RESET_VALUE ((uint8_t)0x00)
  995. #define TIM4_EGR_RESET_VALUE ((uint8_t)0x00)
  996. #define TIM4_CNTR_RESET_VALUE ((uint8_t)0x00)
  997. #define TIM4_PSCR_RESET_VALUE ((uint8_t)0x00)
  998. #define TIM4_ARR_RESET_VALUE ((uint8_t)0xFF)
  999. /**
  1000. * @}
  1001. */
  1002. /** @addtogroup TIM4_Registers_Bits_Definition
  1003. * @{
  1004. */
  1005. /*CR1*/
  1006. #define TIM4_CR1_ARPE ((uint8_t)0x80) /*!< Auto-Reload Preload Enable mask. */
  1007. #define TIM4_CR1_OPM ((uint8_t)0x08) /*!< One Pulse Mode mask. */
  1008. #define TIM4_CR1_URS ((uint8_t)0x04) /*!< Update Request Source mask. */
  1009. #define TIM4_CR1_UDIS ((uint8_t)0x02) /*!< Update DIsable mask. */
  1010. #define TIM4_CR1_CEN ((uint8_t)0x01) /*!< Counter Enable mask. */
  1011. /*IER*/
  1012. #define TIM4_IER_UIE ((uint8_t)0x01) /*!< Update Interrupt Enable mask. */
  1013. /*SR1*/
  1014. #define TIM4_SR1_UIF ((uint8_t)0x01) /*!< Update Interrupt Flag mask. */
  1015. /*EGR*/
  1016. #define TIM4_EGR_UG ((uint8_t)0x01) /*!< Update Generation mask. */
  1017. /*CNTR*/
  1018. #define TIM4_CNTR_CNT ((uint8_t)0xFF) /*!< Counter Value (LSB) mask. */
  1019. /*PSCR*/
  1020. #define TIM4_PSCR_PSC ((uint8_t)0x07) /*!< Prescaler Value mask. */
  1021. /*ARR*/
  1022. #define TIM4_ARR_ARR ((uint8_t)0xFF) /*!< Autoreload Value mask. */
  1023. /**
  1024. * @}
  1025. */
  1026. /*----------------------------------------------------------------------------*/
  1027. /**
  1028. * @brief 16-bit timer with synchro module (TIM5)
  1029. */
  1030. typedef struct TIM5_struct {
  1031. __IO uint8_t CR1; /*!<TIM5 Control Register 1 */
  1032. __IO uint8_t CR2; /*!<TIM5 Control Register 2 */
  1033. __IO uint8_t SMCR; /*!<TIM5 Slave Mode Control Register */
  1034. __IO uint8_t IER; /*!<TIM5 Interrupt Enable Register */
  1035. __IO uint8_t SR1; /*!<TIM5 Status Register 1 */
  1036. __IO uint8_t SR2; /*!<TIM5 Status Register 2 */
  1037. __IO uint8_t EGR; /*!<TIM5 Event Generation Register */
  1038. __IO uint8_t CCMR1; /*!<TIM5 Capture/Compare Mode Register 1 */
  1039. __IO uint8_t CCMR2; /*!<TIM5 Capture/Compare Mode Register 2 */
  1040. __IO uint8_t CCMR3; /*!<TIM5 Capture/Compare Mode Register 3 */
  1041. __IO uint8_t CCER1; /*!<TIM5 Capture/Compare Enable Register 1 */
  1042. __IO uint8_t CCER2; /*!<TIM5 Capture/Compare Enable Register 2 */
  1043. __IO uint8_t CNTRH; /*!<TIM5 Counter High */
  1044. __IO uint8_t CNTRL; /*!<TIM5 Counter Low */
  1045. __IO uint8_t PSCR; /*!<TIM5 Prescaler Register */
  1046. __IO uint8_t ARRH; /*!<TIM5 Auto-Reload Register High */
  1047. __IO uint8_t ARRL; /*!<TIM5 Auto-Reload Register Low */
  1048. __IO uint8_t CCR1H; /*!<TIM5 Capture/Compare Register 1 High */
  1049. __IO uint8_t CCR1L; /*!<TIM5 Capture/Compare Register 1 Low */
  1050. __IO uint8_t CCR2H; /*!<TIM5 Capture/Compare Register 2 High */
  1051. __IO uint8_t CCR2L; /*!<TIM5 Capture/Compare Register 2 Low */
  1052. __IO uint8_t CCR3H; /*!<TIM5 Capture/Compare Register 3 High */
  1053. __IO uint8_t CCR3L; /*!<TIM5 Capture/Compare Register 3 Low */
  1054. } TIM5_TypeDef;
  1055. /** @addtogroup TIM5_Registers_Reset_Value
  1056. * @{
  1057. */
  1058. #define TIM5_CR1_RESET_VALUE ((uint8_t)0x00)
  1059. #define TIM5_CR2_RESET_VALUE ((uint8_t)0x00)
  1060. #define TIM5_SMCR_RESET_VALUE ((uint8_t)0x00)
  1061. #define TIM5_IER_RESET_VALUE ((uint8_t)0x00)
  1062. #define TIM5_SR1_RESET_VALUE ((uint8_t)0x00)
  1063. #define TIM5_SR2_RESET_VALUE ((uint8_t)0x00)
  1064. #define TIM5_EGR_RESET_VALUE ((uint8_t)0x00)
  1065. #define TIM5_CCMR1_RESET_VALUE ((uint8_t)0x00)
  1066. #define TIM5_CCMR2_RESET_VALUE ((uint8_t)0x00)
  1067. #define TIM5_CCMR3_RESET_VALUE ((uint8_t)0x00)
  1068. #define TIM5_CCER1_RESET_VALUE ((uint8_t)0x00)
  1069. #define TIM5_CCER2_RESET_VALUE ((uint8_t)0x00)
  1070. #define TIM5_CNTRH_RESET_VALUE ((uint8_t)0x00)
  1071. #define TIM5_CNTRL_RESET_VALUE ((uint8_t)0x00)
  1072. #define TIM5_PSCR_RESET_VALUE ((uint8_t)0x00)
  1073. #define TIM5_ARRH_RESET_VALUE ((uint8_t)0xFF)
  1074. #define TIM5_ARRL_RESET_VALUE ((uint8_t)0xFF)
  1075. #define TIM5_CCR1H_RESET_VALUE ((uint8_t)0x00)
  1076. #define TIM5_CCR1L_RESET_VALUE ((uint8_t)0x00)
  1077. #define TIM5_CCR2H_RESET_VALUE ((uint8_t)0x00)
  1078. #define TIM5_CCR2L_RESET_VALUE ((uint8_t)0x00)
  1079. #define TIM5_CCR3H_RESET_VALUE ((uint8_t)0x00)
  1080. #define TIM5_CCR3L_RESET_VALUE ((uint8_t)0x00)
  1081. /**
  1082. * @}
  1083. */
  1084. /** @addtogroup TIM5_Registers_Bits_Definition
  1085. * @{
  1086. */
  1087. /* CR1*/
  1088. #define TIM5_CR1_ARPE ((uint8_t)0x80) /*!< Auto-Reload Preload Enable mask. */
  1089. #define TIM5_CR1_OPM ((uint8_t)0x08) /*!< One Pulse Mode mask. */
  1090. #define TIM5_CR1_URS ((uint8_t)0x04) /*!< Update Request Source mask. */
  1091. #define TIM5_CR1_UDIS ((uint8_t)0x02) /*!< Update DIsable mask. */
  1092. #define TIM5_CR1_CEN ((uint8_t)0x01) /*!< Counter Enable mask. */
  1093. /* CR2*/
  1094. #define TIM5_CR2_TI1S ((uint8_t)0x80) /*!< TI1S Selection Mask. */
  1095. #define TIM5_CR2_MMS ((uint8_t)0x70) /*!< MMS Selection Mask. */
  1096. /* SMCR*/
  1097. #define TIM5_SMCR_MSM ((uint8_t)0x80) /*!< Master/Slave Mode Mask. */
  1098. #define TIM5_SMCR_TS ((uint8_t)0x70) /*!< Trigger Selection Mask. */
  1099. #define TIM5_SMCR_SMS ((uint8_t)0x07) /*!< Slave Mode Selection Mask. */
  1100. /*IER*/
  1101. #define TIM5_IER_TIE ((uint8_t)0x40) /*!< Trigger Interrupt Enable mask. */
  1102. #define TIM5_IER_CC3IE ((uint8_t)0x08) /*!< Capture/Compare 3 Interrupt Enable mask. */
  1103. #define TIM5_IER_CC2IE ((uint8_t)0x04) /*!< Capture/Compare 2 Interrupt Enable mask. */
  1104. #define TIM5_IER_CC1IE ((uint8_t)0x02) /*!< Capture/Compare 1 Interrupt Enable mask. */
  1105. #define TIM5_IER_UIE ((uint8_t)0x01) /*!< Update Interrupt Enable mask. */
  1106. /*SR1*/
  1107. #define TIM5_SR1_TIF ((uint8_t)0x40) /*!< Trigger Interrupt Flag mask. */
  1108. #define TIM5_SR1_CC3IF ((uint8_t)0x08) /*!< Capture/Compare 3 Interrupt Flag mask. */
  1109. #define TIM5_SR1_CC2IF ((uint8_t)0x04) /*!< Capture/Compare 2 Interrupt Flag mask. */
  1110. #define TIM5_SR1_CC1IF ((uint8_t)0x02) /*!< Capture/Compare 1 Interrupt Flag mask. */
  1111. #define TIM5_SR1_UIF ((uint8_t)0x01) /*!< Update Interrupt Flag mask. */
  1112. /*SR2*/
  1113. #define TIM5_SR2_CC3OF ((uint8_t)0x08) /*!< Capture/Compare 3 Overcapture Flag mask. */
  1114. #define TIM5_SR2_CC2OF ((uint8_t)0x04) /*!< Capture/Compare 2 Overcapture Flag mask. */
  1115. #define TIM5_SR2_CC1OF ((uint8_t)0x02) /*!< Capture/Compare 1 Overcapture Flag mask. */
  1116. /*EGR*/
  1117. #define TIM5_EGR_TG ((uint8_t)0x40) /*!< Trigger Generation mask. */
  1118. #define TIM5_EGR_CC3G ((uint8_t)0x08) /*!< Capture/Compare 3 Generation mask. */
  1119. #define TIM5_EGR_CC2G ((uint8_t)0x04) /*!< Capture/Compare 2 Generation mask. */
  1120. #define TIM5_EGR_CC1G ((uint8_t)0x02) /*!< Capture/Compare 1 Generation mask. */
  1121. #define TIM5_EGR_UG ((uint8_t)0x01) /*!< Update Generation mask. */
  1122. /*CCMR*/
  1123. #define TIM5_CCMR_ICxPSC ((uint8_t)0x0C) /*!< Input Capture x Prescaler mask. */
  1124. #define TIM5_CCMR_ICxF ((uint8_t)0xF0) /*!< Input Capture x Filter mask. */
  1125. #define TIM5_CCMR_OCM ((uint8_t)0x70) /*!< Output Compare x Mode mask. */
  1126. #define TIM5_CCMR_OCxPE ((uint8_t)0x08) /*!< Output Compare x Preload Enable mask. */
  1127. #define TIM5_CCMR_CCxS ((uint8_t)0x03) /*!< Capture/Compare x Selection mask. */
  1128. /*CCER1*/
  1129. #define TIM5_CCER1_CC2P ((uint8_t)0x20) /*!< Capture/Compare 2 output Polarity mask. */
  1130. #define TIM5_CCER1_CC2E ((uint8_t)0x10) /*!< Capture/Compare 2 output enable mask. */
  1131. #define TIM5_CCER1_CC1P ((uint8_t)0x02) /*!< Capture/Compare 1 output Polarity mask. */
  1132. #define TIM5_CCER1_CC1E ((uint8_t)0x01) /*!< Capture/Compare 1 output enable mask. */
  1133. /*CCER2*/
  1134. #define TIM5_CCER2_CC3P ((uint8_t)0x02) /*!< Capture/Compare 3 output Polarity mask. */
  1135. #define TIM5_CCER2_CC3E ((uint8_t)0x01) /*!< Capture/Compare 3 output enable mask. */
  1136. /*CNTR*/
  1137. #define TIM5_CNTRH_CNT ((uint8_t)0xFF) /*!< Counter Value (MSB) mask. */
  1138. #define TIM5_CNTRL_CNT ((uint8_t)0xFF) /*!< Counter Value (LSB) mask. */
  1139. /*PSCR*/
  1140. #define TIM5_PSCR_PSC ((uint8_t)0xFF) /*!< Prescaler Value (MSB) mask. */
  1141. /*ARR*/
  1142. #define TIM5_ARRH_ARR ((uint8_t)0xFF) /*!< Autoreload Value (MSB) mask. */
  1143. #define TIM5_ARRL_ARR ((uint8_t)0xFF) /*!< Autoreload Value (LSB) mask. */
  1144. /*CCR1*/
  1145. #define TIM5_CCR1H_CCR1 ((uint8_t)0xFF) /*!< Capture/Compare 1 Value (MSB) mask. */
  1146. #define TIM5_CCR1L_CCR1 ((uint8_t)0xFF) /*!< Capture/Compare 1 Value (LSB) mask. */
  1147. /*CCR2*/
  1148. #define TIM5_CCR2H_CCR2 ((uint8_t)0xFF) /*!< Capture/Compare 2 Value (MSB) mask. */
  1149. #define TIM5_CCR2L_CCR2 ((uint8_t)0xFF) /*!< Capture/Compare 2 Value (LSB) mask. */
  1150. /*CCR3*/
  1151. #define TIM5_CCR3H_CCR3 ((uint8_t)0xFF) /*!< Capture/Compare 3 Value (MSB) mask. */
  1152. #define TIM5_CCR3L_CCR3 ((uint8_t)0xFF) /*!< Capture/Compare 3 Value (LSB) mask. */
  1153. /*CCMR*/
  1154. #define TIM5_CCMR_TIxDirect_Set ((uint8_t)0x01)
  1155. /**
  1156. * @}
  1157. */
  1158. /*----------------------------------------------------------------------------*/
  1159. /**
  1160. * @brief 8-bit system timer with synchro module(TIM6)
  1161. */
  1162. typedef struct TIM6_struct {
  1163. __IO uint8_t CR1; /*!< control register 1 */
  1164. __IO uint8_t CR2; /*!< control register 2 */
  1165. __IO uint8_t SMCR; /*!< Synchro mode control register */
  1166. __IO uint8_t IER; /*!< interrupt enable register */
  1167. __IO uint8_t SR1; /*!< status register 1 */
  1168. __IO uint8_t EGR; /*!< event generation register */
  1169. __IO uint8_t CNTR; /*!< counter register */
  1170. __IO uint8_t PSCR; /*!< prescaler register */
  1171. __IO uint8_t ARR; /*!< auto-reload register */
  1172. }
  1173. TIM6_TypeDef;
  1174. /** @addtogroup TIM6_Registers_Reset_Value
  1175. * @{
  1176. */
  1177. #define TIM6_CR1_RESET_VALUE ((uint8_t)0x00)
  1178. #define TIM6_CR2_RESET_VALUE ((uint8_t)0x00)
  1179. #define TIM6_SMCR_RESET_VALUE ((uint8_t)0x00)
  1180. #define TIM6_IER_RESET_VALUE ((uint8_t)0x00)
  1181. #define TIM6_SR1_RESET_VALUE ((uint8_t)0x00)
  1182. #define TIM6_EGR_RESET_VALUE ((uint8_t)0x00)
  1183. #define TIM6_CNTR_RESET_VALUE ((uint8_t)0x00)
  1184. #define TIM6_PSCR_RESET_VALUE ((uint8_t)0x00)
  1185. #define TIM6_ARR_RESET_VALUE ((uint8_t)0xFF)
  1186. /**
  1187. * @}
  1188. */
  1189. /** @addtogroup TIM6_Registers_Bits_Definition
  1190. * @{
  1191. */
  1192. /* CR1*/
  1193. #define TIM6_CR1_ARPE ((uint8_t)0x80) /*!< Auto-Reload Preload Enable Mask. */
  1194. #define TIM6_CR1_OPM ((uint8_t)0x08) /*!< One Pulse Mode Mask. */
  1195. #define TIM6_CR1_URS ((uint8_t)0x04) /*!< Update Request Source Mask. */
  1196. #define TIM6_CR1_UDIS ((uint8_t)0x02) /*!< Update DIsable Mask. */
  1197. #define TIM6_CR1_CEN ((uint8_t)0x01) /*!< Counter Enable Mask. */
  1198. /* CR2*/
  1199. #define TIM6_CR2_MMS ((uint8_t)0x70) /*!< MMS Selection Mask. */
  1200. /* SMCR*/
  1201. #define TIM6_SMCR_MSM ((uint8_t)0x80) /*!< Master/Slave Mode Mask. */
  1202. #define TIM6_SMCR_TS ((uint8_t)0x70) /*!< Trigger Selection Mask. */
  1203. #define TIM6_SMCR_SMS ((uint8_t)0x07) /*!< Slave Mode Selection Mask. */
  1204. /* IER*/
  1205. #define TIM6_IER_TIE ((uint8_t)0x40) /*!< Trigger Interrupt Enable Mask. */
  1206. #define TIM6_IER_UIE ((uint8_t)0x01) /*!< Update Interrupt Enable Mask. */
  1207. /* SR1*/
  1208. #define TIM6_SR1_TIF ((uint8_t)0x40) /*!< Trigger Interrupt Flag mask. */
  1209. #define TIM6_SR1_UIF ((uint8_t)0x01) /*!< Update Interrupt Flag Mask. */
  1210. /* EGR*/
  1211. #define TIM6_EGR_TG ((uint8_t)0x40) /*!< Trigger Generation mask. */
  1212. #define TIM6_EGR_UG ((uint8_t)0x01) /*!< Update Generation Mask. */
  1213. /* CNTR*/
  1214. #define TIM6_CNTR_CNT ((uint8_t)0xFF) /*!<Counter Value (LSB) Mask. */
  1215. /* PSCR*/
  1216. #define TIM6_PSCR_PSC ((uint8_t)0x07) /*!<Prescaler Value Mask. */
  1217. #define TIM6_ARR_ARR ((uint8_t)0xFF) /*!<Autoreload Value Mask. */
  1218. /**
  1219. * @}
  1220. */
  1221. /*----------------------------------------------------------------------------*/
  1222. /**
  1223. * @brief Inter-Integrated Circuit (I2C)
  1224. */
  1225. typedef struct I2C_struct {
  1226. __IO uint8_t CR1; /*!< I2C control register 1 */
  1227. __IO uint8_t CR2; /*!< I2C control register 2 */
  1228. __IO uint8_t FREQR; /*!< I2C frequency register */
  1229. __IO uint8_t OARL; /*!< I2C own address register LSB */
  1230. __IO uint8_t OARH; /*!< I2C own address register MSB */
  1231. uint8_t RESERVED1; /*!< Reserved byte */
  1232. __IO uint8_t DR; /*!< I2C data register */
  1233. __IO uint8_t SR1; /*!< I2C status register 1 */
  1234. __IO uint8_t SR2; /*!< I2C status register 2 */
  1235. __IO uint8_t SR3; /*!< I2C status register 3 */
  1236. __IO uint8_t ITR; /*!< I2C interrupt register */
  1237. __IO uint8_t CCRL; /*!< I2C clock control register low */
  1238. __IO uint8_t CCRH; /*!< I2C clock control register high */
  1239. __IO uint8_t TRISER; /*!< I2C maximum rise time register */
  1240. uint8_t RESERVED2; /*!< Reserved byte */
  1241. }
  1242. I2C_TypeDef;
  1243. /** @addtogroup I2C_Registers_Reset_Value
  1244. * @{
  1245. */
  1246. #define I2C_CR1_RESET_VALUE ((uint8_t)0x00)
  1247. #define I2C_CR2_RESET_VALUE ((uint8_t)0x00)
  1248. #define I2C_FREQR_RESET_VALUE ((uint8_t)0x00)
  1249. #define I2C_OARL_RESET_VALUE ((uint8_t)0x00)
  1250. #define I2C_OARH_RESET_VALUE ((uint8_t)0x00)
  1251. #define I2C_DR_RESET_VALUE ((uint8_t)0x00)
  1252. #define I2C_SR1_RESET_VALUE ((uint8_t)0x00)
  1253. #define I2C_SR2_RESET_VALUE ((uint8_t)0x00)
  1254. #define I2C_SR3_RESET_VALUE ((uint8_t)0x00)
  1255. #define I2C_ITR_RESET_VALUE ((uint8_t)0x00)
  1256. #define I2C_CCRL_RESET_VALUE ((uint8_t)0x00)
  1257. #define I2C_CCRH_RESET_VALUE ((uint8_t)0x00)
  1258. #define I2C_TRISER_RESET_VALUE ((uint8_t)0x02)
  1259. /**
  1260. * @}
  1261. */
  1262. /** @addtogroup I2C_Registers_Bits_Definition
  1263. * @{
  1264. */
  1265. #define I2C_CR1_NOSTRETCH ((uint8_t)0x80) /*!< Clock Stretching Disable (Slave mode) */
  1266. #define I2C_CR1_ENGC ((uint8_t)0x40) /*!< General Call Enable */
  1267. #define I2C_CR1_PE ((uint8_t)0x01) /*!< Peripheral Enable */
  1268. #define I2C_CR2_SWRST ((uint8_t)0x80) /*!< Software Reset */
  1269. #define I2C_CR2_POS ((uint8_t)0x08) /*!< Acknowledge */
  1270. #define I2C_CR2_ACK ((uint8_t)0x04) /*!< Acknowledge Enable */
  1271. #define I2C_CR2_STOP ((uint8_t)0x02) /*!< Stop Generation */
  1272. #define I2C_CR2_START ((uint8_t)0x01) /*!< Start Generation */
  1273. #define I2C_FREQR_FREQ ((uint8_t)0x3F) /*!< Peripheral Clock Frequency */
  1274. #define I2C_OARL_ADD ((uint8_t)0xFE) /*!< Interface Address bits [7..1] */
  1275. #define I2C_OARL_ADD0 ((uint8_t)0x01) /*!< Interface Address bit0 */
  1276. #define I2C_OARH_ADDMODE ((uint8_t)0x80) /*!< Addressing Mode (Slave mode) */
  1277. #define I2C_OARH_ADDCONF ((uint8_t)0x40) /*!< Address Mode Configuration */
  1278. #define I2C_OARH_ADD ((uint8_t)0x06) /*!< Interface Address bits [9..8] */
  1279. #define I2C_DR_DR ((uint8_t)0xFF) /*!< Data Register */
  1280. #define I2C_SR1_TXE ((uint8_t)0x80) /*!< Data Register Empty (transmitters) */
  1281. #define I2C_SR1_RXNE ((uint8_t)0x40) /*!< Data Register not Empty (receivers) */
  1282. #define I2C_SR1_STOPF ((uint8_t)0x10) /*!< Stop detection (Slave mode) */
  1283. #define I2C_SR1_ADD10 ((uint8_t)0x08) /*!< 10-bit header sent (Master mode) */
  1284. #define I2C_SR1_BTF ((uint8_t)0x04) /*!< Byte Transfer Finished */
  1285. #define I2C_SR1_ADDR ((uint8_t)0x02) /*!< Address sent (master mode)/matched (slave mode) */
  1286. #define I2C_SR1_SB ((uint8_t)0x01) /*!< Start Bit (Master mode) */
  1287. #define I2C_SR2_WUFH ((uint8_t)0x20) /*!< Wake-up from Halt */
  1288. #define I2C_SR2_OVR ((uint8_t)0x08) /*!< Overrun/Underrun */
  1289. #define I2C_SR2_AF ((uint8_t)0x04) /*!< Acknowledge Failure */
  1290. #define I2C_SR2_ARLO ((uint8_t)0x02) /*!< Arbitration Lost (master mode) */
  1291. #define I2C_SR2_BERR ((uint8_t)0x01) /*!< Bus Error */
  1292. #define I2C_SR3_GENCALL ((uint8_t)0x10) /*!< General Call Header (Slave mode) */
  1293. #define I2C_SR3_TRA ((uint8_t)0x04) /*!< Transmitter/Receiver */
  1294. #define I2C_SR3_BUSY ((uint8_t)0x02) /*!< Bus Busy */
  1295. #define I2C_SR3_MSL ((uint8_t)0x01) /*!< Master/Slave */
  1296. #define I2C_ITR_ITBUFEN ((uint8_t)0x04) /*!< Buffer Interrupt Enable */
  1297. #define I2C_ITR_ITEVTEN ((uint8_t)0x02) /*!< Event Interrupt Enable */
  1298. #define I2C_ITR_ITERREN ((uint8_t)0x01) /*!< Error Interrupt Enable */
  1299. #define I2C_CCRL_CCR ((uint8_t)0xFF) /*!< Clock Control Register (Master mode) */
  1300. #define I2C_CCRH_FS ((uint8_t)0x80) /*!< Master Mode Selection */
  1301. #define I2C_CCRH_DUTY ((uint8_t)0x40) /*!< Fast Mode Duty Cycle */
  1302. #define I2C_CCRH_CCR ((uint8_t)0x0F) /*!< Clock Control Register in Fast/Standard mode (Master mode) bits [11..8] */
  1303. #define I2C_TRISER_TRISE ((uint8_t)0x3F) /*!< Maximum Rise Time in Fast/Standard mode (Master mode) */
  1304. /**
  1305. * @}
  1306. */
  1307. /*----------------------------------------------------------------------------*/
  1308. /**
  1309. * @brief Interrupt Controller (ITC)
  1310. */
  1311. typedef struct ITC_struct {
  1312. __IO uint8_t ISPR1; /*!< Interrupt Software Priority register 1 */
  1313. __IO uint8_t ISPR2; /*!< Interrupt Software Priority register 2 */
  1314. __IO uint8_t ISPR3; /*!< Interrupt Software Priority register 3 */
  1315. __IO uint8_t ISPR4; /*!< Interrupt Software Priority register 4 */
  1316. __IO uint8_t ISPR5; /*!< Interrupt Software Priority register 5 */
  1317. __IO uint8_t ISPR6; /*!< Interrupt Software Priority register 6 */
  1318. __IO uint8_t ISPR7; /*!< Interrupt Software Priority register 7 */
  1319. __IO uint8_t ISPR8; /*!< Interrupt Software Priority register 8 */
  1320. }
  1321. ITC_TypeDef;
  1322. /** @addtogroup ITC_Registers_Reset_Value
  1323. * @{
  1324. */
  1325. #define ITC_SPRX_RESET_VALUE ((uint8_t)0xFF) /*!< Reset value of Software Priority registers */
  1326. /**
  1327. * @}
  1328. */
  1329. /** @addtogroup CPU_Registers_Bits_Definition
  1330. * @{
  1331. */
  1332. #define CPU_CC_I1I0 ((uint8_t)0x28) /*!< Condition Code register, I1 and I0 bits mask */
  1333. /**
  1334. * @}
  1335. */
  1336. /*----------------------------------------------------------------------------*/
  1337. /**
  1338. * @brief External Interrupt Controller (EXTI)
  1339. */
  1340. typedef struct EXTI_struct {
  1341. __IO uint8_t CR1; /*!< External Interrupt Control Register for PORTA to PORTD */
  1342. __IO uint8_t CR2; /*!< External Interrupt Control Register for PORTE and TLI */
  1343. }
  1344. EXTI_TypeDef;
  1345. /** @addtogroup EXTI_Registers_Reset_Value
  1346. * @{
  1347. */
  1348. #define EXTI_CR1_RESET_VALUE ((uint8_t)0x00)
  1349. #define EXTI_CR2_RESET_VALUE ((uint8_t)0x00)
  1350. /**
  1351. * @}
  1352. */
  1353. /** @addtogroup EXTI_Registers_Bits_Definition
  1354. * @{
  1355. */
  1356. #define EXTI_CR1_PDIS ((uint8_t)0xC0) /*!< PORTD external interrupt sensitivity bits mask */
  1357. #define EXTI_CR1_PCIS ((uint8_t)0x30) /*!< PORTC external interrupt sensitivity bits mask */
  1358. #define EXTI_CR1_PBIS ((uint8_t)0x0C) /*!< PORTB external interrupt sensitivity bits mask */
  1359. #define EXTI_CR1_PAIS ((uint8_t)0x03) /*!< PORTA external interrupt sensitivity bits mask */
  1360. #define EXTI_CR2_TLIS ((uint8_t)0x04) /*!< Top level interrupt sensitivity bit mask */
  1361. #define EXTI_CR2_PEIS ((uint8_t)0x03) /*!< PORTE external interrupt sensitivity bits mask */
  1362. /**
  1363. * @}
  1364. */
  1365. /*----------------------------------------------------------------------------*/
  1366. /**
  1367. * @brief FLASH program and Data memory (FLASH)
  1368. */
  1369. typedef struct FLASH_struct {
  1370. __IO uint8_t CR1; /*!< Flash control register 1 */
  1371. __IO uint8_t CR2; /*!< Flash control register 2 */
  1372. __IO uint8_t NCR2; /*!< Flash complementary control register 2 */
  1373. __IO uint8_t FPR; /*!< Flash protection register */
  1374. __IO uint8_t NFPR; /*!< Flash complementary protection register */
  1375. __IO uint8_t IAPSR; /*!< Flash in-application programming status register */
  1376. uint8_t RESERVED1; /*!< Reserved byte */
  1377. uint8_t RESERVED2; /*!< Reserved byte */
  1378. __IO uint8_t PUKR; /*!< Flash program memory unprotection register */
  1379. uint8_t RESERVED3; /*!< Reserved byte */
  1380. __IO uint8_t DUKR; /*!< Data EEPROM unprotection register */
  1381. }
  1382. FLASH_TypeDef;
  1383. /** @addtogroup FLASH_Registers_Reset_Value
  1384. * @{
  1385. */
  1386. #define FLASH_CR1_RESET_VALUE ((uint8_t)0x00)
  1387. #define FLASH_CR2_RESET_VALUE ((uint8_t)0x00)
  1388. #define FLASH_NCR2_RESET_VALUE ((uint8_t)0xFF)
  1389. #define FLASH_IAPSR_RESET_VALUE ((uint8_t)0x40)
  1390. #define FLASH_PUKR_RESET_VALUE ((uint8_t)0x00)
  1391. #define FLASH_DUKR_RESET_VALUE ((uint8_t)0x00)
  1392. /**
  1393. * @}
  1394. */
  1395. /** @addtogroup FLASH_Registers_Bits_Definition
  1396. * @{
  1397. */
  1398. #define FLASH_CR1_HALT ((uint8_t)0x08) /*!< Standby in Halt mode mask */
  1399. #define FLASH_CR1_AHALT ((uint8_t)0x04) /*!< Standby in Active Halt mode mask */
  1400. #define FLASH_CR1_IE ((uint8_t)0x02) /*!< Flash Interrupt enable mask */
  1401. #define FLASH_CR1_FIX ((uint8_t)0x01) /*!< Fix programming time mask */
  1402. #define FLASH_CR2_OPT ((uint8_t)0x80) /*!< Select option byte mask */
  1403. #define FLASH_CR2_WPRG ((uint8_t)0x40) /*!< Word Programming mask */
  1404. #define FLASH_CR2_ERASE ((uint8_t)0x20) /*!< Erase block mask */
  1405. #define FLASH_CR2_FPRG ((uint8_t)0x10) /*!< Fast programming mode mask */
  1406. #define FLASH_CR2_PRG ((uint8_t)0x01) /*!< Program block mask */
  1407. #define FLASH_NCR2_NOPT ((uint8_t)0x80) /*!< Select option byte mask */
  1408. #define FLASH_NCR2_NWPRG ((uint8_t)0x40) /*!< Word Programming mask */
  1409. #define FLASH_NCR2_NERASE ((uint8_t)0x20) /*!< Erase block mask */
  1410. #define FLASH_NCR2_NFPRG ((uint8_t)0x10) /*!< Fast programming mode mask */
  1411. #define FLASH_NCR2_NPRG ((uint8_t)0x01) /*!< Program block mask */
  1412. #define FLASH_IAPSR_HVOFF ((uint8_t)0x40) /*!< End of high voltage flag mask */
  1413. #define FLASH_IAPSR_DUL ((uint8_t)0x08) /*!< Data EEPROM unlocked flag mask */
  1414. #define FLASH_IAPSR_EOP ((uint8_t)0x04) /*!< End of operation flag mask */
  1415. #define FLASH_IAPSR_PUL ((uint8_t)0x02) /*!< Flash Program memory unlocked flag mask */
  1416. #define FLASH_IAPSR_WR_PG_DIS ((uint8_t)0x01) /*!< Write attempted to protected page mask */
  1417. #define FLASH_PUKR_PUK ((uint8_t)0xFF) /*!< Flash Program memory unprotection mask */
  1418. #define FLASH_DUKR_DUK ((uint8_t)0xFF) /*!< Data EEPROM unprotection mask */
  1419. /**
  1420. * @}
  1421. */
  1422. /*----------------------------------------------------------------------------*/
  1423. /**
  1424. * @brief Option Bytes (OPT)
  1425. */
  1426. typedef struct OPT_struct {
  1427. __IO uint8_t OPT0; /*!< Option byte 0: Read-out protection (not accessible in IAP mode) */
  1428. __IO uint8_t OPT1; /*!< Option byte 1: User boot code */
  1429. __IO uint8_t NOPT1; /*!< Complementary Option byte 1 */
  1430. __IO uint8_t OPT2; /*!< Option byte 2: Alternate function remapping */
  1431. __IO uint8_t NOPT2; /*!< Complementary Option byte 2 */
  1432. __IO uint8_t OPT3; /*!< Option byte 3: Watchdog option */
  1433. __IO uint8_t NOPT3; /*!< Complementary Option byte 3 */
  1434. __IO uint8_t OPT4; /*!< Option byte 4: Clock option */
  1435. __IO uint8_t NOPT4; /*!< Complementary Option byte 4 */
  1436. __IO uint8_t OPT5; /*!< Option byte 5: HSE clock startup */
  1437. __IO uint8_t NOPT5; /*!< Complementary Option byte 5 */
  1438. uint8_t RESERVED1; /*!< Reserved Option byte*/
  1439. uint8_t RESERVED2; /*!< Reserved Option byte*/
  1440. __IO uint8_t OPT7; /*!< Option byte 7: flash wait states */
  1441. __IO uint8_t NOPT7; /*!< Complementary Option byte 7 */
  1442. }
  1443. OPT_TypeDef;
  1444. /*----------------------------------------------------------------------------*/
  1445. /**
  1446. * @brief Independent Watchdog (IWDG)
  1447. */
  1448. typedef struct IWDG_struct {
  1449. __IO uint8_t KR; /*!< Key Register */
  1450. __IO uint8_t PR; /*!< Prescaler Register */
  1451. __IO uint8_t RLR; /*!< Reload Register */
  1452. }
  1453. IWDG_TypeDef;
  1454. /** @addtogroup IWDG_Registers_Reset_Value
  1455. * @{
  1456. */
  1457. #define IWDG_PR_RESET_VALUE ((uint8_t)0x00)
  1458. #define IWDG_RLR_RESET_VALUE ((uint8_t)0xFF)
  1459. /**
  1460. * @}
  1461. */
  1462. /*----------------------------------------------------------------------------*/
  1463. /**
  1464. * @brief Window Watchdog (WWDG)
  1465. */
  1466. typedef struct WWDG_struct {
  1467. __IO uint8_t CR; /*!< Control Register */
  1468. __IO uint8_t WR; /*!< Window Register */
  1469. }
  1470. WWDG_TypeDef;
  1471. /** @addtogroup WWDG_Registers_Reset_Value
  1472. * @{
  1473. */
  1474. #define WWDG_CR_RESET_VALUE ((uint8_t)0x7F)
  1475. #define WWDG_WR_RESET_VALUE ((uint8_t)0x7F)
  1476. /**
  1477. * @}
  1478. */
  1479. /** @addtogroup WWDG_Registers_Bits_Definition
  1480. * @{
  1481. */
  1482. #define WWDG_CR_WDGA ((uint8_t)0x80) /*!< WDGA bit mask */
  1483. #define WWDG_CR_T6 ((uint8_t)0x40) /*!< T6 bit mask */
  1484. #define WWDG_CR_T ((uint8_t)0x7F) /*!< T bits mask */
  1485. #define WWDG_WR_MSB ((uint8_t)0x80) /*!< MSB bit mask */
  1486. #define WWDG_WR_W ((uint8_t)0x7F) /*!< W bits mask */
  1487. /**
  1488. * @}
  1489. */
  1490. /*----------------------------------------------------------------------------*/
  1491. /**
  1492. * @brief Reset Controller (RST)
  1493. */
  1494. typedef struct RST_struct {
  1495. __IO uint8_t SR; /*!< Reset status register */
  1496. }
  1497. RST_TypeDef;
  1498. /** @addtogroup RST_Registers_Bits_Definition
  1499. * @{
  1500. */
  1501. #define RST_SR_EMCF ((uint8_t)0x10) /*!< EMC reset flag bit mask */
  1502. #define RST_SR_SWIMF ((uint8_t)0x08) /*!< SWIM reset flag bit mask */
  1503. #define RST_SR_ILLOPF ((uint8_t)0x04) /*!< Illegal opcode reset flag bit mask */
  1504. #define RST_SR_IWDGF ((uint8_t)0x02) /*!< IWDG reset flag bit mask */
  1505. #define RST_SR_WWDGF ((uint8_t)0x01) /*!< WWDG reset flag bit mask */
  1506. /**
  1507. * @}
  1508. */
  1509. /*----------------------------------------------------------------------------*/
  1510. /**
  1511. * @brief Serial Peripheral Interface (SPI)
  1512. */
  1513. typedef struct SPI_struct {
  1514. __IO uint8_t CR1; /*!< SPI control register 1 */
  1515. __IO uint8_t CR2; /*!< SPI control register 2 */
  1516. __IO uint8_t ICR; /*!< SPI interrupt control register */
  1517. __IO uint8_t SR; /*!< SPI status register */
  1518. __IO uint8_t DR; /*!< SPI data I/O register */
  1519. __IO uint8_t CRCPR; /*!< SPI CRC polynomial register */
  1520. __IO uint8_t RXCRCR; /*!< SPI Rx CRC register */
  1521. __IO uint8_t TXCRCR; /*!< SPI Tx CRC register */
  1522. }
  1523. SPI_TypeDef;
  1524. /** @addtogroup SPI_Registers_Reset_Value
  1525. * @{
  1526. */
  1527. #define SPI_CR1_RESET_VALUE ((uint8_t)0x00) /*!< Control Register 1 reset value */
  1528. #define SPI_CR2_RESET_VALUE ((uint8_t)0x00) /*!< Control Register 2 reset value */
  1529. #define SPI_ICR_RESET_VALUE ((uint8_t)0x00) /*!< Interrupt Control Register reset value */
  1530. #define SPI_SR_RESET_VALUE ((uint8_t)0x02) /*!< Status Register reset value */
  1531. #define SPI_DR_RESET_VALUE ((uint8_t)0x00) /*!< Data Register reset value */
  1532. #define SPI_CRCPR_RESET_VALUE ((uint8_t)0x07) /*!< Polynomial Register reset value */
  1533. #define SPI_RXCRCR_RESET_VALUE ((uint8_t)0x00) /*!< RX CRC Register reset value */
  1534. #define SPI_TXCRCR_RESET_VALUE ((uint8_t)0x00) /*!< TX CRC Register reset value */
  1535. /**
  1536. * @}
  1537. */
  1538. /** @addtogroup SPI_Registers_Bits_Definition
  1539. * @{
  1540. */
  1541. #define SPI_CR1_LSBFIRST ((uint8_t)0x80) /*!< Frame format mask */
  1542. #define SPI_CR1_SPE ((uint8_t)0x40) /*!< Enable bits mask */
  1543. #define SPI_CR1_BR ((uint8_t)0x38) /*!< Baud rate control mask */
  1544. #define SPI_CR1_MSTR ((uint8_t)0x04) /*!< Master Selection mask */
  1545. #define SPI_CR1_CPOL ((uint8_t)0x02) /*!< Clock Polarity mask */
  1546. #define SPI_CR1_CPHA ((uint8_t)0x01) /*!< Clock Phase mask */
  1547. #define SPI_CR2_BDM ((uint8_t)0x80) /*!< Bi-directional data mode enable mask */
  1548. #define SPI_CR2_BDOE ((uint8_t)0x40) /*!< Output enable in bi-directional mode mask */
  1549. #define SPI_CR2_CRCEN ((uint8_t)0x20) /*!< Hardware CRC calculation enable mask */
  1550. #define SPI_CR2_CRCNEXT ((uint8_t)0x10) /*!< Transmit CRC next mask */
  1551. #define SPI_CR2_RXONLY ((uint8_t)0x04) /*!< Receive only mask */
  1552. #define SPI_CR2_SSM ((uint8_t)0x02) /*!< Software slave management mask */
  1553. #define SPI_CR2_SSI ((uint8_t)0x01) /*!< Internal slave select mask */
  1554. #define SPI_ICR_TXEI ((uint8_t)0x80) /*!< Tx buffer empty interrupt enable mask */
  1555. #define SPI_ICR_RXEI ((uint8_t)0x40) /*!< Rx buffer empty interrupt enable mask */
  1556. #define SPI_ICR_ERRIE ((uint8_t)0x20) /*!< Error interrupt enable mask */
  1557. #define SPI_ICR_WKIE ((uint8_t)0x10) /*!< Wake-up interrupt enable mask */
  1558. #define SPI_SR_BSY ((uint8_t)0x80) /*!< Busy flag */
  1559. #define SPI_SR_OVR ((uint8_t)0x40) /*!< Overrun flag */
  1560. #define SPI_SR_MODF ((uint8_t)0x20) /*!< Mode fault */
  1561. #define SPI_SR_CRCERR ((uint8_t)0x10) /*!< CRC error flag */
  1562. #define SPI_SR_WKUP ((uint8_t)0x08) /*!< Wake-Up flag */
  1563. #define SPI_SR_TXE ((uint8_t)0x02) /*!< Transmit buffer empty */
  1564. #define SPI_SR_RXNE ((uint8_t)0x01) /*!< Receive buffer not empty */
  1565. /**
  1566. * @}
  1567. */
  1568. /*----------------------------------------------------------------------------*/
  1569. /**
  1570. * @brief Universal Synchronous Asynchronous Receiver Transmitter (UART1)
  1571. */
  1572. typedef struct UART1_struct {
  1573. __IO uint8_t SR; /*!< UART1 status register */
  1574. __IO uint8_t DR; /*!< UART1 data register */
  1575. __IO uint8_t BRR1; /*!< UART1 baud rate register */
  1576. __IO uint8_t BRR2; /*!< UART1 DIV mantissa[11:8] SCIDIV fraction */
  1577. __IO uint8_t CR1; /*!< UART1 control register 1 */
  1578. __IO uint8_t CR2; /*!< UART1 control register 2 */
  1579. __IO uint8_t CR3; /*!< UART1 control register 3 */
  1580. __IO uint8_t CR4; /*!< UART1 control register 4 */
  1581. __IO uint8_t CR5; /*!< UART1 control register 5 */
  1582. __IO uint8_t GTR; /*!< UART1 guard time register */
  1583. __IO uint8_t PSCR; /*!< UART1 prescaler register */
  1584. }
  1585. UART1_TypeDef;
  1586. /** @addtogroup UART1_Registers_Reset_Value
  1587. * @{
  1588. */
  1589. #define UART1_SR_RESET_VALUE ((uint8_t)0xC0)
  1590. #define UART1_BRR1_RESET_VALUE ((uint8_t)0x00)
  1591. #define UART1_BRR2_RESET_VALUE ((uint8_t)0x00)
  1592. #define UART1_CR1_RESET_VALUE ((uint8_t)0x00)
  1593. #define UART1_CR2_RESET_VALUE ((uint8_t)0x00)
  1594. #define UART1_CR3_RESET_VALUE ((uint8_t)0x00)
  1595. #define UART1_CR4_RESET_VALUE ((uint8_t)0x00)
  1596. #define UART1_CR5_RESET_VALUE ((uint8_t)0x00)
  1597. #define UART1_GTR_RESET_VALUE ((uint8_t)0x00)
  1598. #define UART1_PSCR_RESET_VALUE ((uint8_t)0x00)
  1599. /**
  1600. * @}
  1601. */
  1602. /** @addtogroup UART1_Registers_Bits_Definition
  1603. * @{
  1604. */
  1605. #define UART1_SR_TXE ((uint8_t)0x80) /*!< Transmit Data Register Empty mask */
  1606. #define UART1_SR_TC ((uint8_t)0x40) /*!< Transmission Complete mask */
  1607. #define UART1_SR_RXNE ((uint8_t)0x20) /*!< Read Data Register Not Empty mask */
  1608. #define UART1_SR_IDLE ((uint8_t)0x10) /*!< IDLE line detected mask */
  1609. #define UART1_SR_OR ((uint8_t)0x08) /*!< OverRun error mask */
  1610. #define UART1_SR_NF ((uint8_t)0x04) /*!< Noise Flag mask */
  1611. #define UART1_SR_FE ((uint8_t)0x02) /*!< Framing Error mask */
  1612. #define UART1_SR_PE ((uint8_t)0x01) /*!< Parity Error mask */
  1613. #define UART1_BRR1_DIVM ((uint8_t)0xFF) /*!< LSB mantissa of UART1DIV [7:0] mask */
  1614. #define UART1_BRR2_DIVM ((uint8_t)0xF0) /*!< MSB mantissa of UART1DIV [11:8] mask */
  1615. #define UART1_BRR2_DIVF ((uint8_t)0x0F) /*!< Fraction bits of UART1DIV [3:0] mask */
  1616. #define UART1_CR1_R8 ((uint8_t)0x80) /*!< Receive Data bit 8 */
  1617. #define UART1_CR1_T8 ((uint8_t)0x40) /*!< Transmit data bit 8 */
  1618. #define UART1_CR1_UARTD ((uint8_t)0x20) /*!< UART1 Disable (for low power consumption) */
  1619. #define UART1_CR1_M ((uint8_t)0x10) /*!< Word length mask */
  1620. #define UART1_CR1_WAKE ((uint8_t)0x08) /*!< Wake-up method mask */
  1621. #define UART1_CR1_PCEN ((uint8_t)0x04) /*!< Parity Control Enable mask */
  1622. #define UART1_CR1_PS ((uint8_t)0x02) /*!< UART1 Parity Selection */
  1623. #define UART1_CR1_PIEN ((uint8_t)0x01) /*!< UART1 Parity Interrupt Enable mask */
  1624. #define UART1_CR2_TIEN ((uint8_t)0x80) /*!< Transmitter Interrupt Enable mask */
  1625. #define UART1_CR2_TCIEN ((uint8_t)0x40) /*!< Transmission Complete Interrupt Enable mask */
  1626. #define UART1_CR2_RIEN ((uint8_t)0x20) /*!< Receiver Interrupt Enable mask */
  1627. #define UART1_CR2_ILIEN ((uint8_t)0x10) /*!< IDLE Line Interrupt Enable mask */
  1628. #define UART1_CR2_TEN ((uint8_t)0x08) /*!< Transmitter Enable mask */
  1629. #define UART1_CR2_REN ((uint8_t)0x04) /*!< Receiver Enable mask */
  1630. #define UART1_CR2_RWU ((uint8_t)0x02) /*!< Receiver Wake-Up mask */
  1631. #define UART1_CR2_SBK ((uint8_t)0x01) /*!< Send Break mask */
  1632. #define UART1_CR3_LINEN ((uint8_t)0x40) /*!< Alternate Function output mask */
  1633. #define UART1_CR3_STOP ((uint8_t)0x30) /*!< STOP bits [1:0] mask */
  1634. #define UART1_CR3_CKEN ((uint8_t)0x08) /*!< Clock Enable mask */
  1635. #define UART1_CR3_CPOL ((uint8_t)0x04) /*!< Clock Polarity mask */
  1636. #define UART1_CR3_CPHA ((uint8_t)0x02) /*!< Clock Phase mask */
  1637. #define UART1_CR3_LBCL ((uint8_t)0x01) /*!< Last Bit Clock pulse mask */
  1638. #define UART1_CR4_LBDIEN ((uint8_t)0x40) /*!< LIN Break Detection Interrupt Enable mask */
  1639. #define UART1_CR4_LBDL ((uint8_t)0x20) /*!< LIN Break Detection Length mask */
  1640. #define UART1_CR4_LBDF ((uint8_t)0x10) /*!< LIN Break Detection Flag mask */
  1641. #define UART1_CR4_ADD ((uint8_t)0x0F) /*!< Address of the UART1 node mask */
  1642. #define UART1_CR5_SCEN ((uint8_t)0x20) /*!< Smart Card Enable mask */
  1643. #define UART1_CR5_NACK ((uint8_t)0x10) /*!< Smart Card Nack Enable mask */
  1644. #define UART1_CR5_HDSEL ((uint8_t)0x08) /*!< Half-Duplex Selection mask */
  1645. #define UART1_CR5_IRLP ((uint8_t)0x04) /*!< Irda Low Power Selection mask */
  1646. #define UART1_CR5_IREN ((uint8_t)0x02) /*!< Irda Enable mask */
  1647. /**
  1648. * @}
  1649. */
  1650. /*----------------------------------------------------------------------------*/
  1651. /**
  1652. * @brief Universal Synchronous Asynchronous Receiver Transmitter (UART2)
  1653. */
  1654. typedef struct UART2_struct {
  1655. __IO uint8_t SR; /*!< UART1 status register */
  1656. __IO uint8_t DR; /*!< UART1 data register */
  1657. __IO uint8_t BRR1; /*!< UART1 baud rate register */
  1658. __IO uint8_t BRR2; /*!< UART1 DIV mantissa[11:8] SCIDIV fraction */
  1659. __IO uint8_t CR1; /*!< UART1 control register 1 */
  1660. __IO uint8_t CR2; /*!< UART1 control register 2 */
  1661. __IO uint8_t CR3; /*!< UART1 control register 3 */
  1662. __IO uint8_t CR4; /*!< UART1 control register 4 */
  1663. __IO uint8_t CR5; /*!< UART1 control register 5 */
  1664. __IO uint8_t CR6; /*!< UART1 control register 6 */
  1665. __IO uint8_t GTR; /*!< UART1 guard time register */
  1666. __IO uint8_t PSCR; /*!< UART1 prescaler register */
  1667. }
  1668. UART2_TypeDef;
  1669. /** @addtogroup UART2_Registers_Reset_Value
  1670. * @{
  1671. */
  1672. #define UART2_SR_RESET_VALUE ((uint8_t)0xC0)
  1673. #define UART2_BRR1_RESET_VALUE ((uint8_t)0x00)
  1674. #define UART2_BRR2_RESET_VALUE ((uint8_t)0x00)
  1675. #define UART2_CR1_RESET_VALUE ((uint8_t)0x00)
  1676. #define UART2_CR2_RESET_VALUE ((uint8_t)0x00)
  1677. #define UART2_CR3_RESET_VALUE ((uint8_t)0x00)
  1678. #define UART2_CR4_RESET_VALUE ((uint8_t)0x00)
  1679. #define UART2_CR5_RESET_VALUE ((uint8_t)0x00)
  1680. #define UART2_CR6_RESET_VALUE ((uint8_t)0x00)
  1681. #define UART2_GTR_RESET_VALUE ((uint8_t)0x00)
  1682. #define UART2_PSCR_RESET_VALUE ((uint8_t)0x00)
  1683. /**
  1684. * @}
  1685. */
  1686. /** @addtogroup UART2_Registers_Bits_Definition
  1687. * @{
  1688. */
  1689. #define UART2_SR_TXE ((uint8_t)0x80) /*!< Transmit Data Register Empty mask */
  1690. #define UART2_SR_TC ((uint8_t)0x40) /*!< Transmission Complete mask */
  1691. #define UART2_SR_RXNE ((uint8_t)0x20) /*!< Read Data Register Not Empty mask */
  1692. #define UART2_SR_IDLE ((uint8_t)0x10) /*!< IDLE line detected mask */
  1693. #define UART2_SR_OR ((uint8_t)0x08) /*!< OverRun error mask */
  1694. #define UART2_SR_NF ((uint8_t)0x04) /*!< Noise Flag mask */
  1695. #define UART2_SR_FE ((uint8_t)0x02) /*!< Framing Error mask */
  1696. #define UART2_SR_PE ((uint8_t)0x01) /*!< Parity Error mask */
  1697. #define UART2_BRR1_DIVM ((uint8_t)0xFF) /*!< LSB mantissa of UART2DIV [7:0] mask */
  1698. #define UART2_BRR2_DIVM ((uint8_t)0xF0) /*!< MSB mantissa of UART2DIV [11:8] mask */
  1699. #define UART2_BRR2_DIVF ((uint8_t)0x0F) /*!< Fraction bits of UART2DIV [3:0] mask */
  1700. #define UART2_CR1_R8 ((uint8_t)0x80) /*!< Receive Data bit 8 */
  1701. #define UART2_CR1_T8 ((uint8_t)0x40) /*!< Transmit data bit 8 */
  1702. #define UART2_CR1_UARTD ((uint8_t)0x20) /*!< UART2 Disable (for low power consumption) */
  1703. #define UART2_CR1_M ((uint8_t)0x10) /*!< Word length mask */
  1704. #define UART2_CR1_WAKE ((uint8_t)0x08) /*!< Wake-up method mask */
  1705. #define UART2_CR1_PCEN ((uint8_t)0x04) /*!< Parity Control Enable mask */
  1706. #define UART2_CR1_PS ((uint8_t)0x02) /*!< UART2 Parity Selection */
  1707. #define UART2_CR1_PIEN ((uint8_t)0x01) /*!< UART2 Parity Interrupt Enable mask */
  1708. #define UART2_CR2_TIEN ((uint8_t)0x80) /*!< Transmitter Interrupt Enable mask */
  1709. #define UART2_CR2_TCIEN ((uint8_t)0x40) /*!< Transmission Complete Interrupt Enable mask */
  1710. #define UART2_CR2_RIEN ((uint8_t)0x20) /*!< Receiver Interrupt Enable mask */
  1711. #define UART2_CR2_ILIEN ((uint8_t)0x10) /*!< IDLE Line Interrupt Enable mask */
  1712. #define UART2_CR2_TEN ((uint8_t)0x08) /*!< Transmitter Enable mask */
  1713. #define UART2_CR2_REN ((uint8_t)0x04) /*!< Receiver Enable mask */
  1714. #define UART2_CR2_RWU ((uint8_t)0x02) /*!< Receiver Wake-Up mask */
  1715. #define UART2_CR2_SBK ((uint8_t)0x01) /*!< Send Break mask */
  1716. #define UART2_CR3_LINEN ((uint8_t)0x40) /*!< Alternate Function output mask */
  1717. #define UART2_CR3_STOP ((uint8_t)0x30) /*!< STOP bits [1:0] mask */
  1718. #define UART2_CR3_CKEN ((uint8_t)0x08) /*!< Clock Enable mask */
  1719. #define UART2_CR3_CPOL ((uint8_t)0x04) /*!< Clock Polarity mask */
  1720. #define UART2_CR3_CPHA ((uint8_t)0x02) /*!< Clock Phase mask */
  1721. #define UART2_CR3_LBCL ((uint8_t)0x01) /*!< Last Bit Clock pulse mask */
  1722. #define UART2_CR4_LBDIEN ((uint8_t)0x40) /*!< LIN Break Detection Interrupt Enable mask */
  1723. #define UART2_CR4_LBDL ((uint8_t)0x20) /*!< LIN Break Detection Length mask */
  1724. #define UART2_CR4_LBDF ((uint8_t)0x10) /*!< LIN Break Detection Flag mask */
  1725. #define UART2_CR4_ADD ((uint8_t)0x0F) /*!< Address of the UART2 node mask */
  1726. #define UART2_CR5_SCEN ((uint8_t)0x20) /*!< Smart Card Enable mask */
  1727. #define UART2_CR5_NACK ((uint8_t)0x10) /*!< Smart Card Nack Enable mask */
  1728. #define UART2_CR5_IRLP ((uint8_t)0x04) /*!< Irda Low Power Selection mask */
  1729. #define UART2_CR5_IREN ((uint8_t)0x02) /*!< Irda Enable mask */
  1730. #define UART2_CR6_LDUM ((uint8_t)0x80) /*!< LIN Divider Update Method */
  1731. #define UART2_CR6_LSLV ((uint8_t)0x20) /*!< LIN Slave Enable */
  1732. #define UART2_CR6_LASE ((uint8_t)0x10) /*!< LIN Auto synchronization Enable */
  1733. #define UART2_CR6_LHDIEN ((uint8_t)0x04) /*!< LIN Header Detection Interrupt Enable */
  1734. #define UART2_CR6_LHDF ((uint8_t)0x02) /*!< LIN Header Detection Flag */
  1735. #define UART2_CR6_LSF ((uint8_t)0x01) /*!< LIN Synch Field */
  1736. /**
  1737. * @}
  1738. */
  1739. /*----------------------------------------------------------------------------*/
  1740. /**
  1741. * @brief LIN Universal Asynchronous Receiver Transmitter (UART3)
  1742. */
  1743. typedef struct UART3_struct {
  1744. __IO uint8_t SR; /*!< status register */
  1745. __IO uint8_t DR; /*!< data register */
  1746. __IO uint8_t BRR1; /*!< baud rate register */
  1747. __IO uint8_t BRR2; /*!< DIV mantissa[11:8] SCIDIV fraction */
  1748. __IO uint8_t CR1; /*!< control register 1 */
  1749. __IO uint8_t CR2; /*!< control register 2 */
  1750. __IO uint8_t CR3; /*!< control register 3 */
  1751. __IO uint8_t CR4; /*!< control register 4 */
  1752. uint8_t RESERVED; /*!< Reserved byte */
  1753. __IO uint8_t CR6; /*!< control register 5 */
  1754. }
  1755. UART3_TypeDef;
  1756. /** @addtogroup UART3_Registers_Reset_Value
  1757. * @{
  1758. */
  1759. #define UART3_SR_RESET_VALUE ((uint8_t)0xC0)
  1760. #define UART3_BRR1_RESET_VALUE ((uint8_t)0x00)
  1761. #define UART3_BRR2_RESET_VALUE ((uint8_t)0x00)
  1762. #define UART3_CR1_RESET_VALUE ((uint8_t)0x00)
  1763. #define UART3_CR2_RESET_VALUE ((uint8_t)0x00)
  1764. #define UART3_CR3_RESET_VALUE ((uint8_t)0x00)
  1765. #define UART3_CR4_RESET_VALUE ((uint8_t)0x00)
  1766. #define UART3_CR6_RESET_VALUE ((uint8_t)0x00)
  1767. /**
  1768. * @}
  1769. */
  1770. /** @addtogroup UART3_Registers_Bits_Definition
  1771. * @{
  1772. */
  1773. #define UART3_SR_TXE ((uint8_t)0x80) /*!< Transmit Data Register Empty mask */
  1774. #define UART3_SR_TC ((uint8_t)0x40) /*!< Transmission Complete mask */
  1775. #define UART3_SR_RXNE ((uint8_t)0x20) /*!< Read Data Register Not Empty mask */
  1776. #define UART3_SR_IDLE ((uint8_t)0x10) /*!< IDLE line detected mask */
  1777. #define UART3_SR_OR ((uint8_t)0x08) /*!< OverRun error mask */
  1778. #define UART3_SR_NF ((uint8_t)0x04) /*!< Noise Flag mask */
  1779. #define UART3_SR_FE ((uint8_t)0x02) /*!< Framing Error mask */
  1780. #define UART3_SR_PE ((uint8_t)0x01) /*!< Parity Error mask */
  1781. #define UART3_BRR1_DIVM ((uint8_t)0xFF) /*!< LSB mantissa of UARTDIV [7:0] mask */
  1782. #define UART3_BRR2_DIVM ((uint8_t)0xF0) /*!< MSB mantissa of UARTDIV [11:8] mask */
  1783. #define UART3_BRR2_DIVF ((uint8_t)0x0F) /*!< Fraction bits of UARTDIV [3:0] mask */
  1784. #define UART3_CR1_R8 ((uint8_t)0x80) /*!< Receive Data bit 8 */
  1785. #define UART3_CR1_T8 ((uint8_t)0x40) /*!< Transmit data bit 8 */
  1786. #define UART3_CR1_UARTD ((uint8_t)0x20) /*!< UART Disable (for low power consumption) */
  1787. #define UART3_CR1_M ((uint8_t)0x10) /*!< Word length mask */
  1788. #define UART3_CR1_WAKE ((uint8_t)0x08) /*!< Wake-up method mask */
  1789. #define UART3_CR1_PCEN ((uint8_t)0x04) /*!< Parity control enable mask */
  1790. #define UART3_CR1_PS ((uint8_t)0x02) /*!< Parity selection bit mask */
  1791. #define UART3_CR1_PIEN ((uint8_t)0x01) /*!< Parity interrupt enable bit mask */
  1792. #define UART3_CR2_TIEN ((uint8_t)0x80) /*!< Transmitter Interrupt Enable mask */
  1793. #define UART3_CR2_TCIEN ((uint8_t)0x40) /*!< Transmission Complete Interrupt Enable mask */
  1794. #define UART3_CR2_RIEN ((uint8_t)0x20) /*!< Receiver Interrupt Enable mask */
  1795. #define UART3_CR2_ILIEN ((uint8_t)0x10) /*!< IDLE Line Interrupt Enable mask */
  1796. #define UART3_CR2_TEN ((uint8_t)0x08) /*!< Transmitter Enable mask */
  1797. #define UART3_CR2_REN ((uint8_t)0x04) /*!< Receiver Enable mask */
  1798. #define UART3_CR2_RWU ((uint8_t)0x02) /*!< Receiver Wake-Up mask */
  1799. #define UART3_CR2_SBK ((uint8_t)0x01) /*!< Send Break mask */
  1800. #define UART3_CR3_LINEN ((uint8_t)0x40) /*!< Alternate Function output mask */
  1801. #define UART3_CR3_STOP ((uint8_t)0x30) /*!< STOP bits [1:0] mask */
  1802. #define UART3_CR4_LBDIEN ((uint8_t)0x40) /*!< LIN Break Detection Interrupt Enable mask */
  1803. #define UART3_CR4_LBDL ((uint8_t)0x20) /*!< LIN Break Detection Length mask */
  1804. #define UART3_CR4_LBDF ((uint8_t)0x10) /*!< LIN Break Detection Flag mask */
  1805. #define UART3_CR4_ADD ((uint8_t)0x0F) /*!< Address of the UART3 node mask */
  1806. #define UART3_CR6_LDUM ((uint8_t)0x80) /*!< LIN Divider Update Method */
  1807. #define UART3_CR6_LSLV ((uint8_t)0x20) /*!< LIN Slave Enable */
  1808. #define UART3_CR6_LASE ((uint8_t)0x10) /*!< LIN Auto synchronization Enable */
  1809. #define UART3_CR6_LHDIEN ((uint8_t)0x04) /*!< LIN Header Detection Interrupt Enable */
  1810. #define UART3_CR6_LHDF ((uint8_t)0x02) /*!< LIN Header Detection Flag */
  1811. #define UART3_CR6_LSF ((uint8_t)0x01) /*!< LIN Synch Field */
  1812. /**
  1813. * @}
  1814. */
  1815. /*----------------------------------------------------------------------------*/
  1816. /**
  1817. * @brief Universal Synchronous Asynchronous Receiver Transmitter (UART4)
  1818. */
  1819. #if defined(STM8AF622x)
  1820. typedef struct UART4_struct
  1821. {
  1822. __IO uint8_t SR; /*!< UART4 status register */
  1823. __IO uint8_t DR; /*!< UART4 data register */
  1824. __IO uint8_t BRR1; /*!< UART4 baud rate register */
  1825. __IO uint8_t BRR2; /*!< UART4 DIV mantissa[11:8] SCIDIV fraction */
  1826. __IO uint8_t CR1; /*!< UART4 control register 1 */
  1827. __IO uint8_t CR2; /*!< UART4 control register 2 */
  1828. __IO uint8_t CR3; /*!< UART4 control register 3 */
  1829. __IO uint8_t CR4; /*!< UART4 control register 4 */
  1830. __IO uint8_t CR5; /*!< UART4 control register 5 */
  1831. __IO uint8_t CR6; /*!< UART4 control register 6 */
  1832. __IO uint8_t GTR; /*!< UART4 guard time register */
  1833. __IO uint8_t PSCR; /*!< UART4 prescaler register */
  1834. }
  1835. UART4_TypeDef;
  1836. /** @addtogroup UART4_Registers_Reset_Value
  1837. * @{
  1838. */
  1839. #define UART4_SR_RESET_VALUE ((uint8_t)0xC0)
  1840. #define UART4_BRR1_RESET_VALUE ((uint8_t)0x00)
  1841. #define UART4_BRR2_RESET_VALUE ((uint8_t)0x00)
  1842. #define UART4_CR1_RESET_VALUE ((uint8_t)0x00)
  1843. #define UART4_CR2_RESET_VALUE ((uint8_t)0x00)
  1844. #define UART4_CR3_RESET_VALUE ((uint8_t)0x00)
  1845. #define UART4_CR4_RESET_VALUE ((uint8_t)0x00)
  1846. #define UART4_CR5_RESET_VALUE ((uint8_t)0x00)
  1847. #define UART4_CR6_RESET_VALUE ((uint8_t)0x00)
  1848. #define UART4_GTR_RESET_VALUE ((uint8_t)0x00)
  1849. #define UART4_PSCR_RESET_VALUE ((uint8_t)0x00)
  1850. /**
  1851. * @}
  1852. */
  1853. /** @addtogroup UART4_Registers_Bits_Definition
  1854. * @{
  1855. */
  1856. #define UART4_SR_TXE ((uint8_t)0x80) /*!< Transmit Data Register Empty mask */
  1857. #define UART4_SR_TC ((uint8_t)0x40) /*!< Transmission Complete mask */
  1858. #define UART4_SR_RXNE ((uint8_t)0x20) /*!< Read Data Register Not Empty mask */
  1859. #define UART4_SR_IDLE ((uint8_t)0x10) /*!< IDLE line detected mask */
  1860. #define UART4_SR_OR ((uint8_t)0x08) /*!< OverRun error mask */
  1861. #define UART4_SR_NF ((uint8_t)0x04) /*!< Noise Flag mask */
  1862. #define UART4_SR_FE ((uint8_t)0x02) /*!< Framing Error mask */
  1863. #define UART4_SR_PE ((uint8_t)0x01) /*!< Parity Error mask */
  1864. #define UART4_BRR1_DIVM ((uint8_t)0xFF) /*!< LSB mantissa of UART4DIV [7:0] mask */
  1865. #define UART4_BRR2_DIVM ((uint8_t)0xF0) /*!< MSB mantissa of UART4DIV [11:8] mask */
  1866. #define UART4_BRR2_DIVF ((uint8_t)0x0F) /*!< Fraction bits of UART4DIV [3:0] mask */
  1867. #define UART4_CR1_R8 ((uint8_t)0x80) /*!< Receive Data bit 8 */
  1868. #define UART4_CR1_T8 ((uint8_t)0x40) /*!< Transmit data bit 8 */
  1869. #define UART4_CR1_UARTD ((uint8_t)0x20) /*!< UART4 Disable (for low power consumption) */
  1870. #define UART4_CR1_M ((uint8_t)0x10) /*!< Word length mask */
  1871. #define UART4_CR1_WAKE ((uint8_t)0x08) /*!< Wake-up method mask */
  1872. #define UART4_CR1_PCEN ((uint8_t)0x04) /*!< Parity Control Enable mask */
  1873. #define UART4_CR1_PS ((uint8_t)0x02) /*!< UART4 Parity Selection */
  1874. #define UART4_CR1_PIEN ((uint8_t)0x01) /*!< UART4 Parity Interrupt Enable mask */
  1875. #define UART4_CR2_TIEN ((uint8_t)0x80) /*!< Transmitter Interrupt Enable mask */
  1876. #define UART4_CR2_TCIEN ((uint8_t)0x40) /*!< Transmission Complete Interrupt Enable mask */
  1877. #define UART4_CR2_RIEN ((uint8_t)0x20) /*!< Receiver Interrupt Enable mask */
  1878. #define UART4_CR2_ILIEN ((uint8_t)0x10) /*!< IDLE Line Interrupt Enable mask */
  1879. #define UART4_CR2_TEN ((uint8_t)0x08) /*!< Transmitter Enable mask */
  1880. #define UART4_CR2_REN ((uint8_t)0x04) /*!< Receiver Enable mask */
  1881. #define UART4_CR2_RWU ((uint8_t)0x02) /*!< Receiver Wake-Up mask */
  1882. #define UART4_CR2_SBK ((uint8_t)0x01) /*!< Send Break mask */
  1883. #define UART4_CR3_LINEN ((uint8_t)0x40) /*!< Alternate Function output mask */
  1884. #define UART4_CR3_STOP ((uint8_t)0x30) /*!< STOP bits [1:0] mask */
  1885. #define UART4_CR3_CKEN ((uint8_t)0x08) /*!< Clock Enable mask */
  1886. #define UART4_CR3_CPOL ((uint8_t)0x04) /*!< Clock Polarity mask */
  1887. #define UART4_CR3_CPHA ((uint8_t)0x02) /*!< Clock Phase mask */
  1888. #define UART4_CR3_LBCL ((uint8_t)0x01) /*!< Last Bit Clock pulse mask */
  1889. #define UART4_CR4_LBDIEN ((uint8_t)0x40) /*!< LIN Break Detection Interrupt Enable mask */
  1890. #define UART4_CR4_LBDL ((uint8_t)0x20) /*!< LIN Break Detection Length mask */
  1891. #define UART4_CR4_LBDF ((uint8_t)0x10) /*!< LIN Break Detection Flag mask */
  1892. #define UART4_CR4_ADD ((uint8_t)0x0F) /*!< Address of the UART4 node mask */
  1893. #define UART4_CR5_SCEN ((uint8_t)0x20) /*!< Smart Card Enable mask */
  1894. #define UART4_CR5_NACK ((uint8_t)0x10) /*!< Smart Card Nack Enable mask */
  1895. #define UART4_CR5_HDSEL ((uint8_t)0x08) /*!< Half-Duplex Selection mask */
  1896. #define UART4_CR5_IRLP ((uint8_t)0x04) /*!< Irda Low Power Selection mask */
  1897. #define UART4_CR5_IREN ((uint8_t)0x02) /*!< Irda Enable mask */
  1898. #define UART4_CR6_LDUM ((uint8_t)0x80) /*!< LIN Divider Update Method */
  1899. #define UART4_CR6_LSLV ((uint8_t)0x20) /*!< LIN Slave Enable */
  1900. #define UART4_CR6_LASE ((uint8_t)0x10) /*!< LIN Auto synchronization Enable */
  1901. #define UART4_CR6_LHDIEN ((uint8_t)0x04) /*!< LIN Header Detection Interrupt Enable */
  1902. #define UART4_CR6_LHDF ((uint8_t)0x02) /*!< LIN Header Detection Flag */
  1903. #define UART4_CR6_LSF ((uint8_t)0x01) /*!< LIN Synch Field */
  1904. #endif /* STM8AF622x */
  1905. /**
  1906. * @}
  1907. */
  1908. /*----------------------------------------------------------------------------*/
  1909. /*----------------------------------------------------------------------------*/
  1910. /**
  1911. * @brief Controller Area Network (CAN)
  1912. */
  1913. typedef struct {
  1914. __IO uint8_t MCR; /*!< CAN master control register */
  1915. __IO uint8_t MSR; /*!< CAN master status register */
  1916. __IO uint8_t TSR; /*!< CAN transmit status register */
  1917. __IO uint8_t TPR; /*!< CAN transmit priority register */
  1918. __IO uint8_t RFR; /*!< CAN receive FIFO register */
  1919. __IO uint8_t IER; /*!< CAN interrupt enable register */
  1920. __IO uint8_t DGR; /*!< CAN diagnosis register */
  1921. __IO uint8_t PSR; /*!< CAN page selection register */
  1922. union {
  1923. struct {
  1924. __IO uint8_t MCSR;
  1925. __IO uint8_t MDLCR;
  1926. __IO uint8_t MIDR1;
  1927. __IO uint8_t MIDR2;
  1928. __IO uint8_t MIDR3;
  1929. __IO uint8_t MIDR4;
  1930. __IO uint8_t MDAR1;
  1931. __IO uint8_t MDAR2;
  1932. __IO uint8_t MDAR3;
  1933. __IO uint8_t MDAR4;
  1934. __IO uint8_t MDAR5;
  1935. __IO uint8_t MDAR6;
  1936. __IO uint8_t MDAR7;
  1937. __IO uint8_t MDAR8;
  1938. __IO uint8_t MTSRL;
  1939. __IO uint8_t MTSRH;
  1940. } TxMailbox;
  1941. struct {
  1942. __IO uint8_t FR01;
  1943. __IO uint8_t FR02;
  1944. __IO uint8_t FR03;
  1945. __IO uint8_t FR04;
  1946. __IO uint8_t FR05;
  1947. __IO uint8_t FR06;
  1948. __IO uint8_t FR07;
  1949. __IO uint8_t FR08;
  1950. __IO uint8_t FR09;
  1951. __IO uint8_t FR10;
  1952. __IO uint8_t FR11;
  1953. __IO uint8_t FR12;
  1954. __IO uint8_t FR13;
  1955. __IO uint8_t FR14;
  1956. __IO uint8_t FR15;
  1957. __IO uint8_t FR16;
  1958. } Filter;
  1959. struct {
  1960. __IO uint8_t F0R1;
  1961. __IO uint8_t F0R2;
  1962. __IO uint8_t F0R3;
  1963. __IO uint8_t F0R4;
  1964. __IO uint8_t F0R5;
  1965. __IO uint8_t F0R6;
  1966. __IO uint8_t F0R7;
  1967. __IO uint8_t F0R8;
  1968. __IO uint8_t F1R1;
  1969. __IO uint8_t F1R2;
  1970. __IO uint8_t F1R3;
  1971. __IO uint8_t F1R4;
  1972. __IO uint8_t F1R5;
  1973. __IO uint8_t F1R6;
  1974. __IO uint8_t F1R7;
  1975. __IO uint8_t F1R8;
  1976. } Filter01;
  1977. struct {
  1978. __IO uint8_t F2R1;
  1979. __IO uint8_t F2R2;
  1980. __IO uint8_t F2R3;
  1981. __IO uint8_t F2R4;
  1982. __IO uint8_t F2R5;
  1983. __IO uint8_t F2R6;
  1984. __IO uint8_t F2R7;
  1985. __IO uint8_t F2R8;
  1986. __IO uint8_t F3R1;
  1987. __IO uint8_t F3R2;
  1988. __IO uint8_t F3R3;
  1989. __IO uint8_t F3R4;
  1990. __IO uint8_t F3R5;
  1991. __IO uint8_t F3R6;
  1992. __IO uint8_t F3R7;
  1993. __IO uint8_t F3R8;
  1994. } Filter23;
  1995. struct {
  1996. __IO uint8_t F4R1;
  1997. __IO uint8_t F4R2;
  1998. __IO uint8_t F4R3;
  1999. __IO uint8_t F4R4;
  2000. __IO uint8_t F4R5;
  2001. __IO uint8_t F4R6;
  2002. __IO uint8_t F4R7;
  2003. __IO uint8_t F4R8;
  2004. __IO uint8_t F5R1;
  2005. __IO uint8_t F5R2;
  2006. __IO uint8_t F5R3;
  2007. __IO uint8_t F5R4;
  2008. __IO uint8_t F5R5;
  2009. __IO uint8_t F5R6;
  2010. __IO uint8_t F5R7;
  2011. __IO uint8_t F5R8;
  2012. } Filter45;
  2013. struct {
  2014. __IO uint8_t ESR;
  2015. __IO uint8_t EIER;
  2016. __IO uint8_t TECR;
  2017. __IO uint8_t RECR;
  2018. __IO uint8_t BTR1;
  2019. __IO uint8_t BTR2;
  2020. uint8_t Reserved1[2];
  2021. __IO uint8_t FMR1;
  2022. __IO uint8_t FMR2;
  2023. __IO uint8_t FCR1;
  2024. __IO uint8_t FCR2;
  2025. __IO uint8_t FCR3;
  2026. uint8_t Reserved2[3];
  2027. } Config;
  2028. struct {
  2029. __IO uint8_t MFMI;
  2030. __IO uint8_t MDLCR;
  2031. __IO uint8_t MIDR1;
  2032. __IO uint8_t MIDR2;
  2033. __IO uint8_t MIDR3;
  2034. __IO uint8_t MIDR4;
  2035. __IO uint8_t MDAR1;
  2036. __IO uint8_t MDAR2;
  2037. __IO uint8_t MDAR3;
  2038. __IO uint8_t MDAR4;
  2039. __IO uint8_t MDAR5;
  2040. __IO uint8_t MDAR6;
  2041. __IO uint8_t MDAR7;
  2042. __IO uint8_t MDAR8;
  2043. __IO uint8_t MTSRL;
  2044. __IO uint8_t MTSRH;
  2045. } RxFIFO;
  2046. } Page;
  2047. } CAN_TypeDef;
  2048. /** @addtogroup CAN_Registers_Bits_Definition
  2049. * @{
  2050. */
  2051. /******************************* Common ***************************************/
  2052. /* CAN Master Control Register bits */
  2053. #define CAN_MCR_INRQ ((uint8_t)0x01)
  2054. #define CAN_MCR_SLEEP ((uint8_t)0x02)
  2055. #define CAN_MCR_TXFP ((uint8_t)0x04)
  2056. #define CAN_MCR_RFLM ((uint8_t)0x08)
  2057. #define CAN_MCR_NART ((uint8_t)0x10)
  2058. #define CAN_MCR_AWUM ((uint8_t)0x20)
  2059. #define CAN_MCR_ABOM ((uint8_t)0x40)
  2060. #define CAN_MCR_TTCM ((uint8_t)0x80)
  2061. /* CAN Master Status Register bits */
  2062. #define CAN_MSR_INAK ((uint8_t)0x01)
  2063. #define CAN_MSR_SLAK ((uint8_t)0x02)
  2064. #define CAN_MSR_ERRI ((uint8_t)0x04)
  2065. #define CAN_MSR_WKUI ((uint8_t)0x08)
  2066. #define CAN_MSR_TX ((uint8_t)0x10)
  2067. #define CAN_MSR_RX ((uint8_t)0x20)
  2068. /* CAN Transmit Status Register bits */
  2069. #define CAN_TSR_RQCP0 ((uint8_t)0x01)
  2070. #define CAN_TSR_RQCP1 ((uint8_t)0x02)
  2071. #define CAN_TSR_RQCP2 ((uint8_t)0x04)
  2072. #define CAN_TSR_RQCP012 ((uint8_t)0x07)
  2073. #define CAN_TSR_TXOK0 ((uint8_t)0x10)
  2074. #define CAN_TSR_TXOK1 ((uint8_t)0x20)
  2075. #define CAN_TSR_TXOK2 ((uint8_t)0x40)
  2076. #define CAN_TPR_CODE0 ((uint8_t)0x01)
  2077. #define CAN_TPR_TME0 ((uint8_t)0x04)
  2078. #define CAN_TPR_TME1 ((uint8_t)0x08)
  2079. #define CAN_TPR_TME2 ((uint8_t)0x10)
  2080. #define CAN_TPR_LOW0 ((uint8_t)0x20)
  2081. #define CAN_TPR_LOW1 ((uint8_t)0x40)
  2082. #define CAN_TPR_LOW2 ((uint8_t)0x80)
  2083. /* CAN Receive FIFO Register bits */
  2084. #define CAN_RFR_FMP01 ((uint8_t)0x03)
  2085. #define CAN_RFR_FULL ((uint8_t)0x08)
  2086. #define CAN_RFR_FOVR ((uint8_t)0x10)
  2087. #define CAN_RFR_RFOM ((uint8_t)0x20)
  2088. /* CAN Interrupt Register bits */
  2089. #define CAN_IER_TMEIE ((uint8_t)0x01)
  2090. #define CAN_IER_FMPIE ((uint8_t)0x02)
  2091. #define CAN_IER_FFIE ((uint8_t)0x04)
  2092. #define CAN_IER_FOVIE ((uint8_t)0x08)
  2093. #define CAN_IER_WKUIE ((uint8_t)0x80)
  2094. /* CAN diagnostic Register bits */
  2095. #define CAN_DGR_LBKM ((uint8_t)0x01)
  2096. #define CAN_DGR_SLIM ((uint8_t)0x02)
  2097. #define CAN_DGR_SAMP ((uint8_t)0x04)
  2098. #define CAN_DGR_RX ((uint8_t)0x08)
  2099. #define CAN_DGR_TXM2E ((uint8_t)0x10)
  2100. /* CAN page select Register bits */
  2101. #define CAN_PSR_PS0 ((uint8_t)0x01)
  2102. #define CAN_PSR_PS1 ((uint8_t)0x02)
  2103. #define CAN_PSR_PS2 ((uint8_t)0x04)
  2104. /******************** Tx MailBox & Fifo Page common bits **********************/
  2105. #define CAN_MCSR_TXRQ ((uint8_t)0x01)
  2106. #define CAN_MCSR_ABRQ ((uint8_t)0x02)
  2107. #define CAN_MCSR_RQCP ((uint8_t)0x04)
  2108. #define CAN_MCSR_TXOK ((uint8_t)0x08)
  2109. #define CAN_MCSR_ALST ((uint8_t)0x10)
  2110. #define CAN_MCSR_TERR ((uint8_t)0x20)
  2111. #define CAN_MDLCR_DLC ((uint8_t)0x0F)
  2112. #define CAN_MDLCR_TGT ((uint8_t)0x80)
  2113. #define CAN_MIDR1_RTR ((uint8_t)0x20)
  2114. #define CAN_MIDR1_IDE ((uint8_t)0x40)
  2115. /************************* Filter Page ****************************************/
  2116. /* CAN Error Status Register bits */
  2117. #define CAN_ESR_EWGF ((uint8_t)0x01)
  2118. #define CAN_ESR_EPVF ((uint8_t)0x02)
  2119. #define CAN_ESR_BOFF ((uint8_t)0x04)
  2120. #define CAN_ESR_LEC0 ((uint8_t)0x10)
  2121. #define CAN_ESR_LEC1 ((uint8_t)0x20)
  2122. #define CAN_ESR_LEC2 ((uint8_t)0x40)
  2123. #define CAN_ESR_LEC ((uint8_t)0x70)
  2124. /* CAN Error Status Register bits */
  2125. #define CAN_EIER_EWGIE ((uint8_t)0x01)
  2126. #define CAN_EIER_EPVIE ((uint8_t)0x02)
  2127. #define CAN_EIER_BOFIE ((uint8_t)0x04)
  2128. #define CAN_EIER_LECIE ((uint8_t)0x10)
  2129. #define CAN_EIER_ERRIE ((uint8_t)0x80)
  2130. /* CAN transmit error counter Register bits(CAN_TECR) */
  2131. #define CAN_TECR_TEC0 ((uint8_t)0x01)
  2132. #define CAN_TECR_TEC1 ((uint8_t)0x02)
  2133. #define CAN_TECR_TEC2 ((uint8_t)0x04)
  2134. #define CAN_TECR_TEC3 ((uint8_t)0x08)
  2135. #define CAN_TECR_TEC4 ((uint8_t)0x10)
  2136. #define CAN_TECR_TEC5 ((uint8_t)0x20)
  2137. #define CAN_TECR_TEC6 ((uint8_t)0x40)
  2138. #define CAN_TECR_TEC7 ((uint8_t)0x80)
  2139. /* CAN RECEIVE error counter Register bits(CAN_TECR) */
  2140. #define CAN_RECR_REC0 ((uint8_t)0x01)
  2141. #define CAN_RECR_REC1 ((uint8_t)0x02)
  2142. #define CAN_RECR_REC2 ((uint8_t)0x04)
  2143. #define CAN_RECR_REC3 ((uint8_t)0x08)
  2144. #define CAN_RECR_REC4 ((uint8_t)0x10)
  2145. #define CAN_RECR_REC5 ((uint8_t)0x20)
  2146. #define CAN_RECR_REC6 ((uint8_t)0x40)
  2147. #define CAN_RECR_REC7 ((uint8_t)0x80)
  2148. /* CAN filter mode register bits (CAN_FMR) */
  2149. #define CAN_FMR1_FML0 ((uint8_t)0x01)
  2150. #define CAN_FMR1_FMH0 ((uint8_t)0x02)
  2151. #define CAN_FMR1_FML1 ((uint8_t)0x04)
  2152. #define CAN_FMR1_FMH1 ((uint8_t)0x08)
  2153. #define CAN_FMR1_FML2 ((uint8_t)0x10)
  2154. #define CAN_FMR1_FMH2 ((uint8_t)0x20)
  2155. #define CAN_FMR1_FML3 ((uint8_t)0x40)
  2156. #define CAN_FMR1_FMH3 ((uint8_t)0x80)
  2157. #define CAN_FMR2_FML4 ((uint8_t)0x01)
  2158. #define CAN_FMR2_FMH4 ((uint8_t)0x02)
  2159. #define CAN_FMR2_FML5 ((uint8_t)0x04)
  2160. #define CAN_FMR2_FMH5 ((uint8_t)0x08)
  2161. /* CAN filter Config register bits (CAN_FCR) */
  2162. #define CAN_FCR1_FACT0 ((uint8_t)0x01)
  2163. #define CAN_FCR1_FACT1 ((uint8_t)0x10)
  2164. #define CAN_FCR2_FACT2 ((uint8_t)0x01)
  2165. #define CAN_FCR2_FACT3 ((uint8_t)0x10)
  2166. #define CAN_FCR3_FACT4 ((uint8_t)0x01)
  2167. #define CAN_FCR3_FACT5 ((uint8_t)0x10)
  2168. #define CAN_FCR1_FSC00 ((uint8_t)0x02)
  2169. #define CAN_FCR1_FSC01 ((uint8_t)0x04)
  2170. #define CAN_FCR1_FSC10 ((uint8_t)0x20)
  2171. #define CAN_FCR1_FSC11 ((uint8_t)0x40)
  2172. #define CAN_FCR2_FSC20 ((uint8_t)0x02)
  2173. #define CAN_FCR2_FSC21 ((uint8_t)0x04)
  2174. #define CAN_FCR2_FSC30 ((uint8_t)0x20)
  2175. #define CAN_FCR2_FSC31 ((uint8_t)0x40)
  2176. #define CAN_FCR3_FSC40 ((uint8_t)0x02)
  2177. #define CAN_FCR3_FSC41 ((uint8_t)0x04)
  2178. #define CAN_FCR3_FSC50 ((uint8_t)0x20)
  2179. #define CAN_FCR3_FSC51 ((uint8_t)0x40)
  2180. /**
  2181. * @}
  2182. */
  2183. /** @addtogroup CAN_Registers_Reset_Value
  2184. * @{
  2185. */
  2186. #define CAN_MCR_RESET_VALUE ((uint8_t)0x02)
  2187. #define CAN_MSR_RESET_VALUE ((uint8_t)0x02)
  2188. #define CAN_TSR_RESET_VALUE ((uint8_t)0x00)
  2189. #define CAN_TPR_RESET_VALUE ((uint8_t)0x0C)
  2190. #define CAN_RFR_RESET_VALUE ((uint8_t)0x00)
  2191. #define CAN_IER_RESET_VALUE ((uint8_t)0x00)
  2192. #define CAN_DGR_RESET_VALUE ((uint8_t)0x0C)
  2193. #define CAN_PSR_RESET_VALUE ((uint8_t)0x00)
  2194. #define CAN_ESR_RESET_VALUE ((uint8_t)0x00)
  2195. #define CAN_EIER_RESET_VALUE ((uint8_t)0x00)
  2196. #define CAN_TECR_RESET_VALUE ((uint8_t)0x00)
  2197. #define CAN_RECR_RESET_VALUE ((uint8_t)0x00)
  2198. #define CAN_BTR1_RESET_VALUE ((uint8_t)0x40)
  2199. #define CAN_BTR2_RESET_VALUE ((uint8_t)0x23)
  2200. #define CAN_FMR1_RESET_VALUE ((uint8_t)0x00)
  2201. #define CAN_FMR2_RESET_VALUE ((uint8_t)0x00)
  2202. #define CAN_FCR_RESET_VALUE ((uint8_t)0x00)
  2203. #define CAN_MFMI_RESET_VALUE ((uint8_t)0x00)
  2204. #define CAN_MDLC_RESET_VALUE ((uint8_t)0x00)
  2205. #define CAN_MCSR_RESET_VALUE ((uint8_t)0x00)
  2206. /**
  2207. * @}
  2208. */
  2209. /**
  2210. * @brief Configuration Registers (CFG)
  2211. */
  2212. typedef struct CFG_struct {
  2213. __IO uint8_t GCR; /*!< Global Configuration register */
  2214. }
  2215. CFG_TypeDef;
  2216. /** @addtogroup CFG_Registers_Reset_Value
  2217. * @{
  2218. */
  2219. #define CFG_GCR_RESET_VALUE ((uint8_t)0x00)
  2220. /**
  2221. * @}
  2222. */
  2223. /** @addtogroup CFG_Registers_Bits_Definition
  2224. * @{
  2225. */
  2226. #define CFG_GCR_SWD ((uint8_t)0x01) /*!< Swim disable bit mask */
  2227. #define CFG_GCR_AL ((uint8_t)0x02) /*!< Activation Level bit mask */
  2228. /**
  2229. * @}
  2230. */
  2231. /**
  2232. * @}
  2233. */
  2234. /******************************************************************************/
  2235. /* Peripherals Base Address */
  2236. /******************************************************************************/
  2237. /** @addtogroup MAP_FILE_Base_Addresses
  2238. * @{
  2239. */
  2240. #define OPT_BaseAddress 0x4800
  2241. #define GPIOA_BaseAddress 0x5000
  2242. #define GPIOB_BaseAddress 0x5005
  2243. #define GPIOC_BaseAddress 0x500A
  2244. #define GPIOD_BaseAddress 0x500F
  2245. #define GPIOE_BaseAddress 0x5014
  2246. #define GPIOF_BaseAddress 0x5019
  2247. #define GPIOG_BaseAddress 0x501E
  2248. #define GPIOH_BaseAddress 0x5023
  2249. #define GPIOI_BaseAddress 0x5028
  2250. #define FLASH_BaseAddress 0x505A
  2251. #define EXTI_BaseAddress 0x50A0
  2252. #define RST_BaseAddress 0x50B3
  2253. #define CLK_BaseAddress 0x50C0
  2254. #define WWDG_BaseAddress 0x50D1
  2255. #define IWDG_BaseAddress 0x50E0
  2256. #define AWU_BaseAddress 0x50F0
  2257. #define BEEP_BaseAddress 0x50F3
  2258. #define SPI_BaseAddress 0x5200
  2259. #define I2C_BaseAddress 0x5210
  2260. #define UART1_BaseAddress 0x5230
  2261. #define UART2_BaseAddress 0x5240
  2262. #define UART3_BaseAddress 0x5240
  2263. #define UART4_BaseAddress 0x5230
  2264. #define TIM1_BaseAddress 0x5250
  2265. #define TIM2_BaseAddress 0x5300
  2266. #define TIM3_BaseAddress 0x5320
  2267. #define TIM4_BaseAddress 0x5340
  2268. #define TIM5_BaseAddress 0x5300
  2269. #define TIM6_BaseAddress 0x5340
  2270. #define ADC1_BaseAddress 0x53E0
  2271. #define ADC2_BaseAddress 0x5400
  2272. #define CAN_BaseAddress 0x5420
  2273. #define CFG_BaseAddress 0x7F60
  2274. #define ITC_BaseAddress 0x7F70
  2275. #define DM_BaseAddress 0x7F90
  2276. /**
  2277. * @}
  2278. */
  2279. /******************************************************************************/
  2280. /* Peripherals declarations */
  2281. /******************************************************************************/
  2282. #if defined(STM8S105) || defined(STM8S005) || defined(STM8S103) || defined(STM8S003) || \
  2283. defined(STM8S903) || defined(STM8AF626x) || defined(STM8AF622x)
  2284. #define ADC1 ((ADC1_TypeDef *) ADC1_BaseAddress)
  2285. #endif /* (STM8S105) ||(STM8S103) || (STM8S005) ||(STM8S003) || (STM8S903) || (STM8AF626x) || (STM8AF622x)*/
  2286. #if defined(STM8S208) || defined(STM8S207) || defined (STM8S007) || defined (STM8AF52Ax) || \
  2287. defined (STM8AF62Ax)
  2288. #define ADC2 ((ADC2_TypeDef *) ADC2_BaseAddress)
  2289. #endif /* (STM8S208) ||(STM8S207) || (STM8S007) || (STM8AF52Ax) || (STM8AF62Ax) */
  2290. #define AWU ((AWU_TypeDef *) AWU_BaseAddress)
  2291. #define BEEP ((BEEP_TypeDef *) BEEP_BaseAddress)
  2292. #if defined (STM8S208) || defined (STM8AF52Ax)
  2293. #define CAN ((CAN_TypeDef *) CAN_BaseAddress)
  2294. #endif /* (STM8S208) || (STM8AF52Ax) */
  2295. #define CLK ((CLK_TypeDef *) CLK_BaseAddress)
  2296. #define EXTI ((EXTI_TypeDef *) EXTI_BaseAddress)
  2297. #define FLASH ((FLASH_TypeDef *) FLASH_BaseAddress)
  2298. #define OPT ((OPT_TypeDef *) OPT_BaseAddress)
  2299. #define GPIOA ((GPIO_TypeDef *) GPIOA_BaseAddress)
  2300. #define GPIOB ((GPIO_TypeDef *) GPIOB_BaseAddress)
  2301. #define GPIOC ((GPIO_TypeDef *) GPIOC_BaseAddress)
  2302. #define GPIOD ((GPIO_TypeDef *) GPIOD_BaseAddress)
  2303. #define GPIOE ((GPIO_TypeDef *) GPIOE_BaseAddress)
  2304. #define GPIOF ((GPIO_TypeDef *) GPIOF_BaseAddress)
  2305. #if defined(STM8S207) || defined (STM8S007) || defined(STM8S208) || defined(STM8S105) || \
  2306. defined(STM8S005) || defined (STM8AF52Ax) || defined (STM8AF62Ax) || defined (STM8AF626x)
  2307. #define GPIOG ((GPIO_TypeDef *) GPIOG_BaseAddress)
  2308. #endif /* (STM8S208) ||(STM8S207) || (STM8S105) || (STM8AF52Ax) || (STM8AF62Ax) || (STM8AF626x) */
  2309. #if defined(STM8S207) || defined (STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || \
  2310. defined (STM8AF62Ax)
  2311. #define GPIOH ((GPIO_TypeDef *) GPIOH_BaseAddress)
  2312. #define GPIOI ((GPIO_TypeDef *) GPIOI_BaseAddress)
  2313. #endif /* (STM8S208) ||(STM8S207) || (STM8AF62Ax) || (STM8AF52Ax) */
  2314. #define RST ((RST_TypeDef *) RST_BaseAddress)
  2315. #define WWDG ((WWDG_TypeDef *) WWDG_BaseAddress)
  2316. #define IWDG ((IWDG_TypeDef *) IWDG_BaseAddress)
  2317. #define SPI ((SPI_TypeDef *) SPI_BaseAddress)
  2318. #define I2C ((I2C_TypeDef *) I2C_BaseAddress)
  2319. #if defined(STM8S208) || defined(STM8S207) || defined (STM8S007) || defined(STM8S103) || \
  2320. defined(STM8S003) || defined(STM8S903) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
  2321. #define UART1 ((UART1_TypeDef *) UART1_BaseAddress)
  2322. #endif /* (STM8S208) ||(STM8S207) || (STM8S103) || (STM8S903) || (STM8AF52Ax) || (STM8AF62Ax) */
  2323. #if defined (STM8S105) || defined (STM8S005) || defined (STM8AF626x)
  2324. #define UART2 ((UART2_TypeDef *) UART2_BaseAddress)
  2325. #endif /* STM8S105 || STM8S005 || STM8AF626x */
  2326. #if defined(STM8S208) || defined(STM8S207) || defined (STM8S007) || defined (STM8AF52Ax) || \
  2327. defined (STM8AF62Ax)
  2328. #define UART3 ((UART3_TypeDef *) UART3_BaseAddress)
  2329. #endif /* (STM8S208) ||(STM8S207) || (STM8AF62Ax) || (STM8AF52Ax) */
  2330. #if defined(STM8AF622x)
  2331. #define UART4 ((UART4_TypeDef *) UART4_BaseAddress)
  2332. #endif /* (STM8AF622x) */
  2333. #define TIM1 ((TIM1_TypeDef *) TIM1_BaseAddress)
  2334. #if defined(STM8S208) || defined(STM8S207) || defined (STM8S007) || defined(STM8S103) || \
  2335. defined(STM8S003) || defined(STM8S105) || defined(STM8S005) || defined (STM8AF52Ax) || \
  2336. defined (STM8AF62Ax) || defined (STM8AF626x)
  2337. #define TIM2 ((TIM2_TypeDef *) TIM2_BaseAddress)
  2338. #endif /* (STM8S208) ||(STM8S207) || (STM8S103) || (STM8S105) || (STM8AF52Ax) || (STM8AF62Ax) || (STM8AF626x)*/
  2339. #if defined(STM8S208) || defined(STM8S207) || defined (STM8S007) || defined(STM8S105) || \
  2340. defined(STM8S005) || defined (STM8AF52Ax) || defined (STM8AF62Ax) || defined (STM8AF626x)
  2341. #define TIM3 ((TIM3_TypeDef *) TIM3_BaseAddress)
  2342. #endif /* (STM8S208) ||(STM8S207) || (STM8S105) || (STM8AF62Ax) || (STM8AF52Ax) || (STM8AF626x)*/
  2343. #if defined(STM8S208) || defined(STM8S207) || defined (STM8S007) || defined(STM8S103) || \
  2344. defined(STM8S003) || defined(STM8S105) || defined(STM8S005) || defined (STM8AF52Ax) || \
  2345. defined (STM8AF62Ax) || defined (STM8AF626x)
  2346. #define TIM4 ((TIM4_TypeDef *) TIM4_BaseAddress)
  2347. #endif /* (STM8S208) ||(STM8S207) || (STM8S103) || (STM8S105) || (STM8AF52Ax) || (STM8AF62Ax) || (STM8AF626x)*/
  2348. #if defined (STM8S903) || defined (STM8AF622x)
  2349. #define TIM5 ((TIM5_TypeDef *) TIM5_BaseAddress)
  2350. #define TIM6 ((TIM6_TypeDef *) TIM6_BaseAddress)
  2351. #endif /* (STM8S903) || (STM8AF622x) */
  2352. #define ITC ((ITC_TypeDef *) ITC_BaseAddress)
  2353. #define CFG ((CFG_TypeDef *) CFG_BaseAddress)
  2354. #define DM ((DM_TypeDef *) DM_BaseAddress)
  2355. #ifdef USE_STDPERIPH_DRIVER
  2356. #include "stm8s_conf.h"
  2357. #endif
  2358. /* Exported macro --------------------------------------------------------------*/
  2359. /*============================== Interrupts ====================================*/
  2360. #ifdef _RAISONANCE_
  2361. #include <intrins.h>
  2362. #define enableInterrupts() _rim_() /* enable interrupts */
  2363. #define disableInterrupts() _sim_() /* disable interrupts */
  2364. #define rim() _rim_() /* enable interrupts */
  2365. #define sim() _sim_() /* disable interrupts */
  2366. #define nop() _nop_() /* No Operation */
  2367. #define trap() _trap_() /* Trap (soft IT) */
  2368. #define wfi() _wfi_() /* Wait For Interrupt */
  2369. #define halt() _halt_() /* Halt */
  2370. #elif defined(_COSMIC_)
  2371. #define enableInterrupts() {_asm("rim\n");} /* enable interrupts */
  2372. #define disableInterrupts() {_asm("sim\n");} /* disable interrupts */
  2373. #define rim() {_asm("rim\n");} /* enable interrupts */
  2374. #define sim() {_asm("sim\n");} /* disable interrupts */
  2375. #define nop() {_asm("nop\n");} /* No Operation */
  2376. #define trap() {_asm("trap\n");} /* Trap (soft IT) */
  2377. #define wfi() {_asm("wfi\n");} /* Wait For Interrupt */
  2378. #define halt() {_asm("halt\n");} /* Halt */
  2379. #elif defined(_SDCC_) // SDCC patch: for inline assembly
  2380. #define enableInterrupts() __asm__("rim") /* enable interrupts */
  2381. #define disableInterrupts() __asm__("sim") /* disable interrupts */
  2382. #define rim() __asm__("rim") /* enable interrupts */
  2383. #define sim() __asm__("sim") /* disable interrupts */
  2384. #define nop() __asm__("nop") /* No Operation */
  2385. #define trap() __asm__("trap") /* Trap (soft IT) */
  2386. #define wfi() __asm__("wfi") /* Wait For Interrupt */
  2387. #define halt() __asm__("halt") /* Halt */
  2388. #else /*_IAR_*/
  2389. #include <intrinsics.h>
  2390. #define enableInterrupts() __enable_interrupt() /* enable interrupts */
  2391. #define disableInterrupts() __disable_interrupt() /* disable interrupts */
  2392. #define rim() __enable_interrupt() /* enable interrupts */
  2393. #define sim() __disable_interrupt() /* disable interrupts */
  2394. #define nop() __no_operation() /* No Operation */
  2395. #define trap() __trap() /* Trap (soft IT) */
  2396. #define wfi() __wait_for_interrupt() /* Wait For Interrupt */
  2397. #define halt() __halt() /* Halt */
  2398. #endif /*_RAISONANCE_*/
  2399. /*============================== Interrupt vector Handling ========================*/
  2400. #ifdef _COSMIC_
  2401. #define INTERRUPT_HANDLER(a,b) @far @interrupt void a(void)
  2402. #define INTERRUPT_HANDLER_TRAP(a) void @far @interrupt a(void)
  2403. #endif /* _COSMIC_ */
  2404. #ifdef _RAISONANCE_
  2405. #define INTERRUPT_HANDLER(a,b) void a(void) interrupt b
  2406. #define INTERRUPT_HANDLER_TRAP(a) void a(void) trap
  2407. #endif /* _RAISONANCE_ */
  2408. #ifdef _IAR_
  2409. #define STRINGVECTOR(x) #x
  2410. #define VECTOR_ID(x) STRINGVECTOR( vector = (x) )
  2411. #define INTERRUPT_HANDLER( a, b ) \
  2412. _Pragma( VECTOR_ID( (b)+2 ) ) \
  2413. __interrupt void (a)( void )
  2414. #define INTERRUPT_HANDLER_TRAP(a) \
  2415. _Pragma( VECTOR_ID( 1 ) ) \
  2416. __interrupt void (a) (void)
  2417. #endif /* _IAR_ */
  2418. #ifdef _SDCC_ // SDCC patch: ISR handlers
  2419. #define INTERRUPT_HANDLER(a, b) void a() __interrupt(b)
  2420. #if (SKIP_TRAPS == 0) // SDCC patch: trap handling requires SDCC >=v3.4.3
  2421. #define INTERRUPT_HANDLER_TRAP(a) void a(void) __trap
  2422. #endif /* USE_TRAPS=1 */
  2423. #endif /* _SDCC_ */
  2424. /*============================== Interrupt Handler declaration ========================*/
  2425. #ifdef _COSMIC_
  2426. #define INTERRUPT @far @interrupt
  2427. #elif defined(_IAR_)
  2428. #define INTERRUPT __interrupt
  2429. #elif defined(_SDCC_) // SDCC patch: doesn't work, yet :-(
  2430. #define INTERRUPT __interrupt
  2431. #endif /* _COSMIC_ */
  2432. /*============================== Handling bits ====================================*/
  2433. /*-----------------------------------------------------------------------------
  2434. Method : I
  2435. Description : Handle the bit from the character variables.
  2436. Comments : The different parameters of commands are
  2437. - VAR : Name of the character variable where the bit is located.
  2438. - Place : Bit position in the variable (7 6 5 4 3 2 1 0)
  2439. - Value : Can be 0 (reset bit) or not 0 (set bit)
  2440. The "MskBit" command allows to select some bits in a source
  2441. variables and copy it in a destination var (return the value).
  2442. The "ValBit" command returns the value of a bit in a char
  2443. variable: the bit is reset if it returns 0 else the bit is set.
  2444. This method generates not an optimised code yet.
  2445. -----------------------------------------------------------------------------*/
  2446. #define SetBit(VAR, Place) ( (VAR) |= (uint8_t)((uint8_t)1<<(uint8_t)(Place)) )
  2447. #define ClrBit(VAR, Place) ( (VAR) &= (uint8_t)((uint8_t)((uint8_t)1<<(uint8_t)(Place))^(uint8_t)255) )
  2448. #define ChgBit(VAR, Place) ( (VAR) ^= (uint8_t)((uint8_t)1<<(uint8_t)(Place)) )
  2449. #define AffBit(VAR, Place, Value) ((Value) ? \
  2450. ((VAR) |= ((uint8_t)1<<(Place))) : \
  2451. ((VAR) &= (((uint8_t)1<<(Place))^(uint8_t)255)))
  2452. #define MskBit(Dest, Msk, Src) ( (Dest) = ((Msk) & (Src)) | ((~(Msk)) & (Dest)) )
  2453. #define ValBit(VAR, Place) ((uint8_t)(VAR) & (uint8_t)((uint8_t)1<<(uint8_t)(Place)))
  2454. #define BYTE_0(n) ((uint8_t)((n) & (uint8_t)0xFF)) /*!< Returns the low byte of the 32-bit value */
  2455. #define BYTE_1(n) ((uint8_t)(BYTE_0((n) >> (uint8_t)8))) /*!< Returns the second byte of the 32-bit value */
  2456. #define BYTE_2(n) ((uint8_t)(BYTE_0((n) >> (uint8_t)16))) /*!< Returns the third byte of the 32-bit value */
  2457. #define BYTE_3(n) ((uint8_t)(BYTE_0((n) >> (uint8_t)24))) /*!< Returns the high byte of the 32-bit value */
  2458. /*============================== Assert Macros ====================================*/
  2459. #define IS_STATE_VALUE_OK(SensitivityValue) \
  2460. (((SensitivityValue) == ENABLE) || \
  2461. ((SensitivityValue) == DISABLE))
  2462. /*-----------------------------------------------------------------------------
  2463. Method : II
  2464. Description : Handle directly the bit.
  2465. Comments : The idea is to handle directly with the bit name. For that, it is
  2466. necessary to have RAM area descriptions (example: HW register...)
  2467. and the following command line for each area.
  2468. This method generates the most optimized code.
  2469. -----------------------------------------------------------------------------*/
  2470. #define AREA 0x00 /* The area of bits begins at address 0x10. */
  2471. #define BitClr(BIT) ( *((unsigned char *) (AREA+(BIT)/8)) &= (~(1<<(7-(BIT)%8))) )
  2472. #define BitSet(BIT) ( *((unsigned char *) (AREA+(BIT)/8)) |= (1<<(7-(BIT)%8)) )
  2473. #define BitVal(BIT) ( *((unsigned char *) (AREA+(BIT)/8)) & (1<<(7-(BIT)%8)) )
  2474. /* Exported functions ------------------------------------------------------- */
  2475. #endif /* __STM8S_H */
  2476. /**
  2477. * @}
  2478. */
  2479. /**
  2480. * @}
  2481. */
  2482. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/