LPC804: Run the user code from your own bootloader

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

LPC804: Run the user code from your own bootloader

1,813 次查看
masterboy
Contributor III

Hi everyone,

I have a project based on LPC804 in MCUxpresso, which consists of two parts. The first is the bootloader and the second is the user code. The bootloader is used to upload data and user code. The user code is at the address on flash memory 0x500, which I run with the following code:

// Load new stack pointer address
asm volatile ("ldr r0, = 0x500");
asm volatile ("ldr r0, [r0]");
asm volatile ("mov sp, r0");
// Load new program counter address
asm volatile ("ldr r0, = 0x504");
asm volatile ("ldr r0, [r0]");
asm volatile ("mov pc, r0");

I want to ask, is that right?

I need to move the interrupt vector table in the user code. I'm moving it to RAM using this code:


uint32_t * src, * dst;
int32_t size;
__disable_irq ();
// copy vector table
src=(uint32_t *) VTOR_OFFSET; // 0x500
dst = (uint32_t *) 0x10000000;
size = 192;
while (size> 0) {
* dst ++ = * src ++;
size - = 4;
}
LPC_SYSCON-> SYSMEMREMAP = 0x1; // Remap to internal RAM
__enable_irq ();

Is it right? Is it possible to move this table elsewhere on the flash memory within the user code? Thank you.

标签 (1)
0 项奖励
回复
3 回复数

1,797 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello,

There is a jump function from bootloader to application code, you can refer to:

//-----------------------------------------------------------------------------
// FUNCTION: JumpToUserApplication
// SCOPE: Bootloader application system function
// DESCRIPTION: The function startup user application
//
// PARAMETERS: pointer on user vector table
//
// RETURNS: function never go back
//-----------------------------------------------------------------------------

void JumpToUserApplication(LWord userSP, LWord userStartup)
{

// set up stack pointer
__asm("msr msp, r0");
__asm("msr psp, r0");

// Jump to PC (r1)
__asm("mov pc, r1");
}

Before jump, you'd better disable interrupt, and call this jump function like below:

// relocate vector table
SCB_VTOR = RELOCATED_VECTORS;
AppIDC = 0;
// Jump to user application
JumpToUserApplication(*((unsigned long*)RELOCATED_VECTORS), *((unsigned long*)(RELOCATED_VECTORS+4)));
return 0;

About Copy Flash to RAM, I think you need copy before mian of application project, you can  refer to the file startup_lpc804.c of SDK demos.

 

BR

Alice

0 项奖励
回复

1,749 次查看
rahulshah
Contributor I

Hi @Alice_Yang,

As you have mentioned "JumpToUserApplication" function, so where can i find this code?

Because i have downloaded LPC804 SBL examples from following link:

https://www.nxp.com/docs/en/application-note-software/AN12378SW.zip

In that only "bootValidApp" function available to jump to application from bootloader and it is also in assembly.

Can you give me C code example for jump to application. Also in above link SBL project is based on keil. Can you give me SBL project which is based on  MCUExpresso.

 

Regards,

Rahul Shah

0 项奖励
回复

1,746 次查看
converse
Senior Contributor V

The code for JumpToUserApplication is in the post from Alice. It is in C, but uses inline assembler as this is the only way to provide the required call sequence.

0 项奖励
回复