I am writing the following code to store value in array of time and data.I am getting 2 warnings.
main6.c(17): warning: #550-D: variable "time" was set but never used
unsigned long time[50];
main6.c(18): warning: #550-D: variable "data" was set but never used
unsigned long data[50];
Code:-
#include "MKL46Z4.h" // Device header
void InitLED(void)
{
SIM->SCGC5=SIM_SCGC5_PORTD_MASK;// Enable clock to PORTD
PORTD->PCR[5]=256;// Set pin 5 of PORTD as GPIO
PTD->PDDR=(1u<<5);// Set pin 5 of PORTD as OUTPUT
}
void InitSYSTICK(void)
{
SysTick->CTRL=0;//Disable the systick timer
SysTick->LOAD=0x00FFFFFF;//Reload it to its full value 24 bits
SysTick->VAL=0;//Write something in current register to reset it
SysTick->CTRL=0x00000005;//101
}
int main()
{
unsigned long time[50];
unsigned long data[50];
unsigned long i=0,now=0,last=0,j=0;
InitLED();
InitSYSTICK();
last=SysTick->VAL;
while(1)
{
PTD->PTOR=(1u<<5);//Toggle LED
if(i<50)
{
now=SysTick->VAL;
time[i]=(last-now);
data[i]=PTD->PDOR;
last=now;
i++;
}
for(j=0;j<=800000;j++)
{}
}
}
I dont know where i am going wrong.Please Help.
Hi Rohan,
It looks ok. Warning message says that variable is set to some value but not used :
time[i]=(last-now); // this sets variable time
data[i]=PTD->PDOR; // this sets variable data
but nobody reads a value stored in arrays data[] and time[]. This warning message is probably shown due to enabled -Wall compiler option.
for example this reads a values from arrays and warning should not be shown (with disabled code optimizations -O0) :
time[i]= (last-now) + (time[0]-time[0]);
data[i]= PTD->PDOR + (data[0]-data[0]);
Best Regards,
Ondrej
The led is not blinking.When I Debug it,it reaches till data[i]=PTD->PDOR; and then goes into the HardFault_Handler.I dont know why is this happening?
Using volatile has led to 0 warnings but its not working.Please Help.
Are you using gdb? I use this little script to help me display ARM exceptions ARMv7 exception helper
I am not getting what u said?I am new to embedded.
You said that while debugging your execution goes into the HardFault_Handler. Are you using GDB to debug?
Even if you are not, you can probably inspect your registers. I have a mini debug session example here Kinetis K24 debug session that might help you.
I have no idea what you are talking about.I think there is some problem when i try to read the PDOR register because it is at this point that the debugger CMSIS-DAP goes into HardFault_Handler.
This Line:
data[i]=PTD->PDOR;
it is at this point that the debugger goes to HardFault_Handler.Please look into it whether i am reading it correctly or is there a problem somewhere else in the code.
The compiler is correct: you write to these variables, but you do not read from them/use them.
If you want to get rid of the warnings, you either simply add some reads of the data, or you might mark it as volatile.
If you are using GCC, then you could use this pragma in front of the function too:
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
I hope ths helps,
Erich
The led is not blinking.When I Debug it,it reaches till data[i]=PTD->PDOR; and then goes into the HardFault_Handler.I dont know why is this happening?
Using volatile has led to 0 warnings but its not working.Please Help.