stm32l5xx.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /**
  2. ******************************************************************************
  3. * @file stm32l5xx.h
  4. * @author MCD Application Team
  5. * @brief CMSIS STM32L5xx 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 STM32L5xx 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 stm32l5xx
  32. * @{
  33. */
  34. #ifndef STM32L5xx_H
  35. #define STM32L5xx_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 (STM32L5)
  46. #define STM32L5
  47. #endif /* STM32L5 */
  48. /* Uncomment the line below according to the target STM32L5 device used in your
  49. application
  50. */
  51. #if !defined (STM32L552xx) && !defined (STM32L562xx)
  52. /* #define STM32L552xx */ /*!< STM32L552xx Devices */
  53. /* #define STM32L562xx */ /*!< STM32L562xx Devices */
  54. #endif
  55. /* Tip: To avoid modifying this file each time you need to switch between these
  56. devices, you can define the device in your toolchain compiler preprocessor.
  57. */
  58. #if !defined (USE_HAL_DRIVER)
  59. /**
  60. * @brief Comment the line below if you will not use the peripherals drivers.
  61. In this case, these drivers will not be included and the application code will
  62. be based on direct access to peripherals registers
  63. */
  64. /*#define USE_HAL_DRIVER */
  65. #endif /* USE_HAL_DRIVER */
  66. /**
  67. * @brief CMSIS Device version number
  68. */
  69. #define __STM32L5_CMSIS_VERSION_MAIN (0x01U) /*!< [31:24] main version */
  70. #define __STM32L5_CMSIS_VERSION_SUB1 (0x00U) /*!< [23:16] sub1 version */
  71. #define __STM32L5_CMSIS_VERSION_SUB2 (0x05U) /*!< [15:8] sub2 version */
  72. #define __STM32L5_CMSIS_VERSION_RC (0x00U) /*!< [7:0] release candidate */
  73. #define __STM32L5_CMSIS_VERSION ((__STM32L5_CMSIS_VERSION_MAIN << 24U)\
  74. |(__STM32L5_CMSIS_VERSION_SUB1 << 16U)\
  75. |(__STM32L5_CMSIS_VERSION_SUB2 << 8U )\
  76. |(__STM32L5_CMSIS_VERSION_RC))
  77. /**
  78. * @}
  79. */
  80. /** @addtogroup Device_Included
  81. * @{
  82. */
  83. #if defined(STM32L552xx)
  84. #include "stm32l552xx.h"
  85. #elif defined(STM32L562xx)
  86. #include "stm32l562xx.h"
  87. #else
  88. #error "Please select first the target STM32L5xx device used in your application (in stm32l5xx.h file)"
  89. #endif
  90. /**
  91. * @}
  92. */
  93. /** @addtogroup Exported_types
  94. * @{
  95. */
  96. typedef enum
  97. {
  98. RESET = 0,
  99. SET = !RESET
  100. } FlagStatus, ITStatus;
  101. typedef enum
  102. {
  103. DISABLE = 0,
  104. ENABLE = !DISABLE
  105. } FunctionalState;
  106. #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
  107. typedef enum
  108. {
  109. SUCCESS = 0,
  110. ERROR = !SUCCESS
  111. } ErrorStatus;
  112. /**
  113. * @}
  114. */
  115. /** @addtogroup Exported_macros
  116. * @{
  117. */
  118. #define SET_BIT(REG, BIT) ((REG) |= (BIT))
  119. #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT))
  120. #define READ_BIT(REG, BIT) ((REG) & (BIT))
  121. #define CLEAR_REG(REG) ((REG) = (0x0))
  122. #define WRITE_REG(REG, VAL) ((REG) = (VAL))
  123. #define READ_REG(REG) ((REG))
  124. #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
  125. /* Use of CMSIS compiler intrinsics for register exclusive access */
  126. /* Atomic 32-bit register access macro to set one or several bits */
  127. #define ATOMIC_SET_BIT(REG, BIT) \
  128. do { \
  129. uint32_t val; \
  130. do { \
  131. val = __LDREXW((__IO uint32_t *)&(REG)) | (BIT); \
  132. } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
  133. } while(0)
  134. /* Atomic 32-bit register access macro to clear one or several bits */
  135. #define ATOMIC_CLEAR_BIT(REG, BIT) \
  136. do { \
  137. uint32_t val; \
  138. do { \
  139. val = __LDREXW((__IO uint32_t *)&(REG)) & ~(BIT); \
  140. } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
  141. } while(0)
  142. /* Atomic 32-bit register access macro to clear and set one or several bits */
  143. #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \
  144. do { \
  145. uint32_t val; \
  146. do { \
  147. val = (__LDREXW((__IO uint32_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
  148. } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
  149. } while(0)
  150. /* Atomic 16-bit register access macro to set one or several bits */
  151. #define ATOMIC_SETH_BIT(REG, BIT) \
  152. do { \
  153. uint16_t val; \
  154. do { \
  155. val = __LDREXH((__IO uint16_t *)&(REG)) | (BIT); \
  156. } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
  157. } while(0)
  158. /* Atomic 16-bit register access macro to clear one or several bits */
  159. #define ATOMIC_CLEARH_BIT(REG, BIT) \
  160. do { \
  161. uint16_t val; \
  162. do { \
  163. val = __LDREXH((__IO uint16_t *)&(REG)) & ~(BIT); \
  164. } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
  165. } while(0)
  166. /* Atomic 16-bit register access macro to clear and set one or several bits */
  167. #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK) \
  168. do { \
  169. uint16_t val; \
  170. do { \
  171. val = (__LDREXH((__IO uint16_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
  172. } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
  173. } while(0)
  174. #define POSITION_VAL(VAL) (__CLZ(__RBIT(VAL)))
  175. /**
  176. * @}
  177. */
  178. #if defined (USE_HAL_DRIVER)
  179. #include "stm32l5xx_hal.h"
  180. #endif /* USE_HAL_DRIVER */
  181. #ifdef __cplusplus
  182. }
  183. #endif /* __cplusplus */
  184. #endif /* STM32L5xx_H */
  185. /**
  186. * @}
  187. */
  188. /**
  189. * @}
  190. */