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