core_cm3.h 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. /**************************************************************************//**
  2. * @file core_cm3.h
  3. * @brief CMSIS Cortex-M3 Core Peripheral Access Layer Header File
  4. * @version V1.40
  5. * @date 16. February 2010
  6. *
  7. * @note
  8. * Copyright (C) 2009-2010 ARM Limited. All rights reserved.
  9. *
  10. * @par
  11. * ARM Limited (ARM) is supplying this software for use with Cortex-M
  12. * processor based microcontrollers. This file can be freely distributed
  13. * within development tools that are supporting such ARM based processors.
  14. *
  15. * @par
  16. * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  17. * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  19. * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  20. * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  21. *
  22. ******************************************************************************/
  23. #ifndef __CORE_CM3_H__
  24. #define __CORE_CM3_H__
  25. /** @addtogroup CMSIS_CM3_core_LintCinfiguration CMSIS CM3 Core Lint Configuration
  26. *
  27. * List of Lint messages which will be suppressed and not shown:
  28. * - not yet checked
  29. * .
  30. * Note: To re-enable a Message, insert a space before 'lint' *
  31. *
  32. */
  33. /** @addtogroup CMSIS_CM3_core_definitions CM3 Core Definitions
  34. This file defines all structures and symbols for CMSIS core:
  35. - CMSIS version number
  36. - Cortex-M core registers and bitfields
  37. - Cortex-M core peripheral base address
  38. @{
  39. */
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. #define __CM3_CMSIS_VERSION_MAIN (0x01) /*!< [31:16] CMSIS HAL main version */
  44. #define __CM3_CMSIS_VERSION_SUB (0x40) /*!< [15:0] CMSIS HAL sub version */
  45. #define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16) | __CM3_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number */
  46. #define __CORTEX_M (0x03) /*!< Cortex core */
  47. #ifndef __NVIC_PRIO_BITS
  48. #define __NVIC_PRIO_BITS 4 /*!< standard definition for NVIC Priority Bits */
  49. #endif
  50. #include <stdint.h> /* Include standard types */
  51. /**
  52. * IO definitions
  53. *
  54. * define access restrictions to peripheral registers
  55. */
  56. #ifdef __cplusplus
  57. #define __I volatile /*!< defines 'read only' permissions */
  58. #else
  59. #define __I volatile const /*!< defines 'read only' permissions */
  60. #endif
  61. #define __O volatile /*!< defines 'write only' permissions */
  62. #define __IO volatile /*!< defines 'read / write' permissions */
  63. /*******************************************************************************
  64. * Register Abstraction
  65. ******************************************************************************/
  66. /** @addtogroup CMSIS_CM3_core_register CMSIS CM3 Core Register
  67. @{
  68. */
  69. /** @addtogroup CMSIS_ARM_CORE CMSIS ARM Core
  70. memory mapped structure for Nested Vectored Interrupt Controller (NVIC)
  71. @{
  72. */
  73. typedef union
  74. {
  75. struct
  76. {
  77. #if (__CORTEX_M != 0x04)
  78. uint32_t _reserved0:27;
  79. #else
  80. uint32_t _reserved0:16;
  81. uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
  82. uint32_t _reserved1:7;
  83. #endif
  84. uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
  85. uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
  86. uint32_t C:1; /*!< bit: 29 Carry condition code flag */
  87. uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
  88. uint32_t N:1; /*!< bit: 31 Negative condition code flag */
  89. } b;
  90. uint32_t w;
  91. } APSR_Type;
  92. typedef union
  93. {
  94. struct
  95. {
  96. uint32_t ISR:9; /*!< bit: 00..08 Exception number */
  97. uint32_t _reserved0:23;
  98. } b;
  99. uint32_t w;
  100. } IPSR_Type;
  101. typedef union
  102. {
  103. struct
  104. {
  105. uint32_t ISR:9; /*!< bit: 00..08 Exception number */
  106. #if (__CORTEX_M != 0x04)
  107. uint32_t _reserved0:15;
  108. #else
  109. uint32_t _reserved0:7;
  110. uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
  111. uint32_t _reserved1:4;
  112. #endif
  113. uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
  114. uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */
  115. uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
  116. uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
  117. uint32_t C:1; /*!< bit: 29 Carry condition code flag */
  118. uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
  119. uint32_t N:1; /*!< bit: 31 Negative condition code flag */
  120. } b;
  121. uint32_t w;
  122. } xPSR_Type;
  123. typedef union
  124. {
  125. struct
  126. {
  127. uint32_t nPRIV:1; /*!< bit: 00 Execution privilege in Thread mode */
  128. uint32_t SPSEL:1; /*!< bit: 01 Stack to be used */
  129. uint32_t FPCA:1; /*!< bit: 02 FP extension active flag */
  130. uint32_t _reserved0:29;
  131. } b;
  132. uint32_t w;
  133. } CONTROL_Type;
  134. /*@}*/ /* end of group CMSIS_ARM_CORE */
  135. /** @addtogroup CMSIS_CM3_NVIC CMSIS CM3 NVIC
  136. memory mapped structure for Nested Vectored Interrupt Controller (NVIC)
  137. @{
  138. */
  139. typedef struct
  140. {
  141. __IO uint32_t ISER[8]; /*!< Offset: 0x000 Interrupt Set Enable Register */
  142. uint32_t RESERVED0[24];
  143. __IO uint32_t ICER[8]; /*!< Offset: 0x080 Interrupt Clear Enable Register */
  144. uint32_t RSERVED1[24];
  145. __IO uint32_t ISPR[8]; /*!< Offset: 0x100 Interrupt Set Pending Register */
  146. uint32_t RESERVED2[24];
  147. __IO uint32_t ICPR[8]; /*!< Offset: 0x180 Interrupt Clear Pending Register */
  148. uint32_t RESERVED3[24];
  149. __IO uint32_t IABR[8]; /*!< Offset: 0x200 Interrupt Active bit Register */
  150. uint32_t RESERVED4[56];
  151. __IO uint8_t IP[240]; /*!< Offset: 0x300 Interrupt Priority Register (8Bit wide) */
  152. uint32_t RESERVED5[644];
  153. __O uint32_t STIR; /*!< Offset: 0xE00 Software Trigger Interrupt Register */
  154. } NVIC_Type;
  155. /*@}*/ /* end of group CMSIS_CM3_NVIC */
  156. /** @addtogroup CMSIS_CM3_SCB CMSIS CM3 SCB
  157. memory mapped structure for System Control Block (SCB)
  158. @{
  159. */
  160. typedef struct
  161. {
  162. __I uint32_t CPUID; /*!< Offset: 0x00 CPU ID Base Register */
  163. __IO uint32_t ICSR; /*!< Offset: 0x04 Interrupt Control State Register */
  164. __IO uint32_t VTOR; /*!< Offset: 0x08 Vector Table Offset Register */
  165. __IO uint32_t AIRCR; /*!< Offset: 0x0C Application Interrupt / Reset Control Register */
  166. __IO uint32_t SCR; /*!< Offset: 0x10 System Control Register */
  167. __IO uint32_t CCR; /*!< Offset: 0x14 Configuration Control Register */
  168. __IO uint8_t SHP[12]; /*!< Offset: 0x18 System Handlers Priority Registers (4-7, 8-11, 12-15) */
  169. __IO uint32_t SHCSR; /*!< Offset: 0x24 System Handler Control and State Register */
  170. __IO uint32_t CFSR; /*!< Offset: 0x28 Configurable Fault Status Register */
  171. __IO uint32_t HFSR; /*!< Offset: 0x2C Hard Fault Status Register */
  172. __IO uint32_t DFSR; /*!< Offset: 0x30 Debug Fault Status Register */
  173. __IO uint32_t MMFAR; /*!< Offset: 0x34 Mem Manage Address Register */
  174. __IO uint32_t BFAR; /*!< Offset: 0x38 Bus Fault Address Register */
  175. __IO uint32_t AFSR; /*!< Offset: 0x3C Auxiliary Fault Status Register */
  176. __I uint32_t PFR[2]; /*!< Offset: 0x40 Processor Feature Register */
  177. __I uint32_t DFR; /*!< Offset: 0x48 Debug Feature Register */
  178. __I uint32_t ADR; /*!< Offset: 0x4C Auxiliary Feature Register */
  179. __I uint32_t MMFR[4]; /*!< Offset: 0x50 Memory Model Feature Register */
  180. __I uint32_t ISAR[5]; /*!< Offset: 0x60 ISA Feature Register */
  181. } SCB_Type;
  182. /* SCB CPUID Register Definitions */
  183. #define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */
  184. #define SCB_CPUID_IMPLEMENTER_Msk (0xFFul << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
  185. #define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */
  186. #define SCB_CPUID_VARIANT_Msk (0xFul << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
  187. #define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */
  188. #define SCB_CPUID_PARTNO_Msk (0xFFFul << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
  189. #define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */
  190. #define SCB_CPUID_REVISION_Msk (0xFul << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */
  191. /* SCB Interrupt Control State Register Definitions */
  192. #define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */
  193. #define SCB_ICSR_NMIPENDSET_Msk (1ul << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
  194. #define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */
  195. #define SCB_ICSR_PENDSVSET_Msk (1ul << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
  196. #define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */
  197. #define SCB_ICSR_PENDSVCLR_Msk (1ul << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
  198. #define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */
  199. #define SCB_ICSR_PENDSTSET_Msk (1ul << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
  200. #define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */
  201. #define SCB_ICSR_PENDSTCLR_Msk (1ul << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
  202. #define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */
  203. #define SCB_ICSR_ISRPREEMPT_Msk (1ul << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
  204. #define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */
  205. #define SCB_ICSR_ISRPENDING_Msk (1ul << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
  206. #define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */
  207. #define SCB_ICSR_VECTPENDING_Msk (0x1FFul << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
  208. #define SCB_ICSR_RETTOBASE_Pos 11 /*!< SCB ICSR: RETTOBASE Position */
  209. #define SCB_ICSR_RETTOBASE_Msk (1ul << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE Mask */
  210. #define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */
  211. #define SCB_ICSR_VECTACTIVE_Msk (0x1FFul << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */
  212. /* SCB Interrupt Control State Register Definitions */
  213. #define SCB_VTOR_TBLBASE_Pos 29 /*!< SCB VTOR: TBLBASE Position */
  214. #define SCB_VTOR_TBLBASE_Msk (0x1FFul << SCB_VTOR_TBLBASE_Pos) /*!< SCB VTOR: TBLBASE Mask */
  215. #define SCB_VTOR_TBLOFF_Pos 7 /*!< SCB VTOR: TBLOFF Position */
  216. #define SCB_VTOR_TBLOFF_Msk (0x3FFFFFul << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
  217. /* SCB Application Interrupt and Reset Control Register Definitions */
  218. #define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
  219. #define SCB_AIRCR_VECTKEY_Msk (0xFFFFul << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
  220. #define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */
  221. #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFul << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
  222. #define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */
  223. #define SCB_AIRCR_ENDIANESS_Msk (1ul << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
  224. #define SCB_AIRCR_PRIGROUP_Pos 8 /*!< SCB AIRCR: PRIGROUP Position */
  225. #define SCB_AIRCR_PRIGROUP_Msk (7ul << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */
  226. #define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */
  227. #define SCB_AIRCR_SYSRESETREQ_Msk (1ul << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
  228. #define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */
  229. #define SCB_AIRCR_VECTCLRACTIVE_Msk (1ul << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
  230. #define SCB_AIRCR_VECTRESET_Pos 0 /*!< SCB AIRCR: VECTRESET Position */
  231. #define SCB_AIRCR_VECTRESET_Msk (1ul << SCB_AIRCR_VECTRESET_Pos) /*!< SCB AIRCR: VECTRESET Mask */
  232. /* SCB System Control Register Definitions */
  233. #define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */
  234. #define SCB_SCR_SEVONPEND_Msk (1ul << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
  235. #define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */
  236. #define SCB_SCR_SLEEPDEEP_Msk (1ul << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
  237. #define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */
  238. #define SCB_SCR_SLEEPONEXIT_Msk (1ul << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
  239. /* SCB Configuration Control Register Definitions */
  240. #define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */
  241. #define SCB_CCR_STKALIGN_Msk (1ul << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
  242. #define SCB_CCR_BFHFNMIGN_Pos 8 /*!< SCB CCR: BFHFNMIGN Position */
  243. #define SCB_CCR_BFHFNMIGN_Msk (1ul << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */
  244. #define SCB_CCR_DIV_0_TRP_Pos 4 /*!< SCB CCR: DIV_0_TRP Position */
  245. #define SCB_CCR_DIV_0_TRP_Msk (1ul << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP Mask */
  246. #define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */
  247. #define SCB_CCR_UNALIGN_TRP_Msk (1ul << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
  248. #define SCB_CCR_USERSETMPEND_Pos 1 /*!< SCB CCR: USERSETMPEND Position */
  249. #define SCB_CCR_USERSETMPEND_Msk (1ul << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */
  250. #define SCB_CCR_NONBASETHRDENA_Pos 0 /*!< SCB CCR: NONBASETHRDENA Position */
  251. #define SCB_CCR_NONBASETHRDENA_Msk (1ul << SCB_CCR_NONBASETHRDENA_Pos) /*!< SCB CCR: NONBASETHRDENA Mask */
  252. /* SCB System Handler Control and State Register Definitions */
  253. #define SCB_SHCSR_USGFAULTENA_Pos 18 /*!< SCB SHCSR: USGFAULTENA Position */
  254. #define SCB_SHCSR_USGFAULTENA_Msk (1ul << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */
  255. #define SCB_SHCSR_BUSFAULTENA_Pos 17 /*!< SCB SHCSR: BUSFAULTENA Position */
  256. #define SCB_SHCSR_BUSFAULTENA_Msk (1ul << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */
  257. #define SCB_SHCSR_MEMFAULTENA_Pos 16 /*!< SCB SHCSR: MEMFAULTENA Position */
  258. #define SCB_SHCSR_MEMFAULTENA_Msk (1ul << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */
  259. #define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */
  260. #define SCB_SHCSR_SVCALLPENDED_Msk (1ul << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
  261. #define SCB_SHCSR_BUSFAULTPENDED_Pos 14 /*!< SCB SHCSR: BUSFAULTPENDED Position */
  262. #define SCB_SHCSR_BUSFAULTPENDED_Msk (1ul << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */
  263. #define SCB_SHCSR_MEMFAULTPENDED_Pos 13 /*!< SCB SHCSR: MEMFAULTPENDED Position */
  264. #define SCB_SHCSR_MEMFAULTPENDED_Msk (1ul << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */
  265. #define SCB_SHCSR_USGFAULTPENDED_Pos 12 /*!< SCB SHCSR: USGFAULTPENDED Position */
  266. #define SCB_SHCSR_USGFAULTPENDED_Msk (1ul << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */
  267. #define SCB_SHCSR_SYSTICKACT_Pos 11 /*!< SCB SHCSR: SYSTICKACT Position */
  268. #define SCB_SHCSR_SYSTICKACT_Msk (1ul << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */
  269. #define SCB_SHCSR_PENDSVACT_Pos 10 /*!< SCB SHCSR: PENDSVACT Position */
  270. #define SCB_SHCSR_PENDSVACT_Msk (1ul << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */
  271. #define SCB_SHCSR_MONITORACT_Pos 8 /*!< SCB SHCSR: MONITORACT Position */
  272. #define SCB_SHCSR_MONITORACT_Msk (1ul << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */
  273. #define SCB_SHCSR_SVCALLACT_Pos 7 /*!< SCB SHCSR: SVCALLACT Position */
  274. #define SCB_SHCSR_SVCALLACT_Msk (1ul << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */
  275. #define SCB_SHCSR_USGFAULTACT_Pos 3 /*!< SCB SHCSR: USGFAULTACT Position */
  276. #define SCB_SHCSR_USGFAULTACT_Msk (1ul << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */
  277. #define SCB_SHCSR_BUSFAULTACT_Pos 1 /*!< SCB SHCSR: BUSFAULTACT Position */
  278. #define SCB_SHCSR_BUSFAULTACT_Msk (1ul << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */
  279. #define SCB_SHCSR_MEMFAULTACT_Pos 0 /*!< SCB SHCSR: MEMFAULTACT Position */
  280. #define SCB_SHCSR_MEMFAULTACT_Msk (1ul << SCB_SHCSR_MEMFAULTACT_Pos) /*!< SCB SHCSR: MEMFAULTACT Mask */
  281. /* SCB Configurable Fault Status Registers Definitions */
  282. #define SCB_CFSR_USGFAULTSR_Pos 16 /*!< SCB CFSR: Usage Fault Status Register Position */
  283. #define SCB_CFSR_USGFAULTSR_Msk (0xFFFFul << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */
  284. #define SCB_CFSR_BUSFAULTSR_Pos 8 /*!< SCB CFSR: Bus Fault Status Register Position */
  285. #define SCB_CFSR_BUSFAULTSR_Msk (0xFFul << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */
  286. #define SCB_CFSR_MEMFAULTSR_Pos 0 /*!< SCB CFSR: Memory Manage Fault Status Register Position */
  287. #define SCB_CFSR_MEMFAULTSR_Msk (0xFFul << SCB_CFSR_MEMFAULTSR_Pos) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */
  288. /* SCB Hard Fault Status Registers Definitions */
  289. #define SCB_HFSR_DEBUGEVT_Pos 31 /*!< SCB HFSR: DEBUGEVT Position */
  290. #define SCB_HFSR_DEBUGEVT_Msk (1ul << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */
  291. #define SCB_HFSR_FORCED_Pos 30 /*!< SCB HFSR: FORCED Position */
  292. #define SCB_HFSR_FORCED_Msk (1ul << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */
  293. #define SCB_HFSR_VECTTBL_Pos 1 /*!< SCB HFSR: VECTTBL Position */
  294. #define SCB_HFSR_VECTTBL_Msk (1ul << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */
  295. /* SCB Debug Fault Status Register Definitions */
  296. #define SCB_DFSR_EXTERNAL_Pos 4 /*!< SCB DFSR: EXTERNAL Position */
  297. #define SCB_DFSR_EXTERNAL_Msk (1ul << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */
  298. #define SCB_DFSR_VCATCH_Pos 3 /*!< SCB DFSR: VCATCH Position */
  299. #define SCB_DFSR_VCATCH_Msk (1ul << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */
  300. #define SCB_DFSR_DWTTRAP_Pos 2 /*!< SCB DFSR: DWTTRAP Position */
  301. #define SCB_DFSR_DWTTRAP_Msk (1ul << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */
  302. #define SCB_DFSR_BKPT_Pos 1 /*!< SCB DFSR: BKPT Position */
  303. #define SCB_DFSR_BKPT_Msk (1ul << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */
  304. #define SCB_DFSR_HALTED_Pos 0 /*!< SCB DFSR: HALTED Position */
  305. #define SCB_DFSR_HALTED_Msk (1ul << SCB_DFSR_HALTED_Pos) /*!< SCB DFSR: HALTED Mask */
  306. /*@}*/ /* end of group CMSIS_CM3_SCB */
  307. /** @addtogroup CMSIS_CM3_SysTick CMSIS CM3 SysTick
  308. memory mapped structure for SysTick
  309. @{
  310. */
  311. typedef struct
  312. {
  313. __IO uint32_t CTRL; /*!< Offset: 0x00 SysTick Control and Status Register */
  314. __IO uint32_t LOAD; /*!< Offset: 0x04 SysTick Reload Value Register */
  315. __IO uint32_t VAL; /*!< Offset: 0x08 SysTick Current Value Register */
  316. __I uint32_t CALIB; /*!< Offset: 0x0C SysTick Calibration Register */
  317. } SysTick_Type;
  318. /* SysTick Control / Status Register Definitions */
  319. #define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
  320. #define SysTick_CTRL_COUNTFLAG_Msk (1ul << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
  321. #define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
  322. #define SysTick_CTRL_CLKSOURCE_Msk (1ul << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
  323. #define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
  324. #define SysTick_CTRL_TICKINT_Msk (1ul << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
  325. #define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
  326. #define SysTick_CTRL_ENABLE_Msk (1ul << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */
  327. /* SysTick Reload Register Definitions */
  328. #define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
  329. #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFul << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */
  330. /* SysTick Current Register Definitions */
  331. #define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
  332. #define SysTick_VAL_CURRENT_Msk (0xFFFFFFul << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */
  333. /* SysTick Calibration Register Definitions */
  334. #define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
  335. #define SysTick_CALIB_NOREF_Msk (1ul << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
  336. #define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
  337. #define SysTick_CALIB_SKEW_Msk (1ul << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
  338. #define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
  339. #define SysTick_CALIB_TENMS_Msk (0xFFFFFFul << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */
  340. /*@}*/ /* end of group CMSIS_CM3_SysTick */
  341. /** @addtogroup CMSIS_CM3_ITM CMSIS CM3 ITM
  342. memory mapped structure for Instrumentation Trace Macrocell (ITM)
  343. @{
  344. */
  345. typedef struct
  346. {
  347. __O union
  348. {
  349. __O uint8_t u8; /*!< Offset: ITM Stimulus Port 8-bit */
  350. __O uint16_t u16; /*!< Offset: ITM Stimulus Port 16-bit */
  351. __O uint32_t u32; /*!< Offset: ITM Stimulus Port 32-bit */
  352. } PORT [32]; /*!< Offset: 0x00 ITM Stimulus Port Registers */
  353. uint32_t RESERVED0[864];
  354. __IO uint32_t TER; /*!< Offset: ITM Trace Enable Register */
  355. uint32_t RESERVED1[15];
  356. __IO uint32_t TPR; /*!< Offset: ITM Trace Privilege Register */
  357. uint32_t RESERVED2[15];
  358. __IO uint32_t TCR; /*!< Offset: ITM Trace Control Register */
  359. uint32_t RESERVED3[29];
  360. __IO uint32_t IWR; /*!< Offset: ITM Integration Write Register */
  361. __IO uint32_t IRR; /*!< Offset: ITM Integration Read Register */
  362. __IO uint32_t IMCR; /*!< Offset: ITM Integration Mode Control Register */
  363. uint32_t RESERVED4[43];
  364. __IO uint32_t LAR; /*!< Offset: ITM Lock Access Register */
  365. __IO uint32_t LSR; /*!< Offset: ITM Lock Status Register */
  366. uint32_t RESERVED5[6];
  367. __I uint32_t PID4; /*!< Offset: ITM Peripheral Identification Register #4 */
  368. __I uint32_t PID5; /*!< Offset: ITM Peripheral Identification Register #5 */
  369. __I uint32_t PID6; /*!< Offset: ITM Peripheral Identification Register #6 */
  370. __I uint32_t PID7; /*!< Offset: ITM Peripheral Identification Register #7 */
  371. __I uint32_t PID0; /*!< Offset: ITM Peripheral Identification Register #0 */
  372. __I uint32_t PID1; /*!< Offset: ITM Peripheral Identification Register #1 */
  373. __I uint32_t PID2; /*!< Offset: ITM Peripheral Identification Register #2 */
  374. __I uint32_t PID3; /*!< Offset: ITM Peripheral Identification Register #3 */
  375. __I uint32_t CID0; /*!< Offset: ITM Component Identification Register #0 */
  376. __I uint32_t CID1; /*!< Offset: ITM Component Identification Register #1 */
  377. __I uint32_t CID2; /*!< Offset: ITM Component Identification Register #2 */
  378. __I uint32_t CID3; /*!< Offset: ITM Component Identification Register #3 */
  379. } ITM_Type;
  380. /* ITM Trace Privilege Register Definitions */
  381. #define ITM_TPR_PRIVMASK_Pos 0 /*!< ITM TPR: PRIVMASK Position */
  382. #define ITM_TPR_PRIVMASK_Msk (0xFul << ITM_TPR_PRIVMASK_Pos) /*!< ITM TPR: PRIVMASK Mask */
  383. /* ITM Trace Control Register Definitions */
  384. #define ITM_TCR_BUSY_Pos 23 /*!< ITM TCR: BUSY Position */
  385. #define ITM_TCR_BUSY_Msk (1ul << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */
  386. #define ITM_TCR_ATBID_Pos 16 /*!< ITM TCR: ATBID Position */
  387. #define ITM_TCR_ATBID_Msk (0x7Ful << ITM_TCR_ATBID_Pos) /*!< ITM TCR: ATBID Mask */
  388. #define ITM_TCR_TSPrescale_Pos 8 /*!< ITM TCR: TSPrescale Position */
  389. #define ITM_TCR_TSPrescale_Msk (3ul << ITM_TCR_TSPrescale_Pos) /*!< ITM TCR: TSPrescale Mask */
  390. #define ITM_TCR_SWOENA_Pos 4 /*!< ITM TCR: SWOENA Position */
  391. #define ITM_TCR_SWOENA_Msk (1ul << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */
  392. #define ITM_TCR_DWTENA_Pos 3 /*!< ITM TCR: DWTENA Position */
  393. #define ITM_TCR_DWTENA_Msk (1ul << ITM_TCR_DWTENA_Pos) /*!< ITM TCR: DWTENA Mask */
  394. #define ITM_TCR_SYNCENA_Pos 2 /*!< ITM TCR: SYNCENA Position */
  395. #define ITM_TCR_SYNCENA_Msk (1ul << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */
  396. #define ITM_TCR_TSENA_Pos 1 /*!< ITM TCR: TSENA Position */
  397. #define ITM_TCR_TSENA_Msk (1ul << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */
  398. #define ITM_TCR_ITMENA_Pos 0 /*!< ITM TCR: ITM Enable bit Position */
  399. #define ITM_TCR_ITMENA_Msk (1ul << ITM_TCR_ITMENA_Pos) /*!< ITM TCR: ITM Enable bit Mask */
  400. /* ITM Integration Write Register Definitions */
  401. #define ITM_IWR_ATVALIDM_Pos 0 /*!< ITM IWR: ATVALIDM Position */
  402. #define ITM_IWR_ATVALIDM_Msk (1ul << ITM_IWR_ATVALIDM_Pos) /*!< ITM IWR: ATVALIDM Mask */
  403. /* ITM Integration Read Register Definitions */
  404. #define ITM_IRR_ATREADYM_Pos 0 /*!< ITM IRR: ATREADYM Position */
  405. #define ITM_IRR_ATREADYM_Msk (1ul << ITM_IRR_ATREADYM_Pos) /*!< ITM IRR: ATREADYM Mask */
  406. /* ITM Integration Mode Control Register Definitions */
  407. #define ITM_IMCR_INTEGRATION_Pos 0 /*!< ITM IMCR: INTEGRATION Position */
  408. #define ITM_IMCR_INTEGRATION_Msk (1ul << ITM_IMCR_INTEGRATION_Pos) /*!< ITM IMCR: INTEGRATION Mask */
  409. /* ITM Lock Status Register Definitions */
  410. #define ITM_LSR_ByteAcc_Pos 2 /*!< ITM LSR: ByteAcc Position */
  411. #define ITM_LSR_ByteAcc_Msk (1ul << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */
  412. #define ITM_LSR_Access_Pos 1 /*!< ITM LSR: Access Position */
  413. #define ITM_LSR_Access_Msk (1ul << ITM_LSR_Access_Pos) /*!< ITM LSR: Access Mask */
  414. #define ITM_LSR_Present_Pos 0 /*!< ITM LSR: Present Position */
  415. #define ITM_LSR_Present_Msk (1ul << ITM_LSR_Present_Pos) /*!< ITM LSR: Present Mask */
  416. /*@}*/ /* end of group CMSIS_CM3_ITM */
  417. /** @addtogroup CMSIS_CM3_InterruptType CMSIS CM3 Interrupt Type
  418. memory mapped structure for Interrupt Type
  419. @{
  420. */
  421. typedef struct
  422. {
  423. uint32_t RESERVED0;
  424. __I uint32_t ICTR; /*!< Offset: 0x04 Interrupt Control Type Register */
  425. __IO uint32_t ACTLR; /*!< Offset: 0x08 Auxiliary Control Register */
  426. } InterruptType_Type;
  427. /* Interrupt Controller Type Register Definitions */
  428. #define InterruptType_ICTR_INTLINESNUM_Pos 0 /*!< InterruptType ICTR: INTLINESNUM Position */
  429. #define InterruptType_ICTR_INTLINESNUM_Msk (0x1Ful << InterruptType_ICTR_INTLINESNUM_Pos) /*!< InterruptType ICTR: INTLINESNUM Mask */
  430. /* Auxiliary Control Register Definitions */
  431. #define InterruptType_ACTLR_DISFOLD_Pos 2 /*!< InterruptType ACTLR: DISFOLD Position */
  432. #define InterruptType_ACTLR_DISFOLD_Msk (1ul << InterruptType_ACTLR_DISFOLD_Pos) /*!< InterruptType ACTLR: DISFOLD Mask */
  433. #define InterruptType_ACTLR_DISDEFWBUF_Pos 1 /*!< InterruptType ACTLR: DISDEFWBUF Position */
  434. #define InterruptType_ACTLR_DISDEFWBUF_Msk (1ul << InterruptType_ACTLR_DISDEFWBUF_Pos) /*!< InterruptType ACTLR: DISDEFWBUF Mask */
  435. #define InterruptType_ACTLR_DISMCYCINT_Pos 0 /*!< InterruptType ACTLR: DISMCYCINT Position */
  436. #define InterruptType_ACTLR_DISMCYCINT_Msk (1ul << InterruptType_ACTLR_DISMCYCINT_Pos) /*!< InterruptType ACTLR: DISMCYCINT Mask */
  437. /*@}*/ /* end of group CMSIS_CM3_InterruptType */
  438. #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1)
  439. /** @addtogroup CMSIS_CM3_MPU CMSIS CM3 MPU
  440. memory mapped structure for Memory Protection Unit (MPU)
  441. @{
  442. */
  443. typedef struct
  444. {
  445. __I uint32_t TYPE; /*!< Offset: 0x00 MPU Type Register */
  446. __IO uint32_t CTRL; /*!< Offset: 0x04 MPU Control Register */
  447. __IO uint32_t RNR; /*!< Offset: 0x08 MPU Region RNRber Register */
  448. __IO uint32_t RBAR; /*!< Offset: 0x0C MPU Region Base Address Register */
  449. __IO uint32_t RASR; /*!< Offset: 0x10 MPU Region Attribute and Size Register */
  450. __IO uint32_t RBAR_A1; /*!< Offset: 0x14 MPU Alias 1 Region Base Address Register */
  451. __IO uint32_t RASR_A1; /*!< Offset: 0x18 MPU Alias 1 Region Attribute and Size Register */
  452. __IO uint32_t RBAR_A2; /*!< Offset: 0x1C MPU Alias 2 Region Base Address Register */
  453. __IO uint32_t RASR_A2; /*!< Offset: 0x20 MPU Alias 2 Region Attribute and Size Register */
  454. __IO uint32_t RBAR_A3; /*!< Offset: 0x24 MPU Alias 3 Region Base Address Register */
  455. __IO uint32_t RASR_A3; /*!< Offset: 0x28 MPU Alias 3 Region Attribute and Size Register */
  456. } MPU_Type;
  457. /* MPU Type Register */
  458. #define MPU_TYPE_IREGION_Pos 16 /*!< MPU TYPE: IREGION Position */
  459. #define MPU_TYPE_IREGION_Msk (0xFFul << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
  460. #define MPU_TYPE_DREGION_Pos 8 /*!< MPU TYPE: DREGION Position */
  461. #define MPU_TYPE_DREGION_Msk (0xFFul << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */
  462. #define MPU_TYPE_SEPARATE_Pos 0 /*!< MPU TYPE: SEPARATE Position */
  463. #define MPU_TYPE_SEPARATE_Msk (1ul << MPU_TYPE_SEPARATE_Pos) /*!< MPU TYPE: SEPARATE Mask */
  464. /* MPU Control Register */
  465. #define MPU_CTRL_PRIVDEFENA_Pos 2 /*!< MPU CTRL: PRIVDEFENA Position */
  466. #define MPU_CTRL_PRIVDEFENA_Msk (1ul << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */
  467. #define MPU_CTRL_HFNMIENA_Pos 1 /*!< MPU CTRL: HFNMIENA Position */
  468. #define MPU_CTRL_HFNMIENA_Msk (1ul << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */
  469. #define MPU_CTRL_ENABLE_Pos 0 /*!< MPU CTRL: ENABLE Position */
  470. #define MPU_CTRL_ENABLE_Msk (1ul << MPU_CTRL_ENABLE_Pos) /*!< MPU CTRL: ENABLE Mask */
  471. /* MPU Region Number Register */
  472. #define MPU_RNR_REGION_Pos 0 /*!< MPU RNR: REGION Position */
  473. #define MPU_RNR_REGION_Msk (0xFFul << MPU_RNR_REGION_Pos) /*!< MPU RNR: REGION Mask */
  474. /* MPU Region Base Address Register */
  475. #define MPU_RBAR_ADDR_Pos 5 /*!< MPU RBAR: ADDR Position */
  476. #define MPU_RBAR_ADDR_Msk (0x7FFFFFFul << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */
  477. #define MPU_RBAR_VALID_Pos 4 /*!< MPU RBAR: VALID Position */
  478. #define MPU_RBAR_VALID_Msk (1ul << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */
  479. #define MPU_RBAR_REGION_Pos 0 /*!< MPU RBAR: REGION Position */
  480. #define MPU_RBAR_REGION_Msk (0xFul << MPU_RBAR_REGION_Pos) /*!< MPU RBAR: REGION Mask */
  481. /* MPU Region Attribute and Size Register */
  482. #define MPU_RASR_XN_Pos 28 /*!< MPU RASR: XN Position */
  483. #define MPU_RASR_XN_Msk (1ul << MPU_RASR_XN_Pos) /*!< MPU RASR: XN Mask */
  484. #define MPU_RASR_AP_Pos 24 /*!< MPU RASR: AP Position */
  485. #define MPU_RASR_AP_Msk (7ul << MPU_RASR_AP_Pos) /*!< MPU RASR: AP Mask */
  486. #define MPU_RASR_TEX_Pos 19 /*!< MPU RASR: TEX Position */
  487. #define MPU_RASR_TEX_Msk (7ul << MPU_RASR_TEX_Pos) /*!< MPU RASR: TEX Mask */
  488. #define MPU_RASR_S_Pos 18 /*!< MPU RASR: Shareable bit Position */
  489. #define MPU_RASR_S_Msk (1ul << MPU_RASR_S_Pos) /*!< MPU RASR: Shareable bit Mask */
  490. #define MPU_RASR_C_Pos 17 /*!< MPU RASR: Cacheable bit Position */
  491. #define MPU_RASR_C_Msk (1ul << MPU_RASR_C_Pos) /*!< MPU RASR: Cacheable bit Mask */
  492. #define MPU_RASR_B_Pos 16 /*!< MPU RASR: Bufferable bit Position */
  493. #define MPU_RASR_B_Msk (1ul << MPU_RASR_B_Pos) /*!< MPU RASR: Bufferable bit Mask */
  494. #define MPU_RASR_SRD_Pos 8 /*!< MPU RASR: Sub-Region Disable Position */
  495. #define MPU_RASR_SRD_Msk (0xFFul << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */
  496. #define MPU_RASR_SIZE_Pos 1 /*!< MPU RASR: Region Size Field Position */
  497. #define MPU_RASR_SIZE_Msk (0x1Ful << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */
  498. #define MPU_RASR_ENA_Pos 0 /*!< MPU RASR: Region enable bit Position */
  499. #define MPU_RASR_ENA_Msk (0x1Ful << MPU_RASR_ENA_Pos) /*!< MPU RASR: Region enable bit Disable Mask */
  500. /*@}*/ /* end of group CMSIS_CM3_MPU */
  501. #endif
  502. /** @addtogroup CMSIS_CM3_CoreDebug CMSIS CM3 Core Debug
  503. memory mapped structure for Core Debug Register
  504. @{
  505. */
  506. typedef struct
  507. {
  508. __IO uint32_t DHCSR; /*!< Offset: 0x00 Debug Halting Control and Status Register */
  509. __O uint32_t DCRSR; /*!< Offset: 0x04 Debug Core Register Selector Register */
  510. __IO uint32_t DCRDR; /*!< Offset: 0x08 Debug Core Register Data Register */
  511. __IO uint32_t DEMCR; /*!< Offset: 0x0C Debug Exception and Monitor Control Register */
  512. } CoreDebug_Type;
  513. /* Debug Halting Control and Status Register */
  514. #define CoreDebug_DHCSR_DBGKEY_Pos 16 /*!< CoreDebug DHCSR: DBGKEY Position */
  515. #define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFul << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */
  516. #define CoreDebug_DHCSR_S_RESET_ST_Pos 25 /*!< CoreDebug DHCSR: S_RESET_ST Position */
  517. #define CoreDebug_DHCSR_S_RESET_ST_Msk (1ul << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */
  518. #define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24 /*!< CoreDebug DHCSR: S_RETIRE_ST Position */
  519. #define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1ul << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */
  520. #define CoreDebug_DHCSR_S_LOCKUP_Pos 19 /*!< CoreDebug DHCSR: S_LOCKUP Position */
  521. #define CoreDebug_DHCSR_S_LOCKUP_Msk (1ul << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */
  522. #define CoreDebug_DHCSR_S_SLEEP_Pos 18 /*!< CoreDebug DHCSR: S_SLEEP Position */
  523. #define CoreDebug_DHCSR_S_SLEEP_Msk (1ul << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */
  524. #define CoreDebug_DHCSR_S_HALT_Pos 17 /*!< CoreDebug DHCSR: S_HALT Position */
  525. #define CoreDebug_DHCSR_S_HALT_Msk (1ul << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */
  526. #define CoreDebug_DHCSR_S_REGRDY_Pos 16 /*!< CoreDebug DHCSR: S_REGRDY Position */
  527. #define CoreDebug_DHCSR_S_REGRDY_Msk (1ul << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */
  528. #define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5 /*!< CoreDebug DHCSR: C_SNAPSTALL Position */
  529. #define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1ul << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */
  530. #define CoreDebug_DHCSR_C_MASKINTS_Pos 3 /*!< CoreDebug DHCSR: C_MASKINTS Position */
  531. #define CoreDebug_DHCSR_C_MASKINTS_Msk (1ul << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */
  532. #define CoreDebug_DHCSR_C_STEP_Pos 2 /*!< CoreDebug DHCSR: C_STEP Position */
  533. #define CoreDebug_DHCSR_C_STEP_Msk (1ul << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */
  534. #define CoreDebug_DHCSR_C_HALT_Pos 1 /*!< CoreDebug DHCSR: C_HALT Position */
  535. #define CoreDebug_DHCSR_C_HALT_Msk (1ul << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */
  536. #define CoreDebug_DHCSR_C_DEBUGEN_Pos 0 /*!< CoreDebug DHCSR: C_DEBUGEN Position */
  537. #define CoreDebug_DHCSR_C_DEBUGEN_Msk (1ul << CoreDebug_DHCSR_C_DEBUGEN_Pos) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */
  538. /* Debug Core Register Selector Register */
  539. #define CoreDebug_DCRSR_REGWnR_Pos 16 /*!< CoreDebug DCRSR: REGWnR Position */
  540. #define CoreDebug_DCRSR_REGWnR_Msk (1ul << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */
  541. #define CoreDebug_DCRSR_REGSEL_Pos 0 /*!< CoreDebug DCRSR: REGSEL Position */
  542. #define CoreDebug_DCRSR_REGSEL_Msk (0x1Ful << CoreDebug_DCRSR_REGSEL_Pos) /*!< CoreDebug DCRSR: REGSEL Mask */
  543. /* Debug Exception and Monitor Control Register */
  544. #define CoreDebug_DEMCR_TRCENA_Pos 24 /*!< CoreDebug DEMCR: TRCENA Position */
  545. #define CoreDebug_DEMCR_TRCENA_Msk (1ul << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */
  546. #define CoreDebug_DEMCR_MON_REQ_Pos 19 /*!< CoreDebug DEMCR: MON_REQ Position */
  547. #define CoreDebug_DEMCR_MON_REQ_Msk (1ul << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */
  548. #define CoreDebug_DEMCR_MON_STEP_Pos 18 /*!< CoreDebug DEMCR: MON_STEP Position */
  549. #define CoreDebug_DEMCR_MON_STEP_Msk (1ul << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */
  550. #define CoreDebug_DEMCR_MON_PEND_Pos 17 /*!< CoreDebug DEMCR: MON_PEND Position */
  551. #define CoreDebug_DEMCR_MON_PEND_Msk (1ul << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */
  552. #define CoreDebug_DEMCR_MON_EN_Pos 16 /*!< CoreDebug DEMCR: MON_EN Position */
  553. #define CoreDebug_DEMCR_MON_EN_Msk (1ul << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */
  554. #define CoreDebug_DEMCR_VC_HARDERR_Pos 10 /*!< CoreDebug DEMCR: VC_HARDERR Position */
  555. #define CoreDebug_DEMCR_VC_HARDERR_Msk (1ul << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */
  556. #define CoreDebug_DEMCR_VC_INTERR_Pos 9 /*!< CoreDebug DEMCR: VC_INTERR Position */
  557. #define CoreDebug_DEMCR_VC_INTERR_Msk (1ul << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */
  558. #define CoreDebug_DEMCR_VC_BUSERR_Pos 8 /*!< CoreDebug DEMCR: VC_BUSERR Position */
  559. #define CoreDebug_DEMCR_VC_BUSERR_Msk (1ul << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */
  560. #define CoreDebug_DEMCR_VC_STATERR_Pos 7 /*!< CoreDebug DEMCR: VC_STATERR Position */
  561. #define CoreDebug_DEMCR_VC_STATERR_Msk (1ul << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */
  562. #define CoreDebug_DEMCR_VC_CHKERR_Pos 6 /*!< CoreDebug DEMCR: VC_CHKERR Position */
  563. #define CoreDebug_DEMCR_VC_CHKERR_Msk (1ul << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */
  564. #define CoreDebug_DEMCR_VC_NOCPERR_Pos 5 /*!< CoreDebug DEMCR: VC_NOCPERR Position */
  565. #define CoreDebug_DEMCR_VC_NOCPERR_Msk (1ul << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */
  566. #define CoreDebug_DEMCR_VC_MMERR_Pos 4 /*!< CoreDebug DEMCR: VC_MMERR Position */
  567. #define CoreDebug_DEMCR_VC_MMERR_Msk (1ul << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */
  568. #define CoreDebug_DEMCR_VC_CORERESET_Pos 0 /*!< CoreDebug DEMCR: VC_CORERESET Position */
  569. #define CoreDebug_DEMCR_VC_CORERESET_Msk (1ul << CoreDebug_DEMCR_VC_CORERESET_Pos) /*!< CoreDebug DEMCR: VC_CORERESET Mask */
  570. /*@}*/ /* end of group CMSIS_CM3_CoreDebug */
  571. /* Memory mapping of Cortex-M3 Hardware */
  572. #define SCS_BASE (0xE000E000) /*!< System Control Space Base Address */
  573. #define ITM_BASE (0xE0000000) /*!< ITM Base Address */
  574. #define CoreDebug_BASE (0xE000EDF0) /*!< Core Debug Base Address */
  575. #define SysTick_BASE (SCS_BASE + 0x0010) /*!< SysTick Base Address */
  576. #define NVIC_BASE (SCS_BASE + 0x0100) /*!< NVIC Base Address */
  577. #define SCB_BASE (SCS_BASE + 0x0D00) /*!< System Control Block Base Address */
  578. #define InterruptType ((InterruptType_Type *) SCS_BASE) /*!< Interrupt Type Register */
  579. #define SCB ((SCB_Type *) SCB_BASE) /*!< SCB configuration struct */
  580. #define SysTick ((SysTick_Type *) SysTick_BASE) /*!< SysTick configuration struct */
  581. #define NVIC ((NVIC_Type *) NVIC_BASE) /*!< NVIC configuration struct */
  582. #define ITM ((ITM_Type *) ITM_BASE) /*!< ITM configuration struct */
  583. #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
  584. #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1)
  585. #define MPU_BASE (SCS_BASE + 0x0D90) /*!< Memory Protection Unit */
  586. #define MPU ((MPU_Type*) MPU_BASE) /*!< Memory Protection Unit */
  587. #endif
  588. /*@}*/ /* end of group CMSIS_CM3_core_register */
  589. /*******************************************************************************
  590. * Hardware Abstraction Layer
  591. ******************************************************************************/
  592. #if defined ( __CC_ARM )
  593. #define __ASM __asm /*!< asm keyword for ARM Compiler */
  594. #define __INLINE __inline /*!< inline keyword for ARM Compiler */
  595. #elif defined ( __ICCARM__ )
  596. #define __ASM __asm /*!< asm keyword for IAR Compiler */
  597. #define __INLINE inline /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */
  598. #elif defined ( __GNUC__ )
  599. #define __ASM __asm /*!< asm keyword for GNU Compiler */
  600. #define __INLINE inline /*!< inline keyword for GNU Compiler */
  601. #elif defined ( __TASKING__ )
  602. #define __ASM __asm /*!< asm keyword for TASKING Compiler */
  603. #define __INLINE inline /*!< inline keyword for TASKING Compiler */
  604. #endif
  605. /* ########################## Core Instruction Access ######################### */
  606. #include "core_cmInstr.h"
  607. /* ########################### Core Function Access ########################### */
  608. #include "core_cmFunc.h"
  609. /** @addtogroup CMSIS_CM3_Core_FunctionInterface CMSIS CM3 Core Function Interface
  610. Core Function Interface containing:
  611. - Core NVIC Functions
  612. - Core SysTick Functions
  613. - Core Reset Functions
  614. */
  615. /*@{*/
  616. /* ########################## NVIC functions #################################### */
  617. /**
  618. * @brief Set the Priority Grouping in NVIC Interrupt Controller
  619. *
  620. * @param PriorityGroup is priority grouping field
  621. *
  622. * Set the priority grouping field using the required unlock sequence.
  623. * The parameter priority_grouping is assigned to the field
  624. * SCB->AIRCR [10:8] PRIGROUP field. Only values from 0..7 are used.
  625. * In case of a conflict between priority grouping and available
  626. * priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.
  627. */
  628. static __INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
  629. {
  630. uint32_t reg_value;
  631. uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
  632. reg_value = SCB->AIRCR; /* read old register configuration */
  633. reg_value &= ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk); /* clear bits to change */
  634. reg_value = (reg_value |
  635. (0x5FA << SCB_AIRCR_VECTKEY_Pos) |
  636. (PriorityGroupTmp << 8)); /* Insert write key and priorty group */
  637. SCB->AIRCR = reg_value;
  638. }
  639. /**
  640. * @brief Get the Priority Grouping from NVIC Interrupt Controller
  641. *
  642. * @return priority grouping field
  643. *
  644. * Get the priority grouping from NVIC Interrupt Controller.
  645. * priority grouping is SCB->AIRCR [10:8] PRIGROUP field.
  646. */
  647. static __INLINE uint32_t NVIC_GetPriorityGrouping(void)
  648. {
  649. return ((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos); /* read priority grouping field */
  650. }
  651. /**
  652. * @brief Enable Interrupt in NVIC Interrupt Controller
  653. *
  654. * @param IRQn The positive number of the external interrupt to enable
  655. *
  656. * Enable a device specific interupt in the NVIC interrupt controller.
  657. * The interrupt number cannot be a negative value.
  658. */
  659. static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
  660. {
  661. NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* enable interrupt */
  662. }
  663. /**
  664. * @brief Disable the interrupt line for external interrupt specified
  665. *
  666. * @param IRQn The positive number of the external interrupt to disable
  667. *
  668. * Disable a device specific interupt in the NVIC interrupt controller.
  669. * The interrupt number cannot be a negative value.
  670. */
  671. static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
  672. {
  673. NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* disable interrupt */
  674. }
  675. /**
  676. * @brief Read the interrupt pending bit for a device specific interrupt source
  677. *
  678. * @param IRQn The number of the device specifc interrupt
  679. * @return 1 = interrupt pending, 0 = interrupt not pending
  680. *
  681. * Read the pending register in NVIC and return 1 if its status is pending,
  682. * otherwise it returns 0
  683. */
  684. static __INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
  685. {
  686. return((uint32_t) ((NVIC->ISPR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if pending else 0 */
  687. }
  688. /**
  689. * @brief Set the pending bit for an external interrupt
  690. *
  691. * @param IRQn The number of the interrupt for set pending
  692. *
  693. * Set the pending bit for the specified interrupt.
  694. * The interrupt number cannot be a negative value.
  695. */
  696. static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
  697. {
  698. NVIC->ISPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* set interrupt pending */
  699. }
  700. /**
  701. * @brief Clear the pending bit for an external interrupt
  702. *
  703. * @param IRQn The number of the interrupt for clear pending
  704. *
  705. * Clear the pending bit for the specified interrupt.
  706. * The interrupt number cannot be a negative value.
  707. */
  708. static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
  709. {
  710. NVIC->ICPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */
  711. }
  712. /**
  713. * @brief Read the active bit for an external interrupt
  714. *
  715. * @param IRQn The number of the interrupt for read active bit
  716. * @return 1 = interrupt active, 0 = interrupt not active
  717. *
  718. * Read the active register in NVIC and returns 1 if its status is active,
  719. * otherwise it returns 0.
  720. */
  721. static __INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)
  722. {
  723. return((uint32_t)((NVIC->IABR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if active else 0 */
  724. }
  725. /**
  726. * @brief Set the priority for an interrupt
  727. *
  728. * @param IRQn The number of the interrupt for set priority
  729. * @param priority The priority to set
  730. *
  731. * Set the priority for the specified interrupt. The interrupt
  732. * number can be positive to specify an external (device specific)
  733. * interrupt, or negative to specify an internal (core) interrupt.
  734. *
  735. * Note: The priority cannot be set for every core interrupt.
  736. */
  737. static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
  738. {
  739. if(IRQn < 0) {
  740. SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M3 System Interrupts */
  741. else {
  742. NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for device specific Interrupts */
  743. }
  744. /**
  745. * @brief Read the priority for an interrupt
  746. *
  747. * @param IRQn The number of the interrupt for get priority
  748. * @return The priority for the interrupt
  749. *
  750. * Read the priority for the specified interrupt. The interrupt
  751. * number can be positive to specify an external (device specific)
  752. * interrupt, or negative to specify an internal (core) interrupt.
  753. *
  754. * The returned priority value is automatically aligned to the implemented
  755. * priority bits of the microcontroller.
  756. *
  757. * Note: The priority cannot be set for every core interrupt.
  758. */
  759. static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
  760. {
  761. if(IRQn < 0) {
  762. return((uint32_t)(SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M3 system interrupts */
  763. else {
  764. return((uint32_t)(NVIC->IP[(uint32_t)(IRQn)] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
  765. }
  766. /**
  767. * @brief Encode the priority for an interrupt
  768. *
  769. * @param PriorityGroup The used priority group
  770. * @param PreemptPriority The preemptive priority value (starting from 0)
  771. * @param SubPriority The sub priority value (starting from 0)
  772. * @return The encoded priority for the interrupt
  773. *
  774. * Encode the priority for an interrupt with the given priority group,
  775. * preemptive priority value and sub priority value.
  776. * In case of a conflict between priority grouping and available
  777. * priority bits (__NVIC_PRIO_BITS) the samllest possible priority group is set.
  778. *
  779. * The returned priority value can be used for NVIC_SetPriority(...) function
  780. */
  781. static __INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
  782. {
  783. uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
  784. uint32_t PreemptPriorityBits;
  785. uint32_t SubPriorityBits;
  786. PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;
  787. SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;
  788. return (
  789. ((PreemptPriority & ((1 << (PreemptPriorityBits)) - 1)) << SubPriorityBits) |
  790. ((SubPriority & ((1 << (SubPriorityBits )) - 1)))
  791. );
  792. }
  793. /**
  794. * @brief Decode the priority of an interrupt
  795. *
  796. * @param Priority The priority for the interrupt
  797. * @param PriorityGroup The used priority group
  798. * @param pPreemptPriority The preemptive priority value (starting from 0)
  799. * @param pSubPriority The sub priority value (starting from 0)
  800. *
  801. * Decode an interrupt priority value with the given priority group to
  802. * preemptive priority value and sub priority value.
  803. * In case of a conflict between priority grouping and available
  804. * priority bits (__NVIC_PRIO_BITS) the samllest possible priority group is set.
  805. *
  806. * The priority value can be retrieved with NVIC_GetPriority(...) function
  807. */
  808. static __INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)
  809. {
  810. uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
  811. uint32_t PreemptPriorityBits;
  812. uint32_t SubPriorityBits;
  813. PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;
  814. SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;
  815. *pPreemptPriority = (Priority >> SubPriorityBits) & ((1 << (PreemptPriorityBits)) - 1);
  816. *pSubPriority = (Priority ) & ((1 << (SubPriorityBits )) - 1);
  817. }
  818. /* ################################## SysTick function ############################################ */
  819. #if (!defined (__Vendor_SysTickConfig)) || (__Vendor_SysTickConfig == 0)
  820. /**
  821. * @brief Initialize and start the SysTick counter and its interrupt.
  822. *
  823. * @param ticks number of ticks between two interrupts
  824. * @return 1 = failed, 0 = successful
  825. *
  826. * Initialise the system tick timer and its interrupt and start the
  827. * system tick timer / counter in free running mode to generate
  828. * periodical interrupts.
  829. */
  830. static __INLINE uint32_t SysTick_Config(uint32_t ticks)
  831. {
  832. if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
  833. SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */
  834. NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */
  835. SysTick->VAL = 0; /* Load the SysTick Counter Value */
  836. SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
  837. SysTick_CTRL_TICKINT_Msk |
  838. SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
  839. return (0); /* Function successful */
  840. }
  841. #endif
  842. /* ################################## Reset function ############################################ */
  843. /**
  844. * @brief Initiate a system reset request.
  845. *
  846. * Initiate a system reset request to reset the MCU
  847. */
  848. static __INLINE void NVIC_SystemReset(void)
  849. {
  850. __DSB(); /* Ensure all outstanding memory accesses included
  851. buffered write are completed before reset */
  852. SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
  853. (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
  854. SCB_AIRCR_SYSRESETREQ_Msk); /* Keep priority group unchanged */
  855. __DSB(); /* Ensure completion of memory access */
  856. while(1); /* wait until reset */
  857. }
  858. /*@}*/ /* end of group CMSIS_CM3_Core_FunctionInterface */
  859. /* ##################################### Debug In/Output function ########################################### */
  860. /** @addtogroup CMSIS_CM3_CoreDebugInterface CMSIS CM3 Core Debug Interface
  861. Core Debug Interface containing:
  862. - Core Debug Receive / Transmit Functions
  863. - Core Debug Defines
  864. - Core Debug Variables
  865. */
  866. /*@{*/
  867. extern volatile int ITM_RxBuffer; /*!< variable to receive characters */
  868. #define ITM_RXBUFFER_EMPTY 0x5AA55AA5 /*!< value identifying ITM_RxBuffer is ready for next character */
  869. /**
  870. * @brief Outputs a character via the ITM channel 0
  871. *
  872. * @param ch character to output
  873. * @return character to output
  874. *
  875. * The function outputs a character via the ITM channel 0.
  876. * The function returns when no debugger is connected that has booked the output.
  877. * It is blocking when a debugger is connected, but the previous character send is not transmitted.
  878. */
  879. static __INLINE uint32_t ITM_SendChar (uint32_t ch)
  880. {
  881. if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) && /* Trace enabled */
  882. (ITM->TCR & ITM_TCR_ITMENA_Msk) && /* ITM enabled */
  883. (ITM->TER & (1ul << 0) ) ) /* ITM Port #0 enabled */
  884. {
  885. while (ITM->PORT[0].u32 == 0);
  886. ITM->PORT[0].u8 = (uint8_t) ch;
  887. }
  888. return (ch);
  889. }
  890. /**
  891. * @brief Inputs a character via variable ITM_RxBuffer
  892. *
  893. * @return received character, -1 = no character received
  894. *
  895. * The function inputs a character via variable ITM_RxBuffer.
  896. * The function returns when no debugger is connected that has booked the output.
  897. * It is blocking when a debugger is connected, but the previous character send is not transmitted.
  898. */
  899. static __INLINE int ITM_ReceiveChar (void) {
  900. int ch = -1; /* no character available */
  901. if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) {
  902. ch = ITM_RxBuffer;
  903. ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */
  904. }
  905. return (ch);
  906. }
  907. /**
  908. * @brief Check if a character via variable ITM_RxBuffer is available
  909. *
  910. * @return 1 = character available, 0 = no character available
  911. *
  912. * The function checks variable ITM_RxBuffer whether a character is available or not.
  913. * The function returns '1' if a character is available and '0' if no character is available.
  914. */
  915. static __INLINE int ITM_CheckChar (void) {
  916. if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) {
  917. return (0); /* no character available */
  918. } else {
  919. return (1); /* character available */
  920. }
  921. }
  922. /*@}*/ /* end of group CMSIS_CM3_core_DebugInterface */
  923. #ifdef __cplusplus
  924. }
  925. #endif
  926. /*@}*/ /* end of group CMSIS_CM3_core_definitions */
  927. #endif /* __CORE_CM3_H__ */
  928. /*lint -restore */