About the memory in PIC18F25k50

Status
Not open for further replies.

maniac84

Full Member level 6
Joined
Mar 4, 2012
Messages
337
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Visit site
Activity points
3,661
I faced 'section '.udata_xxx.o' can not fit the section' error and after searching through the net, we actually can create objects larger than 256 Bytes by configure the linker files like below:

Code:
DATABANK   NAME=gpr1       START=0x100             END=0x1FF
DATABANK   NAME=gpr2       START=0x200             END=0x2FF
DATABANK   NAME=gpr3       START=0x300             END=0x3FF
DATABANK   NAME=gpr4       START=0x400             END=0x4FF
DATABANK   NAME=gpr5       START=0x500             END=0x5FF

These 256-byte regions need to be combined into larger regions to fit the new sections:

DATABANK  NAME=large_udata  START=0x100  END=0x389  PROTECTED
DATABANK  NAME=large_idata  START=0x38A  END=0x519  PROTECTED
DATABANK  NAME=gpr5         START=0x51A  END=0x5FF

If I don't put the word PROTECTED, it can compile. But everytime I put the word PROTECTED, the 'cannot fit error' occurs again. Does this means my firmware really have no memory already?
 

The Optional Keyword PROTECTED is used to identify and area in RAM, that can be assigned only to a variable that are specifically identified in a source code.

I know. that's what I am trying to do. fixing the area for my variable.
but when I put 'protected' the 'does not fit error' wil appear after I compile. y?
 

hello,

have a look on this example for a 18F46K22
very easy with this MCU because a lot of RAM available..
i reserve 512 bytes RAM for a nokia LCD caracteres table..
don't forget, you can not use all of RAM databank, because the C compiler will use some udata or idtata area..

declaration in my C programm
Code:
#pragma udata NokiaBank // 2 bank = 512 bytes


const char table[480] = {
0x00,0x00,0x00,0x00,0x00, // 20 space ASCII table for NOKIA LCD: 96 rows * 5 shorts= 480 shorts
0x00,0x00,0x5f,0x00,0x00, // 21 ! Note that this is the same set of codes for character you 
0x00,0x07,0x00,0x07,0x00, // 22 " would find on a HD44780 based character LCD.  
0x14,0x7f,0x14,0x7f,0x14, // 23 # Also, given the size of the LCD (84 pixels by 48 pixels), 
0x24,0x2a,0x7f,0x2a,0x12, // 24 $ the maximum number of characters per row is only 14.  
0x23,0x13,0x08,0x64,0x62, // 25 % 
0x36,0x49,0x55,0x22,0x50, // 26 & 
0x00,0x05,0x03,0x00,0x00, // 27 ' 
0x00,0x1c,0x22,0x41,0x00, // 28 ( 
... etc ....
0x10,0x08,0x08,0x10,0x08, // 7e Right Arrow -> 
0x78,0x46,0x41,0x46,0x78}; // 7f Left Arrow <-
#pragma

and the modified linker file :
Code:
// File: 18f46k22_g.lkr
// Generic linker script for the PIC18F46K22 processor

#DEFINE _CODEEND _DEBUGCODESTART - 1
#DEFINE _CEND _CODEEND + _DEBUGCODELEN
#DEFINE _DATAEND _DEBUGDATASTART - 1
#DEFINE _DEND _DATAEND + _DEBUGDATALEN

LIBPATH .

#IFDEF _CRUNTIME
  #IFDEF _EXTENDEDMODE
    FILES c018i_e.o
    FILES clib_e.lib
    FILES p18f46k22_e.lib

  #ELSE
    FILES c018i.o
    FILES clib.lib
    FILES p18f46k22.lib
  #FI

#FI

#IFDEF _DEBUGCODESTART
  CODEPAGE   NAME=page       START=0x0               END=_CODEEND
  CODEPAGE   NAME=debug      START=_DEBUGCODESTART   END=_CEND        PROTECTED
#ELSE
  CODEPAGE   NAME=page       START=0x0               END=0xFFFF
#FI

