|
| 1 | +/** |
| 2 | + ****************************************************************************** |
| 3 | + * @file stm32h5xx.h |
| 4 | + * @author MCD Application Team |
| 5 | + * @brief CMSIS STM32H5xx Device Peripheral Access Layer Header File. |
| 6 | + * |
| 7 | + * The file is the unique include file that the application programmer |
| 8 | + * is using in the C source code, usually in main.c. This file contains: |
| 9 | + * - Configuration section that allows to select: |
| 10 | + * - The STM32H5xx device used in the target application |
| 11 | + * - To use or not the peripheral’s drivers in application code(i.e. |
| 12 | + * code will be based on direct access to peripheral’s registers |
| 13 | + * rather than drivers API), this option is controlled by |
| 14 | + * "#define USE_HAL_DRIVER" |
| 15 | + * |
| 16 | + ****************************************************************************** |
| 17 | + * @attention |
| 18 | + * |
| 19 | + * Copyright (c) 2023 STMicroelectronics. |
| 20 | + * All rights reserved. |
| 21 | + * |
| 22 | + * This software is licensed under terms that can be found in the LICENSE file |
| 23 | + * in the root directory of this software component. |
| 24 | + * If no LICENSE file comes with this software, it is provided AS-IS. |
| 25 | + * |
| 26 | + ****************************************************************************** |
| 27 | + */ |
| 28 | + |
| 29 | +/** @addtogroup CMSIS |
| 30 | + * @{ |
| 31 | + */ |
| 32 | + |
| 33 | +/** @addtogroup stm32h5xx |
| 34 | + * @{ |
| 35 | + */ |
| 36 | + |
| 37 | +#ifndef STM32H5xx_H |
| 38 | +#define STM32H5xx_H |
| 39 | +#include "math.h" |
| 40 | + |
| 41 | +#ifdef __cplusplus |
| 42 | + extern "C" { |
| 43 | +#endif /* __cplusplus */ |
| 44 | + |
| 45 | +/** @addtogroup Library_configuration_section |
| 46 | + * @{ |
| 47 | + */ |
| 48 | + |
| 49 | +/** |
| 50 | + * @brief STM32 Family |
| 51 | + */ |
| 52 | +#if !defined (STM32H5) |
| 53 | +#define STM32H5 |
| 54 | +#endif /* STM32H5 */ |
| 55 | + |
| 56 | +/* Uncomment the line below according to the target STM32H5 device used in your |
| 57 | + application |
| 58 | + */ |
| 59 | + |
| 60 | +#if !defined (STM32H573xx) && !defined (STM32H563xx) \ |
| 61 | + && !defined (STM32H562xx) && !defined (STM32H503xx) |
| 62 | + /* #define STM32H573xx */ /*!< STM32H5753xx Devices */ |
| 63 | + /* #define STM32H563xx */ /*!< STM32H563xx Devices */ |
| 64 | + /* #define STM32H562xx */ /*!< STM32H562xx Devices */ |
| 65 | + /* #define STM32H503xx */ /*!< STM32H503xx Devices */ |
| 66 | +#endif |
| 67 | + |
| 68 | +/* Tip: To avoid modifying this file each time you need to switch between these |
| 69 | + devices, you can define the device in your toolchain compiler preprocessor. |
| 70 | + */ |
| 71 | +#if !defined (USE_HAL_DRIVER) |
| 72 | +/** |
| 73 | + * @brief Comment the line below if you will not use the peripherals drivers. |
| 74 | + In this case, these drivers will not be included and the application code will |
| 75 | + be based on direct access to peripherals registers |
| 76 | + */ |
| 77 | + /*#define USE_HAL_DRIVER */ |
| 78 | +#endif /* USE_HAL_DRIVER */ |
| 79 | + |
| 80 | +/** |
| 81 | + * @brief CMSIS Device version number 1.0.0 |
| 82 | + */ |
| 83 | +#define __STM32H5_CMSIS_VERSION_MAIN (0x01) /*!< [31:24] main version */ |
| 84 | +#define __STM32H5_CMSIS_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */ |
| 85 | +#define __STM32H5_CMSIS_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */ |
| 86 | +#define __STM32H5_CMSIS_VERSION_RC (0x00) /*!< [7:0] release candidate */ |
| 87 | +#define __STM32H5_CMSIS_VERSION ((__STM32H5_CMSIS_VERSION_MAIN << 24U)\ |
| 88 | + |(__STM32H5_CMSIS_VERSION_SUB1 << 16U)\ |
| 89 | + |(__STM32H5_CMSIS_VERSION_SUB2 << 8U )\ |
| 90 | + |(__STM32H5_CMSIS_VERSION_RC)) |
| 91 | + |
| 92 | +/** |
| 93 | + * @} |
| 94 | + */ |
| 95 | + |
| 96 | +/** @addtogroup Device_Included |
| 97 | + * @{ |
| 98 | + */ |
| 99 | + |
| 100 | +#if defined(STM32H573xx) |
| 101 | + #include "stm32h573xx.h" |
| 102 | +#elif defined(STM32H563xx) |
| 103 | + #include "stm32h563xx.h" |
| 104 | +#elif defined(STM32H562xx) |
| 105 | + #include "stm32h562xx.h" |
| 106 | +#elif defined(STM32H503xx) |
| 107 | + #include "stm32h503xx.h" |
| 108 | +#else |
| 109 | + #error "Please select first the target STM32H5xx device used in your application (in stm32h5xx.h file)" |
| 110 | +#endif |
| 111 | + |
| 112 | + |
| 113 | +/** |
| 114 | + * @} |
| 115 | + */ |
| 116 | + |
| 117 | +/** @addtogroup Exported_types |
| 118 | + * @{ |
| 119 | + */ |
| 120 | +typedef enum |
| 121 | +{ |
| 122 | + RESET = 0, |
| 123 | + SET = !RESET |
| 124 | +} FlagStatus, ITStatus; |
| 125 | + |
| 126 | +typedef enum |
| 127 | +{ |
| 128 | + DISABLE = 0, |
| 129 | + ENABLE = !DISABLE |
| 130 | +} FunctionalState; |
| 131 | +#define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE)) |
| 132 | + |
| 133 | +typedef enum |
| 134 | +{ |
| 135 | + SUCCESS = 0, |
| 136 | + ERROR = !SUCCESS |
| 137 | +} ErrorStatus; |
| 138 | + |
| 139 | +/** |
| 140 | + * @} |
| 141 | + */ |
| 142 | + |
| 143 | + |
| 144 | +/** @addtogroup Exported_macros |
| 145 | + * @{ |
| 146 | + */ |
| 147 | +#define SET_BIT(REG, BIT) ((REG) |= (BIT)) |
| 148 | + |
| 149 | +#define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT)) |
| 150 | + |
| 151 | +#define READ_BIT(REG, BIT) ((REG) & (BIT)) |
| 152 | + |
| 153 | +#define CLEAR_REG(REG) ((REG) = (0x0)) |
| 154 | + |
| 155 | +#define WRITE_REG(REG, VAL) ((REG) = (VAL)) |
| 156 | + |
| 157 | +#define READ_REG(REG) ((REG)) |
| 158 | + |
| 159 | +#define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK))) |
| 160 | + |
| 161 | +/* Use of CMSIS compiler intrinsics for register exclusive access */ |
| 162 | +/* Atomic 32-bit register access macro to set one or several bits */ |
| 163 | +#define ATOMIC_SET_BIT(REG, BIT) \ |
| 164 | + do { \ |
| 165 | + uint32_t val; \ |
| 166 | + do { \ |
| 167 | + val = __LDREXW((__IO uint32_t *)&(REG)) | (BIT); \ |
| 168 | + } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \ |
| 169 | + } while(0) |
| 170 | + |
| 171 | +/* Atomic 32-bit register access macro to clear one or several bits */ |
| 172 | +#define ATOMIC_CLEAR_BIT(REG, BIT) \ |
| 173 | + do { \ |
| 174 | + uint32_t val; \ |
| 175 | + do { \ |
| 176 | + val = __LDREXW((__IO uint32_t *)&(REG)) & ~(BIT); \ |
| 177 | + } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \ |
| 178 | + } while(0) |
| 179 | + |
| 180 | +/* Atomic 32-bit register access macro to clear and set one or several bits */ |
| 181 | +#define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \ |
| 182 | + do { \ |
| 183 | + uint32_t val; \ |
| 184 | + do { \ |
| 185 | + val = (__LDREXW((__IO uint32_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \ |
| 186 | + } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \ |
| 187 | + } while(0) |
| 188 | + |
| 189 | +/* Atomic 16-bit register access macro to set one or several bits */ |
| 190 | +#define ATOMIC_SETH_BIT(REG, BIT) \ |
| 191 | + do { \ |
| 192 | + uint16_t val; \ |
| 193 | + do { \ |
| 194 | + val = __LDREXH((__IO uint16_t *)&(REG)) | (BIT); \ |
| 195 | + } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \ |
| 196 | + } while(0) |
| 197 | + |
| 198 | +/* Atomic 16-bit register access macro to clear one or several bits */ |
| 199 | +#define ATOMIC_CLEARH_BIT(REG, BIT) \ |
| 200 | + do { \ |
| 201 | + uint16_t val; \ |
| 202 | + do { \ |
| 203 | + val = __LDREXH((__IO uint16_t *)&(REG)) & ~(BIT); \ |
| 204 | + } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \ |
| 205 | + } while(0) |
| 206 | + |
| 207 | +/* Atomic 16-bit register access macro to clear and set one or several bits */ |
| 208 | +#define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK) \ |
| 209 | + do { \ |
| 210 | + uint16_t val; \ |
| 211 | + do { \ |
| 212 | + val = (__LDREXH((__IO uint16_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \ |
| 213 | + } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \ |
| 214 | + } while(0) |
| 215 | + |
| 216 | +#define POSITION_VAL(VAL) (__CLZ(__RBIT(VAL))) |
| 217 | + |
| 218 | + |
| 219 | +/** |
| 220 | + * @} |
| 221 | + */ |
| 222 | + |
| 223 | +#if defined (USE_HAL_DRIVER) |
| 224 | + #include "stm32h5xx_hal.h" |
| 225 | +#endif /* USE_HAL_DRIVER */ |
| 226 | + |
| 227 | +#ifdef __cplusplus |
| 228 | +} |
| 229 | +#endif /* __cplusplus */ |
| 230 | + |
| 231 | +#endif /* STM32H5xx_H */ |
| 232 | +/** |
| 233 | + * @} |
| 234 | + */ |
| 235 | + |
| 236 | +/** |
| 237 | + * @} |
| 238 | + */ |
0 commit comments