Allocating large arrays in RAM on the HiFive1 Rev B

Dear SiFive community,

I am trying to run a program that requires a significant amount of RAM on a HiFive1 Rev B board. More precisely, the code makes use of an array of ~400 unsigned integers.

By making some simple tests, I noticed that a simple code doesn’t run on the HiFive1 Rev B when it manipulates large arrays.

For instance, the following program:

int main(void) {
    unsigned int test[150];
    for(int i = 0; i < 150; i++) {
        test[i] = i;
        printf("%d ,", test[i]);

runs normally when compiled and loaded on the board.

However, by slightly increasing the array’s size (e.g. from 150 to 200), the code doesn’t run anymore as expected since nothing is printed out.

I don’t understand why increasing the size of the array by 50 results in such an issue. Since the board comes with 16Kb of RAM, I think it has nothing to do with memory limitation.

Am I missing something?

I am compiling/loading the program with a simple make BSP=metal PROGRAM=test_memory TARGET=sifive-hifive1-revb clean software upload using the Freedom E SDK (so the linker file used is

Defining the array inside main means it uses stack space, and you probably have a limited amount of stack space. Try moving it outside main, or using malloc to allocate space for the array.

Thanks @jimw for your suggestion.

You were right, it was due to stack limitation.

By adding the following lines to the Makefile

override CFLAGS += 	-Xlinker --defsym=__stack_size=0x1200 \
                    -Xlinker --defsym=__heap_size=0x800

it now runs as expected.