Please help.... malloc is creating prob......

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Please help.... malloc is creating prob......

2,373 Views
CM8486
Contributor I

Hello all,

 

I am using mc9s08ac60 and CW v6.1. 

 

Following is my prm file:

 

 

/***************************************************************************

 /* This is a linker parameter file for the mc9s08ac60 */

NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */

SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
    Z_RAM                    =  READ_WRITE   0x0070 TO 0x00FF;
    RAM                      =  READ_WRITE   0x0100 TO 0x086F;
    ROM                      =  READ_ONLY    0x1860 TO 0xFFAF;
    ROM1                     =  READ_ONLY    0x0870 TO 0x17FF;
    ROM2                     =  READ_ONLY    0xFFC0 TO 0xFFC5;
 /* INTVECTS                 =  READ_ONLY    0xFFC6 TO 0xFFFF; Reserved for Interrupt Vectors */
END

PLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */
    DEFAULT_RAM                         /* non-zero page variables */
                                        INTO  RAM;

    _PRESTART,                          /* startup code */
    STARTUP,                            /* startup data structures */
    ROM_VAR,                            /* constant variables */
    STRINGS,                            /* string literals */
    VIRTUAL_TABLE_SEGMENT,              /* C++ virtual table segment */
    DEFAULT_ROM,
    COPY                                /* copy down information: how to initialize variables */
                                        INTO  ROM; /* ,ROM1,ROM2: To use "ROM1,ROM2" as well, pass the option -OnB=b to the compiler */

    _DATA_ZEROPAGE,                     /* zero page variables */
    MY_ZEROPAGE                         INTO  Z_RAM;
END


STACKSIZE 0x50

VECTOR 0 _Startup /* Reset vector: this is the default entry point for an application. */

****************************************************************************/

 

now when i try to use malloc it gives a link error: L1102

saying out of allocation space in segment RAM at address 0x106.

 

Please suggest me the prob?

Thanks.

Labels (1)
0 Kudos
10 Replies

559 Views
CM8486
Contributor I

Hi all,

 

Can anyone please suugest how to write .prm files? were are the rules? or any doc?

 

Thanks...

 

0 Kudos

559 Views
Lundin
Senior Contributor IV
To use malloc on a 8-bit mcu sounds peculiar. You should seriously question if it is necessary for your application. In 99% of all 8-bit applications this isn't necessary. And you can be sure it is banned in all safety-critical applications.

Whenever dynamic alloaction is used, the compiler will slaughter a fixed size of your RAM for the heap. In the non-standard header libdefs.h there is a constant LIBDEF_HEAPSIZE which is set to 2000 by default. You have to alter this for a smaller heap.
0 Kudos

559 Views
CM8486
Contributor I

Hi http://forums.freescale.com/freescale/view_profile?user.id=2892" target="_blankLundin,

 

Thanks for your quick response.

 

you are right i am  not going to use it in my application....

 

but what size should be assgined to LIBDEF_HEAPSIZE?

i just want to check.....  i have tried with smaller value but error remains the same...

thanks....

Message Edited by CM8486 on 2009-03-04 01:10 PM
0 Kudos

559 Views
CompilerGuru
NXP Employee
NXP Employee

Changing the LIBDEF_HEAPSIZE define is not enough, the library file which uses it has to be rebuilt too.

See:

 

http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&message.id=763&query.id=9234#M...

 

As alternative you can also add the source file which uses LIBDEF_HEAPSIZE (hmm. guess: alloc.c?) to your project and place it in the link order before the ansi library. This will cause a warning about the different object sizes, but works appart from that.

In the end, if you do not need to use malloc, there is probably little use in setting this up.


Daniel
0 Kudos

559 Views
bigmac
Specialist III

Hello,

 

The error message would seem to indicate that the linker is attempting to create a heap commencing at address 0x106, which I would assume to be immediately following the global and static variables declared within your program.

 

However, with the use of the STACKSIZE entry within the PRM file, my understanding is that the stack will be placed immediately following the global and static variables, independently of the RAM size for the device.  I wonder if this might possibly be the cause of the problem.

 

