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.
Encoder/EncoderMspInitF0.cpp@7:62c2c1382d86, 2016-10-23 (annotated)
- Committer:
- triochi
- Date:
- Sun Oct 23 15:48:58 2016 +0000
- Revision:
- 7:62c2c1382d86
Changed encoder library;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| triochi | 7:62c2c1382d86 | 1 | #include "mbed.h" |
| triochi | 7:62c2c1382d86 | 2 | /* |
| triochi | 7:62c2c1382d86 | 3 | * HAL_TIM_Encoder_MspInit() |
| triochi | 7:62c2c1382d86 | 4 | * Overrides the __weak function stub in stm32f0xx_hal_tim.h |
| triochi | 7:62c2c1382d86 | 5 | * |
| triochi | 7:62c2c1382d86 | 6 | * Edit the below for your preferred pin wiring & pullup/down |
| triochi | 7:62c2c1382d86 | 7 | * I have encoder common at 3V3, using GPIO_PULLDOWN on inputs. |
| triochi | 7:62c2c1382d86 | 8 | * Encoder A&B outputs connected directly to GPIOs. |
| triochi | 7:62c2c1382d86 | 9 | * |
| triochi | 7:62c2c1382d86 | 10 | * http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00088500.pdf |
| triochi | 7:62c2c1382d86 | 11 | * Table 11 has GPIO alternate function pinout mappings. |
| triochi | 7:62c2c1382d86 | 12 | * |
| triochi | 7:62c2c1382d86 | 13 | * TIM1_CH1: AF2 @ PA_8 - TIM1 used as system ticker under mbed, so unavailable |
| triochi | 7:62c2c1382d86 | 14 | * TIM1_CH2: AF2 @ PA_9 |
| triochi | 7:62c2c1382d86 | 15 | * |
| triochi | 7:62c2c1382d86 | 16 | * TIM3_CH1: AF1 @ PA_6, PB_4; AF0 @ PC_6* *only for F030xC devices |
| triochi | 7:62c2c1382d86 | 17 | * TIM3_CH2: AF1 @ PA_7, PB_5; AF0 @ PC_7* |
| triochi | 7:62c2c1382d86 | 18 | * |
| triochi | 7:62c2c1382d86 | 19 | */ |
| triochi | 7:62c2c1382d86 | 20 | |
| triochi | 7:62c2c1382d86 | 21 | #ifdef TARGET_STM32F0 |
| triochi | 7:62c2c1382d86 | 22 | void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) |
| triochi | 7:62c2c1382d86 | 23 | { |
| triochi | 7:62c2c1382d86 | 24 | GPIO_InitTypeDef GPIO_InitStruct; |
| triochi | 7:62c2c1382d86 | 25 | |
| triochi | 7:62c2c1382d86 | 26 | if (htim->Instance == TIM3) { //PB_4 PB_5 = Nucleo D5 D4 |
| triochi | 7:62c2c1382d86 | 27 | __TIM3_CLK_ENABLE(); |
| triochi | 7:62c2c1382d86 | 28 | __GPIOB_CLK_ENABLE(); |
| triochi | 7:62c2c1382d86 | 29 | GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5; |
| triochi | 7:62c2c1382d86 | 30 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| triochi | 7:62c2c1382d86 | 31 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; |
| triochi | 7:62c2c1382d86 | 32 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
| triochi | 7:62c2c1382d86 | 33 | GPIO_InitStruct.Alternate = GPIO_AF1_TIM3; |
| triochi | 7:62c2c1382d86 | 34 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| triochi | 7:62c2c1382d86 | 35 | } |
| triochi | 7:62c2c1382d86 | 36 | } |
| triochi | 7:62c2c1382d86 | 37 | #endif |