Thursday, 27 October 2022

SD Card Access for a Arty A7: Part 1

Foreword

In the previous post we wrote some code enabling the reading and writing of 16 bits at a time from DDR3 memory, as required by an Amiga FPGA core. All this effort was required because DDR3 memory doesn't work with a single 16-bit group at time, but several.

Luckily we could around this "hurdle" of DDR3 by making use of data masks.

At this point in the journey to implement an Amiga core on an Arty A7,  it becoming clear that we will need some sort of non-volatile storage for storing ROM's and disk images. We will be using SD Card storage as non-volatile storage on the Arty A7.

The technical details of interfacing with an SD Card via an FPGA can be quite overwhelming, even if you are using an existing library. So, in order to make it less intimidating, I will make a multi part series of interfacing with the SD Card.

This post forms the first in the series of interfacing an Arty A7 with an SD Card. More parts to come in the future.

Using PMOD Headers

When I started this blog, more than three years ago, the FPGA I started playing with was a Zybo board. This nice thing of this board was that it had a build in SD Card Slot.

On the Arty A7 board, however, we don't have such a luxury. All hope not lost, however. One can add an external SD Card reader by means of a PMOD header.

For those that are not familiar with PMOD headers, let us go into a bit more detail of what PMOD headers is and how it is used.

PMOD is a standard Digilent use on their development boards. Digilent, by the way is the manufacturer that produces both the Arty A7 board and the Zybo board.

Let us start by having a look at the PMOD headers on my Arty A7 board:


As you can see, each PMOD header is 6 pins wide and 2 pins high. The pin spacing for these headers are fairly standard, and are the same as you will find on a breadboard or the GPIO pins on a Raspberry Pi.

One thing that might annoy the alert reader is that their is no 'safety notch' to prevent inserting the PMOD module the wrong way around. It is indeed possible to insert a PMOD module the wrong way around, so just keep this in mind when working with PMOD's. More on this a bit later.

At this point, the question is: Which PMOD header do we use on the Arty A7 board? At first sight, this may sound like a stupid question. I mean, if you have a PC with a number of USB ports, you just pick one, right?

Well, with PMOD's you need to exercise a bit more caution. Let me explain. You get two types of PMOD: Standard and high speed. With standard PMOD the current is limited on each by means of resistors. This is a kind of safety feature, so that if you incidentally short two pins on the header, the FPGA doesn't go up in smoke. 

The downside of these resistors is that they also limit the maximum speed that the pins on the PMOD can run at and this is where high speed PMOD comes in. On a high speed PMOD, these protection resistors are absent, which makes it possible to make your FPGA go up in smoke 😱.

So, nothing wrong in using a high speed PMOD, but if don't need the speed it provides, it is safer to for the Standard PMOD.

Let us where these types of PMOD's are located on the Arty A7. I got this picture from the Arty A7 Reference manual, hosted here:


The PMODs are located right at the top, as indicated by callout #16. If you look closely at the diagram, you will see the PMOD's are number from left to right as JA, JB, JC and JD.

The Reference manual states that JB and JC are high speed PMODs and JA and JD are standard PMOD's. At first I found it quite intriguing that the high speed PMODs are next to each other, while the Standard PMODs are not. I eventually found some answer for this when I saw how a VGA PMOD look like:

Here we see that a VGA PMOD needs two separate PMODs next to each other. This PMOD needs High Speed PMODs and thus it makes sense for me somewhat that Digilent put two High Speed PMODs next to each other on their development boards. All the other Standard PMOD modules I have seen for sale only uses a single PMOD, so the location of Standard PMODs doesn't really matter.

The SD Card PMOD

So, I bought myself a PMOD SD Card Reader from RS Components. With everything removed from the bag of the courier and excess packaging, this is what I got:


This module is for the full size SD Card, so I will need to use an adaptor for reading a MicroSD Card.

There is a nice diagram on the packaging indicating which pin is which on the PMOD header. The Technical reference for this module, here, makes mention that there is a small printing error on the printed diagram on the packaging. However, I verified the diagram on my packaging, and it looked correct for me. Perhaps they fixed it in later revisions.

Now, to come back to our question from the previous section, how do we determine the correct orientation for inserting this module into the PMOD header? Start by flipping this module around, so that the Sd Card slot faces to the top:


In this picture I have indicated with a red arrow the presence of a "1" on the PCB. This marks pin 1 of the PMOD header, which if you follow this pin from the PCB, is the top right pin on the PMOD header.

Compare this to the pin out of a PMOD header, which I also retrieved from digilent.com :


This means the upright orientation of the SD Card slot, as shown above, is the correct way to insert the module into the PMOD Header.

I feel I was quite pedantic, just to explain which site is up 😂. 

About the Software

We have more or less the hardware in place for reading from an SD Card. However, we still need the necessary software for interfacing with the SD Card.

I belief Vivado does provide some IP blocks for interfacing with an SD Card reader. However, I am not a big fan of these proprietary blocks, and would rather want to use an Opensource module.

There is indeed an Opensource module on GitHub developed by Dan Gisselquist. This module is written in Verilog. We will explore this project more in the next post.

In Summary

In this post we explored how to interface the Arty A7 with an SD Card for non-volatile storage. I will be using a PMOD module from  Digilent that will act as the SD Card reader.

In the next post we will be exploring the SD Card project by Dan Gisselquist, which we use to interface the Arty A7 with the SD Card reader.

Until next time!

No comments:

Post a Comment