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

Peripheral codegen for Grapefruit / Cosmo #2010

Merged
merged 8 commits into from
Feb 12, 2025
Merged

Conversation

mkeeter
Copy link
Collaborator

@mkeeter mkeeter commented Feb 10, 2025

This PR adds a new target to build-fpga-regmap, generating Rust code for a memory-mapped peripheral. For Grapefruit and Cosmo, the Spartan-7 FPGA is connected over FMC, so we can treat peripherals implemented in the FPGA as native(ish). This PR uses the new codegen paths for cosmo-hf and grapefruit-seq, replacing raw addresses. The peripheral types take a drv_spartan7_loader_api::Spartan7Token, which proves that the FPGA is loaded and running.

Other changes that came along for the ride:

  • Grapefruit FPGA files (bitstream and JSON) are moved to drv/spartan7-loader/grapefruit/ subfolder. I also updated to a more recent build (latest main), and removed the HTML file (since the JSON is smaller + has the same information).
  • syn is bumped to version 2, which requires a few miscellaneous changes

Copy link
Contributor

@nathanaelhuffman nathanaelhuffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a minor comment about some other access types we might see. We have a lot of other stuff that could be exposed from the RDL side, but probably best to deal with it along-and-along as we start experiencing them.

Excited about making this more 1st class!

name: String,
value: u8,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum SwAccess {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a note, there are a few more possible types here: https://systemrdl-compiler.readthedocs.io/en/stable/api/types.html#systemrdl.rdltypes.builtin_enums.AccessType
that could show up.

We also don't do much with the OnRead and OnWrite types described below that section but am open to doing so if there's code-gen value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I'm going to leave those as unimplemented so that they'll fail loudly if we ever end up using them!

Copy link
Collaborator

@labbott labbott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor questions but LGTM

@@ -67,14 +65,16 @@ fn main() -> ! {
// Idol loop after the FPGA has been brought up.
let seq =
drv_spartan7_loader_api::Spartan7Loader::from(LOADER.get_task_id());
seq.ping();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional drop of the ping?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the call to seq.get_token() is what ensures that the FPGA is loaded.

_ => {
variant_errors.push(compile_error(
t.span(),
&format!(
"unexpected token {t:?}; expected #[idol(...)]"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing most of this is the fallout from syn update?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, they revamped the meta syntax tree in v2

@mkeeter mkeeter force-pushed the mkeeter/peripheral-codegen branch from 15b8bfc to 4225bea Compare February 12, 2025 17:05
@mkeeter mkeeter enabled auto-merge (squash) February 12, 2025 17:05
@mkeeter mkeeter merged commit 41792ab into master Feb 12, 2025
125 checks passed
@mkeeter mkeeter deleted the mkeeter/peripheral-codegen branch February 12, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants