stm32f1xx.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx.h
  4. * @author MCD Application Team
  5. * @brief CMSIS STM32F1xx 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 STM32F1xx 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) 2017-2021 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 stm32f1xx
  32. * @{
  33. */
  34. #ifndef __STM32F1XX_H
  35. #define __STM32F1XX_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 (STM32F1)
  46. #define STM32F1
  47. #endif /* STM32F1 */
  48. /* Uncomment the line below according to the target STM32L device used in your
  49. application
  50. */
  51. #if !defined (STM32F100xB) && !defined (STM32F100xE) && !defined (STM32F101x6) && \
  52. !defined (STM32F101xB) && !defined (STM32F101xE) && !defined (STM32F101xG) && !defined (STM32F102x6) && !defined (STM32F102xB) && !defined (STM32F103x6) && \
  53. !defined (STM32F103xB) && !defined (STM32F103xE) && !defined (STM32F103xG) && !defined (STM32F105xC) && !defined (STM32F107xC)
  54. /* #define STM32F100xB */ /*!< STM32F100C4, STM32F100R4, STM32F100C6, STM32F100R6, STM32F100C8, STM32F100R8, STM32F100V8, STM32F100CB, STM32F100RB and STM32F100VB */
  55. /* #define STM32F100xE */ /*!< STM32F100RC, STM32F100VC, STM32F100ZC, STM32F100RD, STM32F100VD, STM32F100ZD, STM32F100RE, STM32F100VE and STM32F100ZE */
  56. /* #define STM32F101x6 */ /*!< STM32F101C4, STM32F101R4, STM32F101T4, STM32F101C6, STM32F101R6 and STM32F101T6 Devices */
  57. /* #define STM32F101xB */ /*!< STM32F101C8, STM32F101R8, STM32F101T8, STM32F101V8, STM32F101CB, STM32F101RB, STM32F101TB and STM32F101VB */
  58. /* #define STM32F101xE */ /*!< STM32F101RC, STM32F101VC, STM32F101ZC, STM32F101RD, STM32F101VD, STM32F101ZD, STM32F101RE, STM32F101VE and STM32F101ZE */
  59. /* #define STM32F101xG */ /*!< STM32F101RF, STM32F101VF, STM32F101ZF, STM32F101RG, STM32F101VG and STM32F101ZG */
  60. /* #define STM32F102x6 */ /*!< STM32F102C4, STM32F102R4, STM32F102C6 and STM32F102R6 */
  61. /* #define STM32F102xB */ /*!< STM32F102C8, STM32F102R8, STM32F102CB and STM32F102RB */
  62. /* #define STM32F103x6 */ /*!< STM32F103C4, STM32F103R4, STM32F103T4, STM32F103C6, STM32F103R6 and STM32F103T6 */
  63. /* #define STM32F103xB */ /*!< STM32F103C8, STM32F103R8, STM32F103T8, STM32F103V8, STM32F103CB, STM32F103RB, STM32F103TB and STM32F103VB */
  64. /* #define STM32F103xE */ /*!< STM32F103RC, STM32F103VC, STM32F103ZC, STM32F103RD, STM32F103VD, STM32F103ZD, STM32F103RE, STM32F103VE and STM32F103ZE */
  65. /* #define STM32F103xG */ /*!< STM32F103RF, STM32F103VF, STM32F103ZF, STM32F103RG, STM32F103VG and STM32F103ZG */
  66. /* #define STM32F105xC */ /*!< STM32F105R8, STM32F105V8, STM32F105RB, STM32F105VB, STM32F105RC and STM32F105VC */
  67. /* #define STM32F107xC */ /*!< STM32F107RB, STM32F107VB, STM32F107RC and STM32F107VC */
  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
  82. */
  83. #define __STM32F1_CMSIS_VERSION_MAIN (0x04) /*!< [31:24] main version */
  84. #define __STM32F1_CMSIS_VERSION_SUB1 (0x03) /*!< [23:16] sub1 version */
  85. #define __STM32F1_CMSIS_VERSION_SUB2 (0x04) /*!< [15:8] sub2 version */
  86. #define __STM32F1_CMSIS_VERSION_RC (0x00) /*!< [7:0] release candidate */
  87. #define __STM32F1_CMSIS_VERSION ((__STM32F1_CMSIS_VERSION_MAIN << 24)\
  88. |(__STM32F1_CMSIS_VERSION_SUB1 << 16)\
  89. |(__STM32F1_CMSIS_VERSION_SUB2 << 8 )\
  90. |(__STM32F1_CMSIS_VERSION_RC))
  91. /**
  92. * @}
  93. */
  94. /** @addtogroup Device_Included
  95. * @{
  96. */
  97. #if defined(STM32F100xB)
  98. #include "stm32f100xb.h"
  99. #elif defined(STM32F100xE)
  100. #include "stm32f100xe.h"
  101. #elif defined(STM32F101x6)
  102. #include "stm32f101x6.h"
  103. #elif defined(STM32F101xB)
  104. #include "stm32f101xb.h"
  105. #elif defined(STM32F101xE)
  106. #include "stm32f101xe.h"
  107. #elif defined(STM32F101xG)
  108. #include "stm32f101xg.h"
  109. #elif defined(STM32F102x6)
  110. #include "stm32f102x6.h"
  111. #elif defined(STM32F102xB)
  112. #include "stm32f102xb.h"
  113. #elif defined(STM32F103x6)
  114. #include "stm32f103x6.h"
  115. #elif defined(STM32F103xB)
  116. #include "stm32f103xb.h"
  117. #elif defined(STM32F103xE)
  118. #include "stm32f103xe.h"
  119. #elif defined(STM32F103xG)
  120. #include "stm32f103xg.h"
  121. #elif defined(STM32F105xC)
  122. #include "stm32f105xc.h"
  123. #elif defined(STM32F107xC)
  124. #include "stm32f107xc.h"
  125. #else
  126. #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)"
  127. #endif
  128. /**
  129. * @}
  130. */
  131. /** @addtogroup Exported_types
  132. * @{
  133. */
  134. typedef enum
  135. {
  136. RESET = 0,
  137. SET = !RESET
  138. } FlagStatus, ITStatus;
  139. typedef enum
  140. {
  141. DISABLE = 0,
  142. ENABLE = !DISABLE
  143. } FunctionalState;
  144. #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
  145. typedef enum
  146. {
  147. SUCCESS = 0U,
  148. ERROR = !SUCCESS
  149. } ErrorStatus;
  150. /**
  151. * @}
  152. */
  153. /** @addtogroup Exported_macros
  154. * @{
  155. */
  156. #define SET_BIT(REG, BIT) ((REG) |= (BIT))
  157. #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT))
  158. #define READ_BIT(REG, BIT) ((REG) & (BIT))
  159. #define CLEAR_REG(REG) ((REG) = (0x0))
  160. #define WRITE_REG(REG, VAL) ((REG) = (VAL))
  161. #define READ_REG(REG) ((REG))
  162. #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
  163. #define POSITION_VAL(VAL) (__CLZ(__RBIT(VAL)))
  164. /* Use of CMSIS compiler intrinsics for register exclusive access */
  165. /* Atomic 32-bit register access macro to set one or several bits */
  166. #define ATOMIC_SET_BIT(REG, BIT) \
  167. do { \
  168. uint32_t val; \
  169. do { \
  170. val = __LDREXW((__IO uint32_t *)&(REG)) | (BIT); \
  171. } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
  172. } while(0)
  173. /* Atomic 32-bit register access macro to clear one or several bits */
  174. #define ATOMIC_CLEAR_BIT(REG, BIT) \
  175. do { \
  176. uint32_t val; \
  177. do { \
  178. val = __LDREXW((__IO uint32_t *)&(REG)) & ~(BIT); \
  179. } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
  180. } while(0)
  181. /* Atomic 32-bit register access macro to clear and set one or several bits */
  182. #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \
  183. do { \
  184. uint32_t val; \
  185. do { \
  186. val = (__LDREXW((__IO uint32_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
  187. } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
  188. } while(0)
  189. /* Atomic 16-bit register access macro to set one or several bits */
  190. #define ATOMIC_SETH_BIT(REG, BIT) \
  191. do { \
  192. uint16_t val; \
  193. do { \
  194. val = __LDREXH((__IO uint16_t *)&(REG)) | (BIT); \
  195. } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
  196. } while(0)
  197. /* Atomic 16-bit register access macro to clear one or several bits */
  198. #define ATOMIC_CLEARH_BIT(REG, BIT) \
  199. do { \
  200. uint16_t val; \
  201. do { \
  202. val = __LDREXH((__IO uint16_t *)&(REG)) & ~(BIT); \
  203. } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
  204. } while(0)
  205. /* Atomic 16-bit register access macro to clear and set one or several bits */
  206. #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK) \
  207. do { \
  208. uint16_t val; \
  209. do { \
  210. val = (__LDREXH((__IO uint16_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
  211. } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
  212. } while(0)
  213. /**
  214. * @}
  215. */
  216. #if defined (USE_HAL_DRIVER)
  217. #include "stm32f1xx_hal.h"
  218. #endif /* USE_HAL_DRIVER */
  219. #ifdef __cplusplus
  220. }
  221. #endif /* __cplusplus */
  222. #endif /* __STM32F1xx_H */
  223. /**
  224. * @}
  225. */
  226. /**
  227. * @}
  228. */