Foreword
In the previous post I gave a quick run down of initials perceptions of the Arty A7 board in getting memory access to work.
The Memory Interface Generator (MIG) provided by Vivado is very easy to use to create blocks for interfacing with the memory on the Arty board. However, no matter how much I tweaked the MIG generated code, I couldn't get to a design with minimal latency.
I started looking into alternative opensource Memory Controller designs, with the hope of getting around this latency issue.
One of the opensource designs I have looked into in the previous post, was a ddr3 design by Ultraembedded on Github. This is a very simplistic design, but also have latency issues.
In this post I will look into another Opensource memory controller, which is provided on Github by the Elphel camera project.
The Elphel Camera project is quite a project of note, of which the DDR3 memory controller forms just one component of it. So, in order to understand the surrounding context of their memory controller, I will start at a very high level, explaining what the Elphel camera project is about, and then gradually zoom into the memory controller itself.
About Elphel Inc.
Elphel Inc. is a company that produces opensource digital cameras. It uses lenses and Image sensors from other manufacturers. These cameras processes the images from the image sensors and produces JPGs using an FPGA and a CPU.
One of the notable customers for Elphel cameras was Google Street View. I am sure many people have seen a vehicle like this in their neighbourhood the past decade or so, which was used to capture the footage for Google Street View:
Through the years Elphel produced different camera models, with their most recent models using a SoC that contains both a CPU and an FPGA: The Xilinx Zynq 7030 SoC. This is the big brother of the Zynq 7010, which is used in the Zybo board.
Let us have a quick look at the block diagram for the 10393:
The nice thing here is that the FPGA embedded in the Zynq 7030, and the FPGA on the Arty A7 is from the same FPGA family, so it should be easy to use the 10393 memory controller on our Arty A7 board. However, as you will see later there is some minor tweaks we need to do to make it work on the Arty.
Focusing on the 10393 memory controller
Let us now focus on the 10393 memory controller. First of all, here is the link to the source code for the 10393:
https://github.com/Elphel/x393
The following diagram they provide gives a quick overview on how the components fit together:
Shared External Memory is basically the memory controller, providing various channels for peripherals that need access to memory. The image sensors use channels 8, 9, 10 and 11 for writing image data to memory.
The blocks creating JPEGs for every sensor, uses channel 12, 13, 14 and 15 for reading from memory. Something interesting about these blocks is that they write the resulting JPEGs to the ports SAXIHP1 and SAXIHP2. These ports will ensure that this information ends up in the RAM to which the ARM CPU has access to, so that the JPEGs can be written to an SATA hard drive.
Looking at the code, it is quite difficult to figure out at first glance how the memory controller works. However, I have found it helps if you initially only focus on these files:
- memctrl/mcntrl393.v
- memctrl/memctrl16.v
- memctrl/phy/mcontr_sequencer.v
- memctrl/phy/phy_cmd.v
- memctrl/phy/phy_top.v
More on the DDR3 protocol
- Address
- Cas - Column select
- Ras - Row select
- We - write enable
- DQ - data
- DQS - data strobe
- Command clock