stm32f1xx_hal_def.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_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 __STM32F1xx_HAL_DEF
  21. #define __STM32F1xx_HAL_DEF
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f1xx.h"
  27. #include "Legacy/stm32_hal_legacy.h"
  28. #include <stddef.h>
  29. /* Exported types ------------------------------------------------------------*/
  30. /**
  31. * @brief HAL Status structures definition
  32. */
  33. typedef enum
  34. {
  35. HAL_OK = 0x00U,
  36. HAL_ERROR = 0x01U,
  37. HAL_BUSY = 0x02U,
  38. HAL_TIMEOUT = 0x03U
  39. } HAL_StatusTypeDef;
  40. /**
  41. * @brief HAL Lock structures definition
  42. */
  43. typedef enum
  44. {
  45. HAL_UNLOCKED = 0x00U,
  46. HAL_LOCKED = 0x01U
  47. } HAL_LockTypeDef;
  48. /* Exported macro ------------------------------------------------------------*/
  49. #define HAL_MAX_DELAY 0xFFFFFFFFU
  50. #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) != 0U)
  51. #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U)
  52. #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \
  53. do{ \
  54. (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \
  55. (__DMA_HANDLE__).Parent = (__HANDLE__); \
  56. } while(0U)
  57. #if !defined(UNUSED)
  58. #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */
  59. #endif /* UNUSED */
  60. /** @brief Reset the Handle's State field.
  61. * @param __HANDLE__ specifies the Peripheral Handle.
  62. * @note This macro can be used for the following purpose:
  63. * - When the Handle is declared as local variable; before passing it as parameter
  64. * to HAL_PPP_Init() for the first time, it is mandatory to use this macro
  65. * to set to 0 the Handle's "State" field.
  66. * Otherwise, "State" field may have any random value and the first time the function
  67. * HAL_PPP_Init() is called, the low level hardware initialization will be missed
  68. * (i.e. HAL_PPP_MspInit() will not be executed).
  69. * - When there is a need to reconfigure the low level hardware: instead of calling
  70. * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init().
  71. * In this later function, when the Handle's "State" field is set to 0, it will execute the function
  72. * HAL_PPP_MspInit() which will reconfigure the low level hardware.
  73. * @retval None
  74. */
  75. #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U)
  76. #if (USE_RTOS == 1U)
  77. /* Reserved for future use */
  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 (0U)
  91. #define __HAL_UNLOCK(__HANDLE__) \
  92. do{ \
  93. (__HANDLE__)->Lock = HAL_UNLOCKED; \
  94. }while (0U)
  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. /**
  139. * @brief __RAM_FUNC definition
  140. */
  141. #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
  142. /* ARM Compiler V4/V5 and V6
  143. --------------------------
  144. RAM functions are defined using the toolchain options.
  145. Functions that are executed in RAM should reside in a separate source module.
  146. Using the 'Options for File' dialog you can simply change the 'Code / Const'
  147. area of a module to a memory space in physical RAM.
  148. Available memory areas are declared in the 'Target' tab of the 'Options for Target'
  149. dialog.
  150. */
  151. #define __RAM_FUNC
  152. #elif defined ( __ICCARM__ )
  153. /* ICCARM Compiler
  154. ---------------
  155. RAM functions are defined using a specific toolchain keyword "__ramfunc".
  156. */
  157. #define __RAM_FUNC __ramfunc
  158. #elif defined ( __GNUC__ )
  159. /* GNU Compiler
  160. ------------
  161. RAM functions are defined using a specific toolchain attribute
  162. "__attribute__((section(".RamFunc")))".
  163. */
  164. #define __RAM_FUNC __attribute__((section(".RamFunc")))
  165. #endif
  166. /**
  167. * @brief __NOINLINE definition
  168. */
  169. #if defined ( __CC_ARM ) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined ( __GNUC__ )
  170. /* ARM V4/V5 and V6 & GNU Compiler
  171. -------------------------------
  172. */
  173. #define __NOINLINE __attribute__ ( (noinline) )
  174. #elif defined ( __ICCARM__ )
  175. /* ICCARM Compiler
  176. ---------------
  177. */
  178. #define __NOINLINE _Pragma("optimize = no_inline")
  179. #endif
  180. #ifdef __cplusplus
  181. }
  182. #endif
  183. #endif /* ___STM32F1xx_HAL_DEF */