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;
}
Don't let main() exit.
Look at the code generated by the compiler.
Step through the code with the debugger.
Your complaint sounds familiar. Analyze the code that is being run, and the target settings and startup code.
sorry but what did you mean by don't let main exit ?
i went to disassembly window and i got these instructions
325: unsigned int volatile *regdistance =(unsigned int *) accelerator ; 326: 0x0000010A 2159 MOVS r1,#0x59 0x0000010C 0609 LSLS r1,r1,#24 327: *regdistance =22; 328: 329: 330: 0x0000010E 2016 MOVS r0,#0x16 0x00000110 6008 STR r0,[r1,#0x00] 331: }
logically the value has been sent to the 0x59000000 address when i do the simulation with vivado and with the assembly code the up go to the peripheral located on the 0x59000000 then the device take the value 22 as an input. however with c code the up don't even go the peripheral
Have you installed a command line or a GUI for your program to return to after your programs ends by falling out if main()? Notice that there is a big difference between writing programs for a Mac or PC.
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