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

EX_PCD_BOOTLOADER PIC24FJ128GL305

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



Joined: 18 Nov 2008
Posts: 274
Location: Athens, Greece.

View user's profile Send private message

EX_PCD_BOOTLOADER PIC24FJ128GL305
PostPosted: Fri Dec 23, 2022 2:37 am     Reply with quote

CCS 5.104

Hello,

I have a working bootloader code for PIC24FJ48GA002 and now i am trying to test it on a PIC24FJ128GL305 but I get "Error#126 Invalid ORG range:"

Code:

Info#300  More info:   Segment at 00000-017FE (0000 used):
Info#300  More info:   Segment at 01800-0FFFE (0000 used)  Priv:
Info#300  More info:   Segment at 10000-15EFE (0000 used)  Priv:
Info#300  More info:   Attempted to create: 01800-01804  for #org:
Error#126  Invalid ORG range:
1 Errors,  1 Warnings.:



Please share your ideas Smile

Code:

#include <24FJ128GL305.h>

#FUSES NOWDT             //Watch Dog Timer
#FUSES NOPROTECT         //Code not protected from reading
#FUSES FRC_PLL       
#FUSES NOPR              //Pimary oscillator disabled
#FUSES OSCIO             //OSC2 is general purpose output
#FUSES NOCKSNOFSM
#FUSES NOBROWNOUT

#BUILD (stack=1024)

#use delay(int=32M)

#use    fast_io(B)
#use    fast_io(C)
#use    fast_io(D)
#use    fast_io(E)
#use    fast_io(F)
#use    fast_io(G)

#pin_select U1TX = PIN_F4
#pin_select U1RX = PIN_F5

#use rs232(BAUD=115200,BRGH1OK,UART1,ERRORS)

#word LATB= getenv("SFR:LATB")
#word LATC=getenv("SFR:LATC")
#word LATD=getenv("SFR:LATD")
#word LATE=getenv("SFR:LATE")
#word LATF=getenv("SFR:LATF")
#word LATG=getenv("SFR:LATG")

#word TRISB= getenv("SFR:TRISB")
#word TRISC=getenv("SFR:TRISC")
#word TRISD=getenv("SFR:TRISD")
#word TRISE=getenv("SFR:TRISE")
#word TRISF=getenv("SFR:TRISF")
#word TRISG=getenv("SFR:TRISG")

#word PORTB=getenv("SFR:PORTB")
#word PORTC=getenv("SFR:PORTC")
#word PORTD=getenv("SFR:PORTD")
#word PORTE=getenv("SFR:PORTE")
#word PORTF=getenv("SFR:PORTF")
#word PORTG=getenv("SFR:PORTG")

#word PR1=getenv("SFR:PR1")
#word PR2=getenv("SFR:PR2")
#word PR3=getenv("SFR:PR3")

#word IOCPUG=getenv("SFR:IOCPUG")

#define _bootloader
#define LOADER_PAGES 3
#include <pcd_bootloader.h>
#include "loader_pcd.h"

#org LOADER_END+1,LOADER_END+5

void application(void)
{
   while(TRUE);
}


#include "Pins.h"
#include "Variables.h"
#include "Timer.h"

//------------------------------------------------------
void Main(){
   TRISB=0b0100000001000000;
   TRISC=0b0000000000000000;    
    TRISD=0b0000000000001000;   
   TRISE=0b0000000000000000;    
    TRISF=0b0000000000100000;   
   TRISG=0b0000000010000000;   
   
    IOCPUG=0b0000000010000000;    //Enable G7 pull up (Button))

    LATB=0;   
    LATC=0; 
    LATD=0;
    LATE=0;
    LATF=0; 
    LATG=0; 

   SETUP_ADC(ADC_OFF);
   SETUP_ADC_PORTS(NO_ANALOGS);                     

   delay_ms(10);
   
    OledCS=1;
    EepromCS=1;
   
    printf("\n\rStarting Bootloader.");
    delay_ms(500);
   
    if(!Button){
     printf("\r\nWaiting for download...");
     load_program();         
    }
   
    printf("\r\nStarting App...");
   
    application();   

}

