Bootloader implementation on SAM3S4C

Discussion around product based on ARM Cortex M3 core.

Moderators: nferre, ncollot

ramonf
Posts: 12
Joined: Mon Aug 08, 2011 5:59 pm

Bootloader implementation on SAM3S4C

Mon Feb 20, 2012 4:02 pm

Hey, I'm working on a project on a SAM3S4C, and I started to create a seperate bootloader for it.
The bootloader is a seperate project in IAR.
I'm sucessfully flushing the application code into the internal flash, however, when I try to jump to the application from the bootloader, using the Vector interrupt table re-allocation, the code just won't start.

The bootloader is placed at 0x00400000 - 0x00401FFF
and it's vector table is at 0x00400000.
The application is located at 0x00402000 - 0x0043FFFF
and it's vector table is at 0x00402000

This is the code for jumping to the application from the bootloader is:

Code: Select all

int * address = ( int * ) 0x00402004; //pointer to reset handler of application
__set_MSP ( * ( int * ) 0x00402000 ); //set the stack pointer to that of the application

* ( int * ) 0xE000ED08 = 0x00402000; // VTOR: set the vector table to that of the app

( ( void ( * ) () ) ( *address ) ) (); // pointer recast as function pointer and the dereferenced/called

    while ( 1 )
        { }; //you application was never executed
can anyone help me with this ?
incognito
Posts: 32
Joined: Tue Jul 13, 2010 12:54 pm

Re: Bootloader implementation on SAM3S4C

Mon Feb 20, 2012 5:21 pm

Remember to do the following

address = address | 0x01;

The cortex-m3 executes thumb-2 instructions, thus, when you do a jump to a new application, the address given to the function pointer should have LSB as 1 to indicate that it is jumping to a thumb2 instruction.
CptTitanic
Posts: 871
Joined: Sat Oct 30, 2010 6:04 pm

Re: Bootloader implementation on SAM3S4C

Mon Feb 20, 2012 8:50 pm

I would expect the address in the vector table to already have the low order bit set. Perhaps you should print it out, and confirm that it, and the stack pointer has a reasonable address.

What is the impact of changing the stack pointer on local/automatic variables?

I personally would do this in assembler.

Now, presumably you have a debugger, why can't you step through the code, and the transition to the application code? Doing so would provide some clarity about what's going on, and why it might be failing.

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: No registered users and 2 guests