Jump to content

Recommended Posts


I need certain functions (which writes to LCD) to be accessible from the bootloader as well as my main application.


Can I put these function at fixed address in my bootloader? And call them in the main code as well?

If the above approach is correct how do I declare the same function in my main code?


Is there any other better approach?


Thank you



Link to post
Share on other sites
  • 2 weeks later...



You can call a function at a known address simply by using a function pointer.


You might want to take a look at pages 72 and 73 of the "Boost C manual"





Best regards


Edited by JorgeF
Link to post
Share on other sites
  • 8 months later...

Thanks Jorge,


But still I'm not able to get it working.


Here is an example of what I'm trying to achieve. I want to call a function in my Main code which is declared in my bootloader at an specific address.


in my BOOTLOADER the function is mapped to address 0x070


void Message(char *str) @0x070
		while(!txsta1.TRMT); // Wait till Tx Reg is free
		txreg1 = *str;       // Load the data into the TxReg
	  }while(*str != '\0');      // Loop till end of String

In my MAIN application I use function pointer

void (*foo)(char*);

void main()
       if(recByte == 'T')
         foo = 0x70;  // address of the function
         foo("Test Message");
         recByte = ' ';


Everything compiles ok but I get a warning


Warning: function never returns: '__fptr'


Then I tried


foo = ((*)(char*))0x070;
foo("Test Message");
Still I get error.
Then I tried using typedef
typedef void (*FnPtr)(char*);
FnPtr foo;

foo = (FnPtr)0x70;


Still I get same warning.




But if I move the function void Message(char *str) @0x070

to main application, and use

foo = Message;


the code works.



I'm I doing something really stupid or is there anyother way to point to an address of a function?


Many Thanks


Edited by John S
Link to post
Share on other sites

I's tricky to call a function that is not linked to an application. The way to proceed is to use built in assembler like 'call 0x70'. The only issue with this approach is that it's impossible to use call arguments so the solution is to declare a fixed address array to pass data to your bootloader function.




Link to post
Share on other sites

...But what is the difference between CALL and GOTO ?...


No difference. GOTO is ok as well. My point was to use built-in assembler rather than C but whatever you use CALL or GOTO doesn't matter.




Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...