-

Committer:
calmantara186
Date:
Wed Apr 10 19:48:18 2019 +0000
Revision:
0:1c05321d03a4
external encoder;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
calmantara186 0:1c05321d03a4 1 #include "mbed.h"
calmantara186 0:1c05321d03a4 2 /*
calmantara186 0:1c05321d03a4 3 * HAL_TIM_Encoder_MspInit()
calmantara186 0:1c05321d03a4 4 * Overrides the __weak function stub in stm32f4xx_hal_tim.h
calmantara186 0:1c05321d03a4 5 *
calmantara186 0:1c05321d03a4 6 * Edit the below for your preferred pin wiring & pullup/down
calmantara186 0:1c05321d03a4 7 * I have encoder common at 3V3, using GPIO_PULLDOWN on inputs.
calmantara186 0:1c05321d03a4 8 * Encoder A&B outputs connected directly to GPIOs.
calmantara186 0:1c05321d03a4 9 *
calmantara186 0:1c05321d03a4 10 * www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00102166.pdf
calmantara186 0:1c05321d03a4 11 * www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00141306.pdf
calmantara186 0:1c05321d03a4 12 *
calmantara186 0:1c05321d03a4 13 * TIM1_CH1: AF1 @ PA_8, PE_9
calmantara186 0:1c05321d03a4 14 * TIM1_CH2: AF1 @ PA_9, PE_11
calmantara186 0:1c05321d03a4 15 *
calmantara186 0:1c05321d03a4 16 * TIM2_CH1: AF1 @ PA_0, PA_5, PA_15, PB_8* *F446 only
calmantara186 0:1c05321d03a4 17 * TIM2_CH2: AF1 @ PA_1, PB_3, PB_9* *F446 only
calmantara186 0:1c05321d03a4 18 *
calmantara186 0:1c05321d03a4 19 * TIM3_CH1: AF2 @ PA_6, PB_4, PC_6
calmantara186 0:1c05321d03a4 20 * TIM3_CH2: AF2 @ PA_7, PB_5, PC_7
calmantara186 0:1c05321d03a4 21 *
calmantara186 0:1c05321d03a4 22 * TIM4_CH1: AF2 @ PB_6, PD_12
calmantara186 0:1c05321d03a4 23 * TIM4_CH2: AF2 @ PB_7, PD_13
calmantara186 0:1c05321d03a4 24 *
calmantara186 0:1c05321d03a4 25 * TIM5_CH1: AF2 @ PA_0* *TIM5 used by mbed system ticker so unavailable
calmantara186 0:1c05321d03a4 26 * TIM5_CH2: AF2 @ PA_1*
calmantara186 0:1c05321d03a4 27 *
calmantara186 0:1c05321d03a4 28 * TIM8_CH1: AF3 @ PC_6
calmantara186 0:1c05321d03a4 29 * TIM8_CH2: AF3 @ PC_7
calmantara186 0:1c05321d03a4 30 */
calmantara186 0:1c05321d03a4 31
calmantara186 0:1c05321d03a4 32 #ifdef TARGET_STM32F4
calmantara186 0:1c05321d03a4 33 void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
calmantara186 0:1c05321d03a4 34 {
calmantara186 0:1c05321d03a4 35 GPIO_InitTypeDef GPIO_InitStruct;
calmantara186 0:1c05321d03a4 36
calmantara186 0:1c05321d03a4 37 if (htim->Instance == TIM1) { //PA8 PA9 = Nucleo D7 D8
calmantara186 0:1c05321d03a4 38 __TIM1_CLK_ENABLE();
calmantara186 0:1c05321d03a4 39 __GPIOA_CLK_ENABLE();
calmantara186 0:1c05321d03a4 40 GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9;
calmantara186 0:1c05321d03a4 41 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
calmantara186 0:1c05321d03a4 42 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
calmantara186 0:1c05321d03a4 43 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
calmantara186 0:1c05321d03a4 44 GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
calmantara186 0:1c05321d03a4 45 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
calmantara186 0:1c05321d03a4 46 }
calmantara186 0:1c05321d03a4 47 else if (htim->Instance == TIM2) { //PA0 PA1 = Nucleo A0 A1 //USANDO ALTERNO PB8 Y PB 9 para el pololulu funcione
calmantara186 0:1c05321d03a4 48 __TIM2_CLK_ENABLE();
calmantara186 0:1c05321d03a4 49 __GPIOB_CLK_ENABLE();
calmantara186 0:1c05321d03a4 50 GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9;
calmantara186 0:1c05321d03a4 51 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
calmantara186 0:1c05321d03a4 52 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
calmantara186 0:1c05321d03a4 53 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
calmantara186 0:1c05321d03a4 54 GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
calmantara186 0:1c05321d03a4 55 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
calmantara186 0:1c05321d03a4 56 }
calmantara186 0:1c05321d03a4 57 else if (htim->Instance == TIM3) { //PB4 PB5 = Nucleo D5 D4
calmantara186 0:1c05321d03a4 58 __TIM3_CLK_ENABLE();
calmantara186 0:1c05321d03a4 59 __GPIOB_CLK_ENABLE();
calmantara186 0:1c05321d03a4 60 GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5;
calmantara186 0:1c05321d03a4 61 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
calmantara186 0:1c05321d03a4 62 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
calmantara186 0:1c05321d03a4 63 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
calmantara186 0:1c05321d03a4 64 GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
calmantara186 0:1c05321d03a4 65 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
calmantara186 0:1c05321d03a4 66 }
calmantara186 0:1c05321d03a4 67 else if (htim->Instance == TIM4) { // PB6 PB7 = Nucleo D10 MORPHO_PB7
calmantara186 0:1c05321d03a4 68 __TIM4_CLK_ENABLE();
calmantara186 0:1c05321d03a4 69 __GPIOB_CLK_ENABLE();
calmantara186 0:1c05321d03a4 70 GPIO_InitStruct.Pin = GPIO_PIN_7 | GPIO_PIN_6;
calmantara186 0:1c05321d03a4 71 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
calmantara186 0:1c05321d03a4 72 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
calmantara186 0:1c05321d03a4 73 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
calmantara186 0:1c05321d03a4 74 GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
calmantara186 0:1c05321d03a4 75 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
calmantara186 0:1c05321d03a4 76 }
calmantara186 0:1c05321d03a4 77
calmantara186 0:1c05321d03a4 78
calmantara186 0:1c05321d03a4 79 else if (htim->Instance == TIM8) { // PC7 PC8 = D9 PC6
calmantara186 0:1c05321d03a4 80 __TIM8_CLK_ENABLE();
calmantara186 0:1c05321d03a4 81 __GPIOC_CLK_ENABLE();
calmantara186 0:1c05321d03a4 82 GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
calmantara186 0:1c05321d03a4 83 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
calmantara186 0:1c05321d03a4 84 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
calmantara186 0:1c05321d03a4 85 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
calmantara186 0:1c05321d03a4 86 GPIO_InitStruct.Alternate = GPIO_AF3_TIM8;
calmantara186 0:1c05321d03a4 87 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
calmantara186 0:1c05321d03a4 88 }
calmantara186 0:1c05321d03a4 89
calmantara186 0:1c05321d03a4 90
calmantara186 0:1c05321d03a4 91
calmantara186 0:1c05321d03a4 92
calmantara186 0:1c05321d03a4 93
calmantara186 0:1c05321d03a4 94
calmantara186 0:1c05321d03a4 95 }
calmantara186 0:1c05321d03a4 96 #endif