 |
 |
| View previous topic :: View next topic |
| Author |
Message |
GregEnReus
Joined: 18 Mar 2026 Posts: 3
|
| Strange #ORG issue |
Posted: Wed Mar 18, 2026 2:42 pm |
|
|
I've written a Bootloader.
Why?
Long story. Anyway, it works perfectly. I want to locate it at the top of the memory space.
This compiles:
#build(Reset=0x1700, Interrupt=0x0008:0x0018)
#org 0x0010,0x16FF {}
#org 0x0000, 0x0006
void ForceResetVector() {
#asm
GOTO 0x1700
#endasm
}
Not only does it compile but the application also works. Perfectly.
There's plenty of room above the compiler code but this does not compile:
#build(Reset=0x1800, Interrupt=0x0008:0x0018)
#org 0x0010,0x17FF {}
#org 0x0000, 0x0006
void ForceResetVector() {
#asm
GOTO 0x1800
#endasm
}
The compiler complains as follows:
*** Error 71 "UpperMemoryFBDPBootloader.c" Line 333(0,1): Out of ROM, A segment or the program is too large MAIN
Seg 01808-01CBE, 00AE left, need 00D2
Seg 00000-00006, 0002 left, need 00D2
Seg 00008-0000E, 0008 left, need 00D2
Seg 00010-017FE, 17F0 left, need 00D2
Seg 01800-01806, 0004 left, need 00D2
Any insight as to my stupidity in this will be thankfully received. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9629 Location: Greensville,Ontario
|
|
Posted: Wed Mar 18, 2026 2:53 pm |
|
|
| wild guess... have you totally erased the PIC ? |
|
 |
asmallri
Joined: 12 Aug 2004 Posts: 1662 Location: Perth, Australia
|
| Re: Strange #ORG issue |
Posted: Wed Mar 18, 2026 6:32 pm |
|
|
| GregEnReus wrote: | I've written a Bootloader.
Why?
Long story. Anyway, it works perfectly. I want to locate it at the top of the memory space.
..
Any insight as to my stupidity in this will be thankfully received. |
You did not mention what PIC you are using. From the output it looks like you are out or program memory.
I assume you are not using interrupts in the bootloader. If this is the case then yuo do not need the interrupt declaration in the build statement. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
 |
GregEnReus
Joined: 18 Mar 2026 Posts: 3
|
| Re: Strange #ORG issue |
Posted: Thu Mar 19, 2026 3:28 am |
|
|
Hello Andrew, from Brush Electronics no less!
Thank you for taking the time to reply.
| asmallri wrote: |
You did not mention what PIC you are using. From the output it looks like you are out or program memory.
I assume you are not using interrupts in the bootloader. If this is the case then yuo do not need the interrupt declaration in the build statement. |
18F1320
Why?
That's what I had in the parts box.
I found when writing the bootloader that the only way I could make it work was to totally avoid interrupts. The code polls the soft UART.
For a long time, when I tried this:
#build(Reset=0x1700), with any combination of #org, the compiler would complain. Now for some inexplicable reason it compiles! So thanks for the Andrew, that's awesome.
So then, this compiles:
#build(Reset=0x1700)
#org 0x0010,0x16FF {}
#org 0x0000, 0x0006
void ForceResetVector() {
#asm
GOTO 0x1700
#endasm
}
And the program memory looks like this:
0000 EF80 F00B 0C00 FFFF FFFF FFFF FFFF FFFF ........ ........
The application starts at 0x1700:
1700 EF7D F00D FFFF FFFF 6AF7 0F18 6EF6 0E17 }....... .j...n..
1710 22F7 0009 50F5 0012 4246 5044 5620 2E31 ."...P.. FBDP V1.
1720 3632 0000 860B 9093 9093 808A 0E50 6ED3 26...... ....P..n
1730 50D3 6A3B 6A3A 6A39 0E01 6E38 9093 908A .P;j:j9j ..8n....
1740 EFCC F00D C04B F04D C04A F04C C04D F003 ....K.M. J.L.M...
The application ends at 0x1BCA:
1B90 960B 6A40 6A41 D5C6 0E00 BA9E 0E01 0801 ..@jAj.. ........
1BA0 E101 D73A A60B D00F 960B 6A41 0E1B 6E40 ..:..... ..Aj..@n
1BB0 6A42 5042 DDA9 2A42 6E00 6E43 D749 0E0A BjBP..B* .nCnI...
1BC0 5C42 E1F7 DDDA D753 D7E7 D7FF FFFF FFFF B\....S. ........
1BD0 FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF ........ ........
We then have blank memory all the way up to 0x1FFF:
1FC0 FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF ........ ........
1FD0 FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF ........ ........
1FE0 FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF ........ ........
1FF0 FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF ........ ........
If I then try to push the code further up to 0x1800 the compiler complains with:
*** Error 71 "UpperMemoryFBDPBootloader.c" Line 334(0,1): Out of ROM, A segment or the program is too large MAIN
Seg 01808-01CBE, 00C6 left, need 00D2
Seg 00000-00006, 0002 left, need 00D2
Seg 00008-0000E, 0008 left, need 00D2
Seg 00010-017FE, 17F0 left, need 00D2
Seg 01800-01806, 0004 left, need 00D2
1 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Thu Mar 19 09:52:50 2026
After some more digging around I think it may be that the compiler is reserving the "tail end" of the memory for internal library functions, stack space, or its own specialised "startup" code that it doesn't want the #ORG pragma to trample on.
I tried replacing the code with a 1 line application that just turns B0 on.
I managed to push it all the way up to 0x1C00 but that's still 1k shy of the 8k memory space limit.
Interesting. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9629 Location: Greensville,Ontario
|
|
Posted: Thu Mar 19, 2026 5:45 am |
|
|
hmm,
Seg 01800-01806, 0004 left, need 00D2
doesn't this mean the segment( memory) starting at 1800 is only 7 bytes long ? and you need a lot more ??
would need to see the datasheet to see the 'memory map'.. but I've got 3000# of steel to relocate first.... |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20052
|
|
Posted: Thu Mar 19, 2026 8:00 am |
|
|
One big thing is that the PIC18, only allows RESET to be to the base of
memory. To use a high memory boot loader, you would need a reset handler
at the bottom of memory that then jumps to the high memory boot-loader.
It can be done, but all uses extra space, since this re-vector code at the
bottom of memory has to be protected as well as the boot loader itself.
This is why low memory boot loaders are really the 'standard' for the PIC. |
|
 |
