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