stm32f1xx_hal_def.h 8.2 KB

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