Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update of UART SDK and some minor features #1

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified hw/x_heep.bit
Binary file not shown.
312 changes: 156 additions & 156 deletions hw/x_heep.hwh

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions sw/arm/jupyter_notebooks/energy_estimation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"outputs": [],
"source": [
"# Compile the application\n",
"x_heep.compile_app(\"energy_estimation\")"
"x_heep.compile_app(\"energy_estimation\");"
]
},
{
Expand Down Expand Up @@ -75,8 +75,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Run the application\n",
"x_heep.run_app()"
"t, sf = x_heep.thread_start() # Start a background thread that reads from the UART\n",
"out, _ = x_heep.run_app() # Run the application (disregarding the error output)\n",
"x_heep.thread_stop(t, sf) # Stop the background thread that reads from the UART"
]
},
{
Expand Down
20 changes: 6 additions & 14 deletions sw/arm/jupyter_notebooks/hello_world.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@
"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": [
"from pynq import x_heep\n",
"# Load the X-HEEP bitstream\n",
"x_heep = x_heep()"
]
Expand All @@ -30,18 +21,19 @@
"outputs": [],
"source": [
"# Compile the application\n",
"x_heep.compile_app(\"hello_world\")"
"x_heep.compile_app(\"hello_world\");"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fd8e74c7",
"id": "96d2d8a3",
"metadata": {},
"outputs": [],
"source": [
"# Run the application\n",
"x_heep.run_app()"
"t, sf = x_heep.thread_start() # Start a background thread that reads from the UART\n",
"out, _ = x_heep.run_app() # Run the application (disregarding the error output)\n",
"x_heep.thread_stop(t, sf) # Stop the background thread that reads from the UART"
]
}
],
Expand Down
7 changes: 4 additions & 3 deletions sw/arm/jupyter_notebooks/performance_estimation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"outputs": [],
"source": [
"# Compile the application\n",
"x_heep.compile_app(\"performance_estimation\")"
"x_heep.compile_app(\"performance_estimation\");"
]
},
{
Expand Down Expand Up @@ -75,8 +75,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Run the application\n",
"x_heep.run_app()"
"t, sf = x_heep.thread_start() # Start a background thread that reads from the UART\n",
"out, _ = x_heep.run_app() # Run the application (disregarding the error output)\n",
"x_heep.thread_stop(t, sf) # Stop the background thread that reads from the UART"
]
},
{
Expand Down
131 changes: 97 additions & 34 deletions sw/arm/jupyter_notebooks/virtual_adc_read.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "9a4c49a0",
"metadata": {},
"source": [
"# Virtual ADC example\n",
"---\n"
]
},
{
"cell_type": "markdown",
"id": "2fd59f4a",
"metadata": {},
"source": [
"## Load the bitstream into the Programmable Logic"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -10,86 +27,132 @@
"outputs": [],
"source": [
"# Import the X-HEEP Python class\n",
"from pynq import x_heep"
"from pynq import x_heep\n",
"# Load the X-HEEP bitstream\n",
"xh = x_heep()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e11233ef",
"metadata": {
"scrolled": true
},
"outputs": [],
"cell_type": "markdown",
"id": "c9e56e3e",
"metadata": {},
"source": [
"# Load the X-HEEP bitstream\n",
"x_heep = x_heep()"
"## Generate a random array to use as input signal "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "37d96249",
"id": "3b18fcf9",
"metadata": {},
"outputs": [],
"source": [
"# Compile the application\n",
"x_heep.compile_app(\"virtual_adc_read\")"
"import numpy as np\n",
"# Set the seed for reproducibility (optional)\n",
"np.random.seed(46)\n",
"\n",
"# Generate a random integer array\n",
"array_size = 32\n",
"rand_in = np.random.randint(0, 100, size=array_size, dtype=np.int32)\n",
"\n",
"# Print the generated array\n",
"print(\"Generated Array:\", rand_in)\n",
"\n",
"# Save the array to a binary file\n",
"file_path = \"/home/xilinx/x-heep-femu-sdk/sw/riscv/apps/virtual_adc_read/adc_in.bin\"\n",
"data = rand_in.copy()\n",
"with open(file_path, 'wb') as file:\n",
" data.byteswap(True).tofile(file)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b6a2e17d",
"cell_type": "markdown",
"id": "b693f119",
"metadata": {},
"outputs": [],
"source": [
"# Init the ADC memory\n",
"adc = x_heep.init_adc_mem()"
"## Compile the code and run the application\n",
"You can change the variable `SKIP_COMPILE` to 1 to avoid compiling each time."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "83ad80fc",
"id": "37d96249",
"metadata": {},
"outputs": [],
"source": [
"# Reset the ADC memory\n",
"x_heep.reset_adc_mem(adc)"
"# This will automatically make accessible the changes made in the sdk\n",
"%reload_ext autoreload \n",
"\n",
"# Skip compiling if all you want to do is run the application\n",
"SKIP_COMPILE = 0\n",
"\n",
"# Compile the application\n",
"if SKIP_COMPILE or xh.compile_app(\"virtual_adc_read\"):\n",
" adc = xh.init_adc_mem() # Init the ADC memory\n",
" xh.reset_adc_mem(adc) # Reset the ADC memory\n",
" xh.write_adc_mem(adc) # Write the ADC memory\n",
"\n",
" t, sf = xh.thread_start() # Start a background thread that reads from the UART\n",
" out, _ = xh.run_app() # Run the application (disregarding the error output)\n",
" xh.thread_stop(t, sf) # Stop the background thread that reads from the UART"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23c2adb4",
"attachments": {},
"cell_type": "markdown",
"id": "e5984a04",
"metadata": {},
"outputs": [],
"source": [
"# Write the ADC memory\n",
"x_heep.write_adc_mem(adc)"
"### Check if the CPU's output is the same as the expected result\n",
"\n",
"The application is supposed to make the difference of every consecutive pair:\n",
"\n",
"$y[0] = x[0]$\n",
"\n",
"$y[i] = x[i] - x[i-1]$ \n",
"\n",
"$i \\in (0,N]$"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c5429d6",
"id": "155c59b1",
"metadata": {},
"outputs": [],
"source": [
"# Run the application\n",
"x_heep.run_app()"
"app_out = [int(x) for x in xh.uart_data if x.strip()]\n",
"\n",
"exp_out = [rand_in[i] - rand_in[i-1] for i in range(1, len(rand_in))]\n",
"\n",
"if all([a == e for a,e in zip(app_out, exp_out)]): print(\"✅ SUCCESS\")\n",
"else: print(\"❌ FAILED\")\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "35374e96",
"metadata": {},
"source": [
"## Plot the input and output"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ce8e1af0",
"id": "a08fa0cc",
"metadata": {},
"outputs": [],
"source": [
"# Delete adc\n",
"del adc"
"import matplotlib.pyplot as plt\n",
"\n",
"plt.plot(rand_in)\n",
"plt.plot(app_out)\n",
"\n",
"plt.legend([\"Input\", \"Difference\"])\n",
"\n"
]
}
],
Expand Down
19 changes: 4 additions & 15 deletions sw/arm/jupyter_notebooks/virtual_adc_write.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"outputs": [],
"source": [
"# Compile the application\n",
"x_heep.compile_app(\"virtual_adc_write\")"
"x_heep.compile_app(\"virtual_adc_write\");"
]
},
{
Expand Down Expand Up @@ -68,8 +68,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Run the application\n",
"x_heep.run_app()"
"t, sf = x_heep.thread_start() # Start a background thread that reads from the UART\n",
"out, _ = x_heep.run_app() # Run the application (disregarding the error output)\n",
"x_heep.thread_stop(t, sf) # Stop the background thread that reads from the UART"
]
},
{
Expand Down Expand Up @@ -100,18 +101,6 @@
"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,
Expand Down
19 changes: 4 additions & 15 deletions sw/arm/jupyter_notebooks/virtual_flash_read.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"outputs": [],
"source": [
"# Compile the application\n",
"x_heep.compile_app(\"virtual_flash_read\")"
"x_heep.compile_app(\"virtual_flash_read\");"
]
},
{
Expand Down Expand Up @@ -83,8 +83,9 @@
},
"outputs": [],
"source": [
"# Run the application\n",
"x_heep.run_app()"
"t, sf = x_heep.thread_start() # Start a background thread that reads from the UART\n",
"out, _ = x_heep.run_app() # Run the application (disregarding the error output)\n",
"x_heep.thread_stop(t, sf) # Stop the background thread that reads from the UART"
]
},
{
Expand All @@ -106,18 +107,6 @@
"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,
Expand Down
19 changes: 4 additions & 15 deletions sw/arm/jupyter_notebooks/virtual_flash_write.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"outputs": [],
"source": [
"# Compile the application\n",
"x_heep.compile_app(\"virtual_flash_write\")"
"x_heep.compile_app(\"virtual_flash_write\");"
]
},
{
Expand Down Expand Up @@ -72,8 +72,9 @@
},
"outputs": [],
"source": [
"# Run the application\n",
"x_heep.run_app()"
"t, sf = x_heep.thread_start() # Start a background thread that reads from the UART\n",
"out, _ = x_heep.run_app() # Run the application (disregarding the error output)\n",
"x_heep.thread_stop(t, sf) # Stop the background thread that reads from the UART"
]
},
{
Expand Down Expand Up @@ -108,18 +109,6 @@
"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,
Expand Down
Loading