stm32l1xx_hal_tim_ex.c 10 KB

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