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.
 
 
 

1897 lines
65 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_tim_ex.c
  4. * @author MCD Application Team
  5. * @version V1.7.1
  6. * @date 14-April-2017
  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 Hall Sensor Interface Initialization
  11. * + Time Hall Sensor Interface Start
  12. * + Time Complementary signal bread and dead time configuration
  13. * + Time Master and Slave synchronization configuration
  14. @verbatim
  15. ==============================================================================
  16. ##### TIMER Extended features #####
  17. ==============================================================================
  18. [..]
  19. The Timer Extension features include:
  20. (#) Complementary outputs with programmable dead-time for :
  21. (++) Input Capture
  22. (++) Output Compare
  23. (++) PWM generation (Edge and Center-aligned Mode)
  24. (++) One-pulse mode output
  25. (#) Synchronization circuit to control the timer with external signals and to
  26. interconnect several timers together.
  27. (#) Break input to put the timer output signals in reset state or in a known state.
  28. (#) Supports incremental (quadrature) encoder and hall-sensor circuitry for
  29. positioning purposes
  30. ##### How to use this driver #####
  31. ==============================================================================
  32. [..]
  33. (#) Initialize the TIM low level resources by implementing the following functions
  34. depending from feature used :
  35. (++) Complementary Output Compare : HAL_TIM_OC_MspInit()
  36. (++) Complementary PWM generation : HAL_TIM_PWM_MspInit()
  37. (++) Complementary One-pulse mode output : HAL_TIM_OnePulse_MspInit()
  38. (++) Hall Sensor output : HAL_TIM_HallSensor_MspInit()
  39. (#) Initialize the TIM low level resources :
  40. (##) Enable the TIM interface clock using __TIMx_CLK_ENABLE();
  41. (##) TIM pins configuration
  42. (+++) Enable the clock for the TIM GPIOs using the following function:
  43. __GPIOx_CLK_ENABLE();
  44. (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
  45. (#) The external Clock can be configured, if needed (the default clock is the
  46. internal clock from the APBx), using the following function:
  47. HAL_TIM_ConfigClockSource, the clock configuration should be done before
  48. any start function.
  49. (#) Configure the TIM in the desired functioning mode using one of the
  50. initialization function of this driver:
  51. (++) HAL_TIMEx_HallSensor_Init and HAL_TIMEx_ConfigCommutationEvent: to use the
  52. Timer Hall Sensor Interface and the commutation event with the corresponding
  53. Interrupt and DMA request if needed (Note that One Timer is used to interface
  54. with the Hall sensor Interface and another Timer should be used to use
  55. the commutation event).
  56. (#) Activate the TIM peripheral using one of the start functions:
  57. (++) Complementary Output Compare : HAL_TIMEx_OCN_Start(), HAL_TIMEx_OCN_Start_DMA(), HAL_TIMEx_OC_Start_IT()
  58. (++) Complementary PWM generation : HAL_TIMEx_PWMN_Start(), HAL_TIMEx_PWMN_Start_DMA(), HAL_TIMEx_PWMN_Start_IT()
  59. (++) Complementary One-pulse mode output : HAL_TIMEx_OnePulseN_Start(), HAL_TIMEx_OnePulseN_Start_IT()
  60. (++) Hall Sensor output : HAL_TIMEx_HallSensor_Start(), HAL_TIMEx_HallSensor_Start_DMA(), HAL_TIMEx_HallSensor_Start_IT().
  61. @endverbatim
  62. ******************************************************************************
  63. * @attention
  64. *
  65. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  66. *
  67. * Redistribution and use in source and binary forms, with or without modification,
  68. * are permitted provided that the following conditions are met:
  69. * 1. Redistributions of source code must retain the above copyright notice,
  70. * this list of conditions and the following disclaimer.
  71. * 2. Redistributions in binary form must reproduce the above copyright notice,
  72. * this list of conditions and the following disclaimer in the documentation
  73. * and/or other materials provided with the distribution.
  74. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  75. * may be used to endorse or promote products derived from this software
  76. * without specific prior written permission.
  77. *
  78. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  79. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  80. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  81. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  82. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  83. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  84. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  85. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  86. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  87. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  88. *
  89. ******************************************************************************
  90. */
  91. /* Includes ------------------------------------------------------------------*/
  92. #include "stm32f4xx_hal.h"
  93. /** @addtogroup STM32F4xx_HAL_Driver
  94. * @{
  95. */
  96. /** @defgroup TIMEx TIMEx
  97. * @brief TIM HAL module driver
  98. * @{
  99. */
  100. #ifdef HAL_TIM_MODULE_ENABLED
  101. /* Private typedef -----------------------------------------------------------*/
  102. /* Private define ------------------------------------------------------------*/
  103. /* Private macro -------------------------------------------------------------*/
  104. /* Private variables ---------------------------------------------------------*/
  105. /** @addtogroup TIMEx_Private_Functions
  106. * @{
  107. */
  108. /* Private function prototypes -----------------------------------------------*/
  109. static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState);
  110. /**
  111. * @}
  112. */
  113. /* Exported functions --------------------------------------------------------*/
  114. /** @defgroup TIMEx_Exported_Functions TIM Exported Functions
  115. * @{
  116. */
  117. /** @defgroup TIMEx_Exported_Functions_Group1 Timer Hall Sensor functions
  118. * @brief Timer Hall Sensor functions
  119. *
  120. @verbatim
  121. ==============================================================================
  122. ##### Timer Hall Sensor functions #####
  123. ==============================================================================
  124. [..]
  125. This section provides functions allowing to:
  126. (+) Initialize and configure TIM HAL Sensor.
  127. (+) De-initialize TIM HAL Sensor.
  128. (+) Start the Hall Sensor Interface.
  129. (+) Stop the Hall Sensor Interface.
  130. (+) Start the Hall Sensor Interface and enable interrupts.
  131. (+) Stop the Hall Sensor Interface and disable interrupts.
  132. (+) Start the Hall Sensor Interface and enable DMA transfers.
  133. (+) Stop the Hall Sensor Interface and disable DMA transfers.
  134. @endverbatim
  135. * @{
  136. */
  137. /**
  138. * @brief Initializes the TIM Hall Sensor Interface and create the associated handle.
  139. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  140. * the configuration information for TIM module.
  141. * @param sConfig: TIM Hall Sensor configuration structure
  142. * @retval HAL status
  143. */
  144. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef* sConfig)
  145. {
  146. TIM_OC_InitTypeDef OC_Config;
  147. /* Check the TIM handle allocation */
  148. if(htim == NULL)
  149. {
  150. return HAL_ERROR;
  151. }
  152. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  153. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  154. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  155. assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));
  156. assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
  157. assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
  158. /* Set the TIM state */
  159. htim->State= HAL_TIM_STATE_BUSY;
  160. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  161. HAL_TIMEx_HallSensor_MspInit(htim);
  162. /* Configure the Time base in the Encoder Mode */
  163. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  164. /* Configure the Channel 1 as Input Channel to interface with the three Outputs of the Hall sensor */
  165. TIM_TI1_SetConfig(htim->Instance, sConfig->IC1Polarity, TIM_ICSELECTION_TRC, sConfig->IC1Filter);
  166. /* Reset the IC1PSC Bits */
  167. htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
  168. /* Set the IC1PSC value */
  169. htim->Instance->CCMR1 |= sConfig->IC1Prescaler;
  170. /* Enable the Hall sensor interface (XOR function of the three inputs) */
  171. htim->Instance->CR2 |= TIM_CR2_TI1S;
  172. /* Select the TIM_TS_TI1F_ED signal as Input trigger for the TIM */
  173. htim->Instance->SMCR &= ~TIM_SMCR_TS;
  174. htim->Instance->SMCR |= TIM_TS_TI1F_ED;
  175. /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */
  176. htim->Instance->SMCR &= ~TIM_SMCR_SMS;
  177. htim->Instance->SMCR |= TIM_SLAVEMODE_RESET;
  178. /* Program channel 2 in PWM 2 mode with the desired Commutation_Delay*/
  179. OC_Config.OCFastMode = TIM_OCFAST_DISABLE;
  180. OC_Config.OCIdleState = TIM_OCIDLESTATE_RESET;
  181. OC_Config.OCMode = TIM_OCMODE_PWM2;
  182. OC_Config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
  183. OC_Config.OCNPolarity = TIM_OCNPOLARITY_HIGH;
  184. OC_Config.OCPolarity = TIM_OCPOLARITY_HIGH;
  185. OC_Config.Pulse = sConfig->Commutation_Delay;
  186. TIM_OC2_SetConfig(htim->Instance, &OC_Config);
  187. /* Select OC2REF as trigger output on TRGO: write the MMS bits in the TIMx_CR2
  188. register to 101 */
  189. htim->Instance->CR2 &= ~TIM_CR2_MMS;
  190. htim->Instance->CR2 |= TIM_TRGO_OC2REF;
  191. /* Initialize the TIM state*/
  192. htim->State= HAL_TIM_STATE_READY;
  193. return HAL_OK;
  194. }
  195. /**
  196. * @brief DeInitializes the TIM Hall Sensor interface
  197. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  198. * the configuration information for TIM module.
  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: pointer to a TIM_HandleTypeDef structure that contains
  219. * the configuration information for TIM module.
  220. * @retval None
  221. */
  222. __weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
  223. {
  224. /* Prevent unused argument(s) compilation warning */
  225. UNUSED(htim);
  226. /* NOTE : This function Should not be modified, when the callback is needed,
  227. the HAL_TIMEx_HallSensor_MspInit could be implemented in the user file
  228. */
  229. }
  230. /**
  231. * @brief DeInitializes TIM Hall Sensor MSP.
  232. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  233. * the configuration information for TIM module.
  234. * @retval None
  235. */
  236. __weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
  237. {
  238. /* Prevent unused argument(s) compilation warning */
  239. UNUSED(htim);
  240. /* NOTE : This function Should not be modified, when the callback is needed,
  241. the HAL_TIMEx_HallSensor_MspDeInit could be implemented in the user file
  242. */
  243. }
  244. /**
  245. * @brief Starts the TIM Hall Sensor Interface.
  246. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  247. * the configuration information for TIM module.
  248. * @retval HAL status
  249. */
  250. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)
  251. {
  252. /* Check the parameters */
  253. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  254. /* Enable the Input Capture channels 1
  255. (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
  256. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  257. /* Enable the Peripheral */
  258. __HAL_TIM_ENABLE(htim);
  259. /* Return function status */
  260. return HAL_OK;
  261. }
  262. /**
  263. * @brief Stops the TIM Hall sensor Interface.
  264. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  265. * the configuration information for TIM module.
  266. * @retval HAL status
  267. */
  268. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)
  269. {
  270. /* Check the parameters */
  271. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  272. /* Disable the Input Capture channels 1, 2 and 3
  273. (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
  274. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  275. /* Disable the Peripheral */
  276. __HAL_TIM_DISABLE(htim);
  277. /* Return function status */
  278. return HAL_OK;
  279. }
  280. /**
  281. * @brief Starts the TIM Hall Sensor Interface in interrupt mode.
  282. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  283. * the configuration information for TIM module.
  284. * @retval HAL status
  285. */
  286. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)
  287. {
  288. /* Check the parameters */
  289. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  290. /* Enable the capture compare Interrupts 1 event */
  291. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  292. /* Enable the Input Capture channels 1
  293. (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
  294. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  295. /* Enable the Peripheral */
  296. __HAL_TIM_ENABLE(htim);
  297. /* Return function status */
  298. return HAL_OK;
  299. }
  300. /**
  301. * @brief Stops the TIM Hall Sensor Interface in interrupt mode.
  302. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  303. * the configuration information for TIM module.
  304. * @retval HAL status
  305. */
  306. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim)
  307. {
  308. /* Check the parameters */
  309. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  310. /* Disable the Input Capture channels 1
  311. (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
  312. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  313. /* Disable the capture compare Interrupts event */
  314. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  315. /* Disable the Peripheral */
  316. __HAL_TIM_DISABLE(htim);
  317. /* Return function status */
  318. return HAL_OK;
  319. }
  320. /**
  321. * @brief Starts the TIM Hall Sensor Interface in DMA mode.
  322. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  323. * the configuration information for TIM module.
  324. * @param pData: The destination Buffer address.
  325. * @param Length: The length of data to be transferred from TIM peripheral to memory.
  326. * @retval HAL status
  327. */
  328. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
  329. {
  330. /* Check the parameters */
  331. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  332. if((htim->State == HAL_TIM_STATE_BUSY))
  333. {
  334. return HAL_BUSY;
  335. }
  336. else if((htim->State == HAL_TIM_STATE_READY))
  337. {
  338. if(((uint32_t)pData == 0U) && (Length > 0))
  339. {
  340. return HAL_ERROR;
  341. }
  342. else
  343. {
  344. htim->State = HAL_TIM_STATE_BUSY;
  345. }
  346. }
  347. /* Enable the Input Capture channels 1
  348. (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
  349. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  350. /* Set the DMA Input Capture 1 Callback */
  351. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
  352. /* Set the DMA error callback */
  353. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
  354. /* Enable the DMA Stream for Capture 1*/
  355. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length);
  356. /* Enable the capture compare 1 Interrupt */
  357. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  358. /* Enable the Peripheral */
  359. __HAL_TIM_ENABLE(htim);
  360. /* Return function status */
  361. return HAL_OK;
  362. }
  363. /**
  364. * @brief Stops the TIM Hall Sensor Interface in DMA mode.
  365. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  366. * the configuration information for TIM module.
  367. * @retval HAL status
  368. */
  369. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
  370. {
  371. /* Check the parameters */
  372. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  373. /* Disable the Input Capture channels 1
  374. (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
  375. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  376. /* Disable the capture compare Interrupts 1 event */
  377. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  378. /* Disable the Peripheral */
  379. __HAL_TIM_DISABLE(htim);
  380. /* Return function status */
  381. return HAL_OK;
  382. }
  383. /**
  384. * @}
  385. */
  386. /** @defgroup TIMEx_Exported_Functions_Group2 Timer Complementary Output Compare functions
  387. * @brief Timer Complementary Output Compare functions
  388. *
  389. @verbatim
  390. ==============================================================================
  391. ##### Timer Complementary Output Compare functions #####
  392. ==============================================================================
  393. [..]
  394. This section provides functions allowing to:
  395. (+) Start the Complementary Output Compare/PWM.
  396. (+) Stop the Complementary Output Compare/PWM.
  397. (+) Start the Complementary Output Compare/PWM and enable interrupts.
  398. (+) Stop the Complementary Output Compare/PWM and disable interrupts.
  399. (+) Start the Complementary Output Compare/PWM and enable DMA transfers.
  400. (+) Stop the Complementary Output Compare/PWM and disable DMA transfers.
  401. @endverbatim
  402. * @{
  403. */
  404. /**
  405. * @brief Starts the TIM Output Compare signal generation on the complementary
  406. * output.
  407. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  408. * the configuration information for TIM module.
  409. * @param Channel: TIM Channel to be enabled.
  410. * This parameter can be one of the following values:
  411. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  412. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  413. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  414. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  415. * @retval HAL status
  416. */
  417. HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
  418. {
  419. /* Check the parameters */
  420. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  421. /* Enable the Capture compare channel N */
  422. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
  423. /* Enable the Main Output */
  424. __HAL_TIM_MOE_ENABLE(htim);
  425. /* Enable the Peripheral */
  426. __HAL_TIM_ENABLE(htim);
  427. /* Return function status */
  428. return HAL_OK;
  429. }
  430. /**
  431. * @brief Stops the TIM Output Compare signal generation on the complementary
  432. * output.
  433. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  434. * the configuration information for TIM module.
  435. * @param Channel: TIM Channel to be disabled.
  436. * This parameter can be one of the following values:
  437. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  438. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  439. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  440. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  441. * @retval HAL status
  442. */
  443. HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
  444. {
  445. /* Check the parameters */
  446. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  447. /* Disable the Capture compare channel N */
  448. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
  449. /* Disable the Main Output */
  450. __HAL_TIM_MOE_DISABLE(htim);
  451. /* Disable the Peripheral */
  452. __HAL_TIM_DISABLE(htim);
  453. /* Return function status */
  454. return HAL_OK;
  455. }
  456. /**
  457. * @brief Starts the TIM Output Compare signal generation in interrupt mode
  458. * on the complementary output.
  459. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  460. * the configuration information for TIM module.
  461. * @param Channel: TIM Channel to be enabled.
  462. * This parameter can be one of the following values:
  463. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  464. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  465. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  466. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  467. * @retval HAL status
  468. */
  469. HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  470. {
  471. /* Check the parameters */
  472. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  473. switch (Channel)
  474. {
  475. case TIM_CHANNEL_1:
  476. {
  477. /* Enable the TIM Output Compare interrupt */
  478. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  479. }
  480. break;
  481. case TIM_CHANNEL_2:
  482. {
  483. /* Enable the TIM Output Compare interrupt */
  484. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  485. }
  486. break;
  487. case TIM_CHANNEL_3:
  488. {
  489. /* Enable the TIM Output Compare interrupt */
  490. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
  491. }
  492. break;
  493. case TIM_CHANNEL_4:
  494. {
  495. /* Enable the TIM Output Compare interrupt */
  496. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
  497. }
  498. break;
  499. default:
  500. break;
  501. }
  502. /* Enable the TIM Break interrupt */
  503. __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
  504. /* Enable the Capture compare channel N */
  505. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
  506. /* Enable the Main Output */
  507. __HAL_TIM_MOE_ENABLE(htim);
  508. /* Enable the Peripheral */
  509. __HAL_TIM_ENABLE(htim);
  510. /* Return function status */
  511. return HAL_OK;
  512. }
  513. /**
  514. * @brief Stops the TIM Output Compare signal generation in interrupt mode
  515. * on the complementary output.
  516. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  517. * the configuration information for TIM module.
  518. * @param Channel: TIM Channel to be disabled.
  519. * This parameter can be one of the following values:
  520. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  521. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  522. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  523. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  524. * @retval HAL status
  525. */
  526. HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  527. {
  528. /* Check the parameters */
  529. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  530. switch (Channel)
  531. {
  532. case TIM_CHANNEL_1:
  533. {
  534. /* Disable the TIM Output Compare interrupt */
  535. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  536. }
  537. break;
  538. case TIM_CHANNEL_2:
  539. {
  540. /* Disable the TIM Output Compare interrupt */
  541. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  542. }
  543. break;
  544. case TIM_CHANNEL_3:
  545. {
  546. /* Disable the TIM Output Compare interrupt */
  547. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
  548. }
  549. break;
  550. case TIM_CHANNEL_4:
  551. {
  552. /* Disable the TIM Output Compare interrupt */
  553. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
  554. }
  555. break;
  556. default:
  557. break;
  558. }
  559. /* Disable the Capture compare channel N */
  560. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
  561. /* Disable the TIM Break interrupt (only if no more channel is active) */
  562. if((READ_REG(htim->Instance->CCER) & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
  563. {
  564. __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
  565. }
  566. /* Disable the Main Output */
  567. __HAL_TIM_MOE_DISABLE(htim);
  568. /* Disable the Peripheral */
  569. __HAL_TIM_DISABLE(htim);
  570. /* Return function status */
  571. return HAL_OK;
  572. }
  573. /**
  574. * @brief Starts the TIM Output Compare signal generation in DMA mode
  575. * on the complementary output.
  576. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  577. * the configuration information for TIM module.
  578. * @param Channel: TIM Channel to be enabled.
  579. * This parameter can be one of the following values:
  580. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  581. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  582. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  583. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  584. * @param pData: The source Buffer address.
  585. * @param Length: The length of data to be transferred from memory to TIM peripheral
  586. * @retval HAL status
  587. */
  588. HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
  589. {
  590. /* Check the parameters */
  591. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  592. if((htim->State == HAL_TIM_STATE_BUSY))
  593. {
  594. return HAL_BUSY;
  595. }
  596. else if((htim->State == HAL_TIM_STATE_READY))
  597. {
  598. if(((uint32_t)pData == 0U) && (Length > 0))
  599. {
  600. return HAL_ERROR;
  601. }
  602. else
  603. {
  604. htim->State = HAL_TIM_STATE_BUSY;
  605. }
  606. }
  607. switch (Channel)
  608. {
  609. case TIM_CHANNEL_1:
  610. {
  611. /* Set the DMA Period elapsed callback */
  612. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
  613. /* Set the DMA error callback */
  614. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
  615. /* Enable the DMA Stream */
  616. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
  617. /* Enable the TIM Output Compare DMA request */
  618. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  619. }
  620. break;
  621. case TIM_CHANNEL_2:
  622. {
  623. /* Set the DMA Period elapsed callback */
  624. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
  625. /* Set the DMA error callback */
  626. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
  627. /* Enable the DMA Stream */
  628. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
  629. /* Enable the TIM Output Compare DMA request */
  630. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  631. }
  632. break;
  633. case TIM_CHANNEL_3:
  634. {
  635. /* Set the DMA Period elapsed callback */
  636. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
  637. /* Set the DMA error callback */
  638. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
  639. /* Enable the DMA Stream */
  640. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
  641. /* Enable the TIM Output Compare DMA request */
  642. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
  643. }
  644. break;
  645. case TIM_CHANNEL_4:
  646. {
  647. /* Set the DMA Period elapsed callback */
  648. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
  649. /* Set the DMA error callback */
  650. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
  651. /* Enable the DMA Stream */
  652. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
  653. /* Enable the TIM Output Compare DMA request */
  654. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
  655. }
  656. break;
  657. default:
  658. break;
  659. }
  660. /* Enable the Capture compare channel N */
  661. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
  662. /* Enable the Main Output */
  663. __HAL_TIM_MOE_ENABLE(htim);
  664. /* Enable the Peripheral */
  665. __HAL_TIM_ENABLE(htim);
  666. /* Return function status */
  667. return HAL_OK;
  668. }
  669. /**
  670. * @brief Stops the TIM Output Compare signal generation in DMA mode
  671. * on the complementary output.
  672. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  673. * the configuration information for TIM module.
  674. * @param Channel: TIM Channel to be disabled.
  675. * This parameter can be one of the following values:
  676. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  677. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  678. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  679. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  680. * @retval HAL status
  681. */
  682. HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
  683. {
  684. /* Check the parameters */
  685. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  686. switch (Channel)
  687. {
  688. case TIM_CHANNEL_1:
  689. {
  690. /* Disable the TIM Output Compare DMA request */
  691. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  692. }
  693. break;
  694. case TIM_CHANNEL_2:
  695. {
  696. /* Disable the TIM Output Compare DMA request */
  697. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  698. }
  699. break;
  700. case TIM_CHANNEL_3:
  701. {
  702. /* Disable the TIM Output Compare DMA request */
  703. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
  704. }
  705. break;
  706. case TIM_CHANNEL_4:
  707. {
  708. /* Disable the TIM Output Compare interrupt */
  709. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
  710. }
  711. break;
  712. default:
  713. break;
  714. }
  715. /* Disable the Capture compare channel N */
  716. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
  717. /* Disable the Main Output */
  718. __HAL_TIM_MOE_DISABLE(htim);
  719. /* Disable the Peripheral */
  720. __HAL_TIM_DISABLE(htim);
  721. /* Change the htim state */
  722. htim->State = HAL_TIM_STATE_READY;
  723. /* Return function status */
  724. return HAL_OK;
  725. }
  726. /**
  727. * @}
  728. */
  729. /** @defgroup TIMEx_Exported_Functions_Group3 Timer Complementary PWM functions
  730. * @brief Timer Complementary PWM functions
  731. *
  732. @verbatim
  733. ==============================================================================
  734. ##### Timer Complementary PWM functions #####
  735. ==============================================================================
  736. [..]
  737. This section provides functions allowing to:
  738. (+) Start the Complementary PWM.
  739. (+) Stop the Complementary PWM.
  740. (+) Start the Complementary PWM and enable interrupts.
  741. (+) Stop the Complementary PWM and disable interrupts.
  742. (+) Start the Complementary PWM and enable DMA transfers.
  743. (+) Stop the Complementary PWM and disable DMA transfers.
  744. (+) Start the Complementary Input Capture measurement.
  745. (+) Stop the Complementary Input Capture.
  746. (+) Start the Complementary Input Capture and enable interrupts.
  747. (+) Stop the Complementary Input Capture and disable interrupts.
  748. (+) Start the Complementary Input Capture and enable DMA transfers.
  749. (+) Stop the Complementary Input Capture and disable DMA transfers.
  750. (+) Start the Complementary One Pulse generation.
  751. (+) Stop the Complementary One Pulse.
  752. (+) Start the Complementary One Pulse and enable interrupts.
  753. (+) Stop the Complementary One Pulse and disable interrupts.
  754. @endverbatim
  755. * @{
  756. */
  757. /**
  758. * @brief Starts the PWM signal generation on the complementary output.
  759. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  760. * the configuration information for TIM module.
  761. * @param Channel: TIM Channel to be enabled.
  762. * This parameter can be one of the following values:
  763. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  764. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  765. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  766. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  767. * @retval HAL status
  768. */
  769. HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
  770. {
  771. /* Check the parameters */
  772. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  773. /* Enable the complementary PWM output */
  774. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
  775. /* Enable the Main Output */
  776. __HAL_TIM_MOE_ENABLE(htim);
  777. /* Enable the Peripheral */
  778. __HAL_TIM_ENABLE(htim);
  779. /* Return function status */
  780. return HAL_OK;
  781. }
  782. /**
  783. * @brief Stops the PWM signal generation on the complementary output.
  784. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  785. * the configuration information for TIM module.
  786. * @param Channel: TIM Channel to be disabled.
  787. * This parameter can be one of the following values:
  788. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  789. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  790. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  791. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  792. * @retval HAL status
  793. */
  794. HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
  795. {
  796. /* Check the parameters */
  797. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  798. /* Disable the complementary PWM output */
  799. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
  800. /* Disable the Main Output */
  801. __HAL_TIM_MOE_DISABLE(htim);
  802. /* Disable the Peripheral */
  803. __HAL_TIM_DISABLE(htim);
  804. /* Return function status */
  805. return HAL_OK;
  806. }
  807. /**
  808. * @brief Starts the PWM signal generation in interrupt mode on the
  809. * complementary output.
  810. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  811. * the configuration information for TIM module.
  812. * @param Channel: TIM Channel to be disabled.
  813. * This parameter can be one of the following values:
  814. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  815. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  816. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  817. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  818. * @retval HAL status
  819. */
  820. HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  821. {
  822. /* Check the parameters */
  823. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  824. switch (Channel)
  825. {
  826. case TIM_CHANNEL_1:
  827. {
  828. /* Enable the TIM Capture/Compare 1 interrupt */
  829. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  830. }
  831. break;
  832. case TIM_CHANNEL_2:
  833. {
  834. /* Enable the TIM Capture/Compare 2 interrupt */
  835. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  836. }
  837. break;
  838. case TIM_CHANNEL_3:
  839. {
  840. /* Enable the TIM Capture/Compare 3 interrupt */
  841. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
  842. }
  843. break;
  844. case TIM_CHANNEL_4:
  845. {
  846. /* Enable the TIM Capture/Compare 4 interrupt */
  847. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
  848. }
  849. break;
  850. default:
  851. break;
  852. }
  853. /* Enable the TIM Break interrupt */
  854. __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
  855. /* Enable the complementary PWM output */
  856. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
  857. /* Enable the Main Output */
  858. __HAL_TIM_MOE_ENABLE(htim);
  859. /* Enable the Peripheral */
  860. __HAL_TIM_ENABLE(htim);
  861. /* Return function status */
  862. return HAL_OK;
  863. }
  864. /**
  865. * @brief Stops the PWM signal generation in interrupt mode on the
  866. * complementary output.
  867. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  868. * the configuration information for TIM module.
  869. * @param Channel: TIM Channel to be disabled.
  870. * This parameter can be one of the following values:
  871. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  872. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  873. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  874. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  875. * @retval HAL status
  876. */
  877. HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
  878. {
  879. /* Check the parameters */
  880. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  881. switch (Channel)
  882. {
  883. case TIM_CHANNEL_1:
  884. {
  885. /* Disable the TIM Capture/Compare 1 interrupt */
  886. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  887. }
  888. break;
  889. case TIM_CHANNEL_2:
  890. {
  891. /* Disable the TIM Capture/Compare 2 interrupt */
  892. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  893. }
  894. break;
  895. case TIM_CHANNEL_3:
  896. {
  897. /* Disable the TIM Capture/Compare 3 interrupt */
  898. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
  899. }
  900. break;
  901. case TIM_CHANNEL_4:
  902. {
  903. /* Disable the TIM Capture/Compare 3 interrupt */
  904. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
  905. }
  906. break;
  907. default:
  908. break;
  909. }
  910. /* Disable the complementary PWM output */
  911. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
  912. /* Disable the TIM Break interrupt (only if no more channel is active) */
  913. if((READ_REG(htim->Instance->CCER) & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
  914. {
  915. __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
  916. }
  917. /* Disable the Main Output */
  918. __HAL_TIM_MOE_DISABLE(htim);
  919. /* Disable the Peripheral */
  920. __HAL_TIM_DISABLE(htim);
  921. /* Return function status */
  922. return HAL_OK;
  923. }
  924. /**
  925. * @brief Starts the TIM PWM signal generation in DMA mode on the
  926. * complementary output
  927. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  928. * the configuration information for TIM module.
  929. * @param Channel: TIM Channel to be enabled.
  930. * This parameter can be one of the following values:
  931. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  932. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  933. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  934. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  935. * @param pData: The source Buffer address.
  936. * @param Length: The length of data to be transferred from memory to TIM peripheral
  937. * @retval HAL status
  938. */
  939. HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
  940. {
  941. /* Check the parameters */
  942. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  943. if((htim->State == HAL_TIM_STATE_BUSY))
  944. {
  945. return HAL_BUSY;
  946. }
  947. else if((htim->State == HAL_TIM_STATE_READY))
  948. {
  949. if(((uint32_t)pData == 0U) && (Length > 0))
  950. {
  951. return HAL_ERROR;
  952. }
  953. else
  954. {
  955. htim->State = HAL_TIM_STATE_BUSY;
  956. }
  957. }
  958. switch (Channel)
  959. {
  960. case TIM_CHANNEL_1:
  961. {
  962. /* Set the DMA Period elapsed callback */
  963. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
  964. /* Set the DMA error callback */
  965. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
  966. /* Enable the DMA Stream */
  967. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
  968. /* Enable the TIM Capture/Compare 1 DMA request */
  969. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  970. }
  971. break;
  972. case TIM_CHANNEL_2:
  973. {
  974. /* Set the DMA Period elapsed callback */
  975. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
  976. /* Set the DMA error callback */
  977. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
  978. /* Enable the DMA Stream */
  979. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
  980. /* Enable the TIM Capture/Compare 2 DMA request */
  981. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  982. }
  983. break;
  984. case TIM_CHANNEL_3:
  985. {
  986. /* Set the DMA Period elapsed callback */
  987. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
  988. /* Set the DMA error callback */
  989. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
  990. /* Enable the DMA Stream */
  991. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
  992. /* Enable the TIM Capture/Compare 3 DMA request */
  993. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
  994. }
  995. break;
  996. case TIM_CHANNEL_4:
  997. {
  998. /* Set the DMA Period elapsed callback */
  999. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
  1000. /* Set the DMA error callback */
  1001. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
  1002. /* Enable the DMA Stream */
  1003. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
  1004. /* Enable the TIM Capture/Compare 4 DMA request */
  1005. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
  1006. }
  1007. break;
  1008. default:
  1009. break;
  1010. }
  1011. /* Enable the complementary PWM output */
  1012. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
  1013. /* Enable the Main Output */
  1014. __HAL_TIM_MOE_ENABLE(htim);
  1015. /* Enable the Peripheral */
  1016. __HAL_TIM_ENABLE(htim);
  1017. /* Return function status */
  1018. return HAL_OK;
  1019. }
  1020. /**
  1021. * @brief Stops the TIM PWM signal generation in DMA mode on the complementary
  1022. * output
  1023. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1024. * the configuration information for TIM module.
  1025. * @param Channel: TIM Channel to be disabled.
  1026. * This parameter can be one of the following values:
  1027. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1028. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1029. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1030. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1031. * @retval HAL status
  1032. */
  1033. HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
  1034. {
  1035. /* Check the parameters */
  1036. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
  1037. switch (Channel)
  1038. {
  1039. case TIM_CHANNEL_1:
  1040. {
  1041. /* Disable the TIM Capture/Compare 1 DMA request */
  1042. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  1043. }
  1044. break;
  1045. case TIM_CHANNEL_2:
  1046. {
  1047. /* Disable the TIM Capture/Compare 2 DMA request */
  1048. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  1049. }
  1050. break;
  1051. case TIM_CHANNEL_3:
  1052. {
  1053. /* Disable the TIM Capture/Compare 3 DMA request */
  1054. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
  1055. }
  1056. break;
  1057. case TIM_CHANNEL_4:
  1058. {
  1059. /* Disable the TIM Capture/Compare 4 DMA request */
  1060. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
  1061. }
  1062. break;
  1063. default:
  1064. break;
  1065. }
  1066. /* Disable the complementary PWM output */
  1067. TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
  1068. /* Disable the Main Output */
  1069. __HAL_TIM_MOE_DISABLE(htim);
  1070. /* Disable the Peripheral */
  1071. __HAL_TIM_DISABLE(htim);
  1072. /* Change the htim state */
  1073. htim->State = HAL_TIM_STATE_READY;
  1074. /* Return function status */
  1075. return HAL_OK;
  1076. }
  1077. /**
  1078. * @}
  1079. */
  1080. /** @defgroup TIMEx_Exported_Functions_Group4 Timer Complementary One Pulse functions
  1081. * @brief Timer Complementary One Pulse functions
  1082. *
  1083. @verbatim
  1084. ==============================================================================
  1085. ##### Timer Complementary One Pulse functions #####
  1086. ==============================================================================
  1087. [..]
  1088. This section provides functions allowing to:
  1089. (+) Start the Complementary One Pulse generation.
  1090. (+) Stop the Complementary One Pulse.
  1091. (+) Start the Complementary One Pulse and enable interrupts.
  1092. (+) Stop the Complementary One Pulse and disable interrupts.
  1093. @endverbatim
  1094. * @{
  1095. */
  1096. /**
  1097. * @brief Starts the TIM One Pulse signal generation on the complementary
  1098. * output.
  1099. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1100. * the configuration information for TIM module.
  1101. * @param OutputChannel: TIM Channel to be enabled.
  1102. * This parameter can be one of the following values:
  1103. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1104. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1105. * @retval HAL status
  1106. */
  1107. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  1108. {
  1109. /* Check the parameters */
  1110. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
  1111. /* Enable the complementary One Pulse output */
  1112. TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
  1113. /* Enable the Main Output */
  1114. __HAL_TIM_MOE_ENABLE(htim);
  1115. /* Return function status */
  1116. return HAL_OK;
  1117. }
  1118. /**
  1119. * @brief Stops the TIM One Pulse signal generation on the complementary
  1120. * output.
  1121. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1122. * the configuration information for TIM module.
  1123. * @param OutputChannel: TIM Channel to be disabled.
  1124. * This parameter can be one of the following values:
  1125. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1126. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1127. * @retval HAL status
  1128. */
  1129. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  1130. {
  1131. /* Check the parameters */
  1132. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
  1133. /* Disable the complementary One Pulse output */
  1134. TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
  1135. /* Disable the Main Output */
  1136. __HAL_TIM_MOE_DISABLE(htim);
  1137. /* Disable the Peripheral */
  1138. __HAL_TIM_DISABLE(htim);
  1139. /* Return function status */
  1140. return HAL_OK;
  1141. }
  1142. /**
  1143. * @brief Starts the TIM One Pulse signal generation in interrupt mode on the
  1144. * complementary channel.
  1145. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1146. * the configuration information for TIM module.
  1147. * @param OutputChannel: TIM Channel to be enabled.
  1148. * This parameter can be one of the following values:
  1149. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1150. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1151. * @retval HAL status
  1152. */
  1153. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  1154. {
  1155. /* Check the parameters */
  1156. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
  1157. /* Enable the TIM Capture/Compare 1 interrupt */
  1158. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  1159. /* Enable the TIM Capture/Compare 2 interrupt */
  1160. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  1161. /* Enable the complementary One Pulse output */
  1162. TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
  1163. /* Enable the Main Output */
  1164. __HAL_TIM_MOE_ENABLE(htim);
  1165. /* Return function status */
  1166. return HAL_OK;
  1167. }
  1168. /**
  1169. * @brief Stops the TIM One Pulse signal generation in interrupt mode on the
  1170. * complementary channel.
  1171. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1172. * the configuration information for TIM module.
  1173. * @param OutputChannel: TIM Channel to be disabled.
  1174. * This parameter can be one of the following values:
  1175. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1176. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1177. * @retval HAL status
  1178. */
  1179. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  1180. {
  1181. /* Check the parameters */
  1182. assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
  1183. /* Disable the TIM Capture/Compare 1 interrupt */
  1184. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  1185. /* Disable the TIM Capture/Compare 2 interrupt */
  1186. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  1187. /* Disable the complementary One Pulse output */
  1188. TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
  1189. /* Disable the Main Output */
  1190. __HAL_TIM_MOE_DISABLE(htim);
  1191. /* Disable the Peripheral */
  1192. __HAL_TIM_DISABLE(htim);
  1193. /* Return function status */
  1194. return HAL_OK;
  1195. }
  1196. /**
  1197. * @}
  1198. */
  1199. /** @defgroup TIMEx_Exported_Functions_Group5 Peripheral Control functions
  1200. * @brief Peripheral Control functions
  1201. *
  1202. @verbatim
  1203. ==============================================================================
  1204. ##### Peripheral Control functions #####
  1205. ==============================================================================
  1206. [..]
  1207. This section provides functions allowing to:
  1208. (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode.
  1209. (+) Configure External Clock source.
  1210. (+) Configure Complementary channels, break features and dead time.
  1211. (+) Configure Master and the Slave synchronization.
  1212. (+) Configure the commutation event in case of use of the Hall sensor interface.
  1213. (+) Configure the DMA Burst Mode.
  1214. @endverbatim
  1215. * @{
  1216. */
  1217. /**
  1218. * @brief Configure the TIM commutation event sequence.
  1219. * @note This function is mandatory to use the commutation event in order to
  1220. * update the configuration at each commutation detection on the TRGI input of the Timer,
  1221. * the typical use of this feature is with the use of another Timer(interface Timer)
  1222. * configured in Hall sensor interface, this interface Timer will generate the
  1223. * commutation at its TRGO output (connected to Timer used in this function) each time
  1224. * the TI1 of the Interface Timer detect a commutation at its input TI1.
  1225. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1226. * the configuration information for TIM module.
  1227. * @param InputTrigger: the Internal trigger corresponding to the Timer Interfacing with the Hall sensor.
  1228. * This parameter can be one of the following values:
  1229. * @arg TIM_TS_ITR0: Internal trigger 0 selected
  1230. * @arg TIM_TS_ITR1: Internal trigger 1 selected
  1231. * @arg TIM_TS_ITR2: Internal trigger 2 selected
  1232. * @arg TIM_TS_ITR3: Internal trigger 3 selected
  1233. * @arg TIM_TS_NONE: No trigger is needed
  1234. * @param CommutationSource: the Commutation Event source.
  1235. * This parameter can be one of the following values:
  1236. * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
  1237. * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
  1238. * @retval HAL status
  1239. */
  1240. HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
  1241. {
  1242. /* Check the parameters */
  1243. assert_param(IS_TIM_ADVANCED_INSTANCE(htim->Instance));
  1244. assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
  1245. __HAL_LOCK(htim);
  1246. if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
  1247. (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
  1248. {
  1249. /* Select the Input trigger */
  1250. htim->Instance->SMCR &= ~TIM_SMCR_TS;
  1251. htim->Instance->SMCR |= InputTrigger;
  1252. }
  1253. /* Select the Capture Compare preload feature */
  1254. htim->Instance->CR2 |= TIM_CR2_CCPC;
  1255. /* Select the Commutation event source */
  1256. htim->Instance->CR2 &= ~TIM_CR2_CCUS;
  1257. htim->Instance->CR2 |= CommutationSource;
  1258. __HAL_UNLOCK(htim);
  1259. return HAL_OK;
  1260. }
  1261. /**
  1262. * @brief Configure the TIM commutation event sequence with interrupt.
  1263. * @note This function is mandatory to use the commutation event in order to
  1264. * update the configuration at each commutation detection on the TRGI input of the Timer,
  1265. * the typical use of this feature is with the use of another Timer(interface Timer)
  1266. * configured in Hall sensor interface, this interface Timer will generate the
  1267. * commutation at its TRGO output (connected to Timer used in this function) each time
  1268. * the TI1 of the Interface Timer detect a commutation at its input TI1.
  1269. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1270. * the configuration information for TIM module.
  1271. * @param InputTrigger: the Internal trigger corresponding to the Timer Interfacing with the Hall sensor.
  1272. * This parameter can be one of the following values:
  1273. * @arg TIM_TS_ITR0: Internal trigger 0 selected
  1274. * @arg TIM_TS_ITR1: Internal trigger 1 selected
  1275. * @arg TIM_TS_ITR2: Internal trigger 2 selected
  1276. * @arg TIM_TS_ITR3: Internal trigger 3 selected
  1277. * @arg TIM_TS_NONE: No trigger is needed
  1278. * @param CommutationSource: the Commutation Event source.
  1279. * This parameter can be one of the following values:
  1280. * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
  1281. * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
  1282. * @retval HAL status
  1283. */
  1284. HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
  1285. {
  1286. /* Check the parameters */
  1287. assert_param(IS_TIM_ADVANCED_INSTANCE(htim->Instance));
  1288. assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
  1289. __HAL_LOCK(htim);
  1290. if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
  1291. (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
  1292. {
  1293. /* Select the Input trigger */
  1294. htim->Instance->SMCR &= ~TIM_SMCR_TS;
  1295. htim->Instance->SMCR |= InputTrigger;
  1296. }
  1297. /* Select the Capture Compare preload feature */
  1298. htim->Instance->CR2 |= TIM_CR2_CCPC;
  1299. /* Select the Commutation event source */
  1300. htim->Instance->CR2 &= ~TIM_CR2_CCUS;
  1301. htim->Instance->CR2 |= CommutationSource;
  1302. /* Enable the Commutation Interrupt Request */
  1303. __HAL_TIM_ENABLE_IT(htim, TIM_IT_COM);
  1304. __HAL_UNLOCK(htim);
  1305. return HAL_OK;
  1306. }
  1307. /**
  1308. * @brief Configure the TIM commutation event sequence with DMA.
  1309. * @note This function is mandatory to use the commutation event in order to
  1310. * update the configuration at each commutation detection on the TRGI input of the Timer,
  1311. * the typical use of this feature is with the use of another Timer(interface Timer)
  1312. * configured in Hall sensor interface, this interface Timer will generate the
  1313. * commutation at its TRGO output (connected to Timer used in this function) each time
  1314. * the TI1 of the Interface Timer detect a commutation at its input TI1.
  1315. * @note: The user should configure the DMA in his own software, in This function only the COMDE bit is set
  1316. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1317. * the configuration information for TIM module.
  1318. * @param InputTrigger: the Internal trigger corresponding to the Timer Interfacing with the Hall sensor.
  1319. * This parameter can be one of the following values:
  1320. * @arg TIM_TS_ITR0: Internal trigger 0 selected
  1321. * @arg TIM_TS_ITR1: Internal trigger 1 selected
  1322. * @arg TIM_TS_ITR2: Internal trigger 2 selected
  1323. * @arg TIM_TS_ITR3: Internal trigger 3 selected
  1324. * @arg TIM_TS_NONE: No trigger is needed
  1325. * @param CommutationSource: the Commutation Event source.
  1326. * This parameter can be one of the following values:
  1327. * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
  1328. * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
  1329. * @retval HAL status
  1330. */
  1331. HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
  1332. {
  1333. /* Check the parameters */
  1334. assert_param(IS_TIM_ADVANCED_INSTANCE(htim->Instance));
  1335. assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
  1336. __HAL_LOCK(htim);
  1337. if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
  1338. (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
  1339. {
  1340. /* Select the Input trigger */
  1341. htim->Instance->SMCR &= ~TIM_SMCR_TS;
  1342. htim->Instance->SMCR |= InputTrigger;
  1343. }
  1344. /* Select the Capture Compare preload feature */
  1345. htim->Instance->CR2 |= TIM_CR2_CCPC;
  1346. /* Select the Commutation event source */
  1347. htim->Instance->CR2 &= ~TIM_CR2_CCUS;
  1348. htim->Instance->CR2 |= CommutationSource;
  1349. /* Enable the Commutation DMA Request */
  1350. /* Set the DMA Commutation Callback */
  1351. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
  1352. /* Set the DMA error callback */
  1353. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError;
  1354. /* Enable the Commutation DMA Request */
  1355. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_COM);
  1356. __HAL_UNLOCK(htim);
  1357. return HAL_OK;
  1358. }
  1359. /**
  1360. * @brief Configures the TIM in master mode.
  1361. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1362. * the configuration information for TIM module.
  1363. * @param sMasterConfig: pointer to a TIM_MasterConfigTypeDef structure that
  1364. * contains the selected trigger output (TRGO) and the Master/Slave
  1365. * mode.
  1366. * @retval HAL status
  1367. */
  1368. HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef * sMasterConfig)
  1369. {
  1370. /* Check the parameters */
  1371. assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance));
  1372. assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
  1373. assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode));
  1374. __HAL_LOCK(htim);
  1375. htim->State = HAL_TIM_STATE_BUSY;
  1376. /* Reset the MMS Bits */
  1377. htim->Instance->CR2 &= ~TIM_CR2_MMS;
  1378. /* Select the TRGO source */
  1379. htim->Instance->CR2 |= sMasterConfig->MasterOutputTrigger;
  1380. /* Reset the MSM Bit */
  1381. htim->Instance->SMCR &= ~TIM_SMCR_MSM;
  1382. /* Set or Reset the MSM Bit */
  1383. htim->Instance->SMCR |= sMasterConfig->MasterSlaveMode;
  1384. htim->State = HAL_TIM_STATE_READY;
  1385. __HAL_UNLOCK(htim);
  1386. return HAL_OK;
  1387. }
  1388. /**
  1389. * @brief Configures the Break feature, dead time, Lock level, OSSI/OSSR State
  1390. * and the AOE(automatic output enable).
  1391. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1392. * the configuration information for TIM module.
  1393. * @param sBreakDeadTimeConfig: pointer to a TIM_ConfigBreakDeadConfig_TypeDef structure that
  1394. * contains the BDTR Register configuration information for the TIM peripheral.
  1395. * @retval HAL status
  1396. */
  1397. HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
  1398. TIM_BreakDeadTimeConfigTypeDef * sBreakDeadTimeConfig)
  1399. {
  1400. uint32_t tmpbdtr = 0U;
  1401. /* Check the parameters */
  1402. assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance));
  1403. assert_param(IS_TIM_OSSR_STATE(sBreakDeadTimeConfig->OffStateRunMode));
  1404. assert_param(IS_TIM_OSSI_STATE(sBreakDeadTimeConfig->OffStateIDLEMode));
  1405. assert_param(IS_TIM_LOCK_LEVEL(sBreakDeadTimeConfig->LockLevel));
  1406. assert_param(IS_TIM_DEADTIME(sBreakDeadTimeConfig->DeadTime));
  1407. assert_param(IS_TIM_BREAK_STATE(sBreakDeadTimeConfig->BreakState));
  1408. assert_param(IS_TIM_BREAK_POLARITY(sBreakDeadTimeConfig->BreakPolarity));
  1409. assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(sBreakDeadTimeConfig->AutomaticOutput));
  1410. /* Check input state */
  1411. __HAL_LOCK(htim);
  1412. /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
  1413. the OSSI State, the dead time value and the Automatic Output Enable Bit */
  1414. /* Set the BDTR bits */
  1415. MODIFY_REG(tmpbdtr, TIM_BDTR_DTG, sBreakDeadTimeConfig->DeadTime);
  1416. MODIFY_REG(tmpbdtr, TIM_BDTR_LOCK, sBreakDeadTimeConfig->LockLevel);
  1417. MODIFY_REG(tmpbdtr, TIM_BDTR_OSSI, sBreakDeadTimeConfig->OffStateIDLEMode);
  1418. MODIFY_REG(tmpbdtr, TIM_BDTR_OSSR, sBreakDeadTimeConfig->OffStateRunMode);
  1419. MODIFY_REG(tmpbdtr, TIM_BDTR_BKE, sBreakDeadTimeConfig->BreakState);
  1420. MODIFY_REG(tmpbdtr, TIM_BDTR_BKP, sBreakDeadTimeConfig->BreakPolarity);
  1421. MODIFY_REG(tmpbdtr, TIM_BDTR_AOE, sBreakDeadTimeConfig->AutomaticOutput);
  1422. MODIFY_REG(tmpbdtr, TIM_BDTR_MOE, sBreakDeadTimeConfig->AutomaticOutput);
  1423. /* Set TIMx_BDTR */
  1424. htim->Instance->BDTR = tmpbdtr;
  1425. __HAL_UNLOCK(htim);
  1426. return HAL_OK;
  1427. }
  1428. /**
  1429. * @brief Configures the TIM2, TIM5 and TIM11 Remapping input capabilities.
  1430. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1431. * the configuration information for TIM module.
  1432. * @param Remap: specifies the TIM input remapping source.
  1433. * This parameter can be one of the following values:
  1434. * @arg TIM_TIM2_TIM8_TRGO: TIM2 ITR1 input is connected to TIM8 Trigger output(default)
  1435. * @arg TIM_TIM2_ETH_PTP: TIM2 ITR1 input is connected to ETH PTP trigger output.
  1436. * @arg TIM_TIM2_USBFS_SOF: TIM2 ITR1 input is connected to USB FS SOF.
  1437. * @arg TIM_TIM2_USBHS_SOF: TIM2 ITR1 input is connected to USB HS SOF.
  1438. * @arg TIM_TIM5_GPIO: TIM5 CH4 input is connected to dedicated Timer pin(default)
  1439. * @arg TIM_TIM5_LSI: TIM5 CH4 input is connected to LSI clock.
  1440. * @arg TIM_TIM5_LSE: TIM5 CH4 input is connected to LSE clock.
  1441. * @arg TIM_TIM5_RTC: TIM5 CH4 input is connected to RTC Output event.
  1442. * @arg TIM_TIM11_GPIO: TIM11 CH4 input is connected to dedicated Timer pin(default)
  1443. * @arg TIM_TIM11_HSE: TIM11 CH4 input is connected to HSE_RTC clock
  1444. * (HSE divided by a programmable prescaler)
  1445. * @arg TIM_TIM9_TIM3_TRGO: TIM9 ITR1 input is connected to TIM3 Trigger output(default)
  1446. * @arg TIM_TIM9_LPTIM: TIM9 ITR1 input is connected to LPTIM.
  1447. * @arg TIM_TIM5_TIM3_TRGO: TIM5 ITR1 input is connected to TIM3 Trigger output(default)
  1448. * @arg TIM_TIM5_LPTIM: TIM5 ITR1 input is connected to LPTIM.
  1449. * @arg TIM_TIM1_TIM3_TRGO: TIM1 ITR2 input is connected to TIM3 Trigger output(default)
  1450. * @arg TIM_TIM1_LPTIM: TIM1 ITR2 input is connected to LPTIM.
  1451. * @retval HAL status
  1452. */
  1453. HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap)
  1454. {
  1455. __HAL_LOCK(htim);
  1456. /* Check parameters */
  1457. assert_param(IS_TIM_REMAP_INSTANCE(htim->Instance));
  1458. assert_param(IS_TIM_REMAP(Remap));
  1459. #if defined(LPTIM_OR_TIM1_ITR2_RMP)
  1460. if ((Remap == TIM_TIM9_TIM3_TRGO)|| (Remap == TIM_TIM9_LPTIM)||(Remap ==TIM_TIM5_TIM3_TRGO)||\
  1461. (Remap == TIM_TIM5_LPTIM)||(Remap == TIM_TIM1_TIM3_TRGO)|| (Remap == TIM_TIM1_LPTIM))
  1462. {
  1463. __HAL_RCC_LPTIM1_CLK_ENABLE();
  1464. LPTIM1->OR = (Remap& 0xEFFFFFFFU);
  1465. }
  1466. else
  1467. {
  1468. /* Set the Timer remapping configuration */
  1469. htim->Instance->OR = Remap;
  1470. }
  1471. #else
  1472. /* Set the Timer remapping configuration */
  1473. htim->Instance->OR = Remap;
  1474. #endif
  1475. htim->State = HAL_TIM_STATE_READY;
  1476. __HAL_UNLOCK(htim);
  1477. return HAL_OK;
  1478. }
  1479. /**
  1480. * @}
  1481. */
  1482. /** @defgroup TIMEx_Exported_Functions_Group6 Extension Callbacks functions
  1483. * @brief Extension Callbacks functions
  1484. *
  1485. @verbatim
  1486. ==============================================================================
  1487. ##### Extension Callbacks functions #####
  1488. ==============================================================================
  1489. [..]
  1490. This section provides Extension TIM callback functions:
  1491. (+) Timer Commutation callback
  1492. (+) Timer Break callback
  1493. @endverbatim
  1494. * @{
  1495. */
  1496. /**
  1497. * @brief Hall commutation changed callback in non blocking mode
  1498. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1499. * the configuration information for TIM module.
  1500. * @retval None
  1501. */
  1502. __weak void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim)
  1503. {
  1504. /* Prevent unused argument(s) compilation warning */
  1505. UNUSED(htim);
  1506. /* NOTE : This function Should not be modified, when the callback is needed,
  1507. the HAL_TIMEx_CommutationCallback could be implemented in the user file
  1508. */
  1509. }
  1510. /**
  1511. * @brief Hall Break detection callback in non blocking mode
  1512. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1513. * the configuration information for TIM module.
  1514. * @retval None
  1515. */
  1516. __weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
  1517. {
  1518. /* Prevent unused argument(s) compilation warning */
  1519. UNUSED(htim);
  1520. /* NOTE : This function Should not be modified, when the callback is needed,
  1521. the HAL_TIMEx_BreakCallback could be implemented in the user file
  1522. */
  1523. }
  1524. /**
  1525. * @}
  1526. */
  1527. /** @defgroup TIMEx_Exported_Functions_Group7 Extension Peripheral State functions
  1528. * @brief Extension Peripheral State functions
  1529. *
  1530. @verbatim
  1531. ==============================================================================
  1532. ##### Extension Peripheral State functions #####
  1533. ==============================================================================
  1534. [..]
  1535. This subsection permits to get in run-time the status of the peripheral
  1536. and the data flow.
  1537. @endverbatim
  1538. * @{
  1539. */
  1540. /**
  1541. * @brief Return the TIM Hall Sensor interface state
  1542. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1543. * the configuration information for TIM module.
  1544. * @retval HAL state
  1545. */
  1546. HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
  1547. {
  1548. return htim->State;
  1549. }
  1550. /**
  1551. * @}
  1552. */
  1553. /**
  1554. * @brief TIM DMA Commutation callback.
  1555. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  1556. * the configuration information for the specified DMA module.
  1557. * @retval None
  1558. */
  1559. void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
  1560. {
  1561. TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  1562. htim->State= HAL_TIM_STATE_READY;
  1563. HAL_TIMEx_CommutationCallback(htim);
  1564. }
  1565. /**
  1566. * @}
  1567. */
  1568. /**
  1569. * @brief Enables or disables the TIM Capture Compare Channel xN.
  1570. * @param TIMx to select the TIM peripheral
  1571. * @param Channel: specifies the TIM Channel
  1572. * This parameter can be one of the following values:
  1573. * @arg TIM_Channel_1: TIM Channel 1
  1574. * @arg TIM_Channel_2: TIM Channel 2
  1575. * @arg TIM_Channel_3: TIM Channel 3
  1576. * @param ChannelNState: specifies the TIM Channel CCxNE bit new state.
  1577. * This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable.
  1578. * @retval None
  1579. */
  1580. static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState)
  1581. {
  1582. uint32_t tmp = 0U;
  1583. /* Check the parameters */
  1584. assert_param(IS_TIM_CC4_INSTANCE(TIMx));
  1585. assert_param(IS_TIM_COMPLEMENTARY_CHANNELS(Channel));
  1586. tmp = TIM_CCER_CC1NE << Channel;
  1587. /* Reset the CCxNE Bit */
  1588. TIMx->CCER &= ~tmp;
  1589. /* Set or reset the CCxNE Bit */
  1590. TIMx->CCER |= (uint32_t)(ChannelNState << Channel);
  1591. }
  1592. /**
  1593. * @}
  1594. */
  1595. #endif /* HAL_TIM_MODULE_ENABLED */
  1596. /**
  1597. * @}
  1598. */
  1599. /**
  1600. * @}
  1601. */
  1602. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/