hi i defined a peripheral at 0x59000000 address and am trying to send a value to that register with my c code i succeeded to send a value with assembly
AGAIN LDR R1, =0x59000000 LDR R0, =0x00000022 STR R0, [R1]
but i failed to do that with my c code
#define accelerator 0x59000000 int main() { unsigned int volatile *regdistance =(unsigned int *) accelerator ;
*regdistance =22;
}
however with c code the up don't even go the peripheral
YOU KEEP TELLING ME THIS
Stop using the simulator, start using the debugger, uncheck "run to main" and STEP THROUGH ALL THE CODE THAT THE PROCESSOR IS EXECUTING. This way you will KNOW what is actually happening.
main() { // ... while(1); // infinite loop so it doesn't fall off the end of the world }
http://www.keil.com/forum/61285/access-to-the-register/
http://www.keil.com/forum/61290/access-to-register/
thank M Westonsupermare Pier i did as you said and i found the problem,even though i was a bit slow, sorry if i annoyed you by my ignorance. the prob was with the definition of the pointer i didn't get why since my colleague used that same definition and it worked but i had to use this form
unsigned int xd[10]; unsigned int regdistance __attribute__((at(0x59000000))); int main() { int i; for( i=1;i<10;i++){ xd[i]=(-1+2*(rand())); regdistance = xd[i]; while(1);
.
also if you don't mind would you explain to me why do i have to make sure that my main doesn't exit.
Don't forget "volatile" if a memory address maps to some I/O register, since the compiler must not assume that two reads in a row will give the same value. And it must not assume that if you do two identical writes then it's safe to remove the second write.
ok thank you
>>also if you don't mind would you explain to me why do i have to make sure that my main doesn't exit.
Where do you think the system goes after you leave? Have you provided any code in the startup.s to handle this expectation?
It is not like running a C application on Windows/Linux where it returns to the command console with a return code. In embedded unless you provide some defined behaviour it is going to crash, like exiting a tall building via an open upper floor window. It is not going anywhere good, best to stop in a loop where you can break with the debugger if required, and not start some random journey executing unknown/undefined code.
crystal clear thank you