SPI Flash Read Module [Verilog]

Share

Requirement Analysis

This module implements a Flash controller that reads 4 bytes at a time.

As mentioned in Building a Computer with Nexys4 DDR [1]: Hardware, the computer needs a “hard disk” for reading read-only data.

Principle Analysis

The SPI Flash chip used by Nexys4 DDR is the S25FL128S.

The circuit diagram is below:

pic 1

What Is SPI?

For simplicity, I only introduce the basics here. For details, see the wiki.

SPI is a serial bus protocol. Data is transmitted bit by bit through a wire. The signals needed here are sck, cs_n, si, and so.

sck is the clock signal, used for synchronization. Its frequency can be chosen freely within the working range.

cs_n is the chip-select signal. The _n suffix means active low, so the chip starts working when cs_n is pulled low.

si is the signal line input to the master device. Reading data from the Flash chip depends on it.

so is the signal line input to the Flash chip. Writing data to the Flash chip depends on it.

What Is a Flash Chip?

Simply put, it consists of many readable and writable cells, EEPROM, plus a controller. The controller wraps many commands for operating those cells. So the most important part of using a Flash chip is sending the correct commands to its controller.

The structure of the Flash chip is shown below:

pic 2

Flash commands vary slightly across manufacturers, but because there are standards, most common commands are the same. You can refer to each chip’s documentation.

S25FL128S chip documentation

Timing

Flash Chip Timing

Since we only need to read data, this article only introduces the one command used here: READ.

According to the S25FL128S documentation, the timing of the read command is:

pic 3

From the diagram, to read data we need to:

  1. Pull cs_n low.
  2. Keep sck within the working frequency range. The datasheet says the maximum frequency for the READ command is 50 MHz, so sck can be anywhere in (0, 50M]. Since the onboard crystal of Nexys4 DDR is 100 MHz, 50 MHz is convenient to generate by division.
pic 4
  1. Send the READ command, 03H, and the 24-bit address bit by bit through the so signal line.
  2. Finally, the Flash chip outputs data bit by bit through the si signal line.

Wishbone Bus Read Timing

As a peripheral, the Flash controller needs to connect to the bus, so the interface must satisfy the bus requirements.

This computer uses the Wishbone bus. Its timing is relatively simple. Here is the signal flow for a bus read operation:

pic 5

In short, during operation, STB_O and CYC_O are raised at the same time, the address is put into ADR_O, and then the circuit waits for clock cycles on CLK_I. The bus then waits for the peripheral. When the peripheral finishes processing the signal, it raises ACK_I to complete the transfer.

After the master receives the data, it lowers STB_O and CYC_O. At that point, the peripheral knows that the access is complete and lowers ACK_I.

Design

State Machine Design

This part mainly refers to this article.

As shown below:

pic 6

Read more

可多路视频播放的VisionOS 媒体查看器开发

可多路视频播放的VisionOS 媒体查看器开发

开发一款能够同时播放多个视频的vision pro媒体查看器。 0:00 /0:40 1× 缘起 Vision Pro 发布时我就特别想买,毕业工作后终于有资金购入并加入Apple开发者计划,从今年五月到现在也用了快小半年,用起来确实挺爽。 但是有些痛点还是很难受,其中一个痛点就是无法同时播放多个视频音频(实际上VisionOS提供了同时播放音频的API,但是似乎我用的APP都是不遵守🤣 导致都在抢占),因此为了满足我自己的这个痛点,也学习一下Vision OS 的应用开发,甚至完成度足够的话考虑上架App Store,便有了这个目标是多视频同时播放的媒体查看器项目。 现有工作 我购买了4XVR、Infuse、Moon Player、ES 文件助手(这款只有iPad OS版,不是专供Vision OS的),这几个月体验下来,全都存在我提到的和其他APP抢占音频通道,无法同时播放的问题,其他的我的主观的体验如下: 4XVR:使用最多,用起来最舒服,格式支持很全,VR视频也能看,号称全v

By Feiran Yu