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

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

Children