001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganlikun 0:13413ea9a877 1 /**
ganlikun 0:13413ea9a877 2 ******************************************************************************
ganlikun 0:13413ea9a877 3 * @file stm32f4xx_hal_def.h
ganlikun 0:13413ea9a877 4 * @author MCD Application Team
ganlikun 0:13413ea9a877 5 * @version V1.7.1
ganlikun 0:13413ea9a877 6 * @date 14-April-2017
ganlikun 0:13413ea9a877 7 * @brief This file contains HAL common defines, enumeration, macros and
ganlikun 0:13413ea9a877 8 * structures definitions.
ganlikun 0:13413ea9a877 9 ******************************************************************************
ganlikun 0:13413ea9a877 10 * @attention
ganlikun 0:13413ea9a877 11 *
ganlikun 0:13413ea9a877 12 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
ganlikun 0:13413ea9a877 13 *
ganlikun 0:13413ea9a877 14 * Redistribution and use in source and binary forms, with or without modification,
ganlikun 0:13413ea9a877 15 * are permitted provided that the following conditions are met:
ganlikun 0:13413ea9a877 16 * 1. Redistributions of source code must retain the above copyright notice,
ganlikun 0:13413ea9a877 17 * this list of conditions and the following disclaimer.
ganlikun 0:13413ea9a877 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
ganlikun 0:13413ea9a877 19 * this list of conditions and the following disclaimer in the documentation
ganlikun 0:13413ea9a877 20 * and/or other materials provided with the distribution.
ganlikun 0:13413ea9a877 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
ganlikun 0:13413ea9a877 22 * may be used to endorse or promote products derived from this software
ganlikun 0:13413ea9a877 23 * without specific prior written permission.
ganlikun 0:13413ea9a877 24 *
ganlikun 0:13413ea9a877 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ganlikun 0:13413ea9a877 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ganlikun 0:13413ea9a877 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ganlikun 0:13413ea9a877 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
ganlikun 0:13413ea9a877 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ganlikun 0:13413ea9a877 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
ganlikun 0:13413ea9a877 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
ganlikun 0:13413ea9a877 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ganlikun 0:13413ea9a877 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
ganlikun 0:13413ea9a877 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ganlikun 0:13413ea9a877 35 *
ganlikun 0:13413ea9a877 36 ******************************************************************************
ganlikun 0:13413ea9a877 37 */
ganlikun 0:13413ea9a877 38
ganlikun 0:13413ea9a877 39 /* Define to prevent recursive inclusion -------------------------------------*/
ganlikun 0:13413ea9a877 40 #ifndef __STM32F4xx_HAL_DEF
ganlikun 0:13413ea9a877 41 #define __STM32F4xx_HAL_DEF
ganlikun 0:13413ea9a877 42
ganlikun 0:13413ea9a877 43 #ifdef __cplusplus
ganlikun 0:13413ea9a877 44 extern "C" {
ganlikun 0:13413ea9a877 45 #endif
ganlikun 0:13413ea9a877 46
ganlikun 0:13413ea9a877 47 /* Includes ------------------------------------------------------------------*/
ganlikun 0:13413ea9a877 48 #include "stm32f4xx.h"
ganlikun 0:13413ea9a877 49 #include "stm32_hal_legacy.h"
ganlikun 0:13413ea9a877 50 #include <stdio.h>
ganlikun 0:13413ea9a877 51
ganlikun 0:13413ea9a877 52 /* Exported types ------------------------------------------------------------*/
ganlikun 0:13413ea9a877 53
ganlikun 0:13413ea9a877 54 /**
ganlikun 0:13413ea9a877 55 * @brief HAL Status structures definition
ganlikun 0:13413ea9a877 56 */
ganlikun 0:13413ea9a877 57 typedef enum
ganlikun 0:13413ea9a877 58 {
ganlikun 0:13413ea9a877 59 HAL_OK = 0x00U,
ganlikun 0:13413ea9a877 60 HAL_ERROR = 0x01U,
ganlikun 0:13413ea9a877 61 HAL_BUSY = 0x02U,
ganlikun 0:13413ea9a877 62 HAL_TIMEOUT = 0x03U
ganlikun 0:13413ea9a877 63 } HAL_StatusTypeDef;
ganlikun 0:13413ea9a877 64
ganlikun 0:13413ea9a877 65 /**
ganlikun 0:13413ea9a877 66 * @brief HAL Lock structures definition
ganlikun 0:13413ea9a877 67 */
ganlikun 0:13413ea9a877 68 typedef enum
ganlikun 0:13413ea9a877 69 {
ganlikun 0:13413ea9a877 70 HAL_UNLOCKED = 0x00U,
ganlikun 0:13413ea9a877 71 HAL_LOCKED = 0x01U
ganlikun 0:13413ea9a877 72 } HAL_LockTypeDef;
ganlikun 0:13413ea9a877 73
ganlikun 0:13413ea9a877 74 /* Exported macro ------------------------------------------------------------*/
ganlikun 0:13413ea9a877 75 #define HAL_MAX_DELAY 0xFFFFFFFFU
ganlikun 0:13413ea9a877 76
ganlikun 0:13413ea9a877 77 #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) != RESET)
ganlikun 0:13413ea9a877 78 #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == RESET)
ganlikun 0:13413ea9a877 79
ganlikun 0:13413ea9a877 80 #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \
ganlikun 0:13413ea9a877 81 do{ \
ganlikun 0:13413ea9a877 82 (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \
ganlikun 0:13413ea9a877 83 (__DMA_HANDLE__).Parent = (__HANDLE__); \
ganlikun 0:13413ea9a877 84 } while(0)
ganlikun 0:13413ea9a877 85
ganlikun 0:13413ea9a877 86 #define UNUSED(x) ((void)(x))
ganlikun 0:13413ea9a877 87
ganlikun 0:13413ea9a877 88 /** @brief Reset the Handle's State field.
ganlikun 0:13413ea9a877 89 * @param __HANDLE__: specifies the Peripheral Handle.
ganlikun 0:13413ea9a877 90 * @note This macro can be used for the following purpose:
ganlikun 0:13413ea9a877 91 * - When the Handle is declared as local variable; before passing it as parameter
ganlikun 0:13413ea9a877 92 * to HAL_PPP_Init() for the first time, it is mandatory to use this macro
ganlikun 0:13413ea9a877 93 * to set to 0 the Handle's "State" field.
ganlikun 0:13413ea9a877 94 * Otherwise, "State" field may have any random value and the first time the function
ganlikun 0:13413ea9a877 95 * HAL_PPP_Init() is called, the low level hardware initialization will be missed
ganlikun 0:13413ea9a877 96 * (i.e. HAL_PPP_MspInit() will not be executed).
ganlikun 0:13413ea9a877 97 * - When there is a need to reconfigure the low level hardware: instead of calling
ganlikun 0:13413ea9a877 98 * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init().
ganlikun 0:13413ea9a877 99 * In this later function, when the Handle's "State" field is set to 0, it will execute the function
ganlikun 0:13413ea9a877 100 * HAL_PPP_MspInit() which will reconfigure the low level hardware.
ganlikun 0:13413ea9a877 101 * @retval None
ganlikun 0:13413ea9a877 102 */
ganlikun 0:13413ea9a877 103 #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U)
ganlikun 0:13413ea9a877 104
ganlikun 0:13413ea9a877 105 #if (USE_RTOS == 1U)
ganlikun 0:13413ea9a877 106 /* Reserved for future use */
ganlikun 0:13413ea9a877 107 #error "USE_RTOS should be 0 in the current HAL release"
ganlikun 0:13413ea9a877 108 #else
ganlikun 0:13413ea9a877 109 #define __HAL_LOCK(__HANDLE__) \
ganlikun 0:13413ea9a877 110 do{ \
ganlikun 0:13413ea9a877 111 if((__HANDLE__)->Lock == HAL_LOCKED) \
ganlikun 0:13413ea9a877 112 { \
ganlikun 0:13413ea9a877 113 return HAL_BUSY; \
ganlikun 0:13413ea9a877 114 } \
ganlikun 0:13413ea9a877 115 else \
ganlikun 0:13413ea9a877 116 { \
ganlikun 0:13413ea9a877 117 (__HANDLE__)->Lock = HAL_LOCKED; \
ganlikun 0:13413ea9a877 118 } \
ganlikun 0:13413ea9a877 119 }while (0U)
ganlikun 0:13413ea9a877 120
ganlikun 0:13413ea9a877 121 #define __HAL_UNLOCK(__HANDLE__) \
ganlikun 0:13413ea9a877 122 do{ \
ganlikun 0:13413ea9a877 123 (__HANDLE__)->Lock = HAL_UNLOCKED; \
ganlikun 0:13413ea9a877 124 }while (0U)
ganlikun 0:13413ea9a877 125 #if defined (__CC_ARM)
ganlikun 0:13413ea9a877 126 #pragma diag_suppress 3731
ganlikun 0:13413ea9a877 127 #endif
ganlikun 0:13413ea9a877 128 static inline void atomic_set_u32(volatile uint32_t *ptr, uint32_t mask)
ganlikun 0:13413ea9a877 129 {
ganlikun 0:13413ea9a877 130 uint32_t newValue;
ganlikun 0:13413ea9a877 131 do {
ganlikun 0:13413ea9a877 132 newValue = (uint32_t)__LDREXW((volatile unsigned long *)ptr) | mask;
ganlikun 0:13413ea9a877 133
ganlikun 0:13413ea9a877 134 } while (__STREXW(newValue,(volatile unsigned long*) ptr));
ganlikun 0:13413ea9a877 135 }
ganlikun 0:13413ea9a877 136
ganlikun 0:13413ea9a877 137
ganlikun 0:13413ea9a877 138 static inline void atomic_clr_u32(volatile uint32_t *ptr, uint32_t mask)
ganlikun 0:13413ea9a877 139 {
ganlikun 0:13413ea9a877 140 uint32_t newValue;
ganlikun 0:13413ea9a877 141 do {
ganlikun 0:13413ea9a877 142 newValue = (uint32_t)__LDREXW((volatile unsigned long *)ptr) &~mask;
ganlikun 0:13413ea9a877 143
ganlikun 0:13413ea9a877 144 } while (__STREXW(newValue,(volatile unsigned long*) ptr));
ganlikun 0:13413ea9a877 145 }
ganlikun 0:13413ea9a877 146
ganlikun 0:13413ea9a877 147 #endif /* USE_RTOS */
ganlikun 0:13413ea9a877 148
ganlikun 0:13413ea9a877 149 #if defined ( __GNUC__ ) && !defined ( __CC_ARM )
ganlikun 0:13413ea9a877 150 #ifndef __weak
ganlikun 0:13413ea9a877 151 #define __weak __attribute__((weak))
ganlikun 0:13413ea9a877 152 #endif /* __weak */
ganlikun 0:13413ea9a877 153 #ifndef __packed
ganlikun 0:13413ea9a877 154 #define __packed __attribute__((__packed__))
ganlikun 0:13413ea9a877 155 #endif /* __packed */
ganlikun 0:13413ea9a877 156 #endif /* __GNUC__ */
ganlikun 0:13413ea9a877 157
ganlikun 0:13413ea9a877 158
ganlikun 0:13413ea9a877 159 /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */
ganlikun 0:13413ea9a877 160 #if defined (__GNUC__) /* GNU Compiler */
ganlikun 0:13413ea9a877 161 #ifndef __ALIGN_END
ganlikun 0:13413ea9a877 162 #define __ALIGN_END __attribute__ ((aligned (4)))
ganlikun 0:13413ea9a877 163 #endif /* __ALIGN_END */
ganlikun 0:13413ea9a877 164 #ifndef __ALIGN_BEGIN
ganlikun 0:13413ea9a877 165 #define __ALIGN_BEGIN
ganlikun 0:13413ea9a877 166 #endif /* __ALIGN_BEGIN */
ganlikun 0:13413ea9a877 167 #else
ganlikun 0:13413ea9a877 168 #ifndef __ALIGN_END
ganlikun 0:13413ea9a877 169 #define __ALIGN_END
ganlikun 0:13413ea9a877 170 #endif /* __ALIGN_END */
ganlikun 0:13413ea9a877 171 #ifndef __ALIGN_BEGIN
ganlikun 0:13413ea9a877 172 #if defined (__CC_ARM) /* ARM Compiler */
ganlikun 0:13413ea9a877 173 #define __ALIGN_BEGIN __align(4)
ganlikun 0:13413ea9a877 174 #elif defined (__ICCARM__) /* IAR Compiler */
ganlikun 0:13413ea9a877 175 #define __ALIGN_BEGIN
ganlikun 0:13413ea9a877 176 #endif /* __CC_ARM */
ganlikun 0:13413ea9a877 177 #endif /* __ALIGN_BEGIN */
ganlikun 0:13413ea9a877 178 #endif /* __GNUC__ */
ganlikun 0:13413ea9a877 179
ganlikun 0:13413ea9a877 180
ganlikun 0:13413ea9a877 181 /**
ganlikun 0:13413ea9a877 182 * @brief __RAM_FUNC definition
ganlikun 0:13413ea9a877 183 */
ganlikun 0:13413ea9a877 184 #if defined ( __CC_ARM )
ganlikun 0:13413ea9a877 185 /* ARM Compiler
ganlikun 0:13413ea9a877 186 ------------
ganlikun 0:13413ea9a877 187 RAM functions are defined using the toolchain options.
ganlikun 0:13413ea9a877 188 Functions that are executed in RAM should reside in a separate source module.
ganlikun 0:13413ea9a877 189 Using the 'Options for File' dialog you can simply change the 'Code / Const'
ganlikun 0:13413ea9a877 190 area of a module to a memory space in physical RAM.
ganlikun 0:13413ea9a877 191 Available memory areas are declared in the 'Target' tab of the 'Options for Target'
ganlikun 0:13413ea9a877 192 dialog.
ganlikun 0:13413ea9a877 193 */
ganlikun 0:13413ea9a877 194 #define __RAM_FUNC HAL_StatusTypeDef
ganlikun 0:13413ea9a877 195
ganlikun 0:13413ea9a877 196 #elif defined ( __ICCARM__ )
ganlikun 0:13413ea9a877 197 /* ICCARM Compiler
ganlikun 0:13413ea9a877 198 ---------------
ganlikun 0:13413ea9a877 199 RAM functions are defined using a specific toolchain keyword "__ramfunc".
ganlikun 0:13413ea9a877 200 */
ganlikun 0:13413ea9a877 201 #define __RAM_FUNC __ramfunc HAL_StatusTypeDef
ganlikun 0:13413ea9a877 202
ganlikun 0:13413ea9a877 203 #elif defined ( __GNUC__ )
ganlikun 0:13413ea9a877 204 /* GNU Compiler
ganlikun 0:13413ea9a877 205 ------------
ganlikun 0:13413ea9a877 206 RAM functions are defined using a specific toolchain attribute
ganlikun 0:13413ea9a877 207 "__attribute__((section(".RamFunc")))".
ganlikun 0:13413ea9a877 208 */
ganlikun 0:13413ea9a877 209 #define __RAM_FUNC HAL_StatusTypeDef __attribute__((section(".RamFunc")))
ganlikun 0:13413ea9a877 210
ganlikun 0:13413ea9a877 211 #endif
ganlikun 0:13413ea9a877 212
ganlikun 0:13413ea9a877 213 /**
ganlikun 0:13413ea9a877 214 * @brief __NOINLINE definition
ganlikun 0:13413ea9a877 215 */
ganlikun 0:13413ea9a877 216 #if defined ( __CC_ARM ) || defined ( __GNUC__ )
ganlikun 0:13413ea9a877 217 /* ARM & GNUCompiler
ganlikun 0:13413ea9a877 218 ----------------
ganlikun 0:13413ea9a877 219 */
ganlikun 0:13413ea9a877 220 #define __NOINLINE __attribute__ ( (noinline) )
ganlikun 0:13413ea9a877 221
ganlikun 0:13413ea9a877 222 #elif defined ( __ICCARM__ )
ganlikun 0:13413ea9a877 223 /* ICCARM Compiler
ganlikun 0:13413ea9a877 224 ---------------
ganlikun 0:13413ea9a877 225 */
ganlikun 0:13413ea9a877 226 #define __NOINLINE _Pragma("optimize = no_inline")
ganlikun 0:13413ea9a877 227
ganlikun 0:13413ea9a877 228 #endif
ganlikun 0:13413ea9a877 229
ganlikun 0:13413ea9a877 230 #ifdef __cplusplus
ganlikun 0:13413ea9a877 231 }
ganlikun 0:13413ea9a877 232 #endif
ganlikun 0:13413ea9a877 233
ganlikun 0:13413ea9a877 234 #endif /* ___STM32F4xx_HAL_DEF */
ganlikun 0:13413ea9a877 235
ganlikun 0:13413ea9a877 236 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
ganlikun 0:13413ea9a877 237