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

Function pointer using absolute address in Keil MDK

Hi,

I try to call a function by function pointer with absolute address, but not working. I am using Keil MDK v5.21, the function will be placed in particular memory by using the scatter file and compiler keyword such as __attribute__((section("name"))).

For Example, the function OrangeLed(void); will be placed in 0x08000400 and rest of the code will placed from 0x08000000 to 0x08000100. Now i am calling the OrangeLed() from main as shown below,

Trial1

typedef  void (*pFunction1)(void);
pFunction1 Jump_To_Led;
uint32_t JumpAddress;
void main(){
JumpAddress = *(volatile uint32_t*)0x08000400;/*Absolute address of OrangeLed()*/
Jump_To_Led= (pFunction1) JumpAddress;
Jump_To_Led();/*calling the OrangeLed()*/
while(1){
 blinkRedLed();
 }
}

Trial2 by referring
http://www.keil.com/support/docs/3240.htm

typedef  void (*pFunction1)(void);
typedef  void (*pFunType)(void);
void main(){
pFunType pFunction1 = (pFunType)0x08000400;/*Absolute address of OrangeLed()*/
(*pFunction1)();/*calling the OrangeLed()*/
while(1){
 blinkRedLed();
 }
}


Other detail:
C Compiler: Armcc.exe V5.06
Linker/Locator: ArmLink.exe V5.06
Target: STM32F072RB

In, both of the trials, it's not working. Can anybody help how to do this.

Vairamani.

Parents
  • "the function is stored in 0x08000401."

    No - the function is still stored at an even address.
    All functions are stored at even addresses.
    Since the processor knows that all functions are stored at even addresses, it can use the least significant bit as a flag to inform if the _even_ target address contains thumb code or not.

Reply
  • "the function is stored in 0x08000401."

    No - the function is still stored at an even address.
    All functions are stored at even addresses.
    Since the processor knows that all functions are stored at even addresses, it can use the least significant bit as a flag to inform if the _even_ target address contains thumb code or not.

Children
No data