stm32l4xx.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx.h
  4. * @author MCD Application Team
  5. * @brief CMSIS STM32L4xx 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 STM32L4xx 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 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 stm32l4xx
  32. * @{
  33. */
  34. #ifndef __STM32L4xx_H
  35. #define __STM32L4xx_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 (STM32L4)
  46. #define STM32L4
  47. #endif /* STM32L4 */
  48. /* Uncomment the line below according to the target STM32L4 device used in your
  49. application
  50. */
  51. #if !defined (STM32L412xx) && !defined (STM32L422xx) && \
  52. !defined (STM32L431xx) && !defined (STM32L432xx) && !defined (STM32L433xx) && !defined (STM32L442xx) && !defined (STM32L443xx) && \
  53. !defined (STM32L451xx) && !defined (STM32L452xx) && !defined (STM32L462xx) && \
  54. !defined (STM32L471xx) && !defined (STM32L475xx) && !defined (STM32L476xx) && !defined (STM32L485xx) && !defined (STM32L486xx) && \
  55. !defined (STM32L496xx) && !defined (STM32L4A6xx) && \
  56. !defined (STM32L4P5xx) && !defined (STM32L4Q5xx) && \
  57. !defined (STM32L4R5xx) && !defined (STM32L4R7xx) && !defined (STM32L4R9xx) && !defined (STM32L4S5xx) && !defined (STM32L4S7xx) && !defined (STM32L4S9xx)
  58. /* #define STM32L412xx */ /*!< STM32L412xx Devices */
  59. /* #define STM32L422xx */ /*!< STM32L422xx Devices */
  60. /* #define STM32L431xx */ /*!< STM32L431xx Devices */
  61. /* #define STM32L432xx */ /*!< STM32L432xx Devices */
  62. /* #define STM32L433xx */ /*!< STM32L433xx Devices */
  63. /* #define STM32L442xx */ /*!< STM32L442xx Devices */
  64. /* #define STM32L443xx */ /*!< STM32L443xx Devices */
  65. /* #define STM32L451xx */ /*!< STM32L451xx Devices */
  66. /* #define STM32L452xx */ /*!< STM32L452xx Devices */
  67. /* #define STM32L462xx */ /*!< STM32L462xx Devices */
  68. /* #define STM32L471xx */ /*!< STM32L471xx Devices */
  69. /* #define STM32L475xx */ /*!< STM32L475xx Devices */
  70. /* #define STM32L476xx */ /*!< STM32L476xx Devices */
  71. /* #define STM32L485xx */ /*!< STM32L485xx Devices */
  72. /* #define STM32L486xx */ /*!< STM32L486xx Devices */
  73. /* #define STM32L496xx */ /*!< STM32L496xx Devices */
  74. /* #define STM32L4A6xx */ /*!< STM32L4A6xx Devices */
  75. /* #define STM32L4P5xx */ /*!< STM32L4Q5xx Devices */
  76. /* #define STM32L4R5xx */ /*!< STM32L4R5xx Devices */
  77. /* #define STM32L4R7xx */ /*!< STM32L4R7xx Devices */
  78. /* #define STM32L4R9xx */ /*!< STM32L4R9xx Devices */
  79. /* #define STM32L4S5xx */ /*!< STM32L4S5xx Devices */
  80. /* #define STM32L4S7xx */ /*!< STM32L4S7xx Devices */
  81. /* #define STM32L4S9xx */ /*!< STM32L4S9xx Devices */
  82. #endif
  83. /* Tip: To avoid modifying this file each time you need to switch between these
  84. devices, you can define the device in your toolchain compiler preprocessor.
  85. */
  86. #if !defined (USE_HAL_DRIVER)
  87. /**
  88. * @brief Comment the line below if you will not use the peripherals drivers.
  89. In this case, these drivers will not be included and the application code will
  90. be based on direct access to peripherals registers
  91. */
  92. /*#define USE_HAL_DRIVER */
  93. #endif /* USE_HAL_DRIVER */
  94. /**
  95. * @brief CMSIS Device version number
  96. */
  97. #define __STM32L4_CMSIS_VERSION_MAIN (0x01) /*!< [31:24] main version */
  98. #define __STM32L4_CMSIS_VERSION_SUB1 (0x07) /*!< [23:16] sub1 version */
  99. #define __STM32L4_CMSIS_VERSION_SUB2 (0x04) /*!< [15:8] sub2 version */
  100. #define __STM32L4_CMSIS_VERSION_RC (0x00) /*!< [7:0] release candidate */
  101. #define __STM32L4_CMSIS_VERSION ((__STM32L4_CMSIS_VERSION_MAIN << 24)\
  102. |(__STM32L4_CMSIS_VERSION_SUB1 << 16)\
  103. |(__STM32L4_CMSIS_VERSION_SUB2 << 8 )\
  104. |(__STM32L4_CMSIS_VERSION_RC))
  105. /**
  106. * @}
  107. */
  108. /** @addtogroup Device_Included
  109. * @{
  110. */
  111. #if defined(STM32L412xx)
  112. #include "stm32l412xx.h"
  113. #elif defined(STM32L422xx)
  114. #include "stm32l422xx.h"
  115. #elif defined(STM32L431xx)
  116. #include "stm32l431xx.h"
  117. #elif defined(STM32L432xx)
  118. #include "stm32l432xx.h"
  119. #elif defined(STM32L433xx)
  120. #include "stm32l433xx.h"
  121. #elif defined(STM32L442xx)
  122. #include "stm32l442xx.h"
  123. #elif defined(STM32L443xx)
  124. #include "stm32l443xx.h"
  125. #elif defined(STM32L451xx)
  126. #include "stm32l451xx.h"
  127. #elif defined(STM32L452xx)
  128. #include "stm32l452xx.h"
  129. #elif defined(STM32L462xx)
  130. #include "stm32l462xx.h"
  131. #elif defined(STM32L471xx)
  132. #include "stm32l471xx.h"
  133. #elif defined(STM32L475xx)
  134. #include "stm32l475xx.h"
  135. #elif defined(STM32L476xx)
  136. #include "stm32l476xx.h"
  137. #elif defined(STM32L485xx)
  138. #include "stm32l485xx.h"
  139. #elif defined(STM32L486xx)
  140. #include "stm32l486xx.h"
  141. #elif defined(STM32L496xx)
  142. #include "stm32l496xx.h"
  143. #elif defined(STM32L4A6xx)
  144. #include "stm32l4a6xx.h"
  145. #elif defined(STM32L4P5xx)
  146. #include "stm32l4p5xx.h"
  147. #elif defined(STM32L4Q5xx)
  148. #include "stm32l4q5xx.h"
  149. #elif defined(STM32L4R5xx)
  150. #include "stm32l4r5xx.h"
  151. #elif defined(STM32L4R7xx)
  152. #include "stm32l4r7xx.h"
  153. #elif defined(STM32L4R9xx)
  154. #include "stm32l4r9xx.h"
  155. #elif defined(STM32L4S5xx)
  156. #include "stm32l4s5xx.h"
  157. #elif defined(STM32L4S7xx)
  158. #include "stm32l4s7xx.h"
  159. #elif defined(STM32L4S9xx)
  160. #include "stm32l4s9xx.h"
  161. #else
  162. #error "Please select first the target STM32L4xx device used in your application (in stm32l4xx.h file)"
  163. #endif
  164. /**
  165. * @}
  166. */
  167. /** @addtogroup Exported_types
  168. * @{
  169. */
  170. typedef enum
  171. {
  172. RESET = 0,
  173. SET = !RESET
  174. } FlagStatus, ITStatus;
  175. typedef enum
  176. {
  177. DISABLE = 0,
  178. ENABLE = !DISABLE
  179. } FunctionalState;
  180. #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
  181. typedef enum
  182. {
  183. SUCCESS = 0,
  184. ERROR = !SUCCESS
  185. } ErrorStatus;
  186. /**
  187. * @}
  188. */
  189. /** @addtogroup Exported_macros
  190. * @{
  191. */
  192. #define SET_BIT(REG, BIT) ((REG) |= (BIT))
  193. #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT))
  194. #define READ_BIT(REG, BIT) ((REG) & (BIT))
  195. #define CLEAR_REG(REG) ((REG) = (0x0))
  196. #define WRITE_REG(REG, VAL) ((REG) = (VAL))
  197. #define READ_REG(REG) ((REG))
  198. #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
  199. /* Use of CMSIS compiler intrinsics for register exclusive access */
  200. /* Atomic 32-bit register access macro to set one or several bits */
  201. #define ATOMIC_SET_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. /* Atomic 32-bit register access macro to clear one or several bits */
  209. #define ATOMIC_CLEAR_BIT(REG, BIT) \
  210. do { \
  211. uint32_t val; \
  212. do { \
  213. val = __LDREXW((__IO uint32_t *)&(REG)) & ~(BIT); \
  214. } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
  215. } while(0)
  216. /* Atomic 32-bit register access macro to clear and set one or several bits */
  217. #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \
  218. do { \
  219. uint32_t val; \
  220. do { \
  221. val = (__LDREXW((__IO uint32_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
  222. } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
  223. } while(0)
  224. /* Atomic 16-bit register access macro to set one or several bits */
  225. #define ATOMIC_SETH_BIT(REG, BIT) \
  226. do { \
  227. uint16_t val; \
  228. do { \
  229. val = __LDREXH((__IO uint16_t *)&(REG)) | (BIT); \
  230. } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
  231. } while(0)
  232. /* Atomic 16-bit register access macro to clear one or several bits */
  233. #define ATOMIC_CLEARH_BIT(REG, BIT) \
  234. do { \
  235. uint16_t val; \
  236. do { \
  237. val = __LDREXH((__IO uint16_t *)&(REG)) & ~(BIT); \
  238. } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
  239. } while(0)
  240. /* Atomic 16-bit register access macro to clear and set one or several bits */
  241. #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK) \
  242. do { \
  243. uint16_t val; \
  244. do { \
  245. val = (__LDREXH((__IO uint16_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
  246. } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
  247. } while(0)
  248. #define POSITION_VAL(VAL) (__CLZ(__RBIT(VAL)))
  249. /**
  250. * @}
  251. */
  252. #if defined (USE_HAL_DRIVER)
  253. #include "stm32l4xx_hal.h"
  254. #endif /* USE_HAL_DRIVER */
  255. #ifdef __cplusplus
  256. }
  257. #endif /* __cplusplus */
  258. #endif /* __STM32L4xx_H */
  259. /**
  260. * @}
  261. */
  262. /**
  263. * @}
  264. */