AnsweredAssumed Answered

Problem with timer external clock STM32F303VC

Question asked by Snaut on Mar 14, 2015
Latest reply on Mar 15, 2015 by Snaut
Hello everybody. I try configure the timer 3 with external clock, but I have a problem. When done a signal in PD2 (ETR), the timer don't increase. I think that problem is for any enable clock... I use HAL libraries with ST cube but the register I configure with manual form.
I use STM32F3 Discovery
This is my code.

/* Includes ------------------------------------------------------------------*/
#include "stm32f3xx_hal.h"

/* Private variables ---------------------------------------------------------*/
TIM_HandleTypeDef htim3;

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void TIM3_Config(void);


int main(void)
{
  HAL_Init();
  SystemClock_Config();

  MX_GPIO_Init();
  TIM3_Config();

  while (1)
  {
        GPIOA->ODR=TIM3->CNT;
  }
}

void SystemClock_Config(void)
{

  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV8;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);

  __SYSCFG_CLK_ENABLE();

}

void TIM3_Config(void)
{    
    __TIM3_CLK_ENABLE();
        TIM3->CR1=0x0001;
        TIM3->CR2=0x0000;
        TIM3->SMCR=0x5000;
        TIM3->DIER=0x0001;
        TIM3->EGR=0x0000;
        TIM3->CNT=0x0005;  
        TIM3->PSC=0x0000;
}

void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct;

      __GPIOA_CLK_ENABLE();
    __GPIOD_CLK_ENABLE();
 
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|
                                                GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|
                                                GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

}

Outcomes