Skip to content

Latest commit

 

History

History
57 lines (49 loc) · 2.13 KB

File metadata and controls

57 lines (49 loc) · 2.13 KB

Topic

Timer overview

  • stm32f103 overview
  • With stm32f103C8t6 we have 4 timer:
    • Advanced Control: TIM1 using APB2
    • General purpose: TIM 2 - TIM 4 using APB1
  • stm32f103 performance line block diagram
  • Clock frequency for stm32f103C8t6:
    • stm32f103 peripheral clocks

Set up a general timer

  • clock config 72MHz for APB1:
  • timer clock config
  • Then configure the TIM2 countup each 1us:
  • TIM2 configuration
  • Then check generate .c and .h file:
  • generate .c, .h
  • (If interrupt mode) tick to enable interrupt
  • enable interrupt

Coding with timer 2

  • Now in project we have tim.h and tim.c
  • In folder driver for stm32f103 find the stm32f1xx_hal_tim.h list all APIs for timer.

1. Something worth noting

The tim.h
  • extern TIM_HandleTypeDef htim2;
  • void MX_TIM2_Init(void);
The stm32f1xx_hal_tim.h
    /* Blocking mode: Polling */
    HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim);
    HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim);
    /* Non-Blocking mode: Interrupt */
    HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim);
    HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim);
    /* Non-Blocking mode: DMA */
    HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
    HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim);

    // Callback in non blocking modes (Interrupt and DMA)
    void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim);
    void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef *htim);