From 06c6aed23df333c176bd4949828a06c3e4ee8983 Mon Sep 17 00:00:00 2001 From: Nico Tonnhofer Date: Thu, 24 Mar 2016 21:32:47 +0100 Subject: [PATCH] STM32F411: Turn on only timers needed in heater-stm32.c Test: PWM pins work as before. --- heater-stm32.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/heater-stm32.c b/heater-stm32.c index b5594cc..8a86c3d 100644 --- a/heater-stm32.c +++ b/heater-stm32.c @@ -142,23 +142,20 @@ void heater_init() { */ if (NUM_HEATERS) { // At least one channel in use. - - // For simplicity, turn on all timers, not only the used ones. - // TODO: turn on only the used ones. we know pin ## TIMER. - RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; - RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; - RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; - RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; - RCC->APB1ENR |= RCC_APB1ENR_TIM5EN; - RCC->APB2ENR |= RCC_APB2ENR_TIM9EN; - RCC->APB2ENR |= RCC_APB2ENR_TIM10EN; - RCC->APB2ENR |= RCC_APB2ENR_TIM11EN; + uint8_t macro_mask; // Auto-generate pin setup. - - #undef DEFINE_HEATER - uint8_t macro_mask; + #undef DEFINE_HEATER #define DEFINE_HEATER(name, pin, pwm) \ + if (pin ## _TIMER == TIM1) { \ + RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; } /* turn on TIM1 */ \ + else if (pin ## _TIMER == TIM2) { \ + RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; } /* turn on TIM2 */ \ + else if (pin ## _TIMER == TIM3) { \ + RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; } /* turn on TIM3 */ \ + else if (pin ## _TIMER == TIM4) { \ + RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; } /* turn on TIM4 */ \ + /* TIM5 is for stepper, TIM9, TIM10 and TIM11 are not used */ \ pin ## _PORT->MODER &= ~(3 << (pin ## _PIN << 1)); /* reset pin mode */ \ pin ## _PORT->MODER |= (2 << (pin ## _PIN << 1)); /* pin mode to AF */ \ pin ## _PORT->OSPEEDR |= (3 << (pin ## _PIN << 1)); /* high speed */ \