1 /*
2 * Copyright (c) 2009-2024 Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 /*
20 * CMSIS Cortex-M0 Core Peripheral Access Layer Header File
21 */
22
23 #if defined ( __ICCARM__ )
24 #pragma system_include /* treat file as system include file for MISRA check */
25 #elif defined (__clang__)
26 #pragma clang system_header /* treat file as system include file */
27 #elif defined ( __GNUC__ )
28 #pragma GCC diagnostic ignored "-Wpedantic" /* disable pedantic warning due to unnamed structs/unions */
29 #endif
30
31 #ifndef __CORE_CM0_H_GENERIC
32 #define __CORE_CM0_H_GENERIC
33
34 #include <stdint.h>
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /**
41 \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
42 CMSIS violates the following MISRA-C:2004 rules:
43
44 \li Required Rule 8.5, object/function definition in header file.<br>
45 Function definitions in header files are used to allow 'inlining'.
46
47 \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
48 Unions are used for effective representation of core registers.
49
50 \li Advisory Rule 19.7, Function-like macro defined.<br>
51 Function-like macros are used to allow more efficient code.
52 */
53
54
55 /*******************************************************************************
56 * CMSIS definitions
57 ******************************************************************************/
58 /**
59 \ingroup Cortex_M0
60 @{
61 */
62
63 #include "cmsis_version.h"
64
65 /* CMSIS CM0 definitions */
66
67 #define __CORTEX_M (0U) /*!< Cortex-M Core */
68
69 /** __FPU_USED indicates whether an FPU is used or not.
70 This core does not support an FPU at all
71 */
72 #define __FPU_USED 0U
73
74 #if defined ( __CC_ARM )
75 #if defined (__TARGET_FPU_VFP)
76 #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
77 #endif
78
79 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
80 #if defined (__ARM_FP)
81 #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
82 #endif
83
84 #elif defined (__ti__)
85 #if defined (__ARM_FP)
86 #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
87 #endif
88
89 #elif defined ( __GNUC__ )
90 #if defined (__VFP_FP__) && !defined(__SOFTFP__)
91 #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
92 #endif
93
94 #elif defined ( __ICCARM__ )
95 #if defined (__ARMVFP__)
96 #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
97 #endif
98
99 #elif defined ( __TI_ARM__ )
100 #if defined (__TI_VFP_SUPPORT__)
101 #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
102 #endif
103
104 #elif defined ( __TASKING__ )
105 #if defined (__FPU_VFP__)
106 #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
107 #endif
108
109 #elif defined ( __CSMC__ )
110 #if ( __CSMC__ & 0x400U)
111 #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
112 #endif
113
114 #endif
115
116 #include "cmsis_compiler.h" /* CMSIS compiler specific defines */
117
118
119 #ifdef __cplusplus
120 }
121 #endif
122
123 #endif /* __CORE_CM0_H_GENERIC */
124
125 #ifndef __CMSIS_GENERIC
126
127 #ifndef __CORE_CM0_H_DEPENDANT
128 #define __CORE_CM0_H_DEPENDANT
129
130 #ifdef __cplusplus
131 extern "C" {
132 #endif
133
134 /* check device defines and use defaults */
135 #if defined __CHECK_DEVICE_DEFINES
136 #ifndef __CM0_REV
137 #define __CM0_REV 0x0000U
138 #warning "__CM0_REV not defined in device header file; using default!"
139 #endif
140
141 #ifndef __NVIC_PRIO_BITS
142 #define __NVIC_PRIO_BITS 2U
143 #warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
144 #endif
145
146 #ifndef __Vendor_SysTickConfig
147 #define __Vendor_SysTickConfig 0U
148 #warning "__Vendor_SysTickConfig not defined in device header file; using default!"
149 #endif
150 #endif
151
152 /* IO definitions (access restrictions to peripheral registers) */
153 /**
154 \defgroup CMSIS_glob_defs CMSIS Global Defines
155
156 <strong>IO Type Qualifiers</strong> are used
157 \li to specify the access to peripheral variables.
158 \li for automatic generation of peripheral register debug information.
159 */
160 #ifdef __cplusplus
161 #define __I volatile /*!< Defines 'read only' permissions */
162 #else
163 #define __I volatile const /*!< Defines 'read only' permissions */
164 #endif
165 #define __O volatile /*!< Defines 'write only' permissions */
166 #define __IO volatile /*!< Defines 'read / write' permissions */
167
168 /* following defines should be used for structure members */
169 #define __IM volatile const /*! Defines 'read only' structure member permissions */
170 #define __OM volatile /*! Defines 'write only' structure member permissions */
171 #define __IOM volatile /*! Defines 'read / write' structure member permissions */
172
173 /*@} end of group Cortex_M0 */
174
175
176
177 /*******************************************************************************
178 * Register Abstraction
179 Core Register contain:
180 - Core Register
181 - Core NVIC Register
182 - Core SCB Register
183 - Core SysTick Register
184 ******************************************************************************/
185 /**
186 \defgroup CMSIS_core_register Defines and Type Definitions
187 \brief Type definitions and defines for Cortex-M processor based devices.
188 */
189
190 /**
191 \ingroup CMSIS_core_register
192 \defgroup CMSIS_CORE Status and Control Registers
193 \brief Core Register type definitions.
194 @{
195 */
196
197 /**
198 \brief Union type to access the Application Program Status Register (APSR).
199 */
200 typedef union
201 {
202 struct
203 {
204 uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */
205 uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
206 uint32_t C:1; /*!< bit: 29 Carry condition code flag */
207 uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
208 uint32_t N:1; /*!< bit: 31 Negative condition code flag */
209 } b; /*!< Structure used for bit access */
210 uint32_t w; /*!< Type used for word access */
211 } APSR_Type;
212
213 /** \brief APSR Register Definitions */
214 #define APSR_N_Pos 31U /*!< APSR: N Position */
215 #define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */
216
217 #define APSR_Z_Pos 30U /*!< APSR: Z Position */
218 #define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */
219
220 #define APSR_C_Pos 29U /*!< APSR: C Position */
221 #define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */
222
223 #define APSR_V_Pos 28U /*!< APSR: V Position */
224 #define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */
225
226
227 /**
228 \brief Union type to access the Interrupt Program Status Register (IPSR).
229 */
230 typedef union
231 {
232 struct
233 {
234 uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
235 uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
236 } b; /*!< Structure used for bit access */
237 uint32_t w; /*!< Type used for word access */
238 } IPSR_Type;
239
240 /** \brief IPSR Register Definitions */
241 #define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */
242 #define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
243
244
245 /**
246 \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
247 */
248 typedef union
249 {
250 struct
251 {
252 uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
253 uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
254 uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
255 uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */
256 uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
257 uint32_t C:1; /*!< bit: 29 Carry condition code flag */
258 uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
259 uint32_t N:1; /*!< bit: 31 Negative condition code flag */
260 } b; /*!< Structure used for bit access */
261 uint32_t w; /*!< Type used for word access */
262 } xPSR_Type;
263
264 /** \brief xPSR Register Definitions */
265 #define xPSR_N_Pos 31U /*!< xPSR: N Position */
266 #define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */
267
268 #define xPSR_Z_Pos 30U /*!< xPSR: Z Position */
269 #define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */
270
271 #define xPSR_C_Pos 29U /*!< xPSR: C Position */
272 #define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */
273
274 #define xPSR_V_Pos 28U /*!< xPSR: V Position */
275 #define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */
276
277 #define xPSR_T_Pos 24U /*!< xPSR: T Position */
278 #define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
279
280 #define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
281 #define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
282
283
284 /**
285 \brief Union type to access the Control Registers (CONTROL).
286 */
287 typedef union
288 {
289 struct
290 {
291 uint32_t _reserved0:1; /*!< bit: 0 Reserved */
292 uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
293 uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */
294 } b; /*!< Structure used for bit access */
295 uint32_t w; /*!< Type used for word access */
296 } CONTROL_Type;
297
298 /** \brief CONTROL Register Definitions */
299 #define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */
300 #define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */
301
302 /*@} end of group CMSIS_CORE */
303
304
305 /**
306 \ingroup CMSIS_core_register
307 \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
308 \brief Type definitions for the NVIC Registers
309 @{
310 */
311
312 /**
313 \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
314 */
315 typedef struct
316 {
317 __IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
318 uint32_t RESERVED0[31U];
319 __IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
320 uint32_t RESERVED1[31U];
321 __IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
322 uint32_t RESERVED2[31U];
323 __IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
324 uint32_t RESERVED3[31U];
325 uint32_t RESERVED4[64U];
326 __IOM uint32_t IPR[8U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
327 } NVIC_Type;
328
329 /*@} end of group CMSIS_NVIC */
330
331
332 /**
333 \ingroup CMSIS_core_register
334 \defgroup CMSIS_SCB System Control Block (SCB)
335 \brief Type definitions for the System Control Block Registers
336 @{
337 */
338
339 /**
340 \brief Structure type to access the System Control Block (SCB).
341 */
342 typedef struct
343 {
344 __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
345 __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
346 uint32_t RESERVED0;
347 __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
348 __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
349 __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
350 uint32_t RESERVED1;
351 __IOM uint32_t SHPR[2U]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
352 __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
353 } SCB_Type;
354
355 /** \brief SCB CPUID Register Definitions */
356 #define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */
357 #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
358
359 #define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */
360 #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
361
362 #define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */
363 #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
364
365 #define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */
366 #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
367
368 #define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */
369 #define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */
370
371 /** \brief SCB Interrupt Control State Register Definitions */
372 #define SCB_ICSR_NMIPENDSET_Pos 31U /*!< SCB ICSR: NMIPENDSET Position */
373 #define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
374
375 #define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */
376 #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
377
378 #define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */
379 #define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
380
381 #define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */
382 #define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
383
384 #define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */
385 #define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
386
387 #define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */
388 #define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
389
390 #define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */
391 #define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
392
393 #define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */
394 #define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
395
396 #define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */
397 #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
398
399 /** \brief SCB Application Interrupt and Reset Control Register Definitions */
400 #define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */
401 #define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
402
403 #define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */
404 #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
405
406 #define SCB_AIRCR_ENDIANNESS_Pos 15U /*!< SCB AIRCR: ENDIANNESS Position */
407 #define SCB_AIRCR_ENDIANNESS_Msk (1UL << SCB_AIRCR_ENDIANNESS_Pos) /*!< SCB AIRCR: ENDIANNESS Mask */
408
409 #define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */
410 #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
411
412 #define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */
413 #define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
414
415 /** \brief SCB System Control Register Definitions */
416 #define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */
417 #define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
418
419 #define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */
420 #define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
421
422 #define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */
423 #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
424
425 /** \brief SCB Configuration Control Register Definitions */
426 #define SCB_CCR_STKALIGN_Pos 9U /*!< SCB CCR: STKALIGN Position */
427 #define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
428
429 #define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */
430 #define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
431
432 /** \brief SCB System Handler Control and State Register Definitions */
433 #define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */
434 #define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
435
436 /*@} end of group CMSIS_SCB */
437
438
439 /**
440 \ingroup CMSIS_core_register
441 \defgroup CMSIS_SysTick System Tick Timer (SysTick)
442 \brief Type definitions for the System Timer Registers.
443 @{
444 */
445
446 /**
447 \brief Structure type to access the System Timer (SysTick).
448 */
449 typedef struct
450 {
451 __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
452 __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
453 __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
454 __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
455 } SysTick_Type;
456
457 /** \brief SysTick Control / Status Register Definitions */
458 #define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */
459 #define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
460
461 #define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */
462 #define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
463
464 #define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */
465 #define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
466
467 #define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */
468 #define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */
469
470 /** \brief SysTick Reload Register Definitions */
471 #define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */
472 #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */
473
474 /** \brief SysTick Current Register Definitions */
475 #define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */
476 #define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */
477
478 /** \brief SysTick Calibration Register Definitions */
479 #define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */
480 #define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
481
482 #define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */
483 #define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
484
485 #define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */
486 #define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */
487
488 /*@} end of group CMSIS_SysTick */
489
490
491 /**
492 \ingroup CMSIS_core_register
493 \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
494 \brief Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor.
495 Therefore they are not covered by the Cortex-M0 header file.
496 @{
497 */
498 /*@} end of group CMSIS_CoreDebug */
499
500
501 /**
502 \ingroup CMSIS_core_register
503 \defgroup CMSIS_core_bitfield Core register bit field macros
504 \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
505 @{
506 */
507
508 /**
509 \brief Mask and shift a bit field value for use in a register bit range.
510 \param[in] field Name of the register bit field.
511 \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
512 \return Masked and shifted value.
513 */
514 #define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
515
516 /**
517 \brief Mask and shift a register value to extract a bit field value.
518 \param[in] field Name of the register bit field.
519 \param[in] value Value of register. This parameter is interpreted as an uint32_t type.
520 \return Masked and shifted bit field value.
521 */
522 #define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
523
524 /*@} end of group CMSIS_core_bitfield */
525
526
527 /**
528 \ingroup CMSIS_core_register
529 \defgroup CMSIS_core_base Core Definitions
530 \brief Definitions for base addresses, unions, and structures.
531 @{
532 */
533
534 /* Memory mapping of Core Hardware */
535 #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
536 #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
537 #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
538 #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
539
540 #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
541 #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
542 #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
543
544
545 /*@} */
546
547
548 /**
549 \defgroup CMSIS_deprecated_aliases Backwards Compatibility Aliases
550 \brief Alias definitions present for backwards compatibility for deprecated symbols.
551 @{
552 */
553
554 #ifndef CMSIS_DISABLE_DEPRECATED
555
556 #define SCB_AIRCR_ENDIANESS_Pos SCB_AIRCR_ENDIANNESS_Pos
557 #define SCB_AIRCR_ENDIANESS_Msk SCB_AIRCR_ENDIANNESS_Msk
558
559 #endif // CMSIS_DISABLE_DEPRECATED
560
561 /*@} */
562
563
564 /*******************************************************************************
565 * Hardware Abstraction Layer
566 Core Function Interface contains:
567 - Core NVIC Functions
568 - Core SysTick Functions
569 - Core Register Access Functions
570 ******************************************************************************/
571 /**
572 \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
573 */
574
575
576
577 /* ########################## NVIC functions #################################### */
578 /**
579 \ingroup CMSIS_Core_FunctionInterface
580 \defgroup CMSIS_Core_NVICFunctions NVIC Functions
581 \brief Functions that manage interrupts and exceptions via the NVIC.
582 @{
583 */
584
585 #ifdef CMSIS_NVIC_VIRTUAL
586 #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE
587 #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h"
588 #endif
589 #include CMSIS_NVIC_VIRTUAL_HEADER_FILE
590 #else
591 #define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
592 #define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
593 #define NVIC_EnableIRQ __NVIC_EnableIRQ
594 #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
595 #define NVIC_DisableIRQ __NVIC_DisableIRQ
596 #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
597 #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
598 #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ
599 /* NVIC_GetActive not available for Cortex-M0 */
600 #define NVIC_SetPriority __NVIC_SetPriority
601 #define NVIC_GetPriority __NVIC_GetPriority
602 #define NVIC_SystemReset __NVIC_SystemReset
603 #endif /* CMSIS_NVIC_VIRTUAL */
604
605 #ifdef CMSIS_VECTAB_VIRTUAL
606 #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE
607 #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h"
608 #endif
609 #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE
610 #else
611 #define NVIC_SetVector __NVIC_SetVector
612 #define NVIC_GetVector __NVIC_GetVector
613 #endif /* (CMSIS_VECTAB_VIRTUAL) */
614
615 #define NVIC_USER_IRQ_OFFSET 16
616
617
618 /* The following EXC_RETURN values are saved the LR on exception entry */
619 #define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */
620 #define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */
621 #define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */
622
623
624 /* Interrupt Priorities are WORD accessible only under Armv6-M */
625 /* The following MACROS handle generation of the register offset and byte masks */
626 #define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
627 #define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
628 #define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
629
630 #define __NVIC_SetPriorityGrouping(X) (void)(X)
631 #define __NVIC_GetPriorityGrouping() (0U)
632
633 /**
634 \brief Enable Interrupt
635 \details Enables a device specific interrupt in the NVIC interrupt controller.
636 \param [in] IRQn Device specific interrupt number.
637 \note IRQn must not be negative.
638 */
__NVIC_EnableIRQ(IRQn_Type IRQn)639 __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
640 {
641 if ((int32_t)(IRQn) >= 0)
642 {
643 __COMPILER_BARRIER();
644 NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
645 __COMPILER_BARRIER();
646 }
647 }
648
649
650 /**
651 \brief Get Interrupt Enable status
652 \details Returns a device specific interrupt enable status from the NVIC interrupt controller.
653 \param [in] IRQn Device specific interrupt number.
654 \return 0 Interrupt is not enabled.
655 \return 1 Interrupt is enabled.
656 \note IRQn must not be negative.
657 */
__NVIC_GetEnableIRQ(IRQn_Type IRQn)658 __STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
659 {
660 if ((int32_t)(IRQn) >= 0)
661 {
662 return((uint32_t)(((NVIC->ISER[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
663 }
664 else
665 {
666 return(0U);
667 }
668 }
669
670
671 /**
672 \brief Disable Interrupt
673 \details Disables a device specific interrupt in the NVIC interrupt controller.
674 \param [in] IRQn Device specific interrupt number.
675 \note IRQn must not be negative.
676 */
__NVIC_DisableIRQ(IRQn_Type IRQn)677 __STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn)
678 {
679 if ((int32_t)(IRQn) >= 0)
680 {
681 NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
682 __DSB();
683 __ISB();
684 }
685 }
686
687
688 /**
689 \brief Get Pending Interrupt
690 \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
691 \param [in] IRQn Device specific interrupt number.
692 \return 0 Interrupt status is not pending.
693 \return 1 Interrupt status is pending.
694 \note IRQn must not be negative.
695 */
__NVIC_GetPendingIRQ(IRQn_Type IRQn)696 __STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn)
697 {
698 if ((int32_t)(IRQn) >= 0)
699 {
700 return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
701 }
702 else
703 {
704 return(0U);
705 }
706 }
707
708
709 /**
710 \brief Set Pending Interrupt
711 \details Sets the pending bit of a device specific interrupt in the NVIC pending register.
712 \param [in] IRQn Device specific interrupt number.
713 \note IRQn must not be negative.
714 */
__NVIC_SetPendingIRQ(IRQn_Type IRQn)715 __STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn)
716 {
717 if ((int32_t)(IRQn) >= 0)
718 {
719 NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
720 }
721 }
722
723
724 /**
725 \brief Clear Pending Interrupt
726 \details Clears the pending bit of a device specific interrupt in the NVIC pending register.
727 \param [in] IRQn Device specific interrupt number.
728 \note IRQn must not be negative.
729 */
__NVIC_ClearPendingIRQ(IRQn_Type IRQn)730 __STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn)
731 {
732 if ((int32_t)(IRQn) >= 0)
733 {
734 NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
735 }
736 }
737
738
739 /**
740 \brief Set Interrupt Priority
741 \details Sets the priority of a device specific interrupt or a processor exception.
742 The interrupt number can be positive to specify a device specific interrupt,
743 or negative to specify a processor exception.
744 \param [in] IRQn Interrupt number.
745 \param [in] priority Priority to set.
746 \note The priority cannot be set for every processor exception.
747 */
__NVIC_SetPriority(IRQn_Type IRQn,uint32_t priority)748 __STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
749 {
750 if ((int32_t)(IRQn) >= 0)
751 {
752 NVIC->IPR[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IPR[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
753 (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
754 }
755 else
756 {
757 SCB->SHPR[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHPR[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
758 (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
759 }
760 }
761
762
763 /**
764 \brief Get Interrupt Priority
765 \details Reads the priority of a device specific interrupt or a processor exception.
766 The interrupt number can be positive to specify a device specific interrupt,
767 or negative to specify a processor exception.
768 \param [in] IRQn Interrupt number.
769 \return Interrupt Priority.
770 Value is aligned automatically to the implemented priority bits of the microcontroller.
771 */
__NVIC_GetPriority(IRQn_Type IRQn)772 __STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn)
773 {
774
775 if ((int32_t)(IRQn) >= 0)
776 {
777 return((uint32_t)(((NVIC->IPR[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
778 }
779 else
780 {
781 return((uint32_t)(((SCB->SHPR[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
782 }
783 }
784
785
786 /**
787 \brief Encode Priority
788 \details Encodes the priority for an interrupt with the given priority group,
789 preemptive priority value, and subpriority value.
790 In case of a conflict between priority grouping and available
791 priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
792 \param [in] PriorityGroup Used priority group.
793 \param [in] PreemptPriority Preemptive priority value (starting from 0).
794 \param [in] SubPriority Subpriority value (starting from 0).
795 \return Encoded priority. Value can be used in the function \ref NVIC_SetPriority().
796 */
NVIC_EncodePriority(uint32_t PriorityGroup,uint32_t PreemptPriority,uint32_t SubPriority)797 __STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
798 {
799 uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
800 uint32_t PreemptPriorityBits;
801 uint32_t SubPriorityBits;
802
803 PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
804 SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
805
806 return (
807 ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) |
808 ((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL)))
809 );
810 }
811
812
813 /**
814 \brief Decode Priority
815 \details Decodes an interrupt priority value with a given priority group to
816 preemptive priority value and subpriority value.
817 In case of a conflict between priority grouping and available
818 priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.
819 \param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority().
820 \param [in] PriorityGroup Used priority group.
821 \param [out] pPreemptPriority Preemptive priority value (starting from 0).
822 \param [out] pSubPriority Subpriority value (starting from 0).
823 */
NVIC_DecodePriority(uint32_t Priority,uint32_t PriorityGroup,uint32_t * const pPreemptPriority,uint32_t * const pSubPriority)824 __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority)
825 {
826 uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
827 uint32_t PreemptPriorityBits;
828 uint32_t SubPriorityBits;
829
830 PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
831 SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
832
833 *pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL);
834 *pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL);
835 }
836
837
838 /**
839 \brief Set Interrupt Vector
840 \details Sets an interrupt vector in SRAM based interrupt vector table.
841 The interrupt number can be positive to specify a device specific interrupt,
842 or negative to specify a processor exception.
843 Address 0 must be mapped to SRAM.
844 \param [in] IRQn Interrupt number
845 \param [in] vector Address of interrupt handler function
846 */
__NVIC_SetVector(IRQn_Type IRQn,uint32_t vector)847 __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
848 {
849 uint32_t *vectors = (uint32_t *)(NVIC_USER_IRQ_OFFSET << 2); /* point to 1st user interrupt */
850 *(vectors + (int32_t)IRQn) = vector; /* use pointer arithmetic to access vector */
851 /* ARM Application Note 321 states that the M0 does not require the architectural barrier */
852 }
853
854
855 /**
856 \brief Get Interrupt Vector
857 \details Reads an interrupt vector from interrupt vector table.
858 The interrupt number can be positive to specify a device specific interrupt,
859 or negative to specify a processor exception.
860 \param [in] IRQn Interrupt number.
861 \return Address of interrupt handler function
862 */
__NVIC_GetVector(IRQn_Type IRQn)863 __STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
864 {
865 uint32_t *vectors = (uint32_t *)(NVIC_USER_IRQ_OFFSET << 2); /* point to 1st user interrupt */
866 return *(vectors + (int32_t)IRQn); /* use pointer arithmetic to access vector */
867 }
868
869
870 /**
871 \brief System Reset
872 \details Initiates a system reset request to reset the MCU.
873 */
__NVIC_SystemReset(void)874 __NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
875 {
876 __DSB(); /* Ensure all outstanding memory accesses included
877 buffered write are completed before reset */
878 SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
879 SCB_AIRCR_SYSRESETREQ_Msk);
880 __DSB(); /* Ensure completion of memory access */
881
882 for(;;) /* wait until reset */
883 {
884 __NOP();
885 }
886 }
887
888 /*@} end of CMSIS_Core_NVICFunctions */
889
890
891 /* ########################## FPU functions #################################### */
892 /**
893 \ingroup CMSIS_Core_FunctionInterface
894 \defgroup CMSIS_Core_FpuFunctions FPU Functions
895 \brief Function that provides FPU type.
896 @{
897 */
898
899 /**
900 \brief get FPU type
901 \details returns the FPU type
902 \returns
903 - \b 0: No FPU
904 - \b 1: Single precision FPU
905 - \b 2: Double + Single precision FPU
906 */
SCB_GetFPUType(void)907 __STATIC_INLINE uint32_t SCB_GetFPUType(void)
908 {
909 return 0U; /* No FPU */
910 }
911
912
913 /*@} end of CMSIS_Core_FpuFunctions */
914
915
916
917 /* ################################## SysTick function ############################################ */
918 /**
919 \ingroup CMSIS_Core_FunctionInterface
920 \defgroup CMSIS_Core_SysTickFunctions SysTick Functions
921 \brief Functions that configure the System.
922 @{
923 */
924
925 #if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
926
927 /**
928 \brief System Tick Configuration
929 \details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
930 Counter is in free running mode to generate periodic interrupts.
931 \param [in] ticks Number of ticks between two interrupts.
932 \return 0 Function succeeded.
933 \return 1 Function failed.
934 \note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
935 function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
936 must contain a vendor-specific implementation of this function.
937 */
SysTick_Config(uint32_t ticks)938 __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
939 {
940 if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
941 {
942 return (1UL); /* Reload value impossible */
943 }
944
945 SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
946 NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
947 SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
948 SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
949 SysTick_CTRL_TICKINT_Msk |
950 SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
951 return (0UL); /* Function successful */
952 }
953
954 #endif
955
956 /*@} end of CMSIS_Core_SysTickFunctions */
957
958
959
960
961 #ifdef __cplusplus
962 }
963 #endif
964
965 #endif /* __CORE_CM0_H_DEPENDANT */
966
967 #endif /* __CMSIS_GENERIC */
968