In this project, I experimented with controlling GPIO on the KR260 FPGA board.
Using Python (PYNQ), we managed to perform LED output and switch input via the PMOD connector with custom-designed board.
We'll share how I designed an original board and tested its functionality.
This project is part of a subproject for the AMD Pervasive AI Developer Contest.
Be sure to check out the other projects as well.
***The main project is currently under submission. ***
0. Main project << under submission
1. PYNQ + GPIO(LED Blinking) << this project
2. PYNQ + PWM(DC-Motor Control)
3. Object Detection(Yolo) with DPU-PYNQ
4. Implementation DPU, GPIO, and PWM
6. GStreamer + OpenCV with 360°Camera
7. 360 Live Streaming + Object Detect(DPU)
8. ROS2 3D Marker from 360 Live Streaming
9. Control 360° Object Detection Robot Car
10. Improve Object Detection Speed with YOLOX
11. Benchmark Architectures of the DPU
12. Power Consumption of 360° Object Detection Robot Car
13. Application to Vitis AI ONNX Runtime Engine (VOE)
14. Appendix: Object Detection Using YOLOX with a Webcam
Please note that before running the above subprojects, the following setup, which is the reference for this AMDcontest, is required.
https://github.com/amd/Kria-RoboticsAI
IntroductionThe KR260, an FPGA board from AMD (Xilinx), is equipped with a PMOD connector that can also be utilized for GPIO purposes.
I created a custom board to experiment with LED output and switch input functionalities.
Below is a test video that demonstrates control via an ipynb file, clearly showing the board's operation.
Circuit Diagram and Artwork (AW)The data for the circuit diagram and AW connected to PMOD are available on GitHub. They were developed using KiCad.
GitHub Repository for PCB KR260 PMOD Test
For direct connection to the PMOD connector, I utilized pin headers with a 2.54mm pitch.
Below are the circuit diagram and AW respectively.
The.tcl file for the Vivado project is located in the following directory.
If you want to create it automatically using the Tcl file, use the following command:
vivado -mode batch -source kr260-gpio-test.tcl
Create Project
We will guide you through the creation steps in Vivado.
We selected "Create Project" and proceeded with an appropriate name for the project.
In Project Type, We retained the default RTL setting.
In Default Part, We chose the board and selected KR260.
Create Block Design
Once the project file was ready, we proceeded with "Create Block Design" to advance the block design.
From the Diagram's "+" section, we selected Zynq UltraScale+ MPSoC.
Then, we added a GPIO IP from the same "+" section in the Diagram.
After clicking "Run connection Automation" and accepting the default settings, various IPs like reset and AXI were automatically placed. Clicking "Regenerate Layout" neatly arranged them.
We added another GPIO IP, separating them for output and input purposes and matching their names with IP numbers.
We then edited the GPIO IPs. By default, they are set as a 32-bit bus, but we adjusted the GPIO Width since we used three outputs and one input for each IP, also checking All outputs and All inputs.
Create HDL Wrapper
Right-clicking the design under Source, we executed "Create HDL Wrapper, " which generates HDL from the IP block design, allowing you to verify output and input from each GPIO.
Creating an XDC File
Next, we assigned pins by right-clicking under Constrains and selecting Add Sources.
We created an XDC file and set pins for PMOD4: pin 1 (AC12), pin 3 (AD12), pin 5 (AE10), and pin 7 (AF10) for input and output respectively.
set_property PACKAGE_PIN AC12 [get_ports gpio_rtl_0_tri_o[0]]
set_property PACKAGE_PIN AD12 [get_ports gpio_rtl_0_tri_o[1]]
set_property PACKAGE_PIN AE10 [get_ports gpio_rtl_0_tri_o[2]]
set_property PACKAGE_PIN AF10 [get_ports gpio_rtl_1_tri_i[0]]
set_property IOSTANDARD LVCMOS33 [get_ports gpio_rtl_0_tri_o[0]]
set_property IOSTANDARD LVCMOS33 [get_ports gpio_rtl_0_tri_o[1]]
set_property IOSTANDARD LVCMOS33 [get_ports gpio_rtl_0_tri_o[2]]
set_property IOSTANDARD LVCMOS33 [get_ports gpio_rtl_1_tri_i[0]]
Generating Bitstream
After ensuring there were no errors, I generated the bitstream file.
- The.bit file can be found in the project's ~.runs/impl_1 directory.
- A.hwh file, containing hardware information, is also necessary. It's located in the project folder after generating the bitstream, ~.gen/sources_1/bd/design_1/hw_handoff.
The.hwf file name should match the Bitstream.bit name.
(For example, "design_1_wrapper.bit" and "design_1_wrapper.hwh".)
We renamed them accordingly to transfer the.bit and.hwh files to the KR260.
Below is an example of copying to KR260 at 192.168.11.7:
scp -r pynq-gpio/ ubuntu@192.168.11.7:/home/ubuntu/
Run Jupyter_notebooksWithin the /root/jupyter_notebooks/ directory in KR260, a folder is created to house the executed .ipynb file alongside the .bit and .hwl files produced by Vivado.
Below is an example of copying to the jupyter_notebooks directory on the KR260.
sudo su
cd $PYNQ_JUPYTER_NOTEBOOKS
cd jupyter_notebooks/
ls
cp -rf /home/ubuntu/pynq-gpio/ ./
After KR260 installation, the IP address is confirmed using ifconfig; in my case, it was 192.168.11.7.
Accessing Jupyter Notebook is done by navigating to http://192.168.11.7:9090/ in a web browser (Chrome was used here).
The test .bit.hwh.ipynb files are available on GitHub.
The notebook includes steps to control the AXI-GPIO IP, loaded from the Vivado-generated .bit file, utilizing PYNQ's AXI-GPIO library. Official documentation for AXI-GPIO manipulation can be found here.
Please check test video to see it in action
In the notebook, the AxiGPIO is imported, and the GPIO IP and channel1 are specified.
LED outputs are managed through a series of Write commands, cycling through 0x3, 0x2, 0x1, and 0x0 to toggle the LEDs on and off.
Switch input reading is also demonstrated, showing 1 when pressed and 0 when not.
A for loop is used to sequentially light up three LEDs.
Many thanks for reference articles.
https://marsee101.blog.fc2.com/blog-entry-5847.html
SummaryThis project showcased how to control GPIO on the KR260 using Python (PYNQ) via the PMOD connector for LED output and switch input.
The next step will involve utilizing the KR260 with a PWM IP to control a DC motor using PWM.
2. PYNQ + PWM(DC-Motor Control) << next project
Comments