| View previous topic :: View next topic |
| Author |
Message |
Guest
|
|
Posted: Fri Jan 05, 2007 4:59 am |
|
|
| pcwh Version 3.249 |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Jan 05, 2007 10:21 am |
|
|
The error is caused by you increasing the size of main() and now the segment of main overlaps with the memory segment of the bootloader. The reason it compiles in v3.249 is that in bootloader.h the size of the bootloader was fine tuned from | Code: | | #define LOADER_SIZE 0x1BF | to | Code: | | #define LOADER_SIZE 0x17F |
Then also change toor you will still have a memory overlap.
After this your memory map will look like:
0x000 - 0x003 Reset vector
0x004 - 0x006 Interrupt vector
0x007 - 0x020 rs232 handler code. Note: a bit tricky as you did not hard code this to this memory region. Add a #org to solve this.
0x020 - 0x080 Main (0x1A bytes free)
0x080 - 0x17F CCS bootloader (about 8 bytes free) |
|
 |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Mon Jan 08, 2007 1:44 am |
|
|
the reply of CCS support is:
| Quote: | | Your ORG for the loader is 0-1FF and before main() you have an ORG to place it at 20-80. These ranges overlap. You should put main above the loader and vectors. |
The loader.c was fine tuned in 3.249, you say. As I don't have that version but version 3.226, I don't have that version?
| Quote: | | 0x007 - 0x020 rs232 handler code. Note: a bit tricky as you did not hard code this to this memory region. Add a #org to solve this. |
1. What is hard code to a memory region?
2. Is this the way for the RS232 handler ?
| Code: | #org 0x7,0x1F
#use rs232 (baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, ERRORS) |
my lst file
| Code: | .................... #include <16F877A.h>
.................... //////// Standard Header file for the PIC16F877A device ////////////////
.................... #device PIC16F877A
.................... #list
....................
.................... #fuses XT, PUT, NOWDT, NOPROTECT, NOLVP, NOCPD, NOWRT, NOBROWNOUT, NODEBUG
.................... #use delay(clock=4000000)
....................
.................... #org 0x07,0x1F
.................... #use rs232 (baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, ERRORS)
*
0035: CLRF 20
*
020A: BTFSS 0C.5
020B: GOTO 20A
020C: MOVF 18,W
020D: MOVWF 20
020E: MOVF 1A,W
020F: MOVWF 78
0210: BTFSS 20.1
0211: GOTO 214
0212: BCF 18.4
0213: BSF 18.4
0214: NOP
0215: RETLW 00 |
lst of application ():
seems that the rs232 handler will be overwritten?
| Code: | .................... #org LOADER_END+1,LOADER_END+10
.................... void application (void) // Dummy functie, eigenlijk staat hier de échte main
.................... {
.................... putc ('A');
*
0200: MOVLW 41
0201: BTFSS 0C.4
0202: GOTO 201
0203: MOVWF 19
.................... while(TRUE);
0204: GOTO 204
.................... }
0205: RETLW 00 |
|
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jan 08, 2007 4:13 am |
|
|
| Quote: | | The loader.c was fine tuned in 3.249, you say. As I don't have that version but version 3.226, I don't have that version? | Right. Your v3.226 differs from v3.249 in only 1 line, see my previous post for the change to make.
| Quote: | | 1. What is hard code to a memory region? | Probably I should have used the official term 'locate' instead of 'hard code'. Anyway, what I meant to say is that you want to make sure all your bootloader code is in the memory range 0x000 - 0x1FF. For the RS232 functions no specific memory region was specified, than the compiler can choose a memory location outside your desired range.
| Quote: | 2. Is this the way for the RS232 handler ?
Code:
#org 0x7,0x1F
#use rs232 (baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, ERRORS) | Yes, that is the idea I had in mind, except that for this to work for compiler generated functions you will have to add the 'default' keyword.
| Code: | | #org 0x0007,0x001F default |
I have to say the resulting code is not the most beautiful I've ever seen, there are way to many #org statements. Many of the created memory regions have some spare bytes which is a waste of memory. Changes to the code will often lead to memory regions overflowing and result in ambiguous error messages.
It is possible to replace the several small memory regions with one big one but that would require stripping all the #org statements from the CCS provided loader.c file, not sure if you want to do that. |
|
 |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Mon Jan 08, 2007 6:39 am |
