Counter using TIM2

Dependencies:   mbed

Fork of Nucleo_Hello_counter by paolo della vedova

Committer:
fadamo
Date:
Fri Dec 04 10:06:23 2015 +0000
Revision:
5:e1783d6ee885
Counter using TIM2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fadamo 5:e1783d6ee885 1 #include "mbed.h"
fadamo 5:e1783d6ee885 2 /*
fadamo 5:e1783d6ee885 3 * HAL_TIM_Encoder_MspInit()
fadamo 5:e1783d6ee885 4 * Overrides the __weak function stub in stm32f4xx_hal_tim.h
fadamo 5:e1783d6ee885 5 *
fadamo 5:e1783d6ee885 6 * Edit the below for your preferred pin wiring & pullup/down
fadamo 5:e1783d6ee885 7 * I have encoder common at 3V3, using GPIO_PULLDOWN on inputs.
fadamo 5:e1783d6ee885 8 * Encoder A&B outputs connected directly to GPIOs.
fadamo 5:e1783d6ee885 9 *
fadamo 5:e1783d6ee885 10 */
fadamo 5:e1783d6ee885 11
fadamo 5:e1783d6ee885 12 #ifdef TARGET_STM32L0
fadamo 5:e1783d6ee885 13 void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
fadamo 5:e1783d6ee885 14 {
fadamo 5:e1783d6ee885 15 GPIO_InitTypeDef GPIO_InitStruct;
fadamo 5:e1783d6ee885 16
fadamo 5:e1783d6ee885 17 if (htim->Instance == TIM2) { //PA0 PA1 = Nucleo A0 A1
fadamo 5:e1783d6ee885 18 __TIM2_CLK_ENABLE();
fadamo 5:e1783d6ee885 19 __GPIOA_CLK_ENABLE();
fadamo 5:e1783d6ee885 20 GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1;
fadamo 5:e1783d6ee885 21 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
fadamo 5:e1783d6ee885 22 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
fadamo 5:e1783d6ee885 23 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
fadamo 5:e1783d6ee885 24 GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
fadamo 5:e1783d6ee885 25 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
fadamo 5:e1783d6ee885 26 }
fadamo 5:e1783d6ee885 27 }
fadamo 5:e1783d6ee885 28 #endif
fadamo 5:e1783d6ee885 29