jumping to application from bootloader

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

jumping to application from bootloader

Jump to solution
2,161 Views
niket_zope
Contributor III

hello I'm making a bootloader Getting issue of hardfault  & configuring stack pointer.

Doing :

start boot flash 0x00000000 

start appflash  0x00001000 

can any one suggest what's bad with the code ? I am new to bootloader.

typedef void (application_t) (void);

typedef struct vector
{
uint32_t stack_addr;   // intvec[0] is initial Stack Pointer
application_t *func_p; // intvec[1] is initial Program Counter
} vector_t;

extern const uint32_t app_intvect; // Application vector address symbol from
                                                       // the linker configuration file

                                                       //  value = 0x00001000 


int main(void)
{
const vector_t * vector_p = (vector_t *) &app_intvect;
// volatile uint32_t stack_arr[100] = {0}; // Allocate some stack

__enable_interrupt();

printf("Hello from bootloader!\n");
printf("MSP BEFORE: %x \n", __get_MSP());
printf("PSP BEFORE: %x \n", __get_PSP());

__disable_interrupt(); // 1. Disable interrupts

__set_SP(vector_p->stack_addr); // 2. Configure stack pointer

SCB->VTOR = (uint32_t) &app_intvect; // 3. Configure VTOR


printf("MSP AFTER: %x \n", __get_MSP());
printf("PSP AFTER: %x \n", __get_PSP());

vector_p->func_p(); // 4. Jump to application


}

 

0 Kudos
Reply
1 Solution
2,143 Views
niket_zope
Contributor III

Thanks for the link it was helpful.

I did following and was able to successfully jump to application from bootloader.

1. defined the application vector table address in the linker config file.

2. Created a vector structure containing two members 1. stackpointer 2. the location of program counter.

3. typecast the linker defined symbol to an object created from above structure.

4. disabled the interrupts.

5. configure the stack pointer value.

6. set the VTOR.

7. jump to application. 

 

sample code for help

typedef void (application_t) (void);

typedef struct vector
{
uint32_t         stack_addr;   // intvec[0] is initial Stack Pointer
application_t *func_p;         // intvec[1] is initial Program Counter
} vector_t;

extern const uint32_t app_intvect; // Application vector address symbol from
                                                       // the linker configuration file

int main(void)
{
const vector_t * vector_p = (vector_t *) &app_intvect;


__enable_interrupt();

__disable_interrupt(); // 1. Disable interrupts

__set_MSP(vector_p->stack_addr); // 2. Configure stack pointer

SCB->VTOR = (uint32_t) &app_intvect; // 3. Configure VTOR

vector_p->func_p(); // 4. Jump to application


}

View solution in original post

2 Replies
2,144 Views
niket_zope
Contributor III

Thanks for the link it was helpful.

I did following and was able to successfully jump to application from bootloader.

1. defined the application vector table address in the linker config file.

2. Created a vector structure containing two members 1. stackpointer 2. the location of program counter.

3. typecast the linker defined symbol to an object created from above structure.

4. disabled the interrupts.

5. configure the stack pointer value.

6. set the VTOR.

7. jump to application. 

 

sample code for help

typedef void (application_t) (void);

typedef struct vector
{
uint32_t         stack_addr;   // intvec[0] is initial Stack Pointer
application_t *func_p;         // intvec[1] is initial Program Counter
} vector_t;

extern const uint32_t app_intvect; // Application vector address symbol from
                                                       // the linker configuration file

int main(void)
{
const vector_t * vector_p = (vector_t *) &app_intvect;


__enable_interrupt();

__disable_interrupt(); // 1. Disable interrupts

__set_MSP(vector_p->stack_addr); // 2. Configure stack pointer

SCB->VTOR = (uint32_t) &app_intvect; // 3. Configure VTOR

vector_p->func_p(); // 4. Jump to application


}

2,160 Views
nxf56274
NXP Employee
NXP Employee

Hi,

You can refer this article.

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------