Products > Programming

GCC ARM32 32F417 how to call or jump to a specific address?

(1/9) > >>

peter-h:
Of course, the "answers" are all over the internet, but none of them compile, or (if they compile) none work.

I have what is basically an overlay at FLASH base+32k ie.. 0x08008000 and need to jump to that address.

The address is actually a symbol from the linkfile called FLASH_APP.

I see examples like

   ldr  r3, =JMPADDR
   bx   r3

and have been trying various forms of stuff like asm volatile("bx %0" : : "r" (0x08008000)); but nothing works. I spent decades coding in asm so this should be simple :)

I am using GCC v10. Many thanks for any tips.

emece67:
The LSB of the register must be set to 1 in order to remain in Thumb mode (the only mode supported by such core), otherwise an UsageFault exception will be raised, so just use `asm volatile("bx %0" : : "r" (0x08008000 + 1));`

peter-h:
That doesn't appear to go to a fixed absolute address:

emece67:
I bet it does. The LDR = is a pseudo-instruction that can get the value from a data-pool using a PC relative memory access instruction (which seems to be your case) or can be assembled to some combination of other instructions that, when executed, end with your desired value into your desired register. What are the contents of R3 after executing such LDR R3, [PC, #80]? The comment partially seen after it seems to indicate that the value to be loaded is some 0x8000...

The disassembled code loads into R3 the value pointed by PC+80 (supposedly 0x80008001), not the value of PC+80. There is no instruction in the Cortex-M instruction set allowing the load of a 32 bit number into a register, so the compiler/assembler uses this kind of tricks.

SiliconWizard:
If you're using GCC, you can also use computed gotos: http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
Of course, this is not standard C, and if the pointer points to an absolute address rather than "the address of a label", the behavior *may* be undefined. Not sure.
But it's just a "fun" feature to know, and it seems to "work":

https://godbolt.org/z/bfdMMaczv

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version