> For the complete documentation index, see [llms.txt](https://weenslab.gitbook.io/pages/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://weenslab.gitbook.io/pages/fpga-tutorials/fpga-boards-getting-started/getting-started-with-pynq-on-red-pitaya-stemlab-125-14.md).

# Getting Started with PYNQ on Red Pitaya STEMlab 125-14

## Red Pitaya STEMlab 125-14

Red Pitaya is a project that aims to provide an alternative to numerous expensive laboratory measuring and control instruments. It is classified as open-source, but the hardware design is proprietary. This board uses the **Xilinx Zynq 7000 (XC7Z010-1CLG400C)**.

<figure><img src="https://4146991827-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIsb2SAYKLkGlVOGOY0EE%2Fuploads%2FjcoAE53POpTSHJYm042E%2Fred_pitaya_stemlab_125_14.jpg?alt=media&amp;token=db58e645-236c-430f-a356-2778478e5ad7" alt="" width="375"><figcaption><p>Red Pitaya STEMlab 125-14. Source: <a href="https://en.wikipedia.org/wiki/Red_Pitaya_%28computer%29">https://en.wikipedia.org/wiki/Red_Pitaya_%28computer%29</a></p></figcaption></figure>

This board has its own Linux image that comes with web-based measurement applications, but in this case I don't do measurement, so I want to try to use the PYNQ image.

## MicroSD Setup

Red Pitaya STEMlab 125-14 is not officially supported by PYNQ. Thankfully, someone has already built the PYNQ image for this board. So, I just use the PYNQ image from this [repository](https://github.com/dspsandbox/Pynq-Redpitaya-125).

#### Required programs:

* Win32DiskImager (<https://win32diskimager.org/>)
* PuTTY (<https://www.putty.org/>)

#### How to write the image to a microSD card:

1. Download the image file **Pynq-Redpitaya-125-14-3.0.1.img** from the repository.
2. Write the image file to the microSD card with the **Win32DiskImager** program.

#### How to boot the board:

1. Insert the microSD card into the board, connect the micro USB cable to the PC, and connect the power supply.
2. Open the **PuTTY** program and set up a serial connection. Select the appropriate COM port by looking at Device Manager (Windows).
   * Baud rate = **115200**
   * Data bits = **8**
   * Stop bits = **1**
   * Flow control = **None**
   * Parity = **None**
3. The system is automatically logged in, but if you want to connect to the board from an SSH terminal, then we have to enter the username and password.
   * Username: **xilinx**
   * Password: **xilinx**

<figure><img src="https://4146991827-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIsb2SAYKLkGlVOGOY0EE%2Fuploads%2FKbvwZOpsJo5oOlv55gkV%2Fred_pitaya_pynq_first_boot.png?alt=media&amp;token=5f2907c3-397b-437b-b0d9-796af208c7a4" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Important**

If you want to turn off the board, you should shutdown it; don't immediately remove the power supply. This is done to avoid corrupted microSD, which can cause boot failure.
{% endhint %}

#### How to turn off the board:

Run this command.

```sh
sudo shutdown -h now
```

## USB Wi-Fi Dongle Setup

I use an **Edimax EW-7811Un** USB Wi-Fi dongle that uses the **Realtek RTL8188CUS** chipset. The driver for this Wi-Fi dongle is already installed.

We can use this command to display information about USB buses and the devices connected to them. We will see the USB Wi-Fi dongle detected.

```sh
lsusb
```

<figure><img src="https://4146991827-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIsb2SAYKLkGlVOGOY0EE%2Fuploads%2FZcAqrIBVHmFD4mm9U0tU%2Flsusb_wifi_dongle.png?alt=media&amp;token=05bee05f-9713-4842-a4b5-840dc720f94e" alt=""><figcaption></figcaption></figure>

Next, we can use this command to connect to a Wi-Fi access point.&#x20;

```sh
sudo wpa_passphrase "YourSSID" "YourPassword" > wpa_supplicant.conf
sudo wpa_supplicant -c wpa_supplicant.conf -i wlan0 -B -Dnl80211
```

Then, use this command to configure a static IP address.

```sh
sudo nano /etc/network/interfaces.d/wlan0
```

```
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.99
netmask 255.255.255.0
gateway 192.168.1.1
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
```

Finally, we can reboot the board to see the changes.

```sh
sudo reboot
```

<figure><img src="https://4146991827-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIsb2SAYKLkGlVOGOY0EE%2Fuploads%2FvpElsNMVlEVdjpN5rYo7%2Fifconfig_wifi_dongle.png?alt=media&amp;token=3de93fef-3bb9-4cb0-b4ce-2f9580cc2b2c" alt=""><figcaption></figcaption></figure>

Now, we can login to the Jupyter Notebook via web browser by entering the IP address of the board:

* URL: **192.168.1.99:9090**
* Password: **xilinx**

## Wi-Fi Connection with PEAP

We can also connect to a Wi-Fi access point that uses PEAP, which is commonly used in enterprise wireless and wired networks. This is the configuration for the `wpa_supplicant.conf`.

```sh
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
```

```
network={
        ssid="YourSSID"
        scan_ssid=1
        key_mgmt=WPA-EAP
        identity="YourUsername"
        password="YourPassword"
        eap=PEAP
        phase1="peaplabel=0"
        phase2="auth=MSCHAPV2"
}
```

This configuration is used to configure the board with a dynamic IP address.

```sh
sudo nano /etc/network/interfaces.d/wlan0
```

```
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
```

## DNS Configuration

For some reason, when I try to install a Python package using `pip`, an error occurs, and I find that the error is related to the DNS configuration. So, I set the DNS permanently in the `resolv.conf` file.

```
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0xb5004190>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/yfinance/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0xb5004298>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/yfinance/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0xb50043a0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/yfinance/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0xb50044f0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/yfinance/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0xb50045c8>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/yfinance/
ERROR: Could not find a version that satisfies the requirement yfinance (from versions: none)
ERROR: No matching distribution found for yfinance
```

First, we install the `resolvconf` package.

```sh
sudo apt install resolvconf
```

Then, we activate and run the `resolvconf` service.

```sh
sudo systemctl enable resolvconf
sudo systemctl start resolvconf
sudo systemctl status resolvconf 
```

Next, we enter the nameserver IP address in the **head** `resolvconf` configuration file.

```sh
sudo nano /etc/resolvconf/resolv.conf.d/head 
```

```
nameserver 8.8.8.8
nameserver 8.8.4.4
```

After that, we run the `resolv.conf` update.

```sh
sudo resolvconf --enable-updates
sudo resolvconf -u
```

If an error like this occurs, then run the following command.

```
/etc/resolvconf/update.d/libc: Warning: /etc/resolv.conf is not a symbolic link to /run/resolvconf/resolv.conf
```

```sh
sudo dpkg-reconfigure resolvconf
```

Finally, we can verify by displaying the contents of the `resolv.conf` file.

```sh
cat /etc/resolv.conf
```

<figure><img src="https://4146991827-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIsb2SAYKLkGlVOGOY0EE%2Fuploads%2FWPma0nssfHSGlCljOFrA%2Fred_pitaya_dns_resolv_conf.png?alt=media&amp;token=443affd3-b529-4b40-aa0d-8aa0e5fb7aa1" alt=""><figcaption></figcaption></figure>

## Hardware Design

Now that we have configured the board, the next step is to try to create a basic hardware design. My hardware design consists of an AXI GPIO and an AXI DMA. The AXI GPIO is connected to 8 LEDs. The AXI DMA is connected to a looped-back AXIS FIFO.

<figure><img src="https://4146991827-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIsb2SAYKLkGlVOGOY0EE%2Fuploads%2FDieWsqjbswcfUcT1tab0%2Fblock-design-red-pitaya-pynq.png?alt=media&amp;token=240ac419-5d48-4be3-95cd-716f6dbb9ed9" alt=""><figcaption></figcaption></figure>

The following figure shows the Zynq IP high-performance port configuration. The **S AXI HP0** and **S AXI HP2** interfaces are enabled.

<figure><img src="https://4146991827-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIsb2SAYKLkGlVOGOY0EE%2Fuploads%2FqmBnVUeixzc1wz7gERB8%2Fzynq-ip-config-red-pitaya-pynq.png?alt=media&amp;token=d7a97a6d-a421-4f97-a092-37293a8ab7be" alt=""><figcaption></figcaption></figure>

The following figure shows the AXI DMA IP configuration.

<figure><img src="https://4146991827-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIsb2SAYKLkGlVOGOY0EE%2Fuploads%2F8lpYTy5cmJDCqQBq1izH%2Faxi-dma-ip-config-red-pitaya-pynq.png?alt=media&amp;token=645b5424-0c63-424a-9a8e-7c78f56e0447" alt=""><figcaption></figcaption></figure>

The following figure shows the AXI GPIO IP configuration.

<figure><img src="https://4146991827-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIsb2SAYKLkGlVOGOY0EE%2Fuploads%2FrI72wSi5GChHHxHxxT84%2Faxi-gpio-ip-config-red-pitaya-pynq.png?alt=media&amp;token=141b2ece-378c-4ea2-b2ea-9f029a15c8fc" alt=""><figcaption></figcaption></figure>

## Upload Design Files

To upload files, such as bitstreams, from the laptop to the board, you can use FileZilla via the Ethernet connection.

Required programs:

* FileZilla (<https://filezilla-project.org/>)

The connections required are:

* Host: **192.168.1.99**
* Username: **xilinx**
* Password: **xilinx**
* Port: **22**

To upload the hardware design to PYNQ, you need to upload three files: `.bit`, `.tcl`, and `.hwh`.

## Python Program

The following notebook is used to test the hardware design. It consists of a Python program to test the AXI GPIO and the AXI DMA.

{% embed url="<https://gist.github.com/weenslab/95253ea2ef1372ba10fef739fa8df80b>" %}

The results show that the AXI GPIO and AXI DMA can be accessed successfully.

## References

* Red Pitaya STEMlab 125-14, <https://redpitaya.com/stemlab-125-14/>
* PYNQ for Redpitaya-125-14, <https://github.com/dspsandbox/Pynq-Redpitaya-125>
* Connect to your WiFi using Linux command line, <https://www.youtube.com/watch?v=c-9kRhvs3Mw>
* How to Set Permanent resolv.conf on Ubuntu, <https://musaamin.web.id/set-permanent-resolv-conf-ubuntu/>
* Tutorial: PYNQ DMA (Part 1: Hardware design), <https://discuss.pynq.io/t/tutorial-pynq-dma-part-1-hardware-design/3133>
* Tutorial: PYNQ DMA (Part 2: Using the DMA from PYNQ), <https://discuss.pynq.io/t/tutorial-pynq-dma-part-2-using-the-dma-from-pynq/3134>
