Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12604 Discussions

Size of C file running using NIOS II ON CHIP RAM

Altera_Forum
Honored Contributor II
1,904 Views

How to figure out how much amount of space is being occupied by the C.c file which is used to to run as an NIOS II hardware ?? 

 

For example in the file http://www.altera.com/literature/hb/external-memory/emi_tut_qdr.pdf 

consider I am running the DDR_TEST.c file on the NIOS II processor. What will the memory occupied int he ON CHIP RAM???
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
730 Views

Use the nios2-elf-size utility on the corresponding .o or .elf file. 

 

Search for "nios2-elf-size" in this document: 

http://www.altera.com/literature/hb/nios2/edh_ed51004.pdf
0 Kudos
Altera_Forum
Honored Contributor II
730 Views

Most of the memory is needed for the libc functions that Altera support by default. 

In particular printf() drags in about 70k of code because it is built on top of the standard stdio library code which also pulls in malloc(). 

Even if you don't actually call printf() there is code to close the fds after main returns. 

 

There is a 'small' version (that uses alt_printf() etc), but even that isn't as small as it could be. 

 

It really ought to be possible to write a 'hello world' program in less than a 100 instructions, and use that as a base for simple embedded systems.
0 Kudos
Altera_Forum
Honored Contributor II
730 Views

 

--- Quote Start ---  

In particular printf() drags in about 70k of code because it is built on top of the standard stdio library code which also pulls in malloc(). 

 

--- Quote End ---  

 

 

I think you're off by 10x. :) 

 

WIth "enable_small_c_library" and "enable_reduced_device_drivers" options enabled, then "Hello world" with a JTAG UART console takes 7KB. 

 

Without those options enabled, it is around 28KB.
0 Kudos
Altera_Forum
Honored Contributor II
730 Views

with the ONCHIP RAM memory on the system being only 64KB(max specified by altera), even if a small program like hello world takes 7KB, then it means i cant run a big code on it ??

0 Kudos
Altera_Forum
Honored Contributor II
730 Views

Running out of memory is an old problem. If you need to run software that is bigger than the available onchip memory, then you may want to consider adding an external memory with adequate capacity to your hardware design. 

For many traditional microcontroller tasks, 64KB is ample capacity however.
0 Kudos
Altera_Forum
Honored Contributor II
730 Views

Thanks a lot ted & dsl :)

0 Kudos
Altera_Forum
Honored Contributor II
730 Views

I run real code on two nios, one has under 4k code, the other about 8k. There is 32k of internal memory, about 10k of which is a big lookup table. 

What this doesn't use is any of the Altera support code. 

The 4k code contains a multi-channel hdlc controller (doing bit-stuffing and crc in software) that is capable of driving 64 64kb hdlc streams (for telephony). The second nios does the low level hdlc protocol (timers, retransmissions and host interface).
0 Kudos
Reply