[SOLVED] creat an array : unsigned short array [4] [100]

Status
Not open for further replies.

Laweack

Newbie level 6
Joined
Apr 27, 2012
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,367
Hello everybody , i tried to creat an array in 2 dimensions with the declaration :
unsigned short array [4] [100 ] ;

I use a pic 18f47j53 and i have already write a program who makes work the USB in HID like in the exemple given by Microchip.
But when i start to compile i have an error :

MPLINK 4.40, Linker
Device Database Version 1.3
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - section '.udata_main.o' can not fit the section. Section '.udata_main.o' length=0x000003a2
Errors : 1


I think its because of the size of my array because when its an array with less value the length value in the error is less important too but i absolutly need an array of (4 * 100)

Help...
 

Do you need this to be in RAM (will it change during execution)?
Can you make it a constant and write it in the flash?
 

Error - section '.udata_main.o' can not fit the section. Section '.udata_main.o' length=0x000003a2

The above line indicates the requested data section will not fit withing the available RAM. The PIC18F47J53 has 3.8k of dual use RAM for general purpose storage as well as USB implementation.

I would suggest either uploading or posting your code for review of possible optimization of the devices resources.

I would also suggest you refrain from using the integer type "short" when possible.

Code:
unsigned [COLOR="#FF0000"]short[/COLOR] array [4] [100 ];

Depending on the compiler its size can range from 1 byte to several bytes, in the case of Microchip C18 compiler the integer type "short" has a size of two bytes.

If a single byte would suffice, I would suggest using integer type unsigned char, instead.

Code:
unsigned [COLOR="#FF0000"]char[/COLOR] array [4] [100 ];


BigDog
 

hello,

i don't know the 18F45J53 , but i was facing with the same problem on a 18F26K22
witch has a big area of RAM. But i was not able to declare Table size more than 256 , without error..

In the file used by the linker ( 18f26k22.lkr for me) you can find out how the banks are managed.
To use 512 bytes, collapse 2 bank of 256 bytes
so you can declare a table of 4x100 bytes..
if it is integer (16 bits) uses 4 banks!

use a copy of original *.lkr to modify and test...


my example :
Code:
example with a PIC18F26K22
table of 350 bytes .. over than a BANK size !
so modiy the "18f26k22.lkr" file to collapse 2 BANK in only one to obtain 512 bytes available!
and give a name for this section

example 
......
DATABANK NAME=msgToSend START=0x100 END=0x2FF PROTECTED // 512 bytes
DATABANK NAME=usartBuff START=0x300 END=0x4FF PROTECTED // 512 bytes
DATABANK   NAME=gpr5       START=0x500             END=0x5FF
.... etc ..
DATABANK   NAME=gpr13      START=0xD00             END=0xDFF


SECTION NAME=msgToSend RAM=msgToSend
SECTION NAME=usartBuff RAM=usartBuff

......
renamed  as 18F26k22_a.lkr 


after in the C program

add in the project the modified file 18f26k22_a.lkr" 
to link with this file , not with the standard file.

declare a pragma idata ...

#pragma idata msgToSend 		// déclaration des tableaux dans leur mémoire respective
char msgToSend[300] = { 0 };
#pragma idata usartBuff
char inputBuffer[500] = { 0 };
#pragma idata
char *msg_ptr = &msgToSend[0];	// pointeurs pour manipuler les grands tableaux
char *buff_ptr = &inputBuffer[0]; 

... etc ...
 
Hi everybody thank for your help !

So i will start with the answer of alexan_e :
No i cant write it like a constant because in my application i need to do modification in this array all the time so :s


For bigdogguru :
I have already optimize my code and the example of microchip that i used is the following : "Device-HID-Custom Demo" that you can find in : "Microchip Solutions v2012-04-03" --> "USB" --> "Device-HID-Custom Demo" . There are a lot of files link with this example, i use it and just change the processIO in the file main.c to make the microcontrolleur do the action i wanted, i dont know if its that you asked but perhaps the example of microchip can be optimize ?!


