japaric / stm32f103xx-hal

HAL for the STM32F103xx family of microcontrollers
Apache License 2.0
115 stars 40 forks source link

Apply prescaler and reset counter on timer start #58

Closed TheZoq2 closed 6 years ago

TheZoq2 commented 6 years ago

First of all, this commit fixes #57. Turns out that the prescaler value isn't applied until after an "update" event which gets triggered when the counter resets. This commit makes the update event trigger in the start function and then resets the uif flag which would otherwise indicate that the timer is already done.

This also fixes an issue where the following program would not wait for the second timer

loop {
    timer1.start(Hertz(2));
    block!(timer1.wait));
    timer2.start(Hertz(1));
    block(timer2.wait());
}
japaric commented 6 years ago

Thanks @TheZoq2

bors r+

(I feel like I have run into this and fixed it more than once before ...)

bors[bot] commented 6 years ago

Build succeeded