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

CCS Bootloader for PIC24HJ256GP610 [SOLVED]

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



Joined: 02 Mar 2015
Posts: 19

View user's profile Send private message

CCS Bootloader for PIC24HJ256GP610 [SOLVED]
PostPosted: Mon Mar 02, 2015 4:58 am     Reply with quote

I'm sorry for opening another topic about bootloaders.
I know that there are plenty of them and I really read through a lot of them since last week. But none really helped me.

I have successfully loaded the example bootloader (ex_pcd_bootloader.c, because I am using the pcd compiler) on to the pic.

I am using PCD Version 5.040

My problem now is that I cannot load a simple program (an blinking led) hex file on to the PIC24 with the Siow.exe that is provided with ccs.

I always get the "Timeout while downloading" error message.

My settings in the Siow.exe is

ComPorts: Direct to COM6 (that is where the PIC its connected to)
Baud rates: 9600
Parity: None
Data bits: 8
Stop bits: 1
Software Flow Control: Both , Xon Value 0x11, Xoff Value 0x13
Hardware Flow Control: Nothing selected

This is the program i want to load on to the pic with the bootloader (siow.exe)

Code:
#device PIC24HJ256GP610

#include "24HJ256GP610.h"

//////////////////////////////////////////////////////////////////////
#fuses NONE // so that the bootloader fuses are not overwritten///////
/////////////////////////////////////////////////////////////////////////////

#use delay(crystal=20MHz)
#use delay(clock=80000000)

#define LED PIN_A12

//////////////////////////////////////////////////////////////////////
#DEFINE LOADER_END (getenv("FLASH_ERASE_SIZE")-1)//////////////////////
#BUILD (reset=LOADER_END+1,interrupt=LOADER_END+5)/////////////////////
#ORG 0x000,LOADER_END {} ///////////////////////////////////////////////
#use rs232(baud=9600,parity=N,UART1,bits=8,STREAM=COM1) // use COM1///////
#use rs232(baud=9600,parity=N,UART2,bits=8,STREAM=COM6) // use COM6///////
/////////////////////////////////////////////////////////////////////

void initPorts(void)
{
   set_tris_a(0xEFFF);
}

void main(void)
{
   setup_oscillator(OSC_CRYSTAL, 80000000, 20000000);
   initPorts();

   while(1)
   {
      output_bit(LED,1);
      delay_ms(500);
      output_bit(LED,0);
      delay_ms(500);
   }
}


I thank you for any help.


Last edited by PIC24H on Wed Mar 04, 2015 5:21 pm; edited 6 times in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19530

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 5:55 am     Reply with quote

Do the build offsets, by just using #include pcd_bootloader.h

This automatically sets the build as required to match the bootloader. Look at how ex_pcd_bootload.c is done (this is an example program to load with the bootloader).

Your location for the run time program is wrong for the standard bootloader setup (in fact it is wrong for any setup)....
PIC24H



Joined: 02 Mar 2015
Posts: 19

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 6:35 am     Reply with quote

Ttelmah wrote:
Do the build offsets, by just using #include pcd_bootloader.h

This automatically sets the build as required to match the bootloader. Look at how ex_pcd_bootload.c is done (this is an example program to load with the bootloader).

Your location for the run time program is wrong for the standard bootloader setup (in fact it is wrong for any setup)....


Thanks for your reply. I have created a new project with the ex_pcd_bootload.c. I have included the 24HJxxx.h and the pcd_bootloader.h. It compiles fine without errors. But when using Siow.exe to transfer it to the pic I get the same error "Timeout while downloading".

this is the code (I left parts out)


Code:
#include "24HJ25....."
#fuses NOWDT
#use delay(.....
#use rs232(....
.
.

#include "pcd_bootloader..."

void main()
{
.
.
.
.

   while(TRUE)
   {
   }
}
temtronic



Joined: 01 Jul 2010
Posts: 9233
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 7:33 am     Reply with quote

just some silly basic ideas...
1) have both bootloader and program the SAME fuses and clock speeds ?

2) is the PC(SIOW) really on COM6 ? easy to confirm, use loopback.

I've been down a similar path and the wire from PC to PIC was faulty !!!

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19530

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 7:36 am     Reply with quote

Also I notice two #USE DELAY statements in the original code.....
PIC24H



Joined: 02 Mar 2015
Posts: 19

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 8:24 am     Reply with quote

