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

"Invalid #org range"

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



Joined: 03 Oct 2005
Posts: 88
Location: Ploiesti, Romania

View user's profile Send private message

"Invalid #org range"
PostPosted: Sat Jan 21, 2006 11:01 am     Reply with quote

I am using PCH version 3.241 with a 18F452. I put the following before the main() function:
Code:
#build (reset = 0x0002)
#rom 0x0000 = {0x0000}  // Put a NOP

Everything works ok, I get a NOP at first location. The problem is that I cannot allocate a function with #org between 0x7F00 and 0x7FFF. The compiler reports "invalid #org range" after the last line of the file the main() function is in. The function fits in that space. I noticed this with PCH 3.236 to 3.241. With PCH 3.235 worked. Is this a compiler bug?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 22, 2006 12:07 am     Reply with quote

I made the following program, based on your description, and it
compiles without error with PCH vs. 3.241.
Code:

#include <18F452.H>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay (clock=4000000)

#build (reset = 0x0002)       
#rom 0x0000 = {0x0000}

#org 0x7F00, 0x7FFF
void my_function(void)
{
char c;

c = 0x55;
}

//==================================
void main()
{

my_function();

while(1);
}
VanHauser



Joined: 03 Oct 2005
Posts: 88
Location: Ploiesti, Romania

View user's profile Send private message

PostPosted: Sun Jan 22, 2006 7:43 am     Reply with quote

Your program compiles ok, with and without #org default after my_function() definition. This is very weird. I noticed that if I change #build (reset = 0x0002) into #build (reset = 0x0001) (which is a stupid thing to do) my program compiles ok Shocked My #org'ed function is only 114 bytes long, so there is plenty of space for it. This function is part of a rather big program (62 K hex) and I don't use #org anywhere else in the program.

Here's the error report:
Code:
--- Info 300 "D:\...\cdl-01.c" Line 103(0,1): More info:   Segment at 00000-00000 (0000 used)
--- Info 300 "D:\...\cdl-01.c" Line 103(0,1): More info:   Segment at 00002-00008 (0004 used)  Priv
--- Info 300 "D:\...\cdl-01.c" Line 103(0,1): More info:   Segment at 0000A-07EFE (0000 used)
--- Info 300 "D:\...\cdl-01.c" Line 103(0,1): More info:   Segment at 07F00-07FFE (0000 used)  Priv
--- Info 300 "D:\...\cdl-01.c" Line 103(0,1): More info:   Attempted to create: 00008-000B6  for ISR
*** Error 126 "D:\...\cdl-01.c" Line 103(0,1): Invalid ORG range
      1 Errors,  0 Warnings.


That file is 102 lines long in reality.
VanHauser



Joined: 03 Oct 2005
Posts: 88
Location: Ploiesti, Romania

View user's profile Send private message

PostPosted: Sun Jan 22, 2006 8:49 am     Reply with quote

Problem solved:
Code:
#build (reset = 0x0002:0x0003)
#rom 0x0000 = {0x0000}  // Put a NOP

It was a compiler bug for sure. Thanks for your help, PCM Programmer.
guy



Joined: 21 Oct 2005
Posts: 297

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

PostPosted: Mon Jan 23, 2006 8:48 am     Reply with quote

I tried:
Code:
#include <18F6520.h>
#device ADC=10
#fuses HS   // SET CONFIG BEFORE PROG!
//NOOSCSEN,PUT,BROWNOUT,BORV27,WDT,WDT1,NODEBUG,PROTECT,STVREN,NOLVP,
#use delay(CLOCK=10000000)   // 10MHz

#build (reset = 0x0002:0x0003)
#rom 0x0000 = {0x0000}  // Put a NOP

#include <bootloader.h>
...


