• MATLAB
  • Link Error: Could not allocate data memory
2020/10/14 07:03:37
Poley
Hi,
 
I am trying to build my model to get my hex file with XC16 and I get the error: Link Error: Could not allocate data memory
 
I assume this is due to running out of RAM. My model isn't that big so it shouldn't be running out, is there anything I can do to get pass this? I have attached my build log that shows the error. Any help will be greatly appreciated.
 
Thanks!

Attached Image(s)

2020/10/15 01:39:58
Lubin
Hi Poley,
 
Do you have an idea about what requires such amount of RAM ?
Typically, it might be the use of lookup table. There are sometime better options (great matlab function to optimize a given lookup table or using a function to approximate your Look Up Table)
 
Compiler setting seems ok.
 
However please check at Simulink options which also impact memory consumption.
The "inline parameters" option save quite some RAM. Note that otherwise, parameters (constant in your model) are considered as (tunable) variable. The compiler will likely not store theses "constant variable" in program memory if there is any chance it can be modified by a process.
There are other Simulink code implementation options to explore which could impact memory consumption.
 
Last ressort, you might try compiling from MPLAB X using the generated project. It gives you access to a more (if not all) options available in our XC compilers.


2020/10/15 01:44:07
Poley
Lubin
Hi Poley,
 
Do you have an idea about what requires such amount of RAM ?
Typically, it might be the use of lookup table. There are sometime better options (great matlab function to optimize a given lookup table or using a function to approximate your Look Up Table)
 
Compiler setting seems ok.
 
However please check at Simulink options which also impact memory consumption.
The "inline parameters" option save quite some RAM. Note that otherwise, parameters (constant in your model) are considered as (tunable) variable. The compiler will likely not store theses "constant variable" in program memory if there is any chance it can be modified by a process.
There are other Simulink code implementation options to explore which could impact memory consumption.
 
Last ressort, you might try compiling from MPLAB X using the generated project. It gives you access to a more (if not all) options available in our XC compilers.






Hi Lubin
 
I will give what you mentioned a try and will report back!
 
I do have multiple lookup tables ( only small ones) not sure how I would make a function instead? 
 
Also I have purchased the PRO version of XC16, how do I change my current free version to this one? It only has 'Free' available when I try to fresh install, the others are greyed out. Want to use a higher optimisation level which doesn't currently change even when I change it in compiler options. - Update I have got the PRO license installed but changing optimization level doesn't change code size for some reason.
 
Thanks
 
2020/10/15 02:36:44
Lubin
Hi Poley,
 
XC16 installation page: https://microchipdeveloper.com/xc16:installation
I think you install the free version, then you are prompted if you want to set a license key...
 
Within your LookUp Table, ensure datatype is set appropriately (16 bit fixed point whenever possible for best efficiency on dsPIC)


Regarding function approximation, there is a "Curve fitting toolbox" within matlab. 
If you already know the type of function that would fit your curve, there might also be a possibility to get results through linear algebra resolution problem resolution thus using only matlab base functions on matrix.
 
I do not know if you have constraints in terms of execution speed in your application.
 
Regarding math function execution time, few ones could be accelerated using the "Code Replacement" option for the dsPIC where generated code for a short list of operation are replaced by Microchip optimized code for dsPIC.
 
However if such function require math which would be too slow to compute on the dsPIC, you might generate an optimized lookup table: Interpolated one, where a limited number of (x,y) points are placed so as to minimize the worst case interpollation error. The Matlab function fixpt_look1_func_approx is in the base matlab package and works great. It can compute the minimum numer of point required for a given error threshold.
2020/10/15 02:49:27
Poley
Hi Lubin
 
I have the PRO license installed but changing the optimization in the compiler options doesn't effect the code size at all I still get the exact same error message that I attached before. 
 
Changed all lookup tables that I can ( I don't have the curve fitting toolbox) but still the same.
 
Do I need to do anything else to make it use a different optimization? It seems to reduce program memory and not data memory
 
Thanks 
2020/10/15 12:40:51
cawilkie
This device has 16K of RAM.
 
Just from the linker error report I can see that more than 16K of RAM is being requested:
 
BMS_Danecca_2020.o: Link Error: Could not allocate section .bss, size = 17942 bytes, attributes = bss


The optimiser tends not to have an effect on data memory usage; this tends to be directly related to the application needs translated from source.
 
I see Lubin has suggested several ways that data memory use can be reduced.   Perhaps there are some clues from looking at the source for BMS_Danecca_2020.c?
 
Regards
Calum
2020/10/15 13:23:18
Poley
Yeah I have noticed that it just reduces the ‘program’ memory. I’ve tried everything Lubin has suggested and it is still throwing the same problem.

I will look through the .c and see if I can see anything obvious! I have realised that there are multiple ‘doubles’ in my model (hundred) that are 64 bits by default (can’t change) and nearly all can be uint8 or uint16’s which should take a large chunk of data down once changed, thanks!
2020/10/16 03:02:05
Poley
Changed signals to Single and not now get this error that I have never seen before? It clears when I restart my PC but then comes back after 1 build every time, has anyone come across this before?
 
C:\Users\Danecca\AppData\Local\Temp\ccBy9D58.00001aac.p: line 0316: PA-E0028 Error: Expected a machine or assembler instruction
 
Thanks

Attached Image(s)

© 2021 APG vNext Commercial Version 4.5

Use My Existing Forum Account