Issues with SD CardInfo example on Papilio Duo AVR


Brandon Walderman

Recommended Posts

Hello,

I'm working on an implementation of the HACK computer from Nand2Tetris. My experience has been almost all on the FPGA side so far. I have written a working CPU with keyboard input and VGA output, and now I want to use the AVR as a kind of bootloader. My goal is to load the computer's software from a file on an SD card using the Arduino SD library and then stream it to the FPGA which will copy it into the SRAM. Once the program is transferred, the AVR should tell the FPGA to begin executing it.

As a first step, I'm trying to get the CardInfo example to run and verify that it can read an SD card, but I haven't had much luck. My experience so far has been with Verilog programming in Xilinx ISE, so I'm completely new to Arduino programming. The card.init() call fails with SD_INIT_TIMEOUT. For now, I'm using a blank FPGA circuit. I suspect something is wrong with the Arduino pin assignments for the AVR and I'm not sure how to verify I have the correct pins. The example file only has a variable for configuring the CS pin:

const int chipSelect = 4;

The example file doesn't mention the SCK, MOSI, or MISO pins. I tried running CardInfo with the default value of chipSelect = 4. Then I tried chipSelect = 10. Neither of these values worked. I looked up the pin-out diagram here: http://papilio.cc/uploads/Papilio/Papilio DUO pinout for CC.pdf. This states that the chip select pin is D16. I'm not sure what this maps to in C++ code though; chipSelect = 16 did not work either. How can I determine what the correct pin number to use is? Do I also need to setup the SCK, MOSI and MISO pins somehow?

Thanks!

-Brandon

Link to comment
Share on other sites

Hello Brandon,

Those examples use a SPI controller connected to the wishbone bus of the ZPUino. So the location of the SCK, MOSI, and MISO pins are determined by how you connect the SPI controller in your FPGA circuit. Take a look at the examples in DesignLab and look at the FPGA circuit portion to see how they are connected. The error you are getting is most likely caused by not loading a zpuino circuit to your FPGA that has the SPI master... 

It is also possible to connect the SCK, MOSI, and MISO pins to the flex pins in a Designlab circuit, this lets you move those pins to any physical pin of the FPGA with your code. There should be examples of how to do this in DesignLab too.

Jack

Link to comment
Share on other sites

  • 2 weeks later...

Hi Jack,

Thanks for the reply. The Papilio Duo and the shield have been a blast so far.

It turned out the first problem was that I was using the libraries and example files that came with DesignLab, rather than the modified examples found in the DesignLab_Examples GitHub repo. When I ran the CardInfo example from the GitHub repo on the ZPUIno, it worked correctly. Some extra work was needed to get this example working on the AVR. I've created a pull request here with the needed changes if you are interested: https://github.com/GadgetFactory/DesignLab_Examples/pull/5

I forgot to mention I've been using a Classic Computing Shield with the Papilio Duo, so I needed to use the pins on the shield that the SD slot is connected to, and I didn't have the option of using flex pins.

Brandon

Link to comment
Share on other sites

Hello Brandon,

Glad you got it working  and thank you for the pull request. I'm actually thinking through a reboot of the source code at the moment. Getting away from DesignLab, the schematic based approach just didn't garner much interest, and going to a node.js solution with examples synthesized with a CI backend on Gitlab. I've actually started a couple of projects with CI at Gitlab and am still working through how to manage VHDL/Verilog libraries with node.js before I proceed. Hopefully I can do a reboot and get everything easier to find and maintain...

Jack.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.