OTA Upgrade PIC24

OTA Upgrade PIC24

Postby HallMark » Thu Jul 24, 2014 5:56 am

Hello,

I am new to self programming of PIC24. Basically I have SIM900D modem and my application is fully working I can send receive data with server.
Now I want to implement OTA upgrade for PIC24. For that I need to write a dedicated routine called bootloader with all SIM900D functions.
So here is my flow for that please correct me if I am wrong at any place.
I will store this dedicated routine at some starting location and allocate some flash for that, My Application code will store afterward locations and I have a dedicated Serial flash where I can store the incoming firmware.
Now my question is when I receive the new firmware(hex file) by SIM900D do I need to simply write that file from Application start location? Or I have to skip any part from hex which is actually not required to overwrite?
Configuration word is also going to be received in Hex file correct? Do I need to update them also or it is OK to leave them as it will be same in both that dedicated bootloader with GSM functions?
HallMark
 
Posts: 19
Joined: Mon Jun 30, 2014 12:11 pm

Re: OTA Upgrade PIC24

Postby jtemples » Thu Jul 24, 2014 6:03 am

HallMark wrote:Now my question is when I receive the new firmware(hex file) by SIM900D do I need to simply write that file from Application start location? Or I have to skip any part from hex which is actually not required to overwrite?

You'll want to be sure that nothing in the new firmware image could overwrite the bootloader itself.

Configuration word is also going to be received in Hex file correct? Do I need to update them also or it is OK to leave them as it will be same in both that dedicated bootloader with GSM functions?

It's ok to leave them. It's actually safer to leave them since it could brick the device if the power failed while you were updating them.
jtemples
Verified identity
 
Posts: 195
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: OTA Upgrade PIC24

Postby HallMark » Thu Jul 24, 2014 6:17 am

jtemples wrote:You'll want to be sure that nothing in the new firmware image could overwrite the bootloader itself.


Hi jtemples,
Thank you for the quick reply. Will you please share some more information on how can I fix the Flash and RAM location for Bootloader code and Application code? I think it is OK of Bootloader and Application code share RAM location as at a time there is going to be execution of one program only. When it is in bootloader it will get exit only after getting new image and successful update of PIC24 Application flash area.
HallMark
 
Posts: 19
Joined: Mon Jun 30, 2014 12:11 pm

Re: OTA Upgrade PIC24

Postby jtemples » Thu Jul 24, 2014 6:56 am

Yes, you can share the RAM between the two. It's been a very long time since I did a bootloader for a PIC24, and that was with a compiler that's no longer available, so I can't provide specific details on how to reserve ROM areas with the current compiler. I would think you could find examples of PIC24 bootloaders in some of the Microchip stacks such as the USB stack.
jtemples
Verified identity
 
Posts: 195
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: OTA Upgrade PIC24

Postby HallMark » Thu Jul 24, 2014 7:01 am

jtemples wrote:Yes, you can share the RAM between the two. It's been a very long time since I did a bootloader for a PIC24, and that was with a compiler that's no longer available, so I can't provide specific details on how to reserve ROM areas with the current compiler. I would think you could find examples of PIC24 bootloaders in some of the Microchip stacks such as the USB stack.

I tried to go thru Serial bootloader example, There are some .gld script files and some remapping of vector script and that make me more confused how to edit them and why remapping of interrupt required.
HallMark
 
Posts: 19
Joined: Mon Jun 30, 2014 12:11 pm

Re: OTA Upgrade PIC24

Postby jtemples » Thu Jul 24, 2014 7:14 am

I looked at my old bootloader and I didn't do anything with interrupt vectors. Maybe they remapped the interrupt vectors because the vectors are in a protected boot block that couldn't be written by the bootloader. If that's the case, you wouldn't have to use the protected boot block if you didn't want too fool with interrupt remapping.
jtemples
Verified identity
 
Posts: 195
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: OTA Upgrade PIC24

Postby BobAGI » Thu Jul 24, 2014 7:20 am

Gosh, this reply was lost when I tried to submit some time ago, but when I decided to have another go and hit the Quick Reply button it reappeared!
So here I go trying to post it again:

