From ad453ef35ab42d5e5bff291dfa0aefd0d1049d66 Mon Sep 17 00:00:00 2001 From: Raptor Engineering Development Team Date: Fri, 19 Aug 2022 14:07:28 -0500 Subject: [PATCH] Mark uptime counter volatile to avoid miscompilation of delay loops Since the uptime counter is updated in an ISR, the compiler may attempt to optimize away code that checks for an updated value. Avoid this by marking the uptime counter as volatile. --- isr.c | 2 +- main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/isr.c b/isr.c index 142ba3c..f541c37 100644 --- a/isr.c +++ b/isr.c @@ -10,7 +10,7 @@ uint32_t irq_unhandled_source = 0; uint8_t irq_unhandled_vector_valid = 0; uint8_t irq_unhandled_source_valid = 0; -uint64_t uptime_counter_ms = 0; +volatile uint64_t uptime_counter_ms = 0; void isr(uint64_t vec); void isr_dec(void); diff --git a/main.c b/main.c index a56f16b..edd0190 100644 --- a/main.c +++ b/main.c @@ -112,7 +112,7 @@ uint8_t host_flash_write_buffer[FLASH_MAX_WR_WINDOW_BYTES]; -extern uint64_t uptime_counter_ms; +extern volatile uint64_t uptime_counter_ms; extern uint32_t irq_unhandled_vector; extern uint32_t irq_unhandled_source; -- 2.30.2