# neorv32 neorv32 with modiefied Makefiles, compatible with MSYS2 64 for cross compilatation on Windows and Linux. # Windows Installation and example of cross compilation ### 1. Installation You must download the latest RISCV precompiled binaries for your platform from: https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/ in this case the architecture x64 for windows binaries(https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v13.2.0-2/xpack-riscv-none-elf-gcc-13.2.0-2-darwin-x64.tar.gz), then extract these under the folder C:\riscv_precompiled\ Note: If you change the location where you installed the RISC-V precompiled binaries, you need to modify line 42 of the file common.mk. This will be explained further in this manual at point number 8. Your precompiled binaries should look like this on your file system:
### 2. Cloning repository Clone or download this repository on your windows machine. ``` $ git clone https://gitea.squirrelnut.synology.me:5001/FPGALover/neorv32 ``` ### 2. Download and install MSYS2(msys2-x86_64-20240113.exe) --> https://www.msys2.org/ Once MSYS2 is installed, run MSYS2, and run the command using the MYSS2 command shell (pacman -S mingw-w64-ucrt-x86_64-gcc)
``` $ pacman -S mingw-w64-ucrt-x86_64-gcc ```

Select ALL dependencies by pressing Enter and select Y[yes].
``` resolving dependencies... looking for conflicting packages... Packages (15) mingw-w64-ucrt-x86_64-binutils-2.41-2 mingw-w64-ucrt-x86_64-crt-git-11.0.0.r216.gffe883434-1 mingw-w64-ucrt-x86_64-gcc-libs-13.2.0-2 mingw-w64-ucrt-x86_64-gmp-6.3.0-2 mingw-w64-ucrt-x86_64-headers-git-11.0.0.r216.gffe883434-1 mingw-w64-ucrt-x86_64-isl-0.26-1 mingw-w64-ucrt-x86_64-libiconv-1.17-3 mingw-w64-ucrt-x86_64-libwinpthread-git-11.0.0.r216.gffe883434-1 mingw-w64-ucrt-x86_64-mpc-1.3.1-2 mingw-w64-ucrt-x86_64-mpfr-4.2.1-2 mingw-w64-ucrt-x86_64-windows-default-manifest-6.4-4 mingw-w64-ucrt-x86_64-winpthreads-git-11.0.0.r216.gffe883434-1 mingw-w64-ucrt-x86_64-zlib-1.3-1 mingw-w64-ucrt-x86_64-zstd-1.5.5-1 mingw-w64-ucrt-x86_64-gcc-13.2.0-2 Total Download Size: 49.38 MiB Total Installed Size: 418.82 MiB :: Proceed with installation? [Y/n] [... downloading and installation continues ...] ```

After the installation is completed, add the *Path* *"C:\msys64\ucrt64\bin"* under the enviroments variable on Windows.


Open a windows cmd and run the command (gcc --version) ``` $ gcc --version gcc.exe (Rev2, Built by MSYS2 project) 13.2.0 ```

Using windows explorer, go to the folder C:\msys64\ucrt64\bin make a copy of the file **mingw32-make.exe** and name it **make.exe**


### 3. Cross-Compiling Using the windows CMD, go to the directory where you cloned or donwloaded this repository to the directory **neorv32\sw\example\demo_blink_led_asm**

