BrunoLevy / learn-fpga

Learning FPGA, yosys, nextpnr, and RISC-V
BSD 3-Clause "New" or "Revised" License
2.44k stars 236 forks source link

How to fit larger programs on the Icestick ULXS3 or Arty #95

Closed JamesTimothyMeech closed 1 year ago

JamesTimothyMeech commented 1 year ago

I have been attempting to run some C++ programs over the FemtoRV soft processor on an FPGA.

I have been getting error messages such as this one because my programs do not fit in the available RAM:

FemtoRV/FIRMWARE//TOOLCHAIN/riscv64-unknown-elf-gcc-8.3.0-2020.04.0-x86_64-linux-ubuntu14/bin/riscv64-unknown-elf-ld: region RAM' overflowed by 3952 bytes

I tried including the -s and -Os flags in the RVCFLAGS variable to decrease the size of the compiled program but this does not seem to help.

I have also tried compiling the programs for the ULXS3 which does not help because it uses 64kb of RAM for FemtoOS. If my main goal is to have more RAM for my C++ program and I do not want FemtoOS.

What is the easiest way for me to edit one of the .ld files to get more RAM for my program?

BrunoLevy commented 1 year ago

On the ULX3S, the default configuration has 256 KB of RAM. There is a C++ example in FemtoRV/FIRMWARE/CPP_EXAMPLES, to compile it:

$ cd learn-fpga/FemtoRV
$ make ULX3S.firmware_config
$ cd FIRMARE/CPP_EXAMPLE
$ make cpp_test.elf

Then copy cpp_test.elf on a SDCard and use FemtOS to start it (see the tutorial)

Now if you want to do something more serious, you will need sufficient RAM to load the standard C++ runtime (that is super big), so you can use a SOC with an SDRam controller. The one in LiteX is super well designed, see instructions here. I could sucessfully compile and run different C++ programs and run them on different cores (FemtoRV, but also the much more efficient VexRiscV and NaxRiscV).