A possible solution might be to alter the PRM file to allocate an explicit stack segment at the top of RAM, and to specify STACKTOP rather than STACKSIZE. This would be in addition to reducing the default heap size.

 

Regards,

Mac

 

0 Kudos

559 Views
CM8486
Contributor I

Hi mac,

 

Thanks for reply...

 

i would like to tell that i haven't declared any of the variable.i have declared just the char *p gloabally. then also it is giving location  0x0106 ????as per above prm file.

 

another thing i have changed the STACKSIZE to STACKTOP. now my prm looks like:

 

/****************************************************************************

/* This is a linker parameter file for the mc9s08ac60 */

NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */

SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
    Z_RAM                    =  READ_WRITE   0x0070 TO 0x00FF;
    STACKSEG                 =  READ_WRITE   0X0100 TO 0X0200;
    RAM                      =  READ_WRITE   0x0201 TO 0x086F;
    ROM                      =  READ_ONLY    0x1860 TO 0xFFAF;
    ROM1                     =  READ_ONLY    0x0870 TO 0x17FF;
    ROM2                     =  READ_ONLY    0xFFC0 TO 0xFFC5;
 /* INTVECTS                 =  READ_ONLY    0xFFC6 TO 0xFFFF; Reserved for Interrupt Vectors */
END

PLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */
    DEFAULT_RAM                         /* non-zero page variables */
                                        INTO  RAM;
   

    _PRESTART,                          /* startup code */
    STARTUP,                            /* startup data structures */
    ROM_VAR,                            /* constant variables */
    STRINGS,                            /* string literals */
    VIRTUAL_TABLE_SEGMENT,              /* C++ virtual table segment */
    DEFAULT_ROM,
    COPY                                /* copy down information: how to initialize variables */
                                        INTO  ROM; /* ,ROM1,ROM2: To use "ROM1,ROM2" as well, pass the option -OnB=b to the compiler */

    _DATA_ZEROPAGE,                     /* zero page variables */
    MY_ZEROPAGE                         INTO  Z_RAM;
END


STACKTOP 0x01FF

VECTOR 0 _Startup /* Reset vector: this is the default entry point for an application. */
 

 

*****************************************************************************/

 

now it gives it gives a link error: L1102

saying out of allocation space in segment RAM at address 0x207.

 

Thanks..

 

0 Kudos

559 Views
CompilerGuru
NXP Employee
NXP Employee

Chaning the macro in libdefs.h without recompiling the library does not cause the heap to be smaller. So there is just not enogh space for the heap. The stack would be allocated behind the heap if the linking would not run our of RAM before.

 

 

Daniel

0 Kudos

559 Views
CM8486
Contributor I

hi Daniel,

 

Thanks for taking interest... 

 

i have tried both the way... but dont succeed....

 

i have changed the macro , recompile the library... but doesn't happed..

n also tried adding alloc.c but the same doesn't help...

 

Thanks...

0 Kudos

559 Views
CompilerGuru
NXP Employee
NXP Employee

Make sure the size you define does really fit, so start too small in order to rule this out.

 

Another thing I do try for out of memory cases is to temporarly provide more memory in the prm that the target actually has. This way you see what gets allocated in the prm file and how much memory more is needed. Don't forget to undo the memory extension, it wont run on the target....

 

For the library building way, did you build the right library (or did you even build all)?

For the alloc.c case, did you change the link order?

 

Daniel

 

 

 

0 Kudos

559 Views
CM8486
Contributor I

Hi Daniel,

 

thanks.

 

i have tried small size as per your suggestion....but doesnt happen.

 

i am not getting why it is stucked at that address 0x207. whare as i haven't declared any of the variable

except char*p to which i am assigning memory using malloc.

 

For the library building way - i have built the library by build all option.but doesn't work.

and for the  alloc.c i ahve changed the link order but doesn't work?

 

i am becoming desperate to solve this problem. Please help...

 

Thanks.

 

 

 

0 Kudos