STM32L4xx_HAL_Driver  1.14.0
TIM Time Base functions

Time Base functions. More...

Functions

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 initialize the associated handle. More...
 
HAL_StatusTypeDef HAL_TIM_Base_DeInit (TIM_HandleTypeDef *htim)
 DeInitializes the TIM Base peripheral. More...
 
void HAL_TIM_Base_MspInit (TIM_HandleTypeDef *htim)
 Initializes the TIM Base MSP. More...
 
void HAL_TIM_Base_MspDeInit (TIM_HandleTypeDef *htim)
 DeInitializes TIM Base MSP. More...
 
HAL_StatusTypeDef HAL_TIM_Base_Start (TIM_HandleTypeDef *htim)
 Starts the TIM Base generation. More...
 
HAL_StatusTypeDef HAL_TIM_Base_Stop (TIM_HandleTypeDef *htim)
 Stops the TIM Base generation. More...
 
HAL_StatusTypeDef HAL_TIM_Base_Start_IT (TIM_HandleTypeDef *htim)
 Starts the TIM Base generation in interrupt mode. More...
 
HAL_StatusTypeDef HAL_TIM_Base_Stop_IT (TIM_HandleTypeDef *htim)
 Stops the TIM Base generation in interrupt mode. More...
 
HAL_StatusTypeDef HAL_TIM_Base_Start_DMA (TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
 Starts the TIM Base generation in DMA mode. More...
 
HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA (TIM_HandleTypeDef *htim)
 Stops the TIM Base generation in DMA mode. More...
 

Detailed Description

Time Base functions.

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

Function Documentation

◆ HAL_TIM_Base_DeInit()

HAL_StatusTypeDef HAL_TIM_Base_DeInit ( TIM_HandleTypeDef htim)

DeInitializes the TIM Base peripheral.

Parameters
htimTIM Base handle
Return values
HALstatus

Definition at line 320 of file stm32l4xx_hal_tim.c.

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

◆ HAL_TIM_Base_Init()

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 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_Base_DeInit() before HAL_TIM_Base_Init()
Parameters
htimTIM Base handle
Return values
HALstatus

Definition at line 268 of file stm32l4xx_hal_tim.c.

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

◆ HAL_TIM_Base_MspDeInit()

__weak void HAL_TIM_Base_MspDeInit ( TIM_HandleTypeDef htim)

DeInitializes TIM Base MSP.

Parameters
htimTIM Base handle
Return values
None

Definition at line 371 of file stm32l4xx_hal_tim.c.

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 }

◆ HAL_TIM_Base_MspInit()

__weak void HAL_TIM_Base_MspInit ( TIM_HandleTypeDef htim)

Initializes the TIM Base MSP.

Parameters
htimTIM Base handle
Return values
None

Definition at line 356 of file stm32l4xx_hal_tim.c.

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 }

◆ HAL_TIM_Base_Start()

HAL_StatusTypeDef HAL_TIM_Base_Start ( TIM_HandleTypeDef htim)

Starts the TIM Base generation.

Parameters
htimTIM Base handle
Return values
HALstatus

Definition at line 387 of file stm32l4xx_hal_tim.c.

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 }
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIM_Base_Start_DMA()

HAL_StatusTypeDef HAL_TIM_Base_Start_DMA ( TIM_HandleTypeDef htim,
uint32_t *  pData,
uint16_t  Length 
)

Starts the TIM Base generation in DMA mode.

Parameters
htimTIM Base handle
pDataThe source Buffer address.
LengthThe length of data to be transferred from memory to peripheral.
Return values
HALstatus

Definition at line 486 of file stm32l4xx_hal_tim.c.

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 }
static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma)
TIM DMA Period Elapse half complete callback.
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
static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma)
TIM DMA Period Elapse complete callback.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIM_Base_Start_IT()

HAL_StatusTypeDef HAL_TIM_Base_Start_IT ( TIM_HandleTypeDef htim)

Starts the TIM Base generation in interrupt mode.

Parameters
htimTIM Base handle
Return values
HALstatus

Definition at line 439 of file stm32l4xx_hal_tim.c.

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 }
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIM_Base_Stop()

HAL_StatusTypeDef HAL_TIM_Base_Stop ( TIM_HandleTypeDef htim)

Stops the TIM Base generation.

Parameters
htimTIM Base handle
Return values
HALstatus

Definition at line 416 of file stm32l4xx_hal_tim.c.

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 }
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIM_Base_Stop_DMA()

HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA ( TIM_HandleTypeDef htim)

Stops the TIM Base generation in DMA mode.

Parameters
htimTIM Base handle
Return values
HALstatus

Definition at line 545 of file stm32l4xx_hal_tim.c.

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 }
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_TIM_Base_Stop_IT()

HAL_StatusTypeDef HAL_TIM_Base_Stop_IT ( TIM_HandleTypeDef htim)

Stops the TIM Base generation in interrupt mode.

Parameters
htimTIM Base handle
Return values
HALstatus

Definition at line 465 of file stm32l4xx_hal_tim.c.

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 }
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))