diff --git a/hw/README.md b/hw/README.md new file mode 100644 index 0000000..31b1115 --- /dev/null +++ b/hw/README.md @@ -0,0 +1,5 @@ +# X-HEEP hardware reference + +https://github.com/esl-epfl/x-heep-femu + +d7b7341d2be860289760541477f1009ade953a49 diff --git a/hw/x_heep.bit b/hw/x_heep.bit old mode 100755 new mode 100644 index 4972e12..31552a3 Binary files a/hw/x_heep.bit and b/hw/x_heep.bit differ diff --git a/hw/x_heep.hwh b/hw/x_heep.hwh old mode 100755 new mode 100644 index 27cf47b..49f4ec7 --- a/hw/x_heep.hwh +++ b/hw/x_heep.hwh @@ -1,5 +1,5 @@  - + @@ -109,16 +109,6 @@ - - - - - - - - - - @@ -284,7 +274,7 @@ - + @@ -294,7 +284,7 @@ - + @@ -304,17 +294,17 @@ - + - + - + @@ -394,7 +384,7 @@ - + @@ -414,7 +404,7 @@ - + @@ -469,7 +459,7 @@ - + @@ -509,6 +499,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -699,6 +884,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -724,14 +1004,34 @@ - + + + + + + + + + + + - + + + + + + - + - + + + + + + @@ -781,17 +1081,11 @@ - - - - - - - + @@ -813,7 +1107,7 @@ - + @@ -861,10 +1155,12 @@ - + + - + + @@ -875,7 +1171,7 @@ - + @@ -897,7 +1193,7 @@ - + @@ -945,10 +1241,98 @@ - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -981,7 +1365,7 @@ - + @@ -1035,7 +1419,7 @@ - + @@ -1063,31 +1447,85 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1707,8 +2145,8 @@ - - + + @@ -2035,44 +2473,44 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -2085,6 +2523,26 @@ + + + + + + + + + + + + + + + + + + + + @@ -2105,7 +2563,27 @@ - + + + + + + + + + + + + + + + + + + + + + @@ -2190,7 +2668,7 @@ - + @@ -2210,7 +2688,7 @@ - + @@ -2270,7 +2748,7 @@ - + @@ -2300,7 +2778,7 @@ - + @@ -2385,7 +2863,7 @@ - + @@ -2405,7 +2883,7 @@ - + @@ -2465,7 +2943,7 @@ - + @@ -2685,543 +3163,1213 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + @@ -3400,6 +4548,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3481,6 +4714,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3740,11 +5038,11 @@ - + - + @@ -3995,12 +5293,12 @@ - + - + @@ -4635,7 +5933,7 @@ - + @@ -4655,12 +5953,12 @@ - + - + - + @@ -4708,154 +6006,349 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -5059,21 +6552,221 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + @@ -5239,7 +6932,7 @@ - + @@ -5255,6 +6948,16 @@ + + + + + + + + + + @@ -5328,6 +7031,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -5401,11 +7177,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + @@ -5453,13 +7303,10 @@ - - - - - - + + + diff --git a/sw/arm/apps/virtual_obi_read/virtual_obi_read.py b/sw/arm/apps/virtual_obi_read/virtual_obi_read.py new file mode 100644 index 0000000..8f8b294 --- /dev/null +++ b/sw/arm/apps/virtual_obi_read/virtual_obi_read.py @@ -0,0 +1,32 @@ +# Copyright 2023 EPFL +# Solderpad Hardware License, Version 2.1, see LICENSE.md for details. +# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +# +# Author: Simone Machetti - simone.machetti@epfl.ch + +# Import the X-HEEP Python class +from pynq import x_heep + +# Load the X-HEEP bitstream +x_heep = x_heep() + +# Compile the application +x_heep.compile_app("virtual_obi_read") + +# Init the OBI memory +obi = x_heep.init_obi_mem() + +# Reset the OBI memory +x_heep.reset_obi_mem(obi) + +# Write to the OBI memory +write_list = list() +for i in range(1024): + write_list.append(i ** 2) +x_heep.write_obi_mem(write_list, obi) + +# Run the application +x_heep.run_app() + +# Delete OBI +del obi diff --git a/sw/arm/apps/virtual_obi_write/virtual_obi_write.py b/sw/arm/apps/virtual_obi_write/virtual_obi_write.py new file mode 100644 index 0000000..861dbf6 --- /dev/null +++ b/sw/arm/apps/virtual_obi_write/virtual_obi_write.py @@ -0,0 +1,34 @@ +# Copyright 2023 EPFL +# Solderpad Hardware License, Version 2.1, see LICENSE.md for details. +# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +# +# Author: Simone Machetti - simone.machetti@epfl.ch + +# Import the X-HEEP Python class +from pynq import x_heep + +# Load the X-HEEP bitstream +x_heep = x_heep() + +# Compile the application +x_heep.compile_app("virtual_obi_write") + +# Init the OBI memory +obi = x_heep.init_obi_mem() + +# Reset the OBI memory +x_heep.reset_obi_mem(obi) + +# Run the application +x_heep.run_app() + +# Read the OBI memory +obi_read = x_heep.read_obi_mem(obi) +target_read = list() +for i in range(1024): + target_read.append(i ** 2) +if target_read == obi_read: + print("Write operation successful.") + +# Delete OBI +del obi diff --git a/sw/arm/jupyter_notebooks/virtual_obi_read.ipynb b/sw/arm/jupyter_notebooks/virtual_obi_read.ipynb new file mode 100755 index 0000000..887ef45 --- /dev/null +++ b/sw/arm/jupyter_notebooks/virtual_obi_read.ipynb @@ -0,0 +1,116 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "63f1eaa7", + "metadata": {}, + "outputs": [], + "source": [ + "# Import the X-HEEP Python class\n", + "from pynq import x_heep" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2d224b64", + "metadata": {}, + "outputs": [], + "source": [ + "# Load the X-HEEP bitstream\n", + "x_heep = x_heep()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6af7d95", + "metadata": {}, + "outputs": [], + "source": [ + "# Compile the application\n", + "x_heep.compile_app(\"virtual_obi_read\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "75a905c1", + "metadata": {}, + "outputs": [], + "source": [ + "# Init the OBI memory\n", + "obi = x_heep.init_obi_mem()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "00c60248", + "metadata": {}, + "outputs": [], + "source": [ + "# Reset the OBI memory\n", + "x_heep.reset_obi_mem(obi)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "35615647", + "metadata": {}, + "outputs": [], + "source": [ + "# Write to the OBI memory\n", + "write_list = list()\n", + "for i in range(1024):\n", + " write_list.append(i ** 2)\n", + "x_heep.write_obi_mem(write_list, obi)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b4b82dd7", + "metadata": {}, + "outputs": [], + "source": [ + "# Run the application\n", + "x_heep.run_app()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "84f8d8c9", + "metadata": {}, + "outputs": [], + "source": [ + "# Delete OBI\n", + "del obi" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/sw/arm/jupyter_notebooks/virtual_obi_write.ipynb b/sw/arm/jupyter_notebooks/virtual_obi_write.ipynb new file mode 100755 index 0000000..ab527d6 --- /dev/null +++ b/sw/arm/jupyter_notebooks/virtual_obi_write.ipynb @@ -0,0 +1,118 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "63f1eaa7", + "metadata": {}, + "outputs": [], + "source": [ + "# Import the X-HEEP Python class\n", + "from pynq import x_heep" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2d224b64", + "metadata": {}, + "outputs": [], + "source": [ + "# Load the X-HEEP bitstream\n", + "x_heep = x_heep()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6af7d95", + "metadata": {}, + "outputs": [], + "source": [ + "# Compile the application\n", + "x_heep.compile_app(\"virtual_obi_write\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "75a905c1", + "metadata": {}, + "outputs": [], + "source": [ + "# Init the OBI memory\n", + "obi = x_heep.init_obi_mem()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "35615647", + "metadata": {}, + "outputs": [], + "source": [ + "# Reset the OBI memory\n", + "x_heep.reset_obi_mem(obi)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fd8e74c7", + "metadata": {}, + "outputs": [], + "source": [ + "# Run the application\n", + "x_heep.run_app()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b9065ea6", + "metadata": {}, + "outputs": [], + "source": [ + "# Read the OBI memory\n", + "obi_read = x_heep.read_obi_mem(obi)\n", + "target_read = list()\n", + "for i in range(1024):\n", + " target_read.append(i ** 2)\n", + "if target_read == obi_read:\n", + " print(\"Write operation successful.\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e507c63", + "metadata": {}, + "outputs": [], + "source": [ + "# Delete OBI\n", + "del obi" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/sw/arm/sdk/x_heep_api.py b/sw/arm/sdk/x_heep_api.py index 9039745..068728b 100755 --- a/sw/arm/sdk/x_heep_api.py +++ b/sw/arm/sdk/x_heep_api.py @@ -13,11 +13,12 @@ ADC_OFFSET = 0x40000000 FLASH_AXI_ADDRESS_ADDER_OFFSET = 0x43C00000 -PERFORMANCE_COUNTERS_OFFSET = 0x43C10000 +OBI_AXI_ADDRESS_ADDER_OFFSET = 0x43C10000 +PERFORMANCE_COUNTERS_OFFSET = 0x43C20000 class x_heep(Overlay): - def __init__(self, **kwargs): + def __init__(self, ILA_debug = False, **kwargs): # Load bitstream super().__init__("/home/xilinx/x-heep-femu-sdk/hw/x_heep.bit", **kwargs) @@ -127,6 +128,39 @@ def read_adc_mem(self, adc_mem): file.close() + def init_obi_mem(self): + + # Allocate OBI memory + obi = allocate(shape=(1024,)) + + # Write OBI memory base address to AXI address adder + axi_address_adder = MMIO(OBI_AXI_ADDRESS_ADDER_OFFSET, 0x4) + axi_address_adder.write(0x0, obi.physical_address) + + # Reset OBI memory + obi[:] = 0 + + return obi + + + def reset_obi_mem(self, obi): + + # Reset OBI memory + obi[:] = 0 + + + def write_obi_mem(self, write_list, obi): + + # Write OBI memory + obi[:] = write_list + + + def read_obi_mem(self, obi): + + # Read OBI memory + return list(obi) + + def init_perf_cnt(self): # Map performance counters diff --git a/sw/riscv/Makefile b/sw/riscv/Makefile index de4e992..ee789ea 100755 --- a/sw/riscv/Makefile +++ b/sw/riscv/Makefile @@ -152,5 +152,37 @@ apps/energy_estimation/energy_estimation.elf: apps/energy_estimation/energy_esti -L $(RISCV)/riscv32-unknown-elf/lib \ -lc -lm -lgcc -flto -ffunction-sections -fdata-sections -specs=nano.specs +apps/virtual_obi_read/virtual_obi_read.elf: apps/virtual_obi_read/virtual_obi_read.c + $(RISCV_EXE_PREFIX)gcc -march=rv32imc -o $@ -w -Os -g -nostdlib \ + $(CUSTOM_GCC_FLAGS) \ + -DHOST_BUILD \ + -T link/link.ld \ + -I $(RISCV)/riscv32-unknown-elf/include \ + $(INC_FOLDERS_GCC) \ + -static \ + $(LIB_CRT) \ + $^ $(LIB_RUNTIME) \ + $(LIB_BASE) \ + $(LIB_DRIVERS) \ + -Wl,-Map=apps/virtual_obi_read/virtual_obi_read.map \ + -L $(RISCV)/riscv32-unknown-elf/lib \ + -lc -lm -lgcc -flto -ffunction-sections -fdata-sections -specs=nano.specs + +apps/virtual_obi_write/virtual_obi_write.elf: apps/virtual_obi_write/virtual_obi_write.c + $(RISCV_EXE_PREFIX)gcc -march=rv32imc -o $@ -w -Os -g -nostdlib \ + $(CUSTOM_GCC_FLAGS) \ + -DHOST_BUILD \ + -T link/link.ld \ + -I $(RISCV)/riscv32-unknown-elf/include \ + $(INC_FOLDERS_GCC) \ + -static \ + $(LIB_CRT) \ + $^ $(LIB_RUNTIME) \ + $(LIB_BASE) \ + $(LIB_DRIVERS) \ + -Wl,-Map=apps/virtual_obi_write/virtual_obi_write.map \ + -L $(RISCV)/riscv32-unknown-elf/lib \ + -lc -lm -lgcc -flto -ffunction-sections -fdata-sections -specs=nano.specs + clean: rm -rf build diff --git a/sw/riscv/apps/virtual_obi_read/virtual_obi_read.c b/sw/riscv/apps/virtual_obi_read/virtual_obi_read.c new file mode 100644 index 0000000..cc67235 --- /dev/null +++ b/sw/riscv/apps/virtual_obi_read/virtual_obi_read.c @@ -0,0 +1,31 @@ +/* +* Copyright 2023 EPFL +* Solderpad Hardware License, Version 2.1, see LICENSE.md for details. +* SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +* +* Author: Simone Machetti - simone.machetti@epfl.ch +*/ + +#include +#include +#include "core_v_mini_mcu.h" + +int main(int argc, char *argv[]) +{ + unsigned int* pointer = (unsigned int*)EXT_SLAVE_START_ADDRESS; + unsigned int value = *pointer; + + for (int i=0; i < 1024; i++){ + value = *pointer; + if (value != i * i){ + printf("An element does not match!"); + printf("Not matching: %d -- %d", value, i*i); + return EXIT_FAILURE; + } + pointer++; + } + + printf("Read operation successful."); + + return EXIT_SUCCESS; +} diff --git a/sw/riscv/apps/virtual_obi_write/virtual_obi_write.c b/sw/riscv/apps/virtual_obi_write/virtual_obi_write.c new file mode 100644 index 0000000..405e0df --- /dev/null +++ b/sw/riscv/apps/virtual_obi_write/virtual_obi_write.c @@ -0,0 +1,25 @@ +/* +* Copyright 2023 EPFL +* Solderpad Hardware License, Version 2.1, see LICENSE.md for details. +* SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +* +* Author: Simone Machetti - simone.machetti@epfl.ch +*/ + +#include +#include +#include "core_v_mini_mcu.h" + +int main(int argc, char *argv[]) +{ + unsigned int* pointer = (unsigned int*)EXT_SLAVE_START_ADDRESS; + + for (int i=0; i < 1024; i++){ + *pointer = i*i; + pointer++; + } + + printf("Done.\n\r"); + + return EXIT_SUCCESS; +}