core_cm3.h 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. /**************************************************************************//**
  2. * @file core_cm3.h
  3. * @brief CMSIS Cortex-M3 Core Peripheral Access Layer Header File
  4. * @version V2.10
  5. * @date 19. July 2011
  6. *
  7. * @note
  8. * Copyright (C) 2009-2011 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. #if defined ( __ICCARM__ )
  24. #pragma system_include /* treat file as system include file for MISRA check */
  25. #endif
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #ifndef __CORE_CM3_H_GENERIC
  30. #define __CORE_CM3_H_GENERIC
  31. /** \mainpage CMSIS Cortex-M3
  32. This documentation describes the CMSIS Cortex-M Core Peripheral Access Layer.
  33. It consists of:
  34. - Cortex-M Core Register Definitions
  35. - Cortex-M functions
  36. - Cortex-M instructions
  37. The CMSIS Cortex-M3 Core Peripheral Access Layer contains C and assembly functions that ease
  38. access to the Cortex-M Core
  39. */
  40. /** \defgroup CMSIS_MISRA_Exceptions CMSIS MISRA-C:2004 Compliance Exceptions
  41. CMSIS violates following MISRA-C2004 Rules:
  42. - Violates MISRA 2004 Required Rule 8.5, object/function definition in header file.<br>
  43. Function definitions in header files are used to allow 'inlining'.
  44. - Violates MISRA 2004 Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
  45. Unions are used for effective representation of core registers.
  46. - Violates MISRA 2004 Advisory Rule 19.7, Function-like macro defined.<br>
  47. Function-like macros are used to allow more efficient code.
  48. */
  49. /*******************************************************************************
  50. * CMSIS definitions
  51. ******************************************************************************/
  52. /** \defgroup CMSIS_core_definitions CMSIS Core Definitions
  53. This file defines all structures and symbols for CMSIS core:
  54. - CMSIS version number
  55. - Cortex-M core
  56. - Cortex-M core Revision Number
  57. @{
  58. */
  59. /* CMSIS CM3 definitions */
  60. #define __CM3_CMSIS_VERSION_MAIN (0x02) /*!< [31:16] CMSIS HAL main version */
  61. #define __CM3_CMSIS_VERSION_SUB (0x10) /*!< [15:0] CMSIS HAL sub version */
  62. #define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16) | __CM3_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number */
  63. #define __CORTEX_M (0x03) /*!< Cortex core */
  64. #if defined ( __CC_ARM )
  65. #define __ASM __asm /*!< asm keyword for ARM Compiler */
  66. #define __INLINE __inline /*!< inline keyword for ARM Compiler */
  67. #elif defined ( __ICCARM__ )
  68. #define __ASM __asm /*!< asm keyword for IAR Compiler */
  69. #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
  70. #elif defined ( __GNUC__ )
  71. #define __ASM __asm /*!< asm keyword for GNU Compiler */
  72. #define __INLINE inline /*!< inline keyword for GNU Compiler */
  73. #elif defined ( __TASKING__ )
  74. #define __ASM __asm /*!< asm keyword for TASKING Compiler */
  75. #define __INLINE inline /*!< inline keyword for TASKING Compiler */
  76. #endif
  77. /*!< __FPU_USED to be checked prior to making use of FPU specific registers and functions */
  78. #define __FPU_USED 0
  79. #if defined ( __CC_ARM )
  80. #if defined __TARGET_FPU_VFP
  81. #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  82. #endif
  83. #elif defined ( __ICCARM__ )
  84. #if defined __ARMVFP__
  85. #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  86. #endif
  87. #elif defined ( __GNUC__ )
  88. #if defined (__VFP_FP__) && !defined(__SOFTFP__)
  89. #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  90. #endif
  91. #elif defined ( __TASKING__ )
  92. /* add preprocessor checks */
  93. #endif
  94. #include <stdint.h> /*!< standard types definitions */
  95. #include "core_cmInstr.h" /*!< Core Instruction Access */
  96. #include "core_cmFunc.h" /*!< Core Function Access */
  97. #endif /* __CORE_CM3_H_GENERIC */
  98. #ifndef __CMSIS_GENERIC
  99. #ifndef __CORE_CM3_H_DEPENDANT
  100. #define __CORE_CM3_H_DEPENDANT
  101. /* check device defines and use defaults */
  102. #if defined __CHECK_DEVICE_DEFINES
  103. #ifndef __CM3_REV
  104. #define __CM3_REV 0x0200
  105. #warning "__CM3_REV not defined in device header file; using default!"
  106. #endif
  107. #ifndef __MPU_PRESENT
  108. #define __MPU_PRESENT 0
  109. #warning "__MPU_PRESENT not defined in device header file; using default!"
  110. #endif
  111. #ifndef __NVIC_PRIO_BITS
  112. #define __NVIC_PRIO_BITS 4
  113. #warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
  114. #endif
  115. #ifndef __Vendor_SysTickConfig
  116. #define __Vendor_SysTickConfig 0
  117. #warning "__Vendor_SysTickConfig not defined in device header file; using default!"
  118. #endif
  119. #endif
  120. /* IO definitions (access restrictions to peripheral registers) */
  121. #ifdef __cplusplus
  122. #define __I volatile /*!< defines 'read only' permissions */
  123. #else
  124. #define __I volatile const /*!< defines 'read only' permissions */
  125. #endif
  126. #define __O volatile /*!< defines 'write only' permissions */
  127. #define __IO volatile /*!< defines 'read / write' permissions */
  128. /*@} end of group CMSIS_core_definitions */
  129. /*******************************************************************************
  130. * Register Abstraction
  131. ******************************************************************************/
  132. /** \defgroup CMSIS_core_register CMSIS Core Register
  133. Core Register contain:
  134. - Core Register
  135. - Core NVIC Register
  136. - Core SCB Register
  137. - Core SysTick Register
  138. - Core Debug Register
  139. - Core MPU Register
  140. */
  141. /** \ingroup CMSIS_core_register
  142. \defgroup CMSIS_CORE CMSIS Core
  143. Type definitions for the Cortex-M Core Registers
  144. @{
  145. */
  146. /** \brief Union type to access the Application Program Status Register (APSR).
  147. */
  148. typedef union
  149. {
  150. struct
  151. {
  152. #if (__CORTEX_M != 0x04)
  153. uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */
  154. #else
  155. uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */
  156. uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
  157. uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */
  158. #endif
  159. uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
  160. uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
  161. uint32_t C:1; /*!< bit: 29 Carry condition code flag */
  162. uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
  163. uint32_t N:1; /*!< bit: 31 Negative condition code flag */
  164. } b; /*!< Structure used for bit access */
  165. uint32_t w; /*!< Type used for word access */
  166. } APSR_Type;
  167. /** \brief Union type to access the Interrupt Program Status Register (IPSR).
  168. */
  169. typedef union
  170. {
  171. struct
  172. {
  173. uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
  174. uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
  175. } b; /*!< Structure used for bit access */
  176. uint32_t w; /*!< Type used for word access */
  177. } IPSR_Type;
  178. /** \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
  179. */
  180. typedef union
  181. {
  182. struct
  183. {
  184. uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
  185. #if (__CORTEX_M != 0x04)
  186. uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
  187. #else
  188. uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */
  189. uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
  190. uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */
  191. #endif
  192. uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
  193. uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */
  194. uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
  195. uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
  196. uint32_t C:1; /*!< bit: 29 Carry condition code flag */
  197. uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
  198. uint32_t N:1; /*!< bit: 31 Negative condition code flag */
  199. } b; /*!< Structure used for bit access */
  200. uint32_t w; /*!< Type used for word access */
  201. } xPSR_Type;
  202. /** \brief Union type to access the Control Registers (CONTROL).
  203. */
  204. typedef union
  205. {
  206. struct
  207. {
  208. uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */
  209. uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
  210. uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */
  211. uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */
  212. } b; /*!< Structure used for bit access */
  213. uint32_t w; /*!< Type used for word access */
  214. } CONTROL_Type;
  215. /*@} end of group CMSIS_CORE */
  216. /** \ingroup CMSIS_core_register
  217. \defgroup CMSIS_NVIC CMSIS NVIC
  218. Type definitions for the Cortex-M NVIC Registers
  219. @{
  220. */
  221. /** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
  222. */
  223. typedef struct
  224. {
  225. __IO uint32_t ISER[8]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
  226. uint32_t RESERVED0[24];
  227. __IO uint32_t ICER[8]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
  228. uint32_t RSERVED1[24];
  229. __IO uint32_t ISPR[8]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
  230. uint32_t RESERVED2[24];
  231. __IO uint32_t ICPR[8]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
  232. uint32_t RESERVED3[24];
  233. __IO uint32_t IABR[8]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */
  234. uint32_t RESERVED4[56];
  235. __IO uint8_t IP[240]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */
  236. uint32_t RESERVED5[644];
  237. __O uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */
  238. } NVIC_Type;
  239. /* Software Triggered Interrupt Register Definitions */
  240. #define NVIC_STIR_INTID_Pos 0 /*!< STIR: INTLINESNUM Position */
  241. #define NVIC_STIR_INTID_Msk (0x1FFUL << NVIC_STIR_INTID_Pos) /*!< STIR: INTLINESNUM Mask */
  242. /*@} end of group CMSIS_NVIC */
  243. /** \ingroup CMSIS_core_register
  244. \defgroup CMSIS_SCB CMSIS SCB
  245. Type definitions for the Cortex-M System Control Block Registers
  246. @{
  247. */
  248. /** \brief Structure type to access the System Control Block (SCB).
  249. */
  250. typedef struct
  251. {
  252. __I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
  253. __IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
  254. __IO uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
  255. __IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
  256. __IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
  257. __IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
  258. __IO uint8_t SHP[12]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */
  259. __IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
  260. __IO uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */
  261. __IO uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */
  262. __IO uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */
  263. __IO uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */
  264. __IO uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */
  265. __IO uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */
  266. __I uint32_t PFR[2]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */
  267. __I uint32_t DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */
  268. __I uint32_t ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */
  269. __I uint32_t MMFR[4]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */
  270. __I uint32_t ISAR[5]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */
  271. uint32_t RESERVED0[5];
  272. __IO uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */
  273. } SCB_Type;
  274. /* SCB CPUID Register Definitions */
  275. #define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */
  276. #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
  277. #define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */
  278. #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
  279. #define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */
  280. #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
  281. #define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */
  282. #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
  283. #define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */
  284. #define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */
  285. /* SCB Interrupt Control State Register Definitions */
  286. #define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */
  287. #define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
  288. #define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */
  289. #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
  290. #define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */
  291. #define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
  292. #define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */
  293. #define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
  294. #define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */
  295. #define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
  296. #define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */
  297. #define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
  298. #define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */
  299. #define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
  300. #define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */
  301. #define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
  302. #define SCB_ICSR_RETTOBASE_Pos 11 /*!< SCB ICSR: RETTOBASE Position */
  303. #define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE Mask */
  304. #define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */
  305. #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */
  306. /* SCB Vector Table Offset Register Definitions */
  307. #define SCB_VTOR_TBLOFF_Pos 7 /*!< SCB VTOR: TBLOFF Position */
  308. #define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
  309. /* SCB Application Interrupt and Reset Control Register Definitions */
  310. #define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
  311. #define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
  312. #define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */
  313. #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
  314. #define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */
  315. #define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
  316. #define SCB_AIRCR_PRIGROUP_Pos 8 /*!< SCB AIRCR: PRIGROUP Position */
  317. #define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */
  318. #define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */
  319. #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
  320. #define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */
  321. #define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
  322. #define SCB_AIRCR_VECTRESET_Pos 0 /*!< SCB AIRCR: VECTRESET Position */
  323. #define SCB_AIRCR_VECTRESET_Msk (1UL << SCB_AIRCR_VECTRESET_Pos) /*!< SCB AIRCR: VECTRESET Mask */
  324. /* SCB System Control Register Definitions */
  325. #define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */
  326. #define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
  327. #define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */
  328. #define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
  329. #define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */
  330. #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
  331. /* SCB Configuration Control Register Definitions */
  332. #define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */
  333. #define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
  334. #define SCB_CCR_BFHFNMIGN_Pos 8 /*!< SCB CCR: BFHFNMIGN Position */
  335. #define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */
  336. #define SCB_CCR_DIV_0_TRP_Pos 4 /*!< SCB CCR: DIV_0_TRP Position */
  337. #define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP Mask */
  338. #define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */
  339. #define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
  340. #define SCB_CCR_USERSETMPEND_Pos 1 /*!< SCB CCR: USERSETMPEND Position */
  341. #define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */
  342. #define SCB_CCR_NONBASETHRDENA_Pos 0 /*!< SCB CCR: NONBASETHRDENA Position */
  343. #define SCB_CCR_NONBASETHRDENA_Msk (1UL << SCB_CCR_NONBASETHRDENA_Pos) /*!< SCB CCR: NONBASETHRDENA Mask */
  344. /* SCB System Handler Control and State Register Definitions */
  345. #define SCB_SHCSR_USGFAULTENA_Pos 18 /*!< SCB SHCSR: USGFAULTENA Position */
  346. #define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */
  347. #define SCB_SHCSR_BUSFAULTENA_Pos 17 /*!< SCB SHCSR: BUSFAULTENA Position */
  348. #define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */
  349. #define SCB_SHCSR_MEMFAULTENA_Pos 16 /*!< SCB SHCSR: MEMFAULTENA Position */
  350. #define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */
  351. #define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */
  352. #define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
  353. #define SCB_SHCSR_BUSFAULTPENDED_Pos 14 /*!< SCB SHCSR: BUSFAULTPENDED Position */
  354. #define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */
  355. #define SCB_SHCSR_MEMFAULTPENDED_Pos 13 /*!< SCB SHCSR: MEMFAULTPENDED Position */
  356. #define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */
  357. #define SCB_SHCSR_USGFAULTPENDED_Pos 12 /*!< SCB SHCSR: USGFAULTPENDED Position */
  358. #define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */
  359. #define SCB_SHCSR_SYSTICKACT_Pos 11 /*!< SCB SHCSR: SYSTICKACT Position */
  360. #define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */
  361. #define SCB_SHCSR_PENDSVACT_Pos 10 /*!< SCB SHCSR: PENDSVACT Position */
  362. #define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */
  363. #define SCB_SHCSR_MONITORACT_Pos 8 /*!< SCB SHCSR: MONITORACT Position */
  364. #define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */
  365. #define SCB_SHCSR_SVCALLACT_Pos 7 /*!< SCB SHCSR: SVCALLACT Position */
  366. #define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */
  367. #define SCB_SHCSR_USGFAULTACT_Pos 3 /*!< SCB SHCSR: USGFAULTACT Position */
  368. #define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */
  369. #define SCB_SHCSR_BUSFAULTACT_Pos 1 /*!< SCB SHCSR: BUSFAULTACT Position */
  370. #define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */
  371. #define SCB_SHCSR_MEMFAULTACT_Pos 0 /*!< SCB SHCSR: MEMFAULTACT Position */
  372. #define SCB_SHCSR_MEMFAULTACT_Msk (1UL << SCB_SHCSR_MEMFAULTACT_Pos) /*!< SCB SHCSR: MEMFAULTACT Mask */
  373. /* SCB Configurable Fault Status Registers Definitions */
  374. #define SCB_CFSR_USGFAULTSR_Pos 16 /*!< SCB CFSR: Usage Fault Status Register Position */
  375. #define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */
  376. #define SCB_CFSR_BUSFAULTSR_Pos 8 /*!< SCB CFSR: Bus Fault Status Register Position */
  377. #define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */
  378. #define SCB_CFSR_MEMFAULTSR_Pos 0 /*!< SCB CFSR: Memory Manage Fault Status Register Position */
  379. #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL << SCB_CFSR_MEMFAULTSR_Pos) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */
  380. /* SCB Hard Fault Status Registers Definitions */
  381. #define SCB_HFSR_DEBUGEVT_Pos 31 /*!< SCB HFSR: DEBUGEVT Position */
  382. #define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */
  383. #define SCB_HFSR_FORCED_Pos 30 /*!< SCB HFSR: FORCED Position */
  384. #define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */
  385. #define SCB_HFSR_VECTTBL_Pos 1 /*!< SCB HFSR: VECTTBL Position */
  386. #define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */
  387. /* SCB Debug Fault Status Register Definitions */
  388. #define SCB_DFSR_EXTERNAL_Pos 4 /*!< SCB DFSR: EXTERNAL Position */
  389. #define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */
  390. #define SCB_DFSR_VCATCH_Pos 3 /*!< SCB DFSR: VCATCH Position */
  391. #define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */
  392. #define SCB_DFSR_DWTTRAP_Pos 2 /*!< SCB DFSR: DWTTRAP Position */
  393. #define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */
  394. #define SCB_DFSR_BKPT_Pos 1 /*!< SCB DFSR: BKPT Position */
  395. #define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */
  396. #define SCB_DFSR_HALTED_Pos 0 /*!< SCB DFSR: HALTED Position */
  397. #define SCB_DFSR_HALTED_Msk (1UL << SCB_DFSR_HALTED_Pos) /*!< SCB DFSR: HALTED Mask */
  398. /*@} end of group CMSIS_SCB */
  399. /** \ingroup CMSIS_core_register
  400. \defgroup CMSIS_SCnSCB CMSIS System Control and ID Register not in the SCB
  401. Type definitions for the Cortex-M System Control and ID Register not in the SCB
  402. @{
  403. */
  404. /** \brief Structure type to access the System Control and ID Register not in the SCB.
  405. */
  406. typedef struct
  407. {
  408. uint32_t RESERVED0[1];
  409. __I uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */
  410. #if ((defined __CM3_REV) && (__CM3_REV >= 0x200))
  411. __IO uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */
  412. #else
  413. uint32_t RESERVED1[1];
  414. #endif
  415. } SCnSCB_Type;
  416. /* Interrupt Controller Type Register Definitions */
  417. #define SCnSCB_ICTR_INTLINESNUM_Pos 0 /*!< ICTR: INTLINESNUM Position */
  418. #define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL << SCnSCB_ICTR_INTLINESNUM_Pos) /*!< ICTR: INTLINESNUM Mask */
  419. /* Auxiliary Control Register Definitions */
  420. #define SCnSCB_ACTLR_DISFOLD_Pos 2 /*!< ACTLR: DISFOLD Position */
  421. #define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */
  422. #define SCnSCB_ACTLR_DISDEFWBUF_Pos 1 /*!< ACTLR: DISDEFWBUF Position */
  423. #define SCnSCB_ACTLR_DISDEFWBUF_Msk (1UL << SCnSCB_ACTLR_DISDEFWBUF_Pos) /*!< ACTLR: DISDEFWBUF Mask */
  424. #define SCnSCB_ACTLR_DISMCYCINT_Pos 0 /*!< ACTLR: DISMCYCINT Position */
  425. #define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL << SCnSCB_ACTLR_DISMCYCINT_Pos) /*!< ACTLR: DISMCYCINT Mask */
  426. /*@} end of group CMSIS_SCnotSCB */
  427. /** \ingroup CMSIS_core_register
  428. \defgroup CMSIS_SysTick CMSIS SysTick
  429. Type definitions for the Cortex-M System Timer Registers
  430. @{
  431. */
  432. /** \brief Structure type to access the System Timer (SysTick).
  433. */
  434. typedef struct
  435. {
  436. __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
  437. __IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
  438. __IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
  439. __I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
  440. } SysTick_Type;
  441. /* SysTick Control / Status Register Definitions */
  442. #define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
  443. #define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
  444. #define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
  445. #define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
  446. #define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
  447. #define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
  448. #define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
  449. #define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */
  450. /* SysTick Reload Register Definitions */
  451. #define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
  452. #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */
  453. /* SysTick Current Register Definitions */
  454. #define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
  455. #define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */
  456. /* SysTick Calibration Register Definitions */
  457. #define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
  458. #define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
  459. #define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
  460. #define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
  461. #define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
  462. #define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */
  463. /*@} end of group CMSIS_SysTick */
  464. /** \ingroup CMSIS_core_register
  465. \defgroup CMSIS_ITM CMSIS ITM
  466. Type definitions for the Cortex-M Instrumentation Trace Macrocell (ITM)
  467. @{
  468. */
  469. /** \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM).
  470. */
  471. typedef struct
  472. {
  473. __O union
  474. {
  475. __O uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */
  476. __O uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */
  477. __O uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */
  478. } PORT [32]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */
  479. uint32_t RESERVED0[864];
  480. __IO uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */
  481. uint32_t RESERVED1[15];
  482. __IO uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */
  483. uint32_t RESERVED2[15];
  484. __IO uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */
  485. } ITM_Type;
  486. /* ITM Trace Privilege Register Definitions */
  487. #define ITM_TPR_PRIVMASK_Pos 0 /*!< ITM TPR: PRIVMASK Position */
  488. #define ITM_TPR_PRIVMASK_Msk (0xFUL << ITM_TPR_PRIVMASK_Pos) /*!< ITM TPR: PRIVMASK Mask */
  489. /* ITM Trace Control Register Definitions */
  490. #define ITM_TCR_BUSY_Pos 23 /*!< ITM TCR: BUSY Position */
  491. #define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */
  492. #define ITM_TCR_TraceBusID_Pos 16 /*!< ITM TCR: ATBID Position */
  493. #define ITM_TCR_TraceBusID_Msk (0x7FUL << ITM_TCR_TraceBusID_Pos) /*!< ITM TCR: ATBID Mask */
  494. #define ITM_TCR_GTSFREQ_Pos 10 /*!< ITM TCR: Global timestamp frequency Position */
  495. #define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */
  496. #define ITM_TCR_TSPrescale_Pos 8 /*!< ITM TCR: TSPrescale Position */
  497. #define ITM_TCR_TSPrescale_Msk (3UL << ITM_TCR_TSPrescale_Pos) /*!< ITM TCR: TSPrescale Mask */
  498. #define ITM_TCR_SWOENA_Pos 4 /*!< ITM TCR: SWOENA Position */
  499. #define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */
  500. #define ITM_TCR_TXENA_Pos 3 /*!< ITM TCR: TXENA Position */
  501. #define ITM_TCR_TXENA_Msk (1UL << ITM_TCR_TXENA_Pos) /*!< ITM TCR: TXENA Mask */
  502. #define ITM_TCR_SYNCENA_Pos 2 /*!< ITM TCR: SYNCENA Position */
  503. #define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */
  504. #define ITM_TCR_TSENA_Pos 1 /*!< ITM TCR: TSENA Position */
  505. #define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */
  506. #define ITM_TCR_ITMENA_Pos 0 /*!< ITM TCR: ITM Enable bit Position */
  507. #define ITM_TCR_ITMENA_Msk (1UL << ITM_TCR_ITMENA_Pos) /*!< ITM TCR: ITM Enable bit Mask */
  508. /*@}*/ /* end of group CMSIS_ITM */
  509. #if (__MPU_PRESENT == 1)
  510. /** \ingroup CMSIS_core_register
  511. \defgroup CMSIS_MPU CMSIS MPU
  512. Type definitions for the Cortex-M Memory Protection Unit (MPU)
  513. @{
  514. */
  515. /** \brief Structure type to access the Memory Protection Unit (MPU).
  516. */
  517. typedef struct
  518. {
  519. __I uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */
  520. __IO uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */
  521. __IO uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */
  522. __IO uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */
  523. __IO uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */
  524. __IO uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */
  525. __IO uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */
  526. __IO uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */
  527. __IO uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */
  528. __IO uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */
  529. __IO uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */
  530. } MPU_Type;
  531. /* MPU Type Register */
  532. #define MPU_TYPE_IREGION_Pos 16 /*!< MPU TYPE: IREGION Position */
  533. #define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
  534. #define MPU_TYPE_DREGION_Pos 8 /*!< MPU TYPE: DREGION Position */
  535. #define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */
  536. #define MPU_TYPE_SEPARATE_Pos 0 /*!< MPU TYPE: SEPARATE Position */
  537. #define MPU_TYPE_SEPARATE_Msk (1UL << MPU_TYPE_SEPARATE_Pos) /*!< MPU TYPE: SEPARATE Mask */
  538. /* MPU Control Register */
  539. #define MPU_CTRL_PRIVDEFENA_Pos 2 /*!< MPU CTRL: PRIVDEFENA Position */
  540. #define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */
  541. #define MPU_CTRL_HFNMIENA_Pos 1 /*!< MPU CTRL: HFNMIENA Position */
  542. #define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */
  543. #define MPU_CTRL_ENABLE_Pos 0 /*!< MPU CTRL: ENABLE Position */
  544. #define MPU_CTRL_ENABLE_Msk (1UL << MPU_CTRL_ENABLE_Pos) /*!< MPU CTRL: ENABLE Mask */
  545. /* MPU Region Number Register */
  546. #define MPU_RNR_REGION_Pos 0 /*!< MPU RNR: REGION Position */
  547. #define MPU_RNR_REGION_Msk (0xFFUL << MPU_RNR_REGION_Pos) /*!< MPU RNR: REGION Mask */
  548. /* MPU Region Base Address Register */
  549. #define MPU_RBAR_ADDR_Pos 5 /*!< MPU RBAR: ADDR Position */
  550. #define MPU_RBAR_ADDR_Msk (0x7FFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */
  551. #define MPU_RBAR_VALID_Pos 4 /*!< MPU RBAR: VALID Position */
  552. #define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */
  553. #define MPU_RBAR_REGION_Pos 0 /*!< MPU RBAR: REGION Position */
  554. #define MPU_RBAR_REGION_Msk (0xFUL << MPU_RBAR_REGION_Pos) /*!< MPU RBAR: REGION Mask */
  555. /* MPU Region Attribute and Size Register */
  556. #define MPU_RASR_ATTRS_Pos 16 /*!< MPU RASR: MPU Region Attribute field Position */
  557. #define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */
  558. #define MPU_RASR_SRD_Pos 8 /*!< MPU RASR: Sub-Region Disable Position */
  559. #define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */
  560. #define MPU_RASR_SIZE_Pos 1 /*!< MPU RASR: Region Size Field Position */
  561. #define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */
  562. #define MPU_RASR_ENABLE_Pos 0 /*!< MPU RASR: Region enable bit Position */
  563. #define MPU_RASR_ENABLE_Msk (1UL << MPU_RASR_ENABLE_Pos) /*!< MPU RASR: Region enable bit Disable Mask */
  564. /*@} end of group CMSIS_MPU */
  565. #endif
  566. /** \ingroup CMSIS_core_register
  567. \defgroup CMSIS_CoreDebug CMSIS Core Debug
  568. Type definitions for the Cortex-M Core Debug Registers
  569. @{
  570. */
  571. /** \brief Structure type to access the Core Debug Register (CoreDebug).
  572. */
  573. typedef struct
  574. {
  575. __IO uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */
  576. __O uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */
  577. __IO uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */
  578. __IO uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */
  579. } CoreDebug_Type;
  580. /* Debug Halting Control and Status Register */
  581. #define CoreDebug_DHCSR_DBGKEY_Pos 16 /*!< CoreDebug DHCSR: DBGKEY Position */
  582. #define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */
  583. #define CoreDebug_DHCSR_S_RESET_ST_Pos 25 /*!< CoreDebug DHCSR: S_RESET_ST Position */
  584. #define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */
  585. #define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24 /*!< CoreDebug DHCSR: S_RETIRE_ST Position */
  586. #define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */
  587. #define CoreDebug_DHCSR_S_LOCKUP_Pos 19 /*!< CoreDebug DHCSR: S_LOCKUP Position */
  588. #define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */
  589. #define CoreDebug_DHCSR_S_SLEEP_Pos 18 /*!< CoreDebug DHCSR: S_SLEEP Position */
  590. #define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */
  591. #define CoreDebug_DHCSR_S_HALT_Pos 17 /*!< CoreDebug DHCSR: S_HALT Position */
  592. #define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */
  593. #define CoreDebug_DHCSR_S_REGRDY_Pos 16 /*!< CoreDebug DHCSR: S_REGRDY Position */
  594. #define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */
  595. #define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5 /*!< CoreDebug DHCSR: C_SNAPSTALL Position */
  596. #define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */
  597. #define CoreDebug_DHCSR_C_MASKINTS_Pos 3 /*!< CoreDebug DHCSR: C_MASKINTS Position */
  598. #define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */
  599. #define CoreDebug_DHCSR_C_STEP_Pos 2 /*!< CoreDebug DHCSR: C_STEP Position */
  600. #define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */
  601. #define CoreDebug_DHCSR_C_HALT_Pos 1 /*!< CoreDebug DHCSR: C_HALT Position */
  602. #define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */
  603. #define CoreDebug_DHCSR_C_DEBUGEN_Pos 0 /*!< CoreDebug DHCSR: C_DEBUGEN Position */
  604. #define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL << CoreDebug_DHCSR_C_DEBUGEN_Pos) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */
  605. /* Debug Core Register Selector Register */
  606. #define CoreDebug_DCRSR_REGWnR_Pos 16 /*!< CoreDebug DCRSR: REGWnR Position */
  607. #define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */
  608. #define CoreDebug_DCRSR_REGSEL_Pos 0 /*!< CoreDebug DCRSR: REGSEL Position */
  609. #define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL << CoreDebug_DCRSR_REGSEL_Pos) /*!< CoreDebug DCRSR: REGSEL Mask */
  610. /* Debug Exception and Monitor Control Register */
  611. #define CoreDebug_DEMCR_TRCENA_Pos 24 /*!< CoreDebug DEMCR: TRCENA Position */
  612. #define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */
  613. #define CoreDebug_DEMCR_MON_REQ_Pos 19 /*!< CoreDebug DEMCR: MON_REQ Position */
  614. #define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */
  615. #define CoreDebug_DEMCR_MON_STEP_Pos 18 /*!< CoreDebug DEMCR: MON_STEP Position */
  616. #define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */
  617. #define CoreDebug_DEMCR_MON_PEND_Pos 17 /*!< CoreDebug DEMCR: MON_PEND Position */
  618. #define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */
  619. #define CoreDebug_DEMCR_MON_EN_Pos 16 /*!< CoreDebug DEMCR: MON_EN Position */
  620. #define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */
  621. #define CoreDebug_DEMCR_VC_HARDERR_Pos 10 /*!< CoreDebug DEMCR: VC_HARDERR Position */
  622. #define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */
  623. #define CoreDebug_DEMCR_VC_INTERR_Pos 9 /*!< CoreDebug DEMCR: VC_INTERR Position */
  624. #define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */
  625. #define CoreDebug_DEMCR_VC_BUSERR_Pos 8 /*!< CoreDebug DEMCR: VC_BUSERR Position */
  626. #define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */
  627. #define CoreDebug_DEMCR_VC_STATERR_Pos 7 /*!< CoreDebug DEMCR: VC_STATERR Position */
  628. #define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */
  629. #define CoreDebug_DEMCR_VC_CHKERR_Pos 6 /*!< CoreDebug DEMCR: VC_CHKERR Position */
  630. #define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */
  631. #define CoreDebug_DEMCR_VC_NOCPERR_Pos 5 /*!< CoreDebug DEMCR: VC_NOCPERR Position */
  632. #define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */
  633. #define CoreDebug_DEMCR_VC_MMERR_Pos 4 /*!< CoreDebug DEMCR: VC_MMERR Position */
  634. #define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */
  635. #define CoreDebug_DEMCR_VC_CORERESET_Pos 0 /*!< CoreDebug DEMCR: VC_CORERESET Position */
  636. #define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL << CoreDebug_DEMCR_VC_CORERESET_Pos) /*!< CoreDebug DEMCR: VC_CORERESET Mask */
  637. /*@} end of group CMSIS_CoreDebug */
  638. /** \ingroup CMSIS_core_register
  639. @{
  640. */
  641. /* Memory mapping of Cortex-M3 Hardware */
  642. #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
  643. #define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */
  644. #define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */
  645. #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
  646. #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
  647. #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
  648. #define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */
  649. #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
  650. #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
  651. #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
  652. #define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */
  653. #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
  654. #if (__MPU_PRESENT == 1)
  655. #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
  656. #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
  657. #endif
  658. /*@} */
  659. /*******************************************************************************
  660. * Hardware Abstraction Layer
  661. ******************************************************************************/
  662. /** \defgroup CMSIS_Core_FunctionInterface CMSIS Core Function Interface
  663. Core Function Interface contains:
  664. - Core NVIC Functions
  665. - Core SysTick Functions
  666. - Core Debug Functions
  667. - Core Register Access Functions
  668. */
  669. /* ########################## NVIC functions #################################### */
  670. /** \ingroup CMSIS_Core_FunctionInterface
  671. \defgroup CMSIS_Core_NVICFunctions CMSIS Core NVIC Functions
  672. @{
  673. */
  674. /** \brief Set Priority Grouping
  675. This function sets the priority grouping field using the required unlock sequence.
  676. The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field.
  677. Only values from 0..7 are used.
  678. In case of a conflict between priority grouping and available
  679. priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.
  680. \param [in] PriorityGroup Priority grouping field
  681. */
  682. static __INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
  683. {
  684. uint32_t reg_value;
  685. uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07); /* only values 0..7 are used */
  686. reg_value = SCB->AIRCR; /* read old register configuration */
  687. reg_value &= ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk); /* clear bits to change */
  688. reg_value = (reg_value |
  689. ((uint32_t)0x5FA << SCB_AIRCR_VECTKEY_Pos) |
  690. (PriorityGroupTmp << 8)); /* Insert write key and priorty group */
  691. SCB->AIRCR = reg_value;
  692. }
  693. /** \brief Get Priority Grouping
  694. This function gets the priority grouping from NVIC Interrupt Controller.
  695. Priority grouping is SCB->AIRCR [10:8] PRIGROUP field.
  696. \return Priority grouping field
  697. */
  698. static __INLINE uint32_t NVIC_GetPriorityGrouping(void)
  699. {
  700. return ((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos); /* read priority grouping field */
  701. }
  702. /** \brief Enable External Interrupt
  703. This function enables a device specific interrupt in the NVIC interrupt controller.
  704. The interrupt number cannot be a negative value.
  705. \param [in] IRQn Number of the external interrupt to enable
  706. */
  707. static __INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
  708. {
  709. NVIC->ISER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* enable interrupt */
  710. }
  711. /** \brief Disable External Interrupt
  712. This function disables a device specific interrupt in the NVIC interrupt controller.
  713. The interrupt number cannot be a negative value.
  714. \param [in] IRQn Number of the external interrupt to disable
  715. */
  716. static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
  717. {
  718. NVIC->ICER[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* disable interrupt */
  719. }
  720. /** \brief Get Pending Interrupt
  721. This function reads the pending register in the NVIC and returns the pending bit
  722. for the specified interrupt.
  723. \param [in] IRQn Number of the interrupt for get pending
  724. \return 0 Interrupt status is not pending
  725. \return 1 Interrupt status is pending
  726. */
  727. static __INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
  728. {
  729. return((uint32_t) ((NVIC->ISPR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if pending else 0 */
  730. }
  731. /** \brief Set Pending Interrupt
  732. This function sets the pending bit for the specified interrupt.
  733. The interrupt number cannot be a negative value.
  734. \param [in] IRQn Number of the interrupt for set pending
  735. */
  736. static __INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
  737. {
  738. NVIC->ISPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* set interrupt pending */
  739. }
  740. /** \brief Clear Pending Interrupt
  741. This function clears the pending bit for the specified interrupt.
  742. The interrupt number cannot be a negative value.
  743. \param [in] IRQn Number of the interrupt for clear pending
  744. */
  745. static __INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
  746. {
  747. NVIC->ICPR[((uint32_t)(IRQn) >> 5)] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */
  748. }
  749. /** \brief Get Active Interrupt
  750. This function reads the active register in NVIC and returns the active bit.
  751. \param [in] IRQn Number of the interrupt for get active
  752. \return 0 Interrupt status is not active
  753. \return 1 Interrupt status is active
  754. */
  755. static __INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)
  756. {
  757. return((uint32_t)((NVIC->IABR[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); /* Return 1 if active else 0 */
  758. }
  759. /** \brief Set Interrupt Priority
  760. This function sets the priority for the specified interrupt. The interrupt
  761. number can be positive to specify an external (device specific)
  762. interrupt, or negative to specify an internal (core) interrupt.
  763. Note: The priority cannot be set for every core interrupt.
  764. \param [in] IRQn Number of the interrupt for set priority
  765. \param [in] priority Priority to set
  766. */
  767. static __INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
  768. {
  769. if(IRQn < 0) {
  770. SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for Cortex-M System Interrupts */
  771. else {
  772. NVIC->IP[(uint32_t)(IRQn)] = ((priority << (8 - __NVIC_PRIO_BITS)) & 0xff); } /* set Priority for device specific Interrupts */
  773. }
  774. /** \brief Get Interrupt Priority
  775. This function reads the priority for the specified interrupt. The interrupt
  776. number can be positive to specify an external (device specific)
  777. interrupt, or negative to specify an internal (core) interrupt.
  778. The returned priority value is automatically aligned to the implemented
  779. priority bits of the microcontroller.
  780. \param [in] IRQn Number of the interrupt for get priority
  781. \return Interrupt Priority
  782. */
  783. static __INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
  784. {
  785. if(IRQn < 0) {
  786. return((uint32_t)(SCB->SHP[((uint32_t)(IRQn) & 0xF)-4] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M system interrupts */
  787. else {
  788. return((uint32_t)(NVIC->IP[(uint32_t)(IRQn)] >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
  789. }
  790. /** \brief Encode Priority
  791. This function encodes the priority for an interrupt with the given priority group,
  792. preemptive priority value and sub priority value.
  793. In case of a conflict between priority grouping and available
  794. priority bits (__NVIC_PRIO_BITS) the samllest possible priority group is set.
  795. The returned priority value can be used for NVIC_SetPriority(...) function
  796. \param [in] PriorityGroup Used priority group
  797. \param [in] PreemptPriority Preemptive priority value (starting from 0)
  798. \param [in] SubPriority Sub priority value (starting from 0)
  799. \return Encoded priority for the interrupt
  800. */
  801. static __INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
  802. {
  803. uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
  804. uint32_t PreemptPriorityBits;
  805. uint32_t SubPriorityBits;
  806. PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;
  807. SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;
  808. return (
  809. ((PreemptPriority & ((1 << (PreemptPriorityBits)) - 1)) << SubPriorityBits) |
  810. ((SubPriority & ((1 << (SubPriorityBits )) - 1)))
  811. );
  812. }
  813. /** \brief Decode Priority
  814. This function decodes an interrupt priority value with the given priority group to
  815. preemptive priority value and sub priority value.
  816. In case of a conflict between priority grouping and available
  817. priority bits (__NVIC_PRIO_BITS) the samllest possible priority group is set.
  818. The priority value can be retrieved with NVIC_GetPriority(...) function
  819. \param [in] Priority Priority value
  820. \param [in] PriorityGroup Used priority group
  821. \param [out] pPreemptPriority Preemptive priority value (starting from 0)
  822. \param [out] pSubPriority Sub priority value (starting from 0)
  823. */
  824. static __INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)
  825. {
  826. uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
  827. uint32_t PreemptPriorityBits;
  828. uint32_t SubPriorityBits;
  829. PreemptPriorityBits = ((7 - PriorityGroupTmp) > __NVIC_PRIO_BITS) ? __NVIC_PRIO_BITS : 7 - PriorityGroupTmp;
  830. SubPriorityBits = ((PriorityGroupTmp + __NVIC_PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + __NVIC_PRIO_BITS;
  831. *pPreemptPriority = (Priority >> SubPriorityBits) & ((1 << (PreemptPriorityBits)) - 1);
  832. *pSubPriority = (Priority ) & ((1 << (SubPriorityBits )) - 1);
  833. }
  834. /** \brief System Reset
  835. This function initiate a system reset request to reset the MCU.
  836. */
  837. static __INLINE void NVIC_SystemReset(void)
  838. {
  839. __DSB(); /* Ensure all outstanding memory accesses included
  840. buffered write are completed before reset */
  841. SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
  842. (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
  843. SCB_AIRCR_SYSRESETREQ_Msk); /* Keep priority group unchanged */
  844. __DSB(); /* Ensure completion of memory access */
  845. while(1); /* wait until reset */
  846. }
  847. /*@} end of CMSIS_Core_NVICFunctions */
  848. /* ################################## SysTick function ############################################ */
  849. /** \ingroup CMSIS_Core_FunctionInterface
  850. \defgroup CMSIS_Core_SysTickFunctions CMSIS Core SysTick Functions
  851. @{
  852. */
  853. #if (__Vendor_SysTickConfig == 0)
  854. /** \brief System Tick Configuration
  855. This function initialises the system tick timer and its interrupt and start the system tick timer.
  856. Counter is in free running mode to generate periodical interrupts.
  857. \param [in] ticks Number of ticks between two interrupts
  858. \return 0 Function succeeded
  859. \return 1 Function failed
  860. */
  861. static __INLINE uint32_t SysTick_Config(uint32_t ticks)
  862. {
  863. if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
  864. SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */
  865. NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */
  866. SysTick->VAL = 0; /* Load the SysTick Counter Value */
  867. SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
  868. SysTick_CTRL_TICKINT_Msk |
  869. SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
  870. return (0); /* Function successful */
  871. }
  872. #endif
  873. /*@} end of CMSIS_Core_SysTickFunctions */
  874. /* ##################################### Debug In/Output function ########################################### */
  875. /** \ingroup CMSIS_Core_FunctionInterface
  876. \defgroup CMSIS_core_DebugFunctions CMSIS Core Debug Functions
  877. @{
  878. */
  879. extern volatile int32_t ITM_RxBuffer; /*!< external variable to receive characters */
  880. #define ITM_RXBUFFER_EMPTY 0x5AA55AA5 /*!< value identifying ITM_RxBuffer is ready for next character */
  881. /** \brief ITM Send Character
  882. This function transmits a character via the ITM channel 0.
  883. It just returns when no debugger is connected that has booked the output.
  884. It is blocking when a debugger is connected, but the previous character send is not transmitted.
  885. \param [in] ch Character to transmit
  886. \return Character to transmit
  887. */
  888. static __INLINE uint32_t ITM_SendChar (uint32_t ch)
  889. {
  890. if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) && /* Trace enabled */
  891. (ITM->TCR & ITM_TCR_ITMENA_Msk) && /* ITM enabled */
  892. (ITM->TER & (1UL << 0) ) ) /* ITM Port #0 enabled */
  893. {
  894. while (ITM->PORT[0].u32 == 0);
  895. ITM->PORT[0].u8 = (uint8_t) ch;
  896. }
  897. return (ch);
  898. }
  899. /** \brief ITM Receive Character
  900. This function inputs a character via external variable ITM_RxBuffer.
  901. It just returns when no debugger is connected that has booked the output.
  902. It is blocking when a debugger is connected, but the previous character send is not transmitted.
  903. \return Received character
  904. \return -1 No character received
  905. */
  906. static __INLINE int32_t ITM_ReceiveChar (void) {
  907. int32_t ch = -1; /* no character available */
  908. if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) {
  909. ch = ITM_RxBuffer;
  910. ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */
  911. }
  912. return (ch);
  913. }
  914. /** \brief ITM Check Character
  915. This function checks external variable ITM_RxBuffer whether a character is available or not.
  916. It returns '1' if a character is available and '0' if no character is available.
  917. \return 0 No character available
  918. \return 1 Character available
  919. */
  920. static __INLINE int32_t ITM_CheckChar (void) {
  921. if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) {
  922. return (0); /* no character available */
  923. } else {
  924. return (1); /* character available */
  925. }
  926. }
  927. /*@} end of CMSIS_core_DebugFunctions */
  928. #endif /* __CORE_CM3_H_DEPENDANT */
  929. #endif /* __CMSIS_GENERIC */
  930. #ifdef __cplusplus
  931. }
  932. #endif