AnsweredAssumed Answered

Problem: Time Base generation on STM32F411 Nucleo

Question asked by syrer.nazir on Jan 26, 2015
Latest reply on Jan 27, 2015 by syrer.nazir
Hello,

as a new comer to the world of STM32, i started with some tutorials and examples to get into working with those nice microprocessors/micro controllers. Im trying since 1 week to produce a simple time base in order to start with the timer modules. Actually it runs right now, but no matter which parameters i use for the prescaler and top value (in ARR-register), i still get the same signal as output (period ~770ns with 50%dutyCycle). Does anyone have an idea what the problem is?
some facts:
+ Board: STM32F411 NucleoI use the HAL-Library from ST.
+ The program should toggle a pin each time the top value is reached.
int main(void)
{
  HAL_Init();
   
  /* Configure the System clock to 100 MHz */
  SystemClock_Config();
     
  /* Configure output port */
  port_init();
     
  /* == Timer Challenge == */
  TimHandle.Instance = TIM3;
  TimHandle.Init.Period = 0x0fff;
  TimHandle.Init.Prescaler = 0x00ff;
  TimHandle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
 
    /* ++ debug info output ++ */
    //printf("\nHello world!\n");
    //printf("%d\n",HAL_RCC_GetSysClockFreq());
    /* ++ debug info output ++ */
 
    HAL_TIM_Base_Init(&TimHandle);
    HAL_TIM_Base_Start_IT(&TimHandle);
     
    /* == Timer Challenge == */
     
  while (1)
  {
         
  }
}
 
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
{
    // Enable TIM Interface Clock
    __TIM3_CLK_ENABLE();
     
    HAL_NVIC_SetPriority(TIM3_IRQn, 4, 0);
  // Enable the TIMx global Interrupt
  HAL_NVIC_EnableIRQ(TIM3_IRQn);
}
 
void port_init(void)
{
    /* Enable the LED Clock */
    __GPIOA_CLK_ENABLE();
     
  GPIO_InitTypeDef  GPIOA_InitStruct;
  GPIOA_InitStruct.Pin = GPIO_PIN_6;
  GPIOA_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIOA_InitStruct.Pull = GPIO_PULLUP;
  GPIOA_InitStruct.Speed = GPIO_SPEED_FAST;
   
  HAL_GPIO_Init(GPIOA, &GPIOA_InitStruct);
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,GPIO_PIN_RESET);
}

File stm32f4xx_it.c
void TIM3_IRQHandler(void)
{
    HAL_NVIC_ClearPendingIRQ(TIM3_IRQn);
    HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_6);
}

Outcomes