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 support@ccsinfo.com

Remapped Interrupt Vectors Problem

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



Joined: 02 Oct 2012
Posts: 10

View user's profile Send private message

Remapped Interrupt Vectors Problem
PostPosted: Mon Jan 28, 2013 4:36 am     Reply with quote

Dear All ,

I am trying to make a bootloader over rs232, i can easily write in program memory with my bootloader program. It is fine.

The problem is about the programs i am trying to load by bootloader. Actually main problems is about the programs with interrupts.

When I comment,
Code:
#build (reset=0x400, interrupt=0x408)

#org 0, BOOTLOADER_END {}

in the code below and when i write it in to the chip directly with pickit3 it works fine.

But when i try to remap the vectors and write it into chip, it just doesnt work.
When i do not use any interrupts in my code, my applications work fine both when downloaded by pickit and through my bootloader software.

So any comments about interrupt vector remapping ?

Regards,
Code:

#include "18F46K22.h"

#define BOOTLOADER_START        0x2A
#define BOOTLOADER_END          0x3FF

#build (reset=0x400, interrupt=0x408)

#org 0, BOOTLOADER_END {}

#fuses hsh,nopllen

#use delay (clock=20000000)   


int i=0;


#int_timer1

void timer1_isr(){
   set_timer1(1);
   i++;
   if(input(pin_e1)){
         if(!(i%20)) {
         output_toggle(pin_a4);}
         }
   else{
      if(!(i%20)){
      output_toggle(pin_a3);}
      }
}



void main ()
{         
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_8 );
   set_timer1(1);   

   enable_interrupts(INT_timer1);
   enable_interrupts(GLOBAL);     
   
   while(1){   

   }

}

Ttelmah



Joined: 11 Mar 2010
Posts: 19225

View user's profile Send private message

PostPosted: Mon Jan 28, 2013 5:06 am     Reply with quote

The bootloader needs to contain the remap call, and this needs to go to the same address as the build.
In ex_bootloader.c, this is the part:
Code:

#ORG default

#int_global
void isr(void) {
   jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}

This places itself at the standard interrupt vector, and then causes a jump to four instructions (8 bytes) after the start of the relocated code.
I'd suspect this section is missing from the bootloader you are using.

Best Wishes
SBTECH



Joined: 02 Oct 2012
Posts: 10

View user's profile Send private message

PostPosted: Mon Jan 28, 2013 5:42 am     Reply with quote

Dear Ttelmah,

I am using the bootloader here , and it works fine. http://www.picprojects.net/serialbootloader/index.html


Actually I did not manage to ask the question clearly. Problem is about the code that is going to be downloaded by bootloader program.

The code i embed above did not work when i download it to the chip directly with Pickit. I am doing this to disregard any possible problems maybe caused by bootloader software.

When i did not remapped the vectors, its simple and fine software.

but when i use build functions,
#build (reset=0x400, interrupt=0x408)

#org 0, BOOTLOADER_END {}

it does not work.

I am just trying to change vectors of a simple software.

When I do not use interrupts i can write and run program hex code any where in the program memory.

Should not it work ? if i write it directly with pickit to the chip ?

I mean, if any code prepared to be downloaded into a chip through bootloader can work or not on the chip when it is directly downloaded by Pickit?
Ttelmah



Joined: 11 Mar 2010
Posts: 19225

View user's profile Send private message

PostPosted: Mon Jan 28, 2013 6:09 am     Reply with quote

This code _requires_ the bootloader vector remapper to be present to work. It can't run without it. To try it without using the bootloader to do the programming, you have to load the bootloader, then set your programmer to not erase, and write the code as well.
Or you can load the bootloader into MPLAB, then load the main code, and then get MPLAB to save the whole of the program memory as a single file, and program this.
You can never load code that is designed to use a bootloader into a chip, without the bootloader there. It just won't work.....

Best Wishes
SBTECH



Joined: 02 Oct 2012
Posts: 10

View user's profile Send private message

PostPosted: Mon Jan 28, 2013 6:51 am     Reply with quote

Ttelmah, You are a life saver ! Thank you very much it works !!
SBTECH



Joined: 02 Oct 2012
Posts: 10

View user's profile Send private message

PostPosted: Fri Feb 01, 2013 10:05 am     Reply with quote

Hi fellows ,

I have accomplished some details of my bootloader after your suggestions here.

Now I have another little problem to solve. I am able to load my application software to my PIC through rs232 and it starts running as soon as it completes loading the hex file.

Right now my problem is about entering bootloader mode while running application software . I write an example code for you to help me debug my code.

assume the code below as my running application code.

Code:
#include "18F46K22.h"

#define bootpin pin_a5
#define BOOTLOADER_START        0x2A
#define BOOTLOADER_END          0x3FF
#build (reset=BOOTLOADER_END +1  , interrupt=0x408 )
#org 0, BOOTLOADER_END {}

#fuses HSh,wdt256,pllen
#use delay(clock=80M)
 
int i;
int BootAct;

#int_timer1
void timer1_isr(){

   set_timer1(1);
   i++;
   
     if(!(i%20)) {
     output_toggle(pin_a4);}
     
 }



void main ()
{   
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_8 );
   set_timer1(1);   
   enable_interrupts(INT_timer1);
   enable_interrupts(GLOBAL);     
   
   
   if(read_eeprom(253)==0xFF ){
   write_eeprom(253,0);
   }
     
   while(1){
   
   BootAct=input(pin_a5);
   output_low(pin_a0);
   
      if(BootAct>0){
     
      write_eeprom(253,1);
      output_high(pin_a1);
      //!delay_ms(2000);
      #asm
      goto 0x00
      #EndAsm
     
      }
   }

}


And the code below is piece of my bootloader code.
Code:

#include "18f46k22.h"

#fuses HSh,wdt256,pllen

#use delay(clock=80M)
....
.....
#define BOOTLOADER_START        0x2A
#define BOOTLOADER_END          0x3FF
#define RESET_VECTOR            0x400
#define INTERRUPT_VECTOR_LOW    0x408
#define INTERRUPT_VECTOR_HIGH   0x418
#define APPLICATION_START       RESET_VECTOR

#ORG BOOTLOADER_START, BOOTLOADER_END auto=0 default
...

...
#ORG BOOTLOADER_START
void main()
{
   
    setup_adc(ADC_OFF);
   
    int16 snc=read_eeprom(253);
    if(snc==0xFF || snc==0x01){
   
    output_high(pin_a0);
    bootloader();
    write_eeprom(253,0);
    output_low(pin_a0);
   
    #asm
    goto RESET_VECTOR
    #endasm
   
   }
   
   
    else {
    #asm
    goto RESET_VECTOR
    #endasm
         }

}


When i want to enter bootload mode, i see that my pin_a0 goes high, so i know that i managed to force my stack pointer to 00h adress. But while pin_a0 goes high, i also see that my application program still runs.

When i perform a MCLR reset by hardware, my software starts in bootloader mode without problems. But the thing i want to do here is perform a MCLR reset by software. In my final software people should easily enter boot mode without even seeing my board.

How can i manage this ? I tried reset_cpu(); but it did not help.

So I am waiting for your comments about this issue.
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