Skip to content

Add support for SPI#442

Draft
ABIbreak wants to merge 2 commits into
mainfrom
spi-protocol
Draft

Add support for SPI#442
ABIbreak wants to merge 2 commits into
mainfrom
spi-protocol

Conversation

@ABIbreak

Copy link
Copy Markdown
Contributor

This PR will add support for SPI to sddf in terms of the following deliverables:

  1. Driver for the OpenTitan SPI host device with PULP patches
  2. Virtualiser for SPI
  3. Client for a SPI flash

@ABIbreak ABIbreak self-assigned this Jun 26, 2025
@ABIbreak

ABIbreak commented Jun 26, 2025

Copy link
Copy Markdown
Contributor Author

Blocking on:

  • Diagnose difference in behavior when enabling CSAAT
  • Extend recieve_data to support slices at arbitrary alignments
  • Write client for SPI flash
  • Create libspi, mirroring libi2c
  • Add support for SPI configuration (CPHA, CPOL, clock frequency) in the config struct

@ABIbreak

ABIbreak commented Jun 26, 2025

Copy link
Copy Markdown
Contributor Author

Nice-to-haves:

  • Add Javadoc comments for functions
  • Add licenses to files
  • Run clang format
  • Do outstanding TODOs that still exist in the code
  • Update examples/spi/{Makefile, build.zig, build.zig.zon}
  • Write documentation

@ABIbreak ABIbreak requested a review from omeh-a July 3, 2025 08:14
@ABIbreak

ABIbreak commented Jul 3, 2025

Copy link
Copy Markdown
Contributor Author

In the driver, config.slice_size is set manually; I will update sdfgen to populate this automatically

EDIT: done

@Ivan-Velickovic

Copy link
Copy Markdown
Collaborator

@ABIbreak does this need to be based on Lesley's I2C branch? For review it would be easier if it was just the SPI changes.

@ABIbreak

ABIbreak commented Jul 4, 2025

Copy link
Copy Markdown
Contributor Author

No, I'll rebase off of main

@ABIbreak

ABIbreak commented Jul 4, 2025

Copy link
Copy Markdown
Contributor Author

examples/spi/{Makefile, build.zig, build.zig.zon} were directly copied from the examples/i2c/, I will edit them later

Comment thread .gitignore Outdated
Comment thread drivers/spi/opentitan/spi.c
}

LOG_DRIVER_ERR("Polling RX timed out\n");
return -1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should probably use numbered error codes (ETIMEOUT? idk); instead of int returns.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should probably use numbered error codes (ETIMEOUT? idk); instead of int returns.

This is used internally and there's only one error case in this function, so I don't think this is necessary. We don't have a standard way of going about this though .... probably something we should write into the engineering docs 😳

Comment thread drivers/spi/opentitan/spi.c Outdated
}

if (poll_rx()) {
return -1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as above re: error codes.

Comment thread drivers/spi/opentitan/spi.c Outdated
Comment thread spi/libspi.c Outdated
Comment thread spi/libspi.c Outdated
Comment thread drivers/spi/opentitan/spi.c
Comment thread drivers/spi/opentitan/spi.c Outdated
Comment thread build.zig Outdated
Comment thread .gitignore Outdated
Comment thread drivers/spi/opentitan/driver.h Outdated
uint16_t num_cmds;
void *slice_base;
// Request in-progress state
uint8_t cmd_in_progress;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If this is an index, is it intended that the cmd_in_progress is a smalelr type than num_cmds?

Comment thread drivers/spi/opentitan/driver.h Outdated
Comment thread drivers/spi/opentitan/driver.h
}

LOG_DRIVER_ERR("Polling RX timed out\n");
return -1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should probably use numbered error codes (ETIMEOUT? idk); instead of int returns.

This is used internally and there's only one error case in this function, so I don't think this is necessary. We don't have a standard way of going about this though .... probably something we should write into the engineering docs 😳

Comment thread drivers/spi/opentitan/spi.c Outdated
Comment thread drivers/spi/opentitan/spi.c Outdated
Comment thread drivers/spi/opentitan/spi.c Outdated
Comment thread drivers/spi/opentitan/spi.c Outdated
Signed-off-by: George Chen <george.j.chen@student.unsw.edu.au>
Signed-off-by: George Chen <george.j.chen@student.unsw.edu.au>
@midnightveil midnightveil added protocol Issues pertaining to protocols for interfacing with drivers new-protocol drivers Issues pertaining to driver code for a device class labels Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

drivers Issues pertaining to driver code for a device class new-protocol protocol Issues pertaining to protocols for interfacing with drivers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants