CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Microchip HID Bootloader with PIC24F

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
orangeshasta



Joined: 13 Feb 2008
Posts: 7

View user's profile Send private message

Microchip HID Bootloader with PIC24F
PostPosted: Thu Apr 28, 2011 9:37 am     Reply with quote

Hi all,

I'm trying to get Microchip's HID bootloader with a project I have running on a PIC24FJ256GB106. I've got the bootloader itself running properly, and I can successfully load and run a simple "Hello World" program which just prints out of the UART, delays 1000ms, and repeats.

However, when I load code that involves interrupts, things stop behaving. I've narrowed down the problem, and it looks like the CCS compiler isn't remapping my interrupts the way I expect.

Anyway, here's some code:
Code:

#include <24FJ256GB106.h>
#device adc=10
#FUSES NODEBUG
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES ICSP3                    //ICD uses PGC3/PGD3 pins
#FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOIOL1WAY                //Allows multiple reconfigurations of peripheral pins
#FUSES NOOSCIO                    //OSC2 is not general purpose output
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES PR_PLL                   //Primary Oscillator with PLL
#FUSES PLL2                     //Divide By 2(8MHz oscillator input)
#FUSES NOJTAG
#use delay(clock=32M)

// START OF bootloader definition
#define LOADER_END 0x13FE
#build(reset=LOADER_END+2, interrupt=LOADER_END+6)
#org 0, LOADER_END {} // nothing will replace the bootloader memory space
// END OF bootloader definition

// Variable definitions, interrupt service routines, main, etc. below here


So, I've set aside program memory between 0 and 0x13FE, which is taken up by the bootloader. Because that is the space where the reset and interrupt vectors are, the reset vector gets remapped to 0x1400 and the interrupts should start at 0x1404, according to the datasheet and the bootloader documentation. My code uses a lot of interrupts (EXT1, Timer1 - Timer5, RDA, TBE, and RDA2), and I can see in the start of my .lst file where they are remapped:

Code:

*
01400 0457FE 000000  GOTO    57FE           :
*
01430 042150 000000  GOTO    2150           :
*
01440 042174 000000  GOTO    2174           :
01444 0421F4 000000  GOTO    21F4           :
*
01450 042314 000000  GOTO    2314           :
01454 04241E 000000  GOTO    241E           :
*
01474 041D66 000000  GOTO    1D66           :
*
01490 042216 000000  GOTO    2216           :
01494 0422E0 000000  GOTO    22E0           :
*
0149C 0424EE 000000  GOTO    24EE           :


That second instruction (GOTO 2150), for the sake of example, is my Timer1 ISR. As you can see, that instruction is located at 0x1430. However, according to the linker file in the Microchip bootloader, it should be located at 0x1424. The other interrupts are similarly offset by +6. I can't change my #BUILD statement to have the interrupts mapped to a location 6 words earlier, because that's space set aside for the bootloader. Does anyone have any idea how I might be able to get these mapped properly?

Thanks in advance,
Bob

P.S. Also, I am using the most up-to-date version of the compiler: v4.120
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Mon Jun 20, 2011 6:19 pm     Reply with quote

Dear

You solve this problem?, Can you tell me. I have similar problem

Regards,
orangeshasta



Joined: 13 Feb 2008
Posts: 7

View user's profile Send private message

PostPosted: Tue Jun 21, 2011 8:11 am     Reply with quote

Not really - as it turns out, the method that CCS provides for remapping the IVT doesn't allow for making the interrupts have four bytes in between each one, as Microchip does (to hold a GOTO instruction). Therefore, it would not be straightforward to make the Microchip HID bootloader work with the CCS compiler.

The only way I know of to simply make it work would be to hard-code all of the the IVT memory locations in Microchip's linker script, using only 2 bytes for each entry. This was suggested to me by Microchip support - however, I'm not too familiar with the syntax, etc. of the Microchip linker file and so I decided that I needed to move on with my project rather than spend more time trying to get the bootloader to behave.

Let me know if you come up with anything though, I'd be curious to hear how you did it.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Jun 21, 2011 9:32 am     Reply with quote

One option with the Microchip HID bootloader is to use no mapping at all, make the bootloader code write the complete IVT from PCD application image, except for the reset vector, that points to the bootloader into page 0. This brings a certain risk of bootloader failure, because you need to unprotect the bootloader area.

A fail safe bootloader must have all used interrupt vectors fixed, e.g. by using predefined ISR addresses.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group