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@0:ee5cb967aa17, 2015-01-10 (annotated)
- Committer:
 - gregeric
 - Date:
 - Sat Jan 10 20:06:07 2015 +0000
 - Revision:
 - 0:ee5cb967aa17
 - Child:
 - 1:cd7b42c99ff8
 
Hello World example using the STM32's timer hardware interface, no interrupts.; ; Supporting Nucleo F030, F401, F411 (others can be added - L0xx included but untested).; ; Encoder with TIM4 not working on F411, OK on F401?
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| gregeric | 0:ee5cb967aa17 | 1 | #include "mbed.h" | 
| gregeric | 0:ee5cb967aa17 | 2 | /* | 
| gregeric | 0:ee5cb967aa17 | 3 | * HAL_TIM_Encoder_MspInit() | 
| gregeric | 0:ee5cb967aa17 | 4 | * Overrides the __weak function stub in stm32f4xx_hal_tim.h | 
| gregeric | 0:ee5cb967aa17 | 5 | * | 
| gregeric | 0:ee5cb967aa17 | 6 | * Edit the below for your preferred pin wiring & pullup/down | 
| gregeric | 0:ee5cb967aa17 | 7 | * I have encoder common at 3V3, using GPIO_PULLDOWN on inputs. | 
| gregeric | 0:ee5cb967aa17 | 8 | * Encoder A&B outputs connected directly to GPIOs. | 
| gregeric | 0:ee5cb967aa17 | 9 | * | 
| gregeric | 0:ee5cb967aa17 | 10 | * All Nucleos support encoders, from 030 up. | 
| gregeric | 0:ee5cb967aa17 | 11 | * On 030, there's only TIM3 @ AF1 PA6 PA7 (D11 D12) | 
| gregeric | 0:ee5cb967aa17 | 12 | */ | 
| gregeric | 0:ee5cb967aa17 | 13 | |
| gregeric | 0:ee5cb967aa17 | 14 | #ifdef TARGET_STM32F0 | 
| gregeric | 0:ee5cb967aa17 | 15 | void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) | 
| gregeric | 0:ee5cb967aa17 | 16 | { | 
| gregeric | 0:ee5cb967aa17 | 17 | GPIO_InitTypeDef GPIO_InitStruct; | 
| gregeric | 0:ee5cb967aa17 | 18 | |
| gregeric | 0:ee5cb967aa17 | 19 | if (htim->Instance == TIM3) { //PA6 PA7 = Nucleo D12 D11 | 
| gregeric | 0:ee5cb967aa17 | 20 | __TIM3_CLK_ENABLE(); | 
| gregeric | 0:ee5cb967aa17 | 21 | __GPIOA_CLK_ENABLE(); | 
| gregeric | 0:ee5cb967aa17 | 22 | GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7; | 
| gregeric | 0:ee5cb967aa17 | 23 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | 
| gregeric | 0:ee5cb967aa17 | 24 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; | 
| gregeric | 0:ee5cb967aa17 | 25 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | 
| gregeric | 0:ee5cb967aa17 | 26 | GPIO_InitStruct.Alternate = GPIO_AF1_TIM3; | 
| gregeric | 0:ee5cb967aa17 | 27 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | 
| gregeric | 0:ee5cb967aa17 | 28 | } | 
| gregeric | 0:ee5cb967aa17 | 29 | } | 
| gregeric | 0:ee5cb967aa17 | 30 | #endif |