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

#use rs232 in Bootloader

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



Joined: 18 Nov 2013
Posts: 179

View user's profile Send private message

#use rs232 in Bootloader
PostPosted: Wed Jun 10, 2026 12:15 pm     Reply with quote

Does the #use rs232 setting in the bootloader file need to match the same setting in the main app?

PIC18F67K22, PCWH v5.123.
Ttelmah



Joined: 11 Mar 2010
Posts: 20164

View user's profile Send private message

PostPosted: Wed Jun 10, 2026 12:40 pm     Reply with quote

No.
You can change bud rate, format etc..
SeeCwriter



Joined: 18 Nov 2013
Posts: 179

View user's profile Send private message

PostPosted: Wed Dec 02, 2026 5:12 pm     Reply with quote

Still using the 18F67K22, and PCWH v5.125.

I have a bootloader file from another project. It seems to work as expected. I use ccsbootloader.exe (v1.6) to download my app and it appears to finish normally with no errors.
But when I reboot after removing the push_button input, the program doesn't run. I've tried multiple times with the same results.
So I looked at the example bootloader, ex_bootloader.c, and there are some differences from my bootloader, which was a modified version of an example file from an earlier compiler.

The bootloader I'm using has this:
Code:

#org LOADER_END+2, LOADER_END+4
void application(void) {
  while(TRUE);
}
...
#INT_GLOBAL
void isr( void )
{
   jump_to_isr( LOADER_END + 9 );
}


While the same code in the current example has:
Code:

#org LOADER_END+1,LOADER_END+3
void application(void) {
  while(TRUE);
}
...
#int_global
void isr(void) {
   jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}

They are both for __PCH__ devices.

I modified my bootloader to match the example loader and my application still doesn't run.
The one other difference is that my loader runs at 19200 baud while the example is 9600. I wouldn't think that would matter.

My app runs fine if I don't use the bootloader. And I do include bootloader.h when building for the bootloader.
Therefore, that suggests that either the bootloader is jumping to wrong location for my app or my app is not at the right location.
Ttelmah



Joined: 11 Mar 2010
Posts: 20164

View user's profile Send private message

PostPosted: Thu Dec 03, 2026 1:43 am     Reply with quote

Look at how 'LOADER_END' is defined. It looks as if your loader is
setting this to one lower than the current example boot loader.
The actual placement of these vectors is in the hardware.

It looks like this loader is setting it to the last _word_ address in
the boot loader, not the last byte in the boot loader.
SeeCwriter



Joined: 18 Nov 2013
Posts: 179

View user's profile Send private message

PostPosted: Thu Dec 03, 2026 9:10 am     Reply with quote

I added this line to the bootloader:
Code:

#warning Loader end: LOADER_END

Output:
Code:

Loader end: 0x4FF
SeeCwriter



Joined: 18 Nov 2013
Posts: 179

View user's profile Send private message

PostPosted: Thu Dec 03, 2026 10:46 am     Reply with quote

I found example file ex_bootloader.c, dated 2014. This is the application section:
Code:

#if defined(__PCM__)
 #org LOADER_END+1,LOADER_END+2
#elif defined(__PCH__)
 #org LOADER_END+2,LOADER_END+4
#endif
void application(void) {
  while(TRUE);
}

So this example recognizes there is a difference between PCM and PCH PICs.
The same example from PCHW v5.125 has this:
Code:

#org LOADER_END+1,LOADER_END+3
void application(void) {
  while(TRUE);
}

It doesn't care if PCM or PCH is used.
Can both be correct?
Ttelmah



Joined: 11 Mar 2010
Posts: 20164

View user's profile Send private message

PostPosted: Thu Dec 03, 2026 11:17 pm     Reply with quote

I'd have to go and read the manuals carefully. It looks as if the newer
compiler automatically makes the address align to the instruction boundary.
SeeCwriter



Joined: 18 Nov 2013
Posts: 179

View user's profile Send private message

PostPosted: Fri Dec 04, 2026 9:06 am     Reply with quote

Examining the loader lst files, shows that all instructions are placed on an even address. For example, the location of application is the same here
Code:

.................... #org LOADER_END+1,LOADER_END+3
.................... void application( void )
.................... {
....................    while( TRUE );
*
00500:  BRA    0500
00502:  RETURN 0
.................... }

