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

How to build a bootloader on RS485 network?

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



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

How to build a bootloader on RS485 network?
PostPosted: Thu Oct 10, 2013 8:21 pm     Reply with quote

Dear all.
I have a project to build a system data manager using RS485 Network.
All nodes will be controlled by PC.
And I want to use a bootloader to upgrade firmware for nodes.
I refer to an example ( ex_bootload.c and ex_bootloader.c) by CCS but the problem is it doesn't have a control pin on RS232 COMport to control bootloader process.
I used TX and RX Bus individual.
All nodes used PIC18F4680, and i write code on CCS C 5.012.
Pls show me an example bootloader for PIC18F to refer to, or tell me a way to solve it ?
Thanks all.
_________________
Begin Begin Begin !!!
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Fri Oct 11, 2013 2:51 am     Reply with quote

You answered your own question

Quote:
is it doesn't have a control pin on RS232 COMport to control bootloader process


You have some programming to do.
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Sat Oct 26, 2013 7:17 pm     Reply with quote

Hi.
I tried bootloader with CCS C but it don't work. I tested on PIC16F877A.
Have you tried with this bootloader example of CCS C?
I think I solve this problem by re-using this example to build bootloader, insert command to control PIC enter bootloader, replace checking low level on PIN B4.
Pls help me.
Thanks
_________________
Begin Begin Begin !!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Oct 27, 2013 9:48 am     Reply with quote

You are the only one who can do this....

RS485, is a hardware specification, not a 'data format'. So what you can do, will be totally down to how you design the format.

How it can be done will depends on your configuration.

However some suggestions:

1) Design a data packet, which sets the device to 'bootloader mode'. Main PIC code would have to receive it, and when it is seen, it sets a flag in perhaps the EEPROM, and reboots the card, which then wakes up and enters the bootloader. Then in your PC code, you would send this packet, wait for a moment while the card reboots, then send the new code. When the program completes have the bootloader clear the flag. So the EEPROM byte replaces using the external signal.

2) Do it with a 'pause' when power is applied. During this time, the card listens for a data packet with it's address, and if this is seen, continues in the bootloader. If not, after a second or so, it switches to normal operation.

Key thing to remember, is that a hardware 'switch' or jumper, is inherently difficult to accidentally trigger, but any 'software' solution, needs to be carefully written if accidental changes are to be avoided.... This is why the example uses the hardware solution.

Best Wishes
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Oct 27, 2013 7:12 pm     Reply with quote

Thank you,Ttelmah Smile
I begin learn to work with bootloader(BLD) for my project.
In my project, on main bus RS485, I controlled all node by command, so that, I think I will choose the 1st idea of you to build BLD.
So, I want to tried with BLD example of CCS, next, I will replace "hard ware condition" by "soft command" to enter BLD follow you instruction.
The problems when i tried with BLD of CCS is after program user application finish and reset, PIC until run with BLD software, not boot to user software.

I used CCS C ver 5.012, PIC16F877A and edited code as follow:

1) BLD code:
Code:

#if defined(__PCM__)
#include <16F877A.h>
#fuses NOWDT
#use delay(crystal=10MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define PUSH_BUTTON PIN_b4

#elif defined(__PCH__)
#include <16F877A.h>
#fuses NOWDT
#use delay(crystal=10MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define PUSH_BUTTON PIN_b4
#endif

#define _bootloader

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

#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);
}

void main(void)
{
   printf("\n\r test boot loader ");
   if(!input(PUSH_BUTTON))
   {
      printf("\r\nBootloader Version 1.0\r\n");
   
      // Let the user know it is ready to accept a download
      printf("\r\nWaiting for download...");
      load_program();
   }

   application();
}

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


2. User application code:
Code:

#include <16F877A.h>
#fuses NOWDT
#use delay(crystal=10MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
//!#endif

#include <bootloader.h>

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

   while(TRUE)
   {
      printf("\n\r %u ",++i);
       delay_ms(1000);
   }
}



Pls show me way to test it final, I reference with another instructions in forum but it still not work.
Links:

http://www.ccsinfo.com/forum/viewtopic.php?t=40920
http://www.ccsinfo.com/forum/viewtopic.php?t=45044&start=6
_________________
Begin Begin Begin !!!
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