1 /** 2 ****************************************************************************** 3 * @file stm32g4xx.h 4 * @author MCD Application Team 5 * @brief CMSIS STM32G4xx 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 STM32G4xx device used in the target application 11 * - To use or not the peripheral�s drivers in application code(i.e. 12 * code will be based on direct access to peripheral�s registers 13 * rather than drivers API), this option is controlled by 14 * "#define USE_HAL_DRIVER" 15 * 16 ****************************************************************************** 17 * @attention 18 * 19 * Copyright (c) 2019 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 stm32g4xx 34 * @{ 35 */ 36 37 #ifndef __STM32G4xx_H 38 #define __STM32G4xx_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 (STM32G4) 52 #define STM32G4 53 #endif /* STM32G4 */ 54 55 /* Uncomment the line below according to the target STM32G4 device used in your 56 application 57 */ 58 59 #if !defined (STM32G431xx) && !defined (STM32G441xx) && !defined (STM32G471xx) && \ 60 !defined (STM32G473xx) && !defined (STM32G474xx) && !defined (STM32G484xx) && \ 61 !defined (STM32GBK1CB) && !defined (STM32G491xx) && !defined (STM32G4A1xx) && \ 62 !defined (STM32G411xB) && !defined (STM32G411xC) && !defined (STM32G414xx) 63 /* #define STM32G411xB */ /*!< STM32G411xB Devices */ 64 /* #define STM32G411xC */ /*!< STM32G411xC Devices */ 65 /* #define STM32G414xx */ /*!< STM32G414xx Devices */ 66 /* #define STM32G431xx */ /*!< STM32G431xx Devices */ 67 /* #define STM32G441xx */ /*!< STM32G441xx Devices */ 68 /* #define STM32G471xx */ /*!< STM32G471xx Devices */ 69 /* #define STM32G473xx */ /*!< STM32G473xx Devices */ 70 /* #define STM32G483xx */ /*!< STM32G483xx Devices */ 71 /* #define STM32G474xx */ /*!< STM32G474xx Devices */ 72 /* #define STM32G484xx */ /*!< STM32G484xx Devices */ 73 /* #define STM32G491xx */ /*!< STM32G491xx Devices */ 74 /* #define STM32G4A1xx */ /*!< STM32G4A1xx Devices */ 75 /* #define STM32GBK1CB */ /*!< STM32GBK1CB Devices */ 76 #endif 77 78 /* Tip: To avoid modifying this file each time you need to switch between these 79 devices, you can define the device in your toolchain compiler preprocessor. 80 */ 81 #if !defined (USE_HAL_DRIVER) 82 /** 83 * @brief Comment the line below if you will not use the peripherals drivers. 84 In this case, these drivers will not be included and the application code will 85 be based on direct access to peripherals registers 86 */ 87 /*#define USE_HAL_DRIVER */ 88 #endif /* USE_HAL_DRIVER */ 89 90 /** 91 * @brief CMSIS Device version number V1.2.5 92 */ 93 #define __STM32G4_CMSIS_VERSION_MAIN (0x01U) /*!< [31:24] main version */ 94 #define __STM32G4_CMSIS_VERSION_SUB1 (0x02U) /*!< [23:16] sub1 version */ 95 #define __STM32G4_CMSIS_VERSION_SUB2 (0x05U) /*!< [15:8] sub2 version */ 96 #define __STM32G4_CMSIS_VERSION_RC (0x00U) /*!< [7:0] release candidate */ 97 #define __STM32G4_CMSIS_VERSION ((__STM32G4_CMSIS_VERSION_MAIN << 24)\ 98 |(__STM32G4_CMSIS_VERSION_SUB1 << 16)\ 99 |(__STM32G4_CMSIS_VERSION_SUB2 << 8 )\ 100 |(__STM32G4_CMSIS_VERSION_RC)) 101 102 /** 103 * @} 104 */ 105 106 /** @addtogroup Device_Included 107 * @{ 108 */ 109 110 #if defined(STM32G431xx) 111 #include "stm32g431xx.h" 112 #elif defined(STM32G441xx) 113 #include "stm32g441xx.h" 114 #elif defined(STM32G471xx) 115 #include "stm32g471xx.h" 116 #elif defined(STM32G473xx) 117 #include "stm32g473xx.h" 118 #elif defined(STM32G483xx) 119 #include "stm32g483xx.h" 120 #elif defined(STM32G474xx) 121 #include "stm32g474xx.h" 122 #elif defined(STM32G484xx) 123 #include "stm32g484xx.h" 124 #elif defined(STM32G491xx) 125 #include "stm32g491xx.h" 126 #elif defined(STM32G4A1xx) 127 #include "stm32g4a1xx.h" 128 #elif defined(STM32GBK1CB) 129 #include "stm32gbk1cb.h" 130 #elif defined(STM32G411xB) 131 #include "stm32g411xb.h" 132 #elif defined(STM32G411xC) 133 #include "stm32g411xc.h" 134 #elif defined(STM32G414xx) 135 #include "stm32g414xx.h" 136 #else 137 #error "Please select first the target STM32G4xx device used in your application (in stm32g4xx.h file)" 138 #endif 139 140 /** 141 * @} 142 */ 143 144 /** @addtogroup Exported_types 145 * @{ 146 */ 147 typedef enum 148 { 149 RESET = 0, 150 SET = !RESET 151 } FlagStatus, ITStatus; 152 153 typedef enum 154 { 155 DISABLE = 0, 156 ENABLE = !DISABLE 157 } FunctionalState; 158 #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE)) 159 160 typedef enum 161 { 162 SUCCESS = 0, 163 ERROR = !SUCCESS 164 } ErrorStatus; 165 166 /** 167 * @} 168 */ 169 170 171 /** @addtogroup Exported_macros 172 * @{ 173 */ 174 #define SET_BIT(REG, BIT) ((REG) |= (BIT)) 175 176 #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT)) 177 178 #define READ_BIT(REG, BIT) ((REG) & (BIT)) 179 180 #define CLEAR_REG(REG) ((REG) = (0x0)) 181 182 #define WRITE_REG(REG, VAL) ((REG) = (VAL)) 183 184 #define READ_REG(REG) ((REG)) 185 186 #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK))) 187 188 #define POSITION_VAL(VAL) (__CLZ(__RBIT(VAL))) 189 190 /* Use of CMSIS compiler intrinsics for register exclusive access */ 191 /* Atomic 32-bit register access macro to set one or several bits */ 192 #define ATOMIC_SET_BIT(REG, BIT) \ 193 do { \ 194 uint32_t val; \ 195 do { \ 196 val = __LDREXW((__IO uint32_t *)&(REG)) | (BIT); \ 197 } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \ 198 } while(0) 199 200 /* Atomic 32-bit register access macro to clear one or several bits */ 201 #define ATOMIC_CLEAR_BIT(REG, BIT) \ 202 do { \ 203 uint32_t val; \ 204 do { \ 205 val = __LDREXW((__IO uint32_t *)&(REG)) & ~(BIT); \ 206 } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \ 207 } while(0) 208 209 /* Atomic 32-bit register access macro to clear and set one or several bits */ 210 #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \ 211 do { \ 212 uint32_t val; \ 213 do { \ 214 val = (__LDREXW((__IO uint32_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \ 215 } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \ 216 } while(0) 217 218 /* Atomic 16-bit register access macro to set one or several bits */ 219 #define ATOMIC_SETH_BIT(REG, BIT) \ 220 do { \ 221 uint16_t val; \ 222 do { \ 223 val = __LDREXH((__IO uint16_t *)&(REG)) | (BIT); \ 224 } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \ 225 } while(0) 226 227 /* Atomic 16-bit register access macro to clear one or several bits */ 228 #define ATOMIC_CLEARH_BIT(REG, BIT) \ 229 do { \ 230 uint16_t val; \ 231 do { \ 232 val = __LDREXH((__IO uint16_t *)&(REG)) & ~(BIT); \ 233 } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \ 234 } while(0) 235 236 /* Atomic 16-bit register access macro to clear and set one or several bits */ 237 #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK) \ 238 do { \ 239 uint16_t val; \ 240 do { \ 241 val = (__LDREXH((__IO uint16_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \ 242 } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \ 243 } while(0) 244 245 246 /** 247 * @} 248 */ 249 250 #if defined (USE_HAL_DRIVER) 251 #include "stm32g4xx_hal.h" 252 #endif /* USE_HAL_DRIVER */ 253 254 #ifdef __cplusplus 255 } 256 #endif /* __cplusplus */ 257 258 #endif /* __STM32G4xx_H */ 259 /** 260 * @} 261 */ 262 263 /** 264 * @} 265 */ 266 267 268 269 270