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

#build(reset...), missing jump at address 0 [DONE]

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



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

#build(reset...), missing jump at address 0 [DONE]
PostPosted: Wed Aug 25, 2010 8:19 am     Reply with quote

v4.014
18F2685

Bootloader
LOADER_END = 0x7FF

Hello,

after inserting

Code:

#build(reset=LOADER_END+1, interrupt=LOADER_END+9)


in my program, it will not start.

Before inserting this I have a jump to main() at address 0, see lst file:
Code:

*
00000:  GOTO   F612
*
00008:  MOVWF  05
0000A:  MOVFF  FD8,06
0000E:  MOVFF  FE0,07
00012:  MOVLB  0
00014:  MOVFF  FE9,0D
00018:  MOVFF  FEA,08
0001C:  MOVFF  FE1,09
00020:  MOVFF  FE2,0A
00024:  MOVFF  FD9,0B


After inserting this I have a jump to main() at the correct address 0800, see lst file:
Code:

*
00800:  GOTO   F610
*
00808:  MOVWF  05
0080A:  MOVFF  FD8,06
0080E:  MOVFF  FE0,07
00812:  MOVLB  0
00814:  MOVFF  FE9,0D
00818:  MOVFF  FEA,08
0081C:  MOVFF  FE1,09
00820:  MOVFF  FE2,0A
00824:  MOVFF  FD9,0B


but what i was missing is the jump to 0800 at starting address 0. I can not see anything at address 0 in the lst file but there is something at address 0 as the hex file shows at line 2: :10000000F2CF0EF0F29EF76A1E0FF66E000EF72288

Code:

:020000040000FA
:10000000F2CF0EF0F29EF76A1E0FF66E000EF72288
:10001000000EF86E0900F5500EBEF28E120050412F
:100020005300F2CF0EF0F29EF76A400FF66E000E0C


What is going on here, where is the jump to 0800? Is the missing jump the reason for that program will not start?

Best regards
nilsener


Last edited by nilsener on Thu Aug 26, 2010 6:48 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Aug 25, 2010 8:35 am     Reply with quote

Of course it won't.....

The build instruction, tells the compiler to build this code to run with the reset location at 0x800, and the interrupt 8 addresses above this.
Your _bootloader_, needs to be built at the bottom of memory, and contain the code, so that if it doesn't see the conditions saying 'load code', _it_ jumps to the 0x800 location. It also needs to vector the interrupt code up to the 0x808 location.

If you look at the ex_bootloader.c example, you will see that if it does not find the condition to perform a bootload (B5 pulled low), then it jumps to 'application', which is a dummy routine placed just after the loader end. Hence performing the jump to the 'real' code, once this is loaded. It also has a #int_global defined, that jumps to the required interrupt location in the main code.

Best Wishes
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Wed Aug 25, 2010 9:59 am     Reply with quote

Hello Ttelmah,

thanks for quick response. I am starting to understand.

Now I get the following error:

Line 7548(1,2): Duplicate Interrupt function

if I insert the #int_global statement:

Quote:

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


Do you have an idea what happens here?

best regards
nilsener
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Aug 25, 2010 2:28 pm     Reply with quote

Has your bootloader got an interrupt handler?. If so, then you will need to get more complex, and have test/branches in this....

Best Wishes
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Thu Aug 26, 2010 1:21 am     Reply with quote

Hello Ttelmah,

my bootloader is not using interrupts. I have the

Code:

disable_interrupts(GLOBAL); 


statement at the very beginning of the bootloader.

Does it mean, that I can do it without inserting the #int_global statement?:

Code:

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



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Aug 26, 2010 2:26 am     Reply with quote

No.
Get it clear what has to be where.

If your _main_ code, uses interrupts, your _bootloader_ code, must contain the code to revector the global interrupt. If your bootloader is not using interrupts, there should be no complaint from the compiler when you build _this_ with the #int_global.

Similarly, it is the bootloader code, that must contain the jump to the main code at address 0x800.

