View previous topic :: View next topic |
Author |
Message |
VanHauser
Joined: 03 Oct 2005 Posts: 88 Location: Ploiesti, Romania
|
"Invalid #org range" |
Posted: Sat Jan 21, 2006 11:01 am |
|
|
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
|
|
Posted: Sun Jan 22, 2006 12:07 am |
|
|
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
|
|
Posted: Sun Jan 22, 2006 7:43 am |
|
|
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 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
|
|
Posted: Sun Jan 22, 2006 8:49 am |
|
|
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
|
|
Posted: Mon Jan 23, 2006 8:48 am |
|
|
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
|
|
Posted: Mon Jan 23, 2006 9:39 am |
|
|
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
|
Success (so far) |
Posted: Mon Jan 23, 2006 3:32 pm |
|
|
#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
|
getting there but not quite |
Posted: Mon Jan 23, 2006 4:26 pm |
|
|
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
|
|
Posted: Mon Jan 23, 2006 4:51 pm |
|
|
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
|
|
Posted: Mon Jan 23, 2006 6:50 pm |
|
|
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
|
|
Posted: Tue Jan 24, 2006 2:36 am |
|
|
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
|
|
Posted: Wed Jan 25, 2006 3:29 am |
|
|
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 |
|
|
|