Increasing memory size to store variables in FRDM-KL26Z

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

Increasing memory size to store variables in FRDM-KL26Z

3,926 Views
danyonchu
Contributor I

I am trying to store a large byte array (size 20-30,000) inside of memory that I receive from another FRDM-KL26z uController over I2C. When I try to store data into that array, I get the 'm_data overflowed by xxxx bytes' error. From what I think is happening is that variables get written to RAM during runtime and I don't have enough of that. What is m_data and is there a way to increase m_data size? Or instead is there a way to write to flash? If that first option isn't possible/feasible, are there any precompiled functions that already do this in the SDK? I am using SDK v1.x and programming using Kinetis Design studio

0 Kudos
Reply
18 Replies

3,305 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Danyon,

You can relocate the large array to RAM or FLASH memory , please refer to this tutorial :

Relocating Code and Data Using the KDS GCC Linker File for Kinetis 

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
Reply

3,305 Views
danyonchu
Contributor I

Hi Alice,

I took a look at the file and I believe point 5 answers my question but that leads to another questions. How do I get access to the *.Id file for my project in KDS? Does this need to be generated through some project settings? I have been looking into a couple documents on google and most of them just explain what a linker file is, but not how I can find it to edit. Would you be able to guide me on this?

I have been referencing this document: https://mcuoneclipse.com/2014/10/06/putting-code-of-files-into-special-section-with-the-gnu-linker/ 

but I haven't been able to find the settings/files the person talks about.

Edit: I am not using a processor expert project. I found that if I create a new Processor Explorer project using the *.peb file for my board, it will automatically have the *.Id file. Is it possible to use that file and link it in my original project? Or do I need to redo my project as a processor expert project? What is the difference between a PE project and a regular one made using the Project-Generator?

0 Kudos
Reply

3,305 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Danyon,

Could you please send your project to me ?

If your project is made on KDS, it automatic has the linker file :

pastedImage_1.png

Hope it helps

Alice

0 Kudos
Reply

3,305 Views
danyonchu
Contributor I

I am not too sure if you would be able to open the project with just these files. Let me know if you need any other files.

0 Kudos
Reply

3,305 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi  Danyon,

Does your project created on KDS, or ported from other IDE?

I can't open it without the whole project.

BR

Alice

0 Kudos
Reply

3,305 Views
danyonchu
Contributor I

It was created using the KDS-project-generator. It is based off of the i2c_slave driver example given in sdk 1.x. I am trying to modify it so that I can transfer large bitmaps to display to the screen. I am trying to receive a 20kbyte bitmap and store it in the slave rather than throwing it right away onto an LCD screen, however am running into the issue of storage space in RAM, which is why I am exploring the possibility of storing the variables in other types of memory.

0 Kudos
Reply

3,305 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Danyon,

Please right click your project, then select "Properties", then you can find the linker file path:

pastedImage_1.png

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
Reply

3,305 Views
danyonchu
Contributor I

That screen helped a lot. Unfortunately while following the tutorial in the PDF, I still get build errors. I believe this is because I am only relocating my data within RAM. And given the fact that my array is 20kB and I only have 16kB RAM, I get overlapping section errors.

Error code:

make -k -j4 all

Building target: Display_slave_MKL26Z128VLH4.elf

Invoking: Cross ARM C Linker

arm-none-eabi-gcc -mcpu=cortex-m0plus -mthumb -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -g -T ../../../../../../platform/devices/MKL26Z4/linker/gcc/MKL26Z128xxx4_flash.ld -Xlinker --gc-sections -Wl,-Map,"Display_slave_MKL26Z128VLH4.map" -Xlinker -z -Xlinker muldefs --specs=nano.specs -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -Os -mapcs -Xlinker -static -o "Display_slave_MKL26Z128VLH4.elf" -Xlinker --start-group ./utilities/fsl_debug_console.o ./utilities/print_scan.o ./startup/startup.o ./startup/startup_MKL26Z4.o ./startup/system_MKL26Z4.o ./sources/fsl_i2c_irq.o ./sources/main.o ./board/board.o ./board/gpio_pins.o ./board/hardware_init.o ./board/pin_mux.o ../../../../../../lib/ksdk_platform_lib/kds/KL26Z4/debug/libksdk_platform.a -lm -lg -lgcc -lnosys -Xlinker --end-group

