Reviewed-on: #18
Zynq 7000 Bare-Metal Rust Support
This crate collection provides support to write bare-metal Rust applications for the AMD Zynq 7000 family of SoCs.
List of crates
This project contains the following crates:
Zynq Workspace
This workspace contains libraries and application which can only be run on the target system.
- The
zynq7000-rtrun-time crate containing basic low-level startup code necessary to boot a Rust app on the Zynq7000. - The
zynq7000PAC crate containing basic low-level register definitions. - The
zynq7000-mmucrate containing common MMU abstractions used by both the HAL and the run-time crate. - The
zynq7000-halHAL crate containing higher-level abstractions on top of the PAC register crate. - The
zynq7000-embassycrate containing support for running the embassy-rs asynchronous run-time.
This project was developed using a Zedboard, so there are several crates available targeted towards this board:
- The
zedboard-bspcrate containing board specific components for the Zedboard. - The
zedboard-fsblcontains a simple first-stage bootloader application for the Zedboard. - The
zedboard-qspi-flashercontains an application which is able to flash a boot binary from DDR to the QSPI.
It also contains the following helper crates:
- The
examplesfolder contains various example applications crates using the HAL and the PAC. This folder also contains dedicated example applications using theembassynative Rust RTOS.
Other libraries and tools
- The
zedboard-fpga-designfolder contains a sample FPGA design and block design which was used in some of the provided software examples. The project was created with Vivado version 2024.1. The folder contains a README with all the steps required to load this project from a TCL script. - The
zynq7000-boot-imagelibrary contains generic helpers to interface with the AMD boot binary. - The
tools/zynq7000-ps7init-extracttool allows extracting configuration from the AMD generatedps7init.tclfile which contains static configuration parameters for DDR initialization.
Using the .cargo/config.toml file
This is mostly relevant for development directly inside this repostiory.
Use the following command to have a starting config.toml file
cp .cargo/config.toml.template .cargo/config.toml
You then can adapt the config.toml to your needs. For example, you can configure runners
to conveniently flash with cargo run.
Using the sample VS Code files
Use the following command to have a starting configuration for VS Code:
cp -rT vscode .vscode
You can then adapt the files in .vscode to your needs.
Building the blinky example
Building an application requires nightly to build the core and alloc library
because the thumbv7a-none-eabihf Rust target only has Tier 3 support
If you have not installed it yet, you can do so with
rustup toolchain install nightly
Assuming you have the following segments inside your .cargo/config.toml
[target.armv7a-none-eabihf]
rustflags = [
"-Ctarget-cpu=cortex-a9",
"-Ctarget-feature=+vfp3",
"-Ctarget-feature=+neon",
"-Clink-arg=-Tlink.x",
# If this is not enabled, debugging / stepping can become problematic.
"-Cforce-frame-pointers=yes",
# Can be useful for debugging.
# "-Clink-args=-Map=app.map"
]
# Tier 3 target, so no pre-compiled artifacts included.
[unstable]
build-std = ["core", "alloc"]
[build]
target = "armv7a-none-eabihf"
You can build the blinky example app using
cd zynq
cargo build --bin blinky
Flashing, running and debugging the software
This repository was only tested with the Zedboard but should be easily adaptable to other Zynq7000 based platforms and boards.
If you want to test and use this crate on a Zedboard, make sure that the board jumpers on the Zedboard are configured for JTAG boot.
Pre-Requisites
xscttool installation. You have to install the Vitis tool to get access to this tool. You can minimize the download size by de-selecting all SoC families that you do not require. Vitis also includes a Vivado installation which is required to do anything with the FPGA.hw_serverinstallation which is generally included with Vitis/Vivado. This tool starts a GDB server which will be used to connect to and debug the target board. It also allows initializing the processing system and uploading the FPGA design via JTAG.- A valid
ps7_init.tclscript to configure the processing system. This is necessary to even be able flashing application into the DDR via JTAG. There are multiple ways to generate this startup script, but the recommended way here is to the thesdtgentool included inxsctwhich also generates a bitstream for the FPGA configuration. You can find a sampleps7_init.tclscript inside thescriptsfolder. However, it is strongly recommended to get familiar with Vivado and generate the SDT folder yourself. gdb-multiarchinstallation to debug applications.python3installation to use the provided tooling.
Programming and Debug Flow
-
Start the
hw_serverapplication first. This is required for other tooling provided by this repository as well. -
The provided
scripts/zynq7000-init.pyscript can be used to initialize the processing system with theps7_init.tclscript, program the bitstream, and load an ELF file to the DDR. You can runscripts/zynq7000-init.pyto get some help and additional information. Here is an example command to initialize the processing system without loading a bitstream using the provided initialization script (adaptAMD_TOOLSto your system):export AMD_TOOLS="/tools/Xilinx/Vitis/2024.1" ./scripts/zynq7000-init.py --itcl ./scripts/ps7_init.tcl -
Assuming you have managed to build the blinky example, you can flash the example now using GDB:
gdb-multiarch -q -x gdb.gdb target/armv7a-none-eabihf/debug/blinkyYou can use the
-tuiargument to also have a terminal UI. This repository provides ascripts/runner.shwhich performs all the steps specified above. The.cargo/def-config.tomlscript contains the runner and some template environmental variables that need to be set for this to work. The command above also loaded the app, but this task can be performed by thezynq7000-init.pywrapper as well.
Using VS Code
The provided VS Code configuration files can be used to perform the CLI steps specified above
in a GUI completely and to also have a graphical debugging interface. You can use this
as a starting point for your own application. You need to adapt the options.env variables
in .vscode/tasks.json for this to work.
Embedded Rust
If you have not done this yet, it is recommended to read some of the excellent resources available to learn Rust: