Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2 | Rev 9 | ||
|---|---|---|---|
| Line 10... | Line 10... | ||
| 10 | * + HAL_IncTick is called inside HAL_TIM_PeriodElapsedCallback ie each 1ms |
10 | * + HAL_IncTick is called inside HAL_TIM_PeriodElapsedCallback ie each 1ms |
| 11 | * |
11 | * |
| 12 | ****************************************************************************** |
12 | ****************************************************************************** |
| 13 | * @attention |
13 | * @attention |
| 14 | * |
14 | * |
| 15 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
15 | * <h2><center>© Copyright (c) 2017 STMicroelectronics. |
| - | 16 | * All rights reserved.</center></h2> |
|
| 16 | * |
17 | * |
| 17 | * Redistribution and use in source and binary forms, with or without modification, |
18 | * This software component is licensed by ST under BSD 3-Clause license, |
| 18 | * are permitted provided that the following conditions are met: |
19 | * the "License"; You may not use this file except in compliance with the |
| 19 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
| 20 | * this list of conditions and the following disclaimer. |
- | |
| 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
| 22 | * this list of conditions and the following disclaimer in the documentation |
- | |
| 23 | * and/or other materials provided with the distribution. |
20 | * License. You may obtain a copy of the License at: |
| 24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
- | |
| 25 | * may be used to endorse or promote products derived from this software |
21 | * opensource.org/licenses/BSD-3-Clause |
| 26 | * without specific prior written permission. |
- | |
| 27 | * |
- | |
| 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
- | |
| 29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- | |
| 30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
- | |
| 31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
- | |
| 32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
| 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
- | |
| 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
- | |
| 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
- | |
| 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- | |
| 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
- | |
| 38 | * |
22 | * |
| 39 | ****************************************************************************** |
23 | ****************************************************************************** |
| 40 | */ |
24 | */ |
| 41 | 25 | ||
| 42 | /* Includes ------------------------------------------------------------------*/ |
26 | /* Includes ------------------------------------------------------------------*/ |
| Line 63... | Line 47... | ||
| 63 | * @brief This function configures the TIM2 as a time base source. |
47 | * @brief This function configures the TIM2 as a time base source. |
| 64 | * The time source is configured to have 1ms time base with a dedicated |
48 | * The time source is configured to have 1ms time base with a dedicated |
| 65 | * Tick interrupt priority. |
49 | * Tick interrupt priority. |
| 66 | * @note This function is called automatically at the beginning of program after |
50 | * @note This function is called automatically at the beginning of program after |
| 67 | * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). |
51 | * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). |
| 68 | * @param TickPriority: Tick interrupt priority. |
52 | * @param TickPriority Tick interrupt priority. |
| 69 | * @retval HAL status |
53 | * @retval HAL status |
| 70 | */ |
54 | */ |
| 71 | HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) |
55 | HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) |
| 72 | { |
56 | { |
| 73 | RCC_ClkInitTypeDef clkconfig; |
57 | RCC_ClkInitTypeDef clkconfig; |
| 74 | uint32_t uwTimclock, uwAPB1Prescaler = 0U; |
58 | uint32_t uwTimclock, uwAPB1Prescaler = 0U; |
| 75 | uint32_t uwPrescalerValue = 0U; |
59 | uint32_t uwPrescalerValue = 0U; |
| 76 | uint32_t pFLatency; |
60 | uint32_t pFLatency; |
| - | 61 | HAL_StatusTypeDef status = HAL_OK; |
|
| 77 | 62 | ||
| 78 | /*Configure the TIM2 IRQ priority */ |
- | |
| 79 | HAL_NVIC_SetPriority(TIM2_IRQn, TickPriority, 0U); |
- | |
| 80 | - | ||
| 81 | /* Enable the TIM2 global Interrupt */ |
- | |
| 82 | HAL_NVIC_EnableIRQ(TIM2_IRQn); |
- | |
| 83 | 63 | ||
| 84 | /* Enable TIM2 clock */ |
64 | /* Enable TIM2 clock */ |
| 85 | __HAL_RCC_TIM2_CLK_ENABLE(); |
65 | __HAL_RCC_TIM2_CLK_ENABLE(); |
| 86 | 66 | ||
| 87 | /* Get clock configuration */ |
67 | /* Get clock configuration */ |
| Line 115... | Line 95... | ||
| 115 | TimHandle.Init.Period = (1000000U / 1000U) - 1U; |
95 | TimHandle.Init.Period = (1000000U / 1000U) - 1U; |
| 116 | TimHandle.Init.Prescaler = uwPrescalerValue; |
96 | TimHandle.Init.Prescaler = uwPrescalerValue; |
| 117 | TimHandle.Init.ClockDivision = 0U; |
97 | TimHandle.Init.ClockDivision = 0U; |
| 118 | TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; |
98 | TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; |
| 119 | TimHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
99 | TimHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
| 120 | if (HAL_TIM_Base_Init(&TimHandle) == HAL_OK) |
100 | status = HAL_TIM_Base_Init(&TimHandle); |
| - | 101 | if (status == HAL_OK) |
|
| 121 | { |
102 | { |
| 122 | /* Start the TIM time Base generation in interrupt mode */ |
103 | /* Start the TIM time Base generation in interrupt mode */ |
| 123 | return HAL_TIM_Base_Start_IT(&TimHandle); |
104 | status = HAL_TIM_Base_Start_IT(&TimHandle); |
| - | 105 | if (status == HAL_OK) |
|
| - | 106 | { |
|
| - | 107 | /* Enable the TIM2 global Interrupt */ |
|
| - | 108 | HAL_NVIC_EnableIRQ(TIM2_IRQn); |
|
| - | 109 | ||
| - | 110 | if (TickPriority < (1UL << __NVIC_PRIO_BITS)) |
|
| - | 111 | { |
|
| - | 112 | /*Configure the TIM2 IRQ priority */ |
|
| - | 113 | HAL_NVIC_SetPriority(TIM2_IRQn, TickPriority ,0); |
|
| - | 114 | uwTickPrio = TickPriority; |
|
| - | 115 | } |
|
| - | 116 | else |
|
| - | 117 | { |
|
| - | 118 | status = HAL_ERROR; |
|
| - | 119 | } |
|
| - | 120 | } |
|
| 124 | } |
121 | } |
| 125 | 122 | ||
| 126 | /* Return function status */ |
123 | /* Return function status */ |
| 127 | return HAL_ERROR; |
124 | return status; |
| 128 | } |
125 | } |
| 129 | 126 | ||
| 130 | /** |
127 | /** |
| 131 | * @brief Suspend Tick increment. |
128 | * @brief Suspend Tick increment. |
| 132 | * @note Disable the tick increment by disabling TIM2 update interrupt. |
129 | * @note Disable the tick increment by disabling TIM2 update interrupt. |
| Line 152... | Line 149... | ||
| 152 | /** |
149 | /** |
| 153 | * @brief Period elapsed callback in non blocking mode |
150 | * @brief Period elapsed callback in non blocking mode |
| 154 | * @note This function is called when TIM2 interrupt took place, inside |
151 | * @note This function is called when TIM2 interrupt took place, inside |
| 155 | * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment |
152 | * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment |
| 156 | * a global variable "uwTick" used as application time base. |
153 | * a global variable "uwTick" used as application time base. |
| 157 | * @param htim : TIM handle |
154 | * @param htim TIM handle |
| 158 | * @retval None |
155 | * @retval None |
| 159 | */ |
156 | */ |
| 160 | void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
157 | void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
| 161 | { |
158 | { |
| 162 | HAL_IncTick(); |
159 | HAL_IncTick(); |