Build the controller that changes one byte of flash and keeps every other byte of its block.
Hardware context: A settings store in a small flash memory, one byte per setting. Build the controller that updates one byte of flash and keeps the other bytes of its block.
A device keeps its settings in a small flash memory. Each setting is one byte. In flash, a PROGRAM can only change a 1 to a 0. An ERASE sets a whole block of four bytes to ff.
This is an Implement problem. Write flash_update. For each request it stores one new byte. The other three bytes of the block must keep their values.
The flash is slow. It is busy for some cycles after each PROGRAM and ERASE, and it ignores any command that arrives while it is busy.
The test connects your module to a model of the flash, filled with different bytes in every test. It sends four updates and compares the whole flash at the end.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
ups | 52 | input of each check |
Full specification
module flash_update (
input logic clk,
input logic rst, // synchronous, active high
input logic req, // 1 for one cycle while ready is 1: store data in byte addr
input logic [4:0] addr, // byte address: addr[4:2] is the block, addr[1:0] the byte in it
input logic [7:0] data,
output logic ready, // 1: idle, and the last update is complete in the flash
// the flash pins
output logic [1:0] cmd, // 0 NOP, 1 PROGRAM, 2 ERASE, 3 READ
output logic [4:0] faddr, // the byte to read or program, or any byte of the block to erase
output logic [7:0] fdata, // the data of a PROGRAM
input logic [7:0] frdata, // after a READ: the byte, from the next cycle on
input logic fbusy // 1: the flash is busy and ignores every command
);
// your design
endmodule
| Command | Effect | Busy after it |
|---|---|---|
| 3 READ | The byte at faddr is on frdata from the next cycle on, until the next READ. | not busy |
| 1 PROGRAM | The byte at faddr becomes (old byte AND fdata). | 2 cycles |
| 2 ERASE | All four bytes of the block of faddr become ff. | 4 cycles |
| 0 NOP | Nothing. | not busy |
fbusy is 1 in every cycle in which the flash is busy. A command sent in such a cycle is ignored, and a READ sent then makes frdata unknown.
| Port rule | Definition |
|---|---|
| Request | req is 1 for one cycle while ready is 1. addr and data are valid in that cycle only. |
| ready | 1 when the controller is idle and the flash has finished the update. After a request it must be 1 again within 40 cycles. |
| Wear | Use at most one ERASE per update. |
| Reset | At a rising edge with rst = 1 the controller goes idle and sends NOP. The flash keeps its bytes. |
Each test sends four requests. Each one comes as soon as ready is 1 again, sometimes after a few idle cycles. The result has three fields.
| Field | Meaning |
|---|---|
| rules_broken | Rule numbers. 0: a command sent while the flash was busy. 1: a PROGRAM that tried to change a 0 to a 1. 2: more erases than updates. |
| late | The updates that did not finish in time, or could not be sent. |
| wrong_bytes | How many of the 32 bytes differ from the expected content at the end. |
Examples
Example 1
Four Updates in Four Blocks- Input
a5 into byte 6; 3c into byte 17; 7e into byte 0; 81 into byte 31
- Output
rules_broken = {}, late = {}, wrong_bytes = 0, updates = 4
Each update changes one byte. The other three bytes of each block, and the four blocks nobody touched, must keep their seeded values. A controller that erases and programs only the new byte loses the neighbours.
Example 2
Two Updates in One Block, Back to Back- Input
12 into byte 9; 34 into byte 10; 56 into byte 8; 78 into byte 11
- Output
rules_broken = {}, late = {}, wrong_bytes = 0, updates = 4
The second request comes as soon as ready is 1. If ready returns before the last PROGRAM is over, the next READ finds the flash busy.
Example 3
A New Byte That Sets Bits- Input
ff into byte 4; f0 into byte 5; 0f into byte 20; ff into byte 21
- Output
rules_broken = {}, late = {}, wrong_bytes = 0, updates = 4
The old bytes hold many 0 bits, and the new bytes need some of them to be 1. A PROGRAM alone cannot do that: only the erase brings a 0 back to 1.
Constraints and Contract
- Requests arrive only while ready is 1 and are known 0/1 values. Inputs change while the clock is low.
- Keep the module name and the ports. The flash is the only storage that counts: the test reads it, not your module.
Hints
Hint 1
List the steps of one update on paper: read the four bytes, erase, program the four bytes. Then add a wait wherever the flash can be busy.
Hint 2
A READ gives its byte one cycle later. So each read needs two cycles: one to send READ, one to store frdata.
Hint 3
Keep one 2-bit counter for the byte number. Use it for the reads and again for the programs. Put the new byte in place when you program, not when you read.
What the grader checks: Eight directed and eight seeded tests send four updates each to a flash model of 32 bytes. The model checks every command against the busy flag and every PROGRAM against the old byte, and counts the erases. The whole flash is compared with a JavaScript model at the end. Real program and erase times, status polling and power loss in the middle of an update are outside this problem.
The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.
16 checks on Icarus Verilog + Yosys · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 steps and the final capstone