I am currently working on a bootloader for ARM Cortex M3.
I have two functions: one in C and one in the assembly, but when I try to call the assembly function, my program freezes and generates some kind of error.
The functions are as follows:
WITH
extern void asmJump(void* Address) __attribute__((noreturn)); void load(void* Address) { asmJump(Address); }
Assembly:
.section .text .global asmJump asmJump: @ Accepts the address of the Vector Table @ as its first parameter (passed in r0) ldr r2, [r0] @ Move the stack pointer addr. to a temp register. ldr r3, [r0,
And my problem is this:
The code prints "Hello" at the serial number, and then calls load . The downloaded code prints "Good Bye" and then resets the chip.
If I slowly asmJump part where load calls asmJump , everything works fine. However, when I run the code, my code experiences a "memory error". I know this is a memory error, because it causes Hard Fault in some way (the Hard Fault handler runs an infinite while loop when paused after 4 or 5 seconds).
Has anyone experienced this problem before? If so, can you tell me how to solve it?
As you can see, I tried to use the attributes of the function to fix the problem, but so far I could not find a solution. I hope someone can help me understand what the problem is in the first place.
Edit:
Thanks to @JoeHass for your answer and @MartinRosenau for your comment, I have since found this SO answer , which has a very detailed explanation of why I need this shortcut. It takes a very long time to read, but worth it.