LPC804: Run the user code from your own bootloader

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

LPC804: Run the user code from your own bootloader

1,803件の閲覧回数
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,787件の閲覧回数
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,739件の閲覧回数
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,736件の閲覧回数
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 件の賞賛
返信