G8.5.1 Update a Byte in Flash

MediumImplementIcarus Verilog + Yosys · serverReview the topic

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

SignalWidthRole
ups52input of each check
Full specification
The module you write (keep the name and the ports)
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
CommandEffectBusy after it
3 READThe byte at faddr is on frdata from the next cycle on, until the next READ.not busy
1 PROGRAMThe byte at faddr becomes (old byte AND fdata).2 cycles
2 ERASEAll four bytes of the block of faddr become ff.4 cycles
0 NOPNothing.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 ruleDefinition
Requestreq is 1 for one cycle while ready is 1. addr and data are valid in that cycle only.
ready1 when the controller is idle and the flash has finished the update. After a request it must be 1 again within 40 cycles.
WearUse at most one ERASE per update.
ResetAt 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.

FieldMeaning
rules_brokenRule 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.
lateThe updates that did not finish in time, or could not be sent.
wrong_bytesHow 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

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Four Updates in Four Blocks

Input
a5 into byte 6; 3c into byte 17; 7e into byte 0; 81 into byte 31
Expected 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.

Run samples executes all 3 public checks. Check all tests runs 16 checks on the server.

Icarus Verilog + Yosys · server