stm32h7xx_hal_def.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. #define UNUSED(x) ((void)(x))
  59. /** @brief Reset the Handle's State field.
  60. * @param __HANDLE__: specifies the Peripheral Handle.
  61. * @note This macro can be used for the following purpose:
  62. * - When the Handle is declared as local variable; before passing it as parameter
  63. * to HAL_PPP_Init() for the first time, it is mandatory to use this macro
  64. * to set to 0 the Handle's "State" field.
  65. * Otherwise, "State" field may have any random value and the first time the function
  66. * HAL_PPP_Init() is called, the low level hardware initialization will be missed
  67. * (i.e. HAL_PPP_MspInit() will not be executed).
  68. * - When there is a need to reconfigure the low level hardware: instead of calling
  69. * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init().
  70. * In this later function, when the Handle's "State" field is set to 0, it will execute the function
  71. * HAL_PPP_MspInit() which will reconfigure the low level hardware.
  72. * @retval None
  73. */
  74. #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0)
  75. #if (USE_RTOS == 1)
  76. #error " USE_RTOS should be 0 in the current HAL release "
  77. #else
  78. #define __HAL_LOCK(__HANDLE__) \
  79. do{ \
  80. if((__HANDLE__)->Lock == HAL_LOCKED) \
  81. { \
  82. return HAL_BUSY; \
  83. } \
  84. else \
  85. { \
  86. (__HANDLE__)->Lock = HAL_LOCKED; \
  87. } \
  88. }while (0)
  89. #define __HAL_UNLOCK(__HANDLE__) \
  90. do{ \
  91. (__HANDLE__)->Lock = HAL_UNLOCKED; \
  92. }while (0)
  93. #endif /* USE_RTOS */
  94. #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */
  95. #ifndef __weak
  96. #define __weak __attribute__((weak))
  97. #endif
  98. #ifndef __packed
  99. #define __packed __attribute__((packed))
  100. #endif
  101. #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
  102. #ifndef __weak
  103. #define __weak __attribute__((weak))
  104. #endif /* __weak */
  105. #ifndef __packed
  106. #define __packed __attribute__((__packed__))
  107. #endif /* __packed */
  108. #endif /* __GNUC__ */
  109. /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */
  110. #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* ARM Compiler V6 */
  111. #ifndef __ALIGN_BEGIN
  112. #define __ALIGN_BEGIN
  113. #endif
  114. #ifndef __ALIGN_END
  115. #define __ALIGN_END __attribute__ ((aligned (4)))
  116. #endif
  117. #elif defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
  118. #ifndef __ALIGN_END
  119. #define __ALIGN_END __attribute__ ((aligned (4)))
  120. #endif /* __ALIGN_END */
  121. #ifndef __ALIGN_BEGIN
  122. #define __ALIGN_BEGIN
  123. #endif /* __ALIGN_BEGIN */
  124. #else
  125. #ifndef __ALIGN_END
  126. #define __ALIGN_END
  127. #endif /* __ALIGN_END */
  128. #ifndef __ALIGN_BEGIN
  129. #if defined (__CC_ARM) /* ARM Compiler V5 */
  130. #define __ALIGN_BEGIN __align(4)
  131. #elif defined (__ICCARM__) /* IAR Compiler */
  132. #define __ALIGN_BEGIN
  133. #endif /* __CC_ARM */
  134. #endif /* __ALIGN_BEGIN */
  135. #endif /* __GNUC__ */
  136. /* Macro to get variable aligned on 32-bytes,needed for cache maintenance purpose */
  137. #if defined (__GNUC__) /* GNU Compiler */
  138. #define ALIGN_32BYTES(buf) buf __attribute__ ((aligned (32)))
  139. #elif defined (__ICCARM__) /* IAR Compiler */
  140. #define ALIGN_32BYTES(buf) _Pragma("data_alignment=32") buf
  141. #elif defined (__CC_ARM) /* ARM Compiler */
  142. #define ALIGN_32BYTES(buf) __align(32) buf
  143. #endif
  144. /**
  145. * @brief __RAM_FUNC definition
  146. */
  147. #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
  148. /* ARM Compiler V4/V5 and V6
  149. --------------------------
  150. RAM functions are defined using the toolchain options.
  151. Functions that are executed in RAM should reside in a separate source module.
  152. Using the 'Options for File' dialog you can simply change the 'Code / Const'
  153. area of a module to a memory space in physical RAM.
  154. Available memory areas are declared in the 'Target' tab of the 'Options for Target'
  155. dialog.
  156. */
  157. #define __RAM_FUNC
  158. #elif defined ( __ICCARM__ )
  159. /* ICCARM Compiler
  160. ---------------
  161. RAM functions are defined using a specific toolchain keyword "__ramfunc".
  162. */
  163. #define __RAM_FUNC __ramfunc
  164. #elif defined ( __GNUC__ )
  165. /* GNU Compiler
  166. ------------
  167. RAM functions are defined using a specific toolchain attribute
  168. "__attribute__((section(".RamFunc")))".
  169. */
  170. #define __RAM_FUNC __attribute__((section(".RamFunc")))
  171. #endif
  172. /**
  173. * @brief __NOINLINE definition
  174. */
  175. #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined ( __GNUC__ )
  176. /* ARM V4/V5 and V6 & GNU Compiler
  177. -------------------------------
  178. */
  179. #define __NOINLINE __attribute__ ( (noinline) )
  180. #elif defined ( __ICCARM__ )
  181. /* ICCARM Compiler
  182. ---------------
  183. */
  184. #define __NOINLINE _Pragma("optimize = no_inline")
  185. #endif
  186. #ifdef __cplusplus
  187. }
  188. #endif
  189. #endif /* STM32H7xx_HAL_DEF */