Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed encoderKRAI Motor_new
EncoderMspInitF4.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 * www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00102166.pdf 00011 * www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00141306.pdf 00012 * 00013 * TIM1_CH1: AF1 @ PA_8, PE_9 00014 * TIM1_CH2: AF1 @ PA_9, PE_11 00015 * 00016 * TIM2_CH1: AF1 @ PA_0, PA_5, PA_15, PB_8* *F446 only 00017 * TIM2_CH2: AF1 @ PA_1, PB_3, PB_9* *F446 only 00018 * 00019 * TIM3_CH1: AF2 @ PA_6, PB_4, PC_6 00020 * TIM3_CH2: AF2 @ PA_7, PB_5, PC_7 00021 * 00022 * TIM4_CH1: AF2 @ PB_6, PD_12 00023 * TIM4_CH2: AF2 @ PB_7, PD_13 00024 * 00025 * TIM5_CH1: AF2 @ PA_0* *TIM5 used by mbed system ticker so unavailable 00026 * TIM5_CH2: AF2 @ PA_1* 00027 * 00028 * TIM8_CH1: AF3 @ PC_6 00029 * TIM8_CH2: AF3 @ PC_7 00030 */ 00031 00032 #ifdef TARGET_STM32F4 00033 void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) 00034 { 00035 GPIO_InitTypeDef GPIO_InitStruct; 00036 00037 if (htim->Instance == TIM1) { //PA8 PA9 = Nucleo D7 D8 00038 __TIM1_CLK_ENABLE(); 00039 __GPIOA_CLK_ENABLE(); 00040 GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9; 00041 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00042 GPIO_InitStruct.Pull = GPIO_PULLDOWN; 00043 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 00044 GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; 00045 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 00046 } 00047 else if (htim->Instance == TIM2) { //PA0 PA1 = Nucleo A0 A1 //USANDO ALTERNO PB8 Y PB 9 para el pololulu funcione 00048 __TIM2_CLK_ENABLE(); 00049 __GPIOB_CLK_ENABLE(); 00050 GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9; 00051 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00052 GPIO_InitStruct.Pull = GPIO_PULLDOWN; 00053 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 00054 GPIO_InitStruct.Alternate = GPIO_AF1_TIM2; 00055 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 00056 } 00057 else if (htim->Instance == TIM3) { //PB4 PB5 = Nucleo D5 D4 00058 __TIM3_CLK_ENABLE(); 00059 __GPIOB_CLK_ENABLE(); 00060 GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5; 00061 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00062 GPIO_InitStruct.Pull = GPIO_PULLDOWN; 00063 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 00064 GPIO_InitStruct.Alternate = GPIO_AF2_TIM3; 00065 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 00066 } 00067 else if (htim->Instance == TIM4) { // PB6 PB7 = Nucleo D10 MORPHO_PB7 00068 __TIM4_CLK_ENABLE(); 00069 __GPIOB_CLK_ENABLE(); 00070 GPIO_InitStruct.Pin = GPIO_PIN_7 | GPIO_PIN_6; 00071 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00072 GPIO_InitStruct.Pull = GPIO_PULLDOWN; 00073 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 00074 GPIO_InitStruct.Alternate = GPIO_AF2_TIM4; 00075 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 00076 } 00077 00078 00079 else if (htim->Instance == TIM8) { // PC7 PC8 = D9 PC6 00080 __TIM8_CLK_ENABLE(); 00081 __GPIOC_CLK_ENABLE(); 00082 GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7; 00083 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00084 GPIO_InitStruct.Pull = GPIO_PULLDOWN; 00085 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 00086 GPIO_InitStruct.Alternate = GPIO_AF3_TIM8; 00087 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 00088 } 00089 00090 00091 00092 00093 00094 00095 } 00096 #endif
Generated on Sat Jul 16 2022 17:05:35 by
1.7.2