You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
7.8 KiB

  1. -- #################################################################################################
  2. -- # << NEORV32 - Example setup including the bootloader, for the Gatemate (c) Eval Board >> #
  3. -- # ********************************************************************************************* #
  4. -- # BSD 3-Clause License #
  5. -- # #
  6. -- # Copyright (c) 2022, Torsten Meissner. All rights reserved. #
  7. -- # #
  8. -- # Redistribution and use in source and binary forms, with or without modification, are #
  9. -- # permitted provided that the following conditions are met: #
  10. -- # #
  11. -- # 1. Redistributions of source code must retain the above copyright notice, this list of #
  12. -- # conditions and the following disclaimer. #
  13. -- # #
  14. -- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of #
  15. -- # conditions and the following disclaimer in the documentation and/or other materials #
  16. -- # provided with the distribution. #
  17. -- # #
  18. -- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to #
  19. -- # endorse or promote products derived from this software without specific prior written #
  20. -- # permission. #
  21. -- # #
  22. -- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS #
  23. -- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF #
  24. -- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE #
  25. -- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, #
  26. -- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
  27. -- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED #
  28. -- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
  29. -- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED #
  30. -- # OF THE POSSIBILITY OF SUCH DAMAGE. #
  31. -- # ********************************************************************************************* #
  32. -- # The NEORV32 Processor - https://github.com/stnolting/neorv32 (c) Stephan Nolting #
  33. -- #################################################################################################
  34. library ieee;
  35. use ieee.std_logic_1164.all;
  36. use ieee.numeric_std.all;
  37. library neorv32;
  38. use neorv32.neorv32_package.all;
  39. library gatemate;
  40. use gatemate.components.all;
  41. entity neorv32_aes is
  42. port (
  43. -- Clock and Reset inputs
  44. clk_i : in std_logic; -- 10 MHz clock
  45. rst_n_i : in std_logic; -- SW3 button
  46. -- LED outputs
  47. led_n_o : out std_logic_vector(7 downto 0);
  48. -- UART0
  49. -- uart_rx_i : in std_logic; -- PMODA IO
  50. -- uart_tx_o : out std_logic -- PMODA IO
  51. debug_o : out std_logic_vector(15 downto 0)
  52. );
  53. end entity;
  54. architecture rtl of neorv32_aes is
  55. -- configuration --
  56. constant f_clock_c : natural := 10_000_000; -- clock frequency in Hz
  57. -- Globals
  58. signal s_pll_lock : std_logic;
  59. signal s_pll_clk : std_logic;
  60. signal s_cfg_end : std_logic;
  61. signal s_rst_n : std_logic;
  62. signal s_rst_debounced : std_logic;
  63. signal s_con_gpio : std_ulogic_vector(63 downto 0);
  64. signal s_debug : std_logic_vector(63 downto 0);
  65. begin
  66. PLL : CC_PLL
  67. generic map (
  68. REF_CLK => "10",
  69. OUT_CLK => "10",
  70. PERF_MD => "SPEED"
  71. )
  72. port map (
  73. CLK_REF => clk_i,
  74. USR_CLK_REF => '0',
  75. CLK_FEEDBACK => '0',
  76. USR_LOCKED_STDY_RST => '0',
  77. USR_PLL_LOCKED_STDY => open,
  78. USR_PLL_LOCKED => s_pll_lock,
  79. CLK0 => s_pll_clk,
  80. CLK90 => open,
  81. CLK180 => open,
  82. CLK270 => open,
  83. CLK_REF_OUT => open
  84. );
  85. cfg_end : CC_CFG_END
  86. port map (
  87. CFG_END => s_cfg_end
  88. );
  89. rst_debounce : block is
  90. signal s_rst_d : std_logic_vector(29 downto 0);
  91. begin
  92. process (s_pll_clk, rst_n_i) is
  93. begin
  94. if (not rst_n_i) then
  95. s_rst_d <= (others => '0');
  96. elsif (rising_edge(s_pll_clk)) then
  97. s_rst_d <= s_rst_d(s_rst_d'left-1 downto 0) & rst_n_i;
  98. end if;
  99. end process;
  100. s_rst_debounced <= and s_rst_d;
  101. end block rst_debounce;
  102. s_rst_n <= s_pll_lock and s_cfg_end and s_rst_debounced;
  103. -- The core of the problem ----------------------------------------------------------------
  104. -- -------------------------------------------------------------------------------------------
  105. neorv32_inst: entity neorv32.neorv32_top
  106. generic map (
  107. CLOCK_FREQUENCY => f_clock_c, -- clock frequency of s_pll_clk in Hz
  108. INT_BOOTLOADER_EN => false, -- boot configuration: true = boot explicit bootloader; false = boot from int/ext (I)MEM
  109. -- RISC-V CPU Extensions --
  110. CPU_EXTENSION_RISCV_C => false, -- implement compressed extension?
  111. CPU_EXTENSION_RISCV_M => true, -- implement mul/div extension?
  112. CPU_EXTENSION_RISCV_Zicsr => true, -- implement CSR system?
  113. CPU_EXTENSION_RISCV_Zicntr => true, -- implement base counters?
  114. -- Tuning Options --
  115. FAST_MUL_EN => false,
  116. FAST_SHIFT_EN => false,
  117. -- Internal Instruction memory --
  118. MEM_INT_IMEM_EN => true, -- implement processor-internal instruction memory
  119. MEM_INT_IMEM_SIZE => 4*1024, --16*1024, -- size of processor-internal instruction memory in bytes
  120. -- Internal Data memory --
  121. MEM_INT_DMEM_EN => true, -- implement processor-internal data memory
  122. MEM_INT_DMEM_SIZE => 8*1024, -- size of processor-internal data memory in bytes
  123. -- Processor peripherals --
  124. IO_GPIO_EN => true, -- implement general purpose input/output port unit (GPIO)?
  125. IO_MTIME_EN => true, -- implement machine system timer (MTIME)?
  126. IO_UART0_EN => false, -- implement primary universal asynchronous receiver/transmitter (UART0)?
  127. IO_CFS_EN => false, -- implement custom functions subsystem (CFS)?
  128. IO_AES_EN => true -- implement AES(128) custom function?
  129. )
  130. port map (
  131. -- Global control --
  132. clk_i => std_ulogic(s_pll_clk),
  133. rstn_i => std_ulogic(s_rst_n),
  134. -- GPIO
  135. gpio_o => s_con_gpio,
  136. -- primary UART0
  137. uart0_txd_o => open, -- uart_tx_o,
  138. uart0_rxd_i => '1', -- uart_rx_i,
  139. -- debug
  140. debug_o => s_debug
  141. );
  142. debug_o <= s_debug(15 downto 0);
  143. -- p_r ERROR when connecting uart_rx_i & yosys option -retime (with both Yosys inferred & instantiated CC_BRAM_40K or CC_BRAM_40K memory)
  144. -- FATAL ERROR: RAM 4070 Output DOA[6] not used but Input DIA[6] used!
  145. -- program finished with exit code: 2
  146. -- IO Connection --------------------------------------------------------------------------
  147. led_n_o <= not std_logic_vector(s_con_gpio(7 downto 0));
  148. end architecture;