Author Topic: Jump to Serial Loader from Within Application code  (Read 3378 times)

Offline Al

  • Newbie
  • *
  • Posts: 12
    • View Profile
Jump to Serial Loader from Within Application code
« on: January 19, 2021, 12:31:21 AM »
What is the best way to do this?  I am using the MSD device serial loader.

Basically, I need to start the serial loader from a PC application that is sending a command over serial.  I want that command to execute the jump to the serial loader.  Everything works fine using a switch held during power up but I am looking for a programatic way to invoke the serial loader.


Thanks
Al

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Jump to Serial Loader from Within Application code
« Reply #1 on: January 19, 2021, 12:55:00 AM »
Al

The mailbox technique is explained in appendix C of https://www.utasker.com/docs/uTasker/uTaskerSerialLoader.pdf

*BOOT_MAIL_BOX = RESET_TO_SERIAL_LOADER;
fnResetBoard();


does it (more details in the document, together with how to ensure your application leaves space for persistent mailbox memory).

Regards

Mark

Offline Al

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Jump to Serial Loader from Within Application code
« Reply #2 on: January 19, 2021, 02:52:19 AM »
Thanks... I will look into this  tomorrow.

However, isn't there an easier way to just jump to the serial loader start address from my C/C++ code? I've tried using function pointers, inline ASM. etc. to jump to 0x0000 but none of them work.  Is 0x0000 not the place to jump to?

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Jump to Serial Loader from Within Application code
« Reply #3 on: January 19, 2021, 03:13:41 AM »
Al

The mailbox technique is the best method in my opinion since it passes through a software rest which ensures all peripherals are in their default state.

If you wanted to jump to the serial loader directly 0x0 is incorrect because ARM programs never start at 0x0. 0x00000000 is the location of the reset vector and to jump you need to use assembler code as follows:

extern void start_application(unsigned long app_link_location)
{
    asm(" ldr sp, [r0,#0]");                                             // load the stack pointer value from the program's reset vector
    asm(" ldr pc, [r0,#4]");                                             // load the program counter value from the program's reset vector to cause operation to continue from there
}


and call it with

start_application(0);


Regards

Mark
 

Offline Al

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Jump to Serial Loader from Within Application code
« Reply #4 on: January 19, 2021, 03:58:42 AM »
Hi Mark

That does cause a jump but to the application not the serial loader. 

I defined the start_application function as you said:

Code: [Select]
//===============================================
extern void start_application(unsigned long app_link_location)
//===============================================
{
    asm(" ldr sp, [r0,#0]");  // load the stack pointer value from the program's reset vector
    asm(" ldr pc, [r0,#4]");  // load the program counter value from the program's reset vector to cause operation to continue from there
}

I have the following code in the startup of the application:

Code: [Select]
// TEST ------------------------------
prtStrD("Delaying 4 seconds then jumping to serial loader...");
for (int ii=0; ii<4; ii++)
{
delay(1000); 
Serial.println(ii);
}
start_application(0);
// TEST ------------------------------

I loaded the application using the serial loader which was previously loaded directly.  The serial loader loads the code and starts it but the above startup code simply executes over and over again.  What am I missing?

Thanks
Al

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Jump to Serial Loader from Within Application code
« Reply #5 on: January 19, 2021, 06:55:33 AM »
Al

I expect the problem is the fact that jumping to the serial loader just causes the serial loader to start the application if there is nothing telling it that it should stay in the loader mode.
If you set the force loader input and jump it will probably run the serial loader.

This is the reason for the mail box - it informs the serial loader that it should stay in that mode and not just start the application again.

Regards

Mark

Offline Al

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Jump to Serial Loader from Within Application code
« Reply #6 on: January 19, 2021, 07:06:22 AM »
I will look at the mailbox approach but another question...

Would you elaborate on what you mean by "set the force loader input" in the following, please?
Quote
If you set the force loader input and jump it will probably run the serial loader.

Thanks
Al

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Jump to Serial Loader from Within Application code
« Reply #7 on: January 19, 2021, 01:42:13 PM »
Al

I mean the switch that you have already referred to:

Quote
Everything works fine using a switch held during power up

This is the input that "forces" the serial loader to do its job rather than immediately starting a loaded application.

Regards

Mark

Offline Al

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Jump to Serial Loader from Within Application code
« Reply #8 on: January 19, 2021, 03:40:43 PM »
I thought you were saying to somehow use that pin to "programmatically" tell the serial loader to go into load mode so the jump works.

Thanks for the information on this.