This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

APP_TIMER_DEF() warnings in Keil

I just ported my SDK 9.0 app timer code to SDK 10.0 which requires the use of the new APP_TIMER_DEF() macro. The problem is that is generates warnings in Keil (v5.17) that the timer ID variable I sent to the macro is declared but never referenced. The code compiles and runs fine, but I hate having warnings generated by my code. Any way to fix this?

Parents
  • You should only get that warning if a variable is declared but never referenced. Can you verify that you use the variable that you have declared? E.g. if you have declared the timer ID with APP_TIMER_DEF() you should use it somewhere, typically at lest you would create the timer using app_timer_create().

  • There is in fact a issue with this code. You declare the timer ID's correctly in line 40 and 41. These are used later. Then, by a mistake I assume, you declare the same variables again in main (line 151 and 152). These new variables will shadow the previously declared variables, and they are never used in your code. Thus the warning is correct. Just remove line 151 and 152 and you should be good (probably the extra variables are optimized away anyway, so the resulting application will not change, but you will get rid of the warning). For some reason Keil does not give a warning on shadowing even if you select "All Warnings", so it can be easy to miss.

Reply
  • There is in fact a issue with this code. You declare the timer ID's correctly in line 40 and 41. These are used later. Then, by a mistake I assume, you declare the same variables again in main (line 151 and 152). These new variables will shadow the previously declared variables, and they are never used in your code. Thus the warning is correct. Just remove line 151 and 152 and you should be good (probably the extra variables are optimized away anyway, so the resulting application will not change, but you will get rid of the warning). For some reason Keil does not give a warning on shadowing even if you select "All Warnings", so it can be easy to miss.

Children
No Data
Related