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