| 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) | 
|---|
| 60 |   /* #define STM32C011xx */   /*!< STM32C011xx Devices */ | 
|---|
| 61 |   /* #define STM32C031xx */   /*!< STM32C031xx Devices */ | 
|---|
| 62 | #endif | 
|---|
| 63 |  | 
|---|
| 64 | /*  Tip: To avoid modifying this file each time you need to switch between these | 
|---|
| 65 |         devices, you can define the device in your toolchain compiler preprocessor. | 
|---|
| 66 |   */ | 
|---|
| 67 | #if !defined  (USE_HAL_DRIVER) | 
|---|
| 68 | /** | 
|---|
| 69 |  * @brief Comment the line below if you will not use the peripherals drivers. | 
|---|
| 70 |    In this case, these drivers will not be included and the application code will | 
|---|
| 71 |    be based on direct access to peripherals registers | 
|---|
| 72 |    */ | 
|---|
| 73 |   /*#define USE_HAL_DRIVER */ | 
|---|
| 74 | #endif /* USE_HAL_DRIVER */ | 
|---|
| 75 |  | 
|---|
| 76 | /** | 
|---|
| 77 |   * @brief CMSIS Device version number V1.0.0 | 
|---|
| 78 |   */ | 
|---|
| 79 | #define __STM32C0_CMSIS_VERSION_MAIN   (0x01U) /*!< [31:24] main version */ | 
|---|
| 80 | #define __STM32C0_CMSIS_VERSION_SUB1   (0x00U) /*!< [23:16] sub1 version */ | 
|---|
| 81 | #define __STM32C0_CMSIS_VERSION_SUB2   (0x00U) /*!< [15:8]  sub2 version */ | 
|---|
| 82 | #define __STM32C0_CMSIS_VERSION_RC     (0x00U) /*!< [7:0]  release candidate */ | 
|---|
| 83 | #define __STM32C0_CMSIS_VERSION        ((__STM32C0_CMSIS_VERSION_MAIN << 24)\ | 
|---|
| 84 |                                        |(__STM32C0_CMSIS_VERSION_SUB1 << 16)\ | 
|---|
| 85 |                                        |(__STM32C0_CMSIS_VERSION_SUB2 << 8 )\ | 
|---|
| 86 |                                        |(__STM32C0_CMSIS_VERSION_RC)) | 
|---|
| 87 |  | 
|---|
| 88 | /** | 
|---|
| 89 |   * @} | 
|---|
| 90 |   */ | 
|---|
| 91 |  | 
|---|
| 92 | /** @addtogroup Device_Included | 
|---|
| 93 |   * @{ | 
|---|
| 94 |   */ | 
|---|
| 95 |  | 
|---|
| 96 | #if defined(STM32C011xx) | 
|---|
| 97 |   #include "stm32c011xx.h" | 
|---|
| 98 | #elif defined(STM32C031xx) | 
|---|
| 99 |   #include "stm32c031xx.h" | 
|---|
| 100 | #else | 
|---|
| 101 |  #error "Please select first the target STM32C0xx device used in your application (in stm32c0xx.h file)" | 
|---|
| 102 | #endif | 
|---|
| 103 |  | 
|---|
| 104 | /** | 
|---|
| 105 |   * @} | 
|---|
| 106 |   */ | 
|---|
| 107 |  | 
|---|
| 108 | /** @addtogroup Exported_types | 
|---|
| 109 |   * @{ | 
|---|
| 110 |   */ | 
|---|
| 111 | typedef enum | 
|---|
| 112 | { | 
|---|
| 113 |   RESET = 0, | 
|---|
| 114 |   SET = !RESET | 
|---|
| 115 | } FlagStatus, ITStatus; | 
|---|
| 116 |  | 
|---|
| 117 | typedef enum | 
|---|
| 118 | { | 
|---|
| 119 |   DISABLE = 0, | 
|---|
| 120 |   ENABLE = !DISABLE | 
|---|
| 121 | } FunctionalState; | 
|---|
| 122 | #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE)) | 
|---|
| 123 |  | 
|---|
| 124 | typedef enum | 
|---|
| 125 | { | 
|---|
| 126 |   SUCCESS = 0, | 
|---|
| 127 |   ERROR = !SUCCESS | 
|---|
| 128 | } ErrorStatus; | 
|---|
| 129 |  | 
|---|
| 130 | /** | 
|---|
| 131 |   * @} | 
|---|
| 132 |   */ | 
|---|
| 133 |  | 
|---|
| 134 | /** @addtogroup Exported_macros | 
|---|
| 135 |   * @{ | 
|---|
| 136 |   */ | 
|---|
| 137 | #define SET_BIT(REG, BIT)     ((REG) |= (BIT)) | 
|---|
| 138 |  | 
|---|
| 139 | #define CLEAR_BIT(REG, BIT)   ((REG) &= ~(BIT)) | 
|---|
| 140 |  | 
|---|
| 141 | #define READ_BIT(REG, BIT)    ((REG) & (BIT)) | 
|---|
| 142 |  | 
|---|
| 143 | #define CLEAR_REG(REG)        ((REG) = (0x0)) | 
|---|
| 144 |  | 
|---|
| 145 | #define WRITE_REG(REG, VAL)   ((REG) = (VAL)) | 
|---|
| 146 |  | 
|---|
| 147 | #define READ_REG(REG)         ((REG)) | 
|---|
| 148 |  | 
|---|
| 149 | #define MODIFY_REG(REG, CLEARMASK, SETMASK)  WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK))) | 
|---|
| 150 |  | 
|---|
| 151 | /* Use of interrupt control for register exclusive access */ | 
|---|
| 152 | /* Atomic 32-bit register access macro to set one or several bits */ | 
|---|
| 153 | #define ATOMIC_SET_BIT(REG, BIT)                             \ | 
|---|
| 154 |   do {                                                       \ | 
|---|
| 155 |     uint32_t primask;                                        \ | 
|---|
| 156 |     primask = __get_PRIMASK();                               \ | 
|---|
| 157 |     __set_PRIMASK(1);                                        \ | 
|---|
| 158 |     SET_BIT((REG), (BIT));                                   \ | 
|---|
| 159 |     __set_PRIMASK(primask);                                  \ | 
|---|
| 160 |   } while(0) | 
|---|
| 161 |  | 
|---|
| 162 | /* Atomic 32-bit register access macro to clear one or several bits */ | 
|---|
| 163 | #define ATOMIC_CLEAR_BIT(REG, BIT)                           \ | 
|---|
| 164 |   do {                                                       \ | 
|---|
| 165 |     uint32_t primask;                                        \ | 
|---|
| 166 |     primask = __get_PRIMASK();                               \ | 
|---|
| 167 |     __set_PRIMASK(1);                                        \ | 
|---|
| 168 |     CLEAR_BIT((REG), (BIT));                                 \ | 
|---|
| 169 |     __set_PRIMASK(primask);                                  \ | 
|---|
| 170 |   } while(0) | 
|---|
| 171 |  | 
|---|
| 172 | /* Atomic 32-bit register access macro to clear and set one or several bits */ | 
|---|
| 173 | #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK)            \ | 
|---|
| 174 |   do {                                                       \ | 
|---|
| 175 |     uint32_t primask;                                        \ | 
|---|
| 176 |     primask = __get_PRIMASK();                               \ | 
|---|
| 177 |     __set_PRIMASK(1);                                        \ | 
|---|
| 178 |     MODIFY_REG((REG), (CLEARMSK), (SETMASK));                \ | 
|---|
| 179 |     __set_PRIMASK(primask);                                  \ | 
|---|
| 180 |   } while(0) | 
|---|
| 181 |  | 
|---|
| 182 | /* Atomic 16-bit register access macro to set one or several bits */ | 
|---|
| 183 | #define ATOMIC_SETH_BIT(REG, BIT) ATOMIC_SET_BIT(REG, BIT)                                   \ | 
|---|
| 184 |  | 
|---|
| 185 | /* Atomic 16-bit register access macro to clear one or several bits */ | 
|---|
| 186 | #define ATOMIC_CLEARH_BIT(REG, BIT) ATOMIC_CLEAR_BIT(REG, BIT)                               \ | 
|---|
| 187 |  | 
|---|
| 188 | /* Atomic 16-bit register access macro to clear and set one or several bits */ | 
|---|
| 189 | #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK) ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \ | 
|---|
| 190 |  | 
|---|
| 191 | #define POSITION_VAL(VAL)     (__CLZ(__RBIT(VAL))) | 
|---|
| 192 | /** | 
|---|
| 193 |   * @} | 
|---|
| 194 |   */ | 
|---|
| 195 |  | 
|---|
| 196 | #if defined (USE_HAL_DRIVER) | 
|---|
| 197 |  #include "stm32c0xx_hal.h" | 
|---|
| 198 | #endif /* USE_HAL_DRIVER */ | 
|---|
| 199 |  | 
|---|
| 200 | #ifdef __cplusplus | 
|---|
| 201 | } | 
|---|
| 202 | #endif /* __cplusplus */ | 
|---|
| 203 |  | 
|---|
| 204 | #endif /* STM32C0xx_H */ | 
|---|
| 205 | /** | 
|---|
| 206 |   * @} | 
|---|
| 207 |   */ | 
|---|
| 208 |  | 
|---|
| 209 | /** | 
|---|
| 210 |   * @} | 
|---|
| 211 |   */ | 
|---|
| 212 |  | 
|---|