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