]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L0/stm32l0xx_hal_tim_ex.c
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32L0 / stm32l0xx_hal_tim_ex.c
1 /**
2 ******************************************************************************
3 * @file stm32l0xx_hal_tim_ex.c
4 * @author MCD Application Team
5 * @version V1.2.0
6 * @date 06-February-2015
7 * @brief TIM HAL module driver.
8 * @brief This file provides firmware functions to manage the following
9 * functionalities of the Timer (TIM) peripheral:
10 * + Time Hall Sensor Interface Initialization
11 * + Time Hall Sensor Interface Start
12 * + Time Master and Slave synchronization configuration
13 @verbatim
14 ================================================================================
15 ##### TIM specific features integration #####
16 ================================================================================
17
18 [..] The Timer features include:
19 (#) 16-bit up, down, up/down auto-reload counter.
20 (#) 16-bit programmable prescaler allowing dividing (also on the fly) the counter clock
21 frequency either by any factor between 1 and 65536.
22 (#) Up to 4 independent channels for:
23 Input Capture
24 Output Compare
25 PWM generation (Edge and Center-aligned Mode)
26 One-pulse mode output
27 (#) Synchronization circuit to control the timer with external signals and to interconnect
28 several timers together.
29 (#) Supports incremental (quadrature) encoder and hall-sensor circuitry for positioning
30 purposes
31
32 ##### How to use this driver #####
33 ================================================================================
34 [..]
35 (#) Enable the TIM interface clock using
36 __HAL_RCC_TIMx_CLK_ENABLE();
37
38 (#) TIM pins configuration
39 (++) Enable the clock for the TIM GPIOs using the following function:
40 __HAL_RCC_GPIOx_CLK_ENABLE();
41 (++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
42
43 (#) The external Clock can be configured, if needed (the default clock is the internal clock from the APBx),
44 using the following function:
45 HAL_TIM_ConfigClockSource, the clock configuration should be done before any start function.
46
47 (#) Configure the TIM in the desired operating mode using one of the
48 configuration function of this driver:
49 (++) HAL_TIMEx_MasterConfigSynchronization() to configure the peripheral in master mode.
50
51 (#) Remap the Timer I/O using HAL_TIMEx_RemapConfig() API.
52
53
54 @endverbatim
55 ******************************************************************************
56 * @attention
57 *
58 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
59 *
60 * Redistribution and use in source and binary forms, with or without modification,
61 * are permitted provided that the following conditions are met:
62 * 1. Redistributions of source code must retain the above copyright notice,
63 * this list of conditions and the following disclaimer.
64 * 2. Redistributions in binary form must reproduce the above copyright notice,
65 * this list of conditions and the following disclaimer in the documentation
66 * and/or other materials provided with the distribution.
67 * 3. Neither the name of STMicroelectronics nor the names of its contributors
68 * may be used to endorse or promote products derived from this software
69 * without specific prior written permission.
70 *
71 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
72 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
73 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
74 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
75 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
76 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
77 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
78 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
79 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
80 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
81 *
82 ******************************************************************************
83 */
84
85 /* Includes ------------------------------------------------------------------*/
86 #include "stm32l0xx_hal.h"
87
88 /** @addtogroup STM32L0xx_HAL_Driver
89 * @{
90 */
91
92 /** @addtogroup TIMEx
93 * @brief TIMEx HAL module driver
94 * @{
95 */
96
97 #ifdef HAL_TIM_MODULE_ENABLED
98
99
100 /** @addtogroup TIMEx_Exported_Functions
101 * @{
102 */
103
104
105 /** @addtogroup TIMEx_Exported_Functions_Group1
106 * @brief Peripheral Control functions
107 *
108 @verbatim
109 ===============================================================================
110 ##### Peripheral Control functions #####
111 ===============================================================================
112 [..] This section provides functions allowing to:
113 (+) Configure Master and the Slave synchronization.
114
115 @endverbatim
116 * @{
117 */
118
119 /**
120 * @brief Configures the TIM in master mode.
121 * @param htim: TIM handle.
122 * @param sMasterConfig: pointer to a TIM_MasterConfigTypeDef structure that
123 * contains the selected trigger output (TRGO) and the Master/Slave
124 * mode.
125 * @retval HAL status
126 */
127 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef * sMasterConfig)
128 {
129 /* Check the parameters */
130 assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance));
131 assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
132 assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode));
133
134 __HAL_LOCK(htim);
135
136 /* Change the handler state */
137 htim->State = HAL_TIM_STATE_BUSY;
138
139 /* Reset the MMS Bits */
140 htim->Instance->CR2 &= ~TIM_CR2_MMS;
141 /* Select the TRGO source */
142 htim->Instance->CR2 |= sMasterConfig->MasterOutputTrigger;
143
144 /* Reset the MSM Bit */
145 htim->Instance->SMCR &= ~TIM_SMCR_MSM;
146 /* Set or Reset the MSM Bit */
147 htim->Instance->SMCR |= sMasterConfig->MasterSlaveMode;
148
149 htim->State = HAL_TIM_STATE_READY;
150
151 __HAL_UNLOCK(htim);
152
153 return HAL_OK;
154 }
155
156
157 #if defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) \
158 || defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx)
159
160 /**
161 * @brief Configures the remapping of the TIM2, TIM3, TIM21 and TIM22 inputs.
162 * The channel inputs (T1..T4) and the Trigger input (ETR) of the
163 * timers can be remaped thanks to this function. When an input is
164 * mapped, on a GPIO, refer yourself to the GPIO alternate functions
165 * for more details.
166 * @note It is not possible to connect TIM2 and TIM21 on
167 * GPIOB5_AF4 at the same time.
168 * When selecting TIM3_TI2_GPIOB5_AF4, Channel2 of TIM3 will be
169 * connected to GPIOB5_AF4 and Channel2 of TIM22 will be connected to
170 * some other GPIOs. (refer to alternate functions for more details)
171 * When selecting TIM3_TI2_GPIO_DEF, Channel2 of Timer 3 will be
172 * connected an GPIO (other than GPIOB5_AF4) and Channel2 of TIM22
173 * will be connected to GPIOB5_AF4.
174 *
175 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
176 * the configuration information for TIM module.
177 * @param Remap: specifies the TIM input remapping source.
178 * This parameter is a combination of the following values
179 * depending on TIM instance:
180 *
181 * For TIM2, the parameter can have the following values:
182 * @arg TIM2_ETR_GPIO: TIM2 ETR connected to GPIO (default):
183 * GPIOA(0)_AF5 or GPIOA(5)_AF2 or
184 * GPIOA(15)_AF2 or GPIOE(9)_AF2
185 * @arg TIM2_ETR_HSI48: TIM2 ETR connected to HSI48
186 * @arg TIM2_ETR_LSE: TIM2 ETR connected to LSE
187 * @arg TIM2_ETR_COMP2_OUT: TIM2 ETR connected to COMP2 output
188 * @arg TIM2_ETR_COMP1_OUT: TIM2 ETR connected to COMP1 output
189 * @arg TIM2_TI4_GPIO : TIM2 TI4 connected to GPIO1(default):
190 * GPIOA(3)_AF2 or GPIOB(11)_AF2 or
191 * GPIOE(12)_AF0
192 * @arg TIM2_TI4_COMP1: TIM2 TI4 connected to COMP1
193 * @arg TIM2_TI4_COMP2: TIM2 TI4 connected to COMP2
194 *
195 * For TIM3, the parameter can have the following values:
196 * @arg TIM3_ETR_GPIO: TIM3 ETR connected to GPIO (default):
197 * GPIOE(2)_AF2 or GPIOD(2)_AF2 or
198 * GPIOE(2)AF2
199 * @arg TIM3_ETR_HSI: TIM3 ETR connected to HSI
200 * @arg TIM3_TI1_USB_SOF: TIM3 TI1 connected to USB_SOF (default)
201 * @arg TIM3_TI1_GPIO: TIM3 TI1 connected to GPIO :
202 * GPIOE(3)_AF2 or GPIOA(6)_AF2 or
203 * GPIOC(6)_AF2 or GPIOB(4)_AF2
204 * @arg TIM3_TI2_GPIOB5_AF4:TIM3 TI3 connected to GPIOB(5)_AF4
205 * (refer to note)
206 * @arg TIM3_TI2_GPIO_DEF: TIM3 TI3 connected to GPIO (default):
207 * GPIO_A(7)_AF2 or GPIO_B(5)_AF4 or
208 * GPIOC(7)_AF2 or GPIOE(7)_AF2
209 * @arg TIM3_TI4_GPIO_DEF: TIM3 TI4 connected to GPIO:
210 * GPIO_B(1)_AF2 or GPIO_E(6)_AF2
211 * @arg TIM3_TI4_GPIOC9_AF2:TIM3 TI4 connected to GPIOC(9)_AF2
212 *
213 * For TIM21, the parameter can have the following values:
214 * @arg TIM21_ETR_GPIO: TIM21 ETR connected to GPIO(default) :
215 * APB2_PC(9)_AF0 or APB2_PA(1)_AF5
216 * @arg TIM21_ETR_COMP2_OUT:TIM21 ETR connected to COMP2 output
217 * @arg TIM21_ETR_COMP1_OUT:TIM21 ETR connected to COMP1 output
218 * @arg TIM21_ETR_LSE: TIM21 ETR connected to LSE
219 * @arg TIM21_TI1_MCO: TIM21 TI1 connected to MCO
220 * @arg TIM21_TI1_RTC_WKUT_IT: TIM21 TI1 connected to RTC WAKEUP interrupt
221 * @arg TIM21_TI1_HSE_RTC: TIM21 TI1 connected to HSE_RTC
222 * @arg TIM21_TI1_MSI: TIM21 TI1 connected to MSI clock
223 * @arg TIM21_TI1_LSE: TIM21 TI1 connected to LSE
224 * @arg TIM21_TI1_LSI: TIM21 TI1 connected to LSI
225 * @arg TIM21_TI1_COMP1_OUT:TIM21 TI1 connected to COMP1_OUT
226 * @arg TIM21_TI1_GPIO: TIM21 TI1 connected to GPIO(default):
227 * GPIOA(2)_AF0 or GPIOB(13)_AF6 or
228 * GPIOE(5)_AF0 or GPIOD(0)_AF0
229 * @arg TIM21_TI2_GPIO: TIM21 TI2 connected to GPIO(default):
230 * GPIOA(3)_AF0 or GPIOB(14)_AF6 or
231 * GPIOE(6)_AF0 or GPIOD(7)_AF1
232 * @arg TIM21_TI2_COMP2_OUT:TIM21 TI2 connected to COMP2 output
233 *
234 * For TIM22, the parameter can have the following values:
235 * @arg TIM22_ETR_LSE: TIM22 ETR connected to LSE
236 * @arg TIM22_ETR_COMP2_OUT:TIM22 ETR connected to COMP2 output
237 * @arg TIM22_ETR_COMP1_OUT:TIM22 ETR connected to COMP1 output
238 * @arg TIM22_ETR_GPIO: TIM22 ETR connected to GPIO(default):
239 * GPIOC(8)_AF0 or GPIOA(4)_AF5
240 * @arg TIM22_TI1_GPIO1: TIM22 TI1 connected to GPIO(default):
241 * GPIOC(6)_AF0 or GPIOA(6)_AF5 or
242 * GPIOB(4)_AF4 or GPIOE(0)_AF3
243 * @arg TIM22_TI1_COMP2_OUT:TIM22 TI1 connected to COMP2 output
244 * @arg TIM22_TI1_COMP1_OUT:TIM22 TI1 connected to COMP1 output
245 * @arg TIM22_TI1_GPIO2: TIM22 TI1 connected to GPIO:
246 * GPIOC(6)_AF0 or GPIOA(6)_AF5 or
247 * GPIOB(4)_AF4 or GPIOE(3)_AF0
248 *
249 * @retval HAL status
250 */
251 #else
252 /**
253 * @brief Configures the remapping of the TIM2, TIM21 and TIM22 inputs.
254 * The channel inputs (T1..T4) and the Trigger input (ETR) of the
255 * timers can be remaped thanks to this function. When an input is
256 * mapped, on a GPIO, refer yourself to the GPIO alternate functions
257 * for more details.
258 *
259 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
260 * the configuration information for TIM module.
261 * @param Remap: specifies the TIM input remapping source.
262 * This parameter is a combination of the following values
263 * depending on TIM instance:
264 *
265 * For TIM2, the parameter can have the following values:
266 * @arg TIM2_ETR_GPIO: TIM2 ETR connected to GPIO (default):
267 * GPIOA(0)_AF5 or GPIOA(5)_AF2 or
268 * GPIOA(15)_AF2 or GPIOE(9)_AF2
269 * @arg TIM2_ETR_HSI48: TIM2 ETR connected to HSI48
270 * @arg TIM2_ETR_LSE: TIM2 ETR connected to LSE
271 * @arg TIM2_ETR_COMP2_OUT: TIM2 ETR connected to COMP2 output
272 * @arg TIM2_ETR_COMP1_OUT: TIM2 ETR connected to COMP1 output
273 * @arg TIM2_TI4_GPIO: TIM2 TI4 connected to GPIO1(default):
274 * GPIOA(3)_AF2 or GPIOB(11)_AF2 or
275 * GPIOE(12)_AF0
276 * @arg TIM2_TI4_COMP1: TIM2 TI4 connected to COMP1
277 * @arg TIM2_TI4_COMP2: TIM2 TI4 connected to COMP2
278 * @arg TIM2_TI4_GPIO2: TIM2 TI4 connected to GPIO2 :
279 * GPIOA(3)_AF2 or GPIOB(11)_AF2 or
280 * GPIOE(12)_AF0
281 *
282 * For TIM21, the parameter can have the following values:
283 * @arg TIM21_ETR_GPIO: TIM21 ETR connected to GPIO(default) :
284 * APB2_PC(9)_AF0 or APB2_PA(1)_AF5
285 * @arg TIM21_ETR_COMP2_OUT:TIM21 ETR connected to COMP2 output
286 * @arg TIM21_ETR_COMP1_OUT:TIM21 ETR connected to COMP1 output
287 * @arg TIM21_ETR_LSE: TIM21 ETR connected to LSE
288 * @arg TIM21_TI1_MCO: TIM21 TI1 connected to MCO
289 * @arg TIM21_TI1_RTC_WKUT_IT: TIM21 TI1 connected to RTC WAKEUP interrupt
290 * @arg TIM21_TI1_HSE_RTC: TIM21 TI1 connected to HSE_RTC
291 * @arg TIM21_TI1_MSI: TIM21 TI1 connected to MSI clock
292 * @arg TIM21_TI1_LSE: TIM21 TI1 connected to LSE
293 * @arg TIM21_TI1_LSI: TIM21 TI1 connected to LSI
294 * @arg TIM21_TI1_COMP1_OUT:TIM21 TI1 connected to COMP1_OUT
295 * @arg TIM21_TI1_GPIO: TIM21 TI1 connected to GPIO(default):
296 * GPIOA(2)_AF0 or GPIOB(13)_AF6 or
297 * GPIOE(5)_AF0 or GPIOD(0)_AF0
298 * @arg TIM21_TI2_GPIO: TIM21 TI2 connected to GPIO(default):
299 * GPIOA(3)_AF0 or GPIOB(14)_AF6 or
300 * GPIOE(6)_AF0 or GPIOD(7)_AF1
301 * @arg TIM21_TI2_COMP2_OUT:TIM21 TI2 connected to COMP2 output
302 *
303 * For TIM22, the parameter can have the following values:
304 * @arg TIM22_ETR_LSE: TIM22 ETR connected to LSE
305 * @arg TIM22_ETR_COMP2_OUT:TIM22 ETR connected to COMP2 output
306 * @arg TIM22_ETR_COMP1_OUT:TIM22 ETR connected to COMP1 output
307 * @arg TIM22_ETR_GPIO: TIM22 ETR connected to GPIO(default):
308 * GPIOC(8)_AF0 or GPIOA(4)_AF5
309 * @arg TIM22_TI1_GPIO1: TIM22 TI1 connected to GPIO(default):
310 * GPIOC(6)_AF0 or GPIOA(6)_AF5 or
311 * GPIOB(4)_AF4 or GPIOE(0)_AF3
312 * @arg TIM22_TI1_COMP2_OUT:TIM22 TI1 connected to COMP2 output
313 * @arg TIM22_TI1_COMP1_OUT:TIM22 TI1 connected to COMP1 output
314 * @arg TIM22_TI1_GPIO2: TIM22 TI1 connected to GPIO:
315 * GPIOC(6)_AF0 or GPIOA(6)_AF5 or
316 * GPIOB(4)_AF4 or GPIOE(3)_AF0
317 *
318 * @retval HAL status
319 */
320
321 #endif /* STM32L07xxx or STM32L08xxx */
322
323 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap)
324 {
325
326 __HAL_LOCK(htim);
327
328 /* Check parameters */
329 assert_param(IS_TIM_REMAP(htim->Instance,Remap));
330
331 /* Set the Timer remapping configuration */
332 htim->Instance->OR = Remap;
333
334 htim->State = HAL_TIM_STATE_READY;
335
336 __HAL_UNLOCK(htim);
337
338 return HAL_OK;
339 }
340
341 /**
342 * @}
343 */
344
345 /**
346 * @}
347 */
348
349 #endif /* HAL_TIM_MODULE_ENABLED */
350 /**
351 * @}
352 */
353
354 /**
355 * @}
356 */
357 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Imprint / Impressum