You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* Then check if this target timestamp is not in the past, or close to wrap-around
502
+
/* Then check if this target timestamp is in the past and we are not close to wrap-around.
503
503
* Let's assume last_read_counter = 0xFFFC, and we want to program timestamp = 0x100
504
504
* The interrupt will not fire before the CMPOK flag is OK, so there are 2 cases:
505
505
* in case CMPOK flag is set by HW after or at wrap-around, then this will fire only @0x100
506
506
* in case CMPOK flag is set before, it will indeed fire early, as for the wrap-around case.
507
+
* (this is because the comparison is implemented as ">= CMP" rather than "== CMP" as indicated
508
+
* by the reference manual, see https://community.st.com/t5/stm32-mcus-embedded-software/lptim-compare-interruption-sometimes-is-triggered-when-it-should/td-p/85513 )
509
+
*
507
510
* But that will take at least 3 cycles and the interrupt fires at the end of a cycle.
508
511
* In our case 0xFFFC + 3 => at the transition between 0xFFFF and 0.
509
512
* If last_read_counter was 0xFFFB, it should be at the transition between 0xFFFE and 0xFFFF.
510
513
* There might be crossing cases where it would also fire @ 0xFFFE, but by the time we read the counter,
511
514
* it may already have moved to the next one, so for now we've taken this as margin of error.
512
515
*/
513
-
if ((timestamp<last_read_counter) && (last_read_counter <= (0xFFFF-LP_TIMER_SAFE_GUARD))) {
514
-
/* Workaround, because limitation */
516
+
if ((timestamp<last_read_counter) && (last_read_counter <= (LPTIM_PERIOD-LP_TIMER_SAFE_GUARD))) {
517
+
/* Workaround, because limitation. Trigger the interrupt when we are about to roll over. */
0 commit comments