Jump from bootloader to actual firmware

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

Jump from bootloader to actual firmware

6,524 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DennisFrie on Wed Sep 24 15:37:41 MST 2014
Hi guys
I'm using a secondary bootloader on my LPC1549, but keep getting a hardfault error, when calling the main firmware.

The bootloader is placed in flash address 0x00 and the main firmware is loaded to 0x2000.

Atm. I'm testing with a very basic sketch, where the "bootloader" just calls the main-firmware.

This is what I'm doing atm:

// Start by disabling interrupts, before changing interrupt vectors
__disable_irq();

// Set vector table offset
SCB->VTOR = 0x2000; // Note, can be anded with max allowed address, 0x3FFFFF80

// Create pointer to new program address
void (*code_ptr)(void) = (void (*)(void))0x2000;

// Call firmware at address 0x2000 (from pointer above)
code_ptr();



Looking at application note AN10866 for LPC17xx, the program counter and stack pointer is changed, but I'm not sure if the vector table offset is enough on LPC15xx.
Trying to change the stack using the code below, my LPC dev. board crashses completely

asm volatile("ldr r0, =0x2000"); // Point to top stack
asm volatile("ldr r0, [r0]");
asm volatile("mov sp, r0");

asm volatile("ldr r0, =0x2004"); // Point to Reset handler
asm volatile("ldr r0, [r0]");
asm volatile("mov pc, r0");


I've tried
__set_MSP(*(__IO uint32_t*)0x2000); and call 0x2004 instead, but same result


Any good hints as to what I'm missing here?

When compiling the primary firmware, the compiler is set to use start from address 0x2000.

Without the updated vector table, I keep getting a hardfault-error (0x13C). With the updated vector table it ends at 0x213C (same hardfault vector, just with the offset).
Labels (1)
0 Kudos
39 Replies

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rama krishna deekshitulu on Mon Feb 15 23:12:46 MST 2016
thank you for suggesting...
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rama krishna deekshitulu on Mon Feb 15 23:11:51 MST 2016
thank you for suggesting...
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Mon Feb 15 06:36:35 MST 2016

Quote: rama krishna deekshitulu
I'm new in this forum. I'm working with a LPC1225/ microcontroller. I've encountered this problem...



:quest:

This is the LPC15xx (which is a M3) forum...

Could be useful to post your problem in LPC12xx forum (which is a M0)  ;-)

Your problem is related to the vector table, which can't be switched to another Flash addresses in M0  :((

See:

https://www.lpcware.com/content/forum/secondary-bootloader-on-cortex-m0
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rama krishna deekshitulu on Mon Feb 15 06:10:43 MST 2016
Hi LabRat,

I'm new in this forum. I'm working with a LPC1225/ microcontroller. I've encountered this problem:

When I'm trying to execute the IAP application for system tick timer the code is stuck at delay function. if i'm not use delay function its working fine.that means second boot loader application is working well.. please check below code and help me please.
/*****************boot loader application********************/
/****************************************  SysTick_Handler  ************************************/

void SysTick_Handler(void)
{
msTicks++;
}

void delay_ms(unsigned int k)
{
    msTicks=0;
while(msTicks<k);

}

int main(void)
{SysTick_Config(SystemCoreClock / 1000); /* generates 1ms time delay*/
UARTInit(0,9600);
printf("EEPROM-32Kb\r\n");
delay_ms(10);
printf("boot loading done\r\n");
}

/********************bootloader*****************************/
SystemCoreClockUpdate();
SysTick_Config(SystemCoreClock / 1000); /* generates 1ms time delay*/
__disable_irq();
    UART0Init(9600);
printf("abcd");
    asm volatile("ldr r0, =0X3000");
asm volatile("ldr r0, [r0]");
asm volatile("mov sp, r0");
/* Load program counter with application reset vector address, located at
   second word of application area. */ //reset

asm volatile("ldr r0, =0X3004");
asm volatile("ldr r0, [r0]");
asm volatile("mov pc, r0");
while(1);
}
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gintaras Drukteinis on Wed Aug 26 03:08:09 MST 2015

Hi, there is application note for cortex-M0:
https://www.lpcware.com/content/nxpfile/an10995-lpc1100-secondary-bootloader-software-v13
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gintaras Drukteinis on Wed Aug 26 02:59:41 MST 2015
Hello,

This topic was helpful for me, I wrote the function that works with LPC11U68:

void execute_code(unsigned addr)
{
void (*user_code_entry)(void);
uint32_t *p;

__disable_irq();// Start by disabling interrupts, before changing interrupt vectors
Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_IRC); //switch to IRC


/* Set vector table offset*/
SCB->VTOR = addr;

p = (uint32_t *)addr;

/*Set stack pointer to given address*/
  __set_MSP(*p);

/*Set address for RESET*/
p++;
user_code_entry = (void (*)(void))(*p);

/*Jump to application*/
user_code_entry();

}


Regards!
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by abthegreat on Thu Aug 13 04:04:37 MST 2015
I would like to achieve the same thing while using an LPC122x , The M0 does not allow for the vector table to be relocated as in this example. Any ideas how i can modify this code to fit my need.