#int_default
void isr(void){
   jump_to_isr(LOADER_END+5);
}

_________________
George.


Last edited by georpo on Fri Dec 23, 2022 5:34 am; edited 1 time in total
georpo



Joined: 18 Nov 2008
Posts: 274
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Fri Dec 23, 2022 2:57 am     Reply with quote

If I change to :

Code:

#org LOADER_END+1


It works, I do not know if this will cause any problem
but the bootloader compiled and I got it to download the firmware successfully.
_________________
George.
georpo



Joined: 18 Nov 2008
Posts: 274
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Fri Dec 23, 2022 3:09 am     Reply with quote

OK, without setting the org range, the timer interrupt is not working.
I guess it is related to this:

Code:

#int_default
void isr(void){
   jump_to_isr(LOADER_END+5);
}


So what is the correct org range?
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Dec 23, 2022 11:11 am     Reply with quote

That is the wrong #org for the application. It needs to just use
Code:

#org APPLICATION_START
void application(void)
{
   while(TRUE);
}

Your current #ORG making it clash with the #INT #ORG....

You are trying to load the application into the vector above the LOADER,
where the jump to the actual application needs to be. This then makes
it clash with the interrupt re-vectoring table (on PCD, the #INT_DEFAULT
jump_to_isr code generates a whole new vector table for the main
application). Hence it can't get it to fit....
georpo



Joined: 18 Nov 2008
Posts: 274
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Fri Dec 23, 2022 2:39 pm     Reply with quote

Ttelmah to the rescue once again.

The code from the example is working just fine.
And it also worked for the PIC24FJ128GL305 but the interrupt never triggered.

I will try your suggestion and report back.

Should I also change this to past projects already working?
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Dec 24, 2022 6:58 am     Reply with quote

Are you sure you need the stack to be 1K?. That is using a lot of your RAM.
Look at the stack size in the compiled code. Remember each 'location' needs
two bytes, but I'd have thought something like 512, would be enough.

Your fuses need NOIOL1WAY, or your main code is not going to be able
to set the PPS for devices. Possibly this is what is preventing the interrupt
from working (the device is not actually on the pins you think).
What interrupt are you trying to use? Obviously check it is enabled etc..

Have a great Christmas. Very Happy
georpo



Joined: 18 Nov 2008
Posts: 274
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Wed Dec 28, 2022 12:44 am     Reply with quote

Hi!

I changed to #org APPLICATION_START but the timer2 interrupt does not fire. Everything works, OLED,UART,SPI but not the interrupt. Maybe the "jump_to_isr(LOADER_END+5);" is wrong? why +5?

The interrupt and the timer are configured correctly because if I run the firmware directly without bootloader the interrupt fires.
Please look at the code below.

BOOTLOADER

Code:

#include <24FJ128GL305.h>

#FUSES NOWDT             //Watch Dog Timer
#FUSES NOPROTECT         //Code not protected from reading
#FUSES FRC_PLL       
#FUSES NOPR              //Pimary oscillator disabled
#FUSES OSCIO             //OSC2 is general purpose output
#FUSES NOCKSNOFSM
#FUSES NOBROWNOUT
#FUSES NOIOL1WAY

#BUILD (stack=512)

#use delay(int=32M)

#use    fast_io(B)
#use    fast_io(C)
#use    fast_io(D)
#use    fast_io(E)
#use    fast_io(F)
#use    fast_io(G)

#pin_select U1TX = PIN_F4
#pin_select U1RX = PIN_F5

#pin_select SDO1    = PIN_D4
#pin_select SCK1OUT = PIN_D5
#pin_select SDI1    = PIN_D3

#use rs232(BAUD=115200,BRGH1OK,UART1,ERRORS)

#define _bootloader
#define LOADER_PAGES 3
#include <pcd_bootloader.h>
#include "loader_pcd.h"

//#org LOADER_END+1,LOADER_END+5
//#org LOADER_END+1
#org APPLICATION_START
void application(void)
{
   while(TRUE);
}

