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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 macros ------------------------------------------------------------*/
  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_MASTER_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. /* Update TIMx CR2 */
  96. htim->Instance->CR2 = tmpcr2;
  97. if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
  98. {
  99. /* Reset the MSM Bit */
  100. tmpsmcr &= ~TIM_SMCR_MSM;
  101. /* Set master mode */
  102. tmpsmcr |= sMasterConfig->MasterSlaveMode;
  103. /* Update TIMx SMCR */
  104. htim->Instance->SMCR = tmpsmcr;
  105. }
  106. /* Change the htim state */
  107. htim->State = HAL_TIM_STATE_READY;
  108. __HAL_UNLOCK(htim);
  109. return HAL_OK;
  110. }
  111. /**
  112. * @brief Configures the TIMx Remapping input capabilities.
  113. * @param htim TIM handle.
  114. * @param Remap specifies the TIM remapping source.
  115. *
  116. * For TIM2, the parameter can have the following values:(see note)
  117. * @arg TIM_TIM2_ITR1_TIM10_OC: TIM2 ITR1 input is connected to TIM10 OC
  118. * @arg TIM_TIM2_ITR1_TIM5_TGO: TIM2 ITR1 input is connected to TIM5 TGO
  119. *
  120. * For TIM3, the parameter can have the following values:(see note)
  121. * @arg TIM_TIM3_ITR2_TIM11_OC: TIM3 ITR2 input is connected to TIM11 OC
  122. * @arg TIM_TIM3_ITR2_TIM5_TGO: TIM3 ITR2 input is connected to TIM5 TGO
  123. *
  124. * For TIM9, the parameter is a combination of 2 fields (field1 | field2):
  125. *
  126. * field1 can have the following values:(see note)
  127. * @arg TIM_TIM9_ITR1_TIM3_TGO: TIM9 ITR1 input is connected to TIM3 TGO
  128. * @arg TIM_TIM9_ITR1_TS: TIM9 ITR1 input is connected to touch sensing I/O
  129. *
  130. * field2 can have the following values:
  131. * @arg TIM_TIM9_GPIO: TIM9 Channel1 is connected to GPIO
  132. * @arg TIM_TIM9_LSE: TIM9 Channel1 is connected to LSE internal clock
  133. * @arg TIM_TIM9_GPIO1: TIM9 Channel1 is connected to GPIO
  134. * @arg TIM_TIM9_GPIO2: TIM9 Channel1 is connected to GPIO
  135. *
  136. * For TIM10, the parameter is a combination of 3 fields (field1 | field2 | field3):
  137. *
  138. * field1 can have the following values:(see note)
  139. * @arg TIM_TIM10_TI1RMP: TIM10 Channel 1 depends on TI1_RMP
  140. * @arg TIM_TIM10_RI: TIM10 Channel 1 is connected to RI
  141. *
  142. * field2 can have the following values:(see note)
  143. * @arg TIM_TIM10_ETR_LSE: TIM10 ETR input is connected to LSE clock
  144. * @arg TIM_TIM10_ETR_TIM9_TGO: TIM10 ETR input is connected to TIM9 TGO
  145. *
  146. * field3 can have the following values:
  147. * @arg TIM_TIM10_GPIO: TIM10 Channel1 is connected to GPIO
  148. * @arg TIM_TIM10_LSI: TIM10 Channel1 is connected to LSI internal clock
  149. * @arg TIM_TIM10_LSE: TIM10 Channel1 is connected to LSE internal clock
  150. * @arg TIM_TIM10_RTC: TIM10 Channel1 is connected to RTC wakeup interrupt
  151. *
  152. * For TIM11, the parameter is a combination of 3 fields (field1 | field2 | field3):
  153. *
  154. * field1 can have the following values:(see note)
  155. * @arg TIM_TIM11_TI1RMP: TIM11 Channel 1 depends on TI1_RMP
  156. * @arg TIM_TIM11_RI: TIM11 Channel 1 is connected to RI
  157. *
  158. * field2 can have the following values:(see note)
  159. * @arg TIM_TIM11_ETR_LSE: TIM11 ETR input is connected to LSE clock
  160. * @arg TIM_TIM11_ETR_TIM9_TGO: TIM11 ETR input is connected to TIM9 TGO
  161. *
  162. * field3 can have the following values:
  163. * @arg TIM_TIM11_GPIO: TIM11 Channel1 is connected to GPIO
  164. * @arg TIM_TIM11_MSI: TIM11 Channel1 is connected to MSI internal clock
  165. * @arg TIM_TIM11_HSE_RTC: TIM11 Channel1 is connected to HSE_RTC clock
  166. * @arg TIM_TIM11_GPIO1: TIM11 Channel1 is connected to GPIO
  167. *
  168. * @note Available only in Cat.3, Cat.4,Cat.5 and Cat.6 devices.
  169. *
  170. * @retval HAL status
  171. */
  172. HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap)
  173. {
  174. __HAL_LOCK(htim);
  175. /* Check parameters */
  176. assert_param(IS_TIM_REMAP(htim->Instance, Remap));
  177. /* Set the Timer remapping configuration */
  178. WRITE_REG(htim->Instance->OR, Remap);
  179. __HAL_UNLOCK(htim);
  180. return HAL_OK;
  181. }
  182. /**
  183. * @}
  184. */
  185. /**
  186. * @}
  187. */
  188. #endif /* HAL_TIM_MODULE_ENABLED */
  189. /**
  190. * @}
  191. */
  192. /**
  193. * @}
  194. */
  195. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/