Implement SPI Flash driver and server#347
Draft
lchiawei wants to merge 3 commits into
Draft
Conversation
lchiawei
force-pushed
the
feature/spi-driver-server
branch
5 times, most recently
from
July 16, 2026 00:04
9128b31 to
58c84b3
Compare
Key modifications and fixes made during the port:
- Implements the `embedded-hal` `SpiDevice` trait, which includes:
* Defines a related `SpiError` type.
* Defines the `transaction` method in the struct, which accepts an
array of operations, and `csaat` will be asserted during the entire
operation series.
* Marks the operations like `Transfer`, `TransferInPlace`, and
`DelayNs` as unsupported explicitly, which is also originally
unsupported.
* Removes unsupported hardware optimization methods like `prefetch`,
`drain_fifo`, and `aligned_drain_fifo` since they are not defined
in `embedded_hal`. If we need the original optimization that only
works on aligned words, we can branch on aligned/unaligned input
and apply similar optimization when the input is aligned. However,
we should stick with the input type defined in `embedded_hal`.
- Defines a dedicated `SpiConfig` struct and a dedicated `configure`
method to make SPI Host configurable.
Also includes a smoke test validating SPI read transactions by checking
the SFDP signature.
Signed-off-by: Chia-Wei Liu <lchiawei@google.com>
Key modifications and fixes made during the port:
- Makes the driver explicitly enter "Global 4-byte" mode when flash size
>= 16 MB, which includes:
* Update the command config in `from_sfdp()` &
`from_sfdp_conservative()`.
* Explicitly enters the global 4-byte mode at the end of
initialization.
- Skips the support of DUAL / QUAD in `SpiTxnWidth`. Also, inits the
driver with non-conservative version for now.
- Moves `transfer_req_resp` from legacy SPI Host driver to SPI Flash
driver, as a helper method.
- Moves `check_valid_size` from legacy Flash trait to SPI Flash
driver, as a helper method.
- Adds `is_busy` helper method as what we did for `BlockingFlash` trait,
although we didn't implement this trait directly now.
- Wraps legacy `page_size` and `size` into a `geometry` method required
by `Flash` trait. Currently we hard-coded the erasable bitmap as 4KB
and 64KB, and we may parse them in the future.
- For `erase()` method, the `Flash` trait only accepts the size declared
in the erasable bitmap, but here we uses the legacy implementation
which will loop over the size to erase. However, we still only accepts
power of 2 as the erase size due to `Flash` trait's contract. Also
removes the original `erase_page()` method.
- Drops `FlashStreamingRead` support (as we mentioned in SPI Host
driver commit).
Mock SPI Device & Unit Test Refactoring:
- Ports the legacy `FakeSpiHost` to OpenPRoT, renaming it to `FakeSpiDevice`
under `drivers/mock/spi_device_fake.rs` and implementing standard
`embedded_hal::spi::SpiDevice` and `ErrorType` traits.
- Rewrites mock transmission logic to be stateless by removing `TxnState`,
supporting multi-buffer transaction execution and automatic TX/RX clock
log alignment and padding.
- Introduces `assert_all_expectations_met()` to strictly assert that all
preprogrammed SPI responses are executed, preventing silent test leaks.
- Adapts unit tests to new `PowerOf2Usize` API constraints:
* Erase lengths in mixed granularity and multiple page tests are changed
to powers of 2 (e.g., 144KB -> 128KB, 12KB -> 16KB).
* Obsolete `test_erase_zero_length` is removed as zero-length input is
prevented at compile time.
- Aligns mock expectations with Global 4-byte address mode: expected
opcodes are updated from 4-byte-specific ones (e.g. `OP_READ4B`) to
standard opcodes (e.g. `OP_READ`) with 4-byte address streams.
- Removes obsolete unit tests for prefetch, FIFO draining, and
Streaming Read.
Signed-off-by: Chia-Wei Liu <lchiawei@google.com>
lchiawei
force-pushed
the
feature/spi-driver-server
branch
from
July 16, 2026 17:58
58c84b3 to
bf0f941
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR depends on #345 and #346. I will rebase this PR onto them after they are merged.