This document specifies the general functionality of flash. As the final feature set will largely depend on how similar vendor flash IPs are, it is at the moment unclear where the open-source / proprietary boundaries should lie. This document thus makes a best effort guess as to what that boundary should be and breaks the functionality down accordingly.
This document assumes flash functionality shall be divided into two partitions.
The Flash Protocol Controller sits between the host software interface and the physical flash. Its primary function is to translate software requests into a high level protocol for the actual flash block. Importantly, the flash protocol controller shall not be responsible for the detailed timing and waveform control of the flash. Instead, it shall maintain FIFOs / interrupts for the software to process data.
The Flash Physical Controller is the wrapper module that contains the actual flash memory instantiation. It is responsible for converting high level protocol commands (such as read, program, erase) into low level signal and timing specific to a particular flash IP. It is also responsible for any BIST, redundancy handling, remapping features or custom configurations required for the flash memory.
The diagram below summarizes a high level breakdown.
As the flash physical controller is highly dependent on flash memory selected, the default flash physical controller simply emulates real flash behavior with on-chip memories. The goal of the emulated flash is to provide software developers with a reasonable representation of a well-behaving flash operating under nominal conditions.
Below are the emulated properties
The flash physical controller does NOT emulate the following properties
Depending on need, in flash 0.5+, it may be necessary to add controller logic to perform the following functions
The flash protocol controller uses a simple FIFO interface to communicate between the software and flash physical controller. There is a read fifo for read operations, and a program fifo for program operations. Note, this means flash can be read both through the controller and the main bus interface. This may prove useful if the controller wishes to allocate specific regions to HW FSMs only, but is not a necessary feature.
When software initiates a read transaction of a programmable number of flash words, the flash controller will fill up the read FIFO for software to consume. Likewise, when software initiates a program transaction, software will fill up the program FIFO for the controller to consume.
The controller is designed such that the overall number of words in a transaction can significantly exceed the FIFO depth. In the case of read, once the FIFO is full, the controller will cease writing more entries and wait for software to consume the contents (an interrupt will be triggered to the software to alert it to such an event). In the case of program, the controller will stop writing to flash once all existing data is consumed - it will likewise trigger an interrupt to software to prepare more data. See detailed steps in theory of operation. The following is a diagram of the controller construction as well as its over connectivity with the flash module.
As the physical controller is IP specific, this section will only try to describe the connecting protocol signals, its function, and the memory allocation of configuration registers.
Signal | Purpose |
---|---|
host_req_i | Host initiated direct read, should always be highest priority. Host is only able to perform direct reads |
host_addr_i | Address of host initiated direct read |
host_req_rdy_o | Host request ready, ‘1’ implies transaction has been accepted, but not necessarily finished |
host_req_done_o | Host request completed |
host_rdata_o | Host read data, 1 flash word wide |
req_i | Controller initiated transaction |
addr_i | Address of controller initiated transaction |
rd_i | Controller initiated read |
prog_i | Controller initiated program |
pg_erase_i | Controller initiated page erase |
prog_data_i | Controller initiated program data, 1 flash word wide |
bk_erase_i | Controller initiated bank erase |
rd_done_o | Controller initiated read done |
prog_done_o | Controller initiated program done |
erase_done_o | Controller initiated erase done |
init_busy_o | Physical controller reset release initialization in progress |
rd_data_o | Controller read data, 1 flash word wide |
Unlike controller initiated reads, host reads have separate rdy / done signals to ensure transactions can be properly pipelined. As host reads are usually tied to host execution upstream, additional latency can severely harm performance and is not desired. The protocol expected waveform is shown below.
{{< wavejson >}} {signal: [ {name: ‘clk_i’, wave: ‘p..............’}, {name: ‘rst_ni’, wave: ‘0.1............’}, {name: ‘host_req_i’, wave: ‘0..10.1...0....’}, {name: ‘host_addr_i’, wave: ‘x..3x.3.33x....’, data: [‘Adr0’, ‘Adr1’, ‘Adr2’, ‘Adr3’]}, {name: ‘host_req_rdy_o’, wave: ‘1...0..1.......’}, {name: ‘host_req_done_o’, wave: ‘0...10..1110...’}, {name: ‘host_rdata_o’, wave: ‘x...4x..444x...’,data: [‘Dat0’, ‘Dat1’, ‘Dat2’, ‘Dat3’]}, ]} {{< /wavejson >}}
The host_req_done_o
is always single cycle pulsed and upstream logic is expected to always accept and correctly handle the return. The same cycle the return data is posted a new command / address can be accepted. While the example shows flash reads completing in back to back cycles, this is typically not the case.
Unlike host reads, controller reads are not as performance critical and do not have command / data pipeline requirements. Instead, the protocol controller will hold the read request and address lines until the done is seen. Once the done is seen, the controller then transitions to the next read operation. See expected waveform below.
{{< wavejson >}} {signal: [ {name: ‘clk_i’, wave: ‘p..............’}, {name: ‘rst_ni’, wave: ‘0.1............’}, {name: ‘req_i’, wave: ‘0..1.....0.....’}, {name: ‘addr_i’, wave: ‘x..3..3..x.3..x’, data: [‘Adr0’, ‘Adr1’, ‘Adr2’]}, {name: ‘rd_i’, wave: ‘0..1.....0.1..0’}, {name: ‘rd_done_o’, wave: ‘0....10.10...10’}, {name: ‘rdata_o’, wave: ‘x....4x.4x...4x’, data: [‘Dat0’, ‘Dat1’, ‘Dat2’]}, ]} {{< /wavejson >}}
Program behavior is similar to reads. The protocol controller will hold the request, address and data lines until the programming is complete.
{{< wavejson >}} {signal: [ {name: ‘clk_i’, wave: ‘p..............’}, {name: ‘rst_ni’, wave: ‘0.1............’}, {name: ‘req_i’, wave: ‘0..1.....0.....’}, {name: ‘addr_i’, wave: ‘x..3..3..x.3..x’, data: [‘Adr0’, ‘Adr1’, ‘Adr2’]}, {name: ‘prog_i’, wave: ‘0..1.....0.1..0’}, {name: ‘prog_data_i’, wave: ‘x..4..4..x.4..x’, data: [‘Dat0’, ‘Dat1’, ‘Dat2’]}, {name: ‘prog_done_o’, wave: ‘0....10.10...10’}, ]} {{< /wavejson >}}
To issue a flash read, the programmer must
void read_flash (uint32_t addr, uint32_t num, uint32_t *data) { uint32_t val; // Setup address REG32(FLASH_CTRL_ADDR) = addr; // kick off flash operation val = FlashRead << FLASH_CTRL_CONTROL_OP_OFFSET | (num-1) << FLASH_CTRL_CONTROL_NUM_OFFSET | 0x1 << FLASH_CTRL_CONTROL_START; REG32(FLASH_CTRL_CONTROL(0)) = val;
It is acceptable for total number of flash words to be significantly greater than the depth of the read FIFO. In this situation, the read FIFO will fill up (or hit programmable fill value), pause the flash read and trigger an interrupt to software. Once there is space inside the FIFO, the controller will resume reading until the appropriate number of words have been read. Once the total count has been reached, the flash controller will post OP_DONE in the {{< regref “OP_STATUS” >}} register.
To program flash, the same procedure as read is followed. However, instead of setting the {{< regref “CONTROL” >}} register for read operation, a program operation is selected instead. Software will then fill the program FIFO and wait for the controller to consume this data. Similar to the read case, the controller will automatically stall when there is insufficient data in the FIFO. When all desired words have been programmed, the controller will post OP_DONE in the {{< regref “OP_STATUS” >}} register.
The flash protocol controller maintains two separate access windows for the FIFO. It is implemented this way because the access window supports transaction back-pressure should the FIFO become full (in case of write) or empty (in case of read).
{{< registers “hw/ip/flash_ctrl/data/flash_ctrl.hjson” >}}