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