Skip to content

Commit 06b747f

Browse files
committed
tm32/timing_stm32: Added an error counter to address an occasional glitch, where a threshold violation is detected during normal operation.
Now we need to count 3 threshold violations to trigger the protection mechanism.
1 parent 522a327 commit 06b747f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/platforms/common/stm32/timing_stm32.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ uint32_t target_clk_divider = 0;
3535
static size_t morse_tick = 0;
3636
#if defined(PLATFORM_HAS_POWER_SWITCH) && defined(STM32F1)
3737
static uint8_t monitor_ticks = 0;
38+
static uint8_t monitor_error_count = 0;
3839

3940
/* Derived from calculating (1.2V / 3.0V) * 4096 */
4041
#define ADC_VREFINT_MAX 1638U
@@ -119,7 +120,12 @@ void sys_tick_handler(void)
119120

120121
/* Now compare the reference against the known good range */
121122
if (ref > ADC_VREFINT_MAX || ref < ADC_VREFINT_MIN) {
122-
/* Something's wrong, so turn tpwr off and set the morse blink pattern */
123+
monitor_error_count++;
124+
} else if (monitor_error_count)
125+
monitor_error_count--;
126+
127+
/* Something's wrong, and it is not a glitch, so turn tpwr off and set the morse blink pattern */
128+
if (monitor_error_count > 3) {
123129
platform_target_set_power(false);
124130
morse("TPWR ERROR", true);
125131
}

0 commit comments

Comments
 (0)