|
|
View previous topic :: View next topic |
Author |
Message |
pasini
Joined: 12 Dec 2005 Posts: 50 Location: Curitiba - Brazil
|
External memory+bootloader -> problem #org |
Posted: Thu Mar 23, 2006 6:45 am |
|
|
PIC18F8680 MPLAB 7.31 CCS 3.241
I have a bootloader running in the internal memory of PIC and it is supposed to program the real app code to the external Flash program memory. External memory begins at 0x10000 and goes up to 0x80000 (19bits of address - 512kwords). The configuration I want is EMCU extended microcontroller mode, with internal and external program memories.
The problem is when I write the real code (that is supposed to begin at 0x10000) with #org directive.
My code is:
Code: |
#include "18f8680.h"
#device *=16 ADC=10
//#fuses HS,NOWDT,NOPROTECT,NOLVP
#fuses HS,NOWDT,NOPUT,NOPROTECT,BROWNOUT,NOLVP,NOCPD,NOWRT,EMCU//,WAIT //,NODEBUG
#use delay(clock=20000000)
#use rs232(stream=RS232,baud=9600,xmit=PIN_C6,rcv=PIN_C7,parity=N,bits=8)
//#use FAST_IO (C)
#case
#build(memory=0x10000:0x80000)
#define BASE 0x010000
#define BUZZER PIN_C2
#define LigaBuzzer() output_high(BUZZER)
#define DesligaBuzzer() output_low(BUZZER)
#org 0x10000
void retorno_isr(void)
{
/* #asm
MOVFF 0F,00
MOVFF 10,01
MOVFF 11,02
MOVFF 12,03
MOVFF 13,04
MOVFF 0D,FE9
MOVFF 08,FEA
MOVFF 09,FE1
MOVFF 0A,FE2
MOVFF 0B,FD9
MOVFF 0C,FDA
MOVFF 14,FF3
MOVFF 15,FF4
MOVFF 16,FFA
MOVFF 05,FE8
MOVFF 07,FE0
MOVFF 06,FD8
RETFIE 0
#endasm
*/
}
#org 0x10100, 0x101FE
void TIMER0_isr(void)
{
#asm
goto 0x10000
#endasm
}
#org 0x10200, 0x102FE
void TIMER2_isr(void)
{
#asm
goto 0x10000
#endasm
}
#org 0x10300, 0x103FE
void main(void)
{
while(1)
{
LigaBuzzer();
delay_ms(25);
DesligaBuzzer();
delay_ms(25);
}
}
|
and the output errors are ( repeated erros, displaying just one -> same erros for different memory locations)
Quote: |
--- Info 300 "teste.c" Line 44(1,8): More info: Attempted to create: 10100-101FE for #org
*** Error 126 "teste.c" Line 44(1,8): Invalid ORG range
|
Why is the #org range incorrect ?
If I do not include the #org statement and use the bootloader to offset the addresses to external memory it does not compile too because code is located in the interrupt vectors locations.
Please, any suggestions ?
Thanks in advance for any help.
Pasini |
|
|
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
|
Posted: Thu Mar 23, 2006 7:10 am |
|
|
I think this happens because the CCS compiler knows the device only has 64k of available address space (i.e. the internal flash).
Since you're using the external memory at address 0x10000 (i.e. 64k and above), the compiler is saying you're not allowed to do that !!
I believe this has been covered in the past, and you can "fool" the compiler by making your own version of the chip using the Chip Edit tool. With this new version of the device, you simply make the address range bigger, hence fooling the compiler into thinking it's okay to place code above the 64k boundary. |
|
|
pasini
Joined: 12 Dec 2005 Posts: 50 Location: Curitiba - Brazil
|
|
Posted: Thu Mar 23, 2006 8:35 am |
|
|
How do I create a new device ? I never did that.
I tried copying the PIC18F8680 to _PIC18F8680 and change the memory size but the device is not shown in the device list.
Do I have to to change device.dat ? How do I do this ?
Will it work to solve my problem ? Have you tried this before ?
Thanks
Pasini |
|
|
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
|
Posted: Thu Mar 23, 2006 9:01 am |
|
|
Using the device editor, I copied the 18F8622 device (which only has 64k of internal flash) and called it 18F8622Z.
I then edited this device and in the Memory -> Program (words) entry, changed the size from 32768 to 131072. This fools the compiler into thinking the device has 256k of internal flash to play with !!).
I then copied the 18F8622.h header file, and called it 18F8622Z.h.
In this new header file, I changed the line :
to Code: | #device PIC18F8622Z |
The following code then compiles ...
Code: | #include <18F8622Z.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC //Internal RC Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES MCU //Microcontroller Mode
#use delay(clock=20000000)
#org 0x10000
void main()
{
printf("Hello world!");
}
|
to give the following listing ...
Code: | CCS PCH C Compiler, Version 3.243, 32117 23-Mar-06 14:53
Filename: C:\Documents and Settings\Mark\My Documents\321.lst
ROM used: 92 bytes (0%)
Largest free fragment is 65536
RAM used: 6 (0%) at main() level
6 (0%) worst case
Stack: 1 locations
*
00000: GOTO 10000
.................... #include <18F8622Z.h>
.................... //////// Standard Header file for the PIC18F8622Z device ////////////////
.................... #device PIC18F8622Z
.................... #list
....................
.................... #device adc=8
....................
.................... #FUSES NOWDT //No Watch Dog Timer
.................... #FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
.................... #FUSES INTRC //Internal RC Osc
.................... #FUSES NOPROTECT //Code not protected from reading
.................... #FUSES NOIESO //Internal External Switch Over mode disabled
.................... #FUSES BROWNOUT //Reset when brownout detected
.................... #FUSES BORV25 //Brownout reset at 2.5V
.................... #FUSES NOPUT //No Power Up Timer
.................... #FUSES NOCPD //No EE protection
.................... #FUSES NOSTVREN //Stack full/underflow will not cause reset
.................... #FUSES NODEBUG //No Debug mode for ICD
.................... #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
.................... #FUSES NOWRT //Program memory not write protected
.................... #FUSES NOCPB //No Boot Block code protection
.................... #FUSES NOEBTRB //Boot block not protected from table reads
.................... #FUSES NOEBTR //Memory not protected from table reads
.................... #FUSES NOWRTD //Data EEPROM not write protected
.................... #FUSES NOWRTC //configuration not registers write protected
.................... #FUSES NOWRTB //Boot block not write protected
.................... #FUSES FCMEN //Fail-safe clock monitor enabled
.................... #FUSES LPT1OSC //Timer1 configured for low-power operation
.................... #FUSES MCLR //Master Clear pin enabled
.................... #FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
.................... #FUSES MCU //Microcontroller Mode
....................
.................... #use delay(clock=20000000)
....................
.................... #org 0x10000
....................
.................... void main()
.................... {
*
10000: CLRF FF8
10002: BCF FD0.7
10004: CLRF FEA
10006: CLRF FE9
10008: MOVF FC1,W
1000A: ANDLW C0
1000C: IORLW 0F
1000E: MOVWF FC1
10010: MOVLW 07
10012: MOVWF FB4
.................... printf("Hello world!");
10014: CLRF 06
10016: MOVF 06,W
10018: CALL 0008
1001C: IORLW 00
1001E: BTFSC FD8.2
10020: GOTO 10034
10024: INCF 06,F
10026: BTFSS 00.0
10028: GOTO 10026
1002C: BCF FFF.7
1002E: MOVWF 00
10030: GOTO 10016
.................... }
....................
10034: SLEEP
Configuration Fuses:
Word 1: 4900 NOIESO FCMEN INTRC
Word 2: 0E1F BROWNOUT WDT128 NOWDT BORV25 NOPUT
Word 3: 87F3 CCP2C1 LPT1OSC MCLR MCU WAIT BW16 ABW20 ECCPE
Word 4: 0080 NOSTVREN NODEBUG NOLVP NOXINST RESERVED
Word 5: C00F NOPROTECT NOCPD NOCPB
Word 6: E00F NOWRT NOWRTD NOWRTC NOWRTB
Word 7: 400F NOEBTRB NOEBTR
|
You can clearly see that the compiler puts all the code (apart from the restart vector) at address 0x10000 and above |
|
|
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
|
Posted: Thu Mar 23, 2006 9:02 am |
|
|
pasini wrote: | ... but the device is not shown in the device list. |
It should be at the end of the list !! |
|
|
pasini
Joined: 12 Dec 2005 Posts: 50 Location: Curitiba - Brazil
|
|
Posted: Mon Mar 27, 2006 7:12 am |
|
|
Ok if I include only the #org 0x10000. If I try to include other #org�s the error appears again.
Code: | #org 0x010000
void main(void)
{
while(1)
{ LigaBuzzer();
delay_ms(150);
DesligaBuzzer();
delay_ms(50);
}
}
#org 0x010500,0x10600
void timer0(void)
{
}
#org 0x010700,0x010800
void timer2(void)
{
}
|
The error is Quote: | --- Info 300 "teste.c" Line 125(1,9): More info: Attempted to create: 10700-10800 for #org
*** Error 126 "teste.c" Line 125(1,9): Invalid ORG range |
Thanks
Pasini |
|
|
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
|
Posted: Tue Mar 28, 2006 3:26 am |
|
|
If you check the CCS Reference Manual, you will see the #org syntax is as follows:-
Code: | #org start, end
or
#org segment
or
#org start, end {}
or
#org start, end auto=0
#ORG start,end DEFAULT
or
#ORG DEFAULT |
Each instance of #org must have a "start" and an "end" value, unless you are continuing a previously declared #org, in which case you can jsut specify the "start" value (which CCS call the "segment").
So in your case you must have something like ...
Code: | #org 0x010000, 0x10300 // *** NOTE THE ADDITIONAL END VALUE !! ***
void main(void)
{
while(1)
{ LigaBuzzer();
delay_ms(150);
DesligaBuzzer();
delay_ms(50);
}
}
#org 0x010500,0x10600
void timer0(void)
{
}
#org 0x010700,0x010800
void timer2(void)
{
} |
As a test, I compiled the following ...
Code: | #include <18F8680Z.h>
#org 0x10000, 0x10500
int16 fn(void) {
return(0x1234);
}
#org 0x15000, 0x15500
void main()
{
printf("Hello world!");
fn();
}
|
The resulting LST file follows, and you clearly see the reset vector is at 0x0000, which jumps straight to 0x15000, with fn() located at 0x10000.
Code: | CCS PCH C Compiler, Version 3.249, 266 28-Mar-06 10:21
Filename: C:\Documents and Settings\Mark\My Documents\321.lst
ROM used: 106 bytes (0%)
Largest free fragment is 65536
RAM used: 6 (0%) at main() level
6 (0%) worst case
Stack: 1 locations
*
00000: GOTO 15000
.................... #include <18F8680Z.h>
.................... //////// Standard Header file for the PIC18F8680 device ////////////////
.................... #device PIC18F8680Z
.................... #list
....................
....................
.................... #org 0x10000, 0x10500
....................
.................... int16 fn(void) {
.................... return(0x1234);
*
10000: MOVLW 34
10002: MOVWF 01
10004: MOVLW 12
10006: MOVWF 02
.................... }
10008: RETLW 00
....................
.................... #org 0x15000, 0x15500
....................
.................... void main()
.................... {
*
15000: CLRF FF8
15002: BCF FD0.7
15004: CLRF FEA
15006: CLRF FE9
15008: MOVF FC1,W
1500A: ANDLW C0
1500C: IORLW 0F
1500E: MOVWF FC1
15010: MOVLW 07
15012: MOVWF FB4
.................... printf("Hello world!");
15014: CLRF 06
15016: MOVF 06,W
15018: CALL 0008
1501C: IORLW 00
1501E: BTFSC FD8.2
15020: GOTO 15034
15024: INCF 06,F
15026: BTFSS 00.0
15028: GOTO 15026
1502C: BCF FFF.7
1502E: MOVWF 00
15030: GOTO 15016
....................
.................... fn();
15034: CALL 10000
.................... }
15038: SLEEP
|
Hope this gets you up and running ... |
|
|
pasini
Joined: 12 Dec 2005 Posts: 50 Location: Curitiba - Brazil
|
|
Posted: Tue Mar 28, 2006 6:08 pm |
|
|
Now I really understand what I shall do to make everything run ok.
Being sure that the external memory is properly connected to the MCU, create an alternative MCU with the extended memory. Put all the code, including the bootloader, in a single project with extended memory mode. Be careful with the #org's. Program the MCU and run the bootloader to save remaining program code.
Yes, it runs like this
Thank you all for the help. |
|
|
|
|
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
|