``` $ cd neorv32\sw\example\demo_blink_led_asm ```
Note: if you changed the location of the precompiled RISCV binaries, you need to modify the file "neorv32\sw\common\common.mk" at the line # 42: ``` # Compiler toolchain RISCV_PREFIX = **\riscv-none-elf-** ``` Run the command **make all** (make sure all antivirus are disabled) ``` $ make all "Memory utilization:" text data bss dec hex filename 432 0 0 432 1b0 main.elf "Generationg APP BIN" "OK - APP BIN" "Generationg APP IMG VHD" "OK - APP IMG VHD" "Generationg RAW HEX" "OK - RAW HEX" "Generationg RAW BIN" "OK - RAW BIN" "Generationg BOOT IMG VHD" "OK - BOOT IMG VHD" "Memories Generated" ``` List the generated files and you will see
``` $ ls -l -rw-rw-rw- 1 adriz 0 6781 2024-02-24 01:45 main.asm -rw-rw-rw- 1 adriz 0 432 2024-02-24 01:45 main.bin -rw-rw-rw- 1 adriz 0 8708 2024-02-24 01:45 main.elf -rw-rw-rw- 1 adriz 0 5456 2024-02-23 16:14 main.S -rw-rw-rw- 1 adriz 0 2764 2024-02-24 01:45 main.S.o -rw-rw-rw- 1 adriz 0 274 2024-02-24 01:16 makefile -rw-rw-rw- 1 adriz 0 1882 2024-02-24 01:45 neorv32_application_image.vhd -rw-rw-rw- 1 adriz 0 1878 2024-02-24 01:45 neorv32_bootloader_image.vhd -rw-rw-rw- 1 adriz 0 444 2024-02-24 01:45 neorv32_exe.bin -rw-rw-rw- 1 adriz 0 432 2024-02-24 01:45 neorv32_raw_exe.bin -rw-rw-rw- 1 adriz 0 972 2024-02-24 01:45 neorv32_raw_exe.hex ``` You have been able to Assemble assembly code for the RISCV on windows. Go con the folder **neorv32\sw\example\demo_blink_led** which is the same example as the previous one but written on C code., and run the line "make all" ``` $ make all "Memory utilization:" text data bss dec hex filename 1092 0 0 1092 444 main.elf "Generationg APP BIN" "OK - APP BIN" "Generationg APP IMG VHD" "OK - APP IMG VHD" "Generationg RAW HEX" "OK - RAW HEX" "Generationg RAW BIN" "OK - RAW BIN" "Generationg BOOT IMG VHD" "OK - BOOT IMG VHD" "Memories Generated" ``` Now you have cross-compiled sucessfuly on windows for C and Assembly code. If you go to the folder **neorv32\sw\example**, and run the command "make all" you will be able to build all the projects within this folder. Enjoy! # Linux Installation and example of cross compilation ### 1. Installation Open shell and run: ``` sudo apt-get update sudo apt-get install autoconf automake autotools-dev curl python3 python3-pip libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev ninja-build git cmake libglib2.0-dev git clone https://github.com/riscv/riscv-gnu-toolchain cd riscv-gnu-toolchain/ mkdir build/ cd build sudo mkdir /opt/riscv32im sudo chown $USER /opt/riscv32im ./configure --with-arch=rv32im --prefix=/opt/riscv32im make -j$(nproc) ``` ### 2. Clone this repo Using shell, go to the directory where you cloned or donwloaded this repository to the directory **neorv32\sw\example\demo_blink_led_asm** ``` $ git clone https://gitea.squirrelnut.synology.me:5001/FPGALover/neorv32 $ cd neorv32\sw\example\demo_blink_led ``` Note: if you changed the location of the RISCV compiler, you need to modify the file "neorv32\sw\common\common.mk" on the line # 448: ``` ... # Compiler toolchain RISCV_PREFIX = **/bin/riscv32-unknown-elf-** ... ``` ### 3. Cross-Compile Run the command **make all** ``` $ make all Memory utilization: text data bss dec hex filename 1012 0 0 1012 3f4 main.elf Executable (neorv32_exe.bin) size in bytes: 1024 Installing application image to ../../../rtl/core/neorv32_application_image.vhd ``` List the generated files and you will see ``` $ ls -l -rw-r--r-- 1 adrizcorp adrizcorp 18160 Feb 24 01:54 main.asm -rw-r--r-- 1 adrizcorp adrizcorp 1012 Feb 24 01:54 main.bin -rw-r--r-- 1 adrizcorp adrizcorp 4314 Feb 23 15:08 main.c -rw-r--r-- 1 adrizcorp adrizcorp 7696 Feb 24 01:54 main.c.o -rwxr-xr-x 1 adrizcorp adrizcorp 42856 Feb 24 01:54 main.elf -rw-r--r-- 1 adrizcorp adrizcorp 141 Feb 23 15:08 makefile -rw-r--r-- 1 adrizcorp adrizcorp 3704 Feb 24 01:54 neorv32_application_image.vhd -rw-r--r-- 1 adrizcorp adrizcorp 1024 Feb 24 01:54 neorv32_exe.bin -rw-r--r-- 1 adrizcorp adrizcorp 1012 Feb 24 01:54 neorv32_raw_exe.bin -rw-r--r-- 1 adrizcorp adrizcorp 2277 Feb 24 01:54 neorv32_raw_exe.hex ``` Now you have been able to compile C code for the RISCV processor. Enjoy!