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 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 __STM32H5xx_HAL_DEF
23 #define __STM32H5xx_HAL_DEF
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
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 "stm32h5xx.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 #define ARMCC_MIN_VERSION  6010050
65 
66 #define HAL_IS_BIT_SET(REG, BIT)         (((REG) & (BIT)) == (BIT))
67 #define HAL_IS_BIT_CLR(REG, BIT)         (((REG) & (BIT)) == 0U)
68 
69 #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__)             \
70   do{                                                    \
71     (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \
72     (__DMA_HANDLE__).Parent = (__HANDLE__);              \
73   } while(0)
74 
75 #define UNUSED(x) ((void)(x))
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 #if  defined ( __GNUC__ )
117 #ifndef __weak
118 #define __weak   __attribute__((weak))
119 #endif /* __weak */
120 #ifndef __packed
121 #define __packed __attribute__((__packed__))
122 #endif /* __packed */
123 #endif /* __GNUC__ */
124 
125 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= ARMCC_MIN_VERSION)
126 #ifndef __weak
127 #define __weak  __WEAK
128 #endif /* __weak */
129 #ifndef __packed
130 #define __packed  __PACKED
131 #endif /* __packed */
132 #endif
133 
134 /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4"
135    must be used instead */
136 #if defined   (__GNUC__)        /* GNU Compiler */
137 #ifndef __ALIGN_END
138 #define __ALIGN_END    __attribute__ ((aligned (4)))
139 #endif /* __ALIGN_END */
140 #ifndef __ALIGN_BEGIN
141 #define __ALIGN_BEGIN
142 #endif /* __ALIGN_BEGIN */
143 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= ARMCC_MIN_VERSION)
144 #ifndef __ALIGN_END
145 #define __ALIGN_END    __ALIGNED(4)
146 #endif /* __ALIGN_END */
147 #ifndef __ALIGN_BEGIN
148 #define __ALIGN_BEGIN
149 #endif /* __ALIGN_BEGIN */
150 #else
151 #ifndef __ALIGN_END
152 #define __ALIGN_END
153 #endif /* __ALIGN_END */
154 #ifndef __ALIGN_BEGIN
155 #if defined   (__CC_ARM)      /* ARM Compiler */
156 #define __ALIGN_BEGIN    __align(4)
157 #elif defined (__ICCARM__)    /* IAR Compiler */
158 #define __ALIGN_BEGIN
159 #endif /* __CC_ARM */
160 #endif /* __ALIGN_BEGIN */
161 #endif /* __GNUC__ */
162 
163 /* Macro to get variable aligned on 32-bytes,needed for cache maintenance purpose */
164 #if defined   (__GNUC__)        /* GNU Compiler */
165 #define ALIGN_32BYTES(buf)  buf __attribute__ ((aligned (32)))
166 #elif defined (__ICCARM__)    /* IAR Compiler */
167 #define ALIGN_32BYTES(buf) _Pragma("data_alignment=32") buf
168 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= ARMCC_MIN_VERSION)
169 #define ALIGN_32BYTES(buf) __ALIGNED(32) buf
170 #elif defined   (__CC_ARM)      /* ARM Compiler */
171 #define ALIGN_32BYTES(buf) __align(32) buf
172 #endif /* __GNUC__ */
173 
174 /**
175   * @brief  __RAM_FUNC definition
176   */
177 #if defined ( __CC_ARM   ) || ((__ARMCC_VERSION) && (__ARMCC_VERSION >= ARMCC_MIN_VERSION))
178 
179 /* ARM Compiler
180 
181    RAM functions are defined using the toolchain options.
182    Functions that are executed in RAM should reside in a separate source module.
183    Using the 'Options for File' dialog you can simply change the 'Code / Const'
184    area of a module to a memory space in physical RAM.
185    Available memory areas are declared in the 'Target' tab of the 'Options for Target'
186    dialog.
187 */
188 #define __RAM_FUNC HAL_StatusTypeDef
189 
190 #elif defined ( __ICCARM__ )
191 /* ICCARM Compiler
192 
193    RAM functions are defined using a specific toolchain keyword "__ramfunc".
194 */
195 #define __RAM_FUNC __ramfunc HAL_StatusTypeDef
196 
197 #elif defined   (  __GNUC__  )
198 /* GNU Compiler
199 
200   RAM functions are defined using a specific toolchain attribute
201    "__attribute__((section(".RamFunc")))".
202 */
203 #define __RAM_FUNC HAL_StatusTypeDef  __attribute__((section(".RamFunc")))
204 
205 #endif /* defined ( __CC_ARM   ) || ((__ARMCC_VERSION) && (__ARMCC_VERSION >= ARMCC_MIN_VERSION)) */
206 
207 /**
208   * @brief  __NOINLINE definition
209   */
210 #if defined ( __CC_ARM   ) || ((__ARMCC_VERSION) && (__ARMCC_VERSION >= ARMCC_MIN_VERSION)) || defined   (  __GNUC__  )
211 /* ARM & GNUCompiler
212 
213 */
214 #define __NOINLINE __attribute__ ( (noinline) )
215 
216 #elif defined ( __ICCARM__ )
217 /* ICCARM Compiler
218 
219 */
220 #define __NOINLINE _Pragma("optimize = no_inline")
221 
222 #endif /* ( __CC_ARM   ) || ((__ARMCC_VERSION) && (__ARMCC_VERSION >= ARMCC_MIN_VERSION)) || defined   (  __GNUC__  ) */
223 
224 
225 #ifdef __cplusplus
226 }
227 #endif /* __cplusplus */
228 
229 #endif /* ___STM32H5xx_HAL_DEF */
230 
231