jumping to application from bootloader

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

jumping to application from bootloader

跳至解决方案
1,717 次查看
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 项奖励
回复
1 解答
1,699 次查看
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 回复数
1,700 次查看
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


}

1,716 次查看
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.
-------------------------------------------------------------------------------