32bits encoder counter using 16bits TIM and a 32bits software counter

Dependents:   v1 v2 v2bis GestionPixy ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EncoderMspInitL0.cpp Source File

EncoderMspInitL0.cpp

00001 #include "mbed.h"
00002 /*
00003  * HAL_TIM_Encoder_MspInit()
00004  * Overrides the __weak function stub in stm32f4xx_hal_tim.h
00005  *
00006  * Edit the below for your preferred pin wiring & pullup/down
00007  * I have encoder common at 3V3, using GPIO_PULLDOWN on inputs.
00008  * Encoder A&B outputs connected directly to GPIOs.
00009  *
00010  */
00011 
00012 #ifdef TARGET_STM32L0
00013 void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
00014 {
00015     GPIO_InitTypeDef GPIO_InitStruct;
00016 
00017     if (htim->Instance == TIM2) { //PA0 PA1 = Nucleo A0 A1
00018         __TIM2_CLK_ENABLE();
00019         __GPIOA_CLK_ENABLE();
00020         GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1;
00021         GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
00022         GPIO_InitStruct.Pull = GPIO_PULLDOWN;
00023         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
00024         GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
00025         HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
00026     }
00027 }
00028 #endif