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.
 
 
 

2251 lines
78 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_tim_ex.c
  4. * @author MCD Application Team
  5. * @version V1.7.1
  6. * @date 21-April-2017
  7. * @brief TIM HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities of the Timer Extended peripheral:
  10. * + Time Hall Sensor Interface Initialization
  11. * + Time Hall Sensor Interface Start
  12. * + Time Complementary signal break and dead time configuration
  13. * + Time Master and Slave synchronization configuration
  14. * + Time Output Compare/PWM Channel Configuration (for channels 5 and 6)
  15. * + Time OCRef clear configuration
  16. * + Timer remapping capabilities configuration
  17. @verbatim
  18. ==============================================================================
  19. ##### TIMER Extended features #####
  20. ==============================================================================
  21. [..]
  22. The Timer Extended features include:
  23. (#) Complementary outputs with programmable dead-time for :
  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
  28. interconnect several timers together.
  29. (#) Break input to put the timer output signals in reset state or in a known state.
  30. (#) Supports incremental (quadrature) encoder and hall-sensor circuitry for
  31. positioning purposes
  32. ##### How to use this driver #####
  33. ==============================================================================
  34. [..]
  35. (#) Initialize the TIM low level resources by implementing the following functions
  36. depending on the selected feature:
  37. (++) Hall Sensor output : HAL_TIMEx_HallSensor_MspInit()
  38. (#) Initialize the TIM low level resources :
  39. (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE();
  40. (##) TIM pins configuration
  41. (+++) Enable the clock for the TIM GPIOs using the following function:
  42. __HAL_RCC_GPIOx_CLK_ENABLE();
  43. (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
  44. (#) The external Clock can be configured, if needed (the default clock is the
  45. internal clock from the APBx), using the following function:
  46. HAL_TIM_ConfigClockSource, the clock configuration should be done before
  47. any start function.
  48. (#) Configure the TIM in the desired functioning mode using one of the
  49. initialization function of this driver:
  50. (++) HAL_TIMEx_HallSensor_Init() and HAL_TIMEx_ConfigCommutationEvent(): to use the
  51. Timer Hall Sensor Interface and the commutation event with the corresponding
  52. Interrupt and DMA request if needed (Note that One Timer is used to interface
  53. with the Hall sensor Interface and another Timer should be used to use
  54. the commutation event).
  55. (#) Activate the TIM peripheral using one of the start functions:
  56. (++) Complementary Output Compare : HAL_TIMEx_OCN_Start(), HAL_TIMEx_OCN_Start_DMA(), HAL_TIMEx_OC_Start_IT()
  57. (++) Complementary PWM generation : HAL_TIMEx_PWMN_Start(), HAL_TIMEx_PWMN_Start_DMA(), HAL_TIMEx_PWMN_Start_IT()
  58. (++) Complementary One-pulse mode output : HAL_TIMEx_OnePulseN_Start(), HAL_TIMEx_OnePulseN_Start_IT()
  59. (++) Hall Sensor output : HAL_TIMEx_HallSensor_Start(), HAL_TIMEx_HallSensor_Start_DMA(), HAL_TIMEx_HallSensor_Start_IT().
  60. @endverbatim
  61. ******************************************************************************
  62. * @attention
  63. *
  64. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  65. *
  66. * Redistribution and use in source and binary forms, with or without modification,
  67. * are permitted provided that the following conditions are met:
  68. * 1. Redistributions of source code must retain the above copyright notice,
  69. * this list of conditions and the following disclaimer.
  70. * 2. Redistributions in binary form must reproduce the above copyright notice,
  71. * this list of conditions and the following disclaimer in the documentation
  72. * and/or other materials provided with the distribution.
  73. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  74. * may be used to endorse or promote products derived from this software
  75. * without specific prior written permission.
  76. *
  77. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  78. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  79. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  80. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  81. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  82. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  83. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  84. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  85. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  86. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  87. *
  88. ******************************************************************************
  89. */
  90. /* Includes ------------------------------------------------------------------*/
  91. #include "stm32l4xx_hal.h"
  92. /** @addtogroup STM32L4xx_HAL_Driver
  93. * @{
  94. */
  95. /** @defgroup TIMEx TIMEx
  96. * @brief TIM Extended HAL module driver
  97. * @{
  98. */
  99. #ifdef HAL_TIM_MODULE_ENABLED
  100. /* Private typedef -----------------------------------------------------------*/
  101. /* Private define ------------------------------------------------------------*/
  102. #define BDTR_BKF_SHIFT (16)
  103. #define BDTR_BK2F_SHIFT (20)
  104. #define TIMx_ETRSEL_MASK ((uint32_t)0x0001C000)
  105. /* Private macro -------------------------------------------------------------*/
  106. /* Private variables ---------------------------------------------------------*/
  107. /* Private function prototypes -----------------------------------------------*/
  108. static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState);
  109. /* Private functions ---------------------------------------------------------*/
  110. /* Exported functions --------------------------------------------------------*/
  111. /** @defgroup TIMEx_Exported_Functions TIM Extended Exported Functions
  112. * @{
  113. */
  114. /** @defgroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions
  115. * @brief Timer Hall Sensor functions
  116. *
  117. @verbatim
  118. ==============================================================================
  119. ##### Timer Hall Sensor functions #####
  120. ==============================================================================
  121. [..]
  122. This section provides functions allowing to:
  123. (+) Initialize and configure TIM HAL Sensor.
  124. (+) De-initialize TIM HAL Sensor.
  125. (+) Start the Hall Sensor Interface.
  126. (+) Stop the Hall Sensor Interface.
  127. (+) Start the Hall Sensor Interface and enable interrupts.
  128. (+) Stop the Hall Sensor Interface and disable interrupts.
  129. (+) Start the Hall Sensor Interface and enable DMA transfers.
  130. (+) Stop the Hall Sensor Interface and disable DMA transfers.
  131. @endverbatim
  132. * @{
  133. */
  134. /**
  135. * @brief Initializes the TIM Hall Sensor Interface and initialize the associated handle.
  136. * @param htim: TIM Encoder Interface handle
  137. * @param sConfig: TIM Hall Sensor configuration structure
  138. * @retval HAL status
  139. */
  140. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef* sConfig)
  141. {
  142. TIM_OC_InitTypeDef OC_Config;
  143. /* Check the TIM handle allocation */
  144. if(htim == NULL)
  145. {
  146. return HAL_ERROR;
  147. }
  148. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  149. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  150. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  151. assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));
  152. assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
  153. assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
  154. if(htim->State == HAL_TIM_STATE_RESET)
  155. {
  156. /* Allocate lock resource and initialize it */
  157. htim->Lock = HAL_UNLOCKED;
  158. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  159. HAL_TIMEx_HallSensor_MspInit(htim);
  160. }
  161. /* Set the TIM state */
  162. htim->State = HAL_TIM_STATE_BUSY;
  163. /* Configure the Time base in the Encoder Mode */
  164. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  165. /* Configure the Channel 1 as Input Channel to interface with the three Outputs of the Hall sensor */
  166. TIM_TI1_SetConfig(htim->Instance, sConfig->IC1Polarity, TIM_ICSELECTION_TRC, sConfig->IC1Filter);
  167. /* Reset the IC1PSC Bits */
  168. htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
  169. /* Set the IC1PSC value */
  170. htim->Instance->CCMR1 |= sConfig->IC1Prescaler;
  171. /* Enable the Hall sensor interface (XOR function of the three inputs) */
  172. htim->Instance->CR2 |= TIM_CR2_TI1S;
  173. /* Select the TIM_TS_TI1F_ED signal as Input trigger for the TIM */
  174. htim->Instance->SMCR &= ~TIM_SMCR_TS;
  175. htim->Instance->SMCR |= TIM_TS_TI1F_ED;
  176. /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */
  177. htim->Instance->SMCR &= ~TIM_SMCR_SMS;
  178. htim->Instance->SMCR |= TIM_SLAVEMODE_RESET;
  179. /* Program channel 2 in PWM 2 mode with the desired Commutation_Delay*/
  180. OC_Config.OCFastMode = TIM_OCFAST_DISABLE;
  181. OC_Config.OCIdleState = TIM_OCIDLESTATE_RESET;
  182. OC_Config.OCMode = TIM_OCMODE_PWM2;
  183. OC_Config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
  184. OC_Config.OCNPolarity = TIM_OCNPOLARITY_HIGH;
  185. OC_Config.OCPolarity = TIM_OCPOLARITY_HIGH;
  186. OC_Config.Pulse = sConfig->Commutation_Delay;
  187. TIM_OC2_SetConfig(htim->Instance, &OC_Config);
  188. /* Select OC2REF as trigger output on TRGO: write the MMS bits in the TIMx_CR2
  189. register to 101 */
  190. htim->Instance->CR2 &= ~TIM_CR2_MMS;
  191. htim->Instance->CR2 |= TIM_TRGO_OC2REF;
  192. /* Initialize the TIM state*/
  193. htim->State= HAL_TIM_STATE_READY;
  194. return HAL_OK;
  195. }
  196. /**
  197. * @brief DeInitialize the TIM Hall Sensor interface
  198. * @param htim: TIM Hall Sensor handle
  199. * @retval HAL status
  200. */
  201. HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim)
  202. {
  203. /* Check the parameters */
  204. assert_param(IS_TIM_INSTANCE(htim->Instance));
  205. htim->State = HAL_TIM_STATE_BUSY;
  206. /* Disable the TIM Peripheral Clock */
  207. __HAL_TIM_DISABLE(htim);
  208. /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
  209. HAL_TIMEx_HallSensor_MspDeInit(htim);
  210. /* Change TIM state */
  211. htim->State = HAL_TIM_STATE_RESET;
  212. /* Release Lock */
  213. __HAL_UNLOCK(htim);
  214. return HAL_OK;
  215. }
  216. /**
  217. * @brief Initializes the TIM Hall Sensor MSP.
  218. * @param htim: TIM handle
  219. * @retval None
  220. */
  221. __weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
  222. {
  223. /* Prevent unused argument(s) compilation warning */
  224. UNUSED(htim);
  225. /* NOTE : This function should not be modified, when the callback is needed,
  226. the HAL_TIMEx_HallSensor_MspInit could be implemented in the user file
  227. */
  228. }
  229. /**
  230. * @brief DeInitialize TIM Hall Sensor MSP.
  231. * @param htim: TIM handle
  232. * @retval None
  233. */
  234. __weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
  235. {
  236. /* Prevent unused argument(s) compilation warning */
  237. UNUSED(htim);
  238. /* NOTE : This function should not be modified, when the callback is needed,
  239. the HAL_TIMEx_HallSensor_MspDeInit could be implemented in the user file
  240. */
  241. }
  242. /**
  243. * @brief Starts the TIM Hall Sensor Interface.
  244. * @param htim : TIM Hall Sensor handle
  245. * @retval HAL status
  246. */
  247. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)
  248. {
  249. /* Check the parameters */
  250. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  251. /* Enable the Input Capture channels 1
  252. (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
  253. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  254. /* Enable the Peripheral */
  255. __HAL_TIM_ENABLE(htim);
  256. /* Return function status */
  257. return HAL_OK;
  258. }
  259. /**
  260. * @brief Stops the TIM Hall sensor Interface.
  261. * @param htim : TIM Hall Sensor handle
  262. * @retval HAL status
  263. */
  264. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)
  265. {
  266. /* Check the parameters */
  267. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  268. /* Disable the Input Capture channels 1, 2 and 3
  269. (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
  270. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  271. /* Disable the Peripheral */
  272. __HAL_TIM_DISABLE(htim);
  273. /* Return function status */
  274. return HAL_OK;
  275. }
  276. /**
  277. * @brief Starts the TIM Hall Sensor Interface in interrupt mode.
  278. * @param htim : TIM Hall Sensor handle
  279. * @retval HAL status
  280. */
  281. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)
  282. {
  283. /* Check the parameters */
  284. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  285. /* Enable the capture compare Interrupts 1 event */
  286. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  287. /* Enable the Input Capture channels 1
  288. (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
  289. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  290. /* Enable the Peripheral */
  291. __HAL_TIM_ENABLE(htim);
  292. /* Return function status */
  293. return HAL_OK;
  294. }
  295. /**
  296. * @brief Stops the TIM Hall Sensor Interface in interrupt mode.
  297. * @param htim : TIM handle
  298. * @retval HAL status
  299. */
  300. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim)
  301. {
  302. /* Check the parameters */
  303. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  304. /* Disable the Input Capture channels 1
  305. (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
  306. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  307. /* Disable the capture compare Interrupts event */
  308. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  309. /* Disable the Peripheral */
  310. __HAL_TIM_DISABLE(htim);
  311. /* Return function status */
  312. return HAL_OK;
  313. }
  314. /**
  315. * @brief Starts the TIM Hall Sensor Interface in DMA mode.
  316. * @param htim : TIM Hall Sensor handle
  317. * @param pData: The destination Buffer address.
  318. * @param Length: The length of data to be transferred from TIM peripheral to memory.
  319. * @retval HAL status
  320. */
  321. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
  322. {
  323. /* Check the parameters */
  324. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  325. if((htim->State == HAL_TIM_STATE_BUSY))
  326. {
  327. return HAL_BUSY;
  328. }
  329. else if((htim->State == HAL_TIM_STATE_READY))
  330. {
  331. if(((uint32_t)pData == 0 ) && (Length > 0))
  332. {
  333. return HAL_ERROR;
  334. }
  335. else
  336. {
  337. htim->State = HAL_TIM_STATE_BUSY;
  338. }
  339. }
  340. /* Enable the Input Capture channels 1
  341. (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
  342. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  343. /* Set the DMA Input Capture 1 Callback */
  344. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
  345. /* Set the DMA error callback */
  346. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
  347. /* Enable the DMA channel for Capture 1*/
  348. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length);
  349. /* Enable the capture compare 1 Interrupt */
  350. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  351. /* Enable the Peripheral */
  352. __HAL_TIM_ENABLE(htim);
  353. /* Return function status */
  354. return HAL_OK;
  355. }
  356. /**
  357. * @brief Stops the TIM Hall Sensor Interface in DMA mode.
  358. * @param htim : TIM handle
  359. * @retval HAL status
  360. */
  361. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
  362. {
  363. /* Check the parameters */
  364. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  365. /* Disable the Input Capture channels 1
  366. (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
  367. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  368. /* Disable the capture compare Interrupts 1 event */
  369. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  370. /* Disable the Peripheral */
  371. __HAL_TIM_DISABLE(htim);
  372. /* Return function status */
  373. return HAL_OK;
  374. }
  375. /**
  376. * @}
  377. */
  378. /** @defgroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions
  379. * @brief Timer Complementary Output Compare functions
  380. *
  381. @verbatim
  382. ==============================================================================
  383. ##### Timer Complementary Output Compare functions #####
  384. ==============================================================================
  385. [..]
  386. This section provides functions allowing to:
  387. (+) Start the Complementary Output Compare/PWM.
  388. (+) Stop the Complementary Output Compare/PWM.
  389. (+) Start the Complementary Output Compare/PWM and enable interrupts.
  390. (+) Stop the Complementary Output Compare/PWM and disable interrupts.
  391. (+) Start the Complementary Output Compare/PWM and enable DMA transfers.
  392. (+) Stop the Complementary Output Compare/PWM and disable DMA transfers.
  393. @endverbatim
  394. * @{
  395. */
  396. /**
  397. * @brief Starts the TIM Output Compare signal generation on the complementary
  398. * output.
  399. * @param htim : TIM Output Compare handle
  400. * @param Channel : TIM Channel to be enabled
  401. * This parameter can be one of the following values:
  402. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  403. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  404. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  405. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  406. * @retval HAL status
  407. */
  408. HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
  409. {
  410. /* Check the parameters */
  411. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  412. /* Enable the Capture compare channel N */
  413. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
  414. /* Enable the Main Ouput */
  415. __HAL_TIM_MOE_ENABLE(htim);
  416. /* Enable the Peripheral */
  417. __HAL_TIM_ENABLE(htim);
  418. /* Return function status */
  419. return HAL_OK;
  420. }
  421. /**
  422. * @brief Stops the TIM Output Compare signal generation on the complementary
  423. * output.
  424. * @param htim : TIM handle
  425. * @param Channel : TIM Channel to be disabled
  426. * This parameter can be one of the following values:
  427. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  428. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  429. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  430. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  431. * @retval HAL status
  432. */
  433. HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
  434. {
  435. /* Check the parameters */
  436. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  437. /* Disable the Capture compare channel N */
  438. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
  439. /* Disable the Main Ouput */
  440. __HAL_TIM_MOE_DISABLE(htim);
  441. /* Disable the Peripheral */
  442. __HAL_TIM_DISABLE(htim);
  443. /* Return function status */
  444. return HAL_OK;
  445. }
  446. /**
  447. * @brief Starts the TIM Output Compare signal generation in interrupt mode
  448. * on the complementary output.
  449. * @param htim : TIM OC handle
  450. * @param Channel : TIM Channel to be enabled
  451. * This parameter can be one of the following values:
  452. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  453. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  454. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  455. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  456. * @retval HAL status
  457. */
  458. HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  459. {
  460. /* Check the parameters */
  461. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  462. switch (Channel)
  463. {
  464. case TIM_CHANNEL_1:
  465. {
  466. /* Enable the TIM Output Compare interrupt */
  467. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  468. }
  469. break;
  470. case TIM_CHANNEL_2:
  471. {
  472. /* Enable the TIM Output Compare interrupt */
  473. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  474. }
  475. break;
  476. case TIM_CHANNEL_3:
  477. {
  478. /* Enable the TIM Output Compare interrupt */
  479. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
  480. }
  481. break;
  482. case TIM_CHANNEL_4:
  483. {
  484. /* Enable the TIM Output Compare interrupt */
  485. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
  486. }
  487. break;
  488. default:
  489. break;
  490. }
  491. /* Enable the TIM Break interrupt */
  492. __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
  493. /* Enable the Capture compare channel N */
  494. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
  495. /* Enable the Main Ouput */
  496. __HAL_TIM_MOE_ENABLE(htim);
  497. /* Enable the Peripheral */
  498. __HAL_TIM_ENABLE(htim);
  499. /* Return function status */
  500. return HAL_OK;
  501. }
  502. /**
  503. * @brief Stops the TIM Output Compare signal generation in interrupt mode
  504. * on the complementary output.
  505. * @param htim : TIM Output Compare handle
  506. * @param Channel : TIM Channel to be disabled
  507. * This parameter can be one of the following values:
  508. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  509. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  510. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  511. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  512. * @retval HAL status
  513. */
  514. HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  515. {
  516. uint32_t tmpccer = 0;
  517. /* Check the parameters */
  518. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  519. switch (Channel)
  520. {
  521. case TIM_CHANNEL_1:
  522. {
  523. /* Disable the TIM Output Compare interrupt */
  524. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  525. }
  526. break;
  527. case TIM_CHANNEL_2:
  528. {
  529. /* Disable the TIM Output Compare interrupt */
  530. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  531. }
  532. break;
  533. case TIM_CHANNEL_3:
  534. {
  535. /* Disable the TIM Output Compare interrupt */
  536. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
  537. }
  538. break;
  539. case TIM_CHANNEL_4:
  540. {
  541. /* Disable the TIM Output Compare interrupt */
  542. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
  543. }
  544. break;
  545. default:
  546. break;
  547. }
  548. /* Disable the Capture compare channel N */
  549. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
  550. /* Disable the TIM Break interrupt (only if no more channel is active) */
  551. tmpccer = htim->Instance->CCER;
  552. if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
  553. {
  554. __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
  555. }
  556. /* Disable the Main Ouput */
  557. __HAL_TIM_MOE_DISABLE(htim);
  558. /* Disable the Peripheral */
  559. __HAL_TIM_DISABLE(htim);
  560. /* Return function status */
  561. return HAL_OK;
  562. }
  563. /**
  564. * @brief Starts the TIM Output Compare signal generation in DMA mode
  565. * on the complementary output.
  566. * @param htim : TIM Output Compare handle
  567. * @param Channel : TIM Channel to be enabled
  568. * This parameter can be one of the following values:
  569. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  570. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  571. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  572. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  573. * @param pData: The source Buffer address.
  574. * @param Length: The length of data to be transferred from memory to TIM peripheral
  575. * @retval HAL status
  576. */
  577. HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
  578. {
  579. /* Check the parameters */
  580. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  581. if((htim->State == HAL_TIM_STATE_BUSY))
  582. {
  583. return HAL_BUSY;
  584. }
  585. else if((htim->State == HAL_TIM_STATE_READY))
  586. {
  587. if(((uint32_t)pData == 0 ) && (Length > 0))
  588. {
  589. return HAL_ERROR;
  590. }
  591. else
  592. {
  593. htim->State = HAL_TIM_STATE_BUSY;
  594. }
  595. }
  596. switch (Channel)
  597. {
  598. case TIM_CHANNEL_1:
  599. {
  600. /* Set the DMA Period elapsed callback */
  601. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
  602. /* Set the DMA error callback */
  603. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
  604. /* Enable the DMA channel */
  605. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
  606. /* Enable the TIM Output Compare DMA request */
  607. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  608. }
  609. break;
  610. case TIM_CHANNEL_2:
  611. {
  612. /* Set the DMA Period elapsed callback */
  613. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
  614. /* Set the DMA error callback */
  615. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
  616. /* Enable the DMA channel */
  617. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
  618. /* Enable the TIM Output Compare DMA request */
  619. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  620. }
  621. break;
  622. case TIM_CHANNEL_3:
  623. {
  624. /* Set the DMA Period elapsed callback */
  625. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
  626. /* Set the DMA error callback */
  627. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
  628. /* Enable the DMA channel */
  629. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
  630. /* Enable the TIM Output Compare DMA request */
  631. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
  632. }
  633. break;
  634. case TIM_CHANNEL_4:
  635. {
  636. /* Set the DMA Period elapsed callback */
  637. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
  638. /* Set the DMA error callback */
  639. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
  640. /* Enable the DMA channel */
  641. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
  642. /* Enable the TIM Output Compare DMA request */
  643. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
  644. }
  645. break;
  646. default:
  647. break;
  648. }
  649. /* Enable the Capture compare channel N */
  650. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
  651. /* Enable the Main Ouput */
  652. __HAL_TIM_MOE_ENABLE(htim);
  653. /* Enable the Peripheral */
  654. __HAL_TIM_ENABLE(htim);
  655. /* Return function status */
  656. return HAL_OK;
  657. }
  658. /**
  659. * @brief Stops the TIM Output Compare signal generation in DMA mode
  660. * on the complementary output.
  661. * @param htim : TIM Output Compare handle
  662. * @param Channel : TIM Channel to be disabled
  663. * This parameter can be one of the following values:
  664. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  665. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  666. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  667. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  668. * @retval HAL status
  669. */
  670. HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
  671. {
  672. /* Check the parameters */
  673. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  674. switch (Channel)
  675. {
  676. case TIM_CHANNEL_1:
  677. {
  678. /* Disable the TIM Output Compare DMA request */
  679. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  680. }
  681. break;
  682. case TIM_CHANNEL_2:
  683. {
  684. /* Disable the TIM Output Compare DMA request */
  685. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  686. }
  687. break;
  688. case TIM_CHANNEL_3:
  689. {
  690. /* Disable the TIM Output Compare DMA request */
  691. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
  692. }
  693. break;
  694. case TIM_CHANNEL_4:
  695. {
  696. /* Disable the TIM Output Compare interrupt */
  697. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
  698. }
  699. break;
  700. default:
  701. break;
  702. }
  703. /* Disable the Capture compare channel N */
  704. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
  705. /* Disable the Main Ouput */
  706. __HAL_TIM_MOE_DISABLE(htim);
  707. /* Disable the Peripheral */
  708. __HAL_TIM_DISABLE(htim);
  709. /* Change the htim state */
  710. htim->State = HAL_TIM_STATE_READY;
  711. /* Return function status */
  712. return HAL_OK;
  713. }
  714. /**
  715. * @}
  716. */
  717. /** @defgroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions
  718. * @brief Timer Complementary PWM functions
  719. *
  720. @verbatim
  721. ==============================================================================
  722. ##### Timer Complementary PWM functions #####
  723. ==============================================================================
  724. [..]
  725. This section provides functions allowing to:
  726. (+) Start the Complementary PWM.
  727. (+) Stop the Complementary PWM.
  728. (+) Start the Complementary PWM and enable interrupts.
  729. (+) Stop the Complementary PWM and disable interrupts.
  730. (+) Start the Complementary PWM and enable DMA transfers.
  731. (+) Stop the Complementary PWM and disable DMA transfers.
  732. (+) Start the Complementary Input Capture measurement.
  733. (+) Stop the Complementary Input Capture.
  734. (+) Start the Complementary Input Capture and enable interrupts.
  735. (+) Stop the Complementary Input Capture and disable interrupts.
  736. (+) Start the Complementary Input Capture and enable DMA transfers.
  737. (+) Stop the Complementary Input Capture and disable DMA transfers.
  738. (+) Start the Complementary One Pulse generation.
  739. (+) Stop the Complementary One Pulse.
  740. (+) Start the Complementary One Pulse and enable interrupts.
  741. (+) Stop the Complementary One Pulse and disable interrupts.
  742. @endverbatim
  743. * @{
  744. */
  745. /**
  746. * @brief Starts the PWM signal generation on the complementary output.
  747. * @param htim : TIM handle
  748. * @param Channel : TIM Channel to be enabled
  749. * This parameter can be one of the following values:
  750. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  751. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  752. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  753. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  754. * @retval HAL status
  755. */
  756. HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
  757. {
  758. /* Check the parameters */
  759. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  760. /* Enable the complementary PWM output */
  761. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
  762. /* Enable the Main Ouput */
  763. __HAL_TIM_MOE_ENABLE(htim);
  764. /* Enable the Peripheral */
  765. __HAL_TIM_ENABLE(htim);
  766. /* Return function status */
  767. return HAL_OK;
  768. }
  769. /**
  770. * @brief Stops the PWM signal generation on the complementary output.
  771. * @param htim : TIM handle
  772. * @param Channel : TIM Channel to be disabled
  773. * This parameter can be one of the following values:
  774. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  775. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  776. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  777. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  778. * @retval HAL status
  779. */
  780. HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
  781. {
  782. /* Check the parameters */
  783. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  784. /* Disable the complementary PWM output */
  785. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
  786. /* Disable the Main Ouput */
  787. __HAL_TIM_MOE_DISABLE(htim);
  788. /* Disable the Peripheral */
  789. __HAL_TIM_DISABLE(htim);
  790. /* Return function status */
  791. return HAL_OK;
  792. }
  793. /**
  794. * @brief Starts the PWM signal generation in interrupt mode on the
  795. * complementary output.
  796. * @param htim : TIM handle
  797. * @param Channel : TIM Channel to be disabled
  798. * This parameter can be one of the following values:
  799. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  800. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  801. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  802. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  803. * @retval HAL status
  804. */
  805. HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  806. {
  807. /* Check the parameters */
  808. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  809. switch (Channel)
  810. {
  811. case TIM_CHANNEL_1:
  812. {
  813. /* Enable the TIM Capture/Compare 1 interrupt */
  814. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  815. }
  816. break;
  817. case TIM_CHANNEL_2:
  818. {
  819. /* Enable the TIM Capture/Compare 2 interrupt */
  820. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  821. }
  822. break;
  823. case TIM_CHANNEL_3:
  824. {
  825. /* Enable the TIM Capture/Compare 3 interrupt */
  826. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
  827. }
  828. break;
  829. case TIM_CHANNEL_4:
  830. {
  831. /* Enable the TIM Capture/Compare 4 interrupt */
  832. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
  833. }
  834. break;
  835. default:
  836. break;
  837. }
  838. /* Enable the TIM Break interrupt */
  839. __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
  840. /* Enable the complementary PWM output */
  841. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
  842. /* Enable the Main Ouput */
  843. __HAL_TIM_MOE_ENABLE(htim);
  844. /* Enable the Peripheral */
  845. __HAL_TIM_ENABLE(htim);
  846. /* Return function status */
  847. return HAL_OK;
  848. }
  849. /**
  850. * @brief Stops the PWM signal generation in interrupt mode on the
  851. * complementary output.
  852. * @param htim : TIM handle
  853. * @param Channel : TIM Channel to be disabled
  854. * This parameter can be one of the following values:
  855. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  856. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  857. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  858. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  859. * @retval HAL status
  860. */
  861. HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
  862. {
  863. uint32_t tmpccer = 0;
  864. /* Check the parameters */
  865. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  866. switch (Channel)
  867. {
  868. case TIM_CHANNEL_1:
  869. {
  870. /* Disable the TIM Capture/Compare 1 interrupt */
  871. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  872. }
  873. break;
  874. case TIM_CHANNEL_2:
  875. {
  876. /* Disable the TIM Capture/Compare 2 interrupt */
  877. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  878. }
  879. break;
  880. case TIM_CHANNEL_3:
  881. {
  882. /* Disable the TIM Capture/Compare 3 interrupt */
  883. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
  884. }
  885. break;
  886. case TIM_CHANNEL_4:
  887. {
  888. /* Disable the TIM Capture/Compare 3 interrupt */
  889. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
  890. }
  891. break;
  892. default:
  893. break;
  894. }
  895. /* Disable the complementary PWM output */
  896. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
  897. /* Disable the TIM Break interrupt (only if no more channel is active) */
  898. tmpccer = htim->Instance->CCER;
  899. if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
  900. {
  901. __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
  902. }
  903. /* Disable the Main Ouput */
  904. __HAL_TIM_MOE_DISABLE(htim);
  905. /* Disable the Peripheral */
  906. __HAL_TIM_DISABLE(htim);
  907. /* Return function status */
  908. return HAL_OK;
  909. }
  910. /**
  911. * @brief Starts the TIM PWM signal generation in DMA mode on the
  912. * complementary output
  913. * @param htim : TIM handle
  914. * @param Channel : TIM Channel to be enabled
  915. * This parameter can be one of the following values:
  916. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  917. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  918. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  919. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  920. * @param pData: The source Buffer address.
  921. * @param Length: The length of data to be transferred from memory to TIM peripheral
  922. * @retval HAL status
  923. */
  924. HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
  925. {
  926. /* Check the parameters */
  927. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  928. if((htim->State == HAL_TIM_STATE_BUSY))
  929. {
  930. return HAL_BUSY;
  931. }
  932. else if((htim->State == HAL_TIM_STATE_READY))
  933. {
  934. if(((uint32_t)pData == 0 ) && (Length > 0))
  935. {
  936. return HAL_ERROR;
  937. }
  938. else
  939. {
  940. htim->State = HAL_TIM_STATE_BUSY;
  941. }
  942. }
  943. switch (Channel)
  944. {
  945. case TIM_CHANNEL_1:
  946. {
  947. /* Set the DMA Period elapsed callback */
  948. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
  949. /* Set the DMA error callback */
  950. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
  951. /* Enable the DMA channel */
  952. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
  953. /* Enable the TIM Capture/Compare 1 DMA request */
  954. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  955. }
  956. break;
  957. case TIM_CHANNEL_2:
  958. {
  959. /* Set the DMA Period elapsed callback */
  960. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
  961. /* Set the DMA error callback */
  962. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
  963. /* Enable the DMA channel */
  964. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
  965. /* Enable the TIM Capture/Compare 2 DMA request */
  966. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  967. }
  968. break;
  969. case TIM_CHANNEL_3:
  970. {
  971. /* Set the DMA Period elapsed callback */
  972. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
  973. /* Set the DMA error callback */
  974. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
  975. /* Enable the DMA channel */
  976. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
  977. /* Enable the TIM Capture/Compare 3 DMA request */
  978. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
  979. }
  980. break;
  981. case TIM_CHANNEL_4:
  982. {
  983. /* Set the DMA Period elapsed callback */
  984. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
  985. /* Set the DMA error callback */
  986. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
  987. /* Enable the DMA channel */
  988. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
  989. /* Enable the TIM Capture/Compare 4 DMA request */
  990. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
  991. }
  992. break;
  993. default:
  994. break;
  995. }
  996. /* Enable the complementary PWM output */
  997. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
  998. /* Enable the Main Ouput */
  999. __HAL_TIM_MOE_ENABLE(htim);
  1000. /* Enable the Peripheral */
  1001. __HAL_TIM_ENABLE(htim);
  1002. /* Return function status */
  1003. return HAL_OK;
  1004. }
  1005. /**
  1006. * @brief Stops the TIM PWM signal generation in DMA mode on the complementary
  1007. * output
  1008. * @param htim : TIM handle
  1009. * @param Channel : TIM Channel to be disabled
  1010. * This parameter can be one of the following values:
  1011. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1012. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1013. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1014. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1015. * @retval HAL status
  1016. */
  1017. HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
  1018. {
  1019. /* Check the parameters */
  1020. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  1021. switch (Channel)
  1022. {
  1023. case TIM_CHANNEL_1:
  1024. {
  1025. /* Disable the TIM Capture/Compare 1 DMA request */
  1026. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  1027. }
  1028. break;
  1029. case TIM_CHANNEL_2:
  1030. {
  1031. /* Disable the TIM Capture/Compare 2 DMA request */
  1032. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  1033. }
  1034. break;
  1035. case TIM_CHANNEL_3:
  1036. {
  1037. /* Disable the TIM Capture/Compare 3 DMA request */
  1038. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
  1039. }
  1040. break;
  1041. case TIM_CHANNEL_4:
  1042. {
  1043. /* Disable the TIM Capture/Compare 4 DMA request */
  1044. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
  1045. }
  1046. break;
  1047. default:
  1048. break;
  1049. }
  1050. /* Disable the complementary PWM output */
  1051. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
  1052. /* Disable the Main Ouput */
  1053. __HAL_TIM_MOE_DISABLE(htim);
  1054. /* Disable the Peripheral */
  1055. __HAL_TIM_DISABLE(htim);
  1056. /* Change the htim state */
  1057. htim->State = HAL_TIM_STATE_READY;
  1058. /* Return function status */
  1059. return HAL_OK;
  1060. }
  1061. /**
  1062. * @}
  1063. */
  1064. /** @defgroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions
  1065. * @brief Timer Complementary One Pulse functions
  1066. *
  1067. @verbatim
  1068. ==============================================================================
  1069. ##### Timer Complementary One Pulse functions #####
  1070. ==============================================================================
  1071. [..]
  1072. This section provides functions allowing to:
  1073. (+) Start the Complementary One Pulse generation.
  1074. (+) Stop the Complementary One Pulse.
  1075. (+) Start the Complementary One Pulse and enable interrupts.
  1076. (+) Stop the Complementary One Pulse and disable interrupts.
  1077. @endverbatim
  1078. * @{
  1079. */
  1080. /**
  1081. * @brief Starts the TIM One Pulse signal generation on the complementary
  1082. * output.
  1083. * @param htim : TIM One Pulse handle
  1084. * @param OutputChannel : TIM Channel to be enabled
  1085. * This parameter can be one of the following values:
  1086. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1087. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1088. * @retval HAL status
  1089. */
  1090. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  1091. {
  1092. /* Check the parameters */
  1093. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
  1094. /* Enable the complementary One Pulse output */
  1095. TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
  1096. /* Enable the Main Ouput */
  1097. __HAL_TIM_MOE_ENABLE(htim);
  1098. /* Return function status */
  1099. return HAL_OK;
  1100. }
  1101. /**
  1102. * @brief Stops the TIM One Pulse signal generation on the complementary
  1103. * output.
  1104. * @param htim : TIM One Pulse handle
  1105. * @param OutputChannel : TIM Channel to be disabled
  1106. * This parameter can be one of the following values:
  1107. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1108. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1109. * @retval HAL status
  1110. */
  1111. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  1112. {
  1113. /* Check the parameters */
  1114. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
  1115. /* Disable the complementary One Pulse output */
  1116. TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
  1117. /* Disable the Main Ouput */
  1118. __HAL_TIM_MOE_DISABLE(htim);
  1119. /* Disable the Peripheral */
  1120. __HAL_TIM_DISABLE(htim);
  1121. /* Return function status */
  1122. return HAL_OK;
  1123. }
  1124. /**
  1125. * @brief Starts the TIM One Pulse signal generation in interrupt mode on the
  1126. * complementary channel.
  1127. * @param htim : TIM One Pulse handle
  1128. * @param OutputChannel : TIM Channel to be enabled
  1129. * This parameter can be one of the following values:
  1130. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1131. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1132. * @retval HAL status
  1133. */
  1134. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  1135. {
  1136. /* Check the parameters */
  1137. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
  1138. /* Enable the TIM Capture/Compare 1 interrupt */
  1139. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  1140. /* Enable the TIM Capture/Compare 2 interrupt */
  1141. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  1142. /* Enable the complementary One Pulse output */
  1143. TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
  1144. /* Enable the Main Ouput */
  1145. __HAL_TIM_MOE_ENABLE(htim);
  1146. /* Return function status */
  1147. return HAL_OK;
  1148. }
  1149. /**
  1150. * @brief Stops the TIM One Pulse signal generation in interrupt mode on the
  1151. * complementary channel.
  1152. * @param htim : TIM One Pulse handle
  1153. * @param OutputChannel : TIM Channel to be disabled
  1154. * This parameter can be one of the following values:
  1155. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1156. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1157. * @retval HAL status
  1158. */
  1159. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  1160. {
  1161. /* Check the parameters */
  1162. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
  1163. /* Disable the TIM Capture/Compare 1 interrupt */
  1164. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  1165. /* Disable the TIM Capture/Compare 2 interrupt */
  1166. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  1167. /* Disable the complementary One Pulse output */
  1168. TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
  1169. /* Disable the Main Ouput */
  1170. __HAL_TIM_MOE_DISABLE(htim);
  1171. /* Disable the Peripheral */
  1172. __HAL_TIM_DISABLE(htim);
  1173. /* Return function status */
  1174. return HAL_OK;
  1175. }
  1176. /**
  1177. * @}
  1178. */
  1179. /** @defgroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions
  1180. * @brief Peripheral Control functions
  1181. *
  1182. @verbatim
  1183. ==============================================================================
  1184. ##### Peripheral Control functions #####
  1185. ==============================================================================
  1186. [..]
  1187. This section provides functions allowing to:
  1188. (+) Configure the commutation event in case of use of the Hall sensor interface.
  1189. (+) Configure Output channels for OC and PWM mode.
  1190. (+) Configure Complementary channels, break features and dead time.
  1191. (+) Configure Master synchronization.
  1192. (+) Configure timer remapping capabilities.
  1193. (+) Enable or disable channel grouping
  1194. @endverbatim
  1195. * @{
  1196. */
  1197. /**
  1198. * @brief Configure the TIM commutation event sequence.
  1199. * @note This function is mandatory to use the commutation event in order to
  1200. * update the configuration at each commutation detection on the TRGI input of the Timer,
  1201. * the typical use of this feature is with the use of another Timer(interface Timer)
  1202. * configured in Hall sensor interface, this interface Timer will generate the
  1203. * commutation at its TRGO output (connected to Timer used in this function) each time
  1204. * the TI1 of the Interface Timer detect a commutation at its input TI1.
  1205. * @param htim: TIM handle
  1206. * @param InputTrigger : the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
  1207. * This parameter can be one of the following values:
  1208. * @arg TIM_TS_ITR0: Internal trigger 0 selected
  1209. * @arg TIM_TS_ITR1: Internal trigger 1 selected
  1210. * @arg TIM_TS_ITR2: Internal trigger 2 selected
  1211. * @arg TIM_TS_ITR3: Internal trigger 3 selected
  1212. * @arg TIM_TS_NONE: No trigger is needed
  1213. * @param CommutationSource : the Commutation Event source
  1214. * This parameter can be one of the following values:
  1215. * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
  1216. * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
  1217. * @retval HAL status
  1218. */
  1219. HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
  1220. {
  1221. /* Check the parameters */
  1222. assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
  1223. assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
  1224. __HAL_LOCK(htim);
  1225. if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
  1226. (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
  1227. {
  1228. /* Select the Input trigger */
  1229. htim->Instance->SMCR &= ~TIM_SMCR_TS;
  1230. htim->Instance->SMCR |= InputTrigger;
  1231. }
  1232. /* Select the Capture Compare preload feature */
  1233. htim->Instance->CR2 |= TIM_CR2_CCPC;
  1234. /* Select the Commutation event source */
  1235. htim->Instance->CR2 &= ~TIM_CR2_CCUS;
  1236. htim->Instance->CR2 |= CommutationSource;
  1237. __HAL_UNLOCK(htim);
  1238. return HAL_OK;
  1239. }
  1240. /**
  1241. * @brief Configure the TIM commutation event sequence with interrupt.
  1242. * @note This function is mandatory to use the commutation event in order to
  1243. * update the configuration at each commutation detection on the TRGI input of the Timer,
  1244. * the typical use of this feature is with the use of another Timer(interface Timer)
  1245. * configured in Hall sensor interface, this interface Timer will generate the
  1246. * commutation at its TRGO output (connected to Timer used in this function) each time
  1247. * the TI1 of the Interface Timer detect a commutation at its input TI1.
  1248. * @param htim: TIM handle
  1249. * @param InputTrigger : the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
  1250. * This parameter can be one of the following values:
  1251. * @arg TIM_TS_ITR0: Internal trigger 0 selected
  1252. * @arg TIM_TS_ITR1: Internal trigger 1 selected
  1253. * @arg TIM_TS_ITR2: Internal trigger 2 selected
  1254. * @arg TIM_TS_ITR3: Internal trigger 3 selected
  1255. * @arg TIM_TS_NONE: No trigger is needed
  1256. * @param CommutationSource : the Commutation Event source
  1257. * This parameter can be one of the following values:
  1258. * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
  1259. * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
  1260. * @retval HAL status
  1261. */
  1262. HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
  1263. {
  1264. /* Check the parameters */
  1265. assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
  1266. assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
  1267. __HAL_LOCK(htim);
  1268. if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
  1269. (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
  1270. {
  1271. /* Select the Input trigger */
  1272. htim->Instance->SMCR &= ~TIM_SMCR_TS;
  1273. htim->Instance->SMCR |= InputTrigger;
  1274. }
  1275. /* Select the Capture Compare preload feature */
  1276. htim->Instance->CR2 |= TIM_CR2_CCPC;
  1277. /* Select the Commutation event source */
  1278. htim->Instance->CR2 &= ~TIM_CR2_CCUS;
  1279. htim->Instance->CR2 |= CommutationSource;
  1280. /* Enable the Commutation Interrupt Request */
  1281. __HAL_TIM_ENABLE_IT(htim, TIM_IT_COM);
  1282. __HAL_UNLOCK(htim);
  1283. return HAL_OK;
  1284. }
  1285. /**
  1286. * @brief Configure the TIM commutation event sequence with DMA.
  1287. * @note This function is mandatory to use the commutation event in order to
  1288. * update the configuration at each commutation detection on the TRGI input of the Timer,
  1289. * the typical use of this feature is with the use of another Timer(interface Timer)
  1290. * configured in Hall sensor interface, this interface Timer will generate the
  1291. * commutation at its TRGO output (connected to Timer used in this function) each time
  1292. * the TI1 of the Interface Timer detect a commutation at its input TI1.
  1293. * @note The user should configure the DMA in his own software, in This function only the COMDE bit is set
  1294. * @param htim: TIM handle
  1295. * @param InputTrigger : the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
  1296. * This parameter can be one of the following values:
  1297. * @arg TIM_TS_ITR0: Internal trigger 0 selected
  1298. * @arg TIM_TS_ITR1: Internal trigger 1 selected
  1299. * @arg TIM_TS_ITR2: Internal trigger 2 selected
  1300. * @arg TIM_TS_ITR3: Internal trigger 3 selected
  1301. * @arg TIM_TS_NONE: No trigger is needed
  1302. * @param CommutationSource : the Commutation Event source
  1303. * This parameter can be one of the following values:
  1304. * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
  1305. * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
  1306. * @retval HAL status
  1307. */
  1308. HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
  1309. {
  1310. /* Check the parameters */
  1311. assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
  1312. assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
  1313. __HAL_LOCK(htim);
  1314. if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
  1315. (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
  1316. {
  1317. /* Select the Input trigger */
  1318. htim->Instance->SMCR &= ~TIM_SMCR_TS;
  1319. htim->Instance->SMCR |= InputTrigger;
  1320. }
  1321. /* Select the Capture Compare preload feature */
  1322. htim->Instance->CR2 |= TIM_CR2_CCPC;
  1323. /* Select the Commutation event source */
  1324. htim->Instance->CR2 &= ~TIM_CR2_CCUS;
  1325. htim->Instance->CR2 |= CommutationSource;
  1326. /* Enable the Commutation DMA Request */
  1327. /* Set the DMA Commutation Callback */
  1328. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
  1329. /* Set the DMA error callback */
  1330. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError;
  1331. /* Enable the Commutation DMA Request */
  1332. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_COM);
  1333. __HAL_UNLOCK(htim);
  1334. return HAL_OK;
  1335. }
  1336. /**
  1337. * @brief Configures the TIM in master mode.
  1338. * @param htim: TIM handle.
  1339. * @param sMasterConfig: pointer to a TIM_MasterConfigTypeDef structure that
  1340. * contains the selected trigger output (TRGO) and the Master/Slave
  1341. * mode.
  1342. * @retval HAL status
  1343. */
  1344. HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
  1345. TIM_MasterConfigTypeDef * sMasterConfig)
  1346. {
  1347. uint32_t tmpcr2;
  1348. uint32_t tmpsmcr;
  1349. /* Check the parameters */
  1350. assert_param(IS_TIM_SYNCHRO_INSTANCE(htim->Instance));
  1351. assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
  1352. assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode));
  1353. /* Check input state */
  1354. __HAL_LOCK(htim);
  1355. /* Get the TIMx CR2 register value */
  1356. tmpcr2 = htim->Instance->CR2;
  1357. /* Get the TIMx SMCR register value */
  1358. tmpsmcr = htim->Instance->SMCR;
  1359. /* If the timer supports ADC synchronization through TRGO2, set the master mode selection 2 */
  1360. if (IS_TIM_TRGO2_INSTANCE(htim->Instance))
  1361. {
  1362. /* Check the parameters */
  1363. assert_param(IS_TIM_TRGO2_SOURCE(sMasterConfig->MasterOutputTrigger2));
  1364. /* Clear the MMS2 bits */
  1365. tmpcr2 &= ~TIM_CR2_MMS2;
  1366. /* Select the TRGO2 source*/
  1367. tmpcr2 |= sMasterConfig->MasterOutputTrigger2;
  1368. }
  1369. /* Reset the MMS Bits */
  1370. tmpcr2 &= ~TIM_CR2_MMS;
  1371. /* Select the TRGO source */
  1372. tmpcr2 |= sMasterConfig->MasterOutputTrigger;
  1373. /* Reset the MSM Bit */
  1374. tmpsmcr &= ~TIM_SMCR_MSM;
  1375. /* Set master mode */
  1376. tmpsmcr |= sMasterConfig->MasterSlaveMode;
  1377. /* Update TIMx CR2 */
  1378. htim->Instance->CR2 = tmpcr2;
  1379. /* Update TIMx SMCR */
  1380. htim->Instance->SMCR = tmpsmcr;
  1381. __HAL_UNLOCK(htim);
  1382. return HAL_OK;
  1383. }
  1384. /**
  1385. * @brief Configures the Break feature, dead time, Lock level, OSSI/OSSR State
  1386. * and the AOE(automatic output enable).
  1387. * @param htim: TIM handle
  1388. * @param sBreakDeadTimeConfig: pointer to a TIM_ConfigBreakDeadConfigTypeDef structure that
  1389. * contains the BDTR Register configuration information for the TIM peripheral.
  1390. * @retval HAL status
  1391. */
  1392. HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
  1393. TIM_BreakDeadTimeConfigTypeDef * sBreakDeadTimeConfig)
  1394. {
  1395. uint32_t tmpbdtr = 0;
  1396. /* Check the parameters */
  1397. assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance));
  1398. assert_param(IS_TIM_OSSR_STATE(sBreakDeadTimeConfig->OffStateRunMode));
  1399. assert_param(IS_TIM_OSSI_STATE(sBreakDeadTimeConfig->OffStateIDLEMode));
  1400. assert_param(IS_TIM_LOCK_LEVEL(sBreakDeadTimeConfig->LockLevel));
  1401. assert_param(IS_TIM_DEADTIME(sBreakDeadTimeConfig->DeadTime));
  1402. assert_param(IS_TIM_BREAK_STATE(sBreakDeadTimeConfig->BreakState));
  1403. assert_param(IS_TIM_BREAK_POLARITY(sBreakDeadTimeConfig->BreakPolarity));
  1404. assert_param(IS_TIM_BREAK_FILTER(sBreakDeadTimeConfig->BreakFilter));
  1405. assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(sBreakDeadTimeConfig->AutomaticOutput));
  1406. /* Check input state */
  1407. __HAL_LOCK(htim);
  1408. /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
  1409. the OSSI State, the dead time value and the Automatic Output Enable Bit */
  1410. /* Set the BDTR bits */
  1411. MODIFY_REG(tmpbdtr, TIM_BDTR_DTG, sBreakDeadTimeConfig->DeadTime);
  1412. MODIFY_REG(tmpbdtr, TIM_BDTR_LOCK, sBreakDeadTimeConfig->LockLevel);
  1413. MODIFY_REG(tmpbdtr, TIM_BDTR_OSSI, sBreakDeadTimeConfig->OffStateIDLEMode);
  1414. MODIFY_REG(tmpbdtr, TIM_BDTR_OSSR, sBreakDeadTimeConfig->OffStateRunMode);
  1415. MODIFY_REG(tmpbdtr, TIM_BDTR_BKE, sBreakDeadTimeConfig->BreakState);
  1416. MODIFY_REG(tmpbdtr, TIM_BDTR_BKP, sBreakDeadTimeConfig->BreakPolarity);
  1417. MODIFY_REG(tmpbdtr, TIM_BDTR_AOE, sBreakDeadTimeConfig->AutomaticOutput);
  1418. MODIFY_REG(tmpbdtr, TIM_BDTR_MOE, sBreakDeadTimeConfig->AutomaticOutput);
  1419. MODIFY_REG(tmpbdtr, TIM_BDTR_BKF, (sBreakDeadTimeConfig->BreakFilter << BDTR_BKF_SHIFT));
  1420. if (IS_TIM_BKIN2_INSTANCE(htim->Instance))
  1421. {
  1422. assert_param(IS_TIM_BREAK2_STATE(sBreakDeadTimeConfig->Break2State));
  1423. assert_param(IS_TIM_BREAK2_POLARITY(sBreakDeadTimeConfig->Break2Polarity));
  1424. assert_param(IS_TIM_BREAK_FILTER(sBreakDeadTimeConfig->Break2Filter));
  1425. /* Set the BREAK2 input related BDTR bits */
  1426. MODIFY_REG(tmpbdtr, TIM_BDTR_BK2F, (sBreakDeadTimeConfig->Break2Filter << BDTR_BK2F_SHIFT));
  1427. MODIFY_REG(tmpbdtr, TIM_BDTR_BK2E, sBreakDeadTimeConfig->Break2State);
  1428. MODIFY_REG(tmpbdtr, TIM_BDTR_BK2P, sBreakDeadTimeConfig->Break2Polarity);
  1429. }
  1430. /* Set TIMx_BDTR */
  1431. htim->Instance->BDTR = tmpbdtr;
  1432. __HAL_UNLOCK(htim);
  1433. return HAL_OK;
  1434. }
  1435. /**
  1436. * @brief Configures the break input source.
  1437. * @param htim: TIM handle.
  1438. * @param BreakInput: Break input to configure
  1439. * This parameter can be one of the following values:
  1440. * @arg TIM_BREAKINPUT_BRK: Timer break input
  1441. * @arg TIM_BREAKINPUT_BRK2: Timer break 2 input
  1442. * @param sBreakInputConfig: Break input source configuration
  1443. * @retval HAL status
  1444. */
  1445. HAL_StatusTypeDef HAL_TIMEx_ConfigBreakInput(TIM_HandleTypeDef *htim,
  1446. uint32_t BreakInput,
  1447. TIMEx_BreakInputConfigTypeDef *sBreakInputConfig)
  1448. {
  1449. uint32_t tmporx = 0;
  1450. uint32_t bkin_enable_mask = 0;
  1451. uint32_t bkin_polarity_mask = 0;
  1452. uint32_t bkin_enable_bitpos = 0;
  1453. uint32_t bkin_polarity_bitpos = 0;
  1454. /* Check the parameters */
  1455. assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance));
  1456. assert_param(IS_TIM_BREAKINPUT(BreakInput));
  1457. assert_param(IS_TIM_BREAKINPUTSOURCE(sBreakInputConfig->Source));
  1458. assert_param(IS_TIM_BREAKINPUTSOURCE_STATE(sBreakInputConfig->Enable));
  1459. #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L471xx) || \
  1460. defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
  1461. defined (STM32L496xx) || defined (STM32L4A6xx)
  1462. if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1)
  1463. {
  1464. assert_param(IS_TIM_BREAKINPUTSOURCE_POLARITY(sBreakInputConfig->Polarity));
  1465. }
  1466. #else
  1467. assert_param(IS_TIM_BREAKINPUTSOURCE_POLARITY(sBreakInputConfig->Polarity));
  1468. #endif /* STM32L451xx || STM32L452xx || STM32L462xx || STM32L471xx */
  1469. /* STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx */
  1470. /* STM32L496xx || STM32L4A6xx */
  1471. /* Check input state */
  1472. __HAL_LOCK(htim);
  1473. switch(sBreakInputConfig->Source)
  1474. {
  1475. case TIM_BREAKINPUTSOURCE_BKIN:
  1476. {
  1477. bkin_enable_mask = TIM1_OR2_BKINE;
  1478. bkin_enable_bitpos = 0;
  1479. bkin_polarity_mask = TIM1_OR2_BKINP;
  1480. bkin_polarity_bitpos = 9;
  1481. }
  1482. break;
  1483. case TIM_BREAKINPUTSOURCE_COMP1:
  1484. {
  1485. bkin_enable_mask = TIM1_OR2_BKCMP1E;
  1486. bkin_enable_bitpos = 1;
  1487. bkin_polarity_mask = TIM1_OR2_BKCMP1P;
  1488. bkin_polarity_bitpos = 10;
  1489. }
  1490. break;
  1491. case TIM_BREAKINPUTSOURCE_COMP2:
  1492. {
  1493. bkin_enable_mask = TIM1_OR2_BKCMP2E;
  1494. bkin_enable_bitpos = 2;
  1495. bkin_polarity_mask = TIM1_OR2_BKCMP2P;
  1496. bkin_polarity_bitpos = 11;
  1497. }
  1498. break;
  1499. #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L471xx) || \
  1500. defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
  1501. defined (STM32L496xx) || defined (STM32L4A6xx)
  1502. case TIM_BREAKINPUTSOURCE_DFSDM1:
  1503. {
  1504. bkin_enable_mask = TIM1_OR2_BKDF1BK0E;
  1505. bkin_enable_bitpos = 8;
  1506. }
  1507. break;
  1508. #endif /* STM32L451xx || STM32L452xx || STM32L462xx || STM32L471xx */
  1509. /* STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx */
  1510. /* STM32L496xx || STM32L4A6xx */
  1511. default:
  1512. break;
  1513. }
  1514. switch(BreakInput)
  1515. {
  1516. case TIM_BREAKINPUT_BRK:
  1517. {
  1518. /* Get the TIMx_OR2 register value */
  1519. tmporx = htim->Instance->OR2;
  1520. /* Enable the break input */
  1521. tmporx &= ~bkin_enable_mask;
  1522. tmporx |= (sBreakInputConfig->Enable << bkin_enable_bitpos) & bkin_enable_mask;
  1523. /* Set the break input polarity */
  1524. #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L471xx) || \
  1525. defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
  1526. defined (STM32L496xx) || defined (STM32L4A6xx)
  1527. if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1)
  1528. #endif /* STM32L451xx || STM32L452xx || STM32L462xx || STM32L471xx */
  1529. /* STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx */
  1530. /* STM32L496xx || STM32L4A6xx */
  1531. {
  1532. tmporx &= ~bkin_polarity_mask;
  1533. tmporx |= (sBreakInputConfig->Polarity << bkin_polarity_bitpos) & bkin_polarity_mask;
  1534. }
  1535. /* Set TIMx_OR2 */
  1536. htim->Instance->OR2 = tmporx;
  1537. }
  1538. break;
  1539. case TIM_BREAKINPUT_BRK2:
  1540. {
  1541. /* Get the TIMx_OR3 register value */
  1542. tmporx = htim->Instance->OR3;
  1543. /* Enable the break input */
  1544. tmporx &= ~bkin_enable_mask;
  1545. tmporx |= (sBreakInputConfig->Enable << bkin_enable_bitpos) & bkin_enable_mask;
  1546. /* Set the break input polarity */
  1547. #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L471xx) || \
  1548. defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
  1549. defined (STM32L496xx) || defined (STM32L4A6xx)
  1550. if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1)
  1551. #endif /* STM32L451xx || STM32L452xx || STM32L462xx || STM32L471xx */
  1552. /* STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx */
  1553. /* STM32L496xx || STM32L4A6xx */
  1554. {
  1555. tmporx &= ~bkin_polarity_mask;
  1556. tmporx |= (sBreakInputConfig->Polarity << bkin_polarity_bitpos) & bkin_polarity_mask;
  1557. }
  1558. /* Set TIMx_OR3 */
  1559. htim->Instance->OR3 = tmporx;
  1560. }
  1561. break;
  1562. default:
  1563. break;
  1564. }
  1565. __HAL_UNLOCK(htim);
  1566. return HAL_OK;
  1567. }
  1568. /**
  1569. * @brief Configures the TIMx Remapping input capabilities.
  1570. * @param htim: TIM handle.
  1571. * @param Remap: specifies the TIM remapping source.
  1572. *
  1573. @if STM32L486xx
  1574. * For TIM1, the parameter is a combination of 4 fields (field1 | field2 | field3 | field4):
  1575. *
  1576. * field1 can have the following values:
  1577. * @arg TIM_TIM1_ETR_ADC1_NONE: TIM1_ETR is not connected to any ADC1 AWD (analog watchdog)
  1578. * @arg TIM_TIM1_ETR_ADC1_AWD1: TIM1_ETR is connected to ADC1 AWD1
  1579. * @arg TIM_TIM1_ETR_ADC1_AWD2: TIM1_ETR is connected to ADC1 AWD2
  1580. * @arg TIM_TIM1_ETR_ADC1_AWD3: TIM1_ETR is connected to ADC1 AWD3
  1581. *
  1582. * field2 can have the following values:
  1583. * @arg TIM_TIM1_ETR_ADC3_NONE: TIM1_ETR is not connected to any ADC3 AWD (analog watchdog)
  1584. * @arg TIM_TIM1_ETR_ADC3_AWD1: TIM1_ETR is connected to ADC3 AWD1
  1585. * @arg TIM_TIM1_ETR_ADC3_AWD2: TIM1_ETR is connected to ADC3 AWD2
  1586. * @arg TIM_TIM1_ETR_ADC3_AWD3: TIM1_ETR is connected to ADC3 AWD3
  1587. *
  1588. * field3 can have the following values:
  1589. * @arg TIM_TIM1_TI1_GPIO: TIM1 TI1 is connected to GPIO
  1590. * @arg TIM_TIM1_TI1_COMP1: TIM1 TI1 is connected to COMP1 output
  1591. *
  1592. * field4 can have the following values:
  1593. * @arg TIM_TIM1_ETR_COMP1: TIM1_ETR is connected to COMP1 output
  1594. * @arg TIM_TIM1_ETR_COMP2: TIM1_ETR is connected to COMP2 output
  1595. * @note When field4 is set to TIM_TIM1_ETR_COMP1 or TIM_TIM1_ETR_COMP2 field1 and field2 values are not significant
  1596. @endif
  1597. @if STM32L443xx
  1598. * For TIM1, the parameter is a combination of 3 fields (field1 | field2 | field3):
  1599. *
  1600. * field1 can have the following values:
  1601. * @arg TIM_TIM1_ETR_ADC1_NONE: TIM1_ETR is not connected to any ADC1 AWD (analog watchdog)
  1602. * @arg TIM_TIM1_ETR_ADC1_AWD1: TIM1_ETR is connected to ADC1 AWD1
  1603. * @arg TIM_TIM1_ETR_ADC1_AWD2: TIM1_ETR is connected to ADC1 AWD2
  1604. * @arg TIM_TIM1_ETR_ADC1_AWD3: TIM1_ETR is connected to ADC1 AWD3
  1605. *
  1606. * field2 can have the following values:
  1607. * @arg TIM_TIM1_TI1_GPIO: TIM1 TI1 is connected to GPIO
  1608. * @arg TIM_TIM1_TI1_COMP1: TIM1 TI1 is connected to COMP1 output
  1609. *
  1610. * field3 can have the following values:
  1611. * @arg TIM_TIM1_ETR_COMP1: TIM1_ETR is connected to COMP1 output
  1612. * @arg TIM_TIM1_ETR_COMP2: TIM1_ETR is connected to COMP2 output
  1613. *
  1614. * @note When field3 is set to TIM_TIM1_ETR_COMP1 or TIM_TIM1_ETR_COMP2 field1 values is not significant
  1615. *
  1616. @endif
  1617. @if STM32L486xx
  1618. * For TIM2, the parameter is a combination of 3 fields (field1 | field2 | field3):
  1619. *
  1620. * field1 can have the following values:
  1621. * @arg TIM_TIM2_ITR1_TIM8_TRGO: TIM2_ITR1 is connected to TIM8_TRGO
  1622. * @arg TIM_TIM2_ITR1_OTG_FS_SOF: TIM2_ITR1 is connected to OTG_FS SOF
  1623. *
  1624. * field2 can have the following values:
  1625. * @arg TIM_TIM2_ETR_GPIO: TIM2_ETR is connected to GPIO
  1626. * @arg TIM_TIM2_ETR_LSE: TIM2_ETR is connected to LSE
  1627. * @arg TIM_TIM2_ETR_COMP1: TIM2_ETR is connected to COMP1 output
  1628. * @arg TIM_TIM2_ETR_COMP2: TIM2_ETR is connected to COMP2 output
  1629. *
  1630. * field3 can have the following values:
  1631. * @arg TIM_TIM2_TI4_GPIO: TIM2 TI4 is connected to GPIO
  1632. * @arg TIM_TIM2_TI4_COMP1: TIM2 TI4 is connected to COMP1 output
  1633. * @arg TIM_TIM2_TI4_COMP2: TIM2 TI4 is connected to COMP2 output
  1634. * @arg TIM_TIM2_TI4_COMP1_COMP2: TIM2 TI4 is connected to logical OR between COMP1 and COMP2 output
  1635. @endif
  1636. @if STM32L443xx
  1637. * For TIM2, the parameter is a combination of 3 fields (field1 | field2 | field3):
  1638. *
  1639. * field1 can have the following values:
  1640. * @arg TIM_TIM2_ITR1_NONE: No internal trigger on TIM2_ITR1
  1641. * @arg TIM_TIM2_ITR1_USB_SOF: TIM2_ITR1 is connected to USB SOF
  1642. *
  1643. * field2 can have the following values:
  1644. * @arg TIM_TIM2_ETR_GPIO: TIM2_ETR is connected to GPIO
  1645. * @arg TIM_TIM2_ETR_LSE: TIM2_ETR is connected to LSE
  1646. * @arg TIM_TIM2_ETR_COMP1: TIM2_ETR is connected to COMP1 output
  1647. * @arg TIM_TIM2_ETR_COMP2: TIM2_ETR is connected to COMP2 output
  1648. *
  1649. * field3 can have the following values:
  1650. * @arg TIM_TIM2_TI4_GPIO: TIM2 TI4 is connected to GPIO
  1651. * @arg TIM_TIM2_TI4_COMP1: TIM2 TI4 is connected to COMP1 output
  1652. * @arg TIM_TIM2_TI4_COMP2: TIM2 TI4 is connected to COMP2 output
  1653. * @arg TIM_TIM2_TI4_COMP1_COMP2: TIM2 TI4 is connected to logical OR between COMP1 and COMP2 output
  1654. *
  1655. @endif
  1656. @if STM32L486xx
  1657. * For TIM3, the parameter is a combination 2 fields(field1 | field2):
  1658. *
  1659. * field1 can have the following values:
  1660. * @arg TIM_TIM3_TI1_GPIO: TIM3 TI1 is connected to GPIO
  1661. * @arg TIM_TIM3_TI1_COMP1: TIM3 TI1 is connected to COMP1 output
  1662. * @arg TIM_TIM3_TI1_COMP2: TIM3 TI1 is connected to COMP2 output
  1663. * @arg TIM_TIM3_TI1_COMP1_COMP2: TIM3 TI1 is connected to logical OR between COMP1 and COMP2 output
  1664. *
  1665. * field2 can have the following values:
  1666. * @arg TIM_TIM3_ETR_GPIO: TIM3_ETR is connected to GPIO
  1667. * @arg TIM_TIM3_ETR_COMP1: TIM3_ETR is connected to COMP1 output
  1668. *
  1669. @endif
  1670. @if STM32L486xx
  1671. * For TIM8, the parameter is a combination of 3 fields (field1 | field2 | field3):
  1672. *
  1673. * field1 can have the following values:
  1674. * @arg TIM_TIM8_ETR_ADC2_NONE: TIM8_ETR is not connected to any ADC2 AWD (analog watchdog)
  1675. * @arg TIM_TIM8_ETR_ADC2_AWD1: TIM8_ETR is connected to ADC2 AWD1
  1676. * @arg TIM_TIM8_ETR_ADC2_AWD2: TIM8_ETR is connected to ADC2 AWD2
  1677. * @arg TIM_TIM8_ETR_ADC2_AWD3: TIM8_ETR is connected to ADC2 AWD3
  1678. *
  1679. * field2 can have the following values:
  1680. * @arg TIM_TIM8_ETR_ADC3_NONE: TIM8_ETR is not connected to any ADC3 AWD (analog watchdog)
  1681. * @arg TIM_TIM8_ETR_ADC3_AWD1: TIM8_ETR is connected to ADC3 AWD1
  1682. * @arg TIM_TIM8_ETR_ADC3_AWD2: TIM8_ETR is connected to ADC3 AWD2
  1683. * @arg TIM_TIM8_ETR_ADC3_AWD3: TIM8_ETR is connected to ADC3 AWD3
  1684. *
  1685. * field3 can have the following values:
  1686. * @arg TIM_TIM8_TI1_GPIO: TIM8 TI1 is connected to GPIO
  1687. * @arg TIM_TIM8_TI1_COMP2: TIM8 TI1 is connected to COMP2 output
  1688. *
  1689. * field4 can have the following values:
  1690. * @arg TIM_TIM8_ETR_COMP1: TIM8_ETR is connected to COMP1 output
  1691. * @arg TIM_TIM8_ETR_COMP2: TIM8_ETR is connected to COMP2 output
  1692. * @note When field4 is set to TIM_TIM8_ETR_COMP1 or TIM_TIM8_ETR_COMP2 field1 and field2 values are not significant
  1693. *
  1694. @endif
  1695. * For TIM15, the parameter is a combination of 3 fields (field1 | field2):
  1696. *
  1697. * field1 can have the following values:
  1698. * @arg TIM_TIM15_TI1_GPIO: TIM15 TI1 is connected to GPIO
  1699. * @arg TIM_TIM15_TI1_LSE: TIM15 TI1 is connected to LSE
  1700. *
  1701. * field2 can have the following values:
  1702. * @arg TIM_TIM15_ENCODERMODE_NONE: No redirection
  1703. * @arg TIM_TIM15_ENCODERMODE_TIM2: TIM2 IC1 and TIM2 IC2 are connected to TIM15 IC1 and TIM15 IC2 respectively
  1704. * @arg TIM_TIM15_ENCODERMODE_TIM3: TIM3 IC1 and TIM3 IC2 are connected to TIM15 IC1 and TIM15 IC2 respectively
  1705. * @arg TIM_TIM15_ENCODERMODE_TIM4: TIM4 IC1 and TIM4 IC2 are connected to TIM15 IC1 and TIM15 IC2 respectively
  1706. *
  1707. @if STM32L486xx
  1708. * @arg TIM_TIM16_TI1_GPIO: TIM16 TI1 is connected to GPIO
  1709. * @arg TIM_TIM16_TI1_LSI: TIM16 TI1 is connected to LSI
  1710. * @arg TIM_TIM16_TI1_LSE: TIM16 TI1 is connected to LSE
  1711. * @arg TIM_TIM16_TI1_RTC: TIM16 TI1 is connected to RTC wakeup interrupt
  1712. *
  1713. @endif
  1714. @if STM32L443xx
  1715. * For TIM16, the parameter can have the following values:
  1716. * @arg TIM_TIM16_TI1_GPIO: TIM16 TI1 is connected to GPIO
  1717. * @arg TIM_TIM16_TI1_LSI: TIM16 TI1 is connected to LSI
  1718. * @arg TIM_TIM16_TI1_LSE: TIM16 TI1 is connected to LSE
  1719. * @arg TIM_TIM16_TI1_RTC: TIM16 TI1 is connected to RTC wakeup interrupt
  1720. * @arg TIM_TIM16_TI1_MSI: TIM16 TI1 is connected to MSI (contraints: MSI clock < 1/4 TIM APB clock)
  1721. * @arg TIM_TIM16_TI1_HSE_32: TIM16 TI1 is connected to HSE div 32 (note that HSE div 32 must be selected as RTC clock source)
  1722. * @arg TIM_TIM16_TI1_MCO: TIM16 TI1 is connected to MCO
  1723. *
  1724. @endif
  1725. @if STM32L486xx
  1726. * For TIM17, the parameter can have the following values:
  1727. * @arg TIM_TIM17_TI1_GPIO: TIM17 TI1 is connected to GPIO
  1728. * @arg TIM_TIM17_TI1_MSI: TIM17 TI1 is connected to MSI (contraints: MSI clock < 1/4 TIM APB clock)
  1729. * @arg TIM_TIM17_TI1_HSE_32: TIM17 TI1 is connected to HSE div 32
  1730. * @arg TIM_TIM17_TI1_MCO: TIM17 TI1 is connected to MCO
  1731. @endif
  1732. *
  1733. * @retval HAL status
  1734. */
  1735. HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap)
  1736. {
  1737. uint32_t tmpor1 = 0;
  1738. uint32_t tmpor2 = 0;
  1739. __HAL_LOCK(htim);
  1740. /* Check parameters */
  1741. assert_param(IS_TIM_REMAP_INSTANCE(htim->Instance));
  1742. assert_param(IS_TIM_REMAP(Remap));
  1743. /* Set ETR_SEL bit field (if required) */
  1744. if (IS_TIM_ETRSEL_INSTANCE(htim->Instance))
  1745. {
  1746. tmpor2 = htim->Instance->OR2;
  1747. tmpor2 &= ~TIMx_ETRSEL_MASK;
  1748. tmpor2 |= (Remap & TIMx_ETRSEL_MASK);
  1749. /* Set TIMx_OR2 */
  1750. htim->Instance->OR2 = tmpor2;
  1751. }
  1752. /* Set other remapping capabilities */
  1753. tmpor1 = Remap;
  1754. tmpor1 &= ~TIMx_ETRSEL_MASK;
  1755. /* Set TIMx_OR1 */
  1756. htim->Instance->OR1 = Remap;
  1757. /* Set TIMx_OR1 */
  1758. htim->Instance->OR1 = tmpor1;
  1759. htim->State = HAL_TIM_STATE_READY;
  1760. __HAL_UNLOCK(htim);
  1761. return HAL_OK;
  1762. }
  1763. /**
  1764. * @brief Group channel 5 and channel 1, 2 or 3
  1765. * @param htim: TIM handle.
  1766. * @param Channels: specifies the reference signal(s) the OC5REF is combined with.
  1767. * This parameter can be any combination of the following values:
  1768. * TIM_GROUPCH5_NONE: No effect of OC5REF on OC1REFC, OC2REFC and OC3REFC
  1769. * TIM_GROUPCH5_OC1REFC: OC1REFC is the logical AND of OC1REFC and OC5REF
  1770. * TIM_GROUPCH5_OC2REFC: OC2REFC is the logical AND of OC2REFC and OC5REF
  1771. * TIM_GROUPCH5_OC3REFC: OC3REFC is the logical AND of OC3REFC and OC5REF
  1772. * @retval HAL status
  1773. */
  1774. HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t Channels)
  1775. {
  1776. /* Check parameters */
  1777. assert_param(IS_TIM_COMBINED3PHASEPWM_INSTANCE(htim->Instance));
  1778. assert_param(IS_TIM_GROUPCH5(Channels));
  1779. /* Process Locked */
  1780. __HAL_LOCK(htim);
  1781. htim->State = HAL_TIM_STATE_BUSY;
  1782. /* Clear GC5Cx bit fields */
  1783. htim->Instance->CCR5 &= ~(TIM_CCR5_GC5C3|TIM_CCR5_GC5C2|TIM_CCR5_GC5C1);
  1784. /* Set GC5Cx bit fields */
  1785. htim->Instance->CCR5 |= Channels;
  1786. htim->State = HAL_TIM_STATE_READY;
  1787. __HAL_UNLOCK(htim);
  1788. return HAL_OK;
  1789. }
  1790. /**
  1791. * @}
  1792. */
  1793. /** @defgroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions
  1794. * @brief Extended Callbacks functions
  1795. *
  1796. @verbatim
  1797. ==============================================================================
  1798. ##### Extended Callbacks functions #####
  1799. ==============================================================================
  1800. [..]
  1801. This section provides Extended TIM callback functions:
  1802. (+) Timer Commutation callback
  1803. (+) Timer Break callback
  1804. @endverbatim
  1805. * @{
  1806. */
  1807. /**
  1808. * @brief Hall commutation changed callback in non-blocking mode
  1809. * @param htim : TIM handle
  1810. * @retval None
  1811. */
  1812. __weak void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim)
  1813. {
  1814. /* Prevent unused argument(s) compilation warning */
  1815. UNUSED(htim);
  1816. /* NOTE : This function should not be modified, when the callback is needed,
  1817. the HAL_TIMEx_CommutationCallback could be implemented in the user file
  1818. */
  1819. }
  1820. /**
  1821. * @brief Hall Break detection callback in non-blocking mode
  1822. * @param htim : TIM handle
  1823. * @retval None
  1824. */
  1825. __weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
  1826. {
  1827. /* Prevent unused argument(s) compilation warning */
  1828. UNUSED(htim);
  1829. /* NOTE : This function should not be modified, when the callback is needed,
  1830. the HAL_TIMEx_BreakCallback could be implemented in the user file
  1831. */
  1832. }
  1833. /**
  1834. * @}
  1835. */
  1836. /** @defgroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions
  1837. * @brief Extended Peripheral State functions
  1838. *
  1839. @verbatim
  1840. ==============================================================================
  1841. ##### Extended Peripheral State functions #####
  1842. ==============================================================================
  1843. [..]
  1844. This subsection permits to get in run-time the status of the peripheral
  1845. and the data flow.
  1846. @endverbatim
  1847. * @{
  1848. */
  1849. /**
  1850. * @brief Return the TIM Hall Sensor interface handle state.
  1851. * @param htim: TIM Hall Sensor handle
  1852. * @retval HAL state
  1853. */
  1854. HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
  1855. {
  1856. return htim->State;
  1857. }
  1858. /**
  1859. * @}
  1860. */
  1861. /**
  1862. * @brief TIM DMA Commutation callback.
  1863. * @param hdma : pointer to DMA handle.
  1864. * @retval None
  1865. */
  1866. void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
  1867. {
  1868. TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  1869. htim->State= HAL_TIM_STATE_READY;
  1870. HAL_TIMEx_CommutationCallback(htim);
  1871. }
  1872. /**
  1873. * @brief Enables or disables the TIM Capture Compare Channel xN.
  1874. * @param TIMx to select the TIM peripheral
  1875. * @param Channel: specifies the TIM Channel
  1876. * This parameter can be one of the following values:
  1877. * @arg TIM_Channel_1: TIM Channel 1
  1878. * @arg TIM_Channel_2: TIM Channel 2
  1879. * @arg TIM_Channel_3: TIM Channel 3
  1880. * @param ChannelNState: specifies the TIM Channel CCxNE bit new state.
  1881. * This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable.
  1882. * @retval None
  1883. */
  1884. static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState)
  1885. {
  1886. uint32_t tmp = 0;
  1887. tmp = TIM_CCER_CC1NE << Channel;
  1888. /* Reset the CCxNE Bit */
  1889. TIMx->CCER &= ~tmp;
  1890. /* Set or reset the CCxNE Bit */
  1891. TIMx->CCER |= (uint32_t)(ChannelNState << Channel);
  1892. }
  1893. /**
  1894. * @}
  1895. */
  1896. #endif /* HAL_TIM_MODULE_ENABLED */
  1897. /**
  1898. * @}
  1899. */
  1900. /**
  1901. * @}
  1902. */
  1903. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/