CODEPAGE   NAME=idlocs     START=0x200000          END=0x200007       PROTECTED
CODEPAGE   NAME=config     START=0x300000          END=0x30000D       PROTECTED
CODEPAGE   NAME=devid      START=0x3FFFFE          END=0x3FFFFF       PROTECTED
CODEPAGE   NAME=eedata     START=0xF00000          END=0xF003FF       PROTECTED

#IFDEF _EXTENDEDMODE
  DATABANK   NAME=gpre       START=0x0               END=0x5F
#ELSE
  ACCESSBANK NAME=accessram  START=0x0               END=0x5F
#FI

DATABANK   NAME=gpr0       START=0x60              END=0xFF
DATABANK   NAME=gpr1       START=0x100             END=0x1FF
DATABANK   NAME=gpr2       START=0x200             END=0x2FF
DATABANK   NAME=gpr3       START=0x300             END=0x3FF
DATABANK   NAME=gpr4       START=0x400             END=0x4FF

DATABANK   NAME=NokiaBank     START=0x500               END=0x6FF
// DATABANK   NAME=gpr5       START=0x500             END=0x5FF
// DATABANK   NAME=gpr6       START=0x600             END=0x6FF
SECTION NAME=NokiaBank   RAM=NokiaBank

DATABANK   NAME=GrosseBank      START=0x700               END=0x9FF
// DATABANK   NAME=gpr7       START=0x700             END=0x7FF
// DATABANK   NAME=gpr8       START=0x800             END=0x8FF
// DATABANK   NAME=gpr9       START=0x900             END=0x9FF

SECTION NAME=GrosseBank RAM=GrosseBank


DATABANK   NAME=gprA       START=0xA00             END=0xAFF
DATABANK   NAME=gprB       START=0xB00             END=0xBFF
DATABANK   NAME=gprC       START=0xC00             END=0xCFF
DATABANK   NAME=gprD       START=0xD00             END=0xDFF

#IFDEF _DEBUGDATASTART
  DATABANK   NAME=gprE       START=0xE00             END=_DATAEND
  DATABANK   NAME=dbgspr     START=_DEBUGDATASTART   END=_DEND           PROTECTED
#ELSE //no debug
  DATABANK   NAME=gprE       START=0xE00             END=0xEFF
#FI

DATABANK   NAME=gprF       START=0xF00             END=0xF37
DATABANK   NAME=sfr15      START=0xF38             END=0xF5F          PROTECTED
ACCESSBANK NAME=accesssfr  START=0xF60             END=0xFFF          PROTECTED

#IFDEF _CRUNTIME
  SECTION    NAME=CONFIG     ROM=config
  #IFDEF _DEBUGDATASTART
    STACK SIZE=0x100 RAM=gprD
  #ELSE
    STACK SIZE=0x100 RAM=gprE
  #FI
#FI

and other buffer for communications
in GrosseBank area of 512 bytes (2 banks)

Code:
#define MAX_LEN1 128
#define MAX_LEN2 128
#define MAX_LEN3 128
#define MAX_LEN4 120   

#pragma udata GrossBank
static unsigned char buffer[MAX_LEN1];
static unsigned char EdfInfo[MAX_LEN2];
static unsigned char Texte[MAX_LEN3];
static unsigned char BT[MAX_LEN4];
#pragma
 


Thanks for the example. I notice you modified the memory to put "DATABANK NAME=NokiaBank START=0x500 END=0x6FF" and "DATABANK NAME=GrosseBank START=0x700 END=0x9FF". Did you try put 'PROTECTED' onto it?

For me, if I don't put 'PROTECTED', my firmware can be compile successfully. But I notice that my compiler will assign some other variable to the location I fixed. I know this can be fixed by putting the word 'PROTECTED' beside it.
But when I put 'PROTECTED', the compiler compile failed with the 'cannot fit error'. Why? Does this means that my memory is used up all?
Is it that I can fixed anywhere from grp1 to grp7? How do we know where the compiler assigned the other variables?
 
Last edited:

hello,




you want to use 1536-256= 1280 bytes for your own usage !
i think the compiler doesn't have egnough RAM area for itself !
and i think it's better to allocate modulo BANK of 256 bytes, and not cut somwhere in a BANK.
ex:
DATABANK NAME=large_udata START=0x100 END=0x4FF // 1023 bytes
DATABANK NAME=gpr5 START=0x500 END=0x5FF


