Yes you can.
There are 3 files that you will need to understand before you can be sure that you know how to solve this:
- The SAM3N4C Startup Code
- The DeviceVectors definition
- The SAM3N4C Linker Memory Region Definitions
- The SAM3N4C Linker Script
I've given you the links to the SAM3N4C chip because I'm familiar with it. The code can be made to suit your chip that you're using.
To make it work for what you are asking you will need a vector table that has a pointer to your function. You will need to place this vector table at a known address and you will use it to get your function pointer. Your function will be placed in the memory immediately following this vector table.
Brief explanation:
It seems that you're still unfamiliar with how things work on a Cortex-M3 so I'll try and explain a little.
main
is not special. It is just a function and it isn't even the first thing that executes. The first function that runs on a Cortex-M3 is your Reset Vector interrupt service routine. This function then sets up all of your memory and then calls main (see The SAM3N4C Startup Code).
On a Cortex-M3 there is a pointer to this special function at a known offset from the start of your memory (0x00000004) and that is what your hardware uses to boot/start. The Reset_Handler()
function from The SAM3N4C Startup Code is placed at that address. This is done in the DeviceVectors exception_table
struct that you can see being initialized in the code given in The SAM3N4C Startup Code. This struct contains all the function pointers and for the reset vector to be located at an offset of 0x00000004 from the start of memory, the exception_table
needs to be placed at a the very start of memory. This is done by using the __attribute__ ((section(".vectors")))
flag to place the exception_table
in the .vectors section (see The GNU attribute syntax). This is then used in The SAM3N4C Linker Script, which includes the memory region definitions given in The SAM3N4C Linker Memory Region Definitions, to place it at the very beginning of memory (using the KEEP(*(.vectors .vectors.*))
line, which is put into memory first).
I recommend investigating your existing linker scripts for how they work because they will give you a clue as to how you can do this. Reading more about the GNU linker will help you with this.
Also, the solution you are after would, in my opinion, replicate this behavior but you would use a smaller 'vector table' since you only need one function...