Jump to content
  • 0

How to write to the Nexys 3 using the SDK


_hlee

Question

I want to be able to to write a file to RAM and configure the Nexys 3 by loading a bit file. I know that I can do this via the Digilent Adept program, however, I would like to do the same programmatically. I've looked through the SDK documentation but I'm not sure where to begin. 

Link to comment
Share on other sites

14 answers to this question

Recommended Posts

@_hlee,

You might need to clarify with some more information exactly what it is you wish to do.

I recently finished posting a series of articles on zipcpu.com regarding how to communicate to a memory (I demonstrated a block RAM and an internal logic scope) within an FPGA from a serial port.  You can find the example code here.  It's not specific to any processor, as built, and only depends upon a clock and a serial port.  Given that it's licensed under LGPL, you should be able to convert it into ... whatever it is exactly that you'd like to do.  (Want to read/write flash?  SDRAM?  It all starts there ...)

If that doesn't help, then ... can you explain more of what you would like to do?

Dan

Link to comment
Share on other sites

Hi @D@n, I'm not entirely sure if the code you gave me is what I want to do so let me clarify and give some more detail. 

I have a Nexys 3 and a Nexys 4 that I am currently interacting with via the Digilent Adept program. I currently write a compiled c program into RAM memory (a .bin file). Then I program the device with a .bit file. I would like to automate this process. 

Are there any resources to help with this? 

Lee

 

Link to comment
Share on other sites

@_hlee,

What you are asking for, with respect to the Nexys 4, is physically impossible.  Because the Nexys-4 is built with SDRAM instead of SRAM, and because the memory components of an SDRAM are made of capacitors that need to be refreshed, it is (generally) impossible to load the memory and *then* load the bitfile.  (Feel free to find a way, and then prove me wrong ...)  The configuration loaded onto the device needs to actively manage (refresh) that memory, and so it cannot load memory in one pass and a bit file in the next without violating the SDRAM's refresh criteria.  The cellular RAM on the Nexys 3 doesn't have this problem.

The more sustainable approach is often to write the program memory into flash, and then when the CPU starts up to have it copy from flash to S(D)RAM as it starts up.  This is the purpose of a bootloader.  You may find this approach to getting a bootloader running works well for MicroBlaze based designs.  You can also see the code for the ZipCPU's bootloader here, if you'd like to examine an open source approach to the task.

Another approach I use, with the ZipCPU, is to start the design/configuration (.bit file) with the CPU in a halted state.  This then allows me to write to the memory within the design, adjust the flash, adjust the SDRAM, adjust any CPU registers, and then give the CPU a command to start running.  This logic is captured within the zipload command, that is a part of the ZBasic and OpenArty repo's.  To do this, though, you'll need both logic support on the FPGA as well software support on your host computer.

Dan

Link to comment
Share on other sites

@D@n

Thanks for the in-depth reply. I mistyped in my previous response. I am not doing so with the Nexys 4 but with the Nexys 3. 

I am, however, still uncertain of where to go. So let's forget trying to load a program into memory (I can try to figure that out later). First things first, how do I start the design/configuration? I'm looking at the documentation that comes with the SDK and there's nothing there about configuring the device. So is there a function that lets me write to a place in memory? What place in memory would I even write to? 

Also, I am communicating via the UART ports. Am I correct in that I should be looking at the DACI interface specs? 

Lee

Link to comment
Share on other sites

@_hlee,

Have you used ISE before?  You'll need to start it up, create a new project, and identify the FPGA chip you are using within ISE.  Digilent has a tutorial for getting started with FPGA's here.

The best "first project" to start with on an FPGA (or other embedded system) is usually "blinky"--a simple design that turns the LED's on and off.  You can find Digilent's tutorial on how to get blinky up and running here.  Hmm ... looking that over, it uses an asynchronous reset (BAD).  Here's another Verilog tutorial on how to write "blinky" that doesn't have that problem.  Don't forget, you'll need to connect the outputs of this design to the FPGA pins on your board via a UCF file.

Once you move past blinky, you might wish to turn your LED's into those from Knight Rider's car ... after that it's usually time to get serious.  I'm every engineer out there has a different opinion of what your first serious project should be.  My recommendation is that your first serious project should be one that helps you debug the rest of your projects.  You can find an example of such a project here.  It's described in a series of articles, all hosted on zipcpu.com, about how to get access to the internals of what's going on within an FPGA.

Dan

Link to comment
Share on other sites

@D@n,

I should clarify. I've already created a bit file. It's the third step in the "getting started with FPGAs" that I would like to find a way to program. The process of opening the Adept program, picking the board I want to program, picking the file to program, and pressing the "program" button is something I want to automate. 

Is there any way to do this? 

Thanks for all your help. 

Lee. 

Link to comment
Share on other sites

@_hlee,

I feel like I'm answering all the wrong questions.  My apologies!

Look at the Adept utility djtgcfg.  The man page should be pretty good for explaining how it works.  I generally call it three times: once to enumerate the devices I have, once to initialize the device I want to program, and then the last time to actually program the device.  You need the enumeration, if for no other reason than to find the identifier that identifies your device.

Dan

Link to comment
Share on other sites

@D@n,

Thanks so much! I don't think I could have ever found that utility without you. 

Does the djtgcfg utility also give the user the ability to write to the flash memory of a nexys 3? The man paeg shows me how to program the device with a `.bit` file but there isn't anything on writing to flash (SPI or BPI Flash) or RAM.

Lee

Link to comment
Share on other sites

@_hlee,

With a little searching, I found this answer record:

The basic answer is that programming flash is only available via the GUI.

Bummer.

I've never been slowed down by this, though.  I've always programmed the flash myself from a command line--as I've discussed in the mis-guided answers above.  ;)  Doing that, though, requires a design specifically built with the capability of loading flash from within the design--it's not as simple to build as your favorite MicroBlaze design that reads from flash--although once you load the flash, there shouldn't be any problem with switching to the design you are interested in and running that ...

Dan

Link to comment
Share on other sites

@D@n,

Hmm. I had seen that post too and I was hoping that things had changed in the past 2 years. 

Also, I should point out that I'm not trying to program the FPGA by sending a `.bit` file to flash memory. I'm trying to send in a binary file (`.bin`) that the `.bit` file that I've programed the FPGA with already will run. The `.bin` file is just a compiled c program. Is there a way to write bits of flash memory programmatically (say via the SDK if not the command line utilities?). 

Lee

Link to comment
Share on other sites

@_hlee,

As for whether or not anything has changed, let's see if we can get @sbobrowicz to join us and answer the question.

As for writing programs to flash, if you have a design you can use to write flash memory in the first place, you can use the libelf library to extract from your binary program (assuming it's in an ELF format, which I think the SDK uses ...) into the appropriate memory regions of the flash.  Again, the zipload program I pointed you at before would do this, as long as you had a design that would allow you to communicate with it.  You'd also need for the two designs to share the address of the flash memory between them.

Dan

Link to comment
Share on other sites

Hi @_hlee,

I re-verified thatSPI Flash from Adept 2 is still a feature that is only available in the Adept GUI, which only works in Windows. Adept 2 can not write some arbitrary set of bits to either SPI Flash, BPI Flash, or the RAM on a nexys 3 without the GUI. I believe you could program the flash using iMPACT in linux if that is an option.

cheers,

Jon

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...