How to check the code size and memory use in codewarrior V10.3

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

How to check the code size and memory use in codewarrior V10.3

Jump to solution
31,130 Views
pengliang
Contributor III

Hi all,

I am using PE to generate the code for module that I used. Looks like there is lots of code. I want to see how much the code size and data memory usage. How can I do in codewarrior? I just could not find it.

 

Please guide me

 

Thanks in advance.

Labels (1)
1 Solution
8,125 Views
CrasyCat
Specialist III

Hello

Look in your .map file for a section called "Memory Configuration".

If you are using the default linker file you should see at least following memory areas with their start address and size:

  m_interrupts: Contains the vector table.

  m_text: Contains the application code

  m_data: Contains the application data

The size of m_text represents the application code size and the size for m_data represents the application data size.

If you defined additional memory areas in the linker file (*.ld) you may have to consider the additional memory areas as well.

CrasyCat

View solution in original post

19 Replies
8,125 Views
BlackNight
NXP Employee
NXP Employee

There is an easy way to dump the code and data size to the console view, see

Code Size Information with gcc for ARM/Kinetis | MCU on Eclipse

As for reducing the code size: by default optimizations are switched off. Enabling compiler and linker optimizations should greatly reduce your footprint. See Tutorial: Freedom with FreeRTOS and Kinetis-L | MCU on Eclipse

which shows how to have an application *with* an RTOS toggling LEDs on a KL25Z can be done with 5 KByte of Flash and 1 KByte of RAM.

Hope this helps,

Erich

8,125 Views
pengliang
Contributor III

Thank you for replying.

BTW, do you think 5KB of FLASH for just toggling LEDs is too big?

0 Kudos
8,125 Views
BlackNight
NXP Employee
NXP Employee

My RGB 'toggling' LED application comes with waiting routines and Processor Expert LED drivers and full blown startup code. And even with that luxury load, it only takes 3 KByte:

"C:/Freescale/CW MCU v10.3/arm-none-eabi-gcc-4_6_2/bin/arm-none-eabi-size"  --format=berkeley Freedom_LED.elf

   text       data        bss        dec        hex    filename

   3252         40       1068       4360       1108    Freedom_LED.elf

Stripping off startup code and more would get it well below the above size. What you need at the minimum is the vector table plus just the toggling code, then you get below 1 K for sure. But then it would not be suitable for anything advanced.


8,125 Views
pengliang
Contributor III

what if not use PE? it seems PE generated code that taken most of memory size,.

0 Kudos
8,125 Views
BlackNight
NXP Employee
NXP Employee

Hi Peng,

it is not PE. It is the startup code and linker settings which adds to the size. I'll see if I can come up with some suggestions how to strip that down to around 400-800 bytes total. But what you can do right away:

There is a linker symbol defined which I think makes sense in the context of using an UART with printf(). But if you are not using this, then you get the startup code down to around 800 bytes (so 2 K less):

go to the linker options, and here remove the two lines marked in yellow below:

2796_2796.png

Hope this helps,

Erich

8,125 Views
pengliang
Contributor III

Erich,

Thank you for helping me to shrink code size. I would try it. but if I remove these two lines, would it affect my code? or give compile error? I am not quite sure what do that two lines do. Does it just do printf() using UART?

0 Kudos
8,125 Views
BlackNight
NXP Employee
NXP Employee

Peng,

yes, as long as you are not using these formatter/sprintf() (I think?) things, you can remove it. The linker will complain otherwise, then you can re-add the lines. So safe to remove them.

Erich

8,125 Views
pengliang
Contributor III

Great, Thank you very much

0 Kudos
8,125 Views
BlackNight
NXP Employee
NXP Employee

In any case: I played a little bit with the settings, and have put some details and background information in this post: Optimizing the Kinetis gcc Startup | MCU on Eclipse

Erich

8,125 Views
pengliang
Contributor III

Erich, that is good stuff. Thank you

0 Kudos
8,125 Views
CrasyCat
Specialist III

Hello

Here I would make sure a .map file is generated and I would check the application code and data size in there.

The way map file generation is enabled and information are stored depends on the MCU you are targeting.

Which MCU are you targeting (HC08, Coldfire, Kinetis, ...)?

CrasyCat

8,125 Views
carloszamora
Contributor I

Where/How can I find the .map file? I'm using CodeWarrior and K70. I've been searching for the file location and how to generate it but I have no idea.

0 Kudos
8,125 Views
BlackNight
NXP Employee
NXP Employee

Hi Carlos,

the map file is usually where the .elf (application) file is generated. Check the 'Release' or 'Debug' folder in your project.

Erich

0 Kudos
8,125 Views
carloszamora
Contributor I

For some reason, I can't find either of those folders.The .elf file is also missing. Is there a specific way to generate all of that? I'm currently working on the "hello peg" project for the K70.

0 Kudos
8,125 Views
pengliang
Contributor III

I am using Kinetis L series KL25Z.

I looked at .map file. but How would I know the flash memory size and data memory size has been used. How to read it?

Thank you

8,126 Views
CrasyCat
Specialist III

Hello

Look in your .map file for a section called "Memory Configuration".

If you are using the default linker file you should see at least following memory areas with their start address and size:

  m_interrupts: Contains the vector table.

  m_text: Contains the application code

  m_data: Contains the application data

The size of m_text represents the application code size and the size for m_data represents the application data size.

If you defined additional memory areas in the linker file (*.ld) you may have to consider the additional memory areas as well.

CrasyCat

8,125 Views
pengliang
Contributor III

Hi CrasyCat,

Thank you. I figured out how to check the memory size. Thank you firstly.

And also, my application code is taking 4500 byte. However, in my application, I only toggling LEDs. why it takes that much program memory. btw, I am using PE to generate drivers. Is there a better way to minimize the program flash size?

Thank you

0 Kudos
8,125 Views
pengliang
Contributor III

This is what I see in .map file

Memory Configuration

Name                                  Origin                 Length                 Attributes

m_interrupts                       0x00000000         0x000000c0           xr

m_text                               0x00000410         0x0001fbf0             xr

m_data_1FFFF000              0x1ffff000             0x00001000          rw

m_data                               0x20000000         0x00003000          rw

m_cfmprotrom                     0x00000400         0x00000010          xr

*default*                              0x00000000         0xffffffff

Then, m_text length is 1fbf0 which is 130032 byte? the application code is already 130k byte? this is not possible. the application just do some very simple LED toggling. Am I wrong to calculate the application code size?

Please correct me

Thank you

0 Kudos
8,125 Views
danielbronson
Contributor II

If I see this for my Memory Map:

# Memory map:

  v_addr   p_addr   size     name

  0000C000 0000C000 00000000            .x_Peripherals

  00000000 00000000 000000DE .interrupt_vectors .p_Interrupts

  00000208 00000208 00004E6C .ApplicationCode .p_Code

  00000000 00000000 00000F30 .ApplicationData .x_Data

  00000F30 00000F30 00000000 .WIRData   .x_Data

  00000200 00000200 00000008 .reserved_FCF .p_reserved_FCF

  00005074 00000000 000003D8 .data_in_p_flash_ROM .p_flash_ROM_data

  00008000 00008000 00004000            .x_internal_ROM

  00060000 00060000 00000F41 .ApplicationCodeInRAM .p_internal_RAM

How can I tell how much Flash Memory and RAM I am using?

Thanks for any and all help!

0 Kudos