#word LATB= getenv("SFR:LATB")
#word LATC=getenv("SFR:LATC")
#word LATD=getenv("SFR:LATD")
#word LATE=getenv("SFR:LATE")
#word LATF=getenv("SFR:LATF")
#word LATG=getenv("SFR:LATG")

#word TRISB= getenv("SFR:TRISB")
#word TRISC=getenv("SFR:TRISC")
#word TRISD=getenv("SFR:TRISD")
#word TRISE=getenv("SFR:TRISE")
#word TRISF=getenv("SFR:TRISF")
#word TRISG=getenv("SFR:TRISG")

#word PORTB=getenv("SFR:PORTB")
#word PORTC=getenv("SFR:PORTC")
#word PORTD=getenv("SFR:PORTD")
#word PORTE=getenv("SFR:PORTE")
#word PORTF=getenv("SFR:PORTF")
#word PORTG=getenv("SFR:PORTG")

#word PR1=getenv("SFR:PR1")
#word PR2=getenv("SFR:PR2")
#word PR3=getenv("SFR:PR3")

#word IOCPUG=getenv("SFR:IOCPUG")

#include "Pins.h"
#include "Variables.h"
#include "Timer.h"


//------------------------------------------------------
void Main(){
    TRISB=0b0100000001000000;
    TRISC=0b0000000000000000;    
    TRISD=0b0000000000001000;   
    TRISE=0b0000000000000000;    
    TRISF=0b0000000000100000;   
    TRISG=0b0000000010000000;   
   
    IOCPUG=0b0000000010000000;    //Enable G7 pull up (Button))

    LATB=0;   
    LATC=0; 
    LATD=0;
    LATE=0;
    LATF=0; 
    LATG=0; 

    SETUP_ADC(ADC_OFF);
    SETUP_ADC_PORTS(NO_ANALOGS);            
   
    setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H , 4000000);

    delay_ms(10);
   
    Led=1;
   
    OledCS=1;
    EepromCS=1;
   
    printf("\n\rStarting Bootloader.");
    delay_ms(2000);
   
    if(!Button){
     printf("\r\nWaiting for download...");
     load_program();         
    }
   
    printf("\r\nStarting App...");
   
    Led=0;
   
    application();   

}

#int_default
void isr(void){
   jump_to_isr(LOADER_END+5);
}




FIRMWARE

Code:

#include <24FJ128GL305.h>

#define UseBootloader

#ifdef UseBootloader
 #FUSES NONE
#else

#FUSES NOWDT             //Watch Dog Timer
#FUSES NOPROTECT         //Code not protected from reading
#FUSES FRC_PLL       
#FUSES NOPR              //Pimary oscillator disabled
#FUSES OSCIO             //OSC2 is general purpose output
#FUSES NOCKSNOFSM
#FUSES NOBROWNOUT
#FUSES NOIOL1WAY

#endif


#BUILD (stack=512)

#use delay(int=32M)

#use    fast_io(B)
#use    fast_io(C)
#use    fast_io(D)
#use    fast_io(E)
#use    fast_io(F)
#use    fast_io(G)

#pin_select U1TX = PIN_F4
#pin_select U1RX = PIN_F5

#ifndef UseBootloader
 #pin_select SDO1    = PIN_D4
 #pin_select SCK1OUT = PIN_D5
 #pin_select SDI1    = PIN_D3
#endif

#use rs232(BAUD=115200,BRGH1OK,UART1,ERRORS)

#ifdef UseBootloader
 #define LOADER_PAGES 3
 #include <pcd_bootloader.h>
#endif

#word LATB= getenv("SFR:LATB")
#word LATC=getenv("SFR:LATC")
#word LATD=getenv("SFR:LATD")
#word LATE=getenv("SFR:LATE")
#word LATF=getenv("SFR:LATF")
#word LATG=getenv("SFR:LATG")

#word TRISB= getenv("SFR:TRISB")
#word TRISC=getenv("SFR:TRISC")
#word TRISD=getenv("SFR:TRISD")
#word TRISE=getenv("SFR:TRISE")
#word TRISF=getenv("SFR:TRISF")
#word TRISG=getenv("SFR:TRISG")

