vhdl
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| vhdl [2025/12/14 13:28] – [NIOS] 2a00:1028:919d:bcb2:da5e:d3ff:fe59:4914 | vhdl [2025/12/22 13:56] (current) – [Quartus] 2a00:1028:919d:bcb2:da5e:d3ff:fe59:4914 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== VHDL ===== | + | VHDL https:// |
| - | + | ||
| - | https:// | + | |
| Verilator https:// | Verilator https:// | ||
| - | ===== SDRAM Memory ===== | + | SDRAM https:// |
| - | + | ||
| - | https:// | + | |
| and https:// | and https:// | ||
| Line 16: | Line 11: | ||
| https:// | https:// | ||
| + | |||
| ===== DE-10 Standard ===== | ===== DE-10 Standard ===== | ||
| Line 204: | Line 200: | ||
| Initialization: | Initialization: | ||
| + | |||
| + | |||
| ==== DSP ==== | ==== DSP ==== | ||
| Line 472: | Line 470: | ||
| + | ==== Avalon DDR Memory ==== | ||
| + | |||
| + | Ask Copilot : vhdl example of component with avalon memory master | ||
| + | |||
| + | <code vhdl> | ||
| + | library ieee; | ||
| + | use ieee.std_logic_1164.all; | ||
| + | use ieee.numeric_std.all; | ||
| + | |||
| + | entity avalon_master_example is | ||
| + | port ( | ||
| + | clk : in std_logic; | ||
| + | reset_n | ||
| + | |||
| + | -- Avalon-MM master signals | ||
| + | address | ||
| + | writedata | ||
| + | readdata | ||
| + | read : out std_logic; | ||
| + | write : out std_logic; | ||
| + | waitrequest : in std_logic | ||
| + | ); | ||
| + | end entity; | ||
| + | |||
| + | architecture rtl of avalon_master_example is | ||
| + | type state_type is (IDLE, WRITE_REQ, WRITE_WAIT, READ_REQ, READ_WAIT); | ||
| + | signal state : state_type := IDLE; | ||
| + | signal addr : unsigned(31 downto 0) := (others => ' | ||
| + | begin | ||
| + | process(clk, | ||
| + | begin | ||
| + | if reset_n = ' | ||
| + | state <= IDLE; | ||
| + | address | ||
| + | writedata | ||
| + | read <= ' | ||
| + | write <= ' | ||
| + | elsif rising_edge(clk) then | ||
| + | case state is | ||
| + | when IDLE => | ||
| + | -- Start a write transaction | ||
| + | address | ||
| + | writedata <= x" | ||
| + | write <= ' | ||
| + | state <= WRITE_REQ; | ||
| + | |||
| + | when WRITE_REQ => | ||
| + | if waitrequest = ' | ||
| + | write <= ' | ||
| + | state <= WRITE_WAIT; | ||
| + | end if; | ||
| + | |||
| + | when WRITE_WAIT => | ||
| + | -- After write, start a read | ||
| + | address <= std_logic_vector(addr); | ||
| + | read <= ' | ||
| + | state <= READ_REQ; | ||
| + | |||
| + | when READ_REQ => | ||
| + | if waitrequest = ' | ||
| + | read <= ' | ||
| + | state <= READ_WAIT; | ||
| + | end if; | ||
| + | |||
| + | when READ_WAIT => | ||
| + | -- Data available in readdata | ||
| + | report "Read data: " & integer' | ||
| + | state <= IDLE; | ||
| + | end case; | ||
| + | end if; | ||
| + | end process; | ||
| + | end architecture; | ||
| + | </ | ||
| + | |||
| + | https:// | ||
| + | |||
| + | https:// | ||
| + | |||
| + | Ask Copilot : de10-standard soc system in verilog and component in vhdl | ||
| + | |||
| + | Ask Copilot : sketch out a step‑by‑step guide for writing the .tcl wrapper | ||
| + | |||
| + | Ask Copilot : de10-standard change vhdl component without rebuilding whole quartus project | ||
| + | |||
| + | Ask Copilot : Quartus add avalon component with access to ddr | ||
| + | |||
| + | Ask Copilot : de10-standard linux shows only 768 MB RAM | ||
| + | |||
| + | Ask Copilot : how to use part of FPGA RESERVED 256 MB in vhdl example | ||
| + | |||
| + | Ask Copilot : how to write from HPS to FPGA RESERVED 128 MB RAM and how to read from vhdl example | ||
| + | |||
| + | |||
| + | Your FPGA logic must be an Avalon‑MM Master connected to the FPGA‑to‑HPS SDRAM bridge. | ||
| + | |||
| + | <code vhdl> | ||
| + | library ieee; | ||
| + | use ieee.std_logic_1164.all; | ||
| + | use ieee.numeric_std.all; | ||
| + | |||
| + | entity ddr_reader is | ||
| + | port ( | ||
| + | clk : in std_logic; | ||
| + | reset_n | ||
| + | -- Avalon-MM Master | ||
| + | avm_address | ||
| + | avm_read | ||
| + | avm_readdata | ||
| + | avm_readdatavalid : in std_logic; | ||
| + | avm_waitrequest | ||
| + | -- Output | ||
| + | data_out | ||
| + | ); | ||
| + | end entity; | ||
| + | |||
| + | architecture rtl of ddr_reader is | ||
| + | signal addr : unsigned(31 downto 0) := x" | ||
| + | begin | ||
| + | process(clk, | ||
| + | begin | ||
| + | if reset_n = ' | ||
| + | avm_read <= ' | ||
| + | addr <= x" | ||
| + | elsif rising_edge(clk) then | ||
| + | if avm_waitrequest = ' | ||
| + | avm_address <= std_logic_vector(addr); | ||
| + | avm_read | ||
| + | else | ||
| + | avm_read <= ' | ||
| + | end if; | ||
| + | |||
| + | if avm_readdatavalid = ' | ||
| + | data_out <= avm_readdata; | ||
| + | addr <= addr + 4; -- increment address | ||
| + | end if; | ||
| + | end if; | ||
| + | end process; | ||
| + | end rtl; | ||
| + | </ | ||
| + | |||
| + | Ask Copilot : Quartus how to add Avalon‑MM Master | ||
| + | |||
| + | < | ||
| + | Tools → Platform Designer (Qsys). | ||
| + | File → New Component. | ||
| + | |||
| + | In the Interfaces tab, add a new interface: | ||
| + | Type: Avalon‑MM Master | ||
| + | | ||
| + | |||
| + | Add your custom component to the system. (File/Open File, Project/Add Current File) | ||
| + | Connect the Avalon‑MM Master interface to a target (e.g., DDR SDRAM Controller). | ||
| + | Assign address ranges in the Address Map. | ||
| + | </ | ||
| ==== Verilog SDRAM ==== | ==== Verilog SDRAM ==== | ||
| Line 617: | Line 769: | ||
| 230 * 1024 16-bit COMPILATION ERROR | 230 * 1024 16-bit COMPILATION ERROR | ||
| 229 * 1024 16-bit COMPILATION ERROR | 229 * 1024 16-bit COMPILATION ERROR | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | Control Panel | ||
| + | |||
| + | Logic utilization (in ALMs) 11, | ||
| + | Total registers 23823 | ||
| + | Total pins 338 / 499 ( 68 % ) | ||
| + | Total virtual pins 0 | ||
| + | Total block memory bits 1, | ||
| + | Total DSP Blocks 20 / 112 ( 18 % ) | ||
| </ | </ | ||
| Line 624: | Line 787: | ||
| PROCESSOR https:// | PROCESSOR https:// | ||
| - | ==== NIOS ==== | ||
| VGA https:// | VGA https:// | ||
| Line 635: | Line 797: | ||
| https:// | https:// | ||
| + | |||
| + | https:// | ||
| + | |||
| 0x40000000 https:// | 0x40000000 https:// | ||
| - | https://github.com/zangman/de10-nano/blob/master/ | + | |
| + | CD https://download.terasic.com/downloads/ | ||
| https:// | https:// | ||
| + | |||
| + | https:// | ||
| + | |||
| + | https:// | ||
| + | |||
| + | < | ||
| + | ethaddr=fe: | ||
| + | ipaddr=10.8.0.97 | ||
| + | serverip=10.8.0.36 | ||
| + | xfpga=tftpboot 100 socfpga.rbf; | ||
| + | xload=run xfpga; tftpboot 8000 zImage; bootz 8000 – 100 | ||
| + | </ | ||
| + | |||
| + | https:// | ||
| + | |||
| + | https:// | ||
| + | |||
| + | https:// | ||
| + | |||
| + | https:// | ||
| + | |||
| + | ==== Avalon MM ==== | ||
| + | |||
| + | https:// | ||
| + | |||
| + | < | ||
| + | # connect clk to clk_50.clk | ||
| + | |||
| + | # connect reset to clk_50.clk_reset | ||
| + | |||
| + | # connect s_slave to hps_0.h2f_axi_master | ||
| + | |||
| + | # connect m_master to hps_0.f2h_sdram0_data, | ||
| + | |||
| + | # assign address ranges to the slave | ||
| + | # hps_0.f2h_sdram0_data ... 0x00000000 – 0x3FFFFFFF | ||
| + | |||
| + | # set_interface_property reset associatedClock clk | ||
| + | </ | ||
| + | |||
| + | <code vhdl> | ||
| + | library ieee; | ||
| + | use ieee.std_logic_1164.all; | ||
| + | use ieee.numeric_std.all; | ||
| + | |||
| + | entity ddr3_burst_master_ctrl is | ||
| + | generic ( | ||
| + | BURST_LEN : integer := 8 | ||
| + | ); | ||
| + | port ( | ||
| + | clk : in std_logic; | ||
| + | reset : in std_logic; | ||
| + | |||
| + | -------------------------------------------------------------------- | ||
| + | -- Avalon-MM SLAVE (Nios II / HPS controls registers) | ||
| + | -------------------------------------------------------------------- | ||
| + | s_address | ||
| + | s_write | ||
| + | s_read | ||
| + | s_writedata | ||
| + | s_readdata | ||
| + | |||
| + | -------------------------------------------------------------------- | ||
| + | -- Avalon-MM MASTER (to DDR3 or HPS bridge) | ||
| + | -------------------------------------------------------------------- | ||
| + | m_address | ||
| + | m_read | ||
| + | m_readdata | ||
| + | m_readdatavalid | ||
| + | m_write | ||
| + | m_writedata | ||
| + | m_waitrequest | ||
| + | m_byteenable | ||
| + | m_burstcount | ||
| + | ); | ||
| + | end entity; | ||
| + | |||
| + | architecture rtl of ddr3_burst_master_ctrl is | ||
| + | |||
| + | -------------------------------------------------------------------- | ||
| + | -- Slave registers | ||
| + | -------------------------------------------------------------------- | ||
| + | signal reg_control | ||
| + | signal reg_baseaddr | ||
| + | signal reg_length | ||
| + | signal reg_status | ||
| + | |||
| + | signal start_pulse | ||
| + | |||
| + | -------------------------------------------------------------------- | ||
| + | -- Burst engine | ||
| + | -------------------------------------------------------------------- | ||
| + | type state_t is (IDLE, WRITE, WRITE_WAIT, READ, READ_WAIT, DONE); | ||
| + | signal state : state_t := IDLE; | ||
| + | |||
| + | signal idx : integer := 0; | ||
| + | signal burst_idx | ||
| + | signal expected | ||
| + | |||
| + | begin | ||
| + | |||
| + | m_byteenable <= " | ||
| + | m_burstcount <= std_logic_vector(to_unsigned(BURST_LEN, | ||
| + | |||
| + | -------------------------------------------------------------------- | ||
| + | -- SLAVE REGISTER READBACK | ||
| + | -------------------------------------------------------------------- | ||
| + | with s_address select | ||
| + | s_readdata <= reg_control | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | -------------------------------------------------------------------- | ||
| + | -- SLAVE REGISTER WRITE | ||
| + | -------------------------------------------------------------------- | ||
| + | process(clk) | ||
| + | begin | ||
| + | if rising_edge(clk) then | ||
| + | if reset = ' | ||
| + | reg_control | ||
| + | reg_status | ||
| + | else | ||
| + | if s_write = ' | ||
| + | case s_address is | ||
| + | when " | ||
| + | when " | ||
| + | when " | ||
| + | when others => null; | ||
| + | end case; | ||
| + | end if; | ||
| + | end if; | ||
| + | end if; | ||
| + | end process; | ||
| + | |||
| + | -------------------------------------------------------------------- | ||
| + | -- Detect start pulse | ||
| + | -------------------------------------------------------------------- | ||
| + | process(clk) | ||
| + | begin | ||
| + | if rising_edge(clk) then | ||
| + | start_pulse <= ' | ||
| + | if reg_control(0) = ' | ||
| + | start_pulse <= ' | ||
| + | reg_control(0) <= ' | ||
| + | end if; | ||
| + | end if; | ||
| + | end process; | ||
| + | |||
| + | -------------------------------------------------------------------- | ||
| + | -- BURST ENGINE | ||
| + | -------------------------------------------------------------------- | ||
| + | process(clk, | ||
| + | begin | ||
| + | if reset = ' | ||
| + | state <= IDLE; | ||
| + | m_read <= ' | ||
| + | m_write <= ' | ||
| + | reg_status <= (others => ' | ||
| + | idx <= 0; | ||
| + | burst_idx <= 0; | ||
| + | |||
| + | elsif rising_edge(clk) then | ||
| + | case state is | ||
| + | |||
| + | ---------------------------------------------------------------- | ||
| + | when IDLE => | ||
| + | reg_status <= (others => ' | ||
| + | if start_pulse = ' | ||
| + | idx <= 0; | ||
| + | state <= WRITE; | ||
| + | end if; | ||
| + | |||
| + | ---------------------------------------------------------------- | ||
| + | -- BURST WRITE | ||
| + | ---------------------------------------------------------------- | ||
| + | when WRITE => | ||
| + | m_address <= std_logic_vector( | ||
| + | unsigned(reg_baseaddr) + to_unsigned(idx*4, | ||
| + | ); | ||
| + | m_write <= ' | ||
| + | burst_idx <= 0; | ||
| + | |||
| + | expected <= std_logic_vector( | ||
| + | to_unsigned(idx, | ||
| + | ); | ||
| + | m_writedata <= expected; | ||
| + | |||
| + | state <= WRITE_WAIT; | ||
| + | |||
| + | when WRITE_WAIT => | ||
| + | if m_waitrequest = ' | ||
| + | burst_idx <= burst_idx + 1; | ||
| + | |||
| + | if burst_idx = BURST_LEN-1 then | ||
| + | m_write <= ' | ||
| + | idx <= idx + BURST_LEN; | ||
| + | |||
| + | if idx >= to_integer(unsigned(reg_length)) then | ||
| + | idx <= 0; | ||
| + | state <= READ; | ||
| + | else | ||
| + | state <= WRITE; | ||
| + | end if; | ||
| + | |||
| + | else | ||
| + | expected <= std_logic_vector( | ||
| + | to_unsigned(idx + burst_idx + 1, 32) xor x" | ||
| + | ); | ||
| + | m_writedata <= expected; | ||
| + | end if; | ||
| + | end if; | ||
| + | |||
| + | ---------------------------------------------------------------- | ||
| + | -- BURST READ | ||
| + | ---------------------------------------------------------------- | ||
| + | when READ => | ||
| + | m_address <= std_logic_vector( | ||
| + | unsigned(reg_baseaddr) + to_unsigned(idx*4, | ||
| + | ); | ||
| + | m_read <= ' | ||
| + | burst_idx <= 0; | ||
| + | state <= READ_WAIT; | ||
| + | |||
| + | when READ_WAIT => | ||
| + | if m_waitrequest = ' | ||
| + | m_read <= ' | ||
| + | end if; | ||
| + | |||
| + | if m_readdatavalid = ' | ||
| + | expected <= std_logic_vector( | ||
| + | to_unsigned(idx + burst_idx, 32) xor x" | ||
| + | ); | ||
| + | |||
| + | if m_readdata /= expected then | ||
| + | reg_status(1) <= ' | ||
| + | end if; | ||
| + | |||
| + | burst_idx <= burst_idx + 1; | ||
| + | |||
| + | if burst_idx = BURST_LEN-1 then | ||
| + | idx <= idx + BURST_LEN; | ||
| + | |||
| + | if idx >= to_integer(unsigned(reg_length)) then | ||
| + | state <= DONE; | ||
| + | else | ||
| + | state <= READ; | ||
| + | end if; | ||
| + | end if; | ||
| + | end if; | ||
| + | |||
| + | ---------------------------------------------------------------- | ||
| + | when DONE => | ||
| + | reg_status(0) <= ' | ||
| + | |||
| + | end case; | ||
| + | end if; | ||
| + | end process; | ||
| + | |||
| + | end architecture; | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | set_module_property NAME ddr3_burst_master_ctrl | ||
| + | set_module_property VERSION 1.0 | ||
| + | set_module_property DISPLAY_NAME "DDR3 Burst Master with Control Registers" | ||
| + | set_module_property DESCRIPTION " | ||
| + | set_module_property AUTHOR " | ||
| + | set_module_property INSTANTIATE_IN_SYSTEM_MODULE true | ||
| + | set_module_property EDITABLE true | ||
| + | set_module_property HDL_LANGUAGE VHDL | ||
| + | set_module_property TOP_LEVEL_HDL_FILE ddr3_burst_master_ctrl.vhd | ||
| + | set_module_property TOP_LEVEL_HDL_MODULE ddr3_burst_master_ctrl | ||
| + | |||
| + | # ============================================================ | ||
| + | # Clock interface | ||
| + | # ============================================================ | ||
| + | add_interface clk clock end | ||
| + | set_interface_property clk EXPORT_OF "" | ||
| + | add_interface_port clk clk clk Input 1 | ||
| + | |||
| + | # ============================================================ | ||
| + | # Reset interface | ||
| + | # ============================================================ | ||
| + | add_interface reset reset end | ||
| + | set_interface_property reset EXPORT_OF "" | ||
| + | add_interface_port reset reset reset Input 1 | ||
| + | |||
| + | # ============================================================ | ||
| + | # Avalon-MM SLAVE (register interface for Nios II / HPS) | ||
| + | # ============================================================ | ||
| + | add_interface s_slave avalon slave | ||
| + | set_interface_property s_slave associatedClock clk | ||
| + | set_interface_property s_slave associatedReset reset | ||
| + | set_interface_property s_slave addressUnits WORDS | ||
| + | set_interface_property s_slave readLatency 0 | ||
| + | set_interface_property s_slave writeWaitTime 0 | ||
| + | |||
| + | add_interface_port s_slave s_address address Input 4 | ||
| + | add_interface_port s_slave s_write write Input 1 | ||
| + | add_interface_port s_slave s_read read Input 1 | ||
| + | add_interface_port s_slave s_writedata writedata Input 32 | ||
| + | add_interface_port s_slave s_readdata readdata Output 32 | ||
| + | |||
| + | # ============================================================ | ||
| + | # Avalon-MM MASTER (burst engine to DDR3 or HPS bridge) | ||
| + | # ============================================================ | ||
| + | add_interface m_master avalon master | ||
| + | set_interface_property m_master associatedClock clk | ||
| + | set_interface_property m_master associatedReset reset | ||
| + | set_interface_property m_master addressUnits WORDS | ||
| + | set_interface_property m_master burstOnBurstBoundariesOnly false | ||
| + | set_interface_property m_master linewrapBursts false | ||
| + | set_interface_property m_master maximumPendingReadTransactions 1 | ||
| + | set_interface_property m_master readLatency 0 | ||
| + | |||
| + | add_interface_port m_master m_address address Output 32 | ||
| + | add_interface_port m_master m_read read Output 1 | ||
| + | add_interface_port m_master m_readdata readdata Input 32 | ||
| + | add_interface_port m_master m_readdatavalid readdatavalid Input 1 | ||
| + | add_interface_port m_master m_write write Output 1 | ||
| + | add_interface_port m_master m_writedata writedata Output 32 | ||
| + | add_interface_port m_master m_waitrequest waitrequest Input 1 | ||
| + | add_interface_port m_master m_byteenable byteenable Output 4 | ||
| + | add_interface_port m_master m_burstcount burstcount Output 8 | ||
| + | |||
| + | </ | ||
| + | |||
| + | **add_component.tcl** | ||
| + | |||
| + | < | ||
| + | In a Quartus TCL console or shell: | ||
| + | qsys-script --script=add_component.tcl | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | # Load existing system | ||
| + | load_system soc_system.qsys | ||
| + | |||
| + | # ------------------------------------------------------------- | ||
| + | # Add your custom component | ||
| + | # ------------------------------------------------------------- | ||
| + | add_instance ddr3_burst_master_ctrl_0 ddr3_burst_master_ctrl | ||
| + | |||
| + | # ------------------------------------------------------------- | ||
| + | # Connect clocks and resets from HPS | ||
| + | # ------------------------------------------------------------- | ||
| + | add_connection hps_0.h2f_user0_clock ddr3_burst_master_ctrl_0.clk | ||
| + | add_connection hps_0.h2f_reset | ||
| + | |||
| + | # ------------------------------------------------------------- | ||
| + | # Connect control registers to HPS lightweight bridge | ||
| + | # ------------------------------------------------------------- | ||
| + | add_connection hps_0.h2f_lw_axi_master ddr3_burst_master_ctrl_0.s_slave | ||
| + | |||
| + | # Assign address window for control registers | ||
| + | set_connection_parameter_value hps_0.h2f_lw_axi_master/ | ||
| + | |||
| + | set_connection_parameter_value hps_0.h2f_lw_axi_master/ | ||
| + | |||
| + | # ------------------------------------------------------------- | ||
| + | # Connect burst master to HPS DDR3 | ||
| + | # ------------------------------------------------------------- | ||
| + | add_connection ddr3_burst_master_ctrl_0.m_master hps_0.f2h_sdram0_data | ||
| + | |||
| + | # ------------------------------------------------------------- | ||
| + | # Export status signals (optional) | ||
| + | # ------------------------------------------------------------- | ||
| + | add_interface burst_status conduit end | ||
| + | set_interface_property burst_status EXPORT_OF ddr3_burst_master_ctrl_0.status | ||
| + | |||
| + | # ------------------------------------------------------------- | ||
| + | # Save updated system | ||
| + | # ------------------------------------------------------------- | ||
| + | save_system soc_system.qsys | ||
| + | |||
| + | </ | ||
vhdl.1765718911.txt.gz · Last modified: 2025/12/14 13:28 by 2a00:1028:919d:bcb2:da5e:d3ff:fe59:4914
