stm32l4xx_hal_def.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 "Legacy/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. #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
  112. #ifndef __weak
  113. #define __weak __attribute__((weak))
  114. #endif /* __weak */
  115. #ifndef __packed
  116. #define __packed __attribute__((__packed__))
  117. #endif /* __packed */
  118. #endif /* __GNUC__ */
  119. /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */
  120. #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
  121. #ifndef __ALIGN_END
  122. #define __ALIGN_END __attribute__ ((aligned (4)))
  123. #endif /* __ALIGN_END */
  124. #ifndef __ALIGN_BEGIN
  125. #define __ALIGN_BEGIN
  126. #endif /* __ALIGN_BEGIN */
  127. #else
  128. #ifndef __ALIGN_END
  129. #define __ALIGN_END
  130. #endif /* __ALIGN_END */
  131. #ifndef __ALIGN_BEGIN
  132. #if defined (__CC_ARM) /* ARM Compiler */
  133. #define __ALIGN_BEGIN __align(4)
  134. #elif defined (__ICCARM__) /* IAR Compiler */
  135. #define __ALIGN_BEGIN
  136. #endif /* __CC_ARM */
  137. #endif /* __ALIGN_BEGIN */
  138. #endif /* __GNUC__ */
  139. /**
  140. * @brief __RAM_FUNC definition
  141. */
  142. #if defined ( __CC_ARM )
  143. /* ARM Compiler
  144. ------------
  145. RAM functions are defined using the toolchain options.
  146. Functions that are executed in RAM should reside in a separate source module.
  147. Using the 'Options for File' dialog you can simply change the 'Code / Const'
  148. area of a module to a memory space in physical RAM.
  149. Available memory areas are declared in the 'Target' tab of the 'Options for Target'
  150. dialog.
  151. */
  152. #define __RAM_FUNC HAL_StatusTypeDef
  153. #elif defined ( __ICCARM__ )
  154. /* ICCARM Compiler
  155. ---------------
  156. RAM functions are defined using a specific toolchain keyword "__ramfunc".
  157. */
  158. #define __RAM_FUNC __ramfunc HAL_StatusTypeDef
  159. #elif defined ( __GNUC__ )
  160. /* GNU Compiler
  161. ------------
  162. RAM functions are defined using a specific toolchain attribute
  163. "__attribute__((section(".RamFunc")))".
  164. */
  165. #define __RAM_FUNC HAL_StatusTypeDef __attribute__((section(".RamFunc")))
  166. #endif
  167. /**
  168. * @brief __NOINLINE definition
  169. */
  170. #if defined ( __CC_ARM ) || defined ( __GNUC__ )
  171. /* ARM & GNUCompiler
  172. ----------------
  173. */
  174. #define __NOINLINE __attribute__ ( (noinline) )
  175. #elif defined ( __ICCARM__ )
  176. /* ICCARM Compiler
  177. ---------------
  178. */
  179. #define __NOINLINE _Pragma("optimize = no_inline")
  180. #endif
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184. #endif /* ___STM32L4xx_HAL_DEF */
  185. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/