TIA
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DennisFrie on Fri Sep 26 05:16:18 MST 2014

Quote: LabRat
Not sure which clock setup you use in your bootloader, but it's useful to switch back to IRC:

__disable_irq();
[color=#f00] Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_IRC); //switch to IRC[/color]
// Set vector table offset 
...



- You are amazing, that fixed the problem. Everything seems to be working as expected now.

Your help here have been much appreciated - huge help!

Now where do you want me to send that beer :bigsmile:
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Thu Sep 25 16:11:45 MST 2014
Not sure which clock setup you use in your bootloader, but it's useful to switch back to IRC:

__disable_irq();
[color=#f00] Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_IRC); //switch to IRC[/color]
// Set vector table offset 
...
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DennisFrie on Thu Sep 25 14:04:44 MST 2014
Using the USB-bootloader to delete the flash and loading a working sketch, the SWD works again. That's what I've done so far.
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Thu Sep 25 13:57:37 MST 2014

Quote: DennisFrie
I'm using the LPCxpresso 1549 board for testing with attached JTAG debugger - doubt another debugger will make a difference?.



You are using LPCxpresso 1549 board with SWD...

If that fails, reset everything, close LPCXpresso and try it again...  

After that you have to switch to ISP (UART / USB  or CAN) .

http://www.lpcware.com/content/faq/lpcxpresso/regaining-debug-access

In ISP mode, debugger should work again...
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DennisFrie on Thu Sep 25 13:45:29 MST 2014
I'm using the LPCxpresso 1549 board for testing with attached JTAG debugger - doubt another debugger will make a difference?.
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Thu Sep 25 13:34:47 MST 2014

Quote: DennisFrie
Unfortunately no luck. As soon as the couple of lines in the bootloader/jumper have been executed, I'm not even able to connect the board or upload new firmware..



Switch to ISP and try it again...
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DennisFrie on Thu Sep 25 13:30:32 MST 2014
Unfortunately no luck. As soon as the couple of lines in the bootloader/jumper have been executed, I'm not even able to connect the board or upload new firmware..
[img]https://dl.dropboxusercontent.com/u/3947315/bootloaderDebug/NoLuck.png[/img]

[img]https://dl.dropboxusercontent.com/u/3947315/bootloaderDebug/NoLuck2.png[/img]
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DennisFrie on Thu Sep 25 13:20:50 MST 2014
I tried to set the LED on at the beginning of the blinky-code (to avoid any interrupt problems), but that didn't seem to work either.

I will just test with your 2 modifications.

I really appreciate your patience, I owe you a beer for all the help  ;-)
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Thu Sep 25 13:06:21 MST 2014
I had to change several things (because of my hardware / board), then blinky was working here...

There are 2 important changes:

1. Comment out WFI, so you can debug blinky (with 'Attach only')...

while (1) {
[color=#f00]//__WFI();[/color]
}


2. Enable interrupt again:
int main(void)
{
 uint32_t sysTickRate;
[color=#f00] __enable_irq();[/color]
 SystemCoreClockUpdate();
...


Now debugging with debug informations should be possible again...

0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DennisFrie on Thu Sep 25 12:45:19 MST 2014

Quote: LabRat

Quote: DennisFrie
Seems to give the exact same result.It ends here again, seems to be the same address (but one off)



If I read your board library correct, there's a LED at PIO0.3 (LED1).

What you are seeing is the loop waiting for an interrupt.

If you run the application there should be a LED toggling with 7.5 Hz...

Can you see something like that?



I'm using the exact LPCopen example for now, as I want to change as little as possible until I've found the problem.

I use the LPCXpresso board and only toggle the green LED on PIO0_3. Unfortunately nothing happens.

If I upload your code/periph_blink directly to 0x0000 the green led flashes just fine
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Thu Sep 25 12:35:46 MST 2014

Quote: DennisFrie
Seems to give the exact same result.It ends here again, seems to be the same address (but one off)



If I read your board library correct, there's a LED at PIO0.3 (LED1).

What you are seeing is the loop waiting for an interrupt.

If you run the application there should be a LED toggling with 7.5 Hz...

Can you see something like that?
0 Kudos

3,915 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DennisFrie on Thu Sep 25 12:26:22 MST 2014

Quote: LabRat
Could you try this blinky (in sector 2)  ?



Seems to give the exact same result. Can I ask what you have changed, if anything?
It ends here again, seems to be the same address (but one off)
[img]https://dl.dropboxusercontent.com/u/3947315/bootloaderDebug/endsHereAgain.png[/img]

It's uploaded here:
[img]https://dl.dropboxusercontent.com/u/3947315/bootloaderDebug/UploadedHere.png[/img]

Can be seen in sector 2
[img]https://dl.dropboxusercontent.com/u/3947315/bootloaderDebug/CanBeSeenInSector2.png[/img]
0 Kudos

3,916 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Thu Sep 25 12:03:22 MST 2014
Could you try this blinky (in sector 2)  ?
0 Kudos