FPGA

How to save code in FPGA board

Time: 2024-12-17 11:52:12View:

To save code (bitstream or design) into an FPGA board, the process involves programming the FPGA with the appropriate configuration file, typically a bitstream file (e.g., .bit, .bin, or .svf files). Depending on whether you want the configuration to be volatile (temporary) or non-volatile (persistent after power-off), the steps will vary slightly.

Here is a detailed guide to saving and programming your code into an FPGA board:


FPGA-Development-Board-1-1024x576.png

1. Volatile Configuration (Temporary Programming)

In this mode, the FPGA is programmed temporarily. Once the power is turned off, the configuration is lost. This is the default programming method for FPGAs because most FPGAs use SRAM-based logic cells.

Steps:

  1. Develop the Code:

    • Write your FPGA design code (e.g., in Verilog, VHDL) in an FPGA development tool like Xilinx Vivado, Intel Quartus, or Lattice Diamond.
  2. Synthesize and Generate the Bitstream:

    • Xilinx: .bit or .bin file
    • Intel (Altera): .sof (SRAM Object File)
    • Lattice: .jed or .bin
    • Compile the code to generate the bitstream file:
  3. Connect the FPGA Board:

    • JTAG Programmer: Most FPGA boards have a JTAG connector (e.g., Xilinx Platform Cable or Intel USB Blaster).
    • USB: Some boards have built-in USB interfaces for programming.
    • SPI Flash Programmer (optional).
    • Use a programming interface or cable like:
  4. Load the Bitstream into the FPGA:

    • Select the FPGA device.
    • Load the .bit or .sof file into the FPGA.
    • Open your FPGA tool (Vivado, Quartus, etc.) and connect to the FPGA board.
    • Use the programming tool within the IDE (e.g., Xilinx Hardware Manager or Intel Quartus Programmer):
    • Start programming. The FPGA will be configured temporarily.

Key Notes:

  • The configuration will be lost when the power is turned off.
  • Useful for testing and debugging purposes.

2. Non-Volatile Configuration (Persistent Programming)

To save the FPGA configuration permanently, you need to store the bitstream into an external non-volatile memory (like SPI Flash, EEPROM, or onboard PROM). Upon power-up, the FPGA loads the configuration from the non-volatile memory.

Steps:

  1. Prepare the Bitstream for Flash Memory:

    • For Xilinx: Use Vivado to convert .bit to .bin or .mcs.
    • For Intel: Generate .pof or .jic files.
    • Generate a file format suitable for flash memory (e.g., .bin, .mcs, or .hex):
  2. Identify the Storage Device:

    • Many FPGA boards include onboard SPI Flash, EEPROM, or other non-volatile memory.
    • Example: Xilinx FPGA boards often use SPI Flash memory (e.g., Micron or Winbond chips).
  3. Program the Non-Volatile Memory:

    • Target the flash memory instead of the FPGA directly.
    • Select the appropriate file (e.g., .bin, .mcs, .pof).
    • Configure the flash memory with the bitstream.
    • Connect the FPGA board using a JTAG programmer, USB programmer, or built-in configuration interface.
    • Open the programming tool (Vivado, Quartus, etc.) and:
  4. Verify and Boot:

    • Power-cycle the FPGA board to test whether the FPGA automatically loads the bitstream from flash memory.

Key Notes:

  • This process ensures the FPGA is configured automatically at power-up.
  • If you update the design, you need to reprogram the flash memory.

3. Common Tools for Saving Code into an FPGA

  1. Xilinx FPGAs (e.g., Spartan, Artix, Zynq):

    • Tool: Vivado or ISE.
    • Programmer: JTAG Programmer (e.g., Xilinx Platform Cable USB).
    • Save to volatile memory (FPGA itself) or non-volatile SPI Flash.
  2. Intel (Altera) FPGAs (e.g., Cyclone, Stratix):

    • Tool: Quartus Prime.
    • Programmer: USB-Blaster.
    • Save to SRAM (volatile) or EPCS/EPCQ Flash memory (non-volatile).
  3. Lattice FPGAs:

    • Tool: Lattice Diamond.
    • Programmer: Lattice Cable.
    • Save to onboard flash or EEPROM.
  4. General Tools:

    • OpenOCD: Open-source tool for JTAG programming.
    • FTDI-based USB-to-JTAG programmers: Used with open-source tools.

4. FPGA Configuration Memories

Here are common types of non-volatile memories for FPGAs:

  1. SPI Flash (most common): Used to store bitstreams permanently.
  2. EEPROM/PROM: Electrically programmable memory.
  3. eMMC or SD Cards: On some boards, you can save the bitstream to an external SD card.

Example – Saving Code on a Xilinx FPGA (Vivado)

  1. Open Vivado and connect the FPGA board using a JTAG cable.
  2. Generate the bitstream file (.bit) and convert it to .bin or .mcs if programming flash.
  3. Open the Hardware Manager in Vivado.
  4. Select Add Configuration Memory Device to program the SPI Flash.
  5. Choose the flash memory part number on your board (e.g., Winbond W25Q).
  6. Load the .mcs file and program the flash.
  7. Power-cycle the FPGA to verify persistent programming.

Summary

  • Volatile Programming: Program the FPGA directly using a JTAG/USB interface. The configuration is lost when power is removed.
  • Non-Volatile Programming: Store the bitstream in external flash memory so that the FPGA is automatically configured on power-up.

For most applications, non-volatile programming is preferred to ensure the FPGA loads the design automatically.