what table size do you need ?
one of 650 and another one of 400 bytes ?
at the same time ?

Maybe your PIC is not appropriate for your application.
Not egnouh RAM
do you need USB ?
because PIC18F26K22 maybe can replace 25K20.

Here is my tests with PROTECTED

if i put PROTECTED ike this
DATABANK NAME=NokiaBank START=0x500 END=0x6FF PROTECTED
DATABANK NAME=GrosseBank START=0x700 END=0x9FF

i get this error
MPLINK 4.45, Linker
Device Database Version 1.10
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - section 'GrossBank' can not fit the section. Section 'GrossBank' length=0x000001f8
Errors : 1

after , if i put PROTECTED like this
DATABANK NAME=NokiaBank START=0x500 END=0x6FF
DATABANK NAME=GrosseBank START=0x700 END=0x9FF PROTECTED

i get this error
MPLINK 4.45, Linker
Device Database Version 1.10
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - section '.idata_18F46K22_EDFinfo_Nokia_BT_Archos_131127_20Mhz.o'
can not fit the section. Section .idata_18F46K22_EDFinfo_Nokia_BT_Archos_131127_20Mhz.o'
length=0x00000288
Errors : 1


Without PROTECTED, no problemo..
MPLINK 4.45, Linker
Device Database Version 1.10
Copyright (c) 1998-2011 Microchip Technology Inc.
Errors : 0

MP2HEX 4.45, COFF to HEX File Converter
Copyright (c) 1998-2011 Microchip Technology Inc.
Errors : 0

remember, in my case i have 3.5K of RAM!!!


I think PROTECTED is for compiler protection.
To avoid user program to corrupt SFR Area or DEBUG area

Other advise ?
 

Let me give another example. Below is my code:

Code:
ACCESSBANK NAME=accessram  START=0x0            END=0x5F
DATABANK   NAME=gpr0       START=0x60           END=0xFF
DATABANK   NAME=gpr1       START=0x100          END=0x1FF
DATABANK   NAME=gpr2       START=0x200          END=0x2FF
DATABANK   NAME=gpr3       START=0x300          END=0x3FF
DATABANK   NAME=gpr4       START=0x400          END=0x4FF	
DATABANK   NAME=gpr5       START=0x500          END=0x5FF
DATABANK   NAME=udata1      START=0x600          END=0x7FF			
//DATABANK   NAME=gpr7       START=0x700          END=0x7FF

DATABANK   NAME=sfr15      START=0xF53             END=0xF5F          PROTECTED
ACCESSBANK NAME=accesssfr  START=0xF60          END=0xFFF

I put my udata1 bigger memory so that can support 511 buffer.
And in the main.c file I have this:

Code:
#pragma udata udata1
static 	BYTE 	RS485RXDATA[511];

So, if I put the word 'PROTECTED' after the line 'DATABANK NAME=udata1 START=0x600 END=0x7FF', it still come out error saying ' Error - section 'udata1' can not fit the section. Section 'udata1' length=0x000001ff'.
I have to make RS485RXDATA[256] only can compile successful. Why?
 

hello,

do you have aterminateur for #pragma ?
like this
Code:
#pragma udata udata1
static 	BYTE 	RS485RXDATA[511];
[COLOR="#FF0000"][B]#pragma[/B][/COLOR]

I am working on another subject "Petite Fat for SD card"
and also use a buffer of 512 bytes
same as your case...
and add PROTECTED , no error in compiling results..

BUT MY APPLICATION DOESN'T USE A LOT OF RAM for other variable..
and this PIC has 3896 bytes of RAM !
Are you also using a debugger ? wich can use some RAM area.
Maybe your compiler need some amount of RAM , wich can overlap your reservation.


Code:
/ rev PF 8_12_2013 pour SD card 
// File: 18f26k22_g.lkr
// Generic linker script for the PIC18F26K22 processor

#DEFINE _CODEEND _DEBUGCODESTART - 1
#DEFINE _CEND _CODEEND + _DEBUGCODELEN
#DEFINE _DATAEND _DEBUGDATASTART - 1
#DEFINE _DEND _DATAEND + _DEBUGDATALEN

LIBPATH .