c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe:../../../../../../platform/devices/MKL26Z4/linker/gcc/MKL26Z128xxx4_flash.ld:77: warning: memory region `m_data_1FFFF000' not declared

c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: section .interrupts loaded at [00000000,000000bf] overlaps section .mySection loaded at [00000000,00004e1f]

collect2.exe: error: ld returned 1 exit status

make: *** [Display_slave_MKL26Z128VLH4.elf] Error 1

makefile:45: recipe for target 'Display_slave_MKL26Z128VLH4.elf' failed

make: Target 'all' not remade because of errors.

0 Kudos
Reply

3,305 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Danyon,

Please check the two error message:

pastedImage_1.png

You can also send your whole project to me.

BR

Alice

0 Kudos
Reply

3,305 Views
danyonchu
Contributor I

Here is the project zipped

0 Kudos
Reply

3,305 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Danyon,

1. You haven't send your  linker file .

2. In  your code  I haven't find the code about

__attribute__ ((section(".xxx"))) xxx;

The two points are mainly we need to check .

BR

Alice

0 Kudos
Reply

3,305 Views
danyonchu
Contributor I

Hi Alice,

I mistakenly sent you the project when I was reverting back to the original code to make sure everything still worked. Here is the correct version. I actually do not encounter any errors on build in this version. I am not sure what is different, however the code will not run when uploaded to the board. What I mean by this is all of the initializations and setup code that previously worked would no longer run. I verified this by printf's to a terminal such as puTTY. I did notice that on line 61, when I define IMG_LENGTH as 10,000, the code will run. but not when IMG_LENGTH is defined as 20,000. Is this a space limitation?

#define IMG_LENGTH 10000 //<-this works

#define IMG_LENGTH 20000 //<-this does not work

0 Kudos
Reply

3,305 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Danyon,

1> The chip MKL26Z128VLH4 on FRDM-KL26 board only have 16K RAM,

pastedImage_1.png

So when configure #define IMG_LENGTH 20000 , it overflow. May be you can take place the array to

flash into account.

2> And the linker file you send me has a mistake :

pastedImage_2.png

BR

Alice

0 Kudos
Reply

3,304 Views
danyonchu
Contributor I

Hi,

You are correct that I do not have enough RAM. This is the reason I have been trying to move this array into flash.

I have made the changes you have mentioned. When copying the .bin file into the microcontroller, i get a 'not enough space' error.

0 Kudos
Reply

3,305 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Danyon,

Which .bin file do you copy ? How ?

The MKL26Z128 has 128K flash in total,  from the message we can see there is 384K about your file.

BR

Alice

0 Kudos
Reply

3,305 Views
danyonchu
Contributor I

The .bin file that I copy is from the image below. I copy it by dragging it into the drive that appears when you connect the FRDM-KL26Z board through a USB port in the computer.

The only lines I changed in the linker file were:

/* Specify the memory areas */

MEMORY
{
  m_interrupts          (RX)  : ORIGIN = 0x00000000, LENGTH = 0x00000100
  m_flash_config        (RX)  : ORIGIN = 0x00000400, LENGTH = 0x00000010
  m_text                (RX)  : ORIGIN = 0x00000410, LENGTH = 0x0001FBF0
  m_data                (RW)  : ORIGIN = 0x1FFFF000, LENGTH = 0x00004000

 m_data_1FFF0000                (RW)  : ORIGIN = 0x1FFF0000, LENGTH = 0x00006000
}

/* Define output sections */
SECTIONS
{
 /*.mySection : {
  *(.myRAM)
 } > m_data_1FFF0000*/

.

.

.

this only declares a mem space of ~25KB. If these lines are removed, I can upload the code without an error to the FRDM board. What is going on? How can the code size be increased by at least 226KB to reach 384KB?

Capture.PNG

0 Kudos
Reply

3,305 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Danyon,

1) What about this memory ?

pastedImage_1.png

Please check the SRAM ranges on Reference manual of your chip.

2) About the chip of " MKL26Z128VLH4", the largest internal FLASH is 128K , largest internal SRAM is 16KB.

BR

Alice

0 Kudos
Reply

3,305 Views
danyonchu
Contributor I

I will be looking into external memory as well as SPI communication in order to transfer the information at faster speeds rather than to store it in the microcontroller

0 Kudos
Reply