stm32l4xx_hal_def.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_def.h
  4. * @author MCD Application Team
  5. * @brief This file contains HAL common defines, enumeration, macros and
  6. * structures definitions.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  11. *
  12. * Redistribution and use in source and binary forms, with or without modification,
  13. * are permitted provided that the following conditions are met:
  14. * 1. Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  20. * may be used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  29. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  30. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  31. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ******************************************************************************
  35. */
  36. /* Define to prevent recursive inclusion -------------------------------------*/
  37. #ifndef __STM32L4xx_HAL_DEF
  38. #define __STM32L4xx_HAL_DEF
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /* Includes ------------------------------------------------------------------*/
  43. #include "stm32l4xx.h"
  44. #include "stm32_hal_legacy.h" /* Aliases file for old names compatibility */
  45. #include <stdio.h>
  46. /* Exported types ------------------------------------------------------------*/
  47. /**
  48. * @brief HAL Status structures definition
  49. */
  50. typedef enum
  51. {
  52. HAL_OK = 0x00,
  53. HAL_ERROR = 0x01,
  54. HAL_BUSY = 0x02,
  55. HAL_TIMEOUT = 0x03
  56. } HAL_StatusTypeDef;
  57. /**
  58. * @brief HAL Lock structures definition
  59. */
  60. typedef enum
  61. {
  62. HAL_UNLOCKED = 0x00,
  63. HAL_LOCKED = 0x01
  64. } HAL_LockTypeDef;
  65. /* Exported macros -----------------------------------------------------------*/
  66. #define HAL_MAX_DELAY 0xFFFFFFFFU
  67. #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT))
  68. #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == RESET)
  69. #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \
  70. do{ \
  71. (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \
  72. (__DMA_HANDLE__).Parent = (__HANDLE__); \
  73. } while(0)
  74. #define UNUSED(x) ((void)(x))
  75. /** @brief Reset the Handle's State field.
  76. * @param __HANDLE__: specifies the Peripheral Handle.
  77. * @note This macro can be used for the following purpose:
  78. * - When the Handle is declared as local variable; before passing it as parameter
  79. * to HAL_PPP_Init() for the first time, it is mandatory to use this macro
  80. * to set to 0 the Handle's "State" field.
  81. * Otherwise, "State" field may have any random value and the first time the function
  82. * HAL_PPP_Init() is called, the low level hardware initialization will be missed
  83. * (i.e. HAL_PPP_MspInit() will not be executed).
  84. * - When there is a need to reconfigure the low level hardware: instead of calling
  85. * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init().
  86. * In this later function, when the Handle's "State" field is set to 0, it will execute the function
  87. * HAL_PPP_MspInit() which will reconfigure the low level hardware.
  88. * @retval None
  89. */
  90. #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0)
  91. #if (USE_RTOS == 1)
  92. /* Reserved for future use */
  93. #error " USE_RTOS should be 0 in the current HAL release "
  94. #else
  95. #define __HAL_LOCK(__HANDLE__) \
  96. do{ \
  97. if((__HANDLE__)->Lock == HAL_LOCKED) \
  98. { \
  99. return HAL_BUSY; \
  100. } \
  101. else \
  102. { \
  103. (__HANDLE__)->Lock = HAL_LOCKED; \
  104. } \
  105. }while (0)
  106. #define __HAL_UNLOCK(__HANDLE__) \
  107. do{ \
  108. (__HANDLE__)->Lock = HAL_UNLOCKED; \
  109. }while (0)
  110. #endif /* USE_RTOS */
  111. // Added for MBED PR #3062
  112. #if defined (__CC_ARM)
  113. #pragma diag_suppress 3731
  114. #endif
  115. // Added for MBED PR #3062
  116. static inline void atomic_set_u32(volatile uint32_t *ptr, uint32_t mask)
  117. {
  118. uint32_t newValue;
  119. do {
  120. newValue = (uint32_t)__LDREXW(ptr) | mask;
  121. } while (__STREXW(newValue, ptr));
  122. }
  123. // Added for MBED PR #3062
  124. static inline void atomic_clr_u32(volatile uint32_t *ptr, uint32_t mask)
  125. {
  126. uint32_t newValue;
  127. do {
  128. newValue = (uint32_t)__LDREXW(ptr) &~mask;
  129. } while (__STREXW(newValue, ptr));
  130. }
  131. #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
  132. #ifndef __weak
  133. #define __weak __attribute__((weak))
  134. #endif /* __weak */
  135. #ifndef __packed
  136. #define __packed __attribute__((__packed__))
  137. #endif /* __packed */
  138. #endif /* __GNUC__ */
  139. /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */
  140. #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
  141. #ifndef __ALIGN_END
  142. #define __ALIGN_END __attribute__ ((aligned (4)))
  143. #endif /* __ALIGN_END */
  144. #ifndef __ALIGN_BEGIN
  145. #define __ALIGN_BEGIN
  146. #endif /* __ALIGN_BEGIN */
  147. #else
  148. #ifndef __ALIGN_END
  149. #define __ALIGN_END
  150. #endif /* __ALIGN_END */
  151. #ifndef __ALIGN_BEGIN
  152. #if defined (__CC_ARM) /* ARM Compiler */
  153. #define __ALIGN_BEGIN __align(4)
  154. #elif defined (__ICCARM__) /* IAR Compiler */
  155. #define __ALIGN_BEGIN
  156. #endif /* __CC_ARM */
  157. #endif /* __ALIGN_BEGIN */
  158. #endif /* __GNUC__ */
  159. /**
  160. * @brief __RAM_FUNC definition
  161. */
  162. #if defined ( __CC_ARM )
  163. /* ARM Compiler
  164. ------------
  165. RAM functions are defined using the toolchain options.
  166. Functions that are executed in RAM should reside in a separate source module.
  167. Using the 'Options for File' dialog you can simply change the 'Code / Const'
  168. area of a module to a memory space in physical RAM.
  169. Available memory areas are declared in the 'Target' tab of the 'Options for Target'
  170. dialog.
  171. */
  172. #define __RAM_FUNC HAL_StatusTypeDef
  173. #elif defined ( __ICCARM__ )
  174. /* ICCARM Compiler
  175. ---------------
  176. RAM functions are defined using a specific toolchain keyword "__ramfunc".
  177. */
  178. #define __RAM_FUNC __ramfunc HAL_StatusTypeDef
  179. #elif defined ( __GNUC__ )
  180. /* GNU Compiler
  181. ------------
  182. RAM functions are defined using a specific toolchain attribute
  183. "__attribute__((section(".RamFunc")))".
  184. */
  185. #define __RAM_FUNC HAL_StatusTypeDef __attribute__((section(".RamFunc")))
  186. #endif
  187. /**
  188. * @brief __NOINLINE definition
  189. */
  190. #if defined ( __CC_ARM ) || defined ( __GNUC__ )
  191. /* ARM & GNUCompiler
  192. ----------------
  193. */
  194. #define __NOINLINE __attribute__ ( (noinline) )
  195. #elif defined ( __ICCARM__ )
  196. /* ICCARM Compiler
  197. ---------------
  198. */
  199. #define __NOINLINE _Pragma("optimize = no_inline")
  200. #endif
  201. #ifdef __cplusplus
  202. }
  203. #endif
  204. #endif /* ___STM32L4xx_HAL_DEF */
  205. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/