This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

accessing memory-mapped peripherals with C

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;

}

Parents
  • 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.

Reply
  • 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.

Children