From e4e4fb01a19fa9bff3bec4b398c860aa92110c2e Mon Sep 17 00:00:00 2001 From: Daniel Glaser <7723396+the78mole@users.noreply.github.com> Date: Fri, 22 May 2020 19:26:41 +0200 Subject: [PATCH] Adding volatile to tasks.c's runtime information to protect against compiler optimization (#62) As discussed in https://forums.freertos.org/t/make-runtime-stats-working-with-compiler-optimization-enabled/9846 and on lined out on https://blog.the78mole.de/freertos-debugging-on-stm32-cpu-usage/, adding the volatile prevents the run-time stats variable being optimized away when used with compiler optimizations. --- tasks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks.c b/tasks.c index d63f6ccfd..c057973d1 100644 --- a/tasks.c +++ b/tasks.c @@ -393,7 +393,7 @@ PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended = ( UBaseType_t /* Do not move these variables to function scope as doing so prevents the code working with debuggers that need to remove the static qualifier. */ PRIVILEGED_DATA static uint32_t ulTaskSwitchedInTime = 0UL; /*< Holds the value of a timer/counter the last time a task was switched in. */ - PRIVILEGED_DATA static uint32_t ulTotalRunTime = 0UL; /*< Holds the total amount of execution time as defined by the run time counter clock. */ + PRIVILEGED_DATA static volatile uint32_t ulTotalRunTime = 0UL; /*< Holds the total amount of execution time as defined by the run time counter clock. */ #endif