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

Bootloader and PCW compiler: memory mapping
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








PostPosted: Fri Jan 05, 2007 4:59 am     Reply with quote

pcwh Version 3.249
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Jan 05, 2007 10:21 am     Reply with quote

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
Code:
#org 0x20, 0x80
to
Code:
#org 0x20, 0x79
or 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

View user's profile Send private message

PostPosted: Mon Jan 08, 2007 1:44 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 08, 2007 4:13 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 08, 2007 6:39 am     Reply with quote

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:

Code:
putc ('B');


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

View user's profile Send private message

PostPosted: Mon Jan 08, 2007 8:52 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 09, 2007 2:38 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 09, 2007 8:48 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 09, 2007 9:37 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 09, 2007 9:47 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 15, 2007 8:38 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 16, 2007 1:43 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 16, 2007 7:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 16, 2007 7:59 am     Reply with quote

I'm sorry, if you've bought a legit copy of the compiler, you have the files..
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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