You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stm32l1xx_hal_tim_ex.c 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_tim_ex.c
  4. * @author MCD Application Team
  5. * @brief TIM HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Timer Extended peripheral:
  8. * + Time Master and Slave synchronization configuration
  9. * + Time OCRef clear configuration
  10. * + Timer remapping capabilities configuration
  11. @verbatim
  12. ==============================================================================
  13. ##### TIMER Extended features #####
  14. ==============================================================================
  15. [..]
  16. The Timer Extended features include:
  17. (#) Synchronization circuit to control the timer with external signals and to
  18. interconnect several timers together.
  19. @endverbatim
  20. ******************************************************************************
  21. * @attention
  22. *
  23. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  24. * All rights reserved.</center></h2>
  25. *
  26. * This software component is licensed by ST under BSD 3-Clause license,
  27. * the "License"; You may not use this file except in compliance with the
  28. * License. You may obtain a copy of the License at:
  29. * opensource.org/licenses/BSD-3-Clause
  30. *
  31. ******************************************************************************
  32. */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "stm32l1xx_hal.h"
  35. /** @addtogroup STM32L1xx_HAL_Driver
  36. * @{
  37. */
  38. /** @defgroup TIMEx TIMEx
  39. * @brief TIM Extended HAL module driver
  40. * @{
  41. */
  42. #ifdef HAL_TIM_MODULE_ENABLED
  43. /* Private typedef -----------------------------------------------------------*/
  44. /* Private define ------------------------------------------------------------*/
  45. /* Private macro -------------------------------------------------------------*/
  46. /* Private variables ---------------------------------------------------------*/
  47. /* Private function prototypes -----------------------------------------------*/
  48. /* Exported functions --------------------------------------------------------*/
  49. /** @defgroup TIMEx_Exported_Functions TIM Extended Exported Functions
  50. * @{
  51. */
  52. /** @defgroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions
  53. * @brief Peripheral Control functions
  54. *
  55. @verbatim
  56. ==============================================================================
  57. ##### Peripheral Control functions #####
  58. ==============================================================================
  59. [..]
  60. This section provides functions allowing to:
  61. (+) Configure Master synchronization.
  62. (+) Configure timer remapping capabilities.
  63. @endverbatim
  64. * @{
  65. */
  66. /**
  67. * @brief Configures the TIM in master mode.
  68. * @param htim TIM handle.
  69. * @param sMasterConfig pointer to a TIM_MasterConfigTypeDef structure that
  70. * contains the selected trigger output (TRGO) and the Master/Slave
  71. * mode.
  72. * @retval HAL status
  73. */
  74. HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
  75. TIM_MasterConfigTypeDef *sMasterConfig)
  76. {
  77. uint32_t tmpcr2;
  78. uint32_t tmpsmcr;
  79. /* Check the parameters */
  80. assert_param(IS_TIM_SYNCHRO_INSTANCE(htim->Instance));
  81. assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
  82. assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode));
  83. /* Check input state */
  84. __HAL_LOCK(htim);
  85. /* Change the handler state */
  86. htim->State = HAL_TIM_STATE_BUSY;
  87. /* Get the TIMx CR2 register value */
  88. tmpcr2 = htim->Instance->CR2;
  89. /* Get the TIMx SMCR register value */
  90. tmpsmcr = htim->Instance->SMCR;
  91. /* Reset the MMS Bits */
  92. tmpcr2 &= ~TIM_CR2_MMS;
  93. /* Select the TRGO source */
  94. tmpcr2 |= sMasterConfig->MasterOutputTrigger;
  95. /* Reset the MSM Bit */
  96. tmpsmcr &= ~TIM_SMCR_MSM;
  97. /* Set master mode */
  98. tmpsmcr |= sMasterConfig->MasterSlaveMode;
  99. /* Update TIMx CR2 */
  100. htim->Instance->CR2 = tmpcr2;
  101. /* Update TIMx SMCR */
  102. htim->Instance->SMCR = tmpsmcr;
  103. /* Change the htim state */
  104. htim->State = HAL_TIM_STATE_READY;
  105. __HAL_UNLOCK(htim);
  106. return HAL_OK;
  107. }
  108. /**
  109. * @brief Configures the TIMx Remapping input capabilities.
  110. * @param htim TIM handle.
  111. * @param Remap specifies the TIM remapping source.
  112. *
  113. * For TIM2, the parameter can have the following values:(see note)
  114. * @arg TIM_TIM2_ITR1_TIM10_OC: TIM2 ITR1 input is connected to TIM10 OC
  115. * @arg TIM_TIM2_ITR1_TIM5_TGO: TIM2 ITR1 input is connected to TIM5 TGO
  116. *
  117. * For TIM3, the parameter can have the following values:(see note)
  118. * @arg TIM_TIM3_ITR2_TIM11_OC: TIM3 ITR2 input is connected to TIM11 OC
  119. * @arg TIM_TIM3_ITR2_TIM5_TGO: TIM3 ITR2 input is connected to TIM5 TGO
  120. *
  121. * For TIM9, the parameter is a combination of 2 fields (field1 | field2):
  122. *
  123. * field1 can have the following values:(see note)
  124. * @arg TIM_TIM9_ITR1_TIM3_TGO: TIM9 ITR1 input is connected to TIM3 TGO
  125. * @arg TIM_TIM9_ITR1_TS: TIM9 ITR1 input is connected to touch sensing I/O
  126. *
  127. * field2 can have the following values:
  128. * @arg TIM_TIM9_GPIO: TIM9 Channel1 is connected to GPIO
  129. * @arg TIM_TIM9_LSE: TIM9 Channel1 is connected to LSE internal clock
  130. * @arg TIM_TIM9_GPIO1: TIM9 Channel1 is connected to GPIO
  131. * @arg TIM_TIM9_GPIO2: TIM9 Channel1 is connected to GPIO
  132. *
  133. * For TIM10, the parameter is a combination of 3 fields (field1 | field2 | field3):
  134. *
  135. * field1 can have the following values:(see note)
  136. * @arg TIM_TIM10_TI1RMP: TIM10 Channel 1 depends on TI1_RMP
  137. * @arg TIM_TIM10_RI: TIM10 Channel 1 is connected to RI
  138. *
  139. * field2 can have the following values:(see note)
  140. * @arg TIM_TIM10_ETR_LSE: TIM10 ETR input is connected to LSE clock
  141. * @arg TIM_TIM10_ETR_TIM9_TGO: TIM10 ETR input is connected to TIM9 TGO
  142. *
  143. * field3 can have the following values:
  144. * @arg TIM_TIM10_GPIO: TIM10 Channel1 is connected to GPIO
  145. * @arg TIM_TIM10_LSI: TIM10 Channel1 is connected to LSI internal clock
  146. * @arg TIM_TIM10_LSE: TIM10 Channel1 is connected to LSE internal clock
  147. * @arg TIM_TIM10_RTC: TIM10 Channel1 is connected to RTC wakeup interrupt
  148. *
  149. * For TIM11, the parameter is a combination of 3 fields (field1 | field2 | field3):
  150. *
  151. * field1 can have the following values:(see note)
  152. * @arg TIM_TIM11_TI1RMP: TIM11 Channel 1 depends on TI1_RMP
  153. * @arg TIM_TIM11_RI: TIM11 Channel 1 is connected to RI
  154. *
  155. * field2 can have the following values:(see note)
  156. * @arg TIM_TIM11_ETR_LSE: TIM11 ETR input is connected to LSE clock
  157. * @arg TIM_TIM11_ETR_TIM9_TGO: TIM11 ETR input is connected to TIM9 TGO
  158. *
  159. * field3 can have the following values:
  160. * @arg TIM_TIM11_GPIO: TIM11 Channel1 is connected to GPIO
  161. * @arg TIM_TIM11_MSI: TIM11 Channel1 is connected to MSI internal clock
  162. * @arg TIM_TIM11_HSE_RTC: TIM11 Channel1 is connected to HSE_RTC clock
  163. * @arg TIM_TIM11_GPIO1: TIM11 Channel1 is connected to GPIO
  164. *
  165. * @note Available only in Cat.3, Cat.4,Cat.5 and Cat.6 devices.
  166. *
  167. * @retval HAL status
  168. */
  169. HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap)
  170. {
  171. __HAL_LOCK(htim);
  172. /* Check parameters */
  173. assert_param(IS_TIM_REMAP(htim->Instance, Remap));
  174. /* Set the Timer remapping configuration */
  175. WRITE_REG(htim->Instance->OR, Remap);
  176. __HAL_UNLOCK(htim);
  177. return HAL_OK;
  178. }
  179. /**
  180. * @}
  181. */
  182. /**
  183. * @}
  184. */
  185. #endif /* HAL_TIM_MODULE_ENABLED */
  186. /**
  187. * @}
  188. */
  189. /**
  190. * @}
  191. */
  192. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/