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 !
If this is Thumb code (Cortex Mx), then you'll need to add ONE to the address.
Thanks! It really works at the absolute address calling function!Can you tell me why? And I actually found this when I try to copy my function to another section like this:
copy_to_ram((char *)0x1ffffC00,(char *)(copyTest),64);
Before I jump to the function ,the copyTest shows its address as 0x230.Once I jump into the copy_to_ram,the param of copyTest turns to 0x231. And now my question is: I want to copy the function copyTest which locates in flash before to RAM,and again call the function by absolute address in RAM .How should I copy it,from 0x230 or 0x231? How should I call it in RAM? I think it's right to copy from 0x230.but I tried to call the RAM function from 0x1ffffC00 or 0x1ffffC01, neither works. Can you be kind to teach me more?Thanks!
Many ARM cores can run two different instruction sets. 32-bit ARM instructions and 16-bit thumb-mode instructions.
The 16-bit instructions still operates on full 32-bit registers but needs a bit of extra work to load a 32-bit immediate value or for accessing a 32-bit absolute address.
Anyway - the core looks at the least significant bit of function pointers to know if the function is using the 32-bit ARM instruction set or the 16-bit Thumb instruction set. This allows 32-bit and 16-bit code to be missed in the same program. So speed-sensitive code can use 32-bit instructions, while other code can save code space by using the more compact thumb instructions.
Thanks very much! Then I think I should still copy from the 0x230 And calls from the address+1.But why still I can't call it from ram and turns to hard fault?
could you be nice to answer me again? Thanks!
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.
Not all processors can run code from all addresses - the address range needs to be handled by the prefetch logic.
Another thing - some processors needs some form of barrier operation after writing code to RAM to make sure that the processor hasn't cached the content of RAM before the RAM write. This can happen when a processor have one instruction cache and one data cache - the data cache sees the RAM writes and has the correct information, but the instruction cache doesn't have any logic to sniff code memory changes.
I can't see anywhere that the chip in question - or even the core in question - has been mentioned but, if it's a Cortex-M, take a look at the links & info here:
community.arm.com/.../5414
Covers Cortex-M0, Cortex-M0+, Cortex-M3, Cortex-M4
Hi,the core is ARM cortex_m0,and the chip is freescale's KL serials. I scanned the linked page,not understand full.I think they are telling how to locate the hard fault.It may be help,but can I ask if my problem is result from executing code from ram? actually I also want to know why it jumps to hard fault when I locate function in special session,like a session in flash? I think the crash has similarity with my coping code from flash to ram and running it. Am I on the right way to solve the problem?Thanks !
View all questions in Keil forum