• AVR Freaks

Helpful ReplyHot!Application communicating with Bootloader

Author
ViniciusL
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2019/07/29 00:21:43
  • Location: 0
  • Status: offline
2019/08/19 00:19:34 (permalink)
0

Application communicating with Bootloader

Hello for everyone,
 
I created a customized bootloader project to make the firmware upgrade and it is working good. My application have a PC communication interface and I need to add a command to start the FW update. To make it works I need to enable a flag, reset my application and run the bootloader again. My 2 questions are: 
  • What should I attempt before reset to bootloader?
  • How would be the easiest way to share a flag btween the bootloader and application ?
 
 
 
#1
NKurzman
A Guy on the Net
  • Total Posts : 17719
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: Application communicating with Bootloader 2019/08/19 04:10:40 (permalink) ☄ Helpfulby ViniciusL 2019/08/23 00:59:05
0
Eeprom is easy if you have it. Flash is harder.
Another way is to check RCON flags. This will allow to see that a software reset happen. Assuming you do not need to use The software reset for anything else.
Or you can save a pattern of bytes into persistent ram as the communication. The persistent ram must be the same between the boot loader and main application
#2
maxruben
Super Member
  • Total Posts : 3354
  • Reward points : 0
  • Joined: 2011/02/22 03:35:11
  • Location: Sweden
  • Status: offline
Re: Application communicating with Bootloader 2019/08/19 05:38:37 (permalink) ☄ Helpfulby ViniciusL 2019/08/23 00:59:02
0
I have successfully used some of the SFR registers not used by the application for just this. This was for a PIC24FJ64GA004 but it could be working for PIC32 also. Depends what happens with the SFRs at reset.
 
When the main application receives a command to start a firmware upgrade it writes specific values to TMR1 and PR1 and does a soft reset. The bootloader always starts up after a reset so it checks in RCON if this is a software reset and that the specific values in TMR1 and PR1 is there. If so, the bootloader never jumps to the application but instead waits for the firmware download to start (triggered by the firmware download software). If TMR1 and PR1 is not the special values, the bootloader just waits the normal timeout before jumping to the application.
 
/Ruben
#3
ViniciusL
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2019/07/29 00:21:43
  • Location: 0
  • Status: offline
Re: Application communicating with Bootloader 2019/08/23 01:09:49 (permalink)
0
I found a very easy way to solve my problem and I would like to know your opinion about iy. I created a variable allocated at an specif address of RAM using this Code att my application and bootloader:
 
volatile int fwupdateFlag __attribute__((address(0xA000A200), persistent));
 
When I need to start a FW update, I write an specific value in this variable and reset my application with this function:
 
void reset_to_bootloader(void)
{
   void (*fptr)(void);
   fptr = (void (*)(void))BOOTLOADER_RESET_ADDRESS;

   while(1)
   {
      // disable interrupts
      PLIB_INT_Disable(INT_ID_0);
      fptr();
   }
}
 
 

Maybe this can be useful for someone.
 
#4
Jump to:
© 2019 APG vNext Commercial Version 4.5