|
|
View previous topic :: View next topic |
Author |
Message |
Requan
Joined: 11 May 2008 Posts: 74
|
ex_bootload.c problem to run |
Posted: Tue Dec 18, 2012 7:16 am |
|
|
Dear All,
Please forgive me my question, but I tried 3 days to run this code but without good results(PIC18F452, 20MHz).
To observe if i in bootloader mode i send text "Ready" when program is in boot mode:
Code: |
#define defined(__PCH__)
#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C1, rcv=PIN_C2) // Jumpers: 8 to 11, 7 to 12
#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#endif
#define _bootloader
#include <bootloader.h>
#include <loader.c>
#if defined(__PCM__)
#org LOADER_END+1,LOADER_END+10
#elif defined(__PCH__)
#org LOADER_END+2,LOADER_END+20
#endif
void application(void)
{
printf("Exit...");
while(TRUE);
}
#if defined(__PCH__)
#org 0x40,0x7F
#else
#org 0x20,0x3F
#endif
void main(void) {
if(!input(PIN_B5))
{
printf("Ready...");
load_program();
}
application();
}
#ORG default
#int_global
void isr(void) {
jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}
|
i can send hex file by CCS terminal but when it finished sending nothing happen.
Code to send:
Code: |
#include <18F452.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,bits=8,parity=N,stop=1, stream = UART1)
#include "Flex_Lcd.c"
void main()
{
lcd_init(); // Always call this first.
printf(lcd_putc,"\fReady...");
fprintf(UART1,"Running...\r\n");
while(TRUE)
{
}
}
|
Could You advice me what i should to do? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Tue Dec 18, 2012 10:49 am |
|
|
comments..
1) Have you proved your 'code to send' to PIC works if you bypass the bootloader code? Just a regular 'compile and download' via MPLAB?
2) Remove the 'if defined ....' code from the bootloader and just use cose that is applicable to your compiler. This 'trims' down the code to what IS required, as the odds are you're only using one compiler type and one PIC type.
3) You should always add 'errors' to the #use rs232(....) options. This keeps the hardware UART from 'locking up' due to errors,like overrun.
hth
jay |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Dec 18, 2012 5:02 pm |
|
|
4) Remove this line: Code: | #define defined(__PCH__) | It is set inside the compiler and you are not supposed to set it yourself.
5) Give your bootloader the same fuses as the application code. Most bootloaders can not change the fuses. |
|
|
ronaldoklais
Joined: 18 Dec 2012 Posts: 13
|
|
Posted: Tue Dec 18, 2012 8:07 pm |
|
|
Move include of bootloader.h to second code. |
|
|
Requan
Joined: 11 May 2008 Posts: 74
|
|
Posted: Wed Dec 19, 2012 7:18 am |
|
|
Thanks for replies.
Previously i removed: "if defined", but without results.
I put the same fuse but no effects.
Quote: | Have you proved your 'code to send' to PIC works if you bypass the bootloader code? Just a regular 'compile and download' via MPLAB? |
Yes, code it works
Quote: | Move include of bootloader.h to second code. |
no results |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Dec 19, 2012 8:03 am |
|
|
Post your compiler version number.
Post your code as it is now with all recommendations applied. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Wed Dec 19, 2012 8:45 am |
|
|
So, have you added bootloader.h to the 'program to run'?. It won't work without this. It needs to be:
Code: |
#include <18F452.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,bits=8,parity=N,stop=1, stream = UART1,ERRORS)
#include <bootloader.h>
#include "Flex_Lcd.c"
void main() {
//I would pause a little here
delay_ms(100);
lcd_init(); // Always call this first.
printf(lcd_putc,"\fReady...");
fprintf(UART1,"Running...\r\n");
while(TRUE) {
}
}
|
It sounds as if your bootloader is actually working (otherwise you wouldn't be able to send the code), but then the 'main' program is not being located where it needs to be. This is what bootloader.h 'does'. It changes operation according to whether '_bootloader' is defined. It must be present in both the bootloader, and the application code, and must be before things like flex_lcd are loaded.
Simplify the bootloader to:
Code: |
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,ERRORS) // Jumpers: 8 to 11, 7 to 12
#define _bootloader
#include <bootloader.h>
#include <loader.c>
#org LOADER_END+2,LOADER_END+20
void application(void) {
printf("Exit...");
while(TRUE);
}
#org 0x40,0x7F
void main(void) {
if(!input(PIN_B5))
{
printf("Ready...");
load_program();
}
application();
}
#ORG default
#int_global
void isr(void) {
jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}
|
Best Wishes |
|
|
ronaldoklais
Joined: 18 Dec 2012 Posts: 13
|
|
Posted: Wed Dec 19, 2012 12:12 pm |
|
|
When you add code to the bootloader program (first code), the length of the program are increased. Then, the loader jump to incorrect address of you program.
Try remove the two printf. |
|
|
Requan
Joined: 11 May 2008 Posts: 74
|
|
Posted: Thu Dec 20, 2012 1:04 am |
|
|
Sorry, I wrong understand that i have to add bootloader.h to second code. Now its works, thanks a lot for help |
|
|
Requan
Joined: 11 May 2008 Posts: 74
|
|
Posted: Thu Dec 20, 2012 7:49 am |
|
|
Let me ask something more:
I would like to modify program to enter in bootloader mode via rs232 command (instead button).
In main program when I receive command e.g “BOOT” I set data in eeprom and reset cpu.
In bootloader program I checked eeprom, send response via rs232, reset data in eeprom and perform bootloading.
Problem is ROM in PIC18f452 is to small to do all thinks above in bootloader program.
Second idea is after each reset, wait e.g. 5s for bootloader command from rs232 but I think is not good solution.
Could You advise me better idea?
Best Regards,
Martin |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Dec 20, 2012 12:28 pm |
|
|
I could write a whole book on bootloaders, but for now let's keep it simple.
Both of your ideas can be realised and will work, but the first idea of setting a flag in EEPROM to trigger the bootloader is perhaps some overkill and more programming effort. This type of procedure is used when you first upload the new program to some kind of 'extra' memory and then on reboot have the bootloader copy the program data from the 'extra' memory to the correct internal memory location. The 'extra' memory, for example, can be spare internal memory like in modern PC BIOSes or an external storage like SD card. This procedure can be very useful for some applications but is perhaps overkill for your purpose.
The second idea is easier to implement. However, you don't want to have a 5 second delay on every reboot. I would reduce the wait time to 1 second and choose a key which has auto-repeat on the user's PC, for example the space bar.
On startup wait a maximum of 1 second for the 'space' character and when you've seen a few of these characters passing by, let's say 3, then you enter the bootloader routine.
A third option for you to consider is to supply the end user with a dedicated bootloader program that will guide him through the upgrade process. This requires the end user to install a special program on his PC but gives more flexibility and all kinds of error checking.
It's been a while since I've been working on bootloaders and I get the impression not a lot of new development is going on, but one of the proven projects is Tiny Bootloader. Worth a look.
One of my draw backs against the Tiny Bootloader is that he doesn't provide the source code to the Windows program. This has now been solved by a new Google Project where they use the same communication protocol as Tiny Bootloader: http://code.google.com/p/pic-bootloaders/ |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Dec 20, 2012 2:10 pm |
|
|
If you have control of the hardware, one other option, is to use another pin, and the second channel of the MAX232. Wire this to detect (or use a resistor divider and diode), the DTR/DSR line. The just have your bootloader look for this being active on boot. No delay, and no button. Just connect the port, and have your PC code set the port 'ready'.
Best Wishes |
|
|
Requan
Joined: 11 May 2008 Posts: 74
|
|
Posted: Sun Dec 23, 2012 12:35 pm |
|
|
Thanks for response.
Could You also tell me why for bootloader we use RAM memory only?
in example for 18F452 we have:
so to end of RAM. Whats happen when i increase memory to 8F to fit my code for PIC18F46k20?
I read in one of ckielstra's post that it posible to use #locate to use RAM so what will be safe memory value for pic18F46k20?.
Best Regards,
Martin |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Sun Dec 23, 2012 12:47 pm |
|
|
Nothing to do with RAM.
#ORG, is controlling the ROM placement of the code, not the RAM.
You can enlarge it (will have to for a more complex bootloader), but then if you go more than a few bytes will have to increase the space reserved in bootloader.h (make your own copy, and change this, not the original).
Quote from this file:
"LOADER_END and LOADER_SIZE may need to be adjusted for a specific chip and bootloader."
Best Wishes |
|
|
Requan
Joined: 11 May 2008 Posts: 74
|
|
Posted: Wed Dec 26, 2012 12:27 pm |
|
|
Ttelmah
I apologize for my (as always) stupid question but how i will find out about loader size and where it end - by experiments only?
Best Regards,
Martin |
|
|
|
|
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
|