STM32L4xx_HAL_Driver  1.14.0

TIM Encoder functions. More...

Functions

HAL_StatusTypeDef HAL_TIM_Encoder_Init (TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef *sConfig)
 Initializes the TIM Encoder Interface and initialize the associated handle. More...
 
HAL_StatusTypeDef HAL_TIM_Encoder_DeInit (TIM_HandleTypeDef *htim)
 DeInitializes the TIM Encoder interface. More...
 
void HAL_TIM_Encoder_MspInit (TIM_HandleTypeDef *htim)
 Initializes the TIM Encoder Interface MSP. More...
 
void HAL_TIM_Encoder_MspDeInit (TIM_HandleTypeDef *htim)
 DeInitializes TIM Encoder Interface MSP. More...
 
HAL_StatusTypeDef HAL_TIM_Encoder_Start (TIM_HandleTypeDef *htim, uint32_t Channel)
 Starts the TIM Encoder Interface. More...
 
HAL_StatusTypeDef HAL_TIM_Encoder_Stop (TIM_HandleTypeDef *htim, uint32_t Channel)
 Stops the TIM Encoder Interface. More...
 
HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
 Starts the TIM Encoder Interface in interrupt mode. More...
 
HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
 Stops the TIM Encoder Interface in interrupt mode. More...
 
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. More...
 
HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA (TIM_HandleTypeDef *htim, uint32_t Channel)
 Stops the TIM Encoder Interface in DMA mode. More...
 

Detailed Description

TIM Encoder functions.

  ==============================================================================
                          ##### TIM Encoder functions #####
  ==============================================================================
  [..]
    This section provides functions allowing to:
    (+) Initialize and configure the TIM Encoder.
    (+) De-initialize the TIM Encoder.
    (+) Start the TIM Encoder.
    (+) Stop the TIM Encoder.
    (+) Start the TIM Encoder and enable interrupt.
    (+) Stop the TIM Encoder and disable interrupt.
    (+) Start the TIM Encoder and enable DMA transfer.
    (+) Stop the TIM Encoder and disable DMA transfer.

Function Documentation

◆ HAL_TIM_Encoder_DeInit()

HAL_StatusTypeDef HAL_TIM_Encoder_DeInit ( TIM_HandleTypeDef htim)

DeInitializes the TIM Encoder interface.

Parameters
htimTIM Encoder Interface handle
Return values
HALstatus

Definition at line 2712 of file stm32l4xx_hal_tim.c.

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 }
__HAL_UNLOCK(hrtc)
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim)
DeInitializes TIM Encoder Interface MSP.

◆ HAL_TIM_Encoder_Init()

HAL_StatusTypeDef HAL_TIM_Encoder_Init ( TIM_HandleTypeDef htim,
TIM_Encoder_InitTypeDef sConfig 
)

Initializes the TIM Encoder Interface and initialize the associated handle.

Note
Switching from Center Aligned counter mode to Edge counter mode (or reverse) requires a timer reset to avoid unexpected direction due to DIR bit readonly in center aligned mode. Ex: call HAL_TIM_Encoder_DeInit() before HAL_TIM_Encoder_Init()
Encoder mode and External clock mode 2 are not compatible and must not be selected together Ex: A call for HAL_TIM_Encoder_Init will erase the settings of HAL_TIM_ConfigClockSource using TIM_CLOCKSOURCE_ETRMODE2 and vice versa
Parameters
htimTIM Encoder Interface handle
sConfigTIM Encoder Interface configuration structure
Return values
HALstatus

Definition at line 2607 of file stm32l4xx_hal_tim.c.

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 }
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.
void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
Initializes the TIM Encoder Interface MSP.
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIM_Encoder_MspDeInit()

__weak void HAL_TIM_Encoder_MspDeInit ( TIM_HandleTypeDef htim)

DeInitializes TIM Encoder Interface MSP.

Parameters
htimTIM Encoder Interface handle
Return values
None

Definition at line 2763 of file stm32l4xx_hal_tim.c.

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 }

◆ HAL_TIM_Encoder_MspInit()

__weak void HAL_TIM_Encoder_MspInit ( TIM_HandleTypeDef htim)

