stm32g4xx.h 8.7 KB

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