#IFDEF _CRUNTIME
  #IFDEF _EXTENDEDMODE
    FILES c018i_e.o
    FILES clib_e.lib
    FILES p18f26k22_e.lib

  #ELSE
    FILES c018i.o
    FILES clib.lib
    FILES p18f26k22.lib
  #FI

#FI

#IFDEF _DEBUGCODESTART
  CODEPAGE   NAME=page       START=0x0               END=_CODEEND
  CODEPAGE   NAME=debug      START=_DEBUGCODESTART   END=_CEND        PROTECTED
#ELSE
  CODEPAGE   NAME=page       START=0x0               END=0xFFFF
#FI

CODEPAGE   NAME=idlocs     START=0x200000          END=0x200007       PROTECTED
CODEPAGE   NAME=config     START=0x300000          END=0x30000D       PROTECTED
CODEPAGE   NAME=devid      START=0x3FFFFE          END=0x3FFFFF       PROTECTED
CODEPAGE   NAME=eedata     START=0xF00000          END=0xF003FF       PROTECTED

#IFDEF _EXTENDEDMODE
  DATABANK   NAME=gpre       START=0x0               END=0x5F
#ELSE
  ACCESSBANK NAME=accessram  START=0x0               END=0x5F
#FI

DATABANK   NAME=gpr0       START=0x60              END=0xFF
DATABANK   NAME=gpr1       START=0x100             END=0x1FF
DATABANK   NAME=gpr2       START=0x200             END=0x2FF
DATABANK   NAME=gpr3       START=0x300             END=0x3FF
DATABANK   NAME=gpr4       START=0x400             END=0x4FF
DATABANK   NAME=gpr5       START=0x500             END=0x5FF
DATABANK   NAME=gr6        START=0x600			   END=0x6FF
//DATABANK   NAME=gpr7       START=0x700             END=0x7FF
//DATABANK   NAME=gpr8       START=0x800             END=0x8FF
//DATABANK   NAME=gpr9       START=0x900             END=0x9FF

DATABANK   NAME=BigBuffer    START=0x700             END=0x9FF  PROTECTED
    
DATABANK   NAME=gprA       START=0xA00             END=0xAFF   
DATABANK   NAME=gprB       START=0xB00             END=0xBFF
DATABANK   NAME=gprC       START=0xC00             END=0xCFF
DATABANK   NAME=gprD       START=0xD00             END=0xDFF

#IFDEF _DEBUGDATASTART
  DATABANK   NAME=gprE       START=0xE00             END=_DATAEND
  DATABANK   NAME=dbgspr     START=_DEBUGDATASTART   END=_DEND           PROTECTED
#ELSE //no debug
  DATABANK   NAME=gprE       START=0xE00             END=0xEFF
#FI

DATABANK   NAME=gprF       START=0xF00             END=0xF37
DATABANK   NAME=sfr15      START=0xF38             END=0xF5F          PROTECTED
ACCESSBANK NAME=accesssfr  START=0xF60             END=0xFFF          PROTECTED

SECTION    NAME=BigBuffer RAM=BigBuffer


#IFDEF _CRUNTIME
  SECTION    NAME=CONFIG     ROM=config
  #IFDEF _DEBUGDATASTART
    STACK SIZE=0x100 RAM=gprD
  #ELSE
    STACK SIZE=0x100 RAM=gprE
  #FI
#FI
 

Yes. I did put the #pragma after the #pragma udata udata1.
Yes. I'm compiling while debugging. Are you sure the debugger has used the RAM. That means if I do not use the debugger, it will successfully be compiled when I use RS485RXDATA[511]. I'll try it first.

- - - Updated - - -

Nope. Still fail with the same error message when I compile without debugger.

- - - Updated - - -

Now does that means I really have not enough RAM already if I use RS485RXDATA[511]?
How do we check what is the amount of RAM used currently?
 

hello,


Have a look on "memory usage gauge "
it is not very accurate ,but will show if you have some space of ram available..

The best way to check in details :
project
build options
project
Mplink linker
coche Generate map file

Build all again
and open your *.map file
and check inside all RAM allocations..
 

Attachments

  • Mapping.jpg
    142.8 KB · Views: 106
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…