Initializes the TIM Encoder Interface MSP.

Parameters
htimTIM Encoder Interface handle
Return values
None

Definition at line 2748 of file stm32l4xx_hal_tim.c.

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 }

◆ HAL_TIM_Encoder_Start()

HAL_StatusTypeDef HAL_TIM_Encoder_Start ( TIM_HandleTypeDef htim,
uint32_t  Channel 
)

Starts the TIM Encoder Interface.

Parameters
htimTIM Encoder Interface handle
ChannelTIM Channels to be enabled This parameter can be one of the following values:
  • TIM_CHANNEL_1: TIM Channel 1 selected
  • TIM_CHANNEL_2: TIM Channel 2 selected
  • TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
Return values
HALstatus

Definition at line 2783 of file stm32l4xx_hal_tim.c.

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 }
return HAL_OK
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIM_Encoder_Start_DMA()

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.

Parameters
htimTIM Encoder Interface handle
ChannelTIM Channels to be enabled This parameter can be one of the following values:
  • TIM_CHANNEL_1: TIM Channel 1 selected
  • TIM_CHANNEL_2: TIM Channel 2 selected
  • TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
pData1The destination Buffer address for IC1.
pData2The destination Buffer address for IC2.
LengthThe length of data to be transferred from TIM peripheral to memory.
Return values
HALstatus

Definition at line 2977 of file stm32l4xx_hal_tim.c.

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 }
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.
void TIM_DMAError(DMA_HandleTypeDef *hdma)
TIM DMA error callback.
return HAL_OK
void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef *hdma)
TIM DMA Capture half complete callback.
void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma)
TIM DMA Capture complete callback.
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIM_Encoder_Start_IT()

HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT ( TIM_HandleTypeDef htim,
uint32_t  Channel 
)

Starts the TIM Encoder Interface in interrupt mode.

Parameters
htimTIM Encoder Interface handle
ChannelTIM Channels to be enabled This parameter can be one of the following values:
  • TIM_CHANNEL_1: TIM Channel 1 selected
  • TIM_CHANNEL_2: TIM Channel 2 selected
  • TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
Return values
HALstatus

Definition at line 2873 of file stm32l4xx_hal_tim.c.

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 }
return HAL_OK
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIM_Encoder_Stop()

HAL_StatusTypeDef HAL_TIM_Encoder_Stop ( TIM_HandleTypeDef htim,
uint32_t  Channel 
)

Stops the TIM Encoder Interface.

Parameters
htimTIM Encoder Interface handle
ChannelTIM Channels to be disabled This parameter can be one of the following values:
  • TIM_CHANNEL_1: TIM Channel 1 selected
  • TIM_CHANNEL_2: TIM Channel 2 selected
  • TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
Return values
HALstatus

Definition at line 2827 of file stm32l4xx_hal_tim.c.

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 }
return HAL_OK
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIM_Encoder_Stop_DMA()

HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA ( TIM_HandleTypeDef htim,
uint32_t  Channel 
)

Stops the TIM Encoder Interface in DMA mode.

Parameters
htimTIM Encoder Interface handle
ChannelTIM Channels to be enabled This parameter can be one of the following values:
  • TIM_CHANNEL_1: TIM Channel 1 selected
  • TIM_CHANNEL_2: TIM Channel 2 selected
  • TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
Return values
HALstatus

Definition at line 3112 of file stm32l4xx_hal_tim.c.

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 }
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
return HAL_OK
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIM_Encoder_Stop_IT()

HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT ( TIM_HandleTypeDef htim,
uint32_t  Channel 
)

Stops the TIM Encoder Interface in interrupt mode.

Parameters
htimTIM Encoder Interface handle
ChannelTIM Channels to be disabled This parameter can be one of the following values:
  • TIM_CHANNEL_1: TIM Channel 1 selected
  • TIM_CHANNEL_2: TIM Channel 2 selected
  • TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
Return values
HALstatus

Definition at line 2923 of file stm32l4xx_hal_tim.c.

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 }
return HAL_OK
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
Enables or disables the TIM Capture Compare Channel x.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))