View previous topic :: View next topic |
Author |
Message |
spilz
Joined: 30 Jan 2012 Posts: 219
|
Bootloader restart in loop when no program is loaded : How ? |
Posted: Mon Nov 05, 2012 9:29 am |
|
|
Hi everybody !
I have a problem with my electronic system and I need your help
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: 19498
|
|
Posted: Mon Nov 05, 2012 9:41 am |
|
|
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
|
|
Posted: Mon Nov 05, 2012 9:51 am |
|
|
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: 19498
|
|
Posted: Mon Nov 05, 2012 1:15 pm |
|
|
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
|
|
Posted: Mon Nov 05, 2012 1:44 pm |
|
|
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 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Tue Nov 06, 2012 2:08 am |
|
|
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 |
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
|
|
Posted: Tue Nov 06, 2012 2:49 am |
|
|
Hi Ttelmah,
It's exactly what I was looking for 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: 19498
|
|
Posted: Tue Nov 06, 2012 4:15 am |
|
|
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
|
|
Posted: Tue Nov 06, 2012 4:32 am |
|
|
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: 19498
|
|
Posted: Tue Nov 06, 2012 4:44 am |
|
|
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
|
|
Posted: Tue Nov 06, 2012 4:50 am |
|
|
what do you mean by "read the block", i'm not sure to understand |
|
|
|