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

how to access core register in c source file

I am using keil mdk arm 5 for controller stm32f0xx.i want to write hard fault handler which prints core resisters value before entering hard fault.i want to write handler in c.so i created one source file having same name as hardfault_handler and try to access sp register through asm keyword but its showing error that r0 and sp is undefined.how can i access core register in source file???

  • Typically you wouldn't, you'd have a small assembler routine to pass the right stack based on the LR as a parameter to your C routine, and then you could decode stack content via that as a pointer.

    See many examples by Joseph Yiu, perhaps buy his book

    In the ABI note also that calling with 4 parameters is equivalent to passing in those registers

    uint32_t foo(uint32_t r0, uint32_t r1, uint32_t r2, uint32_t r3)
    {
    ...
      return(r0);
    }