Hal Drivers for L4

Dependents:   BSP OneHopeOnePrayer FINAL_AUDIO_RECORD AudioDemo

Fork of STM32L4xx_HAL_Driver by Senior Design: Sound Monitor

Committer:
EricLew
Date:
Wed Nov 25 17:30:43 2015 +0000
Revision:
2:7aef7655b0a8
Parent:
0:80ee8f3b695e
commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EricLew 0:80ee8f3b695e 1 /**
EricLew 0:80ee8f3b695e 2 ******************************************************************************
EricLew 0:80ee8f3b695e 3 * @file stm32l4xx_ll_utils.h
EricLew 0:80ee8f3b695e 4 * @author MCD Application Team
EricLew 0:80ee8f3b695e 5 * @version V1.1.0
EricLew 0:80ee8f3b695e 6 * @date 16-September-2015
EricLew 0:80ee8f3b695e 7 * @brief Header file of UTILS LL module.
EricLew 0:80ee8f3b695e 8 @verbatim
EricLew 0:80ee8f3b695e 9 ==============================================================================
EricLew 0:80ee8f3b695e 10 ##### How to use this driver #####
EricLew 0:80ee8f3b695e 11 ==============================================================================
EricLew 0:80ee8f3b695e 12 [..]
EricLew 0:80ee8f3b695e 13 The LL UTILS driver contains a set of generic APIs that can be
EricLew 0:80ee8f3b695e 14 used by user:
EricLew 0:80ee8f3b695e 15 (+) Device electronic signature
EricLew 0:80ee8f3b695e 16 (+) Timing functions
EricLew 0:80ee8f3b695e 17
EricLew 0:80ee8f3b695e 18 @endverbatim
EricLew 0:80ee8f3b695e 19 ******************************************************************************
EricLew 0:80ee8f3b695e 20 * @attention
EricLew 0:80ee8f3b695e 21 *
EricLew 0:80ee8f3b695e 22 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
EricLew 0:80ee8f3b695e 23 *
EricLew 0:80ee8f3b695e 24 * Redistribution and use in source and binary forms, with or without modification,
EricLew 0:80ee8f3b695e 25 * are permitted provided that the following conditions are met:
EricLew 0:80ee8f3b695e 26 * 1. Redistributions of source code must retain the above copyright notice,
EricLew 0:80ee8f3b695e 27 * this list of conditions and the following disclaimer.
EricLew 0:80ee8f3b695e 28 * 2. Redistributions in binary form must reproduce the above copyright notice,
EricLew 0:80ee8f3b695e 29 * this list of conditions and the following disclaimer in the documentation
EricLew 0:80ee8f3b695e 30 * and/or other materials provided with the distribution.
EricLew 0:80ee8f3b695e 31 * 3. Neither the name of STMicroelectronics nor the names of its contributors
EricLew 0:80ee8f3b695e 32 * may be used to endorse or promote products derived from this software
EricLew 0:80ee8f3b695e 33 * without specific prior written permission.
EricLew 0:80ee8f3b695e 34 *
EricLew 0:80ee8f3b695e 35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
EricLew 0:80ee8f3b695e 36 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
EricLew 0:80ee8f3b695e 37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
EricLew 0:80ee8f3b695e 38 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
EricLew 0:80ee8f3b695e 39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
EricLew 0:80ee8f3b695e 40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
EricLew 0:80ee8f3b695e 41 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
EricLew 0:80ee8f3b695e 42 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
EricLew 0:80ee8f3b695e 43 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
EricLew 0:80ee8f3b695e 44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
EricLew 0:80ee8f3b695e 45 *
EricLew 0:80ee8f3b695e 46 ******************************************************************************
EricLew 0:80ee8f3b695e 47 */
EricLew 0:80ee8f3b695e 48
EricLew 0:80ee8f3b695e 49 /* Define to prevent recursive inclusion -------------------------------------*/
EricLew 0:80ee8f3b695e 50 #ifndef __STM32L4xx_LL_UTILS_H
EricLew 0:80ee8f3b695e 51 #define __STM32L4xx_LL_UTILS_H
EricLew 0:80ee8f3b695e 52
EricLew 0:80ee8f3b695e 53 #ifdef __cplusplus
EricLew 0:80ee8f3b695e 54 extern "C" {
EricLew 0:80ee8f3b695e 55 #endif
EricLew 0:80ee8f3b695e 56
EricLew 0:80ee8f3b695e 57 /* Includes ------------------------------------------------------------------*/
EricLew 0:80ee8f3b695e 58 #include "stm32l4xx.h"
EricLew 0:80ee8f3b695e 59
EricLew 0:80ee8f3b695e 60 /** @addtogroup STM32L4xx_LL_Driver
EricLew 0:80ee8f3b695e 61 * @{
EricLew 0:80ee8f3b695e 62 */
EricLew 0:80ee8f3b695e 63
EricLew 0:80ee8f3b695e 64 /** @defgroup UTILS_LL UTILS
EricLew 0:80ee8f3b695e 65 * @{
EricLew 0:80ee8f3b695e 66 */
EricLew 0:80ee8f3b695e 67
EricLew 0:80ee8f3b695e 68 /* Private types -------------------------------------------------------------*/
EricLew 0:80ee8f3b695e 69 /* Private variables ---------------------------------------------------------*/
EricLew 0:80ee8f3b695e 70
EricLew 0:80ee8f3b695e 71 /* Private constants ---------------------------------------------------------*/
EricLew 0:80ee8f3b695e 72 /** @defgroup UTILS_LL_Private_Constants UTILS Private Constants
EricLew 0:80ee8f3b695e 73 * @{
EricLew 0:80ee8f3b695e 74 */
EricLew 0:80ee8f3b695e 75
EricLew 0:80ee8f3b695e 76 /* Max delay can be used in LL_mDelay */
EricLew 0:80ee8f3b695e 77 #define LL_MAX_DELAY (uint32_t)0xFFFFFFFF
EricLew 0:80ee8f3b695e 78
EricLew 0:80ee8f3b695e 79 /**
EricLew 0:80ee8f3b695e 80 * @brief Unique device ID register base address
EricLew 0:80ee8f3b695e 81 */
EricLew 0:80ee8f3b695e 82 #define UID_BASE_ADDRESS (uint32_t)0x1FFF7590
EricLew 0:80ee8f3b695e 83
EricLew 0:80ee8f3b695e 84 /**
EricLew 0:80ee8f3b695e 85 * @brief Flash size data register base address
EricLew 0:80ee8f3b695e 86 */
EricLew 0:80ee8f3b695e 87 #define FLASHSIZE_BASE_ADDRESS (uint32_t)0x1FFF75E0
EricLew 0:80ee8f3b695e 88
EricLew 0:80ee8f3b695e 89 /**
EricLew 0:80ee8f3b695e 90 * @brief Package data register base address
EricLew 0:80ee8f3b695e 91 */
EricLew 0:80ee8f3b695e 92 #define PACKAGESIZE_BASE_ADDRESS (uint32_t)0x1FFF7500
EricLew 0:80ee8f3b695e 93
EricLew 0:80ee8f3b695e 94 /**
EricLew 0:80ee8f3b695e 95 * @}
EricLew 0:80ee8f3b695e 96 */
EricLew 0:80ee8f3b695e 97
EricLew 0:80ee8f3b695e 98 /* Private macros ------------------------------------------------------------*/
EricLew 0:80ee8f3b695e 99
EricLew 0:80ee8f3b695e 100 /* Exported types ------------------------------------------------------------*/
EricLew 0:80ee8f3b695e 101 /* Exported constants --------------------------------------------------------*/
EricLew 0:80ee8f3b695e 102 /** @defgroup UTILS_LL_Exported_Constants UTILS Exported Constants
EricLew 0:80ee8f3b695e 103 * @{
EricLew 0:80ee8f3b695e 104 */
EricLew 0:80ee8f3b695e 105
EricLew 0:80ee8f3b695e 106 /** @defgroup UTILS_EC_PACKAGETYPE PACKAGE TYPE
EricLew 0:80ee8f3b695e 107 * @{
EricLew 0:80ee8f3b695e 108 */
EricLew 0:80ee8f3b695e 109 #define LL_UTILS_PACKAGETYPE_LQFP64 (uint32_t)0x00000000 /*!< LQFP64 package type */
EricLew 0:80ee8f3b695e 110 #define LL_UTILS_PACKAGETYPE_LQPF100 (uint32_t)0x00000002 /*!< LQFP100 package type */
EricLew 0:80ee8f3b695e 111 #define LL_UTILS_PACKAGETYPE_BGA132 (uint32_t)0x00000003 /*!< BGA132 package type */
EricLew 0:80ee8f3b695e 112 #define LL_UTILS_PACKAGETYPE_LQFP144_CSP72 (uint32_t)0x00000004 /*!< LQFP144, WLCSP81 or WLCSP72 package type */
EricLew 0:80ee8f3b695e 113 /**
EricLew 0:80ee8f3b695e 114 * @}
EricLew 0:80ee8f3b695e 115 */
EricLew 0:80ee8f3b695e 116
EricLew 0:80ee8f3b695e 117 /**
EricLew 0:80ee8f3b695e 118 * @}
EricLew 0:80ee8f3b695e 119 */
EricLew 0:80ee8f3b695e 120
EricLew 0:80ee8f3b695e 121 /* Exported macro ------------------------------------------------------------*/
EricLew 0:80ee8f3b695e 122
EricLew 0:80ee8f3b695e 123 /* Exported functions --------------------------------------------------------*/
EricLew 0:80ee8f3b695e 124 /** @defgroup UTILS_LL_Exported_Functions UTILS Exported Functions
EricLew 0:80ee8f3b695e 125 * @{
EricLew 0:80ee8f3b695e 126 */
EricLew 0:80ee8f3b695e 127
EricLew 0:80ee8f3b695e 128 /** @defgroup UTILS_EF_DEVICE_ELECTRONIC_SIGNATURE DEVICE ELECTRONIC SIGNATURE
EricLew 0:80ee8f3b695e 129 * @{
EricLew 0:80ee8f3b695e 130 */
EricLew 0:80ee8f3b695e 131
EricLew 0:80ee8f3b695e 132 /**
EricLew 0:80ee8f3b695e 133 * @brief Get Word0 of the unique device identifier (UID based on 96 bits)
EricLew 0:80ee8f3b695e 134 * @retval UID[31:0]: X and Y coordinates on the wafer expressed in BCD format
EricLew 0:80ee8f3b695e 135 */
EricLew 0:80ee8f3b695e 136 __STATIC_INLINE uint32_t LL_GetUID_Word0(void)
EricLew 0:80ee8f3b695e 137 {
EricLew 0:80ee8f3b695e 138 return (uint32_t)(READ_REG(*((uint32_t *)UID_BASE_ADDRESS)));
EricLew 0:80ee8f3b695e 139 }
EricLew 0:80ee8f3b695e 140
EricLew 0:80ee8f3b695e 141 /**
EricLew 0:80ee8f3b695e 142 * @brief Get Word1 of the unique device identifier (UID based on 96 bits)
EricLew 0:80ee8f3b695e 143 * @retval UID[63:32]: Wafer number (UID[39:32]) & LOT_NUM[23:0] (UID[63:40])
EricLew 0:80ee8f3b695e 144 */
EricLew 0:80ee8f3b695e 145 __STATIC_INLINE uint32_t LL_GetUID_Word1(void)
EricLew 0:80ee8f3b695e 146 {
EricLew 0:80ee8f3b695e 147 return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 4))));
EricLew 0:80ee8f3b695e 148 }
EricLew 0:80ee8f3b695e 149
EricLew 0:80ee8f3b695e 150 /**
EricLew 0:80ee8f3b695e 151 * @brief Get Word2 of the unique device identifier (UID based on 96 bits)
EricLew 0:80ee8f3b695e 152 * @retval UID[95:64]: Lot number (ASCII encoded) - LOT_NUM[31:24]
EricLew 0:80ee8f3b695e 153 */
EricLew 0:80ee8f3b695e 154 __STATIC_INLINE uint32_t LL_GetUID_Word2(void)
EricLew 0:80ee8f3b695e 155 {
EricLew 0:80ee8f3b695e 156 return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 8))));
EricLew 0:80ee8f3b695e 157 }
EricLew 0:80ee8f3b695e 158
EricLew 0:80ee8f3b695e 159 /**
EricLew 0:80ee8f3b695e 160 * @brief Get Flash memory size
EricLew 0:80ee8f3b695e 161 * @note This bitfield indicates the size of the device Flash memory expressed in
EricLew 0:80ee8f3b695e 162 * Kbytes. As an example, 0x040 corresponds to 64 Kbytes.
EricLew 0:80ee8f3b695e 163 * @retval FLASH_SIZE[15:0]: Flash memory size
EricLew 0:80ee8f3b695e 164 */
EricLew 0:80ee8f3b695e 165 __STATIC_INLINE uint32_t LL_GetFlashSize(void)
EricLew 0:80ee8f3b695e 166 {
EricLew 0:80ee8f3b695e 167 return (uint16_t)(READ_REG(*((uint32_t *)FLASHSIZE_BASE_ADDRESS)));
EricLew 0:80ee8f3b695e 168 }
EricLew 0:80ee8f3b695e 169
EricLew 0:80ee8f3b695e 170 /**
EricLew 0:80ee8f3b695e 171 * @brief Get Package type
EricLew 0:80ee8f3b695e 172 * @retval Returned value can be one of the following values:
EricLew 0:80ee8f3b695e 173 * @arg @ref LL_UTILS_PACKAGETYPE_LQFP64
EricLew 0:80ee8f3b695e 174 * @arg @ref LL_UTILS_PACKAGETYPE_LQPF100
EricLew 0:80ee8f3b695e 175 * @arg @ref LL_UTILS_PACKAGETYPE_BGA132
EricLew 0:80ee8f3b695e 176 * @arg @ref LL_UTILS_PACKAGETYPE_LQFP144_CSP72
EricLew 0:80ee8f3b695e 177 */
EricLew 0:80ee8f3b695e 178 __STATIC_INLINE uint32_t LL_GetPackageType(void)
EricLew 0:80ee8f3b695e 179 {
EricLew 0:80ee8f3b695e 180 return (uint8_t)(READ_REG(*((uint32_t *)PACKAGESIZE_BASE_ADDRESS)));
EricLew 0:80ee8f3b695e 181 }
EricLew 0:80ee8f3b695e 182
EricLew 0:80ee8f3b695e 183 /**
EricLew 0:80ee8f3b695e 184 * @}
EricLew 0:80ee8f3b695e 185 */
EricLew 0:80ee8f3b695e 186
EricLew 0:80ee8f3b695e 187 /** @defgroup UTILS_EF_DELAY DELAY
EricLew 0:80ee8f3b695e 188 * @{
EricLew 0:80ee8f3b695e 189 */
EricLew 0:80ee8f3b695e 190
EricLew 0:80ee8f3b695e 191 /**
EricLew 0:80ee8f3b695e 192 * @brief This function provides accurate delay (in milliseconds) based
EricLew 0:80ee8f3b695e 193 * on SysTick counter flag
EricLew 0:80ee8f3b695e 194 * @note To respect 1ms timebase, user should call LL_InitTick function which
EricLew 0:80ee8f3b695e 195 * will configure Systick to 1ms
EricLew 0:80ee8f3b695e 196 * @param Delay specifies the delay time length, in milliseconds.
EricLew 0:80ee8f3b695e 197 * @retval None
EricLew 0:80ee8f3b695e 198 */
EricLew 0:80ee8f3b695e 199 __STATIC_INLINE void LL_mDelay(uint32_t Delay)
EricLew 0:80ee8f3b695e 200 {
EricLew 0:80ee8f3b695e 201 volatile uint32_t tmp = SysTick->CTRL; /* Clear the COUNTFLAG first */
EricLew 0:80ee8f3b695e 202 ((void)tmp);
EricLew 0:80ee8f3b695e 203
EricLew 0:80ee8f3b695e 204 /* Add a period to guaranty minimum wait */
EricLew 0:80ee8f3b695e 205 if (Delay < LL_MAX_DELAY)
EricLew 0:80ee8f3b695e 206 {
EricLew 0:80ee8f3b695e 207 Delay++;
EricLew 0:80ee8f3b695e 208 }
EricLew 0:80ee8f3b695e 209
EricLew 0:80ee8f3b695e 210 while (Delay)
EricLew 0:80ee8f3b695e 211 {
EricLew 0:80ee8f3b695e 212 if ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) != 0)
EricLew 0:80ee8f3b695e 213 {
EricLew 0:80ee8f3b695e 214 Delay--;
EricLew 0:80ee8f3b695e 215 }
EricLew 0:80ee8f3b695e 216 }
EricLew 0:80ee8f3b695e 217 }
EricLew 0:80ee8f3b695e 218
EricLew 0:80ee8f3b695e 219 /**
EricLew 0:80ee8f3b695e 220 * @brief This function configures the source of the time base.
EricLew 0:80ee8f3b695e 221 * @note The time source is configured to have 1ms time base.
EricLew 0:80ee8f3b695e 222 * @param HCLKFrequency HCLK frequency in Hz (can be calculated thanks to RCC helper macro)
EricLew 0:80ee8f3b695e 223 * @retval None
EricLew 0:80ee8f3b695e 224 */
EricLew 0:80ee8f3b695e 225 __STATIC_INLINE void LL_Init1msTick(uint32_t HCLKFrequency)
EricLew 0:80ee8f3b695e 226 {
EricLew 0:80ee8f3b695e 227 /* Configure the SysTick to have interrupt in 1ms time base */
EricLew 0:80ee8f3b695e 228 SysTick->LOAD = (uint32_t)((HCLKFrequency / 1000) - 1UL); /* set reload register */
EricLew 0:80ee8f3b695e 229 SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
EricLew 0:80ee8f3b695e 230 SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
EricLew 0:80ee8f3b695e 231 SysTick_CTRL_ENABLE_Msk; /* Enable the Systick Timer */
EricLew 0:80ee8f3b695e 232 }
EricLew 0:80ee8f3b695e 233
EricLew 0:80ee8f3b695e 234 /**
EricLew 0:80ee8f3b695e 235 * @}
EricLew 0:80ee8f3b695e 236 */
EricLew 0:80ee8f3b695e 237
EricLew 0:80ee8f3b695e 238 /** @defgroup UTILS_EF_SYSTEM SYSTEM
EricLew 0:80ee8f3b695e 239 * @{
EricLew 0:80ee8f3b695e 240 */
EricLew 0:80ee8f3b695e 241
EricLew 0:80ee8f3b695e 242 /**
EricLew 0:80ee8f3b695e 243 * @brief This function sets directly SystemCoreClock CMSIS variable.
EricLew 0:80ee8f3b695e 244 * @note Variable can be calculated also through SystemCoreClockUpdate function.
EricLew 0:80ee8f3b695e 245 * @param HCLKFrequency HCLK frequency in Hz (can be calculated thanks to RCC helper macro)
EricLew 0:80ee8f3b695e 246 * @retval None
EricLew 0:80ee8f3b695e 247 */
EricLew 0:80ee8f3b695e 248 __STATIC_INLINE void LL_SetSystemCoreClock(uint32_t HCLKFrequency)
EricLew 0:80ee8f3b695e 249 {
EricLew 0:80ee8f3b695e 250 /* HCLK clock frequency */
EricLew 0:80ee8f3b695e 251 SystemCoreClock = HCLKFrequency;
EricLew 0:80ee8f3b695e 252 }
EricLew 0:80ee8f3b695e 253
EricLew 0:80ee8f3b695e 254 /**
EricLew 0:80ee8f3b695e 255 * @}
EricLew 0:80ee8f3b695e 256 */
EricLew 0:80ee8f3b695e 257
EricLew 0:80ee8f3b695e 258
EricLew 0:80ee8f3b695e 259 /**
EricLew 0:80ee8f3b695e 260 * @}
EricLew 0:80ee8f3b695e 261 */
EricLew 0:80ee8f3b695e 262
EricLew 0:80ee8f3b695e 263 /**
EricLew 0:80ee8f3b695e 264 * @}
EricLew 0:80ee8f3b695e 265 */
EricLew 0:80ee8f3b695e 266
EricLew 0:80ee8f3b695e 267 /**
EricLew 0:80ee8f3b695e 268 * @}
EricLew 0:80ee8f3b695e 269 */
EricLew 0:80ee8f3b695e 270
EricLew 0:80ee8f3b695e 271 #ifdef __cplusplus
EricLew 0:80ee8f3b695e 272 }
EricLew 0:80ee8f3b695e 273 #endif
EricLew 0:80ee8f3b695e 274
EricLew 0:80ee8f3b695e 275 #endif /* __STM32L4xx_LL_UTILS_H */
EricLew 0:80ee8f3b695e 276
EricLew 0:80ee8f3b695e 277 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
EricLew 0:80ee8f3b695e 278