cancel
Showing results for 
Search instead for 
Did you mean: 

how can I put the boot function at the absolute address

wang mengmeng
Associate II
Posted on June 11, 2018 at 12:44

Hello everyone?

I have an issue with bootLoader development?I have debug the bootLoader successfully with SPC560P44, but I am not quite sure about how to jump to bootloader from the application program?

our conventional method is putting the boot function at  the absolute address?and we can jump to bootloader by call the function pointer?but in the SPC5Studio we don't know how to put the function at the absolute address?Can anyone know this ?Appreciate 

to receive your reply?

#bootloader
1 ACCEPTED SOLUTION

Accepted Solutions
procolo
Senior
Posted on June 13, 2018 at 12:07

Hello,

you can perform the jump in two wa using the following codes

  • void (*fptr)(void);

    uint32_t jump_address

    fptr = (void (*)(void))jump_address;

    fptr();

if application to program is compiled with spc5studio please take into consideration:

  • the address to jump is not the first address programmed (which is the boot header) but the value stored in the next 32bit location of the binary file. example
    • vuint32_t jump_address;

      jump_address_pointer = 'address where you have programmed you binary' + 4UL;

      jump_address = *((vuint32_t*)(jump_address_pointer));
  • before jump, you must switch in DRUN mode, stop peripherals used  and disable interrupts
    • if (SPCSetRunMode(SPC5_RUNMODE_DRUN) == CLOCK_FAILED) {

      SPC5_CLOCK_FAILURE_HOOK();

      }

      sysTimeWaitMilliseconds(200);

      can_lld_stop(&CAND1);  // stop peripheral used by bootloader application

      SPCSetPeripheralClockMode(SPC5_PIT_PCTL, SPC5_PIT_STOP_PCTL); //stop osal

      irqIsrDisable(); 

Regards,

Procolo

View solution in original post

16 REPLIES 16
procolo
Senior
Posted on June 13, 2018 at 12:07

Hello,

you can perform the jump in two wa using the following codes

  • void (*fptr)(void);

    uint32_t jump_address

    fptr = (void (*)(void))jump_address;

    fptr();

if application to program is compiled with spc5studio please take into consideration:

  • the address to jump is not the first address programmed (which is the boot header) but the value stored in the next 32bit location of the binary file. example
    • vuint32_t jump_address;

      jump_address_pointer = 'address where you have programmed you binary' + 4UL;

      jump_address = *((vuint32_t*)(jump_address_pointer));
  • before jump, you must switch in DRUN mode, stop peripherals used  and disable interrupts
    • if (SPCSetRunMode(SPC5_RUNMODE_DRUN) == CLOCK_FAILED) {

      SPC5_CLOCK_FAILURE_HOOK();

      }

      sysTimeWaitMilliseconds(200);

      can_lld_stop(&CAND1);  // stop peripheral used by bootloader application

      SPCSetPeripheralClockMode(SPC5_PIT_PCTL, SPC5_PIT_STOP_PCTL); //stop osal

      irqIsrDisable(); 

Regards,

Procolo

procolo
Senior
Posted on June 13, 2018 at 14:37

Hello Wang,

There should be no correlation.

SPC5_CLOCK_FAILURE_HOOK(); is called when there is a failure during  spc_clock_init(void) which is a function called before the main(). 

There are many point inside this function where the hook is called, so we have to understand which is the correct point where fail happen and which is the status of ME.GS.R register.

anyway,  if you are using PLL in your app, you should turn them off when seting DRUN mode before jump. 

ME.DRUN.R = SPC5_ME_MC_SYSCLK_IRC | SPC5_ME_MC_IRCON | \

SPC5_ME_MC_XOSC0ON | SPC5_ME_MC_CFLAON_NORMAL | \

SPC5_ME_MC_DFLAON_NORMAL | SPC5_ME_MC_MVRON;

if (SPCSetRunMode(SPC5_RUNMODE_DRUN) == CLOCK_FAILED) {

SPC5_CLOCK_FAILURE_HOOK();

}

Ragards,

Procolo

Posted on June 13, 2018 at 12:46

Hello Procolo?

 Thank you for your reply?I have jumped successfully from bootloader to application program?and it was run well?but I have problems jumping form APP to bootloader which has a function located at 0xb800?I used the same jumping function. and I could find it already jumped to the address 0xb800 through the PC pointer?however it seems failed at the initialization func ?and the PC pointer stop at 0x00000c14 which was put the vectors seen from the map doc.

SPC5_CLOCK_FAILURE_HOOK();

and I found  it was really curious that if I close everything in APP ,only the jump func left , it  could jump successfully. Is there any connections between the PC pointer  address which the  jump func located and the aim bootloader func address which I need to jump to?Do I describe clearly?I need your help?thank you so much again?

linker file

0690X0000060LFEQA2.png0690X0000060LFJQA2.png

destination

0690X0000060LFOQA2.png

the jump code

0690X0000060LFTQA2.png
procolo
Senior
Posted on June 13, 2018 at 16:30

Hello,

before jumping, could  you please try to disable interrupts after stopping the peripherals?

actually , some stop functions re enable when exit , so if you disable interrupt before stopping peripherals they may be re enabled when jumping.

Redards,

Procolo

Posted on June 13, 2018 at 15:36

Hello 

Procolo:

      I have copied your code when I jump,but it did‘t work, I disabled all the peripheral and find that the if the  adc_lld_stop_conversion(&ADCD1); was disabled ,then it worked。But if I tired more ,I found it did not run successfully everytime, I traced the PC in CPU window ,found that the PC was sometimes in IVOR6 or sometimes in IVOR1,what should I do to find the problem?many thanksï¼�

Posted on June 14, 2018 at 04:43

Hello 

Procolo?

      I think I have disabled the interrupts after 

stopping peripherals?but it still entered the IVOR6,  I can?t find where the problem is?here are my application code and the bootloader code? I copy the code from your answers?and is I don't init any

peripherals

 in app? it can jump successfully? it is so weird. There are only peripherals of  can and timer.

0690X0000060LF9QAM.png0690X0000060LC1QAM.png0690X0000060LFsQAM.png
procolo
Senior
Posted on June 14, 2018 at 08:11

Hello,

my idea is that there is some peripheral which is not correctly stopping and lead to an error when jumping.

we should understand which one is. could you try to enable one peripheral at a time and check when it does not work?

also, please try to set DRUN mode as last operation before jumping:

  • stop peripherals
  • irq disable
  • DRUN

Regards,

procolo
Senior
Posted on June 14, 2018 at 10:07

Hello,

let's investigate. I need the following infomation, could you please provide them?:

  • Version of SPC5studio using (Help-->About SPC5studio)
  • instruction causing ivor6 exception (I think after the jump but don't know exactly where)
  • CAN configuration before and after the jump (if used). you can send me can_lld_cfg.c files of both programs
  • if you do not stop can peripheral, do you have the same issue?

Thanks and best regards,

Procolo

Posted on June 14, 2018 at 09:16

Hello procolo:

      Thank you for your tips. I have changed my code as your proposal,Then I initialized my peripheral one by one , and  found it maybe the CAN does the effect, if there is only initialization and TX message, it is OK to jump, but if there are message for rx, the program enters IVOR6 even if I have stopped the CAN module.Do you  have any opinion to solve this?