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

Another Bootloader

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



Joined: 08 Sep 2010
Posts: 9

View user's profile Send private message

Another Bootloader
PostPosted: Wed Nov 16, 2016 5:28 am     Reply with quote

Hi All,
Well I have not posted on here for a while, to be honest, I usually just search through all the post and find the answer, but I am stumped on the this.

Compiler PCH Version 4.109
PIC 18F4585

Prototype board my own, all pins used are correct and it works without fault.

bootloader code
bootloader.c
Code:

#include <18F4585.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP


#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12

//#endif

#define LED PIN_B1
#define _bootloader


#include <bootloader.h>
#include <loader.c>


//#if defined(__PCM__)
// #org LOADER_END+1,LOADER_END+10
//#if defined(__PCH__)
 #org LOADER_END+2,LOADER_END+20  //0ld 20
//#endif
#int_global
void isr(void) {
   jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));//old jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8))
}


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

//#if defined(__PCH__)
#org 0x40,0x7F  //old 7F
//#else
//#org 0x20,0x3F
//#endif
void main(void)
{
   if(!input(PIN_B5))
   { output_high(LED);
      load_program();
   }

   application();
}

#ORG default


Bootloader.h code

Code:

#if defined(__PCM__)
   #define LOADER_END   0x1FF
   #define LOADER_SIZE   0x1BF
#elif defined(__PCH__)
   #define LOADER_END   0x4FF//old 4FF
   #define LOADER_SIZE   0x3FF
#endif

#ifndef _bootloader

#if defined(__PCM__)
   #build(reset=LOADER_END+1, interrupt=LOADER_END+5)
#elif defined(__PCH__)
   #build(reset=LOADER_END+1, interrupt=LOADER_END+9)
#endif

#org 0, LOADER_END {}

#endif



Test Program code
LedFlash.c


Code:

#include <LedFlash.h>
#include <bootloader.h>

#define LED PIN_B1

void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_0);
   //setup_pp(PMP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);


    //Example blinking LED program
    while(true){
      output_low(LED);
      delay_ms(1000);
      output_high(LED);
      delay_ms(1000);
    }

}


LedFlash.h

Code:

#include <18F4585.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV21                   //Brownout reset at 2.1V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES BBSIZ4K                  //4K words Boot Block size
#FUSES NOWRTC                   //Configuration registers not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PC,ERRORS)


Bootloader.h and loader.c are unmodified
What it does do,
Both compile without errors and load into the pic using a ICD U64
Both run and work.

What it doesn't do
Bootloader doesn't load the LedFlash program.
On power up with PIN B5 low, the LED comes on, so I know it is in the load condition.
I then send the program via a FDTI USB to serial converter, using CCS SOIW and TERA TERM, both have the same outcome.
I have reduced the serial port buffer to its lowest setting 64, and flow control in on.
If I add a transmit delay between characters and lines I can see the PIC responding as it should, but on completion of the down load (PIN B5) sent high during download, the pic just stays in the Load condition,
What am I missing?
thanks inadvance
jeremiah



Joined: 20 Jul 2010
Posts: 1355

View user's profile Send private message

PostPosted: Wed Nov 16, 2016 8:06 am     Reply with quote

I don't think this is your problem, but something to eliminate as a possibility:

Your application fuses and your bootloader fuses are not specified identically. If the defaults differ, then you could have a fuses mismatch, which could lead to interesting behavior.

I would either:
1. Use the same exact fuses in both
OR
2. Specify #fuses NONE in the application side
davidnclare



Joined: 08 Sep 2010
Posts: 9

View user's profile Send private message

PostPosted: Wed Nov 16, 2016 8:20 am     Reply with quote

Thanks, just tried that still, the same.
I am going to try and increase the buffer in the loader.c file make it bigger than the buffer on the USB to serial port converter.
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Wed Nov 16, 2016 9:05 am     Reply with quote

Critical thing is that XON/XOFF handshaking must be enabled on the port that you use. There isn't actually a 'buffer' in loader.c (in the sense of a FIFO). There is just a temporary store into which the line is read. When the line is complete, the sender _must_ stop (this is why the code sends XOFF). The reason is the processor has to actually stop code execution, to write it's own flash memory, so any data arriving while this is going on, will cause a disaster.
Generally you need to enable this in both device manager, and in the program (some ports respond to one, and not the other....).
davidnclare



Joined: 08 Sep 2010
Posts: 9

View user's profile Send private message

PostPosted: Wed Nov 16, 2016 9:12 am     Reply with quote

Thanks, I have been doing it in the terminal emulator, but not in device manager, I will try it.
davidnclare



Joined: 08 Sep 2010
Posts: 9

View user's profile Send private message

PostPosted: Wed Nov 16, 2016 9:49 am     Reply with quote

XON/XOFF handshaking enable in both location, I have also turned up the delay after each line transmission, and you can definitely see the tx and rx led's cycle on the off as they should.
It is like it is not doing the last lines on the code and reseting the PIC
Thanks, I will keep trying things.
davidnclare



Joined: 08 Sep 2010
Posts: 9

View user's profile Send private message

PostPosted: Wed Nov 16, 2016 11:56 am     Reply with quote

I think I have sorted it
Code:

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


Should be
Code:

void isr(void) {
   jump_to_isr(LOADER_END+1*(getenv("BITS_PER_INSTRUCTION")/8));//old jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8))
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Wed Nov 16, 2016 1:16 pm     Reply with quote

That is not right.

The ISR entry is at address 4 in the processor. Loader end+5 is correct (loader end is one below where the code should start)..

I'd suggest your real problem is that your code is slightly overrunning the area allocated. You do understand that _you_ have to set loader end to the next page boundary above where your bootloader code ends. I'd suspect your loader, is larger than the CCS supplied one, hence the problems.
davidnclare



Joined: 08 Sep 2010
Posts: 9

View user's profile Send private message

PostPosted: Thu Nov 17, 2016 4:12 am     Reply with quote

Hi,
For some reason the Application was not at 0x500 by changing the isr and recompiling, it put the application at 0x500, so now changed the isr code back and it works bazar.
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