The 'main' code, is a complete program built to reside at addresses 0x800 and up, with interrupt handlers etc.. _It_ does not contain anything to connect it to the hardware vectors at the bottom of memory. This linking, is the _bootloader's_ responsibility.

So long as your booloader does not contain any interrupt calls, you can compile the _bootloader_ with the #int_global section added, without complaint.

It sounds to me as if you are trying to attach this to the main code, which already has interrupt handlers present - this _will not work_.
Again, look at the examples.

Best Wishes
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Thu Aug 26, 2010 2:59 am     Reply with quote

Ok. It seems to me that the bootloader is designed to be a stand alone in the PIC and then loading the main application. What i should do is to add the bootloader to our main application (big file with more than 7000 lines) to have bootloader and main application in one file, in order to easy program it in the chip with the Promate III programmer, later. I don't want to program the bootloader first to the chip and then loading the main application as it is not suitable for production. If possible it should be done without using the #IMPORT statement to import a HEX-File into the project.

I have interrrupts in the main application and I think this is why I get the "Duplicate Interrupt function" error while inserting the #int_global statement:

Code:

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


Do you have any further suggestions what to do?
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Aug 26, 2010 4:24 am     Reply with quote

Yes,
You do not 'add' the bootloader to the main.
What you do, is build a standalone bootloader, and a standalone main. Then, use MPLAB, and load the bootloader hex file. Then load the main hex file.
This gives you an image in memory, with _both_ programs present.
You then export this.
Program using this exported file.

Best Wishes
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Thu Aug 26, 2010 4:52 am     Reply with quote

OK. Is it necessary to make some #ORG modifications in the main application? I mean to #ORG the main application to LOADER_END+1 and to reserve the bootblock with #ORG 0,LOADER_END {} ? I think it must be sure that there is no address overlap from bootloader and main application?!
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Thu Aug 26, 2010 6:48 am     Reply with quote

Ok, I have it, it is running. The #ORG modification makes the bootloader.h for me, I have to include it into the main application. I was completely on the wrong way by trying to make all in one file. I learned a lot in this thread, thank you very much Ttelmah, you are my hero Smile

Best regards
nilsener
Delfy_Coltech



Joined: 25 Nov 2009
Posts: 27
Location: Vietnam

View user's profile Send private message Visit poster's website

Bootloader and main app. all in one?
PostPosted: Wed Dec 29, 2010 10:41 pm     Reply with quote

Good morning,

I am studying to make bootloader for dsPIC using CCS PCD Compiler ver. 4.107.
I have a question is: What do I have to do to combine bootloader and main application all in one?

I see, we have to use #ORG, but i can't understand throughly.
Can you explain clearly? Thanks a lot! ^^
_________________
-------------------------------------------------
Mechatronics Department, Coltech, VNUH
Hanoi, Vietnam.
-------------------------------------------------
nilsener



Joined: 06 Dec 2005
Posts: 59

View user's profile Send private message

PostPosted: Fri Dec 31, 2010 8:46 am     Reply with quote

Hello,

you have to handle the bootloader and your main application as two different projects. Modify the CCS bootloader example if necessary to fit your requirements. The #org statement in the CCS bootloader example tells the compiler that the bootloader should be located into the bootblock of the PIC. Modify the addresses of the #org statement if necessary. Compile the bootloader.

Then insert the following lines in your main application after the #fuses line (path is where your bootloader is on hard disk):


Code:

#include "C:\path\bootloader.h"

#import (FILE=C:\path\bootloader.HEX,HEX,RANGE= 0 : 0x1FFF)


The #org statement in the bootloader.h tells the compiler to put your main application outside the bootblock of the PIC because this place is reserved for the bootloader.

The #import statement imports the hex file of the already compiled bootloader into yor main application. Adjust the Range adresses if necessary, e.g. RANGE= 0 : LOADER_END imports the hex file from address 0 till LOADER_END. After compiling you have combined the bootloader and the main application in one file. Open the lst file of the main application with an editor and check if the hex file of the bootloader is completely imported. You will find the hex file of the bootloader at the end of the lst file.

Please let me know if you have further questions.

Best Regards
Nilsener
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