stm32f1xx_hal_tim_ex.c 59 KB

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