STM32F411: Respect configured PWM frequencies in heater-stm32.c

Test: the PWM frequency on the scope should be similar to the
one configures in the board file with DEFINE_HEATER().
This commit is contained in:
Nico Tonnhofer 2016-03-24 21:50:11 +01:00
parent 06c6aed23d
commit 423c5694d0
1 changed files with 7 additions and 1 deletions

View File

@ -142,6 +142,7 @@ void heater_init() {
*/
if (NUM_HEATERS) { // At least one channel in use.
uint32_t freq;
uint8_t macro_mask;
// Auto-generate pin setup.
@ -173,7 +174,12 @@ void heater_init() {
pin ## _TIMER->ARR = PWM_SCALE - 1; /* reset on auto reload at 254 */ \
/* PWM_SCALE - 1, so CCR = 255 is full off. */ \
pin ## _TIMER-> EXPANDER(CCR, pin ## _CHANNEL,) = 0; /* start off */ \
pin ## _TIMER->PSC = F_CPU / PWM_SCALE / 1000 - 1; /* 1kHz */ \
freq = F_CPU / PWM_SCALE / pwm; /* Figure PWM freq. */ \
if (freq > 65535) \
freq = 65535; \
if (freq < 1) \
freq = 1; \
pin ## _TIMER->PSC = freq - 1; /* 1kHz */ \
macro_mask = pin ## _CHANNEL > 2 ? 2 : 1; \
if (macro_mask == 1) { \
pin ## _TIMER->CCMR1 |= 0x0D << (3 + (8 * (pin ## _CHANNEL / macro_mask - 1))); \