Increase Stack size

Dear Reader,

I have been working on a few programs now for the hifive1. Due to certain constraints on the exercise I am not allowed to use the heap. So most of my data is on the stack. This leads to the issue that the stack overflows. I have checked in the elf file produced by the linker, and noticed that the stack only has a size of 0x400, and the heap has a much larger space. Is there a way I can increase this stack size, and reduce the heap size for it.

Kind regards,
mortalAmongstGods(mag)

Edit the freedom metal linker script. HiFive1 and HiFive1 Rev B are different cards with different linker scripts. Assuming this is the original HiFive1 then see for instance


which has a section
__stack_size = DEFINED(__stack_size) ? __stack_size : 0x400;
PROVIDE(__stack_size = __stack_size);
__heap_size = DEFINED(__heap_size) ? __heap_size : 0x800;
PROVIDE(__metal_boot_hart = 0);
You can change those numbers by editing the linker script to replace it with the numbers you want.

You probably want to make a copy of the original linker script, edit it, and then use your modified linker script when linking.

1 Like

Thank you very much for this info. I will try it out tomorrow, but I thinknit will fix my problem.

Hi mag,

We also needed to increase the stack size for the wolfCrypt port on the HiFive1. You can pass this CFLAG linker argument “-Xlinker --defsym=__stack_size=0x1200” to increase stack size at build time via an environment variable or Makefile.

Example: https://github.com/wolfSSL/wolfssl/blob/master/IDE/RISCV/SIFIVE-HIFIVE1/Makefile#L25

David G, wolfSSL