fix LPC812 PWM
Fork of mbed-dev by
targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal.c@0:9b334a45a8ff, 2015-10-01 (annotated)
- Committer:
- bogdanm
- Date:
- Thu Oct 01 15:25:22 2015 +0300
- Revision:
- 0:9b334a45a8ff
Initial commit on mbed-dev
Replaces mbed-src (now inactive)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:9b334a45a8ff | 1 | /** |
bogdanm | 0:9b334a45a8ff | 2 | ****************************************************************************** |
bogdanm | 0:9b334a45a8ff | 3 | * @file stm32f0xx_hal.c |
bogdanm | 0:9b334a45a8ff | 4 | * @author MCD Application Team |
bogdanm | 0:9b334a45a8ff | 5 | * @version V1.3.0 |
bogdanm | 0:9b334a45a8ff | 6 | * @date 26-June-2015 |
bogdanm | 0:9b334a45a8ff | 7 | * @brief HAL module driver. |
bogdanm | 0:9b334a45a8ff | 8 | * This is the common part of the HAL initialization |
bogdanm | 0:9b334a45a8ff | 9 | * |
bogdanm | 0:9b334a45a8ff | 10 | @verbatim |
bogdanm | 0:9b334a45a8ff | 11 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 12 | ##### How to use this driver ##### |
bogdanm | 0:9b334a45a8ff | 13 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 14 | [..] |
bogdanm | 0:9b334a45a8ff | 15 | The common HAL driver contains a set of generic and common APIs that can be |
bogdanm | 0:9b334a45a8ff | 16 | used by the PPP peripheral drivers and the user to start using the HAL. |
bogdanm | 0:9b334a45a8ff | 17 | [..] |
bogdanm | 0:9b334a45a8ff | 18 | The HAL contains two APIs categories: |
bogdanm | 0:9b334a45a8ff | 19 | (+) HAL Initialization and de-initialization functions |
bogdanm | 0:9b334a45a8ff | 20 | (+) HAL Control functions |
bogdanm | 0:9b334a45a8ff | 21 | |
bogdanm | 0:9b334a45a8ff | 22 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 23 | ****************************************************************************** |
bogdanm | 0:9b334a45a8ff | 24 | * @attention |
bogdanm | 0:9b334a45a8ff | 25 | * |
bogdanm | 0:9b334a45a8ff | 26 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
bogdanm | 0:9b334a45a8ff | 27 | * |
bogdanm | 0:9b334a45a8ff | 28 | * Redistribution and use in source and binary forms, with or without modification, |
bogdanm | 0:9b334a45a8ff | 29 | * are permitted provided that the following conditions are met: |
bogdanm | 0:9b334a45a8ff | 30 | * 1. Redistributions of source code must retain the above copyright notice, |
bogdanm | 0:9b334a45a8ff | 31 | * this list of conditions and the following disclaimer. |
bogdanm | 0:9b334a45a8ff | 32 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
bogdanm | 0:9b334a45a8ff | 33 | * this list of conditions and the following disclaimer in the documentation |
bogdanm | 0:9b334a45a8ff | 34 | * and/or other materials provided with the distribution. |
bogdanm | 0:9b334a45a8ff | 35 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
bogdanm | 0:9b334a45a8ff | 36 | * may be used to endorse or promote products derived from this software |
bogdanm | 0:9b334a45a8ff | 37 | * without specific prior written permission. |
bogdanm | 0:9b334a45a8ff | 38 | * |
bogdanm | 0:9b334a45a8ff | 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
bogdanm | 0:9b334a45a8ff | 40 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
bogdanm | 0:9b334a45a8ff | 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
bogdanm | 0:9b334a45a8ff | 42 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
bogdanm | 0:9b334a45a8ff | 43 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
bogdanm | 0:9b334a45a8ff | 44 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
bogdanm | 0:9b334a45a8ff | 45 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
bogdanm | 0:9b334a45a8ff | 46 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
bogdanm | 0:9b334a45a8ff | 47 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
bogdanm | 0:9b334a45a8ff | 48 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bogdanm | 0:9b334a45a8ff | 49 | * |
bogdanm | 0:9b334a45a8ff | 50 | ****************************************************************************** |
bogdanm | 0:9b334a45a8ff | 51 | */ |
bogdanm | 0:9b334a45a8ff | 52 | |
bogdanm | 0:9b334a45a8ff | 53 | /* Includes ------------------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 54 | #include "stm32f0xx_hal.h" |
bogdanm | 0:9b334a45a8ff | 55 | |
bogdanm | 0:9b334a45a8ff | 56 | /** @addtogroup STM32F0xx_HAL_Driver |
bogdanm | 0:9b334a45a8ff | 57 | * @{ |
bogdanm | 0:9b334a45a8ff | 58 | */ |
bogdanm | 0:9b334a45a8ff | 59 | |
bogdanm | 0:9b334a45a8ff | 60 | /** @defgroup HAL HAL |
bogdanm | 0:9b334a45a8ff | 61 | * @brief HAL module driver. |
bogdanm | 0:9b334a45a8ff | 62 | * @{ |
bogdanm | 0:9b334a45a8ff | 63 | */ |
bogdanm | 0:9b334a45a8ff | 64 | |
bogdanm | 0:9b334a45a8ff | 65 | #ifdef HAL_MODULE_ENABLED |
bogdanm | 0:9b334a45a8ff | 66 | |
bogdanm | 0:9b334a45a8ff | 67 | /* Private typedef -----------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 68 | /* Private define ------------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 69 | /** @defgroup HAL_Private_Constants HAL Private Constants |
bogdanm | 0:9b334a45a8ff | 70 | * @{ |
bogdanm | 0:9b334a45a8ff | 71 | */ |
bogdanm | 0:9b334a45a8ff | 72 | /** |
bogdanm | 0:9b334a45a8ff | 73 | * @brief STM32F0xx HAL Driver version number V1.3.0 |
bogdanm | 0:9b334a45a8ff | 74 | */ |
bogdanm | 0:9b334a45a8ff | 75 | #define __STM32F0xx_HAL_VERSION_MAIN (0x01) /*!< [31:24] main version */ |
bogdanm | 0:9b334a45a8ff | 76 | #define __STM32F0xx_HAL_VERSION_SUB1 (0x03) /*!< [23:16] sub1 version */ |
bogdanm | 0:9b334a45a8ff | 77 | #define __STM32F0xx_HAL_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */ |
bogdanm | 0:9b334a45a8ff | 78 | #define __STM32F0xx_HAL_VERSION_RC (0x00) /*!< [7:0] release candidate */ |
bogdanm | 0:9b334a45a8ff | 79 | #define __STM32F0xx_HAL_VERSION ((__STM32F0xx_HAL_VERSION_MAIN << 24)\ |
bogdanm | 0:9b334a45a8ff | 80 | |(__STM32F0xx_HAL_VERSION_SUB1 << 16)\ |
bogdanm | 0:9b334a45a8ff | 81 | |(__STM32F0xx_HAL_VERSION_SUB2 << 8 )\ |
bogdanm | 0:9b334a45a8ff | 82 | |(__STM32F0xx_HAL_VERSION_RC)) |
bogdanm | 0:9b334a45a8ff | 83 | |
bogdanm | 0:9b334a45a8ff | 84 | #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF) |
bogdanm | 0:9b334a45a8ff | 85 | /** |
bogdanm | 0:9b334a45a8ff | 86 | * @} |
bogdanm | 0:9b334a45a8ff | 87 | */ |
bogdanm | 0:9b334a45a8ff | 88 | |
bogdanm | 0:9b334a45a8ff | 89 | /* Private macro -------------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 90 | /** @defgroup HAL_Private_Macros HAL Private Macros |
bogdanm | 0:9b334a45a8ff | 91 | * @{ |
bogdanm | 0:9b334a45a8ff | 92 | */ |
bogdanm | 0:9b334a45a8ff | 93 | /** |
bogdanm | 0:9b334a45a8ff | 94 | * @} |
bogdanm | 0:9b334a45a8ff | 95 | */ |
bogdanm | 0:9b334a45a8ff | 96 | |
bogdanm | 0:9b334a45a8ff | 97 | /* Private variables ---------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 98 | /** @defgroup HAL_Private_Variables HAL Private Variables |
bogdanm | 0:9b334a45a8ff | 99 | * @{ |
bogdanm | 0:9b334a45a8ff | 100 | */ |
bogdanm | 0:9b334a45a8ff | 101 | static __IO uint32_t uwTick; |
bogdanm | 0:9b334a45a8ff | 102 | /** |
bogdanm | 0:9b334a45a8ff | 103 | * @} |
bogdanm | 0:9b334a45a8ff | 104 | */ |
bogdanm | 0:9b334a45a8ff | 105 | /* Private function prototypes -----------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 106 | /* Exported functions ---------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 107 | |
bogdanm | 0:9b334a45a8ff | 108 | /** @defgroup HAL_Exported_Functions HAL Exported Functions |
bogdanm | 0:9b334a45a8ff | 109 | * @{ |
bogdanm | 0:9b334a45a8ff | 110 | */ |
bogdanm | 0:9b334a45a8ff | 111 | |
bogdanm | 0:9b334a45a8ff | 112 | /** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions |
bogdanm | 0:9b334a45a8ff | 113 | * @brief Initialization and de-initialization functions |
bogdanm | 0:9b334a45a8ff | 114 | * |
bogdanm | 0:9b334a45a8ff | 115 | @verbatim |
bogdanm | 0:9b334a45a8ff | 116 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 117 | ##### Initialization and de-initialization functions ##### |
bogdanm | 0:9b334a45a8ff | 118 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 119 | [..] This section provides functions allowing to: |
bogdanm | 0:9b334a45a8ff | 120 | (+) Initializes the Flash interface, the NVIC allocation and initial clock |
bogdanm | 0:9b334a45a8ff | 121 | configuration. It initializes the source of time base also when timeout |
bogdanm | 0:9b334a45a8ff | 122 | is needed and the backup domain when enabled. |
bogdanm | 0:9b334a45a8ff | 123 | (+) de-Initializes common part of the HAL. |
bogdanm | 0:9b334a45a8ff | 124 | (+) Configure The time base source to have 1ms time base with a dedicated |
bogdanm | 0:9b334a45a8ff | 125 | Tick interrupt priority. |
bogdanm | 0:9b334a45a8ff | 126 | (++) Systick timer is used by default as source of time base, but user |
bogdanm | 0:9b334a45a8ff | 127 | can eventually implement his proper time base source (a general purpose |
bogdanm | 0:9b334a45a8ff | 128 | timer for example or other time source), keeping in mind that Time base |
bogdanm | 0:9b334a45a8ff | 129 | duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and |
bogdanm | 0:9b334a45a8ff | 130 | handled in milliseconds basis. |
bogdanm | 0:9b334a45a8ff | 131 | (++) Time base configuration function (HAL_InitTick ()) is called automatically |
bogdanm | 0:9b334a45a8ff | 132 | at the beginning of the program after reset by HAL_Init() or at any time |
bogdanm | 0:9b334a45a8ff | 133 | when clock is configured, by HAL_RCC_ClockConfig(). |
bogdanm | 0:9b334a45a8ff | 134 | (++) Source of time base is configured to generate interrupts at regular |
bogdanm | 0:9b334a45a8ff | 135 | time intervals. Care must be taken if HAL_Delay() is called from a |
bogdanm | 0:9b334a45a8ff | 136 | peripheral ISR process, the Tick interrupt line must have higher priority |
bogdanm | 0:9b334a45a8ff | 137 | (numerically lower) than the peripheral interrupt. Otherwise the caller |
bogdanm | 0:9b334a45a8ff | 138 | ISR process will be blocked. |
bogdanm | 0:9b334a45a8ff | 139 | (++) functions affecting time base configurations are declared as __Weak |
bogdanm | 0:9b334a45a8ff | 140 | to make override possible in case of other implementations in user file. |
bogdanm | 0:9b334a45a8ff | 141 | |
bogdanm | 0:9b334a45a8ff | 142 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 143 | * @{ |
bogdanm | 0:9b334a45a8ff | 144 | */ |
bogdanm | 0:9b334a45a8ff | 145 | |
bogdanm | 0:9b334a45a8ff | 146 | /** |
bogdanm | 0:9b334a45a8ff | 147 | * @brief This function configures the Flash prefetch, |
bogdanm | 0:9b334a45a8ff | 148 | * Configures time base source, NVIC and Low level hardware |
bogdanm | 0:9b334a45a8ff | 149 | * @note This function is called at the beginning of program after reset and before |
bogdanm | 0:9b334a45a8ff | 150 | * the clock configuration |
bogdanm | 0:9b334a45a8ff | 151 | * @note The time base configuration is based on HSI clock when exiting from Reset. |
bogdanm | 0:9b334a45a8ff | 152 | * Once done, time base tick start incrementing. |
bogdanm | 0:9b334a45a8ff | 153 | * In the default implementation,Systick is used as source of time base. |
bogdanm | 0:9b334a45a8ff | 154 | * The tick variable is incremented each 1ms in its ISR. |
bogdanm | 0:9b334a45a8ff | 155 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 156 | */ |
bogdanm | 0:9b334a45a8ff | 157 | HAL_StatusTypeDef HAL_Init(void) |
bogdanm | 0:9b334a45a8ff | 158 | { |
bogdanm | 0:9b334a45a8ff | 159 | /* Configure Flash prefetch */ |
bogdanm | 0:9b334a45a8ff | 160 | #if (PREFETCH_ENABLE != 0) |
bogdanm | 0:9b334a45a8ff | 161 | __HAL_FLASH_PREFETCH_BUFFER_ENABLE(); |
bogdanm | 0:9b334a45a8ff | 162 | #endif /* PREFETCH_ENABLE */ |
bogdanm | 0:9b334a45a8ff | 163 | |
bogdanm | 0:9b334a45a8ff | 164 | /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */ |
bogdanm | 0:9b334a45a8ff | 165 | |
bogdanm | 0:9b334a45a8ff | 166 | HAL_InitTick(TICK_INT_PRIORITY); |
bogdanm | 0:9b334a45a8ff | 167 | |
bogdanm | 0:9b334a45a8ff | 168 | /* Init the low level hardware */ |
bogdanm | 0:9b334a45a8ff | 169 | HAL_MspInit(); |
bogdanm | 0:9b334a45a8ff | 170 | |
bogdanm | 0:9b334a45a8ff | 171 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 172 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 173 | } |
bogdanm | 0:9b334a45a8ff | 174 | |
bogdanm | 0:9b334a45a8ff | 175 | /** |
bogdanm | 0:9b334a45a8ff | 176 | * @brief This function de-Initializes common part of the HAL and stops the source |
bogdanm | 0:9b334a45a8ff | 177 | * of time base. |
bogdanm | 0:9b334a45a8ff | 178 | * @note This function is optional. |
bogdanm | 0:9b334a45a8ff | 179 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 180 | */ |
bogdanm | 0:9b334a45a8ff | 181 | HAL_StatusTypeDef HAL_DeInit(void) |
bogdanm | 0:9b334a45a8ff | 182 | { |
bogdanm | 0:9b334a45a8ff | 183 | /* Reset of all peripherals */ |
bogdanm | 0:9b334a45a8ff | 184 | __HAL_RCC_APB1_FORCE_RESET(); |
bogdanm | 0:9b334a45a8ff | 185 | __HAL_RCC_APB1_RELEASE_RESET(); |
bogdanm | 0:9b334a45a8ff | 186 | |
bogdanm | 0:9b334a45a8ff | 187 | __HAL_RCC_APB2_FORCE_RESET(); |
bogdanm | 0:9b334a45a8ff | 188 | __HAL_RCC_APB2_RELEASE_RESET(); |
bogdanm | 0:9b334a45a8ff | 189 | |
bogdanm | 0:9b334a45a8ff | 190 | __HAL_RCC_AHB_FORCE_RESET(); |
bogdanm | 0:9b334a45a8ff | 191 | __HAL_RCC_AHB_RELEASE_RESET(); |
bogdanm | 0:9b334a45a8ff | 192 | |
bogdanm | 0:9b334a45a8ff | 193 | /* De-Init the low level hardware */ |
bogdanm | 0:9b334a45a8ff | 194 | HAL_MspDeInit(); |
bogdanm | 0:9b334a45a8ff | 195 | |
bogdanm | 0:9b334a45a8ff | 196 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 197 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 198 | } |
bogdanm | 0:9b334a45a8ff | 199 | |
bogdanm | 0:9b334a45a8ff | 200 | /** |
bogdanm | 0:9b334a45a8ff | 201 | * @brief Initializes the MSP. |
bogdanm | 0:9b334a45a8ff | 202 | * @retval None |
bogdanm | 0:9b334a45a8ff | 203 | */ |
bogdanm | 0:9b334a45a8ff | 204 | __weak void HAL_MspInit(void) |
bogdanm | 0:9b334a45a8ff | 205 | { |
bogdanm | 0:9b334a45a8ff | 206 | /* NOTE : This function Should not be modified, when the callback is needed, |
bogdanm | 0:9b334a45a8ff | 207 | the HAL_MspInit could be implemented in the user file |
bogdanm | 0:9b334a45a8ff | 208 | */ |
bogdanm | 0:9b334a45a8ff | 209 | } |
bogdanm | 0:9b334a45a8ff | 210 | |
bogdanm | 0:9b334a45a8ff | 211 | /** |
bogdanm | 0:9b334a45a8ff | 212 | * @brief DeInitializes the MSP. |
bogdanm | 0:9b334a45a8ff | 213 | * @retval None |
bogdanm | 0:9b334a45a8ff | 214 | */ |
bogdanm | 0:9b334a45a8ff | 215 | __weak void HAL_MspDeInit(void) |
bogdanm | 0:9b334a45a8ff | 216 | { |
bogdanm | 0:9b334a45a8ff | 217 | /* NOTE : This function Should not be modified, when the callback is needed, |
bogdanm | 0:9b334a45a8ff | 218 | the HAL_MspDeInit could be implemented in the user file |
bogdanm | 0:9b334a45a8ff | 219 | */ |
bogdanm | 0:9b334a45a8ff | 220 | } |
bogdanm | 0:9b334a45a8ff | 221 | |
bogdanm | 0:9b334a45a8ff | 222 | /** |
bogdanm | 0:9b334a45a8ff | 223 | * @brief This function configures the source of the time base. |
bogdanm | 0:9b334a45a8ff | 224 | * The time source is configured to have 1ms time base with a dedicated |
bogdanm | 0:9b334a45a8ff | 225 | * Tick interrupt priority. |
bogdanm | 0:9b334a45a8ff | 226 | * @note This function is called automatically at the beginning of program after |
bogdanm | 0:9b334a45a8ff | 227 | * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig(). |
bogdanm | 0:9b334a45a8ff | 228 | * @note In the default implementation, SysTick timer is the source of time base. |
bogdanm | 0:9b334a45a8ff | 229 | * It is used to generate interrupts at regular time intervals. |
bogdanm | 0:9b334a45a8ff | 230 | * Care must be taken if HAL_Delay() is called from a peripheral ISR process, |
bogdanm | 0:9b334a45a8ff | 231 | * The the SysTick interrupt must have higher priority (numerically lower) |
bogdanm | 0:9b334a45a8ff | 232 | * than the peripheral interrupt. Otherwise the caller ISR process will be blocked. |
bogdanm | 0:9b334a45a8ff | 233 | * The function is declared as __Weak to be overwritten in case of other |
bogdanm | 0:9b334a45a8ff | 234 | * implementation in user file. |
bogdanm | 0:9b334a45a8ff | 235 | * @param TickPriority: Tick interrupt priority. |
bogdanm | 0:9b334a45a8ff | 236 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 237 | */ |
bogdanm | 0:9b334a45a8ff | 238 | __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) |
bogdanm | 0:9b334a45a8ff | 239 | { |
bogdanm | 0:9b334a45a8ff | 240 | /*Configure the SysTick to have interrupt in 1ms time basis*/ |
bogdanm | 0:9b334a45a8ff | 241 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
bogdanm | 0:9b334a45a8ff | 242 | |
bogdanm | 0:9b334a45a8ff | 243 | /*Configure the SysTick IRQ priority */ |
bogdanm | 0:9b334a45a8ff | 244 | HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0); |
bogdanm | 0:9b334a45a8ff | 245 | |
bogdanm | 0:9b334a45a8ff | 246 | /* Return function status */ |
bogdanm | 0:9b334a45a8ff | 247 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 248 | } |
bogdanm | 0:9b334a45a8ff | 249 | |
bogdanm | 0:9b334a45a8ff | 250 | /** |
bogdanm | 0:9b334a45a8ff | 251 | * @} |
bogdanm | 0:9b334a45a8ff | 252 | */ |
bogdanm | 0:9b334a45a8ff | 253 | |
bogdanm | 0:9b334a45a8ff | 254 | /** @defgroup HAL_Exported_Functions_Group2 HAL Control functions |
bogdanm | 0:9b334a45a8ff | 255 | * @brief HAL Control functions |
bogdanm | 0:9b334a45a8ff | 256 | * |
bogdanm | 0:9b334a45a8ff | 257 | @verbatim |
bogdanm | 0:9b334a45a8ff | 258 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 259 | ##### HAL Control functions ##### |
bogdanm | 0:9b334a45a8ff | 260 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 261 | [..] This section provides functions allowing to: |
bogdanm | 0:9b334a45a8ff | 262 | (+) Provide a tick value in millisecond |
bogdanm | 0:9b334a45a8ff | 263 | (+) Provide a blocking delay in millisecond |
bogdanm | 0:9b334a45a8ff | 264 | (+) Suspend the time base source interrupt |
bogdanm | 0:9b334a45a8ff | 265 | (+) Resume the time base source interrupt |
bogdanm | 0:9b334a45a8ff | 266 | (+) Get the HAL API driver version |
bogdanm | 0:9b334a45a8ff | 267 | (+) Get the device identifier |
bogdanm | 0:9b334a45a8ff | 268 | (+) Get the device revision identifier |
bogdanm | 0:9b334a45a8ff | 269 | (+) Enable/Disable Debug module during Sleep mode |
bogdanm | 0:9b334a45a8ff | 270 | (+) Enable/Disable Debug module during STOP mode |
bogdanm | 0:9b334a45a8ff | 271 | (+) Enable/Disable Debug module during STANDBY mode |
bogdanm | 0:9b334a45a8ff | 272 | |
bogdanm | 0:9b334a45a8ff | 273 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 274 | * @{ |
bogdanm | 0:9b334a45a8ff | 275 | */ |
bogdanm | 0:9b334a45a8ff | 276 | |
bogdanm | 0:9b334a45a8ff | 277 | /** |
bogdanm | 0:9b334a45a8ff | 278 | * @brief This function is called to increment a global variable "uwTick" |
bogdanm | 0:9b334a45a8ff | 279 | * used as application time base. |
bogdanm | 0:9b334a45a8ff | 280 | * @note In the default implementation, this variable is incremented each 1ms |
bogdanm | 0:9b334a45a8ff | 281 | * in Systick ISR. |
bogdanm | 0:9b334a45a8ff | 282 | * @note This function is declared as __weak to be overwritten in case of other |
bogdanm | 0:9b334a45a8ff | 283 | * implementations in user file. |
bogdanm | 0:9b334a45a8ff | 284 | * @retval None |
bogdanm | 0:9b334a45a8ff | 285 | */ |
bogdanm | 0:9b334a45a8ff | 286 | __weak void HAL_IncTick(void) |
bogdanm | 0:9b334a45a8ff | 287 | { |
bogdanm | 0:9b334a45a8ff | 288 | uwTick++; |
bogdanm | 0:9b334a45a8ff | 289 | } |
bogdanm | 0:9b334a45a8ff | 290 | |
bogdanm | 0:9b334a45a8ff | 291 | /** |
bogdanm | 0:9b334a45a8ff | 292 | * @brief Provides a tick value in millisecond. |
bogdanm | 0:9b334a45a8ff | 293 | * @note This function is declared as __weak to be overwritten in case of other |
bogdanm | 0:9b334a45a8ff | 294 | * implementations in user file. |
bogdanm | 0:9b334a45a8ff | 295 | * @retval tick value |
bogdanm | 0:9b334a45a8ff | 296 | */ |
bogdanm | 0:9b334a45a8ff | 297 | __weak uint32_t HAL_GetTick(void) |
bogdanm | 0:9b334a45a8ff | 298 | { |
bogdanm | 0:9b334a45a8ff | 299 | return uwTick; |
bogdanm | 0:9b334a45a8ff | 300 | } |
bogdanm | 0:9b334a45a8ff | 301 | |
bogdanm | 0:9b334a45a8ff | 302 | /** |
bogdanm | 0:9b334a45a8ff | 303 | * @brief This function provides accurate delay (in milliseconds) based |
bogdanm | 0:9b334a45a8ff | 304 | * on variable incremented. |
bogdanm | 0:9b334a45a8ff | 305 | * @note In the default implementation , SysTick timer is the source of time base. |
bogdanm | 0:9b334a45a8ff | 306 | * It is used to generate interrupts at regular time intervals where uwTick |
bogdanm | 0:9b334a45a8ff | 307 | * is incremented. |
bogdanm | 0:9b334a45a8ff | 308 | * @note ThiS function is declared as __weak to be overwritten in case of other |
bogdanm | 0:9b334a45a8ff | 309 | * implementations in user file. |
bogdanm | 0:9b334a45a8ff | 310 | * @param Delay: specifies the delay time length, in milliseconds. |
bogdanm | 0:9b334a45a8ff | 311 | * @retval None |
bogdanm | 0:9b334a45a8ff | 312 | */ |
bogdanm | 0:9b334a45a8ff | 313 | __weak void HAL_Delay(__IO uint32_t Delay) |
bogdanm | 0:9b334a45a8ff | 314 | { |
bogdanm | 0:9b334a45a8ff | 315 | uint32_t tickstart = 0; |
bogdanm | 0:9b334a45a8ff | 316 | tickstart = HAL_GetTick(); |
bogdanm | 0:9b334a45a8ff | 317 | while((HAL_GetTick() - tickstart) < Delay) |
bogdanm | 0:9b334a45a8ff | 318 | { |
bogdanm | 0:9b334a45a8ff | 319 | } |
bogdanm | 0:9b334a45a8ff | 320 | } |
bogdanm | 0:9b334a45a8ff | 321 | |
bogdanm | 0:9b334a45a8ff | 322 | /** |
bogdanm | 0:9b334a45a8ff | 323 | * @brief Suspend Tick increment. |
bogdanm | 0:9b334a45a8ff | 324 | * @note In the default implementation , SysTick timer is the source of time base. It is |
bogdanm | 0:9b334a45a8ff | 325 | * used to generate interrupts at regular time intervals. Once HAL_SuspendTick() |
bogdanm | 0:9b334a45a8ff | 326 | * is called, the the SysTick interrupt will be disabled and so Tick increment |
bogdanm | 0:9b334a45a8ff | 327 | * is suspended. |
bogdanm | 0:9b334a45a8ff | 328 | * @note This function is declared as __weak to be overwritten in case of other |
bogdanm | 0:9b334a45a8ff | 329 | * implementations in user file. |
bogdanm | 0:9b334a45a8ff | 330 | * @retval None |
bogdanm | 0:9b334a45a8ff | 331 | */ |
bogdanm | 0:9b334a45a8ff | 332 | __weak void HAL_SuspendTick(void) |
bogdanm | 0:9b334a45a8ff | 333 | |
bogdanm | 0:9b334a45a8ff | 334 | { |
bogdanm | 0:9b334a45a8ff | 335 | /* Disable SysTick Interrupt */ |
bogdanm | 0:9b334a45a8ff | 336 | CLEAR_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk); |
bogdanm | 0:9b334a45a8ff | 337 | } |
bogdanm | 0:9b334a45a8ff | 338 | |
bogdanm | 0:9b334a45a8ff | 339 | /** |
bogdanm | 0:9b334a45a8ff | 340 | * @brief Resume Tick increment. |
bogdanm | 0:9b334a45a8ff | 341 | * @note In the default implementation , SysTick timer is the source of time base. It is |
bogdanm | 0:9b334a45a8ff | 342 | * used to generate interrupts at regular time intervals. Once HAL_ResumeTick() |
bogdanm | 0:9b334a45a8ff | 343 | * is called, the the SysTick interrupt will be enabled and so Tick increment |
bogdanm | 0:9b334a45a8ff | 344 | * is resumed. |
bogdanm | 0:9b334a45a8ff | 345 | * @note This function is declared as __weak to be overwritten in case of other |
bogdanm | 0:9b334a45a8ff | 346 | * implementations in user file. |
bogdanm | 0:9b334a45a8ff | 347 | * @retval None |
bogdanm | 0:9b334a45a8ff | 348 | */ |
bogdanm | 0:9b334a45a8ff | 349 | __weak void HAL_ResumeTick(void) |
bogdanm | 0:9b334a45a8ff | 350 | { |
bogdanm | 0:9b334a45a8ff | 351 | /* Enable SysTick Interrupt */ |
bogdanm | 0:9b334a45a8ff | 352 | SET_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk); |
bogdanm | 0:9b334a45a8ff | 353 | } |
bogdanm | 0:9b334a45a8ff | 354 | |
bogdanm | 0:9b334a45a8ff | 355 | /** |
bogdanm | 0:9b334a45a8ff | 356 | * @brief This method returns the HAL revision |
bogdanm | 0:9b334a45a8ff | 357 | * @retval version : 0xXYZR (8bits for each decimal, R for RC) |
bogdanm | 0:9b334a45a8ff | 358 | */ |
bogdanm | 0:9b334a45a8ff | 359 | uint32_t HAL_GetHalVersion(void) |
bogdanm | 0:9b334a45a8ff | 360 | { |
bogdanm | 0:9b334a45a8ff | 361 | return __STM32F0xx_HAL_VERSION; |
bogdanm | 0:9b334a45a8ff | 362 | } |
bogdanm | 0:9b334a45a8ff | 363 | |
bogdanm | 0:9b334a45a8ff | 364 | /** |
bogdanm | 0:9b334a45a8ff | 365 | * @brief Returns the device revision identifier. |
bogdanm | 0:9b334a45a8ff | 366 | * @retval Device revision identifier |
bogdanm | 0:9b334a45a8ff | 367 | */ |
bogdanm | 0:9b334a45a8ff | 368 | uint32_t HAL_GetREVID(void) |
bogdanm | 0:9b334a45a8ff | 369 | { |
bogdanm | 0:9b334a45a8ff | 370 | return((DBGMCU->IDCODE) >> 16); |
bogdanm | 0:9b334a45a8ff | 371 | } |
bogdanm | 0:9b334a45a8ff | 372 | |
bogdanm | 0:9b334a45a8ff | 373 | /** |
bogdanm | 0:9b334a45a8ff | 374 | * @brief Returns the device identifier. |
bogdanm | 0:9b334a45a8ff | 375 | * @retval Device identifier |
bogdanm | 0:9b334a45a8ff | 376 | */ |
bogdanm | 0:9b334a45a8ff | 377 | uint32_t HAL_GetDEVID(void) |
bogdanm | 0:9b334a45a8ff | 378 | { |
bogdanm | 0:9b334a45a8ff | 379 | return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK); |
bogdanm | 0:9b334a45a8ff | 380 | } |
bogdanm | 0:9b334a45a8ff | 381 | |
bogdanm | 0:9b334a45a8ff | 382 | /** |
bogdanm | 0:9b334a45a8ff | 383 | * @brief Enable the Debug Module during STOP mode |
bogdanm | 0:9b334a45a8ff | 384 | * @retval None |
bogdanm | 0:9b334a45a8ff | 385 | */ |
bogdanm | 0:9b334a45a8ff | 386 | void HAL_DBGMCU_EnableDBGStopMode(void) |
bogdanm | 0:9b334a45a8ff | 387 | { |
bogdanm | 0:9b334a45a8ff | 388 | SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); |
bogdanm | 0:9b334a45a8ff | 389 | } |
bogdanm | 0:9b334a45a8ff | 390 | |
bogdanm | 0:9b334a45a8ff | 391 | /** |
bogdanm | 0:9b334a45a8ff | 392 | * @brief Disable the Debug Module during STOP mode |
bogdanm | 0:9b334a45a8ff | 393 | * @retval None |
bogdanm | 0:9b334a45a8ff | 394 | */ |
bogdanm | 0:9b334a45a8ff | 395 | void HAL_DBGMCU_DisableDBGStopMode(void) |
bogdanm | 0:9b334a45a8ff | 396 | { |
bogdanm | 0:9b334a45a8ff | 397 | CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); |
bogdanm | 0:9b334a45a8ff | 398 | } |
bogdanm | 0:9b334a45a8ff | 399 | |
bogdanm | 0:9b334a45a8ff | 400 | /** |
bogdanm | 0:9b334a45a8ff | 401 | * @brief Enable the Debug Module during STANDBY mode |
bogdanm | 0:9b334a45a8ff | 402 | * @retval None |
bogdanm | 0:9b334a45a8ff | 403 | */ |
bogdanm | 0:9b334a45a8ff | 404 | void HAL_DBGMCU_EnableDBGStandbyMode(void) |
bogdanm | 0:9b334a45a8ff | 405 | { |
bogdanm | 0:9b334a45a8ff | 406 | SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); |
bogdanm | 0:9b334a45a8ff | 407 | } |
bogdanm | 0:9b334a45a8ff | 408 | |
bogdanm | 0:9b334a45a8ff | 409 | /** |
bogdanm | 0:9b334a45a8ff | 410 | * @brief Disable the Debug Module during STANDBY mode |
bogdanm | 0:9b334a45a8ff | 411 | * @retval None |
bogdanm | 0:9b334a45a8ff | 412 | */ |
bogdanm | 0:9b334a45a8ff | 413 | void HAL_DBGMCU_DisableDBGStandbyMode(void) |
bogdanm | 0:9b334a45a8ff | 414 | { |
bogdanm | 0:9b334a45a8ff | 415 | CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); |
bogdanm | 0:9b334a45a8ff | 416 | } |
bogdanm | 0:9b334a45a8ff | 417 | |
bogdanm | 0:9b334a45a8ff | 418 | /** |
bogdanm | 0:9b334a45a8ff | 419 | * @} |
bogdanm | 0:9b334a45a8ff | 420 | */ |
bogdanm | 0:9b334a45a8ff | 421 | |
bogdanm | 0:9b334a45a8ff | 422 | /** |
bogdanm | 0:9b334a45a8ff | 423 | * @} |
bogdanm | 0:9b334a45a8ff | 424 | */ |
bogdanm | 0:9b334a45a8ff | 425 | |
bogdanm | 0:9b334a45a8ff | 426 | #endif /* HAL_MODULE_ENABLED */ |
bogdanm | 0:9b334a45a8ff | 427 | /** |
bogdanm | 0:9b334a45a8ff | 428 | * @} |
bogdanm | 0:9b334a45a8ff | 429 | */ |
bogdanm | 0:9b334a45a8ff | 430 | |
bogdanm | 0:9b334a45a8ff | 431 | /** |
bogdanm | 0:9b334a45a8ff | 432 | * @} |
bogdanm | 0:9b334a45a8ff | 433 | */ |
bogdanm | 0:9b334a45a8ff | 434 | |
bogdanm | 0:9b334a45a8ff | 435 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |