### Install Alveo Examples Package using PIP Source: https://github.com/xilinx/pynq/blob/master/docs/source/getting_started/alveo_getting_started.rst Installs the pynq-alveo-examples package, which provides introductory examples for PYNQ on Alveo. This package is installed via pip. ```bash pip install pynq-alveo-examples ``` -------------------------------- ### Retrieve PYNQ Notebooks Source: https://github.com/xilinx/pynq/blob/master/docs/source/getting_started/alveo_getting_started.rst Fetches all available PYNQ notebooks, typically for Alveo examples, into a local 'pynq-notebooks' directory. This command may download overlays. ```bash pynq get-notebooks ``` -------------------------------- ### Install Jupyter using PIP Source: https://github.com/xilinx/pynq/blob/master/docs/source/getting_started/alveo_getting_started.rst Installs the Jupyter Notebook package using pip. This is an alternative to installing it via the pynq-alveo-examples package. ```bash pip install jupyter ``` -------------------------------- ### Install PYNQ Development Version from Source Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_remote/quickstart.rst Installs the latest development version of PYNQ by cloning the GitHub repository and installing it directly from the source code. This is useful for users who want the newest features or are contributing to PYNQ development. ```bash pip install git+https://github.com/Xilinx/PYNQ.git ``` -------------------------------- ### Download and Install Anaconda Source: https://github.com/xilinx/pynq/blob/master/docs/source/getting_started/alveo_getting_started.rst Downloads the Anaconda installer script and then executes it to install the Anaconda Python distribution. This is recommended for managing PYNQ environments. ```bash wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh -O anaconda3.sh bash anaconda3.sh ``` -------------------------------- ### Source XRT Setup Script Source: https://github.com/xilinx/pynq/blob/master/docs/source/getting_started/alveo_getting_started.rst Executes the Xilinx Runtime (XRT) setup script. This must be done in every bash session before using PYNQ with Alveo. The path is typically fixed. ```bash source /opt/xilinx/xrt/setup.sh ``` -------------------------------- ### Start Jupyter Lab Server Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_remote/quickstart.rst Launches the Jupyter Lab environment, providing a web-based interface to access and run PYNQ notebooks. This command is essential for interacting with the PYNQ framework and executing the example code. ```bash jupyter lab ``` ```bash python -m jupyterlab ``` -------------------------------- ### Navigate to Notebooks and Start Jupyter Source: https://github.com/xilinx/pynq/blob/master/docs/source/getting_started/alveo_getting_started.rst Changes the current directory to the 'pynq-notebooks' folder and starts the Jupyter Notebook server. Assumes notebooks have been previously retrieved. ```bash cd pynq-notebooks jupyter notebook ``` -------------------------------- ### Install PYNQ-HelloWorld Dependencies and Overlay Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_remote/quickstart.rst Installs necessary Python packages like jupyterlab, matplotlib, and pillow, followed by the pynq-helloworld overlay. The BOARD environment variable must be set to target the correct AMD adaptive SoC. ```bash pip install jupyterlab matplotlib pillow wheel BOARD=ZCU104 pip install --no-build-isolation pynq-helloworld ``` ```powershell $env:BOARD="ZCU104"; pip install --no-build-isolation pynq-helloworld ``` ```batch set BOARD=ZCU104 && pip install --no-build-isolation pynq-helloworld ``` -------------------------------- ### Install PYNQ Package using PIP Source: https://github.com/xilinx/pynq/blob/master/docs/source/getting_started/alveo_getting_started.rst Installs the PYNQ Python package using the pip package installer. This is a fundamental step for using PYNQ. ```bash pip install pynq ``` -------------------------------- ### Download PYNQ Notebooks and Overlay Files Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_remote/quickstart.rst Downloads the PYNQ-HelloWorld notebooks and overlay files for a specified board. The '-d' argument is crucial for the get-notebooks function to locate the correct files for the target device. ```bash pynq get-notebooks pynq-helloworld -d ZCU104 ``` -------------------------------- ### Get Help on PYNQ Video Subsystem Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_overlays/loading_an_overlay.ipynb This example shows how to use the `help()` function to get detailed information about the video subsystem, specifically the `HDMIWrapper` class. This is useful for understanding the available attributes and methods for video input/output control. ```python help(base_overlay.video) ``` -------------------------------- ### Run Host Setup Script for VM-Based Build Source: https://github.com/xilinx/pynq/blob/master/sdbuild/README.md Executes the setup script for the VM-based PYNQ image build process. This script installs required packages and configures the host environment. It's a prerequisite for building PYNQ images without Docker on a supported Linux distribution. Ensure sudo is configured for passwordless use. ```shell scripts/setup_host.sh ``` -------------------------------- ### PYNQ CLI: Accessing Examples Help Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_cli.rst Shows how to display the help message for the 'pynq examples' command, which may contain additional options related to examples. ```bash pynq examples --help ``` -------------------------------- ### Install and Upgrade IPython for Older Python Versions Source: https://github.com/xilinx/pynq/blob/master/docs/source/getting_started/alveo_getting_started.rst This command ensures a compatible version of IPython is installed when using Python versions older than 3.6 with Jupyter. It's a crucial step for maintaining stability and functionality. ```bash pip install --upgrade ipython==7.9 ``` -------------------------------- ### Accessing PYNQ MicroBlaze Examples Source: https://github.com/xilinx/pynq/blob/master/docs/source/overlay_design_methodology/pynq_microblaze_subsystem.rst This command shows the directory where example PYNQ MicroBlaze code can be found. Users can navigate to this directory to explore and utilize pre-built examples for programming the MicroBlaze. ```console /base/microblaze ``` -------------------------------- ### Instantiate BaseOverlay and Pmod_PWM in Python Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z2/base/notebooks/pmod/pmod_pwm.ipynb Imports the BaseOverlay from pynq.overlays.base and instantiates it. Then, it imports Pmod_PWM and creates an instance for PMODA, setting the initial pin to 0. This is the setup required to use the Pmod PWM functionality. ```python from pynq.overlays.base import BaseOverlay base = BaseOverlay("base.bit") from pynq.lib import Pmod_PWM pwm = Pmod_PWM(base.PMODA,0) ``` -------------------------------- ### Access Arduino Examples Directory Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_libraries/arduino.rst This console command shows how to navigate to the directory containing Arduino-related example notebooks on a PYNQ-Z1 board. This is useful for exploring further practical applications. ```bash /base/arduino/ ``` -------------------------------- ### Create Conda Environment from File Source: https://github.com/xilinx/pynq/blob/master/docs/source/getting_started/alveo_getting_started.rst Creates a Conda environment named 'pynq-env' using the specified 'environment.yml' configuration file. This ensures a tested and working environment. ```bash conda env create -f environment.yml ``` -------------------------------- ### Access Example Notebook Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_libraries/axigpio.rst Provides the console command to locate an example notebook demonstrating the use of buttons and LEDs with the AxiGPIO module on PYNQ boards. ```console /base/board/board_btns_leds.ipynb ``` -------------------------------- ### Setup and Run Boolean Generator - Python Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/logictools/notebooks/boolean_generator.ipynb Initializes the boolean generator object, sets up the defined boolean function, and runs the generator for verification. The 'setup()' method configures the logic, and 'run()' executes it. ```python boolean_generator = logictools_olay.boolean_generator boolean_generator.setup(function) boolean_generator.run() ``` -------------------------------- ### Configure PYNQ Board Specifications (Makefile) Source: https://github.com/xilinx/pynq/blob/master/sdbuild/README.md This Makefile snippet defines essential board-specific configurations for PYNQ, including the PetaLinux BSP file, the bitstream to load on boot, and any additional packages to install in the root filesystem. These variables are crucial for the build process and image customization. ```makefile BSP_Myboard := Myboard.bsp BITSTREAM_Myboard := Myboard.bit # Optionally install some additional packages STAGE4_PACKAGES_Myboard := my_package ``` -------------------------------- ### Start Logging Multiple Arduino Analog Devices in PYNQ Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/arduino/arduino_analog.ipynb This code initializes and starts logging from multiple Arduino analog devices simultaneously. It specifies the base Arduino interface and a list of Grove connections to monitor. ```python analog2 = Arduino_Analog(base.ARDUINO,[0,1,4]) analog2.set_log_interval_ms(100) analog2.start_log() ``` -------------------------------- ### Accessing RPi Examples Directory (Console) Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_libraries/rpi.rst This snippet shows how to navigate to the directory containing RPi examples on a PYNQ-Z2 board using the Jupyter Dashboard. It assumes access to the board's file system via the dashboard. ```console /base/rpi/ ``` -------------------------------- ### Install XRT on PYNQ using qemu.sh script Source: https://github.com/xilinx/pynq/blob/master/sdbuild/packages/xrtlib/README.md Automates the process of building and installing XRT for PYNQ devices. It can download pre-built packages or build XRT from source if the force-rebuild option is used. Installs XRT and pyxrt.so, and creates a Debian package. ```bash chmod +x qemu.sh ./qemu.sh [--force-rebuild] ``` -------------------------------- ### Activate Conda Environment Source: https://github.com/xilinx/pynq/blob/master/docs/source/getting_started/alveo_getting_started.rst Sources the Conda activation script to add Conda to the system's PATH. This is necessary if Conda is not automatically added during installation. ```bash source /bin/activate ``` -------------------------------- ### Build PYNQ Image using Make (VM-Based) Source: https://github.com/xilinx/pynq/blob/master/sdbuild/README.md Initiates the PYNQ image build process when using the VM-based setup. This command assumes Petalinux is installed and on the PATH, and that prebuilt tarballs are placed in 'sdbuild/prebuilt/'. The BOARDDIR argument specifies the directory containing board-specific configurations. ```shell make BOARDDIR= ``` -------------------------------- ### Configure and Start HDMI Interfaces Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/notebooks/getting_started/5_base_overlay_video.ipynb Configures the HDMI input and output interfaces, setting the output mode to match the input, and then starts both interfaces. This prepares them for data transfer. ```python hdmi_in.configure() hdmi_out.configure(hdmi_in.mode) hdmi_in.start() hdmi_out.start() ``` -------------------------------- ### Example wpa_supplicant.conf Network Configuration Source: https://github.com/xilinx/pynq/blob/master/sdbuild/packages/wifi_connect/README.md This snippet demonstrates the structure of a `wpa_supplicant.conf` file, which is used to configure WiFi networks for automatic connection. It shows how to define multiple networks with their SSIDs, passwords (plain text or hashed), and unique IDs. This configuration is typically placed in the boot partition for automated setup. ```shell network={ # Network name ssid="MyHomeNetwork" # Password in plain text using quotes psk="AndItsPlaintextPassword" # A unique ID for this entry id_str="home" } network={ # Second network name ssid="ConferenceWiFi" # Password obfuscated with wpa_passphrase command psk=d1d140ae3d73f946bfb117479b8967a5a5b541f712c0f40ba8049f34ce43e89c # A unique ID id_str="demonight" } ``` -------------------------------- ### Clone PYNQ Repository (Bash) Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_remote/image_build.rst Clones the PYNQ repository and its submodules. This is the first step in setting up the build environment. Ensure you have Git installed. ```bash git clone --recursive https://github.com/Xilinx/PYNQ.git ``` -------------------------------- ### Grove OLED Microblaze Driver Example Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/pmod/pmod_grove_oled.ipynb Example demonstrating the usage of the existing Microblaze driver for the Grove OLED Pmod, highlighting its speed advantage. ```APIDOC ## Grove_OLED Initialization and Usage ### Description This example shows how to initialize and use the Grove_OLED class, which utilizes an existing Microblaze driver for potentially faster performance. ### Method Initialize the `Grove_OLED` object, clear the screen, write text, and then delete the object. ### Endpoint N/A (This is a Python code example) ### Parameters - **pmod_id** (object) - Required - The PMOD object (e.g., `base.PMODB`). - **pmod_port** (constant) - Required - The Grove connection port (e.g., `PMOD_GROVE_G3`). ### Request Example ```python from pynq.lib.pmod import Grove_OLED from pynq.lib.pmod import PMOD_GROVE_G3 from pynq import PL # Flush IOP PL.reset() # Initialize the Grove_OLED object oled = Grove_OLED(base.PMODB, PMOD_GROVE_G3) # Clear the screen oled.clear() # Write text to the screen oled.write('Hello from Microblaze.') # Delete the object to release resources del oled ``` ### Response N/A (This is an example of how to use the driver, not an API response) ### Error Handling - `ValueError`: If invalid `gr_pins` are provided during initialization (handled internally by the class). ``` -------------------------------- ### Start Logging with Grove ADC (Pmod Adapter) Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/pmod/pmod_grove_adc.ipynb Configures and starts logging analog readings from the Grove ADC connected via the Pmod adapter at a specified interval (100 milliseconds). This allows for continuous data collection over time. ```python grove_adc.set_log_interval_ms(100) grove_adc.start_log() ``` -------------------------------- ### Start Analog Logging in PYNQ Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/arduino/arduino_analog.ipynb This code configures and starts logging analog values from an Arduino analog controller. It sets the logging interval in milliseconds and initiates the data capture process. ```python from time import sleep analog1.set_log_interval_ms(100) analog1.start_log() ``` -------------------------------- ### Start Grove ADC Logging with Pmod Adapter Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z2/base/notebooks/pmod/pmod_grove_adc.ipynb Configures and starts logging analog readings from the Grove ADC connected via the Pmod adapter. Readings are logged at a specified interval (100ms). ```python grove_adc.set_log_interval_ms(100) grove_adc.start_log() ``` -------------------------------- ### Example Usage with LEDs Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_overlays/loading_an_overlay.ipynb Demonstrates how to use the PYNQ API to toggle an LED, illustrating the object-oriented control. ```APIDOC ## LED Control Example ### Description This example shows how to toggle a specific LED on the board using the PYNQ overlay and channel/pin access. ### Method - **`base_overlay.leds[index].toggle()`** - Toggles the state of the LED at the specified index. ### Endpoint Not applicable, this is a Python code example within the PYNQ framework. ### Parameters #### `leds[index].toggle()` - **`index`** (int) - Required - The index of the LED to toggle (e.g., 0 for LD0). ### Request Example ```python # Assuming 'base_overlay' is an initialized PYNQ overlay object base_overlay.leds[0].toggle() # Toggles LD0 on the board ``` ### Response No direct response, the action directly affects the hardware (LED state change). ``` -------------------------------- ### Initialize and Start HDMI Output Frontend (Python) Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z2/base/notebooks/video/hdmi_video_pipeline.ipynb Accesses and initializes the HDMI output frontend driver. Before starting, the video mode must be set, typically to match the input frontend's mode. Starting this frontend prepares for video output. ```python hdmiout_frontend = base.video.hdmi_out.frontend hdmiout_frontend.mode = hdmiin_frontend.mode hdmiout_frontend.start() ``` -------------------------------- ### Initialize and Start HDMI Output Frontend Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/video/hdmi_video_pipeline.ipynb Initializes the HDMI output frontend driver and sets its video mode to match the input. The 'start()' method is called to prepare the output, though no video data is sent by default. ```python hdmiout_frontend = base.video.hdmi_out.frontend hdmiout_frontend.mode = hdmiin_frontend.mode hdmiout_frontend.start() ``` -------------------------------- ### Install Vivado Board Files for PYNQ Source: https://github.com/xilinx/pynq/blob/master/docs/source/overlay_design_methodology/board_settings.rst This console command shows the target directory within a Xilinx Vivado installation where board files should be copied to enable selection of specific PYNQ boards when creating new projects. Restarting Vivado is required after installation. ```console /Vivado//data/xhub/boards/XilinxBoardStore/boards/Xilinx/ ``` -------------------------------- ### Set up Xilinx Tool Environment inside Docker Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_sd_card.rst Sources the environment setup scripts for Vivado and PetaLinux within the Docker container. This makes the Xilinx tools available in the container's PATH, enabling their use for building PYNQ images. Adjust paths to match your specific installation. ```console source /tools/Xilinx/Vivado/2024.1/settings64.sh source /home/user/petalinux/settings.sh ``` -------------------------------- ### Configure and Display FSM Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/logictools/notebooks/fsm_generator.ipynb This snippet sets up the FSM generator with the previously defined specification and displays a visual representation of the FSM's state diagram. The setup can optionally include a custom clock frequency. ```python fsm_generator.setup(fsm_spec) fsm_generator.show_state_diagram() ``` -------------------------------- ### Install PYNQ from Source Distribution Source: https://github.com/xilinx/pynq/blob/master/docs/source/overlay_design_methodology/python_packaging.rst This command installs the PYNQ Python library from a previously generated source distribution tarball. Environment variables BOARD and PYNQ_JUPYTER_NOTEBOOKS should be set before installation. A reboot is required after installation. ```console export BOARD= export PYNQ_JUPYTER_NOTEBOOKS= pip3 install pynq-.tar.gz ``` -------------------------------- ### Initialize and Start HDMI Input Frontend Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/video/hdmi_video_pipeline.ipynb Initializes the HDMI input frontend driver from the base overlay and starts it to detect the video mode. The 'start()' method blocks until a video lock is achieved. ```python hdmiin_frontend = base.video.hdmi_in.frontend hdmiin_frontend.start() hdmiin_frontend.mode ``` -------------------------------- ### Connect Pmod PWM to Pmod Interface Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/pmod/pmod_pwm.ipynb Connects the Pmod PWM driver to a specified Pmod interface (e.g., PMODA) and pin. This setup is crucial for directing the PWM signal to the desired hardware interface. ```python from pynq.lib import Pmod_PWM pwm = Pmod_PWM(base.PMODA,0) ``` -------------------------------- ### PYNQ Logictools Common Methods Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_libraries/logictools.rst These methods are common to all hardware blocks within the logictools overlay, allowing for basic control and configuration. They include setup, run, step, stop, reset, and trace operations. ```python overlay.logictools.setup() overlay.logictools.run() overlay.logictools.step() overlay.logictools.stop() overlay.logictools.reset() overlay.logictools.trace() ``` -------------------------------- ### Create Wifi Instance using Pynq Source: https://github.com/xilinx/pynq/blob/master/pynq/notebooks/common/wifi.ipynb Initializes a Wifi instance from the pynq.lib library. This requires either a USB WiFi module to be plugged in or an embedded WiFi module to be present on the board. ```python from pynq.lib import Wifi port = Wifi() ``` -------------------------------- ### Initialize and Start HDMI Input Frontend (Python) Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z2/base/notebooks/video/hdmi_video_pipeline.ipynb Accesses and initializes the HDMI input frontend driver from the base overlay. Starting the frontend attempts to detect the video mode and locks onto it, making the video mode information available. ```python hdmiin_frontend = base.video.hdmi_in.frontend hdmiin_frontend.start() hdmiin_frontend.mode ``` -------------------------------- ### Install PYNQ Host Dependencies Script Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_sd_card.rst Executes a shell script to install the necessary dependencies on a native Ubuntu OS for building PYNQ images. This script is part of the PYNQ repository and ensures the build environment is correctly configured if not using Docker. ```console /sdbuild/scripts/setup_host.sh ``` -------------------------------- ### Start HDMI Input/Output Streams Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_libraries/video.rst Starts the HDMI input and output data streams after they have been configured. This enables data transfer between the interfaces. ```Python hdmi_in.start() hdmi_out.start() ``` -------------------------------- ### Load Base Overlay in PYNQ Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/arduino/arduino_analog.ipynb This code snippet initializes the PYNQ environment by loading the base overlay, which is a prerequisite for interacting with PYNQ hardware. ```python # Make sure the base overlay is loaded from pynq.overlays.base import BaseOverlay base = BaseOverlay("base.bit") ``` -------------------------------- ### Test Grove OLED with Python Class Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/pmod/pmod_grove_oled.ipynb Example code to instantiate and use the `Python_Grove_OLED` class. It first resets the IOP, creates an OLED object connected to PMODB and PMOD_GROVE_G3, clears the screen, writes a message, and then deletes the object. ```python from pynq import PL from pynq.lib.pmod import PMOD_GROVE_G3 # Flush IOP PL.reset() oled = Python_Grove_OLED(base.PMODB,PMOD_GROVE_G3) oled.clear() oled.write('Hi from Python.') del oled ``` -------------------------------- ### MicroBlaze Mailbox Communication Example (Python/C) Source: https://github.com/xilinx/pynq/blob/master/docs/source/overlay_design_methodology/pynq_microblaze_subsystem.rst Illustrates the process of initiating a peripheral read from Python to a MicroBlaze application. This involves writing a command to a mailbox, which the MicroBlaze reads, processes, and responds to by placing data in the mailbox. The example outlines the steps for both Python and the MicroBlaze application. ```console 1. Python writes a read command (e.g. 0x3) to the mailbox command address (0xfffc). 2. MicroBlaze application checks the command address, and reads and decodes the command. 3. MicroBlaze performs a read from the peripheral and places the data at the mailbox base address (0xf000). 4. MicroBlaze writes 0x0 to the mailbox command address (0xfffc) to confirm transaction is complete. 5. Python checks the command address (0xfffc), and sees that the MicroBlaze has written 0x0, indicating the read is complete, and data is available. ``` ```c #define MAILBOX_BASE 0xf000 #define MAILBOX_CMD_ADDR (0xfffc) // In MicroBlaze application (e.g., circular_buffer.h) // ... read command from MAILBOX_CMD_ADDR ... // ... process command ... // ... write data to MAILBOX_BASE ... // ... write 0x0 to MAILBOX_CMD_ADDR to indicate completion ... ``` ```python # In Python application # Assuming 'mb_interface' is an object representing the MicroBlaze interface command_read = 0x3 mailbox_cmd_address = 0xfffc mailbox_base_address = 0xf000 # 1. Python writes a read command mb_interface.write_to_mailbox(command_read, mailbox_cmd_address) # 5. Python checks for completion and reads data status = mb_interface.read_from_mailbox(mailbox_cmd_address) if status == 0x0: data = mb_interface.read_from_mailbox(mailbox_base_address) # Process data ``` -------------------------------- ### RootFS Package Installation Scripts (Bash) Source: https://github.com/xilinx/pynq/blob/master/sdbuild/packages/README.md These bash scripts facilitate the installation of additional packages into the PYNQ root filesystem. `pre.sh` copies files, `qemu.sh` runs within the chroot using QEMU, and `post.sh` handles cleanup. They expect the chroot directory as the first argument. ```bash # pre.sh: Copies required files into the chroot. # Usage: ./pre.sh CHROOT_DIR=$1 # Example: Copy a file into the chroot cp my_file.txt "$CHROOT_DIR/path/in/chroot/" ``` ```bash # qemu.sh: Runs within the chroot under QEMU. # Usage: (executed by build system) # Example: Install a package inside the chroot apt-get update && apt-get install -y some-package ``` ```bash # post.sh: Performs cleanup after installation. # Usage: ./post.sh CHROOT_DIR=$1 # Example: Remove temporary files rm -rf "$CHROOT_DIR/tmp/" ``` -------------------------------- ### Instantiate and Download PYNQ Overlay (Python) Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_libraries/overlay.rst Instantiates the Overlay class with a .bit file, which implicitly downloads the bitstream to the PL. The .bit file path can be relative, absolute, or located within installed packages. ```Python from pynq import Overlay base = Overlay("base.bit") # bitstream implicitly downloaded to PL ``` -------------------------------- ### Activate Conda Environment Source: https://github.com/xilinx/pynq/blob/master/docs/source/getting_started/alveo_getting_started.rst Activates the 'pynq-env' Conda environment, making its packages and Python interpreter available in the current shell session. ```bash conda activate pynq-env ``` -------------------------------- ### Boolean Generator: Setup, Run, and Stop Hardware Logic Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_libraries/logictools.rst Configures and controls the Boolean Generator. The `setup()` method applies the defined function specifications. `run()` activates the hardware logic. `stop()` disconnects the I/O pins, and `reset()` clears all pin reservations, allowing for a new configuration. ```Python boolean_generator.setup(function_specs) ``` ```Python boolean_generator.run() ``` ```Python boolean_generator.stop() ``` ```Python boolean_generator.reset() ``` -------------------------------- ### Connect to Wifi Network Source: https://github.com/xilinx/pynq/blob/master/pynq/notebooks/common/wifi.ipynb Connects to a specified WiFi network by prompting the user for the SSID and password. The connection process may take some time to establish. ```python ssid = input("Type in the SSID:") pwd = input("Type in the password:") port.connect(ssid, pwd) ``` -------------------------------- ### Get Analog Log Data in PYNQ Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/arduino/arduino_analog.ipynb This snippet retrieves the logged analog data after logging has been started. The data is returned as a nested list, where each inner list contains samples for a single channel. ```python log1 = analog1.get_log() ``` -------------------------------- ### Setup.py for PYNQ Package Distribution Source: https://github.com/xilinx/pynq/blob/master/docs/source/overlay_design_methodology/python_packaging.rst This Python script demonstrates how to configure a setup.py file for distributing a PYNQ package. It includes PYNQ-specific entry points for notebooks and overlays, registers PYNQ's build_py command for managing overlay files, and declares dependencies on the 'pynq' package. ```python from setuptools import setup, find_packages from pynq.utils import build_py import new_overlay setup( name = "new_overlay", version = new_overlay.__version__, url = 'https://github.com/your_github/new_overlay', license = 'All rights reserved.', author = "Your Name", author_email = "your@email.com", packages = find_packages(), inlcude_package_data=True, install_requires=[ 'pynq' ], setup_requires=[ 'pynq' ], entry_points={ 'pynq.notebooks': [ 'new-overlay = new_overlay.notebooks' ] }, cmdclass={'build_py': build_py}, description = "New custom overlay" ) ``` -------------------------------- ### Discovering Overlay Contents Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_overlays/loading_an_overlay.ipynb Explains how to use the `help()` function on an instantiated overlay object to understand its structure and available IPs. ```APIDOC ## GET /overlay/help ### Description Retrieves help information for a loaded overlay, detailing its structure, available IPs, and attributes. ### Method GET ### Endpoint `/overlay/help` ### Parameters #### Query Parameters - **overlay_name** (string) - Required - The name of the loaded overlay for which to get help information. ### Request Example `GET /overlay/help?overlay_name=base_overlay` ### Response #### Success Response (200) - **help_text** (string) - Detailed help information about the specified overlay. #### Response Example ```json { "help_text": "Help on BaseOverlay in module pynq.overlays.base.base object:\n\nclass BaseOverlay(pynq.overlay.Overlay)\n | The Base overlay for the Pynq-Z1\n | ... (full help text) ..." } ``` ``` -------------------------------- ### Start and Stop Temperature Logging Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z2/base/notebooks/pmod/pmod_tmp2.ipynb Demonstrates how to start and stop the PmodTMP2 sensor's logging functionality. The sensor logs temperature readings at a default interval of 1 second. ```python mytmp.start_log() ``` ```python mytmp.stop_log() log = mytmp.get_log() ``` -------------------------------- ### Get Help and Information on a Register - Python Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/board/register_map_intro.ipynb This snippet shows how to use the 'help()' function to get detailed information about a specific register, including its description and subfields. This is useful for understanding the purpose and structure of registers. ```python help(btns.register_map.IP_IER) ``` -------------------------------- ### Setup Pattern Generator and Trace Analyzer Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/logictools/notebooks/single_stepping_generators.ipynb Instantiates the pattern generator and configures it with the defined waveform. Optionally enables the trace analyzer to capture samples for verification. ```python pattern_generator = logictools_olay.pattern_generator pattern_generator.trace(num_analyzer_samples=16) pattern_generator.setup(up_counter, stimulus_group_name='stimulus', analysis_group_name='analysis') ``` -------------------------------- ### Generate PYNQ Boot Files Source: https://github.com/xilinx/pynq/blob/master/sdbuild/README.md Generates only the boot files for a PYNQ SD card image using 'make boot_files'. Requires specifying the board directory. ```makefile make boot_files BOARDDIR=/myboards ``` -------------------------------- ### Start and Stop PmodTMP2 Temperature Logging Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/pmod/pmod_tmp2.ipynb Starts and stops the temperature logging functionality of the PmodTMP2 sensor. Once logging is stopped, the collected log data can be retrieved. The default logging interval is 1 second. ```python mytmp.start_log() # ... wait for at least 10 seconds ... mytmp.stop_log() log = mytmp.get_log() ``` -------------------------------- ### Generate PWM Signal (25% Duty Cycle, 20us Period) Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/pmod/pmod_pwm.ipynb Generates a PWM signal with a 25% duty cycle and a 20 microsecond period for 5 seconds. This example demonstrates configuring the Pmod PWM driver with different timing parameters. ```python import time # Generate a 20 us clocks with 25% duty cycle period=20 duty=25 pwm.generate(period,duty) # Sleep for 5 seconds and stop the timer time.sleep(5) pwm.stop() ``` -------------------------------- ### Generate PYNQ BSP Source: https://github.com/xilinx/pynq/blob/master/sdbuild/README.md Generates the Petalinux BSP for future use with 'make bsp'. Requires specifying the board directory. ```makefile make bsp BOARDDIR=/myboards ``` -------------------------------- ### PYNQ CLI: Get Notebooks Ignoring Overlays Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_cli.rst Explains how to download notebooks even if associated overlays are not found for the target device, using the '--ignore-overlays' option. ```bash pynq get-notebooks --ignore-overlays ``` -------------------------------- ### Loading a Basic Overlay Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_overlays/loading_an_overlay.ipynb Demonstrates how to load a standard overlay using the Overlay class. ```APIDOC ## POST /overlay ### Description Loads a specified overlay (bitstream) into the Programmable Logic (PL) of the FPGA. ### Method POST ### Endpoint `/overlay` ### Parameters #### Request Body - **bitstream_name** (string) - Required - The name of the bitstream file (e.g., "base.bit") to load. - **download** (boolean) - Optional - Whether to download the bitstream. Defaults to true. - **dtbo** (string) - Optional - The device tree overlay file to use. - **ignore_version** (boolean) - Optional - Whether to ignore version mismatches. ### Request Example ```json { "bitstream_name": "base.bit", "download": true } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message that the overlay was loaded successfully. #### Response Example ```json { "message": "Overlay 'base.bit' loaded successfully." } ``` ``` -------------------------------- ### Instantiate and Inspect PYNQ Overlay Source: https://github.com/xilinx/pynq/blob/master/docs/source/overlay_design_methodology/overlay_tutorial.ipynb This snippet demonstrates how to load a PYNQ overlay and inspect its properties to verify that drivers for included IP cores are automatically bound. It assumes the overlay file and its corresponding Python driver files are accessible. ```python overlay = Overlay('/home/xilinx/tutorial_2.bit') overlay? ``` -------------------------------- ### PYNQ CLI: Print Version Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_cli.rst Illustrates how to retrieve the installed PYNQ version and its associated commit hash from the repository. This information is useful for debugging and bug reporting. ```bash pynq --version ``` -------------------------------- ### Add PYNQ to PetaLinux Image Install Source: https://github.com/xilinx/pynq/blob/master/sdbuild/boot/meta-pynq/README.md This snippet shows how to append the 'python3-pynq' package to the PetaLinux image installation. This ensures that the PYNQ Python library is included in the root filesystem when building the image. It's a crucial step for enabling PYNQ functionality within the PetaLinux environment. ```bash IMAGE_INSTALL_append = " python3-pynq" ``` -------------------------------- ### Test Grove OLED with Microblaze Driver Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/pmod/pmod_grove_oled.ipynb Example code demonstrating the use of the pre-existing `Grove_OLED` Microblaze driver. It resets the IOP, initializes the OLED on PMODB and PMOD_GROVE_G3, clears the screen, writes a message, and then deletes the object. This method is noted to be faster than the Python implementation. ```python from pynq.lib.pmod import Grove_OLED from pynq.lib.pmod import PMOD_GROVE_G3 # Flush IOP PL.reset() oled = Grove_OLED(base.PMODB,PMOD_GROVE_G3) oled.clear() oled.write('Hello from Microblaze.') del oled ``` -------------------------------- ### PYNQ CLI: Get Notebooks with Specific Path Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_cli.rst Explains how to specify a custom directory for downloading PYNQ notebooks using the '--path' option. ```bash pynq get-notebooks --path ``` -------------------------------- ### PYNQ CLI: Print Help Message Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_cli.rst Shows how to display the help message for the PYNQ CLI, which includes available options and a list of registered subcommands. ```bash pynq --help ``` -------------------------------- ### Build PetaLinux Boot Files Source: https://github.com/xilinx/pynq/blob/master/sdbuild/boot/meta-pynq/README.md This command is used to package the PetaLinux build artifacts, including the U-Boot bootloader and FPGA bitstream, into the necessary BOOT.BIN file. This file is essential for booting the embedded system with the configured PetaLinux image and PYNQ environment. ```bash petalinux-pacakge --boot --u-boot --fpga ``` -------------------------------- ### Retrieve and Plot Grove ADC Log Data with Pmod Adapter Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z2/base/notebooks/pmod/pmod_grove_adc.ipynb Retrieves logged voltage data from the Grove ADC and plots it over time using matplotlib. Assumes logging has been started. ```python log = grove_adc.get_log() ``` ```python %matplotlib inline import matplotlib.pyplot as plt plt.plot(range(len(log)), log, 'ro') plt.title('Grove ADC Voltage Log') plt.axis([0, len(log), min(log), max(log)]) plt.show() ``` -------------------------------- ### Initialize HDMI Input/Output Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_libraries/video.rst Sets up instances for HDMI input and output using the PYNQ Overlay. This is a prerequisite for any video operations. ```Python from pynq import Overlay from pynq.lib.video import * base = Overlay('base.bit') hdmi_in = base.video.hdmi_in hdmi_out = base.video.hdmi_out ``` -------------------------------- ### Console: Access Logictools Notebooks Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_libraries/logictools.rst Demonstrates the file path to access Logictools Notebooks on a PYNQ-Z1 board. These notebooks provide further examples and practical usage of the Logictools functionalities. ```console /logictools/ ``` -------------------------------- ### PYNQ CLI: Get Notebooks with Specific Device Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_cli.rst Demonstrates how to manually specify the target device for overlay lookup when downloading notebooks using the '--device' option. ```bash pynq get-notebooks --device DEVICE ``` -------------------------------- ### Initialize Grove ADC with Pmod Adapter Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z2/base/notebooks/pmod/pmod_grove_adc.ipynb Initializes the Grove ADC using the Pmod to Grove adapter. Requires the 'base' overlay and specifies the PMOD port and group. Outputs voltage readings. ```python from pynq.overlays.base import BaseOverlay base = BaseOverlay("base.bit") ``` ```python from pynq.lib.pmod import Grove_ADC from pynq.lib.pmod import PMOD_GROVE_G4 grove_adc = Grove_ADC(base.PMODA,PMOD_GROVE_G4) print("{} V".format(round(grove_adc.read(),4))) ``` -------------------------------- ### Allocate NumPy Buffer with PYNQ Source: https://github.com/xilinx/pynq/blob/master/docs/source/getting_started/python_environment.ipynb This Python code demonstrates how to allocate a memory buffer using PYNQ's `allocate` function, which is compatible with NumPy arrays. This buffer can be shared between the ARM processor and programmable logic. It requires an overlay to be loaded to allocate memory. The example shows how to get the buffer, check its type, and retrieve its physical address for use in programmable logic. ```python import numpy as np import pynq def get_pynq_buffer(shape, dtype): """ Simple function to call PYNQ's memory allocator with numpy attributes""" try: return pynq.allocate(shape, dtype) except RuntimeError: print('Load an overlay to allocate memory') return ``` ```python buffer = get_pynq_buffer(shape=(4,4), dtype=np.uint32) buffer ``` ```python isinstance(buffer, np.ndarray) ``` ```python try: pl_buffer_address = hex(buffer.physical_address) pl_buffer_address except AttributeError: print('Load an overlay to allocate memory') ``` -------------------------------- ### PYNQ CLI: Get All Notebooks Without Confirmation Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_cli.rst Demonstrates how to automatically download all available notebooks without user confirmation by passing the 'all' keyword. ```bash pynq get-notebooks all ``` -------------------------------- ### Defining a Custom Overlay Class in Python Source: https://github.com/xilinx/pynq/blob/master/docs/source/overlay_design_methodology/overlay_tutorial.ipynb Provides an example of creating a custom overlay class `TestOverlay` that inherits from `pynq.Overlay`. It includes an `__init__` method to call the parent constructor and a custom `multiply` method. ```python class TestOverlay(Overlay): def __init__(self, bitfile, **kwargs): super().__init__(bitfile, **kwargs) def multiply(self, stream, constant): return self.const_multiply.stream_multiply(stream, constant) ``` -------------------------------- ### Loading and Inspecting PYNQ Overlay (Python) Source: https://github.com/xilinx/pynq/blob/master/docs/source/overlay_design_methodology/overlay_tutorial.ipynb This Python code demonstrates how to load a PYNQ overlay from a .bit file and inspect its contents. The Overlay class is instantiated with the path to the bitstream file, automatically downloading it. The '?' operator is then used to query the overlay for information about the IP cores it contains. ```python from pynq import Overlay overlay = Overlay('/home/xilinx/tutorial_1.bit') overlay? ``` -------------------------------- ### Import Base Overlay and Get GPIO Drivers - Python Source: https://github.com/xilinx/pynq/blob/master/boards/ZCU104/base/notebooks/board/register_map_intro.ipynb Imports the `BaseOverlay` from PYNQ and instantiates it with a bitstream. It then retrieves the drivers for the GPIO buttons and LEDs. This is a prerequisite for interacting with the register map of these peripherals. ```python from pynq.overlays.base import BaseOverlay base = BaseOverlay('base.bit') btns = base.gpio_btns leds = base.gpio_leds ``` -------------------------------- ### Modify Notebook for PYNQ.remote Environment Variable Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_remote/quickstart.rst Updates a Python notebook cell to include the PYNQ_REMOTE_DEVICES environment variable. This is necessary for PYNQ.remote to identify and connect to the target device, requiring the board's IP address. ```python import os os.environ['PYNQ_REMOTE_DEVICES'] = "192.168.2.99" # Replace with your board's IP from pynq import allocate, Overlay ``` -------------------------------- ### Python asyncio Event Loop Setup Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_libraries/interrupt.rst This snippet demonstrates how to get the current asyncio event loop, which is essential for scheduling and running coroutines in PYNQ. Dependencies: asyncio library. Input: None. Output: asyncio event loop object. ```Python import asyncio loop = asyncio.get_event_loop() ``` -------------------------------- ### Instantiate and Use AxiGPIO Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_libraries/axigpio.rst Demonstrates how to load an overlay and instantiate the AxiGPIO class for controlling LEDs and switches. It shows basic read and write operations on GPIO channels. ```Python from pynq import Overlay from pynq.lib import AxiGPIO ol = Overlay("base.bit") led_ip = ol.ip_dict['leds_gpio'] switches_ip = ol.ip_dict['switches_gpio'] leds = AxiGPIO(led_ip).channel1 switches = AxiGPIO(switches_ip).channel1 mask = 0xffffffff leds.write(0xf, mask) switches.read() ``` -------------------------------- ### Initialize PmodTMP2 Sensor Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/pmod/pmod_tmp2.ipynb Initializes the PmodTMP2 sensor attached to a specific port on the PYNQ board. This requires the base overlay to be loaded first. The sensor is then ready to read temperature values. ```python from pynq.overlays.base import BaseOverlay base = BaseOverlay("base.bit") from pynq.lib import Pmod_TMP2 mytmp = Pmod_TMP2(base.PMODB) temperature = mytmp.read() print(str(temperature) + " C") ``` -------------------------------- ### Get Log Data from Multiple Devices in PYNQ Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/arduino/arduino_analog.ipynb This snippet retrieves logged data from multiple concurrently monitored Arduino analog devices. The returned log is a nested list, with each inner list corresponding to the samples from one device/channel. ```python log2 = analog2.get_log() ``` -------------------------------- ### Modify Notebook for RemoteBuffer Image Display Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_remote/quickstart.rst Adjusts a Python notebook cell to correctly display images from PYNQ.remote's RemoteBuffer. Appending '[:]' to the output buffer ensures compatibility with the PIL Image library, addressing differences from PynqBuffer. ```python run_kernel() resized_image = Image.fromarray(out_buffer[:]) ``` -------------------------------- ### Load, Set Volume, and Play Audio on PYNQ-Z2 Source: https://github.com/xilinx/pynq/blob/master/docs/source/pynq_libraries/audio.rst This snippet shows how to load a WAV audio file, set the playback volume, and play the audio using the audio instance on a PYNQ-Z2 board. The base overlay must be loaded prior to execution. ```Python from pynq.overlays.base import BaseOverlay base = BaseOverlay("base.bit") pAudio = base.audio pAudio.set_volume(20) pAudio.load("/home/xilinx/jupyter_notebooks/base/audio/data/recording_0.wav") pAudio.play() ``` -------------------------------- ### Initialize Waveform and Display Pattern (Python) Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/logictools/notebooks/wavedrom_tutorial.ipynb This snippet initializes the LogicToolsOverlay, defines a waveform pattern in WaveJSON format, creates a Waveform object, and displays it. It requires the `pynq.lib.logictools.Waveform` and `pynq.overlays.logictools.LogicToolsOverlay` classes. The input is a dictionary defining signal stimuli and analysis, and the output is an HTML object representing the waveform. ```python from pynq.lib.logictools import Waveform from pynq.overlays.logictools import LogicToolsOverlay logictools_olay = LogicToolsOverlay('logictools.bit') loopback_test = {'signal': [ ['stimulus', {'name': 'output0', 'pin': 'D0', 'wave': 'lh' * 8}, {'name': 'output1', 'pin': 'D1', 'wave': 'l.h.' * 4}, {'name': 'output2', 'pin': 'D2', 'wave': 'l...h...' * 2}], {}, ['analysis', {'name': 'input0', 'pin': 'D0'}, {'name': 'input1', 'pin': 'D1'}, {'name': 'input2', 'pin': 'D2'}]], 'foot': {'tock': 1}, 'head': {'text': 'loopback_test'}} waveform = Waveform(loopback_test) waveform.display() ``` -------------------------------- ### Instantiating and Using a Custom Overlay Source: https://github.com/xilinx/pynq/blob/master/docs/source/overlay_design_methodology/overlay_tutorial.ipynb Demonstrates how to instantiate the custom `TestOverlay` class with a specific bitstream file and then use its custom `multiply` method with input data and a constant. ```python overlay = TestOverlay('/home/xilinx/tutorial_2.bit') overlay.multiply([2,3,4,5,6], 4) ``` -------------------------------- ### Run Pattern Generator and Trace Signals (Python) Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/logictools/notebooks/wavedrom_tutorial.ipynb This code snippet configures and runs the pattern generator to trace signals. It first accesses the pattern generator from the loaded overlay, then traces analyzer samples, sets up the pattern using the WaveJSON dictionary, runs the pattern, and finally displays the waveform. This relies on the `pattern_generator` attribute of the `LogicToolsOverlay` object. The primary input is the `loopback_test` dictionary and configuration parameters for tracing and setup. The output is an HTML object. ```python pattern_generator = logictools_olay.pattern_generator pattern_generator.trace(num_analyzer_samples=16) pattern_generator.setup(loopback_test, stimulus_group_name='stimulus', analysis_group_name='analysis') pattern_generator.run() pattern_generator.show_waveform() ``` -------------------------------- ### Import Pmod Libraries and Base Overlay Source: https://github.com/xilinx/pynq/blob/master/boards/Pynq-Z1/base/notebooks/pmod/pmod_dac_adc.ipynb Imports necessary libraries for Pmod DAC and ADC, along with the BaseOverlay for ZYNQ PL programming. These are essential for interacting with the hardware peripherals. ```python from pynq.overlays.base import BaseOverlay from pynq.lib import Pmod_ADC, Pmod_DAC ```