20200717

Revision:
11:2c48a1479026
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HAL_TIM_Encoder_MspInit/EncoderMspInitF7.cpp	Fri Aug 30 00:50:34 2019 +0000
@@ -0,0 +1,67 @@
+#include "mbed.h"
+/*
+ * HAL_TIM_Encoder_MspInit()
+ * Overrides the __weak function stub in stm32f7xx_hal_tim.h
+ *
+ * Edit the below for your preferred pin wiring & pullup/down
+ * I have encoder common at 3V3, using GPIO_PULLDOWN on inputs.
+ * Encoder A&B outputs connected directly to GPIOs.
+ *
+ * www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00102166.pdf
+ * www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00141306.pdf
+ *
+ * TIM1_CH1: AF1 @ PA_8, PE_9 
+ * TIM1_CH2: AF1 @ PA_9, PE_11 
+ * TIM1_CH3: AF1 @ PA_10, PE_13 
+ * TIM1_CH4: AF1 @ PA_11, PE_14 
+ *
+ * TIM2_CH1: AF1 @ PA_0, PA_5, PA_15
+ * TIM2_CH2: AF1 @ PA_1, PB_3
+ * TIM2_CH3: AF1 @ PA_2, PB_10
+ * TIM2_CH4: AF1 @ PA_3, PB_11
+ * 
+ * TIM3_CH1: AF2 @ PA_6, PB_4, PC_6
+ * TIM3_CH2: AF2 @ PB_5, PC_7
+ * TIM3_CH3: AF2 @ PC_8
+ * TIM3_CH4: AF2 @ PC_9
+ *
+ * TIM4_CH1: AF2 @ PB_6, PD_12
+ * TIM4_CH2: AF2 @ PB_7, PD_13
+ * TIM4_CH3: AF2 @ PB_8, PD_14
+ * TIM4_CH4: AF2 @ PB_9, PD_15
+ *
+ * TIM9_CH1: AF3 @ PE_5
+ * TIM9_CH2: AF3 @ PE_6
+ *
+ */
+
+#ifdef TARGET_STM32F7
+void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) {
+    GPIO_InitTypeDef GPIO_InitStruct;
+    
+    if (htim->Instance == TIM2) { //PB10 P11 = Nucleo D36 D35
+        __TIM2_CLK_ENABLE();
+        //__GPIOB_CLK_ENABLE();
+        GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11;
+        GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+        GPIO_InitStruct.Pull = GPIO_NOPULL;
+        //GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+        //GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
+        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+        
+        HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
+        HAL_NVIC_EnableIRQ(TIM2_IRQn);
+    
+    } else if (htim->Instance == TIM4) { // PD12 PD13 = Nucleo D29 D28 
+        __HAL_RCC_TIM4_CLK_ENABLE();
+        __HAL_RCC_GPIOD_CLK_ENABLE();
+        GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13;
+        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+        GPIO_InitStruct.Pull = GPIO_NOPULL;
+        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
+        GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
+        HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
+    }
+}
+
+#endif
\ No newline at end of file