stm32h7xx_hal_def.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_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. * Copyright (c) 2017 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32H7xx_HAL_DEF
  21. #define STM32H7xx_HAL_DEF
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32h7xx.h"
  27. #include "Legacy/stm32_hal_legacy.h"
  28. #include <stddef.h>
  29. #include <math.h>
  30. /* Exported types ------------------------------------------------------------*/
  31. /**
  32. * @brief HAL Status structures definition
  33. */
  34. typedef enum
  35. {
  36. HAL_OK = 0x00,
  37. HAL_ERROR = 0x01,
  38. HAL_BUSY = 0x02,
  39. HAL_TIMEOUT = 0x03
  40. } HAL_StatusTypeDef;
  41. /**
  42. * @brief HAL Lock structures definition
  43. */
  44. typedef enum
  45. {
  46. HAL_UNLOCKED = 0x00,
  47. HAL_LOCKED = 0x01
  48. } HAL_LockTypeDef;
  49. /* Exported macro ------------------------------------------------------------*/
  50. #define HAL_MAX_DELAY 0xFFFFFFFFU
  51. #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT))
  52. #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U)
  53. #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \
  54. do{ \
  55. (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \
  56. (__DMA_HANDLE__).Parent = (__HANDLE__); \
  57. } while(0)
  58. #if !defined(UNUSED)
  59. #define UNUSED(x) ((void)(x)) /* To avoid gcc/g++ warnings */
  60. #endif /* UNUSED */
  61. /** @brief Reset the Handle's State field.
  62. * @param __HANDLE__: specifies the Peripheral Handle.
  63. * @note This macro can be used for the following purpose:
  64. * - When the Handle is declared as local variable; before passing it as parameter
  65. * to HAL_PPP_Init() for the first time, it is mandatory to use this macro
  66. * to set to 0 the Handle's "State" field.
  67. * Otherwise, "State" field may have any random value and the first time the function
  68. * HAL_PPP_Init() is called, the low level hardware initialization will be missed
  69. * (i.e. HAL_PPP_MspInit() will not be executed).
  70. * - When there is a need to reconfigure the low level hardware: instead of calling
  71. * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init().
  72. * In this later function, when the Handle's "State" field is set to 0, it will execute the function
  73. * HAL_PPP_MspInit() which will reconfigure the low level hardware.
  74. * @retval None
  75. */
  76. #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0)
  77. #if (USE_RTOS == 1)
  78. #error " USE_RTOS should be 0 in the current HAL release "
  79. #else
  80. #define __HAL_LOCK(__HANDLE__) \
  81. do{ \
  82. if((__HANDLE__)->Lock == HAL_LOCKED) \
  83. { \
  84. return HAL_BUSY; \
  85. } \
  86. else \
  87. { \
  88. (__HANDLE__)->Lock = HAL_LOCKED; \
  89. } \
  90. }while (0)
  91. #define __HAL_UNLOCK(__HANDLE__) \
  92. do{ \
  93. (__HANDLE__)->Lock = HAL_UNLOCKED; \
  94. }while (0)
  95. #endif /* USE_RTOS */
  96. #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */
  97. #ifndef __weak
  98. #define __weak __attribute__((weak))
  99. #endif
  100. #ifndef __packed
  101. #define __packed __attribute__((packed))
  102. #endif
  103. #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
  104. #ifndef __weak
  105. #define __weak __attribute__((weak))
  106. #endif /* __weak */
  107. #ifndef __packed
  108. #define __packed __attribute__((__packed__))
  109. #endif /* __packed */
  110. #endif /* __GNUC__ */
  111. /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */
  112. #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */
  113. #ifndef __ALIGN_BEGIN
  114. #define __ALIGN_BEGIN
  115. #endif
  116. #ifndef __ALIGN_END
  117. #define __ALIGN_END __attribute__ ((aligned (4)))
  118. #endif
  119. #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
  120. #ifndef __ALIGN_END
  121. #define __ALIGN_END __attribute__ ((aligned (4)))
  122. #endif /* __ALIGN_END */
  123. #ifndef __ALIGN_BEGIN
  124. #define __ALIGN_BEGIN
  125. #endif /* __ALIGN_BEGIN */
  126. #else
  127. #ifndef __ALIGN_END
  128. #define __ALIGN_END
  129. #endif /* __ALIGN_END */
  130. #ifndef __ALIGN_BEGIN
  131. #if defined (__CC_ARM) /* ARM Compiler V5 */
  132. #define __ALIGN_BEGIN __align(4)
  133. #elif defined (__ICCARM__) /* IAR Compiler */
  134. #define __ALIGN_BEGIN
  135. #endif /* __CC_ARM */
  136. #endif /* __ALIGN_BEGIN */
  137. #endif /* __GNUC__ */
  138. /* Macro to get variable aligned on 32-bytes,needed for cache maintenance purpose */
  139. #if defined (__GNUC__) /* GNU Compiler */
  140. #define ALIGN_32BYTES(buf) buf __attribute__ ((aligned (32)))
  141. #elif defined (__ICCARM__) /* IAR Compiler */
  142. #define ALIGN_32BYTES(buf) _Pragma("data_alignment=32") buf
  143. #elif defined (__CC_ARM) /* ARM Compiler */
  144. #define ALIGN_32BYTES(buf) __align(32) buf
  145. #endif
  146. /**
  147. * @brief __RAM_FUNC definition
  148. */
  149. #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
  150. /* ARM Compiler V4/V5 and V6
  151. --------------------------
  152. RAM functions are defined using the toolchain options.
  153. Functions that are executed in RAM should reside in a separate source module.
  154. Using the 'Options for File' dialog you can simply change the 'Code / Const'
  155. area of a module to a memory space in physical RAM.
  156. Available memory areas are declared in the 'Target' tab of the 'Options for Target'
  157. dialog.
  158. */
  159. #define __RAM_FUNC
  160. #elif defined ( __ICCARM__ )
  161. /* ICCARM Compiler
  162. ---------------
  163. RAM functions are defined using a specific toolchain keyword "__ramfunc".
  164. */
  165. #define __RAM_FUNC __ramfunc
  166. #elif defined ( __GNUC__ )
  167. /* GNU Compiler
  168. ------------
  169. RAM functions are defined using a specific toolchain attribute
  170. "__attribute__((section(".RamFunc")))".
  171. */
  172. #define __RAM_FUNC __attribute__((section(".RamFunc")))
  173. #endif
  174. /**
  175. * @brief __NOINLINE definition
  176. */
  177. #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined ( __GNUC__ )
  178. /* ARM V4/V5 and V6 & GNU Compiler
  179. -------------------------------
  180. */
  181. #define __NOINLINE __attribute__ ( (noinline) )
  182. #elif defined ( __ICCARM__ )
  183. /* ICCARM Compiler
  184. ---------------
  185. */
  186. #define __NOINLINE _Pragma("optimize = no_inline")
  187. #endif
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. #endif /* STM32H7xx_HAL_DEF */