One of my students has reported that the C compiler for RVfpga is throwing errors whenever he tries to use memory allocation functions like malloc. Is the heap, and malloc() and free() supported by the RVfpga tool chain?
We have this from Valerii at PlatformIO:
"The toolchain itself does support the heap memory management (it's the same GCC toolchain used across all of our RISC-V integrations).
To better understand the problem we need a more detailed description of that error. In a nutshell, the CHIPSAlliance development platform can compile 3 different types of project:
- Bare ASM projects (simplistic linker script, no runtime, no heap memory)
- Bare C projects (simplistic linker script, no runtime, no heap memory)
- SDK-based projects (appropriate linker script, C runtime, available heap)
Also, we need to know where the firmware is uploaded to (an FPGA board or simulator).
Without this information it'd be hard to help.
Regards, Valerii, the PlatformIO team"
Luis at UCM gave us these useful comments:
Very short answer:
- Although malloc is provided by the newlib library it requires an appropriate sbrk() function
- By default malloc wrapped is the linking process, hence it must be call using the __real_ prefix
Please find attached a very simple example that I have just tested on the fpga_board as well as on SweRV-ISS (whisper).
- File needs to be unzipped first
Thanks Luis!
Dear all,
Please find the attachment as example code.