It is based on https://developer.mbed.org/users/gregeric/code/Nucleo_Hello_Encoder/

Committer:
inst
Date:
Sat Apr 09 02:09:32 2016 +0000
Revision:
5:fae9a340d212
Parent:
2:4580c3869b7b

        

Who changed what in which revision?

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