RAM Usage with KDS+KSDK: report 20% used and region overflow

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

RAM Usage with KDS+KSDK: report 20% used and region overflow

Jump to solution
1,572 Views
sylvain
Contributor I

Hi There,

 

I am trying to get an idea of the RAM and Flash use of my program as I have recently bumped into a region overflow issue:

section .bss will not fit in region "m_data"

 

I am using the MK64FN1M0VLL12 uc with 256KB RAM and 1MB Flash.

I want to statically add an array which is 170*128*2=43520 bytes long.

From what I see in the print size before adding the array only 66560 Bytes are used in RAM so far.

Alas, I get a m_data region overflown by 31732 bytes when I add the array.

 

Below are code snippets and print size. What am I doing wrong?

 

Thanks a lot for your help,

S.

-----------------------------------------------

data.h:

extern uint16_t data_current_raw[MEASURES_MAX][BUFLEN];

 

data.c:

uint16_t data_current_raw[MEASURES_MAX][BUFLEN] = {{0}};

 

measure.c

#include "data.h"

#DEFINE MEASURES_MAX 170

#DEFINE BUFLEN 128

static uint16_t meas_data_all[MEASURES_MAX][BUFLEN] = {{0}};

(write important data in meas_data_all)

memcpy(data_current_raw, meas_data_all, sizeof(meas_data_all));

 

Here is the size print before adding data_current_raw:

 

Invoking: Cross ARM GNU Print Size

arm-none-eabi-size --format=sysv --totals "XXX.elf"

section              size        addr

.interrupts          1024           0

.flash_config          16        1024

.text              129536        1040

.ARM                    8      130576

.init_array             4      130584

.fini_array             4      130588

.interrupts_ram      1024   536805376

.data                1016   536806400

.bss                50172   536807416

.heap                1024   536870912

.stack               1024   536871936

.ARM.attributes        48           0

.debug_info        266651           0

.debug_abbrev       42800           0

.debug_aranges       9744           0

.debug_ranges       10288           0

.debug_macro       243827           0

.debug_line        133816           0

.debug_str        1898995           0

.comment              112           0

.debug_frame        32100           0

.debug_loc          48696           0

.stab                 156           0

.stabstr              387           0

Total             2872472

Labels (1)
0 Kudos
Reply
1 Solution
1,065 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Sylvain,

we can refer K64 reference manual for why SRAM is separated into two parts.

pastedImage_0.png

becuase SRAM_L and SRAM_U are accessible by different bus.  in some low power mode, for example VLLS2 (Very Low Leakage Stop2), SRAM_L is powered off. A portion of SRAM_U remains powered on.

if your project uses SRAM_L and SRAM_U in same way, I think you can use them together.

for example in ld file, we define m_data as

  m_data            (RW)  : ORIGIN = 0x1FFF0000, LENGTH = 0x00040000
/*  m_data_2         

(RW)  : ORIGIN = 0x20000000, LENGTH = 0x00030000 */

then don't forget allocate related stack and heap to m_data too

pastedImage_1.png

after build, there is no error. in map file. we can see meas_data_all and and data_current_raw succesfully allocated.

.bss.meas_data_all

                0x1fff00a4     0xaa00 ./source/main.o

.bss.data_current_raw

                0x1fffaaa4     0xaa00 ./source/main.o

                0x1fffaaa4                data_current_raw

can this help you?


Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
Reply
3 Replies
1,065 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

hi Sylvain,

I just copied your code in one of K64 KSDK project, I can reproduce your problem.

you defined

uint16_t data_current_raw[MEASURES_MAX][BUFLEN] = {{0}};

static uint16_t meas_data_all[MEASURES_MAX][BUFLEN] = {{0}};

each of the size is 170*128*2=43520 , so two arrays use 43520*2=87040 bytes code size .

both of these arrays are distributed to .bss section.

in linker file(under C:\Freescale\KSDK_1.3.0\platform\devices\MK64F12\linker\gcc), there are two data areas:

pastedImage_1.png

and .bss section is allocated to m_data which total size is 65535 bytes

pastedImage_3.png

if we allocate larger memory to .bss. this can solve the problem. here I allocate .bss to m_data2 which has 196608 bytes size, .bss can hold the arrays.

pastedImage_4.png

then i built the project again. there is no error.

can you please try the same?

can this help you?


Have a great day,
Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,065 Views
sylvain
Contributor I

Hi Zhang,

Thanks a lot for the tip, I will have a go and give you an update.

In the meantime can you tell me why the RAM is cut in two part with respectively 25% and 75% of the memory?

What if I want to make use of the full 256KB of RAM?

Thanks,

Sylvain.

0 Kudos
Reply
1,066 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Sylvain,

we can refer K64 reference manual for why SRAM is separated into two parts.

pastedImage_0.png

becuase SRAM_L and SRAM_U are accessible by different bus.  in some low power mode, for example VLLS2 (Very Low Leakage Stop2), SRAM_L is powered off. A portion of SRAM_U remains powered on.

if your project uses SRAM_L and SRAM_U in same way, I think you can use them together.

for example in ld file, we define m_data as

  m_data            (RW)  : ORIGIN = 0x1FFF0000, LENGTH = 0x00040000
/*  m_data_2         

(RW)  : ORIGIN = 0x20000000, LENGTH = 0x00030000 */

then don't forget allocate related stack and heap to m_data too

pastedImage_1.png

after build, there is no error. in map file. we can see meas_data_all and and data_current_raw succesfully allocated.

.bss.meas_data_all

                0x1fff00a4     0xaa00 ./source/main.o

.bss.data_current_raw

                0x1fffaaa4     0xaa00 ./source/main.o

                0x1fffaaa4                data_current_raw

can this help you?


Zhang Jun

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply