A program to monitor some parameters for a motor

Dependencies:   mbed-dev BufferSerial

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EncoderMspInitF4.cpp Source File

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  *
00014  * TIM2_CH1: AF1 @ PA_0, PA_5, PA_15, PB_8*     *F446 only
00015  * TIM2_CH2: AF1 @ PA_1, PB_3, PB_9*            *F446 only
00016  *
00017  *
00018  */
00019 
00020 #ifdef TARGET_STM32F4
00021 void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
00022 {
00023     GPIO_InitTypeDef GPIO_InitStruct;
00024 
00025     if (htim->Instance == TIM2) { //PA0 PA1 = Nucleo A0 A1
00026         __TIM2_CLK_ENABLE();
00027         __GPIOA_CLK_ENABLE();
00028         GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1;
00029         GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
00030         GPIO_InitStruct.Pull = GPIO_PULLDOWN;
00031         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
00032         GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
00033         HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
00034     }
00035 }
00036 #endif