#word PORTB=getenv("SFR:PORTB")
#word PORTC=getenv("SFR:PORTC")
#word PORTD=getenv("SFR:PORTD")
#word PORTE=getenv("SFR:PORTE")
#word PORTF=getenv("SFR:PORTF")
#word PORTG=getenv("SFR:PORTG")

#word PR1=getenv("SFR:PR1")
#word PR2=getenv("SFR:PR2")
#word PR3=getenv("SFR:PR3")

#word IOCPUG=getenv("SFR:IOCPUG")

#include "Pins.h"
#include "Variables.h"
#include "Timer.h"
#include "ssh1106.h"


//------------------------------------------------------
void Main(){
    TRISB=0b0100000001000000;
    TRISC=0b0000000000000000;    
    TRISD=0b0000000000001000;   
    TRISE=0b0000000000000000;    
    TRISF=0b0000000000100000;   
    TRISG=0b0000000010000000;   
   
    IOCPUG=0b0000000010000000;    //Enable G7 pull up (Button)

    LATB=0;   
    LATC=0; 
    LATD=0;
    LATE=0;
    LATF=0; 
    LATG=0; 

    SETUP_ADC(ADC_OFF);
    SETUP_ADC_PORTS(NO_ANALOGS);   
   
    setup_timer2(TMR_INTERNAL | TMR_DIV_BY_64);   //10mS
    PR2=20000;
 
    #ifndef UseBootloader
     setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H , 4000000);
    #endif
   
     enable_interrupts(INT_TIMER2);      //Enable Timer Interrupt
     enable_interrupts(GLOBAL);

    delay_ms(10);
   
    printf("\r\nRunning!!!");   
   
     
    OledCS=1;
    EepromCS=1;
   
    OledInit();
   
    while(1){
     OledClear(0);   
     sprintf(TextBuffer,"VERSION 6");   
     OledText(0,0,4);
     UpdateOled();
     delay_ms(500);
     OledClear(1);
     delay_ms(500);
     if(!Button) reset_cpu();
    }
}




Code:


#INT_TIMER2
void TImer2ISR(){   
   
    if(!Led) Led=1;
    else Led=0;     

}

_________________
George.
georpo



Joined: 18 Nov 2008
Posts: 274
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Wed Dec 28, 2022 12:57 am     Reply with quote

I found it.

I had the "#INT_TIMER2" both in the bootloader and in the firmware Embarassed

I removed it from the bootloader and now it works in the firmware.

As about the stack size, no I am not sure it should be 1K. I remember that this is usual for PIC24 and DSpic.
Where can I see the stack size in the compiled code?

Thanks!!!
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Dec 28, 2022 2:19 am     Reply with quote

You open the .lst file generated. About 10 lines down it has the number of
stack levels used.
Normally the default stack, is just a little too small if you are using
complex printf statements. However 1024, would only be used if you
had a rather extreme number of calls inside calls inside calls.
For example my current code in a PIC33EP512GM305, is over 195K bytes
in size, but only uses 204 stack levels. 512Bytes works fine.
Remember the stack uses 2 bytes per level, and having perhaps a 10%
margin in sensible.
1K is not 'usual'. But having to expand it beyond the default size is.
1K is commonly used on some of the chips with more RAM than yours,
but it is worth being a little more 'stingy' if you start to find RAM running
short on the main program.

Yes, using interrupts in the bootloader is difficult. Better to 'poll' the
interrupt bit involved, which simplifies things massively. You can do it by
having separate vector tables for the main and the bootloader.

Glad you are moving forwards. Very Happy

Happy New Year to all.
georpo



Joined: 18 Nov 2008
Posts: 274
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Wed Dec 28, 2022 4:27 am     Reply with quote

Code:

               ROM used:   5890 bytes (7%)
                           Largest free fragment is 53502
               RAM used:   1593 (19%) at main() level
                           1627 (20%) worst case
               Stack used: 64 locations (26 in main + 38 for interrupts)
               Stack size: 512


64 locations. so, 64x2=128?
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Dec 28, 2022 10:54 am     Reply with quote

Exactly. That would just be hitting the limit of the default stack. Worth
going a little bigger, but not to 1K!...
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