STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_tim.c
Go to the documentation of this file.
1 
186 /* Includes ------------------------------------------------------------------*/
187 #include "stm32l4xx_hal.h"
188 
198 #ifdef HAL_TIM_MODULE_ENABLED
199 
200 /* Private typedef -----------------------------------------------------------*/
201 /* Private define ------------------------------------------------------------*/
202 /* Private macro -------------------------------------------------------------*/
203 /* Private variables ---------------------------------------------------------*/
204 /* Private function prototypes -----------------------------------------------*/
208 static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
209 static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
210 static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
211 static void TIM_OC5_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
212 static void TIM_OC6_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
213 static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
214 static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
215  uint32_t TIM_ICFilter);
216 static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
217 static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
218  uint32_t TIM_ICFilter);
219 static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
220  uint32_t TIM_ICFilter);
221 static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource);
224 static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma);
225 static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma);
226 static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
227  TIM_SlaveConfigTypeDef *sSlaveConfig);
231 /* Exported functions --------------------------------------------------------*/
232 
268 HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
269 {
270  /* Check the TIM handle allocation */
271  if (htim == NULL)
272  {
273  return HAL_ERROR;
274  }
275 
276  /* Check the parameters */
277  assert_param(IS_TIM_INSTANCE(htim->Instance));
278  assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
279  assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
280  assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
281 
282  if (htim->State == HAL_TIM_STATE_RESET)
283  {
284  /* Allocate lock resource and initialize it */
285  htim->Lock = HAL_UNLOCKED;
286 
287 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
288  /* Reset interrupt callbacks to legacy weak callbacks */
289  TIM_ResetCallback(htim);
290 
291  if (htim->Base_MspInitCallback == NULL)
292  {
293  htim->Base_MspInitCallback = HAL_TIM_Base_MspInit;
294  }
295  /* Init the low level hardware : GPIO, CLOCK, NVIC */
296  htim->Base_MspInitCallback(htim);
297 #else
298  /* Init the low level hardware : GPIO, CLOCK, NVIC */
299  HAL_TIM_Base_MspInit(htim);
300 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
301  }
302 
303  /* Set the TIM state */
304  htim->State = HAL_TIM_STATE_BUSY;
305 
306  /* Set the Time Base configuration */
307  TIM_Base_SetConfig(htim->Instance, &htim->Init);
308 
309  /* Initialize the TIM state*/
310  htim->State = HAL_TIM_STATE_READY;
311 
312  return HAL_OK;
313 }
314 
320 HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim)
321 {
322  /* Check the parameters */
323  assert_param(IS_TIM_INSTANCE(htim->Instance));
324 
325  htim->State = HAL_TIM_STATE_BUSY;
326 
327  /* Disable the TIM Peripheral Clock */
328  __HAL_TIM_DISABLE(htim);
329 
330 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
331  if (htim->Base_MspDeInitCallback == NULL)
332  {
333  htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit;
334  }
335  /* DeInit the low level hardware */
336  htim->Base_MspDeInitCallback(htim);
337 #else
338  /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
340 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
341 
342  /* Change TIM state */
343  htim->State = HAL_TIM_STATE_RESET;
344 
345  /* Release Lock */
346  __HAL_UNLOCK(htim);
347 
348  return HAL_OK;
349 }
350 
357 {
358  /* Prevent unused argument(s) compilation warning */
359  UNUSED(htim);
360 
361  /* NOTE : This function should not be modified, when the callback is needed,
362  the HAL_TIM_Base_MspInit could be implemented in the user file
363  */
364 }
365 
372 {
373  /* Prevent unused argument(s) compilation warning */
374  UNUSED(htim);
375 
376  /* NOTE : This function should not be modified, when the callback is needed,
377  the HAL_TIM_Base_MspDeInit could be implemented in the user file
378  */
379 }
380 
381 
387 HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim)
388 {
389  uint32_t tmpsmcr;
390 
391  /* Check the parameters */
392  assert_param(IS_TIM_INSTANCE(htim->Instance));
393 
394  /* Set the TIM state */
395  htim->State = HAL_TIM_STATE_BUSY;
396 
397  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
398  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
399  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
400  {
401  __HAL_TIM_ENABLE(htim);
402  }
403 
404  /* Change the TIM state*/
405  htim->State = HAL_TIM_STATE_READY;
406 
407  /* Return function status */
408  return HAL_OK;
409 }
410 
416 HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim)
417 {
418  /* Check the parameters */
419  assert_param(IS_TIM_INSTANCE(htim->Instance));
420 
421  /* Set the TIM state */
422  htim->State = HAL_TIM_STATE_BUSY;
423 
424  /* Disable the Peripheral */
425  __HAL_TIM_DISABLE(htim);
426 
427  /* Change the TIM state*/
428  htim->State = HAL_TIM_STATE_READY;
429 
430  /* Return function status */
431  return HAL_OK;
432 }
433 
439 HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
440 {
441  uint32_t tmpsmcr;
442 
443  /* Check the parameters */
444  assert_param(IS_TIM_INSTANCE(htim->Instance));
445 
446  /* Enable the TIM Update interrupt */
447  __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE);
448 
449  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
450  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
451  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
452  {
453  __HAL_TIM_ENABLE(htim);
454  }
455 
456  /* Return function status */
457  return HAL_OK;
458 }
459 
465 HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim)
466 {
467  /* Check the parameters */
468  assert_param(IS_TIM_INSTANCE(htim->Instance));
469  /* Disable the TIM Update interrupt */
470  __HAL_TIM_DISABLE_IT(htim, TIM_IT_UPDATE);
471 
472  /* Disable the Peripheral */
473  __HAL_TIM_DISABLE(htim);
474 
475  /* Return function status */
476  return HAL_OK;
477 }
478 
486 HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
487 {
488  uint32_t tmpsmcr;
489 
490  /* Check the parameters */
491  assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
492 
493  if ((htim->State == HAL_TIM_STATE_BUSY))
494  {
495  return HAL_BUSY;
496  }
497  else if ((htim->State == HAL_TIM_STATE_READY))
498  {
499  if ((pData == NULL) && (Length > 0U))
500  {
501  return HAL_ERROR;
502  }
503  else
504  {
505  htim->State = HAL_TIM_STATE_BUSY;
506  }
507  }
508  else
509  {
510  /* nothing to do */
511  }
512 
513  /* Set the DMA Period elapsed callbacks */
514  htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
515  htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
516 
517  /* Set the DMA error callback */
518  htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
519 
520  /* Enable the DMA channel */
521  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR, Length) != HAL_OK)
522  {
523  return HAL_ERROR;
524  }
525 
526  /* Enable the TIM Update DMA request */
527  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_UPDATE);
528 
529  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
530  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
531  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
532  {
533  __HAL_TIM_ENABLE(htim);
534  }
535 
536  /* Return function status */
537  return HAL_OK;
538 }
539 
545 HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim)
546 {
547  /* Check the parameters */
548  assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
549 
550  /* Disable the TIM Update DMA request */
551  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_UPDATE);
552 
553  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]);
554 
555  /* Disable the Peripheral */
556  __HAL_TIM_DISABLE(htim);
557 
558  /* Change the htim state */
559  htim->State = HAL_TIM_STATE_READY;
560 
561  /* Return function status */
562  return HAL_OK;
563 }
564 
600 HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim)
601 {
602  /* Check the TIM handle allocation */
603  if (htim == NULL)
604  {
605  return HAL_ERROR;
606  }
607 
608  /* Check the parameters */
609  assert_param(IS_TIM_INSTANCE(htim->Instance));
610  assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
611  assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
612  assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
613 
614  if (htim->State == HAL_TIM_STATE_RESET)
615  {
616  /* Allocate lock resource and initialize it */
617  htim->Lock = HAL_UNLOCKED;
618 
619 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
620  /* Reset interrupt callbacks to legacy weak callbacks */
621  TIM_ResetCallback(htim);
622 
623  if (htim->OC_MspInitCallback == NULL)
624  {
625  htim->OC_MspInitCallback = HAL_TIM_OC_MspInit;
626  }
627  /* Init the low level hardware : GPIO, CLOCK, NVIC */
628  htim->OC_MspInitCallback(htim);
629 #else
630  /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
631  HAL_TIM_OC_MspInit(htim);
632 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
633  }
634 
635  /* Set the TIM state */
636  htim->State = HAL_TIM_STATE_BUSY;
637 
638  /* Init the base time for the Output Compare */
639  TIM_Base_SetConfig(htim->Instance, &htim->Init);
640 
641  /* Initialize the TIM state*/
642  htim->State = HAL_TIM_STATE_READY;
643 
644  return HAL_OK;
645 }
646 
652 HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim)
653 {
654  /* Check the parameters */
655  assert_param(IS_TIM_INSTANCE(htim->Instance));
656 
657  htim->State = HAL_TIM_STATE_BUSY;
658 
659  /* Disable the TIM Peripheral Clock */
660  __HAL_TIM_DISABLE(htim);
661 
662 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
663  if (htim->OC_MspDeInitCallback == NULL)
664  {
665  htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit;
666  }
667  /* DeInit the low level hardware */
668  htim->OC_MspDeInitCallback(htim);
669 #else
670  /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
671  HAL_TIM_OC_MspDeInit(htim);
672 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
673 
674  /* Change TIM state */
675  htim->State = HAL_TIM_STATE_RESET;
676 
677  /* Release Lock */
678  __HAL_UNLOCK(htim);
679 
680  return HAL_OK;
681 }
682 
689 {
690  /* Prevent unused argument(s) compilation warning */
691  UNUSED(htim);
692 
693  /* NOTE : This function should not be modified, when the callback is needed,
694  the HAL_TIM_OC_MspInit could be implemented in the user file
695  */
696 }
697 
704 {
705  /* Prevent unused argument(s) compilation warning */
706  UNUSED(htim);
707 
708  /* NOTE : This function should not be modified, when the callback is needed,
709  the HAL_TIM_OC_MspDeInit could be implemented in the user file
710  */
711 }
712 
726 HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
727 {
728  uint32_t tmpsmcr;
729 
730  /* Check the parameters */
731  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
732 
733  /* Enable the Output compare channel */
734  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
735 
736  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
737  {
738  /* Enable the main output */
739  __HAL_TIM_MOE_ENABLE(htim);
740  }
741 
742  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
743  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
744  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
745  {
746  __HAL_TIM_ENABLE(htim);
747  }
748 
749  /* Return function status */
750  return HAL_OK;
751 }
752 
766 HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
767 {
768  /* Check the parameters */
769  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
770 
771  /* Disable the Output compare channel */
772  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
773 
774  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
775  {
776  /* Disable the Main Output */
777  __HAL_TIM_MOE_DISABLE(htim);
778  }
779 
780  /* Disable the Peripheral */
781  __HAL_TIM_DISABLE(htim);
782 
783  /* Return function status */
784  return HAL_OK;
785 }
786 
798 HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
799 {
800  uint32_t tmpsmcr;
801 
802  /* Check the parameters */
803  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
804 
805  switch (Channel)
806  {
807  case TIM_CHANNEL_1:
808  {
809  /* Enable the TIM Capture/Compare 1 interrupt */
810  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
811  break;
812  }
813 
814  case TIM_CHANNEL_2:
815  {
816  /* Enable the TIM Capture/Compare 2 interrupt */
817  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
818  break;
819  }
820 
821  case TIM_CHANNEL_3:
822  {
823  /* Enable the TIM Capture/Compare 3 interrupt */
824  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
825  break;
826  }
827 
828  case TIM_CHANNEL_4:
829  {
830  /* Enable the TIM Capture/Compare 4 interrupt */
831  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
832  break;
833  }
834 
835  default:
836  break;
837  }
838 
839  /* Enable the Output compare channel */
840  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
841 
842  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
843  {
844  /* Enable the main output */
845  __HAL_TIM_MOE_ENABLE(htim);
846  }
847 
848  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
849  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
850  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
851  {
852  __HAL_TIM_ENABLE(htim);
853  }
854 
855  /* Return function status */
856  return HAL_OK;
857 }
858 
870 HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
871 {
872  /* Check the parameters */
873  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
874 
875  switch (Channel)
876  {
877  case TIM_CHANNEL_1:
878  {
879  /* Disable the TIM Capture/Compare 1 interrupt */
880  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
881  break;
882  }
883 
884  case TIM_CHANNEL_2:
885  {
886  /* Disable the TIM Capture/Compare 2 interrupt */
887  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
888  break;
889  }
890 
891  case TIM_CHANNEL_3:
892  {
893  /* Disable the TIM Capture/Compare 3 interrupt */
894  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
895  break;
896  }
897 
898  case TIM_CHANNEL_4:
899  {
900  /* Disable the TIM Capture/Compare 4 interrupt */
901  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
902  break;
903  }
904 
905  default:
906  break;
907  }
908 
909  /* Disable the Output compare channel */
910  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
911 
912  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
913  {
914  /* Disable the Main Output */
915  __HAL_TIM_MOE_DISABLE(htim);
916  }
917 
918  /* Disable the Peripheral */
919  __HAL_TIM_DISABLE(htim);
920 
921  /* Return function status */
922  return HAL_OK;
923 }
924 
938 HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
939 {
940  uint32_t tmpsmcr;
941 
942  /* Check the parameters */
943  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
944 
945  if ((htim->State == HAL_TIM_STATE_BUSY))
946  {
947  return HAL_BUSY;
948  }
949  else if ((htim->State == HAL_TIM_STATE_READY))
950  {
951  if ((pData == NULL) && (Length > 0U))
952  {
953  return HAL_ERROR;
954  }
955  else
956  {
957  htim->State = HAL_TIM_STATE_BUSY;
958  }
959  }
960  else
961  {
962  /* nothing to do */
963  }
964 
965  switch (Channel)
966  {
967  case TIM_CHANNEL_1:
968  {
969  /* Set the DMA compare callbacks */
970  htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
971  htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
972 
973  /* Set the DMA error callback */
974  htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
975 
976  /* Enable the DMA channel */
977  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length) != HAL_OK)
978  {
979  return HAL_ERROR;
980  }
981 
982  /* Enable the TIM Capture/Compare 1 DMA request */
983  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
984  break;
985  }
986 
987  case TIM_CHANNEL_2:
988  {
989  /* Set the DMA compare callbacks */
990  htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
991  htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
992 
993  /* Set the DMA error callback */
994  htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
995 
996  /* Enable the DMA channel */
997  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length) != HAL_OK)
998  {
999  return HAL_ERROR;
1000  }
1001 
1002  /* Enable the TIM Capture/Compare 2 DMA request */
1003  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
1004  break;
1005  }
1006 
1007  case TIM_CHANNEL_3:
1008  {
1009  /* Set the DMA compare callbacks */
1010  htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
1011  htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1012 
1013  /* Set the DMA error callback */
1014  htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
1015 
1016  /* Enable the DMA channel */
1017  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length) != HAL_OK)
1018  {
1019  return HAL_ERROR;
1020  }
1021  /* Enable the TIM Capture/Compare 3 DMA request */
1022  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
1023  break;
1024  }
1025 
1026  case TIM_CHANNEL_4:
1027  {
1028  /* Set the DMA compare callbacks */
1029  htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
1030  htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1031 
1032  /* Set the DMA error callback */
1033  htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
1034 
1035  /* Enable the DMA channel */
1036  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length) != HAL_OK)
1037  {
1038  return HAL_ERROR;
1039  }
1040  /* Enable the TIM Capture/Compare 4 DMA request */
1041  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
1042  break;
1043  }
1044 
1045  default:
1046  break;
1047  }
1048 
1049  /* Enable the Output compare channel */
1050  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1051 
1052  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1053  {
1054  /* Enable the main output */
1055  __HAL_TIM_MOE_ENABLE(htim);
1056  }
1057 
1058  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1059  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1060  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1061  {
1062  __HAL_TIM_ENABLE(htim);
1063  }
1064 
1065  /* Return function status */
1066  return HAL_OK;
1067 }
1068 
1080 HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
1081 {
1082  /* Check the parameters */
1083  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1084 
1085  switch (Channel)
1086  {
1087  case TIM_CHANNEL_1:
1088  {
1089  /* Disable the TIM Capture/Compare 1 DMA request */
1090  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
1091  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
1092  break;
1093  }
1094 
1095  case TIM_CHANNEL_2:
1096  {
1097  /* Disable the TIM Capture/Compare 2 DMA request */
1098  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
1099  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
1100  break;
1101  }
1102 
1103  case TIM_CHANNEL_3:
1104  {
1105  /* Disable the TIM Capture/Compare 3 DMA request */
1106  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
1107  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
1108  break;
1109  }
1110 
1111  case TIM_CHANNEL_4:
1112  {
1113  /* Disable the TIM Capture/Compare 4 interrupt */
1114  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
1115  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
1116  break;
1117  }
1118 
1119  default:
1120  break;
1121  }
1122 
1123  /* Disable the Output compare channel */
1124  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1125 
1126  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1127  {
1128  /* Disable the Main Output */
1129  __HAL_TIM_MOE_DISABLE(htim);
1130  }
1131 
1132  /* Disable the Peripheral */
1133  __HAL_TIM_DISABLE(htim);
1134 
1135  /* Change the htim state */
1136  htim->State = HAL_TIM_STATE_READY;
1137 
1138  /* Return function status */
1139  return HAL_OK;
1140 }
1141 
1177 HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim)
1178 {
1179  /* Check the TIM handle allocation */
1180  if (htim == NULL)
1181  {
1182  return HAL_ERROR;
1183  }
1184 
1185  /* Check the parameters */
1186  assert_param(IS_TIM_INSTANCE(htim->Instance));
1187  assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
1188  assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
1189  assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
1190 
1191  if (htim->State == HAL_TIM_STATE_RESET)
1192  {
1193  /* Allocate lock resource and initialize it */
1194  htim->Lock = HAL_UNLOCKED;
1195 
1196 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1197  /* Reset interrupt callbacks to legacy weak callbacks */
1198  TIM_ResetCallback(htim);
1199 
1200  if (htim->PWM_MspInitCallback == NULL)
1201  {
1202  htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit;
1203  }
1204  /* Init the low level hardware : GPIO, CLOCK, NVIC */
1205  htim->PWM_MspInitCallback(htim);
1206 #else
1207  /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
1208  HAL_TIM_PWM_MspInit(htim);
1209 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1210  }
1211 
1212  /* Set the TIM state */
1213  htim->State = HAL_TIM_STATE_BUSY;
1214 
1215  /* Init the base time for the PWM */
1216  TIM_Base_SetConfig(htim->Instance, &htim->Init);
1217 
1218  /* Initialize the TIM state*/
1219  htim->State = HAL_TIM_STATE_READY;
1220 
1221  return HAL_OK;
1222 }
1223 
1229 HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim)
1230 {
1231  /* Check the parameters */
1232  assert_param(IS_TIM_INSTANCE(htim->Instance));
1233 
1234  htim->State = HAL_TIM_STATE_BUSY;
1235 
1236  /* Disable the TIM Peripheral Clock */
1237  __HAL_TIM_DISABLE(htim);
1238 
1239 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1240  if (htim->PWM_MspDeInitCallback == NULL)
1241  {
1242  htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit;
1243  }
1244  /* DeInit the low level hardware */
1245  htim->PWM_MspDeInitCallback(htim);
1246 #else
1247  /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
1248  HAL_TIM_PWM_MspDeInit(htim);
1249 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1250 
1251  /* Change TIM state */
1252  htim->State = HAL_TIM_STATE_RESET;
1253 
1254  /* Release Lock */
1255  __HAL_UNLOCK(htim);
1256 
1257  return HAL_OK;
1258 }
1259 
1266 {
1267  /* Prevent unused argument(s) compilation warning */
1268  UNUSED(htim);
1269 
1270  /* NOTE : This function should not be modified, when the callback is needed,
1271  the HAL_TIM_PWM_MspInit could be implemented in the user file
1272  */
1273 }
1274 
1281 {
1282  /* Prevent unused argument(s) compilation warning */
1283  UNUSED(htim);
1284 
1285  /* NOTE : This function should not be modified, when the callback is needed,
1286  the HAL_TIM_PWM_MspDeInit could be implemented in the user file
1287  */
1288 }
1289 
1303 HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
1304 {
1305  uint32_t tmpsmcr;
1306 
1307  /* Check the parameters */
1308  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1309 
1310  /* Enable the Capture compare channel */
1311  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1312 
1313  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1314  {
1315  /* Enable the main output */
1316  __HAL_TIM_MOE_ENABLE(htim);
1317  }
1318 
1319  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1320  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1321  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1322  {
1323  __HAL_TIM_ENABLE(htim);
1324  }
1325 
1326  /* Return function status */
1327  return HAL_OK;
1328 }
1329 
1343 HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
1344 {
1345  /* Check the parameters */
1346  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1347 
1348  /* Disable the Capture compare channel */
1349  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1350 
1351  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1352  {
1353  /* Disable the Main Output */
1354  __HAL_TIM_MOE_DISABLE(htim);
1355  }
1356 
1357  /* Disable the Peripheral */
1358  __HAL_TIM_DISABLE(htim);
1359 
1360  /* Change the htim state */
1361  htim->State = HAL_TIM_STATE_READY;
1362 
1363  /* Return function status */
1364  return HAL_OK;
1365 }
1366 
1378 HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
1379 {
1380  uint32_t tmpsmcr;
1381  /* Check the parameters */
1382  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1383 
1384  switch (Channel)
1385  {
1386  case TIM_CHANNEL_1:
1387  {
1388  /* Enable the TIM Capture/Compare 1 interrupt */
1389  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
1390  break;
1391  }
1392 
1393  case TIM_CHANNEL_2:
1394  {
1395  /* Enable the TIM Capture/Compare 2 interrupt */
1396  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
1397  break;
1398  }
1399 
1400  case TIM_CHANNEL_3:
1401  {
1402  /* Enable the TIM Capture/Compare 3 interrupt */
1403  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
1404  break;
1405  }
1406 
1407  case TIM_CHANNEL_4:
1408  {
1409  /* Enable the TIM Capture/Compare 4 interrupt */
1410  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
1411  break;
1412  }
1413 
1414  default:
1415  break;
1416  }
1417 
1418  /* Enable the Capture compare channel */
1419  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1420 
1421  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1422  {
1423  /* Enable the main output */
1424  __HAL_TIM_MOE_ENABLE(htim);
1425  }
1426 
1427  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1428  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1429  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1430  {
1431  __HAL_TIM_ENABLE(htim);
1432  }
1433 
1434  /* Return function status */
1435  return HAL_OK;
1436 }
1437 
1449 HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
1450 {
1451  /* Check the parameters */
1452  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1453 
1454  switch (Channel)
1455  {
1456  case TIM_CHANNEL_1:
1457  {
1458  /* Disable the TIM Capture/Compare 1 interrupt */
1459  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
1460  break;
1461  }
1462 
1463  case TIM_CHANNEL_2:
1464  {
1465  /* Disable the TIM Capture/Compare 2 interrupt */
1466  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
1467  break;
1468  }
1469 
1470  case TIM_CHANNEL_3:
1471  {
1472  /* Disable the TIM Capture/Compare 3 interrupt */
1473  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
1474  break;
1475  }
1476 
1477  case TIM_CHANNEL_4:
1478  {
1479  /* Disable the TIM Capture/Compare 4 interrupt */
1480  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
1481  break;
1482  }
1483 
1484  default:
1485  break;
1486  }
1487 
1488  /* Disable the Capture compare channel */
1489  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1490 
1491  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1492  {
1493  /* Disable the Main Output */
1494  __HAL_TIM_MOE_DISABLE(htim);
1495  }
1496 
1497  /* Disable the Peripheral */
1498  __HAL_TIM_DISABLE(htim);
1499 
1500  /* Return function status */
1501  return HAL_OK;
1502 }
1503 
1517 HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
1518 {
1519  uint32_t tmpsmcr;
1520 
1521  /* Check the parameters */
1522  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1523 
1524  if ((htim->State == HAL_TIM_STATE_BUSY))
1525  {
1526  return HAL_BUSY;
1527  }
1528  else if ((htim->State == HAL_TIM_STATE_READY))
1529  {
1530  if ((pData == NULL) && (Length > 0U))
1531  {
1532  return HAL_ERROR;
1533  }
1534  else
1535  {
1536  htim->State = HAL_TIM_STATE_BUSY;
1537  }
1538  }
1539  else
1540  {
1541  /* nothing to do */
1542  }
1543 
1544  switch (Channel)
1545  {
1546  case TIM_CHANNEL_1:
1547  {
1548  /* Set the DMA compare callbacks */
1549  htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
1550  htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1551 
1552  /* Set the DMA error callback */
1553  htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
1554 
1555  /* Enable the DMA channel */
1556  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length) != HAL_OK)
1557  {
1558  return HAL_ERROR;
1559  }
1560 
1561  /* Enable the TIM Capture/Compare 1 DMA request */
1562  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
1563  break;
1564  }
1565 
1566  case TIM_CHANNEL_2:
1567  {
1568  /* Set the DMA compare callbacks */
1569  htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
1570  htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1571 
1572  /* Set the DMA error callback */
1573  htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
1574 
1575  /* Enable the DMA channel */
1576  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length) != HAL_OK)
1577  {
1578  return HAL_ERROR;
1579  }
1580  /* Enable the TIM Capture/Compare 2 DMA request */
1581  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
1582  break;
1583  }
1584 
1585  case TIM_CHANNEL_3:
1586  {
1587  /* Set the DMA compare callbacks */
1588  htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
1589  htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1590 
1591  /* Set the DMA error callback */
1592  htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
1593 
1594  /* Enable the DMA channel */
1595  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length) != HAL_OK)
1596  {
1597  return HAL_ERROR;
1598  }
1599  /* Enable the TIM Output Capture/Compare 3 request */
1600  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
1601  break;
1602  }
1603 
1604  case TIM_CHANNEL_4:
1605  {
1606  /* Set the DMA compare callbacks */
1607  htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
1608  htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1609 
1610  /* Set the DMA error callback */
1611  htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
1612 
1613  /* Enable the DMA channel */
1614  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length) != HAL_OK)
1615  {
1616  return HAL_ERROR;
1617  }
1618  /* Enable the TIM Capture/Compare 4 DMA request */
1619  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
1620  break;
1621  }
1622 
1623  default:
1624  break;
1625  }
1626 
1627  /* Enable the Capture compare channel */
1628  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1629 
1630  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1631  {
1632  /* Enable the main output */
1633  __HAL_TIM_MOE_ENABLE(htim);
1634  }
1635 
1636  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1637  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1638  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1639  {
1640  __HAL_TIM_ENABLE(htim);
1641  }
1642 
1643  /* Return function status */
1644  return HAL_OK;
1645 }
1646 
1658 HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
1659 {
1660  /* Check the parameters */
1661  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1662 
1663  switch (Channel)
1664  {
1665  case TIM_CHANNEL_1:
1666  {
1667  /* Disable the TIM Capture/Compare 1 DMA request */
1668  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
1669  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
1670  break;
1671  }
1672 
1673  case TIM_CHANNEL_2:
1674  {
1675  /* Disable the TIM Capture/Compare 2 DMA request */
1676  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
1677  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
1678  break;
1679  }
1680 
1681  case TIM_CHANNEL_3:
1682  {
1683  /* Disable the TIM Capture/Compare 3 DMA request */
1684  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
1685  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
1686  break;
1687  }
1688 
1689  case TIM_CHANNEL_4:
1690  {
1691  /* Disable the TIM Capture/Compare 4 interrupt */
1692  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
1693  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
1694  break;
1695  }
1696 
1697  default:
1698  break;
1699  }
1700 
1701  /* Disable the Capture compare channel */
1702  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1703 
1704  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1705  {
1706  /* Disable the Main Output */
1707  __HAL_TIM_MOE_DISABLE(htim);
1708  }
1709 
1710  /* Disable the Peripheral */
1711  __HAL_TIM_DISABLE(htim);
1712 
1713  /* Change the htim state */
1714  htim->State = HAL_TIM_STATE_READY;
1715 
1716  /* Return function status */
1717  return HAL_OK;
1718 }
1719 
1755 HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim)
1756 {
1757  /* Check the TIM handle allocation */
1758  if (htim == NULL)
1759  {
1760  return HAL_ERROR;
1761  }
1762 
1763  /* Check the parameters */
1764  assert_param(IS_TIM_INSTANCE(htim->Instance));
1765  assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
1766  assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
1767  assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
1768 
1769  if (htim->State == HAL_TIM_STATE_RESET)
1770  {
1771  /* Allocate lock resource and initialize it */
1772  htim->Lock = HAL_UNLOCKED;
1773 
1774 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1775  /* Reset interrupt callbacks to legacy weak callbacks */
1776  TIM_ResetCallback(htim);
1777 
1778  if (htim->IC_MspInitCallback == NULL)
1779  {
1780  htim->IC_MspInitCallback = HAL_TIM_IC_MspInit;
1781  }
1782  /* Init the low level hardware : GPIO, CLOCK, NVIC */
1783  htim->IC_MspInitCallback(htim);
1784 #else
1785  /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
1786  HAL_TIM_IC_MspInit(htim);
1787 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1788  }
1789 
1790  /* Set the TIM state */
1791  htim->State = HAL_TIM_STATE_BUSY;
1792 
1793  /* Init the base time for the input capture */
1794  TIM_Base_SetConfig(htim->Instance, &htim->Init);
1795 
1796  /* Initialize the TIM state*/
1797  htim->State = HAL_TIM_STATE_READY;
1798 
1799  return HAL_OK;
1800 }
1801 
1807 HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim)
1808 {
1809  /* Check the parameters */
1810  assert_param(IS_TIM_INSTANCE(htim->Instance));
1811 
1812  htim->State = HAL_TIM_STATE_BUSY;
1813 
1814  /* Disable the TIM Peripheral Clock */
1815  __HAL_TIM_DISABLE(htim);
1816 
1817 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1818  if (htim->IC_MspDeInitCallback == NULL)
1819  {
1820  htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit;
1821  }
1822  /* DeInit the low level hardware */
1823  htim->IC_MspDeInitCallback(htim);
1824 #else
1825  /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
1826  HAL_TIM_IC_MspDeInit(htim);
1827 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1828 
1829  /* Change TIM state */
1830  htim->State = HAL_TIM_STATE_RESET;
1831 
1832  /* Release Lock */
1833  __HAL_UNLOCK(htim);
1834 
1835  return HAL_OK;
1836 }
1837 
1844 {
1845  /* Prevent unused argument(s) compilation warning */
1846  UNUSED(htim);
1847 
1848  /* NOTE : This function should not be modified, when the callback is needed,
1849  the HAL_TIM_IC_MspInit could be implemented in the user file
1850  */
1851 }
1852 
1859 {
1860  /* Prevent unused argument(s) compilation warning */
1861  UNUSED(htim);
1862 
1863  /* NOTE : This function should not be modified, when the callback is needed,
1864  the HAL_TIM_IC_MspDeInit could be implemented in the user file
1865  */
1866 }
1867 
1879 HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
1880 {
1881  uint32_t tmpsmcr;
1882 
1883  /* Check the parameters */
1884  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1885 
1886  /* Enable the Input Capture channel */
1887  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1888 
1889  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1890  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1891  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1892  {
1893  __HAL_TIM_ENABLE(htim);
1894  }
1895 
1896  /* Return function status */
1897  return HAL_OK;
1898 }
1899 
1911 HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
1912 {
1913  /* Check the parameters */
1914  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1915 
1916  /* Disable the Input Capture channel */
1917  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1918 
1919  /* Disable the Peripheral */
1920  __HAL_TIM_DISABLE(htim);
1921 
1922  /* Return function status */
1923  return HAL_OK;
1924 }
1925 
1937 HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
1938 {
1939  uint32_t tmpsmcr;
1940 
1941  /* Check the parameters */
1942  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1943 
1944  switch (Channel)
1945  {
1946  case TIM_CHANNEL_1:
1947  {
1948  /* Enable the TIM Capture/Compare 1 interrupt */
1949  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
1950  break;
1951  }
1952 
1953  case TIM_CHANNEL_2:
1954  {
1955  /* Enable the TIM Capture/Compare 2 interrupt */
1956  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
1957  break;
1958  }
1959 
1960  case TIM_CHANNEL_3:
1961  {
1962  /* Enable the TIM Capture/Compare 3 interrupt */
1963  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
1964  break;
1965  }
1966 
1967  case TIM_CHANNEL_4:
1968  {
1969  /* Enable the TIM Capture/Compare 4 interrupt */
1970  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
1971  break;
1972  }
1973 
1974  default:
1975  break;
1976  }
1977  /* Enable the Input Capture channel */
1978  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1979 
1980  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1981  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1982  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1983  {
1984  __HAL_TIM_ENABLE(htim);
1985  }
1986 
1987  /* Return function status */
1988  return HAL_OK;
1989 }
1990 
2002 HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
2003 {
2004  /* Check the parameters */
2005  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
2006 
2007  switch (Channel)
2008  {
2009  case TIM_CHANNEL_1:
2010  {
2011  /* Disable the TIM Capture/Compare 1 interrupt */
2012  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
2013  break;
2014  }
2015 
2016  case TIM_CHANNEL_2:
2017  {
2018  /* Disable the TIM Capture/Compare 2 interrupt */
2019  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
2020  break;
2021  }
2022 
2023  case TIM_CHANNEL_3:
2024  {
2025  /* Disable the TIM Capture/Compare 3 interrupt */
2026  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
2027  break;
2028  }
2029 
2030  case TIM_CHANNEL_4:
2031  {
2032  /* Disable the TIM Capture/Compare 4 interrupt */
2033  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
2034  break;
2035  }
2036 
2037  default:
2038  break;
2039  }
2040 
2041  /* Disable the Input Capture channel */
2042  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
2043 
2044  /* Disable the Peripheral */
2045  __HAL_TIM_DISABLE(htim);
2046 
2047  /* Return function status */
2048  return HAL_OK;
2049 }
2050 
2064 HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
2065 {
2066  uint32_t tmpsmcr;
2067 
2068  /* Check the parameters */
2069  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
2070  assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
2071 
2072  if ((htim->State == HAL_TIM_STATE_BUSY))
2073  {
2074  return HAL_BUSY;
2075  }
2076  else if ((htim->State == HAL_TIM_STATE_READY))
2077  {
2078  if ((pData == NULL) && (Length > 0U))
2079  {
2080  return HAL_ERROR;
2081  }
2082  else
2083  {
2084  htim->State = HAL_TIM_STATE_BUSY;
2085  }
2086  }
2087  else
2088  {
2089  /* nothing to do */
2090  }
2091 
2092  switch (Channel)
2093  {
2094  case TIM_CHANNEL_1:
2095  {
2096  /* Set the DMA capture callbacks */
2097  htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
2098  htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
2099 
2100  /* Set the DMA error callback */
2101  htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
2102 
2103  /* Enable the DMA channel */
2104  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length) != HAL_OK)
2105  {
2106  return HAL_ERROR;
2107  }
2108  /* Enable the TIM Capture/Compare 1 DMA request */
2109  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
2110  break;
2111  }
2112 
2113  case TIM_CHANNEL_2:
2114  {
2115  /* Set the DMA capture callbacks */
2116  htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
2117  htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
2118 
2119  /* Set the DMA error callback */
2120  htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
2121 
2122  /* Enable the DMA channel */
2123  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData, Length) != HAL_OK)
2124  {
2125  return HAL_ERROR;
2126  }
2127  /* Enable the TIM Capture/Compare 2 DMA request */
2128  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
2129  break;
2130  }
2131 
2132  case TIM_CHANNEL_3:
2133  {
2134  /* Set the DMA capture callbacks */
2135  htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt;
2136  htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
2137 
2138  /* Set the DMA error callback */
2139  htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
2140 
2141  /* Enable the DMA channel */
2142  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData, Length) != HAL_OK)
2143  {
2144  return HAL_ERROR;
2145  }
2146  /* Enable the TIM Capture/Compare 3 DMA request */
2147  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
2148  break;
2149  }
2150 
2151  case TIM_CHANNEL_4:
2152  {
2153  /* Set the DMA capture callbacks */
2154  htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt;
2155  htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
2156 
2157  /* Set the DMA error callback */
2158  htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
2159 
2160  /* Enable the DMA channel */
2161  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData, Length) != HAL_OK)
2162  {
2163  return HAL_ERROR;
2164  }
2165  /* Enable the TIM Capture/Compare 4 DMA request */
2166  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
2167  break;
2168  }
2169 
2170  default:
2171  break;
2172  }
2173 
2174  /* Enable the Input Capture channel */
2175  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
2176 
2177  /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
2178  tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
2179  if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
2180  {
2181  __HAL_TIM_ENABLE(htim);
2182  }
2183 
2184  /* Return function status */
2185  return HAL_OK;
2186 }
2187 
2199 HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
2200 {
2201  /* Check the parameters */
2202  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
2203  assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
2204 
2205  switch (Channel)
2206  {
2207  case TIM_CHANNEL_1:
2208  {
2209  /* Disable the TIM Capture/Compare 1 DMA request */
2210  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
2211  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
2212  break;
2213  }
2214 
2215  case TIM_CHANNEL_2:
2216  {
2217  /* Disable the TIM Capture/Compare 2 DMA request */
2218  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
2219  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
2220  break;
2221  }
2222 
2223  case TIM_CHANNEL_3:
2224  {
2225  /* Disable the TIM Capture/Compare 3 DMA request */
2226  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
2227  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
2228  break;
2229  }
2230 
2231  case TIM_CHANNEL_4:
2232  {
2233  /* Disable the TIM Capture/Compare 4 DMA request */
2234  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
2235  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
2236  break;
2237  }
2238 
2239  default:
2240  break;
2241  }
2242 
2243  /* Disable the Input Capture channel */
2244  TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
2245 
2246  /* Disable the Peripheral */
2247  __HAL_TIM_DISABLE(htim);
2248 
2249  /* Change the htim state */
2250  htim->State = HAL_TIM_STATE_READY;
2251 
2252  /* Return function status */
2253  return HAL_OK;
2254 }
2294 HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode)
2295 {
2296  /* Check the TIM handle allocation */
2297  if (htim == NULL)
2298  {
2299  return HAL_ERROR;
2300  }
2301 
2302  /* Check the parameters */
2303  assert_param(IS_TIM_INSTANCE(htim->Instance));
2304  assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
2305  assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
2306  assert_param(IS_TIM_OPM_MODE(OnePulseMode));
2307  assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
2308 
2309  if (htim->State == HAL_TIM_STATE_RESET)
2310  {
2311  /* Allocate lock resource and initialize it */
2312  htim->Lock = HAL_UNLOCKED;
2313 
2314 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2315  /* Reset interrupt callbacks to legacy weak callbacks */
2316  TIM_ResetCallback(htim);
2317 
2318  if (htim->OnePulse_MspInitCallback == NULL)
2319  {
2320  htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit;
2321  }
2322  /* Init the low level hardware : GPIO, CLOCK, NVIC */
2323  htim->OnePulse_MspInitCallback(htim);
2324 #else
2325  /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
2327 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2328  }
2329 
2330  /* Set the TIM state */
2331  htim->State = HAL_TIM_STATE_BUSY;
2332 
2333  /* Configure the Time base in the One Pulse Mode */
2334  TIM_Base_SetConfig(htim->Instance, &htim->Init);
2335 
2336  /* Reset the OPM Bit */
2337  htim->Instance->CR1 &= ~TIM_CR1_OPM;
2338 
2339  /* Configure the OPM Mode */
2340  htim->Instance->CR1 |= OnePulseMode;
2341 
2342  /* Initialize the TIM state*/
2343  htim->State = HAL_TIM_STATE_READY;
2344 
2345  return HAL_OK;
2346 }
2347 
2354 {
2355  /* Check the parameters */
2356  assert_param(IS_TIM_INSTANCE(htim->Instance));
2357 
2358  htim->State = HAL_TIM_STATE_BUSY;
2359 
2360  /* Disable the TIM Peripheral Clock */
2361  __HAL_TIM_DISABLE(htim);
2362 
2363 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2364  if (htim->OnePulse_MspDeInitCallback == NULL)
2365  {
2366  htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit;
2367  }
2368  /* DeInit the low level hardware */
2369  htim->OnePulse_MspDeInitCallback(htim);
2370 #else
2371  /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
2373 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2374 
2375  /* Change TIM state */
2376  htim->State = HAL_TIM_STATE_RESET;
2377 
2378  /* Release Lock */
2379  __HAL_UNLOCK(htim);
2380 
2381  return HAL_OK;
2382 }
2383 
2390 {
2391  /* Prevent unused argument(s) compilation warning */
2392  UNUSED(htim);
2393 
2394  /* NOTE : This function should not be modified, when the callback is needed,
2395  the HAL_TIM_OnePulse_MspInit could be implemented in the user file
2396  */
2397 }
2398 
2405 {
2406  /* Prevent unused argument(s) compilation warning */
2407  UNUSED(htim);
2408 
2409  /* NOTE : This function should not be modified, when the callback is needed,
2410  the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file
2411  */
2412 }
2413 
2423 HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2424 {
2425  /* Prevent unused argument(s) compilation warning */
2426  UNUSED(OutputChannel);
2427 
2428  /* Enable the Capture compare and the Input Capture channels
2429  (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2430  if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2431  if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2432  in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
2433 
2434  No need to enable the counter, it's enabled automatically by hardware
2435  (the counter starts in response to a stimulus and generate a pulse */
2436 
2437  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2438  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2439 
2440  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2441  {
2442  /* Enable the main output */
2443  __HAL_TIM_MOE_ENABLE(htim);
2444  }
2445 
2446  /* Return function status */
2447  return HAL_OK;
2448 }
2449 
2459 HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2460 {
2461  /* Prevent unused argument(s) compilation warning */
2462  UNUSED(OutputChannel);
2463 
2464  /* Disable the Capture compare and the Input Capture channels
2465  (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2466  if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2467  if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2468  in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
2469 
2470  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2471  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2472 
2473  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2474  {
2475  /* Disable the Main Output */
2476  __HAL_TIM_MOE_DISABLE(htim);
2477  }
2478 
2479  /* Disable the Peripheral */
2480  __HAL_TIM_DISABLE(htim);
2481 
2482  /* Return function status */
2483  return HAL_OK;
2484 }
2485 
2495 HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2496 {
2497  /* Prevent unused argument(s) compilation warning */
2498  UNUSED(OutputChannel);
2499 
2500  /* Enable the Capture compare and the Input Capture channels
2501  (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2502  if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2503  if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2504  in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
2505 
2506  No need to enable the counter, it's enabled automatically by hardware
2507  (the counter starts in response to a stimulus and generate a pulse */
2508 
2509  /* Enable the TIM Capture/Compare 1 interrupt */
2510  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
2511 
2512  /* Enable the TIM Capture/Compare 2 interrupt */
2513  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
2514 
2515  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2516  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2517 
2518  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2519  {
2520  /* Enable the main output */
2521  __HAL_TIM_MOE_ENABLE(htim);
2522  }
2523 
2524  /* Return function status */
2525  return HAL_OK;
2526 }
2527 
2537 HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2538 {
2539  /* Prevent unused argument(s) compilation warning */
2540  UNUSED(OutputChannel);
2541 
2542  /* Disable the TIM Capture/Compare 1 interrupt */
2543  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
2544 
2545  /* Disable the TIM Capture/Compare 2 interrupt */
2546  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
2547 
2548  /* Disable the Capture compare and the Input Capture channels
2549  (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2550  if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2551  if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2552  in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
2553  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2554  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2555 
2556  if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2557  {
2558  /* Disable the Main Output */
2559  __HAL_TIM_MOE_DISABLE(htim);
2560  }
2561 
2562  /* Disable the Peripheral */
2563  __HAL_TIM_DISABLE(htim);
2564 
2565  /* Return function status */
2566  return HAL_OK;
2567 }
2568 
2608 {
2609  uint32_t tmpsmcr;
2610  uint32_t tmpccmr1;
2611  uint32_t tmpccer;
2612 
2613  /* Check the TIM handle allocation */
2614  if (htim == NULL)
2615  {
2616  return HAL_ERROR;
2617  }
2618 
2619  /* Check the parameters */
2620  assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
2621  assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
2622  assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
2623  assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2624  assert_param(IS_TIM_ENCODER_MODE(sConfig->EncoderMode));
2625  assert_param(IS_TIM_IC_SELECTION(sConfig->IC1Selection));
2626  assert_param(IS_TIM_IC_SELECTION(sConfig->IC2Selection));
2627  assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));
2628  assert_param(IS_TIM_IC_POLARITY(sConfig->IC2Polarity));
2629  assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
2630  assert_param(IS_TIM_IC_PRESCALER(sConfig->IC2Prescaler));
2631  assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
2632  assert_param(IS_TIM_IC_FILTER(sConfig->IC2Filter));
2633 
2634  if (htim->State == HAL_TIM_STATE_RESET)
2635  {
2636  /* Allocate lock resource and initialize it */
2637  htim->Lock = HAL_UNLOCKED;
2638 
2639 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2640  /* Reset interrupt callbacks to legacy weak callbacks */
2641  TIM_ResetCallback(htim);
2642 
2643  if (htim->Encoder_MspInitCallback == NULL)
2644  {
2645  htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit;
2646  }
2647  /* Init the low level hardware : GPIO, CLOCK, NVIC */
2648  htim->Encoder_MspInitCallback(htim);
2649 #else
2650  /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
2652 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2653  }
2654 
2655  /* Set the TIM state */
2656  htim->State = HAL_TIM_STATE_BUSY;
2657 
2658  /* Reset the SMS and ECE bits */
2659  htim->Instance->SMCR &= ~(TIM_SMCR_SMS | TIM_SMCR_ECE);
2660 
2661  /* Configure the Time base in the Encoder Mode */
2662  TIM_Base_SetConfig(htim->Instance, &htim->Init);
2663 
2664  /* Get the TIMx SMCR register value */
2665  tmpsmcr = htim->Instance->SMCR;
2666 
2667  /* Get the TIMx CCMR1 register value */
2668  tmpccmr1 = htim->Instance->CCMR1;
2669 
2670  /* Get the TIMx CCER register value */
2671  tmpccer = htim->Instance->CCER;
2672 
2673  /* Set the encoder Mode */
2674  tmpsmcr |= sConfig->EncoderMode;
2675 
2676  /* Select the Capture Compare 1 and the Capture Compare 2 as input */
2677  tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S);
2678  tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8U));
2679 
2680  /* Set the Capture Compare 1 and the Capture Compare 2 prescalers and filters */
2681  tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC);
2682  tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F);
2683  tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8U);
2684  tmpccmr1 |= (sConfig->IC1Filter << 4U) | (sConfig->IC2Filter << 12U);
2685 
2686  /* Set the TI1 and the TI2 Polarities */
2687  tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P);
2688  tmpccer &= ~(TIM_CCER_CC1NP | TIM_CCER_CC2NP);
2689  tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4U);
2690 
2691  /* Write to TIMx SMCR */
2692  htim->Instance->SMCR = tmpsmcr;
2693 
2694  /* Write to TIMx CCMR1 */
2695  htim->Instance->CCMR1 = tmpccmr1;
2696 
2697  /* Write to TIMx CCER */
2698  htim->Instance->CCER = tmpccer;
2699 
2700  /* Initialize the TIM state*/
2701  htim->State = HAL_TIM_STATE_READY;
2702 
2703  return HAL_OK;
2704 }
2705 
2706 
2713 {
2714  /* Check the parameters */
2715  assert_param(IS_TIM_INSTANCE(htim->Instance));
2716 
2717  htim->State = HAL_TIM_STATE_BUSY;
2718 
2719  /* Disable the TIM Peripheral Clock */
2720  __HAL_TIM_DISABLE(htim);
2721 
2722 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2723  if (htim->Encoder_MspDeInitCallback == NULL)
2724  {
2725  htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit;
2726  }
2727  /* DeInit the low level hardware */
2728  htim->Encoder_MspDeInitCallback(htim);
2729 #else
2730  /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
2732 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2733 
2734  /* Change TIM state */
2735  htim->State = HAL_TIM_STATE_RESET;
2736 
2737  /* Release Lock */
2738  __HAL_UNLOCK(htim);
2739 
2740  return HAL_OK;
2741 }
2742 
2749 {
2750  /* Prevent unused argument(s) compilation warning */
2751  UNUSED(htim);
2752 
2753  /* NOTE : This function should not be modified, when the callback is needed,
2754  the HAL_TIM_Encoder_MspInit could be implemented in the user file
2755  */
2756 }
2757 
2764 {
2765  /* Prevent unused argument(s) compilation warning */
2766  UNUSED(htim);
2767 
2768  /* NOTE : This function should not be modified, when the callback is needed,
2769  the HAL_TIM_Encoder_MspDeInit could be implemented in the user file
2770  */
2771 }
2772 
2783 HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
2784 {
2785  /* Check the parameters */
2786  assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2787 
2788  /* Enable the encoder interface channels */
2789  switch (Channel)
2790  {
2791  case TIM_CHANNEL_1:
2792  {
2793  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2794  break;
2795  }
2796 
2797  case TIM_CHANNEL_2:
2798  {
2799  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2800  break;
2801  }
2802 
2803  default :
2804  {
2805  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2806  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2807  break;
2808  }
2809  }
2810  /* Enable the Peripheral */
2811  __HAL_TIM_ENABLE(htim);
2812 
2813  /* Return function status */
2814  return HAL_OK;
2815 }
2816 
2827 HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
2828 {
2829  /* Check the parameters */
2830  assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2831 
2832  /* Disable the Input Capture channels 1 and 2
2833  (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
2834  switch (Channel)
2835  {
2836  case TIM_CHANNEL_1:
2837  {
2838  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2839  break;
2840  }
2841 
2842  case TIM_CHANNEL_2:
2843  {
2844  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2845  break;
2846  }
2847 
2848  default :
2849  {
2850  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2851  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2852  break;
2853  }
2854  }
2855 
2856  /* Disable the Peripheral */
2857  __HAL_TIM_DISABLE(htim);
2858 
2859  /* Return function status */
2860  return HAL_OK;
2861 }
2862 
2873 HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
2874 {
2875  /* Check the parameters */
2876  assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2877 
2878  /* Enable the encoder interface channels */
2879  /* Enable the capture compare Interrupts 1 and/or 2 */
2880  switch (Channel)
2881  {
2882  case TIM_CHANNEL_1:
2883  {
2884  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2885  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
2886  break;
2887  }
2888 
2889  case TIM_CHANNEL_2:
2890  {
2891  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2892  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
2893  break;
2894  }
2895 
2896  default :
2897  {
2898  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2899  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2900  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
2901  __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
2902  break;
2903  }
2904  }
2905 
2906  /* Enable the Peripheral */
2907  __HAL_TIM_ENABLE(htim);
2908 
2909  /* Return function status */
2910  return HAL_OK;
2911 }
2912 
2923 HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
2924 {
2925  /* Check the parameters */
2926  assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2927 
2928  /* Disable the Input Capture channels 1 and 2
2929  (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
2930  if (Channel == TIM_CHANNEL_1)
2931  {
2932  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2933 
2934  /* Disable the capture compare Interrupts 1 */
2935  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
2936  }
2937  else if (Channel == TIM_CHANNEL_2)
2938  {
2939  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2940 
2941  /* Disable the capture compare Interrupts 2 */
2942  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
2943  }
2944  else
2945  {
2946  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2947  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2948 
2949  /* Disable the capture compare Interrupts 1 and 2 */
2950  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
2951  __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
2952  }
2953 
2954  /* Disable the Peripheral */
2955  __HAL_TIM_DISABLE(htim);
2956 
2957  /* Change the htim state */
2958  htim->State = HAL_TIM_STATE_READY;
2959 
2960  /* Return function status */
2961  return HAL_OK;
2962 }
2963 
2977 HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1,
2978  uint32_t *pData2, uint16_t Length)
2979 {
2980  /* Check the parameters */
2981  assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
2982 
2983  if ((htim->State == HAL_TIM_STATE_BUSY))
2984  {
2985  return HAL_BUSY;
2986  }
2987  else if ((htim->State == HAL_TIM_STATE_READY))
2988  {
2989  if ((((pData1 == NULL) || (pData2 == NULL))) && (Length > 0U))
2990  {
2991  return HAL_ERROR;
2992  }
2993  else
2994  {
2995  htim->State = HAL_TIM_STATE_BUSY;
2996  }
2997  }
2998  else
2999  {
3000  /* nothing to do */
3001  }
3002 
3003  switch (Channel)
3004  {
3005  case TIM_CHANNEL_1:
3006  {
3007  /* Set the DMA capture callbacks */
3008  htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
3009  htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
3010 
3011  /* Set the DMA error callback */
3012  htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
3013 
3014  /* Enable the DMA channel */
3015  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length) != HAL_OK)
3016  {
3017  return HAL_ERROR;
3018  }
3019  /* Enable the TIM Input Capture DMA request */
3020  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
3021 
3022  /* Enable the Peripheral */
3023  __HAL_TIM_ENABLE(htim);
3024 
3025  /* Enable the Capture compare channel */
3026  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
3027  break;
3028  }
3029 
3030  case TIM_CHANNEL_2:
3031  {
3032  /* Set the DMA capture callbacks */
3033  htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
3034  htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
3035 
3036  /* Set the DMA error callback */
3037  htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError;
3038  /* Enable the DMA channel */
3039  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length) != HAL_OK)
3040  {
3041  return HAL_ERROR;
3042  }
3043  /* Enable the TIM Input Capture DMA request */
3044  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
3045 
3046  /* Enable the Peripheral */
3047  __HAL_TIM_ENABLE(htim);
3048 
3049  /* Enable the Capture compare channel */
3050  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
3051  break;
3052  }
3053 
3054  case TIM_CHANNEL_ALL:
3055  {
3056  /* Set the DMA capture callbacks */
3057  htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
3058  htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
3059 
3060  /* Set the DMA error callback */
3061  htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
3062 
3063  /* Enable the DMA channel */
3064  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length) != HAL_OK)
3065  {
3066  return HAL_ERROR;
3067  }
3068 
3069  /* Set the DMA capture callbacks */
3070  htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
3071  htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
3072 
3073  /* Set the DMA error callback */
3074  htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
3075 
3076  /* Enable the DMA channel */
3077  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length) != HAL_OK)
3078  {
3079  return HAL_ERROR;
3080  }
3081  /* Enable the Peripheral */
3082  __HAL_TIM_ENABLE(htim);
3083 
3084  /* Enable the Capture compare channel */
3085  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
3086  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
3087 
3088  /* Enable the TIM Input Capture DMA request */
3089  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
3090  /* Enable the TIM Input Capture DMA request */
3091  __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
3092  break;
3093  }
3094 
3095  default:
3096  break;
3097  }
3098  /* Return function status */
3099  return HAL_OK;
3100 }
3101 
3112 HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
3113 {
3114  /* Check the parameters */
3115  assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
3116 
3117  /* Disable the Input Capture channels 1 and 2
3118  (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
3119  if (Channel == TIM_CHANNEL_1)
3120  {
3121  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
3122 
3123  /* Disable the capture compare DMA Request 1 */
3124  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
3125  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
3126  }
3127  else if (Channel == TIM_CHANNEL_2)
3128  {
3129  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
3130 
3131  /* Disable the capture compare DMA Request 2 */
3132  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
3133  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
3134  }
3135  else
3136  {
3137  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
3138  TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
3139 
3140  /* Disable the capture compare DMA Request 1 and 2 */
3141  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
3142  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
3143  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
3144  (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
3145  }
3146 
3147  /* Disable the Peripheral */
3148  __HAL_TIM_DISABLE(htim);
3149 
3150  /* Change the htim state */
3151  htim->State = HAL_TIM_STATE_READY;
3152 
3153  /* Return function status */
3154  return HAL_OK;
3155 }
3156 
3179 {
3180  /* Capture compare 1 event */
3181  if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET)
3182  {
3183  if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC1) != RESET)
3184  {
3185  {
3186  __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1);
3187  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
3188 
3189  /* Input capture event */
3190  if ((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00U)
3191  {
3192 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3193  htim->IC_CaptureCallback(htim);
3194 #else
3196 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3197  }
3198  /* Output compare event */
3199  else
3200  {
3201 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3202  htim->OC_DelayElapsedCallback(htim);
3203  htim->PWM_PulseFinishedCallback(htim);
3204 #else
3207 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3208  }
3209  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
3210  }
3211  }
3212  }
3213  /* Capture compare 2 event */
3214  if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET)
3215  {
3216  if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC2) != RESET)
3217  {
3218  __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC2);
3219  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
3220  /* Input capture event */
3221  if ((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U)
3222  {
3223 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3224  htim->IC_CaptureCallback(htim);
3225 #else
3227 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3228  }
3229  /* Output compare event */
3230  else
3231  {
3232 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3233  htim->OC_DelayElapsedCallback(htim);
3234  htim->PWM_PulseFinishedCallback(htim);
3235 #else
3238 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3239  }
3240  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
3241  }
3242  }
3243  /* Capture compare 3 event */
3244  if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET)
3245  {
3246  if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC3) != RESET)
3247  {
3248  __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC3);
3249  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
3250  /* Input capture event */
3251  if ((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00U)
3252  {
3253 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3254  htim->IC_CaptureCallback(htim);
3255 #else
3257 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3258  }
3259  /* Output compare event */
3260  else
3261  {
3262 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3263  htim->OC_DelayElapsedCallback(htim);
3264  htim->PWM_PulseFinishedCallback(htim);
3265 #else
3268 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3269  }
3270  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
3271  }
3272  }
3273  /* Capture compare 4 event */
3274  if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET)
3275  {
3276  if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC4) != RESET)
3277  {
3278  __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC4);
3279  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
3280  /* Input capture event */
3281  if ((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00U)
3282  {
3283 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3284  htim->IC_CaptureCallback(htim);
3285 #else
3287 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3288  }
3289  /* Output compare event */
3290  else
3291  {
3292 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3293  htim->OC_DelayElapsedCallback(htim);
3294  htim->PWM_PulseFinishedCallback(htim);
3295 #else
3298 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3299  }
3300  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
3301  }
3302  }
3303  /* TIM Update event */
3304  if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET)
3305  {
3306  if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) != RESET)
3307  {
3308  __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE);
3309 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3310  htim->PeriodElapsedCallback(htim);
3311 #else
3313 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3314  }
3315  }
3316  /* TIM Break input event */
3317  if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK) != RESET)
3318  {
3319  if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) != RESET)
3320  {
3321  __HAL_TIM_CLEAR_IT(htim, TIM_IT_BREAK);
3322 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3323  htim->BreakCallback(htim);
3324 #else
3326 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3327  }
3328  }
3329  /* TIM Break2 input event */
3330  if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK2) != RESET)
3331  {
3332  if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) != RESET)
3333  {
3334  __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_BREAK2);
3335 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3336  htim->Break2Callback(htim);
3337 #else
3339 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3340  }
3341  }
3342  /* TIM Trigger detection event */
3343  if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET)
3344  {
3345  if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_TRIGGER) != RESET)
3346  {
3347  __HAL_TIM_CLEAR_IT(htim, TIM_IT_TRIGGER);
3348 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3349  htim->TriggerCallback(htim);
3350 #else
3352 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3353  }
3354  }
3355  /* TIM commutation event */
3356  if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_COM) != RESET)
3357  {
3358  if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_COM) != RESET)
3359  {
3360  __HAL_TIM_CLEAR_IT(htim, TIM_FLAG_COM);
3361 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3362  htim->CommutationCallback(htim);
3363 #else
3365 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3366  }
3367  }
3368 }
3369 
3409  TIM_OC_InitTypeDef *sConfig,
3410  uint32_t Channel)
3411 {
3412  /* Check the parameters */
3413  assert_param(IS_TIM_CHANNELS(Channel));
3414  assert_param(IS_TIM_OC_MODE(sConfig->OCMode));
3415  assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
3416 
3417  /* Process Locked */
3418  __HAL_LOCK(htim);
3419 
3420  htim->State = HAL_TIM_STATE_BUSY;
3421 
3422  switch (Channel)
3423  {
3424  case TIM_CHANNEL_1:
3425  {
3426  /* Check the parameters */
3427  assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3428 
3429  /* Configure the TIM Channel 1 in Output Compare */
3430  TIM_OC1_SetConfig(htim->Instance, sConfig);
3431  break;
3432  }
3433 
3434  case TIM_CHANNEL_2:
3435  {
3436  /* Check the parameters */
3437  assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3438 
3439  /* Configure the TIM Channel 2 in Output Compare */
3440  TIM_OC2_SetConfig(htim->Instance, sConfig);
3441  break;
3442  }
3443 
3444  case TIM_CHANNEL_3:
3445  {
3446  /* Check the parameters */
3447  assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
3448 
3449  /* Configure the TIM Channel 3 in Output Compare */
3450  TIM_OC3_SetConfig(htim->Instance, sConfig);
3451  break;
3452  }
3453 
3454  case TIM_CHANNEL_4:
3455  {
3456  /* Check the parameters */
3457  assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
3458 
3459  /* Configure the TIM Channel 4 in Output Compare */
3460  TIM_OC4_SetConfig(htim->Instance, sConfig);
3461  break;
3462  }
3463 
3464  case TIM_CHANNEL_5:
3465  {
3466  /* Check the parameters */
3467  assert_param(IS_TIM_CC5_INSTANCE(htim->Instance));
3468 
3469  /* Configure the TIM Channel 5 in Output Compare */
3470  TIM_OC5_SetConfig(htim->Instance, sConfig);
3471  break;
3472  }
3473 
3474  case TIM_CHANNEL_6:
3475  {
3476  /* Check the parameters */
3477  assert_param(IS_TIM_CC6_INSTANCE(htim->Instance));
3478 
3479  /* Configure the TIM Channel 6 in Output Compare */
3480  TIM_OC6_SetConfig(htim->Instance, sConfig);
3481  break;
3482  }
3483 
3484  default:
3485  break;
3486  }
3487 
3488  htim->State = HAL_TIM_STATE_READY;
3489 
3490  __HAL_UNLOCK(htim);
3491 
3492  return HAL_OK;
3493 }
3494 
3508 HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef *sConfig, uint32_t Channel)
3509 {
3510  /* Check the parameters */
3511  assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3512  assert_param(IS_TIM_IC_POLARITY(sConfig->ICPolarity));
3513  assert_param(IS_TIM_IC_SELECTION(sConfig->ICSelection));
3514  assert_param(IS_TIM_IC_PRESCALER(sConfig->ICPrescaler));
3515  assert_param(IS_TIM_IC_FILTER(sConfig->ICFilter));
3516 
3517  /* Process Locked */
3518  __HAL_LOCK(htim);
3519 
3520  htim->State = HAL_TIM_STATE_BUSY;
3521 
3522  if (Channel == TIM_CHANNEL_1)
3523  {
3524  /* TI1 Configuration */
3525  TIM_TI1_SetConfig(htim->Instance,
3526  sConfig->ICPolarity,
3527  sConfig->ICSelection,
3528  sConfig->ICFilter);
3529 
3530  /* Reset the IC1PSC Bits */
3531  htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
3532 
3533  /* Set the IC1PSC value */
3534  htim->Instance->CCMR1 |= sConfig->ICPrescaler;
3535  }
3536  else if (Channel == TIM_CHANNEL_2)
3537  {
3538  /* TI2 Configuration */
3539  assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3540 
3541  TIM_TI2_SetConfig(htim->Instance,
3542  sConfig->ICPolarity,
3543  sConfig->ICSelection,
3544  sConfig->ICFilter);
3545 
3546  /* Reset the IC2PSC Bits */
3547  htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
3548 
3549  /* Set the IC2PSC value */
3550  htim->Instance->CCMR1 |= (sConfig->ICPrescaler << 8U);
3551  }
3552  else if (Channel == TIM_CHANNEL_3)
3553  {
3554  /* TI3 Configuration */
3555  assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
3556 
3557  TIM_TI3_SetConfig(htim->Instance,
3558  sConfig->ICPolarity,
3559  sConfig->ICSelection,
3560  sConfig->ICFilter);
3561 
3562  /* Reset the IC3PSC Bits */
3563  htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC;
3564 
3565  /* Set the IC3PSC value */
3566  htim->Instance->CCMR2 |= sConfig->ICPrescaler;
3567  }
3568  else
3569  {
3570  /* TI4 Configuration */
3571  assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
3572 
3573  TIM_TI4_SetConfig(htim->Instance,
3574  sConfig->ICPolarity,
3575  sConfig->ICSelection,
3576  sConfig->ICFilter);
3577 
3578  /* Reset the IC4PSC Bits */
3579  htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC;
3580 
3581  /* Set the IC4PSC value */
3582  htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8U);
3583  }
3584 
3585  htim->State = HAL_TIM_STATE_READY;
3586 
3587  __HAL_UNLOCK(htim);
3588 
3589  return HAL_OK;
3590 }
3591 
3608  TIM_OC_InitTypeDef *sConfig,
3609  uint32_t Channel)
3610 {
3611  /* Check the parameters */
3612  assert_param(IS_TIM_CHANNELS(Channel));
3613  assert_param(IS_TIM_PWM_MODE(sConfig->OCMode));
3614  assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
3615  assert_param(IS_TIM_FAST_STATE(sConfig->OCFastMode));
3616 
3617  /* Process Locked */
3618  __HAL_LOCK(htim);
3619 
3620  htim->State = HAL_TIM_STATE_BUSY;
3621 
3622  switch (Channel)
3623  {
3624  case TIM_CHANNEL_1:
3625  {
3626  /* Check the parameters */
3627  assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3628 
3629  /* Configure the Channel 1 in PWM mode */
3630  TIM_OC1_SetConfig(htim->Instance, sConfig);
3631 
3632  /* Set the Preload enable bit for channel1 */
3633  htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE;
3634 
3635  /* Configure the Output Fast mode */
3636  htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE;
3637  htim->Instance->CCMR1 |= sConfig->OCFastMode;
3638  break;
3639  }
3640 
3641  case TIM_CHANNEL_2:
3642  {
3643  /* Check the parameters */
3644  assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3645 
3646  /* Configure the Channel 2 in PWM mode */
3647  TIM_OC2_SetConfig(htim->Instance, sConfig);
3648 
3649  /* Set the Preload enable bit for channel2 */
3650  htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE;
3651 
3652  /* Configure the Output Fast mode */
3653  htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE;
3654  htim->Instance->CCMR1 |= sConfig->OCFastMode << 8U;
3655  break;
3656  }
3657 
3658  case TIM_CHANNEL_3:
3659  {
3660  /* Check the parameters */
3661  assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
3662 
3663  /* Configure the Channel 3 in PWM mode */
3664  TIM_OC3_SetConfig(htim->Instance, sConfig);
3665 
3666  /* Set the Preload enable bit for channel3 */
3667  htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE;
3668 
3669  /* Configure the Output Fast mode */
3670  htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE;
3671  htim->Instance->CCMR2 |= sConfig->OCFastMode;
3672  break;
3673  }
3674 
3675  case TIM_CHANNEL_4:
3676  {
3677  /* Check the parameters */
3678  assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
3679 
3680  /* Configure the Channel 4 in PWM mode */
3681  TIM_OC4_SetConfig(htim->Instance, sConfig);
3682 
3683  /* Set the Preload enable bit for channel4 */
3684  htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE;
3685 
3686  /* Configure the Output Fast mode */
3687  htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE;
3688  htim->Instance->CCMR2 |= sConfig->OCFastMode << 8U;
3689  break;
3690  }
3691 
3692  case TIM_CHANNEL_5:
3693  {
3694  /* Check the parameters */
3695  assert_param(IS_TIM_CC5_INSTANCE(htim->Instance));
3696 
3697  /* Configure the Channel 5 in PWM mode */
3698  TIM_OC5_SetConfig(htim->Instance, sConfig);
3699 
3700  /* Set the Preload enable bit for channel5*/
3701  htim->Instance->CCMR3 |= TIM_CCMR3_OC5PE;
3702 
3703  /* Configure the Output Fast mode */
3704  htim->Instance->CCMR3 &= ~TIM_CCMR3_OC5FE;
3705  htim->Instance->CCMR3 |= sConfig->OCFastMode;
3706  break;
3707  }
3708 
3709  case TIM_CHANNEL_6:
3710  {
3711  /* Check the parameters */
3712  assert_param(IS_TIM_CC6_INSTANCE(htim->Instance));
3713 
3714  /* Configure the Channel 6 in PWM mode */
3715  TIM_OC6_SetConfig(htim->Instance, sConfig);
3716 
3717  /* Set the Preload enable bit for channel6 */
3718  htim->Instance->CCMR3 |= TIM_CCMR3_OC6PE;
3719 
3720  /* Configure the Output Fast mode */
3721  htim->Instance->CCMR3 &= ~TIM_CCMR3_OC6FE;
3722  htim->Instance->CCMR3 |= sConfig->OCFastMode << 8U;
3723  break;
3724  }
3725 
3726  default:
3727  break;
3728  }
3729 
3730  htim->State = HAL_TIM_STATE_READY;
3731 
3732  __HAL_UNLOCK(htim);
3733 
3734  return HAL_OK;
3735 }
3736 
3753  uint32_t OutputChannel, uint32_t InputChannel)
3754 {
3755  TIM_OC_InitTypeDef temp1;
3756 
3757  /* Check the parameters */
3758  assert_param(IS_TIM_OPM_CHANNELS(OutputChannel));
3759  assert_param(IS_TIM_OPM_CHANNELS(InputChannel));
3760 
3761  if (OutputChannel != InputChannel)
3762  {
3763  /* Process Locked */
3764  __HAL_LOCK(htim);
3765 
3766  htim->State = HAL_TIM_STATE_BUSY;
3767 
3768  /* Extract the Output compare configuration from sConfig structure */
3769  temp1.OCMode = sConfig->OCMode;
3770  temp1.Pulse = sConfig->Pulse;
3771  temp1.OCPolarity = sConfig->OCPolarity;
3772  temp1.OCNPolarity = sConfig->OCNPolarity;
3773  temp1.OCIdleState = sConfig->OCIdleState;
3774  temp1.OCNIdleState = sConfig->OCNIdleState;
3775 
3776  switch (OutputChannel)
3777  {
3778  case TIM_CHANNEL_1:
3779  {
3780  assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3781 
3782  TIM_OC1_SetConfig(htim->Instance, &temp1);
3783  break;
3784  }
3785  case TIM_CHANNEL_2:
3786  {
3787  assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3788 
3789  TIM_OC2_SetConfig(htim->Instance, &temp1);
3790  break;
3791  }
3792  default:
3793  break;
3794  }
3795 
3796  switch (InputChannel)
3797  {
3798  case TIM_CHANNEL_1:
3799  {
3800  assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3801 
3802  TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity,
3803  sConfig->ICSelection, sConfig->ICFilter);
3804 
3805  /* Reset the IC1PSC Bits */
3806  htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
3807 
3808  /* Select the Trigger source */
3809  htim->Instance->SMCR &= ~TIM_SMCR_TS;
3810  htim->Instance->SMCR |= TIM_TS_TI1FP1;
3811 
3812  /* Select the Slave Mode */
3813  htim->Instance->SMCR &= ~TIM_SMCR_SMS;
3814  htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
3815  break;
3816  }
3817  case TIM_CHANNEL_2:
3818  {
3819  assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3820 
3821  TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity,
3822  sConfig->ICSelection, sConfig->ICFilter);
3823 
3824  /* Reset the IC2PSC Bits */
3825  htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
3826 
3827  /* Select the Trigger source */
3828  htim->Instance->SMCR &= ~TIM_SMCR_TS;
3829  htim->Instance->SMCR |= TIM_TS_TI2FP2;
3830 
3831  /* Select the Slave Mode */
3832  htim->Instance->SMCR &= ~TIM_SMCR_SMS;
3833  htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
3834  break;
3835  }
3836 
3837  default:
3838  break;
3839  }
3840 
3841  htim->State = HAL_TIM_STATE_READY;
3842 
3843  __HAL_UNLOCK(htim);
3844 
3845  return HAL_OK;
3846  }
3847  else
3848  {
3849  return HAL_ERROR;
3850  }
3851 }
3852 
3897 HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc,
3898  uint32_t *BurstBuffer, uint32_t BurstLength)
3899 {
3900  /* Check the parameters */
3901  assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
3902  assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
3903  assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
3904  assert_param(IS_TIM_DMA_LENGTH(BurstLength));
3905 
3906  if ((htim->State == HAL_TIM_STATE_BUSY))
3907  {
3908  return HAL_BUSY;
3909  }
3910  else if ((htim->State == HAL_TIM_STATE_READY))
3911  {
3912  if ((BurstBuffer == NULL) && (BurstLength > 0U))
3913  {
3914  return HAL_ERROR;
3915  }
3916  else
3917  {
3918  htim->State = HAL_TIM_STATE_BUSY;
3919  }
3920  }
3921  else
3922  {
3923  /* nothing to do */
3924  }
3925  switch (BurstRequestSrc)
3926  {
3927  case TIM_DMA_UPDATE:
3928  {
3929  /* Set the DMA Period elapsed callbacks */
3930  htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
3931  htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
3932 
3933  /* Set the DMA error callback */
3934  htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
3935 
3936  /* Enable the DMA channel */
3937  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
3938  {
3939  return HAL_ERROR;
3940  }
3941  break;
3942  }
3943  case TIM_DMA_CC1:
3944  {
3945  /* Set the DMA compare callbacks */
3946  htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
3947  htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
3948 
3949  /* Set the DMA error callback */
3950  htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
3951 
3952  /* Enable the DMA channel */
3953  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer,
3954  (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
3955  {
3956  return HAL_ERROR;
3957  }
3958  break;
3959  }
3960  case TIM_DMA_CC2:
3961  {
3962  /* Set the DMA compare callbacks */
3963  htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
3964  htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
3965 
3966  /* Set the DMA error callback */
3967  htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
3968 
3969  /* Enable the DMA channel */
3970  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer,
3971  (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
3972  {
3973  return HAL_ERROR;
3974  }
3975  break;
3976  }
3977  case TIM_DMA_CC3:
3978  {
3979  /* Set the DMA compare callbacks */
3980  htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
3981  htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
3982 
3983  /* Set the DMA error callback */
3984  htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
3985 
3986  /* Enable the DMA channel */
3987  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer,
3988  (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
3989  {
3990  return HAL_ERROR;
3991  }
3992  break;
3993  }
3994  case TIM_DMA_CC4:
3995  {
3996  /* Set the DMA compare callbacks */
3997  htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
3998  htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
3999 
4000  /* Set the DMA error callback */
4001  htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
4002 
4003  /* Enable the DMA channel */
4004  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer,
4005  (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4006  {
4007  return HAL_ERROR;
4008  }
4009  break;
4010  }
4011  case TIM_DMA_COM:
4012  {
4013  /* Set the DMA commutation callbacks */
4014  htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
4015  htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback = TIMEx_DMACommutationHalfCplt;
4016 
4017  /* Set the DMA error callback */
4018  htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ;
4019 
4020  /* Enable the DMA channel */
4021  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)BurstBuffer,
4022  (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4023  {
4024  return HAL_ERROR;
4025  }
4026  break;
4027  }
4028  case TIM_DMA_TRIGGER:
4029  {
4030  /* Set the DMA trigger callbacks */
4031  htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
4032  htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt;
4033 
4034  /* Set the DMA error callback */
4035  htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ;
4036 
4037  /* Enable the DMA channel */
4038  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer,
4039  (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4040  {
4041  return HAL_ERROR;
4042  }
4043  break;
4044  }
4045  default:
4046  break;
4047  }
4048  /* configure the DMA Burst Mode */
4049  htim->Instance->DCR = (BurstBaseAddress | BurstLength);
4050 
4051  /* Enable the TIM DMA Request */
4052  __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
4053 
4054  htim->State = HAL_TIM_STATE_READY;
4055 
4056  /* Return function status */
4057  return HAL_OK;
4058 }
4059 
4066 HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
4067 {
4068  HAL_StatusTypeDef status = HAL_OK;
4069  /* Check the parameters */
4070  assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
4071 
4072  /* Abort the DMA transfer (at least disable the DMA channel) */
4073  switch (BurstRequestSrc)
4074  {
4075  case TIM_DMA_UPDATE:
4076  {
4077  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]);
4078  break;
4079  }
4080  case TIM_DMA_CC1:
4081  {
4082  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
4083  break;
4084  }
4085  case TIM_DMA_CC2:
4086  {
4087  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
4088  break;
4089  }
4090  case TIM_DMA_CC3:
4091  {
4092  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
4093  break;
4094  }
4095  case TIM_DMA_CC4:
4096  {
4097  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
4098  break;
4099  }
4100  case TIM_DMA_COM:
4101  {
4102  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_COMMUTATION]);
4103  break;
4104  }
4105  case TIM_DMA_TRIGGER:
4106  {
4107  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_TRIGGER]);
4108  break;
4109  }
4110  default:
4111  break;
4112  }
4113 
4114  if (HAL_OK == status)
4115  {
4116  /* Disable the TIM Update DMA request */
4117  __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
4118  }
4119 
4120  /* Return function status */
4121  return status;
4122 }
4123 
4168 HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
4169  uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength)
4170 {
4171  /* Check the parameters */
4172  assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
4173  assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
4174  assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
4175  assert_param(IS_TIM_DMA_LENGTH(BurstLength));
4176 
4177  if ((htim->State == HAL_TIM_STATE_BUSY))
4178  {
4179  return HAL_BUSY;
4180  }
4181  else if ((htim->State == HAL_TIM_STATE_READY))
4182  {
4183  if ((BurstBuffer == NULL) && (BurstLength > 0U))
4184  {
4185  return HAL_ERROR;
4186  }
4187  else
4188  {
4189  htim->State = HAL_TIM_STATE_BUSY;
4190  }
4191  }
4192  else
4193  {
4194  /* nothing to do */
4195  }
4196  switch (BurstRequestSrc)
4197  {
4198  case TIM_DMA_UPDATE:
4199  {
4200  /* Set the DMA Period elapsed callbacks */
4201  htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
4202  htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
4203 
4204  /* Set the DMA error callback */
4205  htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
4206 
4207  /* Enable the DMA channel */
4208  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4209  {
4210  return HAL_ERROR;
4211  }
4212  break;
4213  }
4214  case TIM_DMA_CC1:
4215  {
4216  /* Set the DMA capture callbacks */
4217  htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
4218  htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
4219 
4220  /* Set the DMA error callback */
4221  htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
4222 
4223  /* Enable the DMA channel */
4224  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4225  {
4226  return HAL_ERROR;
4227  }
4228  break;
4229  }
4230  case TIM_DMA_CC2:
4231  {
4232  /* Set the DMA capture/compare callbacks */
4233  htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
4234  htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
4235 
4236  /* Set the DMA error callback */
4237  htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
4238 
4239  /* Enable the DMA channel */
4240  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4241  {
4242  return HAL_ERROR;
4243  }
4244  break;
4245  }
4246  case TIM_DMA_CC3:
4247  {
4248  /* Set the DMA capture callbacks */
4249  htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt;
4250  htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
4251 
4252  /* Set the DMA error callback */
4253  htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
4254 
4255  /* Enable the DMA channel */
4256  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4257  {
4258  return HAL_ERROR;
4259  }
4260  break;
4261  }
4262  case TIM_DMA_CC4:
4263  {
4264  /* Set the DMA capture callbacks */
4265  htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt;
4266  htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
4267 
4268  /* Set the DMA error callback */
4269  htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
4270 
4271  /* Enable the DMA channel */
4272  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4273  {
4274  return HAL_ERROR;
4275  }
4276  break;
4277  }
4278  case TIM_DMA_COM:
4279  {
4280  /* Set the DMA commutation callbacks */
4281  htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
4282  htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback = TIMEx_DMACommutationHalfCplt;
4283 
4284  /* Set the DMA error callback */
4285  htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ;
4286 
4287  /* Enable the DMA channel */
4288  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4289  {
4290  return HAL_ERROR;
4291  }
4292  break;
4293  }
4294  case TIM_DMA_TRIGGER:
4295  {
4296  /* Set the DMA trigger callbacks */
4297  htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
4298  htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt;
4299 
4300  /* Set the DMA error callback */
4301  htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ;
4302 
4303  /* Enable the DMA channel */
4304  if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4305  {
4306  return HAL_ERROR;
4307  }
4308  break;
4309  }
4310  default:
4311  break;
4312  }
4313 
4314  /* configure the DMA Burst Mode */
4315  htim->Instance->DCR = (BurstBaseAddress | BurstLength);
4316 
4317  /* Enable the TIM DMA Request */
4318  __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
4319 
4320  htim->State = HAL_TIM_STATE_READY;
4321 
4322  /* Return function status */
4323  return HAL_OK;
4324 }
4325 
4332 HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
4333 {
4334  HAL_StatusTypeDef status = HAL_OK;
4335  /* Check the parameters */
4336  assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
4337 
4338  /* Abort the DMA transfer (at least disable the DMA channel) */
4339  switch (BurstRequestSrc)
4340  {
4341  case TIM_DMA_UPDATE:
4342  {
4343  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]);
4344  break;
4345  }
4346  case TIM_DMA_CC1:
4347  {
4348  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
4349  break;
4350  }
4351  case TIM_DMA_CC2:
4352  {
4353  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
4354  break;
4355  }
4356  case TIM_DMA_CC3:
4357  {
4358  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
4359  break;
4360  }
4361  case TIM_DMA_CC4:
4362  {
4363  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
4364  break;
4365  }
4366  case TIM_DMA_COM:
4367  {
4368  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_COMMUTATION]);
4369  break;
4370  }
4371  case TIM_DMA_TRIGGER:
4372  {
4373  status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_TRIGGER]);
4374  break;
4375  }
4376  default:
4377  break;
4378  }
4379 
4380  if (HAL_OK == status)
4381  {
4382  /* Disable the TIM Update DMA request */
4383  __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
4384  }
4385 
4386  /* Return function status */
4387  return status;
4388 }
4389 
4411 HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource)
4412 {
4413  /* Check the parameters */
4414  assert_param(IS_TIM_INSTANCE(htim->Instance));
4415  assert_param(IS_TIM_EVENT_SOURCE(EventSource));
4416 
4417  /* Process Locked */
4418  __HAL_LOCK(htim);
4419 
4420  /* Change the TIM state */
4421  htim->State = HAL_TIM_STATE_BUSY;
4422 
4423  /* Set the event sources */
4424  htim->Instance->EGR = EventSource;
4425 
4426  /* Change the TIM state */
4427  htim->State = HAL_TIM_STATE_READY;
4428 
4429  __HAL_UNLOCK(htim);
4430 
4431  /* Return function status */
4432  return HAL_OK;
4433 }
4434 
4451  TIM_ClearInputConfigTypeDef *sClearInputConfig,
4452  uint32_t Channel)
4453 {
4454  /* Check the parameters */
4455  assert_param(IS_TIM_OCXREF_CLEAR_INSTANCE(htim->Instance));
4456  assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource));
4457 
4458  /* Process Locked */
4459  __HAL_LOCK(htim);
4460 
4461  htim->State = HAL_TIM_STATE_BUSY;
4462 
4463  switch (sClearInputConfig->ClearInputSource)
4464  {
4465  case TIM_CLEARINPUTSOURCE_NONE:
4466  {
4467  /* Clear the OCREF clear selection bit and the the ETR Bits */
4468  CLEAR_BIT(htim->Instance->SMCR, (TIM_SMCR_OCCS | TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP));
4469  break;
4470  }
4471  case TIM_CLEARINPUTSOURCE_OCREFCLR:
4472  {
4473  /* Clear the OCREF clear selection bit */
4474  CLEAR_BIT(htim->Instance->SMCR, TIM_SMCR_OCCS);
4475  }
4476  break;
4477 
4478  case TIM_CLEARINPUTSOURCE_ETR:
4479  {
4480  /* Check the parameters */
4481  assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity));
4482  assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler));
4483  assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter));
4484 
4485  /* When OCRef clear feature is used with ETR source, ETR prescaler must be off */
4486  if (sClearInputConfig->ClearInputPrescaler != TIM_CLEARINPUTPRESCALER_DIV1)
4487  {
4488  htim->State = HAL_TIM_STATE_READY;
4489  __HAL_UNLOCK(htim);
4490  return HAL_ERROR;
4491  }
4492 
4493  TIM_ETR_SetConfig(htim->Instance,
4494  sClearInputConfig->ClearInputPrescaler,
4495  sClearInputConfig->ClearInputPolarity,
4496  sClearInputConfig->ClearInputFilter);
4497 
4498  /* Set the OCREF clear selection bit */
4499  SET_BIT(htim->Instance->SMCR, TIM_SMCR_OCCS);
4500  break;
4501  }
4502 
4503  default:
4504  break;
4505  }
4506 
4507  switch (Channel)
4508  {
4509  case TIM_CHANNEL_1:
4510  {
4511  if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
4512  {
4513  /* Enable the OCREF clear feature for Channel 1 */
4514  SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE);
4515  }
4516  else
4517  {
4518  /* Disable the OCREF clear feature for Channel 1 */
4519  CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE);
4520  }
4521  break;
4522  }
4523  case TIM_CHANNEL_2:
4524  {
4525  if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
4526  {
4527  /* Enable the OCREF clear feature for Channel 2 */
4528  SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE);
4529  }
4530  else
4531  {
4532  /* Disable the OCREF clear feature for Channel 2 */
4533  CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE);
4534  }
4535  break;
4536  }
4537  case TIM_CHANNEL_3:
4538  {
4539  if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
4540  {
4541  /* Enable the OCREF clear feature for Channel 3 */
4542  SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE);
4543  }
4544  else
4545  {
4546  /* Disable the OCREF clear feature for Channel 3 */
4547  CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE);
4548  }
4549  break;
4550  }
4551  case TIM_CHANNEL_4:
4552  {
4553  if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
4554  {
4555  /* Enable the OCREF clear feature for Channel 4 */
4556  SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE);
4557  }
4558  else
4559  {
4560  /* Disable the OCREF clear feature for Channel 4 */
4561  CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE);
4562  }
4563  break;
4564  }
4565  case TIM_CHANNEL_5:
4566  {
4567  if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
4568  {
4569  /* Enable the OCREF clear feature for Channel 5 */
4570  SET_BIT(htim->Instance->CCMR3, TIM_CCMR3_OC5CE);
4571  }
4572  else
4573  {
4574  /* Disable the OCREF clear feature for Channel 5 */
4575  CLEAR_BIT(htim->Instance->CCMR3, TIM_CCMR3_OC5CE);
4576  }
4577  break;
4578  }
4579  case TIM_CHANNEL_6:
4580  {
4581  if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
4582  {
4583  /* Enable the OCREF clear feature for Channel 6 */
4584  SET_BIT(htim->Instance->CCMR3, TIM_CCMR3_OC6CE);
4585  }
4586  else
4587  {
4588  /* Disable the OCREF clear feature for Channel 6 */
4589  CLEAR_BIT(htim->Instance->CCMR3, TIM_CCMR3_OC6CE);
4590  }
4591  break;
4592  }
4593  default:
4594  break;
4595  }
4596 
4597  htim->State = HAL_TIM_STATE_READY;
4598 
4599  __HAL_UNLOCK(htim);
4600 
4601  return HAL_OK;
4602 }
4603 
4611 HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef *sClockSourceConfig)
4612 {
4613  uint32_t tmpsmcr;
4614 
4615  /* Process Locked */
4616  __HAL_LOCK(htim);
4617 
4618  htim->State = HAL_TIM_STATE_BUSY;
4619 
4620  /* Check the parameters */
4621  assert_param(IS_TIM_CLOCKSOURCE(sClockSourceConfig->ClockSource));
4622 
4623  /* Reset the SMS, TS, ECE, ETPS and ETRF bits */
4624  tmpsmcr = htim->Instance->SMCR;
4625  tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
4626  tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
4627  htim->Instance->SMCR = tmpsmcr;
4628 
4629  switch (sClockSourceConfig->ClockSource)
4630  {
4631  case TIM_CLOCKSOURCE_INTERNAL:
4632  {
4633  assert_param(IS_TIM_INSTANCE(htim->Instance));
4634  break;
4635  }
4636 
4637  case TIM_CLOCKSOURCE_ETRMODE1:
4638  {
4639  /* Check whether or not the timer instance supports external trigger input mode 1 (ETRF)*/
4640  assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance));
4641 
4642  /* Check ETR input conditioning related parameters */
4643  assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
4644  assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4645  assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4646 
4647  /* Configure the ETR Clock source */
4648  TIM_ETR_SetConfig(htim->Instance,
4649  sClockSourceConfig->ClockPrescaler,
4650  sClockSourceConfig->ClockPolarity,
4651  sClockSourceConfig->ClockFilter);
4652 
4653  /* Select the External clock mode1 and the ETRF trigger */
4654  tmpsmcr = htim->Instance->SMCR;
4655  tmpsmcr |= (TIM_SLAVEMODE_EXTERNAL1 | TIM_CLOCKSOURCE_ETRMODE1);
4656  /* Write to TIMx SMCR */
4657  htim->Instance->SMCR = tmpsmcr;
4658  break;
4659  }
4660 
4661  case TIM_CLOCKSOURCE_ETRMODE2:
4662  {
4663  /* Check whether or not the timer instance supports external trigger input mode 2 (ETRF)*/
4664  assert_param(IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(htim->Instance));
4665 
4666  /* Check ETR input conditioning related parameters */
4667  assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
4668  assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4669  assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4670 
4671  /* Configure the ETR Clock source */
4672  TIM_ETR_SetConfig(htim->Instance,
4673  sClockSourceConfig->ClockPrescaler,
4674  sClockSourceConfig->ClockPolarity,
4675  sClockSourceConfig->ClockFilter);
4676  /* Enable the External clock mode2 */
4677  htim->Instance->SMCR |= TIM_SMCR_ECE;
4678  break;
4679  }
4680 
4681  case TIM_CLOCKSOURCE_TI1:
4682  {
4683  /* Check whether or not the timer instance supports external clock mode 1 */
4684  assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
4685 
4686  /* Check TI1 input conditioning related parameters */
4687  assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4688  assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4689 
4690  TIM_TI1_ConfigInputStage(htim->Instance,
4691  sClockSourceConfig->ClockPolarity,
4692  sClockSourceConfig->ClockFilter);
4693  TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1);
4694  break;
4695  }
4696 
4697  case TIM_CLOCKSOURCE_TI2:
4698  {
4699  /* Check whether or not the timer instance supports external clock mode 1 (ETRF)*/
4700  assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
4701 
4702  /* Check TI2 input conditioning related parameters */
4703  assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4704  assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4705 
4706  TIM_TI2_ConfigInputStage(htim->Instance,
4707  sClockSourceConfig->ClockPolarity,
4708  sClockSourceConfig->ClockFilter);
4709  TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2);
4710  break;
4711  }
4712 
4713  case TIM_CLOCKSOURCE_TI1ED:
4714  {
4715  /* Check whether or not the timer instance supports external clock mode 1 */
4716  assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
4717 
4718  /* Check TI1 input conditioning related parameters */
4719  assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4720  assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4721 
4722  TIM_TI1_ConfigInputStage(htim->Instance,
4723  sClockSourceConfig->ClockPolarity,
4724  sClockSourceConfig->ClockFilter);
4725  TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED);
4726  break;
4727  }
4728 
4729  case TIM_CLOCKSOURCE_ITR0:
4730  case TIM_CLOCKSOURCE_ITR1:
4731  case TIM_CLOCKSOURCE_ITR2:
4732  case TIM_CLOCKSOURCE_ITR3:
4733  {
4734  /* Check whether or not the timer instance supports internal trigger input */
4735  assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
4736 
4737  TIM_ITRx_SetConfig(htim->Instance, sClockSourceConfig->ClockSource);
4738  break;
4739  }
4740 
4741  default:
4742  break;
4743  }
4744  htim->State = HAL_TIM_STATE_READY;
4745 
4746  __HAL_UNLOCK(htim);
4747 
4748  return HAL_OK;
4749 }
4750 
4763 HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection)
4764 {
4765  uint32_t tmpcr2;
4766 
4767  /* Check the parameters */
4768  assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
4769  assert_param(IS_TIM_TI1SELECTION(TI1_Selection));
4770 
4771  /* Get the TIMx CR2 register value */
4772  tmpcr2 = htim->Instance->CR2;
4773 
4774  /* Reset the TI1 selection */
4775  tmpcr2 &= ~TIM_CR2_TI1S;
4776 
4777  /* Set the TI1 selection */
4778  tmpcr2 |= TI1_Selection;
4779 
4780  /* Write to TIMxCR2 */
4781  htim->Instance->CR2 = tmpcr2;
4782 
4783  return HAL_OK;
4784 }
4785 
4796 {
4797  /* Check the parameters */
4798  assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
4799  assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
4800  assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
4801 
4802  __HAL_LOCK(htim);
4803 
4804  htim->State = HAL_TIM_STATE_BUSY;
4805 
4806  if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK)
4807  {
4808  htim->State = HAL_TIM_STATE_READY;
4809  __HAL_UNLOCK(htim);
4810  return HAL_ERROR;
4811  }
4812 
4813  /* Disable Trigger Interrupt */
4814  __HAL_TIM_DISABLE_IT(htim, TIM_IT_TRIGGER);
4815 
4816  /* Disable Trigger DMA request */
4817  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER);
4818 
4819  htim->State = HAL_TIM_STATE_READY;
4820 
4821  __HAL_UNLOCK(htim);
4822 
4823  return HAL_OK;
4824 }
4825 
4836  TIM_SlaveConfigTypeDef *sSlaveConfig)
4837 {
4838  /* Check the parameters */
4839  assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
4840  assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
4841  assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
4842 
4843  __HAL_LOCK(htim);
4844 
4845  htim->State = HAL_TIM_STATE_BUSY;
4846 
4847  if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK)
4848  {
4849  htim->State = HAL_TIM_STATE_READY;
4850  __HAL_UNLOCK(htim);
4851  return HAL_ERROR;
4852  }
4853 
4854  /* Enable Trigger Interrupt */
4855  __HAL_TIM_ENABLE_IT(htim, TIM_IT_TRIGGER);
4856 
4857  /* Disable Trigger DMA request */
4858  __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER);
4859 
4860  htim->State = HAL_TIM_STATE_READY;
4861 
4862  __HAL_UNLOCK(htim);
4863 
4864  return HAL_OK;
4865 }
4866 
4878 uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel)
4879 {
4880  uint32_t tmpreg = 0U;
4881 
4882  switch (Channel)
4883  {
4884  case TIM_CHANNEL_1:
4885  {
4886  /* Check the parameters */
4887  assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
4888 
4889  /* Return the capture 1 value */
4890  tmpreg = htim->Instance->CCR1;
4891 
4892  break;
4893  }
4894  case TIM_CHANNEL_2:
4895  {
4896  /* Check the parameters */
4897  assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
4898 
4899  /* Return the capture 2 value */
4900  tmpreg = htim->Instance->CCR2;
4901 
4902  break;
4903  }
4904 
4905  case TIM_CHANNEL_3:
4906  {
4907  /* Check the parameters */
4908  assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
4909 
4910  /* Return the capture 3 value */
4911  tmpreg = htim->Instance->CCR3;
4912 
4913  break;
4914  }
4915 
4916  case TIM_CHANNEL_4:
4917  {
4918  /* Check the parameters */
4919  assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
4920 
4921  /* Return the capture 4 value */
4922  tmpreg = htim->Instance->CCR4;
4923 
4924  break;
4925  }
4926 
4927  default:
4928  break;
4929  }
4930 
4931  return tmpreg;
4932 }
4933 
4963 {
4964  /* Prevent unused argument(s) compilation warning */
4965  UNUSED(htim);
4966 
4967  /* NOTE : This function should not be modified, when the callback is needed,
4968  the HAL_TIM_PeriodElapsedCallback could be implemented in the user file
4969  */
4970 }
4971 
4978 {
4979  /* Prevent unused argument(s) compilation warning */
4980  UNUSED(htim);
4981 
4982  /* NOTE : This function should not be modified, when the callback is needed,
4983  the HAL_TIM_PeriodElapsedHalfCpltCallback could be implemented in the user file
4984  */
4985 }
4986 
4993 {
4994  /* Prevent unused argument(s) compilation warning */
4995  UNUSED(htim);
4996 
4997  /* NOTE : This function should not be modified, when the callback is needed,
4998  the HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file
4999  */
5000 }
5001 
5008 {
5009  /* Prevent unused argument(s) compilation warning */
5010  UNUSED(htim);
5011 
5012  /* NOTE : This function should not be modified, when the callback is needed,
5013  the HAL_TIM_IC_CaptureCallback could be implemented in the user file
5014  */
5015 }
5016 
5023 {
5024  /* Prevent unused argument(s) compilation warning */
5025  UNUSED(htim);
5026 
5027  /* NOTE : This function should not be modified, when the callback is needed,
5028  the HAL_TIM_IC_CaptureHalfCpltCallback could be implemented in the user file
5029  */
5030 }
5031 
5038 {
5039  /* Prevent unused argument(s) compilation warning */
5040  UNUSED(htim);
5041 
5042  /* NOTE : This function should not be modified, when the callback is needed,
5043  the HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file
5044  */
5045 }
5046 
5053 {
5054  /* Prevent unused argument(s) compilation warning */
5055  UNUSED(htim);
5056 
5057  /* NOTE : This function should not be modified, when the callback is needed,
5058  the HAL_TIM_PWM_PulseFinishedHalfCpltCallback could be implemented in the user file
5059  */
5060 }
5061 
5068 {
5069  /* Prevent unused argument(s) compilation warning */
5070  UNUSED(htim);
5071 
5072  /* NOTE : This function should not be modified, when the callback is needed,
5073  the HAL_TIM_TriggerCallback could be implemented in the user file
5074  */
5075 }
5076 
5083 {
5084  /* Prevent unused argument(s) compilation warning */
5085  UNUSED(htim);
5086 
5087  /* NOTE : This function should not be modified, when the callback is needed,
5088  the HAL_TIM_TriggerHalfCpltCallback could be implemented in the user file
5089  */
5090 }
5091 
5098 {
5099  /* Prevent unused argument(s) compilation warning */
5100  UNUSED(htim);
5101 
5102  /* NOTE : This function should not be modified, when the callback is needed,
5103  the HAL_TIM_ErrorCallback could be implemented in the user file
5104  */
5105 }
5106 
5107 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5108 
5145  pTIM_CallbackTypeDef pCallback)
5146 {
5147  HAL_StatusTypeDef status = HAL_OK;
5148 
5149  if (pCallback == NULL)
5150  {
5151  return HAL_ERROR;
5152  }
5153  /* Process locked */
5154  __HAL_LOCK(htim);
5155 
5156  if (htim->State == HAL_TIM_STATE_READY)
5157  {
5158  switch (CallbackID)
5159  {
5161  htim->Base_MspInitCallback = pCallback;
5162  break;
5163 
5165  htim->Base_MspDeInitCallback = pCallback;
5166  break;
5167 
5169  htim->IC_MspInitCallback = pCallback;
5170  break;
5171 
5173  htim->IC_MspDeInitCallback = pCallback;
5174  break;
5175 
5177  htim->OC_MspInitCallback = pCallback;
5178  break;
5179 
5181  htim->OC_MspDeInitCallback = pCallback;
5182  break;
5183 
5185  htim->PWM_MspInitCallback = pCallback;
5186  break;
5187 
5189  htim->PWM_MspDeInitCallback = pCallback;
5190  break;
5191 
5193  htim->OnePulse_MspInitCallback = pCallback;
5194  break;
5195 
5197  htim->OnePulse_MspDeInitCallback = pCallback;
5198  break;
5199 
5201  htim->Encoder_MspInitCallback = pCallback;
5202  break;
5203 
5205  htim->Encoder_MspDeInitCallback = pCallback;
5206  break;
5207 
5209  htim->HallSensor_MspInitCallback = pCallback;
5210  break;
5211 
5213  htim->HallSensor_MspDeInitCallback = pCallback;
5214  break;
5215 
5217  htim->PeriodElapsedCallback = pCallback;
5218  break;
5219 
5221  htim->PeriodElapsedHalfCpltCallback = pCallback;
5222  break;
5223 
5224  case HAL_TIM_TRIGGER_CB_ID :
5225  htim->TriggerCallback = pCallback;
5226  break;
5227 
5229  htim->TriggerHalfCpltCallback = pCallback;
5230  break;
5231 
5233  htim->IC_CaptureCallback = pCallback;
5234  break;
5235 
5237  htim->IC_CaptureHalfCpltCallback = pCallback;
5238  break;
5239 
5241  htim->OC_DelayElapsedCallback = pCallback;
5242  break;
5243 
5245  htim->PWM_PulseFinishedCallback = pCallback;
5246  break;
5247 
5249  htim->PWM_PulseFinishedHalfCpltCallback = pCallback;
5250  break;
5251 
5252  case HAL_TIM_ERROR_CB_ID :
5253  htim->ErrorCallback = pCallback;
5254  break;
5255 
5257  htim->CommutationCallback = pCallback;
5258  break;
5259 
5261  htim->CommutationHalfCpltCallback = pCallback;
5262  break;
5263 
5264  case HAL_TIM_BREAK_CB_ID :
5265  htim->BreakCallback = pCallback;
5266  break;
5267 
5268  case HAL_TIM_BREAK2_CB_ID :
5269  htim->Break2Callback = pCallback;
5270  break;
5271 
5272  default :
5273  /* Return error status */
5274  status = HAL_ERROR;
5275  break;
5276  }
5277  }
5278  else if (htim->State == HAL_TIM_STATE_RESET)
5279  {
5280  switch (CallbackID)
5281  {
5283  htim->Base_MspInitCallback = pCallback;
5284  break;
5285 
5287  htim->Base_MspDeInitCallback = pCallback;
5288  break;
5289 
5291  htim->IC_MspInitCallback = pCallback;
5292  break;
5293 
5295  htim->IC_MspDeInitCallback = pCallback;
5296  break;
5297 
5299  htim->OC_MspInitCallback = pCallback;
5300  break;
5301 
5303  htim->OC_MspDeInitCallback = pCallback;
5304  break;
5305 
5307  htim->PWM_MspInitCallback = pCallback;
5308  break;
5309 
5311  htim->PWM_MspDeInitCallback = pCallback;
5312  break;
5313 
5315  htim->OnePulse_MspInitCallback = pCallback;
5316  break;
5317 
5319  htim->OnePulse_MspDeInitCallback = pCallback;
5320  break;
5321 
5323  htim->Encoder_MspInitCallback = pCallback;
5324  break;
5325 
5327  htim->Encoder_MspDeInitCallback = pCallback;
5328  break;
5329 
5331  htim->HallSensor_MspInitCallback = pCallback;
5332  break;
5333 
5335  htim->HallSensor_MspDeInitCallback = pCallback;
5336  break;
5337 
5338  default :
5339  /* Return error status */
5340  status = HAL_ERROR;
5341  break;
5342  }
5343  }
5344  else
5345  {
5346  /* Return error status */
5347  status = HAL_ERROR;
5348  }
5349 
5350  /* Release Lock */
5351  __HAL_UNLOCK(htim);
5352 
5353  return status;
5354 }
5355 
5393 {
5394  HAL_StatusTypeDef status = HAL_OK;
5395 
5396  /* Process locked */
5397  __HAL_LOCK(htim);
5398 
5399  if (htim->State == HAL_TIM_STATE_READY)
5400  {
5401  switch (CallbackID)
5402  {
5404  htim->Base_MspInitCallback = HAL_TIM_Base_MspInit; /* Legacy weak Base MspInit Callback */
5405  break;
5406 
5408  htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit; /* Legacy weak Base Msp DeInit Callback */
5409  break;
5410 
5412  htim->IC_MspInitCallback = HAL_TIM_IC_MspInit; /* Legacy weak IC Msp Init Callback */
5413  break;
5414 
5416  htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit; /* Legacy weak IC Msp DeInit Callback */
5417  break;
5418 
5420  htim->OC_MspInitCallback = HAL_TIM_OC_MspInit; /* Legacy weak OC Msp Init Callback */
5421  break;
5422 
5424  htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit; /* Legacy weak OC Msp DeInit Callback */
5425  break;
5426 
5428  htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit; /* Legacy weak PWM Msp Init Callback */
5429  break;
5430 
5432  htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit; /* Legacy weak PWM Msp DeInit Callback */
5433  break;
5434 
5436  htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit; /* Legacy weak One Pulse Msp Init Callback */
5437  break;
5438 
5440  htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit; /* Legacy weak One Pulse Msp DeInit Callback */
5441  break;
5442 
5444  htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit; /* Legacy weak Encoder Msp Init Callback */
5445  break;
5446 
5448  htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit; /* Legacy weak Encoder Msp DeInit Callback */
5449  break;
5450 
5452  htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit; /* Legacy weak Hall Sensor Msp Init Callback */
5453  break;
5454 
5456  htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit; /* Legacy weak Hall Sensor Msp DeInit Callback */
5457  break;
5458 
5460  htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback; /* Legacy weak Period Elapsed Callback */
5461  break;
5462 
5464  htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback; /* Legacy weak Period Elapsed half complete Callback */
5465  break;
5466 
5467  case HAL_TIM_TRIGGER_CB_ID :
5468  htim->TriggerCallback = HAL_TIM_TriggerCallback; /* Legacy weak Trigger Callback */
5469  break;
5470 
5472  htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback; /* Legacy weak Trigger half complete Callback */
5473  break;
5474 
5476  htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback; /* Legacy weak IC Capture Callback */
5477  break;
5478 
5480  htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback; /* Legacy weak IC Capture half complete Callback */
5481  break;
5482 
5484  htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback; /* Legacy weak OC Delay Elapsed Callback */
5485  break;
5486 
5488  htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback; /* Legacy weak PWM Pulse Finished Callback */
5489  break;
5490 
5492  htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback; /* Legacy weak PWM Pulse Finished half complete Callback */
5493  break;
5494 
5495  case HAL_TIM_ERROR_CB_ID :
5496  htim->ErrorCallback = HAL_TIM_ErrorCallback; /* Legacy weak Error Callback */
5497  break;
5498 
5500  htim->CommutationCallback = HAL_TIMEx_CommutCallback; /* Legacy weak Commutation Callback */
5501  break;
5502 
5504  htim->CommutationHalfCpltCallback = HAL_TIMEx_CommutHalfCpltCallback; /* Legacy weak Commutation half complete Callback */
5505  break;
5506 
5507  case HAL_TIM_BREAK_CB_ID :
5508  htim->BreakCallback = HAL_TIMEx_BreakCallback; /* Legacy weak Break Callback */
5509  break;
5510 
5511  case HAL_TIM_BREAK2_CB_ID :
5512  htim->Break2Callback = HAL_TIMEx_Break2Callback; /* Legacy weak Break2 Callback */
5513  break;
5514 
5515  default :
5516  /* Return error status */
5517  status = HAL_ERROR;
5518  break;
5519  }
5520  }
5521  else if (htim->State == HAL_TIM_STATE_RESET)
5522  {
5523  switch (CallbackID)
5524  {
5526  htim->Base_MspInitCallback = HAL_TIM_Base_MspInit; /* Legacy weak Base MspInit Callback */
5527  break;
5528 
5530  htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit; /* Legacy weak Base Msp DeInit Callback */
5531  break;
5532 
5534  htim->IC_MspInitCallback = HAL_TIM_IC_MspInit; /* Legacy weak IC Msp Init Callback */
5535  break;
5536 
5538  htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit; /* Legacy weak IC Msp DeInit Callback */
5539  break;
5540 
5542  htim->OC_MspInitCallback = HAL_TIM_OC_MspInit; /* Legacy weak OC Msp Init Callback */
5543  break;
5544 
5546  htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit; /* Legacy weak OC Msp DeInit Callback */
5547  break;
5548 
5550  htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit; /* Legacy weak PWM Msp Init Callback */
5551  break;
5552 
5554  htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit; /* Legacy weak PWM Msp DeInit Callback */
5555  break;
5556 
5558  htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit; /* Legacy weak One Pulse Msp Init Callback */
5559  break;
5560 
5562  htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit; /* Legacy weak One Pulse Msp DeInit Callback */
5563  break;
5564 
5566  htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit; /* Legacy weak Encoder Msp Init Callback */
5567  break;
5568 
5570  htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit; /* Legacy weak Encoder Msp DeInit Callback */
5571  break;
5572 
5574  htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit; /* Legacy weak Hall Sensor Msp Init Callback */
5575  break;
5576 
5578  htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit; /* Legacy weak Hall Sensor Msp DeInit Callback */
5579  break;
5580 
5581  default :
5582  /* Return error status */
5583  status = HAL_ERROR;
5584  break;
5585  }
5586  }
5587  else
5588  {
5589  /* Return error status */
5590  status = HAL_ERROR;
5591  }
5592 
5593  /* Release Lock */
5594  __HAL_UNLOCK(htim);
5595 
5596  return status;
5597 }
5598 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5599 
5625 {
5626  return htim->State;
5627 }
5628 
5635 {
5636  return htim->State;
5637 }
5638 
5645 {
5646  return htim->State;
5647 }
5648 
5655 {
5656  return htim->State;
5657 }
5658 
5665 {
5666  return htim->State;
5667 }
5668 
5675 {
5676  return htim->State;
5677 }
5678 
5697 {
5698  TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5699 
5700  htim->State = HAL_TIM_STATE_READY;
5701 
5702 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5703  htim->ErrorCallback(htim);
5704 #else
5705  HAL_TIM_ErrorCallback(htim);
5706 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5707 }
5708 
5715 {
5716  TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5717 
5718  htim->State = HAL_TIM_STATE_READY;
5719 
5720  if (hdma == htim->hdma[TIM_DMA_ID_CC1])
5721  {
5722  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
5723  }
5724  else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
5725  {
5726  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
5727  }
5728  else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
5729  {
5730  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
5731  }
5732  else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
5733  {
5734  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
5735  }
5736  else
5737  {
5738  /* nothing to do */
5739  }
5740 
5741 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5742  htim->PWM_PulseFinishedCallback(htim);
5743 #else
5745 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5746 
5747  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
5748 }
5749 
5756 {
5757  TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5758 
5759  htim->State = HAL_TIM_STATE_READY;
5760 
5761  if (hdma == htim->hdma[TIM_DMA_ID_CC1])
5762  {
5763  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
5764  }
5765  else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
5766  {
5767  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
5768  }
5769  else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
5770  {
5771  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
5772  }
5773  else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
5774  {
5775  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
5776  }
5777  else
5778  {
5779  /* nothing to do */
5780  }
5781 
5782 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5783  htim->PWM_PulseFinishedHalfCpltCallback(htim);
5784 #else
5786 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5787 
5788  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
5789 }
5790 
5797 {
5798  TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5799 
5800  htim->State = HAL_TIM_STATE_READY;
5801 
5802  if (hdma == htim->hdma[TIM_DMA_ID_CC1])
5803  {
5804  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
5805  }
5806  else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
5807  {
5808  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
5809  }
5810  else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
5811  {
5812  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
5813  }
5814  else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
5815  {
5816  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
5817  }
5818  else
5819  {
5820  /* nothing to do */
5821  }
5822 
5823 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5824  htim->IC_CaptureCallback(htim);
5825 #else
5827 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5828 
5829  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
5830 }
5831 
5838 {
5839  TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5840 
5841  htim->State = HAL_TIM_STATE_READY;
5842 
5843  if (hdma == htim->hdma[TIM_DMA_ID_CC1])
5844  {
5845  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
5846  }
5847  else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
5848  {
5849  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
5850  }
5851  else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
5852  {
5853  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
5854  }
5855  else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
5856  {
5857  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
5858  }
5859  else
5860  {
5861  /* nothing to do */
5862  }
5863 
5864 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5865  htim->IC_CaptureHalfCpltCallback(htim);
5866 #else
5868 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5869 
5870  htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
5871 }
5872 
5879 {
5880  TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5881 
5882  htim->State = HAL_TIM_STATE_READY;
5883 
5884 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5885  htim->PeriodElapsedCallback(htim);
5886 #else
5888 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5889 }
5890 
5897 {
5898  TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5899 
5900  htim->State = HAL_TIM_STATE_READY;
5901 
5902 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5903  htim->PeriodElapsedHalfCpltCallback(htim);
5904 #else
5906 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5907 }
5908 
5915 {
5916  TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5917 
5918  htim->State = HAL_TIM_STATE_READY;
5919 
5920 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5921  htim->TriggerCallback(htim);
5922 #else
5924 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5925 }
5926 
5933 {
5934  TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5935 
5936  htim->State = HAL_TIM_STATE_READY;
5937 
5938 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5939  htim->TriggerHalfCpltCallback(htim);
5940 #else
5942 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5943 }
5944 
5951 void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure)
5952 {
5953  uint32_t tmpcr1;
5954  tmpcr1 = TIMx->CR1;
5955 
5956  /* Set TIM Time Base Unit parameters ---------------------------------------*/
5957  if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx))
5958  {
5959  /* Select the Counter Mode */
5960  tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);
5961  tmpcr1 |= Structure->CounterMode;
5962  }
5963 
5964  if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx))
5965  {
5966  /* Set the clock division */
5967  tmpcr1 &= ~TIM_CR1_CKD;
5968  tmpcr1 |= (uint32_t)Structure->ClockDivision;
5969  }
5970 
5971  /* Set the auto-reload preload */
5972  MODIFY_REG(tmpcr1, TIM_CR1_ARPE, Structure->AutoReloadPreload);
5973 
5974  TIMx->CR1 = tmpcr1;
5975 
5976  /* Set the Autoreload value */
5977  TIMx->ARR = (uint32_t)Structure->Period ;
5978 
5979  /* Set the Prescaler value */
5980  TIMx->PSC = Structure->Prescaler;
5981 
5982  if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx))
5983  {
5984  /* Set the Repetition Counter value */
5985  TIMx->RCR = Structure->RepetitionCounter;
5986  }
5987 
5988  /* Generate an update event to reload the Prescaler
5989  and the repetition counter (only for advanced timer) value immediately */
5990  TIMx->EGR = TIM_EGR_UG;
5991 }
5992 
5999 static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
6000 {
6001  uint32_t tmpccmrx;
6002  uint32_t tmpccer;
6003  uint32_t tmpcr2;
6004 
6005  /* Disable the Channel 1: Reset the CC1E Bit */
6006  TIMx->CCER &= ~TIM_CCER_CC1E;
6007 
6008  /* Get the TIMx CCER register value */
6009  tmpccer = TIMx->CCER;
6010  /* Get the TIMx CR2 register value */
6011  tmpcr2 = TIMx->CR2;
6012 
6013  /* Get the TIMx CCMR1 register value */
6014  tmpccmrx = TIMx->CCMR1;
6015 
6016  /* Reset the Output Compare Mode Bits */
6017  tmpccmrx &= ~TIM_CCMR1_OC1M;
6018  tmpccmrx &= ~TIM_CCMR1_CC1S;
6019  /* Select the Output Compare Mode */
6020  tmpccmrx |= OC_Config->OCMode;
6021 
6022  /* Reset the Output Polarity level */
6023  tmpccer &= ~TIM_CCER_CC1P;
6024  /* Set the Output Compare Polarity */
6025  tmpccer |= OC_Config->OCPolarity;
6026 
6027  if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_1))
6028  {
6029  /* Check parameters */
6030  assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
6031 
6032  /* Reset the Output N Polarity level */
6033  tmpccer &= ~TIM_CCER_CC1NP;
6034  /* Set the Output N Polarity */
6035  tmpccer |= OC_Config->OCNPolarity;
6036  /* Reset the Output N State */
6037  tmpccer &= ~TIM_CCER_CC1NE;
6038  }
6039 
6040  if (IS_TIM_BREAK_INSTANCE(TIMx))
6041  {
6042  /* Check parameters */
6043  assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
6044  assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
6045 
6046  /* Reset the Output Compare and Output Compare N IDLE State */
6047  tmpcr2 &= ~TIM_CR2_OIS1;
6048  tmpcr2 &= ~TIM_CR2_OIS1N;
6049  /* Set the Output Idle state */
6050  tmpcr2 |= OC_Config->OCIdleState;
6051  /* Set the Output N Idle state */
6052  tmpcr2 |= OC_Config->OCNIdleState;
6053  }
6054 
6055  /* Write to TIMx CR2 */
6056  TIMx->CR2 = tmpcr2;
6057 
6058  /* Write to TIMx CCMR1 */
6059  TIMx->CCMR1 = tmpccmrx;
6060 
6061  /* Set the Capture Compare Register value */
6062  TIMx->CCR1 = OC_Config->Pulse;
6063 
6064  /* Write to TIMx CCER */
6065  TIMx->CCER = tmpccer;
6066 }
6067 
6074 void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
6075 {
6076  uint32_t tmpccmrx;
6077  uint32_t tmpccer;
6078  uint32_t tmpcr2;
6079 
6080  /* Disable the Channel 2: Reset the CC2E Bit */
6081  TIMx->CCER &= ~TIM_CCER_CC2E;
6082 
6083  /* Get the TIMx CCER register value */
6084  tmpccer = TIMx->CCER;
6085  /* Get the TIMx CR2 register value */
6086  tmpcr2 = TIMx->CR2;
6087 
6088  /* Get the TIMx CCMR1 register value */
6089  tmpccmrx = TIMx->CCMR1;
6090 
6091  /* Reset the Output Compare mode and Capture/Compare selection Bits */
6092  tmpccmrx &= ~TIM_CCMR1_OC2M;
6093  tmpccmrx &= ~TIM_CCMR1_CC2S;
6094 
6095  /* Select the Output Compare Mode */
6096  tmpccmrx |= (OC_Config->OCMode << 8U);
6097 
6098  /* Reset the Output Polarity level */
6099  tmpccer &= ~TIM_CCER_CC2P;
6100  /* Set the Output Compare Polarity */
6101  tmpccer |= (OC_Config->OCPolarity << 4U);
6102 
6103  if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_2))
6104  {
6105  assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
6106 
6107  /* Reset the Output N Polarity level */
6108  tmpccer &= ~TIM_CCER_CC2NP;
6109  /* Set the Output N Polarity */
6110  tmpccer |= (OC_Config->OCNPolarity << 4U);
6111  /* Reset the Output N State */
6112  tmpccer &= ~TIM_CCER_CC2NE;
6113 
6114  }
6115 
6116  if (IS_TIM_BREAK_INSTANCE(TIMx))
6117  {
6118  /* Check parameters */
6119  assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
6120  assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
6121 
6122  /* Reset the Output Compare and Output Compare N IDLE State */
6123  tmpcr2 &= ~TIM_CR2_OIS2;
6124  tmpcr2 &= ~TIM_CR2_OIS2N;
6125  /* Set the Output Idle state */
6126  tmpcr2 |= (OC_Config->OCIdleState << 2U);
6127  /* Set the Output N Idle state */
6128  tmpcr2 |= (OC_Config->OCNIdleState << 2U);
6129  }
6130 
6131  /* Write to TIMx CR2 */
6132  TIMx->CR2 = tmpcr2;
6133 
6134  /* Write to TIMx CCMR1 */
6135  TIMx->CCMR1 = tmpccmrx;
6136 
6137  /* Set the Capture Compare Register value */
6138  TIMx->CCR2 = OC_Config->Pulse;
6139 
6140  /* Write to TIMx CCER */
6141  TIMx->CCER = tmpccer;
6142 }
6143 
6150 static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
6151 {
6152  uint32_t tmpccmrx;
6153  uint32_t tmpccer;
6154  uint32_t tmpcr2;
6155 
6156  /* Disable the Channel 3: Reset the CC2E Bit */
6157  TIMx->CCER &= ~TIM_CCER_CC3E;
6158 
6159  /* Get the TIMx CCER register value */
6160  tmpccer = TIMx->CCER;
6161  /* Get the TIMx CR2 register value */
6162  tmpcr2 = TIMx->CR2;
6163 
6164  /* Get the TIMx CCMR2 register value */
6165  tmpccmrx = TIMx->CCMR2;
6166 
6167  /* Reset the Output Compare mode and Capture/Compare selection Bits */
6168  tmpccmrx &= ~TIM_CCMR2_OC3M;
6169  tmpccmrx &= ~TIM_CCMR2_CC3S;
6170  /* Select the Output Compare Mode */
6171  tmpccmrx |= OC_Config->OCMode;
6172 
6173  /* Reset the Output Polarity level */
6174  tmpccer &= ~TIM_CCER_CC3P;
6175  /* Set the Output Compare Polarity */
6176  tmpccer |= (OC_Config->OCPolarity << 8U);
6177 
6178  if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_3))
6179  {
6180  assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
6181 
6182  /* Reset the Output N Polarity level */
6183  tmpccer &= ~TIM_CCER_CC3NP;
6184  /* Set the Output N Polarity */
6185  tmpccer |= (OC_Config->OCNPolarity << 8U);
6186  /* Reset the Output N State */
6187  tmpccer &= ~TIM_CCER_CC3NE;
6188  }
6189 
6190  if (IS_TIM_BREAK_INSTANCE(TIMx))
6191  {
6192  /* Check parameters */
6193  assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
6194  assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
6195 
6196  /* Reset the Output Compare and Output Compare N IDLE State */
6197  tmpcr2 &= ~TIM_CR2_OIS3;
6198  tmpcr2 &= ~TIM_CR2_OIS3N;
6199  /* Set the Output Idle state */
6200  tmpcr2 |= (OC_Config->OCIdleState << 4U);
6201  /* Set the Output N Idle state */
6202  tmpcr2 |= (OC_Config->OCNIdleState << 4U);
6203  }
6204 
6205  /* Write to TIMx CR2 */
6206  TIMx->CR2 = tmpcr2;
6207 
6208  /* Write to TIMx CCMR2 */
6209  TIMx->CCMR2 = tmpccmrx;
6210 
6211  /* Set the Capture Compare Register value */
6212  TIMx->CCR3 = OC_Config->Pulse;
6213 
6214  /* Write to TIMx CCER */
6215  TIMx->CCER = tmpccer;
6216 }
6217 
6224 static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
6225 {
6226  uint32_t tmpccmrx;
6227  uint32_t tmpccer;
6228  uint32_t tmpcr2;
6229 
6230  /* Disable the Channel 4: Reset the CC4E Bit */
6231  TIMx->CCER &= ~TIM_CCER_CC4E;
6232 
6233  /* Get the TIMx CCER register value */
6234  tmpccer = TIMx->CCER;
6235  /* Get the TIMx CR2 register value */
6236  tmpcr2 = TIMx->CR2;
6237 
6238  /* Get the TIMx CCMR2 register value */
6239  tmpccmrx = TIMx->CCMR2;
6240 
6241  /* Reset the Output Compare mode and Capture/Compare selection Bits */
6242  tmpccmrx &= ~TIM_CCMR2_OC4M;
6243  tmpccmrx &= ~TIM_CCMR2_CC4S;
6244 
6245  /* Select the Output Compare Mode */
6246  tmpccmrx |= (OC_Config->OCMode << 8U);
6247 
6248  /* Reset the Output Polarity level */
6249  tmpccer &= ~TIM_CCER_CC4P;
6250  /* Set the Output Compare Polarity */
6251  tmpccer |= (OC_Config->OCPolarity << 12U);
6252 
6253  if (IS_TIM_BREAK_INSTANCE(TIMx))
6254  {
6255  /* Check parameters */
6256  assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
6257 
6258  /* Reset the Output Compare IDLE State */
6259  tmpcr2 &= ~TIM_CR2_OIS4;
6260 
6261  /* Set the Output Idle state */
6262  tmpcr2 |= (OC_Config->OCIdleState << 6U);
6263  }
6264 
6265  /* Write to TIMx CR2 */
6266  TIMx->CR2 = tmpcr2;
6267 
6268  /* Write to TIMx CCMR2 */
6269  TIMx->CCMR2 = tmpccmrx;
6270 
6271  /* Set the Capture Compare Register value */
6272  TIMx->CCR4 = OC_Config->Pulse;
6273 
6274  /* Write to TIMx CCER */
6275  TIMx->CCER = tmpccer;
6276 }
6277 
6284 static void TIM_OC5_SetConfig(TIM_TypeDef *TIMx,
6285  TIM_OC_InitTypeDef *OC_Config)
6286 {
6287  uint32_t tmpccmrx;
6288  uint32_t tmpccer;
6289  uint32_t tmpcr2;
6290 
6291  /* Disable the output: Reset the CCxE Bit */
6292  TIMx->CCER &= ~TIM_CCER_CC5E;
6293 
6294  /* Get the TIMx CCER register value */
6295  tmpccer = TIMx->CCER;
6296  /* Get the TIMx CR2 register value */
6297  tmpcr2 = TIMx->CR2;
6298  /* Get the TIMx CCMR1 register value */
6299  tmpccmrx = TIMx->CCMR3;
6300 
6301  /* Reset the Output Compare Mode Bits */
6302  tmpccmrx &= ~(TIM_CCMR3_OC5M);
6303  /* Select the Output Compare Mode */
6304  tmpccmrx |= OC_Config->OCMode;
6305 
6306  /* Reset the Output Polarity level */
6307  tmpccer &= ~TIM_CCER_CC5P;
6308  /* Set the Output Compare Polarity */
6309  tmpccer |= (OC_Config->OCPolarity << 16U);
6310 
6311  if (IS_TIM_BREAK_INSTANCE(TIMx))
6312  {
6313  /* Reset the Output Compare IDLE State */
6314  tmpcr2 &= ~TIM_CR2_OIS5;
6315  /* Set the Output Idle state */
6316  tmpcr2 |= (OC_Config->OCIdleState << 8U);
6317  }
6318  /* Write to TIMx CR2 */
6319  TIMx->CR2 = tmpcr2;
6320 
6321  /* Write to TIMx CCMR3 */
6322  TIMx->CCMR3 = tmpccmrx;
6323 
6324  /* Set the Capture Compare Register value */
6325  TIMx->CCR5 = OC_Config->Pulse;
6326 
6327  /* Write to TIMx CCER */
6328  TIMx->CCER = tmpccer;
6329 }
6330 
6337 static void TIM_OC6_SetConfig(TIM_TypeDef *TIMx,
6338  TIM_OC_InitTypeDef *OC_Config)
6339 {
6340  uint32_t tmpccmrx;
6341  uint32_t tmpccer;
6342  uint32_t tmpcr2;
6343 
6344  /* Disable the output: Reset the CCxE Bit */
6345  TIMx->CCER &= ~TIM_CCER_CC6E;
6346 
6347  /* Get the TIMx CCER register value */
6348  tmpccer = TIMx->CCER;
6349  /* Get the TIMx CR2 register value */
6350  tmpcr2 = TIMx->CR2;
6351  /* Get the TIMx CCMR1 register value */
6352  tmpccmrx = TIMx->CCMR3;
6353 
6354  /* Reset the Output Compare Mode Bits */
6355  tmpccmrx &= ~(TIM_CCMR3_OC6M);
6356  /* Select the Output Compare Mode */
6357  tmpccmrx |= (OC_Config->OCMode << 8U);
6358 
6359  /* Reset the Output Polarity level */
6360  tmpccer &= (uint32_t)~TIM_CCER_CC6P;
6361  /* Set the Output Compare Polarity */
6362  tmpccer |= (OC_Config->OCPolarity << 20U);
6363 
6364  if (IS_TIM_BREAK_INSTANCE(TIMx))
6365  {
6366  /* Reset the Output Compare IDLE State */
6367  tmpcr2 &= ~TIM_CR2_OIS6;
6368  /* Set the Output Idle state */
6369  tmpcr2 |= (OC_Config->OCIdleState << 10U);
6370  }
6371 
6372  /* Write to TIMx CR2 */
6373  TIMx->CR2 = tmpcr2;
6374 
6375  /* Write to TIMx CCMR3 */
6376  TIMx->CCMR3 = tmpccmrx;
6377 
6378  /* Set the Capture Compare Register value */
6379  TIMx->CCR6 = OC_Config->Pulse;
6380 
6381  /* Write to TIMx CCER */
6382  TIMx->CCER = tmpccer;
6383 }
6384 
6391 static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
6392  TIM_SlaveConfigTypeDef *sSlaveConfig)
6393 {
6394  uint32_t tmpsmcr;
6395  uint32_t tmpccmr1;
6396  uint32_t tmpccer;
6397 
6398  /* Get the TIMx SMCR register value */
6399  tmpsmcr = htim->Instance->SMCR;
6400 
6401  /* Reset the Trigger Selection Bits */
6402  tmpsmcr &= ~TIM_SMCR_TS;
6403  /* Set the Input Trigger source */
6404  tmpsmcr |= sSlaveConfig->InputTrigger;
6405 
6406  /* Reset the slave mode Bits */
6407  tmpsmcr &= ~TIM_SMCR_SMS;
6408  /* Set the slave mode */
6409  tmpsmcr |= sSlaveConfig->SlaveMode;
6410 
6411  /* Write to TIMx SMCR */
6412  htim->Instance->SMCR = tmpsmcr;
6413 
6414  /* Configure the trigger prescaler, filter, and polarity */
6415  switch (sSlaveConfig->InputTrigger)
6416  {
6417  case TIM_TS_ETRF:
6418  {
6419  /* Check the parameters */
6420  assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance));
6421  assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler));
6422  assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
6423  assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
6424  /* Configure the ETR Trigger source */
6425  TIM_ETR_SetConfig(htim->Instance,
6426  sSlaveConfig->TriggerPrescaler,
6427  sSlaveConfig->TriggerPolarity,
6428  sSlaveConfig->TriggerFilter);
6429  break;
6430  }
6431 
6432  case TIM_TS_TI1F_ED:
6433  {
6434  /* Check the parameters */
6435  assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
6436  assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
6437 
6438  if(sSlaveConfig->SlaveMode == TIM_SLAVEMODE_GATED)
6439  {
6440  return HAL_ERROR;
6441  }
6442 
6443  /* Disable the Channel 1: Reset the CC1E Bit */
6444  tmpccer = htim->Instance->CCER;
6445  htim->Instance->CCER &= ~TIM_CCER_CC1E;
6446  tmpccmr1 = htim->Instance->CCMR1;
6447 
6448  /* Set the filter */
6449  tmpccmr1 &= ~TIM_CCMR1_IC1F;
6450  tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4U);
6451 
6452  /* Write to TIMx CCMR1 and CCER registers */
6453  htim->Instance->CCMR1 = tmpccmr1;
6454  htim->Instance->CCER = tmpccer;
6455  break;
6456  }
6457 
6458  case TIM_TS_TI1FP1:
6459  {
6460  /* Check the parameters */
6461  assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
6462  assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
6463  assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
6464 
6465  /* Configure TI1 Filter and Polarity */
6466  TIM_TI1_ConfigInputStage(htim->Instance,
6467  sSlaveConfig->TriggerPolarity,
6468  sSlaveConfig->TriggerFilter);
6469  break;
6470  }
6471 
6472  case TIM_TS_TI2FP2:
6473  {
6474  /* Check the parameters */
6475  assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
6476  assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
6477  assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
6478 
6479  /* Configure TI2 Filter and Polarity */
6480  TIM_TI2_ConfigInputStage(htim->Instance,
6481  sSlaveConfig->TriggerPolarity,
6482  sSlaveConfig->TriggerFilter);
6483  break;
6484  }
6485 
6486  case TIM_TS_ITR0:
6487  case TIM_TS_ITR1:
6488  case TIM_TS_ITR2:
6489  case TIM_TS_ITR3:
6490  {
6491  /* Check the parameter */
6492  assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
6493  break;
6494  }
6495 
6496  default:
6497  break;
6498  }
6499  return HAL_OK;
6500 }
6501 
6522 void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
6523  uint32_t TIM_ICFilter)
6524 {
6525  uint32_t tmpccmr1;
6526  uint32_t tmpccer;
6527 
6528  /* Disable the Channel 1: Reset the CC1E Bit */
6529  TIMx->CCER &= ~TIM_CCER_CC1E;
6530  tmpccmr1 = TIMx->CCMR1;
6531  tmpccer = TIMx->CCER;
6532 
6533  /* Select the Input */
6534  if (IS_TIM_CC2_INSTANCE(TIMx) != RESET)
6535  {
6536  tmpccmr1 &= ~TIM_CCMR1_CC1S;
6537  tmpccmr1 |= TIM_ICSelection;
6538  }
6539  else
6540  {
6541  tmpccmr1 |= TIM_CCMR1_CC1S_0;
6542  }
6543 
6544  /* Set the filter */
6545  tmpccmr1 &= ~TIM_CCMR1_IC1F;
6546  tmpccmr1 |= ((TIM_ICFilter << 4U) & TIM_CCMR1_IC1F);
6547 
6548  /* Select the Polarity and set the CC1E Bit */
6549  tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
6550  tmpccer |= (TIM_ICPolarity & (TIM_CCER_CC1P | TIM_CCER_CC1NP));
6551 
6552  /* Write to TIMx CCMR1 and CCER registers */
6553  TIMx->CCMR1 = tmpccmr1;
6554  TIMx->CCER = tmpccer;
6555 }
6556 
6569 static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
6570 {
6571  uint32_t tmpccmr1;
6572  uint32_t tmpccer;
6573 
6574  /* Disable the Channel 1: Reset the CC1E Bit */
6575  tmpccer = TIMx->CCER;
6576  TIMx->CCER &= ~TIM_CCER_CC1E;
6577  tmpccmr1 = TIMx->CCMR1;
6578 
6579  /* Set the filter */
6580  tmpccmr1 &= ~TIM_CCMR1_IC1F;
6581  tmpccmr1 |= (TIM_ICFilter << 4U);
6582 
6583  /* Select the Polarity and set the CC1E Bit */
6584  tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
6585  tmpccer |= TIM_ICPolarity;
6586 
6587  /* Write to TIMx CCMR1 and CCER registers */
6588  TIMx->CCMR1 = tmpccmr1;
6589  TIMx->CCER = tmpccer;
6590 }
6591 
6612 static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
6613  uint32_t TIM_ICFilter)
6614 {
6615  uint32_t tmpccmr1;
6616  uint32_t tmpccer;
6617 
6618  /* Disable the Channel 2: Reset the CC2E Bit */
6619  TIMx->CCER &= ~TIM_CCER_CC2E;
6620  tmpccmr1 = TIMx->CCMR1;
6621  tmpccer = TIMx->CCER;
6622 
6623  /* Select the Input */
6624  tmpccmr1 &= ~TIM_CCMR1_CC2S;
6625  tmpccmr1 |= (TIM_ICSelection << 8U);
6626 
6627  /* Set the filter */
6628  tmpccmr1 &= ~TIM_CCMR1_IC2F;
6629  tmpccmr1 |= ((TIM_ICFilter << 12U) & TIM_CCMR1_IC2F);
6630 
6631  /* Select the Polarity and set the CC2E Bit */
6632  tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
6633  tmpccer |= ((TIM_ICPolarity << 4U) & (TIM_CCER_CC2P | TIM_CCER_CC2NP));
6634 
6635  /* Write to TIMx CCMR1 and CCER registers */
6636  TIMx->CCMR1 = tmpccmr1 ;
6637  TIMx->CCER = tmpccer;
6638 }
6639 
6652 static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
6653 {
6654  uint32_t tmpccmr1;
6655  uint32_t tmpccer;
6656 
6657  /* Disable the Channel 2: Reset the CC2E Bit */
6658  TIMx->CCER &= ~TIM_CCER_CC2E;
6659  tmpccmr1 = TIMx->CCMR1;
6660  tmpccer = TIMx->CCER;
6661 
6662  /* Set the filter */
6663  tmpccmr1 &= ~TIM_CCMR1_IC2F;
6664  tmpccmr1 |= (TIM_ICFilter << 12U);
6665 
6666  /* Select the Polarity and set the CC2E Bit */
6667  tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
6668  tmpccer |= (TIM_ICPolarity << 4U);
6669 
6670  /* Write to TIMx CCMR1 and CCER registers */
6671  TIMx->CCMR1 = tmpccmr1 ;
6672  TIMx->CCER = tmpccer;
6673 }
6674 
6695 static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
6696  uint32_t TIM_ICFilter)
6697 {
6698  uint32_t tmpccmr2;
6699  uint32_t tmpccer;
6700 
6701  /* Disable the Channel 3: Reset the CC3E Bit */
6702  TIMx->CCER &= ~TIM_CCER_CC3E;
6703  tmpccmr2 = TIMx->CCMR2;
6704  tmpccer = TIMx->CCER;
6705 
6706  /* Select the Input */
6707  tmpccmr2 &= ~TIM_CCMR2_CC3S;
6708  tmpccmr2 |= TIM_ICSelection;
6709 
6710  /* Set the filter */
6711  tmpccmr2 &= ~TIM_CCMR2_IC3F;
6712  tmpccmr2 |= ((TIM_ICFilter << 4U) & TIM_CCMR2_IC3F);
6713 
6714  /* Select the Polarity and set the CC3E Bit */
6715  tmpccer &= ~(TIM_CCER_CC3P | TIM_CCER_CC3NP);
6716  tmpccer |= ((TIM_ICPolarity << 8U) & (TIM_CCER_CC3P | TIM_CCER_CC3NP));
6717 
6718  /* Write to TIMx CCMR2 and CCER registers */
6719  TIMx->CCMR2 = tmpccmr2;
6720  TIMx->CCER = tmpccer;
6721 }
6722 
6743 static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
6744  uint32_t TIM_ICFilter)
6745 {
6746  uint32_t tmpccmr2;
6747  uint32_t tmpccer;
6748 
6749  /* Disable the Channel 4: Reset the CC4E Bit */
6750  TIMx->CCER &= ~TIM_CCER_CC4E;
6751  tmpccmr2 = TIMx->CCMR2;
6752  tmpccer = TIMx->CCER;
6753 
6754  /* Select the Input */
6755  tmpccmr2 &= ~TIM_CCMR2_CC4S;
6756  tmpccmr2 |= (TIM_ICSelection << 8U);
6757 
6758  /* Set the filter */
6759  tmpccmr2 &= ~TIM_CCMR2_IC4F;
6760  tmpccmr2 |= ((TIM_ICFilter << 12U) & TIM_CCMR2_IC4F);
6761 
6762  /* Select the Polarity and set the CC4E Bit */
6763  tmpccer &= ~(TIM_CCER_CC4P | TIM_CCER_CC4NP);
6764  tmpccer |= ((TIM_ICPolarity << 12U) & (TIM_CCER_CC4P | TIM_CCER_CC4NP));
6765 
6766  /* Write to TIMx CCMR2 and CCER registers */
6767  TIMx->CCMR2 = tmpccmr2;
6768  TIMx->CCER = tmpccer ;
6769 }
6770 
6786 static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource)
6787 {
6788  uint32_t tmpsmcr;
6789 
6790  /* Get the TIMx SMCR register value */
6791  tmpsmcr = TIMx->SMCR;
6792  /* Reset the TS Bits */
6793  tmpsmcr &= ~TIM_SMCR_TS;
6794  /* Set the Input Trigger source and the slave mode*/
6795  tmpsmcr |= (InputTriggerSource | TIM_SLAVEMODE_EXTERNAL1);
6796  /* Write to TIMx SMCR */
6797  TIMx->SMCR = tmpsmcr;
6798 }
6816 void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler,
6817  uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter)
6818 {
6819  uint32_t tmpsmcr;
6820 
6821  tmpsmcr = TIMx->SMCR;
6822 
6823  /* Reset the ETR Bits */
6824  tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
6825 
6826  /* Set the Prescaler, the Filter value and the Polarity */
6827  tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8U)));
6828 
6829  /* Write to TIMx SMCR */
6830  TIMx->SMCR = tmpsmcr;
6831 }
6832 
6848 void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
6849 {
6850  uint32_t tmp;
6851 
6852  /* Check the parameters */
6853  assert_param(IS_TIM_CC1_INSTANCE(TIMx));
6854  assert_param(IS_TIM_CHANNELS(Channel));
6855 
6856  tmp = TIM_CCER_CC1E << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */
6857 
6858  /* Reset the CCxE Bit */
6859  TIMx->CCER &= ~tmp;
6860 
6861  /* Set or reset the CCxE Bit */
6862  TIMx->CCER |= (uint32_t)(ChannelState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */
6863 }
6864 
6865 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6866 
6873 {
6874  /* Reset the TIM callback to the legacy weak callbacks */
6875  htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback; /* Legacy weak PeriodElapsedCallback */
6876  htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback; /* Legacy weak PeriodElapsedHalfCpltCallback */
6877  htim->TriggerCallback = HAL_TIM_TriggerCallback; /* Legacy weak TriggerCallback */
6878  htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback; /* Legacy weak TriggerHalfCpltCallback */
6879  htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback; /* Legacy weak IC_CaptureCallback */
6880  htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback; /* Legacy weak IC_CaptureHalfCpltCallback */
6881  htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback; /* Legacy weak OC_DelayElapsedCallback */
6882  htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback; /* Legacy weak PWM_PulseFinishedCallback */
6883  htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback; /* Legacy weak PWM_PulseFinishedHalfCpltCallback */
6884  htim->ErrorCallback = HAL_TIM_ErrorCallback; /* Legacy weak ErrorCallback */
6885  htim->CommutationCallback = HAL_TIMEx_CommutCallback; /* Legacy weak CommutationCallback */
6886  htim->CommutationHalfCpltCallback = HAL_TIMEx_CommutHalfCpltCallback; /* Legacy weak CommutationHalfCpltCallback */
6887  htim->BreakCallback = HAL_TIMEx_BreakCallback; /* Legacy weak BreakCallback */
6888  htim->Break2Callback = HAL_TIMEx_Break2Callback; /* Legacy weak Break2Callback */
6889 }
6890 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6891 
6896 #endif /* HAL_TIM_MODULE_ENABLED */
6897 
6904 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
Starts the TIM Base generation in interrupt mode.
HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode)
Initializes the TIM One Pulse Time Base according to the specified parameters in the TIM_HandleTypeDe...
HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef *sConfig)
Initializes the TIM Encoder Interface and initialize the associated handle.
void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
DeInitializes TIM Hall Sensor MSP.
static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
Timer Output Compare 3 configuration.
HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim)
Stops the TIM Base generation in interrupt mode.
void HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef *htim)
PWM Pulse finished half complete callback in non-blocking mode.
void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma)
TIM DMA Commutation half complete callback.
Clock Configuration Handle Structure definition.
HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim)
DeInitializes the TIM peripheral.
TIM Time base Configuration Structure definition.
HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
Starts the TIM Input Capture measurement in DMA mode.
static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
Configure the Polarity and Filter for TI1.
HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
Stops the TIM One Pulse signal generation.
HAL_TIM_CallbackIDTypeDef
HAL TIM Callback ID enumeration definition.
HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim)
Stops the TIM Base generation in DMA mode.
void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
Hall Break detection callback in non-blocking mode.
DMA handle Structure definition.
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
static void TIM_OC5_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
Timer Output Compare 5 configuration.
void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
Initializes the TIM Hall Sensor MSP.
TIM Encoder Configuration Structure definition.
static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma)
TIM DMA Period Elapse half complete callback.
HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength)
Configure the DMA Burst to transfer Data from the TIM peripheral to the memory.
void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter)
Configure the TI1 as Input.
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
PWM Pulse finished callback in non-blocking mode.
TIM Input Capture Configuration Structure definition.
static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter)
Configure the TI3 as Input.
This file contains all the functions prototypes for the HAL module driver.
void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure)
Time Base configuration.
void TIM_ResetCallback(TIM_HandleTypeDef *htim)
Reset interrupt callbacks to the legacy weak callbacks.
HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
Stops the TIM One Pulse signal generation in interrupt mode.
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim)
DeInitializes TIM PWM MSP.
HAL_StatusTypeDef HAL_TIM_UnRegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID)
Unregister a TIM callback TIM callback is redirected to the weak predefined callback.
HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM Output Compare signal generation in DMA mode.
uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel)
Read the captured value from Capture Compare unit.
void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim)
DeInitializes TIM Input Capture MSP.
void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma)
TIM DMA Delay Pulse complete callback.
void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim)
Timer error callback in non-blocking mode.
HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim)
Starts the TIM Base generation.
HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
Starts the TIM One Pulse signal generation.
void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim)
This function handles TIM interrupts requests.
HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM Encoder Interface.
HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
Initializes the TIM Time base Unit according to the specified parameters in the TIM_HandleTypeDef and...
HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
Starts the TIM Encoder Interface in interrupt mode.
void HAL_TIM_IC_CaptureHalfCpltCallback(TIM_HandleTypeDef *htim)
Input Capture half complete callback in non-blocking mode.
HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef *sConfig, uint32_t Channel)
Initializes the TIM Output Compare Channels according to the specified parameters in the TIM_OC_InitT...
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
__HAL_UNLOCK(hrtc)
HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim)
DeInitializes the TIM Encoder interface.
HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
Starts the TIM Input Capture measurement in interrupt mode.
void TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef *hdma)
TIM DMA Delay Pulse half complete callback.
TIM Slave configuration Structure definition.
static void TIM_OC6_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
Timer Output Compare 6 configuration.
HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim)
Initializes the TIM Input Capture Time base according to the specified parameters in the TIM_HandleTy...
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
Initializes the TIM PWM MSP.
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim)
Return the TIM Encoder Mode handle state.
void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim)
DeInitializes TIM One Pulse MSP.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim)
Initializes the TIM Input Capture MSP.
__HAL_LOCK(hrtc)
HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM Input Capture measurement in DMA mode.
void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
Initializes the TIM Encoder Interface MSP.
HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
Starts the TIM Output Compare signal generation in DMA mode.
HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource)
Generate a software event.
TIM Clear Input Configuration Handle Structure definition.
TIM One Pulse Mode Configuration Structure definition.
HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro_IT(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef *sSlaveConfig)
Configures the TIM in Slave mode in interrupt mode.
void TIM_DMAError(DMA_HandleTypeDef *hdma)
TIM DMA error callback.
HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef *sClockSourceConfig)
Configures the clock source to be used.
static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
Configure the Polarity and Filter for TI2.
HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim)
Initializes the TIM PWM Time Base according to the specified parameters in the TIM_HandleTypeDef and ...
static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
Timer Output Compare 4 configuration.
HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim)
Return the TIM OC handle state.
return HAL_OK
static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma)
TIM DMA Trigger half complete callback.
void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim)
Hall commutation changed callback in non-blocking mode.
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim)
DeInitializes TIM Base MSP.
void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef *hdma)
TIM DMA Capture half complete callback.
static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef *sSlaveConfig)
Slave Timer configuration function.
static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource)
Selects the Input Trigger source.
HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef *sConfig, uint32_t OutputChannel, uint32_t InputChannel)
Initializes the TIM One Pulse Channels according to the specified parameters in the TIM_OnePulse_Init...
void(* pTIM_CallbackTypeDef)(TIM_HandleTypeDef *htim)
HAL TIM Callback pointer definition.
HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the PWM signal generation.
HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim)
Return the TIM One Pulse Mode handle state.
HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM Encoder Interface in interrupt mode.
HAL_TIM_StateTypeDef
HAL State structures definition.
HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM Output Compare signal generation in interrupt mode.
void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma)
TIM DMA Capture complete callback.
void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim)
DeInitializes TIM Output Compare MSP.
HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef *sSlaveConfig)
Configures the TIM in Slave mode.
HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM PWM signal generation in DMA mode.
HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim)
Return the TIM PWM handle state.
void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler, uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter)
Configures the TIMx External Trigger (ETR).
HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
Starts the PWM signal generation.
HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
Starts the TIM Encoder Interface.
HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim)
DeInitializes the TIM One Pulse.
HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
Starts the TIM Output Compare signal generation in interrupt mode.
HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim)
Stops the TIM Base generation.
void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim)
Hall commutation changed half complete callback in non-blocking mode.
static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma)
TIM DMA Trigger callback.
static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter)
Configure the TI2 as Input.
HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim)
Return the TIM Input Capture handle state.
HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM Input Capture measurement.
HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef *sConfig, uint32_t Channel)
Initializes the TIM Input Capture Channels according to the specified parameters in the TIM_IC_InitTy...
HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM Output Compare signal generation.
HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length)
Starts the TIM Encoder Interface in DMA mode.
HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM Input Capture measurement in interrupt mode.
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
Stop the DMA burst reading.
void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim)
Initializes the TIM Output Compare MSP.
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
Output Compare callback in non-blocking mode.
TIM Output Compare Configuration Structure definition.
HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
Starts the TIM Base generation in DMA mode.
HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the TIM Encoder Interface in DMA mode.
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
Period elapsed callback in non-blocking mode.
HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim)
Return the TIM Base handle state.
HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
Starts the PWM signal generation in interrupt mode.
void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim)
Initializes the TIM One Pulse MSP.
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
Input Capture callback in non-blocking mode.
HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim)
DeInitializes the TIM peripheral.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim)
Initializes the TIM Output Compare according to the specified parameters in the TIM_HandleTypeDef and...
void HAL_TIMEx_Break2Callback(TIM_HandleTypeDef *htim)
Hall Break2 detection callback in non blocking mode.
void HAL_TIM_TriggerHalfCpltCallback(TIM_HandleTypeDef *htim)
Hall Trigger detection half complete callback in non-blocking mode.
void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
Timer Output Compare 2 configuration.
HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
Starts the TIM Output Compare signal generation.
static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter)
Configure the TI4 as Input.
struct __TIM_HandleTypeDef else typedef struct endif TIM_HandleTypeDef
TIM Time Base Handle Structure definition.
HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
Stops the TIM DMA Burst mode.
HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
Starts the TIM One Pulse signal generation in interrupt mode.
HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
Stops the PWM signal generation in interrupt mode.
HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef *sClearInputConfig, uint32_t Channel)
Configures the OCRef clear feature.
static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma)
TIM DMA Period Elapse complete callback.
void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
TIM DMA Commutation callback.
HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
Starts the TIM Input Capture measurement.
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
Initializes the TIM Base MSP.
HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
Starts the TIM PWM signal generation in DMA mode.
HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim)
DeInitializes the TIM Base peripheral.
static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
Timer Output Compare 1 configuration.
HAL_StatusTypeDef HAL_TIM_RegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID, pTIM_CallbackTypeDef pCallback)
Register a User TIM callback to be used instead of the weak predefined callback.
void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef *htim)
Period elapsed half complete callback in non-blocking mode.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim)
DeInitializes the TIM peripheral.
void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim)
Hall Trigger detection callback in non-blocking mode.
HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection)
Selects the signal connected to the TI1 input: direct from CH1_input or a XOR combination between CH1...
HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef *sConfig, uint32_t Channel)
Initializes the TIM PWM channels according to the specified parameters in the TIM_OC_InitTypeDef.
HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength)
Configure the DMA Burst to transfer Data from the memory to the TIM peripheral.
void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim)
DeInitializes TIM Encoder Interface MSP.