A program to monitor some parameters for a motor
Dependencies: mbed-dev BufferSerial
EncoderMspInitL4.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 * http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00108832.pdf 00011 * Table 15 has GPIOx AFx pinouts 00012 * 00013 * TIM1_CH1: AF1 @ PA8, PE9 00014 * TIM1_CH2: AF1 @ PA9, PE11 00015 * 00016 * TIM2_CH1: AF1 @ PA0, PA5, PA15 00017 * TIM2_CH2: AF1 @ PA1, PB3 00018 * 00019 */ 00020 00021 #ifdef TARGET_STM32L4 00022 void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) 00023 { 00024 GPIO_InitTypeDef GPIO_InitStruct; 00025 00026 if (htim->Instance == TIM1) { //PA8 PA9 = Nucleo D9 D1 00027 __TIM1_CLK_ENABLE(); 00028 __GPIOA_CLK_ENABLE(); 00029 GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9; 00030 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00031 GPIO_InitStruct.Pull = GPIO_PULLDOWN; 00032 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 00033 GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; 00034 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 00035 } 00036 else if (htim->Instance == TIM2) { //PA0 PA1 = Nucleo A0 A1 00037 __TIM2_CLK_ENABLE(); 00038 __GPIOA_CLK_ENABLE(); 00039 GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1; 00040 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00041 GPIO_InitStruct.Pull = GPIO_PULLDOWN; 00042 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 00043 GPIO_InitStruct.Alternate = GPIO_AF1_TIM2; 00044 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 00045 } 00046 } 00047 #endif
Generated on Tue Jul 12 2022 17:32:26 by
![doxygen](doxygen.png)