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

access to function using absolute addr

Hi,everyone ,I'm trying to access my function using its absolute address.It works when I debug it in KEIL step by step,but it jump to hard fault when runs.
my code is as below:

ptr=(int(*)(int))0x240; //0x240 is the address my function locates.
c=ptr(2);

And I've also met a very similar problem.The program jumps to hard fault when I have function(placed in a single file)placed in a special section .And the placement is fulfilled by sct file like this(fsk_tx.c):

; *************************************************************

LR_IROM1 0x00000000 0x00008000 { ; load region size_region ER_IROM1 0x00000000 0x00007000 { ; load address = execution address *.o (RESET, +First) *(InRoot$$Sections) .ANY (+RO)

} ER_ROM 0x00007000 0X1000 { fsk_tx.o } ER_RAM 0x1FFFFB00 0X100 {

} RW_IRAM1 0x1FFFFD00 0x00000300 { ; RW data .ANY (+RW +ZI) } RW_IRAM2 0x20000000 0x00000C00 { .ANY (+RW +ZI) *(runinram) }
}

And the program works if I comment the fsk_tx.o in the sct file.

I'm really puzzled about it ,and I have to make it work soon.
Thanks !

Parents
  • You might want to examine the code you have copied, and using the debugger, step into the function. This might indicate why it's faulting.

    I don't know which part you are using, the address decoding can cause faults, and preclude execution of code. The Mx part's I'm more familiar with have RAM at 0x20000000, and code can generally be executed from there.

Reply
  • You might want to examine the code you have copied, and using the debugger, step into the function. This might indicate why it's faulting.

    I don't know which part you are using, the address decoding can cause faults, and preclude execution of code. The Mx part's I'm more familiar with have RAM at 0x20000000, and code can generally be executed from there.

Children
  • The disassembling window presents code below:
    Mov r1,r0
    cmp r1,#00
    BEQ 0x20000010 --------------->the 0x20000010 is 0x10 bytes below the copy-to-address 0x20000000
    LDR r0,[pc,#12]
    LDR r0,[r0,#0x00] ------------------> hard fault occurs here
    ADDS r0,r0,#1
    LDR r2,[pc,#4]
    STR r0,[r2,#0x00]
    Movs r0,#0x01
    BX lr

    and my C code (copyTest):
    int shijian;
    int copyTest(int waste)
    { if(waste) shijian+=1; return 1;
    }

    And my MCU is freescale's ARM cortex_m0, it's ram is from 0x1ffffc00~0x20000C00.
    I had tried to execute code from ram,so I think the address is executed allowed.And the upper code is what I tried to copy the copyTest from flash to 0X20000000(ram).
    Can you find any problem?Thanks!

  • The LDR r0,[pc,#12] is attempting to load a literal beyond the end of the subroutine, so chances are you're not copying enough of the code representing the subroutine.