1 /**
2   ******************************************************************************
3   * @file    stm32c0xx.h
4   * @author  MCD Application Team
5   * @brief   CMSIS STM32C0xx Device Peripheral Access Layer Header File.
6   *
7   *          The file is the unique include file that the application programmer
8   *          is using in the C source code, usually in main.c. This file contains:
9   *           - Configuration section that allows to select:
10   *              - The STM32C0xx device used in the target application
11   *              - To use or not the peripherals drivers in application code(i.e.
12   *                code will be based on direct access to peripherals registers
13   *                rather than drivers API), this option is controlled by
14   *                "#define USE_HAL_DRIVER"
15   *
16   ******************************************************************************
17   * @attention
18   *
19   * Copyright (c) 2022 STMicroelectronics.
20   * All rights reserved.
21   *
22   * This software is licensed under terms that can be found in the LICENSE file
23   * in the root directory of this software component.
24   * If no LICENSE file comes with this software, it is provided AS-IS.
25   *
26   ******************************************************************************
27   */
28 
29 /** @addtogroup CMSIS
30   * @{
31   */
32 
33 /** @addtogroup stm32c0xx
34   * @{
35   */
36 
37 #ifndef STM32C0xx_H
38 #define STM32C0xx_H
39 
40 #ifdef __cplusplus
41  extern "C" {
42 #endif /* __cplusplus */
43 
44 /** @addtogroup Library_configuration_section
45   * @{
46   */
47 
48 /**
49   * @brief STM32 Family
50   */
51 #if !defined (STM32C0)
52 #define STM32C0
53 #endif /* STM32C0 */
54 
55 /* Uncomment the line below according to the target STM32C0 device used in your
56    application
57   */
58 
59 #if !defined (STM32C011xx) && !defined (STM32C031xx) && !defined (STM32C071xx)
60   /* #define STM32C011xx */   /*!< STM32C011xx Devices */
61   /* #define STM32C031xx */   /*!< STM32C031xx Devices */
62   /* #define STM32C071xx */   /*!< STM32C071xx Devices */
63 #endif
64 
65 /*  Tip: To avoid modifying this file each time you need to switch between these
66         devices, you can define the device in your toolchain compiler preprocessor.
67   */
68 #if !defined  (USE_HAL_DRIVER)
69 /**
70  * @brief Comment the line below if you will not use the peripherals drivers.
71    In this case, these drivers will not be included and the application code will
72    be based on direct access to peripherals registers
73    */
74   /*#define USE_HAL_DRIVER */
75 #endif /* USE_HAL_DRIVER */
76 
77 /**
78   * @brief CMSIS Device version number V1.0.0
79   */
80 #define __STM32C0_CMSIS_VERSION_MAIN   (0x01U) /*!< [31:24] main version */
81 #define __STM32C0_CMSIS_VERSION_SUB1   (0x02U) /*!< [23:16] sub1 version */
82 #define __STM32C0_CMSIS_VERSION_SUB2   (0x00U) /*!< [15:8]  sub2 version */
83 #define __STM32C0_CMSIS_VERSION_RC     (0x00U) /*!< [7:0]  release candidate */
84 #define __STM32C0_CMSIS_VERSION        ((__STM32C0_CMSIS_VERSION_MAIN << 24)\
85                                        |(__STM32C0_CMSIS_VERSION_SUB1 << 16)\
86                                        |(__STM32C0_CMSIS_VERSION_SUB2 << 8 )\
87                                        |(__STM32C0_CMSIS_VERSION_RC))
88 
89 /**
90   * @}
91   */
92 
93 /** @addtogroup Device_Included
94   * @{
95   */
96 
97 #if defined(STM32C011xx)
98   #include "stm32c011xx.h"
99 #elif defined(STM32C031xx)
100   #include "stm32c031xx.h"
101 #elif defined(STM32C071xx)
102   #include "stm32c071xx.h"
103 #else
104  #error "Please select first the target STM32C0xx device used in your application (in stm32c0xx.h file)"
105 #endif
106 
107 /**
108   * @}
109   */
110 
111 /** @addtogroup Exported_types
112   * @{
113   */
114 typedef enum
115 {
116   RESET = 0,
117   SET = !RESET
118 } FlagStatus, ITStatus;
119 
120 typedef enum
121 {
122   DISABLE = 0,
123   ENABLE = !DISABLE
124 } FunctionalState;
125 #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
126 
127 typedef enum
128 {
129   SUCCESS = 0,
130   ERROR = !SUCCESS
131 } ErrorStatus;
132 
133 /**
134   * @}
135   */
136 
137 /** @addtogroup Exported_macros
138   * @{
139   */
140 #define SET_BIT(REG, BIT)     ((REG) |= (BIT))
141 
142 #define CLEAR_BIT(REG, BIT)   ((REG) &= ~(BIT))
143 
144 #define READ_BIT(REG, BIT)    ((REG) & (BIT))
145 
146 #define CLEAR_REG(REG)        ((REG) = (0x0))
147 
148 #define WRITE_REG(REG, VAL)   ((REG) = (VAL))
149 
150 #define READ_REG(REG)         ((REG))
151 
152 #define MODIFY_REG(REG, CLEARMASK, SETMASK)  WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
153 
154 /* Use of interrupt control for register exclusive access */
155 /* Atomic 32-bit register access macro to set one or several bits */
156 #define ATOMIC_SET_BIT(REG, BIT)                             \
157   do {                                                       \
158     uint32_t primask;                                        \
159     primask = __get_PRIMASK();                               \
160     __set_PRIMASK(1);                                        \
161     SET_BIT((REG), (BIT));                                   \
162     __set_PRIMASK(primask);                                  \
163   } while(0)
164 
165 /* Atomic 32-bit register access macro to clear one or several bits */
166 #define ATOMIC_CLEAR_BIT(REG, BIT)                           \
167   do {                                                       \
168     uint32_t primask;                                        \
169     primask = __get_PRIMASK();                               \
170     __set_PRIMASK(1);                                        \
171     CLEAR_BIT((REG), (BIT));                                 \
172     __set_PRIMASK(primask);                                  \
173   } while(0)
174 
175 /* Atomic 32-bit register access macro to clear and set one or several bits */
176 #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK)            \
177   do {                                                       \
178     uint32_t primask;                                        \
179     primask = __get_PRIMASK();                               \
180     __set_PRIMASK(1);                                        \
181     MODIFY_REG((REG), (CLEARMSK), (SETMASK));                \
182     __set_PRIMASK(primask);                                  \
183   } while(0)
184 
185 /* Atomic 16-bit register access macro to set one or several bits */
186 #define ATOMIC_SETH_BIT(REG, BIT) ATOMIC_SET_BIT(REG, BIT)                                   \
187 
188 /* Atomic 16-bit register access macro to clear one or several bits */
189 #define ATOMIC_CLEARH_BIT(REG, BIT) ATOMIC_CLEAR_BIT(REG, BIT)                               \
190 
191 /* Atomic 16-bit register access macro to clear and set one or several bits */
192 #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK) ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \
193 
194 #define POSITION_VAL(VAL)     (__CLZ(__RBIT(VAL)))
195 /**
196   * @}
197   */
198 
199 #if defined (USE_HAL_DRIVER)
200  #include "stm32c0xx_hal.h"
201 #endif /* USE_HAL_DRIVER */
202 
203 #ifdef __cplusplus
204 }
205 #endif /* __cplusplus */
206 
207 #endif /* STM32C0xx_H */
208 /**
209   * @}
210   */
211 
212 /**
213   * @}
214   */
215 
216