Skip to content

[sw] Add SPI device driver and smoketest - #266

Merged
marnovandermaas merged 4 commits into
lowRISC:mainfrom
raylau1:spi_dev_sw
Feb 5, 2026
Merged

marnovandermaas merged 4 commits into
lowRISC:mainfrom
raylau1:spi_dev_sw

Conversation

@raylau1

@raylau1 raylau1 commented Jan 28, 2026

Copy link
Copy Markdown
Contributor

Closes #242

Testing on FPGA can be done with the FT4222H dongle and ftditool by running nix shell git+ssh://git@github.com/lowrisc/ftditool.

JEDEC ID read can be done by running ftditool jedec, which should return:

Jedec:
        mem_type: 0x8
        capacity: 0x14
        mid: 0xef

SFDP read can be done by running ftditool sfdp, which should return:

Sfdp: {
        header: SfdpHeader: {
        signature: 0x50444653
        minor: 10
        major: 1
        num_headers: 0
        access_proto: 0xff}

        parameter: ParamHeader: {
        id: 0xff00
        minor: 7
        major: 1
        length: 23
        table_offset: 0x4}
}

Flash read write test can be done by running ftditool test-page, which should return:

page read 0x0 : Array<256>: {5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a, 5a}

SPI commands received by software during the read write test are displayed on UART with messages similar to below:

SPI RESET
SPI SECTOR ERASE addr: 0x00000000
SPI PAGE PROGRAM addr: 0x00000000 payload_bytes: 0x00000100 payload: 0x5A5A5A5A 0x5A5A5A5A 0x5A5A5A5A 0x5A5A5A5A ...

@marnovandermaas marnovandermaas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just had a few comments for the hardware. The tests look good to me and thanks for adding these. It would be good to get @engdoreis to have a look at the tests as well for a review.

Comment thread sw/device/lib/hal/spi_device.c Resolved
Comment thread sw/device/lib/hal/uart.c Resolved

@engdoreis engdoreis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this PR, this will unblock the bootloader, I left a few comments:

Comment thread sw/device/lib/hal/uart.c Resolved
// [23:16]: Number of parameter headers, zero-based (JESD216F 6.2.2)
// [31:24]: SFDP access protocol (JESD216F 6.2.3)
DEV_WRITE(buf_ptr,
reg32_field( 7, 0, SPI_DEVICE_SFDP_MINOR_REVISION) |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that the content of the table should come from the app via a struct, but I'm ok to merge as is because it serves the purpose of the test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your suggestion, perhaps that can be a future enhancement

Comment thread sw/device/lib/hal/spi_device.c Resolved
Comment thread sw/device/lib/hal/reg_field.c Resolved
@raylau1
raylau1 force-pushed the spi_dev_sw branch 2 times, most recently from 524122f to 5a4ca83 Compare February 2, 2026 14:28

@engdoreis engdoreis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I left one more comment, otherwise LGTM.

Comment thread sw/device/lib/hal/reg_field.c Resolved
This driver is based on the silicon creator SPI device driver in
opentitan at `sw/device/silicon_creator/lib/drivers/spi_device.*`

The initialisation function configures flash commands and writes
the SFDP table content.
To be used with ftditool in CI

@marnovandermaas marnovandermaas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's merge this to make progress!

@marnovandermaas
marnovandermaas merged commit e34ac18 into lowRISC:main Feb 5, 2026
4 checks passed
@marnovandermaas
marnovandermaas deleted the spi_dev_sw branch February 5, 2026 10:02
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.

Integrate SPI device

3 participants