and I still get the same errors, more or less.
Also, I tried adding :
#org 0x7F00, 0x7FFF
just before the beginning of the code (this may not be sufficient for the whole code but I don't understand completely the #org statements) and it till gives the same errors...
You're right that I have many include files, some with .H and some with .C extensions, if this matters.

????
VanHauser



Joined: 03 Oct 2005
Posts: 88
Location: Ploiesti, Romania

View user's profile Send private message

PostPosted: Mon Jan 23, 2006 9:39 am     Reply with quote

You get the same errors because the reset vector defined in bootloader.h overides what you define in your code. Modify it there. There's no need to define #org's.

The section you must modify in [/b]bootloader.h[/b] looks like this:
Code:
#if defined(__PCM__)
   #build(reset=LOADER_END+1, interrupt=LOADER_END+5)
#elif defined(__PCH__)
   #build(reset=LOADER_END+2, interrupt=LOADER_END+8)
#endif


Try changing the PCH section into something like:
#build(reset=LOADER_END+2:LOADER_END+3, interrupt=LOADER_END+8:LOADER_END+17)
[/code]
I'm not sure about the interrupt vector.
guy



Joined: 21 Oct 2005
Posts: 297

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

Success (so far)
PostPosted: Mon Jan 23, 2006 3:32 pm     Reply with quote

#build(reset=LOADER_END+2:LOADER_END+3, interrupt=LOADER_END+8:LOADER_END+17)
did the trick!
Another catch was that although I copied bootloader.h to my project directory and did the changes there, the compiler used the original file (picc/drivers directory). The statement to solve this was:
#include <.\bootloader.h>

I'll keep you updated once the bootloader actually works, but thank a lot everyone, and 2 extra points for VanHauser!!!
Can you explain in a couple of sentences what was the problem and how you solved it?
guy



Joined: 21 Oct 2005
Posts: 297

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

getting there but not quite
PostPosted: Mon Jan 23, 2006 4:26 pm     Reply with quote

Ok. The bootloader works (I also had to change the connection speed - the bootloader works at 9600 and the default for CCS' SIOW download program is 19200). I read back the chip and it seems ok, but when I reset the PIC it doesn't start the program...
I don't understand the changes you asked me to do, but shouldn't the bootload routine (the one programmed into the PIC), which always executes at reset, be changed too, to point to the new ISR and reset vector locations?
If so, which lines do I change?

Guy
VanHauser



Joined: 03 Oct 2005
Posts: 88
Location: Ploiesti, Romania

View user's profile Send private message

PostPosted: Mon Jan 23, 2006 4:51 pm     Reply with quote

The rule in C/C++ is that #include "filename.h" searches first in your current directory and then in the other defined directories (Drivers for ex.), and #include <filename.h> searches only in the defined directories. But to be sure what you include, just rename your file.

I have no logical explanation for this #org problem but I would like to know what's going on too. I tried to compile CCS' examples ex_bootloader.c and ex_bootload.c. Both are compiled ok with PCH and PCM 3.236, 3.241 and 3.242.


Later edit:

To be honest with you, I've never worked with bootloaders. I looked over the examples from CCS and I couldn't find an exact answer for you. But the following might work:
#build(reset=LOADER_END+2:LOADER_END+7, interrupt=LOADER_END+8:LOADER_END+17)
guy



Joined: 21 Oct 2005
Posts: 297

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

PostPosted: Mon Jan 23, 2006 6:50 pm     Reply with quote

So - any ideas why the program doesn't run? (see my prev. post)

Thanks.
Guy
VanHauser



Joined: 03 Oct 2005
Posts: 88
Location: Ploiesti, Romania

View user's profile Send private message

PostPosted: Tue Jan 24, 2006 2:36 am     Reply with quote

Maybe the reset vector isn't long enough. Try enlarging it, and maybe the interrupt vector as well.
guy



Joined: 21 Oct 2005
Posts: 297

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

PostPosted: Wed Jan 25, 2006 3:29 am     Reply with quote

The bootloader was supposed to be sent with a prototype abroad, so I can make firmware changes remotely.
Since we got into trouble I'll send it as is, and finish the bootloader in a few days. I will then update the forum. (the client is pressing for the prototype...)
Thank you so much for the support and see you in a few days.

Guy
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