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 | in | 1 bit | System clock |
rst | in | 1 bit | Synchronous reset (active high) |
start | in | 1 bit | Begin one four-byte read |
addr | in | 24-bit vector | Flash byte address |
miso | in | 1 bit | Data from the flash |
cs_n | out | 1 bit | Chip select, active low and idle high |
sclk | out | 1 bit | SPI clock, idle low |
mosi | out | 1 bit | Data to the flash |
busy | out | 1 bit | High while a read runs |
data | out | 8-bit vector | Latest completed byte |
valid | out | 1 bit | One-clock pulse for each completed byte |
done | out | 1 bit | One-clock pulse after the fourth completed byte |
Behavior
- Only an idle reader accepts
start, and the read it triggers begins one clock later - The reader copies
addrat the moment of acceptance - A read in progress works from that copy, so later
addrchanges cannot reach it startpulses that arrive whilebusyis high are dropped without effect- On the next clock,
busyrises andcs_nfalls to begin the transaction - While idle,
cs_nis high,sclkis low, andmosiis low - Each read uses one continuous transaction under a single
cs_nlow period cs_nfalls exactly one system clock before the first risingsclkedgecs_nstays low through the last data bit- SPI mode 0 is used, with exactly two system clocks for every SPI bit
sclkis low during a bit's first system clock and high during its secondmosiis set during the low phase and remains stable before the risingsclkedgemisois sampled on each risingsclkedge- 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 - After the dummy phase, 32 more
sclkcycles read four data bytes frommiso - Data is received most significant bit first within each byte
mosiremains low throughout the complete data phase- When each byte completes,
dataupdates andvalidpulses for one system clock dataholds its latest completed byte betweenvalidpulses- After the fourth
validpulse,sclkfalls on the next clock anddonepulses for that clock busyremains high andcs_nremains low during thedonepulse- One system clock after the final
sclkfall,cs_nrises andbusyfalls - The unit is idle when
cs_nreturns high andbusyfalls rsthigh at any rising edge aborts the read and clears all transaction progress- Reset forces
cs_nhigh and forcessclk,mosi,busy,valid, anddonelow - No read aborted by reset resumes afterward
What the bench checks
- A flash model decodes the opcode and address off
mosiat each risingsclkedge and serves four bytes derived from the address it heard - The dummy phase is the trap: a
validpulse 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
sclkedges inside it cs_nmust fall one clock before the firstsclkrise and rise one clock after the last fallmosimay never change on a clock wheresclkrose or stayed highaddrswitches to a decoy one clock after acceptance, and extrastartpulses 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
everything is synchronous to clk; inputs are sampled on rising edges, and all outputs are registered.
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.