core_cm3.h 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  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