AnsweredAssumed Answered

Timer Set up conf: intriguing issue.

Question asked by CS on May 20, 2013
Latest reply on May 21, 2013 by YuvaRaja
Hi Folks 

I have this simple example program that I am modifying and by moving one statement into a while statement it breaks it. I'm working on the STM32F4 Discovery board

Here is the code:- 

/*
 ===============================================================================
 Name        : main.cpp
 Author      : 
 Version     :
 Copyright   : Copyright (C)
 Description : main definition
 ===============================================================================
 */


#ifdef __USE_CMSIS
#include "stm32f4xx.h"
#endif


#include <stdio.h>


/* Private typedef -----------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void
LED_Config(void);
void
INTTIM_Config(void);
/* Private functions ---------------------------------------------------------*/


/**
 * @brief  Main program
 * @param  None
 * @retval None
 */
int
main(void)
{
  /* LED Configuration */
  LED_Config();
  INTTIM_Config();


  while (1)
    {
      //INTTIM_Config();
      while (TIM_GetFlagStatus(TIM2, TIM_FLAG_Update ) == RESET)
        {
        };
      TIM_ClearFlag(TIM2, TIM_IT_Update );
      GPIO_ToggleBits(GPIOD, GPIO_Pin_13 );


    }
}


/**
 * @brief  Setup an interval timer
 * @param  None
 * @retval None
 */
void
INTTIM_Config(void)
{
  /* TIM2 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period = 200 - 1; // 1 MHz down to 10 KHz (0.1 ms) between 0x0000 and 0xFFFF.
  TIM_TimeBaseStructure.TIM_Prescaler = 134 - 1; // 24 MHz Clock down to 1 MHz (adjust per your clock)  between 0x0000 and 0xFFFF
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
  /* TIM2 enable counter */
  TIM_Cmd(TIM2, ENABLE);
}


void
LED_Config(void)
{
  /* GPIOD Periph clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);


  /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14
      | GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOD, &GPIO_InitStructure);


}


As it stands the code works fine - however if I commit out the active INTTIM_Config() and make the INTTIM_Config() in the loop active the time base init does not work and the timer stays at default values. 

Any thoughts welcome.

CS

Outcomes