You may want to read the application note AN1157 for the way to place the boot loader and the application in different flash sections.
The BL code itself should have built-in safeguards for erasing its own block of flash, otherwise you will brick the device.
When updating the firmware the BL must first erase the flash it will program and this is done in blocks, not words.
The application vectors cannot reside in the standard place because then they will not be updated by the BL since this is in the protected part of flash.
Therefore the standard way is to put a jump table in application space and code the standard vectors in the BL section to just point to this jump table.
Of course the BL should not use interrupts (goes without saying).
The arrangement is created by two different linker scripts, one for the BL and one for the application.
The BL script places the vectors in low memory starting at 0, but the app script creates a jump table in beginning of the application flash area and also loades it properly depending on which ISR functions you have implemented.

I have created a boot loader for PIC24FJ256GB206 and for these I have the two GLD linker scripts. Can post them if you are interested.
Note that the scripts must be customized for each processor type since the vectors are not the same.
I started from the standard script for my CPU in the compiler (C30).
--
Bo B
Sweden & Texas
User avatar
BobAGI
Verified identity
 
Posts: 49
Joined: Sun May 25, 2014 2:28 pm
Location: Sweden and Texas
PIC experience: Professional 5+ years with MCHP products

Re: OTA Upgrade PIC24

Postby HallMark » Thu Jul 24, 2014 7:35 am

jtemples wrote:I looked at my old bootloader and I didn't do anything with interrupt vectors. Maybe they remapped the interrupt vectors because the vectors are in a protected boot block that couldn't be written by the bootloader. If that's the case, you wouldn't have to use the protected boot block if you didn't want too fool with interrupt remapping.

In this memory map which memory is boot protected? Starting from 0x200h ?
Map.png
Map.png (54.85 KiB) Viewed 10963 times
HallMark
 
Posts: 19
Joined: Mon Jun 30, 2014 12:11 pm

Re: OTA Upgrade PIC24

Postby HallMark » Thu Jul 24, 2014 9:36 am

BobAGI wrote:Gosh, this reply was lost when I tried to submit some time ago, but when I decided to have another go and hit the Quick Reply button it reappeared!
So here I go trying to post it again:

You may want to read the application note AN1157 for the way to place the boot loader and the application in different flash sections.
The BL code itself should have built-in safeguards for erasing its own block of flash, otherwise you will brick the device.
When updating the firmware the BL must first erase the flash it will program and this is done in blocks, not words.
The application vectors cannot reside in the standard place because then they will not be updated by the BL since this is in the protected part of flash.
Therefore the standard way is to put a jump table in application space and code the standard vectors in the BL section to just point to this jump table.
Of course the BL should not use interrupts (goes without saying).
The arrangement is created by two different linker scripts, one for the BL and one for the application.
The BL script places the vectors in low memory starting at 0, but the app script creates a jump table in beginning of the application flash area and also loades it properly depending on which ISR functions you have implemented.

I have created a boot loader for PIC24FJ256GB206 and for these I have the two GLD linker scripts. Can post them if you are interested.
Note that the scripts must be customized for each processor type since the vectors are not the same.
I started from the standard script for my CPU in the compiler (C30).


I try to go thru AN1157 and example code for the bootloader. But I was not sure what step and changes I have to follow to perform that test.
As I want to use SIM900D GPRS code in bootloader I must have to use Serial and timer interrupt. Is there any way to use interrupt even in bootloader?
Interrupt remapping part is not clear to me let me read the application note again and try to understand why interrupt remapping is required.
HallMark
 
Posts: 19
Joined: Mon Jun 30, 2014 12:11 pm

Re: OTA Upgrade PIC24

Postby HallMark » Fri Jul 25, 2014 6:33 am

@BobAGi, Vector table is from 000004H to 0000FEH and for my SIM900 bootloader code starts from 000200H and I allocate say upto 001200H and then from 001400 I start my application code. So when I want to change my application I just have to erase part from 001400H and update them with new received code. Isn't this going to work?
HallMark
 
Posts: 19
Joined: Mon Jun 30, 2014 12:11 pm

Next

Return to PIC24

Who is online

Users browsing this forum: No registered users and 5 guests

cron