temtronic wrote:
just some silly basic ideas...
1) have both bootloader and program the SAME fuses and clock speeds ?

2) is the PC(SIOW) really on COM6 ? easy to confirm, use loopback.

I've been down a similar path and the wire from PC to PIC was faulty !!!

Jay


1) Yes both have used the following fuses and clock speeds

#fuses NOWDT
#use delay(crystal=20MHz)

2) Yes it is. It outputs ASCII Signs in the Siow when i reset it.

fprintf(COM2,"\r\nBootloader Version 1.0\r\n");
fprintf(COM2,"\r\nWaiting for download...");

@Ttelmah

I will join them like this then

#use delay(crystal=20MHz,clock=80000000)
Ttelmah



Joined: 11 Mar 2010
Posts: 19530

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 9:16 am     Reply with quote

That fuse and clock combination, on that chip, with the clocks on separate lines, selects PR, HS, not PR_PLL(tried with three compiler versions). So as originally posted, the chip will actually be running at 20Mhz, while the code thinks it is running at 80MHz. RS232 won't then work....

Putting them on one line, it switches to starting with FRC (which it has to do), and does appear to correctly program the switch to the external clock.

I must admit I don't 'like' relying on the defaults for the fuses. I'd be explicit and select something like:

#fuses NOWDT, PR_PLL, HS, PUT128, NODEBUG, NOPROTECT, NOJTAG
#use delay(crystal=20MHz, clock=80000000)
temtronic



Joined: 01 Jul 2010
Posts: 9233
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 9:27 am     Reply with quote

De fault is the defaults !

Rule #1 , 'defaults' are the OTHER guys idea of how the PIC should be setup

Rule #2, HIS 'defaults' will NEVER be what YOU need

Rule #3, Create a 'header' file with KNOWN, working set of 'default' fuses and #include it ! that way you'll always have a good, KNOWN set of fuses.
it also cleans up the 'clutter' of 20-30 fuses in 'main',


Jay
PIC24H



Joined: 02 Mar 2015
Posts: 19

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 1:39 pm     Reply with quote

Thanks for all your help and hints. I will try it tomorrow when I'm back at the university.
PIC24H



Joined: 02 Mar 2015
Posts: 19

View user's profile Send private message

PostPosted: Tue Mar 03, 2015 2:31 am     Reply with quote

Ok the current status is:

I wrote an simple program so that an led blinks. This is the code

Code:
#include "24HJ256GP610.h"

#fuses NOWDT, PR_PLL, HS, PUT128, NODEBUG, NOPROTECT, NOJTAG
#use delay(crystal=20MHz, clock=80000000)

#use rs232(baud=19200,parity=N,xmit=PIN_F5,rcv=PIN_F4,bits=8,STREAM=COM2)
////#use rs232(baud=19200,STREAM=COM2)


#include "pcd_bootloader.h"

#define LED PIN_A12

void initPorts(void)
{
   set_tris_a(0xEFFF);
}
   
void main(void)
{
   initPorts();

   while(1)
   {
      output_bit(LED,1);
      delay_ms(500);
      output_bit(LED,0);
      delay_ms(500);
   }
}


If I don't #include "pcd_bootloader.h" the program works fine when I'm loading it on to the pic. But when I #include "pcd_bootloader.h" the led doesn't blink. It has something to do with the header file of the bootloader.

Anyway I cant load the program on to the pic using the bootloader and the siow.exe . I still get the "Timeout while downloading" error message.

This is the bootloader code (modified because its not allowed to copy and paste the original code)



Code:
#include "24HJ256GP610.h"
#fuses NOWDT, PR_PLL, HS, PUT128, NODEBUG, NOPROTECT, NOJTAG
#use delay(crystal=20MHz, clock=80000000)
#use rs232(baud=19200,parity=N,xmit=PIN_F5,rcv=PIN_F4,bits=8,STREAM=COM2)

#define BUTTON PIN_F6
   
#define _bldr

#include "pcd_bootloader.h"
#include "loader_pcd.c"

#org LOADER_END+1,LOADER_END+5
void app(void)
{
   while(1);
}

void main(void)
{
   if(!input(BUTTON))
   {
      fprintf(COM2,"\r\nBL Version 1.0\r\n");

      fprintf(COM2,"\r\nWaiting for download...");

      load_program();
   }

   app();
}

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


I didn't made an extra header file for the fuses, but I will do that for future projects.

I really don't know why it is not working. I can't even get the ex_pcd_bootload.c to load on to the pic.

