How to increase stack size on MK22FX512AVLQ12

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

How to increase stack size on MK22FX512AVLQ12

824 Views
asfarley
Contributor IV

Environment: KDS 3.2.0, MK22FX512AVLQ12 MCU, using Processor Expert

 

I'm hitting a stack overflow using a MK22FX512AVLQ12 device. I'm having trouble using the full amount of SRAM indicated in the datasheet.

 

From the datasheet for MK22FX512AVLQ12, this device should have 128kb SRAM but I'm getting linker errors when I attempt to set stack and heap to 0x0800 each:

c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: [xxxx].elf section `._user_heap_stack' will not fit in region `m_data'
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: region `m_data' overflowed by 1844 bytes

 

Any idea why this would be? 0x0800 = 2048 = 2kb so there should be plenty of room to spare. 

 

My linker file is attached for reference. 

 

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

Update: I was able to fix the issue by disabling the "generate linker file" option and setting the start of m_data to 0x1FFF0000. I'm interested to know why PE won't let me adjust this variable in the options for the Cpu component. It gives an error: "ERROR: There is no access to memory from 0x1FFF0000 to 0x1FFF7FFF". This seems to be wrong since the program executes correctly using this configuration. 

Original Attachment has been moved to: ProcessorExpert.ld.zip

Labels (1)
0 Kudos
4 Replies

559 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Alexander,

1. Please check the Reference manual for your chip, The on-chip SRAM is split into two equally-sized logical arrays, SRAM_L and SRAM_U.

• SRAM_L = [0x2000_0000–(SRAM_size/2)] to 0x1FFF_FFFF
• SRAM_U = 0x2000_0000 to [0x2000_0000+(SRAM_size/2)-1]‍‍‍‍

So for the chip of  MK22FX512AVLQ12 :

SRAM_L =0x1FFF0000   to  0x1FFFFFFF

SRAM_U =0x20000000   to  0x2000FFFF

 

2. "region `m_data' overflowed by 1844 bytes" meaning in the region of 'm_data', the data overflowed

1844 bytes, not just occupied 1844 bytes.

3. You can put some data into 'm_data_20000000' region to have try.

Hope it helps


Have a great day,
TIC

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

0 Kudos

559 Views
asfarley
Contributor IV

Thanks, Alice. I see what you mean about the memory boundaries - it's strange that the application seems to run correctly when I set the m_data ORIGIN to 0x1FFF0000 if that's out-of-range for SRAM_U. 

Anyway, my main question is why the PE CPU component doesn't seem to be handling increases in SRAM size correctly. I understand that the overflow message means that the region overflowed by 1844 bytes, not that it was 1844 bytes in total.

 Knowing that the device has 128kb of SRAM (or even 64kb if we're just talking about one of the two regions), it should be possible to bump up the stack or heap sizes to something significantly larger than 0x0800. However, I start getting linker errors if I set the heap and stack sizes to 0x0800 each. This is why I was asking: why can't I allocate a 2kb heap and stack using the 128kb of available SRAM, using the PE component?

0 Kudos

559 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Alexander,

- Sorry for my mistake of last reply . We can start from 0x1FFF0000, it isn't over boundary.

SRAM_L =0x1FFF0000   to  0x1FFFFFFF

- And I made a project about your chip on KDSv3.2 , configure the stack and heap size all to 0x800. there is no error:

pastedImage_1.png

Please take a screenshot about your error when setting 0x800 .

BR

Alice

559 Views
asfarley
Contributor IV

Hmmm - it's been a while but somehow I've worked around this issue and I'm not getting the error anymore. I'll post back if this comes up again. Thanks!

0 Kudos