stm32l1xx_hal_tim_ex.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 extension peripheral:
  8. * + Time Master and Slave synchronization configuration
  9. * + Timer remapping capabilities configuration
  10. @verbatim
  11. ==============================================================================
  12. ##### TIMER Extended features #####
  13. ==============================================================================
  14. [..]
  15. The Timer Extension features include:
  16. (#) Synchronization circuit to control the timer with external signals and to
  17. interconnect several timers together.
  18. (#) Timer remapping capabilities configuration
  19. @endverbatim
  20. ******************************************************************************
  21. * @attention
  22. *
  23. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  24. *
  25. * Redistribution and use in source and binary forms, with or without modification,
  26. * are permitted provided that the following conditions are met:
  27. * 1. Redistributions of source code must retain the above copyright notice,
  28. * this list of conditions and the following disclaimer.
  29. * 2. Redistributions in binary form must reproduce the above copyright notice,
  30. * this list of conditions and the following disclaimer in the documentation
  31. * and/or other materials provided with the distribution.
  32. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  33. * may be used to endorse or promote products derived from this software
  34. * without specific prior written permission.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  37. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  40. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  41. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  42. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  43. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  45. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46. *
  47. ******************************************************************************
  48. */
  49. /* Includes ------------------------------------------------------------------*/
  50. #include "stm32l1xx_hal.h"
  51. /** @addtogroup STM32L1xx_HAL_Driver
  52. * @{
  53. */
  54. /** @defgroup TIMEx TIMEx
  55. * @brief TIM Extended HAL module driver
  56. * @{
  57. */
  58. #ifdef HAL_TIM_MODULE_ENABLED
  59. /* Private typedef -----------------------------------------------------------*/
  60. /* Private define ------------------------------------------------------------*/
  61. /* Private macro -------------------------------------------------------------*/
  62. /* Private variables ---------------------------------------------------------*/
  63. /* Private function prototypes -----------------------------------------------*/
  64. /* Private functions ---------------------------------------------------------*/
  65. /* Exported functions ---------------------------------------------------------*/
  66. /** @defgroup TIMEx_Exported_Functions TIMEx Exported Functions
  67. * @{
  68. */
  69. /** @defgroup TIMEx_Exported_Functions_Group1 Peripheral Control functions
  70. * @brief Peripheral Control functions
  71. *
  72. @verbatim
  73. ==============================================================================
  74. ##### Peripheral Control functions #####
  75. ==============================================================================
  76. [..]
  77. This section provides functions allowing to:
  78. (+)Configure Master synchronization.
  79. (+) Configure timer remapping capabilities.
  80. @endverbatim
  81. * @{
  82. */
  83. /**
  84. * @brief Configures the TIM in master mode.
  85. * @param htim: TIM handle.
  86. * @param sMasterConfig: pointer to a TIM_MasterConfigTypeDef structure that
  87. * contains the selected trigger output (TRGO) and the Master/Slave
  88. * mode.
  89. * @retval HAL status
  90. */
  91. HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef * sMasterConfig)
  92. {
  93. /* Check the parameters */
  94. assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance));
  95. assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
  96. assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode));
  97. __HAL_LOCK(htim);
  98. htim->State = HAL_TIM_STATE_BUSY;
  99. /* Reset the MMS Bits */
  100. htim->Instance->CR2 &= ~TIM_CR2_MMS;
  101. /* Select the TRGO source */
  102. htim->Instance->CR2 |= sMasterConfig->MasterOutputTrigger;
  103. /* Reset the MSM Bit */
  104. htim->Instance->SMCR &= ~TIM_SMCR_MSM;
  105. /* Set or Reset the MSM Bit */
  106. htim->Instance->SMCR |= sMasterConfig->MasterSlaveMode;
  107. htim->State = HAL_TIM_STATE_READY;
  108. __HAL_UNLOCK(htim);
  109. return HAL_OK;
  110. }
  111. /**
  112. * @brief Configures the TIM2/TIM3/TIM9/TIM10/TIM11 Remapping input capabilities.
  113. * @param htim: TIM handle.
  114. * @param Remap: specifies the TIM remapping source.
  115. * This parameter is a combination of the following values depending on TIM instance.
  116. * @retval HAL status
  117. *
  118. * @note For TIM2, the parameter can have the following values:
  119. * @arg TIM_TIM2_ITR1_TIM10_OC: TIM2 ITR1 input is connected to TIM10 OC
  120. * @arg TIM_TIM2_ITR1_TIM5_TGO: TIM2 ITR1 input is connected to TIM5 TGO
  121. *
  122. * @note For TIM3, the parameter can have the following values:
  123. * @arg TIM_TIM3_ITR2_TIM11_OC: TIM3 ITR2 input is connected to TIM11 OC
  124. * @arg TIM_TIM3_ITR2_TIM5_TGO: TIM3 ITR2 input is connected to TIM5 TGO
  125. *
  126. * @note For TIM9, the parameter is a combination of 2 fields (field1 | field2):
  127. * @note For TIM9, the field1 can have the following values:
  128. * @arg TIM_TIM9_ITR1_TIM3_TGO: TIM9 ITR1 input is connected to TIM3 TGO
  129. * @arg TIM_TIM9_ITR1_TS: TIM9 ITR1 input is connected to touch sensing I/O
  130. * @note For TIM9, the 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. * @note For TIM10, the parameter is a combination of 3 fields (field1 | field2 | field3):
  137. * @note For TIM10, the field1 can have the following values:
  138. * @arg TIM_TIM10_TI1RMP: TIM10 Channel 1 depends on TI1_RMP
  139. * @arg TIM_TIM10_RI: TIM10 Channel 1 is connected to RI
  140. * @note For TIM10, the field2 can have the following values:
  141. * @arg TIM_TIM10_ETR_LSE: TIM10 ETR input is connected to LSE clock
  142. * @arg TIM_TIM10_ETR_TIM9_TGO: TIM10 ETR input is connected to TIM9 TGO
  143. * @note For TIM10, the 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. * @note For TIM11, the parameter is a combination of 3 fields (field1 | field2 | field3):
  150. * @note For TIM11, the field1 can have the following values:
  151. * @arg TIM_TIM11_TI1RMP: TIM11 Channel 1 depends on TI1_RMP
  152. * @arg TIM_TIM11_RI: TIM11 Channel 1 is connected to RI
  153. * @note For TIM11, the field2 can have the following values:
  154. * @arg TIM_TIM11_ETR_LSE: TIM11 ETR input is connected to LSE clock
  155. * @arg TIM_TIM11_ETR_TIM9_TGO: TIM11 ETR input is connected to TIM9 TGO
  156. * @note For TIM11, the field3 can have the following values:
  157. * @arg TIM_TIM11_GPIO: TIM11 Channel1 is connected to GPIO
  158. * @arg TIM_TIM11_MSI: TIM11 Channel1 is connected to MSI internal clock
  159. * @arg TIM_TIM11_HSE_RTC: TIM11 Channel1 is connected to HSE_RTC clock
  160. * @arg TIM_TIM11_GPIO1: TIM11 Channel1 is connected to GPIO
  161. *
  162. */
  163. HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap)
  164. {
  165. __HAL_LOCK(htim);
  166. /* Check parameters */
  167. assert_param(IS_TIM_REMAP_INSTANCE(htim->Instance));
  168. assert_param(IS_TIM_REMAP(htim->Instance,Remap));
  169. /* Set the Timer remapping configuration */
  170. htim->Instance->OR = Remap;
  171. htim->State = HAL_TIM_STATE_READY;
  172. __HAL_UNLOCK(htim);
  173. return HAL_OK;
  174. }
  175. /**
  176. * @}
  177. */
  178. #endif /* HAL_TIM_MODULE_ENABLED */
  179. /**
  180. * @}
  181. */
  182. /**
  183. * @}
  184. */
  185. /**
  186. * @}
  187. */
  188. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/