Help Needed, LPC1850 bootloader fails jump to application with around 50% probability

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

Help Needed, LPC1850 bootloader fails jump to application with around 50% probability

481 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by hitpony on Thu Nov 06 06:50:12 MST 2014
I am using a LPC1850, with NORFLASH at 0x1C000000, and SDRAM at 0x28000000, Bootloader is saved in NORFLASH 0x1C000000, and application saved at 0x1C008000. after poweron, bootloader will copy (via memcpy) the application from 0x1C008000 to 0x28000000, and bootloader will jump to the application with following functions, but I can only jump to the application with 50% successful rate.

In the bootloader, A check is put after the memcpy, the copy is always successful, this proves the NORFLASH and SDRAM should be OK, I guess the failure always happend after  boot_jump(addr); and before main() fuction of the Application.

I have tried to add a watchdog in the bootloader, but when the application failed to be lauched, the system can NOT be reset, and need to press the reset button to restart the system.

The bootloader is via KEIL v4.54, and the application is done via IAR v6.60, and at the start of applicaion, IRQ is enabled.

Can anyone provide a help to see, why the application can only be launched with around 50% probability? and what is the possible reason the watchdog can not reset the system when jump fails.

================== APPLICATION ====================
int main (void)
{
    __enable_irq();

    .....

}

================== BOOTLOADER ====================
int main (void)
{
    ...
    //copy
    memcpy((char *)0x28000000, (uint8_t *)0x1c008000, length);

    //check, and err alwasy is 0
    for(cnt = 0; cnt < (length>>2); cnt++)
    {
         if( (*(((uint32_t *)0x28000000)+cnt)) != (*(((uint32_t *)0x1c008000)+cnt)) )
         {
              err++;
         }
    }

    //jump to application
    ExecuteUserCode(0x28000000);
    ....
}

__asm void boot_jump( uint32_t address )
{
    LDR SP, [R0];Load new stack pointer address
    LDR PC, [R0, #4]        ;Load new program counter address
}

void ExecuteUserCode(uint32_t addr)
{
    __disable_irq();
    SysTick->CTRL = 0;
    SCB->VTOR = addr & 0xFFFFFF80;
    boot_jump(addr);
}
Labels (1)
0 Kudos
4 Replies

389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by hitpony on Sun Nov 09 09:41:18 MST 2014
Problem solved via of following method:
1. In IAR for uCOS III, the initial LPC1850 Clock setup are in "BSP_LowLevelInit" in cstartup.s, via assemble

...
        MODULE  ?cstartup

        ;; Forward declaration of sections.
        SECTION CSTACK:DATA:NOROOT(3)

        SECTION .intvec:CODE:NOROOT(2)

        EXTERN  __iar_program_start
        EXTERN  OS_CPU_PendSVHandler
        EXTERN  OS_CPU_SysTickHandler
        EXTERN  BSP_LowLevelInit
...
...
        THUMB

        PUBWEAK Reset_Handler
        SECTION .text:CODE:REORDER(2)
Reset_Handler
        BL      BSP_LowLevelInit
        LDR     R0, =__iar_program_start
        BX      R0

        PUBWEAK App_NMI_ISR
...

I have to say the uCOS-III system hides these lower level clock setup, and not easy to find, in the function of "BSP_LowLevelInit()" in bsp.c file, I remove the clock setup, and rely on the clock setup in bootloader, the issue solved. now the system could always jump to application.

I could made a summary from this board for the issue:

=== Issues ===:
Bootloader could copy the applicaiton to the target address, but can not jump to the application with 100% of the successful rate.

== Possible reasons ===:
1. Before the jump, interrupt should be disabled via __disable_irq(); and in the beginning of the application, __enable_irq() again.

2. Make sure the SCB->VTOR points to the beginning of the target application address.

3. Make sure the Clock setup are consistant between bootloader and applicaion, espcially for uCOS III OS, the Clock setup are in cstartup.s, and needs to check carefully.

Thanks this board for variouse information I got, and finally solved the issue.

(Other possible reasons are welcome to be added)

Regards
Hitpony
0 Kudos

389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by hitpony on Thu Nov 06 10:05:01 MST 2014
I have tried the proposal, but issue still exist. Sometimes it works, but sometimes still fails, here are the modifications I made, note the application is done with IAR:

Does anyone have more ideas? is it possible a hardware issue, or clock issue? I could not understand why it fails only part of the times.

Thanks in advance!

===== APPLICATION =====
int main (void)
{
SCB->VTOR = ((uint32_t)(&(__vector_table)))
; //added
__enable_irq();

.....

}

===== BOOTLOADER =====
__asm void boot_jump( uint32_t address )
{
MOV LR, #0xFFFFFFFF ;Reset Link Register
LDR SP, [R0] ;Load new stack pointer address
LDR PC, [R0, #4] ;Load new program counter address
}

void ExecuteUserCode(uint32_t addr)
{
__disable_irq();
SysTick->CTRL = 0;
//SCB->VTOR = addr & 0xFFFFFF80; // remove?
boot_jump(addr);
}
0 Kudos

389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by hitpony on Thu Nov 06 09:30:35 MST 2014
Thanks John for your ideas, I try to understand your suggestions, the modification you proposed are as below:

I am using uCOS III as OS in application with IAR ... the startup asm is cstartup.s, where __vector_table is defined.

Do I understand correctly? I willl try this as soon as possible.

===== APPLICATION =====
int main (void)
{
    SCB->VTOR = (uint32_t) __vector_table;   //added
   __enable_irq();

    .....

}


===== BOOTLOADER =====
__asm void boot_jump( uint32_t address )
{
    MOV LR, #0xFFFFFFFF ;Reset Link Register
    LDR SP, [R0];Load new stack pointer address
    LDR PC, [R0, #4]        ;Load new program counter address
}

void ExecuteUserCode(uint32_t addr)
{
    __disable_irq();
    SysTick->CTRL = 0;
    //SCB->VTOR = addr & 0xFFFFFF80;  // remove?
    boot_jump(addr);
}
0 Kudos

389 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by John Sinclair on Thu Nov 06 07:15:21 MST 2014
Hi,

do you have Interrupts? When yes so you have remapped your Vector Table?
Look at:
http://www.lpcware.com/content/forum/lpc1788-freertos-or-rtx-bootlader-ethernet

John
0 Kudos