For paulfjujo :

I have try your solution but pb , i have the error again and again. I wanted to check if my arrat was write in the good part of the memory and ... surprise, surprise... NO -_-'' I dont understand why because i follow your instruction. In fact when i creat an array of [4][10] and define a new DATABANK :
Code:
// File: 18f47j53_g.lkr
// Generic linker script for the PIC18F47J53 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 p18F47J53_e.lib

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

#FI

#IFDEF _DEBUGCODESTART
  CODEPAGE   NAME=bootloader START=0x0            END=0xFFF          PROTECTED
  CODEPAGE   NAME=vectors    START=0x1000         END=0x1029		   PROTECTED
  CODEPAGE   NAME=page       START=0x102A         END=_CODEEND
  CODEPAGE   NAME=debug      START=_DEBUGCODESTART   END=_CEND        PROTECTED
#ELSE
  CODEPAGE   NAME=bootloader START=0x0            END=0xFFF          PROTECTED
  CODEPAGE   NAME=vectors    START=0x1000         END=0x1029		   PROTECTED
  CODEPAGE   NAME=page       START=0x102A               END=0x1FFF7
#FI

CODEPAGE   NAME=config     START=0x1FFF8           END=0x1FFFF        PROTECTED
CODEPAGE   NAME=devid      START=0x3FFFFE          END=0x3FFFFF       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=array        START=0x100             END=0x2FF    PROTECTED	// Here i creat my new bank of 512 bytes ( c'est ici que je suis censé creer ma nouvelle banque de 512 bytes voila qui est fait )
		
DATABANK   NAME=gpr3	   START=0x300	       END=0x3FF
DATABANK   NAME=gpr4       START=0x400             END=0x4FF
DATABANK   NAME=gpr5       START=0x500             END=0x5FF
DATABANK   NAME=gpr6       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=gpr10      START=0xA00             END=0xAFF
DATABANK   NAME=gpr11      START=0xB00             END=0xBFF

#IFDEF _DEBUGDATASTART
  DATABANK   NAME=gpr12      START=0xC00             END=_DATAEND
  DATABANK   NAME=dbgspr     START=_DEBUGDATASTART   END=_DEND           PROTECTED
#ELSE //no debug
  DATABANK   NAME=gpr12      START=0xC00             END=0xCFF
#FI

DATABANK   NAME=gpr13      START=0xD00             END=0xDFF
DATABANK   NAME=gpr14      START=0xE00             END=0xEAF
DATABANK   NAME=sfr14      START=0xEB0             END=0xEFF          PROTECTED
DATABANK   NAME=sfr15      START=0xF00             END=0xF5F          PROTECTED
ACCESSBANK NAME=accesssfr  START=0xF60             END=0xFFF          PROTECTED

SECTION    NAME=USB_VARS   RAM=gpr10
SECTION    NAME=array	        RAM=array

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


there are no error and when i open the .map to see where is my array i found
Code:
      array   0x000e00       data     extern C:\Microchip Solutions v2012-04-03\USB\Device - HID - Custom Demos\Firmware\main.c

he is NOT in the good part of the memory why ?! :'(



Thank you again for all of your answers !!
 

Good news its woorrkkkkksss its just a little mistake in your code paulfjujo ! In fact you have to declare :
Code:
declare a pragma udata ...

#pragma udata msgToSend 		// déclaration des tableaux dans leur mémoire respective
char msgToSend[300] = { 0 };
#pragma udata usartBuff
char inputBuffer[500] = { 0 };
#pragma udata
char *msg_ptr = &msgToSend[0];	// pointeurs pour manipuler les grands tableaux
char *buff_ptr = &inputBuffer[0];

its udata and not idata thx again everyonnnneeeeeeeeeeeeeeee

Your lord and servant ,

Laweack.
 

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…