Practice
Archive Flash Burst
At dawn, the ferry Alder Rose loads its voyage recorder settings from a small SPI flash chip before leaving Ramsgate.
A replacement reader board came back from repair with a clear fault. On a fan-fold hex dump, every page began with FF and lost its last real byte.
The flash chip's fast-read command needs eight dummy clocks between the address and the first data bit. The repaired board had saved that dummy byte as data.
Your task: build a reader that treats the chip's phases as law. Send the command, address, and dummy clocks, then collect four real data bytes.
Interface
| Port | Direction | Type | Description |
|---|---|---|---|
clk_i | in | 1 bit | System clock |
rst_i | in | 1 bit | Synchronous reset (active high) |
start_i | in | 1 bit | Begin one four-byte read |
addr_i | in | 24-bit vector | Flash byte address |
miso_i | in | 1 bit | Data from the flash |
cs_n_o | out | 1 bit | Chip select, active low and idle high |
sclk_o | out | 1 bit | SPI clock, idle low |
mosi_o | out | 1 bit | Data to the flash |
busy_o | out | 1 bit | High while a read runs |
data_o | out | 8-bit vector | Latest completed byte |
valid_o | out | 1 bit | One-clock pulse for each completed byte |
done_o | out | 1 bit | One-clock pulse after the fourth completed byte |
Behavior
- Only an idle reader accepts
start_i, and the read it triggers begins one clock later - The reader copies
addr_iat the moment of acceptance - A read in progress works from that copy, so later
addr_ichanges cannot reach it start_ipulses that arrive whilebusy_ois high are dropped without effect- On the next clock,
busy_orises andcs_n_ofalls to begin the transaction - While idle,
cs_n_ois high,sclk_ois low, andmosi_ois low - Each read uses one continuous transaction under a single
cs_n_olow period cs_n_ofalls exactly one system clock before the first risingsclk_oedgecs_n_ostays low through the last data bit- SPI mode 0 is used, with exactly two system clocks for every SPI bit
sclk_ois low during a bit's first system clock and high during its secondmosi_ois set during the low phase and remains stable before the risingsclk_oedgemiso_iis sampled on each risingsclk_oedge- The first phase sends the fast-read opcode
0x0B, most significant bit first - The next phase sends all 24 captured address bits, most significant bit first
- The next phase sends eight dummy bits, all driven low on
mosi_o - After the dummy phase, 32 more
sclk_ocycles read four data bytes frommiso_i - Data is received most significant bit first within each byte
mosi_oremains low throughout the complete data phase- When each byte completes,
data_oupdates andvalid_opulses for one system clock data_oholds its latest completed byte betweenvalid_opulses- After the fourth
valid_opulse,sclk_ofalls on the next clock anddone_opulses for that clock busy_oremains high andcs_n_oremains low during thedone_opulse- One system clock after the final
sclk_ofall,cs_n_orises andbusy_ofalls - The unit is idle when
cs_n_oreturns high andbusy_ofalls rst_ihigh at any rising edge aborts the read and clears all transaction progress- Reset forces
cs_n_ohigh and forcessclk_o,mosi_o,busy_o,valid_o, anddone_olow - No read aborted by reset resumes afterward
What the bench checks
- A flash model decodes the opcode and address off
mosi_oat each risingsclk_oedge and serves four bytes derived from the address it heard - The dummy phase is the trap: a
valid_opulse before transaction clock 95 is flagged as the dummy byte landing in the data - Each read must fit one chip-select window: 145 clocks low with exactly 72 rising
sclk_oedges inside it cs_n_omust fall one clock before the firstsclk_orise and rise one clock after the last fallmosi_omay never change on a clock wheresclk_orose or stayed highaddr_iswitches to a decoy one clock after acceptance, and extrastart_ipulses land mid-dummy, mid-data, and on the done clock- It asserts reset in the command, dummy, and data phases and expects idle pins at once with no aborted read resuming
Constraints
TIMING: everything is synchronous to
clk_i; inputs are sampled on rising edges, and all outputs are registered.
SCOPE: this models the four logic pins of a mode-0 SPI link and the fast-read phase order. Electrical drive, real flash latencies, and other flash commands are out of scope.
Do not add ports.
Click Run to execute your code. Output will appear here.