Is there a delay missing to recognize that there is something coming?

This is how Siow looks and my configurations (even when I toggle the RTS and DTR nothing changes).





I think something must be wrong with my connection because I cant even load the example apps made for the bootloader on to the pic. Not even the bootloader from microchip and the dummy app provided.

I will look what could be wrong with my connection setup.

Could it be because I am using a RS232 to USB adapter? I have edited it to COM2 with



PIC24H



Joined: 02 Mar 2015
Posts: 19

View user's profile Send private message

PostPosted: Tue Mar 03, 2015 3:23 am     Reply with quote

I think I finally have the problem. When I directly connected it to the rs232 port, without the rs232 to usb adapter it works. I can load files on to the pic with the bootloader. I dont know why my professor gave me this adapter..... Sorry for bothering you guys :( I have learned my lesson

This is an awesome forum by the way. Thanks for all the help. I'll definetly be here for some time
temtronic



Joined: 01 Jul 2010
Posts: 9233
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 03, 2015 6:08 am     Reply with quote

there are two different USB 'adapters'

1) A real RS-232 <> USB, that HAS RS-232 electronics in it,usually comes with DE-9 connector

2) a TTL<>USB adapter, does NOT have RS-232 electronics,usually has a 'header' of 10 pins, NO DE-9 connector on a cable.

#1 came out early to allow 'old' devices to be used with newer PCs that don't have real ,physical .RS-232 comports.

#2 is the $2 type used by guys like me to connect PICs to a PC. Since it is TTL comaptible, it will directly connect to the PICs I/O pins, NO 'MAX232' interface chip required.

hth
jay
PIC24H



Joined: 02 Mar 2015
Posts: 19

View user's profile Send private message

PostPosted: Tue Mar 03, 2015 6:58 am     Reply with quote

temtronic wrote:
there are two different USB 'adapters'

1) A real RS-232 <> USB, that HAS RS-232 electronics in it,usually comes with DE-9 connector

2) a TTL<>USB adapter, does NOT have RS-232 electronics,usually has a 'header' of 10 pins, NO DE-9 connector on a cable.

#1 came out early to allow 'old' devices to be used with newer PCs that don't have real ,physical .RS-232 comports.

#2 is the $2 type used by guys like me to connect PICs to a PC. Since it is TTL compatible, it will directly connect to the PICs I/O pins, NO 'MAX232' interface chip required.

hth
jay


Thanks for the info.

Got one last problem. I successfully loaded the bootloader on to the pic



When I put "Software Flow Control" on none i can upload a program to the pic without getting the "Timeout while downloading" error message.

But after is successfully uploaded the program the error led is green and the Program that should be running now is not working. After a reset den bootloader text is displayed again.



After I press the MCLR Button




My bootloader code is

Code:
#include "24HJ256GP610.h"
#fuses NOWDT, PR_PLL, HS, PUT128, NODEBUG, NOPROTECT, NOJTAG
#use delay(crystal=20MHz)

#use rs232(Baud=9600,UART2,bits=8,STREAM=COM1)

#define BUTTON PIN_F6

#define _bootloader

#include "bootloader.h"
#include "loader.c"

#org LOADER_END+1,LOADER_END+5
void app(void)
{
   while(1);
}

void main(void)
{
   if(!input(BUTTON))
   {
      fprintf(COM1, "\r\nBootloader Ver 1.0\r\n");

      fprintf(COM1, "\r\nWaiting to download...");

      load_program();
   }

   app();
}

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


and the simple program code is

Code:
#include "24HJ256GP610.h"
#include "bootloader.h"

#fuses NOWDT, PR_PLL, HS, PUT128, NODEBUG, NOPROTECT, NOJTAG
#use delay(crystal=20MHz)

#use rs232(Baud=9600,UART2,bits=8,STREAM=COM1)
#define LED PIN_A12

void initPorts(void)
{
   set_tris_a(0xEFFF);
}

void main(void)
{
   setup_oscillator(OSC_CRYSTAL, 80000000, 20000000);
   initPorts();

   while(1)
   {
      output_bit(LED,1);
      delay_ms(500);
      output_bit(LED,0);
      delay_ms(500);
   }
}


this is how i set up the com1 port

PIC24H



Joined: 02 Mar 2015
Posts: 19

View user's profile Send private message

PostPosted: Thu Mar 05, 2015 3:14 am     Reply with quote

The CCS customer support helped me and everything works fine
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