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

Bootloader restart in loop when no program is loaded : How ?

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



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

Bootloader restart in loop when no program is loaded : How ?
PostPosted: Mon Nov 05, 2012 9:29 am     Reply with quote

Hi everybody !

I have a problem with my electronic system and I need your help Smile

Description of the Electronic part :

one PIC18F2550
one quartz 20MHz
battery 3.7V always connected
USB is used to charge the battery and connect to the pic to load program via bootloader
pin_a5 detect if USB is connected
pin_a1 is the only switch I have
NO MCLR, no external system to restart the PIC

In normal used (bootloader and program load):

- usb deconnected : program runs, even if the PIC restart, the bootloader don't try to load a new program.
- usb connected, switch off : program runs, battery charges
- usb connected, switch on : program detect it, restart, in bootloader start to charge new program

PROBLEM :

How to do the first time I need to load the program ?

I need that when there is no program loaded, the PIC restart and check USB and switch again and again.

Thanks for your help,
sorry for my english
Ttelmah



Joined: 11 Mar 2010
Posts: 19512

View user's profile Send private message

PostPosted: Mon Nov 05, 2012 9:41 am     Reply with quote

When you program the bootloader, it does a jump to a dummy one line 'application'. Make this application just be the line 'restart_cpu'. If no other program has been loaded, code will keep on restarting and trying again.

Best Wishes
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Mon Nov 05, 2012 9:51 am     Reply with quote

Thanks for your interest.

It the idea, but how to code this 'restart_cpu' as default value (before the first program is loaded)?

Something like #rom int8 ... ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19512

View user's profile Send private message

PostPosted: Mon Nov 05, 2012 1:15 pm     Reply with quote

You do understand that to use a bootloader, you _have_ to program it into the chip with a conventional programmer before you can start?.
When you program this you include the restart_cpu instruction.
If you don't want to program the chips, or don't have the tools to do this, the chip suppliers will pre-program them for you (usually for a small setup fee).

Best Wishes
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Mon Nov 05, 2012 1:44 pm     Reply with quote

Yes I know what is a bootloader,
my problem is that i can not disconnect the battery, so I can not restart the pic when I want.

So the problem is how to load the bootloader AND the "reset_cpu" with the programmer at the same time, and after, be able to load the new program to replace the "reset_cpu".

So I think we have to write the "reset_cpu" where the new program will be write...
not sure I'm understandable Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 05, 2012 3:04 pm     Reply with quote

Read this discussion of different ways to tell a bootloader to go into
"bootload" mode:
http://www.ccsinfo.com/forum/viewtopic.php?t=48925
Ttelmah



Joined: 11 Mar 2010
Posts: 19512

View user's profile Send private message

PostPosted: Tue Nov 06, 2012 2:08 am     Reply with quote

spilz wrote:
Yes I know what is a bootloader,
my problem is that i can not disconnect the battery, so I can not restart the pic when I want.

So the problem is how to load the bootloader AND the "reset_cpu" with the programmer at the same time, and after, be able to load the new program to replace the "reset_cpu".

So I think we have to write the "reset_cpu" where the new program will be write...
not sure I'm understandable Smile


If you look at ex_bootloader.c you will see that it calls 'application'. In this case, 'application, is a one line routine, that sits and waits forever, doing nothing (while(TRUE);). If you replace this with reset_cpu, then instead, when no code is loaded, the chip will keep looping back to the bootloader.

Best Wishes
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Nov 06, 2012 2:49 am     Reply with quote

Hi Ttelmah,

It's exactly what I was looking for Smile THANK YOU

My other question is :

If there is a probleme when the program is downloaded (for exemple the usb cable is deconnected during download or error during downloading) How to rewrite as default this reset_cpu ?

I'm working on a system that will be used by "normal people" who just want to be able to update the system, and I want to minimize the risk of "bricking" the system.
Ttelmah



Joined: 11 Mar 2010
Posts: 19512

View user's profile Send private message

PostPosted: Tue Nov 06, 2012 4:15 am     Reply with quote

Obvious approach, is to load the page of ROM at this point (one byte after loader_end) into RAM when you start programming the chip, and if the data fails at any point, write this page back.

Best Wishes
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Nov 06, 2012 4:32 am     Reply with quote

yes, it's the idea, but I don't know how do to that,

something like :
Code:
if(load_error)
   rom_w_block(APPLICATION_START, data, 0xF);

where data is the hexa value of "reset_cpu"

where / how can I find the hexa code for "reset_cpu" ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19512

View user's profile Send private message

PostPosted: Tue Nov 06, 2012 4:44 am     Reply with quote

That's why I said read the block.
Simplest way. Put's the correct bytes in the correct location. However It's actually just a simple 'reset' instruction (data sheet) - 0x00FF.

Best Wishes
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Nov 06, 2012 4:50 am     Reply with quote

what do you mean by "read the block", i'm not sure to understand
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