1 /** 2 ****************************************************************************** 3 * @file stm32l5xx.h 4 * @author MCD Application Team 5 * @brief CMSIS STM32L5xx 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 STM32L5xx 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) 2019 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 stm32l5xx 34 * @{ 35 */ 36 37 #ifndef STM32L5xx_H 38 #define STM32L5xx_H 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif /* __cplusplus */ 43 44 /** @addtogroup Library_configuration_section 45 * @{ 46 */ 47 48 /** 49 * @brief STM32 Family 50 */ 51 #if !defined (STM32L5) 52 #define STM32L5 53 #endif /* STM32L5 */ 54 55 /* Uncomment the line below according to the target STM32L5 device used in your 56 application 57 */ 58 59 #if !defined (STM32L552xx) && !defined (STM32L562xx) 60 /* #define STM32L552xx */ /*!< STM32L552xx Devices */ 61 /* #define STM32L562xx */ /*!< STM32L562xx Devices */ 62 #endif 63 64 /* Tip: To avoid modifying this file each time you need to switch between these 65 devices, you can define the device in your toolchain compiler preprocessor. 66 */ 67 #if !defined (USE_HAL_DRIVER) 68 /** 69 * @brief Comment the line below if you will not use the peripherals drivers. 70 In this case, these drivers will not be included and the application code will 71 be based on direct access to peripherals registers 72 */ 73 /*#define USE_HAL_DRIVER */ 74 #endif /* USE_HAL_DRIVER */ 75 76 /** 77 * @brief CMSIS Device version number 78 */ 79 #define __STM32L5_CMSIS_VERSION_MAIN (0x01U) /*!< [31:24] main version */ 80 #define __STM32L5_CMSIS_VERSION_SUB1 (0x00U) /*!< [23:16] sub1 version */ 81 #define __STM32L5_CMSIS_VERSION_SUB2 (0x05U) /*!< [15:8] sub2 version */ 82 #define __STM32L5_CMSIS_VERSION_RC (0x00U) /*!< [7:0] release candidate */ 83 #define __STM32L5_CMSIS_VERSION ((__STM32L5_CMSIS_VERSION_MAIN << 24U)\ 84 |(__STM32L5_CMSIS_VERSION_SUB1 << 16U)\ 85 |(__STM32L5_CMSIS_VERSION_SUB2 << 8U )\ 86 |(__STM32L5_CMSIS_VERSION_RC)) 87 88 /** 89 * @} 90 */ 91 92 /** @addtogroup Device_Included 93 * @{ 94 */ 95 96 #if defined(STM32L552xx) 97 #include "stm32l552xx.h" 98 #elif defined(STM32L562xx) 99 #include "stm32l562xx.h" 100 #else 101 #error "Please select first the target STM32L5xx device used in your application (in stm32l5xx.h file)" 102 #endif 103 104 /** 105 * @} 106 */ 107 108 /** @addtogroup Exported_types 109 * @{ 110 */ 111 typedef enum 112 { 113 RESET = 0, 114 SET = !RESET 115 } FlagStatus, ITStatus; 116 117 typedef enum 118 { 119 DISABLE = 0, 120 ENABLE = !DISABLE 121 } FunctionalState; 122 #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE)) 123 124 typedef enum 125 { 126 SUCCESS = 0, 127 ERROR = !SUCCESS 128 } ErrorStatus; 129 130 /** 131 * @} 132 */ 133 134 135 /** @addtogroup Exported_macros 136 * @{ 137 */ 138 #define SET_BIT(REG, BIT) ((REG) |= (BIT)) 139 140 #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT)) 141 142 #define READ_BIT(REG, BIT) ((REG) & (BIT)) 143 144 #define CLEAR_REG(REG) ((REG) = (0x0)) 145 146 #define WRITE_REG(REG, VAL) ((REG) = (VAL)) 147 148 #define READ_REG(REG) ((REG)) 149 150 #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK))) 151 152 /* Use of CMSIS compiler intrinsics for register exclusive access */ 153 /* Atomic 32-bit register access macro to set one or several bits */ 154 #define ATOMIC_SET_BIT(REG, BIT) \ 155 do { \ 156 uint32_t val; \ 157 do { \ 158 val = __LDREXW((__IO uint32_t *)&(REG)) | (BIT); \ 159 } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \ 160 } while(0) 161 162 /* Atomic 32-bit register access macro to clear one or several bits */ 163 #define ATOMIC_CLEAR_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 and set one or several bits */ 172 #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \ 173 do { \ 174 uint32_t val; \ 175 do { \ 176 val = (__LDREXW((__IO uint32_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \ 177 } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \ 178 } while(0) 179 180 /* Atomic 16-bit register access macro to set one or several bits */ 181 #define ATOMIC_SETH_BIT(REG, BIT) \ 182 do { \ 183 uint16_t val; \ 184 do { \ 185 val = __LDREXH((__IO uint16_t *)&(REG)) | (BIT); \ 186 } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \ 187 } while(0) 188 189 /* Atomic 16-bit register access macro to clear one or several bits */ 190 #define ATOMIC_CLEARH_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 and set one or several bits */ 199 #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK) \ 200 do { \ 201 uint16_t val; \ 202 do { \ 203 val = (__LDREXH((__IO uint16_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \ 204 } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \ 205 } while(0) 206 207 #define POSITION_VAL(VAL) (__CLZ(__RBIT(VAL))) 208 209 210 /** 211 * @} 212 */ 213 214 #if defined (USE_HAL_DRIVER) 215 #include "stm32l5xx_hal.h" 216 #endif /* USE_HAL_DRIVER */ 217 218 #ifdef __cplusplus 219 } 220 #endif /* __cplusplus */ 221 222 #endif /* STM32L5xx_H */ 223 /** 224 * @} 225 */ 226 227 /** 228 * @} 229 */ 230 231