1 /** 2 ****************************************************************************** 3 * @file stm32u5xx_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) 2021 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 20 /* Define to prevent recursive inclusion -------------------------------------*/ 21 #ifndef __STM32U5xx_HAL_DEF 22 #define __STM32U5xx_HAL_DEF 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Includes ------------------------------------------------------------------*/ 29 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 30 #include <arm_cmse.h> 31 #endif /* __ARM_FEATURE_CMSE */ 32 33 #include "stm32u5xx.h" 34 #include "Legacy/stm32_hal_legacy.h" /* Aliases file for old names compatibility */ 35 #include <stddef.h> 36 #include <math.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 #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(0) 72 73 #define UNUSED(x) ((void)(x)) 74 75 /** @brief Reset the Handle's State field. 76 * @param __HANDLE__: specifies the Peripheral Handle. 77 * @note This macro can be used for the following purpose: 78 * - When the Handle is declared as local variable; before passing it as parameter 79 * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 80 * to set to 0 the Handle's "State" field. 81 * Otherwise, "State" field may have any random value and the first time the function 82 * HAL_PPP_Init() is called, the low level hardware initialization will be missed 83 * (i.e. HAL_PPP_MspInit() will not be executed). 84 * - When there is a need to reconfigure the low level hardware: instead of calling 85 * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 86 * In this later function, when the Handle's "State" field is set to 0, it will execute the function 87 * HAL_PPP_MspInit() which will reconfigure the low level hardware. 88 * @retval None 89 */ 90 #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0) 91 92 #if (USE_RTOS == 1) 93 /* Reserved for future use */ 94 #error " USE_RTOS should be 0 in the current HAL release " 95 #else 96 #define __HAL_LOCK(__HANDLE__) \ 97 do{ \ 98 if((__HANDLE__)->Lock == HAL_LOCKED) \ 99 { \ 100 return HAL_BUSY; \ 101 } \ 102 else \ 103 { \ 104 (__HANDLE__)->Lock = HAL_LOCKED; \ 105 } \ 106 }while (0) 107 108 #define __HAL_UNLOCK(__HANDLE__) \ 109 do{ \ 110 (__HANDLE__)->Lock = HAL_UNLOCKED; \ 111 }while (0) 112 #endif /* USE_RTOS */ 113 114 #if defined ( __GNUC__ ) 115 #ifndef __weak 116 #define __weak __attribute__((weak)) 117 #endif /* __weak */ 118 #ifndef __packed 119 #define __packed __attribute__((__packed__)) 120 #endif /* __packed */ 121 #endif /* __GNUC__ */ 122 123 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 124 #ifndef __weak 125 #define __weak __attribute__((weak)) 126 #endif /* __weak */ 127 #ifndef __packed 128 #define __packed __attribute__((packed)) 129 #endif /* __packed */ 130 #endif /* __ARMCC_VERSION */ 131 132 /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used 133 instead */ 134 #if defined (__GNUC__) /* GNU Compiler */ 135 #ifndef __ALIGN_END 136 #define __ALIGN_END __attribute__ ((aligned (4))) 137 #endif /* __ALIGN_END */ 138 #ifndef __ALIGN_BEGIN 139 #define __ALIGN_BEGIN 140 #endif /* __ALIGN_BEGIN */ 141 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 142 #ifndef __ALIGN_END 143 #define __ALIGN_END __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 (__CC_ARM) /* ARM Compiler */ 154 #define __ALIGN_BEGIN __align(4) 155 #elif defined (__ICCARM__) /* IAR Compiler */ 156 #define __ALIGN_BEGIN 157 #endif /* __CC_ARM */ 158 #endif /* __ALIGN_BEGIN */ 159 #endif /* __GNUC__ */ 160 161 /* Macro to get variable aligned on 32-bytes,needed for cache maintenance purpose */ 162 #if defined (__GNUC__) /* GNU Compiler */ 163 #define ALIGN_32BYTES(buf) buf __attribute__ ((aligned (32))) 164 #elif defined (__ICCARM__) /* IAR Compiler */ 165 #define ALIGN_32BYTES(buf) _Pragma("data_alignment=32") buf 166 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 167 #define ALIGN_32BYTES(buf) __ALIGNED(32) buf 168 #elif defined (__CC_ARM) /* ARM Compiler */ 169 #define ALIGN_32BYTES(buf) __align(32) buf 170 #endif /* __GNUC__ */ 171 172 /** 173 * @brief __RAM_FUNC definition 174 */ 175 #if defined ( __CC_ARM ) || ((__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) 176 177 /* ARM Compiler 178 ------------ 179 RAM functions are defined using the toolchain options. 180 Functions that are executed in RAM should reside in a separate source module. 181 Using the 'Options for File' dialog you can simply change the 'Code / Const' 182 area of a module to a memory space in physical RAM. 183 Available memory areas are declared in the 'Target' tab of the 'Options for Target' 184 dialog. 185 */ 186 #define __RAM_FUNC HAL_StatusTypeDef 187 188 #elif defined ( __ICCARM__ ) 189 /* ICCARM Compiler 190 --------------- 191 RAM functions are defined using a specific toolchain keyword "__ramfunc". 192 */ 193 #define __RAM_FUNC __ramfunc HAL_StatusTypeDef 194 195 #elif defined ( __GNUC__ ) 196 /* GNU Compiler 197 ------------ 198 RAM functions are defined using a specific toolchain attribute 199 "__attribute__((section(".RamFunc")))". 200 */ 201 #define __RAM_FUNC HAL_StatusTypeDef __attribute__((section(".RamFunc"))) 202 203 #endif /* __RAM_FUNC */ 204 205 /** 206 * @brief __NOINLINE definition 207 */ 208 #if defined ( __CC_ARM ) || ((__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined ( __GNUC__ ) 209 /* ARM & GNUCompiler 210 ---------------- 211 */ 212 #define __NOINLINE __attribute__ ( (noinline) ) 213 214 #elif defined ( __ICCARM__ ) 215 /* ICCARM Compiler 216 --------------- 217 */ 218 #define __NOINLINE _Pragma("optimize = no_inline") 219 220 #endif /* __NOINLINE */ 221 222 223 #ifdef __cplusplus 224 } 225 #endif 226 227 #endif /* ___STM32U5xx_HAL_DEF */ 228