C Compilation Tips
Custom Linker Scripts
If you start to run out of stack or heap memory, altering your linker script can help. A linker script tells the tools where in memory to place certain types of code. To alter your linker settings, in your software project in SDK you should see a file ldscript.ld. Double-click it.
The default values of 0x2000 (8KiB) are fairly small when we have 1GiB of DDR on the Zybo Z7, so you can increase these (within reason) if you need more dynamic memory space for your C code.
You can also use this file to modify the DDR region used by your program, if you need to reserve an area of memory for storing data outside of your C program.
Please note that if you are using FreeRTOS then you are probably allocating on the heap using pvPortMalloc. Normal malloc uses the main heap which is set using the method above.pvPortMalloc uses a different heap created by FreeRTOS, the size of which is set in the BSP settings under freertosX_xilinx → kernel_behavior → total_heap_size, and which is often not mapped into DDR memory. There is a full breakdown of FreeRTOS memory management here but in general you should be statically allocating things wherever possible, or if not then use malloc() for big things.
Compiler Optimisation Options
It is possible to reduce code size and increase the speed of your program by turning on optimisation in the C compiler options within Xilinx SDK.
The ‘release’ build configuration in SDK sets optimisation to level 2 (-O2), whereas the default ‘debug’ configuration uses no optimisation (-O0).
To change the build configuration, ensure that your main project is selected (the options will be greyed-out otherwise) and choose Project → Build Configurations → Set Active → Release.
Ensure that the Release build is also used for your current Run Configuration, so the correct executable is sent to the board.
For more information on GCC optimisation flags, see the GCC manual.