Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

malloc problem

Honored Contributor II



I am using Quarts and Nios 9.1 versions. 

In my board I have external (altmemddr) and on-chip (inside Cyclone III) memory. 

In the system library properties all memory (including rwdata, heap and stack) is defined to use an on-chip memory. 

But in my applicaion I am tring to allocate part of the variables to the ddr: 

EXTERN unsigned char *CisSheetQueue __attribute__ ((section(".altmemddr.rwdata"))); // Locate this array in DDR 

Later on I am trying to allocate 64K of this memory: 

CisSheetQueue = malloc(CIS_SHEET_QUEUE*sizeof(unsigned char)); 

But this size is not allocated and limited only to ~6K. 

During the compilation of nios there is an info message 16Kbytes free for stack + heap. 

How I can use and allocate a large size (64K) speciphically in DDR?  


Thank you for the help.
0 Kudos
4 Replies
Honored Contributor II

have you connected at least the data_master of the NIOS to the DDR-RAM?

Honored Contributor II

That isn't how malloc() and linker sections work. 


You can either put your heap in altmemddr and use malloc(), or you can statically allocate your array and use the section attribute (as you have attempted) to place that array in altmemddr.
Honored Contributor II

I don't want to put a heap on altmemddr as I want that all variables will be handled in fast way (as it is done on the on-chip memory). 

I have tried to allocate an array in this way: 

unsigned char CisSheetQueue[65535] __attribute__ ((section(".altmemddr.rwdata"))); // Locate this array in DDR 

But in this way the code (that burned to the flash memory) is jumping from 120K to 280K. And I have a limited space to program this code to the specific sector of the flash.
Honored Contributor II

The increase in code size is likely due to the .cinit to initialize the data. 


Instead of doing it this way, just do it with a pointer and a linker region: modify your linker script to create a region to hold your "CisSheetQueue" and then: 


unsigned char *pCisSheetQueue = (unsigned char *)the_address_of_the_region_you_just_created;  


If I recall, you can manage the linker script regions through the BSP editor.