Huge Size Hello world with FreeRTOS on NIOS II

kshamim wrote on Monday, April 02, 2018:

Hello everyone,

I’ve created hello world program with FreeRTOS on NIOS II based on CYCLONE III FPGA.
Elf file created is of huge size, 8244 KBytes to be exact.
This is size is not acceptable as I intend to run code from on-chip memory and I’ve only 128 KB on-chip memory available.

Please suggest why hello world based on FreeRTOS is so large in size ?

Thank you

rtel wrote on Monday, April 02, 2018:

A couple of things:

  1. The size of the elf file is not representative of the size of the
    binary image that gets programmed into the device. If you want to know
    the size of the image then there are a couple of options:
    a) Look at the .map file output by the compiler.
    b) Run -elf-size, giving the .elf file as the input.
    This is a utility that comes with the compiler, not sure of the exact
    name for your particular compiler, it might be something like
    nios-elf-size, you will have to look it up.

  2. Inspect the map file to see what is actually taking up the .text
    space. I suspect very little of it will be FreeRTOS code. Often,
    especially if you are using floating point and newlib, a large
    proportion of the binary image will be newlib code which has had all the
    floating point support stuff dragged in.

FreeRTOSConfig.h contains a definition for the heap size, and that can drive the overall .elf size. My file contains:
#define configTOTAL_HEAP_SIZE ( ( size_t ) 8388608 )
My project compiles to a bit over 8MB

If I change the heap reservation to 1084576 bytes, then make clean, the project drops to a little over 1MB. Code plus fixed data appears to be about 136kB, so I could reduce the heap more if I wanted to. Heap size will depend on your application’s memory needs.