Skip to content

Commit

Permalink
tm32/timing_stm32: Added an error counter to address an occasional gl…
Browse files Browse the repository at this point in the history
…itch, where a threshold violation is detected during normal operation.

Now we need to count 3 threshold violations to trigger the protection
mechanism.
  • Loading branch information
esden committed Jan 11, 2024
1 parent 476017e commit 7d749f3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/platforms/common/stm32/timing_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ uint32_t target_clk_divider = 0;
static size_t morse_tick = 0;
#if defined(PLATFORM_HAS_POWER_SWITCH) && defined(STM32F1)
static uint8_t monitor_ticks = 0;
static uint8_t monitor_error_count = 0;

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

/* Now compare the reference against the known good range */
if (ref > ADC_VREFINT_MAX || ref < ADC_VREFINT_MIN) {
/* Something's wrong, so turn tpwr off and set the morse blink pattern */
monitor_error_count++;
} else if (monitor_error_count)
monitor_error_count--;

/* Something's wrong, and it is not a glitch, so turn tpwr off and set the morse blink pattern */
if (monitor_error_count > 3) {
platform_target_set_power(false);
morse("TPWR ERROR", true);
}
Expand Down

0 comments on commit 7d749f3

Please sign in to comment.