|
|
Ok, it works. You've been a great help. I'm able to download code and so reprogram the PIC. However the first instruction in main:
gives 0xE8 instead of 0x42. Any idea why that is?
| Quote: | | It is possible to replace the several small memory regions with one big one but that would require stripping all the #org statements from the CCS provided loader.c file, not sure if you want to do that. |
What do you mean by that? Is that hard to do?
Are there other ways to save ROM?
bootloader.h
| Code: | #define LOADER_END 0x1FF
#define LOADER_SIZE 0x17F
#ifndef _bootloader
#build ( reset = LOADER_END+1 , interrupt = LOADER_END+5 )
#org 0, LOADER_END {}
#endif |
bootloader.c:
| Code: | #include <16F877A.h>
#fuses XT, PUT, NOWDT, NOPROTECT, NOLVP, NOCPD, NOWRT, NOBROWNOUT, NODEBUG
#use delay(clock=4000000)
#org 0x06,0x11 default
#use rs232 (baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, ERRORS)
#define _bootloader
#include "bootloader.h"
#include "loader.c"
#org LOADER_END+1,LOADER_END+10
void application (void) // Dummy functie, eigenlijk staat hier de échte main
{
putc('A');
while(TRUE);
}
#ORG 0x12,0x6C
void main (void)
{
long timeout = 0;
putc ('B');
while ( !kbhit() && (++timeout < 50000) ) // 5 seconds
delay_us (100);
if ( kbhit() )
{
if ( getc() == 170 )
{
timeout = 0;
while ( !kbhit() && (++timeout < 50000)) // 5 seconds
delay_us (100);
if ( kbhit () )
if ( getc() == 170 )
{
putc ('B');
load_program ();
}
}
}
application (); // Jump to real application
}
#org default
#int_global
void isr (void)
{
#asm
goto LOADER_END+5
#endasm
} |
|
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jan 08, 2007 8:52 am |
|
|
| Quote: | | Are there other ways to save ROM? | Check your inbox, I can't post the code here because of CCS copyright rules. |
|
 |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Tue Jan 09, 2007 2:38 am |
|
|
Thanks, I got your message.
I managed to workaround the serial port problem.
| Code: | delay_us (50);
putc ('L'); |
But I don't understand why this works.
Seems like if you wait a short time before the putc command, it sends the right character. It seems like the PIC UART needs time to initialize.
Anyway thanks for the support on this. |
|
 |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Tue Jan 09, 2007 8:48 am |
|
|
In the original code I have a statement:
| Code: | // Adressen van registers
#define SSPCON1 0x14 |
That is the SPI configuration register on adres 0x0014. However the bootloader code is now there. On what adress is that register now? Is that 0X14 + LOADER_END? |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jan 09, 2007 9:37 am |
|
|
The PIC processor has a Harvard hardware architecture. In this computer architecture there are two separate memory busses: one for the program (ROM) and another for the data and Special Function Registers.
SFR 0x14 and Program Memory address 0x0014 are pointing to a different bus, so no overlap and nothing to be changed. |
|
 |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Tue Jan 09, 2007 9:47 am |
|
|
So this should be no problem?:
| Code: | #SEPARATE
void Disable_SPI ()
{
#ASM
BCF SSPCON1.5
#ENDASM
output_float (PIN_C3); // BR_CLOCK
//output_float (PIN_C4); // SDI
output_float (PIN_C5); // SDO
} |
|
|
 |
domdom
Joined: 06 Sep 2006 Posts: 29
|
|
Posted: Thu Mar 15, 2007 8:38 pm |
|
|
Would you like to share how your write the function load_program() and application()?
and Can you paste the load.c code? |
|
 |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Fri Mar 16, 2007 1:43 am |
|
|
| I'm afraid I can't paste CCS's code because it is copywrited. What is that you want to achieve? |
|
 |
domdom
Joined: 06 Sep 2006 Posts: 29
|
|
Posted: Fri Mar 16, 2007 7:57 am |
|
|
I am using 20mhz 16f877a and 18f4520.
Perhaps you can send to my personal email? is that ok with you?
gaston_keatmy@yahoo.com |
|
 |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Fri Mar 16, 2007 7:59 am |
|
|
| I'm sorry, if you've bought a legit copy of the compiler, you have the files.. |
|
 |
|