jeremiah
Joined: 20 Jul 2010 Posts: 1409
|
| Re: Strange #ORG issue |
Posted: Thu Mar 19, 2026 8:29 am |
|
|
| GregEnReus wrote: | I've written a Bootloader.
Why?
Long story. Anyway, it works perfectly. I want to locate it at the top of the memory space.
This compiles:
#build(Reset=0x1700, Interrupt=0x0008:0x0018)
#org 0x0010,0x16FF {}
#org 0x0000, 0x0006
void ForceResetVector() {
#asm
GOTO 0x1700
#endasm
}
Not only does it compile but the application also works. Perfectly.
There's plenty of room above the compiler code but this does not compile:
#build(Reset=0x1800, Interrupt=0x0008:0x0018)
#org 0x0010,0x17FF {}
#org 0x0000, 0x0006
void ForceResetVector() {
#asm
GOTO 0x1800
#endasm
}
The compiler complains as follows:
*** Error 71 "UpperMemoryFBDPBootloader.c" Line 333(0,1): Out of ROM, A segment or the program is too large MAIN
Seg 01808-01CBE, 00AE left, need 00D2
Seg 00000-00006, 0002 left, need 00D2
Seg 00008-0000E, 0008 left, need 00D2
Seg 00010-017FE, 17F0 left, need 00D2
Seg 01800-01806, 0004 left, need 00D2
Any insight as to my stupidity in this will be thankfully received. |
So I took your second chunk you said wasn't working, tossed into a file with an empty main() and it compiled in both versions 5.025 and 5.119 for me without errors. Here is the file:
| Code: |
#case
#include <18F1320.h>
#build(Reset=0x1800, Interrupt=0x0008:0x0018)
#org 0x0010,0x17FF {}
#org 0x0000, 0x0006
void ForceResetVector() {
#asm
GOTO 0x1800
#endasm
}
void main(){
while(TRUE);
}
|
And the results:
| Code: |
Memory usage: ROM=0% RAM=2% - 2%
0 Errors, 0 Warnings.
Build Successful.
|
So maybe something else in your file is causing issues? |
|
 |
GregEnReus
Joined: 18 Mar 2026 Posts: 3
|
| Re: Strange #ORG issue |
Posted: Thu Mar 19, 2026 10:36 am |
|
|
| jeremiah wrote: | | So maybe something else in your file is causing issues? |
Hello Jeremiah,
Let's have a look....
#include <18F1320.h>
#build(Reset=0x1800, Interrupt=0x0008:0x0018)
#org 0x0010,0x17FF {}
#org 0x0000, 0x0006
void ForceResetVector() {
#asm
GOTO 0x1800
#endasm
}
void main(){
while(TRUE);
}
Yes, that compiles. But this doesn't:
#include <18F1320.h>
#build(Reset=0x1E00, Interrupt=0x0008:0x0018)
#org 0x0010,0x1DFF {}
#org 0x0000, 0x0006
void ForceResetVector() {
#asm
GOTO 0x1E00
#endasm
}
void main(){
while(TRUE);
}
Your code is a basically a While loop, it requires 32 bytes of program memory. The highest it will go without the compiler complaining is:
#build(Reset=0x1C00, Interrupt=0x0008:0x0018)
#org 0x0010,0x1BFF {}
#org 0x0000, 0x0006
void ForceResetVector() {
#asm
GOTO 0x1C00
#endasm
}
void main(){
while(TRUE);
}
From 0x1C00 to 0x1FFF is 1k bytes.
Anyway, it is as it is. It's fine. Thanks for taking the time to look at this. I will no doubt be able to shrink my bootloader code and then I'll be able to push it a little further up.
Golden  |
|
 |
|
|
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
|