This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STM32 TIM2

Dear Sir

I have a freertos running on the stm32 microncontroller(stm32f101VD),I use a trace function from the API of freertos to record ticks and corresponding tasks

Now the problem is that the tick resolution is too high for me and this means that for the same tick I have manay task recorde, and this because a switch contest can occur betwenn two tick freertos.

So I tried to implement a timer and use the count value in in this trace function API from freertos.

I proceeded like that (from the example code you give ):

void TIM2_Init (void) {

  RCC->APB2ENR |= RCC_APB1ENR_TIM2EN;             /* enable clock for TIM4    */

  TIM2->PSC   = ( 1 - 1);                      /* set prescaler   = 10KHz  */
  TIM2->ARR   = 0xFFFF;                      /* set auto-reload = 250 ms */
  TIM2->RCR   =  0;                              /* set repetition counter   */

  TIM2->DIER = TIM_DIER_UIE;                      /* Update Interrupt enable  */
  NVIC_EnableIRQ(TIM2_IRQn);                   /* TIM2   Interrupt enable  */

  TIM2->CR1  |= TIM_CR1_CEN;                      /* timer enable             */
}

void TIM2_IRQHandler  (void) {

        trace_counter++; // this variable change value actually but cant have the count more
                         //precise ,have same problem as before

  if (TIM2->SR & (TIM_SR_UIF)) {                  /* UIF set?                 */



    TIM2->SR &= ~(TIM_SR_UIF);                    /* clear UIF flag           */
  }

Can you please tell me how can I implement this counter?

0