as it is here
Code:

.................... #org LOADER_END+2, LOADER_END+4
.................... void application(void) {
....................   while(TRUE);
*
00500:  BRA    0500
00502:  RETURN 0
.................... }
....................

In both cases the value of LOADER_END is 0x4FF.

So it doesn't matter whether a PCM or PCH PIC used.

I used the Project Wizard to create a new bootloader, and it created the same code as my original bootloader.

Looking at my app's lst file, it is placed at 0x500:
Code:

00500:  GOTO   3F54

And the jump location is the beginning of main():
Code:

....................
.................... void main()
*
03F54:  CLRF   FF8


So I don't understand why it doesn't work.
SeeCwriter



Joined: 18 Nov 2013
Posts: 179

View user's profile Send private message

PostPosted: Fri Dec 04, 2026 9:54 am     Reply with quote

My next test was to replace my application with example file ex_bootload.c. I changed it to use the PIC I'm using, then loaded it with the bootloader. It doesn't run either.
Code:

#include <18F67K22.h>

#use delay( internal=16MHz )
//#use rs232(icd)                                  //Text through the ICD
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7) //Text through the UART

//#define BOOTLOADER_MODE2X

#include <bootloader.h>

void main(void)
{
   int8 i=0;
   
   delay_ms(100);
   
   printf("\r\nApplication Version 1.0\r\n");

   while(TRUE)
   {
      printf("%3u ",i++);
      delay_ms(300);
   }
}


Perhaps the downloading process is corrupting the code. Not sure how to prove that.
Ttelmah



Joined: 11 Mar 2010
Posts: 20164

View user's profile Send private message

PostPosted: Fri Dec 04, 2026 12:28 pm     Reply with quote

On the downloading, it is vital that XON/XOFF flow control is enabled on
the UART port you use. There is no flow control hardware for the
bootloader, and the transmission _must_ stop while the flash memory
is written.
SeeCwriter



Joined: 18 Nov 2013
Posts: 179

View user's profile Send private message

PostPosted: Fri Dec 04, 2026 12:58 pm     Reply with quote

If I'm reading the debug file correctly that ccsbootloader.exe produces, XON/XOFF chars are being used.
Example:
Code:

0000.015  Dispatch  WriteCom      00000014  :0405000013EF03F002[0D]
0000.028  Dispatch  ReadCom       00000001  [13]
0000.028  Trigger   Avail         00000001 
0000.032  Dispatch  ReadCom       00000002  [06][11]
0000.032  Trigger   Avail         00000002 
0000.033  Dispatch  WriteCom      0000001C  :080508000D0A4170706C69637B[0D]
0000.050  Dispatch  ReadCom       00000001  [13]
0000.050  Trigger   Avail         00000001 
0000.055  Dispatch  ReadCom       00000002  [06][11]
0000.055  Trigger   Avail         00000002 
0000.055  Dispatch  WriteCom      0000002C  :100510006174696F6E2056657273696F
                                            6E20312E3B[0D]
0000.081  Dispatch  ReadCom       00000001  [13]
0000.081  Trigger   Avail         00000001 
0000.086  Dispatch  ReadCom       00000002  [06][11]
0000.086  Trigger   Avail         00000002 

It looks like about 5ms between code downloads.
Ttelmah



Joined: 11 Mar 2010
Posts: 20164

View user's profile Send private message

PostPosted: Sat Dec 05, 2026 12:34 pm     Reply with quote

The point is that support for XON/XOFF, _must_ be enabled in the UART
setup on the computer you are using to send this data. A PC Uart by default
does not have support for this enabled. The boot loader sends the characters
but unless the PC handler them transmission will not pause...... Sad
SeeCwriter



Joined: 18 Nov 2013
Posts: 179

View user's profile Send private message

PostPosted: Sat Dec 05, 2026 12:52 pm     Reply with quote

Good point. But I would think that since I'm using CCS's ccsbootloader.exe app that it would take care of configuring the PC UART as needed.
In any case, I contacted CCS Tech Support and they are looking into it. I'll let you know what they come up with.
temtronic



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

View user's profile Send private message

PostPosted: Sat Dec 05, 2026 6:53 pm     Reply with quote

One thing about 'defaults'... NEVER, ever ASSUME..
Always check and confirm !!
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